fancy-ui-vue 0.3.0 → 0.4.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.
Files changed (54) hide show
  1. package/README.md +9 -6
  2. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  3. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  4. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  5. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  6. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  7. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  8. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  9. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  10. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  11. package/dist/components/magnetic-field/index.d.ts +10 -0
  12. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  13. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  14. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  15. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  16. package/dist/components/magnetic-field/types.d.ts +14 -0
  17. package/dist/components/magnetic-field/types.js +5 -0
  18. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  19. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  20. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  21. package/dist/components/pixel-scene/index.d.ts +4 -0
  22. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  23. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  24. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  25. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  26. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  27. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  28. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  29. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  30. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  31. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  32. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  33. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  34. package/dist/components/story-thread/index.d.ts +5 -0
  35. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  36. package/dist/components/story-thread/story-thread-core.js +491 -0
  37. package/dist/components/story-thread/types.d.ts +1 -0
  38. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  39. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  40. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  41. package/dist/components/sun-switch/index.d.ts +4 -0
  42. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  43. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  44. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  45. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  46. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  47. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  48. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  49. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  50. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  51. package/dist/index.d.ts +4 -0
  52. package/dist/index.js +190 -164
  53. package/dist/styles.css +499 -0
  54. package/package.json +1 -1
@@ -0,0 +1,546 @@
1
+ const SUN_PALETTE = Object.freeze([
2
+ "#f7cf4a",
3
+ "#f6a24e",
4
+ "#ef7a5e",
5
+ "#ea7d9c"
6
+ ]);
7
+ const HORIZON_ALPHA = 0.16;
8
+ const DAY_REST_INK = 0.3;
9
+ const REFLECTION_ROWS = Object.freeze([0.85, 0.6, 0.35]);
10
+ const HALO_EXPONENT = 0.7;
11
+ const BAYER4_RAW = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];
12
+ const BAYER4 = Object.freeze(BAYER4_RAW.map((v) => (v + 0.5) / 16));
13
+ function bayer4(x, y) {
14
+ return BAYER4[(y & 3) * 4 + (x & 3)] ?? 0;
15
+ }
16
+ function easeInOutCubic(t) {
17
+ if (!(t > 0)) return 0;
18
+ if (t >= 1) return 1;
19
+ return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
20
+ }
21
+ function haloDensity(D) {
22
+ if (!(D > 0)) return 0;
23
+ if (D >= 1) return 1;
24
+ return D ** HALO_EXPONENT;
25
+ }
26
+ function haloColorIndex(D) {
27
+ const i = Math.floor(D * 4);
28
+ return i <= 0 ? 0 : i >= 3 ? 3 : i;
29
+ }
30
+ function parseInk(css) {
31
+ const s = css.trim().toLowerCase();
32
+ if (s === "transparent") return { r: 0, g: 0, b: 0, a: 0 };
33
+ if (s.startsWith("#")) {
34
+ const hex = s.slice(1);
35
+ if (!/^[0-9a-f]+$/.test(hex)) return null;
36
+ if (hex.length === 3 || hex.length === 4) {
37
+ const n = [...hex].map((c) => parseInt(c + c, 16));
38
+ return { r: n[0] ?? 0, g: n[1] ?? 0, b: n[2] ?? 0, a: n[3] === void 0 ? 1 : n[3] / 255 };
39
+ }
40
+ if (hex.length === 6 || hex.length === 8) {
41
+ const n = [0, 2, 4, 6].map((i) => parseInt(hex.slice(i, i + 2), 16));
42
+ const a2 = hex.length === 8 ? (n[3] ?? 255) / 255 : 1;
43
+ return { r: n[0] ?? 0, g: n[1] ?? 0, b: n[2] ?? 0, a: a2 };
44
+ }
45
+ return null;
46
+ }
47
+ const m = /^rgba?\(([^)]*)\)$/.exec(s);
48
+ if (!m) return null;
49
+ const parts = (m[1] ?? "").split(/[\s,/]+/).filter(Boolean);
50
+ if (parts.length < 3) return null;
51
+ const num = (p, scale) => {
52
+ if (p === void 0) return NaN;
53
+ return p.endsWith("%") ? parseFloat(p) / 100 * scale : parseFloat(p);
54
+ };
55
+ const r = num(parts[0], 255);
56
+ const g = num(parts[1], 255);
57
+ const b = num(parts[2], 255);
58
+ const a = parts[3] === void 0 ? 1 : num(parts[3], 1);
59
+ if ([r, g, b, a].some((v) => !Number.isFinite(v))) return null;
60
+ return { r, g, b, a: Math.min(1, Math.max(0, a)) };
61
+ }
62
+ const SUN_GLOW_DAY = 2.2;
63
+ const SUN_GLOW_LENS = 4.9;
64
+ const HORIZON_GLOW_LENS = 1.6;
65
+ function haloGlow(D) {
66
+ return 1.5 + 3.4 * Math.min(1, Math.max(0, D));
67
+ }
68
+ const RGB_CACHE = /* @__PURE__ */ new Map();
69
+ function rgbOf(css) {
70
+ const hit = RGB_CACHE.get(css);
71
+ if (hit !== void 0) return hit;
72
+ const c = parseInk(css);
73
+ const v = c && c.a > 0 ? Math.round(Math.min(255, Math.max(0, c.r))) << 16 | Math.round(Math.min(255, Math.max(0, c.g))) << 8 | Math.round(Math.min(255, Math.max(0, c.b))) : -1;
74
+ if (RGB_CACHE.size > 64) RGB_CACHE.clear();
75
+ RGB_CACHE.set(css, v);
76
+ return v;
77
+ }
78
+ function mixRgb(a, b, t) {
79
+ const ch = (s) => Math.round((a >> s & 255) * (1 - t) + (b >> s & 255) * t) & 255;
80
+ return ch(16) << 16 | ch(8) << 8 | ch(0);
81
+ }
82
+ function hash2(x, y) {
83
+ let h = Math.imul(x | 0, 668265261) ^ Math.imul(y | 0, 374761393);
84
+ h = Math.imul(h ^ h >>> 15, 2246822507);
85
+ h ^= h >>> 13;
86
+ return (h >>> 0) / 4294967296;
87
+ }
88
+ function rasterSun(o) {
89
+ const R = Math.max(1, Math.round(o.radius));
90
+ const size = 2 * R + 1;
91
+ const hY = o.horizon ? Math.round(0.6 * size) : size;
92
+ const rr = R + 0.5;
93
+ const cells = [];
94
+ for (let y = 0; y < hY; y++) {
95
+ const dy = y - R;
96
+ const half = Math.floor(Math.sqrt(Math.max(0, rr * rr - dy * dy)));
97
+ const color = Math.min(3, Math.floor(y * 4 / hY));
98
+ for (let x = R - half; x <= R + half; x++) cells.push({ x, y, color, layer: "sun" });
99
+ }
100
+ if (o.horizon && hY < size) {
101
+ for (let x = 0; x < size; x += 2) cells.push({ x, y: hY, color: 1, layer: "horizon" });
102
+ for (let k = 0; k < REFLECTION_ROWS.length; k++) {
103
+ const y = hY + 1 + k;
104
+ if (y >= size) break;
105
+ const w = Math.round(rr * (REFLECTION_ROWS[k] ?? 0));
106
+ for (let x = R - w; x <= R + w; x++) {
107
+ if ((x + y) % 4 === 3) continue;
108
+ const color = Math.min(3, 1 + Math.floor(hash2(y, x) * 3));
109
+ cells.push({ x, y, color, layer: "horizon" });
110
+ }
111
+ }
112
+ }
113
+ return { size, horizonRow: hY, cells };
114
+ }
115
+ function gridOffset(origin, cell) {
116
+ return (origin % cell + cell) % cell;
117
+ }
118
+ function coverRadiusCells(origin, W, H, cell, halo) {
119
+ return Math.hypot(Math.max(origin.x, W - origin.x), Math.max(origin.y, H - origin.y)) / cell + halo;
120
+ }
121
+ function staircaseRows(tx, ty, innerRadius, cell, ox, oy) {
122
+ const rows = [];
123
+ if (!(innerRadius > 0)) return rows;
124
+ const last = Math.ceil(ty + innerRadius);
125
+ for (let r = Math.floor(ty - innerRadius); r <= last; r++) {
126
+ const dy = r + 0.5 - ty;
127
+ if (Math.abs(dy) > innerRadius) continue;
128
+ const h = Math.sqrt(innerRadius * innerRadius - dy * dy);
129
+ const y0 = r * cell + oy;
130
+ rows.push({
131
+ y0,
132
+ y1: y0 + cell,
133
+ x0: Math.floor(tx - h) * cell + ox,
134
+ x1: Math.ceil(tx + h) * cell + ox
135
+ });
136
+ }
137
+ return rows;
138
+ }
139
+ function inStaircase(i, j, tx, ty, inner) {
140
+ if (!(inner > 0)) return false;
141
+ const dy = j + 0.5 - ty;
142
+ if (Math.abs(dy) > inner) return false;
143
+ const h = Math.sqrt(inner * inner - dy * dy);
144
+ return i >= Math.floor(tx - h) && i < Math.ceil(tx + h);
145
+ }
146
+ const EMPTY_POLYGON = "polygon(0 0, 0 0, 0 0)";
147
+ function staircaseVertices(rows) {
148
+ const pts = [];
149
+ for (const r of rows) pts.push(r.x1, r.y0, r.x1, r.y1);
150
+ for (let i = rows.length - 1; i >= 0; i--) {
151
+ const r = rows[i];
152
+ if (r) pts.push(r.x0, r.y1, r.x0, r.y0);
153
+ }
154
+ const out = [];
155
+ for (let i = 0; i < pts.length; i += 2) {
156
+ if (i > 0 && pts[i] === pts[i - 2] && pts[i + 1] === pts[i - 1]) continue;
157
+ out.push([pts[i] ?? 0, pts[i + 1] ?? 0]);
158
+ }
159
+ return out;
160
+ }
161
+ function staircasePolygon(rows) {
162
+ if (rows.length === 0) return EMPTY_POLYGON;
163
+ return `polygon(${staircaseVertices(rows).map(([x, y]) => `${x}px ${y}px`).join(", ")})`;
164
+ }
165
+ function staircaseHoleClip(rows, W, H) {
166
+ let d = `M0 0H${W}V${H}H0Z`;
167
+ const pts = rows.length > 0 ? staircaseVertices(rows) : [];
168
+ if (pts.length > 0) d += `M${pts.map(([x, y]) => `${x} ${y}`).join("L")}Z`;
169
+ return `path(evenodd, "${d}")`;
170
+ }
171
+ function paintHalo(ctx, p) {
172
+ const { cx: tx, cy: ty, R, halo, cell, ox, oy } = p;
173
+ if (!(R > 0) || !(halo > 0) || !(cell > 0)) return 0;
174
+ const dpr = p.dpr ?? 1;
175
+ const cols = Math.ceil(p.W / cell) + 1;
176
+ const rows = Math.ceil(p.H / cell) + 1;
177
+ const size = Math.max(1, Math.round(p.dot * dpr));
178
+ const Ri = R - halo;
179
+ let count = 0;
180
+ let lastColor = -1;
181
+ ctx.globalAlpha = 1;
182
+ const yEnd = Math.min(rows, Math.ceil(ty + R));
183
+ for (let y = Math.max(0, Math.floor(ty - R)); y < yEnd; y++) {
184
+ const dy = y + 0.5 - ty;
185
+ const hw = Math.sqrt(Math.max(0, R * R - dy * dy));
186
+ const iw = Ri > 0 && Math.abs(dy) < Ri ? Math.sqrt(Ri * Ri - dy * dy) : -1;
187
+ const skipA = iw > 1 ? Math.ceil(tx - iw + 1) : Infinity;
188
+ const skipB = iw > 1 ? Math.floor(tx + iw - 1) : -Infinity;
189
+ const x1 = Math.min(cols, Math.ceil(tx + hw));
190
+ const py = Math.round((y * cell + oy) * dpr);
191
+ for (let x = Math.max(0, Math.floor(tx - hw)); x < x1; x++) {
192
+ if (x >= skipA && x < skipB) {
193
+ x = skipB - 1;
194
+ continue;
195
+ }
196
+ const D = (R - Math.hypot(x + 0.5 - tx, dy)) / halo;
197
+ if (D < 0 || D > 1 || bayer4(x, y) > haloDensity(D)) continue;
198
+ const ci = haloColorIndex(D);
199
+ if (ci !== lastColor) {
200
+ ctx.fillStyle = p.palette[ci];
201
+ lastColor = ci;
202
+ }
203
+ const px = Math.round((x * cell + ox) * dpr);
204
+ ctx.fillRect(px, py, size, size);
205
+ if (p.glow) p.glow.push(px, py, rgbOf(p.palette[ci]), haloGlow(D));
206
+ count++;
207
+ }
208
+ }
209
+ return count;
210
+ }
211
+ function paintSheet(ctx, color, W, H, dpr, hole, keep) {
212
+ const X = (v) => Math.round(Math.min(W, Math.max(0, v)) * dpr);
213
+ const Y = (v) => Math.round(Math.min(H, Math.max(0, v)) * dpr);
214
+ const band = (x0, y0, x1, y1) => {
215
+ const ax = X(x0);
216
+ const ay = Y(y0);
217
+ const w = X(x1) - ax;
218
+ const h = Y(y1) - ay;
219
+ if (w > 0 && h > 0) ctx.fillRect(ax, ay, w, h);
220
+ };
221
+ ctx.globalAlpha = 1;
222
+ ctx.fillStyle = color;
223
+ if (!hole || hole.length === 0) {
224
+ band(0, 0, W, H);
225
+ } else {
226
+ const first = hole[0];
227
+ const last = hole[hole.length - 1];
228
+ if (first) band(0, 0, W, first.y0);
229
+ for (const r of hole) {
230
+ band(0, r.y0, r.x0, r.y1);
231
+ band(r.x1, r.y0, W, r.y1);
232
+ }
233
+ if (last) band(0, last.y1, W, H);
234
+ }
235
+ }
236
+ function createLens(o) {
237
+ const lerp = o.lerp ?? 0.35;
238
+ const inMs = o.inMs ?? 140;
239
+ const outMs = o.outMs ?? 260;
240
+ let x = 0;
241
+ let y = 0;
242
+ let r = 0;
243
+ let on = false;
244
+ let last = null;
245
+ const lens = {
246
+ get x() {
247
+ return x;
248
+ },
249
+ get y() {
250
+ return y;
251
+ },
252
+ get r() {
253
+ return r;
254
+ },
255
+ radius: o.radius,
256
+ resetClock() {
257
+ last = null;
258
+ },
259
+ step(nowMs, target, reduced) {
260
+ const frame = 1e3 / 60;
261
+ const dt = last === null ? frame : Math.min(64, Math.max(0, nowMs - last));
262
+ last = nowMs;
263
+ if (target.on && !on && r === 0) {
264
+ x = target.x;
265
+ y = target.y;
266
+ }
267
+ on = target.on;
268
+ const g = on ? Math.max(0, lens.radius) : 0;
269
+ if (reduced) {
270
+ x = target.x;
271
+ y = target.y;
272
+ r = g;
273
+ return false;
274
+ }
275
+ const k = 1 - Math.pow(1 - lerp, dt / frame);
276
+ x += (target.x - x) * k;
277
+ y += (target.y - y) * k;
278
+ r += (g - r) * (1 - Math.exp(-3 * dt / (on ? inMs : outMs)));
279
+ if (Math.abs(g - r) < 0.3) r = g;
280
+ return r !== g || Math.abs(target.x - x) + Math.abs(target.y - y) > 0.05;
281
+ },
282
+ covers(i, j) {
283
+ return r > 0.5 && Math.hypot(i + 0.5 - x, j + 0.5 - y) <= r;
284
+ }
285
+ };
286
+ return lens;
287
+ }
288
+ function mergeOptions(base, next) {
289
+ return {
290
+ radius: next.radius ?? base.radius,
291
+ cell: next.cell ?? base.cell,
292
+ dot: next.dot ?? base.dot,
293
+ palette: next.palette ?? base.palette,
294
+ nightAlpha: next.nightAlpha ?? base.nightAlpha,
295
+ horizon: next.horizon ?? base.horizon,
296
+ lens: next.lens ?? base.lens,
297
+ lensRadius: next.lensRadius ?? base.lensRadius,
298
+ checked: next.checked ?? base.checked,
299
+ reducedMotion: next.reducedMotion ?? base.reducedMotion
300
+ };
301
+ }
302
+ function paintSun(ctx, raster, o) {
303
+ const { cell, dpr } = o;
304
+ const size = Math.max(1, Math.round(Math.min(o.dot, cell) * dpr));
305
+ const f = o.front;
306
+ const ftx = f ? f.cx / cell : 0;
307
+ const fty = f ? f.cy / cell : 0;
308
+ const fin = f ? f.R / cell : 0;
309
+ let lastStyle = "";
310
+ let lastAlpha = -1;
311
+ const tint = [];
312
+ for (const c of raster.cells) {
313
+ let day = o.checked;
314
+ let ink = o.ink;
315
+ if (f) {
316
+ if (inStaircase(c.x, c.y, ftx, fty, fin)) {
317
+ day = f.nextChecked;
318
+ } else {
319
+ day = !f.nextChecked;
320
+ ink = f.oldInk;
321
+ }
322
+ }
323
+ let style;
324
+ let alpha;
325
+ let mix = 0;
326
+ const lensed = !!o.lens && o.lens.covers(c.x, c.y);
327
+ if (lensed || c.layer === "sun" && day) {
328
+ style = o.palette[Math.min(3, Math.max(0, c.color))];
329
+ alpha = 1;
330
+ if (!lensed) mix = DAY_REST_INK;
331
+ } else {
332
+ style = ink;
333
+ alpha = c.layer === "sun" ? o.nightAlpha : HORIZON_ALPHA;
334
+ }
335
+ if (alpha <= 0) continue;
336
+ const px = Math.round(c.x * cell * dpr);
337
+ const py = Math.round(c.y * cell * dpr);
338
+ if (o.glow && alpha === 1) {
339
+ const rgb = rgbOf(style);
340
+ if (lensed) {
341
+ o.glow.push(px, py, rgb, c.layer === "sun" ? SUN_GLOW_LENS : HORIZON_GLOW_LENS);
342
+ } else if (mix > 0 && rgb >= 0) {
343
+ const inkC = parseInk(ink);
344
+ const inkRgb = rgbOf(ink);
345
+ const t = inkC && inkRgb >= 0 ? mix * inkC.a : 0;
346
+ o.glow.push(px, py, t > 0 ? mixRgb(rgb, inkRgb, t) : rgb, SUN_GLOW_DAY);
347
+ }
348
+ }
349
+ if (style !== lastStyle) {
350
+ ctx.fillStyle = style;
351
+ lastStyle = style;
352
+ }
353
+ if (alpha !== lastAlpha) {
354
+ ctx.globalAlpha = alpha;
355
+ lastAlpha = alpha;
356
+ }
357
+ ctx.fillRect(px, py, size, size);
358
+ if (mix > 0) tint.push(px, py, ink);
359
+ }
360
+ for (let i = 0; i < tint.length; i += 3) {
361
+ const style = tint[i + 2];
362
+ if (style !== lastStyle) {
363
+ ctx.fillStyle = style;
364
+ lastStyle = style;
365
+ }
366
+ if (lastAlpha !== DAY_REST_INK) {
367
+ ctx.globalAlpha = DAY_REST_INK;
368
+ lastAlpha = DAY_REST_INK;
369
+ }
370
+ ctx.fillRect(tint[i], tint[i + 1], size, size);
371
+ }
372
+ ctx.globalAlpha = 1;
373
+ }
374
+ function createSunPainter(canvas, opts) {
375
+ const maybe = typeof canvas.getContext === "function" ? canvas.getContext("2d") : null;
376
+ if (!maybe) return null;
377
+ const ctx = maybe;
378
+ let o = mergeOptions(opts, {});
379
+ let raster = rasterSun({ radius: o.radius, horizon: o.horizon });
380
+ let ink = "rgb(0, 0, 0)";
381
+ let dpr = 1;
382
+ let front = null;
383
+ let glowTarget = null;
384
+ const lens = createLens({ radius: o.lensRadius });
385
+ const target = { x: 0, y: 0, on: false };
386
+ let raf = 0;
387
+ let suspended = false;
388
+ let destroyed = false;
389
+ let dirty = false;
390
+ const g = globalThis;
391
+ const request = (cb) => g.requestAnimationFrame ? g.requestAnimationFrame(cb) : 0;
392
+ const cancel = (id) => {
393
+ if (id && g.cancelAnimationFrame) g.cancelAnimationFrame(id);
394
+ };
395
+ function paint() {
396
+ dirty = false;
397
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
398
+ const hdr = glowTarget;
399
+ hdr?.sink.clear();
400
+ paintSun(ctx, raster, {
401
+ cell: o.cell,
402
+ dot: o.dot,
403
+ dpr,
404
+ palette: o.palette,
405
+ nightAlpha: o.nightAlpha,
406
+ checked: o.checked,
407
+ ink,
408
+ lens: o.lens ? lens : null,
409
+ front,
410
+ glow: hdr?.sink ?? null
411
+ });
412
+ hdr?.render(
413
+ canvas.width,
414
+ canvas.height,
415
+ Math.max(1, Math.round(Math.min(o.dot, o.cell) * dpr))
416
+ );
417
+ }
418
+ function frame(now) {
419
+ raf = 0;
420
+ if (destroyed || suspended) return;
421
+ const moving = o.lens ? lens.step(now, target, o.reducedMotion) : false;
422
+ paint();
423
+ if (moving || front) raf = request(frame);
424
+ }
425
+ function kick() {
426
+ if (destroyed) return;
427
+ if (suspended) {
428
+ dirty = true;
429
+ return;
430
+ }
431
+ if (raf) return;
432
+ if (!g.requestAnimationFrame) {
433
+ paint();
434
+ return;
435
+ }
436
+ lens.resetClock();
437
+ raf = request(frame);
438
+ }
439
+ function resize() {
440
+ if (destroyed) return;
441
+ dpr = g.devicePixelRatio && g.devicePixelRatio > 0 ? g.devicePixelRatio : 1;
442
+ const css = raster.size * o.cell;
443
+ const w = Math.max(1, Math.round(css * dpr));
444
+ if (canvas.width !== w) canvas.width = w;
445
+ if (canvas.height !== w) canvas.height = w;
446
+ if (suspended) dirty = true;
447
+ else paint();
448
+ }
449
+ resize();
450
+ return {
451
+ setOptions(next) {
452
+ if (destroyed) return;
453
+ const prev = o;
454
+ o = mergeOptions(o, next);
455
+ lens.radius = o.lensRadius;
456
+ if (o.radius !== prev.radius || o.horizon !== prev.horizon) {
457
+ raster = rasterSun({ radius: o.radius, horizon: o.horizon });
458
+ }
459
+ if (o.radius !== prev.radius || o.cell !== prev.cell || o.horizon !== prev.horizon) {
460
+ resize();
461
+ }
462
+ kick();
463
+ },
464
+ setInk(css) {
465
+ if (destroyed || !css || css === ink) return;
466
+ ink = css;
467
+ kick();
468
+ },
469
+ pointer(cellX, cellY, on) {
470
+ if (destroyed) return;
471
+ target.x = cellX;
472
+ target.y = cellY;
473
+ target.on = on && o.lens;
474
+ kick();
475
+ },
476
+ setFront(next) {
477
+ if (destroyed) return;
478
+ front = next;
479
+ kick();
480
+ },
481
+ setGlowTarget(next) {
482
+ if (destroyed) return;
483
+ glowTarget = next;
484
+ if (suspended) dirty = true;
485
+ else paint();
486
+ },
487
+ resize,
488
+ wake() {
489
+ if (destroyed) return;
490
+ const was = suspended;
491
+ suspended = false;
492
+ if (was || dirty) {
493
+ lens.resetClock();
494
+ paint();
495
+ }
496
+ if (!raf && (front || o.lens && (target.on || lens.r > 0))) {
497
+ lens.resetClock();
498
+ raf = request(frame);
499
+ }
500
+ },
501
+ sleep() {
502
+ suspended = true;
503
+ cancel(raf);
504
+ raf = 0;
505
+ },
506
+ destroy() {
507
+ destroyed = true;
508
+ cancel(raf);
509
+ raf = 0;
510
+ front = null;
511
+ }
512
+ };
513
+ }
514
+ export {
515
+ BAYER4,
516
+ DAY_REST_INK,
517
+ EMPTY_POLYGON,
518
+ HALO_EXPONENT,
519
+ HORIZON_ALPHA,
520
+ HORIZON_GLOW_LENS,
521
+ REFLECTION_ROWS,
522
+ SUN_GLOW_DAY,
523
+ SUN_GLOW_LENS,
524
+ SUN_PALETTE,
525
+ bayer4,
526
+ coverRadiusCells,
527
+ createLens,
528
+ createSunPainter,
529
+ easeInOutCubic,
530
+ gridOffset,
531
+ haloColorIndex,
532
+ haloDensity,
533
+ haloGlow,
534
+ hash2,
535
+ inStaircase,
536
+ mixRgb,
537
+ paintHalo,
538
+ paintSheet,
539
+ paintSun,
540
+ parseInk,
541
+ rasterSun,
542
+ rgbOf,
543
+ staircaseHoleClip,
544
+ staircasePolygon,
545
+ staircaseRows
546
+ };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * SunSwitch HDR layer — framework-free, byte-identical in the Svelte, React
3
+ * and Vue trees (see shared-cores.json).
4
+ *
5
+ * The sun and the wave halo are painted in 2D canvases, which stop at SDR
6
+ * white. On HDR displays a WebGPU canvas is laid over each one
7
+ * (`rgba16float`, `colorSpace: "srgb"`, `toneMapping: { mode: "extended" }`)
8
+ * and the painted squares that carry a glow are drawn again there as hard
9
+ * squares at `glow ×` their colour, alpha 1: one instanced quad per square,
10
+ * no blur, no falloff term in the shader. The halo stays made of dithered
11
+ * cells; nothing soft is added.
12
+ *
13
+ * Encoding: the canvas reads its values as extended (gamma-encoded) sRGB, so
14
+ * each channel is sent as `encodeExt(srgbToLinear(c) × glow)`, computed on
15
+ * the CPU when a square is pushed. A glow of exactly 1 reproduces the 2D dot.
16
+ *
17
+ * One GPUDevice per page, reference-counted across layers; each layer owns
18
+ * its context, uniform, instance buffer and bind group. Nothing touches
19
+ * `window` or `navigator` at import.
20
+ */
21
+ import type { GlowSink } from "./sun-switch-core.js";
22
+ /** SDR white ≈ 203 nits; 1000 nits / 203 ≈ 4.9. Every glow is clamped to it. */
23
+ export declare const SUN_HDR_PEAK = 4.9;
24
+ /**
25
+ * A lost device usually comes back (GPU process restarted, driver reset). The
26
+ * component starts its layer again after `SUN_HDR_RESTART_MS × attempt`, up to
27
+ * `SUN_HDR_RESTARTS` times per mount, before dropping the HDR canvas for good.
28
+ */
29
+ export declare const SUN_HDR_RESTARTS = 3;
30
+ export declare const SUN_HDR_RESTART_MS = 600;
31
+ /** sRGB channel (0–255) → linear light. */
32
+ export declare function srgbToLinear(c8: number): number;
33
+ /** Linear light → extended-sRGB encoded value; keeps going above 1 for HDR. */
34
+ export declare function encodeExt(v: number): number;
35
+ /** One channel (0–255) at `glow ×` SDR, encoded for the extended-sRGB canvas. */
36
+ export declare function encodeGlowChannel(c8: number, glow: number): number;
37
+ /**
38
+ * Sync and SSR-safe: WebGPU is exposed and the display reports
39
+ * `(dynamic-range: high)`. Decides whether an HDR canvas is created at all.
40
+ */
41
+ export declare function sunHdrAvailable(): boolean;
42
+ /** Next power of two ≥ n, at least the start capacity. */
43
+ export declare function hdrCapacityFor(n: number): number;
44
+ /**
45
+ * The squares of one frame, encoded as they are pushed. Painters fill it
46
+ * through {@link GlowSink}; the layer uploads it as is.
47
+ */
48
+ export interface SunHdrSquares extends GlowSink {
49
+ /** Squares pushed since the last `clear`. */
50
+ readonly n: number;
51
+ /** `FPI` floats per square; valid up to `n × 8`. */
52
+ readonly data: Float32Array<ArrayBuffer>;
53
+ }
54
+ export declare function createSunHdrSquares(): SunHdrSquares;
55
+ export interface SunHdrLayer {
56
+ /** Filled by the painter for the next `render`. */
57
+ readonly sink: SunHdrSquares;
58
+ /** Draws the squares in `sink` on a `width × height` backing, `size` device px each. */
59
+ render(width: number, height: number, size: number): void;
60
+ destroy(): void;
61
+ /** Resolves when the shared device is lost; the 2D picture carries on. */
62
+ readonly lost: Promise<void>;
63
+ /** Squares drawn by the last `render` (diagnostics, tests). */
64
+ readonly count: number;
65
+ }
66
+ /**
67
+ * Starts a layer on `canvas`. Resolves null when WebGPU, the adapter, the
68
+ * context or extended tone mapping is missing; never throws.
69
+ */
70
+ export declare function startSunHdr(canvas: HTMLCanvasElement): Promise<SunHdrLayer | null>;