@snowcone-app/loaders 0.0.0-stage → 0.3.1
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 +21 -0
- package/README.md +67 -2
- package/dist/beam/index.cjs +438 -0
- package/dist/beam/index.cjs.map +1 -0
- package/dist/beam/index.d.cts +137 -0
- package/dist/beam/index.d.ts +137 -0
- package/dist/beam/index.js +426 -0
- package/dist/beam/index.js.map +1 -0
- package/dist/chunk-2TO7VCSK.js +238 -0
- package/dist/chunk-2TO7VCSK.js.map +1 -0
- package/dist/chunk-6IWUTOBS.js +16 -0
- package/dist/chunk-6IWUTOBS.js.map +1 -0
- package/dist/chunk-7N24M2SH.cjs +259 -0
- package/dist/chunk-7N24M2SH.cjs.map +1 -0
- package/dist/chunk-NCXRWPGN.cjs +19 -0
- package/dist/chunk-NCXRWPGN.cjs.map +1 -0
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mask.cjs +89 -0
- package/dist/mask.cjs.map +1 -0
- package/dist/mask.d.cts +90 -0
- package/dist/mask.d.ts +90 -0
- package/dist/mask.js +4 -0
- package/dist/mask.js.map +1 -0
- package/package.json +84 -3
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
import { snapshotPicture, softAlpha, alphaBox, meanColour, alphaCanvas, recallMask, changedBits, coverageOf, UNRELIABLE_COVERAGE, isLearnable, rememberMask, orBits, meanLuma } from '../chunk-2TO7VCSK.js';
|
|
2
|
+
import { naturalSize, fitRect } from '../chunk-6IWUTOBS.js';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/beam/engine.ts
|
|
7
|
+
var BEAM_FADE_IN_MS = 450;
|
|
8
|
+
var BEAM_SWEEP_MS = 1150;
|
|
9
|
+
var BEAM_PASS_MS = 380;
|
|
10
|
+
var BEAM_TAIL_MS = 150;
|
|
11
|
+
var BEAM_RUSH_MAX_MS = 190;
|
|
12
|
+
var BEAM_FINISH_MS = BEAM_RUSH_MAX_MS + BEAM_PASS_MS + BEAM_TAIL_MS;
|
|
13
|
+
var REGION_FADE_MS = 300;
|
|
14
|
+
var TONES = { cool: "190,222,255", warm: "255,150,60" };
|
|
15
|
+
var ON_LIGHT = { glow: "70,140,255", core: "40,110,240" };
|
|
16
|
+
var FRINGES = ["255,70,70", "255,170,40", "250,240,80", "70,220,110", "70,150,255", "160,90,255"];
|
|
17
|
+
var clamp = (v, a = 0, b = 1) => Math.max(a, Math.min(b, v));
|
|
18
|
+
var ease = (p) => 0.5 - 0.5 * Math.cos(Math.PI * clamp(p));
|
|
19
|
+
var BeamMotion = class {
|
|
20
|
+
t0;
|
|
21
|
+
ph0 = 0;
|
|
22
|
+
/** When the beam started (its fade-in runs from here). */
|
|
23
|
+
bornAt;
|
|
24
|
+
fin = null;
|
|
25
|
+
constructor(now) {
|
|
26
|
+
this.t0 = now;
|
|
27
|
+
this.bornAt = now;
|
|
28
|
+
}
|
|
29
|
+
get finishing() {
|
|
30
|
+
return this.fin !== null;
|
|
31
|
+
}
|
|
32
|
+
loading(now) {
|
|
33
|
+
const ph = (((now - this.t0) / BEAM_SWEEP_MS + this.ph0) % 2 + 2) % 2;
|
|
34
|
+
return ph < 1 ? { s: ease(ph), dir: 1 } : { s: ease(2 - ph), dir: -1 };
|
|
35
|
+
}
|
|
36
|
+
fadeIn(now) {
|
|
37
|
+
const p = clamp((now - this.bornAt) / BEAM_FADE_IN_MS);
|
|
38
|
+
return p * p;
|
|
39
|
+
}
|
|
40
|
+
at(now) {
|
|
41
|
+
if (!this.fin) return { ...this.loading(now), alpha: this.fadeIn(now), finishing: false, done: false };
|
|
42
|
+
const { at, from, end, rush, alpha } = this.fin;
|
|
43
|
+
const t = now - at;
|
|
44
|
+
if (t >= rush + BEAM_PASS_MS + BEAM_TAIL_MS) return { s: 1 - end, dir: end === 0 ? 1 : -1, alpha: 0, finishing: true, done: true };
|
|
45
|
+
if (t < rush) {
|
|
46
|
+
const p2 = t / rush;
|
|
47
|
+
return { s: from + (end - from) * (1 - (1 - p2) * (1 - p2)), dir: end > from ? 1 : -1, alpha, finishing: true, done: false };
|
|
48
|
+
}
|
|
49
|
+
const p = (t - rush) / BEAM_PASS_MS;
|
|
50
|
+
const s = p >= 1 ? 1 - end : end + (1 - 2 * end) * ease(p);
|
|
51
|
+
const fadeFrom = rush + BEAM_PASS_MS * 0.6, fadeLen = BEAM_PASS_MS * 0.4 + BEAM_TAIL_MS;
|
|
52
|
+
const a = t <= fadeFrom ? alpha : alpha * (1 - clamp((t - fadeFrom) / fadeLen));
|
|
53
|
+
return { s, dir: end === 0 ? 1 : -1, alpha: a, finishing: true, done: false };
|
|
54
|
+
}
|
|
55
|
+
/** The picture has caught up: dash to the nearer edge, one pass across, fade. Repeated calls change nothing. */
|
|
56
|
+
finish(now) {
|
|
57
|
+
if (this.fin) return;
|
|
58
|
+
const cur = this.at(now);
|
|
59
|
+
const end = cur.s < 0.5 ? 0 : 1;
|
|
60
|
+
this.fin = { at: now, from: cur.s, end, rush: 60 + (BEAM_RUSH_MAX_MS - 60) * 2 * Math.abs(cur.s - end), alpha: cur.alpha };
|
|
61
|
+
}
|
|
62
|
+
/** Behind again before the exit ended: carry on gliding from where the beam is, the way it was going. */
|
|
63
|
+
resume(now) {
|
|
64
|
+
if (!this.fin) return;
|
|
65
|
+
const cur = this.at(now);
|
|
66
|
+
this.fin = null;
|
|
67
|
+
const ph = Math.acos(clamp(1 - 2 * cur.s, -1, 1)) / Math.PI;
|
|
68
|
+
this.ph0 = cur.dir > 0 ? ph : 2 - ph;
|
|
69
|
+
this.t0 = now;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var WHOLE = { mask: null, box: null };
|
|
73
|
+
var BeamEngine = class {
|
|
74
|
+
motion;
|
|
75
|
+
look;
|
|
76
|
+
tone;
|
|
77
|
+
reduced;
|
|
78
|
+
prev = WHOLE;
|
|
79
|
+
next = WHOLE;
|
|
80
|
+
regionAt = -Infinity;
|
|
81
|
+
maskLayer = null;
|
|
82
|
+
constructor(opts, now) {
|
|
83
|
+
this.motion = new BeamMotion(now);
|
|
84
|
+
this.look = opts.look ?? "beam";
|
|
85
|
+
this.tone = opts.tone ?? "auto";
|
|
86
|
+
this.reduced = !!opts.reducedMotion;
|
|
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:
|
|
89
|
+
* over the whole frame (the first edit of a scene) a painted line would cross the background too, so it stays light. */
|
|
90
|
+
get onLight() {
|
|
91
|
+
return !!this.next.mask && this.next.surface === "light";
|
|
92
|
+
}
|
|
93
|
+
/** How the canvas should blend over the picture: light only adds (`screen`), the soft laser and any beam on a
|
|
94
|
+
* light surface paint on. */
|
|
95
|
+
get blendMode() {
|
|
96
|
+
return this.look === "soft" || this.onLight ? "normal" : "screen";
|
|
97
|
+
}
|
|
98
|
+
/** A new area to stay on; the old one fades into it over {@link REGION_FADE_MS}. While the beam is still fading in
|
|
99
|
+
* from the whole frame, it takes the area at once: no glimpse of a beam across the whole picture first. */
|
|
100
|
+
setRegion(region, now) {
|
|
101
|
+
const next = region ?? WHOLE;
|
|
102
|
+
if (!this.next.mask && now - this.motion.bornAt < BEAM_FADE_IN_MS) {
|
|
103
|
+
this.prev = this.next = next;
|
|
104
|
+
this.regionAt = -Infinity;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.prev = this.mixWeight(now) >= 1 ? this.next : this.prev;
|
|
108
|
+
this.next = next;
|
|
109
|
+
this.regionAt = now;
|
|
110
|
+
}
|
|
111
|
+
finish(now) {
|
|
112
|
+
this.motion.finish(now);
|
|
113
|
+
}
|
|
114
|
+
resume(now) {
|
|
115
|
+
this.motion.resume(now);
|
|
116
|
+
}
|
|
117
|
+
mixWeight(now) {
|
|
118
|
+
return clamp((now - this.regionAt) / REGION_FADE_MS);
|
|
119
|
+
}
|
|
120
|
+
rgb() {
|
|
121
|
+
if (this.tone === "cool" || this.tone === "warm") return TONES[this.tone];
|
|
122
|
+
if (this.tone !== "auto") return this.tone;
|
|
123
|
+
if (this.onLight) return ON_LIGHT.glow;
|
|
124
|
+
return this.next.tone ?? this.prev.tone ?? TONES.cool;
|
|
125
|
+
}
|
|
126
|
+
/** The beam's area in frame pixels: the region's box over the picture, or the picture's visible part. */
|
|
127
|
+
area(region, place, W, H) {
|
|
128
|
+
if (!region.box) {
|
|
129
|
+
const x0 = Math.max(0, place.x), y0 = Math.max(0, place.y);
|
|
130
|
+
return { x: x0, y: y0, w: Math.min(W, place.x + place.w) - x0, h: Math.min(H, place.y + place.h) - y0 };
|
|
131
|
+
}
|
|
132
|
+
const b = region.box;
|
|
133
|
+
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 };
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Draws one frame. `place` is where the picture lands in the frame (`fitRect`), `dpr` the device pixel ratio.
|
|
137
|
+
* Returns `true` once the exit is over (the canvas is cleared).
|
|
138
|
+
*/
|
|
139
|
+
draw(ctx, W, H, place, now, dpr = 1) {
|
|
140
|
+
const pos = this.motion.at(now);
|
|
141
|
+
ctx.globalCompositeOperation = "source-over";
|
|
142
|
+
ctx.globalAlpha = 1;
|
|
143
|
+
ctx.clearRect(0, 0, W, H);
|
|
144
|
+
if (pos.done) return true;
|
|
145
|
+
if (pos.alpha <= 1e-3) return false;
|
|
146
|
+
const t = this.mixWeight(now);
|
|
147
|
+
const a0 = this.area(this.prev, place, W, H), a1 = this.area(this.next, place, W, H);
|
|
148
|
+
const A = { 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 };
|
|
149
|
+
const rgb = this.rgb();
|
|
150
|
+
const pad = 10 * dpr, top = A.y - pad, tall = A.h + 2 * pad;
|
|
151
|
+
ctx.globalAlpha = pos.alpha;
|
|
152
|
+
if (this.reduced) {
|
|
153
|
+
ctx.fillStyle = `rgba(${rgb},0.22)`;
|
|
154
|
+
ctx.fillRect(0, 0, W, H);
|
|
155
|
+
} else {
|
|
156
|
+
const x = A.x + pos.s * A.w, back = -pos.dir;
|
|
157
|
+
const light = this.look !== "soft";
|
|
158
|
+
const painted = this.onLight;
|
|
159
|
+
if (this.look === "soft") {
|
|
160
|
+
ctx.fillStyle = "rgba(255,255,255,0.10)";
|
|
161
|
+
ctx.fillRect(0, 0, W, H);
|
|
162
|
+
const T = A.w * 0.22, g2 = ctx.createLinearGradient(x + back * T, 0, x, 0);
|
|
163
|
+
g2.addColorStop(0, `rgba(${rgb},0)`);
|
|
164
|
+
g2.addColorStop(1, `rgba(${rgb},0.22)`);
|
|
165
|
+
ctx.fillStyle = g2;
|
|
166
|
+
ctx.fillRect(Math.min(x, x + back * T), top, T, tall);
|
|
167
|
+
}
|
|
168
|
+
if (this.look === "prism") {
|
|
169
|
+
FRINGES.forEach((c, i) => {
|
|
170
|
+
ctx.fillStyle = `rgba(${c},${0.55 - i * 0.04})`;
|
|
171
|
+
ctx.fillRect(x + back * (6 + i * 7) * dpr * (pos.finishing ? 1.5 : 1) - 2.5 * dpr, top, 5 * dpr, tall);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const gw = (light ? 18 : 26) * dpr;
|
|
175
|
+
const g = ctx.createLinearGradient(x - gw, 0, x + gw, 0);
|
|
176
|
+
g.addColorStop(0, `rgba(${rgb},0)`);
|
|
177
|
+
g.addColorStop(0.5, `rgba(${rgb},${painted ? 0.45 : light ? 0.85 : 0.75})`);
|
|
178
|
+
g.addColorStop(1, `rgba(${rgb},0)`);
|
|
179
|
+
ctx.fillStyle = g;
|
|
180
|
+
ctx.fillRect(x - gw, top, 2 * gw, tall);
|
|
181
|
+
ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.85)` : "rgba(255,255,255,0.95)";
|
|
182
|
+
ctx.fillRect(x - dpr, top, 2 * dpr, tall);
|
|
183
|
+
ctx.fillStyle = painted ? `rgba(${ON_LIGHT.core},0.7)` : "rgba(255,245,225,0.9)";
|
|
184
|
+
const sparks = light ? 10 : 14;
|
|
185
|
+
for (let i = 0; i < sparks; i++) {
|
|
186
|
+
ctx.globalAlpha = pos.alpha * Math.random();
|
|
187
|
+
ctx.fillRect(x + (Math.random() - 0.5) * 16 * dpr, A.y + Math.random() * A.h, 1.6 * dpr, 1.6 * dpr);
|
|
188
|
+
}
|
|
189
|
+
ctx.globalAlpha = pos.alpha;
|
|
190
|
+
}
|
|
191
|
+
const layer = this.maskOf(W, H, place, t);
|
|
192
|
+
if (layer) {
|
|
193
|
+
ctx.globalAlpha = 1;
|
|
194
|
+
ctx.globalCompositeOperation = "destination-in";
|
|
195
|
+
ctx.drawImage(layer, 0, 0);
|
|
196
|
+
ctx.globalCompositeOperation = "source-over";
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
maskOf(W, H, place, t) {
|
|
201
|
+
if (!this.prev.mask && !this.next.mask) return null;
|
|
202
|
+
if (typeof document === "undefined") return null;
|
|
203
|
+
this.maskLayer ??= document.createElement("canvas");
|
|
204
|
+
const m = this.maskLayer;
|
|
205
|
+
if (m.width !== W || m.height !== H) {
|
|
206
|
+
m.width = W;
|
|
207
|
+
m.height = H;
|
|
208
|
+
}
|
|
209
|
+
const x = m.getContext("2d");
|
|
210
|
+
if (!x) return null;
|
|
211
|
+
x.globalAlpha = 1;
|
|
212
|
+
x.clearRect(0, 0, W, H);
|
|
213
|
+
for (const [r, a] of [[this.prev, 1 - t], [this.next, t]]) {
|
|
214
|
+
if (a <= 0) continue;
|
|
215
|
+
x.globalAlpha = a;
|
|
216
|
+
if (r.mask) x.drawImage(r.mask, place.x, place.y, place.w, place.h);
|
|
217
|
+
else x.fillRect(0, 0, W, H);
|
|
218
|
+
}
|
|
219
|
+
x.globalAlpha = 1;
|
|
220
|
+
return m;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
var LEARN_EVERY_MS = 250;
|
|
224
|
+
var REGION_STEADY_MS = 600;
|
|
225
|
+
var REGION_MIN_MOVE = 0.02;
|
|
226
|
+
var LIGHT_SURFACE = 0.62;
|
|
227
|
+
var MAX_CANVAS_PIXELS = 25e5;
|
|
228
|
+
function lightTone([r, g, b]) {
|
|
229
|
+
return [r, g, b].map((v) => Math.round(v + (255 - v) * 0.6)).join(",");
|
|
230
|
+
}
|
|
231
|
+
function BeamLoader({
|
|
232
|
+
visible,
|
|
233
|
+
onExited,
|
|
234
|
+
picture,
|
|
235
|
+
maskKey,
|
|
236
|
+
fit = "cover",
|
|
237
|
+
mask,
|
|
238
|
+
look = "beam",
|
|
239
|
+
tone = "auto",
|
|
240
|
+
className,
|
|
241
|
+
style
|
|
242
|
+
}) {
|
|
243
|
+
const canvasRef = useRef(null);
|
|
244
|
+
const engineRef = useRef(null);
|
|
245
|
+
const learnNowRef = useRef(() => {
|
|
246
|
+
});
|
|
247
|
+
const [phase, setPhase] = useState("loading");
|
|
248
|
+
const [maskSource, setMaskSource] = useState(mask ? "given" : "whole");
|
|
249
|
+
const live = useRef({ picture, maskKey, fit, onExited });
|
|
250
|
+
live.current = { picture, maskKey, fit, onExited };
|
|
251
|
+
const [area, setArea] = useState(void 0);
|
|
252
|
+
const [surface, setSurface] = useState(void 0);
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
const now = () => typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
255
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
256
|
+
const engine = new BeamEngine({ look, tone, reducedMotion: reduced }, now());
|
|
257
|
+
engineRef.current = engine;
|
|
258
|
+
const pic = () => live.current.picture?.() ?? null;
|
|
259
|
+
const L = {
|
|
260
|
+
key: live.current.maskKey,
|
|
261
|
+
base: null,
|
|
262
|
+
bits: null,
|
|
263
|
+
natural: null,
|
|
264
|
+
lastSrc: "",
|
|
265
|
+
lastSnap: null,
|
|
266
|
+
shown: null,
|
|
267
|
+
shownAt: -Infinity
|
|
268
|
+
};
|
|
269
|
+
const srcOf = (el) => el && typeof HTMLImageElement !== "undefined" && el instanceof HTMLImageElement ? el.currentSrc || el.src : "";
|
|
270
|
+
const look_ = () => {
|
|
271
|
+
const el = pic();
|
|
272
|
+
if (!el) return null;
|
|
273
|
+
const n = naturalSize(el);
|
|
274
|
+
if (n.w > 0) L.natural = n;
|
|
275
|
+
const src = srcOf(el);
|
|
276
|
+
if (src && src === L.lastSrc && L.lastSnap) return L.lastSnap;
|
|
277
|
+
const snap = snapshotPicture(el);
|
|
278
|
+
if (snap) {
|
|
279
|
+
L.lastSrc = src;
|
|
280
|
+
L.lastSnap = snap;
|
|
281
|
+
}
|
|
282
|
+
return snap;
|
|
283
|
+
};
|
|
284
|
+
const surfaceOf = (s, alpha) => s ? meanLuma(s, alpha) > LIGHT_SURFACE ? "light" : "dark" : void 0;
|
|
285
|
+
const apply = (bits, w, h, from, source, force = false) => {
|
|
286
|
+
const alpha = softAlpha(bits, w, h, { grow: 4, blur: 6 });
|
|
287
|
+
const box = alphaBox(alpha, w, h);
|
|
288
|
+
if (!box) return;
|
|
289
|
+
const t = now();
|
|
290
|
+
if (!force) {
|
|
291
|
+
if (engine.motion.finishing) return;
|
|
292
|
+
const p = L.shown;
|
|
293
|
+
if (p) {
|
|
294
|
+
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);
|
|
295
|
+
if (moved < REGION_MIN_MOVE || t - L.shownAt < REGION_STEADY_MS) return;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
const colour = from ? meanColour(from, bits) : null;
|
|
299
|
+
const surf = surfaceOf(from, alpha);
|
|
300
|
+
engine.setRegion({ mask: alphaCanvas(alpha, w, h), box, tone: colour ? lightTone(colour) : void 0, surface: surf }, t);
|
|
301
|
+
L.shown = box;
|
|
302
|
+
L.shownAt = t;
|
|
303
|
+
setMaskSource(source);
|
|
304
|
+
setArea([box.x, box.y, box.w, box.h].map((v) => v.toFixed(3)).join(","));
|
|
305
|
+
setSurface(surf);
|
|
306
|
+
};
|
|
307
|
+
const startOn = (snap) => {
|
|
308
|
+
L.key = live.current.maskKey;
|
|
309
|
+
L.base = snap;
|
|
310
|
+
L.bits = null;
|
|
311
|
+
L.shown = null;
|
|
312
|
+
const known = snap && L.key ? recallMask(L.key, snap.w, snap.h) : null;
|
|
313
|
+
if (known && snap) {
|
|
314
|
+
L.bits = known;
|
|
315
|
+
apply(known, snap.w, snap.h, snap, "learned", true);
|
|
316
|
+
} else {
|
|
317
|
+
const surf = surfaceOf(snap);
|
|
318
|
+
engine.setRegion({ mask: null, box: null, surface: surf }, now());
|
|
319
|
+
setMaskSource("whole");
|
|
320
|
+
setArea(void 0);
|
|
321
|
+
setSurface(surf);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
if (mask) {
|
|
325
|
+
const s = snapshotPicture(mask);
|
|
326
|
+
if (s) {
|
|
327
|
+
const bits = new Uint8Array(s.w * s.h);
|
|
328
|
+
for (let i = 0; i < bits.length; i++) bits[i] = s.rgba[i * 4 + 3] > 127 ? 1 : 0;
|
|
329
|
+
apply(bits, s.w, s.h, look_(), "given", true);
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
startOn(look_());
|
|
333
|
+
}
|
|
334
|
+
const learn = () => {
|
|
335
|
+
if (mask) return;
|
|
336
|
+
const cur = look_();
|
|
337
|
+
if (!cur) return;
|
|
338
|
+
if (live.current.maskKey !== L.key) return startOn(cur);
|
|
339
|
+
if (!L.base) return startOn(cur);
|
|
340
|
+
const bits = changedBits(L.base, cur);
|
|
341
|
+
if (!bits || coverageOf(bits) > UNRELIABLE_COVERAGE) {
|
|
342
|
+
L.base = cur;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (!isLearnable(bits)) return;
|
|
346
|
+
const key = L.key;
|
|
347
|
+
const all = key ? rememberMask(key, cur.w, cur.h, bits) : L.bits ? orBits(L.bits, bits) : bits;
|
|
348
|
+
L.bits = all;
|
|
349
|
+
apply(all, cur.w, cur.h, L.base, "learned");
|
|
350
|
+
};
|
|
351
|
+
const learnTimer = setInterval(learn, LEARN_EVERY_MS);
|
|
352
|
+
let raf = 0;
|
|
353
|
+
const draw = () => {
|
|
354
|
+
const c = canvasRef.current;
|
|
355
|
+
const ctx = c?.getContext("2d");
|
|
356
|
+
if (!c || !ctx) return;
|
|
357
|
+
raf = requestAnimationFrame(draw);
|
|
358
|
+
const dpr = Math.min(2, typeof window !== "undefined" && window.devicePixelRatio || 1);
|
|
359
|
+
const css = Math.max(1, c.clientWidth * c.clientHeight);
|
|
360
|
+
const scale = Math.min(dpr, Math.sqrt(MAX_CANVAS_PIXELS / css));
|
|
361
|
+
const W = Math.max(1, Math.round(c.clientWidth * scale)), H = Math.max(1, Math.round(c.clientHeight * scale));
|
|
362
|
+
if (c.width !== W || c.height !== H) {
|
|
363
|
+
c.width = W;
|
|
364
|
+
c.height = H;
|
|
365
|
+
}
|
|
366
|
+
const n = L.natural;
|
|
367
|
+
const place = n ? fitRect(n.w, n.h, W, H, live.current.fit) : { x: 0, y: 0, w: W, h: H };
|
|
368
|
+
engine.draw(ctx, W, H, place, now(), scale);
|
|
369
|
+
if (c.style.mixBlendMode !== engine.blendMode) c.style.mixBlendMode = engine.blendMode;
|
|
370
|
+
};
|
|
371
|
+
if (typeof requestAnimationFrame === "function") raf = requestAnimationFrame(draw);
|
|
372
|
+
learnNowRef.current = learn;
|
|
373
|
+
return () => {
|
|
374
|
+
clearInterval(learnTimer);
|
|
375
|
+
if (typeof cancelAnimationFrame === "function") cancelAnimationFrame(raf);
|
|
376
|
+
engineRef.current = null;
|
|
377
|
+
learnNowRef.current = () => {
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
}, []);
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
const engine = engineRef.current;
|
|
383
|
+
if (!engine) return;
|
|
384
|
+
const now = typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
385
|
+
if (!visible) {
|
|
386
|
+
learnNowRef.current();
|
|
387
|
+
engine.finish(now);
|
|
388
|
+
setPhase("finishing");
|
|
389
|
+
const t = setTimeout(() => live.current.onExited?.(), BEAM_FINISH_MS);
|
|
390
|
+
return () => clearTimeout(t);
|
|
391
|
+
}
|
|
392
|
+
if (engine.motion.finishing) {
|
|
393
|
+
engine.resume(now);
|
|
394
|
+
setPhase("loading");
|
|
395
|
+
}
|
|
396
|
+
return void 0;
|
|
397
|
+
}, [visible]);
|
|
398
|
+
return /* @__PURE__ */ jsx(
|
|
399
|
+
"canvas",
|
|
400
|
+
{
|
|
401
|
+
ref: canvasRef,
|
|
402
|
+
"aria-hidden": "true",
|
|
403
|
+
"data-sc-loader": "beam",
|
|
404
|
+
"data-sc-loader-look": look,
|
|
405
|
+
"data-sc-loader-phase": phase,
|
|
406
|
+
"data-sc-loader-mask": maskSource,
|
|
407
|
+
"data-sc-loader-area": area,
|
|
408
|
+
"data-sc-loader-surface": surface,
|
|
409
|
+
className,
|
|
410
|
+
style: {
|
|
411
|
+
position: "absolute",
|
|
412
|
+
inset: 0,
|
|
413
|
+
width: "100%",
|
|
414
|
+
height: "100%",
|
|
415
|
+
pointerEvents: "none",
|
|
416
|
+
// the starting blend; the draw loop keeps it in step with the beam (painted on a learned light surface)
|
|
417
|
+
mixBlendMode: look === "soft" ? "normal" : "screen",
|
|
418
|
+
...style
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export { BEAM_FADE_IN_MS, BEAM_FINISH_MS, BEAM_PASS_MS, BEAM_RUSH_MAX_MS, BEAM_SWEEP_MS, BEAM_TAIL_MS, BeamEngine, BeamLoader, BeamMotion, LEARN_EVERY_MS, REGION_FADE_MS };
|
|
425
|
+
//# sourceMappingURL=index.js.map
|
|
426
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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,EAAc,cAAc,YAAY,CAAA;AAElG,IAAM,KAAA,GAAQ,CAAC,CAAA,EAAW,CAAA,GAAI,GAAG,CAAA,GAAI,CAAA,KAAM,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,CAAC,CAAC,CAAA;AACrE,IAAM,IAAA,GAAO,CAAC,CAAA,KAAc,GAAA,GAAM,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,EAAA,GAAK,KAAA,CAAM,CAAC,CAAC,CAAA;AAe5D,IAAM,aAAN,MAAiB;AAAA,EACd,EAAA;AAAA,EACA,GAAA,GAAM,CAAA;AAAA;AAAA,EAEL,MAAA;AAAA,EACD,GAAA,GAAoF,IAAA;AAAA,EAE5F,YAAY,GAAA,EAAa;AACvB,IAAA,IAAA,CAAK,EAAA,GAAK,GAAA;AACV,IAAA,IAAA,CAAK,MAAA,GAAS,GAAA;AAAA,EAChB;AAAA,EAEA,IAAI,SAAA,GAAqB;AACvB,IAAA,O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A,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,uBACE,GAAA;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.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 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) return startOn(cur); // another scene (a colour switch): never learn across\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"]}
|