feat: establish coffee game and grinder baseline

This commit is contained in:
Yanchen
2026-11-11 14:08:47 +08:00
commit 890f3fa5f3
220 changed files with 8361 additions and 0 deletions
+218
View File
@@ -0,0 +1,218 @@
(() => {
const SVG_NS = "http://www.w3.org/2000/svg";
const clamp = (min, max, value) => Math.min(max, Math.max(min, value));
function svgElement(tag, attributes = {}) {
const element = document.createElementNS(SVG_NS, tag);
Object.entries(attributes).forEach(([key, value]) => element.setAttribute(key, value));
return element;
}
class AnalogControl {
constructor(element, options) {
this.element = element;
this.value = options.value ?? 0;
this.onChange = options.onChange;
this.label = options.label;
this.dragging = false;
this.build();
this.bindPointer();
this.setValue(this.value, false);
}
bindPointer() {
this.element.addEventListener("pointerdown", event => {
if (event.pointerType === "mouse" && event.button !== 0) return;
event.preventDefault();
this.element.focus({ preventScroll: true });
this.element.setPointerCapture(event.pointerId);
this.dragging = true;
this.element.classList.add("dragging");
this.setFromPointer(event);
});
this.element.addEventListener("pointermove", event => {
if (!this.dragging) return;
event.preventDefault();
this.setFromPointer(event);
});
const finish = event => {
this.dragging = false;
this.element.classList.remove("dragging");
if (this.element.hasPointerCapture(event.pointerId)) this.element.releasePointerCapture(event.pointerId);
};
this.element.addEventListener("pointerup", finish);
this.element.addEventListener("pointercancel", finish);
this.element.addEventListener("lostpointercapture", () => {
this.dragging = false;
this.element.classList.remove("dragging");
});
this.element.addEventListener("keydown", event => {
const step = event.key === "PageUp" || event.key === "PageDown" ? 0.1 : 0.01;
const directions = { ArrowLeft: -step, ArrowDown: -step, ArrowRight: step, ArrowUp: step, PageDown: -step, PageUp: step };
if (event.key === "Home" || event.key === "End") {
event.preventDefault();
this.setValue(event.key === "Home" ? 0 : 1);
} else if (event.key in directions) {
event.preventDefault();
this.setValue(this.value + directions[event.key]);
}
});
}
setValue(value, notify = true) {
this.value = clamp(0, 1, value);
this.render();
if (notify && this.onChange) this.onChange(this.value);
}
}
class RotaryValve extends AnalogControl {
point(angle, radius) {
const radians = angle * Math.PI / 180;
return { x: 160 + radius * Math.sin(radians), y: 160 - radius * Math.cos(radians) };
}
build() {
this.element.classList.add("machine-control", "rotary-valve");
this.element.setAttribute("viewBox", "0 0 320 260");
this.element.setAttribute("role", "slider");
this.element.setAttribute("tabindex", "0");
this.element.setAttribute("aria-label", this.label);
this.element.setAttribute("aria-valuemin", "0");
this.element.setAttribute("aria-valuemax", "180");
const arc = Array.from({ length: 61 }, (_, index) => {
const point = this.point(-90 + index * 3, 124);
return `${index ? "L" : "M"}${point.x.toFixed(2)},${point.y.toFixed(2)}`;
}).join(" ");
this.element.append(svgElement("path", {
d: arc, fill: "none", stroke: "rgba(238,243,232,.22)",
"stroke-width": 7, "stroke-linecap": "round"
}));
for (let index = 0; index <= 36; index += 1) {
const angle = -90 + index * 5;
const major = index % 6 === 0;
const outer = this.point(angle, 124);
const inner = this.point(angle, major ? 110 : 117);
this.element.append(svgElement("line", {
x1: inner.x, y1: inner.y, x2: outer.x, y2: outer.y,
stroke: major ? "#b8c3b2" : "#71806f", "stroke-width": major ? 2 : 1
}));
if (major) {
const label = this.point(angle, 143);
const text = svgElement("text", {
x: label.x, y: label.y + 3, fill: "#aebba9", "font-size": 10,
"text-anchor": "middle", "font-family": "ui-monospace, monospace"
});
text.textContent = `${index * 5}°`;
this.element.append(text);
}
}
this.element.append(svgElement("circle", {
cx: 160, cy: 160, r: 67, fill: "#2d382f", stroke: "#66765f", "stroke-width": 2
}));
this.handle = svgElement("g", { class: "control-handle" });
this.handle.append(
svgElement("line", {
x1: 160, y1: 160, x2: 160, y2: 72,
stroke: "#b99c63", "stroke-width": 13, "stroke-linecap": "round"
}),
svgElement("rect", {
x: 148, y: 48, width: 24, height: 48, rx: 9,
fill: "#e2d3b3", stroke: "#8e754b", "stroke-width": 3
}),
svgElement("line", {
x1: 160, y1: 59, x2: 160, y2: 85,
stroke: "rgba(91,68,37,.34)", "stroke-width": 3, "stroke-linecap": "round"
})
);
this.element.append(this.handle);
this.element.append(
svgElement("circle", { cx: 160, cy: 160, r: 19, fill: "#d8c5a0", stroke: "#8e754b", "stroke-width": 3 }),
svgElement("circle", { cx: 160, cy: 160, r: 6, fill: "#45523f" })
);
this.angleText = svgElement("text", {
x: 160, y: 233, fill: "#edf2e7", "font-size": 24,
"text-anchor": "middle", "font-family": "ui-monospace, monospace"
});
this.element.append(this.angleText);
}
setFromPointer(event) {
const rect = this.element.getBoundingClientRect();
const x = (event.clientX - rect.left) * 320 / rect.width - 160;
const y = (event.clientY - rect.top) * 260 / rect.height - 160;
const angle = Math.atan2(x, -y) * 180 / Math.PI;
this.setValue(angle < -90 ? 0 : angle > 90 ? 1 : (angle + 90) / 180);
}
render() {
const degrees = this.value * 180;
this.handle.setAttribute("transform", `rotate(${-90 + degrees} 160 160)`);
this.angleText.textContent = `${Math.round(degrees)}°`;
this.element.setAttribute("aria-valuenow", String(Math.round(degrees)));
this.element.setAttribute("aria-valuetext", `${Math.round(degrees)} 度`);
}
}
class FlowLever extends AnalogControl {
build() {
this.element.classList.add("machine-control", "flow-lever");
this.element.setAttribute("viewBox", "0 0 320 260");
this.element.setAttribute("role", "slider");
this.element.setAttribute("tabindex", "0");
this.element.setAttribute("aria-label", this.label);
this.element.setAttribute("aria-valuemin", "0");
this.element.setAttribute("aria-valuemax", "100");
this.element.append(
svgElement("line", { x1: 40, y1: 140, x2: 280, y2: 140, stroke: "#141b16", "stroke-width": 20, "stroke-linecap": "round" }),
svgElement("line", { x1: 40, y1: 140, x2: 280, y2: 140, stroke: "#63705f", "stroke-width": 3, "stroke-linecap": "round" })
);
for (let index = 0; index <= 20; index += 1) {
const major = index % 5 === 0;
const x = 40 + index * 12;
this.element.append(svgElement("line", {
x1: x, y1: 155, x2: x, y2: major ? 169 : 163,
stroke: major ? "#b8c3b2" : "#71806f", "stroke-width": major ? 2 : 1
}));
if (major) {
const text = svgElement("text", {
x, y: 190, fill: "#aebba9", "font-size": 11,
"text-anchor": "middle", "font-family": "ui-monospace, monospace"
});
text.textContent = String(index * 5);
this.element.append(text);
}
}
this.handle = svgElement("g", { class: "control-handle" });
this.handle.append(
svgElement("line", { x1: 0, y1: 141, x2: 0, y2: 85, stroke: "#b99c63", "stroke-width": 14, "stroke-linecap": "round" }),
svgElement("rect", { x: -16, y: 47, width: 32, height: 51, rx: 10, fill: "#e2d3b3", stroke: "#8e754b", "stroke-width": 3 }),
svgElement("line", { x1: 0, y1: 59, x2: 0, y2: 85, stroke: "rgba(91,68,37,.34)", "stroke-width": 3, "stroke-linecap": "round" }),
svgElement("circle", { cx: 0, cy: 140, r: 13, fill: "#d8c5a0", stroke: "#8e754b", "stroke-width": 3 }),
svgElement("circle", { cx: 0, cy: 140, r: 5, fill: "#45523f" })
);
this.element.append(this.handle);
const hint = svgElement("text", {
x: 160, y: 229, fill: "#aebba9", "font-size": 11,
"text-anchor": "middle", "font-family": "ui-sans-serif, sans-serif", "letter-spacing": 2
});
hint.textContent = "关闭 · 萃取水流 · 全开";
this.element.append(hint);
}
setFromPointer(event) {
const rect = this.element.getBoundingClientRect();
const x = (event.clientX - rect.left) * 320 / rect.width;
this.setValue((x - 40) / 240);
}
render() {
const percent = Math.round(this.value * 100);
this.handle.setAttribute("transform", `translate(${40 + this.value * 240} 0)`);
this.element.setAttribute("aria-valuenow", String(percent));
this.element.setAttribute("aria-valuetext", `开度 ${percent}%`);
}
}
window.MachineControls = { RotaryValve, FlowLever };
})();
+154
View File
@@ -0,0 +1,154 @@
(() => {
const SVG_NS = "http://www.w3.org/2000/svg";
const clamp = (min, max, value) => Math.min(max, Math.max(min, value));
function svgElement(tag, attributes = {}) {
const element = document.createElementNS(SVG_NS, tag);
Object.entries(attributes).forEach(([key, value]) => element.setAttribute(key, value));
return element;
}
class Gauge {
constructor(element, options) {
this.element = element;
this.options = { sweep: 180, decimals: 0, ...options };
this.build();
}
point(angle, radius) {
const radians = angle * Math.PI / 180;
return { x: 160 + radius * Math.sin(radians), y: 150 - radius * Math.cos(radians) };
}
arc(from, to, radius) {
return Array.from({ length: 41 }, (_, index) => {
const point = this.point(from + (to - from) * index / 40, radius);
return `${index ? "L" : "M"}${point.x.toFixed(2)},${point.y.toFixed(2)}`;
}).join(" ");
}
build() {
const { min, max, target, tolerance, unit, label, sweep, decimals } = this.options;
const angleFor = value => -sweep / 2 + sweep * (value - min) / (max - min);
this.element.classList.add("gauge");
this.element.setAttribute("viewBox", "0 0 320 205");
this.element.setAttribute("role", "img");
this.element.replaceChildren();
this.element.append(svgElement("path", {
d: this.arc(-sweep / 2, sweep / 2, 113), fill: "none", stroke: "rgba(238,243,232,.13)",
"stroke-width": 13, "stroke-linecap": "round"
}));
if (Number.isFinite(target) && Number.isFinite(tolerance) && tolerance > 0) {
const targetStart = angleFor(clamp(min, max, target - tolerance));
const targetEnd = angleFor(clamp(min, max, target + tolerance));
this.element.append(svgElement("path", {
d: this.arc(targetStart, targetEnd, 113), fill: "none", stroke: "#b8d69b",
"stroke-width": 13, "stroke-linecap": "round"
}));
}
for (let index = 0; index <= 20; index += 1) {
const angle = -sweep / 2 + index * sweep / 20;
const outer = this.point(angle, 94);
const inner = this.point(angle, index % 5 === 0 ? 82 : 88);
this.element.append(svgElement("line", {
x1: inner.x, y1: inner.y, x2: outer.x, y2: outer.y,
stroke: "rgba(238,243,232,.42)", "stroke-width": index % 5 === 0 ? 2 : 1
}));
if (index % 5 === 0) {
const textPoint = this.point(angle, 67);
const text = svgElement("text", {
x: textPoint.x, y: textPoint.y + 3, fill: "#96a394", "font-size": 9,
"text-anchor": "middle", "font-family": "ui-monospace, monospace"
});
text.textContent = (min + (max - min) * index / 20).toFixed(decimals);
this.element.append(text);
}
}
this.needle = svgElement("line", {
x1: 160, y1: 150, x2: 160, y2: 55, stroke: "#f1f4e9", "stroke-width": 3,
"stroke-linecap": "round"
});
this.element.append(this.needle, svgElement("circle", { cx: 160, cy: 150, r: 9, fill: "#e9efe1" }));
this.element.append(svgElement("circle", { cx: 160, cy: 150, r: 4, fill: "#314536" }));
const unitText = svgElement("text", {
x: 160, y: 186, fill: "#9da99b", "font-size": 11, "text-anchor": "middle",
"font-family": "ui-monospace, monospace"
});
unitText.textContent = `${unit} · ${label}`;
this.element.append(unitText);
}
setTarget(target, tolerance) {
this.options.target = target;
this.options.tolerance = tolerance;
this.build();
}
update(value) {
const { min, max, unit, sweep } = this.options;
const angle = -sweep / 2 + sweep * (clamp(min, max, value) - min) / (max - min);
this.needle.setAttribute("transform", `rotate(${angle} 160 150)`);
this.element.setAttribute("aria-label", `当前 ${value.toFixed(2)} ${unit}`);
}
}
class TimerScale {
constructor(element, options) {
this.element = element;
this.max = options.max;
this.output = element.querySelector("[data-time]");
this.band = element.querySelector("[data-target-band]");
this.marker = element.querySelector("[data-time-marker]");
this.targetLabel = element.querySelector("[data-target]");
this.element.querySelector("[data-max]").textContent = `${this.max} s`;
this.update(0, false);
}
setTarget(min, max) {
this.band.style.left = `${min / this.max * 100}%`;
this.band.style.width = `${(max - min) / this.max * 100}%`;
this.targetLabel.textContent = `${min}–${max} s`;
this.element.setAttribute("aria-label", `${this.element.dataset.label},目标 ${min} 到 ${max} 秒`);
}
update(value, active) {
this.output.textContent = value.toFixed(1).padStart(4, "0");
this.marker.style.left = `${clamp(0, 100, value / this.max * 100)}%`;
this.element.classList.toggle("active", active);
}
}
class MetricBar {
constructor(element, options) {
this.element = element;
this.max = options.max;
this.fill = element.querySelector("[data-fill]");
this.marker = element.querySelector("[data-marker]");
this.output = element.querySelector("[data-value]");
this.detail = element.querySelector("[data-detail]");
this.targetLabel = element.querySelector("[data-target]");
this.element.setAttribute("role", "meter");
this.element.setAttribute("aria-valuemin", "0");
this.element.setAttribute("aria-valuemax", String(this.max));
}
setTarget(value, label) {
this.marker.style.left = `${clamp(0, 100, value / this.max * 100)}%`;
this.targetLabel.textContent = label;
}
setDetail(text) {
this.detail.textContent = text;
}
update(value, text) {
const percent = clamp(0, 100, value / this.max * 100);
this.fill.style.width = `${percent}%`;
this.output.textContent = text;
this.element.setAttribute("aria-valuenow", String(value));
this.element.setAttribute("aria-valuetext", text);
}
}
window.Lab = { clamp, Gauge, TimerScale, MetricBar };
})();
+241
View File
@@ -0,0 +1,241 @@
:root {
color-scheme: light;
--paper: #f3f0e9;
--card: #fffdf8;
--ink: #252a26;
--muted: #747a72;
--line: #dcded5;
--green: #345c48;
--green-soft: #e4ede3;
--lime: #c8df9c;
--dark: #202923;
--brass: #d8c5a0;
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; min-width: 320px; min-height: 100vh; min-height: 100svh; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button, a, svg[role="slider"] { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }
[hidden] { display: none !important; }
.lab-header {
width: min(1240px, calc(100% - 48px));
min-height: 76px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
border-bottom: 1px solid rgba(52, 92, 72, .14);
}
.lab-brand { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
width: 34px; height: 34px; display: grid; place-items: center;
border-radius: 50% 50% 46% 54%; background: var(--green); color: #fff;
font: 700 11px/1 ui-monospace, monospace; letter-spacing: -.04em;
}
.brand-copy { font-size: 13px; font-weight: 650; letter-spacing: .04em; }
.brand-copy small { margin-left: 8px; color: var(--muted); font-size: 10px; font-weight: 400; }
.module-nav { display: flex; align-items: center; gap: 5px; }
.module-nav a { padding: 8px 13px; border-radius: 8px; color: var(--muted); font-size: 12px; }
.module-nav a:hover, .module-nav a[aria-current="page"] { background: var(--green-soft); color: var(--green); }
.workspace { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 24px 0 48px; }
.instrument-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.instrument-card {
min-width: 0;
padding: 20px;
display: flex;
flex-direction: column;
background: var(--dark);
color: #eef2e8;
border: 1px solid rgba(255, 255, 255, .035);
border-radius: 16px;
box-shadow: 0 10px 30px rgba(40, 47, 39, .055);
overflow: hidden;
}
.instrument-heading { min-height: 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.instrument-heading h2 { margin: 0; color: #dbe5d3; font-size: 12px; font-weight: 550; letter-spacing: .06em; }
.instrument-heading > span { color: #9eac9b; font: 10px ui-monospace, monospace; text-align: right; }
.gauge, .machine-control { display: block; width: 100%; height: auto; }
.instrument-card > .gauge { margin: auto 0; }
.instrument-reading { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-top: -5px; }
.instrument-reading output { font: 500 34px/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: -.07em; }
.instrument-reading span { color: #aebba9; font-size: 11px; }
.machine-control { cursor: grab; touch-action: none; user-select: none; outline: none; }
.machine-control.dragging { cursor: grabbing; }
.control-handle { pointer-events: none; }
.control-readout {
display: flex; justify-content: center; align-items: baseline; gap: 20px;
margin-top: -2px; color: #aebba9; font-size: 11px;
}
.control-readout > span { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.control-readout output { color: #eef2e8; font: 500 15px ui-monospace, monospace; }
.control-readout small { font-size: 9px; }
.control-readout sub { font-size: 8px; }
.recipe-bar {
grid-column: 1 / -1;
min-width: 0;
margin-bottom: 18px;
padding: 12px 14px;
display: flex;
align-items: center;
gap: 18px;
background: rgba(255, 253, 248, .8);
border: 1px solid rgba(71, 85, 71, .12);
border-radius: 12px;
}
.recipe-picker { display: flex; gap: 3px; padding: 3px; background: #e7eae1; border-radius: 8px; }
.recipe-picker button {
min-width: 40px; min-height: 30px; padding: 5px 9px;
border: 0; border-radius: 6px; background: transparent; color: var(--muted);
cursor: pointer; font: 600 11px ui-monospace, monospace;
}
.recipe-picker button[aria-pressed="true"] { background: var(--card); color: var(--green); box-shadow: 0 1px 4px rgba(40, 47, 39, .1); }
.recipe-picker button:disabled { cursor: default; opacity: .55; }
.recipe-targets { display: flex; align-items: center; justify-content: center; flex: 1; flex-wrap: wrap; gap: 9px 22px; }
.recipe-targets > span { display: inline-flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.recipe-targets strong { color: var(--green); font: 600 12px ui-monospace, monospace; }
.session-actions { display: flex; gap: 7px; }
.action-button {
min-height: 36px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
background: transparent; cursor: pointer; font-size: 11px; font-weight: 550; white-space: nowrap;
}
.action-button.primary { background: var(--green); border-color: var(--green); color: #fff; }
.action-button:hover { filter: brightness(.96); }
.action-button:disabled { cursor: default; opacity: .45; }
.timing-card { grid-column: span 2; }
.flow-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.flow-grid .timing-card { grid-column: 1 / -1; }
.single-timer { grid-template-columns: minmax(0, 1fr); }
.dual-timers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.timer-block { min-width: 0; padding: 15px; border: 1px solid rgba(255, 255, 255, .1); border-radius: 11px; }
.timer-block.active { border-color: var(--lime); background: rgba(200, 223, 156, .06); }
.timer-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.timer-heading > span { color: #dbe5d3; font-size: 11px; }
.timer-heading small { color: #9eac9b; font-size: 9px; }
.timer-value { display: flex; align-items: baseline; gap: 7px; margin: 13px 0 18px; }
.timer-value output { font: 500 36px/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: -.07em; font-variant-numeric: tabular-nums; }
.timer-value > span { color: #9eac9b; font-size: 11px; }
.timer-track { height: 6px; position: relative; background: rgba(255, 255, 255, .12); border-radius: 4px; }
.timer-target-band { position: absolute; top: 0; bottom: 0; background: #a9c48f; border-radius: 3px; }
.timer-target-band::before, .timer-target-band::after {
content: ""; position: absolute; top: -3px; bottom: -3px; width: 1px; background: #d5e8c1;
}
.timer-target-band::before { left: 0; }
.timer-target-band::after { right: 0; }
.timer-marker { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 2px; background: #f4f4e9; }
.timer-labels { display: flex; align-items: center; justify-content: space-between; gap: 4px; margin-top: 9px; color: #9eac9b; font: 9px ui-monospace, monospace; }
.timer-labels [data-target] { color: #c3d8b1; }
.process-note { min-height: 28px; color: #9eac9b; font-size: 10px; line-height: 1.5; }
.extraction-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.metric-block { min-width: 0; padding: 13px; border: 1px solid rgba(255, 255, 255, .1); border-radius: 11px; }
.metric-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: #bac7b5; font-size: 10px; }
.metric-heading output { color: #eef2e8; font: 500 20px ui-monospace, monospace; }
.metric-track { height: 7px; position: relative; margin-top: 14px; background: rgba(255, 255, 255, .12); border-radius: 5px; }
.metric-track [data-fill] { display: block; width: 0; height: 100%; background: var(--lime); border-radius: inherit; }
.metric-track [data-marker] { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--brass); }
.metric-detail { display: flex; justify-content: space-between; gap: 6px; margin-top: 8px; color: #9eac9b; font: 9px ui-monospace, monospace; }
.metric-detail [data-target] { color: #c3d8b1; text-align: right; }
.score-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-top: 14px; padding-top: 13px; border-top: 1px solid rgba(255, 255, 255, .1); color: #bac7b5; font-size: 11px; }
.score-line output { color: var(--lime); font: 500 28px ui-monospace, monospace; }
.liquid-status { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: auto; }
.liquid-label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; color: #9eac9b; font-size: 10px; }
.liquid-label output { color: #dbe5d3; font: 10px ui-monospace, monospace; white-space: nowrap; }
.total-time { margin-top: 14px; }
.meter { height: 5px; background: rgba(255, 255, 255, .12); border-radius: 4px; overflow: hidden; }
.meter > span { display: block; width: 0; height: 100%; background: var(--lime); border-radius: inherit; }
.meter.output > span { background: var(--brass); }
.instrument-feedback { min-height: 17px; margin: 16px 0 0; color: #bac7b5; font-size: 11px; line-height: 1.5; }
.review-details { margin-top: 12px; border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 10px; }
.review-details summary { color: #bac7b5; cursor: pointer; font-size: 10px; }
.review-scores { display: flex; justify-content: space-between; gap: 12px; margin-top: 13px; }
.review-scores > span { color: #9eac9b; font-size: 10px; }
.review-scores output { margin-left: 6px; color: #e4eddc; font: 500 14px ui-monospace, monospace; }
.temperature-workspace { width: min(1240px, calc(100% - 48px)); }
.comparison-lab { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.comparison-group { min-width: 0; }
.comparison-group > h1 { display: flex; align-items: baseline; justify-content: center; gap: 10px; margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.comparison-group > h1 small { color: var(--muted); font-size: 10px; font-weight: 400; }
.comparison-instruments { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.overview { display: grid; align-content: center; min-height: calc(100svh - 124px); }
.overview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.module-card {
min-width: 0; padding: 22px; background: var(--card); border: 1px solid rgba(71, 85, 71, .12);
border-radius: 16px; box-shadow: 0 10px 30px rgba(40, 47, 39, .04);
transition: border-color .15s, transform .15s;
}
.module-card:hover { border-color: #9bab97; transform: translateY(-2px); }
.module-number { color: var(--green); font: 600 10px ui-monospace, monospace; letter-spacing: .12em; }
.module-visual { height: 176px; margin: 18px 0 20px; display: grid; place-items: center; background: var(--dark); border-radius: 11px; }
.module-visual svg { display: block; width: 100%; max-width: 250px; height: 150px; }
.module-card h1, .module-card h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.module-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.module-link { display: flex; align-items: center; justify-content: space-between; margin-top: 22px; color: var(--green); font-size: 11px; font-weight: 600; }
.module-link > span { font-size: 18px; font-weight: 400; }
button:focus-visible, a:focus-visible, summary:focus-visible, svg[role="slider"]:focus-visible {
outline: 3px solid rgba(155, 125, 73, .6); outline-offset: 4px;
}
svg[role="slider"]:focus-visible { border-radius: 10px; }
@media (max-width: 1100px) {
.comparison-lab { grid-template-columns: minmax(0, 720px); justify-content: center; }
.instrument-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.flow-grid .timing-card { grid-column: span 2; }
.overview-grid { gap: 14px; }
.module-card { padding: 18px; }
}
@media (max-width: 760px) {
.recipe-bar { flex-wrap: wrap; gap: 12px; }
.recipe-targets { order: 3; flex-basis: 100%; justify-content: flex-start; padding: 0 3px 3px; }
.session-actions { margin-left: auto; }
.overview-grid { grid-template-columns: 1fr; max-width: 420px; width: 100%; margin: 0 auto; }
.overview { min-height: auto; }
.module-visual { height: 145px; }
.module-visual svg { height: 130px; }
}
@media (max-width: 620px) {
.lab-header, .workspace, .temperature-workspace { width: calc(100% - 28px); }
.lab-header { min-height: 68px; gap: 8px; }
.brand-copy small { display: none; }
.module-nav { gap: 2px; }
.module-nav a { padding: 7px 9px; font-size: 11px; }
.workspace { padding-top: 18px; }
.instrument-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
.instrument-grid .timing-card, .flow-grid .timing-card { grid-column: auto; }
.instrument-card { padding: 16px; }
.comparison-lab { gap: 24px; }
.comparison-instruments { gap: 10px; }
.comparison-instruments .instrument-card { padding: 12px; }
.comparison-group > h1 { font-size: 16px; }
.comparison-group > h1 small { font-size: 9px; }
.comparison-instruments .instrument-heading > span { display: none; }
.comparison-instruments .instrument-heading h2 { font-size: 10px; }
.comparison-instruments .control-readout { flex-direction: column; align-items: center; gap: 4px; font-size: 9px; }
.comparison-instruments .control-readout output { font-size: 12px; }
.dual-timers { gap: 10px; }
.timer-block { padding: 12px; }
.timer-value output { font-size: 30px; }
.timer-heading small { font-size: 8px; }
.liquid-status { gap: 12px; }
}
@media (max-width: 390px) {
.brand-copy { display: none; }
.dual-timers { grid-template-columns: 1fr; }
.extraction-metrics { grid-template-columns: 1fr; }
.liquid-status { grid-template-columns: 1fr; }
.session-actions .action-button { padding: 8px 9px; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { transition: none !important; }
}
+272
View File
@@ -0,0 +1,272 @@
(() => {
const clamp = (min, max, value) => Math.min(max, Math.max(min, value));
const defaults = Object.freeze({
maxHotFlow: 0.225,
coldFlow: 0.0147,
coldTemp: 20,
hotTemp: 100,
hotValveExponent: 6,
sensorTimeConstant: 2,
maxFlow: 30,
saturation: 60
});
const recipes = Object.freeze({
B1: Object.freeze({
targetTemp: 92, tempTolerance: 1, tempErrorWeight: 12,
preMin: 6, preMax: 9, timeErrorWeight: 10,
essenceCapacity: 10, referenceVolume: 300, minEssenceRatio: 1, essencePerMl: 1 / 30
}),
B2: Object.freeze({
targetTemp: 93, tempTolerance: 1, tempErrorWeight: 12,
preMin: 3, preMax: 5, timeErrorWeight: 10,
essenceCapacity: 12, referenceVolume: 360, minEssenceRatio: 1, essencePerMl: 1 / 30
})
});
function hotFlow(machine, valve) {
return machine.maxHotFlow * clamp(0, 1, valve) ** machine.hotValveExponent;
}
function temperature(machine, valve) {
const qh = hotFlow(machine, valve);
return (machine.hotTemp * qh + machine.coldTemp * machine.coldFlow) / (qh + machine.coldFlow);
}
function probeStep(machine, current, valve, dt) {
if (dt <= 0) return current;
const actual = temperature(machine, valve);
return actual + (current - actual) * Math.exp(-dt / machine.sensorTimeConstant);
}
function temperatureSensitivity(machine, valve) {
const u = clamp(0, 1, valve);
const n = machine.hotValveExponent;
const ratio = machine.maxHotFlow / machine.coldFlow;
return (machine.hotTemp - machine.coldTemp) * ratio * n * u ** (n - 1) / (1 + ratio * u ** n) ** 2;
}
function peakValve(machine) {
const n = machine.hotValveExponent;
const ratio = machine.maxHotFlow / machine.coldFlow;
return clamp(0, 1, ((n - 1) / ((n + 1) * ratio)) ** (1 / n));
}
function flow(machine, lever) {
return machine.maxFlow * clamp(0, 1, lever);
}
function idealValve(machine, target) {
if (target <= machine.coldTemp) return 0;
if (target >= machine.hotTemp) return null;
const requiredRatio = (target - machine.coldTemp) / (machine.hotTemp - target);
const valve = (machine.coldFlow * requiredRatio / machine.maxHotFlow) ** (1 / machine.hotValveExponent);
return valve <= 1 ? valve : null;
}
function instantTemperatureScore(value, recipe) {
return clamp(0, 100, 100 - recipe.tempErrorWeight * Math.abs(value - recipe.targetTemp));
}
function temperatureScore(samples, recipe) {
if (!samples.length) return null;
const scores = samples.map(sample => Number.isFinite(sample.score)
? sample.score
: instantTemperatureScore(sample.temperature, recipe));
const average = scores.reduce((sum, score) => sum + score, 0) / scores.length;
const worst = Math.min(...scores);
return { average, worst, score: 0.8 * average + 0.2 * worst };
}
function timingDeviation(time, min, max) {
if (time < min) return time - min;
if (time > max) return time - max;
return 0;
}
function timingScore(time, min, max, weight) {
return clamp(0, 100, 100 - weight * Math.abs(timingDeviation(time, min, max)));
}
function essenceRate(machine, recipe, preTime, hotValve) {
const temperatureFactor = clamp(0.5, 1.25, 1 + 0.04 * (temperature(machine, hotValve) - recipe.targetTemp));
const preFactor = preTime === null ? 1 : clamp(0.6, 1, 1 - 0.08 * Math.abs(timingDeviation(preTime, recipe.preMin, recipe.preMax)));
return recipe.essencePerMl * temperatureFactor * preFactor;
}
class BrewSession {
constructor(machine, recipe, initialSensorTemperature = null) {
this.machine = { ...machine };
this.recipe = { ...recipe };
this.phase = "empty";
this.elapsed = 0;
this.contactTime = null;
this.saturationTime = null;
this.endTime = null;
this.waterIn = 0;
this.preTime = null;
this.extractionTime = 0;
this.essenceCollected = 0;
this.volume = 0;
this.samples = [];
this.sensorSamples = [];
this.sensorTemperature = initialSensorTemperature ?? temperature(this.machine, 0);
this.currentLever = 0;
this.currentHotValve = 0;
this.currentFlow = 0;
this.finalScore = null;
}
load() {
if (this.phase !== "empty") return;
this.phase = "ready";
}
sample(hotValve) {
const value = temperature(this.machine, hotValve);
this.samples.push({
time: this.elapsed,
phase: this.phase,
hotValve: clamp(0, 1, hotValve),
hotFlow: hotFlow(this.machine, hotValve),
temperature: value,
score: instantTemperatureScore(value, this.recipe),
lever: this.currentLever,
flow: this.currentFlow,
essenceCollected: this.essenceCollected,
beverageVolume: this.volume
});
this.sensorSamples.push({ time: this.elapsed, temperature: this.sensorTemperature });
}
essenceRatio() {
return this.recipe.essenceCapacity > 0 ? clamp(0, 1, this.essenceCollected / this.recipe.essenceCapacity) : 0;
}
concentration() {
return this.volume > 0 ? this.essenceRatio() * this.recipe.referenceVolume / this.volume : 0;
}
concentrationScore() {
const concentration = this.concentration();
return concentration > 0 ? Math.min(concentration, 1 / concentration) : 0;
}
collectionGate() {
return Math.min(1, this.essenceRatio() / this.recipe.minEssenceRatio);
}
extractionScore() {
return 100 * this.collectionGate() * this.concentrationScore();
}
collectEssence(q, hotValve, dt) {
if (q <= 0 || dt <= 0) return;
this.essenceCollected = Math.min(
this.recipe.essenceCapacity,
this.essenceCollected + q * essenceRate(this.machine, this.recipe, this.preTime, hotValve) * dt
);
}
step(lever, hotValve, dt) {
if (dt <= 0 || !["ready", "preinfusion", "extraction"].includes(this.phase)) return;
this.currentLever = clamp(0, 1, lever);
this.currentHotValve = clamp(0, 1, hotValve);
this.currentFlow = flow(this.machine, this.currentLever);
const q = this.currentFlow;
if (this.phase === "ready") {
if (q === 0) {
this.sensorTemperature = probeStep(this.machine, this.sensorTemperature, hotValve, dt);
return;
}
this.phase = "preinfusion";
this.contactTime = 0;
this.sample(hotValve);
}
this.sensorTemperature = probeStep(this.machine, this.sensorTemperature, hotValve, dt);
if (this.phase === "preinfusion") {
const untilSaturated = q > 0 ? (this.machine.saturation - this.waterIn) / q : Infinity;
const step = Math.min(dt, Math.max(0, untilSaturated));
if (q > 0) this.waterIn = Math.min(this.machine.saturation, this.waterIn + q * step);
if (this.waterIn >= this.machine.saturation) {
this.preTime = this.elapsed + step;
this.saturationTime = this.preTime;
this.phase = "extraction";
const remaining = dt - step;
if (q > 0 && remaining > 0) {
this.extractionTime += remaining;
this.volume += q * remaining;
this.collectEssence(q, hotValve, remaining);
}
}
this.elapsed += dt;
this.sample(hotValve);
return;
}
this.elapsed += dt;
if (q > 0) {
this.extractionTime += dt;
this.volume += q * dt;
this.collectEssence(q, hotValve, dt);
}
this.sample(hotValve);
}
removeHandle(lever = this.currentLever) {
this.currentLever = clamp(0, 1, lever);
this.currentFlow = flow(this.machine, this.currentLever);
const q = this.currentFlow;
if (["ready", "preinfusion"].includes(this.phase)) {
this.phase = "aborted";
this.endTime = this.elapsed;
return this.phase;
}
if (this.phase !== "extraction") return this.phase;
if (q > 0) return "running";
this.phase = "complete";
this.endTime = this.elapsed;
this.sample(this.currentHotValve);
this.finalScore = {
ratio: this.essenceRatio(),
concentration: this.concentration(),
concentrationScore: this.concentrationScore(),
gate: this.collectionGate(),
score: this.extractionScore()
};
return this.phase;
}
scores() {
const temp = temperatureScore(this.samples, this.recipe);
const extraction = this.finalScore || {
ratio: this.essenceRatio(),
concentration: this.concentration(),
concentrationScore: this.concentrationScore(),
gate: this.collectionGate(),
score: this.extractionScore()
};
return {
temperature: temp ? temp.score : null,
averageTemperature: temp ? temp.average : null,
worstTemperature: temp ? temp.worst : null,
preinfusion: this.preTime === null ? null : timingScore(this.preTime, this.recipe.preMin, this.recipe.preMax, this.recipe.timeErrorWeight),
extraction: extraction.score,
essenceRatio: extraction.ratio,
concentration: extraction.concentration,
concentrationScore: extraction.concentrationScore,
collectionGate: extraction.gate,
essenceCollected: this.essenceCollected,
referenceVolume: this.recipe.referenceVolume
};
}
}
window.CoffeeMachine = {
clamp, defaults, recipes, hotFlow, temperature, probeStep, temperatureSensitivity,
peakValve, flow, idealValve, instantTemperatureScore, temperatureScore,
timingDeviation, timingScore, essenceRate, BrewSession
};
})();
+48
View File
@@ -0,0 +1,48 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>精华与浓度 · 咖啡机手感实验</title>
<link rel="stylesheet" href="../assets/lab.css?v=20261107-2">
<script src="../assets/instruments.js?v=20261107-2" defer></script>
<script src="../assets/machine.js?v=20261107-2" defer></script>
<script src="../assets/controls.js?v=20261107-2" defer></script>
<script src="page.js?v=20261107-2" defer></script>
</head>
<body>
<header class="lab-header">
<a class="lab-brand" href="../?v=20261107-2"><span class="brand-mark">PC</span><span class="brand-copy">咖啡机<small>手感实验</small></span></a>
<nav class="module-nav" aria-label="测试模块"><a href="../temperature/?v=20261107-2">01 水温</a><a href="../flow/?v=20261107-2">02 水流</a><a href="./?v=20261107-2" aria-current="page">03 萃取</a></nav>
</header>
<main class="workspace">
<section class="recipe-bar" aria-label="配方与制杯操作">
<div class="recipe-picker" role="group" aria-label="配方"><button type="button" data-recipe="B1" aria-pressed="true">B1</button><button type="button" data-recipe="B2" aria-pressed="false">B2</button></div>
<div class="recipe-targets"><span>水温 T <strong id="tempTarget">92 ± 1°C</strong></span><span>预浸泡 I <strong id="preTarget">6–9 s</strong></span><span>精华 <strong id="essenceRequirement">≥100%</strong></span><span>参考量 <strong id="referenceVolumeTarget">300 mL</strong></span><span>浓度目标 <strong id="concentrationGoal">1.00×</strong></span></div>
<div class="session-actions"><button class="action-button primary" id="loadButton" type="button">装粉并锁定</button><button class="action-button" id="handleButton" type="button" disabled>取下手柄</button><button class="action-button" id="resetButton" type="button">复位</button></div>
</section>
<div class="instrument-grid extraction-grid">
<section class="instrument-card"><div class="instrument-heading"><h2>出水口温度</h2><span>T_s · 2 s</span></div><svg id="temperatureGauge"></svg></section>
<section class="instrument-card"><div class="instrument-heading"><h2>沸水阀</h2><span>100°C</span></div><svg id="hotValve"></svg><div class="control-readout"><span>开度 <output id="hotValveValue">60%</output></span><span>q<sub>h</sub> <output id="hotFlowValue">0.010</output><small>mL/s</small></span></div></section>
<section class="instrument-card"><div class="instrument-heading"><h2>萃取水流</h2><span>q</span></div><svg id="flowGauge"></svg><div class="instrument-reading"><output id="flowValue">0.00</output><span>mL/s</span></div></section>
<section class="instrument-card"><div class="instrument-heading"><h2>水流拨杆</h2><span>连续开度</span></div><svg id="flowLever"></svg><div class="control-readout"><span>开度 <output id="flowLeverValue">0%</output></span><span>q <output id="waterFlowValue">0.00</output><small>mL/s</small></span></div></section>
<section class="instrument-card timing-card">
<div class="instrument-heading"><h2>双阶段与萃取得分</h2><span id="sessionStatus">待装粉</span></div>
<div class="dual-timers">
<div class="timer-block" id="preTimer" data-label="预浸泡"><div class="timer-heading"><span>预浸泡 I</span><small>首次接触水开始</small></div><div class="timer-value"><output data-time>00.0</output><span>s</span></div><div class="timer-track"><span class="timer-target-band" data-target-band></span><span class="timer-marker" data-time-marker></span></div><div class="timer-labels"><span>0</span><span data-target>6–9 s</span><span data-max>12 s</span></div></div>
<div class="timer-block"><div class="timer-heading"><span>萃取进水</span><small>过程数据 · 不直接评分</small></div><div class="timer-value"><output id="processTime">00.0</output><span>s</span></div><div class="process-note">只记录实际进水时间</div></div>
</div>
<div class="extraction-metrics">
<div class="metric-block" id="essenceMetric"><div class="metric-heading"><span>精华收集 R</span><output data-value>0%</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>0.0 / 10</span><span data-target>≥100%</span></div></div>
<div class="metric-block" id="concentrationMetric"><div class="metric-heading"><span>相对浓度 C</span><output data-value>0.00×</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>等待出液</span><span data-target>目标 1.00×</span></div></div>
</div>
<div class="liquid-status"><div class="liquid-meter"><div class="liquid-label"><span>粉饼吸水</span><output id="saturationValue">0.0 / 60 mL</output></div><div class="meter"><span id="saturationMeter"></span></div></div><div class="liquid-meter"><div class="liquid-label"><span>饮料量</span><output id="volumeValue">0.0 mL</output></div><div class="meter output"><span id="volumeMeter"></span></div></div></div>
<div class="liquid-label total-time"><span>总冲泡时间(含关水间隙)</span><output id="totalTime">0.0 s</output></div>
<div class="score-line"><span>萃取得分 E</span><output id="extractionScore">0.0</output></div>
<p class="instrument-feedback" id="sessionFeedback" role="status">装粉后,推杆开始进水</p>
<details class="review-details" id="reviewDetails" hidden><summary>查看 T / I / E 分项</summary><div class="review-scores"><span>T<output id="temperatureScore">—</output></span><span>I<output id="preinfusionScore">—</output></span><span>E<output id="reviewExtractionScore">—</output></span></div></details>
</section>
</div>
</main>
</body>
</html>
+173
View File
@@ -0,0 +1,173 @@
(() => {
const { Gauge, TimerScale, MetricBar, clamp } = window.Lab;
const { RotaryValve, FlowLever } = window.MachineControls;
const M = window.CoffeeMachine;
const byId = id => document.getElementById(id);
const machine = { ...M.defaults };
const temperatureGauge = new Gauge(byId("temperatureGauge"), {
min: 0, max: 100, target: M.recipes.B1.targetTemp,
tolerance: M.recipes.B1.tempTolerance, unit: "°C", label: "T_s"
});
const flowGauge = new Gauge(byId("flowGauge"), { min: 0, max: machine.maxFlow, unit: "mL/s", label: "q" });
const preTimer = new TimerScale(byId("preTimer"), { max: 12 });
const essenceMetric = new MetricBar(byId("essenceMetric"), { max: 100 });
const concentrationMetric = new MetricBar(byId("concentrationMetric"), { max: 2 });
let recipeName = "B1";
let session = null;
let sensorTemperature = M.temperature(machine, 0.6);
let accumulator = 0;
let previousFrame = performance.now();
const fixedStep = 1 / 120;
const hotValve = new RotaryValve(byId("hotValve"), {
value: 0.6,
label: "沸水阀 · 只调节混水温度",
onChange: readout
});
const flowLever = new FlowLever(byId("flowLever"), {
value: 0,
label: "萃取水流拨杆 · 精华收集与相对浓度",
onChange: readout
});
const isActive = () => Boolean(session && ["ready", "preinfusion", "extraction"].includes(session.phase));
const activeRecipe = () => session ? session.recipe : M.recipes[recipeName];
function configureRecipe() {
const recipe = activeRecipe();
document.querySelectorAll("[data-recipe]").forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.recipe === recipeName));
button.disabled = isActive();
});
byId("tempTarget").textContent = `${recipe.targetTemp} ± ${recipe.tempTolerance}°C`;
byId("preTarget").textContent = `${recipe.preMin}–${recipe.preMax} s`;
byId("essenceRequirement").textContent = `≥${Math.round(recipe.minEssenceRatio * 100)}%`;
byId("referenceVolumeTarget").textContent = `${recipe.referenceVolume} mL`;
byId("concentrationGoal").textContent = "1.00×";
temperatureGauge.setTarget(recipe.targetTemp, recipe.tempTolerance);
preTimer.setTarget(recipe.preMin, recipe.preMax);
essenceMetric.setTarget(recipe.minEssenceRatio * 100, `≥${Math.round(recipe.minEssenceRatio * 100)}%`);
concentrationMetric.setTarget(1, "目标 1.00×");
}
function readout() {
const phase = session ? session.phase : "empty";
const recipe = activeRecipe();
const q = M.flow(machine, flowLever.value);
const waterIn = session ? session.waterIn : 0;
const volume = session ? session.volume : 0;
const scores = session ? session.scores() : null;
const ratio = scores ? scores.essenceRatio : 0;
const concentration = scores ? scores.concentration : 0;
temperatureGauge.update(sensorTemperature);
flowGauge.update(q);
byId("hotValveValue").textContent = `${Math.round(hotValve.value * 100)}%`;
byId("hotFlowValue").textContent = M.hotFlow(machine, hotValve.value).toFixed(3);
byId("flowValue").textContent = q.toFixed(2);
byId("flowLeverValue").textContent = `${Math.round(flowLever.value * 100)}%`;
byId("waterFlowValue").textContent = q.toFixed(2);
preTimer.update(session ? session.preTime ?? session.elapsed : 0, phase === "preinfusion");
byId("processTime").textContent = (session ? session.extractionTime : 0).toFixed(1).padStart(4, "0");
essenceMetric.update(ratio * 100, `${Math.round(ratio * 100)}%`);
essenceMetric.setDetail(`${(session ? session.essenceCollected : 0).toFixed(1)} / ${recipe.essenceCapacity}`);
concentrationMetric.update(concentration, `${concentration.toFixed(2)}×`);
concentrationMetric.setDetail(volume > 0 ? `${volume.toFixed(1)} mL` : "等待出液");
byId("saturationValue").textContent = `${waterIn.toFixed(1)} / ${machine.saturation} mL`;
byId("saturationMeter").style.width = `${clamp(0, 100, waterIn / machine.saturation * 100)}%`;
byId("volumeValue").textContent = `${volume.toFixed(1)} mL`;
byId("volumeMeter").style.width = `${clamp(0, 100, volume / (recipe.referenceVolume * 1.5) * 100)}%`;
byId("totalTime").textContent = `${(session ? session.elapsed : 0).toFixed(1)} s`;
byId("extractionScore").textContent = scores ? scores.extraction.toFixed(1) : "0.0";
document.querySelectorAll("[data-recipe]").forEach(button => { button.disabled = isActive(); });
const status = {
empty: "待装粉", ready: "等待进水",
preinfusion: q > 0 ? "预浸泡" : "I继续 · 关水",
extraction: q > 0 ? "萃取进水" : "萃取暂停",
complete: "本杯完成", aborted: "已放弃"
};
byId("sessionStatus").textContent = status[phase];
byId("loadButton").disabled = isActive();
byId("loadButton").textContent = ["complete", "aborted"].includes(phase) ? "再做一杯" : "装粉并锁定";
byId("handleButton").disabled = !session || !["preinfusion", "extraction"].includes(phase) || (phase === "extraction" && q > 0);
byId("handleButton").textContent = phase === "extraction" && q > 0 ? "先关水" : phase === "complete" ? "已取手柄" : "取下手柄";
const feedback = {
empty: "装粉后,推杆开始进水",
ready: "手柄已锁定 · 等待进水",
preinfusion: q > 0 ? "粉饼吸水中 · I继续" : "停止吸水 · I继续",
extraction: q > 0 ? "精华收集中 · 关注相对浓度" : "暂停进水 · 精华与出液暂停;取手柄结束",
aborted: "粉饼未饱和 · 取手柄放弃本杯"
};
byId("reviewDetails").hidden = phase !== "complete";
if (phase === "complete") {
const entries = [
{ label: "水温", key: "T", score: scores.temperature },
{ label: "预浸泡", key: "I", score: scores.preinfusion },
{ label: "精华与浓度", key: "E", score: scores.extraction }
];
const focus = entries.reduce((worst, entry) => entry.score < worst.score ? entry : worst);
byId("sessionFeedback").textContent = `本杯完成 · 重点关注 ${focus.label} ${focus.key} ${focus.score.toFixed(1)}`;
byId("temperatureScore").textContent = scores.temperature.toFixed(1);
byId("preinfusionScore").textContent = scores.preinfusion.toFixed(1);
byId("reviewExtractionScore").textContent = scores.extraction.toFixed(1);
} else {
byId("sessionFeedback").textContent = feedback[phase];
}
}
function loadSession() {
session = new M.BrewSession(machine, M.recipes[recipeName], sensorTemperature);
session.load();
flowLever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
function resetSession() {
session = null;
flowLever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
document.querySelectorAll("[data-recipe]").forEach(button => {
button.addEventListener("click", () => {
if (isActive()) return;
recipeName = button.dataset.recipe;
session = null;
configureRecipe();
readout();
});
});
byId("loadButton").addEventListener("click", loadSession);
byId("handleButton").addEventListener("click", () => {
if (!session) return;
session.removeHandle(flowLever.value);
readout();
});
byId("resetButton").addEventListener("click", resetSession);
function frame(now) {
const frameTime = Math.min(0.1, Math.max(0, (now - previousFrame) / 1000));
previousFrame = now;
if (isActive()) {
accumulator += frameTime;
while (accumulator >= fixedStep && isActive()) {
session.step(flowLever.value, hotValve.value, fixedStep);
accumulator -= fixedStep;
}
sensorTemperature = session.sensorTemperature;
} else {
sensorTemperature = M.probeStep(machine, sensorTemperature, hotValve.value, frameTime);
}
readout();
requestAnimationFrame(frame);
}
document.addEventListener("visibilitychange", () => { previousFrame = performance.now(); });
configureRecipe();
readout();
requestAnimationFrame(frame);
})();
+45
View File
@@ -0,0 +1,45 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>精华与浓度 · 咖啡机手感实验</title>
<link rel="stylesheet" href="../assets/lab.css?v=20261107-2">
<script src="../assets/instruments.js?v=20261107-2" defer></script>
<script src="../assets/machine.js?v=20261107-2" defer></script>
<script src="../assets/controls.js?v=20261107-2" defer></script>
<script src="page.js?v=20261107-2" defer></script>
</head>
<body>
<header class="lab-header">
<a class="lab-brand" href="../?v=20261107-2"><span class="brand-mark">PC</span><span class="brand-copy">咖啡机<small>手感实验</small></span></a>
<nav class="module-nav" aria-label="测试模块"><a href="../temperature/?v=20261107-2">01 水温</a><a href="./?v=20261107-2" aria-current="page">02 水流</a><a href="../extraction/?v=20261107-2">03 萃取</a></nav>
</header>
<main class="workspace">
<section class="recipe-bar" aria-label="配方与制杯操作">
<div class="recipe-picker" role="group" aria-label="配方"><button type="button" data-recipe="B1" aria-pressed="true">B1</button><button type="button" data-recipe="B2" aria-pressed="false">B2</button></div>
<div class="recipe-targets"><span>预浸泡 I <strong id="preTarget">6–9 s</strong></span><span>精华 <strong id="essenceRequirement">≥100%</strong></span><span>参考量 <strong id="referenceVolumeTarget">300 mL</strong></span><span>浓度目标 <strong id="concentrationGoal">1.00×</strong></span></div>
<div class="session-actions"><button class="action-button primary" id="loadButton" type="button">装粉并锁定</button><button class="action-button" id="handleButton" type="button" disabled>取下手柄</button><button class="action-button" id="resetButton" type="button">复位</button></div>
</section>
<div class="instrument-grid flow-grid">
<section class="instrument-card"><div class="instrument-heading"><h2>萃取水流</h2><span>q</span></div><svg id="flowGauge"></svg><div class="instrument-reading"><output id="flowValue">0.00</output><span>mL/s</span></div></section>
<section class="instrument-card"><div class="instrument-heading"><h2>水流拨杆</h2><span>连续开度</span></div><svg id="flowLever"></svg><div class="control-readout"><span>开度 <output id="flowLeverValue">0%</output></span><span>q <output id="waterFlowValue">0.00</output><small>mL/s</small></span></div></section>
<section class="instrument-card timing-card">
<div class="instrument-heading"><h2>双阶段与萃取得分</h2><span id="sessionStatus">待装粉</span></div>
<div class="dual-timers">
<div class="timer-block" id="preTimer" data-label="预浸泡"><div class="timer-heading"><span>预浸泡 I</span><small>首次接触水开始</small></div><div class="timer-value"><output data-time>00.0</output><span>s</span></div><div class="timer-track"><span class="timer-target-band" data-target-band></span><span class="timer-marker" data-time-marker></span></div><div class="timer-labels"><span>0</span><span data-target>6–9 s</span><span data-max>12 s</span></div></div>
<div class="timer-block"><div class="timer-heading"><span>萃取进水</span><small>过程数据 · 不直接评分</small></div><div class="timer-value"><output id="processTime">00.0</output><span>s</span></div><div class="process-note">只记录实际进水时间</div></div>
</div>
<div class="extraction-metrics">
<div class="metric-block" id="essenceMetric"><div class="metric-heading"><span>精华收集 R</span><output data-value>0%</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>0.0 / 10</span><span data-target>≥100%</span></div></div>
<div class="metric-block" id="concentrationMetric"><div class="metric-heading"><span>相对浓度 C</span><output data-value>0.00×</output></div><div class="metric-track"><span data-fill></span><i data-marker></i></div><div class="metric-detail"><span data-detail>等待出液</span><span data-target>目标 1.00×</span></div></div>
</div>
<div class="liquid-status"><div class="liquid-meter"><div class="liquid-label"><span>粉饼吸水</span><output id="saturationValue">0.0 / 60 mL</output></div><div class="meter"><span id="saturationMeter"></span></div></div><div class="liquid-meter"><div class="liquid-label"><span>饮料量</span><output id="volumeValue">0.0 mL</output></div><div class="meter output"><span id="volumeMeter"></span></div></div></div>
<div class="liquid-label total-time"><span>总冲泡时间(含关水间隙)</span><output id="totalTime">0.0 s</output></div>
<div class="score-line"><span>萃取得分 E</span><output id="extractionScore">0.0</output></div>
<p class="instrument-feedback" id="sessionFeedback" role="status">装粉后,推杆开始进水</p><p class="instrument-feedback" id="scoreFeedback" hidden></p>
</section>
</div>
</main>
</body>
</html>
+148
View File
@@ -0,0 +1,148 @@
(() => {
const { Gauge, TimerScale, MetricBar, clamp } = window.Lab;
const { FlowLever } = window.MachineControls;
const M = window.CoffeeMachine;
const byId = id => document.getElementById(id);
const machine = { ...M.defaults };
const gauge = new Gauge(byId("flowGauge"), { min: 0, max: machine.maxFlow, unit: "mL/s", label: "q" });
const preTimer = new TimerScale(byId("preTimer"), { max: 12 });
const essenceMetric = new MetricBar(byId("essenceMetric"), { max: 100 });
const concentrationMetric = new MetricBar(byId("concentrationMetric"), { max: 2 });
let recipeName = "B1";
let session = null;
let accumulator = 0;
let previousFrame = performance.now();
const fixedStep = 1 / 120;
const lever = new FlowLever(byId("flowLever"), {
value: 0,
label: "萃取水流拨杆 · 精华收集与相对浓度",
onChange: readout
});
const isActive = () => Boolean(session && ["ready", "preinfusion", "extraction"].includes(session.phase));
const activeRecipe = () => session ? session.recipe : M.recipes[recipeName];
const referenceValve = () => M.idealValve(machine, activeRecipe().targetTemp);
function configureRecipe() {
const recipe = activeRecipe();
document.querySelectorAll("[data-recipe]").forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.recipe === recipeName));
button.disabled = isActive();
});
byId("preTarget").textContent = `${recipe.preMin}–${recipe.preMax} s`;
byId("essenceRequirement").textContent = `≥${Math.round(recipe.minEssenceRatio * 100)}%`;
byId("referenceVolumeTarget").textContent = `${recipe.referenceVolume} mL`;
byId("concentrationGoal").textContent = "1.00×";
preTimer.setTarget(recipe.preMin, recipe.preMax);
essenceMetric.setTarget(recipe.minEssenceRatio * 100, `≥${Math.round(recipe.minEssenceRatio * 100)}%`);
concentrationMetric.setTarget(1, "目标 1.00×");
}
function readout() {
const phase = session ? session.phase : "empty";
const recipe = activeRecipe();
const q = M.flow(machine, lever.value);
const waterIn = session ? session.waterIn : 0;
const volume = session ? session.volume : 0;
const scores = session ? session.scores() : null;
const ratio = scores ? scores.essenceRatio : 0;
const concentration = scores ? scores.concentration : 0;
gauge.update(q);
byId("flowValue").textContent = q.toFixed(2);
byId("flowLeverValue").textContent = `${Math.round(lever.value * 100)}%`;
byId("waterFlowValue").textContent = q.toFixed(2);
preTimer.update(session ? session.preTime ?? session.elapsed : 0, phase === "preinfusion");
byId("processTime").textContent = (session ? session.extractionTime : 0).toFixed(1).padStart(4, "0");
essenceMetric.update(ratio * 100, `${Math.round(ratio * 100)}%`);
essenceMetric.setDetail(`${(session ? session.essenceCollected : 0).toFixed(1)} / ${recipe.essenceCapacity}`);
concentrationMetric.update(concentration, `${concentration.toFixed(2)}×`);
concentrationMetric.setDetail(volume > 0 ? `${volume.toFixed(1)} mL` : "等待出液");
byId("saturationValue").textContent = `${waterIn.toFixed(1)} / ${machine.saturation} mL`;
byId("saturationMeter").style.width = `${clamp(0, 100, waterIn / machine.saturation * 100)}%`;
byId("volumeValue").textContent = `${volume.toFixed(1)} mL`;
byId("volumeMeter").style.width = `${clamp(0, 100, volume / (recipe.referenceVolume * 1.5) * 100)}%`;
byId("totalTime").textContent = `${(session ? session.elapsed : 0).toFixed(1)} s`;
byId("extractionScore").textContent = scores ? scores.extraction.toFixed(1) : "0.0";
document.querySelectorAll("[data-recipe]").forEach(button => { button.disabled = isActive(); });
const status = {
empty: "待装粉", ready: "等待进水",
preinfusion: q > 0 ? "预浸泡" : "I继续 · 关水",
extraction: q > 0 ? "萃取进水" : "萃取暂停",
complete: "本杯完成", aborted: "已放弃"
};
byId("sessionStatus").textContent = status[phase];
byId("loadButton").disabled = isActive();
byId("loadButton").textContent = ["complete", "aborted"].includes(phase) ? "再测一杯" : "装粉并锁定";
byId("handleButton").disabled = !session || !["preinfusion", "extraction"].includes(phase) || (phase === "extraction" && q > 0);
byId("handleButton").textContent = phase === "extraction" && q > 0 ? "先关水" : phase === "complete" ? "已取手柄" : "取下手柄";
const feedback = {
empty: "装粉后,推杆开始进水",
ready: "手柄已锁定 · 等待进水",
preinfusion: q > 0 ? "粉饼吸水中 · I继续" : "停止吸水 · I继续",
extraction: q > 0 ? "精华收集中 · 关注相对浓度" : "暂停进水 · 精华与出液暂停;取手柄结束",
complete: "本杯完成 · 手柄已取下",
aborted: "粉饼未饱和 · 取手柄放弃本杯"
};
byId("sessionFeedback").textContent = feedback[phase];
const scoreFeedback = byId("scoreFeedback");
scoreFeedback.hidden = phase !== "complete";
if (phase === "complete") {
scoreFeedback.textContent = `R ${Math.round(scores.essenceRatio * 100)}% · C ${scores.concentration.toFixed(2)}×`;
}
}
function loadSession() {
session = new M.BrewSession(machine, M.recipes[recipeName]);
session.load();
lever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
function resetSession() {
session = null;
lever.setValue(0, false);
accumulator = 0;
configureRecipe();
readout();
}
document.querySelectorAll("[data-recipe]").forEach(button => {
button.addEventListener("click", () => {
if (session && !["complete", "aborted"].includes(session.phase)) return;
recipeName = button.dataset.recipe;
session = null;
configureRecipe();
readout();
});
});
byId("loadButton").addEventListener("click", loadSession);
byId("handleButton").addEventListener("click", () => {
if (!session) return;
session.removeHandle(lever.value);
readout();
});
byId("resetButton").addEventListener("click", resetSession);
function frame(now) {
const frameTime = Math.min(0.1, Math.max(0, (now - previousFrame) / 1000));
previousFrame = now;
if (isActive()) {
accumulator += frameTime;
while (accumulator >= fixedStep && isActive()) {
session.step(lever.value, referenceValve(), fixedStep);
accumulator -= fixedStep;
}
}
readout();
requestAnimationFrame(frame);
}
document.addEventListener("visibilitychange", () => { previousFrame = performance.now(); });
configureRecipe();
readout();
requestAnimationFrame(frame);
})();
+34
View File
@@ -0,0 +1,34 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>咖啡机手感实验 · 完美咖啡</title>
<link rel="stylesheet" href="assets/lab.css?v=20261107-2">
</head>
<body>
<header class="lab-header">
<a class="lab-brand" href="./?v=20261107-2"><span class="brand-mark">PC</span><span class="brand-copy">咖啡机<small>手感实验</small></span></a>
<nav class="module-nav" aria-label="测试模块"><a href="temperature/?v=20261107-2">01 水温</a><a href="flow/?v=20261107-2">02 水流</a><a href="extraction/?v=20261107-2">03 萃取</a></nav>
</header>
<main class="workspace overview">
<section class="overview-grid" aria-label="咖啡机测试模块">
<a class="module-card" href="temperature/?v=20261107-2">
<span class="module-number">01 / TEMPERATURE</span>
<div class="module-visual" aria-hidden="true"><svg viewBox="0 0 280 160"><path d="M40 118 A100 100 0 0 1 240 118" fill="none" stroke="#65725f" stroke-width="8" stroke-linecap="round"/><path d="M57 118 L52 118 M77 76 L73 73 M140 44 L140 39 M203 76 L207 73 M223 118 L228 118" stroke="#b7c2af" stroke-width="2"/><path d="M140 118 L175 63" stroke="#eef2e8" stroke-width="3" stroke-linecap="round"/><circle cx="140" cy="118" r="8" fill="#eef2e8"/><circle cx="140" cy="118" r="3" fill="#202923"/><text x="140" y="148" text-anchor="middle" fill="#aebba9" font-size="10" font-family="monospace">0–100°C · T_s</text></svg></div>
<h2>混水温控</h2><p>沸水阀 · 探头温度表</p><div class="module-link">进入测试<span aria-hidden="true">→</span></div>
</a>
<a class="module-card" href="flow/?v=20261107-2">
<span class="module-number">02 / ESSENCE &amp; STRENGTH</span>
<div class="module-visual" aria-hidden="true"><svg viewBox="0 0 280 160"><path d="M40 110 H240" stroke="#141b16" stroke-width="16" stroke-linecap="round"/><path d="M40 110 H240" stroke="#65725f" stroke-width="2" stroke-linecap="round"/><path d="M40 123 V130 M90 123 V130 M140 123 V130 M190 123 V130 M240 123 V130" stroke="#aebba9" stroke-width="2"/><path d="M166 108 V68" stroke="#b99c63" stroke-width="12" stroke-linecap="round"/><rect x="153" y="28" width="26" height="43" rx="8" fill="#e2d3b3" stroke="#8e754b" stroke-width="3"/><circle cx="166" cy="110" r="11" fill="#d8c5a0" stroke="#8e754b" stroke-width="3"/><text x="40" y="148" text-anchor="middle" fill="#aebba9" font-size="10" font-family="monospace">0</text><text x="240" y="148" text-anchor="middle" fill="#aebba9" font-size="10" font-family="monospace">100</text></svg></div>
<h2>精华与浓度</h2><p>精华收集 · 相对浓度</p><div class="module-link">进入测试<span aria-hidden="true">→</span></div>
</a>
<a class="module-card" href="extraction/?v=20261107-2">
<span class="module-number">03 / COMPLETE BREW</span>
<div class="module-visual" aria-hidden="true"><svg viewBox="0 0 280 160"><rect x="28" y="25" width="102" height="111" rx="10" fill="none" stroke="#65725f" stroke-width="2"/><rect x="150" y="25" width="102" height="111" rx="10" fill="none" stroke="#a9c48f" stroke-width="2"/><text x="44" y="50" fill="#aebba9" font-size="10" font-family="monospace">I</text><text x="166" y="50" fill="#c3d8b1" font-size="10" font-family="monospace">R</text><text x="79" y="91" text-anchor="middle" fill="#eef2e8" font-size="27" font-family="monospace">08.3</text><text x="201" y="91" text-anchor="middle" fill="#eef2e8" font-size="27" font-family="monospace">100%</text><path d="M47 111 H111 M169 111 H233" stroke="#65725f" stroke-width="4" stroke-linecap="round"/><path d="M65 111 H88 M182 111 H222" stroke="#c8df9c" stroke-width="4" stroke-linecap="round"/></svg></div>
<h2>完整制杯</h2><p>水温 · 预浸泡 · 精华与浓度</p><div class="module-link">进入测试<span aria-hidden="true">→</span></div>
</a>
</section>
</main>
</body>
</html>
+51
View File
@@ -0,0 +1,51 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>混水温控 · 咖啡机手感实验</title>
<link rel="stylesheet" href="../assets/lab.css?v=20261107-2">
<script src="../assets/instruments.js?v=20261107-2" defer></script>
<script src="../assets/machine.js?v=20261107-2" defer></script>
<script src="../assets/controls.js?v=20261107-2" defer></script>
<script src="page.js?v=20261107-2" defer></script>
</head>
<body>
<header class="lab-header">
<a class="lab-brand" href="../?v=20261107-2"><span class="brand-mark">PC</span><span class="brand-copy">咖啡机<small>手感实验</small></span></a>
<nav class="module-nav" aria-label="测试模块">
<a href="./?v=20261107-2" aria-current="page">01 水温</a><a href="../flow/?v=20261107-2">02 水流</a><a href="../extraction/?v=20261107-2">03 萃取</a>
</nav>
</header>
<main class="workspace temperature-workspace comparison-lab">
<section class="comparison-group" aria-label="15°C冷水对照组">
<h1>15°C<small>固定冷水 · 60% 峰值</small></h1>
<div class="comparison-instruments">
<section class="instrument-card">
<div class="instrument-heading"><h2>出水口温度</h2><span>探头 · 2 s</span></div>
<svg id="temperatureGauge15"></svg>
</section>
<section class="instrument-card">
<div class="instrument-heading"><h2>沸水阀</h2><span>100°C</span></div>
<svg id="hotValve15"></svg>
<div class="control-readout"><span>开度 <output id="hotValveValue15">60%</output></span><span>q<sub>h</sub> <output id="hotFlowValue15">0.010</output><small>mL/s</small></span></div>
</section>
</div>
</section>
<section class="comparison-group" aria-label="20°C冷水对照组">
<h1>20°C<small>固定冷水 · 60% 峰值</small></h1>
<div class="comparison-instruments">
<section class="instrument-card">
<div class="instrument-heading"><h2>出水口温度</h2><span>探头 · 2 s</span></div>
<svg id="temperatureGauge20"></svg>
</section>
<section class="instrument-card">
<div class="instrument-heading"><h2>沸水阀</h2><span>100°C</span></div>
<svg id="hotValve20"></svg>
<div class="control-readout"><span>开度 <output id="hotValveValue20">60%</output></span><span>q<sub>h</sub> <output id="hotFlowValue20">0.010</output><small>mL/s</small></span></div>
</section>
</div>
</section>
</main>
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
(() => {
const { Gauge } = window.Lab;
const { RotaryValve } = window.MachineControls;
const M = window.CoffeeMachine;
const groups = [
{ key: "15", machine: { ...M.defaults, coldTemp: 15 } },
{ key: "20", machine: { ...M.defaults, coldTemp: 20 } }
];
const gauges = groups.map(group => new Gauge(document.getElementById(`temperatureGauge${group.key}`), {
min: 0, max: 100, unit: "°C", label: "T_s"
}));
const sensorTemperatures = groups.map(group => M.temperature(group.machine, 0.6));
let currentValve = 0.6;
let previousFrame = performance.now();
function synchronize(value) {
currentValve = value;
valves.forEach(valve => valve.setValue(value, false));
groups.forEach(group => {
document.getElementById(`hotValveValue${group.key}`).textContent = `${Math.round(value * 100)}%`;
document.getElementById(`hotFlowValue${group.key}`).textContent = M.hotFlow(group.machine, value).toFixed(3);
});
}
const valves = groups.map(group => new RotaryValve(document.getElementById(`hotValve${group.key}`), {
value: currentValve,
label: `${group.key}°C 冷水 · 60% 峰值沸水阀门角度`,
onChange: synchronize
}));
function frame(now) {
const dt = Math.min(0.1, Math.max(0, (now - previousFrame) / 1000));
previousFrame = now;
groups.forEach((group, index) => {
sensorTemperatures[index] = M.probeStep(group.machine, sensorTemperatures[index], currentValve, dt);
gauges[index].update(sensorTemperatures[index]);
});
requestAnimationFrame(frame);
}
document.addEventListener("visibilitychange", () => { previousFrame = performance.now(); });
synchronize(currentValve);
requestAnimationFrame(frame);
})();