fancy-ui-vue 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +12 -12
  2. package/dist/components/frost-glass/FrostGlass.vue.d.ts +31 -0
  3. package/dist/components/frost-glass/FrostGlass.vue.js +90 -0
  4. package/dist/components/frost-glass/FrostGlass.vue2.js +4 -0
  5. package/dist/components/frost-glass/frost-glass-core.d.ts +155 -0
  6. package/dist/components/frost-glass/frost-glass-core.js +820 -0
  7. package/dist/components/frost-glass/index.d.ts +2 -0
  8. package/dist/components/gift-reveal/GiftReveal.vue.d.ts +50 -0
  9. package/dist/components/gift-reveal/GiftReveal.vue.js +7 -0
  10. package/dist/components/gift-reveal/GiftReveal.vue2.js +177 -0
  11. package/dist/components/gift-reveal/gift-reveal-core.d.ts +109 -0
  12. package/dist/components/gift-reveal/gift-reveal-core.js +116 -0
  13. package/dist/components/gift-reveal/index.d.ts +2 -0
  14. package/dist/components/ornament/Ornament.vue.d.ts +29 -0
  15. package/dist/components/ornament/Ornament.vue.js +112 -0
  16. package/dist/components/ornament/Ornament.vue2.js +4 -0
  17. package/dist/components/ornament/index.d.ts +2 -0
  18. package/dist/components/ornament/ornament-core.d.ts +177 -0
  19. package/dist/components/ornament/ornament-core.js +861 -0
  20. package/dist/components/snowfall/Snowfall.vue.d.ts +29 -0
  21. package/dist/components/snowfall/Snowfall.vue.js +81 -0
  22. package/dist/components/snowfall/Snowfall.vue2.js +4 -0
  23. package/dist/components/snowfall/index.d.ts +2 -0
  24. package/dist/components/snowfall/snowfall-core.d.ts +119 -0
  25. package/dist/components/snowfall/snowfall-core.js +483 -0
  26. package/dist/components/string-lights/StringLights.vue.d.ts +35 -0
  27. package/dist/components/string-lights/StringLights.vue.js +7 -0
  28. package/dist/components/string-lights/StringLights.vue2.js +98 -0
  29. package/dist/components/string-lights/index.d.ts +2 -0
  30. package/dist/components/string-lights/string-lights-core.d.ts +157 -0
  31. package/dist/components/string-lights/string-lights-core.js +228 -0
  32. package/dist/index.d.ts +5 -0
  33. package/dist/index.js +326 -316
  34. package/dist/styles.css +1341 -0
  35. package/package.json +2 -2
