@snowcone-app/loaders 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @snowcone-app/loaders
2
2
 
3
+ ## 0.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#6786](https://github.com/snowcone-app/snowcone-monorepo/pull/6786) [`4baddb1`](https://github.com/snowcone-app/snowcone-monorepo/commit/4baddb1f1cab4e2b9e5942f7af5307924b9e6c81) Thanks [@kevinsproles](https://github.com/kevinsproles)! - US spelling in public text: "color", not "colour". HeroProductImage's `data-render-overlay-why` reason is now `color`. The loaders' API docs and README are updated to match.
8
+
3
9
  ## 0.3.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -35,7 +35,7 @@ once the picture has caught up.
35
35
  ```
36
36
 
37
37
  It finds the part that changes by itself. It compares the picture from before the edit with each new frame, and
38
- what differs (the print, the coloured body) is where it stays. What it learns is kept per `maskKey` in memory and in
38
+ what differs (the print, the colored body) is where it stays. What it learns is kept per `maskKey` in memory and in
39
39
  localStorage (about 1 KB a scene, at most 40 scenes), so the next edit of the same picture starts on the right part at
40
40
  once. Until it knows, it covers the whole picture. Reading the picture needs it to be same-origin or served with CORS
41
41
  (`crossOrigin="anonymous"`); otherwise the beam just covers the whole picture.
@@ -46,10 +46,10 @@ learned.
46
46
  | Prop | Default | |
47
47
  |---|---|---|
48
48
  | `look` | `"beam"` | `"beam"`: light only. `"soft"`: a faint haze and a trail, painted on. `"prism"`: thin rainbow fringes trail the beam. |
49
- | `tone` | `"auto"` | The light's colour. `"auto"` takes a light version of the changing part's colour; `"cool"`, `"warm"`, or `"r,g,b"`. |
49
+ | `tone` | `"auto"` | The light's color. `"auto"` takes a light version of the changing part's color; `"cool"`, `"warm"`, or `"r,g,b"`. |
50
50
 
51
51
  On a light surface (a white cup) light added to white can't be seen, so once the area is known the beam becomes a
52
- coloured line painted on. The learned area only grows during a load, at most every 0.6 s, so the beam never wanders.
52
+ colored line painted on. The learned area only grows during a load, at most every 0.6 s, so the beam never wanders.
53
53
 
54
54
  With `prefers-reduced-motion` the beam doesn't move: a still, soft glow covers the area instead.
55
55
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkMKDNNQDK_cjs = require('../chunk-MKDNNQDK.cjs');
3
+ var chunk66FMKFHB_cjs = require('../chunk-66FMKFHB.cjs');
4
4
  var chunkNCXRWPGN_cjs = require('../chunk-NCXRWPGN.cjs');
5
5
  var react = require('react');
6
6
  var jsxRuntime = require('react/jsx-runtime');
@@ -87,7 +87,7 @@ var BeamEngine = class {
87
87
  this.tone = opts.tone ?? "auto";
88
88
  this.reduced = !!opts.reducedMotion;
89
89
  }
90
- /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
90
+ /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:
91
91
  * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
92
92
  get onLight() {
93
93
  return !!this.next.mask && this.next.surface === "light";
@@ -264,7 +264,7 @@ function BeamLoader({
264
264
  bits: null,
265
265
  natural: null,
266
266
  lastSrc: "",
267
- /** After a scene change (a colour switch): the picture on screen then is still the OLD scene's; learning waits
267
+ /** After a scene change (a color switch): the picture on screen then is still the OLD scene's; learning waits
268
268
  * until another picture has painted. A base taken from it learned "the whole cup changed" for the new scene. */
269
269
  staleSrc: null,
270
270
  lastSnap: null,
@@ -279,17 +279,17 @@ function BeamLoader({
279
279
  if (n.w > 0) L.natural = n;
280
280
  const src = srcOf(el);
281
281
  if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;
282
- const snap = chunkMKDNNQDK_cjs.snapshotPicture(el);
282
+ const snap = chunk66FMKFHB_cjs.snapshotPicture(el);
283
283
  if (snap) {
284
284
  L.lastSrc = src;
285
285
  L.lastSnap = snap;
286
286
  }
287
287
  return snap;
288
288
  };
289
- const surfaceOf = (s, alpha) => s ? chunkMKDNNQDK_cjs.meanLuma(s, alpha) > LIGHT_SURFACE ? "light" : "dark" : void 0;
289
+ const surfaceOf = (s, alpha) => s ? chunk66FMKFHB_cjs.meanLuma(s, alpha) > LIGHT_SURFACE ? "light" : "dark" : void 0;
290
290
  const apply = (bits, w, h, from, source, force = false) => {
291
- const alpha = chunkMKDNNQDK_cjs.softAlpha(bits, w, h, { grow: 4, blur: 6 });
292
- const box = chunkMKDNNQDK_cjs.alphaBox(alpha, w, h);
291
+ const alpha = chunk66FMKFHB_cjs.softAlpha(bits, w, h, { grow: 4, blur: 6 });
292
+ const box = chunk66FMKFHB_cjs.alphaBox(alpha, w, h);
293
293
  if (!box) return;
294
294
  const t = now();
295
295
  if (!force) {
@@ -300,9 +300,9 @@ function BeamLoader({
300
300
  if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;
301
301
  }
302
302
  }
303
- const colour = from ? chunkMKDNNQDK_cjs.meanColour(from, bits) : null;
303
+ const colour = from ? chunk66FMKFHB_cjs.meanColour(from, bits) : null;
304
304
  const surf = surfaceOf(from, alpha);
305
- engine.setRegion({ mask: chunkMKDNNQDK_cjs.alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : void 0, surface: surf }, t);
305
+ engine.setRegion({ mask: chunk66FMKFHB_cjs.alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : void 0, surface: surf }, t);
306
306
  L.shown = box;
307
307
  L.shownAt = t;
308
308
  setMaskSource(source);
@@ -314,7 +314,7 @@ function BeamLoader({
314
314
  L.base = snap;
315
315
  L.bits = null;
316
316
  L.shown = null;
317
- const known = snap && L.key ? chunkMKDNNQDK_cjs.recallMask(L.key, snap.w, snap.h) : null;
317
+ const known = snap && L.key ? chunk66FMKFHB_cjs.recallMask(L.key, snap.w, snap.h) : null;
318
318
  if (known && snap) {
319
319
  L.bits = known;
320
320
  apply(known, snap.w, snap.h, snap, "learned", true);
@@ -327,7 +327,7 @@ function BeamLoader({
327
327
  }
328
328
  };
329
329
  if (mask) {
330
- const s = chunkMKDNNQDK_cjs.snapshotPicture(mask);
330
+ const s = chunk66FMKFHB_cjs.snapshotPicture(mask);
331
331
  if (s) {
332
332
  const bits = new Uint8Array(s.w * s.h);
333
333
  for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;
@@ -354,14 +354,14 @@ function BeamLoader({
354
354
  return startOn(cur);
355
355
  }
356
356
  if (!L.base) return startOn(cur);
357
- const bits = chunkMKDNNQDK_cjs.changedBits(L.base, cur);
358
- if (!bits || chunkMKDNNQDK_cjs.coverageOf(bits) > chunkMKDNNQDK_cjs.UNRELIABLE_COVERAGE) {
357
+ const bits = chunk66FMKFHB_cjs.changedBits(L.base, cur);
358
+ if (!bits || chunk66FMKFHB_cjs.coverageOf(bits) > chunk66FMKFHB_cjs.UNRELIABLE_COVERAGE) {
359
359
  L.base = cur;
360
360
  return;
361
361
  }
362
- if (!chunkMKDNNQDK_cjs.isLearnable(bits)) return;
362
+ if (!chunk66FMKFHB_cjs.isLearnable(bits)) return;
363
363
  const key = L.key;
364
- const all = key ? chunkMKDNNQDK_cjs.rememberMask(key, cur.w, cur.h, bits) : L.bits ? chunkMKDNNQDK_cjs.orBits(L.bits, bits) : bits;
364
+ const all = key ? chunk66FMKFHB_cjs.rememberMask(key, cur.w, cur.h, bits) : L.bits ? chunk66FMKFHB_cjs.orBits(L.bits, bits) : bits;
365
365
  L.bits = all;
366
366
  apply(all, cur.w, cur.h, L.base, "learned");
367
367
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/beam/engine.ts","../../src/beam/BeamLoader.tsx"],"names":["p","g","useRef","useState","useEffect","naturalSize","snapshotPicture","meanLuma","softAlpha","alphaBox","meanColour","alphaCanvas","recallMask","changedBits","coverageOf","UNRELIABLE_COVERAGE","isLearnable","rememberMask","orBits","fitRect","jsx"],"mappings":";;;;;;;;AAUO,IAAM,eAAA,GAAkB;AAExB,I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A,GAAS,QAAA,GAAW,QAAA;AAAA,QAC3C,GAAG;AAAA;AACL;AAAA,GACF;AAEJ","file":"index.cjs","sourcesContent":["/**\n * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is\n * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.\n *\n * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into\n * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).\n */\nimport type { Rect } from \"../index\";\n\n/** The beam fades in over this long. */\nexport const BEAM_FADE_IN_MS = 450;\n/** One sweep from one side to the other while loading. */\nexport const BEAM_SWEEP_MS = 1150;\n/** The last pass, once the picture has caught up. */\nexport const BEAM_PASS_MS = 380;\n/** The fade after the last pass. */\nexport const BEAM_TAIL_MS = 150;\n/** The longest dash to the nearer edge before the last pass (from the middle). */\nexport const BEAM_RUSH_MAX_MS = 190;\n/** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */\nexport const BEAM_FINISH_MS = BEAM_RUSH_MAX_MS + BEAM_PASS_MS + BEAM_TAIL_MS;\n/** A newly learned area replaces the old one over this long (never a jump). */\nexport const REGION_FADE_MS = 300;\n\n/** The looks from the 1 Dec prototype: `beam` = \"Just the beam\" (light only, the default); `soft` = \"Soft laser\"\n * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */\nexport type BeamLook = \"beam\" | \"soft\" | \"prism\";\n/** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */\nexport type BeamTone = \"auto\" | \"cool\" | \"warm\" | `${number},${number},${number}`;\n\nconst TONES = { cool: \"190,222,255\", warm: \"255,150,60\" } as const;\n/** On a light surface light can't show (white + light = white): the beam is a coloured laser painted on instead. */\nconst ON_LIGHT = { glow: \"70,140,255\", core: \"40,110,240\" } as const;\nconst FRINGES = [\"255,70,70\", \"255,170,40\", \"250,240,80\", \"70,220,110\", \"70,150,255\", \"160,90,255\"];\n\nconst clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));\nconst ease = (p: number) => 0.5 - 0.5 * Math.cos(Math.PI * clamp(p));\n\nexport interface BeamPosition {\n /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */\n s: number;\n /** Which way it moves. */\n dir: 1 | -1;\n /** Overall opacity, 0–1. */\n alpha: number;\n finishing: boolean;\n /** The exit is over: nothing to draw, the host may unmount. */\n done: boolean;\n}\n\n/** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */\nexport class BeamMotion {\n private t0: number;\n private ph0 = 0;\n /** When the beam started (its fade-in runs from here). */\n readonly bornAt: number;\n private fin: { at: number; from: number; end: 0 | 1; rush: number; alpha: number } | null = null;\n\n constructor(now: number) {\n this.t0 = now;\n this.bornAt = now;\n }\n\n get finishing(): boolean {\n return this.fin !== null;\n }\n\n private loading(now: number): { s: number; dir: 1 | -1 } {\n const ph = (((now - this.t0) / BEAM_SWEEP_MS + this.ph0) % 2 + 2) % 2;\n return ph < 1 ? { s: ease(ph), dir: 1 } : { s: ease(2 - ph), dir: -1 };\n }\n\n private fadeIn(now: number): number {\n const p = clamp((now - this.bornAt) / BEAM_FADE_IN_MS);\n return p * p;\n }\n\n at(now: number): BeamPosition {\n if (!this.fin) return { ...this.loading(now), alpha: this.fadeIn(now), finishing: false, done: false };\n const { at, from, end, rush, alpha } = this.fin;\n const t = now - at;\n if (t >= rush + BEAM_PASS_MS + BEAM_TAIL_MS) return { s: 1 - end, dir: end === 0 ? 1 : -1, alpha: 0, finishing: true, done: true };\n if (t < rush) {\n const p = t / rush;\n return { s: from + (end - from) * (1 - (1 - p) * (1 - p)), dir: end > from ? 1 : -1, alpha, finishing: true, done: false };\n }\n const p = (t - rush) / BEAM_PASS_MS;\n const s = p >= 1 ? 1 - end : end + (1 - 2 * end) * ease(p);\n // full through most of the pass, then gone by the end of the tail\n const fadeFrom = rush + BEAM_PASS_MS * 0.6, fadeLen = BEAM_PASS_MS * 0.4 + BEAM_TAIL_MS;\n const a = t <= fadeFrom ? alpha : alpha * (1 - clamp((t - fadeFrom) / fadeLen));\n return { s, dir: end === 0 ? 1 : -1, alpha: a, finishing: true, done: false };\n }\n\n /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */\n finish(now: number): void {\n if (this.fin) return;\n const cur = this.at(now);\n const end: 0 | 1 = cur.s < 0.5 ? 0 : 1;\n this.fin = { at: now, from: cur.s, end, rush: 60 + (BEAM_RUSH_MAX_MS - 60) * 2 * Math.abs(cur.s - end), alpha: cur.alpha };\n }\n\n /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */\n resume(now: number): void {\n if (!this.fin) return;\n const cur = this.at(now);\n this.fin = null;\n const ph = Math.acos(clamp(1 - 2 * cur.s, -1, 1)) / Math.PI; // ease(ph) = s\n this.ph0 = cur.dir > 0 ? ph : 2 - ph;\n this.t0 = now;\n }\n}\n\n/** The part of the picture the beam stays on. */\nexport interface BeamRegion {\n /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */\n mask: CanvasImageSource | null;\n /** The mask's box in picture space (0–1); `null` with no mask. */\n box: { x: number; y: number; w: number; h: number } | null;\n /** The colour of the changing part, `\"r,g,b\"`, for `tone: \"auto\"`. */\n tone?: string;\n /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */\n surface?: \"light\" | \"dark\";\n}\n\nconst WHOLE: BeamRegion = { mask: null, box: null };\n\nexport interface BeamEngineOptions {\n look?: BeamLook;\n tone?: BeamTone;\n /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */\n reducedMotion?: boolean;\n}\n\n/** Draws the beam into a 2D canvas the size of the frame. */\nexport class BeamEngine {\n readonly motion: BeamMotion;\n readonly look: BeamLook;\n private readonly tone: BeamTone;\n private readonly reduced: boolean;\n private prev: BeamRegion = WHOLE;\n private next: BeamRegion = WHOLE;\n private regionAt = -Infinity;\n private maskLayer: HTMLCanvasElement | null = null;\n\n constructor(opts: BeamEngineOptions, now: number) {\n this.motion = new BeamMotion(now);\n this.look = opts.look ?? \"beam\";\n this.tone = opts.tone ?? \"auto\";\n this.reduced = !!opts.reducedMotion;\n }\n\n /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:\n * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */\n get onLight(): boolean {\n return !!this.next.mask && this.next.surface === \"light\";\n }\n\n /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a\n * light surface paint on. */\n get blendMode(): \"screen\" | \"normal\" {\n return this.look === \"soft\" || this.onLight ? \"normal\" : \"screen\";\n }\n\n /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in\n * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */\n setRegion(region: BeamRegion | null, now: number): void {\n const next = region ?? WHOLE;\n if (!this.next.mask && now - this.motion.bornAt < BEAM_FADE_IN_MS) {\n this.prev = this.next = next;\n this.regionAt = -Infinity;\n return;\n }\n this.prev = this.mixWeight(now) >= 1 ? this.next : this.prev;\n this.next = next;\n this.regionAt = now;\n }\n\n finish(now: number): void { this.motion.finish(now); }\n resume(now: number): void { this.motion.resume(now); }\n\n private mixWeight(now: number): number {\n return clamp((now - this.regionAt) / REGION_FADE_MS);\n }\n\n private rgb(): string {\n if (this.tone === \"cool\" || this.tone === \"warm\") return TONES[this.tone];\n if (this.tone !== \"auto\") return this.tone;\n if (this.onLight) return ON_LIGHT.glow;\n return this.next.tone ?? this.prev.tone ?? TONES.cool;\n }\n\n /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */\n private area(region: BeamRegion, place: Rect, W: number, H: number): Rect {\n if (!region.box) {\n const x0 = Math.max(0, place.x), y0 = Math.max(0, place.y);\n return { x: x0, y: y0, w: Math.min(W, place.x + place.w) - x0, h: Math.min(H, place.y + place.h) - y0 };\n }\n const b = region.box;\n return { x: place.x + b.x * place.w, y: place.y + b.y * place.h, w: b.w * place.w, h: b.h * place.h };\n }\n\n /**\n * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.\n * Returns `true` once the exit is over (the canvas is cleared).\n */\n draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr = 1): boolean {\n const pos = this.motion.at(now);\n ctx.globalCompositeOperation = \"source-over\";\n ctx.globalAlpha = 1;\n ctx.clearRect(0, 0, W, H);\n if (pos.done) return true;\n if (pos.alpha <= 0.001) return false;\n\n const t = this.mixWeight(now);\n const a0 = this.area(this.prev, place, W, H), a1 = this.area(this.next, place, W, H);\n const A: Rect = { x: a0.x + (a1.x - a0.x) * t, y: a0.y + (a1.y - a0.y) * t, w: a0.w + (a1.w - a0.w) * t, h: a0.h + (a1.h - a0.h) * t };\n const rgb = this.rgb();\n const pad = 10 * dpr, top = A.y - pad, tall = A.h + 2 * pad;\n\n ctx.globalAlpha = pos.alpha;\n if (this.reduced) {\n ctx.fillStyle = `rgba(${rgb},0.22)`;\n ctx.fillRect(0, 0, W, H);\n } else {\n const x = A.x + pos.s * A.w, back = -pos.dir;\n const light = this.look !== \"soft\";\n const painted = this.onLight;\n if (this.look === \"soft\") {\n ctx.fillStyle = \"rgba(255,255,255,0.10)\";\n ctx.fillRect(0, 0, W, H);\n const T = A.w * 0.22, g = ctx.createLinearGradient(x + back * T, 0, x, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(1, `rgba(${rgb},0.22)`);\n ctx.fillStyle = g;\n ctx.fillRect(Math.min(x, x + back * T), top, T, tall);\n }\n if (this.look === \"prism\") {\n FRINGES.forEach((c, i) => {\n ctx.fillStyle = `rgba(${c},${0.55 - i * 0.04})`;\n ctx.fillRect(x + back * (6 + i * 7) * dpr * (pos.finishing ? 1.5 : 1) - 2.5 * dpr, top, 5 * dpr, tall);\n });\n }\n const gw = (light ? 18 : 26) * dpr;\n const g = ctx.createLinearGradient(x - gw, 0, x + gw, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(0.5, `rgba(${rgb},${painted ? 0.45 : light ? 0.85 : 0.75})`);\n g.addColorStop(1, `rgba(${rgb},0)`);\n ctx.fillStyle = g;\n ctx.fillRect(x - gw, top, 2 * gw, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.85)` : \"rgba(255,255,255,0.95)\";\n ctx.fillRect(x - dpr, top, 2 * dpr, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.7)` : \"rgba(255,245,225,0.9)\";\n const sparks = light ? 10 : 14;\n for (let i = 0; i < sparks; i++) {\n ctx.globalAlpha = pos.alpha * Math.random();\n ctx.fillRect(x + (Math.random() - 0.5) * 16 * dpr, A.y + Math.random() * A.h, 1.6 * dpr, 1.6 * dpr);\n }\n ctx.globalAlpha = pos.alpha;\n }\n\n // cut to the area: the old region fading into the new one\n const layer = this.maskOf(W, H, place, t);\n if (layer) {\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = \"destination-in\";\n ctx.drawImage(layer, 0, 0);\n ctx.globalCompositeOperation = \"source-over\";\n }\n return false;\n }\n\n private maskOf(W: number, H: number, place: Rect, t: number): HTMLCanvasElement | null {\n if (!this.prev.mask && !this.next.mask) return null; // the whole frame: nothing to cut\n if (typeof document === \"undefined\") return null;\n this.maskLayer ??= document.createElement(\"canvas\");\n const m = this.maskLayer;\n if (m.width !== W || m.height !== H) { m.width = W; m.height = H; }\n const x = m.getContext(\"2d\");\n if (!x) return null;\n x.globalAlpha = 1;\n x.clearRect(0, 0, W, H);\n for (const [r, a] of [[this.prev, 1 - t], [this.next, t]] as const) {\n if (a <= 0) continue;\n x.globalAlpha = a;\n if (r.mask) x.drawImage(r.mask, place.x, place.y, place.w, place.h);\n else x.fillRect(0, 0, W, H);\n }\n x.globalAlpha = 1;\n return m;\n }\n}\n","\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { fitRect, naturalSize, type LoaderMaskSource, type LoaderPhase, type LoaderProps } from \"../index\";\nimport {\n alphaBox,\n alphaCanvas,\n changedBits,\n coverageOf,\n isLearnable,\n meanLuma,\n meanColour,\n orBits,\n recallMask,\n rememberMask,\n snapshotPicture,\n softAlpha,\n type Snapshot,\n UNRELIABLE_COVERAGE,\n} from \"../mask\";\nimport { BEAM_FINISH_MS, BeamEngine, type BeamLook, type BeamTone } from \"./engine\";\n\n/** How often the picture is compared with its first look while loading. */\nexport const LEARN_EVERY_MS = 250;\n/** A learned area moves on screen at most this often... */\nexport const REGION_STEADY_MS = 600;\n/** ...and only when an edge moves out by more than this share of the picture (an area only grows within an episode). */\nexport const REGION_MIN_MOVE = 0.02;\n/** A surface brighter than this (0–1) is light: the beam is painted on it, not added as light. */\nexport const LIGHT_SURFACE = 0.62;\n/** The beam's canvas never has more pixels than this (it is soft: CSS scales it up). */\nexport const MAX_CANVAS_PIXELS = 2_500_000;\n\nexport interface BeamLoaderProps extends LoaderProps {\n /** `\"beam\"` (default): light only. `\"soft\"`: a faint haze and a trail, painted on. `\"prism\"`: rainbow fringes. */\n look?: BeamLook;\n /** The light's colour. `\"auto\"` (default): a light version of the colour of the part that changes. */\n tone?: BeamTone;\n}\n\n/** A light version of a colour: the beam reads as light on that material (warm on wood, mint on a green cup). */\nfunction lightTone([r, g, b]: [number, number, number]): string {\n return [r, g, b].map((v) => Math.round(v + (255 - v) * 0.6)).join(\",\");\n}\n\n/**\n * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next\n * render is on the way; one last pass across and a fade once it has caught up.\n *\n * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it\n * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per\n * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.\n *\n * Machine-readable state: `data-sc-loader=\"beam\"`, `data-sc-loader-phase` (`loading` | `finishing`),\n * `data-sc-loader-mask` (`whole` | `learned` | `given`).\n */\nexport function BeamLoader({\n visible,\n onExited,\n picture,\n maskKey,\n fit = \"cover\",\n mask,\n look = \"beam\",\n tone = \"auto\",\n className,\n style,\n}: BeamLoaderProps) {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const engineRef = useRef<BeamEngine | null>(null);\n // one last comparison when the picture has caught up (set by the mount effect)\n const learnNowRef = useRef<() => void>(() => {});\n const [phase, setPhase] = useState<LoaderPhase>(\"loading\");\n const [maskSource, setMaskSource] = useState<LoaderMaskSource>(mask ? \"given\" : \"whole\");\n\n // the latest props, for the loops below (they are set up once)\n const live = useRef({ picture, maskKey, fit, onExited });\n live.current = { picture, maskKey, fit, onExited };\n\n // the area on screen, stamped for agents: data-sc-loader-area (picture space) and data-sc-loader-surface\n const [area, setArea] = useState<string | undefined>(undefined);\n const [surface, setSurface] = useState<\"light\" | \"dark\" | undefined>(undefined);\n\n useEffect(() => {\n const now = () => (typeof performance !== \"undefined\" ? performance.now() : Date.now());\n const reduced = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const engine = new BeamEngine({ look, tone, reducedMotion: reduced }, now());\n engineRef.current = engine;\n const pic = () => live.current.picture?.() ?? null;\n\n // What this episode knows. `base` is the first look the frames are compared with; `shown` the area on screen.\n const L = {\n key: live.current.maskKey,\n base: null as Snapshot | null,\n bits: null as Uint8Array | null,\n natural: null as { w: number; h: number } | null,\n lastSrc: \"\",\n /** After a scene change (a colour switch): the picture on screen then is still the OLD scene's; learning waits\n * until another picture has painted. A base taken from it learned \"the whole cup changed\" for the new scene. */\n staleSrc: null as string | null,\n lastSnap: null as Snapshot | null,\n shown: null as { x: number; y: number; w: number; h: number } | null,\n shownAt: -Infinity,\n };\n const srcOf = (el: ReturnType<typeof pic>) =>\n el && typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement ? el.currentSrc || el.src : \"\";\n // A new snapshot only when a new picture is on screen (a frame arrived): reading a 5K frame is not free.\n const look_ = () => {\n const el = pic();\n if (!el) return null;\n const n = naturalSize(el);\n if (n.w > 0) L.natural = n;\n const src = srcOf(el);\n if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;\n const snap = snapshotPicture(el);\n if (snap) { L.lastSrc = src; L.lastSnap = snap; }\n return snap;\n };\n const surfaceOf = (s: Snapshot | null, alpha?: Float32Array | null) => (s ? (meanLuma(s, alpha) > LIGHT_SURFACE ? \"light\" : \"dark\") : undefined);\n\n /** Shows a learned area. Steady on purpose: a small change, or one sooner than REGION_STEADY_MS after the last,\n * keeps the area on screen as it is (it moving under the beam read as the beam fading out and back elsewhere). */\n const apply = (bits: Uint8Array, w: number, h: number, from: Snapshot | null, source: LoaderMaskSource, force = false) => {\n const alpha = softAlpha(bits, w, h, { grow: 4, blur: 6 });\n const box = alphaBox(alpha, w, h);\n if (!box) return;\n const t = now();\n if (!force) {\n if (engine.motion.finishing) return;\n const p = L.shown;\n if (p) {\n // only outward: the area grows as more of the picture is seen changing, never twitches back in\n const moved = Math.max(p.x - box.x, p.y - box.y, box.x + box.w - p.x - p.w, box.y + box.h - p.y - p.h);\n if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;\n }\n }\n const colour = from ? meanColour(from, bits) : null;\n const surf = surfaceOf(from, alpha);\n engine.setRegion({ mask: alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : undefined, surface: surf }, t);\n L.shown = box;\n L.shownAt = t;\n setMaskSource(source);\n setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(\",\"));\n setSurface(surf);\n };\n /** Starts over on what is known about the scene now on screen (mount, or a colour switch swapped the picture). */\n const startOn = (snap: Snapshot | null) => {\n L.key = live.current.maskKey;\n L.base = snap;\n L.bits = null;\n L.shown = null;\n const known = snap && L.key ? recallMask(L.key, snap.w, snap.h) : null;\n if (known && snap) {\n L.bits = known;\n apply(known, snap.w, snap.h, snap, \"learned\", true);\n } else {\n const surf = surfaceOf(snap);\n engine.setRegion({ mask: null, box: null, surface: surf }, now());\n setMaskSource(\"whole\");\n setArea(undefined);\n setSurface(surf);\n }\n };\n\n if (mask) {\n // a given mask: its alpha is the area\n const s = snapshotPicture(mask);\n if (s) {\n const bits = new Uint8Array(s.w * s.h);\n for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;\n apply(bits, s.w, s.h, look_(), \"given\", true);\n }\n } else {\n startOn(look_());\n }\n\n // Compare what is on screen now with the first look: the difference is the part that changes.\n const learn = () => {\n if (mask) return;\n const cur = look_();\n if (!cur) return;\n if (live.current.maskKey !== L.key) {\n // another scene (a colour switch): never learn across it, and not from the old scene's picture still on screen\n L.staleSrc = L.lastSrc;\n L.key = live.current.maskKey;\n L.base = null;\n L.bits = null;\n L.shown = null;\n return;\n }\n if (L.staleSrc !== null) {\n if (L.lastSrc === L.staleSrc) return; // the new scene's picture has not painted yet\n L.staleSrc = null;\n return startOn(cur);\n }\n if (!L.base) return startOn(cur); // the picture was not readable at the start: begin now, with what is known\n const bits = changedBits(L.base, cur);\n if (!bits || coverageOf(bits) > UNRELIABLE_COVERAGE) {\n // another picture, not an edit of the first look (the store picture vs the first live frame, encoded, sized or\n // cropped differently): compare later frames with this one instead\n L.base = cur;\n return;\n }\n if (!isLearnable(bits)) return;\n const key = L.key;\n const all = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;\n L.bits = all;\n apply(all, cur.w, cur.h, L.base, \"learned\");\n };\n const learnTimer = setInterval(learn, LEARN_EVERY_MS);\n\n let raf = 0;\n const draw = () => {\n const c = canvasRef.current;\n const ctx = c?.getContext(\"2d\");\n if (!c || !ctx) return; // no 2D canvas here (a test DOM): nothing to draw, and no point asking again\n raf = requestAnimationFrame(draw);\n // device pixels, capped: the beam is soft, so a 5K frame needs no 15-megapixel canvas redrawn every frame\n const dpr = Math.min(2, (typeof window !== \"undefined\" && window.devicePixelRatio) || 1);\n const css = Math.max(1, c.clientWidth * c.clientHeight);\n const scale = Math.min(dpr, Math.sqrt(MAX_CANVAS_PIXELS / css));\n const W = Math.max(1, Math.round(c.clientWidth * scale)), H = Math.max(1, Math.round(c.clientHeight * scale));\n if (c.width !== W || c.height !== H) { c.width = W; c.height = H; }\n const n = L.natural;\n const place = n ? fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };\n engine.draw(ctx, W, H, place, now(), scale);\n if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;\n };\n if (typeof requestAnimationFrame === \"function\") raf = requestAnimationFrame(draw);\n\n learnNowRef.current = learn;\n return () => {\n clearInterval(learnTimer);\n if (typeof cancelAnimationFrame === \"function\") cancelAnimationFrame(raf);\n engineRef.current = null;\n learnNowRef.current = () => {};\n };\n // set up once per mount: a loader lives for one render-in-flight episode\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // caught up → the last pass, then onExited (a timer, so a hidden tab without animation frames still exits)\n useEffect(() => {\n const engine = engineRef.current;\n if (!engine) return;\n const now = typeof performance !== \"undefined\" ? performance.now() : Date.now();\n if (!visible) {\n learnNowRef.current();\n engine.finish(now);\n setPhase(\"finishing\");\n const t = setTimeout(() => live.current.onExited?.(), BEAM_FINISH_MS);\n return () => clearTimeout(t);\n }\n if (engine.motion.finishing) {\n engine.resume(now);\n setPhase(\"loading\");\n }\n return undefined;\n }, [visible]);\n\n return (\n <canvas\n ref={canvasRef}\n aria-hidden=\"true\"\n data-sc-loader=\"beam\"\n data-sc-loader-look={look}\n data-sc-loader-phase={phase}\n data-sc-loader-mask={maskSource}\n data-sc-loader-area={area}\n data-sc-loader-surface={surface}\n className={className}\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n // the starting blend; the draw loop keeps it in step with the beam (painted on a learned light surface)\n mixBlendMode: look === \"soft\" ? \"normal\" : \"screen\",\n ...style,\n }}\n />\n );\n}\n"]}
1
+ {"version":3,"sources":["../../src/beam/engine.ts","../../src/beam/BeamLoader.tsx"],"names":["p","g","useRef","useState","useEffect","naturalSize","snapshotPicture","meanLuma","softAlp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AO,CAAA;AAAA,QACP,KAAA,EAAO,MAAA;AAAA,QACP,MAAA,EAAQ,MAAA;AAAA,QACR,aAAA,EAAe,MAAA;AAAA;AAAA,QAEf,YAAA,EAAc,IAAA,KAAS,MAAA,GAAS,QAAA,GAAW,QAAA;AAAA,QAC3C,GAAG;AAAA;AACL;AAAA,GACF;AAEJ","file":"index.cjs","sourcesContent":["/**\n * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is\n * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.\n *\n * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into\n * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).\n */\nimport type { Rect } from \"../index\";\n\n/** The beam fades in over this long. */\nexport const BEAM_FADE_IN_MS = 450;\n/** One sweep from one side to the other while loading. */\nexport const BEAM_SWEEP_MS = 1150;\n/** The last pass, once the picture has caught up. */\nexport const BEAM_PASS_MS = 380;\n/** The fade after the last pass. */\nexport const BEAM_TAIL_MS = 150;\n/** The longest dash to the nearer edge before the last pass (from the middle). */\nexport const BEAM_RUSH_MAX_MS = 190;\n/** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */\nexport const BEAM_FINISH_MS = BEAM_RUSH_MAX_MS + BEAM_PASS_MS + BEAM_TAIL_MS;\n/** A newly learned area replaces the old one over this long (never a jump). */\nexport const REGION_FADE_MS = 300;\n\n/** The looks from the 1 Dec prototype: `beam` = \"Just the beam\" (light only, the default); `soft` = \"Soft laser\"\n * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */\nexport type BeamLook = \"beam\" | \"soft\" | \"prism\";\n/** The light's color: `auto` = a light version of the color of the part that changes (cool white until known). */\nexport type BeamTone = \"auto\" | \"cool\" | \"warm\" | `${number},${number},${number}`;\n\nconst TONES = { cool: \"190,222,255\", warm: \"255,150,60\" } as const;\n/** On a light surface light can't show (white + light = white): the beam is a colored laser painted on instead. */\nconst ON_LIGHT = { glow: \"70,140,255\", core: \"40,110,240\" } as const;\nconst FRINGES = [\"255,70,70\", \"255,170,40\", \"250,240,80\", \"70,220,110\", \"70,150,255\", \"160,90,255\"];\n\nconst clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));\nconst ease = (p: number) => 0.5 - 0.5 * Math.cos(Math.PI * clamp(p));\n\nexport interface BeamPosition {\n /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */\n s: number;\n /** Which way it moves. */\n dir: 1 | -1;\n /** Overall opacity, 0–1. */\n alpha: number;\n finishing: boolean;\n /** The exit is over: nothing to draw, the host may unmount. */\n done: boolean;\n}\n\n/** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */\nexport class BeamMotion {\n private t0: number;\n private ph0 = 0;\n /** When the beam started (its fade-in runs from here). */\n readonly bornAt: number;\n private fin: { at: number; from: number; end: 0 | 1; rush: number; alpha: number } | null = null;\n\n constructor(now: number) {\n this.t0 = now;\n this.bornAt = now;\n }\n\n get finishing(): boolean {\n return this.fin !== null;\n }\n\n private loading(now: number): { s: number; dir: 1 | -1 } {\n const ph = (((now - this.t0) / BEAM_SWEEP_MS + this.ph0) % 2 + 2) % 2;\n return ph < 1 ? { s: ease(ph), dir: 1 } : { s: ease(2 - ph), dir: -1 };\n }\n\n private fadeIn(now: number): number {\n const p = clamp((now - this.bornAt) / BEAM_FADE_IN_MS);\n return p * p;\n }\n\n at(now: number): BeamPosition {\n if (!this.fin) return { ...this.loading(now), alpha: this.fadeIn(now), finishing: false, done: false };\n const { at, from, end, rush, alpha } = this.fin;\n const t = now - at;\n if (t >= rush + BEAM_PASS_MS + BEAM_TAIL_MS) return { s: 1 - end, dir: end === 0 ? 1 : -1, alpha: 0, finishing: true, done: true };\n if (t < rush) {\n const p = t / rush;\n return { s: from + (end - from) * (1 - (1 - p) * (1 - p)), dir: end > from ? 1 : -1, alpha, finishing: true, done: false };\n }\n const p = (t - rush) / BEAM_PASS_MS;\n const s = p >= 1 ? 1 - end : end + (1 - 2 * end) * ease(p);\n // full through most of the pass, then gone by the end of the tail\n const fadeFrom = rush + BEAM_PASS_MS * 0.6, fadeLen = BEAM_PASS_MS * 0.4 + BEAM_TAIL_MS;\n const a = t <= fadeFrom ? alpha : alpha * (1 - clamp((t - fadeFrom) / fadeLen));\n return { s, dir: end === 0 ? 1 : -1, alpha: a, finishing: true, done: false };\n }\n\n /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */\n finish(now: number): void {\n if (this.fin) return;\n const cur = this.at(now);\n const end: 0 | 1 = cur.s < 0.5 ? 0 : 1;\n this.fin = { at: now, from: cur.s, end, rush: 60 + (BEAM_RUSH_MAX_MS - 60) * 2 * Math.abs(cur.s - end), alpha: cur.alpha };\n }\n\n /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */\n resume(now: number): void {\n if (!this.fin) return;\n const cur = this.at(now);\n this.fin = null;\n const ph = Math.acos(clamp(1 - 2 * cur.s, -1, 1)) / Math.PI; // ease(ph) = s\n this.ph0 = cur.dir > 0 ? ph : 2 - ph;\n this.t0 = now;\n }\n}\n\n/** The part of the picture the beam stays on. */\nexport interface BeamRegion {\n /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */\n mask: CanvasImageSource | null;\n /** The mask's box in picture space (0–1); `null` with no mask. */\n box: { x: number; y: number; w: number; h: number } | null;\n /** The color of the changing part, `\"r,g,b\"`, for `tone: \"auto\"`. */\n tone?: string;\n /** How light the surface under the area is: `light` (a white cup) gets a painted colored beam, `dark` light only. */\n surface?: \"light\" | \"dark\";\n}\n\nconst WHOLE: BeamRegion = { mask: null, box: null };\n\nexport interface BeamEngineOptions {\n look?: BeamLook;\n tone?: BeamTone;\n /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */\n reducedMotion?: boolean;\n}\n\n/** Draws the beam into a 2D canvas the size of the frame. */\nexport class BeamEngine {\n readonly motion: BeamMotion;\n readonly look: BeamLook;\n private readonly tone: BeamTone;\n private readonly reduced: boolean;\n private prev: BeamRegion = WHOLE;\n private next: BeamRegion = WHOLE;\n private regionAt = -Infinity;\n private maskLayer: HTMLCanvasElement | null = null;\n\n constructor(opts: BeamEngineOptions, now: number) {\n this.motion = new BeamMotion(now);\n this.look = opts.look ?? \"beam\";\n this.tone = opts.tone ?? \"auto\";\n this.reduced = !!opts.reducedMotion;\n }\n\n /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:\n * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */\n get onLight(): boolean {\n return !!this.next.mask && this.next.surface === \"light\";\n }\n\n /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a\n * light surface paint on. */\n get blendMode(): \"screen\" | \"normal\" {\n return this.look === \"soft\" || this.onLight ? \"normal\" : \"screen\";\n }\n\n /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in\n * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */\n setRegion(region: BeamRegion | null, now: number): void {\n const next = region ?? WHOLE;\n if (!this.next.mask && now - this.motion.bornAt < BEAM_FADE_IN_MS) {\n this.prev = this.next = next;\n this.regionAt = -Infinity;\n return;\n }\n this.prev = this.mixWeight(now) >= 1 ? this.next : this.prev;\n this.next = next;\n this.regionAt = now;\n }\n\n finish(now: number): void { this.motion.finish(now); }\n resume(now: number): void { this.motion.resume(now); }\n\n private mixWeight(now: number): number {\n return clamp((now - this.regionAt) / REGION_FADE_MS);\n }\n\n private rgb(): string {\n if (this.tone === \"cool\" || this.tone === \"warm\") return TONES[this.tone];\n if (this.tone !== \"auto\") return this.tone;\n if (this.onLight) return ON_LIGHT.glow;\n return this.next.tone ?? this.prev.tone ?? TONES.cool;\n }\n\n /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */\n private area(region: BeamRegion, place: Rect, W: number, H: number): Rect {\n if (!region.box) {\n const x0 = Math.max(0, place.x), y0 = Math.max(0, place.y);\n return { x: x0, y: y0, w: Math.min(W, place.x + place.w) - x0, h: Math.min(H, place.y + place.h) - y0 };\n }\n const b = region.box;\n return { x: place.x + b.x * place.w, y: place.y + b.y * place.h, w: b.w * place.w, h: b.h * place.h };\n }\n\n /**\n * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.\n * Returns `true` once the exit is over (the canvas is cleared).\n */\n draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr = 1): boolean {\n const pos = this.motion.at(now);\n ctx.globalCompositeOperation = \"source-over\";\n ctx.globalAlpha = 1;\n ctx.clearRect(0, 0, W, H);\n if (pos.done) return true;\n if (pos.alpha <= 0.001) return false;\n\n const t = this.mixWeight(now);\n const a0 = this.area(this.prev, place, W, H), a1 = this.area(this.next, place, W, H);\n const A: Rect = { x: a0.x + (a1.x - a0.x) * t, y: a0.y + (a1.y - a0.y) * t, w: a0.w + (a1.w - a0.w) * t, h: a0.h + (a1.h - a0.h) * t };\n const rgb = this.rgb();\n const pad = 10 * dpr, top = A.y - pad, tall = A.h + 2 * pad;\n\n ctx.globalAlpha = pos.alpha;\n if (this.reduced) {\n ctx.fillStyle = `rgba(${rgb},0.22)`;\n ctx.fillRect(0, 0, W, H);\n } else {\n const x = A.x + pos.s * A.w, back = -pos.dir;\n const light = this.look !== \"soft\";\n const painted = this.onLight;\n if (this.look === \"soft\") {\n ctx.fillStyle = \"rgba(255,255,255,0.10)\";\n ctx.fillRect(0, 0, W, H);\n const T = A.w * 0.22, g = ctx.createLinearGradient(x + back * T, 0, x, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(1, `rgba(${rgb},0.22)`);\n ctx.fillStyle = g;\n ctx.fillRect(Math.min(x, x + back * T), top, T, tall);\n }\n if (this.look === \"prism\") {\n FRINGES.forEach((c, i) => {\n ctx.fillStyle = `rgba(${c},${0.55 - i * 0.04})`;\n ctx.fillRect(x + back * (6 + i * 7) * dpr * (pos.finishing ? 1.5 : 1) - 2.5 * dpr, top, 5 * dpr, tall);\n });\n }\n const gw = (light ? 18 : 26) * dpr;\n const g = ctx.createLinearGradient(x - gw, 0, x + gw, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(0.5, `rgba(${rgb},${painted ? 0.45 : light ? 0.85 : 0.75})`);\n g.addColorStop(1, `rgba(${rgb},0)`);\n ctx.fillStyle = g;\n ctx.fillRect(x - gw, top, 2 * gw, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.85)` : \"rgba(255,255,255,0.95)\";\n ctx.fillRect(x - dpr, top, 2 * dpr, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.7)` : \"rgba(255,245,225,0.9)\";\n const sparks = light ? 10 : 14;\n for (let i = 0; i < sparks; i++) {\n ctx.globalAlpha = pos.alpha * Math.random();\n ctx.fillRect(x + (Math.random() - 0.5) * 16 * dpr, A.y + Math.random() * A.h, 1.6 * dpr, 1.6 * dpr);\n }\n ctx.globalAlpha = pos.alpha;\n }\n\n // cut to the area: the old region fading into the new one\n const layer = this.maskOf(W, H, place, t);\n if (layer) {\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = \"destination-in\";\n ctx.drawImage(layer, 0, 0);\n ctx.globalCompositeOperation = \"source-over\";\n }\n return false;\n }\n\n private maskOf(W: number, H: number, place: Rect, t: number): HTMLCanvasElement | null {\n if (!this.prev.mask && !this.next.mask) return null; // the whole frame: nothing to cut\n if (typeof document === \"undefined\") return null;\n this.maskLayer ??= document.createElement(\"canvas\");\n const m = this.maskLayer;\n if (m.width !== W || m.height !== H) { m.width = W; m.height = H; }\n const x = m.getContext(\"2d\");\n if (!x) return null;\n x.globalAlpha = 1;\n x.clearRect(0, 0, W, H);\n for (const [r, a] of [[this.prev, 1 - t], [this.next, t]] as const) {\n if (a <= 0) continue;\n x.globalAlpha = a;\n if (r.mask) x.drawImage(r.mask, place.x, place.y, place.w, place.h);\n else x.fillRect(0, 0, W, H);\n }\n x.globalAlpha = 1;\n return m;\n }\n}\n","\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { fitRect, naturalSize, type LoaderMaskSource, type LoaderPhase, type LoaderProps } from \"../index\";\nimport {\n alphaBox,\n alphaCanvas,\n changedBits,\n coverageOf,\n isLearnable,\n meanLuma,\n meanColour,\n orBits,\n recallMask,\n rememberMask,\n snapshotPicture,\n softAlpha,\n type Snapshot,\n UNRELIABLE_COVERAGE,\n} from \"../mask\";\nimport { BEAM_FINISH_MS, BeamEngine, type BeamLook, type BeamTone } from \"./engine\";\n\n/** How often the picture is compared with its first look while loading. */\nexport const LEARN_EVERY_MS = 250;\n/** A learned area moves on screen at most this often... */\nexport const REGION_STEADY_MS = 600;\n/** ...and only when an edge moves out by more than this share of the picture (an area only grows within an episode). */\nexport const REGION_MIN_MOVE = 0.02;\n/** A surface brighter than this (0–1) is light: the beam is painted on it, not added as light. */\nexport const LIGHT_SURFACE = 0.62;\n/** The beam's canvas never has more pixels than this (it is soft: CSS scales it up). */\nexport const MAX_CANVAS_PIXELS = 2_500_000;\n\nexport interface BeamLoaderProps extends LoaderProps {\n /** `\"beam\"` (default): light only. `\"soft\"`: a faint haze and a trail, painted on. `\"prism\"`: rainbow fringes. */\n look?: BeamLook;\n /** The light's color. `\"auto\"` (default): a light version of the color of the part that changes. */\n tone?: BeamTone;\n}\n\n/** A light version of a color: the beam reads as light on that material (warm on wood, mint on a green cup). */\nfunction lightTone([r, g, b]: [number, number, number]): string {\n return [r, g, b].map((v) => Math.round(v + (255 - v) * 0.6)).join(\",\");\n}\n\n/**\n * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next\n * render is on the way; one last pass across and a fade once it has caught up.\n *\n * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it\n * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per\n * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.\n *\n * Machine-readable state: `data-sc-loader=\"beam\"`, `data-sc-loader-phase` (`loading` | `finishing`),\n * `data-sc-loader-mask` (`whole` | `learned` | `given`).\n */\nexport function BeamLoader({\n visible,\n onExited,\n picture,\n maskKey,\n fit = \"cover\",\n mask,\n look = \"beam\",\n tone = \"auto\",\n className,\n style,\n}: BeamLoaderProps) {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const engineRef = useRef<BeamEngine | null>(null);\n // one last comparison when the picture has caught up (set by the mount effect)\n const learnNowRef = useRef<() => void>(() => {});\n const [phase, setPhase] = useState<LoaderPhase>(\"loading\");\n const [maskSource, setMaskSource] = useState<LoaderMaskSource>(mask ? \"given\" : \"whole\");\n\n // the latest props, for the loops below (they are set up once)\n const live = useRef({ picture, maskKey, fit, onExited });\n live.current = { picture, maskKey, fit, onExited };\n\n // the area on screen, stamped for agents: data-sc-loader-area (picture space) and data-sc-loader-surface\n const [area, setArea] = useState<string | undefined>(undefined);\n const [surface, setSurface] = useState<\"light\" | \"dark\" | undefined>(undefined);\n\n useEffect(() => {\n const now = () => (typeof performance !== \"undefined\" ? performance.now() : Date.now());\n const reduced = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const engine = new BeamEngine({ look, tone, reducedMotion: reduced }, now());\n engineRef.current = engine;\n const pic = () => live.current.picture?.() ?? null;\n\n // What this episode knows. `base` is the first look the frames are compared with; `shown` the area on screen.\n const L = {\n key: live.current.maskKey,\n base: null as Snapshot | null,\n bits: null as Uint8Array | null,\n natural: null as { w: number; h: number } | null,\n lastSrc: \"\",\n /** After a scene change (a color switch): the picture on screen then is still the OLD scene's; learning waits\n * until another picture has painted. A base taken from it learned \"the whole cup changed\" for the new scene. */\n staleSrc: null as string | null,\n lastSnap: null as Snapshot | null,\n shown: null as { x: number; y: number; w: number; h: number } | null,\n shownAt: -Infinity,\n };\n const srcOf = (el: ReturnType<typeof pic>) =>\n el && typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement ? el.currentSrc || el.src : \"\";\n // A new snapshot only when a new picture is on screen (a frame arrived): reading a 5K frame is not free.\n const look_ = () => {\n const el = pic();\n if (!el) return null;\n const n = naturalSize(el);\n if (n.w > 0) L.natural = n;\n const src = srcOf(el);\n if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;\n const snap = snapshotPicture(el);\n if (snap) { L.lastSrc = src; L.lastSnap = snap; }\n return snap;\n };\n const surfaceOf = (s: Snapshot | null, alpha?: Float32Array | null) => (s ? (meanLuma(s, alpha) > LIGHT_SURFACE ? \"light\" : \"dark\") : undefined);\n\n /** Shows a learned area. Steady on purpose: a small change, or one sooner than REGION_STEADY_MS after the last,\n * keeps the area on screen as it is (it moving under the beam read as the beam fading out and back elsewhere). */\n const apply = (bits: Uint8Array, w: number, h: number, from: Snapshot | null, source: LoaderMaskSource, force = false) => {\n const alpha = softAlpha(bits, w, h, { grow: 4, blur: 6 });\n const box = alphaBox(alpha, w, h);\n if (!box) return;\n const t = now();\n if (!force) {\n if (engine.motion.finishing) return;\n const p = L.shown;\n if (p) {\n // only outward: the area grows as more of the picture is seen changing, never twitches back in\n const moved = Math.max(p.x - box.x, p.y - box.y, box.x + box.w - p.x - p.w, box.y + box.h - p.y - p.h);\n if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;\n }\n }\n const colour = from ? meanColour(from, bits) : null;\n const surf = surfaceOf(from, alpha);\n engine.setRegion({ mask: alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : undefined, surface: surf }, t);\n L.shown = box;\n L.shownAt = t;\n setMaskSource(source);\n setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(\",\"));\n setSurface(surf);\n };\n /** Starts over on what is known about the scene now on screen (mount, or a color switch swapped the picture). */\n const startOn = (snap: Snapshot | null) => {\n L.key = live.current.maskKey;\n L.base = snap;\n L.bits = null;\n L.shown = null;\n const known = snap && L.key ? recallMask(L.key, snap.w, snap.h) : null;\n if (known && snap) {\n L.bits = known;\n apply(known, snap.w, snap.h, snap, \"learned\", true);\n } else {\n const surf = surfaceOf(snap);\n engine.setRegion({ mask: null, box: null, surface: surf }, now());\n setMaskSource(\"whole\");\n setArea(undefined);\n setSurface(surf);\n }\n };\n\n if (mask) {\n // a given mask: its alpha is the area\n const s = snapshotPicture(mask);\n if (s) {\n const bits = new Uint8Array(s.w * s.h);\n for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;\n apply(bits, s.w, s.h, look_(), \"given\", true);\n }\n } else {\n startOn(look_());\n }\n\n // Compare what is on screen now with the first look: the difference is the part that changes.\n const learn = () => {\n if (mask) return;\n const cur = look_();\n if (!cur) return;\n if (live.current.maskKey !== L.key) {\n // another scene (a color switch): never learn across it, and not from the old scene's picture still on screen\n L.staleSrc = L.lastSrc;\n L.key = live.current.maskKey;\n L.base = null;\n L.bits = null;\n L.shown = null;\n return;\n }\n if (L.staleSrc !== null) {\n if (L.lastSrc === L.staleSrc) return; // the new scene's picture has not painted yet\n L.staleSrc = null;\n return startOn(cur);\n }\n if (!L.base) return startOn(cur); // the picture was not readable at the start: begin now, with what is known\n const bits = changedBits(L.base, cur);\n if (!bits || coverageOf(bits) > UNRELIABLE_COVERAGE) {\n // another picture, not an edit of the first look (the store picture vs the first live frame, encoded, sized or\n // cropped differently): compare later frames with this one instead\n L.base = cur;\n return;\n }\n if (!isLearnable(bits)) return;\n const key = L.key;\n const all = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;\n L.bits = all;\n apply(all, cur.w, cur.h, L.base, \"learned\");\n };\n const learnTimer = setInterval(learn, LEARN_EVERY_MS);\n\n let raf = 0;\n const draw = () => {\n const c = canvasRef.current;\n const ctx = c?.getContext(\"2d\");\n if (!c || !ctx) return; // no 2D canvas here (a test DOM): nothing to draw, and no point asking again\n raf = requestAnimationFrame(draw);\n // device pixels, capped: the beam is soft, so a 5K frame needs no 15-megapixel canvas redrawn every frame\n const dpr = Math.min(2, (typeof window !== \"undefined\" && window.devicePixelRatio) || 1);\n const css = Math.max(1, c.clientWidth * c.clientHeight);\n const scale = Math.min(dpr, Math.sqrt(MAX_CANVAS_PIXELS / css));\n const W = Math.max(1, Math.round(c.clientWidth * scale)), H = Math.max(1, Math.round(c.clientHeight * scale));\n if (c.width !== W || c.height !== H) { c.width = W; c.height = H; }\n const n = L.natural;\n const place = n ? fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };\n engine.draw(ctx, W, H, place, now(), scale);\n if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;\n };\n if (typeof requestAnimationFrame === \"function\") raf = requestAnimationFrame(draw);\n\n learnNowRef.current = learn;\n return () => {\n clearInterval(learnTimer);\n if (typeof cancelAnimationFrame === \"function\") cancelAnimationFrame(raf);\n engineRef.current = null;\n learnNowRef.current = () => {};\n };\n // set up once per mount: a loader lives for one render-in-flight episode\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // caught up → the last pass, then onExited (a timer, so a hidden tab without animation frames still exits)\n useEffect(() => {\n const engine = engineRef.current;\n if (!engine) return;\n const now = typeof performance !== \"undefined\" ? performance.now() : Date.now();\n if (!visible) {\n learnNowRef.current();\n engine.finish(now);\n setPhase(\"finishing\");\n const t = setTimeout(() => live.current.onExited?.(), BEAM_FINISH_MS);\n return () => clearTimeout(t);\n }\n if (engine.motion.finishing) {\n engine.resume(now);\n setPhase(\"loading\");\n }\n return undefined;\n }, [visible]);\n\n return (\n <canvas\n ref={canvasRef}\n aria-hidden=\"true\"\n data-sc-loader=\"beam\"\n data-sc-loader-look={look}\n data-sc-loader-phase={phase}\n data-sc-loader-mask={maskSource}\n data-sc-loader-area={area}\n data-sc-loader-surface={surface}\n className={className}\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n // the starting blend; the draw loop keeps it in step with the beam (painted on a learned light surface)\n mixBlendMode: look === \"soft\" ? \"normal\" : \"screen\",\n ...style,\n }}\n />\n );\n}\n"]}
@@ -27,7 +27,7 @@ declare const REGION_FADE_MS = 300;
27
27
  /** The looks from the 1 Dec prototype: `beam` = "Just the beam" (light only, the default); `soft` = "Soft laser"
28
28
  * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */
29
29
  type BeamLook = "beam" | "soft" | "prism";
30
- /** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */
30
+ /** The light's color: `auto` = a light version of the color of the part that changes (cool white until known). */
31
31
  type BeamTone = "auto" | "cool" | "warm" | `${number},${number},${number}`;
32
32
  interface BeamPosition {
33
33
  /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */
@@ -68,9 +68,9 @@ interface BeamRegion {
68
68
  w: number;
69
69
  h: number;
70
70
  } | null;
71
- /** The colour of the changing part, `"r,g,b"`, for `tone: "auto"`. */
71
+ /** The color of the changing part, `"r,g,b"`, for `tone: "auto"`. */
72
72
  tone?: string;
73
- /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */
73
+ /** How light the surface under the area is: `light` (a white cup) gets a painted colored beam, `dark` light only. */
74
74
  surface?: "light" | "dark";
75
75
  }
76
76
  interface BeamEngineOptions {
@@ -90,7 +90,7 @@ declare class BeamEngine {
90
90
  private regionAt;
91
91
  private maskLayer;
92
92
  constructor(opts: BeamEngineOptions, now: number);
93
- /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
93
+ /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:
94
94
  * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
95
95
  get onLight(): boolean;
96
96
  /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a
@@ -118,7 +118,7 @@ declare const LEARN_EVERY_MS = 250;
118
118
  interface BeamLoaderProps extends LoaderProps {
119
119
  /** `"beam"` (default): light only. `"soft"`: a faint haze and a trail, painted on. `"prism"`: rainbow fringes. */
120
120
  look?: BeamLook;
121
- /** The light's colour. `"auto"` (default): a light version of the colour of the part that changes. */
121
+ /** The light's color. `"auto"` (default): a light version of the color of the part that changes. */
122
122
  tone?: BeamTone;
123
123
  }
124
124
  /**
@@ -27,7 +27,7 @@ declare const REGION_FADE_MS = 300;
27
27
  /** The looks from the 1 Dec prototype: `beam` = "Just the beam" (light only, the default); `soft` = "Soft laser"
28
28
  * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */
29
29
  type BeamLook = "beam" | "soft" | "prism";
30
- /** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */
30
+ /** The light's color: `auto` = a light version of the color of the part that changes (cool white until known). */
31
31
  type BeamTone = "auto" | "cool" | "warm" | `${number},${number},${number}`;
32
32
  interface BeamPosition {
33
33
  /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */
@@ -68,9 +68,9 @@ interface BeamRegion {
68
68
  w: number;
69
69
  h: number;
70
70
  } | null;
71
- /** The colour of the changing part, `"r,g,b"`, for `tone: "auto"`. */
71
+ /** The color of the changing part, `"r,g,b"`, for `tone: "auto"`. */
72
72
  tone?: string;
73
- /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */
73
+ /** How light the surface under the area is: `light` (a white cup) gets a painted colored beam, `dark` light only. */
74
74
  surface?: "light" | "dark";
75
75
  }
76
76
  interface BeamEngineOptions {
@@ -90,7 +90,7 @@ declare class BeamEngine {
90
90
  private regionAt;
91
91
  private maskLayer;
92
92
  constructor(opts: BeamEngineOptions, now: number);
93
- /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
93
+ /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:
94
94
  * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
95
95
  get onLight(): boolean;
96
96
  /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a
@@ -118,7 +118,7 @@ declare const LEARN_EVERY_MS = 250;
118
118
  interface BeamLoaderProps extends LoaderProps {
119
119
  /** `"beam"` (default): light only. `"soft"`: a faint haze and a trail, painted on. `"prism"`: rainbow fringes. */
120
120
  look?: BeamLook;
121
- /** The light's colour. `"auto"` (default): a light version of the colour of the part that changes. */
121
+ /** The light's color. `"auto"` (default): a light version of the color of the part that changes. */
122
122
  tone?: BeamTone;
123
123
  }
124
124
  /**
@@ -1,4 +1,4 @@
1
- import { snapshotPicture, softAlpha, alphaBox, meanColour, alphaCanvas, recallMask, changedBits, coverageOf, UNRELIABLE_COVERAGE, isLearnable, rememberMask, orBits, meanLuma } from '../chunk-A3PAVGM3.js';
1
+ import { snapshotPicture, softAlpha, alphaBox, meanColour, alphaCanvas, recallMask, changedBits, coverageOf, UNRELIABLE_COVERAGE, isLearnable, rememberMask, orBits, meanLuma } from '../chunk-JJVBRZTY.js';
2
2
  import { naturalSize, fitRect } from '../chunk-6IWUTOBS.js';
3
3
  import { useRef, useState, useEffect } from 'react';
4
4
  import { jsx } from 'react/jsx-runtime';
@@ -85,7 +85,7 @@ var BeamEngine = class {
85
85
  this.tone = opts.tone ?? "auto";
86
86
  this.reduced = !!opts.reducedMotion;
87
87
  }
88
- /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:
88
+ /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:
89
89
  * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
90
90
  get onLight() {
91
91
  return !!this.next.mask && this.next.surface === "light";
@@ -262,7 +262,7 @@ function BeamLoader({
262
262
  bits: null,
263
263
  natural: null,
264
264
  lastSrc: "",
265
- /** After a scene change (a colour switch): the picture on screen then is still the OLD scene's; learning waits
265
+ /** After a scene change (a color switch): the picture on screen then is still the OLD scene's; learning waits
266
266
  * until another picture has painted. A base taken from it learned "the whole cup changed" for the new scene. */
267
267
  staleSrc: null,
268
268
  lastSnap: null,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/beam/engine.ts","../../src/beam/BeamLoader.tsx"],"names":["p","g"],"mappings":";;;;;;AAUO,IAAM,eA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AAA,QAC3C,GAAG;AAAA;AACL;AAAA,GACF;AAEJ","file":"index.js","sourcesContent":["/**\n * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is\n * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.\n *\n * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into\n * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).\n */\nimport type { Rect } from \"../index\";\n\n/** The beam fades in over this long. */\nexport const BEAM_FADE_IN_MS = 450;\n/** One sweep from one side to the other while loading. */\nexport const BEAM_SWEEP_MS = 1150;\n/** The last pass, once the picture has caught up. */\nexport const BEAM_PASS_MS = 380;\n/** The fade after the last pass. */\nexport const BEAM_TAIL_MS = 150;\n/** The longest dash to the nearer edge before the last pass (from the middle). */\nexport const BEAM_RUSH_MAX_MS = 190;\n/** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */\nexport const BEAM_FINISH_MS = BEAM_RUSH_MAX_MS + BEAM_PASS_MS + BEAM_TAIL_MS;\n/** A newly learned area replaces the old one over this long (never a jump). */\nexport const REGION_FADE_MS = 300;\n\n/** The looks from the 1 Dec prototype: `beam` = \"Just the beam\" (light only, the default); `soft` = \"Soft laser\"\n * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */\nexport type BeamLook = \"beam\" | \"soft\" | \"prism\";\n/** The light's colour: `auto` = a light version of the colour of the part that changes (cool white until known). */\nexport type BeamTone = \"auto\" | \"cool\" | \"warm\" | `${number},${number},${number}`;\n\nconst TONES = { cool: \"190,222,255\", warm: \"255,150,60\" } as const;\n/** On a light surface light can't show (white + light = white): the beam is a coloured laser painted on instead. */\nconst ON_LIGHT = { glow: \"70,140,255\", core: \"40,110,240\" } as const;\nconst FRINGES = [\"255,70,70\", \"255,170,40\", \"250,240,80\", \"70,220,110\", \"70,150,255\", \"160,90,255\"];\n\nconst clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));\nconst ease = (p: number) => 0.5 - 0.5 * Math.cos(Math.PI * clamp(p));\n\nexport interface BeamPosition {\n /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */\n s: number;\n /** Which way it moves. */\n dir: 1 | -1;\n /** Overall opacity, 0–1. */\n alpha: number;\n finishing: boolean;\n /** The exit is over: nothing to draw, the host may unmount. */\n done: boolean;\n}\n\n/** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */\nexport class BeamMotion {\n private t0: number;\n private ph0 = 0;\n /** When the beam started (its fade-in runs from here). */\n readonly bornAt: number;\n private fin: { at: number; from: number; end: 0 | 1; rush: number; alpha: number } | null = null;\n\n constructor(now: number) {\n this.t0 = now;\n this.bornAt = now;\n }\n\n get finishing(): boolean {\n return this.fin !== null;\n }\n\n private loading(now: number): { s: number; dir: 1 | -1 } {\n const ph = (((now - this.t0) / BEAM_SWEEP_MS + this.ph0) % 2 + 2) % 2;\n return ph < 1 ? { s: ease(ph), dir: 1 } : { s: ease(2 - ph), dir: -1 };\n }\n\n private fadeIn(now: number): number {\n const p = clamp((now - this.bornAt) / BEAM_FADE_IN_MS);\n return p * p;\n }\n\n at(now: number): BeamPosition {\n if (!this.fin) return { ...this.loading(now), alpha: this.fadeIn(now), finishing: false, done: false };\n const { at, from, end, rush, alpha } = this.fin;\n const t = now - at;\n if (t >= rush + BEAM_PASS_MS + BEAM_TAIL_MS) return { s: 1 - end, dir: end === 0 ? 1 : -1, alpha: 0, finishing: true, done: true };\n if (t < rush) {\n const p = t / rush;\n return { s: from + (end - from) * (1 - (1 - p) * (1 - p)), dir: end > from ? 1 : -1, alpha, finishing: true, done: false };\n }\n const p = (t - rush) / BEAM_PASS_MS;\n const s = p >= 1 ? 1 - end : end + (1 - 2 * end) * ease(p);\n // full through most of the pass, then gone by the end of the tail\n const fadeFrom = rush + BEAM_PASS_MS * 0.6, fadeLen = BEAM_PASS_MS * 0.4 + BEAM_TAIL_MS;\n const a = t <= fadeFrom ? alpha : alpha * (1 - clamp((t - fadeFrom) / fadeLen));\n return { s, dir: end === 0 ? 1 : -1, alpha: a, finishing: true, done: false };\n }\n\n /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */\n finish(now: number): void {\n if (this.fin) return;\n const cur = this.at(now);\n const end: 0 | 1 = cur.s < 0.5 ? 0 : 1;\n this.fin = { at: now, from: cur.s, end, rush: 60 + (BEAM_RUSH_MAX_MS - 60) * 2 * Math.abs(cur.s - end), alpha: cur.alpha };\n }\n\n /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */\n resume(now: number): void {\n if (!this.fin) return;\n const cur = this.at(now);\n this.fin = null;\n const ph = Math.acos(clamp(1 - 2 * cur.s, -1, 1)) / Math.PI; // ease(ph) = s\n this.ph0 = cur.dir > 0 ? ph : 2 - ph;\n this.t0 = now;\n }\n}\n\n/** The part of the picture the beam stays on. */\nexport interface BeamRegion {\n /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */\n mask: CanvasImageSource | null;\n /** The mask's box in picture space (0–1); `null` with no mask. */\n box: { x: number; y: number; w: number; h: number } | null;\n /** The colour of the changing part, `\"r,g,b\"`, for `tone: \"auto\"`. */\n tone?: string;\n /** How light the surface under the area is: `light` (a white cup) gets a painted coloured beam, `dark` light only. */\n surface?: \"light\" | \"dark\";\n}\n\nconst WHOLE: BeamRegion = { mask: null, box: null };\n\nexport interface BeamEngineOptions {\n look?: BeamLook;\n tone?: BeamTone;\n /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */\n reducedMotion?: boolean;\n}\n\n/** Draws the beam into a 2D canvas the size of the frame. */\nexport class BeamEngine {\n readonly motion: BeamMotion;\n readonly look: BeamLook;\n private readonly tone: BeamTone;\n private readonly reduced: boolean;\n private prev: BeamRegion = WHOLE;\n private next: BeamRegion = WHOLE;\n private regionAt = -Infinity;\n private maskLayer: HTMLCanvasElement | null = null;\n\n constructor(opts: BeamEngineOptions, now: number) {\n this.motion = new BeamMotion(now);\n this.look = opts.look ?? \"beam\";\n this.tone = opts.tone ?? \"auto\";\n this.reduced = !!opts.reducedMotion;\n }\n\n /** On a light surface the beam is painted (a coloured line); on a dark one it is light. Only once the area is known:\n * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */\n get onLight(): boolean {\n return !!this.next.mask && this.next.surface === \"light\";\n }\n\n /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a\n * light surface paint on. */\n get blendMode(): \"screen\" | \"normal\" {\n return this.look === \"soft\" || this.onLight ? \"normal\" : \"screen\";\n }\n\n /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in\n * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */\n setRegion(region: BeamRegion | null, now: number): void {\n const next = region ?? WHOLE;\n if (!this.next.mask && now - this.motion.bornAt < BEAM_FADE_IN_MS) {\n this.prev = this.next = next;\n this.regionAt = -Infinity;\n return;\n }\n this.prev = this.mixWeight(now) >= 1 ? this.next : this.prev;\n this.next = next;\n this.regionAt = now;\n }\n\n finish(now: number): void { this.motion.finish(now); }\n resume(now: number): void { this.motion.resume(now); }\n\n private mixWeight(now: number): number {\n return clamp((now - this.regionAt) / REGION_FADE_MS);\n }\n\n private rgb(): string {\n if (this.tone === \"cool\" || this.tone === \"warm\") return TONES[this.tone];\n if (this.tone !== \"auto\") return this.tone;\n if (this.onLight) return ON_LIGHT.glow;\n return this.next.tone ?? this.prev.tone ?? TONES.cool;\n }\n\n /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */\n private area(region: BeamRegion, place: Rect, W: number, H: number): Rect {\n if (!region.box) {\n const x0 = Math.max(0, place.x), y0 = Math.max(0, place.y);\n return { x: x0, y: y0, w: Math.min(W, place.x + place.w) - x0, h: Math.min(H, place.y + place.h) - y0 };\n }\n const b = region.box;\n return { x: place.x + b.x * place.w, y: place.y + b.y * place.h, w: b.w * place.w, h: b.h * place.h };\n }\n\n /**\n * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.\n * Returns `true` once the exit is over (the canvas is cleared).\n */\n draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr = 1): boolean {\n const pos = this.motion.at(now);\n ctx.globalCompositeOperation = \"source-over\";\n ctx.globalAlpha = 1;\n ctx.clearRect(0, 0, W, H);\n if (pos.done) return true;\n if (pos.alpha <= 0.001) return false;\n\n const t = this.mixWeight(now);\n const a0 = this.area(this.prev, place, W, H), a1 = this.area(this.next, place, W, H);\n const A: Rect = { x: a0.x + (a1.x - a0.x) * t, y: a0.y + (a1.y - a0.y) * t, w: a0.w + (a1.w - a0.w) * t, h: a0.h + (a1.h - a0.h) * t };\n const rgb = this.rgb();\n const pad = 10 * dpr, top = A.y - pad, tall = A.h + 2 * pad;\n\n ctx.globalAlpha = pos.alpha;\n if (this.reduced) {\n ctx.fillStyle = `rgba(${rgb},0.22)`;\n ctx.fillRect(0, 0, W, H);\n } else {\n const x = A.x + pos.s * A.w, back = -pos.dir;\n const light = this.look !== \"soft\";\n const painted = this.onLight;\n if (this.look === \"soft\") {\n ctx.fillStyle = \"rgba(255,255,255,0.10)\";\n ctx.fillRect(0, 0, W, H);\n const T = A.w * 0.22, g = ctx.createLinearGradient(x + back * T, 0, x, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(1, `rgba(${rgb},0.22)`);\n ctx.fillStyle = g;\n ctx.fillRect(Math.min(x, x + back * T), top, T, tall);\n }\n if (this.look === \"prism\") {\n FRINGES.forEach((c, i) => {\n ctx.fillStyle = `rgba(${c},${0.55 - i * 0.04})`;\n ctx.fillRect(x + back * (6 + i * 7) * dpr * (pos.finishing ? 1.5 : 1) - 2.5 * dpr, top, 5 * dpr, tall);\n });\n }\n const gw = (light ? 18 : 26) * dpr;\n const g = ctx.createLinearGradient(x - gw, 0, x + gw, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(0.5, `rgba(${rgb},${painted ? 0.45 : light ? 0.85 : 0.75})`);\n g.addColorStop(1, `rgba(${rgb},0)`);\n ctx.fillStyle = g;\n ctx.fillRect(x - gw, top, 2 * gw, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.85)` : \"rgba(255,255,255,0.95)\";\n ctx.fillRect(x - dpr, top, 2 * dpr, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.7)` : \"rgba(255,245,225,0.9)\";\n const sparks = light ? 10 : 14;\n for (let i = 0; i < sparks; i++) {\n ctx.globalAlpha = pos.alpha * Math.random();\n ctx.fillRect(x + (Math.random() - 0.5) * 16 * dpr, A.y + Math.random() * A.h, 1.6 * dpr, 1.6 * dpr);\n }\n ctx.globalAlpha = pos.alpha;\n }\n\n // cut to the area: the old region fading into the new one\n const layer = this.maskOf(W, H, place, t);\n if (layer) {\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = \"destination-in\";\n ctx.drawImage(layer, 0, 0);\n ctx.globalCompositeOperation = \"source-over\";\n }\n return false;\n }\n\n private maskOf(W: number, H: number, place: Rect, t: number): HTMLCanvasElement | null {\n if (!this.prev.mask && !this.next.mask) return null; // the whole frame: nothing to cut\n if (typeof document === \"undefined\") return null;\n this.maskLayer ??= document.createElement(\"canvas\");\n const m = this.maskLayer;\n if (m.width !== W || m.height !== H) { m.width = W; m.height = H; }\n const x = m.getContext(\"2d\");\n if (!x) return null;\n x.globalAlpha = 1;\n x.clearRect(0, 0, W, H);\n for (const [r, a] of [[this.prev, 1 - t], [this.next, t]] as const) {\n if (a <= 0) continue;\n x.globalAlpha = a;\n if (r.mask) x.drawImage(r.mask, place.x, place.y, place.w, place.h);\n else x.fillRect(0, 0, W, H);\n }\n x.globalAlpha = 1;\n return m;\n }\n}\n","\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { fitRect, naturalSize, type LoaderMaskSource, type LoaderPhase, type LoaderProps } from \"../index\";\nimport {\n alphaBox,\n alphaCanvas,\n changedBits,\n coverageOf,\n isLearnable,\n meanLuma,\n meanColour,\n orBits,\n recallMask,\n rememberMask,\n snapshotPicture,\n softAlpha,\n type Snapshot,\n UNRELIABLE_COVERAGE,\n} from \"../mask\";\nimport { BEAM_FINISH_MS, BeamEngine, type BeamLook, type BeamTone } from \"./engine\";\n\n/** How often the picture is compared with its first look while loading. */\nexport const LEARN_EVERY_MS = 250;\n/** A learned area moves on screen at most this often... */\nexport const REGION_STEADY_MS = 600;\n/** ...and only when an edge moves out by more than this share of the picture (an area only grows within an episode). */\nexport const REGION_MIN_MOVE = 0.02;\n/** A surface brighter than this (0–1) is light: the beam is painted on it, not added as light. */\nexport const LIGHT_SURFACE = 0.62;\n/** The beam's canvas never has more pixels than this (it is soft: CSS scales it up). */\nexport const MAX_CANVAS_PIXELS = 2_500_000;\n\nexport interface BeamLoaderProps extends LoaderProps {\n /** `\"beam\"` (default): light only. `\"soft\"`: a faint haze and a trail, painted on. `\"prism\"`: rainbow fringes. */\n look?: BeamLook;\n /** The light's colour. `\"auto\"` (default): a light version of the colour of the part that changes. */\n tone?: BeamTone;\n}\n\n/** A light version of a colour: the beam reads as light on that material (warm on wood, mint on a green cup). */\nfunction lightTone([r, g, b]: [number, number, number]): string {\n return [r, g, b].map((v) => Math.round(v + (255 - v) * 0.6)).join(\",\");\n}\n\n/**\n * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next\n * render is on the way; one last pass across and a fade once it has caught up.\n *\n * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it\n * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per\n * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.\n *\n * Machine-readable state: `data-sc-loader=\"beam\"`, `data-sc-loader-phase` (`loading` | `finishing`),\n * `data-sc-loader-mask` (`whole` | `learned` | `given`).\n */\nexport function BeamLoader({\n visible,\n onExited,\n picture,\n maskKey,\n fit = \"cover\",\n mask,\n look = \"beam\",\n tone = \"auto\",\n className,\n style,\n}: BeamLoaderProps) {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const engineRef = useRef<BeamEngine | null>(null);\n // one last comparison when the picture has caught up (set by the mount effect)\n const learnNowRef = useRef<() => void>(() => {});\n const [phase, setPhase] = useState<LoaderPhase>(\"loading\");\n const [maskSource, setMaskSource] = useState<LoaderMaskSource>(mask ? \"given\" : \"whole\");\n\n // the latest props, for the loops below (they are set up once)\n const live = useRef({ picture, maskKey, fit, onExited });\n live.current = { picture, maskKey, fit, onExited };\n\n // the area on screen, stamped for agents: data-sc-loader-area (picture space) and data-sc-loader-surface\n const [area, setArea] = useState<string | undefined>(undefined);\n const [surface, setSurface] = useState<\"light\" | \"dark\" | undefined>(undefined);\n\n useEffect(() => {\n const now = () => (typeof performance !== \"undefined\" ? performance.now() : Date.now());\n const reduced = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const engine = new BeamEngine({ look, tone, reducedMotion: reduced }, now());\n engineRef.current = engine;\n const pic = () => live.current.picture?.() ?? null;\n\n // What this episode knows. `base` is the first look the frames are compared with; `shown` the area on screen.\n const L = {\n key: live.current.maskKey,\n base: null as Snapshot | null,\n bits: null as Uint8Array | null,\n natural: null as { w: number; h: number } | null,\n lastSrc: \"\",\n /** After a scene change (a colour switch): the picture on screen then is still the OLD scene's; learning waits\n * until another picture has painted. A base taken from it learned \"the whole cup changed\" for the new scene. */\n staleSrc: null as string | null,\n lastSnap: null as Snapshot | null,\n shown: null as { x: number; y: number; w: number; h: number } | null,\n shownAt: -Infinity,\n };\n const srcOf = (el: ReturnType<typeof pic>) =>\n el && typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement ? el.currentSrc || el.src : \"\";\n // A new snapshot only when a new picture is on screen (a frame arrived): reading a 5K frame is not free.\n const look_ = () => {\n const el = pic();\n if (!el) return null;\n const n = naturalSize(el);\n if (n.w > 0) L.natural = n;\n const src = srcOf(el);\n if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;\n const snap = snapshotPicture(el);\n if (snap) { L.lastSrc = src; L.lastSnap = snap; }\n return snap;\n };\n const surfaceOf = (s: Snapshot | null, alpha?: Float32Array | null) => (s ? (meanLuma(s, alpha) > LIGHT_SURFACE ? \"light\" : \"dark\") : undefined);\n\n /** Shows a learned area. Steady on purpose: a small change, or one sooner than REGION_STEADY_MS after the last,\n * keeps the area on screen as it is (it moving under the beam read as the beam fading out and back elsewhere). */\n const apply = (bits: Uint8Array, w: number, h: number, from: Snapshot | null, source: LoaderMaskSource, force = false) => {\n const alpha = softAlpha(bits, w, h, { grow: 4, blur: 6 });\n const box = alphaBox(alpha, w, h);\n if (!box) return;\n const t = now();\n if (!force) {\n if (engine.motion.finishing) return;\n const p = L.shown;\n if (p) {\n // only outward: the area grows as more of the picture is seen changing, never twitches back in\n const moved = Math.max(p.x - box.x, p.y - box.y, box.x + box.w - p.x - p.w, box.y + box.h - p.y - p.h);\n if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;\n }\n }\n const colour = from ? meanColour(from, bits) : null;\n const surf = surfaceOf(from, alpha);\n engine.setRegion({ mask: alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : undefined, surface: surf }, t);\n L.shown = box;\n L.shownAt = t;\n setMaskSource(source);\n setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(\",\"));\n setSurface(surf);\n };\n /** Starts over on what is known about the scene now on screen (mount, or a colour switch swapped the picture). */\n const startOn = (snap: Snapshot | null) => {\n L.key = live.current.maskKey;\n L.base = snap;\n L.bits = null;\n L.shown = null;\n const known = snap && L.key ? recallMask(L.key, snap.w, snap.h) : null;\n if (known && snap) {\n L.bits = known;\n apply(known, snap.w, snap.h, snap, \"learned\", true);\n } else {\n const surf = surfaceOf(snap);\n engine.setRegion({ mask: null, box: null, surface: surf }, now());\n setMaskSource(\"whole\");\n setArea(undefined);\n setSurface(surf);\n }\n };\n\n if (mask) {\n // a given mask: its alpha is the area\n const s = snapshotPicture(mask);\n if (s) {\n const bits = new Uint8Array(s.w * s.h);\n for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;\n apply(bits, s.w, s.h, look_(), \"given\", true);\n }\n } else {\n startOn(look_());\n }\n\n // Compare what is on screen now with the first look: the difference is the part that changes.\n const learn = () => {\n if (mask) return;\n const cur = look_();\n if (!cur) return;\n if (live.current.maskKey !== L.key) {\n // another scene (a colour switch): never learn across it, and not from the old scene's picture still on screen\n L.staleSrc = L.lastSrc;\n L.key = live.current.maskKey;\n L.base = null;\n L.bits = null;\n L.shown = null;\n return;\n }\n if (L.staleSrc !== null) {\n if (L.lastSrc === L.staleSrc) return; // the new scene's picture has not painted yet\n L.staleSrc = null;\n return startOn(cur);\n }\n if (!L.base) return startOn(cur); // the picture was not readable at the start: begin now, with what is known\n const bits = changedBits(L.base, cur);\n if (!bits || coverageOf(bits) > UNRELIABLE_COVERAGE) {\n // another picture, not an edit of the first look (the store picture vs the first live frame, encoded, sized or\n // cropped differently): compare later frames with this one instead\n L.base = cur;\n return;\n }\n if (!isLearnable(bits)) return;\n const key = L.key;\n const all = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;\n L.bits = all;\n apply(all, cur.w, cur.h, L.base, \"learned\");\n };\n const learnTimer = setInterval(learn, LEARN_EVERY_MS);\n\n let raf = 0;\n const draw = () => {\n const c = canvasRef.current;\n const ctx = c?.getContext(\"2d\");\n if (!c || !ctx) return; // no 2D canvas here (a test DOM): nothing to draw, and no point asking again\n raf = requestAnimationFrame(draw);\n // device pixels, capped: the beam is soft, so a 5K frame needs no 15-megapixel canvas redrawn every frame\n const dpr = Math.min(2, (typeof window !== \"undefined\" && window.devicePixelRatio) || 1);\n const css = Math.max(1, c.clientWidth * c.clientHeight);\n const scale = Math.min(dpr, Math.sqrt(MAX_CANVAS_PIXELS / css));\n const W = Math.max(1, Math.round(c.clientWidth * scale)), H = Math.max(1, Math.round(c.clientHeight * scale));\n if (c.width !== W || c.height !== H) { c.width = W; c.height = H; }\n const n = L.natural;\n const place = n ? fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };\n engine.draw(ctx, W, H, place, now(), scale);\n if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;\n };\n if (typeof requestAnimationFrame === \"function\") raf = requestAnimationFrame(draw);\n\n learnNowRef.current = learn;\n return () => {\n clearInterval(learnTimer);\n if (typeof cancelAnimationFrame === \"function\") cancelAnimationFrame(raf);\n engineRef.current = null;\n learnNowRef.current = () => {};\n };\n // set up once per mount: a loader lives for one render-in-flight episode\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // caught up → the last pass, then onExited (a timer, so a hidden tab without animation frames still exits)\n useEffect(() => {\n const engine = engineRef.current;\n if (!engine) return;\n const now = typeof performance !== \"undefined\" ? performance.now() : Date.now();\n if (!visible) {\n learnNowRef.current();\n engine.finish(now);\n setPhase(\"finishing\");\n const t = setTimeout(() => live.current.onExited?.(), BEAM_FINISH_MS);\n return () => clearTimeout(t);\n }\n if (engine.motion.finishing) {\n engine.resume(now);\n setPhase(\"loading\");\n }\n return undefined;\n }, [visible]);\n\n return (\n <canvas\n ref={canvasRef}\n aria-hidden=\"true\"\n data-sc-loader=\"beam\"\n data-sc-loader-look={look}\n data-sc-loader-phase={phase}\n data-sc-loader-mask={maskSource}\n data-sc-loader-area={area}\n data-sc-loader-surface={surface}\n className={className}\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n // the starting blend; the draw loop keeps it in step with the beam (painted on a learned light surface)\n mixBlendMode: look === \"soft\" ? \"normal\" : \"screen\",\n ...style,\n }}\n />\n );\n}\n"]}
1
+ {"version":3,"sources":["../../src/beam/engine.ts","../../src/beam/BeamLoader.tsx"],"names":["p","g"],"mappings":";;;;;;AAUO,IAAM,eAAA,GAAkB;AAExB,IAAM,aAAA,GAAgB;AAEtB,I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","file":"index.js","sourcesContent":["/**\n * The beam, framework-free: a soft line of light that glides back and forth over the part of the picture that is\n * changing while a render is on the way, then makes one last pass across and fades once the picture has caught up.\n *\n * `BeamMotion` is the timing (pure: give it a clock, read the beam's place and opacity). `BeamEngine` draws it into\n * a 2D canvas, cut to a soft mask of the changing part (or the whole frame when none is known yet).\n */\nimport type { Rect } from \"../index\";\n\n/** The beam fades in over this long. */\nexport const BEAM_FADE_IN_MS = 450;\n/** One sweep from one side to the other while loading. */\nexport const BEAM_SWEEP_MS = 1150;\n/** The last pass, once the picture has caught up. */\nexport const BEAM_PASS_MS = 380;\n/** The fade after the last pass. */\nexport const BEAM_TAIL_MS = 150;\n/** The longest dash to the nearer edge before the last pass (from the middle). */\nexport const BEAM_RUSH_MAX_MS = 190;\n/** Caught up → gone, at most: the dash, the last pass, the tail. A host's fallback timer should wait this long. */\nexport const BEAM_FINISH_MS = BEAM_RUSH_MAX_MS + BEAM_PASS_MS + BEAM_TAIL_MS;\n/** A newly learned area replaces the old one over this long (never a jump). */\nexport const REGION_FADE_MS = 300;\n\n/** The looks from the 1 Dec prototype: `beam` = \"Just the beam\" (light only, the default); `soft` = \"Soft laser\"\n * (a faint haze and a trail, painted on); `prism` = the beam with thin rainbow fringes trailing it. */\nexport type BeamLook = \"beam\" | \"soft\" | \"prism\";\n/** The light's color: `auto` = a light version of the color of the part that changes (cool white until known). */\nexport type BeamTone = \"auto\" | \"cool\" | \"warm\" | `${number},${number},${number}`;\n\nconst TONES = { cool: \"190,222,255\", warm: \"255,150,60\" } as const;\n/** On a light surface light can't show (white + light = white): the beam is a colored laser painted on instead. */\nconst ON_LIGHT = { glow: \"70,140,255\", core: \"40,110,240\" } as const;\nconst FRINGES = [\"255,70,70\", \"255,170,40\", \"250,240,80\", \"70,220,110\", \"70,150,255\", \"160,90,255\"];\n\nconst clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));\nconst ease = (p: number) => 0.5 - 0.5 * Math.cos(Math.PI * clamp(p));\n\nexport interface BeamPosition {\n /** Where the beam is across the area, 0 (left edge) to 1 (right edge). */\n s: number;\n /** Which way it moves. */\n dir: 1 | -1;\n /** Overall opacity, 0–1. */\n alpha: number;\n finishing: boolean;\n /** The exit is over: nothing to draw, the host may unmount. */\n done: boolean;\n}\n\n/** The beam's timing. Times are milliseconds on any monotonic clock (`performance.now()`). */\nexport class BeamMotion {\n private t0: number;\n private ph0 = 0;\n /** When the beam started (its fade-in runs from here). */\n readonly bornAt: number;\n private fin: { at: number; from: number; end: 0 | 1; rush: number; alpha: number } | null = null;\n\n constructor(now: number) {\n this.t0 = now;\n this.bornAt = now;\n }\n\n get finishing(): boolean {\n return this.fin !== null;\n }\n\n private loading(now: number): { s: number; dir: 1 | -1 } {\n const ph = (((now - this.t0) / BEAM_SWEEP_MS + this.ph0) % 2 + 2) % 2;\n return ph < 1 ? { s: ease(ph), dir: 1 } : { s: ease(2 - ph), dir: -1 };\n }\n\n private fadeIn(now: number): number {\n const p = clamp((now - this.bornAt) / BEAM_FADE_IN_MS);\n return p * p;\n }\n\n at(now: number): BeamPosition {\n if (!this.fin) return { ...this.loading(now), alpha: this.fadeIn(now), finishing: false, done: false };\n const { at, from, end, rush, alpha } = this.fin;\n const t = now - at;\n if (t >= rush + BEAM_PASS_MS + BEAM_TAIL_MS) return { s: 1 - end, dir: end === 0 ? 1 : -1, alpha: 0, finishing: true, done: true };\n if (t < rush) {\n const p = t / rush;\n return { s: from + (end - from) * (1 - (1 - p) * (1 - p)), dir: end > from ? 1 : -1, alpha, finishing: true, done: false };\n }\n const p = (t - rush) / BEAM_PASS_MS;\n const s = p >= 1 ? 1 - end : end + (1 - 2 * end) * ease(p);\n // full through most of the pass, then gone by the end of the tail\n const fadeFrom = rush + BEAM_PASS_MS * 0.6, fadeLen = BEAM_PASS_MS * 0.4 + BEAM_TAIL_MS;\n const a = t <= fadeFrom ? alpha : alpha * (1 - clamp((t - fadeFrom) / fadeLen));\n return { s, dir: end === 0 ? 1 : -1, alpha: a, finishing: true, done: false };\n }\n\n /** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */\n finish(now: number): void {\n if (this.fin) return;\n const cur = this.at(now);\n const end: 0 | 1 = cur.s < 0.5 ? 0 : 1;\n this.fin = { at: now, from: cur.s, end, rush: 60 + (BEAM_RUSH_MAX_MS - 60) * 2 * Math.abs(cur.s - end), alpha: cur.alpha };\n }\n\n /** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */\n resume(now: number): void {\n if (!this.fin) return;\n const cur = this.at(now);\n this.fin = null;\n const ph = Math.acos(clamp(1 - 2 * cur.s, -1, 1)) / Math.PI; // ease(ph) = s\n this.ph0 = cur.dir > 0 ? ph : 2 - ph;\n this.t0 = now;\n }\n}\n\n/** The part of the picture the beam stays on. */\nexport interface BeamRegion {\n /** Alpha mask in picture space (alpha = changes), drawn over the picture's rect; `null` = the whole frame. */\n mask: CanvasImageSource | null;\n /** The mask's box in picture space (0–1); `null` with no mask. */\n box: { x: number; y: number; w: number; h: number } | null;\n /** The color of the changing part, `\"r,g,b\"`, for `tone: \"auto\"`. */\n tone?: string;\n /** How light the surface under the area is: `light` (a white cup) gets a painted colored beam, `dark` light only. */\n surface?: \"light\" | \"dark\";\n}\n\nconst WHOLE: BeamRegion = { mask: null, box: null };\n\nexport interface BeamEngineOptions {\n look?: BeamLook;\n tone?: BeamTone;\n /** `prefers-reduced-motion`: no gliding line, a still soft glow over the area instead. */\n reducedMotion?: boolean;\n}\n\n/** Draws the beam into a 2D canvas the size of the frame. */\nexport class BeamEngine {\n readonly motion: BeamMotion;\n readonly look: BeamLook;\n private readonly tone: BeamTone;\n private readonly reduced: boolean;\n private prev: BeamRegion = WHOLE;\n private next: BeamRegion = WHOLE;\n private regionAt = -Infinity;\n private maskLayer: HTMLCanvasElement | null = null;\n\n constructor(opts: BeamEngineOptions, now: number) {\n this.motion = new BeamMotion(now);\n this.look = opts.look ?? \"beam\";\n this.tone = opts.tone ?? \"auto\";\n this.reduced = !!opts.reducedMotion;\n }\n\n /** On a light surface the beam is painted (a colored line); on a dark one it is light. Only once the area is known:\n * over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */\n get onLight(): boolean {\n return !!this.next.mask && this.next.surface === \"light\";\n }\n\n /** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a\n * light surface paint on. */\n get blendMode(): \"screen\" | \"normal\" {\n return this.look === \"soft\" || this.onLight ? \"normal\" : \"screen\";\n }\n\n /** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in\n * from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */\n setRegion(region: BeamRegion | null, now: number): void {\n const next = region ?? WHOLE;\n if (!this.next.mask && now - this.motion.bornAt < BEAM_FADE_IN_MS) {\n this.prev = this.next = next;\n this.regionAt = -Infinity;\n return;\n }\n this.prev = this.mixWeight(now) >= 1 ? this.next : this.prev;\n this.next = next;\n this.regionAt = now;\n }\n\n finish(now: number): void { this.motion.finish(now); }\n resume(now: number): void { this.motion.resume(now); }\n\n private mixWeight(now: number): number {\n return clamp((now - this.regionAt) / REGION_FADE_MS);\n }\n\n private rgb(): string {\n if (this.tone === \"cool\" || this.tone === \"warm\") return TONES[this.tone];\n if (this.tone !== \"auto\") return this.tone;\n if (this.onLight) return ON_LIGHT.glow;\n return this.next.tone ?? this.prev.tone ?? TONES.cool;\n }\n\n /** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */\n private area(region: BeamRegion, place: Rect, W: number, H: number): Rect {\n if (!region.box) {\n const x0 = Math.max(0, place.x), y0 = Math.max(0, place.y);\n return { x: x0, y: y0, w: Math.min(W, place.x + place.w) - x0, h: Math.min(H, place.y + place.h) - y0 };\n }\n const b = region.box;\n return { x: place.x + b.x * place.w, y: place.y + b.y * place.h, w: b.w * place.w, h: b.h * place.h };\n }\n\n /**\n * Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.\n * Returns `true` once the exit is over (the canvas is cleared).\n */\n draw(ctx: CanvasRenderingContext2D, W: number, H: number, place: Rect, now: number, dpr = 1): boolean {\n const pos = this.motion.at(now);\n ctx.globalCompositeOperation = \"source-over\";\n ctx.globalAlpha = 1;\n ctx.clearRect(0, 0, W, H);\n if (pos.done) return true;\n if (pos.alpha <= 0.001) return false;\n\n const t = this.mixWeight(now);\n const a0 = this.area(this.prev, place, W, H), a1 = this.area(this.next, place, W, H);\n const A: Rect = { x: a0.x + (a1.x - a0.x) * t, y: a0.y + (a1.y - a0.y) * t, w: a0.w + (a1.w - a0.w) * t, h: a0.h + (a1.h - a0.h) * t };\n const rgb = this.rgb();\n const pad = 10 * dpr, top = A.y - pad, tall = A.h + 2 * pad;\n\n ctx.globalAlpha = pos.alpha;\n if (this.reduced) {\n ctx.fillStyle = `rgba(${rgb},0.22)`;\n ctx.fillRect(0, 0, W, H);\n } else {\n const x = A.x + pos.s * A.w, back = -pos.dir;\n const light = this.look !== \"soft\";\n const painted = this.onLight;\n if (this.look === \"soft\") {\n ctx.fillStyle = \"rgba(255,255,255,0.10)\";\n ctx.fillRect(0, 0, W, H);\n const T = A.w * 0.22, g = ctx.createLinearGradient(x + back * T, 0, x, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(1, `rgba(${rgb},0.22)`);\n ctx.fillStyle = g;\n ctx.fillRect(Math.min(x, x + back * T), top, T, tall);\n }\n if (this.look === \"prism\") {\n FRINGES.forEach((c, i) => {\n ctx.fillStyle = `rgba(${c},${0.55 - i * 0.04})`;\n ctx.fillRect(x + back * (6 + i * 7) * dpr * (pos.finishing ? 1.5 : 1) - 2.5 * dpr, top, 5 * dpr, tall);\n });\n }\n const gw = (light ? 18 : 26) * dpr;\n const g = ctx.createLinearGradient(x - gw, 0, x + gw, 0);\n g.addColorStop(0, `rgba(${rgb},0)`);\n g.addColorStop(0.5, `rgba(${rgb},${painted ? 0.45 : light ? 0.85 : 0.75})`);\n g.addColorStop(1, `rgba(${rgb},0)`);\n ctx.fillStyle = g;\n ctx.fillRect(x - gw, top, 2 * gw, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.85)` : \"rgba(255,255,255,0.95)\";\n ctx.fillRect(x - dpr, top, 2 * dpr, tall);\n ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.7)` : \"rgba(255,245,225,0.9)\";\n const sparks = light ? 10 : 14;\n for (let i = 0; i < sparks; i++) {\n ctx.globalAlpha = pos.alpha * Math.random();\n ctx.fillRect(x + (Math.random() - 0.5) * 16 * dpr, A.y + Math.random() * A.h, 1.6 * dpr, 1.6 * dpr);\n }\n ctx.globalAlpha = pos.alpha;\n }\n\n // cut to the area: the old region fading into the new one\n const layer = this.maskOf(W, H, place, t);\n if (layer) {\n ctx.globalAlpha = 1;\n ctx.globalCompositeOperation = \"destination-in\";\n ctx.drawImage(layer, 0, 0);\n ctx.globalCompositeOperation = \"source-over\";\n }\n return false;\n }\n\n private maskOf(W: number, H: number, place: Rect, t: number): HTMLCanvasElement | null {\n if (!this.prev.mask && !this.next.mask) return null; // the whole frame: nothing to cut\n if (typeof document === \"undefined\") return null;\n this.maskLayer ??= document.createElement(\"canvas\");\n const m = this.maskLayer;\n if (m.width !== W || m.height !== H) { m.width = W; m.height = H; }\n const x = m.getContext(\"2d\");\n if (!x) return null;\n x.globalAlpha = 1;\n x.clearRect(0, 0, W, H);\n for (const [r, a] of [[this.prev, 1 - t], [this.next, t]] as const) {\n if (a <= 0) continue;\n x.globalAlpha = a;\n if (r.mask) x.drawImage(r.mask, place.x, place.y, place.w, place.h);\n else x.fillRect(0, 0, W, H);\n }\n x.globalAlpha = 1;\n return m;\n }\n}\n","\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { fitRect, naturalSize, type LoaderMaskSource, type LoaderPhase, type LoaderProps } from \"../index\";\nimport {\n alphaBox,\n alphaCanvas,\n changedBits,\n coverageOf,\n isLearnable,\n meanLuma,\n meanColour,\n orBits,\n recallMask,\n rememberMask,\n snapshotPicture,\n softAlpha,\n type Snapshot,\n UNRELIABLE_COVERAGE,\n} from \"../mask\";\nimport { BEAM_FINISH_MS, BeamEngine, type BeamLook, type BeamTone } from \"./engine\";\n\n/** How often the picture is compared with its first look while loading. */\nexport const LEARN_EVERY_MS = 250;\n/** A learned area moves on screen at most this often... */\nexport const REGION_STEADY_MS = 600;\n/** ...and only when an edge moves out by more than this share of the picture (an area only grows within an episode). */\nexport const REGION_MIN_MOVE = 0.02;\n/** A surface brighter than this (0–1) is light: the beam is painted on it, not added as light. */\nexport const LIGHT_SURFACE = 0.62;\n/** The beam's canvas never has more pixels than this (it is soft: CSS scales it up). */\nexport const MAX_CANVAS_PIXELS = 2_500_000;\n\nexport interface BeamLoaderProps extends LoaderProps {\n /** `\"beam\"` (default): light only. `\"soft\"`: a faint haze and a trail, painted on. `\"prism\"`: rainbow fringes. */\n look?: BeamLook;\n /** The light's color. `\"auto\"` (default): a light version of the color of the part that changes. */\n tone?: BeamTone;\n}\n\n/** A light version of a color: the beam reads as light on that material (warm on wood, mint on a green cup). */\nfunction lightTone([r, g, b]: [number, number, number]): string {\n return [r, g, b].map((v) => Math.round(v + (255 - v) * 0.6)).join(\",\");\n}\n\n/**\n * The beam loader: a soft line of light gliding over the part of the picture that is changing, while its next\n * render is on the way; one last pass across and a fade once it has caught up.\n *\n * Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it\n * `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per\n * scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.\n *\n * Machine-readable state: `data-sc-loader=\"beam\"`, `data-sc-loader-phase` (`loading` | `finishing`),\n * `data-sc-loader-mask` (`whole` | `learned` | `given`).\n */\nexport function BeamLoader({\n visible,\n onExited,\n picture,\n maskKey,\n fit = \"cover\",\n mask,\n look = \"beam\",\n tone = \"auto\",\n className,\n style,\n}: BeamLoaderProps) {\n const canvasRef = useRef<HTMLCanvasElement | null>(null);\n const engineRef = useRef<BeamEngine | null>(null);\n // one last comparison when the picture has caught up (set by the mount effect)\n const learnNowRef = useRef<() => void>(() => {});\n const [phase, setPhase] = useState<LoaderPhase>(\"loading\");\n const [maskSource, setMaskSource] = useState<LoaderMaskSource>(mask ? \"given\" : \"whole\");\n\n // the latest props, for the loops below (they are set up once)\n const live = useRef({ picture, maskKey, fit, onExited });\n live.current = { picture, maskKey, fit, onExited };\n\n // the area on screen, stamped for agents: data-sc-loader-area (picture space) and data-sc-loader-surface\n const [area, setArea] = useState<string | undefined>(undefined);\n const [surface, setSurface] = useState<\"light\" | \"dark\" | undefined>(undefined);\n\n useEffect(() => {\n const now = () => (typeof performance !== \"undefined\" ? performance.now() : Date.now());\n const reduced = typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n const engine = new BeamEngine({ look, tone, reducedMotion: reduced }, now());\n engineRef.current = engine;\n const pic = () => live.current.picture?.() ?? null;\n\n // What this episode knows. `base` is the first look the frames are compared with; `shown` the area on screen.\n const L = {\n key: live.current.maskKey,\n base: null as Snapshot | null,\n bits: null as Uint8Array | null,\n natural: null as { w: number; h: number } | null,\n lastSrc: \"\",\n /** After a scene change (a color switch): the picture on screen then is still the OLD scene's; learning waits\n * until another picture has painted. A base taken from it learned \"the whole cup changed\" for the new scene. */\n staleSrc: null as string | null,\n lastSnap: null as Snapshot | null,\n shown: null as { x: number; y: number; w: number; h: number } | null,\n shownAt: -Infinity,\n };\n const srcOf = (el: ReturnType<typeof pic>) =>\n el && typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement ? el.currentSrc || el.src : \"\";\n // A new snapshot only when a new picture is on screen (a frame arrived): reading a 5K frame is not free.\n const look_ = () => {\n const el = pic();\n if (!el) return null;\n const n = naturalSize(el);\n if (n.w > 0) L.natural = n;\n const src = srcOf(el);\n if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;\n const snap = snapshotPicture(el);\n if (snap) { L.lastSrc = src; L.lastSnap = snap; }\n return snap;\n };\n const surfaceOf = (s: Snapshot | null, alpha?: Float32Array | null) => (s ? (meanLuma(s, alpha) > LIGHT_SURFACE ? \"light\" : \"dark\") : undefined);\n\n /** Shows a learned area. Steady on purpose: a small change, or one sooner than REGION_STEADY_MS after the last,\n * keeps the area on screen as it is (it moving under the beam read as the beam fading out and back elsewhere). */\n const apply = (bits: Uint8Array, w: number, h: number, from: Snapshot | null, source: LoaderMaskSource, force = false) => {\n const alpha = softAlpha(bits, w, h, { grow: 4, blur: 6 });\n const box = alphaBox(alpha, w, h);\n if (!box) return;\n const t = now();\n if (!force) {\n if (engine.motion.finishing) return;\n const p = L.shown;\n if (p) {\n // only outward: the area grows as more of the picture is seen changing, never twitches back in\n const moved = Math.max(p.x - box.x, p.y - box.y, box.x + box.w - p.x - p.w, box.y + box.h - p.y - p.h);\n if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;\n }\n }\n const colour = from ? meanColour(from, bits) : null;\n const surf = surfaceOf(from, alpha);\n engine.setRegion({ mask: alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : undefined, surface: surf }, t);\n L.shown = box;\n L.shownAt = t;\n setMaskSource(source);\n setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(\",\"));\n setSurface(surf);\n };\n /** Starts over on what is known about the scene now on screen (mount, or a color switch swapped the picture). */\n const startOn = (snap: Snapshot | null) => {\n L.key = live.current.maskKey;\n L.base = snap;\n L.bits = null;\n L.shown = null;\n const known = snap && L.key ? recallMask(L.key, snap.w, snap.h) : null;\n if (known && snap) {\n L.bits = known;\n apply(known, snap.w, snap.h, snap, \"learned\", true);\n } else {\n const surf = surfaceOf(snap);\n engine.setRegion({ mask: null, box: null, surface: surf }, now());\n setMaskSource(\"whole\");\n setArea(undefined);\n setSurface(surf);\n }\n };\n\n if (mask) {\n // a given mask: its alpha is the area\n const s = snapshotPicture(mask);\n if (s) {\n const bits = new Uint8Array(s.w * s.h);\n for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;\n apply(bits, s.w, s.h, look_(), \"given\", true);\n }\n } else {\n startOn(look_());\n }\n\n // Compare what is on screen now with the first look: the difference is the part that changes.\n const learn = () => {\n if (mask) return;\n const cur = look_();\n if (!cur) return;\n if (live.current.maskKey !== L.key) {\n // another scene (a color switch): never learn across it, and not from the old scene's picture still on screen\n L.staleSrc = L.lastSrc;\n L.key = live.current.maskKey;\n L.base = null;\n L.bits = null;\n L.shown = null;\n return;\n }\n if (L.staleSrc !== null) {\n if (L.lastSrc === L.staleSrc) return; // the new scene's picture has not painted yet\n L.staleSrc = null;\n return startOn(cur);\n }\n if (!L.base) return startOn(cur); // the picture was not readable at the start: begin now, with what is known\n const bits = changedBits(L.base, cur);\n if (!bits || coverageOf(bits) > UNRELIABLE_COVERAGE) {\n // another picture, not an edit of the first look (the store picture vs the first live frame, encoded, sized or\n // cropped differently): compare later frames with this one instead\n L.base = cur;\n return;\n }\n if (!isLearnable(bits)) return;\n const key = L.key;\n const all = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;\n L.bits = all;\n apply(all, cur.w, cur.h, L.base, \"learned\");\n };\n const learnTimer = setInterval(learn, LEARN_EVERY_MS);\n\n let raf = 0;\n const draw = () => {\n const c = canvasRef.current;\n const ctx = c?.getContext(\"2d\");\n if (!c || !ctx) return; // no 2D canvas here (a test DOM): nothing to draw, and no point asking again\n raf = requestAnimationFrame(draw);\n // device pixels, capped: the beam is soft, so a 5K frame needs no 15-megapixel canvas redrawn every frame\n const dpr = Math.min(2, (typeof window !== \"undefined\" && window.devicePixelRatio) || 1);\n const css = Math.max(1, c.clientWidth * c.clientHeight);\n const scale = Math.min(dpr, Math.sqrt(MAX_CANVAS_PIXELS / css));\n const W = Math.max(1, Math.round(c.clientWidth * scale)), H = Math.max(1, Math.round(c.clientHeight * scale));\n if (c.width !== W || c.height !== H) { c.width = W; c.height = H; }\n const n = L.natural;\n const place = n ? fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };\n engine.draw(ctx, W, H, place, now(), scale);\n if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;\n };\n if (typeof requestAnimationFrame === \"function\") raf = requestAnimationFrame(draw);\n\n learnNowRef.current = learn;\n return () => {\n clearInterval(learnTimer);\n if (typeof cancelAnimationFrame === \"function\") cancelAnimationFrame(raf);\n engineRef.current = null;\n learnNowRef.current = () => {};\n };\n // set up once per mount: a loader lives for one render-in-flight episode\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // caught up → the last pass, then onExited (a timer, so a hidden tab without animation frames still exits)\n useEffect(() => {\n const engine = engineRef.current;\n if (!engine) return;\n const now = typeof performance !== \"undefined\" ? performance.now() : Date.now();\n if (!visible) {\n learnNowRef.current();\n engine.finish(now);\n setPhase(\"finishing\");\n const t = setTimeout(() => live.current.onExited?.(), BEAM_FINISH_MS);\n return () => clearTimeout(t);\n }\n if (engine.motion.finishing) {\n engine.resume(now);\n setPhase(\"loading\");\n }\n return undefined;\n }, [visible]);\n\n return (\n <canvas\n ref={canvasRef}\n aria-hidden=\"true\"\n data-sc-loader=\"beam\"\n data-sc-loader-look={look}\n data-sc-loader-phase={phase}\n data-sc-loader-mask={maskSource}\n data-sc-loader-area={area}\n data-sc-loader-surface={surface}\n className={className}\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n pointerEvents: \"none\",\n // the starting blend; the draw loop keeps it in step with the beam (painted on a learned light surface)\n mixBlendMode: look === \"soft\" ? \"normal\" : \"screen\",\n ...style,\n }}\n />\n );\n}\n"]}
@@ -271,5 +271,5 @@ exports.rememberMask = rememberMask;
271
271
  exports.snapshotPicture = snapshotPicture;
272
272
  exports.softAlpha = softAlpha;
273
273
  exports.unpackBits = unpackBits;
274
- //# sourceMappingURL=chunk-MKDNNQDK.cjs.map
275
- //# sourceMappingURL=chunk-MKDNNQDK.cjs.map
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AU,KAAK,CAAC,CAAA;AAAA,IAC5C,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,WAAA,GAAoB;AAClC,EAAA,MAAA,CAAO,KAAA,EAAM;AACb,EAAA,MAAM,KAAK,OAAA,EAAQ;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACT,EAAA,IAAI;AACF,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,OAAA,CAAQ,QAAQ,KAAK,IAAI,CAAA;AACrD,IAAA,KAAA,MAAW,CAAA,IAAK,KAAA,EAAO,EAAA,CAAG,UAAA,CAAW,YAAY,CAAC,CAAA;AAClD,IAAA,EAAA,CAAG,WAAW,QAAQ,CAAA;AAAA,EACxB,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"chunk-MKDNNQDK.cjs","sourcesContent":["/**\n * Learned masks: where a product picture changes, measured from the picture itself.\n *\n * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that\n * differ are \"what changed\" (the print, the coloured body), so the loader can stay on that part instead of the\n * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so\n * the next edit of the same picture knows the area at once.\n *\n * Everything here works on small grids (at most {@link LEARN_SIDE} px on a side): a comparison is a few\n * thousand pixel reads, cheap enough to run several times a second while a render is on the way.\n */\nimport { naturalSize, type PictureElement } from \"./index\";\n\n/** The long side of the grid a picture is compared on. */\nexport const LEARN_SIDE = 192;\n/** A channel difference (0–255, after a light blur) above this is a change, not compression noise. */\nexport const CHANGE_THRESHOLD = 30;\n/**\n * A comparison that finds more than this share of the picture changed is not trusted: it is another picture (a\n * different crop, a first live frame against a differently encoded store picture), not an edit of this one.\n */\nexport const UNRELIABLE_COVERAGE = 0.6;\n\n/** A picture read down to a small grid. */\nexport interface Snapshot {\n w: number;\n h: number;\n rgba: Uint8ClampedArray;\n}\n\n/** The grid size for a picture of `srcW × srcH`: the long side is `side`, the aspect kept. */\nexport function gridSize(srcW: number, srcH: number, side = LEARN_SIDE): { w: number; h: number } {\n if (!(srcW > 0) || !(srcH > 0)) return { w: 0, h: 0 };\n return srcW >= srcH\n ? { w: side, h: Math.max(1, Math.round((side * srcH) / srcW)) }\n : { w: Math.max(1, Math.round((side * srcW) / srcH)), h: side };\n}\n\nlet scratch: HTMLCanvasElement | null = null;\n/**\n * Reads a picture down to its comparison grid. `null` when it cannot be read: not loaded yet, no 2D canvas, or a\n * cross-origin picture served without CORS (the canvas is tainted). A loader then just covers the whole frame.\n */\nexport function snapshotPicture(el: PictureElement | null | undefined, side = LEARN_SIDE): Snapshot | null {\n if (!el || typeof document === \"undefined\") return null;\n if (typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement && !el.complete) return null;\n const { w: sw, h: sh } = naturalSize(el);\n const { w, h } = gridSize(sw, sh, side);\n if (!w || !h) return null;\n try {\n scratch ??= document.createElement(\"canvas\");\n scratch.width = w;\n scratch.height = h;\n const ctx = scratch.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return null;\n ctx.clearRect(0, 0, w, h);\n ctx.drawImage(el as CanvasImageSource, 0, 0, w, h);\n return { w, h, rgba: ctx.getImageData(0, 0, w, h).data };\n } catch {\n return null; // tainted (no CORS) or a decode error: nothing to learn from\n }\n}\n\n/** A 3 × 3 box blur of each colour channel: compression speckle averages out before pixels are compared. */\nfunction blurred(s: Snapshot): Float32Array {\n const { w, h, rgba } = s;\n const out = new Float32Array(w * h * 3);\n for (let y = 0; y < h; y++) {\n for (let x = 0; x < w; x++) {\n let r = 0, g = 0, b = 0, n = 0;\n for (let dy = -1; dy <= 1; dy++) {\n const yy = y + dy;\n if (yy < 0 || yy >= h) continue;\n for (let dx = -1; dx <= 1; dx++) {\n const xx = x + dx;\n if (xx < 0 || xx >= w) continue;\n const i = (yy * w + xx) * 4;\n r += rgba[i]; g += rgba[i + 1]; b += rgba[i + 2]; n++;\n }\n }\n const o = (y * w + x) * 3;\n out[o] = r / n; out[o + 1] = g / n; out[o + 2] = b / n;\n }\n }\n return out;\n}\n\n/**\n * Which grid cells changed between two snapshots of the same picture (1 = changed). `null` when they are not the\n * same grid (another picture, another aspect): there is nothing to compare.\n */\nexport function changedBits(a: Snapshot, b: Snapshot, threshold = CHANGE_THRESHOLD): Uint8Array | null {\n if (a.w !== b.w || a.h !== b.h || a.rgba.length !== b.rgba.length) return null;\n const A = blurred(a), B = blurred(b);\n const bits = new Uint8Array(a.w * a.h);\n for (let i = 0; i < bits.length; i++) {\n const o = i * 3;\n const d = Math.max(Math.abs(A[o] - B[o]), Math.abs(A[o + 1] - B[o + 1]), Math.abs(A[o + 2] - B[o + 2]));\n bits[i] = d > threshold ? 1 : 0;\n }\n return bits;\n}\n\n/** The share of cells set. */\nexport function coverageOf(bits: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < bits.length; i++) n += bits[i];\n return bits.length ? n / bits.length : 0;\n}\n\n/** Whether a comparison is worth learning from: something changed, and not so much that it is another picture. */\nexport function isLearnable(bits: Uint8Array | null): bits is Uint8Array {\n if (!bits) return false;\n const c = coverageOf(bits);\n return c > 0 && c <= UNRELIABLE_COVERAGE;\n}\n\n/** Cells set in either. */\nexport function orBits(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(Math.max(a.length, b.length));\n for (let i = 0; i < out.length; i++) out[i] = (a[i] | b[i]) as 0 | 1;\n return out;\n}\n\nfunction boxPass(src: Float32Array, w: number, h: number, r: number, horizontal: boolean, op: \"max\" | \"mean\"): Float32Array {\n const out = new Float32Array(src.length);\n const len = horizontal ? w : h, lines = horizontal ? h : w;\n for (let l = 0; l < lines; l++) {\n for (let i = 0; i < len; i++) {\n let acc = op === \"max\" ? 0 : 0, n = 0;\n for (let k = -r; k <= r; k++) {\n const j = i + k;\n if (j < 0 || j >= len) continue;\n const v = src[horizontal ? l * w + j : j * w + l];\n if (op === \"max\") { if (v > acc) acc = v; } else { acc += v; n++; }\n }\n out[horizontal ? l * w + i : i * w + l] = op === \"max\" ? acc : acc / n;\n }\n }\n return out;\n}\n\n/**\n * A soft alpha (0–1) from changed cells: grown by `grow` cells (a stroke of a letter becomes the letter's area),\n * then blurred by `blur` cells, so the loader's edge fades out instead of stopping at a hard line. The inside stays\n * fully opaque.\n */\nexport function softAlpha(bits: Uint8Array, w: number, h: number, opts: { grow?: number; blur?: number } = {}): Float32Array {\n const grow = Math.max(0, Math.round(opts.grow ?? 2));\n const blur = Math.max(0, Math.round(opts.blur ?? 4));\n let a: Float32Array = Float32Array.from(bits);\n if (grow) a = boxPass(boxPass(a, w, h, grow, true, \"max\"), w, h, grow, false, \"max\");\n const r = Math.max(1, Math.round(blur / 2));\n if (blur) for (let p = 0; p < 3; p++) a = boxPass(boxPass(a, w, h, r, true, \"mean\"), w, h, r, false, \"mean\");\n for (let i = 0; i < a.length; i++) a[i] = Math.min(1, a[i] * 1.6);\n return a;\n}\n\n/** The box (0–1, picture space) holding every cell above `threshold`, or `null` when there is none. */\nexport function alphaBox(alpha: Float32Array, w: number, h: number, threshold = 0.2): { x: number; y: number; w: number; h: number } | null {\n let x0 = w, y0 = h, x1 = -1, y1 = -1;\n for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {\n if (alpha[y * w + x] <= threshold) continue;\n if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y;\n }\n if (x1 < 0) return null;\n return { x: x0 / w, y: y0 / h, w: (x1 - x0 + 1) / w, h: (y1 - y0 + 1) / h };\n}\n\n/** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */\nexport function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null {\n if (typeof document === \"undefined\") return null;\n const c = document.createElement(\"canvas\");\n c.width = w;\n c.height = h;\n const ctx = c.getContext(\"2d\");\n if (!ctx) return null;\n const img = ctx.createImageData(w, h);\n for (let i = 0; i < alpha.length; i++) {\n const o = i * 4;\n img.data[o] = img.data[o + 1] = img.data[o + 2] = 255;\n img.data[o + 3] = Math.round(alpha[i] * 255);\n }\n ctx.putImageData(img, 0, 0);\n return c;\n}\n\n/** The mean colour of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */\nexport function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null {\n let r = 0, g = 0, b = 0, n = 0;\n for (let i = 0; i < bits.length; i++) {\n if (!bits[i]) continue;\n const o = i * 4;\n r += s.rgba[o]; g += s.rgba[o + 1]; b += s.rgba[o + 2]; n++;\n }\n return n ? [r / n, g / n, b / n] : null;\n}\n\n/**\n * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to\n * know whether light can show on the surface (on white it can't).\n */\nexport function meanLuma(s: Snapshot, alpha?: Float32Array | null, threshold = 0.2): number {\n let sum = 0, n = 0;\n for (let i = 0; i < s.w * s.h; i++) {\n if (alpha && alpha[i] <= threshold) continue;\n const o = i * 4;\n sum += 0.2126 * s.rgba[o] + 0.7152 * s.rgba[o + 1] + 0.0722 * s.rgba[o + 2];\n n++;\n }\n return n ? sum / n / 255 : 0.5;\n}\n\n// ---------- what was learned, per scene ----------\n\n// v2 (2026-12-01): v1 masks could hold a whole cup learned across a colour switch by the first beam (#6723), and a\n// remembered area is kept for good: every v1 entry is dropped once, on first use.\nconst LS_PREFIX = \"sc-loaders:mask:v2:\";\nconst LS_INDEX = \"sc-loaders:mask:v2:index\";\nconst RETIRED_PREFIXES = [\"sc-loaders:mask:v1:\"];\nlet retiredSwept = false;\nfunction sweepRetired(ls: Storage): void {\n if (retiredSwept) return;\n retiredSwept = true;\n try {\n for (let i = ls.length - 1; i >= 0; i--) {\n const k = ls.key(i);\n if (k && RETIRED_PREFIXES.some((p) => k.startsWith(p))) ls.removeItem(k);\n }\n } catch {\n // blocked storage: nothing to sweep\n }\n}\n/** At most this many scenes are kept in localStorage (oldest out first); a scene is ~1 KB. */\nexport const MAX_STORED_MASKS = 40;\nconst memory = new Map<string, Uint8Array>();\n\nconst slot = (key: string, w: number, h: number) => `${key}@${w}x${h}`;\n\n/** Bits to base64, 8 cells a byte. */\nexport function packBits(bits: Uint8Array): string {\n const bytes = new Uint8Array(Math.ceil(bits.length / 8));\n for (let i = 0; i < bits.length; i++) if (bits[i]) bytes[i >> 3] |= 1 << (i & 7);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);\n return btoa(s);\n}\n\n/** base64 back to `n` bits; `null` if it does not hold `n`. */\nexport function unpackBits(packed: string, n: number): Uint8Array | null {\n let s: string;\n try { s = atob(packed); } catch { return null; }\n if (s.length !== Math.ceil(n / 8)) return null;\n const bits = new Uint8Array(n);\n for (let i = 0; i < n; i++) bits[i] = (s.charCodeAt(i >> 3) >> (i & 7)) & 1;\n return bits;\n}\n\nfunction storage(): Storage | null {\n let ls: Storage | null = null;\n try { ls = typeof localStorage === \"undefined\" ? null : localStorage; } catch { return null; }\n if (ls) sweepRetired(ls);\n return ls;\n}\n\n/** What has been learned about a scene's picture on this grid, or `null`. */\nexport function recallMask(key: string, w: number, h: number): Uint8Array | null {\n const k = slot(key, w, h);\n const hit = memory.get(k);\n if (hit) return hit;\n const raw = storage()?.getItem(LS_PREFIX + k);\n const bits = raw ? unpackBits(raw, w * h) : null;\n if (bits) memory.set(k, bits);\n return bits;\n}\n\n/** Adds what changed this time to what a scene already knows; returns the union. */\nexport function rememberMask(key: string, w: number, h: number, bits: Uint8Array): Uint8Array {\n const k = slot(key, w, h);\n const prev = recallMask(key, w, h);\n const next = prev ? orBits(prev, bits) : bits;\n memory.set(k, next);\n const ls = storage();\n if (ls) {\n try {\n ls.setItem(LS_PREFIX + k, packBits(next));\n const index = (JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[]).filter((x) => x !== k);\n index.push(k);\n while (index.length > MAX_STORED_MASKS) ls.removeItem(LS_PREFIX + index.shift()!);\n ls.setItem(LS_INDEX, JSON.stringify(index));\n } catch {\n // full or blocked storage: memory still has it for this visit\n }\n }\n return next;\n}\n\n/** Forgets everything learned (tests; a \"reset\" in a demo). */\nexport function forgetMasks(): void {\n memory.clear();\n const ls = storage();\n if (!ls) return;\n try {\n const index = JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[];\n for (const k of index) ls.removeItem(LS_PREFIX + k);\n ls.removeItem(LS_INDEX);\n } catch {\n // nothing to clear\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/mask.ts"],"names":["naturalSize"],"mappings":";;;;;AAcO,IAAM,UAAA,GAAa;AAEnB,IAAM,gBAAA,GAAmB;AAKzB,IAAM,mBAAA,GAAsB;AAU5B,SAAS,QAAA,CAAS,IAAA,EAAc,IAAA,EAAc,IAAA,GAAO,UAAA,EAAsC;AAChG,EAAA,IAAI,EAAE,IAAA,GAAO,CAAA,CAAA,IAAM,EAAE,IAAA,GAAO,CAAA,CAAA,EAAI,OAAO,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE;AACpD,EAAA,OAAO,IAAA,IAAQ,IAAA,GACX,EAAE,CAAA,EAAG,IAAA,EAAM,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,KAAA,CAAO,IAAA,GAAO,OAAQ,IAAI,CAAC,CAAA,EAAE,GAC5D,EAAE,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,KAAA,CAAO,IAAA,GAAO,IAAA,GAAQ,IAAI,CAAC,CAAA,EAAG,GAAG,IAAA,EAAK;AAClE;AAEA,IAAI,OAAA,GAAoC,IAAA;AAKjC,SAAS,eAAA,CAAgB,EAAA,EAAuC,IAAA,GAAO,UAAA,EAA6B;AACzG,EAAA,IAAI,CAAC,EAAA,IAAM,OAAO,QAAA,KAAa,aAAa,OAAO,IAAA;AACnD,EAAA,IAAI,OAAO,qBAAqB,WAAA,IAAe,EAAA,YAAc,oBAAoB,CAAC,EAAA,CAAG,UAAU,OAAO,IAAA;AACtG,EAAA,MAAM,EAAE,CA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AAA,EAAkB,EAAA,CAAG,WAAW,SAAA,GAAY,KAAA,CAAM,OAAQ,CAAA;AAChF,MAAA,EAAA,CAAG,OAAA,CAAQ,QAAA,EAAU,IAAA,CAAK,SAAA,CAAU,KAAK,CAAC,CAAA;AAAA,IAC5C,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAGO,SAAS,WAAA,GAAoB;AAClC,EAAA,MAAA,CAAO,KAAA,EAAM;AACb,EAAA,MAAM,KAAK,OAAA,EAAQ;AACnB,EAAA,IAAI,CAAC,EAAA,EAAI;AACT,EAAA,IAAI;AACF,IAAA,MAAM,QAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,OAAA,CAAQ,QAAQ,KAAK,IAAI,CAAA;AACrD,IAAA,KAAA,MAAW,CAAA,IAAK,KAAA,EAAO,EAAA,CAAG,UAAA,CAAW,YAAY,CAAC,CAAA;AAClD,IAAA,EAAA,CAAG,WAAW,QAAQ,CAAA;AAAA,EACxB,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"chunk-66FMKFHB.cjs","sourcesContent":["/**\n * Learned masks: where a product picture changes, measured from the picture itself.\n *\n * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that\n * differ are \"what changed\" (the print, the colored body), so the loader can stay on that part instead of the\n * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so\n * the next edit of the same picture knows the area at once.\n *\n * Everything here works on small grids (at most {@link LEARN_SIDE} px on a side): a comparison is a few\n * thousand pixel reads, cheap enough to run several times a second while a render is on the way.\n */\nimport { naturalSize, type PictureElement } from \"./index\";\n\n/** The long side of the grid a picture is compared on. */\nexport const LEARN_SIDE = 192;\n/** A channel difference (0–255, after a light blur) above this is a change, not compression noise. */\nexport const CHANGE_THRESHOLD = 30;\n/**\n * A comparison that finds more than this share of the picture changed is not trusted: it is another picture (a\n * different crop, a first live frame against a differently encoded store picture), not an edit of this one.\n */\nexport const UNRELIABLE_COVERAGE = 0.6;\n\n/** A picture read down to a small grid. */\nexport interface Snapshot {\n w: number;\n h: number;\n rgba: Uint8ClampedArray;\n}\n\n/** The grid size for a picture of `srcW × srcH`: the long side is `side`, the aspect kept. */\nexport function gridSize(srcW: number, srcH: number, side = LEARN_SIDE): { w: number; h: number } {\n if (!(srcW > 0) || !(srcH > 0)) return { w: 0, h: 0 };\n return srcW >= srcH\n ? { w: side, h: Math.max(1, Math.round((side * srcH) / srcW)) }\n : { w: Math.max(1, Math.round((side * srcW) / srcH)), h: side };\n}\n\nlet scratch: HTMLCanvasElement | null = null;\n/**\n * Reads a picture down to its comparison grid. `null` when it cannot be read: not loaded yet, no 2D canvas, or a\n * cross-origin picture served without CORS (the canvas is tainted). A loader then just covers the whole frame.\n */\nexport function snapshotPicture(el: PictureElement | null | undefined, side = LEARN_SIDE): Snapshot | null {\n if (!el || typeof document === \"undefined\") return null;\n if (typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement && !el.complete) return null;\n const { w: sw, h: sh } = naturalSize(el);\n const { w, h } = gridSize(sw, sh, side);\n if (!w || !h) return null;\n try {\n scratch ??= document.createElement(\"canvas\");\n scratch.width = w;\n scratch.height = h;\n const ctx = scratch.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return null;\n ctx.clearRect(0, 0, w, h);\n ctx.drawImage(el as CanvasImageSource, 0, 0, w, h);\n return { w, h, rgba: ctx.getImageData(0, 0, w, h).data };\n } catch {\n return null; // tainted (no CORS) or a decode error: nothing to learn from\n }\n}\n\n/** A 3 × 3 box blur of each color channel: compression speckle averages out before pixels are compared. */\nfunction blurred(s: Snapshot): Float32Array {\n const { w, h, rgba } = s;\n const out = new Float32Array(w * h * 3);\n for (let y = 0; y < h; y++) {\n for (let x = 0; x < w; x++) {\n let r = 0, g = 0, b = 0, n = 0;\n for (let dy = -1; dy <= 1; dy++) {\n const yy = y + dy;\n if (yy < 0 || yy >= h) continue;\n for (let dx = -1; dx <= 1; dx++) {\n const xx = x + dx;\n if (xx < 0 || xx >= w) continue;\n const i = (yy * w + xx) * 4;\n r += rgba[i]; g += rgba[i + 1]; b += rgba[i + 2]; n++;\n }\n }\n const o = (y * w + x) * 3;\n out[o] = r / n; out[o + 1] = g / n; out[o + 2] = b / n;\n }\n }\n return out;\n}\n\n/**\n * Which grid cells changed between two snapshots of the same picture (1 = changed). `null` when they are not the\n * same grid (another picture, another aspect): there is nothing to compare.\n */\nexport function changedBits(a: Snapshot, b: Snapshot, threshold = CHANGE_THRESHOLD): Uint8Array | null {\n if (a.w !== b.w || a.h !== b.h || a.rgba.length !== b.rgba.length) return null;\n const A = blurred(a), B = blurred(b);\n const bits = new Uint8Array(a.w * a.h);\n for (let i = 0; i < bits.length; i++) {\n const o = i * 3;\n const d = Math.max(Math.abs(A[o] - B[o]), Math.abs(A[o + 1] - B[o + 1]), Math.abs(A[o + 2] - B[o + 2]));\n bits[i] = d > threshold ? 1 : 0;\n }\n return bits;\n}\n\n/** The share of cells set. */\nexport function coverageOf(bits: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < bits.length; i++) n += bits[i];\n return bits.length ? n / bits.length : 0;\n}\n\n/** Whether a comparison is worth learning from: something changed, and not so much that it is another picture. */\nexport function isLearnable(bits: Uint8Array | null): bits is Uint8Array {\n if (!bits) return false;\n const c = coverageOf(bits);\n return c > 0 && c <= UNRELIABLE_COVERAGE;\n}\n\n/** Cells set in either. */\nexport function orBits(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(Math.max(a.length, b.length));\n for (let i = 0; i < out.length; i++) out[i] = (a[i] | b[i]) as 0 | 1;\n return out;\n}\n\nfunction boxPass(src: Float32Array, w: number, h: number, r: number, horizontal: boolean, op: \"max\" | \"mean\"): Float32Array {\n const out = new Float32Array(src.length);\n const len = horizontal ? w : h, lines = horizontal ? h : w;\n for (let l = 0; l < lines; l++) {\n for (let i = 0; i < len; i++) {\n let acc = op === \"max\" ? 0 : 0, n = 0;\n for (let k = -r; k <= r; k++) {\n const j = i + k;\n if (j < 0 || j >= len) continue;\n const v = src[horizontal ? l * w + j : j * w + l];\n if (op === \"max\") { if (v > acc) acc = v; } else { acc += v; n++; }\n }\n out[horizontal ? l * w + i : i * w + l] = op === \"max\" ? acc : acc / n;\n }\n }\n return out;\n}\n\n/**\n * A soft alpha (0–1) from changed cells: grown by `grow` cells (a stroke of a letter becomes the letter's area),\n * then blurred by `blur` cells, so the loader's edge fades out instead of stopping at a hard line. The inside stays\n * fully opaque.\n */\nexport function softAlpha(bits: Uint8Array, w: number, h: number, opts: { grow?: number; blur?: number } = {}): Float32Array {\n const grow = Math.max(0, Math.round(opts.grow ?? 2));\n const blur = Math.max(0, Math.round(opts.blur ?? 4));\n let a: Float32Array = Float32Array.from(bits);\n if (grow) a = boxPass(boxPass(a, w, h, grow, true, \"max\"), w, h, grow, false, \"max\");\n const r = Math.max(1, Math.round(blur / 2));\n if (blur) for (let p = 0; p < 3; p++) a = boxPass(boxPass(a, w, h, r, true, \"mean\"), w, h, r, false, \"mean\");\n for (let i = 0; i < a.length; i++) a[i] = Math.min(1, a[i] * 1.6);\n return a;\n}\n\n/** The box (0–1, picture space) holding every cell above `threshold`, or `null` when there is none. */\nexport function alphaBox(alpha: Float32Array, w: number, h: number, threshold = 0.2): { x: number; y: number; w: number; h: number } | null {\n let x0 = w, y0 = h, x1 = -1, y1 = -1;\n for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {\n if (alpha[y * w + x] <= threshold) continue;\n if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y;\n }\n if (x1 < 0) return null;\n return { x: x0 / w, y: y0 / h, w: (x1 - x0 + 1) / w, h: (y1 - y0 + 1) / h };\n}\n\n/** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */\nexport function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null {\n if (typeof document === \"undefined\") return null;\n const c = document.createElement(\"canvas\");\n c.width = w;\n c.height = h;\n const ctx = c.getContext(\"2d\");\n if (!ctx) return null;\n const img = ctx.createImageData(w, h);\n for (let i = 0; i < alpha.length; i++) {\n const o = i * 4;\n img.data[o] = img.data[o + 1] = img.data[o + 2] = 255;\n img.data[o + 3] = Math.round(alpha[i] * 255);\n }\n ctx.putImageData(img, 0, 0);\n return c;\n}\n\n/** The mean color of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */\nexport function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null {\n let r = 0, g = 0, b = 0, n = 0;\n for (let i = 0; i < bits.length; i++) {\n if (!bits[i]) continue;\n const o = i * 4;\n r += s.rgba[o]; g += s.rgba[o + 1]; b += s.rgba[o + 2]; n++;\n }\n return n ? [r / n, g / n, b / n] : null;\n}\n\n/**\n * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to\n * know whether light can show on the surface (on white it can't).\n */\nexport function meanLuma(s: Snapshot, alpha?: Float32Array | null, threshold = 0.2): number {\n let sum = 0, n = 0;\n for (let i = 0; i < s.w * s.h; i++) {\n if (alpha && alpha[i] <= threshold) continue;\n const o = i * 4;\n sum += 0.2126 * s.rgba[o] + 0.7152 * s.rgba[o + 1] + 0.0722 * s.rgba[o + 2];\n n++;\n }\n return n ? sum / n / 255 : 0.5;\n}\n\n// ---------- what was learned, per scene ----------\n\n// v2 (2026-12-01): v1 masks could hold a whole cup learned across a color switch by the first beam (#6723), and a\n// remembered area is kept for good: every v1 entry is dropped once, on first use.\nconst LS_PREFIX = \"sc-loaders:mask:v2:\";\nconst LS_INDEX = \"sc-loaders:mask:v2:index\";\nconst RETIRED_PREFIXES = [\"sc-loaders:mask:v1:\"];\nlet retiredSwept = false;\nfunction sweepRetired(ls: Storage): void {\n if (retiredSwept) return;\n retiredSwept = true;\n try {\n for (let i = ls.length - 1; i >= 0; i--) {\n const k = ls.key(i);\n if (k && RETIRED_PREFIXES.some((p) => k.startsWith(p))) ls.removeItem(k);\n }\n } catch {\n // blocked storage: nothing to sweep\n }\n}\n/** At most this many scenes are kept in localStorage (oldest out first); a scene is ~1 KB. */\nexport const MAX_STORED_MASKS = 40;\nconst memory = new Map<string, Uint8Array>();\n\nconst slot = (key: string, w: number, h: number) => `${key}@${w}x${h}`;\n\n/** Bits to base64, 8 cells a byte. */\nexport function packBits(bits: Uint8Array): string {\n const bytes = new Uint8Array(Math.ceil(bits.length / 8));\n for (let i = 0; i < bits.length; i++) if (bits[i]) bytes[i >> 3] |= 1 << (i & 7);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);\n return btoa(s);\n}\n\n/** base64 back to `n` bits; `null` if it does not hold `n`. */\nexport function unpackBits(packed: string, n: number): Uint8Array | null {\n let s: string;\n try { s = atob(packed); } catch { return null; }\n if (s.length !== Math.ceil(n / 8)) return null;\n const bits = new Uint8Array(n);\n for (let i = 0; i < n; i++) bits[i] = (s.charCodeAt(i >> 3) >> (i & 7)) & 1;\n return bits;\n}\n\nfunction storage(): Storage | null {\n let ls: Storage | null = null;\n try { ls = typeof localStorage === \"undefined\" ? null : localStorage; } catch { return null; }\n if (ls) sweepRetired(ls);\n return ls;\n}\n\n/** What has been learned about a scene's picture on this grid, or `null`. */\nexport function recallMask(key: string, w: number, h: number): Uint8Array | null {\n const k = slot(key, w, h);\n const hit = memory.get(k);\n if (hit) return hit;\n const raw = storage()?.getItem(LS_PREFIX + k);\n const bits = raw ? unpackBits(raw, w * h) : null;\n if (bits) memory.set(k, bits);\n return bits;\n}\n\n/** Adds what changed this time to what a scene already knows; returns the union. */\nexport function rememberMask(key: string, w: number, h: number, bits: Uint8Array): Uint8Array {\n const k = slot(key, w, h);\n const prev = recallMask(key, w, h);\n const next = prev ? orBits(prev, bits) : bits;\n memory.set(k, next);\n const ls = storage();\n if (ls) {\n try {\n ls.setItem(LS_PREFIX + k, packBits(next));\n const index = (JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[]).filter((x) => x !== k);\n index.push(k);\n while (index.length > MAX_STORED_MASKS) ls.removeItem(LS_PREFIX + index.shift()!);\n ls.setItem(LS_INDEX, JSON.stringify(index));\n } catch {\n // full or blocked storage: memory still has it for this visit\n }\n }\n return next;\n}\n\n/** Forgets everything learned (tests; a \"reset\" in a demo). */\nexport function forgetMasks(): void {\n memory.clear();\n const ls = storage();\n if (!ls) return;\n try {\n const index = JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[];\n for (const k of index) ls.removeItem(LS_PREFIX + k);\n ls.removeItem(LS_INDEX);\n } catch {\n // nothing to clear\n }\n}\n"]}
@@ -250,5 +250,5 @@ function forgetMasks() {
250
250
  }
251
251
 
252
252
  export { CHANGE_THRESHOLD, LEARN_SIDE, MAX_STORED_MASKS, UNRELIABLE_COVERAGE, alphaBox, alphaCanvas, changedBits, coverageOf, forgetMasks, gridSize, isLearnable, meanColour, meanLuma, orBits, packBits, recallMask, rememberMask, snapshotPicture, softAlpha, unpackBits };
253
- //# sourceMappingURL=chunk-A3PAVGM3.js.map
254
- //# sourceMappingURL=chunk-A3PAVGM3.js.map
253
+ //# sourceMappingURL=chunk-JJVBRZTY.js.map
254
+ //# sourceMappingURL=chunk-JJVBRZTY.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mask.ts"],"names":[],"mappings":";;;AAcO,IAAM,UAAA,GAAa;AAEnB,IAAM,gBAAA,GAAmB;AAKzB,IAAM,mBAAA,GAAsB;AAU5B,SAAS,QAAA,CAAS,IAAA,EAAc,IAAA,EAAc,IAAA,GAAO,UAAA,EAAsC;AAChG,EAAA,IAAI,EAAE,IAAA,GAAO,CAAA,CAAA,IAAM,EAAE,IAAA,GAAO,CAAA,CAAA,EAAI,OAAO,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE;AACpD,EAAA,OAAO,IAAA,IAAQ,IAAA,GACX,EAAE,CAAA,EAAG,IAAA,EAAM,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAA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es, measured from the picture itself.\n *\n * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that\n * differ are \"what changed\" (the print, the coloured body), so the loader can stay on that part instead of the\n * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so\n * the next edit of the same picture knows the area at once.\n *\n * Everything here works on small grids (at most {@link LEARN_SIDE} px on a side): a comparison is a few\n * thousand pixel reads, cheap enough to run several times a second while a render is on the way.\n */\nimport { naturalSize, type PictureElement } from \"./index\";\n\n/** The long side of the grid a picture is compared on. */\nexport const LEARN_SIDE = 192;\n/** A channel difference (0–255, after a light blur) above this is a change, not compression noise. */\nexport const CHANGE_THRESHOLD = 30;\n/**\n * A comparison that finds more than this share of the picture changed is not trusted: it is another picture (a\n * different crop, a first live frame against a differently encoded store picture), not an edit of this one.\n */\nexport const UNRELIABLE_COVERAGE = 0.6;\n\n/** A picture read down to a small grid. */\nexport interface Snapshot {\n w: number;\n h: number;\n rgba: Uint8ClampedArray;\n}\n\n/** The grid size for a picture of `srcW × srcH`: the long side is `side`, the aspect kept. */\nexport function gridSize(srcW: number, srcH: number, side = LEARN_SIDE): { w: number; h: number } {\n if (!(srcW > 0) || !(srcH > 0)) return { w: 0, h: 0 };\n return srcW >= srcH\n ? { w: side, h: Math.max(1, Math.round((side * srcH) / srcW)) }\n : { w: Math.max(1, Math.round((side * srcW) / srcH)), h: side };\n}\n\nlet scratch: HTMLCanvasElement | null = null;\n/**\n * Reads a picture down to its comparison grid. `null` when it cannot be read: not loaded yet, no 2D canvas, or a\n * cross-origin picture served without CORS (the canvas is tainted). A loader then just covers the whole frame.\n */\nexport function snapshotPicture(el: PictureElement | null | undefined, side = LEARN_SIDE): Snapshot | null {\n if (!el || typeof document === \"undefined\") return null;\n if (typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement && !el.complete) return null;\n const { w: sw, h: sh } = naturalSize(el);\n const { w, h } = gridSize(sw, sh, side);\n if (!w || !h) return null;\n try {\n scratch ??= document.createElement(\"canvas\");\n scratch.width = w;\n scratch.height = h;\n const ctx = scratch.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return null;\n ctx.clearRect(0, 0, w, h);\n ctx.drawImage(el as CanvasImageSource, 0, 0, w, h);\n return { w, h, rgba: ctx.getImageData(0, 0, w, h).data };\n } catch {\n return null; // tainted (no CORS) or a decode error: nothing to learn from\n }\n}\n\n/** A 3 × 3 box blur of each colour channel: compression speckle averages out before pixels are compared. */\nfunction blurred(s: Snapshot): Float32Array {\n const { w, h, rgba } = s;\n const out = new Float32Array(w * h * 3);\n for (let y = 0; y < h; y++) {\n for (let x = 0; x < w; x++) {\n let r = 0, g = 0, b = 0, n = 0;\n for (let dy = -1; dy <= 1; dy++) {\n const yy = y + dy;\n if (yy < 0 || yy >= h) continue;\n for (let dx = -1; dx <= 1; dx++) {\n const xx = x + dx;\n if (xx < 0 || xx >= w) continue;\n const i = (yy * w + xx) * 4;\n r += rgba[i]; g += rgba[i + 1]; b += rgba[i + 2]; n++;\n }\n }\n const o = (y * w + x) * 3;\n out[o] = r / n; out[o + 1] = g / n; out[o + 2] = b / n;\n }\n }\n return out;\n}\n\n/**\n * Which grid cells changed between two snapshots of the same picture (1 = changed). `null` when they are not the\n * same grid (another picture, another aspect): there is nothing to compare.\n */\nexport function changedBits(a: Snapshot, b: Snapshot, threshold = CHANGE_THRESHOLD): Uint8Array | null {\n if (a.w !== b.w || a.h !== b.h || a.rgba.length !== b.rgba.length) return null;\n const A = blurred(a), B = blurred(b);\n const bits = new Uint8Array(a.w * a.h);\n for (let i = 0; i < bits.length; i++) {\n const o = i * 3;\n const d = Math.max(Math.abs(A[o] - B[o]), Math.abs(A[o + 1] - B[o + 1]), Math.abs(A[o + 2] - B[o + 2]));\n bits[i] = d > threshold ? 1 : 0;\n }\n return bits;\n}\n\n/** The share of cells set. */\nexport function coverageOf(bits: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < bits.length; i++) n += bits[i];\n return bits.length ? n / bits.length : 0;\n}\n\n/** Whether a comparison is worth learning from: something changed, and not so much that it is another picture. */\nexport function isLearnable(bits: Uint8Array | null): bits is Uint8Array {\n if (!bits) return false;\n const c = coverageOf(bits);\n return c > 0 && c <= UNRELIABLE_COVERAGE;\n}\n\n/** Cells set in either. */\nexport function orBits(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(Math.max(a.length, b.length));\n for (let i = 0; i < out.length; i++) out[i] = (a[i] | b[i]) as 0 | 1;\n return out;\n}\n\nfunction boxPass(src: Float32Array, w: number, h: number, r: number, horizontal: boolean, op: \"max\" | \"mean\"): Float32Array {\n const out = new Float32Array(src.length);\n const len = horizontal ? w : h, lines = horizontal ? h : w;\n for (let l = 0; l < lines; l++) {\n for (let i = 0; i < len; i++) {\n let acc = op === \"max\" ? 0 : 0, n = 0;\n for (let k = -r; k <= r; k++) {\n const j = i + k;\n if (j < 0 || j >= len) continue;\n const v = src[horizontal ? l * w + j : j * w + l];\n if (op === \"max\") { if (v > acc) acc = v; } else { acc += v; n++; }\n }\n out[horizontal ? l * w + i : i * w + l] = op === \"max\" ? acc : acc / n;\n }\n }\n return out;\n}\n\n/**\n * A soft alpha (0–1) from changed cells: grown by `grow` cells (a stroke of a letter becomes the letter's area),\n * then blurred by `blur` cells, so the loader's edge fades out instead of stopping at a hard line. The inside stays\n * fully opaque.\n */\nexport function softAlpha(bits: Uint8Array, w: number, h: number, opts: { grow?: number; blur?: number } = {}): Float32Array {\n const grow = Math.max(0, Math.round(opts.grow ?? 2));\n const blur = Math.max(0, Math.round(opts.blur ?? 4));\n let a: Float32Array = Float32Array.from(bits);\n if (grow) a = boxPass(boxPass(a, w, h, grow, true, \"max\"), w, h, grow, false, \"max\");\n const r = Math.max(1, Math.round(blur / 2));\n if (blur) for (let p = 0; p < 3; p++) a = boxPass(boxPass(a, w, h, r, true, \"mean\"), w, h, r, false, \"mean\");\n for (let i = 0; i < a.length; i++) a[i] = Math.min(1, a[i] * 1.6);\n return a;\n}\n\n/** The box (0–1, picture space) holding every cell above `threshold`, or `null` when there is none. */\nexport function alphaBox(alpha: Float32Array, w: number, h: number, threshold = 0.2): { x: number; y: number; w: number; h: number } | null {\n let x0 = w, y0 = h, x1 = -1, y1 = -1;\n for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {\n if (alpha[y * w + x] <= threshold) continue;\n if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y;\n }\n if (x1 < 0) return null;\n return { x: x0 / w, y: y0 / h, w: (x1 - x0 + 1) / w, h: (y1 - y0 + 1) / h };\n}\n\n/** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */\nexport function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null {\n if (typeof document === \"undefined\") return null;\n const c = document.createElement(\"canvas\");\n c.width = w;\n c.height = h;\n const ctx = c.getContext(\"2d\");\n if (!ctx) return null;\n const img = ctx.createImageData(w, h);\n for (let i = 0; i < alpha.length; i++) {\n const o = i * 4;\n img.data[o] = img.data[o + 1] = img.data[o + 2] = 255;\n img.data[o + 3] = Math.round(alpha[i] * 255);\n }\n ctx.putImageData(img, 0, 0);\n return c;\n}\n\n/** The mean colour of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */\nexport function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null {\n let r = 0, g = 0, b = 0, n = 0;\n for (let i = 0; i < bits.length; i++) {\n if (!bits[i]) continue;\n const o = i * 4;\n r += s.rgba[o]; g += s.rgba[o + 1]; b += s.rgba[o + 2]; n++;\n }\n return n ? [r / n, g / n, b / n] : null;\n}\n\n/**\n * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to\n * know whether light can show on the surface (on white it can't).\n */\nexport function meanLuma(s: Snapshot, alpha?: Float32Array | null, threshold = 0.2): number {\n let sum = 0, n = 0;\n for (let i = 0; i < s.w * s.h; i++) {\n if (alpha && alpha[i] <= threshold) continue;\n const o = i * 4;\n sum += 0.2126 * s.rgba[o] + 0.7152 * s.rgba[o + 1] + 0.0722 * s.rgba[o + 2];\n n++;\n }\n return n ? sum / n / 255 : 0.5;\n}\n\n// ---------- what was learned, per scene ----------\n\n// v2 (2026-12-01): v1 masks could hold a whole cup learned across a colour switch by the first beam (#6723), and a\n// remembered area is kept for good: every v1 entry is dropped once, on first use.\nconst LS_PREFIX = \"sc-loaders:mask:v2:\";\nconst LS_INDEX = \"sc-loaders:mask:v2:index\";\nconst RETIRED_PREFIXES = [\"sc-loaders:mask:v1:\"];\nlet retiredSwept = false;\nfunction sweepRetired(ls: Storage): void {\n if (retiredSwept) return;\n retiredSwept = true;\n try {\n for (let i = ls.length - 1; i >= 0; i--) {\n const k = ls.key(i);\n if (k && RETIRED_PREFIXES.some((p) => k.startsWith(p))) ls.removeItem(k);\n }\n } catch {\n // blocked storage: nothing to sweep\n }\n}\n/** At most this many scenes are kept in localStorage (oldest out first); a scene is ~1 KB. */\nexport const MAX_STORED_MASKS = 40;\nconst memory = new Map<string, Uint8Array>();\n\nconst slot = (key: string, w: number, h: number) => `${key}@${w}x${h}`;\n\n/** Bits to base64, 8 cells a byte. */\nexport function packBits(bits: Uint8Array): string {\n const bytes = new Uint8Array(Math.ceil(bits.length / 8));\n for (let i = 0; i < bits.length; i++) if (bits[i]) bytes[i >> 3] |= 1 << (i & 7);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);\n return btoa(s);\n}\n\n/** base64 back to `n` bits; `null` if it does not hold `n`. */\nexport function unpackBits(packed: string, n: number): Uint8Array | null {\n let s: string;\n try { s = atob(packed); } catch { return null; }\n if (s.length !== Math.ceil(n / 8)) return null;\n const bits = new Uint8Array(n);\n for (let i = 0; i < n; i++) bits[i] = (s.charCodeAt(i >> 3) >> (i & 7)) & 1;\n return bits;\n}\n\nfunction storage(): Storage | null {\n let ls: Storage | null = null;\n try { ls = typeof localStorage === \"undefined\" ? null : localStorage; } catch { return null; }\n if (ls) sweepRetired(ls);\n return ls;\n}\n\n/** What has been learned about a scene's picture on this grid, or `null`. */\nexport function recallMask(key: string, w: number, h: number): Uint8Array | null {\n const k = slot(key, w, h);\n const hit = memory.get(k);\n if (hit) return hit;\n const raw = storage()?.getItem(LS_PREFIX + k);\n const bits = raw ? unpackBits(raw, w * h) : null;\n if (bits) memory.set(k, bits);\n return bits;\n}\n\n/** Adds what changed this time to what a scene already knows; returns the union. */\nexport function rememberMask(key: string, w: number, h: number, bits: Uint8Array): Uint8Array {\n const k = slot(key, w, h);\n const prev = recallMask(key, w, h);\n const next = prev ? orBits(prev, bits) : bits;\n memory.set(k, next);\n const ls = storage();\n if (ls) {\n try {\n ls.setItem(LS_PREFIX + k, packBits(next));\n const index = (JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[]).filter((x) => x !== k);\n index.push(k);\n while (index.length > MAX_STORED_MASKS) ls.removeItem(LS_PREFIX + index.shift()!);\n ls.setItem(LS_INDEX, JSON.stringify(index));\n } catch {\n // full or blocked storage: memory still has it for this visit\n }\n }\n return next;\n}\n\n/** Forgets everything learned (tests; a \"reset\" in a demo). */\nexport function forgetMasks(): void {\n memory.clear();\n const ls = storage();\n if (!ls) return;\n try {\n const index = JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[];\n for (const k of index) ls.removeItem(LS_PREFIX + k);\n ls.removeItem(LS_INDEX);\n } catch {\n // nothing to clear\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/mask.ts"],"names":[],"mappings":";;;AAcO,IAAM,UAAA,GAAa;AAEnB,IAAM,gBAAA,GAAmB;AAKzB,IAAM,mBAAA,GAAsB;AAU5B,SAAS,QAAA,CAAS,IAAA,EAAc,IAAA,EAAc,IAAA,GAAO,UAAA,EAAsC;AAChG,EAAA,IAAI,EAAE,IAAA,GAAO,CAAA,CAAA,IAAM,EAAE,IAAA,GAAO,CAAA,CAAA,EAAI,OAAO,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE;A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AAG,WAAW,QAAQ,CAAA;AAAA,EACxB,CAAA,CAAA,MAAQ;AAAA,EAER;AACF","file":"chunk-JJVBRZTY.js","sourcesContent":["/**\n * Learned masks: where a product picture changes, measured from the picture itself.\n *\n * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that\n * differ are \"what changed\" (the print, the colored body), so the loader can stay on that part instead of the\n * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so\n * the next edit of the same picture knows the area at once.\n *\n * Everything here works on small grids (at most {@link LEARN_SIDE} px on a side): a comparison is a few\n * thousand pixel reads, cheap enough to run several times a second while a render is on the way.\n */\nimport { naturalSize, type PictureElement } from \"./index\";\n\n/** The long side of the grid a picture is compared on. */\nexport const LEARN_SIDE = 192;\n/** A channel difference (0–255, after a light blur) above this is a change, not compression noise. */\nexport const CHANGE_THRESHOLD = 30;\n/**\n * A comparison that finds more than this share of the picture changed is not trusted: it is another picture (a\n * different crop, a first live frame against a differently encoded store picture), not an edit of this one.\n */\nexport const UNRELIABLE_COVERAGE = 0.6;\n\n/** A picture read down to a small grid. */\nexport interface Snapshot {\n w: number;\n h: number;\n rgba: Uint8ClampedArray;\n}\n\n/** The grid size for a picture of `srcW × srcH`: the long side is `side`, the aspect kept. */\nexport function gridSize(srcW: number, srcH: number, side = LEARN_SIDE): { w: number; h: number } {\n if (!(srcW > 0) || !(srcH > 0)) return { w: 0, h: 0 };\n return srcW >= srcH\n ? { w: side, h: Math.max(1, Math.round((side * srcH) / srcW)) }\n : { w: Math.max(1, Math.round((side * srcW) / srcH)), h: side };\n}\n\nlet scratch: HTMLCanvasElement | null = null;\n/**\n * Reads a picture down to its comparison grid. `null` when it cannot be read: not loaded yet, no 2D canvas, or a\n * cross-origin picture served without CORS (the canvas is tainted). A loader then just covers the whole frame.\n */\nexport function snapshotPicture(el: PictureElement | null | undefined, side = LEARN_SIDE): Snapshot | null {\n if (!el || typeof document === \"undefined\") return null;\n if (typeof HTMLImageElement !== \"undefined\" && el instanceof HTMLImageElement && !el.complete) return null;\n const { w: sw, h: sh } = naturalSize(el);\n const { w, h } = gridSize(sw, sh, side);\n if (!w || !h) return null;\n try {\n scratch ??= document.createElement(\"canvas\");\n scratch.width = w;\n scratch.height = h;\n const ctx = scratch.getContext(\"2d\", { willReadFrequently: true });\n if (!ctx) return null;\n ctx.clearRect(0, 0, w, h);\n ctx.drawImage(el as CanvasImageSource, 0, 0, w, h);\n return { w, h, rgba: ctx.getImageData(0, 0, w, h).data };\n } catch {\n return null; // tainted (no CORS) or a decode error: nothing to learn from\n }\n}\n\n/** A 3 × 3 box blur of each color channel: compression speckle averages out before pixels are compared. */\nfunction blurred(s: Snapshot): Float32Array {\n const { w, h, rgba } = s;\n const out = new Float32Array(w * h * 3);\n for (let y = 0; y < h; y++) {\n for (let x = 0; x < w; x++) {\n let r = 0, g = 0, b = 0, n = 0;\n for (let dy = -1; dy <= 1; dy++) {\n const yy = y + dy;\n if (yy < 0 || yy >= h) continue;\n for (let dx = -1; dx <= 1; dx++) {\n const xx = x + dx;\n if (xx < 0 || xx >= w) continue;\n const i = (yy * w + xx) * 4;\n r += rgba[i]; g += rgba[i + 1]; b += rgba[i + 2]; n++;\n }\n }\n const o = (y * w + x) * 3;\n out[o] = r / n; out[o + 1] = g / n; out[o + 2] = b / n;\n }\n }\n return out;\n}\n\n/**\n * Which grid cells changed between two snapshots of the same picture (1 = changed). `null` when they are not the\n * same grid (another picture, another aspect): there is nothing to compare.\n */\nexport function changedBits(a: Snapshot, b: Snapshot, threshold = CHANGE_THRESHOLD): Uint8Array | null {\n if (a.w !== b.w || a.h !== b.h || a.rgba.length !== b.rgba.length) return null;\n const A = blurred(a), B = blurred(b);\n const bits = new Uint8Array(a.w * a.h);\n for (let i = 0; i < bits.length; i++) {\n const o = i * 3;\n const d = Math.max(Math.abs(A[o] - B[o]), Math.abs(A[o + 1] - B[o + 1]), Math.abs(A[o + 2] - B[o + 2]));\n bits[i] = d > threshold ? 1 : 0;\n }\n return bits;\n}\n\n/** The share of cells set. */\nexport function coverageOf(bits: Uint8Array): number {\n let n = 0;\n for (let i = 0; i < bits.length; i++) n += bits[i];\n return bits.length ? n / bits.length : 0;\n}\n\n/** Whether a comparison is worth learning from: something changed, and not so much that it is another picture. */\nexport function isLearnable(bits: Uint8Array | null): bits is Uint8Array {\n if (!bits) return false;\n const c = coverageOf(bits);\n return c > 0 && c <= UNRELIABLE_COVERAGE;\n}\n\n/** Cells set in either. */\nexport function orBits(a: Uint8Array, b: Uint8Array): Uint8Array {\n const out = new Uint8Array(Math.max(a.length, b.length));\n for (let i = 0; i < out.length; i++) out[i] = (a[i] | b[i]) as 0 | 1;\n return out;\n}\n\nfunction boxPass(src: Float32Array, w: number, h: number, r: number, horizontal: boolean, op: \"max\" | \"mean\"): Float32Array {\n const out = new Float32Array(src.length);\n const len = horizontal ? w : h, lines = horizontal ? h : w;\n for (let l = 0; l < lines; l++) {\n for (let i = 0; i < len; i++) {\n let acc = op === \"max\" ? 0 : 0, n = 0;\n for (let k = -r; k <= r; k++) {\n const j = i + k;\n if (j < 0 || j >= len) continue;\n const v = src[horizontal ? l * w + j : j * w + l];\n if (op === \"max\") { if (v > acc) acc = v; } else { acc += v; n++; }\n }\n out[horizontal ? l * w + i : i * w + l] = op === \"max\" ? acc : acc / n;\n }\n }\n return out;\n}\n\n/**\n * A soft alpha (0–1) from changed cells: grown by `grow` cells (a stroke of a letter becomes the letter's area),\n * then blurred by `blur` cells, so the loader's edge fades out instead of stopping at a hard line. The inside stays\n * fully opaque.\n */\nexport function softAlpha(bits: Uint8Array, w: number, h: number, opts: { grow?: number; blur?: number } = {}): Float32Array {\n const grow = Math.max(0, Math.round(opts.grow ?? 2));\n const blur = Math.max(0, Math.round(opts.blur ?? 4));\n let a: Float32Array = Float32Array.from(bits);\n if (grow) a = boxPass(boxPass(a, w, h, grow, true, \"max\"), w, h, grow, false, \"max\");\n const r = Math.max(1, Math.round(blur / 2));\n if (blur) for (let p = 0; p < 3; p++) a = boxPass(boxPass(a, w, h, r, true, \"mean\"), w, h, r, false, \"mean\");\n for (let i = 0; i < a.length; i++) a[i] = Math.min(1, a[i] * 1.6);\n return a;\n}\n\n/** The box (0–1, picture space) holding every cell above `threshold`, or `null` when there is none. */\nexport function alphaBox(alpha: Float32Array, w: number, h: number, threshold = 0.2): { x: number; y: number; w: number; h: number } | null {\n let x0 = w, y0 = h, x1 = -1, y1 = -1;\n for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {\n if (alpha[y * w + x] <= threshold) continue;\n if (x < x0) x0 = x; if (x > x1) x1 = x; if (y < y0) y0 = y; if (y > y1) y1 = y;\n }\n if (x1 < 0) return null;\n return { x: x0 / w, y: y0 / h, w: (x1 - x0 + 1) / w, h: (y1 - y0 + 1) / h };\n}\n\n/** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */\nexport function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null {\n if (typeof document === \"undefined\") return null;\n const c = document.createElement(\"canvas\");\n c.width = w;\n c.height = h;\n const ctx = c.getContext(\"2d\");\n if (!ctx) return null;\n const img = ctx.createImageData(w, h);\n for (let i = 0; i < alpha.length; i++) {\n const o = i * 4;\n img.data[o] = img.data[o + 1] = img.data[o + 2] = 255;\n img.data[o + 3] = Math.round(alpha[i] * 255);\n }\n ctx.putImageData(img, 0, 0);\n return c;\n}\n\n/** The mean color of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */\nexport function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null {\n let r = 0, g = 0, b = 0, n = 0;\n for (let i = 0; i < bits.length; i++) {\n if (!bits[i]) continue;\n const o = i * 4;\n r += s.rgba[o]; g += s.rgba[o + 1]; b += s.rgba[o + 2]; n++;\n }\n return n ? [r / n, g / n, b / n] : null;\n}\n\n/**\n * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to\n * know whether light can show on the surface (on white it can't).\n */\nexport function meanLuma(s: Snapshot, alpha?: Float32Array | null, threshold = 0.2): number {\n let sum = 0, n = 0;\n for (let i = 0; i < s.w * s.h; i++) {\n if (alpha && alpha[i] <= threshold) continue;\n const o = i * 4;\n sum += 0.2126 * s.rgba[o] + 0.7152 * s.rgba[o + 1] + 0.0722 * s.rgba[o + 2];\n n++;\n }\n return n ? sum / n / 255 : 0.5;\n}\n\n// ---------- what was learned, per scene ----------\n\n// v2 (2026-12-01): v1 masks could hold a whole cup learned across a color switch by the first beam (#6723), and a\n// remembered area is kept for good: every v1 entry is dropped once, on first use.\nconst LS_PREFIX = \"sc-loaders:mask:v2:\";\nconst LS_INDEX = \"sc-loaders:mask:v2:index\";\nconst RETIRED_PREFIXES = [\"sc-loaders:mask:v1:\"];\nlet retiredSwept = false;\nfunction sweepRetired(ls: Storage): void {\n if (retiredSwept) return;\n retiredSwept = true;\n try {\n for (let i = ls.length - 1; i >= 0; i--) {\n const k = ls.key(i);\n if (k && RETIRED_PREFIXES.some((p) => k.startsWith(p))) ls.removeItem(k);\n }\n } catch {\n // blocked storage: nothing to sweep\n }\n}\n/** At most this many scenes are kept in localStorage (oldest out first); a scene is ~1 KB. */\nexport const MAX_STORED_MASKS = 40;\nconst memory = new Map<string, Uint8Array>();\n\nconst slot = (key: string, w: number, h: number) => `${key}@${w}x${h}`;\n\n/** Bits to base64, 8 cells a byte. */\nexport function packBits(bits: Uint8Array): string {\n const bytes = new Uint8Array(Math.ceil(bits.length / 8));\n for (let i = 0; i < bits.length; i++) if (bits[i]) bytes[i >> 3] |= 1 << (i & 7);\n let s = \"\";\n for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]);\n return btoa(s);\n}\n\n/** base64 back to `n` bits; `null` if it does not hold `n`. */\nexport function unpackBits(packed: string, n: number): Uint8Array | null {\n let s: string;\n try { s = atob(packed); } catch { return null; }\n if (s.length !== Math.ceil(n / 8)) return null;\n const bits = new Uint8Array(n);\n for (let i = 0; i < n; i++) bits[i] = (s.charCodeAt(i >> 3) >> (i & 7)) & 1;\n return bits;\n}\n\nfunction storage(): Storage | null {\n let ls: Storage | null = null;\n try { ls = typeof localStorage === \"undefined\" ? null : localStorage; } catch { return null; }\n if (ls) sweepRetired(ls);\n return ls;\n}\n\n/** What has been learned about a scene's picture on this grid, or `null`. */\nexport function recallMask(key: string, w: number, h: number): Uint8Array | null {\n const k = slot(key, w, h);\n const hit = memory.get(k);\n if (hit) return hit;\n const raw = storage()?.getItem(LS_PREFIX + k);\n const bits = raw ? unpackBits(raw, w * h) : null;\n if (bits) memory.set(k, bits);\n return bits;\n}\n\n/** Adds what changed this time to what a scene already knows; returns the union. */\nexport function rememberMask(key: string, w: number, h: number, bits: Uint8Array): Uint8Array {\n const k = slot(key, w, h);\n const prev = recallMask(key, w, h);\n const next = prev ? orBits(prev, bits) : bits;\n memory.set(k, next);\n const ls = storage();\n if (ls) {\n try {\n ls.setItem(LS_PREFIX + k, packBits(next));\n const index = (JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[]).filter((x) => x !== k);\n index.push(k);\n while (index.length > MAX_STORED_MASKS) ls.removeItem(LS_PREFIX + index.shift()!);\n ls.setItem(LS_INDEX, JSON.stringify(index));\n } catch {\n // full or blocked storage: memory still has it for this visit\n }\n }\n return next;\n}\n\n/** Forgets everything learned (tests; a \"reset\" in a demo). */\nexport function forgetMasks(): void {\n memory.clear();\n const ls = storage();\n if (!ls) return;\n try {\n const index = JSON.parse(ls.getItem(LS_INDEX) || \"[]\") as string[];\n for (const k of index) ls.removeItem(LS_PREFIX + k);\n ls.removeItem(LS_INDEX);\n } catch {\n // nothing to clear\n }\n}\n"]}
package/dist/mask.cjs CHANGED
@@ -1,89 +1,89 @@
1
1
  'use strict';
2
2
 
3
- var chunkMKDNNQDK_cjs = require('./chunk-MKDNNQDK.cjs');
3
+ var chunk66FMKFHB_cjs = require('./chunk-66FMKFHB.cjs');
4
4
  require('./chunk-NCXRWPGN.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "CHANGE_THRESHOLD", {
9
9
  enumerable: true,
10
- get: function () { return chunkMKDNNQDK_cjs.CHANGE_THRESHOLD; }
10
+ get: function () { return chunk66FMKFHB_cjs.CHANGE_THRESHOLD; }
11
11
  });
