fancy-ui-vue 0.3.0 → 0.4.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.
Files changed (102) hide show
  1. package/README.md +9 -6
  2. package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +23 -12
  3. package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +10 -1
  4. package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +6 -0
  5. package/dist/components/bg-falling-stars/bg-falling-stars-core.js +24 -2
  6. package/dist/components/bg-stars/StarsBackground.vue.js +1 -1
  7. package/dist/components/bg-stars/StarsBackground.vue2.js +13 -1
  8. package/dist/components/bg-stars/bg-stars-core.d.ts +6 -0
  9. package/dist/components/bg-stars/bg-stars-core.js +21 -1
  10. package/dist/components/book/Book.vue.js +5 -83
  11. package/dist/components/book/Book.vue2.js +82 -1
  12. package/dist/components/box-reveal/BoxReveal.vue.js +5 -47
  13. package/dist/components/box-reveal/BoxReveal.vue2.js +48 -1
  14. package/dist/components/compare/StarField.vue.js +1 -1
  15. package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
  16. package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +14 -5
  17. package/dist/components/flickering-grid/FlickeringGrid.vue.js +19 -1
  18. package/dist/components/flickering-grid/flickering-grid-core.d.ts +6 -0
  19. package/dist/components/flickering-grid/flickering-grid-core.js +30 -1
  20. package/dist/components/flip-words/FlipWords.vue.js +1 -1
  21. package/dist/components/flip-words/FlipWords.vue2.js +14 -7
  22. package/dist/components/hyper-text/HyperText.vue.js +6 -97
  23. package/dist/components/hyper-text/HyperText.vue2.js +101 -0
  24. package/dist/components/letter-pullup/LetterPullup.vue.js +6 -38
  25. package/dist/components/letter-pullup/LetterPullup.vue2.js +40 -0
  26. package/dist/components/logo-cloud/AnimatedLogoCloud.vue.js +1 -1
  27. package/dist/components/magnetic-field/MagnetPuck.vue.d.ts +51 -0
  28. package/dist/components/magnetic-field/MagnetPuck.vue.js +7 -0
  29. package/dist/components/magnetic-field/MagnetPuck.vue2.js +191 -0
  30. package/dist/components/magnetic-field/MagneticField.vue.d.ts +39 -0
  31. package/dist/components/magnetic-field/MagneticField.vue.js +7 -0
  32. package/dist/components/magnetic-field/MagneticField.vue2.js +157 -0
  33. package/dist/components/magnetic-field/MagneticItem.vue.d.ts +28 -0
  34. package/dist/components/magnetic-field/MagneticItem.vue.js +7 -0
  35. package/dist/components/magnetic-field/MagneticItem.vue2.js +72 -0
  36. package/dist/components/magnetic-field/index.d.ts +10 -0
  37. package/dist/components/magnetic-field/magnetic-field-core.d.ts +163 -0
  38. package/dist/components/magnetic-field/magnetic-field-core.js +534 -0
  39. package/dist/components/magnetic-field/magnetic-field-source.d.ts +58 -0
  40. package/dist/components/magnetic-field/magnetic-field-source.js +58 -0
  41. package/dist/components/magnetic-field/types.d.ts +14 -0
  42. package/dist/components/magnetic-field/types.js +5 -0
  43. package/dist/components/matrix-rain/MatrixRain.vue.js +20 -1
  44. package/dist/components/matrix-rain/matrix-rain-core.d.ts +6 -0
  45. package/dist/components/matrix-rain/matrix-rain-core.js +28 -6
  46. package/dist/components/noise-reveal/NoiseReveal.vue.js +7 -0
  47. package/dist/components/noise-reveal/noise-reveal-core.js +23 -7
  48. package/dist/components/pixel-scene/PixelScene.vue.d.ts +60 -0
  49. package/dist/components/pixel-scene/PixelScene.vue.js +184 -0
  50. package/dist/components/pixel-scene/PixelScene.vue2.js +4 -0
  51. package/dist/components/pixel-scene/index.d.ts +4 -0
  52. package/dist/components/pixel-scene/pixel-scene-core.d.ts +256 -0
  53. package/dist/components/pixel-scene/pixel-scene-core.js +878 -0
  54. package/dist/components/pixel-scene/pixel-scene-hdr.d.ts +68 -0
  55. package/dist/components/pixel-scene/pixel-scene-hdr.js +312 -0
  56. package/dist/components/pixel-scene/pixel-scene-scenes.d.ts +31 -0
  57. package/dist/components/pixel-scene/pixel-scene-scenes.js +1074 -0
  58. package/dist/components/ripple/Ripple.vue.js +1 -1
  59. package/dist/components/ripple/Ripple.vue2.js +6 -1
  60. package/dist/components/sparkles/Sparkles.vue.js +10 -1
  61. package/dist/components/sparkles/sparkles-core.d.ts +6 -0
  62. package/dist/components/sparkles/sparkles-core.js +26 -2
  63. package/dist/components/sparkles-text/SparklesText.vue.js +6 -88
  64. package/dist/components/sparkles-text/SparklesText.vue2.js +100 -0
  65. package/dist/components/story-thread/StoryNode.vue.d.ts +11 -0
  66. package/dist/components/story-thread/StoryNode.vue.js +7 -0
  67. package/dist/components/story-thread/StoryNode.vue2.js +23 -0
  68. package/dist/components/story-thread/StoryThread.vue.d.ts +56 -0
  69. package/dist/components/story-thread/StoryThread.vue.js +7 -0
  70. package/dist/components/story-thread/StoryThread.vue2.js +103 -0
  71. package/dist/components/story-thread/index.d.ts +5 -0
  72. package/dist/components/story-thread/story-thread-core.d.ts +119 -0
  73. package/dist/components/story-thread/story-thread-core.js +491 -0
  74. package/dist/components/story-thread/types.d.ts +1 -0
  75. package/dist/components/sun-switch/SunSwitch.vue.d.ts +61 -0
  76. package/dist/components/sun-switch/SunSwitch.vue.js +7 -0
  77. package/dist/components/sun-switch/SunSwitch.vue2.js +559 -0
  78. package/dist/components/sun-switch/index.d.ts +4 -0
  79. package/dist/components/sun-switch/pixel-wave-core.d.ts +82 -0
  80. package/dist/components/sun-switch/pixel-wave-core.js +508 -0
  81. package/dist/components/sun-switch/sun-switch-core.d.ts +251 -0
  82. package/dist/components/sun-switch/sun-switch-core.js +546 -0
  83. package/dist/components/sun-switch/sun-switch-hdr.d.ts +70 -0
  84. package/dist/components/sun-switch/sun-switch-hdr.js +311 -0
  85. package/dist/components/terminal-text/TerminalText.vue.js +1 -1
  86. package/dist/components/terminal-text/TerminalText.vue2.js +36 -4
  87. package/dist/components/text-generate-effect/TextGenerateEffect.vue.js +5 -72
  88. package/dist/components/text-generate-effect/TextGenerateEffect.vue2.js +74 -1
  89. package/dist/components/text-reveal-card/TextRevealCard.vue.js +5 -101
  90. package/dist/components/text-reveal-card/TextRevealCard.vue2.js +98 -1
  91. package/dist/components/text-reveal-card/TextRevealStars.vue.js +1 -1
  92. package/dist/components/text-reveal-card/TextRevealStars.vue2.js +29 -12
  93. package/dist/components/tracing-beam/TracingBeam.vue.d.ts +20 -1
  94. package/dist/components/tracing-beam/TracingBeam.vue.js +5 -164
  95. package/dist/components/tracing-beam/TracingBeam.vue2.js +168 -1
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.js +361 -338
  98. package/dist/styles.css +731 -89
  99. package/package.json +1 -1
  100. package/dist/components/hyper-text/HyperText.vue3.js +0 -5
  101. package/dist/components/letter-pullup/LetterPullup.vue3.js +0 -5
  102. package/dist/components/sparkles-text/SparklesText.vue3.js +0 -5