@@ -0,0 +1,820 @@
1
+ const FROST_GLASS_DEFAULTS = {
2
+ coverage: 0.45,
3
+ growth: 2.4,
4
+ melt: true,
5
+ refreeze: 4,
6
+ tint: "#cfe6ff",
7
+ sparkle: 0.5,
8
+ blur: 3,
9
+ seed: 7
10
+ };
11
+ const MAX_PIXEL_RATIO = 2;
12
+ const MAX_STEP = 1 / 20;
13
+ const HEAT_CELL = 6;
14
+ const HEAT_MAX_CELLS = 128;
15
+ const MELT_RADIUS = 26;
16
+ const MASK_INTERVAL = 66;
17
+ const SPARKLE_FPS = 30;
18
+ function parseHexColor(value, fallback) {
19
+ if (!value) return [fallback[0], fallback[1], fallback[2]];
20
+ const hex = value.trim().replace(/^#/, "");
21
+ const full = hex.length === 3 ? hex.split("").map((c) => c + c).join("") : hex;
22
+ if (!/^[0-9a-fA-F]{6}$/.test(full)) return [fallback[0], fallback[1], fallback[2]];
23
+ const n = Number.parseInt(full, 16);
24
+ return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];
25
+ }
26
+ function clamp01(value) {
27
+ if (!Number.isFinite(value)) return 0;
28
+ return Math.min(1, Math.max(0, value));
29
+ }
30
+ function clampCoverage(coverage) {
31
+ return clamp01(coverage);
32
+ }
33
+ function growthProgress(elapsed, growth) {
34
+ if (!Number.isFinite(growth) || growth <= 0) return 1;
35
+ const t = clamp01(elapsed / growth);
36
+ return 1 - (1 - t) ** 3;
37
+ }
38
+ function fallbackBackground(tint, coverage) {
39
+ const [r, g, b] = parseHexColor(tint, [0.81, 0.9, 1]);
40
+ const rgb = `${Math.round(r * 255)} ${Math.round(g * 255)} ${Math.round(b * 255)}`;
41
+ const clear = Math.round((1 - clampCoverage(coverage)) * 100);
42
+ return `radial-gradient(ellipse closest-side at 50% 50%, transparent ${clear}%, rgb(${rgb} / 0.12) ${Math.min(100, clear + 30)}%, rgb(${rgb} / 0.3) 100%)`;
43
+ }
44
+ function fallbackMask(coverage) {
45
+ const clear = Math.round((1 - clampCoverage(coverage)) * 100);
46
+ return `radial-gradient(ellipse closest-side at 50% 50%, transparent ${clear}%, #000 ${Math.min(100, clear + 35)}%)`;
47
+ }
48
+ function blurLayerDeclarations(blur, coverage) {
49
+ if (!Number.isFinite(blur) || blur <= 0) return [["display", "none"]];
50
+ const filter = `blur(${blur}px)`;
51
+ const mask = `var(--fancy-frost-mask, ${fallbackMask(coverage)})`;
52
+ return [
53
+ ["backdrop-filter", filter],
54
+ ["-webkit-backdrop-filter", filter],
55
+ ["mask-image", mask],
56
+ ["-webkit-mask-image", mask],
57
+ ["mask-size", "100% 100%"],
58
+ ["-webkit-mask-size", "100% 100%"]
59
+ ];
60
+ }
61
+ function frostAmount(edgeDistance, reach) {
62
+ if (reach <= 0) return 0;
63
+ const t = clamp01((reach - edgeDistance) / Math.max(0.08, reach * 0.6));
64
+ return t * t * (3 - 2 * t);
65
+ }
66
+ function valueNoise(x, y, seed) {
67
+ const hash = (ix2, iy2) => {
68
+ let h = Math.imul(ix2, 374761393) ^ Math.imul(iy2, 668265263) ^ Math.imul(seed | 0, 2246822519);
69
+ h = Math.imul(h ^ h >>> 13, 1274126177);
70
+ return ((h ^ h >>> 16) >>> 0) / 4294967296;
71
+ };
72
+ const ix = Math.floor(x);
73
+ const iy = Math.floor(y);
74
+ const fx = x - ix;
75
+ const fy = y - iy;
76
+ const ux = fx * fx * (3 - 2 * fx);
77
+ const uy = fy * fy * (3 - 2 * fy);
78
+ const top = hash(ix, iy) + (hash(ix + 1, iy) - hash(ix, iy)) * ux;
79
+ const bottom = hash(ix, iy + 1) + (hash(ix + 1, iy + 1) - hash(ix, iy + 1)) * ux;
80
+ return top + (bottom - top) * uy;
81
+ }
82
+ function createHeatGrid(width, height) {
83
+ const long = Math.max(1, width, height);
84
+ const cell = Math.max(HEAT_CELL, long / HEAT_MAX_CELLS);
85
+ const cols = Math.max(1, Math.ceil(Math.max(1, width) / cell));
86
+ const rows = Math.max(1, Math.ceil(Math.max(1, height) / cell));
87
+ return { cols, rows, cell, data: new Float32Array(cols * rows) };
88
+ }
89
+ function depositHeat(grid, x0, y0, x1, y1, radius, amount) {
90
+ if (amount <= 0) return;
91
+ const length = Math.hypot(x1 - x0, y1 - y0);
92
+ const steps = Math.max(1, Math.ceil(length / (radius * 0.5)));
93
+ const share = amount / Math.max(1, Math.min(steps, length / (radius * 0.5)));
94
+ const reach = radius / grid.cell;
95
+ for (let s = 0; s <= steps; s++) {
96
+ if (s === 0 && length > 0) continue;
97
+ const k = s / steps;
98
+ const cx = (x0 + (x1 - x0) * k) / grid.cell - 0.5;
99
+ const cy = (y0 + (y1 - y0) * k) / grid.cell - 0.5;
100
+ const minX = Math.max(0, Math.floor(cx - reach));
101
+ const maxX = Math.min(grid.cols - 1, Math.ceil(cx + reach));
102
+ const minY = Math.max(0, Math.floor(cy - reach));
103
+ const maxY = Math.min(grid.rows - 1, Math.ceil(cy + reach));
104
+ for (let y = minY; y <= maxY; y++) {
105
+ for (let x = minX; x <= maxX; x++) {
106
+ const d = Math.hypot(x - cx, y - cy) / reach;
107
+ if (d >= 1) continue;
108
+ const falloff = (1 - d * d) ** 2;
109
+ const index = y * grid.cols + x;
110
+ grid.data[index] = Math.min(1, (grid.data[index] ?? 0) + share * falloff);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ function coolHeat(grid, dt, refreeze) {
116
+ const step = Number.isFinite(refreeze) && refreeze > 0 ? dt / refreeze : 1;
117
+ let warm = false;
118
+ const data = grid.data;
119
+ for (let i = 0; i < data.length; i++) {
120
+ const value = data[i] ?? 0;
121
+ if (value === 0) continue;
122
+ const next = value - step;
123
+ data[i] = next > 0 ? next : 0;
124
+ if (next > 0) warm = true;
125
+ }
126
+ return warm;
127
+ }
128
+ function mulberry32(seed) {
129
+ let a = seed >>> 0;
130
+ return () => {
131
+ a = a + 1831565813 >>> 0;
132
+ let t = a;
133
+ t = Math.imul(t ^ t >>> 15, t | 1);
134
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
135
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
136
+ };
137
+ }
138
+ const VERTEX_SHADER = `
139
+ attribute vec2 aPos;
140
+ void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
141
+ `;
142
+ const FRAGMENT_SHADER = `
143
+ precision highp float;
144
+
145
+ uniform vec2 uRes;
146
+ uniform float uScale;
147
+ uniform float uReach;
148
+ uniform float uTime;
149
+ uniform float uSparkle;
150
+ uniform vec3 uTint;
151
+ uniform vec2 uSeed;
152
+ uniform sampler2D uHeat;
153
+ uniform vec2 uHeatSpan;
154
+ uniform vec2 uHeatCells;
155
+ uniform float uRadius;
156
+
157
+ vec2 size;
158
+ float halfSide;
159
+
160
+ float hash(vec2 p) {
161
+ p = fract(p * vec2(123.34, 456.21) + uSeed);
162
+ p += dot(p, p + 45.32);
163
+ return fract(p.x * p.y);
164
+ }
165
+
166
+ float noise(vec2 p) {
167
+ vec2 i = floor(p);
168
+ vec2 f = fract(p);
169
+ vec2 u = f * f * (3.0 - 2.0 * f);
170
+ return mix(mix(hash(i), hash(i + vec2(1.0, 0.0)), u.x),
171
+ mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x), u.y);
172
+ }
173
+
174
+ float fbm(vec2 p) {
175
+ float v = 0.0;
176
+ float a = 0.5;
177
+ for (int i = 0; i < 4; i++) {
178
+ v += a * noise(p);
179
+ p = mat2(1.6, 1.2, -1.2, 1.6) * p;
180
+ a *= 0.5;
181
+ }
182
+ return v;
183
+ }
184
+
185
+ // Distance to the nearest edge, as a fraction of the half short side.
186
+ // Distance inside the pane's rounded rectangle, in CSS pixels, so the ice
187
+ // follows the corners instead of piling up in the clipped-off square ones.
188
+ float inset(vec2 p) {
189
+ vec2 h = size * 0.5;
190
+ float r = min(uRadius, min(h.x, h.y));
191
+ vec2 q = abs(p - h) - (h - r);
192
+ return r - length(max(q, 0.0)) - min(max(q.x, q.y), 0.0);
193
+ }
194
+
195
+ float edgeDistance(vec2 p) {
196
+ return inset(p) / halfSide;
197
+ }
198
+
199
+ // Unit vector pointing away from the nearest edge.
200
+ vec2 inward(vec2 p) {
201
+ float dx = min(p.x, size.x - p.x);
202
+ float dy = min(p.y, size.y - p.y);
203
+ if (dx < dy) return vec2(p.x < size.x * 0.5 ? 1.0 : -1.0, 0.0);
204
+ return vec2(0.0, p.y < size.y * 0.5 ? 1.0 : -1.0);
205
+ }
206
+
207
+ // Warmth between cell centres, blended with a smoothstep weight instead of the
208
+ // hardware's straight line, so a warm spot is round rather than octagonal.
209
+ float heatAt(vec2 p) {
210
+ vec2 g = p / (uHeatSpan / uHeatCells) - 0.5;
211
+ vec2 i = floor(g);
212
+ vec2 f = g - i;
213
+ f = f * f * (3.0 - 2.0 * f);
214
+ vec2 inv = 1.0 / uHeatCells;
215
+ float a = texture2D(uHeat, (i + 0.5) * inv).r;
216
+ float b = texture2D(uHeat, (i + vec2(1.5, 0.5)) * inv).r;
217
+ float c = texture2D(uHeat, (i + vec2(0.5, 1.5)) * inv).r;
218
+ float d = texture2D(uHeat, (i + 1.5) * inv).r;
219
+ return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);
220
+ }
221
+
222
+ // Where p sits relative to its nearest edge: x runs along that edge, y is the
223
+ // distance into the pane in CSS pixels. Each edge gets its own stretch of x so
224
+ // the four borders do not repeat one another.
225
+ vec2 edgeFrame(vec2 p) {
226
+ float left = p.x;
227
+ float right = size.x - p.x;
228
+ float top = p.y;
229
+ float bottom = size.y - p.y;
230
+ float m = min(min(left, right), min(top, bottom));
231
+ float r = inset(p);
232
+ if (m == left) return vec2(p.y, r);
233
+ if (m == right) return vec2(p.y + 3000.0, r);
234
+ if (m == top) return vec2(p.x + 6000.0, r);
235
+ return vec2(p.x + 9000.0, r);
236
+ }
237
+
238
+ // One family of dendrites rooted on the border, every \`spacing\` pixels along
239
+ // it. Each has a spine growing inward (bent by noise, leaning a little), and
240
+ // side branches leaving it at about 60 degrees, longest where the ice is
241
+ // thick. \`reachT\` is how thick the ice must be for this family to exist, so
242
+ // small growth only fills in behind the big dendrites.
243
+ // x: bright ridge, y: shadow beside it (the side away from the light).
244
+ vec2 dendrites(vec2 f, float spacing, float salt, float thick, float lead, float width) {
245
+ vec2 acc = vec2(0.0);
246
+ float aa = 0.8 / uScale;
247
+ float k0 = floor(f.x / spacing);
248
+ for (int i = -1; i <= 1; i++) {
249
+ float k = k0 + float(i);
250
+ float h1 = hash(vec2(k, salt));
251
+ float h2 = hash(vec2(k, salt + 7.0));
252
+ float h3 = hash(vec2(k, salt + 13.0));
253
+ // Some roots never sprout, so the border is not a comb.
254
+ if (h3 < 0.18) continue;
255
+ float h4 = hash(vec2(k, salt + 19.0));
256
+ // Some dendrites stop short near the border; others run past the haze
257
+ // front by up to \`lead\`.
258
+ float alive = thick - (1.0 - h4) * 0.4 + lead * h2;
259
+ if (alive <= 0.0) continue;
260
+ float r = f.y;
261
+ float centre = (k + 0.2 + 0.6 * h1) * spacing;
262
+ float lean = (h2 - 0.5) * 0.7;
263
+ float bend = (noise(vec2(r * 0.02, k * 3.1 + salt)) - 0.5) * spacing * 0.28;
264
+ // A slow curve on top of the lean, different for every dendrite.
265
+ float curve = (h4 - 0.5) * 0.004 * r * r;
266
+ float x = f.x - centre - r * lean - bend - curve;
267
+ float ax = abs(x);
268
+ float tipFade = smoothstep(0.0, 0.12, alive);
269
+ float w = width * mix(0.45, 1.0, clamp(thick, 0.0, 1.0));
270
+ float spine = 1.0 - smoothstep(w, w + aa * 2.0, ax);
271
+ // Shadow on one side of the spine only: that is what reads as relief.
272
+ float sx = x * sign(lean + 1e-3);
273
+ float spineShade = smoothstep(w, w + aa, sx) * (1.0 - smoothstep(w + 0.8, w + 2.0, sx));
274
+ // Side branches, swept toward the growth direction.
275
+ float gap = spacing * (0.09 + 0.05 * h1);
276
+ // The two sides alternate, and some branches never grow.
277
+ float side = x > 0.0 ? 0.5 : 0.0;
278
+ float b = (r - ax * 0.58) / gap + side;
279
+ float bi = floor(b);
280
+ float hb = hash(vec2(bi + side * 2.0, k + salt));
281
+ float hb2 = hash(vec2(bi + side * 2.0, k + salt + 5.0));
282
+ float reach = spacing * (0.12 + 0.4 * hb * hb) * smoothstep(-0.05, 0.7, thick);
283
+ float branch = 0.0;
284
+ float branchShade = 0.0;
285
+ if (ax < reach && hb > 0.22) {
286
+ // Each branch sits off-centre in its slot and leaves at its own angle.
287
+ float at = 0.5 + (hb2 - 0.5) * 0.5 + ax * (hb - 0.5) * 0.12 / gap;
288
+ float fb = (fract(b) - at) * gap * 0.86;
289
+ float bw = width * 0.55 * (1.0 - 0.6 * ax / reach);
290
+ float fade = 1.0 - ax / reach;
291
+ branch = (1.0 - smoothstep(bw, bw + aa * 2.0, abs(fb))) * fade;
292
+ branchShade = smoothstep(bw, bw + aa, fb) * (1.0 - smoothstep(bw + 0.7, bw + 1.6, fb)) * fade;
293
+ }
294
+ acc.x = max(acc.x, max(spine, branch * 0.85) * tipFade);
295
+ acc.y = max(acc.y, max(spineShade, branchShade * 0.7) * tipFade);
296
+ }
297
+ return acc;
298
+ }
299
+
300
+ void main() {
301
+ size = uRes / uScale;
302
+ halfSide = 0.5 * min(size.x, size.y);
303
+ vec2 p = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y) / uScale;
304
+
305
+ float heat = heatAt(p);
306
+
307
+ // Thickness of the ice: 1 at the border, 0 at the front. The front is lobed:
308
+ // the distance to the edge is warped by two octaves of noise.
309
+ float d = edgeDistance(p) + (fbm(p * 0.006) - 0.5) * 0.5 + (fbm(p * 0.03 + 5.0) - 0.5) * 0.08;
310
+ float thick = (uReach - d) / 0.45;
311
+ // Warmth thins the ice. A warm spot loses its edge first on the way in and
312
+ // gets it back last, so refreezing creeps in from the rim of the trail.
313
+ // The melt edge wanders like the frost front, so a trail is never a clean blob.
314
+ float melted = max(0.0, heat * 2.2 + (fbm(p * 0.035 + 7.0) - 0.5) * 0.9 * smoothstep(0.0, 0.2, heat));
315
+ float t = thick - melted;
316
+
317
+ // Dendrites follow the edge normal, with a light warp so no spine is straight.
318
+ vec2 warp = vec2(fbm(p * 0.013 + 3.1), fbm(p * 0.013 + 8.7)) - 0.5;
319
+ vec2 f = edgeFrame(p + warp * 18.0);
320
+ vec2 big = dendrites(f, 96.0, 1.0, t, 0.22, 0.85);
321
+ vec2 mid = dendrites(f + vec2(31.0, 0.0), 41.0, 2.0, t - 0.25, 0.08, 0.6);
322
+ vec2 fine = dendrites(f + vec2(13.0, 0.0), 17.0, 3.0, t - 0.5, 0.0, 0.42);
323
+ float ridge = max(big.x, max(mid.x * 0.75, fine.x * 0.5));
324
+ // Shadow only where there is ice, so no grey halo forms past the front.
325
+ float shade = max(big.y, max(mid.y * 0.7, fine.y * 0.45)) * (1.0 - ridge) * smoothstep(0.0, 0.3, t);
326
+ // Roots fade into the rime right at the border, so no crystal is cut off
327
+ // as a bright sliver where the rounded corner clips the pane.
328
+ // Corners are left to the rime: there the two edge frames meet and a
329
+ // leaning spine would be stretched into a bright wedge.
330
+ vec2 toCorner = min(p, size - p);
331
+ float corner = smoothstep(8.0, 30.0 + uRadius, length(toCorner));
332
+ float rooted = smoothstep(0.5, 6.0, inset(p)) * corner;
333
+ ridge *= rooted;
334
+ shade *= rooted;
335
+ // Thin ice is faint and cool; thick ice is bright.
336
+ float body = clamp(t, 0.0, 1.0);
337
+ ridge *= 0.35 + 0.65 * body;
338
+
339
+ // Rime: fine grains, thresholded by thickness, so the ice is a continuous
340
+ // granular crust at the border that breaks up into specks toward the front.
341
+ float grain = noise(p * 1.1 + 11.0) * 0.55 + noise(p * 2.6 + 4.0) * 0.45;
342
+ float rime = smoothstep(0.98 - body * 0.8, 1.2 - body * 0.8, grain) * smoothstep(0.0, 0.08, t);
343
+ float haze = smoothstep(0.02, 0.45, t) * (0.55 + 0.45 * fbm(p * 0.03 + 2.0));
344
+
345
+ // Three inks: a cold blue-grey for the haze and rime, white for the ridges,
346
+ // and a deeper blue-grey for their shadow side. The greys are what make the
347
+ // ice read on a white pane; the whites carry it on a dark one.
348
+ vec3 frostInk = mix(vec3(0.80, 0.86, 0.93), uTint, 0.5);
349
+ vec3 deep = mix(vec3(0.34, 0.43, 0.56), uTint * 0.5, 0.35);
350
+ float aHaze = haze * 0.2 + rime * (0.06 + 0.12 * body);
351
+ float aRidge = ridge * 0.8;
352
+ float aShade = shade * (0.3 + 0.2 * body);
353
+
354
+ // The melted trail: clear glass inside, a thin bright meniscus where the
355
+ // water meets the ice, and a slightly darker water edge just inside it.
356
+ float e = 3.0;
357
+ vec2 grad = vec2(heatAt(p + vec2(e, 0.0)) - heatAt(p - vec2(e, 0.0)),
358
+ heatAt(p + vec2(0.0, e)) - heatAt(p - vec2(0.0, e))) / (2.0 * e);
359
+ float slope = max(length(grad) * 2.2, 1e-3);
360
+ // Pixels from the line where the trail just clears the ice.
361
+ float edge = (melted - thick) / slope;
362
+ float wetZone = step(0.02, heat) * smoothstep(0.05, 0.25, thick);
363
+ float meniscus = (1.0 - smoothstep(0.0, 1.1, abs(edge))) * wetZone;
364
+ float waterEdge = (1.0 - smoothstep(0.0, 2.5, abs(edge - 3.0))) * wetZone;
365
+ // The rim is not a drawn outline: it comes and goes along its length.
366
+ float along = smoothstep(0.3, 0.75, fbm(p * 0.045 + 13.0));
367
+ float aMeniscus = meniscus * 0.4 * along;
368
+ float aWater = waterEdge * 0.14 * (0.4 + 0.6 * along);
369
+
370
+ vec3 col = frostInk * aHaze + vec3(1.0) * aRidge + deep * aShade
371
+ + vec3(1.0) * aMeniscus + deep * aWater;
372
+ float alpha = aHaze + aRidge + aShade + aMeniscus + aWater;
373
+
374
+ // Slow glints, only on thick ridges: a tiny four-pointed star in a few cells.
375
+ vec2 sc = floor(p / 13.0);
376
+ float sh = hash(sc + 71.0);
377
+ if (uSparkle > 0.0 && sh > 0.9 && ridge > 0.45) {
378
+ vec2 sp = (sc + 0.5) * 13.0;
379
+ vec2 dd = abs(p - sp);
380
+ float star = exp(-dot(dd, dd) / 2.0) + (exp(-dd.x * dd.x / 0.35) * exp(-dd.y / 3.0) + exp(-dd.y * dd.y / 0.35) * exp(-dd.x / 3.0)) * 0.5;
381
+ float phase = sh * 91.0 + uTime * (0.35 + 0.5 * hash(sc + 3.0));
382
+ float glint = pow(max(0.0, sin(phase)), 18.0) * uSparkle * body;
383
+ col += vec3(1.0) * star * glint;
384
+ alpha += star * glint;
385
+ }
386
+
387
+ alpha = clamp(alpha, 0.0, 0.94);
388
+ col = min(col, vec3(alpha));
389
+ gl_FragColor = vec4(col, alpha);
390
+ }
391
+ `;
392
+ const UNIFORMS = [
393
+ "uRes",
394
+ "uScale",
395
+ "uReach",
396
+ "uTime",
397
+ "uSparkle",
398
+ "uTint",
399
+ "uSeed",
400
+ "uHeat",
401
+ "uHeatSpan",
402
+ "uHeatCells",
403
+ "uRadius"
404
+ ];
405
+ function compile(gl, type, source) {
406
+ const shader = gl.createShader(type);
407
+ if (!shader) return null;
408
+ gl.shaderSource(shader, source);
409
+ gl.compileShader(shader);
410
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
411
+ gl.deleteShader(shader);
412
+ return null;
413
+ }
414
+ return shader;
415
+ }
416
+ function setupGl(gl) {
417
+ const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
418
+ const fragment = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
419
+ const program = gl.createProgram();
420
+ if (!vertex || !fragment || !program) {
421
+ if (vertex) gl.deleteShader(vertex);
422
+ if (fragment) gl.deleteShader(fragment);
423
+ if (program) gl.deleteProgram(program);
424
+ return null;
425
+ }
426
+ gl.attachShader(program, vertex);
427
+ gl.attachShader(program, fragment);
428
+ gl.bindAttribLocation(program, 0, "aPos");
429
+ gl.linkProgram(program);
430
+ gl.deleteShader(vertex);
431
+ gl.deleteShader(fragment);
432
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
433
+ gl.deleteProgram(program);
434
+ return null;
435
+ }
436
+ gl.useProgram(program);
437
+ const buffer = gl.createBuffer();
438
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
439
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
440
+ gl.enableVertexAttribArray(0);
441
+ gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
442
+ const uniforms = {};
443
+ for (const name of UNIFORMS) uniforms[name] = gl.getUniformLocation(program, name);
444
+ const texture = gl.createTexture();
445
+ gl.bindTexture(gl.TEXTURE_2D, texture);
446
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
447
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
448
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
449
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
450
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
451
+ gl.uniform1i(uniforms.uHeat, 0);
452
+ gl.disable(gl.DEPTH_TEST);
453
+ gl.clearColor(0, 0, 0, 0);
454
+ return { program, buffer, texture, uniforms };
455
+ }
456
+ function createFrostGlass(elements, options = {}) {
457
+ const { canvas, root } = elements;
458
+ const blurLayer = elements.blurLayer ?? null;
459
+ const releaseContext = options.releaseContext ?? true;
460
+ let gl = null;
461
+ try {
462
+ gl = canvas.getContext("webgl", {
463
+ alpha: true,
464
+ premultipliedAlpha: true,
465
+ antialias: false,
466
+ powerPreference: "low-power"
467
+ });
468
+ } catch {
469
+ gl = null;
470
+ }
471
+ if (!gl) return null;
472
+ const context = gl;
473
+ let resources = setupGl(context);
474
+ if (!resources) return null;
475
+ const live = {
476
+ coverage: options.coverage ?? FROST_GLASS_DEFAULTS.coverage,
477
+ growth: options.growth ?? FROST_GLASS_DEFAULTS.growth,
478
+ melt: options.melt ?? FROST_GLASS_DEFAULTS.melt,
479
+ refreeze: options.refreeze ?? FROST_GLASS_DEFAULTS.refreeze,
480
+ tint: options.tint ?? FROST_GLASS_DEFAULTS.tint,
481
+ sparkle: options.sparkle ?? FROST_GLASS_DEFAULTS.sparkle,
482
+ reducedMotion: options.reducedMotion ?? false
483
+ };
484
+ const random = mulberry32(options.seed ?? FROST_GLASS_DEFAULTS.seed);
485
+ const seedOffset = [random() * 1e3, random() * 1e3];
486
+ const maskSeed = Math.floor(random() * 1e6);
487
+ let destroyed = false;
488
+ let contextLost = false;
489
+ let frame = 0;
490
+ let last = 0;
491
+ let lastDraw = 0;
492
+ let inView = true;
493
+ let pageVisible = typeof document === "undefined" || !document.hidden;
494
+ let grownFor = 0;
495
+ let time = 0;
496
+ let warm = false;
497
+ let cssWidth = 0;
498
+ let cssHeight = 0;
499
+ let radius = 0;
500
+ let grid = createHeatGrid(1, 1);
501
+ let heatBytes = new Uint8Array(grid.data.length);
502
+ let heatDirty = true;
503
+ let pointerX = Number.NaN;
504
+ let pointerY = Number.NaN;
505
+ let maskCanvas = null;
506
+ let maskContext = null;
507
+ let maskDirty = true;
508
+ let maskAt = 0;
509
+ function grown() {
510
+ if (live.reducedMotion) return 1;
511
+ return growthProgress(grownFor, live.growth);
512
+ }
513
+ function reach() {
514
+ return clampCoverage(live.coverage) * grown();
515
+ }
516
+ function readRadius() {
517
+ if (typeof getComputedStyle !== "function") return 0;
518
+ const value = Number.parseFloat(getComputedStyle(canvas).borderTopLeftRadius);
519
+ return Number.isFinite(value) ? Math.max(0, value) : 0;
520
+ }
521
+ function resize() {
522
+ const ratio = Math.min(
523
+ typeof window !== "undefined" && window.devicePixelRatio || 1,
524
+ MAX_PIXEL_RATIO
525
+ );
526
+ const width = Math.max(1, canvas.clientWidth);
527
+ const height = Math.max(1, canvas.clientHeight);
528
+ const deviceWidth = Math.max(1, Math.round(width * ratio));
529
+ const deviceHeight = Math.max(1, Math.round(height * ratio));
530
+ if (canvas.width !== deviceWidth || canvas.height !== deviceHeight) {
531
+ canvas.width = deviceWidth;
532
+ canvas.height = deviceHeight;
533
+ }
534
+ if (width !== cssWidth || height !== cssHeight) {
535
+ cssWidth = width;
536
+ cssHeight = height;
537
+ radius = readRadius();
538
+ grid = createHeatGrid(width, height);
539
+ heatBytes = new Uint8Array(grid.data.length);
540
+ heatDirty = true;
541
+ maskDirty = true;
542
+ warm = false;
543
+ }
544
+ }
545
+ function uploadHeat() {
546
+ if (!resources) return;
547
+ const data = grid.data;
548
+ for (let i = 0; i < data.length; i++) heatBytes[i] = Math.round((data[i] ?? 0) * 255);
549
+ context.activeTexture(context.TEXTURE0);
550
+ context.bindTexture(context.TEXTURE_2D, resources.texture);
551
+ context.texImage2D(
552
+ context.TEXTURE_2D,
553
+ 0,
554
+ context.LUMINANCE,
555
+ grid.cols,
556
+ grid.rows,
557
+ 0,
558
+ context.LUMINANCE,
559
+ context.UNSIGNED_BYTE,
560
+ heatBytes
561
+ );
562
+ heatDirty = false;
563
+ }
564
+ function updateMask(now) {
565
+ if (!maskDirty) return;
566
+ if (!blurLayer) {
567
+ maskDirty = false;
568
+ return;
569
+ }
570
+ if (now - maskAt < MASK_INTERVAL && (warm || growing())) return;
571
+ if (!maskCanvas && typeof document !== "undefined") {
572
+ maskCanvas = document.createElement("canvas");
573
+ try {
574
+ maskContext = maskCanvas.getContext("2d");
575
+ } catch {
576
+ maskContext = null;
577
+ }
578
+ }
579
+ if (!maskCanvas || !maskContext) {
580
+ maskDirty = false;
581
+ return;
582
+ }
583
+ maskAt = now;
584
+ maskDirty = false;
585
+ const { cols, rows, cell } = grid;
586
+ if (maskCanvas.width !== cols || maskCanvas.height !== rows) {
587
+ maskCanvas.width = cols;
588
+ maskCanvas.height = rows;
589
+ }
590
+ const image = maskContext.createImageData(cols, rows);
591
+ const half = 0.5 * Math.min(cssWidth, cssHeight);
592
+ const front = reach();
593
+ for (let y = 0; y < rows; y++) {
594
+ for (let x = 0; x < cols; x++) {
595
+ const px = (x + 0.5) * cell;
596
+ const py = (y + 0.5) * cell;
597
+ const wobble = (valueNoise(px * 0.01, py * 0.01, maskSeed) - 0.5) * 0.45;
598
+ const edge = Math.min(px, cssWidth - px, py, cssHeight - py) / half + wobble;
599
+ const heat = grid.data[y * cols + x] ?? 0;
600
+ const amount = frostAmount(edge, front) * (1 - Math.min(1, heat * 1.4));
601
+ image.data[(y * cols + x) * 4 + 3] = Math.round(amount * 255);
602
+ }
603
+ }
604
+ maskContext.putImageData(image, 0, 0);
605
+ try {
606
+ blurLayer.style.setProperty("--fancy-frost-mask", `url(${maskCanvas.toDataURL()})`);
607
+ } catch {
608
+ }
609
+ }
610
+ function draw(now) {
611
+ if (destroyed || contextLost || !resources) return;
612
+ resize();
613
+ if (heatDirty) uploadHeat();
614
+ const tint = parseHexColor(live.tint, [0.81, 0.9, 1]);
615
+ const { uniforms } = resources;
616
+ context.viewport(0, 0, canvas.width, canvas.height);
617
+ context.clear(context.COLOR_BUFFER_BIT);
618
+ context.uniform2f(uniforms.uRes, canvas.width, canvas.height);
619
+ context.uniform1f(uniforms.uScale, canvas.width / cssWidth);
620
+ context.uniform1f(uniforms.uReach, reach());
621
+ context.uniform1f(uniforms.uTime, time);
622
+ context.uniform1f(uniforms.uSparkle, clamp01(live.sparkle));
623
+ context.uniform3f(uniforms.uTint, tint[0], tint[1], tint[2]);
624
+ context.uniform2f(uniforms.uSeed, seedOffset[0], seedOffset[1]);
625
+ context.uniform2f(uniforms.uHeatSpan, grid.cols * grid.cell, grid.rows * grid.cell);
626
+ context.uniform2f(uniforms.uHeatCells, grid.cols, grid.rows);
627
+ context.uniform1f(uniforms.uRadius, radius);
628
+ context.drawArrays(context.TRIANGLES, 0, 3);
629
+ lastDraw = now;
630
+ updateMask(now);
631
+ }
632
+ function growing() {
633
+ return grown() < 1;
634
+ }
635
+ function glinting() {
636
+ return !live.reducedMotion && clamp01(live.sparkle) > 0;
637
+ }
638
+ function changing() {
639
+ return growing() || warm || glinting();
640
+ }
641
+ function shouldRun() {
642
+ return !destroyed && !contextLost && inView && pageVisible && changing();
643
+ }
644
+ function tick(now) {
645
+ frame = 0;
646
+ if (destroyed) return;
647
+ const dt = last === 0 ? 0 : Math.min(Math.max((now - last) / 1e3, 0), MAX_STEP);
648
+ last = now;
649
+ const wasGrowing = growing();
650
+ grownFor += dt;
651
+ if (wasGrowing) maskDirty = true;
652
+ if (warm) {
653
+ warm = coolHeat(grid, dt, live.refreeze);
654
+ heatDirty = true;
655
+ maskDirty = true;
656
+ }
657
+ time += dt;
658
+ const glintOnly = !wasGrowing && !warm && !heatDirty && !maskDirty;
659
+ if (!glintOnly || now - lastDraw >= 1e3 / SPARKLE_FPS - 2) draw(now);
660
+ if (shouldRun()) frame = requestAnimationFrame(tick);
661
+ else last = 0;
662
+ }
663
+ function wake() {
664
+ if (destroyed) return;
665
+ if (frame !== 0) return;
666
+ if (shouldRun()) {
667
+ last = 0;
668
+ frame = requestAnimationFrame(tick);
669
+ } else {
670
+ draw(typeof performance !== "undefined" ? performance.now() : 0);
671
+ }
672
+ }
673
+ function localPoint(event) {
674
+ const rect = canvas.getBoundingClientRect();
675
+ const sx = rect.width > 0 ? cssWidth / rect.width : 1;
676
+ const sy = rect.height > 0 ? cssHeight / rect.height : 1;
677
+ return [(event.clientX - rect.left) * sx, (event.clientY - rect.top) * sy];
678
+ }
679
+ function onPointerMove(event) {
680
+ if (!live.melt || live.reducedMotion || destroyed || contextLost) return;
681
+ if (cssWidth <= 1) resize();
682
+ const [x, y] = localPoint(event);
683
+ const fromX = Number.isNaN(pointerX) ? x : pointerX;
684
+ const fromY = Number.isNaN(pointerY) ? y : pointerY;
685
+ const moved = Math.hypot(x - fromX, y - fromY);
686
+ const amount = event.type === "pointerdown" ? 0.9 : Math.min(1, 0.35 + moved * 0.025);
687
+ depositHeat(grid, fromX, fromY, x, y, MELT_RADIUS, amount);
688
+ pointerX = x;
689
+ pointerY = y;
690
+ warm = true;
691
+ heatDirty = true;
692
+ maskDirty = true;
693
+ wake();
694
+ }
695
+ function onPointerLeave() {
696
+ pointerX = Number.NaN;
697
+ pointerY = Number.NaN;
698
+ }
699
+ function onVisibility() {
700
+ pageVisible = !document.hidden;
701
+ wake();
702
+ }
703
+ function onContextLost(event) {
704
+ event.preventDefault();
705
+ contextLost = true;
706
+ resources = null;
707
+ if (frame !== 0) cancelAnimationFrame(frame);
708
+ frame = 0;
709
+ }
710
+ function onContextRestored() {
711
+ if (destroyed) return;
712
+ resources = setupGl(context);
713
+ if (!resources) return;
714
+ contextLost = false;
715
+ heatDirty = true;
716
+ wake();
717
+ }
718
+ root.addEventListener("pointermove", onPointerMove);
719
+ root.addEventListener("pointerdown", onPointerMove);
720
+ root.addEventListener("pointerleave", onPointerLeave);
721
+ root.addEventListener("pointercancel", onPointerLeave);
722
+ canvas.addEventListener("webglcontextlost", onContextLost, false);
723
+ canvas.addEventListener("webglcontextrestored", onContextRestored, false);
724
+ if (typeof document !== "undefined") {
725
+ document.addEventListener("visibilitychange", onVisibility);
726
+ }
727
+ let resizeObserver = null;
728
+ if (typeof ResizeObserver !== "undefined") {
729
+ resizeObserver = new ResizeObserver(() => {
730
+ maskDirty = true;
731
+ wake();
732
+ });
733
+ resizeObserver.observe(canvas);
734
+ }
735
+ let intersectionObserver = null;
736
+ if (typeof IntersectionObserver !== "undefined") {
737
+ intersectionObserver = new IntersectionObserver((entries) => {
738
+ for (const entry of entries) inView = entry.isIntersecting;
739
+ wake();
740
+ });
741
+ intersectionObserver.observe(canvas);
742
+ }
743
+ wake();
744
+ return {
745
+ setOptions(next) {
746
+ if (destroyed) return;
747
+ if (next.coverage !== void 0) live.coverage = next.coverage;
748
+ if (next.growth !== void 0) live.growth = next.growth;
749
+ if (next.melt !== void 0) live.melt = next.melt;
750
+ if (next.refreeze !== void 0) live.refreeze = next.refreeze;
751
+ if (next.tint !== void 0) live.tint = next.tint;
752
+ if (next.sparkle !== void 0) live.sparkle = next.sparkle;
753
+ if (next.reducedMotion !== void 0) {
754
+ live.reducedMotion = next.reducedMotion;
755
+ if (next.reducedMotion) {
756
+ grid.data.fill(0);
757
+ warm = false;
758
+ heatDirty = true;
759
+ }
760
+ }
761
+ maskDirty = true;
762
+ if (frame === 0) wake();
763
+ },
764
+ getState() {
765
+ return { grown: grown(), warm };
766
+ },
767
+ destroy() {
768
+ if (destroyed) return;
769
+ destroyed = true;
770
+ if (frame !== 0) cancelAnimationFrame(frame);
771
+ frame = 0;
772
+ root.removeEventListener("pointermove", onPointerMove);
773
+ root.removeEventListener("pointerdown", onPointerMove);
774
+ root.removeEventListener("pointerleave", onPointerLeave);
775
+ root.removeEventListener("pointercancel", onPointerLeave);
776
+ canvas.removeEventListener("webglcontextlost", onContextLost, false);
777
+ canvas.removeEventListener("webglcontextrestored", onContextRestored, false);
778
+ if (typeof document !== "undefined") {
779
+ document.removeEventListener("visibilitychange", onVisibility);
780
+ }
781
+ resizeObserver?.disconnect();
782
+ intersectionObserver?.disconnect();
783
+ blurLayer?.style.removeProperty("--fancy-frost-mask");
784
+ maskCanvas = null;
785
+ maskContext = null;
786
+ if (resources) {
787
+ context.deleteTexture(resources.texture);
788
+ context.deleteBuffer(resources.buffer);
789
+ context.deleteProgram(resources.program);
790
+ resources = null;
791
+ }
792
+ if (releaseContext) context.getExtension("WEBGL_lose_context")?.loseContext();
793
+ }
794
+ };
795
+ }
796
+ export {
797
+ FRAGMENT_SHADER,
798
+ FROST_GLASS_DEFAULTS,
799
+ HEAT_CELL,
800
+ HEAT_MAX_CELLS,
801
+ MASK_INTERVAL,
802
+ MAX_PIXEL_RATIO,
803
+ MAX_STEP,
804
+ MELT_RADIUS,
805
+ SPARKLE_FPS,
806
+ VERTEX_SHADER,
807
+ blurLayerDeclarations,
808
+ clampCoverage,
809
+ coolHeat,
810
+ createFrostGlass,
811
+ createHeatGrid,
812
+ depositHeat,
813
+ fallbackBackground,
814
+ fallbackMask,
815
+ frostAmount,
816
+ growthProgress,
817
+ mulberry32,
818
+ parseHexColor,
819
+ valueNoise
820
+ };