@snowcone-app/loaders 0.3.4 → 0.5.0
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 +12 -0
- package/README.md +9 -1
- package/dist/beam/index.cjs +84 -19
- package/dist/beam/index.cjs.map +1 -1
- package/dist/beam/index.d.cts +5 -3
- package/dist/beam/index.d.ts +5 -3
- package/dist/beam/index.js +71 -6
- package/dist/beam/index.js.map +1 -1
- package/dist/{chunk-JJVBRZTY.js → chunk-3ZFKVFUC.js} +86 -4
- package/dist/chunk-3ZFKVFUC.js.map +1 -0
- package/dist/{chunk-6IWUTOBS.js → chunk-H4BMPRP6.js} +2 -2
- package/dist/chunk-H4BMPRP6.js.map +1 -0
- package/dist/{chunk-66FMKFHB.cjs → chunk-MO5QVSNF.cjs} +93 -4
- package/dist/chunk-MO5QVSNF.cjs.map +1 -0
- package/dist/{chunk-NCXRWPGN.cjs → chunk-XT3KG3OH.cjs} +2 -2
- package/dist/chunk-XT3KG3OH.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +1 -1
- package/dist/mask.cjs +50 -22
- package/dist/mask.d.cts +50 -1
- package/dist/mask.d.ts +50 -1
- package/dist/mask.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-66FMKFHB.cjs.map +0 -1
- package/dist/chunk-6IWUTOBS.js.map +0 -1
- package/dist/chunk-JJVBRZTY.js.map +0 -1
- package/dist/chunk-NCXRWPGN.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @snowcone-app/loaders
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#6856](https://github.com/snowcone-app/snowcone-monorepo/pull/6856) [`660512c`](https://github.com/snowcone-app/snowcone-monorepo/commit/660512cb888bf255f6bd003fbaaf0967f18e2908) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Print masks reach crops and the editor. Loaders take `maskWindow` (`{ x, y, w, h }`, fractions of the mask's picture): the part of the mask's picture the picture on screen shows; the loader cuts the mask to it (`cropGrid`). A plate's 8:3 strip has its own mask (`mockups[].strip.printMask`), and `HeroProductImage` hands its beam that mask cut to the crop it shows (`printMaskFor(product, mockupId, stripView)`), so the desktop wide hero sweeps only the print on a first edit too. `Editor.Preview` passes the scene's mask (`product.mockups[].printMask`) to its loader as `maskUrl`; `RenderProductMockup.printMask` is typed in the SDK.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#6840](https://github.com/snowcone-app/snowcone-monorepo/pull/6840) [`b9f29e4`](https://github.com/snowcone-app/snowcone-monorepo/commit/b9f29e4ff0b43acb0ef7c3210673a3dd6b8cb2dd) Thanks [@kevinsproles](https://github.com/kevinsproles)! - Loaders take `maskUrl`: a mockup's print mask (made on the server from a white and a black render; the catalog names it on every mockup as `mockups[].printMask`). With it the beam sweeps only the print from the first edit of a mockup it has never seen, instead of the whole picture. Fetched once per page; a 404 or a crop of the picture leaves the beam learning from the frames as before. `data-sc-loader-mask-url` stamps what became of it. The SDK keeps `printMask` through a parse; `HeroProductImage` hands it to its beam (`printMaskUrlFor(product, mockupId)`).
|
|
14
|
+
|
|
3
15
|
## 0.3.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ once the picture has caught up.
|
|
|
28
28
|
onExited={() => setShowLoader(false)}
|
|
29
29
|
picture={() => imgRef.current} // the picture on screen now
|
|
30
30
|
maskKey={mockupId} // what it learns is kept per scene
|
|
31
|
+
maskUrl={mockup.printMask} // the print, known from the first edit (a Snowcone catalog mockup's printMask)
|
|
31
32
|
fit="cover" // the <img>'s object-fit
|
|
32
33
|
/>
|
|
33
34
|
)}
|
|
@@ -40,6 +41,13 @@ localStorage (about 1 KB a scene, at most 40 scenes), so the next edit of the sa
|
|
|
40
41
|
once. Until it knows, it covers the whole picture. Reading the picture needs it to be same-origin or served with CORS
|
|
41
42
|
(`crossOrigin="anonymous"`); otherwise the beam just covers the whole picture.
|
|
42
43
|
|
|
44
|
+
Snowcone's catalog names a print mask on every mockup (`mockups[].printMask`): where its picture shows the print,
|
|
45
|
+
made once on the server from a white and a black render. Pass it as `maskUrl` and the beam stays on the print from the
|
|
46
|
+
FIRST edit of a mockup this browser has never seen (`data-sc-loader-mask="given"`). It is fetched once per page (the URL
|
|
47
|
+
is immutable, so the browser keeps it); a 404 (not made yet), a crop of the picture (another shape) or a bad file leaves
|
|
48
|
+
the beam learning as before, and `data-sc-loader-mask-url` says which (`loading` | `used` | `absent` | `other-shape` |
|
|
49
|
+
`E_LOADER_MASK_FETCH` | `E_LOADER_MASK_INVALID`).
|
|
50
|
+
|
|
43
51
|
Already know the area? Pass `mask` (an image whose alpha is the area, in the picture's own pixels) and nothing is
|
|
44
52
|
learned.
|
|
45
53
|
|
|
@@ -63,6 +71,6 @@ animation frame, `finish(now)` when caught up, and `setRegion(...)` to give it a
|
|
|
63
71
|
## Writing a loader
|
|
64
72
|
|
|
65
73
|
A loader is a component that takes `LoaderProps` (from `@snowcone-app/loaders`): `visible`, `onExited`, `picture`,
|
|
66
|
-
`maskKey`, `fit`, `mask`. It should never take pointer events, always play an exit when `visible` turns false, and turn
|
|
74
|
+
`maskKey`, `fit`, `mask`, `maskUrl`. It should never take pointer events, always play an exit when `visible` turns false, and turn
|
|
67
75
|
back (not restart) if `visible` comes back before its exit ends. `@snowcone-app/loaders/mask` has the frame-comparison
|
|
68
76
|
helpers the beam uses.
|
package/dist/beam/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkMO5QVSNF_cjs = require('../chunk-MO5QVSNF.cjs');
|
|
4
|
+
var chunkXT3KG3OH_cjs = require('../chunk-XT3KG3OH.cjs');
|
|
5
5
|
var react = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
@@ -237,6 +237,8 @@ function BeamLoader({
|
|
|
237
237
|
maskKey,
|
|
238
238
|
fit = "cover",
|
|
239
239
|
mask,
|
|
240
|
+
maskUrl,
|
|
241
|
+
maskWindow,
|
|
240
242
|
look = "beam",
|
|
241
243
|
tone = "auto",
|
|
242
244
|
className,
|
|
@@ -248,8 +250,9 @@ function BeamLoader({
|
|
|
248
250
|
});
|
|
249
251
|
const [phase, setPhase] = react.useState("loading");
|
|
250
252
|
const [maskSource, setMaskSource] = react.useState(mask ? "given" : "whole");
|
|
251
|
-
const live = react.useRef({ picture, maskKey, fit, onExited });
|
|
252
|
-
live.current = { picture, maskKey, fit, onExited };
|
|
253
|
+
const live = react.useRef({ picture, maskKey, maskUrl, maskWindow, fit, onExited });
|
|
254
|
+
live.current = { picture, maskKey, maskUrl, maskWindow, fit, onExited };
|
|
255
|
+
const [maskUrlState, setMaskUrlState] = react.useState(mask || !maskUrl ? void 0 : "loading");
|
|
253
256
|
const [area, setArea] = react.useState(void 0);
|
|
254
257
|
const [surface, setSurface] = react.useState(void 0);
|
|
255
258
|
react.useEffect(() => {
|
|
@@ -269,27 +272,34 @@ function BeamLoader({
|
|
|
269
272
|
staleSrc: null,
|
|
270
273
|
lastSnap: null,
|
|
271
274
|
shown: null,
|
|
272
|
-
shownAt: -Infinity
|
|
275
|
+
shownAt: -Infinity,
|
|
276
|
+
/** The scene's given mask (maskUrl): fetched, waiting for the picture's size, then on the picture's grid. */
|
|
277
|
+
given: null,
|
|
278
|
+
givenBits: null,
|
|
279
|
+
givenUrl: null,
|
|
280
|
+
/** The picture size and window the given mask was last laid on (a new crop lays it again). */
|
|
281
|
+
givenOn: null
|
|
273
282
|
};
|
|
283
|
+
let disposed = false;
|
|
274
284
|
const srcOf = (el) => el && typeof HTMLImageElement !== "undefined" && el instanceof HTMLImageElement ? el.currentSrc || el.src : "";
|
|
275
285
|
const look_ = () => {
|
|
276
286
|
const el = pic();
|
|
277
287
|
if (!el) return null;
|
|
278
|
-
const n =
|
|
288
|
+
const n = chunkXT3KG3OH_cjs.naturalSize(el);
|
|
279
289
|
if (n.w > 0) L.natural = n;
|
|
280
290
|
const src = srcOf(el);
|
|
281
291
|
if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;
|
|
282
|
-
const snap =
|
|
292
|
+
const snap = chunkMO5QVSNF_cjs.snapshotPicture(el);
|
|
283
293
|
if (snap) {
|
|
284
294
|
L.lastSrc = src;
|
|
285
295
|
L.lastSnap = snap;
|
|
286
296
|
}
|
|
287
297
|
return snap;
|
|
288
298
|
};
|
|
289
|
-
const surfaceOf = (s, alpha) => s ?
|
|
299
|
+
const surfaceOf = (s, alpha) => s ? chunkMO5QVSNF_cjs.meanLuma(s, alpha) > LIGHT_SURFACE ? "light" : "dark" : void 0;
|
|
290
300
|
const apply = (bits, w, h, from, source, force = false) => {
|
|
291
|
-
const alpha =
|
|
292
|
-
const box =
|
|
301
|
+
const alpha = chunkMO5QVSNF_cjs.softAlpha(bits, w, h, { grow: 4, blur: 6 });
|
|
302
|
+
const box = chunkMO5QVSNF_cjs.alphaBox(alpha, w, h);
|
|
293
303
|
if (!box) return;
|
|
294
304
|
const t = now();
|
|
295
305
|
if (!force) {
|
|
@@ -300,21 +310,68 @@ function BeamLoader({
|
|
|
300
310
|
if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;
|
|
301
311
|
}
|
|
302
312
|
}
|
|
303
|
-
const colour = from ?
|
|
313
|
+
const colour = from ? chunkMO5QVSNF_cjs.meanColour(from, bits) : null;
|
|
304
314
|
const surf = surfaceOf(from, alpha);
|
|
305
|
-
engine.setRegion({ mask:
|
|
315
|
+
engine.setRegion({ mask: chunkMO5QVSNF_cjs.alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : void 0, surface: surf }, t);
|
|
306
316
|
L.shown = box;
|
|
307
317
|
L.shownAt = t;
|
|
308
318
|
setMaskSource(source);
|
|
309
319
|
setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(","));
|
|
310
320
|
setSurface(surf);
|
|
311
321
|
};
|
|
322
|
+
const showGiven = () => {
|
|
323
|
+
const n = L.natural;
|
|
324
|
+
if (!L.given || !n || !(n.w > 0)) return false;
|
|
325
|
+
const win = live.current.maskWindow;
|
|
326
|
+
const on = `${n.w}x${n.h}@${win ? [win.x, win.y, win.w, win.h].join(",") : "whole"}`;
|
|
327
|
+
if (L.givenOn === on) return false;
|
|
328
|
+
L.givenOn = on;
|
|
329
|
+
const g = win ? chunkMO5QVSNF_cjs.cropGrid(L.given, win) : L.given;
|
|
330
|
+
if (!g || !chunkMO5QVSNF_cjs.sameShape(g.w, g.h, n.w, n.h)) {
|
|
331
|
+
L.givenBits = null;
|
|
332
|
+
setMaskUrlState("other-shape");
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const { w, h } = chunkMO5QVSNF_cjs.gridSize(n.w, n.h);
|
|
336
|
+
const bits = chunkMO5QVSNF_cjs.resampleBits(g.bits, g.w, g.h, w, h);
|
|
337
|
+
L.givenBits = bits;
|
|
338
|
+
L.bits = bits;
|
|
339
|
+
const snap = L.lastSnap && L.lastSnap.w === w && L.lastSnap.h === h ? L.lastSnap : null;
|
|
340
|
+
apply(bits, w, h, snap, "given", true);
|
|
341
|
+
setMaskUrlState("used");
|
|
342
|
+
return true;
|
|
343
|
+
};
|
|
344
|
+
const took = (url, key, r) => {
|
|
345
|
+
if (disposed || L.givenUrl !== url || L.key !== key) return;
|
|
346
|
+
if (r.state === "mask") {
|
|
347
|
+
L.given = r.mask;
|
|
348
|
+
showGiven();
|
|
349
|
+
} else setMaskUrlState(r.state === "absent" ? "absent" : r.code);
|
|
350
|
+
};
|
|
351
|
+
const askGiven = () => {
|
|
352
|
+
const url = live.current.maskUrl;
|
|
353
|
+
L.given = null;
|
|
354
|
+
L.givenBits = null;
|
|
355
|
+
L.givenOn = null;
|
|
356
|
+
L.givenUrl = url ?? null;
|
|
357
|
+
if (!url) {
|
|
358
|
+
setMaskUrlState(void 0);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
const key = L.key;
|
|
362
|
+
const ready = chunkMO5QVSNF_cjs.peekPrintMask(url);
|
|
363
|
+
if (ready) return took(url, key, ready);
|
|
364
|
+
setMaskUrlState("loading");
|
|
365
|
+
void chunkMO5QVSNF_cjs.loadPrintMask(url).then((r) => took(url, key, r));
|
|
366
|
+
};
|
|
312
367
|
const startOn = (snap) => {
|
|
313
368
|
L.key = live.current.maskKey;
|
|
314
369
|
L.base = snap;
|
|
315
370
|
L.bits = null;
|
|
316
371
|
L.shown = null;
|
|
317
|
-
|
|
372
|
+
askGiven();
|
|
373
|
+
if (L.givenBits) return;
|
|
374
|
+
const known = snap && L.key ? chunkMO5QVSNF_cjs.recallMask(L.key, snap.w, snap.h) : null;
|
|
318
375
|
if (known && snap) {
|
|
319
376
|
L.bits = known;
|
|
320
377
|
apply(known, snap.w, snap.h, snap, "learned", true);
|
|
@@ -327,7 +384,7 @@ function BeamLoader({
|
|
|
327
384
|
}
|
|
328
385
|
};
|
|
329
386
|
if (mask) {
|
|
330
|
-
const s =
|
|
387
|
+
const s = chunkMO5QVSNF_cjs.snapshotPicture(mask);
|
|
331
388
|
if (s) {
|
|
332
389
|
const bits = new Uint8Array(s.w * s.h);
|
|
333
390
|
for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;
|
|
@@ -339,6 +396,7 @@ function BeamLoader({
|
|
|
339
396
|
const learn = () => {
|
|
340
397
|
if (mask) return;
|
|
341
398
|
const cur = look_();
|
|
399
|
+
if (L.given && live.current.maskKey === L.key) showGiven();
|
|
342
400
|
if (!cur) return;
|
|
343
401
|
if (live.current.maskKey !== L.key) {
|
|
344
402
|
L.staleSrc = L.lastSrc;
|
|
@@ -346,6 +404,10 @@ function BeamLoader({
|
|
|
346
404
|
L.base = null;
|
|
347
405
|
L.bits = null;
|
|
348
406
|
L.shown = null;
|
|
407
|
+
L.given = null;
|
|
408
|
+
L.givenBits = null;
|
|
409
|
+
L.givenOn = null;
|
|
410
|
+
L.givenUrl = null;
|
|
349
411
|
return;
|
|
350
412
|
}
|
|
351
413
|
if (L.staleSrc !== null) {
|
|
@@ -354,14 +416,15 @@ function BeamLoader({
|
|
|
354
416
|
return startOn(cur);
|
|
355
417
|
}
|
|
356
418
|
if (!L.base) return startOn(cur);
|
|
357
|
-
const bits =
|
|
358
|
-
if (!bits ||
|
|
419
|
+
const bits = chunkMO5QVSNF_cjs.changedBits(L.base, cur);
|
|
420
|
+
if (!bits || chunkMO5QVSNF_cjs.coverageOf(bits) > chunkMO5QVSNF_cjs.UNRELIABLE_COVERAGE) {
|
|
359
421
|
L.base = cur;
|
|
360
422
|
return;
|
|
361
423
|
}
|
|
362
|
-
if (!
|
|
424
|
+
if (!chunkMO5QVSNF_cjs.isLearnable(bits)) return;
|
|
363
425
|
const key = L.key;
|
|
364
|
-
const
|
|
426
|
+
const learned = key ? chunkMO5QVSNF_cjs.rememberMask(key, cur.w, cur.h, bits) : L.bits ? chunkMO5QVSNF_cjs.orBits(L.bits, bits) : bits;
|
|
427
|
+
const all = L.givenBits && L.givenBits.length === learned.length ? chunkMO5QVSNF_cjs.orBits(L.givenBits, learned) : learned;
|
|
365
428
|
L.bits = all;
|
|
366
429
|
apply(all, cur.w, cur.h, L.base, "learned");
|
|
367
430
|
};
|
|
@@ -381,13 +444,14 @@ function BeamLoader({
|
|
|
381
444
|
c.height = H;
|
|
382
445
|
}
|
|
383
446
|
const n = L.natural;
|
|
384
|
-
const place = n ?
|
|
447
|
+
const place = n ? chunkXT3KG3OH_cjs.fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };
|
|
385
448
|
engine.draw(ctx, W, H, place, now(), scale);
|
|
386
449
|
if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;
|
|
387
450
|
};
|
|
388
451
|
if (typeof requestAnimationFrame === "function") raf = requestAnimationFrame(draw);
|
|
389
452
|
learnNowRef.current = learn;
|
|
390
453
|
return () => {
|
|
454
|
+
disposed = true;
|
|
391
455
|
clearInterval(learnTimer);
|
|
392
456
|
if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(raf);
|
|
393
457
|
engineRef.current = null;
|
|
@@ -421,6 +485,7 @@ function BeamLoader({
|
|
|
421
485
|
"data-sc-loader-look": look,
|
|
422
486
|
"data-sc-loader-phase": phase,
|
|
423
487
|
"data-sc-loader-mask": maskSource,
|
|
488
|
+
"data-sc-loader-mask-url": maskUrlState,
|
|
424
489
|
"data-sc-loader-area": area,
|
|
425
490
|
"data-sc-loader-surface": surface,
|
|
426
491
|
className,
|
package/dist/beam/index.cjs.map
CHANGED
|
@@ -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,IAAM,aAAA,GAAgB;AAEtB,IAAM,YAAA,GAAe;AAErB,IAAM,YAAA,GAAe;AAErB,IAAM,gBAAA,GAAmB;AAEzB,IAAM,cAAA,GAAiB,mBAAmB,YAAA,GAAe;AAEzD,IAAM,cAAA,GAAiB;AAQ9B,IAAM,KAAA,GAAQ,EAAE,IAAA,EAAM,aAAA,EAAe,MAAM,YAAA,EAAa;AAExD,IAAM,QAAA,GAAW,EAAE,IAAA,EAAM,YAAA,EAAc,MAAM,YAAA,EAAa;AAC1D,IAAM,UAAU,CAAC,WAAA,EAAa,cAAc,YAAA,EAAc,YAAA,EA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MAAM,KAAK,OAAA,CAAQ,QAAA,MAAc,cAAc,CAAA;AACpE,MAAA,OAAO,MAAM,aAAa,CAAC,CAAA;AAAA,IAC7B;AACA,IAAA,IAAI,MAAA,CAAO,OAAO,SAAA,EAAW;AAC3B,MAAA,MAAA,CAAO,OAAO,GAAG,CAAA;AACjB,MAAA,QAAA,CAAS,SAAS,CAAA;AAAA,IACpB;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,uBACEgB,cAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,GAAA,EAAK,SAAA;AAAA,MACL,aAAA,EAAY,MAAA;AAAA,MACZ,gBAAA,EAAe,MAAA;AAAA,MACf,qBAAA,EAAqB,IAAA;AAAA,MACrB,sBAAA,EAAsB,KAAA;AAAA,MACtB,qBAAA,EAAqB,UAAA;AAAA,MACrB,qBAAA,EAAqB,IAAA;AAAA,MACrB,wBAAA,EAAwB,OAAA;AAAA,MACxB,SAAA;AAAA,MACA,KAAA,EAAO;AAAA,QACL,QAAA,EAAU,UAAA;AAAA,QACV,KAAA,EAAO,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"]}
|
|
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","cropGrid","sameShape","gridSize","resampleBits","peekPrintMask","loadPrintMask","recallMask","changedBits","coverageOf","UNRELIABLE_COVERAGE","isLearnable","rememberMask","orBits","fitRect","jsx"],"mappings":";;;;;;;;AAUO,IAAM,eAAA,GAAkB;AAExB,IAAM,aAAA,GAAgB;AAEtB,IAAM,YAAA,GAAe;AAErB,IAAM,YAAA,GAAe;AAErB,IAAM,gBAAA,GAAmB;AAEzB,IAAM,cAAA,GAAiB,mBAAmB,YAAA,GAAe;AAEzD,IAAM,cAAA,GAAiB;AAQ9B,IAAM,KAAA,GAAQ,EA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,MAAA,MAAA,CAAO,OAAO,GAAG,CAAA;AACjB,MAAA,QAAA,CAAS,WAAW,CAAA;AACpB,MAAA,MAAM,IAAI,UAAA,CAAW,MAAM,KAAK,OAAA,CAAQ,QAAA,MAAc,cAAc,CAAA;AACpE,MAAA,OAAO,MAAM,aAAa,CAAC,CAAA;AAAA,IAC7B;AACA,IAAA,IAAI,MAAA,CAAO,OAAO,SAAA,EAAW;AAC3B,MAAA,MAAA,CAAO,OAAO,GAAG,CAAA;AACjB,MAAA,QAAA,CAAS,SAAS,CAAA;AAAA,IACpB;AACA,IAAA,OAAO,MAAA;AAAA,EACT,CAAA,EAAG,CAAC,OAAO,CAAC,CAAA;AAEZ,EAAA,uBACEsB,cAAA;AAAA,IAAC,QAAA;AAAA,IAAA;AAAA,MACC,GAAA,EAAK,SAAA;AAAA,MACL,aAAA,EAAY,MAAA;AAAA,MACZ,gBAAA,EAAe,MAAA;AAAA,MACf,qBAAA,EAAqB,IAAA;AAAA,MACrB,sBAAA,EAAsB,KAAA;AAAA,MACtB,qBAAA,EAAqB,UAAA;AAAA,MACrB,yBAAA,EAAyB,YAAA;AAAA,MACzB,qBAAA,EAAqB,IAAA;AAAA,MACrB,wBAAA,EAAwB,OAAA;AAAA,MACxB,SAAA;AAAA,MACA,KAAA,EAAO;AAAA,QACL,QAAA,EAAU,UAAA;AAAA,QACV,KAAA,EAAO,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 LoaderMaskUrlState, type LoaderPhase, type LoaderProps } from \"../index\";\nimport { cropGrid,\n alphaBox,\n alphaCanvas,\n changedBits,\n coverageOf,\n gridSize,\n isLearnable,\n loadPrintMask,\n peekPrintMask,\n resampleBits,\n sameShape,\n type GridMask,\n type MaskLoad,\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. Give it\n * `maskUrl` too (the mockup's print mask, Snowcone's `mockups[].printMask`) and it knows the print from the FIRST edit.\n *\n * Machine-readable state: `data-sc-loader=\"beam\"`, `data-sc-loader-phase` (`loading` | `finishing`),\n * `data-sc-loader-mask` (`whole` | `learned` | `given`), `data-sc-loader-mask-url` (what became of `maskUrl`:\n * {@link LoaderMaskUrlState}).\n */\nexport function BeamLoader({\n visible,\n onExited,\n picture,\n maskKey,\n fit = \"cover\",\n mask,\n maskUrl,\n maskWindow,\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, maskUrl, maskWindow, fit, onExited });\n live.current = { picture, maskKey, maskUrl, maskWindow, fit, onExited };\n // what became of maskUrl, stamped as data-sc-loader-mask-url (LoaderMaskUrlState)\n const [maskUrlState, setMaskUrlState] = useState<LoaderMaskUrlState | undefined>(mask || !maskUrl ? undefined : \"loading\");\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 /** The scene's given mask (maskUrl): fetched, waiting for the picture's size, then on the picture's grid. */\n given: null as GridMask | null,\n givenBits: null as Uint8Array | null,\n givenUrl: null as string | null,\n /** The picture size and window the given mask was last laid on (a new crop lays it again). */\n givenOn: null as string | null,\n };\n let disposed = false;\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 /**\n * The given mask on screen, once the picture's size is known: read onto the picture's grid and shown as the area.\n * Cut to `maskWindow` first when the host names one (a crop of the mask's picture). Only for a picture of the same\n * shape: anything else (an unnamed crop) keeps learning. `true` once it is shown.\n */\n const showGiven = (): boolean => {\n const n = L.natural;\n if (!L.given || !n || !(n.w > 0)) return false;\n const win = live.current.maskWindow;\n const on = `${n.w}x${n.h}@${win ? [win.x, win.y, win.w, win.h].join(\",\") : \"whole\"}`;\n if (L.givenOn === on) return false; // laid already (or refused) on this picture and window\n L.givenOn = on;\n const g = win ? cropGrid(L.given, win) : L.given;\n if (!g || !sameShape(g.w, g.h, n.w, n.h)) {\n L.givenBits = null;\n setMaskUrlState(\"other-shape\");\n return false;\n }\n const { w, h } = gridSize(n.w, n.h);\n const bits = resampleBits(g.bits, g.w, g.h, w, h);\n L.givenBits = bits;\n L.bits = bits;\n const snap = L.lastSnap && L.lastSnap.w === w && L.lastSnap.h === h ? L.lastSnap : null;\n apply(bits, w, h, snap, \"given\", true);\n setMaskUrlState(\"used\");\n return true;\n };\n /** What the scene's mask URL answered: a mask goes on screen (now, or once the picture has a size). */\n const took = (url: string, key: string | undefined, r: MaskLoad) => {\n if (disposed || L.givenUrl !== url || L.key !== key) return; // another scene by now\n if (r.state === \"mask\") {\n L.given = r.mask;\n showGiven();\n } else setMaskUrlState(r.state === \"absent\" ? \"absent\" : r.code);\n };\n /** Asks for the scene's given mask (maskUrl), when the host named one: at once if this page already has it. */\n const askGiven = () => {\n const url = live.current.maskUrl;\n L.given = null;\n L.givenBits = null;\n L.givenOn = null;\n L.givenUrl = url ?? null;\n if (!url) {\n setMaskUrlState(undefined);\n return;\n }\n const key = L.key;\n const ready = peekPrintMask(url);\n if (ready) return took(url, key, ready);\n setMaskUrlState(\"loading\");\n void loadPrintMask(url).then((r) => took(url, key, r));\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 askGiven();\n if (L.givenBits) return; // the given mask is on screen: it wins over anything learned\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 // a given mask that came before the picture had a size (or a picture that can't be read: no CORS) goes on now; so\n // does one whose picture became another crop (a new window or size: laid again, cut to it)\n if (L.given && live.current.maskKey === L.key) showGiven();\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 L.given = null;\n L.givenBits = null;\n L.givenOn = null;\n L.givenUrl = 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 learned = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;\n // on a given mask, what is learned only adds to it (an area the server's mask missed); it never shrinks it\n const all = L.givenBits && L.givenBits.length === learned.length ? orBits(L.givenBits, learned) : learned;\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 disposed = true;\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-mask-url={maskUrlState}\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"]}
|
package/dist/beam/index.d.cts
CHANGED
|
@@ -127,11 +127,13 @@ interface BeamLoaderProps extends LoaderProps {
|
|
|
127
127
|
*
|
|
128
128
|
* Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it
|
|
129
129
|
* `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per
|
|
130
|
-
* scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.
|
|
130
|
+
* scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture. Give it
|
|
131
|
+
* `maskUrl` too (the mockup's print mask, Snowcone's `mockups[].printMask`) and it knows the print from the FIRST edit.
|
|
131
132
|
*
|
|
132
133
|
* Machine-readable state: `data-sc-loader="beam"`, `data-sc-loader-phase` (`loading` | `finishing`),
|
|
133
|
-
* `data-sc-loader-mask` (`whole` | `learned` | `given`)
|
|
134
|
+
* `data-sc-loader-mask` (`whole` | `learned` | `given`), `data-sc-loader-mask-url` (what became of `maskUrl`:
|
|
135
|
+
* {@link LoaderMaskUrlState}).
|
|
134
136
|
*/
|
|
135
|
-
declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
|
|
137
|
+
declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, maskUrl, maskWindow, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
|
|
136
138
|
|
|
137
139
|
export { BEAM_FADE_IN_MS, BEAM_FINISH_MS, BEAM_PASS_MS, BEAM_RUSH_MAX_MS, BEAM_SWEEP_MS, BEAM_TAIL_MS, BeamEngine, type BeamEngineOptions, BeamLoader, type BeamLoaderProps, type BeamLook, BeamMotion, type BeamPosition, type BeamRegion, type BeamTone, LEARN_EVERY_MS, REGION_FADE_MS };
|
package/dist/beam/index.d.ts
CHANGED
|
@@ -127,11 +127,13 @@ interface BeamLoaderProps extends LoaderProps {
|
|
|
127
127
|
*
|
|
128
128
|
* Fills its positioned parent (put it over the picture's `<img>`). It finds the part that changes by itself: give it
|
|
129
129
|
* `picture` (the `<img>` on screen) and a `maskKey` (the mockup id) and it compares frames, remembering the area per
|
|
130
|
-
* scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture.
|
|
130
|
+
* scene, so the next edit starts on the right part at once. Until it knows, it covers the whole picture. Give it
|
|
131
|
+
* `maskUrl` too (the mockup's print mask, Snowcone's `mockups[].printMask`) and it knows the print from the FIRST edit.
|
|
131
132
|
*
|
|
132
133
|
* Machine-readable state: `data-sc-loader="beam"`, `data-sc-loader-phase` (`loading` | `finishing`),
|
|
133
|
-
* `data-sc-loader-mask` (`whole` | `learned` | `given`)
|
|
134
|
+
* `data-sc-loader-mask` (`whole` | `learned` | `given`), `data-sc-loader-mask-url` (what became of `maskUrl`:
|
|
135
|
+
* {@link LoaderMaskUrlState}).
|
|
134
136
|
*/
|
|
135
|
-
declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
|
|
137
|
+
declare function BeamLoader({ visible, onExited, picture, maskKey, fit, mask, maskUrl, maskWindow, look, tone, className, style, }: BeamLoaderProps): react_jsx_runtime.JSX.Element;
|
|
136
138
|
|
|
137
139
|
export { BEAM_FADE_IN_MS, BEAM_FINISH_MS, BEAM_PASS_MS, BEAM_RUSH_MAX_MS, BEAM_SWEEP_MS, BEAM_TAIL_MS, BeamEngine, type BeamEngineOptions, BeamLoader, type BeamLoaderProps, type BeamLook, BeamMotion, type BeamPosition, type BeamRegion, type BeamTone, LEARN_EVERY_MS, REGION_FADE_MS };
|