12
12
  Object.defineProperty(exports, "LEARN_SIDE", {
13
13
  enumerable: true,
14
- get: function () { return chunkMKDNNQDK_cjs.LEARN_SIDE; }
14
+ get: function () { return chunk66FMKFHB_cjs.LEARN_SIDE; }
15
15
  });
16
16
  Object.defineProperty(exports, "MAX_STORED_MASKS", {
17
17
  enumerable: true,
18
- get: function () { return chunkMKDNNQDK_cjs.MAX_STORED_MASKS; }
18
+ get: function () { return chunk66FMKFHB_cjs.MAX_STORED_MASKS; }
19
19
  });
20
20
  Object.defineProperty(exports, "UNRELIABLE_COVERAGE", {
21
21
  enumerable: true,
22
- get: function () { return chunkMKDNNQDK_cjs.UNRELIABLE_COVERAGE; }
22
+ get: function () { return chunk66FMKFHB_cjs.UNRELIABLE_COVERAGE; }
23
23
  });
24
24
  Object.defineProperty(exports, "alphaBox", {
25
25
  enumerable: true,
26
- get: function () { return chunkMKDNNQDK_cjs.alphaBox; }
26
+ get: function () { return chunk66FMKFHB_cjs.alphaBox; }
27
27
  });
28
28
  Object.defineProperty(exports, "alphaCanvas", {
29
29
  enumerable: true,
30
- get: function () { return chunkMKDNNQDK_cjs.alphaCanvas; }
30
+ get: function () { return chunk66FMKFHB_cjs.alphaCanvas; }
31
31
  });
