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,483 @@
1
+ const SNOWFALL_DEFAULTS = {
2
+ density: 45,
3
+ speed: 1,
4
+ wind: 0.15,
5
+ depth: 0.8,
6
+ size: 1,
7
+ color: "#f4f7ff",
8
+ glow: 0.5,
9
+ blend: "auto",
10
+ seed: 1
11
+ };
12
+ const MAX_FLAKES = 1600;
13
+ const MAX_PIXEL_RATIO = 2;
14
+ const MAX_STEP = 1 / 20;
15
+ const WIND_SPEED = 70;
16
+ const FLOATS_PER_FLAKE = 8;
17
+ function mulberry32(seed) {
18
+ let a = Math.floor(seed) >>> 0;
19
+ return () => {
20
+ a = a + 1831565813 >>> 0;
21
+ let t = a;
22
+ t = Math.imul(t ^ t >>> 15, t | 1);
23
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
24
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
25
+ };
26
+ }
27
+ function parseHexColor(value, fallback) {
28
+ if (!value) return [fallback[0], fallback[1], fallback[2]];
29
+ const hex = value.trim().replace(/^#/, "");
30
+ const full = hex.length === 3 ? hex.split("").map((c) => c + c).join("") : hex;
31
+ if (!/^[0-9a-fA-F]{6}$/.test(full)) return [fallback[0], fallback[1], fallback[2]];
32
+ const n = Number.parseInt(full, 16);
33
+ return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];
34
+ }
35
+ function resolveBlend(blend, rgb) {
36
+ if (blend === "glow" || blend === "normal") return blend;
37
+ const luma = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
38
+ return luma >= 0.5 ? "glow" : "normal";
39
+ }
40
+ function flakeCount(density, width, height) {
41
+ if (!Number.isFinite(density) || density <= 0) return 0;
42
+ const area = Math.max(0, width) * Math.max(0, height);
43
+ return Math.min(MAX_FLAKES, Math.round(density * area / 1e5));
44
+ }
45
+ function buildFlakes(seed) {
46
+ const random = mulberry32(seed);
47
+ const ranks = Array.from({ length: MAX_FLAKES }, (_, i) => i);
48
+ for (let i = ranks.length - 1; i > 0; i--) {
49
+ const j = Math.floor(random() * (i + 1));
50
+ const swap = ranks[i];
51
+ ranks[i] = ranks[j];
52
+ ranks[j] = swap;
53
+ }
54
+ const flakes = [];
55
+ for (let i = 0; i < MAX_FLAKES; i++) {
56
+ const depth = Math.pow(random(), 2.4);
57
+ flakes.push([
58
+ random(),
59
+ random(),
60
+ depth,
61
+ ranks[i],
62
+ random(),
63
+ 0.35 + random() * 0.9,
64
+ 0.3 + random() * 0.7,
65
+ 0.6 + random() * 2.2
66
+ ]);
67
+ }
68
+ flakes.sort((a, b) => a[2] - b[2]);
69
+ const data = new Float32Array(MAX_FLAKES * FLOATS_PER_FLAKE);
70
+ flakes.forEach((flake, i) => data.set(flake, i * FLOATS_PER_FLAKE));
71
+ return data;
72
+ }
73
+ function fallbackBackground(color) {
74
+ const dot = (x, y, r) => `radial-gradient(circle at ${x}% ${y}%, ${color} 0, transparent ${r}px)`;
75
+ return [
76
+ dot(12, 18, 2),
77
+ dot(31, 64, 3),
78
+ dot(47, 29, 1.5),
79
+ dot(63, 81, 2.5),
80
+ dot(78, 42, 2),
81
+ dot(91, 12, 1.5),
82
+ dot(22, 88, 1.5),
83
+ dot(55, 55, 4)
84
+ ].join(", ");
85
+ }
86
+ const VERTEX_SHADER = `
87
+ precision highp float;
88
+
89
+ attribute vec4 aPlace;
90
+ attribute vec4 aTraits;
91
+
92
+ uniform vec2 uView;
93
+ uniform float uPixelRatio;
94
+ uniform float uMaxPoint;
95
+ uniform float uTime;
96
+ uniform float uDrift;
97
+ uniform float uGust;
98
+ uniform float uCount;
99
+ uniform float uDepth;
100
+ uniform float uSize;
101
+ uniform float uGlow;
102
+
103
+ varying float vAlpha;
104
+ varying float vBlur;
105
+ varying float vCore;
106
+
107
+ const float TAU = 6.2831853;
108
+
109
+ // Gusts as a displacement, never a speed, so the wind can never snap: three
110
+ // slow incommensurate waves, felt a moment later lower down the screen.
111
+ float gust(float t) {
112
+ return sin(t * 0.13) * 1.3 + sin(t * 0.29 + 1.7) * 0.7 + sin(t * 0.071 + 4.1) * 1.6;
113
+ }
114
+
115
+ void main() {
116
+ if (aPlace.w >= uCount) {
117
+ // Not part of this density: park it outside the clip volume.
118
+ gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
119
+ gl_PointSize = 1.0;
120
+ vAlpha = 0.0;
121
+ vBlur = 0.0;
122
+ vCore = 1.0;
123
+ return;
124
+ }
125
+ float z = mix(0.42, aPlace.z, uDepth);
126
+ float near = pow(z, 3.0);
127
+ float phase = aTraits.x * TAU;
128
+ float jitter = 0.7 + 0.6 * fract(aTraits.x * 7.13);
129
+
130
+ float core = mix(1.7, 58.0, near) * uSize * jitter;
131
+ // Out of focus from a little past the middle; the far field stays sharp.
132
+ float blur = smoothstep(0.4, 0.92, z);
133
+ // The halo only belongs to sharp flakes; a disc is already soft.
134
+ float pad = 1.0 + uGlow * 4.0 * (1.0 - blur);
135
+ float sprite = core * pad;
136
+
137
+ // The field wraps with a margin wider than the largest sprite, so a flake
138
+ // leaves the canvas entirely before it comes back on the other side.
139
+ float margin = 24.0 + 44.0 * uSize;
140
+ vec2 field = uView + 2.0 * margin;
141
+
142
+ float fall = mix(13.0, 64.0, z) * (0.85 + 0.3 * fract(aTraits.x * 3.7));
143
+ float y = mod(aPlace.y * field.y + uTime * fall, field.y) - margin;
144
+
145
+ float parallax = mix(0.35, 1.35, z);
146
+ float sway = sin(uTime * aTraits.y + phase) * mix(3.0, 26.0, near) * aTraits.z;
147
+ float wind = (uDrift + gust(uTime - y / 500.0) * uGust) * parallax;
148
+ float x = mod(aPlace.x * field.x + wind + sway, field.x) - margin;
149
+
150
+ gl_Position = vec4(x / uView.x * 2.0 - 1.0, 1.0 - y / uView.y * 2.0, 0.0, 1.0);
151
+ // The hardware caps point size; the shape is drawn in sprite units, so a
152
+ // capped sprite only shrinks, it never clips.
153
+ gl_PointSize = min(sprite * uPixelRatio, uMaxPoint);
154
+
155
+ float twinkle = 1.0 + (1.0 - blur) * 0.32 * sin(uTime * aTraits.w * 2.0 + phase * 3.0);
156
+ // Light per pixel falls as the disc spreads; the far field fades into the distance.
157
+ float bright = mix(0.95, 0.15, blur) * mix(0.5, 1.0, smoothstep(0.0, 0.3, z));
158
+ vAlpha = bright * twinkle;
159
+ vBlur = blur;
160
+ vCore = 1.0 / pad;
161
+ }
162
+ `;
163
+ const FRAGMENT_SHADER = `
164
+ precision highp float;
165
+
166
+ uniform vec3 uColor;
167
+ uniform float uGlow;
168
+
169
+ varying float vAlpha;
170
+ varying float vBlur;
171
+ varying float vCore;
172
+
173
+ void main() {
174
+ vec2 p = gl_PointCoord * 2.0 - 1.0;
175
+ float r = length(p);
176
+ if (r > 1.0) discard;
177
+ float rc = r / vCore;
178
+
179
+ // In focus a small bright dot; drifting out of focus it widens into a soft
180
+ // blob before it settles into a disc.
181
+ float sharp = exp(-rc * rc * mix(3.0, 1.4, smoothstep(0.0, 0.5, vBlur)));
182
+ // Out of focus: a flat disc, soft at the edge, its rim a touch brighter.
183
+ float edge = mix(0.4, 0.2, vBlur);
184
+ float disc = 1.0 - smoothstep(1.0 - edge, 1.0, rc);
185
+ float rim = smoothstep(0.55, 0.9, rc) * disc;
186
+ float bokeh = disc * (0.78 + 0.32 * rim);
187
+ float shape = mix(sharp, bokeh, smoothstep(0.35, 0.85, vBlur));
188
+
189
+ float halo = exp(-r * r * 5.0) * (1.0 - smoothstep(0.7, 1.0, r)) * uGlow * 0.32 * (1.0 - vBlur);
190
+
191
+ float a = clamp((shape + halo) * vAlpha, 0.0, 1.0);
192
+ gl_FragColor = vec4(uColor * a, a);
193
+ }
194
+ `;
195
+ const UNIFORMS = [
196
+ "uView",
197
+ "uPixelRatio",
198
+ "uMaxPoint",
199
+ "uTime",
200
+ "uDrift",
201
+ "uGust",
202
+ "uCount",
203
+ "uDepth",
204
+ "uSize",
205
+ "uGlow",
206
+ "uColor"
207
+ ];
208
+ function compile(gl, type, source) {
209
+ const shader = gl.createShader(type);
210
+ if (!shader) return null;
211
+ gl.shaderSource(shader, source);
212
+ gl.compileShader(shader);
213
+ if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
214
+ gl.deleteShader(shader);
215
+ return null;
216
+ }
217
+ return shader;
218
+ }
219
+ function setup(gl, seed) {
220
+ const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
221
+ const fragment = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
222
+ const program = gl.createProgram();
223
+ if (!vertex || !fragment || !program) {
224
+ if (vertex) gl.deleteShader(vertex);
225
+ if (fragment) gl.deleteShader(fragment);
226
+ if (program) gl.deleteProgram(program);
227
+ return null;
228
+ }
229
+ gl.attachShader(program, vertex);
230
+ gl.attachShader(program, fragment);
231
+ gl.bindAttribLocation(program, 0, "aPlace");
232
+ gl.bindAttribLocation(program, 1, "aTraits");
233
+ gl.linkProgram(program);
234
+ gl.deleteShader(vertex);
235
+ gl.deleteShader(fragment);
236
+ if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
237
+ gl.deleteProgram(program);
238
+ return null;
239
+ }
240
+ gl.useProgram(program);
241
+ const buffer = gl.createBuffer();
242
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
243
+ gl.bufferData(gl.ARRAY_BUFFER, buildFlakes(seed), gl.STATIC_DRAW);
244
+ const stride = FLOATS_PER_FLAKE * 4;
245
+ gl.enableVertexAttribArray(0);
246
+ gl.vertexAttribPointer(0, 4, gl.FLOAT, false, stride, 0);
247
+ gl.enableVertexAttribArray(1);
248
+ gl.vertexAttribPointer(1, 4, gl.FLOAT, false, stride, 16);
249
+ const uniforms = {};
250
+ for (const name of UNIFORMS) uniforms[name] = gl.getUniformLocation(program, name);
251
+ let maxPoint = 64;
252
+ const range = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
253
+ if (range && typeof range[1] === "number" && range[1] >= 1) maxPoint = range[1];
254
+ gl.disable(gl.DEPTH_TEST);
255
+ gl.enable(gl.BLEND);
256
+ gl.clearColor(0, 0, 0, 0);
257
+ return { program, buffer, uniforms, maxPoint };
258
+ }
259
+ function createSnowfall(elements, options = {}) {
260
+ const { canvas } = elements;
261
+ const releaseContext = options.releaseContext ?? true;
262
+ let gl = null;
263
+ try {
264
+ gl = canvas.getContext("webgl", {
265
+ alpha: true,
266
+ premultipliedAlpha: true,
267
+ antialias: false,
268
+ depth: false,
269
+ powerPreference: "low-power"
270
+ });
271
+ } catch {
272
+ gl = null;
273
+ }
274
+ if (!gl) return null;
275
+ const context = gl;
276
+ const live = {
277
+ density: options.density ?? SNOWFALL_DEFAULTS.density,
278
+ speed: options.speed ?? SNOWFALL_DEFAULTS.speed,
279
+ wind: options.wind ?? SNOWFALL_DEFAULTS.wind,
280
+ depth: options.depth ?? SNOWFALL_DEFAULTS.depth,
281
+ size: options.size ?? SNOWFALL_DEFAULTS.size,
282
+ color: options.color ?? SNOWFALL_DEFAULTS.color,
283
+ glow: options.glow ?? SNOWFALL_DEFAULTS.glow,
284
+ blend: options.blend ?? SNOWFALL_DEFAULTS.blend,
285
+ seed: options.seed ?? SNOWFALL_DEFAULTS.seed,
286
+ paused: options.paused ?? false,
287
+ reducedMotion: options.reducedMotion ?? false
288
+ };
289
+ let gpu = setup(context, live.seed);
290
+ if (!gpu) return null;
291
+ let destroyed = false;
292
+ let contextLost = false;
293
+ let frame = 0;
294
+ let last = 0;
295
+ let inView = true;
296
+ let pageVisible = typeof document === "undefined" || !document.hidden;
297
+ let time = 0;
298
+ let drift = 0;
299
+ function resize() {
300
+ const ratio = Math.min(
301
+ typeof window !== "undefined" && window.devicePixelRatio || 1,
302
+ MAX_PIXEL_RATIO
303
+ );
304
+ const width = Math.max(1, Math.round(canvas.clientWidth * ratio));
305
+ const height = Math.max(1, Math.round(canvas.clientHeight * ratio));
306
+ if (canvas.width === width && canvas.height === height) return;
307
+ canvas.width = width;
308
+ canvas.height = height;
309
+ }
310
+ function clamp01(value) {
311
+ return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
312
+ }
313
+ let pageBlend = null;
314
+ function draw() {
315
+ if (destroyed || contextLost || !gpu) return;
316
+ resize();
317
+ const u = gpu.uniforms;
318
+ const cssWidth = Math.max(1, canvas.clientWidth);
319
+ const cssHeight = Math.max(1, canvas.clientHeight);
320
+ const rgb = parseHexColor(live.color, [0.957, 0.969, 1]);
321
+ const wind = Math.max(-1, Math.min(1, Number.isFinite(live.wind) ? live.wind : 0));
322
+ const mode = resolveBlend(live.blend, rgb);
323
+ if (mode !== pageBlend) {
324
+ pageBlend = mode;
325
+ canvas.style.mixBlendMode = mode === "glow" ? "screen" : "";
326
+ }
327
+ if (mode === "glow") {
328
+ context.blendFuncSeparate(
329
+ context.ONE,
330
+ context.ONE_MINUS_SRC_COLOR,
331
+ context.ONE,
332
+ context.ONE_MINUS_SRC_ALPHA
333
+ );
334
+ } else {
335
+ context.blendFunc(context.ONE, context.ONE_MINUS_SRC_ALPHA);
336
+ }
337
+ context.viewport(0, 0, canvas.width, canvas.height);
338
+ context.clear(context.COLOR_BUFFER_BIT);
339
+ context.uniform2f(u.uView, cssWidth, cssHeight);
340
+ context.uniform1f(u.uPixelRatio, canvas.width / cssWidth);
341
+ context.uniform1f(u.uMaxPoint, gpu.maxPoint);
342
+ context.uniform1f(u.uTime, time);
343
+ context.uniform1f(u.uDrift, drift);
344
+ context.uniform1f(u.uGust, 14 + 26 * Math.abs(wind));
345
+ context.uniform1f(u.uCount, flakeCount(live.density, cssWidth, cssHeight));
346
+ context.uniform1f(u.uDepth, clamp01(live.depth));
347
+ context.uniform1f(u.uSize, Math.max(0, Number.isFinite(live.size) ? live.size : 1));
348
+ context.uniform1f(u.uGlow, clamp01(live.glow));
349
+ context.uniform3f(u.uColor, rgb[0], rgb[1], rgb[2]);
350
+ context.drawArrays(context.POINTS, 0, MAX_FLAKES);
351
+ }
352
+ function moving() {
353
+ return !live.paused && !live.reducedMotion;
354
+ }
355
+ function shouldRun() {
356
+ return !destroyed && !contextLost && inView && pageVisible && moving();
357
+ }
358
+ function tick(now) {
359
+ frame = 0;
360
+ if (destroyed) return;
361
+ const dt = last === 0 ? 0 : Math.min(Math.max((now - last) / 1e3, 0), MAX_STEP);
362
+ last = now;
363
+ if (moving()) {
364
+ const rate = Number.isFinite(live.speed) ? Math.max(0, live.speed) : 0;
365
+ const wind = Math.max(-1, Math.min(1, Number.isFinite(live.wind) ? live.wind : 0));
366
+ time += dt * rate;
367
+ drift += dt * rate * wind * WIND_SPEED;
368
+ }
369
+ draw();
370
+ if (shouldRun()) frame = requestAnimationFrame(tick);
371
+ else last = 0;
372
+ }
373
+ function wake() {
374
+ if (destroyed || frame !== 0) return;
375
+ if (shouldRun()) {
376
+ last = 0;
377
+ frame = requestAnimationFrame(tick);
378
+ } else {
379
+ draw();
380
+ }
381
+ }
382
+ function releaseGpu() {
383
+ if (!gpu) return;
384
+ context.deleteBuffer(gpu.buffer);
385
+ context.deleteProgram(gpu.program);
386
+ gpu = null;
387
+ }
388
+ function onVisibility() {
389
+ pageVisible = !document.hidden;
390
+ wake();
391
+ }
392
+ function onContextLost(event) {
393
+ event.preventDefault();
394
+ contextLost = true;
395
+ if (frame !== 0) cancelAnimationFrame(frame);
396
+ frame = 0;
397
+ gpu = null;
398
+ }
399
+ function onContextRestored() {
400
+ if (destroyed) return;
401
+ contextLost = false;
402
+ gpu = setup(context, live.seed);
403
+ if (gpu) wake();
404
+ }
405
+ canvas.addEventListener("webglcontextlost", onContextLost, false);
406
+ canvas.addEventListener("webglcontextrestored", onContextRestored, false);
407
+ if (typeof document !== "undefined") {
408
+ document.addEventListener("visibilitychange", onVisibility);
409
+ }
410
+ let resizeObserver = null;
411
+ if (typeof ResizeObserver !== "undefined") {
412
+ resizeObserver = new ResizeObserver(() => wake());
413
+ resizeObserver.observe(canvas);
414
+ }
415
+ let intersectionObserver = null;
416
+ if (typeof IntersectionObserver !== "undefined") {
417
+ intersectionObserver = new IntersectionObserver((entries) => {
418
+ for (const entry of entries) inView = entry.isIntersecting;
419
+ wake();
420
+ });
421
+ intersectionObserver.observe(canvas);
422
+ }
423
+ wake();
424
+ return {
425
+ setOptions(next) {
426
+ if (destroyed) return;
427
+ if (next.density !== void 0) live.density = next.density;
428
+ if (next.speed !== void 0) live.speed = next.speed;
429
+ if (next.wind !== void 0) live.wind = next.wind;
430
+ if (next.depth !== void 0) live.depth = next.depth;
431
+ if (next.size !== void 0) live.size = next.size;
432
+ if (next.color !== void 0) live.color = next.color;
433
+ if (next.glow !== void 0) live.glow = next.glow;
434
+ if (next.blend !== void 0) live.blend = next.blend;
435
+ if (next.paused !== void 0) live.paused = next.paused;
436
+ if (next.reducedMotion !== void 0) live.reducedMotion = next.reducedMotion;
437
+ if (next.seed !== void 0 && next.seed !== live.seed) {
438
+ live.seed = next.seed;
439
+ if (gpu && !contextLost) {
440
+ context.bindBuffer(context.ARRAY_BUFFER, gpu.buffer);
441
+ context.bufferData(context.ARRAY_BUFFER, buildFlakes(live.seed), context.STATIC_DRAW);
442
+ }
443
+ }
444
+ if (frame === 0) wake();
445
+ },
446
+ getTime() {
447
+ return time;
448
+ },
449
+ destroy() {
450
+ if (destroyed) return;
451
+ destroyed = true;
452
+ if (frame !== 0) cancelAnimationFrame(frame);
453
+ frame = 0;
454
+ canvas.removeEventListener("webglcontextlost", onContextLost, false);
455
+ canvas.removeEventListener("webglcontextrestored", onContextRestored, false);
456
+ if (typeof document !== "undefined") {
457
+ document.removeEventListener("visibilitychange", onVisibility);
458
+ }
459
+ resizeObserver?.disconnect();
460
+ intersectionObserver?.disconnect();
461
+ canvas.style.mixBlendMode = "";
462
+ if (!contextLost) releaseGpu();
463
+ if (releaseContext) context.getExtension("WEBGL_lose_context")?.loseContext();
464
+ }
465
+ };
466
+ }
467
+ export {
468
+ FLOATS_PER_FLAKE,
469
+ FRAGMENT_SHADER,
470
+ MAX_FLAKES,
471
+ MAX_PIXEL_RATIO,
472
+ MAX_STEP,
473
+ SNOWFALL_DEFAULTS,
474
+ VERTEX_SHADER,
475
+ WIND_SPEED,
476
+ buildFlakes,
477
+ createSnowfall,
478
+ fallbackBackground,
479
+ flakeCount,
480
+ mulberry32,
481
+ parseHexColor,
482
+ resolveBlend
483
+ };
@@ -0,0 +1,35 @@
1
+ import type { HTMLAttributes } from "vue";
2
+ import { type StringLightsPattern } from "./string-lights-core.js";
3
+ export type { StringLightsPattern };
4
+ /**
5
+ * StringLights - a string of glowing bulbs hanging on a sagging wire.
6
+ *
7
+ * The geometry and timing live in `string-lights-core.ts`, shared with the
8
+ * Svelte and React packages; this file measures the width, renders the bulbs
9
+ * and lets CSS keyframes run the patterns.
10
+ */
11
+ export interface StringLightsProps {
12
+ /** Number of bulbs on the whole string. */
13
+ count?: number;
14
+ /** Number of drapes across the width. 2 adds one anchor in the middle. */
15
+ swags?: number;
16
+ /** Depth of each drape below its two anchors, in px. */
17
+ sag?: number;
18
+ /** Bulb colours, given out in turn along the string. */
19
+ colors?: string[];
20
+ /** How the bulbs light up over time. */
21
+ pattern?: StringLightsPattern;
22
+ /** Speed multiplier for the pattern. 0 holds every bulb lit. */
23
+ speed?: number;
24
+ /** Diameter of the glass, in px. */
25
+ size?: number;
26
+ /** Strength and reach of the light around each bulb, 0 to 1. */
27
+ glow?: number;
28
+ /** Seed for the twinkle pattern. Same seed, same flicker. */
29
+ seed?: number;
30
+ /** Additional CSS classes */
31
+ class?: HTMLAttributes["class"];
32
+ }
33
+ declare const _default: typeof __VLS_export;
34
+ export default _default;
35
+ declare const __VLS_export: import("vue").DefineComponent<StringLightsProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<StringLightsProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -0,0 +1,7 @@
1
+ import _sfc_main from "./StringLights.vue2.js";
2
+ /* empty css */
3
+ import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
4
+ const StringLights = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-12f37b6d"]]);
5
+ export {
6
+ StringLights as default
7
+ };
@@ -0,0 +1,98 @@
1
+ import { defineComponent, useTemplateRef, ref, computed, onMounted, onBeforeUnmount, createElementBlock, openBlock, mergeProps, unref, createElementVNode, Fragment, renderList, normalizeStyle } from "vue";
2
+ import { cn } from "../../utils.js";
3
+ import { useReducedMotion } from "../../internals/motion/use-media-query.js";
4
+ import { STRING_LIGHTS_DEFAULTS, FALLBACK_WIDTH, effectivePattern, stringLightsLayout, createStringLights, haloStyle, bulbStyle } from "./string-lights-core.js";
5
+ const _hoisted_1 = ["data-pattern"];
6
+ const _hoisted_2 = ["viewBox"];
7
+ const _hoisted_3 = ["d"];
8
+ const DEFAULT_COLORS = [...STRING_LIGHTS_DEFAULTS.colors];
9
+ const _sfc_main = /* @__PURE__ */ defineComponent({
10
+ ...{ name: "StringLights", inheritAttrs: false },
11
+ __name: "StringLights",
12
+ props: {
13
+ count: { default: () => STRING_LIGHTS_DEFAULTS.count },
14
+ swags: { default: () => STRING_LIGHTS_DEFAULTS.swags },
15
+ sag: { default: () => STRING_LIGHTS_DEFAULTS.sag },
16
+ colors: { default: () => DEFAULT_COLORS },
17
+ pattern: { default: () => STRING_LIGHTS_DEFAULTS.pattern },
18
+ speed: { default: () => STRING_LIGHTS_DEFAULTS.speed },
19
+ size: { default: () => STRING_LIGHTS_DEFAULTS.size },
20
+ glow: { default: () => STRING_LIGHTS_DEFAULTS.glow },
21
+ seed: { default: () => STRING_LIGHTS_DEFAULTS.seed },
22
+ class: { type: [Boolean, null, String, Object, Array], default: "" }
23
+ },
24
+ setup(__props) {
25
+ const rootRef = useTemplateRef("root");
26
+ const width = ref(FALLBACK_WIDTH);
27
+ const reducedMotion = useReducedMotion();
28
+ const active = computed(() => effectivePattern(__props.pattern, __props.speed, reducedMotion.value));
29
+ const layout = computed(
30
+ () => stringLightsLayout(width.value, {
31
+ count: __props.count,
32
+ swags: __props.swags,
33
+ sag: __props.sag,
34
+ colors: __props.colors,
35
+ pattern: active.value,
36
+ speed: __props.speed,
37
+ size: __props.size,
38
+ glow: __props.glow,
39
+ seed: __props.seed
40
+ })
41
+ );
42
+ const rootStyle = computed(() => ({
43
+ height: `${layout.value.height}px`,
44
+ "--sl-size": `${Math.max(2, Number.isFinite(__props.size) ? __props.size : STRING_LIGHTS_DEFAULTS.size)}px`,
45
+ "--sl-glow": String(Math.max(0, Math.min(1, Number.isFinite(__props.glow) ? __props.glow : 0)))
46
+ }));
47
+ let engine = null;
48
+ onMounted(() => {
49
+ const root = rootRef.value;
50
+ if (!root) return;
51
+ engine = createStringLights({ root }, { onResize: (w) => width.value = w });
52
+ });
53
+ onBeforeUnmount(() => {
54
+ engine?.destroy();
55
+ engine = null;
56
+ });
57
+ return (_ctx, _cache) => {
58
+ return openBlock(), createElementBlock("div", mergeProps({ ref: "root" }, _ctx.$attrs, {
59
+ class: unref(cn)("fancy-string-lights", __props.class),
60
+ style: rootStyle.value,
61
+ "data-pattern": active.value,
62
+ "aria-hidden": "true"
63
+ }), [
64
+ (openBlock(), createElementBlock("svg", {
65
+ class: "fancy-string-lights-wire",
66
+ viewBox: `0 0 ${layout.value.width} ${layout.value.height}`,
67
+ preserveAspectRatio: "none"
68
+ }, [
69
+ createElementVNode("path", {
70
+ d: layout.value.wire
71
+ }, null, 8, _hoisted_3)
72
+ ], 8, _hoisted_2)),
73
+ (openBlock(true), createElementBlock(Fragment, null, renderList(layout.value.bulbs, (bulb, i) => {
74
+ return openBlock(), createElementBlock("span", {
75
+ key: `h${i}`,
76
+ class: "fancy-string-lights-halo",
77
+ style: normalizeStyle(unref(haloStyle)(bulb))
78
+ }, null, 4);
79
+ }), 128)),
80
+ (openBlock(true), createElementBlock(Fragment, null, renderList(layout.value.bulbs, (bulb, i) => {
81
+ return openBlock(), createElementBlock("span", {
82
+ key: `b${i}`,
83
+ class: "fancy-string-lights-bulb",
84
+ style: normalizeStyle(unref(bulbStyle)(bulb))
85
+ }, [..._cache[0] || (_cache[0] = [
86
+ createElementVNode("span", { class: "fancy-string-lights-glass" }, [
87
+ createElementVNode("span", { class: "fancy-string-lights-lit" })
88
+ ], -1),
89
+ createElementVNode("span", { class: "fancy-string-lights-socket" }, null, -1)
90
+ ])], 4);
91
+ }), 128))
92
+ ], 16, _hoisted_1);
93
+ };
94
+ }
95
+ });
96
+ export {
97
+ _sfc_main as default
98
+ };
@@ -0,0 +1,2 @@
1
+ export { default as StringLights } from "./StringLights.vue";
2
+ export type { StringLightsProps, StringLightsPattern } from "./StringLights.vue";