3D-Drucker
Der Ordner demo-kit/ simuliert das Gerät für die Demo auf der Startseite. Auf dem Gerät wird er nicht benötigt.
Der Ordner demo-kit/ simuliert das Gerät für die Demo auf der Startseite. Auf dem Gerät wird er nicht benötigt.
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Printer</title>
<style>
:root {
--bg: #14171a;
--panel: rgba(24, 28, 32, .78);
--line: rgba(214, 224, 234, .16);
--line-soft: rgba(214, 224, 234, .08);
--orange: #ff7a1a;
--orange-hot: #ffb26b;
--orange-dim: rgba(255, 122, 26, .32);
--blue: #62c6f2;
--red: #ff5a4a;
--text: #e8ecef;
--muted: #8b96a1;
--faint: #5a646e;
--cond: "Roboto Condensed", "sans-serif-condensed", "Arial Narrow", "Avenir Next Condensed", "DIN Condensed", "Bahnschrift", "Segoe UI", system-ui, sans-serif;
--mono: ui-monospace, "Roboto Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
margin: 0; color: var(--text); font: 13px/1.4 var(--cond); font-stretch: condensed;
overflow-x: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
-webkit-text-size-adjust: 100%; text-size-adjust: 100%;
background-color: var(--bg);
background-image:
radial-gradient(ellipse at 50% 0%, rgba(255, 122, 26, .07), rgba(255, 122, 26, 0) 55%),
linear-gradient(rgba(214, 224, 234, .05) 1px, transparent 1px),
linear-gradient(90deg, rgba(214, 224, 234, .05) 1px, transparent 1px),
linear-gradient(rgba(214, 224, 234, .028) 1px, transparent 1px),
linear-gradient(90deg, rgba(214, 224, 234, .028) 1px, transparent 1px);
background-size: 100% 520px, 60px 60px, 60px 60px, 12px 12px, 12px 12px;
background-position: 0 0, -1px -1px, -1px -1px, -1px -1px, -1px -1px;
background-repeat: no-repeat, repeat, repeat, repeat, repeat;
}
main {
max-width: 820px; margin: 0 auto;
padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(104px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}
.lab { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
b { font-weight: 700; }
/* ---------- title block ---------- */
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 2px 0 12px; }
.eyebrow { font: 9.5px/1 var(--mono); letter-spacing: .14em; color: var(--faint); text-transform: uppercase; white-space: nowrap; }
.eyebrow b { color: var(--orange); font-weight: 400; }
h1 { margin: 5px 0 0; font-size: 22px; line-height: 1.05; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ident { min-width: 0; flex: 1; }
.status { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 22px; padding: 0 9px 0 8px; border: 1px solid var(--orange);
color: var(--orange); font-size: 11px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; white-space: nowrap;
background: rgba(255, 122, 26, .08); transition: color .4s, border-color .4s, background .4s; }
.chip i { width: 6px; height: 6px; background: currentColor; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.chip.printing i { animation: beat 1.4s ease-in-out infinite; }
.chip.idle, .chip.none { color: var(--muted); border-color: var(--line); background: transparent; }
.chip.done { color: #14171a; background: var(--orange); }
.chip.cancelled { color: var(--red); border-color: var(--red); background: rgba(255, 90, 74, .08); }
@keyframes beat { 50% { opacity: .25; transform: scale(.7); } }
.link { font: 9.5px/1 var(--mono); letter-spacing: .12em; color: var(--faint); text-transform: uppercase; white-space: nowrap; transition: color .3s; }
.link.off { color: var(--red); }
.link.off::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; vertical-align: -1px;
border: 1.5px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: turn .9s linear infinite; }
@keyframes turn { to { transform: rotate(360deg); } }
/* ---------- sheets: thin frames with corner ticks ---------- */
.sheet { position: relative; border: 1px solid var(--line); background: var(--panel); margin-top: 16px; min-width: 0; }
.sheet::before { content: ""; position: absolute; inset: -5px; pointer-events: none; --c: var(--orange);
background:
linear-gradient(var(--c), var(--c)) 0 0 / 13px 1px, linear-gradient(var(--c), var(--c)) 0 0 / 1px 13px,
linear-gradient(var(--c), var(--c)) 100% 0 / 13px 1px, linear-gradient(var(--c), var(--c)) 100% 0 / 1px 13px,
linear-gradient(var(--c), var(--c)) 0 100% / 13px 1px, linear-gradient(var(--c), var(--c)) 0 100% / 1px 13px,
linear-gradient(var(--c), var(--c)) 100% 100% / 13px 1px, linear-gradient(var(--c), var(--c)) 100% 100% / 1px 13px;
background-repeat: no-repeat; }
.tag { position: absolute; top: -7px; left: 14px; padding: 0 7px; background: var(--bg); color: var(--orange);
font: 9.5px/13px var(--mono); letter-spacing: .16em; text-transform: uppercase; white-space: nowrap; }
.tag.r { left: auto; right: 14px; color: var(--faint); }
/* ---------- hero: the part being built ---------- */
.hero { margin-top: 6px; overflow: visible; }
.stage { position: relative; height: clamp(292px, 43vh, 400px); overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transition: filter .7s ease, opacity .7s ease; }
.hero.paused #scene { filter: saturate(.25) brightness(.6); }
.hero.cancelled #scene { filter: grayscale(1) brightness(.5); }
.hero.idle #scene { filter: saturate(.4) brightness(.7); }
.readout { position: absolute; left: 14px; top: 14px; pointer-events: none; }
.pct { display: flex; align-items: baseline; font-weight: 700; line-height: .86; color: var(--text); margin-top: 5px;
text-shadow: 0 0 22px rgba(20, 23, 26, .9), 0 0 6px rgba(20, 23, 26, .9); }
.pct .int { font-size: 68px; letter-spacing: -.01em; }
.pct .dec { font-size: 28px; color: var(--orange); margin-left: 1px; }
.pct .unit { font-size: 22px; color: var(--orange); margin-left: 3px; font-weight: 400; }
.hero.done .pct .int { animation: pop .9s cubic-bezier(.2, 1.4, .4, 1) 1; }
@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.14); color: var(--orange-hot); } 100% { transform: scale(1); } }
.layerbox { position: absolute; right: 14px; top: 14px; text-align: right; pointer-events: none; }
.layerbox .val { margin-top: 3px; font-size: 26px; font-weight: 700; line-height: 1; white-space: nowrap;
text-shadow: 0 0 14px rgba(20, 23, 26, .9); }
.layerbox .val span { color: var(--muted); font-weight: 400; font-size: 17px; }
.layerbox .val i { font-style: normal; color: var(--orange); margin: 0 3px; font-weight: 400; font-size: 17px; }
.stamp { position: absolute; left: 50%; top: 47%; padding: 6px 16px 5px; border: 3px double currentColor; color: var(--orange);
font-size: 30px; font-weight: 700; letter-spacing: .22em; text-indent: .22em; text-transform: uppercase; white-space: nowrap;
transform: translate(-50%, -50%) rotate(-9deg) scale(1); opacity: 0; pointer-events: none;
background: rgba(20, 23, 26, .72); box-shadow: 0 0 0 1px rgba(20, 23, 26, .6); transition: opacity .25s; }
.stamp small { display: block; font: 9px/1.5 var(--mono); letter-spacing: .2em; text-indent: .2em; text-align: center; font-weight: 400; opacity: .85; }
.stamp.show { opacity: .96; animation: stamp .42s cubic-bezier(.2, 1.5, .4, 1) 1; }
.stamp.cancelled { color: var(--red); }
.stamp.idle { color: var(--muted); }
.stamp.done { color: var(--orange-hot); }
@keyframes stamp { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-16deg) scale(2); } 100% { opacity: .96; transform: translate(-50%, -50%) rotate(-9deg) scale(1); } }
.burst { position: absolute; left: 50%; top: 52%; width: 40px; height: 40px; margin: -20px 0 0 -20px; border: 1.5px solid var(--orange);
border-radius: 50%; opacity: 0; pointer-events: none; }
.hero.done .burst { animation: burst 1.5s cubic-bezier(.1, .7, .3, 1) 2; }
.hero.done .burst.b2 { animation-delay: .22s; }
@keyframes burst { 0% { opacity: .9; transform: scale(.4); } 100% { opacity: 0; transform: scale(11); } }
/* the ruler under the drawing: progress as a measured length */
.ruler { position: relative; height: 34px; margin: 0 14px; border-top: 1px solid var(--line); }
.ruler .scale { position: absolute; left: 0; right: 0; top: 0; height: 7px;
background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 5%); }
.ruler .scale::after { content: ""; position: absolute; right: 0; top: 0; width: 1px; height: 7px; background: var(--line); }
.ruler .fill { position: absolute; left: 0; top: -2px; height: 3px; width: 0; background: var(--orange);
box-shadow: 0 0 10px rgba(255, 122, 26, .8); transition: background .4s; }
.ruler .fill::after { content: ""; position: absolute; right: -4px; top: 3px; border: 4px solid transparent; border-top: 0; border-bottom: 6px solid var(--orange); }
.ruler .marks { position: absolute; left: 0; right: 0; top: 13px; display: flex; justify-content: space-between;
font: 9px/1 var(--mono); color: var(--faint); letter-spacing: .06em; }
.hero.paused .ruler .fill, .hero.cancelled .ruler .fill, .hero.idle .ruler .fill { background: var(--muted); box-shadow: none; }
.hero.paused .ruler .fill::after, .hero.cancelled .ruler .fill::after, .hero.idle .ruler .fill::after { border-bottom-color: var(--muted); }
/* ---------- the four readouts ---------- */
.cells { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.cell { padding: 9px 4px 10px 12px; border-left: 1px solid var(--line-soft); min-width: 0; }
.cell:first-child { border-left: 0; }
.cell .lab { display: flex; align-items: center; gap: 4px; font-size: 9px; letter-spacing: .11em; }
.cell .v { margin-top: 3px; font-size: 20px; font-weight: 700; line-height: 1.1; white-space: nowrap; }
.cell .v small { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 2px; letter-spacing: .08em; }
.cell.hot .v { color: var(--orange); }
.clock { width: 10px; height: 10px; flex: none; overflow: visible; }
.clock circle { fill: none; stroke: var(--orange); stroke-width: 1.4; }
.clock line { stroke: var(--orange); stroke-width: 1.4; stroke-linecap: round; transform-origin: 6px 6px; transition: transform .25s cubic-bezier(.3, 1.8, .5, 1); }
/* ---------- thermal ---------- */
.thermal { padding: 16px 12px 10px; }
.gauges { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.gauge { position: relative; min-width: 0; text-align: center; --c: var(--orange); }
.gauge.bed { --c: var(--blue); }
.gauge svg { display: block; width: 100%; max-width: 150px; margin: 0 auto; overflow: visible; }
.gauge .track { fill: none; stroke: rgba(214, 224, 234, .1); stroke-width: 5; }
.gauge .ticks { fill: none; stroke: rgba(214, 224, 234, .3); stroke-width: 4; stroke-dasharray: .35 4.632; }
.gauge .val { fill: none; stroke: var(--c); stroke-width: 5; stroke-dasharray: 0 100; transition: stroke-dasharray .9s cubic-bezier(.2, .8, .2, 1);
filter: drop-shadow(0 0 4px var(--c)); }
.gauge .target { transition: transform .9s cubic-bezier(.2, .8, .2, 1), opacity .4s; transform-origin: 60px 56px; }
.gauge .target path { fill: var(--text); }
.gauge .target line { stroke: var(--text); stroke-width: 1.2; }
.gauge text { font-family: var(--cond); text-anchor: middle; }
.gauge .big { font-size: 27px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.gauge .deg { font-size: 10px; fill: var(--muted); letter-spacing: .1em; }
.gauge .name { font-size: 9.5px; fill: var(--c); letter-spacing: .22em; font-weight: 700; }
.gauge .sub { margin-top: 1px; font: 10px/1.3 var(--mono); color: var(--muted); letter-spacing: .08em; white-space: nowrap; }
.gauge .sub b { color: var(--text); font-weight: 400; }
.chartwrap { position: relative; margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.legend { display: flex; gap: 14px; align-items: center; font: 9.5px/1 var(--mono); letter-spacing: .12em; color: var(--muted); text-transform: uppercase; }
.legend i { display: inline-block; width: 14px; height: 2px; margin-right: 6px; vertical-align: middle; background: currentColor; }
.legend .n { color: var(--orange); } .legend .b { color: var(--blue); }
.legend .t i { background: none; border-top: 1px dashed currentColor; height: 0; }
.legend .w { margin-left: auto; color: var(--faint); }
#chart { display: block; width: 100%; height: 118px; margin-top: 6px; }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 14px; margin-top: 14px; font: 9px/1.4 var(--mono); letter-spacing: .12em;
color: var(--faint); text-transform: uppercase; white-space: nowrap; }
footer span { overflow: hidden; text-overflow: ellipsis; }
/* ---------- controls ---------- */
.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
padding: 10px calc(16px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
background: linear-gradient(180deg, rgba(20, 23, 26, 0), rgba(15, 17, 20, .94) 22%, #0f1114);
border-top: 0; }
.dock::before { content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 1px;
background: linear-gradient(90deg, transparent, var(--line) 12%, var(--line) 88%, transparent); }
.dock .in { position: relative; max-width: 788px; margin: 10px auto 0; display: grid; grid-template-columns: 1.15fr 1fr; gap: 10px; }
.btn { position: relative; height: 56px; display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0;
border: 1px solid var(--orange); background: linear-gradient(rgba(255, 122, 26, .1), rgba(255, 122, 26, .1)), #14171a; color: var(--orange); padding: 0 12px; margin: 0;
font: 700 15px/1 var(--cond); font-stretch: condensed; letter-spacing: .2em; text-transform: uppercase; cursor: pointer;
-webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden;
clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
transition: background .25s, color .25s, border-color .25s, opacity .25s, transform .12s; }
.btn::after { content: ""; position: absolute; left: -1px; top: 8px; width: 13px; height: 1px; background: currentColor; transform-origin: 0 0; transform: rotate(-45deg); }
.btn::before { content: ""; position: absolute; right: -1px; bottom: 8px; width: 13px; height: 1px; background: currentColor; transform-origin: 100% 0; transform: rotate(-45deg); }
.btn svg { flex: none; }
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn:disabled { cursor: default; border-color: var(--line-soft); color: var(--faint); background: #121518; }
.btn:disabled .ring, .btn:disabled .ico { opacity: .5; }
.btn.resume { background: var(--orange); color: #14171a; box-shadow: 0 0 24px rgba(255, 122, 26, .35); }
.btn.busy { opacity: .6; }
.btn .ico { width: 18px; height: 18px; fill: currentColor; }
#btnCancel { border-color: var(--line); background: #171a1e; color: var(--text); touch-action: none; justify-content: flex-start; padding-left: 12px; }
#btnCancel .txt { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
#btnCancel .txt b { font-size: 14px; letter-spacing: .18em; }
#btnCancel .txt small { font: 8.5px/1 var(--mono); letter-spacing: .1em; color: var(--muted); font-weight: 400; white-space: nowrap; }
#btnCancel .ring { width: 32px; height: 32px; overflow: visible; }
#btnCancel .ring .rt { fill: none; stroke: rgba(214, 224, 234, .2); stroke-width: 2.5; }
#btnCancel .ring .rf { fill: none; stroke: var(--orange); stroke-width: 2.5; stroke-linecap: butt; stroke-dasharray: 81.68; stroke-dashoffset: 81.68;
transform: rotate(-90deg); transform-origin: 16px 16px; filter: drop-shadow(0 0 4px var(--orange)); }
#btnCancel .ring .rx { stroke: currentColor; stroke-width: 1.8; stroke-linecap: square; }
#btnCancel .wash { position: absolute; inset: 0; background: rgba(255, 122, 26, .16); transform-origin: 0 50%; transform: scaleX(0); pointer-events: none; }
#btnCancel.holding { border-color: var(--orange); color: var(--orange); }
#btnCancel.holding .txt small { color: var(--orange); }
#btnCancel.fired { border-color: rgba(255, 90, 74, .45); color: var(--red); }
#btnCancel.fired .ring .rf { stroke: var(--red); filter: drop-shadow(0 0 4px var(--red)); }
.toast { position: absolute; left: 50%; bottom: calc(100% - 2px); transform: translate(-50%, 6px); padding: 6px 12px; background: #0f1114;
border: 1px solid var(--line); color: var(--text); font: 10.5px/1.3 var(--mono); letter-spacing: .06em; white-space: nowrap;
opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--red); color: var(--red); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 359px) {
.pct .int { font-size: 56px; }
.cell .v { font-size: 17px; }
.cell { padding-left: 8px; }
#btnCancel .txt small { display: none; }
}
@media (min-width: 700px) {
.cols { display: grid; grid-template-columns: 1.25fr 1fr; gap: 0 20px; align-items: start; }
.cols .thermal { margin-top: 6px; }
.stage { height: clamp(320px, 50vh, 440px); }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation: none !important; transition: none !important; }
.stamp.show { opacity: .96; }
}
</style>
</head>
<body>
<main>
<header>
<div class="ident">
<div class="eyebrow">DWG <b>PRN-01</b> · SHEET 1/1 · LIVE</div>
<h1 id="file">Printer</h1>
</div>
<div class="status">
<span class="chip none" id="chip"><i></i><span id="chipText">Linking</span></span>
<span class="link" id="link">Connecting</span>
</div>
</header>
<div class="cols">
<section class="sheet hero idle" id="hero" aria-label="Print job">
<span class="tag">Fig. 1 · Build volume</span>
<span class="tag r" id="viewTag">ISO VIEW</span>
<div class="stage">
<canvas id="scene" aria-hidden="true"></canvas>
<div class="burst"></div><div class="burst b2"></div>
<div class="readout">
<div class="lab">Progress</div>
<div class="pct num"><span class="int" id="pctInt">--</span><span class="dec" id="pctDec"></span><span class="unit">%</span></div>
</div>
<div class="layerbox">
<div class="lab">Layer</div>
<div class="val num"><b id="layer">--</b><i>/</i><span id="layers">--</span></div>
</div>
<div class="stamp" id="stamp"><span id="stampText">Paused</span><small id="stampSub"></small></div>
</div>
<div class="ruler" aria-hidden="true">
<div class="scale"></div><div class="fill" id="fill"></div>
<div class="marks"><span>0</span><span>25</span><span>50</span><span>75</span><span>100</span></div>
</div>
<div class="cells">
<div class="cell"><div class="lab">Elapsed</div><div class="v num" id="elapsed">--:--</div></div>
<div class="cell hot"><div class="lab"><svg class="clock" viewBox="0 0 12 12" aria-hidden="true"><circle cx="6" cy="6" r="5"/><line id="hand" x1="6" y1="6" x2="6" y2="2.6"/></svg>Remaining</div><div class="v num" id="remaining">--:--</div></div>
<div class="cell"><div class="lab">Speed</div><div class="v num"><span id="speed">--</span><small>%</small></div></div>
<div class="cell"><div class="lab">Filament</div><div class="v num"><span id="filament">--</span><small>M</small></div></div>
</div>
</section>
<section class="sheet thermal" aria-label="Temperatures">
<span class="tag">Fig. 2 · Thermal</span>
<div class="gauges">
<div class="gauge nozzle">
<svg viewBox="0 0 120 92" role="img" aria-labelledby="nzName">
<path class="track" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<path class="ticks" pathLength="100" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<path class="val" id="nzArc" pathLength="100" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<g class="target" id="nzMark" style="opacity:0"><line x1="98" y1="56" x2="111" y2="56"/><path d="M116.5 52.5 L110.5 56 L116.5 59.5 Z"/></g>
<text class="big" x="60" y="61"><tspan id="nzVal">--</tspan></text>
<text class="deg" x="60" y="73">°C</text>
<text class="name" id="nzName" x="60" y="90">NOZZLE</text>
</svg>
<div class="sub">TARGET <b id="nzTarget">--</b></div>
</div>
<div class="gauge bed">
<svg viewBox="0 0 120 92" role="img" aria-labelledby="bdName">
<path class="track" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<path class="ticks" pathLength="100" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<path class="val" id="bdArc" pathLength="100" d="M21.9 78 A44 44 0 1 1 98.1 78"/>
<g class="target" id="bdMark" style="opacity:0"><line x1="98" y1="56" x2="111" y2="56"/><path d="M116.5 52.5 L110.5 56 L116.5 59.5 Z"/></g>
<text class="big" x="60" y="61"><tspan id="bdVal">--</tspan></text>
<text class="deg" x="60" y="73">°C</text>
<text class="name" id="bdName" x="60" y="90">BED</text>
</svg>
<div class="sub">TARGET <b id="bdTarget">--</b></div>
</div>
</div>
<div class="chartwrap">
<div class="legend"><span class="n"><i></i>Nozzle</span><span class="b"><i></i>Bed</span><span class="t"><i></i>Target</span><span class="w">Last 10 min</span></div>
<canvas id="chart" aria-hidden="true"></canvas>
</div>
</section>
</div>
<footer><span id="footLeft">Device · --</span><span id="footRight">Link · --</span></footer>
</main>
<div class="dock">
<div class="in">
<div class="toast" id="toast" role="status"></div>
<button class="btn" id="btnPause" type="button" disabled>
<svg class="ico" viewBox="0 0 18 18" aria-hidden="true"><path id="pauseIcon" d="M4 3h3.5v12H4zM10.5 3H14v12h-3.5z"/></svg>
<span id="pauseText">Pause</span>
</button>
<button class="btn" id="btnCancel" type="button" disabled aria-label="Cancel the print: press and hold">
<span class="wash" id="wash"></span>
<svg class="ring" viewBox="0 0 32 32" aria-hidden="true">
<circle class="rt" cx="16" cy="16" r="13"/><circle class="rf" id="ringFill" cx="16" cy="16" r="13"/>
<path class="rx" d="M12 12l8 8M20 12l-8 8"/>
</svg>
<span class="txt"><b id="cancelText">Cancel</b><small id="cancelSub">Press and hold</small></span>
</button>
</div>
</div>
<div class="sr" id="live" aria-live="polite"></div>
<script>
(() => {
'use strict';
/* ======================= helpers ======================= */
const $ = id => document.getElementById(id);
const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;
const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
const sleep = ms => new Promise(r => setTimeout(r, ms));
const pad = n => String(n).padStart(2, '0');
const set = (id, text) => { const el = $(id); text = String(text); if (el && el.textContent !== text) el.textContent = text; };
const num = v => typeof v === 'number' && isFinite(v) ? v : 0;
function hms(seconds) {
if (seconds == null || !isFinite(seconds)) return '--:--';
const s = Math.max(0, Math.round(seconds)), h = s / 3600 | 0;
return h ? h + ':' + pad(s / 60 % 60 | 0) + ':' + pad(s % 60) : pad(s / 60 | 0) + ':' + pad(s % 60);
}
const STATES = ['printing', 'paused', 'idle', 'done', 'cancelled'];
const ORANGE = '255,122,26', HOT = '255,190,130', BLUE = '98,198,242', INK = '214,224,234';
/* ======================= what the device said ======================= */
let job = null, jobAt = 0; // the latest job and when it arrived (performance.now)
let shown = 0; // the progress on screen, moving on between two answers
let temps = null; // { nozzle: {actual, target}, bed: {...} }
let hist = [], histT = 0, histAt = 0; // temperature samples { t, nozzle, bed }, the device's time of the newest, and when it arrived
let online = null, failures = 0;
let stateSince = 0, doneAt = -1e9;
async function request(path, method) {
const answer = await Promise.race([
fetch(path, { method: method || 'GET', cache: 'no-store' }),
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 8000)),
]);
let body = null;
try { body = await answer.json(); } catch (e) { /* not JSON */ }
if (!answer.ok && !(answer.status === 409 && body && body.job)) throw new Error('http ' + answer.status);
return { status: answer.status, body };
}
function validJob(j) {
return j && typeof j === 'object' && STATES.includes(j.state) ? j : null;
}
function applyJob(next) {
next = validJob(next); if (!next) return;
const before = job;
const sameJob = before && before.file === next.file && before.layers === next.layers && next.progress >= before.progress - .02;
job = next; jobAt = performance.now();
if (!sameJob || next.state !== 'printing') shown = clamp(num(next.progress), 0, 1);
if (!before || before.state !== next.state || !sameJob) stateChanged(before ? before.state : null, next.state, !sameJob);
wantLayers();
renderStatic();
}
function applyTemps(next, t) {
if (!next || !next.nozzle || !next.bed) return;
temps = { nozzle: next.nozzle, bed: next.bed };
if (Array.isArray(next.history)) hist = next.history.filter(p => p && isFinite(p.t)).map(p => ({ t: +p.t, nozzle: num(p.nozzle), bed: num(p.bed) }));
t = isFinite(t) ? +t : (hist.length ? hist[hist.length - 1].t : Date.now() / 1000);
if (!hist.length || t > hist[hist.length - 1].t) hist.push({ t, nozzle: num(next.nozzle.actual), bed: num(next.bed.actual) });
while (hist.length && hist[0].t < t - 640) hist.shift();
histT = t; histAt = performance.now();
renderTemps();
drawChart();
}
/* ======================= transport: the bridge's WebSocket, else polling ======================= */
let socket = null, socketLive = false, lastMessage = 0, lastTempsFetch = -1e9, socketRetryAt = 0;
function openSocket() {
const bridge = window.connectivitizer;
if (!bridge || typeof bridge.webSocket !== 'function' || socket) return;
let ws;
try { ws = bridge.webSocket('/events'); } catch (e) { return; }
socket = ws;
ws.onopen = () => { if (socket === ws) lastMessage = performance.now(); };
ws.onmessage = event => {
if (socket !== ws || typeof event.data !== 'string') return;
let message;
try { message = JSON.parse(event.data); } catch (e) { return; }
if (!message || typeof message !== 'object') return;
socketLive = true; lastMessage = performance.now();
setOnline(true);
if (message.type === 'progress') { applyJob(message.job); if (message.temps) applyTemps(message.temps, message.t); }
else if (message.type === 'state') applyJob(message.job);
};
ws.onclose = () => { if (socket === ws) dropSocket(); };
ws.onerror = () => { if (socket === ws) dropSocket(); };
}
function dropSocket() {
const ws = socket; socket = null; socketLive = false; socketRetryAt = performance.now() + 5000;
if (ws) { ws.onmessage = ws.onclose = ws.onerror = null; try { ws.close(); } catch (e) { /* already closed */ } }
}
function setOnline(on) {
if (on) failures = 0;
if (on === online) return;
online = on;
renderLink();
}
async function loop() {
for (let turn = 0; ; turn++) {
const now = performance.now();
// A socket that has been silent for a while is taken for dead; the page asks by itself until it is back.
if (socket && now - lastMessage > 6000) dropSocket();
if (!socket && now >= socketRetryAt) openSocket();
try {
if (!socketLive) {
applyJob((await request('/job')).body);
setOnline(true);
}
if (!socketLive || performance.now() - lastTempsFetch > 60000 || !hist.length) {
if (!socketLive ? turn % 2 === 0 || !temps : true) {
const t = (await request('/temps')).body;
lastTempsFetch = performance.now();
if (t) applyTemps(t, t.t);
setOnline(true);
}
}
} catch (e) {
if (++failures >= 2 || online === null) setOnline(false);
}
await sleep(1000);
}
}
/* ======================= the layers of the part ======================= */
const layers = new Map(); // layer number -> { polys: [Float32Array of x,y around 0], z, total }
const wanted = new Set();
let queue = [], loading = 0, partKey = '', partHeight = 1, generation = 0;
function wantLayers() {
if (!job || !job.file || !(job.layers > 0)) return;
const key = job.file + '|' + job.layers;
if (key !== partKey) { partKey = key; layers.clear(); wanted.clear(); queue = []; generation++; }
const N = job.layers, L = clamp(job.layer | 0, 1, N), stride = Math.max(1, Math.ceil(N / 120));
const add = (n, first) => { if (n >= 1 && n <= N && !wanted.has(n)) { wanted.add(n); first ? queue.unshift(n) : queue.push(n); } };
for (let n = 1; n < L; n++) if (n % stride === 0 || n === 1) add(n);
for (let n = L + 2; n <= N; n++) if (n % (stride * 3) === 0 || n === N) add(n);
add(L + 1, true); add(L, true);
pump();
}
function pump() {
while (loading < 3 && queue.length) {
const n = queue.shift(), mine = generation;
loading++;
request('/toolpath?layer=' + n).then(({ body }) => {
if (mine !== generation) return;
if (!body || !Array.isArray(body.polylines)) throw new Error('no outline');
const polys = []; let total = 0;
for (const line of body.polylines) {
if (!Array.isArray(line) || line.length < 4) continue;
const p = new Float32Array(line.length - line.length % 2);
for (let i = 0; i < p.length; i++) p[i] = clamp(num(line[i]), 0, 1) - .5;
for (let i = 2; i < p.length; i += 2) total += Math.hypot(p[i] - p[i - 2], p[i + 1] - p[i - 1]);
polys.push(p);
}
const z = num(body.z);
layers.set(n, { polys, z, total });
if (z > 0 && job && job.layers) partHeight = clamp(z * job.layers / n, .05, 4);
}).catch(() => {
// Asked again with the next answer of the device, a little later.
if (mine === generation) setTimeout(() => { if (mine === generation) wanted.delete(n); }, 3000);
}).then(() => { loading--; pump(); });
}
}
/* ======================= text and gauges ======================= */
const LABEL = { printing: 'Printing', paused: 'Paused', idle: 'Idle', done: 'Done', cancelled: 'Cancelled' };
let stampTimer = 0;
function stateChanged(from, to, newJob) {
stateSince = performance.now();
const hero = $('hero');
hero.classList.remove(...STATES);
hero.classList.add(to);
const chip = $('chip');
chip.className = 'chip ' + to;
set('chipText', LABEL[to]);
const stamp = $('stamp');
clearTimeout(stampTimer);
stamp.className = 'stamp';
const words = { paused: ['Paused', 'Nozzle parked'], cancelled: ['Cancelled', 'Heaters off'], done: ['Complete', 'Remove the part'], idle: ['Standby', 'No job'] }[to];
if (words) {
set('stampText', words[0]); set('stampSub', words[1]);
void stamp.offsetWidth; // so that the stamp comes down again
stamp.classList.add('show', to);
// The finished part should be seen: the stamp of a done print goes away again.
if (to === 'done') stampTimer = setTimeout(() => stamp.classList.remove('show'), 2600);
}
if (to === 'done') doneAt = from === null ? -1e9 : performance.now();
if (from !== null) $('live').textContent = 'The print is ' + LABEL[to].toLowerCase() + '.';
renderButtons();
}
function renderStatic() {
if (!job) return;
set('file', job.file ? String(job.file).replace(/\.(gcode|gco|g)$/i, '') : 'No job');
$('file').title = job.file || '';
set('layer', job.layers ? pad(clamp(job.layer | 0, 0, job.layers)) : '--');
set('layers', job.layers ? job.layers : '--');
set('speed', job.speedPercent != null ? Math.round(num(job.speedPercent)) : '--');
set('filament', job.filamentUsedMm != null ? (num(job.filamentUsedMm) / 1000).toFixed(2) : '--');
renderButtons();
}
// Elapsed, remaining and the percentage move on between two answers of the device while it prints.
function renderLive() {
if (!job) return;
const dt = job.state === 'printing' ? Math.min(3, (performance.now() - jobAt) / 1000) : 0;
const rate = job.state === 'printing' && job.remainingSeconds > 0 ? (1 - job.progress) / job.remainingSeconds : 0;
const p = clamp(num(job.progress) + rate * dt, 0, 1);
if (p > shown || shown - p > .01) shown = p;
const idle = job.state === 'idle' && !job.file;
const pct = shown * 100, whole = Math.floor(pct + 1e-6);
set('pctInt', idle ? '--' : pct >= 99.95 ? '100' : whole);
set('pctDec', idle || pct >= 99.95 ? '' : '.' + Math.floor((pct - whole) * 10 + 1e-6));
$('fill').style.width = (idle ? 0 : pct).toFixed(2) + '%';
const elapsed = num(job.elapsedSeconds) + dt, remaining = Math.max(0, num(job.remainingSeconds) - dt);
set('elapsed', idle ? '--:--' : hms(elapsed));
set('remaining', idle ? '--:--' : hms(remaining));
if (!reduced) $('hand').style.transform = 'rotate(' + (job.state === 'printing' ? Math.floor(elapsed) * 6 : 0) + 'deg)';
}
const NOZZLE_MAX = 300, BED_MAX = 120;
function gauge(prefix, reading, max) {
const actual = num(reading.actual), target = num(reading.target);
$(prefix + 'Arc').style.strokeDasharray = (clamp(actual / max, 0, 1) * 100).toFixed(2) + ' 100';
set(prefix + 'Val', actual.toFixed(actual >= 99.95 ? 0 : 1));
const mark = $(prefix + 'Mark');
mark.style.opacity = target > 0 ? 1 : 0;
mark.style.transform = 'rotate(' + (150 + 240 * clamp(target / max, 0, 1)).toFixed(1) + 'deg)';
set(prefix + 'Target', target > 0 ? Math.round(target) + '°C' : 'OFF');
}
function renderTemps() {
if (!temps) return;
gauge('nz', temps.nozzle, NOZZLE_MAX);
gauge('bd', temps.bed, BED_MAX);
}
function renderLink() {
const link = $('link');
link.classList.toggle('off', online === false);
const bridge = window.connectivitizer, device = bridge && bridge.device;
set('link', online === false ? 'Offline · retrying' : online === null ? 'Connecting' : socketLive ? 'Live · push' : 'Live · polling');
// Only what the app reported about its session is said here.
set('footLeft', 'Device · ' + (device && device.name ? device.name : location.host || 'local'));
set('footRight', device ? 'Link · ' + (device.path === 'direct' ? 'direct' : device.path === 'relayed' ? 'relayed' : '--') + (device.endToEndEncrypted === true ? ' · end-to-end encrypted' : '') : 'Link · browser');
renderButtons();
}
/* ======================= controls ======================= */
let busy = false, toastTimer = 0;
function toast(text, bad) {
const el = $('toast');
el.textContent = text; el.className = 'toast show' + (bad ? ' bad' : '');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => { el.className = 'toast' + (bad ? ' bad' : ''); }, 2600);
}
function renderButtons() {
const state = job ? job.state : 'idle', active = state === 'printing' || state === 'paused';
const pause = $('btnPause'), cancel = $('btnCancel');
pause.disabled = !active || busy || online === false;
pause.classList.toggle('resume', state === 'paused');
pause.classList.toggle('busy', busy);
set('pauseText', state === 'paused' ? 'Resume' : 'Pause');
$('pauseIcon').setAttribute('d', state === 'paused' ? 'M5 2.5v13l10.5-6.5z' : 'M4 3h3.5v12H4zM10.5 3H14v12h-3.5z');
cancel.disabled = !active || busy || online === false;
if (!holding) {
cancel.classList.toggle('fired', state === 'cancelled');
set('cancelText', state === 'cancelled' ? 'Cancelled' : 'Cancel');
set('cancelSub', state === 'cancelled' ? 'Print stopped' : 'Press and hold');
}
}
async function command(path, failed) {
if (busy) return;
busy = true; renderButtons();
try {
const { status, body } = await request(path, 'POST');
const next = validJob(status === 409 ? body.job : body);
if (next) applyJob(next);
if (status === 409) toast('The printer says: ' + (body.error || 'not possible right now'), true);
} catch (e) {
toast(failed, true);
}
busy = false; renderButtons();
}
$('btnPause').addEventListener('click', () => {
if (!job) return;
if (job.state === 'paused') command('/job/resume', 'Could not reach the printer. Still paused.');
else if (job.state === 'printing') command('/job/pause', 'Could not reach the printer. Still printing.');
});
// Cancel is held for a moment, so that a stray tap does not end a print: the ring fills, then it happens.
const HOLD_MS = 1200, RING = 81.68;
let holding = false, holdStart = 0, holdK = 0, holdFrame = 0;
function paintHold(k) {
holdK = k;
$('ringFill').style.strokeDashoffset = (RING * (1 - k)).toFixed(2);
$('wash').style.transform = 'scaleX(' + k.toFixed(3) + ')';
}
function holdStep() {
if (holding) {
const k = clamp((performance.now() - holdStart) / HOLD_MS, 0, 1);
paintHold(k);
if (k >= 1) {
holding = false;
$('btnCancel').classList.remove('holding');
try { if (navigator.vibrate) navigator.vibrate(30); } catch (e) { /* not allowed here */ }
command('/job/cancel', 'Could not reach the printer. Not cancelled.').then(() => paintHold(0));
return;
}
} else {
// Let go too early: the ring runs back.
const k = reduced ? 0 : holdK - .08;
paintHold(Math.max(0, k));
if (k <= 0) return;
}
holdFrame = requestAnimationFrame(holdStep);
}
function holdBegin(event) {
const button = $('btnCancel');
if (button.disabled || holding) return;
if (event.type === 'pointerdown') {
if (event.button) return;
try { button.setPointerCapture(event.pointerId); } catch (e) { /* older WebView */ }
}
holding = true; holdStart = performance.now() - holdK * HOLD_MS;
button.classList.add('holding');
set('cancelSub', 'Keep holding…');
cancelAnimationFrame(holdFrame);
holdFrame = requestAnimationFrame(holdStep);
}
function holdEnd() {
if (!holding) return;
holding = false;
$('btnCancel').classList.remove('holding');
renderButtons();
if (holdK < 1) toast('Hold the button to cancel the print');
}
const cancelButton = $('btnCancel');
cancelButton.addEventListener('pointerdown', holdBegin);
for (const type of ['pointerup', 'pointercancel', 'pointerleave', 'blur']) cancelButton.addEventListener(type, holdEnd);
cancelButton.addEventListener('keydown', e => { if ((e.key === ' ' || e.key === 'Enter') && !e.repeat) { e.preventDefault(); holdBegin(e); } });
cancelButton.addEventListener('keyup', e => { if (e.key === ' ' || e.key === 'Enter') holdEnd(); });
cancelButton.addEventListener('contextmenu', e => e.preventDefault());
/* ======================= drawing ======================= */
function fit(canvas) {
const dpr = Math.min(window.devicePixelRatio || 1, 3), w = canvas.clientWidth, h = canvas.clientHeight;
const pw = Math.round(w * dpr), ph = Math.round(h * dpr);
if (canvas.width !== pw || canvas.height !== ph) { canvas.width = pw; canvas.height = ph; }
const g = canvas.getContext('2d');
g.setTransform(dpr, 0, 0, dpr, 0, 0);
g.clearRect(0, 0, w, h);
return { g, w, h };
}
let yaw = .62, spin = 0, park = 0, lastScene = 0, scaleEase = 0;
const tipAt = { x: 0, y: 0 };
function drawScene(now) {
const canvas = $('scene');
const { g, w, h } = fit(canvas);
if (!w || !h) return;
const dt = Math.min(.1, (now - lastScene) / 1000 || 0); lastScene = now;
const state = job ? job.state : 'idle';
const N = job && job.layers > 0 ? job.layers : 0;
const L = N ? clamp(job.layer | 0, 1, N) : 0;
// The turntable: it turns while printing, stands while paused, and takes a lap of honour when done.
const sinceDone = (now - doneAt) / 1000;
const wantSpin = reduced ? 0 : state === 'printing' ? .2 : state === 'done' ? .2 + 1.5 * Math.exp(-sinceDone / 1.1) : state === 'paused' ? 0 : .05;
spin += (wantSpin - spin) * Math.min(1, dt * 3);
yaw += spin * dt;
const parked = state !== 'printing';
park = reduced ? (parked ? 1 : 0) : park + ((parked ? 1 : 0) - park) * Math.min(1, dt * 4.5);
// An isometric view from above: x and y turn with the table, z goes up.
const H = partHeight;
const wantScale = Math.min((w - 64) / 1.42, (h - 52) / (.866 * H + .71));
scaleEase = scaleEase && !reduced ? scaleEase + (wantScale - scaleEase) * Math.min(1, dt * 5) : wantScale;
const S = scaleEase;
const cx = w / 2 - 8, base = h - 20 - S * .354 - Math.max(0, (h - 52 - S * (.866 * H + .71)) * .45);
const cy = Math.cos(yaw), sy = Math.sin(yaw);
const X = (x, y) => cx + (x * cy - y * sy) * S;
const Y = (x, y, z) => base + (x * sy + y * cy) * S * .5 - z * S * .866;
/* the bed: a plate with a grid, corner marks and its two axes */
g.lineWidth = 1;
g.beginPath();
g.moveTo(X(-.5, -.5), Y(-.5, -.5, 0)); g.lineTo(X(.5, -.5), Y(.5, -.5, 0)); g.lineTo(X(.5, .5), Y(.5, .5, 0)); g.lineTo(X(-.5, .5), Y(-.5, .5, 0)); g.closePath();
g.fillStyle = 'rgba(' + INK + ',.035)'; g.fill();
g.strokeStyle = 'rgba(' + INK + ',.07)';
g.beginPath();
for (let i = 1; i < 10; i++) {
const q = -.5 + i / 10;
g.moveTo(X(q, -.5), Y(q, -.5, 0)); g.lineTo(X(q, .5), Y(q, .5, 0));
g.moveTo(X(-.5, q), Y(-.5, q, 0)); g.lineTo(X(.5, q), Y(.5, q, 0));
}
g.stroke();
g.strokeStyle = 'rgba(' + INK + ',.34)';
g.beginPath();
g.moveTo(X(-.5, -.5), Y(-.5, -.5, 0)); g.lineTo(X(.5, -.5), Y(.5, -.5, 0)); g.lineTo(X(.5, .5), Y(.5, .5, 0)); g.lineTo(X(-.5, .5), Y(-.5, .5, 0)); g.closePath();
g.stroke();
g.strokeStyle = 'rgba(' + ORANGE + ',.9)';
g.beginPath();
for (const [a, b] of [[-1, -1], [1, -1], [1, 1], [-1, 1]]) {
const x = a * .5, y = b * .5;
g.moveTo(X(x - a * .09, y), Y(x - a * .09, y, 0)); g.lineTo(X(x, y), Y(x, y, 0)); g.lineTo(X(x, y - b * .09), Y(x, y - b * .09, 0));
}
g.stroke();
g.font = '9px ' + getComputedStyle(document.body).getPropertyValue('--mono');
g.fillStyle = 'rgba(' + INK + ',.5)'; g.textAlign = 'center'; g.textBaseline = 'middle';
g.fillText('X', X(.6, -.5), Y(.6, -.5, 0)); g.fillText('Y', X(-.5, .6), Y(-.5, .6, 0));
const trace = (layer, upTo) => {
// The whole outline, or only its first `upTo` of length; answers where the line ends.
let left = upTo == null ? Infinity : upTo, tx = 0, ty = 0;
g.beginPath();
for (const p of layer.polys) {
if (left <= 0) break;
g.moveTo(X(p[0], p[1]), Y(p[0], p[1], layer.z)); tx = p[0]; ty = p[1];
for (let i = 2; i < p.length; i += 2) {
const len = Math.hypot(p[i] - p[i - 2], p[i + 1] - p[i - 1]);
if (len >= left) {
const k = len ? left / len : 0;
tx = p[i - 2] + (p[i] - p[i - 2]) * k; ty = p[i - 1] + (p[i + 1] - p[i - 1]) * k;
g.lineTo(X(tx, ty), Y(tx, ty, layer.z)); left = 0; break;
}
left -= len; tx = p[i]; ty = p[i + 1];
g.lineTo(X(tx, ty), Y(tx, ty, layer.z));
}
}
tipAt.x = tx; tipAt.y = ty;
};
/* what is printed: every finished layer as an outline, the lower ones hidden by the ones above */
const top = state === 'done' ? N : L - 1;
const wave = sinceDone * .9 - .15; // the light that runs up the finished part
const settle = state === 'done' ? clamp(sinceDone / 2.4, 0, 1) : 0;
for (let n = 1; n <= top; n++) {
const layer = layers.get(n); if (!layer) continue;
const u = top > 1 ? n / top : 1;
let alpha = .2 + .3 * u * u + (n % 10 === 0 ? .14 : 0) + settle * .12;
let width = n % 10 === 0 ? 1.15 : .9;
if (state === 'done' && !reduced) {
const glow = Math.exp(-Math.pow((n / N - wave) / .07, 2));
alpha += glow * .8; width += glow * 1.2;
}
trace(layer);
g.fillStyle = 'rgba(22,25,28,.8)'; g.fill('evenodd');
g.strokeStyle = 'rgba(' + (alpha > .85 ? HOT : ORANGE) + ',' + clamp(alpha, 0, 1).toFixed(3) + ')';
g.lineWidth = width; g.stroke();
}
/* what is still to come: a faint dashed ghost of the part */
if (state !== 'done' && state !== 'cancelled' && N) {
g.setLineDash([2, 3]); g.lineWidth = 1; g.strokeStyle = 'rgba(' + INK + ',.13)';
for (let n = L + 2; n <= N; n++) { const layer = layers.get(n); if (layer && (n % 3 === 0 || n === N)) { trace(layer); g.stroke(); } }
g.setLineDash([]);
}
/* the layer being printed, as far as the nozzle has come, and the nozzle itself */
const current = state === 'done' ? null : layers.get(L);
if (current && N) {
const frac = state === 'printing' ? clamp(shown * N - (L - 1), 0, 1) : clamp(num(job.progress) * N - (L - 1), 0, 1);
trace(current, current.total * frac);
g.fillStyle = 'rgba(22,25,28,.5)'; if (frac > .98) g.fill('evenodd');
g.save();
g.shadowColor = 'rgba(' + ORANGE + ',.95)'; g.shadowBlur = 12;
g.strokeStyle = 'rgba(' + HOT + ',1)'; g.lineWidth = 2; g.lineJoin = 'round'; g.stroke();
g.restore();
if (state === 'printing' || state === 'paused') {
// Parked: up and away to the corner of the bed.
const e = park * park * (3 - 2 * park);
const nx = tipAt.x + (-.44 - tipAt.x) * e, ny = tipAt.y + (-.44 - tipAt.y) * e, nz = current.z + .3 * e;
const px = X(nx, ny), py = Y(nx, ny, nz);
const pulse = reduced ? 1 : .85 + .15 * Math.sin(now / 90);
if (e < .98) {
const glow = g.createRadialGradient(px, py, 0, px, py, 22 * pulse);
glow.addColorStop(0, 'rgba(255,236,214,' + (.95 * (1 - e)).toFixed(3) + ')');
glow.addColorStop(.18, 'rgba(' + ORANGE + ',' + (.75 * (1 - e)).toFixed(3) + ')');
glow.addColorStop(1, 'rgba(' + ORANGE + ',0)');
g.fillStyle = glow; g.beginPath(); g.arc(px, py, 22 * pulse, 0, Math.PI * 2); g.fill();
}
// the tool head: a tip, a block, and the line it hangs on
g.strokeStyle = 'rgba(' + INK + ',.9)'; g.fillStyle = 'rgba(20,23,26,.92)'; g.lineWidth = 1.1;
g.beginPath(); g.moveTo(px, py - 2.5); g.lineTo(px - 4.5, py - 10); g.lineTo(px + 4.5, py - 10); g.closePath(); g.fill(); g.stroke();
g.beginPath(); g.rect(px - 7, py - 21, 14, 11); g.fill(); g.stroke();
const rail = g.createLinearGradient(0, py - 21, 0, py - 70);
rail.addColorStop(0, 'rgba(' + INK + ',.6)'); rail.addColorStop(1, 'rgba(' + INK + ',0)');
g.strokeStyle = rail; g.beginPath(); g.moveTo(px, py - 21); g.lineTo(px, py - 70); g.stroke();
g.fillStyle = 'rgba(255,244,230,' + (1 - e * .6).toFixed(3) + ')'; g.beginPath(); g.arc(px, py, 1.9, 0, Math.PI * 2); g.fill();
}
}
/* the height scale at the right: layers as on a drawing's dimension line, and a leader to the current one */
if (N) {
const sx = w - 16, y0 = Y(0, 0, 0), y1 = Y(0, 0, H);
g.strokeStyle = 'rgba(' + INK + ',.3)'; g.lineWidth = 1;
g.beginPath(); g.moveTo(sx + .5, y0); g.lineTo(sx + .5, y1);
// Labels at least 22 px apart, whatever the height of the part.
const perLayer = Math.abs(y1 - y0) / N;
const step = [2, 5, 10, 20, 50, 100, 200, 500, 1000].find(v => v * perLayer >= 22) || N;
const zc = state === 'done' ? H : (L - 1 + (current ? clamp(shown * N - (L - 1), 0, 1) : 0)) / N * H;
const yc = Math.round(Y(0, 0, zc)) + .5;
for (let n = 0; n <= N; n += step / 2) {
const y = Math.round(y0 + (y1 - y0) * n / N) + .5, major = n % step === 0;
g.moveTo(sx, y); g.lineTo(sx - (major ? 6 : 3), y);
}
g.moveTo(sx - 6, Math.round(y1) + .5); g.lineTo(sx + 1, Math.round(y1) + .5);
g.stroke();
g.fillStyle = 'rgba(' + INK + ',.42)'; g.textAlign = 'right'; g.textBaseline = 'middle';
for (let n = step; n <= N; n += step) { const y = y0 + (y1 - y0) * n / N; if (y < yc - 19 || y > yc + 9) g.fillText(String(n), sx - 9, y); }
g.strokeStyle = 'rgba(' + ORANGE + ',.75)'; g.setLineDash([1, 3]);
g.beginPath(); g.moveTo(cx + S * .5, yc); g.lineTo(sx - 30, yc); g.stroke(); g.setLineDash([]);
g.fillStyle = 'rgba(' + ORANGE + ',1)';
g.beginPath(); g.moveTo(sx - 1, yc); g.lineTo(sx - 8, yc - 3.5); g.lineTo(sx - 8, yc + 3.5); g.closePath(); g.fill();
g.fillText('L' + String(state === 'done' ? N : L).padStart(String(N).length, '0'), sx - 11, yc - 8);
}
}
function drawChart() {
const { g, w, h } = fit($('chart'));
if (!w || !h) return;
const left = 26, right = 6, topPad = 6, bottom = 16, pw = w - left - right, ph = h - topPad - bottom;
const WINDOW = 600;
const tNow = histT + (reduced ? 0 : (performance.now() - histAt) / 1000);
let max = 100;
for (const p of hist) max = Math.max(max, p.nozzle, p.bed);
if (temps) max = Math.max(max, num(temps.nozzle.target), num(temps.bed.target));
max = Math.ceil((max + 15) / 50) * 50;
const x = t => left + pw - (tNow - t) / WINDOW * pw, y = v => topPad + ph - clamp(v / max, 0, 1) * ph;
const mono = getComputedStyle(document.body).getPropertyValue('--mono');
g.font = '9px ' + mono; g.lineWidth = 1;
// the grid: every 50 degrees, every 2.5 minutes
g.strokeStyle = 'rgba(' + INK + ',.08)'; g.fillStyle = 'rgba(' + INK + ',.4)'; g.textAlign = 'right'; g.textBaseline = 'middle';
g.beginPath();
for (let v = 0; v <= max; v += max > 300 ? 100 : 50) { const yy = Math.round(y(v)) + .5; g.moveTo(left, yy); g.lineTo(w - right, yy); g.fillText(String(v), left - 6, yy); }
for (let i = 0; i <= 4; i++) { const xx = Math.round(left + pw * i / 4) + .5; g.moveTo(xx, topPad); g.lineTo(xx, topPad + ph + 3); }
g.stroke();
g.textBaseline = 'alphabetic';
['-10 MIN', '-7.5', '-5', '-2.5', 'NOW'].forEach((text, i) => { g.textAlign = i === 0 ? 'left' : i === 4 ? 'right' : 'center'; g.fillText(text, left + pw * i / 4, h - 2); });
if (!hist.length) return;
// the targets, dashed
if (temps) {
g.setLineDash([3, 3]);
for (const [target, rgb] of [[num(temps.nozzle.target), ORANGE], [num(temps.bed.target), BLUE]]) {
if (!(target > 0)) continue;
const yy = Math.round(y(target)) + .5;
g.strokeStyle = 'rgba(' + rgb + ',.5)'; g.beginPath(); g.moveTo(left, yy); g.lineTo(w - right, yy); g.stroke();
}
g.setLineDash([]);
}
g.save();
g.beginPath(); g.rect(left, 0, pw + right, h); g.clip();
for (const [key, rgb] of [['bed', BLUE], ['nozzle', ORANGE]]) {
const pts = hist.filter(p => p.t >= tNow - WINDOW - 10);
if (!pts.length) continue;
g.beginPath();
pts.forEach((p, i) => { const px = x(p.t), py = y(p[key]); i ? g.lineTo(px, py) : g.moveTo(px, py); });
const last = pts[pts.length - 1], lx = Math.min(x(last.t), left + pw), ly = y(last[key]);
g.lineTo(left + pw, ly);
g.strokeStyle = 'rgb(' + rgb + ')'; g.lineWidth = 1.6; g.lineJoin = 'round'; g.stroke();
g.lineTo(left + pw, topPad + ph); g.lineTo(x(pts[0].t), topPad + ph); g.closePath();
const fill = g.createLinearGradient(0, topPad, 0, topPad + ph);
fill.addColorStop(0, 'rgba(' + rgb + ',.16)'); fill.addColorStop(1, 'rgba(' + rgb + ',0)');
g.fillStyle = fill; g.fill();
g.fillStyle = 'rgb(' + rgb + ')'; g.shadowColor = 'rgb(' + rgb + ')'; g.shadowBlur = 8;
g.beginPath(); g.arc(left + pw - 1.5, ly, 2.6, 0, Math.PI * 2); g.fill(); g.shadowBlur = 0;
void lx;
}
g.restore();
}
/* ======================= the frame loop ======================= */
let lastChart = 0, lastFrame = 0;
function frame(now) {
if (!document.hidden) {
renderLive();
if (now - lastFrame >= (reduced ? 480 : 30)) { lastFrame = now; try { drawScene(now); } catch (e) { /* a layer that just arrived */ } }
if (now - lastChart >= 1000) { lastChart = now; drawChart(); }
}
requestAnimationFrame(frame);
}
addEventListener('resize', () => { scaleEase = 0; drawChart(); });
/* ======================= start ======================= */
renderLink();
drawChart();
requestAnimationFrame(frame);
if (window.connectivitizer && window.connectivitizer.ready && typeof window.connectivitizer.ready.then === 'function') {
window.connectivitizer.ready.then(renderLink, () => {});
}
loop();
})();
</script>
</body>
</html>