32
32
  Object.defineProperty(exports, "changedBits", {
33
33
  enumerable: true,
34
- get: function () { return chunkMKDNNQDK_cjs.changedBits; }
34
+ get: function () { return chunk66FMKFHB_cjs.changedBits; }
35
35
  });
36
36
  Object.defineProperty(exports, "coverageOf", {
37
37
  enumerable: true,
38
- get: function () { return chunkMKDNNQDK_cjs.coverageOf; }
38
+ get: function () { return chunk66FMKFHB_cjs.coverageOf; }
39
39
  });
40
40
  Object.defineProperty(exports, "forgetMasks", {
41
41
  enumerable: true,
42
- get: function () { return chunkMKDNNQDK_cjs.forgetMasks; }
42
+ get: function () { return chunk66FMKFHB_cjs.forgetMasks; }
43
43
  });
44
44
  Object.defineProperty(exports, "gridSize", {
45
45
  enumerable: true,
46
- get: function () { return chunkMKDNNQDK_cjs.gridSize; }
46
+ get: function () { return chunk66FMKFHB_cjs.gridSize; }
47
47
  });
48
48
  Object.defineProperty(exports, "isLearnable", {
49
49
  enumerable: true,
50
- get: function () { return chunkMKDNNQDK_cjs.isLearnable; }
50
+ get: function () { return chunk66FMKFHB_cjs.isLearnable; }
51
51
  });
