mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:24:19 +00:00
* feat(catalog): add the seven 3D-motion pieces as installable registry blocks Each piece ships as a registry block with a CDN poster and preview, a live catalog detail page and its source. Scripts travel inside the catalog payload (shared vendor libraries fetched once, item scripts inline, the one HDR as a data URI) because the docs host only serves fonts, images and JSON. NO_ESSAY_COMMENTS_OK: the long comment blocks are in vendored libraries and the ported frost source under registry/blocks, not hand-written here. HF_MAX_NONLFS_KB=6000: four hosted texture PNGs under docs/public/catalog/items are runtime assets the docs host must serve as files. fallow skipped locally: it audits against origin/main and this branch is stacked on an older main. * chore(catalog): regenerate gallery data and nav after rebasing onto main * fix(catalog): read the install manifest through the bounded project reader * fix(catalog): a script the inliner missed fails the payload instead of shipping a dead URL * refactor(catalog): the leftover-script check reuses the reference finder * fix(catalog): frost and glass textures load from the CDN and the iteration presets are gone * chore(catalog): regenerate the frost and glass payloads and nav * fix(catalog): frost and glass textures are hosted through the registry url field, not hardcoded * chore(catalog): regenerate the frost and glass payloads against the hosted texture URLs * fix(catalog): the hosted-reference rewrite refuses a bare name it cannot safely replace * ci(catalog): verify changed catalog payloads in headless Chrome and check the docs catalog * feat(catalog): every item page follows the shared layout with a Tune panel and tabs * fix(catalog): let the texture-mask item host its masks so its tile plays live * chore(catalog): regenerate item pages, gallery data and the texture-mask payload * chore(catalog): regenerate item pages after merging main * fix(catalog): declared-only variables get the Tune panel, Code and Docs tabs capped * feat(catalog): give the blend-difference caption a demo scene so its tile plays live * chore(catalog): live payload for the blend-difference caption * perf(catalog): heavy 3d pieces compile and draw before ready, not on the first visible frame * feat(catalog): the avatar promo card hosts its videos, audio and fonts on the CDN * feat(catalog): the avatar promo card tile plays live from its CDN-hosted media * chore(catalog): the avatar promo card plays live, no allowlist left * chore(catalog): shorten two comment blocks * chore(catalog): trim first-party comment blocks to the comment-check limits * chore(catalog): shorten two frost source comments * fix(catalog): the Docs tab renders as prose again, and the detail page honours reduced motion Frame-mode pages carry no prose wrapper, and the detail component sat inside not-prose, so the Docs slot's headings, paragraphs, links and lists had no styling at all. The slots now carry their own prose classes and the chrome around them keeps not-prose. The recorded clip also gets the reduced-motion guard the docs-snippet check requires, and the generator reads stability from the source metadata type so the scripts typecheck passes. * fix(catalog): docs-tab paragraphs render as blocks Mintlify emits paragraphs as inline spans, so two paragraphs in the Docs slot ran together. * fix(ci): drop the duplicate docs_catalog job output git's line-based auto-merge silently duplicated the outputs key when main and this branch each added it on non-adjacent lines during the rebase; oxfmt's yaml parser rejects the repeated map key. * fix(catalog): close four CodeQL alerts in the frost source * chore(catalog): allowlist the avatar-promo-card CDN asset deletions, format sync-docs-catalog check-no-main-deletions.mjs was rejecting 11 local mp4/font files this branch already deleted in favor of CDN hosting; scripts/sync-docs-catalog.mjs had one line over the 100-col print width from an earlier edit in this branch. * fix(catalog): detail tabs use docs prose spacing, Install first; previews skip no-WebGPU runners * fix(catalog): the docs tab scrolls with the page instead of a capped inner box * refactor(catalog): split the payload asset and verify scripts into single-purpose helpers * refactor(catalog): split the preview generator into single-purpose helpers * ci(catalog): fail when the committed catalog differs from generator output The docs host serves the committed catalog and nothing regenerates it, so a stale copy shipped silently. The catalog payloads job now generates into a temp dir and compares it with the committed tree. * chore(catalog): regenerate docs/public/catalog with the refactored scripts One full regeneration from an empty output tree with the current scripts. The tree grows from 58.4 MB to 65.1 MB. Two hosted assets are about 2 MB each (an avatar png and a wav); the same bytes are already committed under assets/, so HF_MAX_NONLFS_KB is raised for this commit only. * fix(catalog): run the catalog script tests under the runner they are written for The rebase put three node:test files in the vitest half of test:scripts, where they report "No test suite found". They now sit in the node --test list. * fix(catalog): a WebGPU item without an adapter shows its recorded clip and says why * ci(catalog): the drift check runs from a committed fetch mirror with no network Generation now serves every font and CDN script fetch from scripts/catalog-fetch-mirror and fails when a fetch is not in it, even if the caller swallowed the error. CATALOG_FETCH_MIRROR=record refreshes the mirror from the live network. The docs_catalog filter also watches packages/core, packages/producer and the mirror, and the 13 re-hashed font files are listed in ALLOWED_DELETIONS. * chore(catalog): clean up the temp font cache and sort the mirror index without a locale * fix(catalog): hide Tune when the clip stands in, time out the adapter request, share one check * fix(catalog): the adapter probe survives a sync throw and a hang; test the clip guard * fix(catalog): keep the adapter probe inside the component, Mintlify evaluates only exports * fix(catalog): run the detail and page generator tests in CI; no Tune flash while probing WebGPU * docs(catalog): credit vendored libraries and make each SKILL.md list what the block installs CREDITS.md names every vendored dependency with its upstream and licence, and flags the two leaf textures whose origin is still to be confirmed. Each SKILL.md Files table now comes from the block manifest and its install and render paths point at compositions/<name>/. A test checks that every path a SKILL.md names is a manifest file that exists. * fix(catalog): a declared WebGPU item passes verify by its manifest tag, not by console wording verify-catalog-payloads forgave a missing adapter only by matching the markup and the message, which library-reported errors and widgets never satisfy. The webgpu tag in the item manifest is now the owner: a tagged item ignores its page and console errors, an untagged one gets no forgiveness, and a marker payload with no html is listed instead of crashing the run. * docs(catalog): correct the credits per block and guard the mount and render paths CREDITS.md states the three.js version and vendored-or-CDN status per block, adds d3-delaunay, Clipper on the CDN and the Google Fonts loads, and lists every texture with no known origin. The SKILL.md test now also checks the mount and render paths against the manifest composition. * test(catalog): read each block manifest once in the SKILL.md file test The two checks shared a copied manifest read, which fallow flagged as a clone with a high score. * fix(catalog): commit the hosted item files a gitignore rule kept out, and check git not the disk The compositions/ and *-ad/ ignore rules matched folder names under docs/public/catalog/items, so 33 hosted fonts, textures and marks were generated but never committed and would 404 on the docs host. The rules now have a negation for that tree and the files are added. The drift check read the checkout, where git-ignored files still exist, so it passed locally and failed only in CI. It now unpacks HEAD with git archive and compares that. * fix(catalog): a tile keeps its poster until the composition has painted * fix(catalog): a tagged WebGPU item forgives only the adapter-absent error, and test the wiring The manifest webgpu tag now decides whether an item may lack an adapter, and the error wording decides which lines are that absence. Any other page or console error on the item, and every failed request, still fails. The per-item decision is one exported function the tests drive, marker payloads are parsed by a tested helper, and the SKILL.md variable counts are checked against their tables (cuboid-carousel said forty-nine for forty). * fix(catalog): the pinned group's posters load eagerly at high priority * fix(catalog): type the tile reveal test so the scripts typecheck passes * fix(catalog): stop the adapter signature matching an unrelated failed adapter request failed to request .*adapter also matched errors about other adapters. It now matches only a request for the WebGPU adapter, so a tagged item cannot hide an unrelated failure behind it. * test(catalog): a tagged item still fails on an error about some other adapter * feat(catalog): the install command sits above the preview, as on the live catalog * fix(catalog): find the install slot through Mintlify's child wrapper * fix(docs): catalog copy buttons keep their size when the label swaps to Copied * refactor(docs): name the shown copy label once in the catalog copy button * fix(docs): primary catalog button keeps a readable label on hover and after copy * fix(docs): inset the catalog tab strip and tab content to match the boxed panels
1 line
21 KiB
JSON
1 line
21 KiB
JSON
{"html":"<!doctype html>\n<html\n lang=\"en\"\n data-composition-variables='[{\"id\":\"waveform\",\"type\":\"enum\",\"label\":\"Waveform\",\"default\":\"sine\",\"options\":[{\"value\":\"sine\",\"label\":\"Sine\"},{\"value\":\"square\",\"label\":\"Square\"},{\"value\":\"triangle\",\"label\":\"Triangle\"},{\"value\":\"data\",\"label\":\"Data series\"}]},{\"id\":\"frequency\",\"type\":\"number\",\"label\":\"Signal frequency\",\"unit\":\"Hz\",\"default\":12,\"min\":0.1,\"max\":200,\"step\":0.1},{\"id\":\"amplitude\",\"type\":\"number\",\"label\":\"Amplitude\",\"unit\":\"div\",\"default\":3,\"min\":0.1,\"max\":4,\"step\":0.1},{\"id\":\"persistenceMs\",\"type\":\"number\",\"label\":\"Phosphor persistence (tau)\",\"unit\":\"ms\",\"default\":100,\"min\":1,\"max\":1000,\"step\":1},{\"id\":\"phosphorColor\",\"type\":\"color\",\"label\":\"Phosphor colour\",\"default\":\"#5dff8f\"},{\"id\":\"sweepRate\",\"type\":\"number\",\"label\":\"Sweep rate\",\"unit\":\"sweeps/s\",\"default\":5,\"min\":0.25,\"max\":60,\"step\":0.25},{\"id\":\"dataSeries\",\"type\":\"string\",\"label\":\"Data series (waveform=data)\",\"default\":\"\",\"placeholder\":\"0,0.4,0.9,0.3,-0.6,-1,-0.2,0.5\"}]'\n>\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n <title>Oscilloscope Trace</title>\n <script src=\"https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js\"></script>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n html,\n body {\n width: 1920px;\n height: 1080px;\n overflow: hidden;\n background: #05070a;\n }\n #os-root {\n position: relative;\n width: 1920px;\n height: 1080px;\n font-family: \"JetBrains Mono\", ui-monospace, monospace;\n }\n #os-bg {\n position: absolute;\n inset: 0;\n background: radial-gradient(120% 120% at 30% 25%, #0d141b 0%, #05070a 68%);\n }\n #os-screen {\n position: absolute;\n inset: 0;\n width: 1920px;\n height: 1080px;\n display: block;\n }\n /* Purely decorative CRT falloff — no timing, no motion. */\n #os-vignette {\n position: absolute;\n inset: 0;\n pointer-events: none;\n background: radial-gradient(\n 78% 78% at 34% 50%,\n rgba(0, 0, 0, 0) 55%,\n rgba(0, 0, 0, 0.55) 100%\n );\n }\n #os-readout {\n position: absolute;\n left: 1250px;\n top: 150px;\n width: 520px;\n color: #6f8794;\n font-size: 26px;\n line-height: 1.15;\n letter-spacing: 0.04em;\n }\n #os-readout .os-title {\n color: #b9ccd6;\n font-size: 34px;\n letter-spacing: 0.22em;\n padding-bottom: 26px;\n border-bottom: 2px solid #1d2a33;\n margin-bottom: 26px;\n }\n #os-readout .os-row {\n display: flex;\n justify-content: space-between;\n padding: 13px 0;\n }\n #os-readout .os-val {\n color: #d7e6ee;\n }\n #os-readout .os-note {\n margin-top: 28px;\n font-size: 20px;\n color: #6a7b85;\n line-height: 1.5;\n }\n </style>\n </head>\n <body>\n <div\n id=\"os-root\"\n data-composition-id=\"oscilloscope-trace\"\n data-start=\"0\"\n data-duration=\"6\"\n data-width=\"1920\"\n data-height=\"1080\"\n >\n <div id=\"os-bg\"></div>\n <canvas\n id=\"os-screen\"\n class=\"clip\"\n width=\"1920\"\n height=\"1080\"\n data-start=\"0\"\n data-duration=\"6\"\n data-track-index=\"0\"\n ></canvas>\n <div id=\"os-vignette\"></div>\n <div id=\"os-readout\" class=\"clip\" data-start=\"0\" data-duration=\"6\" data-track-index=\"1\">\n <div class=\"os-title\">OSCILLOSCOPE</div>\n <div class=\"os-row\"><span>SOURCE</span><span class=\"os-val\" id=\"os-r-wave\">SINE</span></div>\n <div class=\"os-row\"><span>FREQ</span><span class=\"os-val\" id=\"os-r-freq\">-</span></div>\n <div class=\"os-row\"><span>TIMEBASE</span><span class=\"os-val\" id=\"os-r-time\">-</span></div>\n <div class=\"os-row\"><span>VERT</span><span class=\"os-val\" id=\"os-r-amp\">-</span></div>\n <div class=\"os-row\"><span>PHOSPHOR</span><span class=\"os-val\" id=\"os-r-phos\">-</span></div>\n <div class=\"os-note\" id=\"os-r-note\"></div>\n </div>\n </div>\n <script>\n (function () {\n \"use strict\";\n\n // ---------------------------------------------------------------\n // Oscilloscope trace with phosphor persistence.\n //\n // Two pieces of physical truth drive the look:\n //\n // 1. PERSISTENCE. The phosphor keeps emitting after the beam has\n // passed, decaying as exp(-age/tau). Decay constants by EIA\n // phosphor class (research entry F#10):\n // P11/P31 - 0.01-1 ms (what a real bench scope uses: no\n // visible afterglow at video rates)\n // P1 - 80-150 ms (the \"vintage glow\" look; tau ~= 100 ms\n // is the entry's recommended default)\n // P33 - > 1 s\n // P2/P7 - 30 s .. ~1 min (radar territory, out of range here)\n // The tail window is 3*tau: after three time constants ~5% of the\n // brightness remains, which the entry gives as the safe cutoff.\n //\n // 2. BEAM-VELOCITY BRIGHTNESS. A trace is brighter where the beam\n // moves slower, because the same deposited energy is spread over\n // a shorter path. Each sub-step deposits a fixed amount of energy\n // (constant dt), so surface brightness goes as 1/segment-length.\n // Flat parts of the waveform are bright; fast vertical edges are\n // faint. Qualitative law only - the research entry states it with\n // no proportionality constant, so the reference length below is\n // the physical minimum (pure horizontal sweep motion), not a\n // fudge factor.\n //\n // SWEEP RATE PROVENANCE. The phosphor decay constants above are\n // measured; the sweep rate is NOT - the research entry gives no\n // timebase figure. The default of 5 sweeps/s is authored: across the\n // 10-division graticule it works out to 20 ms/div, a real value from\n // the standard 1-2-5 timebase sequence, picked because it puts a few\n // cycles of the default signal on screen. Treat it as a dial, not as\n // a measurement.\n //\n // NO FEEDBACK BUFFER. The canvas is cleared every frame and the tail\n // is recomputed by evaluating the beam curve backwards in time from\n // the current frame: P(t - k*dt) for k = 0..K. Frame N depends only\n // on N, so seeking anywhere is exact rather than approximate.\n // ---------------------------------------------------------------\n\n var COMP_ID = \"oscilloscope-trace\";\n var DURATION = 6;\n\n // Screen geometry: a 10x8 division graticule of SQUARE divisions,\n // the standard CRT scope face.\n var DIV = 100;\n var DIVS_X = 10;\n var DIVS_Y = 8;\n var SW = DIV * DIVS_X;\n var SH = DIV * DIVS_Y;\n var SX = 140;\n var SY = 140;\n var CY = SY + SH / 2;\n\n // Tail window in time constants (research entry F#10: 3*tau leaves\n // ~5% weight, stated there as the safe cutoff).\n var TAIL_TAUS = 3;\n // Sub-step count. The entry suggests K ~= 24 steps across the window,\n // which is enough to quantise the DECAY but far too coarse spatially:\n // at 12 Hz the beam would advance 0.15 of a cycle per step and the\n // trace would render as a polygon. So K is derived from how fast the\n // beam actually moves - keep each sub-step under SEG_TARGET_PX of\n // travel. That target and the clamps are MY numbers, not measured\n // ones; the clamp bounds per-frame cost when persistence is long.\n var SEG_TARGET_PX = 3;\n var K_MIN = 120;\n var K_MAX = 8000;\n\n // Band-limit for the square wave. A real generator + a real scope\n // front end both have finite bandwidth, so the edge is steep but not\n // instantaneous; a mathematical step would make the vertical edge one\n // sub-step long and the velocity law would erase it entirely.\n var SQUARE_SHARPNESS = 8;\n\n function readVariables() {\n var api = window.__hyperframes && window.__hyperframes.getVariables;\n if (typeof api === \"function\") return api() || {};\n // Standalone fallback (raw file opened without the runtime): read\n // the same declaration the runtime reads, so defaults have exactly\n // one home.\n var out = {};\n try {\n var raw = document.documentElement.getAttribute(\"data-composition-variables\");\n var decls = JSON.parse(raw || \"[]\");\n for (var i = 0; i < decls.length; i++) out[decls[i].id] = decls[i].default;\n } catch (err) {\n /* declaration missing or malformed - fall through to hard defaults */\n }\n return out;\n }\n\n function num(value, fallback, min, max) {\n var n = typeof value === \"number\" ? value : parseFloat(value);\n if (!isFinite(n)) n = fallback;\n return Math.min(max, Math.max(min, n));\n }\n\n var V = readVariables();\n var waveform =\n [\"sine\", \"square\", \"triangle\", \"data\"].indexOf(String(V.waveform)) >= 0\n ? String(V.waveform)\n : \"sine\";\n var frequency = num(V.frequency, 12, 0.1, 200);\n var amplitude = num(V.amplitude, 3, 0.1, 4);\n var tau = num(V.persistenceMs, 100, 1, 1000) / 1000;\n var sweepRate = num(V.sweepRate, 5, 0.25, 60);\n var phosphor = parseColor(V.phosphorColor, [93, 255, 143]);\n\n // waveform=\"data\" replays a supplied series instead of a synthetic\n // shape: comma/whitespace separated numbers, clamped to -1..1, linearly\n // interpolated, one full pass of the series per `frequency` cycle.\n // Empty or unparseable -> falls back to sine.\n var series = String(V.dataSeries == null ? \"\" : V.dataSeries)\n .split(/[\\s,]+/)\n .map(parseFloat)\n .filter(function (n) {\n return isFinite(n);\n })\n .map(function (n) {\n return Math.min(1, Math.max(-1, n));\n });\n if (waveform === \"data\" && series.length < 2) waveform = \"sine\";\n\n function parseColor(value, fallback) {\n var m = /^#?([0-9a-f]{6})$/i.exec(String(value == null ? \"\" : value).trim());\n if (!m) return fallback;\n var v = parseInt(m[1], 16);\n return [(v >> 16) & 255, (v >> 8) & 255, v & 255];\n }\n\n function rgba(c, a) {\n return \"rgba(\" + c[0] + \",\" + c[1] + \",\" + c[2] + \",\" + a.toFixed(4) + \")\";\n }\n\n // --- the signal: pure function of time, no state ------------------\n\n function wave(t) {\n var p = frequency * t; // cycles elapsed\n if (waveform === \"square\") {\n return Math.tanh(SQUARE_SHARPNESS * Math.sin(2 * Math.PI * p));\n }\n if (waveform === \"triangle\") {\n return (2 / Math.PI) * Math.asin(Math.sin(2 * Math.PI * p));\n }\n if (waveform === \"data\") {\n var frac = p - Math.floor(p);\n var pos = frac * (series.length - 1);\n var i = Math.floor(pos);\n var f = pos - i;\n var a = series[i];\n var b = series[Math.min(series.length - 1, i + 1)];\n return a + (b - a) * f;\n }\n return Math.sin(2 * Math.PI * p);\n }\n\n /** Horizontal sweep position, 0..1 across the graticule. */\n function sweepU(t) {\n var s = t * sweepRate;\n return s - Math.floor(s);\n }\n\n function beamX(t) {\n return SX + sweepU(t) * SW;\n }\n\n function beamY(t) {\n return CY - wave(t) * amplitude * DIV;\n }\n\n // Upper bound on beam speed, in px/s, used to pick the sub-step count.\n // Horizontal is the constant sweep; vertical is the waveform's steepest\n // slope, which differs per shape - a band-limited square is\n // SQUARE_SHARPNESS times steeper at its edge than a sine of the same\n // frequency, and under-sampling exactly there is what turns the edge\n // into a polygon.\n var slopeBound;\n if (waveform === \"square\") {\n slopeBound = SQUARE_SHARPNESS * 2 * Math.PI * frequency;\n } else if (waveform === \"triangle\") {\n slopeBound = 4 * frequency;\n } else if (waveform === \"data\") {\n var maxStep = 0;\n for (var si = 1; si < series.length; si++) {\n maxStep = Math.max(maxStep, Math.abs(series[si] - series[si - 1]));\n }\n slopeBound = maxStep * (series.length - 1) * frequency;\n } else {\n slopeBound = 2 * Math.PI * frequency;\n }\n var beamSpeedMax = Math.sqrt(\n Math.pow(SW * sweepRate, 2) + Math.pow(slopeBound * amplitude * DIV, 2),\n );\n\n // --- graticule (drawn once to an offscreen canvas) ----------------\n\n var grat = document.createElement(\"canvas\");\n grat.width = 1920;\n grat.height = 1080;\n (function drawGraticule() {\n var g = grat.getContext(\"2d\");\n g.fillStyle = \"#04080a\";\n g.fillRect(SX, SY, SW, SH);\n g.strokeStyle = \"rgba(120,180,160,0.16)\";\n g.lineWidth = 1;\n for (var i = 1; i < DIVS_X; i++) {\n g.beginPath();\n g.moveTo(SX + i * DIV + 0.5, SY);\n g.lineTo(SX + i * DIV + 0.5, SY + SH);\n g.stroke();\n }\n for (var j = 1; j < DIVS_Y; j++) {\n g.beginPath();\n g.moveTo(SX, SY + j * DIV + 0.5);\n g.lineTo(SX + SW, SY + j * DIV + 0.5);\n g.stroke();\n }\n // Centre axes carry the fine 0.2-division ticks, as on a real face.\n g.strokeStyle = \"rgba(150,205,185,0.32)\";\n var cx = SX + SW / 2 + 0.5;\n var cy = CY + 0.5;\n g.beginPath();\n g.moveTo(cx, SY);\n g.lineTo(cx, SY + SH);\n g.moveTo(SX, cy);\n g.lineTo(SX + SW, cy);\n g.stroke();\n g.strokeStyle = \"rgba(150,205,185,0.42)\";\n for (var k = 1; k < DIVS_X * 5; k++) {\n var x = SX + (k * DIV) / 5 + 0.5;\n g.beginPath();\n g.moveTo(x, cy - 9);\n g.lineTo(x, cy + 9);\n g.stroke();\n }\n for (var m = 1; m < DIVS_Y * 5; m++) {\n var y = SY + (m * DIV) / 5 + 0.5;\n g.beginPath();\n g.moveTo(cx - 9, y);\n g.lineTo(cx + 9, y);\n g.stroke();\n }\n g.strokeStyle = \"rgba(160,215,195,0.55)\";\n g.lineWidth = 2;\n g.strokeRect(SX + 1, SY + 1, SW - 2, SH - 2);\n })();\n\n // --- per-frame paint ----------------------------------------------\n\n var canvas = document.getElementById(\"os-screen\");\n var ctx = canvas.getContext(\"2d\");\n\n function draw(t) {\n ctx.globalCompositeOperation = \"source-over\";\n ctx.clearRect(0, 0, 1920, 1080);\n ctx.drawImage(grat, 0, 0);\n\n var windowS = TAIL_TAUS * tau;\n var K = Math.max(\n K_MIN,\n Math.min(K_MAX, Math.round((windowS * beamSpeedMax) / SEG_TARGET_PX)),\n );\n var dt = windowS / K;\n // Length the beam covers in one sub-step with zero vertical motion.\n // That is the slowest the beam can ever move, so it is the maximum\n // brightness reference and the velocity weight never exceeds 1.\n var lRef = SW * sweepRate * dt;\n\n ctx.globalCompositeOperation = \"lighter\";\n ctx.lineCap = \"round\";\n\n // Oldest -> newest, so the bright head lands on top.\n var prevX = 0;\n var prevY = 0;\n var prevU = 0;\n var havePrev = false;\n for (var k = K; k >= 0; k--) {\n var tk = t - k * dt;\n if (tk < 0) {\n // Before frame 0 the beam had not been switched on yet.\n havePrev = false;\n continue;\n }\n var u = sweepU(tk);\n var x = SX + u * SW;\n var y = beamY(tk);\n if (havePrev && u >= prevU) {\n var dx = x - prevX;\n var dy = y - prevY;\n var len = Math.sqrt(dx * dx + dy * dy);\n // Beam-velocity law: brightness ~ 1 / path length per unit time.\n var vel = len > 1e-6 ? Math.min(1, lRef / len) : 1;\n var decay = Math.exp((-k * dt) / tau);\n var a = decay * vel;\n if (a > 0.002) {\n ctx.beginPath();\n ctx.moveTo(prevX, prevY);\n ctx.lineTo(x, y);\n ctx.strokeStyle = rgba(phosphor, a * 0.13);\n ctx.lineWidth = 13;\n ctx.stroke();\n ctx.strokeStyle = rgba(phosphor, a * 0.9);\n ctx.lineWidth = 3;\n ctx.stroke();\n if (a > 0.55) {\n // Overdriven phosphor saturates towards white at the head.\n ctx.strokeStyle =\n \"rgba(255,255,255,\" + (((a - 0.55) / 0.45) * 0.7).toFixed(4) + \")\";\n ctx.lineWidth = 1.4;\n ctx.stroke();\n }\n }\n }\n // Retrace is blanked on a real scope: when u wraps, drop the\n // connecting segment instead of drawing a line back across.\n prevX = x;\n prevY = y;\n prevU = u;\n havePrev = true;\n }\n\n // Beam head: the spot itself, brightest point on the screen.\n var hx = beamX(t);\n var hy = beamY(t);\n var glow = ctx.createRadialGradient(hx, hy, 0, hx, hy, 22);\n glow.addColorStop(0, \"rgba(255,255,255,0.95)\");\n glow.addColorStop(0.22, rgba(phosphor, 0.85));\n glow.addColorStop(1, rgba(phosphor, 0));\n ctx.fillStyle = glow;\n ctx.beginPath();\n ctx.arc(hx, hy, 22, 0, Math.PI * 2);\n ctx.fill();\n\n ctx.globalCompositeOperation = \"source-over\";\n }\n\n // --- readout --------------------------------------------------------\n\n (function fillReadout() {\n // Nearest EIA phosphor class for the chosen tau (bands from the\n // research entry). Labelling, not simulation.\n var tauMs = tau * 1000;\n var cls = tauMs <= 1 ? \"P31\" : tauMs <= 150 ? \"P1\" : \"P33\";\n var msPerDiv = 1000 / (sweepRate * DIVS_X);\n function set(id, text) {\n document.getElementById(id).textContent = text;\n }\n set(\"os-r-wave\", waveform.toUpperCase());\n set(\"os-r-freq\", frequency.toFixed(frequency < 10 ? 2 : 1) + \" Hz\");\n set(\n \"os-r-time\",\n (msPerDiv >= 10 ? msPerDiv.toFixed(0) : msPerDiv.toFixed(2)) + \" ms/div\",\n );\n set(\"os-r-amp\", amplitude.toFixed(1) + \" div pk\");\n set(\"os-r-phos\", cls + \" tau \" + tauMs.toFixed(0) + \" ms\");\n set(\n \"os-r-note\",\n \"Trace brightness falls as exp(-age/tau) behind the beam, and rises where the beam slows.\",\n );\n })();\n\n // --- timeline -------------------------------------------------------\n //\n // tl.eventCallback(\"onUpdate\", ...) is NOT usable here: the runtime\n // seeks with suppressEvents, so the callback never fires on a seek and\n // the canvas would keep whatever the last played frame drew. A tweened\n // property with an accessor is applied by GSAP on every render,\n // including suppressed ones, so the repaint is driven from the setter.\n\n var beam = { t: 0 };\n var driver = {};\n Object.defineProperty(driver, \"t\", {\n get: function () {\n return beam.t;\n },\n set: function (value) {\n beam.t = value;\n draw(value);\n },\n });\n\n window.__timelines = window.__timelines || {};\n var tl = gsap.timeline({ paused: true });\n tl.to(driver, { t: DURATION, duration: DURATION, ease: \"none\", lazy: false }, 0);\n window.__timelines[COMP_ID] = tl;\n\n draw(0);\n })();\n </script>\n </body>\n</html>\n"} |