@@ -0,0 +1,878 @@
1
+ const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5].map(
2
+ (v) => (v + 0.5) / 16
3
+ );
4
+ function bayer(x, y) {
5
+ return BAYER[(y % 4 + 4) % 4 * 4 + (x % 4 + 4) % 4];
6
+ }
7
+ function hash(x, y, s = 0) {
8
+ let h = x * 374761393 + y * 668265263 + s * 2246822519 >>> 0;
9
+ h = Math.imul(h ^ h >>> 13, 1274126177) >>> 0;
10
+ return ((h ^ h >>> 16) >>> 0) / 4294967296;
11
+ }
12
+ function clamp(v, a, b) {
13
+ return Math.max(a, Math.min(b, v));
14
+ }
15
+ function smooth(t) {
16
+ t = clamp(t, 0, 1);
17
+ return t * t * (3 - 2 * t);
18
+ }
19
+ function noise1(x, seed) {
20
+ const i = Math.floor(x);
21
+ const f = x - i;
22
+ const a = hash(i, 0, seed);
23
+ const b = hash(i + 1, 0, seed);
24
+ return a + (b - a) * smooth(f);
25
+ }
26
+ function ridge(x, seed, scale, amp) {
27
+ return noise1(x / scale, seed) * amp + noise1(x / (scale * 0.37), seed + 1) * amp * 0.35;
28
+ }
29
+ const PARSED = /* @__PURE__ */ new Map();
30
+ const RGB_RE = /^rgba?\(\s*(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)[\s,]+(\d+(?:\.\d+)?)/i;
31
+ function parseColour(c) {
32
+ if (typeof c === "number") return c;
33
+ const hit = PARSED.get(c);
34
+ if (hit !== void 0) return hit;
35
+ let v = -1;
36
+ const s = c.trim();
37
+ if (/^#[0-9a-f]{6}$/i.test(s)) v = parseInt(s.slice(1), 16);
38
+ else if (/^#[0-9a-f]{3}$/i.test(s)) {
39
+ const r = parseInt(s[1], 16);
40
+ const g = parseInt(s[2], 16);
41
+ const b = parseInt(s[3], 16);
42
+ v = r * 17 << 16 | g * 17 << 8 | b * 17;
43
+ } else {
44
+ const m = RGB_RE.exec(s);
45
+ if (m) {
46
+ const r = clamp(Math.round(Number(m[1])), 0, 255);
47
+ const g = clamp(Math.round(Number(m[2])), 0, 255);
48
+ const b = clamp(Math.round(Number(m[3])), 0, 255);
49
+ v = r << 16 | g << 8 | b;
50
+ }
51
+ }
52
+ if (PARSED.size < 4096) PARSED.set(c, v);
53
+ return v;
54
+ }
55
+ function mixHex(a, b, t) {
56
+ const A = parseColour(a);
57
+ const B = parseColour(b);
58
+ const ar = A >> 16 & 255;
59
+ const ag = A >> 8 & 255;
60
+ const ab = A & 255;
61
+ const r = clamp(ar + ((B >> 16 & 255) - ar) * t | 0, 0, 255);
62
+ const g = clamp(ag + ((B >> 8 & 255) - ag) * t | 0, 0, 255);
63
+ const bl = clamp(ab + ((B & 255) - ab) * t | 0, 0, 255);
64
+ return r << 16 | g << 8 | bl;
65
+ }
66
+ function grad(stops, t) {
67
+ t = clamp(t, 0, 1);
68
+ for (let i = 1; i < stops.length; i++) {
69
+ const s1 = stops[i];
70
+ if (t <= s1[0]) {
71
+ const s0 = stops[i - 1];
72
+ return mixHex(s0[1], s1[1], (t - s0[0]) / (s1[0] - s0[0] || 1));
73
+ }
74
+ }
75
+ const last = stops[stops.length - 1];
76
+ return last ? parseColour(last[1]) : 0;
77
+ }
78
+ const CSS_CACHE = /* @__PURE__ */ new Map();
79
+ function cssOf(c) {
80
+ let s = CSS_CACHE.get(c);
81
+ if (s === void 0) {
82
+ s = "#" + (c & 16777215).toString(16).padStart(6, "0");
83
+ if (CSS_CACHE.size < 4096) CSS_CACHE.set(c, s);
84
+ }
85
+ return s;
86
+ }
87
+ const LINEAR = new Float32Array(256);
88
+ for (let i = 0; i < 256; i++) {
89
+ const s = i / 255;
90
+ LINEAR[i] = s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4);
91
+ }
92
+ function srgbToLinear(c8) {
93
+ return LINEAR[clamp(Math.round(c8), 0, 255)];
94
+ }
95
+ function encodeExt(v) {
96
+ return v <= 31308e-7 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
97
+ }
98
+ const INK_ALPHA_NIGHT = 0.6;
99
+ const INK_ALPHA_DAY = 0.85;
100
+ const LENS_BOOST = 1.6;
101
+ const LIT_GLOW = 1.5;
102
+ const GLOW_PEAK = 4.9;
103
+ const MAX_CELLS = 72e3;
104
+ const MAX_DPR = 2;
105
+ const MAX_BACKING_PX = 42e5;
106
+ const MIN_CELL = 4;
107
+ const MAX_CELL = 32;
108
+ function createGrid(cols, rows) {
109
+ const n = Math.max(0, cols * rows);
110
+ const g = {
111
+ cols,
112
+ rows,
113
+ color: new Int32Array(n),
114
+ inkA: new Float32Array(n),
115
+ lit: new Uint8Array(n),
116
+ glow: new Float32Array(n),
117
+ halo: new Float32Array(n),
118
+ hcol: new Int32Array(n),
119
+ soft: new Float32Array(n),
120
+ emitters: [],
121
+ copyW: 0,
122
+ copyH: 0,
123
+ sunX: -1,
124
+ sunY: -1
125
+ };
126
+ clearGrid(g);
127
+ return g;
128
+ }
129
+ function clearGrid(g) {
130
+ g.color.fill(-1);
131
+ g.inkA.fill(0);
132
+ g.lit.fill(0);
133
+ g.glow.fill(0);
134
+ g.halo.fill(0);
135
+ g.hcol.fill(-1);
136
+ g.soft.fill(0);
137
+ g.emitters.length = 0;
138
+ g.copyW = 0;
139
+ g.copyH = 0;
140
+ g.sunX = -1;
141
+ g.sunY = -1;
142
+ }
143
+ function writeCell(g, x, y, c, a = 0, l = false, hl = 0) {
144
+ x = Math.round(x);
145
+ y = Math.round(y);
146
+ if (!(x >= 0 && y >= 0 && x < g.cols && y < g.rows)) return;
147
+ const i = y * g.cols + x;
148
+ const col = typeof c === "number" ? c : parseColour(c);
149
+ g.color[i] = col;
150
+ g.inkA[i] = a;
151
+ g.lit[i] = l ? 1 : 0;
152
+ const glow = typeof l === "number" ? Math.min(GLOW_PEAK, l) : l ? LIT_GLOW : 0;
153
+ g.glow[i] = glow;
154
+ g.halo[i] = hl;
155
+ g.hcol[i] = -1;
156
+ g.soft[i] = 0;
157
+ if (hl > 0 && typeof l === "number" && glow > 0) g.emitters.push(x, y, col, glow, hl);
158
+ }
159
+ function pixelHalos(g) {
160
+ const { cols, rows, emitters, glow, halo, color, hcol } = g;
161
+ for (let e = 0; e + 4 < emitters.length; e += 5) {
162
+ const ex = emitters[e];
163
+ const ey = emitters[e + 1];
164
+ const c = emitters[e + 2];
165
+ const l = emitters[e + 3];
166
+ const r = emitters[e + 4] * 2.2;
167
+ const y0 = Math.max(0, Math.floor(ey - r));
168
+ const y1 = Math.min(rows - 1, Math.ceil(ey + r));
169
+ const x0 = Math.max(0, Math.floor(ex - r));
170
+ const x1 = Math.min(cols - 1, Math.ceil(ex + r));
171
+ for (let y = y0; y <= y1; y++) {
172
+ for (let x = x0; x <= x1; x++) {
173
+ const i = y * cols + x;
174
+ if (halo[i] > 0) continue;
175
+ const d = Math.hypot(x - ex, y - ey) / r;
176
+ if (d >= 1) continue;
177
+ const dens = Math.pow(1 - d, 1.7);
178
+ if (bayer(x, y) >= dens) continue;
179
+ const gl = l * (0.3 + 0.55 * dens);
180
+ if (gl <= glow[i]) continue;
181
+ glow[i] = gl;
182
+ hcol[i] = c;
183
+ if (color[i] < 0) color[i] = c;
184
+ }
185
+ }
186
+ }
187
+ }
188
+ const WAVE_MS = 1300;
189
+ const WAVE_HALO_CELLS = 9;
190
+ const WAVE_GLOW_CELLS = 7;
191
+ const WAVE_PALETTE = [16240458, 16163406, 15694430, 15367580];
192
+ function easeInOutCubic(t) {
193
+ if (!(t > 0)) return 0;
194
+ if (t >= 1) return 1;
195
+ return t < 0.5 ? 4 * t * t * t : 1 - (-2 * t + 2) ** 3 / 2;
196
+ }
197
+ function waveGlow(D) {
198
+ return 1.5 + 3.4 * clamp(D, 0, 1);
199
+ }
200
+ function waveBandGlow(x, y, d, inner) {
201
+ if (!(d >= 0 && d < 1)) return 0;
202
+ const dens = Math.pow(1 - d, 1.7);
203
+ if (bayer(x, y) >= dens) return 0;
204
+ return inner ? 1.2 + 2.2 * dens : 1.1 + 1.6 * dens;
205
+ }
206
+ function waveCover(ox, oy, cols, rows) {
207
+ return Math.max(
208
+ Math.hypot(ox, oy),
209
+ Math.hypot(cols - ox, oy),
210
+ Math.hypot(ox, rows - oy),
211
+ Math.hypot(cols - ox, rows - oy)
212
+ ) + WAVE_HALO_CELLS + WAVE_GLOW_CELLS + 1;
213
+ }
214
+ function composeWave(cur, next, side, ox, oy, R) {
215
+ const { cols, rows } = cur;
216
+ const Rin = R - WAVE_HALO_CELLS;
217
+ const em = [];
218
+ for (let k = 0; k + 4 < cur.emitters.length; k += 5)
219
+ if (Math.hypot(cur.emitters[k] + 0.5 - ox, cur.emitters[k + 1] + 0.5 - oy) >= Rin)
220
+ em.push(...cur.emitters.slice(k, k + 5));
221
+ for (let k = 0; k + 4 < next.emitters.length; k += 5)
222
+ if (Math.hypot(next.emitters[k] + 0.5 - ox, next.emitters[k + 1] + 0.5 - oy) < Rin)
223
+ em.push(...next.emitters.slice(k, k + 5));
224
+ const copyW = next.copyW || cur.copyW || 0;
225
+ const copyH = next.copyH || cur.copyH || 0;
226
+ for (let y = 0; y < rows; y++) {
227
+ for (let x = 0; x < cols; x++) {
228
+ const i = y * cols + x;
229
+ const dist = Math.hypot(x + 0.5 - ox, y + 0.5 - oy);
230
+ const inCopy = x < copyW && y < copyH;
231
+ if (dist < Rin) {
232
+ side[i] = 1;
233
+ cur.color[i] = next.color[i];
234
+ cur.inkA[i] = next.inkA[i];
235
+ cur.lit[i] = next.lit[i];
236
+ cur.glow[i] = next.glow[i];
237
+ cur.halo[i] = next.halo[i];
238
+ cur.hcol[i] = next.hcol[i];
239
+ cur.soft[i] = next.soft[i];
240
+ const g = inCopy ? 0 : waveBandGlow(x, y, (Rin - dist) / WAVE_GLOW_CELLS, true);
241
+ if (g > cur.glow[i]) {
242
+ cur.glow[i] = g;
243
+ cur.hcol[i] = WAVE_PALETTE[3];
244
+ if (cur.color[i] < 0) cur.color[i] = WAVE_PALETTE[3];
245
+ }
246
+ continue;
247
+ }
248
+ side[i] = 0;
249
+ if (dist >= R) {
250
+ const g = inCopy ? 0 : waveBandGlow(x, y, (dist - R) / WAVE_GLOW_CELLS, false);
251
+ if (g > cur.glow[i]) {
252
+ cur.glow[i] = g;
253
+ cur.hcol[i] = WAVE_PALETTE[0];
254
+ if (cur.color[i] < 0) cur.color[i] = WAVE_PALETTE[0];
255
+ }
256
+ continue;
257
+ }
258
+ const D = (R - dist) / WAVE_HALO_CELLS;
259
+ if (bayer(x, y) > Math.pow(D, 0.7)) continue;
260
+ cur.color[i] = WAVE_PALETTE[clamp(Math.floor(D * 4), 0, 3)];
261
+ cur.inkA[i] = 0.9;
262
+ cur.lit[i] = 1;
263
+ cur.glow[i] = inCopy ? 1 : waveGlow(D);
264
+ cur.halo[i] = 0;
265
+ cur.hcol[i] = -1;
266
+ }
267
+ }
268
+ cur.emitters.length = 0;
269
+ cur.emitters.push(...em);
270
+ }
271
+ function createLens() {
272
+ return { x: -999, y: -999, tx: -999, ty: -999, r: 0, tr: 0 };
273
+ }
274
+ function stepLens(l, dt, snap) {
275
+ if (snap) {
276
+ l.x = l.tx;
277
+ l.y = l.ty;
278
+ l.r = l.tr;
279
+ return false;
280
+ }
281
+ const f = Math.max(0, dt) / 16.667;
282
+ const k = 1 - Math.pow(0.6, f);
283
+ l.x += (l.tx - l.x) * k;
284
+ l.y += (l.ty - l.y) * k;
285
+ const kr = 1 - Math.pow(0.6, f * (l.tr > l.r ? 1.3 : 0.7));
286
+ l.r += (l.tr - l.r) * kr;
287
+ let moving = false;
288
+ if (Math.abs(l.tx - l.x) > 0.01) moving = true;
289
+ else l.x = l.tx;
290
+ if (Math.abs(l.ty - l.y) > 0.01) moving = true;
291
+ else l.y = l.ty;
292
+ if (Math.abs(l.tr - l.r) > 0.01) moving = true;
293
+ else l.r = l.tr;
294
+ return moving;
295
+ }
296
+ function inLens(l, x, y) {
297
+ return l.r > 0.5 && Math.hypot(x + 0.5 - l.x, y + 0.5 - l.y) < l.r - 2 + bayer(x, y) * 4;
298
+ }
299
+ function cellOrigin(x, cell, dpr) {
300
+ return Math.round(x * cell * dpr);
301
+ }
302
+ function paintGrid(ctx, g, lens, p) {
303
+ const { cols, rows, color, inkA, lit, glow } = g;
304
+ const copyW = g.copyW || 0;
305
+ const copyH = g.copyH || 0;
306
+ const w = p.width ?? ctx.canvas?.width ?? 0;
307
+ const h = p.height ?? ctx.canvas?.height ?? 0;
308
+ ctx.setTransform(1, 0, 0, 1, 0, 0);
309
+ ctx.clearRect(0, 0, w, h);
310
+ const size = Math.max(1, Math.round(p.dot * p.dpr));
311
+ const inkScale = p.night ? INK_ALPHA_NIGHT : INK_ALPHA_DAY;
312
+ const side = p.side ?? null;
313
+ const sideInk = p.sideInk ?? p.ink;
314
+ ctx.globalAlpha = 1;
315
+ if (p.surface) {
316
+ ctx.fillStyle = p.surface;
317
+ ctx.fillRect(0, 0, w, h);
318
+ }
319
+ if (side && p.sideSurface) {
320
+ ctx.fillStyle = p.sideSurface;
321
+ for (let y = 0; y < rows; y++) {
322
+ const y0 = cellOrigin(y, p.cell, p.dpr);
323
+ const y1 = cellOrigin(y + 1, p.cell, p.dpr);
324
+ let x0 = -1;
325
+ for (let x = 0; x <= cols; x++) {
326
+ const on = x < cols && side[y * cols + x] === 1;
327
+ if (on && x0 < 0) x0 = x;
328
+ else if (!on && x0 >= 0) {
329
+ const a = cellOrigin(x0, p.cell, p.dpr);
330
+ ctx.fillRect(a, y0, cellOrigin(x, p.cell, p.dpr) - a, y1 - y0);
331
+ x0 = -1;
332
+ }
333
+ }
334
+ }
335
+ }
336
+ const sideScale = p.sideNight ? INK_ALPHA_NIGHT : INK_ALPHA_DAY;
337
+ const open = lens.r > 0.5;
338
+ const lx0 = open ? Math.floor(lens.x - lens.r - 3) : 1;
339
+ const lx1 = open ? Math.ceil(lens.x + lens.r + 3) : 0;
340
+ const ly0 = open ? Math.floor(lens.y - lens.r - 3) : 1;
341
+ const ly1 = open ? Math.ceil(lens.y + lens.r + 3) : 0;
342
+ let curStyle = -2;
343
+ let curAlpha = -1;
344
+ ctx.globalAlpha = 1;
345
+ for (let y = 0; y < rows; y++) {
346
+ const oy = cellOrigin(y, p.cell, p.dpr);
347
+ const rowLens = y >= ly0 && y <= ly1;
348
+ for (let x = 0; x < cols; x++) {
349
+ const i = y * cols + x;
350
+ const c = color[i];
351
+ if (c < 0) continue;
352
+ let style;
353
+ let alpha;
354
+ if (rowLens && x >= lx0 && x <= lx1 && inLens(lens, x, y)) {
355
+ style = c;
356
+ alpha = 1;
357
+ if (glow[i] < LENS_BOOST && !(x < copyW && y < copyH)) glow[i] = LENS_BOOST;
358
+ } else if (lit[i]) {
359
+ style = c;
360
+ alpha = 1;
361
+ } else {
362
+ const a = inkA[i];
363
+ if (!(a > 0)) continue;
364
+ const onSide = !!side && side[i] === 1;
365
+ style = onSide ? -3 : -1;
366
+ alpha = Math.min(1, a * (onSide ? sideScale : inkScale));
367
+ }
368
+ if (style !== curStyle) {
369
+ ctx.fillStyle = style === -1 ? p.ink : style === -3 ? sideInk : cssOf(style);
370
+ curStyle = style;
371
+ }
372
+ if (alpha !== curAlpha) {
373
+ ctx.globalAlpha = alpha;
374
+ curAlpha = alpha;
375
+ }
376
+ ctx.fillRect(cellOrigin(x, p.cell, p.dpr), oy, size, size);
377
+ }
378
+ }
379
+ ctx.globalAlpha = 1;
380
+ }
381
+ function effectiveCell(cssW, cssH, cell, dot) {
382
+ let c = Number.isFinite(cell) ? clamp(cell, MIN_CELL, MAX_CELL) : 5;
383
+ let d = Number.isFinite(dot) ? clamp(dot, 1, c) : Math.min(4, c);
384
+ const W = Math.max(0, cssW);
385
+ const H = Math.max(0, cssH);
386
+ if (Math.ceil(W / c) * Math.ceil(H / c) > MAX_CELLS) {
387
+ const base = c;
388
+ c = Math.max(c, Math.ceil(Math.sqrt(W * H / MAX_CELLS)));
389
+ while (Math.ceil(W / c) * Math.ceil(H / c) > MAX_CELLS) c++;
390
+ d = Math.max(1, Math.min(c, Math.round(d * c / base)));
391
+ }
392
+ return { cell: c, dot: d };
393
+ }
394
+ function backingDpr(cssW, cssH, deviceDpr) {
395
+ const d = Number.isFinite(deviceDpr) && deviceDpr > 0 ? deviceDpr : 1;
396
+ return d > 1 && Math.max(0, cssW) * Math.max(0, cssH) * d * d > MAX_BACKING_PX ? 1 : d;
397
+ }
398
+ function normalizeLensRadius(r) {
399
+ return typeof r === "number" && Number.isFinite(r) ? clamp(r, 2, 200) : 21;
400
+ }
401
+ const HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
402
+ const INK_FALLBACK = "#808080";
403
+ function createPixelScene(el, options) {
404
+ const { host, canvas } = el;
405
+ let ctx = null;
406
+ try {
407
+ ctx = canvas.getContext("2d");
408
+ } catch {
409
+ ctx = null;
410
+ }
411
+ if (!ctx) return null;
412
+ const c2d = ctx;
413
+ let painter = options.painter;
414
+ let night = !!options.night;
415
+ let cellOpt = options.cell ?? 5;
416
+ let dotOpt = options.dot ?? 4;
417
+ let lensOn = options.lens ?? true;
418
+ let lensRadius = normalizeLensRadius(options.lensRadius);
419
+ let inkOpt = options.ink ?? "currentColor";
420
+ let paused = !!options.paused;
421
+ let waveOn = options.wave ?? true;
422
+ let surfaces = options.surfaces ?? null;
423
+ let inks = options.inks ?? null;
424
+ let rmOverride = options.reducedMotion;
425
+ let onFrame = options.onFrame ?? null;
426
+ let mq = null;
427
+ let mqReduced = false;
428
+ if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
429
+ try {
430
+ mq = window.matchMedia("(prefers-reduced-motion: reduce)");
431
+ mqReduced = mq.matches;
432
+ } catch {
433
+ mq = null;
434
+ }
435
+ }
436
+ const reduced = () => rmOverride !== void 0 ? rmOverride : mqReduced;
437
+ let grid = createGrid(0, 0);
438
+ let nextGrid = createGrid(0, 0);
439
+ let side = new Uint8Array(0);
440
+ const wave = { on: false, from: false, ox: 0, oy: 0, start: -1, cover: 0, oldInk: "" };
441
+ let cssW = 0;
442
+ let cssH = 0;
443
+ let dpr = 1;
444
+ let deviceDpr = 1;
445
+ let cell = 5;
446
+ let dot = 4;
447
+ let t = 0;
448
+ let last = 0;
449
+ let raf = 0;
450
+ let dirty = true;
451
+ let lensMoving = false;
452
+ let inView = true;
453
+ let destroyed = false;
454
+ let ink = INK_FALLBACK;
455
+ let inkAt = -Infinity;
456
+ let inkTimer = 0;
457
+ const lens = createLens();
458
+ const frame = {
459
+ cols: 0,
460
+ rows: 0,
461
+ width: 0,
462
+ height: 0,
463
+ pitch: 0,
464
+ size: 0,
465
+ cellCss: 0,
466
+ dpr: 1,
467
+ pixelated: false,
468
+ color: grid.color,
469
+ glow: grid.glow,
470
+ hcol: grid.hcol,
471
+ soft: grid.soft
472
+ };
473
+ const readDpr = () => typeof window !== "undefined" && window.devicePixelRatio > 0 ? Math.min(MAX_DPR, window.devicePixelRatio) : 1;
474
+ function resolveInk(now, force) {
475
+ if (inks) {
476
+ ink = inks[night ? 1 : 0];
477
+ return;
478
+ }
479
+ if (HEX_RE.test(inkOpt.trim())) {
480
+ ink = inkOpt.trim();
481
+ return;
482
+ }
483
+ if (!force && now - inkAt < 250) return;
484
+ inkAt = now;
485
+ try {
486
+ if (inkOpt.trim().toLowerCase() !== "currentcolor") {
487
+ ink = inkOpt;
488
+ return;
489
+ }
490
+ const col = typeof getComputedStyle === "function" ? getComputedStyle(host).color : "";
491
+ ink = col || INK_FALLBACK;
492
+ } catch {
493
+ ink = INK_FALLBACK;
494
+ }
495
+ }
496
+ const inkFollowsHost = () => inkOpt.trim().toLowerCase() === "currentcolor";
497
+ function refreshInk() {
498
+ if (destroyed || !inkFollowsHost()) return;
499
+ const before = ink;
500
+ resolveInk(typeof performance !== "undefined" ? performance.now() : 0, true);
501
+ if (ink !== before) wake();
502
+ }
503
+ function armInkPoll() {
504
+ if (inkTimer || destroyed || !inkFollowsHost() || typeof setTimeout !== "function") return;
505
+ inkTimer = setTimeout(() => {
506
+ inkTimer = 0;
507
+ if (destroyed || raf || !awake()) return;
508
+ refreshInk();
509
+ if (!raf) armInkPoll();
510
+ }, 500);
511
+ }
512
+ function clearInkPoll() {
513
+ if (inkTimer && typeof clearTimeout === "function") clearTimeout(inkTimer);
514
+ inkTimer = 0;
515
+ }
516
+ function layout() {
517
+ cssW = host.clientWidth || 0;
518
+ cssH = host.clientHeight || 0;
519
+ deviceDpr = readDpr();
520
+ dpr = backingDpr(cssW, cssH, deviceDpr);
521
+ const pixelated = dpr < deviceDpr;
522
+ frame.pixelated = pixelated;
523
+ const rendering = pixelated ? "pixelated" : "";
524
+ if (canvas.style && canvas.style.imageRendering !== rendering)
525
+ canvas.style.imageRendering = rendering;
526
+ const eff = effectiveCell(cssW, cssH, cellOpt, dotOpt);
527
+ cell = eff.cell;
528
+ dot = eff.dot;
529
+ const cols = cssW > 0 ? Math.ceil(cssW / cell) : 0;
530
+ const rows = cssH > 0 ? Math.ceil(cssH / cell) : 0;
531
+ if (cols !== grid.cols || rows !== grid.rows) {
532
+ grid = createGrid(cols, rows);
533
+ nextGrid = createGrid(cols, rows);
534
+ side = new Uint8Array(cols * rows);
535
+ frame.color = grid.color;
536
+ frame.glow = grid.glow;
537
+ frame.hcol = grid.hcol;
538
+ frame.soft = grid.soft;
539
+ }
540
+ const bw = Math.round(cssW * dpr);
541
+ const bh = Math.round(cssH * dpr);
542
+ if (canvas.width !== bw) canvas.width = bw;
543
+ if (canvas.height !== bh) canvas.height = bh;
544
+ dirty = true;
545
+ }
546
+ const docHidden = () => typeof document !== "undefined" && document.hidden === true;
547
+ const awake = () => inView && !docHidden() && grid.cols * grid.rows > 0 && !destroyed;
548
+ const animating = () => !paused && !reduced();
549
+ function schedule() {
550
+ if (raf || destroyed) return;
551
+ if (!awake() || !(animating() || lensMoving || dirty || wave.on)) {
552
+ last = 0;
553
+ if (awake()) armInkPoll();
554
+ else clearInkPoll();
555
+ return;
556
+ }
557
+ if (typeof requestAnimationFrame !== "function") return;
558
+ clearInkPoll();
559
+ raf = requestAnimationFrame(tick);
560
+ }
561
+ function startWave(from, to) {
562
+ clearGrid(nextGrid);
563
+ painter(t, nextGrid, to);
564
+ let ox = grid.sunX >= 0 ? grid.sunX : nextGrid.sunX;
565
+ let oy = grid.sunX >= 0 ? grid.sunY : nextGrid.sunY;
566
+ if (!(ox >= 0)) {
567
+ const lensed = lens.r > 0.5 || lens.tr > 0;
568
+ ox = lensed ? lens.tx : grid.cols * 0.85;
569
+ oy = lensed ? lens.ty : grid.rows * 0.2;
570
+ }
571
+ wave.on = true;
572
+ wave.oldInk = inks ? inks[from ? 1 : 0] : ink;
573
+ wave.from = from;
574
+ wave.ox = ox;
575
+ wave.oy = oy;
576
+ wave.start = -1;
577
+ wave.cover = waveCover(ox, oy, grid.cols, grid.rows);
578
+ }
579
+ function render(now) {
580
+ resolveInk(now, false);
581
+ clearGrid(grid);
582
+ let waving = false;
583
+ if (wave.on) {
584
+ if (wave.start < 0) wave.start = now;
585
+ const p = Math.min(1, Math.max(0, (now - wave.start) / WAVE_MS));
586
+ if (p >= 1) wave.on = false;
587
+ else {
588
+ waving = true;
589
+ painter(t, grid, wave.from);
590
+ clearGrid(nextGrid);
591
+ painter(t, nextGrid, night);
592
+ composeWave(grid, nextGrid, side, wave.ox, wave.oy, easeInOutCubic(p) * wave.cover);
593
+ }
594
+ }
595
+ if (!waving) painter(t, grid, night);
596
+ pixelHalos(grid);
597
+ paintGrid(c2d, grid, lens, {
598
+ cell,
599
+ dot,
600
+ dpr,
601
+ ink: waving ? wave.oldInk : ink,
602
+ night: waving ? wave.from : night,
603
+ side: waving ? side : null,
604
+ sideNight: night,
605
+ sideInk: ink,
606
+ surface: surfaces ? surfaces[(waving ? wave.from : night) ? 1 : 0] : null,
607
+ sideSurface: surfaces && waving ? surfaces[night ? 1 : 0] : null,
608
+ width: canvas.width,
609
+ height: canvas.height
610
+ });
611
+ if (onFrame) {
612
+ frame.cols = grid.cols;
613
+ frame.rows = grid.rows;
614
+ frame.width = canvas.width;
615
+ frame.height = canvas.height;
616
+ frame.pitch = cell * dpr;
617
+ frame.size = Math.max(1, Math.round(dot * dpr));
618
+ frame.cellCss = cell;
619
+ frame.dpr = dpr;
620
+ try {
621
+ onFrame(frame);
622
+ } catch {
623
+ onFrame = null;
624
+ }
625
+ }
626
+ }
627
+ function tick(now) {
628
+ raf = 0;
629
+ if (destroyed) return;
630
+ if (!awake()) {
631
+ last = 0;
632
+ return;
633
+ }
634
+ const dt = last ? Math.min(64, Math.max(0, now - last)) : 16.667;
635
+ last = now;
636
+ if (readDpr() !== deviceDpr) layout();
637
+ if (animating()) t += dt;
638
+ lensMoving = stepLens(lens, dt, reduced());
639
+ render(now);
640
+ dirty = false;
641
+ schedule();
642
+ }
643
+ function wake() {
644
+ dirty = true;
645
+ schedule();
646
+ }
647
+ function aim(e) {
648
+ if (!lensOn) return;
649
+ const b = canvas.getBoundingClientRect();
650
+ if (!(b.width > 0 && b.height > 0)) return;
651
+ const sx = cssW > 0 ? cssW / b.width : 1;
652
+ const sy = cssH > 0 ? cssH / b.height : 1;
653
+ lens.tx = (e.clientX - b.left) * sx / cell;
654
+ lens.ty = (e.clientY - b.top) * sy / cell;
655
+ if (lens.r < 0.5) {
656
+ lens.x = lens.tx;
657
+ lens.y = lens.ty;
658
+ }
659
+ lens.tr = lensRadius;
660
+ lensMoving = true;
661
+ wake();
662
+ }
663
+ function close() {
664
+ lens.tr = 0;
665
+ lensMoving = true;
666
+ wake();
667
+ }
668
+ const onMove = (e) => aim(e);
669
+ const onUp = (e) => {
670
+ if (e.pointerType === "touch") close();
671
+ };
672
+ const onLeave = () => close();
673
+ host.addEventListener("pointermove", onMove);
674
+ host.addEventListener("pointerdown", onMove);
675
+ host.addEventListener("pointerup", onUp);
676
+ host.addEventListener("pointerleave", onLeave);
677
+ host.addEventListener("pointercancel", onLeave);
678
+ let ro = null;
679
+ if (typeof ResizeObserver !== "undefined") {
680
+ ro = new ResizeObserver(() => {
681
+ const w = host.clientWidth || 0;
682
+ const h = host.clientHeight || 0;
683
+ if (w === cssW && h === cssH && readDpr() === deviceDpr) return;
684
+ layout();
685
+ schedule();
686
+ });
687
+ ro.observe(host);
688
+ }
689
+ let io = null;
690
+ if (typeof IntersectionObserver !== "undefined") {
691
+ io = new IntersectionObserver(
692
+ (entries) => {
693
+ const entry = entries[entries.length - 1];
694
+ if (!entry) return;
695
+ inView = entry.isIntersecting;
696
+ if (inView) schedule();
697
+ else clearInkPoll();
698
+ },
699
+ { rootMargin: "128px" }
700
+ );
701
+ io.observe(host);
702
+ }
703
+ const onVisibility = () => {
704
+ if (!docHidden()) schedule();
705
+ else clearInkPoll();
706
+ };
707
+ if (typeof document !== "undefined") document.addEventListener("visibilitychange", onVisibility);
708
+ const onMq = (e) => {
709
+ mqReduced = e.matches;
710
+ wake();
711
+ };
712
+ mq?.addEventListener?.("change", onMq);
713
+ let themeMo = null;
714
+ if (typeof MutationObserver !== "undefined" && typeof document !== "undefined") {
715
+ try {
716
+ themeMo = new MutationObserver(() => refreshInk());
717
+ themeMo.observe(document.documentElement, {
718
+ attributes: true,
719
+ attributeFilter: ["class", "style", "data-theme"]
720
+ });
721
+ } catch {
722
+ themeMo = null;
723
+ }
724
+ }
725
+ let schemeMq = null;
726
+ const onScheme = () => refreshInk();
727
+ if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
728
+ try {
729
+ schemeMq = window.matchMedia("(prefers-color-scheme: dark)");
730
+ schemeMq.addEventListener?.("change", onScheme);
731
+ } catch {
732
+ schemeMq = null;
733
+ }
734
+ }
735
+ let dprMq = null;
736
+ const onDpr = () => {
737
+ if (destroyed) return;
738
+ layout();
739
+ watchDpr();
740
+ wake();
741
+ };
742
+ function watchDpr() {
743
+ dprMq?.removeEventListener?.("change", onDpr);
744
+ dprMq = null;
745
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
746
+ const raw = window.devicePixelRatio > 0 ? window.devicePixelRatio : 1;
747
+ try {
748
+ dprMq = window.matchMedia(`(resolution: ${raw}dppx)`);
749
+ dprMq.addEventListener?.("change", onDpr);
750
+ } catch {
751
+ dprMq = null;
752
+ }
753
+ }
754
+ watchDpr();
755
+ resolveInk(0, true);
756
+ layout();
757
+ schedule();
758
+ return {
759
+ setOptions(next) {
760
+ if (destroyed) return;
761
+ let relayout = false;
762
+ if (next.painter !== void 0 && next.painter !== painter) painter = next.painter;
763
+ if (next.wave !== void 0) waveOn = !!next.wave;
764
+ if (next.night !== void 0 && !!next.night !== night) {
765
+ const to = !!next.night;
766
+ wave.on = false;
767
+ if (waveOn && !reduced() && grid.cols * grid.rows > 0) startWave(night, to);
768
+ night = to;
769
+ if (inks) ink = inks[to ? 1 : 0];
770
+ }
771
+ if (next.surfaces !== void 0) surfaces = next.surfaces;
772
+ if (next.inks !== void 0) {
773
+ inks = next.inks;
774
+ resolveInk(0, true);
775
+ }
776
+ if (next.cell !== void 0 && next.cell !== cellOpt) {
777
+ cellOpt = next.cell;
778
+ relayout = true;
779
+ }
780
+ if (next.dot !== void 0 && next.dot !== dotOpt) {
781
+ dotOpt = next.dot;
782
+ relayout = true;
783
+ }
784
+ if (next.lens !== void 0) {
785
+ lensOn = !!next.lens;
786
+ if (!lensOn) lens.tr = 0;
787
+ }
788
+ if (next.lensRadius !== void 0) {
789
+ lensRadius = normalizeLensRadius(next.lensRadius);
790
+ if (lens.tr > 0) lens.tr = lensRadius;
791
+ }
792
+ if (next.ink !== void 0) {
793
+ inkOpt = next.ink;
794
+ resolveInk(0, true);
795
+ if (!inkFollowsHost()) clearInkPoll();
796
+ }
797
+ if (next.paused !== void 0) paused = !!next.paused;
798
+ if (next.reducedMotion !== void 0) rmOverride = next.reducedMotion;
799
+ if ("onFrame" in next && next.onFrame !== void 0) onFrame = next.onFrame;
800
+ if (relayout) layout();
801
+ wake();
802
+ },
803
+ resize() {
804
+ if (destroyed) return;
805
+ layout();
806
+ schedule();
807
+ },
808
+ destroy() {
809
+ if (destroyed) return;
810
+ destroyed = true;
811
+ if (raf && typeof cancelAnimationFrame === "function") cancelAnimationFrame(raf);
812
+ raf = 0;
813
+ host.removeEventListener("pointermove", onMove);
814
+ host.removeEventListener("pointerdown", onMove);
815
+ host.removeEventListener("pointerup", onUp);
816
+ host.removeEventListener("pointerleave", onLeave);
817
+ host.removeEventListener("pointercancel", onLeave);
818
+ ro?.disconnect();
819
+ io?.disconnect();
820
+ if (typeof document !== "undefined")
821
+ document.removeEventListener("visibilitychange", onVisibility);
822
+ mq?.removeEventListener?.("change", onMq);
823
+ themeMo?.disconnect();
824
+ schemeMq?.removeEventListener?.("change", onScheme);
825
+ dprMq?.removeEventListener?.("change", onDpr);
826
+ dprMq = null;
827
+ clearInkPoll();
828
+ onFrame = null;
829
+ }
830
+ };
831
+ }
832
+ export {
833
+ BAYER,
834
+ GLOW_PEAK,
835
+ INK_ALPHA_DAY,
836
+ INK_ALPHA_NIGHT,
837
+ LENS_BOOST,
838
+ LIT_GLOW,
839
+ MAX_BACKING_PX,
840
+ MAX_CELL,
841
+ MAX_CELLS,
842
+ MAX_DPR,
843
+ MIN_CELL,
844
+ WAVE_GLOW_CELLS,
845
+ WAVE_HALO_CELLS,
846
+ WAVE_MS,
847
+ WAVE_PALETTE,
848
+ backingDpr,
849
+ bayer,
850
+ cellOrigin,
851
+ clamp,
852
+ clearGrid,
853
+ composeWave,
854
+ createGrid,
855
+ createLens,
856
+ createPixelScene,
857
+ cssOf,
858
+ easeInOutCubic,
859
+ effectiveCell,
860
+ encodeExt,
861
+ grad,
862
+ hash,
863
+ inLens,
864
+ mixHex,
865
+ noise1,
866
+ normalizeLensRadius,
867
+ paintGrid,
868
+ parseColour,
869
+ pixelHalos,
870
+ ridge,
871
+ smooth,
872
+ srgbToLinear,
873
+ stepLens,
874
+ waveBandGlow,
875
+ waveCover,
876
+ waveGlow,
877
+ writeCell
878
+ };