52
52
  Object.defineProperty(exports, "meanColour", {
53
53
  enumerable: true,
54
- get: function () { return chunkMKDNNQDK_cjs.meanColour; }
54
+ get: function () { return chunk66FMKFHB_cjs.meanColour; }
55
55
  });
56
56
  Object.defineProperty(exports, "meanLuma", {
57
57
  enumerable: true,
58
- get: function () { return chunkMKDNNQDK_cjs.meanLuma; }
58
+ get: function () { return chunk66FMKFHB_cjs.meanLuma; }
59
59
  });
60
60
  Object.defineProperty(exports, "orBits", {
61
61
  enumerable: true,
62
- get: function () { return chunkMKDNNQDK_cjs.orBits; }
62
+ get: function () { return chunk66FMKFHB_cjs.orBits; }
63
63
  });
64
64
  Object.defineProperty(exports, "packBits", {
65
65
  enumerable: true,
66
- get: function () { return chunkMKDNNQDK_cjs.packBits; }
66
+ get: function () { return chunk66FMKFHB_cjs.packBits; }
67
67
  });
68
68
  Object.defineProperty(exports, "recallMask", {
69
69
  enumerable: true,
70
- get: function () { return chunkMKDNNQDK_cjs.recallMask; }
70
+ get: function () { return chunk66FMKFHB_cjs.recallMask; }
71
71
  });
