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
};
})();