72
72
  Object.defineProperty(exports, "rememberMask", {
73
73
  enumerable: true,
74
- get: function () { return chunkMKDNNQDK_cjs.rememberMask; }
74
+ get: function () { return chunk66FMKFHB_cjs.rememberMask; }
75
75
  });
76
76
  Object.defineProperty(exports, "snapshotPicture", {
77
77
  enumerable: true,
78
- get: function () { return chunkMKDNNQDK_cjs.snapshotPicture; }
78
+ get: function () { return chunk66FMKFHB_cjs.snapshotPicture; }
79
79
  });
80
80
  Object.defineProperty(exports, "softAlpha", {
81
81
  enumerable: true,
82
- get: function () { return chunkMKDNNQDK_cjs.softAlpha; }
82
+ get: function () { return chunk66FMKFHB_cjs.softAlpha; }
83
83
  });
84
84
  Object.defineProperty(exports, "unpackBits", {
85
85
  enumerable: true,
86
- get: function () { return chunkMKDNNQDK_cjs.unpackBits; }
86
+ get: function () { return chunk66FMKFHB_cjs.unpackBits; }
87
87
  });
88
88
  //# sourceMappingURL=mask.cjs.map
89
89
  //# sourceMappingURL=mask.cjs.map
package/dist/mask.d.cts CHANGED
@@ -5,7 +5,7 @@ import 'react';
5
5
  * Learned masks: where a product picture changes, measured from the picture itself.
6
6
  *
7
7
  * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that
8
- * differ are "what changed" (the print, the coloured body), so the loader can stay on that part instead of the
8
+ * differ are "what changed" (the print, the colored body), so the loader can stay on that part instead of the
9
9
  * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so
10
10
  * the next edit of the same picture knows the area at once.
11
11
  *
@@ -67,7 +67,7 @@ declare function alphaBox(alpha: Float32Array, w: number, h: number, threshold?:
67
67
  } | null;
68
68
  /** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */
69
69
  declare function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null;
70
- /** The mean colour of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */
70
+ /** The mean color of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */
71
71
  declare function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null;
72
72
  /**
73
73
  * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to
package/dist/mask.d.ts CHANGED
@@ -5,7 +5,7 @@ import 'react';
5
5
  * Learned masks: where a product picture changes, measured from the picture itself.
6
6
  *
7
7
  * A loader snapshots the picture when a render starts, then compares each new frame with it. The pixels that
8
- * differ are "what changed" (the print, the coloured body), so the loader can stay on that part instead of the
8
+ * differ are "what changed" (the print, the colored body), so the loader can stay on that part instead of the
9
9
  * whole frame. What it learns is kept per scene (a mockup id) in memory and, packed small, in localStorage, so
10
10
  * the next edit of the same picture knows the area at once.
11
11
  *
@@ -67,7 +67,7 @@ declare function alphaBox(alpha: Float32Array, w: number, h: number, threshold?:
67
67
  } | null;
68
68
  /** A soft alpha as a canvas (white, alpha = mask), ready to `drawImage` over a frame. `null` without a 2D canvas. */
69
69
  declare function alphaCanvas(alpha: Float32Array, w: number, h: number): HTMLCanvasElement | null;
70
- /** The mean colour of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */
70
+ /** The mean color of the cells set (from a snapshot), or `null` when none is. A loader tints its light with it. */
71
71
  declare function meanColour(s: Snapshot, bits: Uint8Array): [number, number, number] | null;
72
72
  /**
73
73
  * The mean brightness (0–1) of a snapshot, only where `alpha` is above `threshold` when given. A loader uses it to
package/dist/mask.js CHANGED
@@ -1,4 +1,4 @@
1
- export { CHANGE_THRESHOLD, LEARN_SIDE, MAX_STORED_MASKS, UNRELIABLE_COVERAGE, alphaBox, alphaCanvas, changedBits, coverageOf, forgetMasks, gridSize, isLearnable, meanColour, meanLuma, orBits, packBits, recallMask, rememberMask, snapshotPicture, softAlpha, unpackBits } from './chunk-A3PAVGM3.js';
1
+ export { CHANGE_THRESHOLD, LEARN_SIDE, MAX_STORED_MASKS, UNRELIABLE_COVERAGE, alphaBox, alphaCanvas, changedBits, coverageOf, forgetMasks, gridSize, isLearnable, meanColour, meanLuma, orBits, packBits, recallMask, rememberMask, snapshotPicture, softAlpha, unpackBits } from './chunk-JJVBRZTY.js';
2
2
  import './chunk-6IWUTOBS.js';
3
3
  //# sourceMappingURL=mask.js.map
4
4
  //# sourceMappingURL=mask.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/loaders",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Render-in-flight loaders for live product mockups. Each loader is its own import (`@snowcone-app/loaders/beam`): a site downloads only the loaders it uses.",
5
5
  "keywords": [
6
6
  "snowcone",