snowies 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.
- package/README.md +35 -25
- package/dist/auto.cjs +180 -80
- package/dist/auto.cjs.map +1 -1
- package/dist/auto.d.cts +1 -1
- package/dist/auto.d.ts +1 -1
- package/dist/auto.js +33 -8
- package/dist/auto.js.map +1 -1
- package/dist/{chunk-FUI4H26T.js → chunk-XZHF76OT.js} +151 -80
- package/dist/chunk-XZHF76OT.js.map +1 -0
- package/dist/index.cjs +148 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -14
- package/dist/index.d.ts +3 -14
- package/dist/index.js +1 -1
- package/dist/snowies.global.js +49 -40
- package/dist/snowies.global.js.map +1 -1
- package/dist/{types-KVWKDlXl.d.cts → types-DE9NRAb4.d.cts} +18 -13
- package/dist/{types-KVWKDlXl.d.ts → types-DE9NRAb4.d.ts} +18 -13
- package/package.json +1 -1
- package/dist/chunk-FUI4H26T.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,66 +1,76 @@
|
|
|
1
1
|
# snowies
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zero-dependency, GPU-optimized Christmas effects package for the web written in pure TypeScript. Works with any stack (HTML, React, Vue, Svelte, Astro, Next.js, Laravel, etc.).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Live playground: https://l2ernestoo.github.io/snowies/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **Luces navideñas fijas arriba**: cable SVG, focos con filamento y halo, balanceo suave, iluminación al pasar el mouse y destello al hacer clic (encapsulado en Shadow DOM).
|
|
9
|
-
- **Snow Burst en botones**: explosión radial de nieve y cristales SVG al hacer clic en botones.
|
|
10
|
-
- **Nieve encima de botones (`buttonSnow`)**: módulo independiente y desactivable con dos estilos orgánicos (`subtle` y `fluffy`) y dos modos: manual por defecto (`data-snowies-snow`) o automático (`mode: 'all'`, respetando `data-snowies-ignore`).
|
|
11
|
-
- **Botón flotante ON/OFF discreto y personalizable**: encapsulado en Shadow DOM, modo solo icono por defecto (`variant: 'icon' | 'pill'`), tamaños, temas, icono SVG propio, estilos custom y persistencia en `localStorage`.
|
|
12
|
-
- **Presets y programación por fechas**: activa Navidad automáticamente entre fechas (ej. `12-01` a `01-06`).
|
|
13
|
-
- **Multi-idioma (`es` / `en`)**: detección automática (`locale: 'auto'`) según `<html lang>` o idioma del navegador, o explícito (`'es'` | `'en'`).
|
|
14
|
-
- **Accesible**: respeta `prefers-reduced-motion: reduce`.
|
|
7
|
+
## Features
|
|
15
8
|
|
|
16
|
-
|
|
9
|
+
- **Canvas 2D Snowfall**: 3 depth layers, pre-rendered sprites, automatic pause on hidden tabs (`visibilitychange`), interactive pointer breeze (`mouseWind`), and automatic light/dark background detection (`contrasting: 'auto'`).
|
|
10
|
+
- **Animated Fixed Top Lights**: SVG wire, filament bulbs with halos, neighbor hover glow, click celebration burst, and 3 animation modes (`twinkle`, `wave`, `steady`) isolated in Shadow DOM.
|
|
11
|
+
- **Button Snow Burst**: Radial snow + SVG crystal burst on button clicks via event delegation.
|
|
12
|
+
- **Button Snow (`buttonSnow`)**: Independent decorative organic snow resting on top of buttons with 2 styles (`subtle` and `fluffy`) and 2 modes (`manual` via `data-snowies-snow` by default, or `all` with `data-snowies-ignore` opt-out).
|
|
13
|
+
- **Discreet & Customizable Floating Toggle**: Shadow DOM button (`variant: 'icon' | 'pill'`, `position`, `size`, `theme`, custom SVG `icon`, custom labels, `style` overrides, and `localStorage` persistence).
|
|
14
|
+
- **Presets & Date Scheduling**: Built-in presets (`classic`, `festive`, `minimal`, `light`, `lights-only`, `snow-only`) and optional active date window (`schedule: { from: '12-01', to: '01-06' }`).
|
|
15
|
+
- **Accessible**: Respects `prefers-reduced-motion: reduce`.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
17
18
|
|
|
18
19
|
```bash
|
|
19
20
|
npm install snowies
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
##
|
|
23
|
+
## Quick Start (ESM / TypeScript)
|
|
23
24
|
|
|
24
25
|
```ts
|
|
25
26
|
import { createSnowies } from 'snowies';
|
|
26
27
|
|
|
27
28
|
const snowies = createSnowies({
|
|
28
|
-
preset: 'classic',
|
|
29
|
-
|
|
29
|
+
preset: 'classic',
|
|
30
|
+
snow: { contrasting: 'auto', mouseWind: true },
|
|
31
|
+
lights: { animation: 'wave' },
|
|
32
|
+
buttonSnow: { enabled: true, mode: 'manual', style: 'subtle' },
|
|
30
33
|
toggleButton: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
position: 'bottom-right',
|
|
35
|
+
variant: 'icon',
|
|
36
|
+
// Override any built-in text in your own language:
|
|
37
|
+
textOn: 'Holiday',
|
|
38
|
+
textOff: 'Paused',
|
|
39
|
+
labelOn: 'Disable Christmas effects',
|
|
40
|
+
labelOff: 'Enable Christmas effects',
|
|
34
41
|
},
|
|
42
|
+
schedule: { from: '12-01', to: '01-06' },
|
|
35
43
|
});
|
|
36
44
|
|
|
37
|
-
//
|
|
45
|
+
// Programmatic control
|
|
38
46
|
snowies.toggle();
|
|
39
|
-
snowies.update({ snow: { density: 'heavy'
|
|
47
|
+
snowies.update({ snow: { density: 'heavy' } });
|
|
40
48
|
snowies.destroy();
|
|
41
49
|
```
|
|
42
50
|
|
|
43
|
-
##
|
|
51
|
+
## Direct CDN Usage
|
|
44
52
|
|
|
45
53
|
```html
|
|
46
54
|
<script
|
|
47
55
|
src="https://unpkg.com/snowies"
|
|
48
56
|
data-preset="classic"
|
|
57
|
+
data-lights-animation="wave"
|
|
58
|
+
data-toggle-position="bottom-left"
|
|
49
59
|
data-from="12-01"
|
|
50
60
|
data-to="01-06"
|
|
51
61
|
defer
|
|
52
62
|
></script>
|
|
53
63
|
```
|
|
54
64
|
|
|
55
|
-
##
|
|
65
|
+
## Local Development
|
|
56
66
|
|
|
57
67
|
```bash
|
|
58
68
|
npm install
|
|
59
|
-
npm run dev #
|
|
60
|
-
npm run test #
|
|
61
|
-
npm run build #
|
|
69
|
+
npm run dev # Start interactive playground
|
|
70
|
+
npm run test # Run unit tests
|
|
71
|
+
npm run build # Build dist/ (ESM, CJS, .d.ts, and CDN global)
|
|
62
72
|
```
|
|
63
73
|
|
|
64
|
-
##
|
|
74
|
+
## License
|
|
65
75
|
|
|
66
76
|
MIT
|
package/dist/auto.cjs
CHANGED
|
@@ -313,7 +313,10 @@ function createLights(options) {
|
|
|
313
313
|
const colors = resolvePalette(options.palette);
|
|
314
314
|
const bulbCount = Math.max(6, Math.min(64, Math.round(options.bulbs)));
|
|
315
315
|
const mobileCutoff = Math.max(10, Math.round(bulbCount * 0.45));
|
|
316
|
-
const bg = BACKDROP_STYLES[options.backdrop] ?? BACKDROP_STYLES.
|
|
316
|
+
const bg = BACKDROP_STYLES[options.backdrop] ?? BACKDROP_STYLES.transparent;
|
|
317
|
+
const animMode = options.animation ?? "twinkle";
|
|
318
|
+
const glassAnimCss = animMode === "steady" ? "opacity: 0.96;" : animMode === "wave" ? "animation: glass-wave 2.4s ease-in-out var(--wave-delay) infinite;" : "animation: glass-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;";
|
|
319
|
+
const haloAnimCss = animMode === "steady" ? "opacity: 0.28;" : animMode === "wave" ? "animation: halo-wave 2.4s ease-in-out var(--wave-delay) infinite;" : "animation: halo-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;";
|
|
317
320
|
const style = document.createElement("style");
|
|
318
321
|
style.textContent = `
|
|
319
322
|
:host { display: block; line-height: 0; }
|
|
@@ -329,7 +332,8 @@ function createLights(options) {
|
|
|
329
332
|
margin: 0;
|
|
330
333
|
border: 0;
|
|
331
334
|
box-sizing: border-box;
|
|
332
|
-
overflow:
|
|
335
|
+
overflow-x: clip;
|
|
336
|
+
overflow-y: visible;
|
|
333
337
|
background: ${bg};
|
|
334
338
|
cursor: ${options.interactive ? "pointer" : "default"};
|
|
335
339
|
-webkit-tap-highlight-color: transparent;
|
|
@@ -386,7 +390,7 @@ function createLights(options) {
|
|
|
386
390
|
radial-gradient(ellipse at 50% 35%, var(--bulb-core) 5%, var(--bulb-color) 80%);
|
|
387
391
|
box-shadow: 0 0 5px var(--bulb-color), 0 0 12px var(--bulb-color);
|
|
388
392
|
will-change: opacity, transform;
|
|
389
|
-
|
|
393
|
+
${glassAnimCss}
|
|
390
394
|
transition: transform 0.25s ease, opacity 0.25s ease;
|
|
391
395
|
}
|
|
392
396
|
.filament {
|
|
@@ -399,16 +403,16 @@ function createLights(options) {
|
|
|
399
403
|
.halo {
|
|
400
404
|
position: absolute;
|
|
401
405
|
z-index: 0;
|
|
402
|
-
top: 2px;
|
|
406
|
+
top: -2px;
|
|
403
407
|
left: 50%;
|
|
404
|
-
width:
|
|
405
|
-
height:
|
|
408
|
+
width: 58px;
|
|
409
|
+
height: 58px;
|
|
406
410
|
transform: translateX(-50%);
|
|
407
|
-
background: radial-gradient(ellipse
|
|
411
|
+
background: radial-gradient(ellipse at 50% 44%, var(--bulb-color) 0%, transparent 66%);
|
|
408
412
|
opacity: 0.2;
|
|
409
413
|
pointer-events: none;
|
|
410
414
|
will-change: opacity;
|
|
411
|
-
|
|
415
|
+
${haloAnimCss}
|
|
412
416
|
transition: opacity 0.25s ease;
|
|
413
417
|
}
|
|
414
418
|
.lamp.is-near .glass,
|
|
@@ -434,6 +438,14 @@ function createLights(options) {
|
|
|
434
438
|
from { opacity: 0.12; }
|
|
435
439
|
to { opacity: 0.34; }
|
|
436
440
|
}
|
|
441
|
+
@keyframes glass-wave {
|
|
442
|
+
0%, 58%, 100% { opacity: 0.58; transform: scale(0.97); }
|
|
443
|
+
22% { opacity: 1; transform: scale(1.1); }
|
|
444
|
+
}
|
|
445
|
+
@keyframes halo-wave {
|
|
446
|
+
0%, 58%, 100% { opacity: 0.08; }
|
|
447
|
+
22% { opacity: 0.52; }
|
|
448
|
+
}
|
|
437
449
|
@media (max-width: 640px) {
|
|
438
450
|
.lamp:nth-of-type(n + ${mobileCutoff + 1}) { display: none; }
|
|
439
451
|
}
|
|
@@ -443,9 +455,10 @@ function createLights(options) {
|
|
|
443
455
|
`;
|
|
444
456
|
const strip = document.createElement(options.interactive ? "button" : "div");
|
|
445
457
|
strip.className = "strip";
|
|
458
|
+
strip.setAttribute("data-animation", animMode);
|
|
446
459
|
if (options.interactive) {
|
|
447
460
|
strip.setAttribute("type", "button");
|
|
448
|
-
strip.setAttribute("aria-label", options.ariaLabel
|
|
461
|
+
strip.setAttribute("aria-label", options.ariaLabel || "Illuminate Christmas lights");
|
|
449
462
|
} else {
|
|
450
463
|
strip.setAttribute("aria-hidden", "true");
|
|
451
464
|
}
|
|
@@ -464,6 +477,7 @@ function createLights(options) {
|
|
|
464
477
|
lamp.style.setProperty("--bulb-color", c.color);
|
|
465
478
|
lamp.style.setProperty("--bulb-core", c.core);
|
|
466
479
|
lamp.style.setProperty("--bulb-delay", `${i * -0.43}s`);
|
|
480
|
+
lamp.style.setProperty("--wave-delay", `${(i * -0.1).toFixed(2)}s`);
|
|
467
481
|
lamp.style.setProperty("--bulb-duration", `${3.4 + i % 5 * 0.35}s`);
|
|
468
482
|
lamp.style.setProperty("--bulb-cord", `${4 + i % 3 * 2}px`);
|
|
469
483
|
lamp.style.setProperty("--bulb-tilt", `${i % 2 ? 5 : -5}deg`);
|
|
@@ -546,6 +560,37 @@ function createPrng(initialSeed = 202611) {
|
|
|
546
560
|
return seed / 4294967296;
|
|
547
561
|
};
|
|
548
562
|
}
|
|
563
|
+
function parseRgbLuminance(color) {
|
|
564
|
+
const match = /rgba?\(\s*(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*(\d*(?:\.\d+)?))?\s*\)/i.exec(
|
|
565
|
+
color
|
|
566
|
+
);
|
|
567
|
+
if (!match) return null;
|
|
568
|
+
const alpha = match[4] !== void 0 && match[4] !== "" ? Number(match[4]) : 1;
|
|
569
|
+
if (Number.isNaN(alpha) || alpha < 0.1) return null;
|
|
570
|
+
const r = Number(match[1]);
|
|
571
|
+
const g = Number(match[2]);
|
|
572
|
+
const b = Number(match[3]);
|
|
573
|
+
return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
574
|
+
}
|
|
575
|
+
function detectLightBackground() {
|
|
576
|
+
if (typeof window === "undefined" || typeof document === "undefined") return false;
|
|
577
|
+
const candidates = [document.body, document.documentElement];
|
|
578
|
+
for (const el of candidates) {
|
|
579
|
+
if (!el) continue;
|
|
580
|
+
const bg = window.getComputedStyle(el).backgroundColor;
|
|
581
|
+
const lum = parseRgbLuminance(bg);
|
|
582
|
+
if (lum !== null) {
|
|
583
|
+
return lum > 0.55;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (typeof window.matchMedia === "function") {
|
|
587
|
+
return window.matchMedia("(prefers-color-scheme: light)").matches;
|
|
588
|
+
}
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
function resolveContrasting(setting) {
|
|
592
|
+
return setting === "auto" ? detectLightBackground() : Boolean(setting);
|
|
593
|
+
}
|
|
549
594
|
function createFlakeSprite(contrasting, soft) {
|
|
550
595
|
if (typeof document === "undefined") return null;
|
|
551
596
|
const size = soft ? 32 : 20;
|
|
@@ -594,8 +639,18 @@ function createSnow(options) {
|
|
|
594
639
|
return { destroy() {
|
|
595
640
|
} };
|
|
596
641
|
}
|
|
597
|
-
|
|
598
|
-
|
|
642
|
+
let isContrasting = resolveContrasting(options.contrasting);
|
|
643
|
+
let sharpSprite = createFlakeSprite(isContrasting, false);
|
|
644
|
+
let softSprite = createFlakeSprite(isContrasting, true);
|
|
645
|
+
const refreshContrasting = () => {
|
|
646
|
+
if (options.contrasting !== "auto") return;
|
|
647
|
+
const next = detectLightBackground();
|
|
648
|
+
if (next !== isContrasting) {
|
|
649
|
+
isContrasting = next;
|
|
650
|
+
sharpSprite = createFlakeSprite(isContrasting, false);
|
|
651
|
+
softSprite = createFlakeSprite(isContrasting, true);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
599
654
|
let width = window.innerWidth;
|
|
600
655
|
let height = window.innerHeight;
|
|
601
656
|
let flakes = [];
|
|
@@ -603,6 +658,8 @@ function createSnow(options) {
|
|
|
603
658
|
let lastTime = 0;
|
|
604
659
|
let paused = document.visibilityState === "hidden";
|
|
605
660
|
let destroyed = false;
|
|
661
|
+
let targetWind = 0;
|
|
662
|
+
let currentWind = 0;
|
|
606
663
|
const initFlakes = () => {
|
|
607
664
|
const random = createPrng(202611);
|
|
608
665
|
const count = resolveCount(options.density, width);
|
|
@@ -641,10 +698,18 @@ function createSnow(options) {
|
|
|
641
698
|
const dt = Math.min((now - lastTime) / 1e3, 0.05);
|
|
642
699
|
lastTime = now;
|
|
643
700
|
const t = now / 1e3;
|
|
701
|
+
if (options.mouseWind) {
|
|
702
|
+
currentWind += (targetWind - currentWind) * Math.min(1, dt * 3.2);
|
|
703
|
+
}
|
|
644
704
|
ctx.clearRect(0, 0, width, height);
|
|
645
705
|
for (let i = 0; i < flakes.length; i++) {
|
|
646
706
|
const f = flakes[i];
|
|
647
707
|
f.y += f.speedY * dt;
|
|
708
|
+
if (options.mouseWind && Math.abs(currentWind) > 2e-3) {
|
|
709
|
+
f.x += currentWind * 58 * (0.45 + f.layer * 0.42) * dt;
|
|
710
|
+
if (f.x < -24) f.x += width + 48;
|
|
711
|
+
else if (f.x > width + 24) f.x -= width + 48;
|
|
712
|
+
}
|
|
648
713
|
const xOffset = options.wind ? Math.sin(t * f.driftFreq + f.phase) * f.driftAmp : 0;
|
|
649
714
|
const drawX = f.x + xOffset;
|
|
650
715
|
if (f.y > height + f.radius * 2) {
|
|
@@ -660,7 +725,7 @@ function createSnow(options) {
|
|
|
660
725
|
const drawSize = f.radius * (f.layer === 2 ? 3.2 : 2.5);
|
|
661
726
|
ctx.drawImage(sprite, drawX - drawSize / 2, f.y - drawSize / 2, drawSize, drawSize);
|
|
662
727
|
} else {
|
|
663
|
-
ctx.fillStyle =
|
|
728
|
+
ctx.fillStyle = isContrasting ? "#d7edff" : "#ffffff";
|
|
664
729
|
ctx.beginPath();
|
|
665
730
|
ctx.arc(drawX, f.y, f.radius, 0, Math.PI * 2);
|
|
666
731
|
ctx.fill();
|
|
@@ -680,9 +745,33 @@ function createSnow(options) {
|
|
|
680
745
|
rafId = window.requestAnimationFrame(render);
|
|
681
746
|
}
|
|
682
747
|
};
|
|
748
|
+
const handlePointerMove = (event) => {
|
|
749
|
+
targetWind = (event.clientX / Math.max(1, width) - 0.5) * 2;
|
|
750
|
+
};
|
|
751
|
+
const handlePointerLeave = () => {
|
|
752
|
+
targetWind = 0;
|
|
753
|
+
};
|
|
683
754
|
resize();
|
|
684
755
|
window.addEventListener("resize", resize, { passive: true });
|
|
685
756
|
document.addEventListener("visibilitychange", handleVisibility);
|
|
757
|
+
if (options.mouseWind) {
|
|
758
|
+
window.addEventListener("pointermove", handlePointerMove, { passive: true });
|
|
759
|
+
document.documentElement.addEventListener("pointerleave", handlePointerLeave, { passive: true });
|
|
760
|
+
}
|
|
761
|
+
let observer = null;
|
|
762
|
+
if (options.contrasting === "auto" && typeof MutationObserver !== "undefined") {
|
|
763
|
+
observer = new MutationObserver(refreshContrasting);
|
|
764
|
+
observer.observe(document.documentElement, {
|
|
765
|
+
attributes: true,
|
|
766
|
+
attributeFilter: ["class", "style", "data-theme"]
|
|
767
|
+
});
|
|
768
|
+
if (document.body) {
|
|
769
|
+
observer.observe(document.body, {
|
|
770
|
+
attributes: true,
|
|
771
|
+
attributeFilter: ["class", "style", "data-theme"]
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
686
775
|
if (!paused) {
|
|
687
776
|
rafId = window.requestAnimationFrame(render);
|
|
688
777
|
}
|
|
@@ -692,6 +781,11 @@ function createSnow(options) {
|
|
|
692
781
|
if (rafId) window.cancelAnimationFrame(rafId);
|
|
693
782
|
window.removeEventListener("resize", resize);
|
|
694
783
|
document.removeEventListener("visibilitychange", handleVisibility);
|
|
784
|
+
if (options.mouseWind) {
|
|
785
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
786
|
+
document.documentElement.removeEventListener("pointerleave", handlePointerLeave);
|
|
787
|
+
}
|
|
788
|
+
observer?.disconnect();
|
|
695
789
|
canvas.remove();
|
|
696
790
|
}
|
|
697
791
|
};
|
|
@@ -892,9 +986,10 @@ var DEFAULT_CONFIG = {
|
|
|
892
986
|
snow: {
|
|
893
987
|
enabled: true,
|
|
894
988
|
density: "medium",
|
|
895
|
-
contrasting:
|
|
989
|
+
contrasting: "auto",
|
|
896
990
|
speed: 1,
|
|
897
991
|
wind: true,
|
|
992
|
+
mouseWind: true,
|
|
898
993
|
zIndex: 9990
|
|
899
994
|
},
|
|
900
995
|
lights: {
|
|
@@ -903,9 +998,11 @@ var DEFAULT_CONFIG = {
|
|
|
903
998
|
backdrop: "transparent",
|
|
904
999
|
bulbs: 32,
|
|
905
1000
|
palette: "classic",
|
|
1001
|
+
animation: "twinkle",
|
|
906
1002
|
interactive: true,
|
|
907
1003
|
pushBody: false,
|
|
908
1004
|
zIndex: 9995,
|
|
1005
|
+
ariaLabel: "Illuminate Christmas lights",
|
|
909
1006
|
container: null
|
|
910
1007
|
},
|
|
911
1008
|
buttonBurst: {
|
|
@@ -930,51 +1027,75 @@ var DEFAULT_CONFIG = {
|
|
|
930
1027
|
offset: 16,
|
|
931
1028
|
persist: true,
|
|
932
1029
|
storageKey: "snowies:enabled",
|
|
933
|
-
labelOn: "
|
|
934
|
-
labelOff: "
|
|
935
|
-
textOn: "
|
|
936
|
-
textOff: "
|
|
1030
|
+
labelOn: "Disable Christmas effects",
|
|
1031
|
+
labelOff: "Enable Christmas effects",
|
|
1032
|
+
textOn: "Holiday",
|
|
1033
|
+
textOff: "Paused",
|
|
937
1034
|
zIndex: 9999
|
|
938
1035
|
}
|
|
939
1036
|
};
|
|
940
1037
|
var PRESETS = {
|
|
941
1038
|
classic: {
|
|
942
|
-
snow: { enabled: true, density: "medium", contrasting:
|
|
943
|
-
lights: {
|
|
1039
|
+
snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
|
|
1040
|
+
lights: {
|
|
1041
|
+
enabled: true,
|
|
1042
|
+
position: "fixed",
|
|
1043
|
+
backdrop: "transparent",
|
|
1044
|
+
palette: "classic",
|
|
1045
|
+
animation: "twinkle"
|
|
1046
|
+
},
|
|
944
1047
|
buttonBurst: { enabled: true },
|
|
945
1048
|
buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
|
|
946
1049
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
947
1050
|
},
|
|
948
1051
|
minimal: {
|
|
949
|
-
snow: { enabled: true, density: "light", contrasting:
|
|
1052
|
+
snow: { enabled: true, density: "light", contrasting: "auto", speed: 0.85, mouseWind: false },
|
|
950
1053
|
lights: { enabled: false },
|
|
951
1054
|
buttonBurst: { enabled: false },
|
|
952
1055
|
buttonSnow: { enabled: false },
|
|
953
1056
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
954
1057
|
},
|
|
955
1058
|
festive: {
|
|
956
|
-
snow: { enabled: true, density: "heavy", contrasting:
|
|
957
|
-
lights: {
|
|
1059
|
+
snow: { enabled: true, density: "heavy", contrasting: "auto", speed: 1.1, mouseWind: true },
|
|
1060
|
+
lights: {
|
|
1061
|
+
enabled: true,
|
|
1062
|
+
position: "fixed",
|
|
1063
|
+
backdrop: "pine",
|
|
1064
|
+
palette: "classic",
|
|
1065
|
+
animation: "wave"
|
|
1066
|
+
},
|
|
958
1067
|
buttonBurst: { enabled: true, particles: 56, crystals: true },
|
|
959
1068
|
buttonSnow: { enabled: true, mode: "manual", style: "fluffy" },
|
|
960
1069
|
toggleButton: { enabled: true, variant: "pill", theme: "festive" }
|
|
961
1070
|
},
|
|
962
1071
|
light: {
|
|
963
|
-
snow: { enabled: true, density: "medium", contrasting: true },
|
|
964
|
-
lights: {
|
|
1072
|
+
snow: { enabled: true, density: "medium", contrasting: true, mouseWind: true },
|
|
1073
|
+
lights: {
|
|
1074
|
+
enabled: true,
|
|
1075
|
+
position: "fixed",
|
|
1076
|
+
backdrop: "transparent",
|
|
1077
|
+
palette: "ice",
|
|
1078
|
+
animation: "twinkle"
|
|
1079
|
+
},
|
|
965
1080
|
buttonBurst: { enabled: true },
|
|
966
1081
|
buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
|
|
967
1082
|
toggleButton: { enabled: true, variant: "icon", theme: "light" }
|
|
968
1083
|
},
|
|
969
1084
|
"lights-only": {
|
|
970
1085
|
snow: { enabled: false },
|
|
971
|
-
lights: {
|
|
1086
|
+
lights: {
|
|
1087
|
+
enabled: true,
|
|
1088
|
+
position: "fixed",
|
|
1089
|
+
backdrop: "transparent",
|
|
1090
|
+
palette: "classic",
|
|
1091
|
+
animation: "twinkle"
|
|
1092
|
+
},
|
|
972
1093
|
buttonBurst: { enabled: false },
|
|
973
1094
|
buttonSnow: { enabled: false },
|
|
974
1095
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
975
1096
|
},
|
|
976
1097
|
"snow-only": {
|
|
977
|
-
snow: { enabled: true, density: "medium", contrasting:
|
|
1098
|
+
snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
|
|
978
1099
|
lights: { enabled: false },
|
|
979
1100
|
buttonBurst: { enabled: false },
|
|
980
1101
|
buttonSnow: { enabled: false },
|
|
@@ -982,37 +1103,6 @@ var PRESETS = {
|
|
|
982
1103
|
}
|
|
983
1104
|
};
|
|
984
1105
|
|
|
985
|
-
// src/utils/i18n.ts
|
|
986
|
-
var MESSAGES = {
|
|
987
|
-
en: {
|
|
988
|
-
toggleLabelOn: "Disable Christmas effects",
|
|
989
|
-
toggleLabelOff: "Enable Christmas effects",
|
|
990
|
-
toggleTextOn: "Holiday",
|
|
991
|
-
toggleTextOff: "Paused",
|
|
992
|
-
lightsAriaLabel: "Illuminate Christmas lights"
|
|
993
|
-
},
|
|
994
|
-
es: {
|
|
995
|
-
toggleLabelOn: "Desactivar efectos navide\xF1os",
|
|
996
|
-
toggleLabelOff: "Activar efectos navide\xF1os",
|
|
997
|
-
toggleTextOn: "Navidad",
|
|
998
|
-
toggleTextOff: "Pausado",
|
|
999
|
-
lightsAriaLabel: "Hacer brillar las luces navide\xF1as"
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
function resolveLocale(locale = "auto") {
|
|
1003
|
-
if (locale === "es" || locale === "en") return locale;
|
|
1004
|
-
if (typeof document !== "undefined") {
|
|
1005
|
-
const docLang = document.documentElement?.lang?.toLowerCase();
|
|
1006
|
-
if (docLang) {
|
|
1007
|
-
return docLang.startsWith("es") ? "es" : "en";
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
if (typeof navigator !== "undefined" && navigator.language) {
|
|
1011
|
-
return navigator.language.toLowerCase().startsWith("es") ? "es" : "en";
|
|
1012
|
-
}
|
|
1013
|
-
return "en";
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
1106
|
// src/utils/config.ts
|
|
1017
1107
|
function mergeFeature(base, presetOverride, userOverride) {
|
|
1018
1108
|
let result = { ...base };
|
|
@@ -1032,33 +1122,18 @@ function resolveConfig(options = {}, previous) {
|
|
|
1032
1122
|
const presetName = options.preset ?? previous?.preset ?? DEFAULT_CONFIG.preset;
|
|
1033
1123
|
const presetDef = options.preset ? PRESETS[presetName] ?? {} : previous ? {} : PRESETS[presetName] ?? {};
|
|
1034
1124
|
const base = previous && !options.preset ? previous : DEFAULT_CONFIG;
|
|
1035
|
-
const locale = resolveLocale(options.locale ?? previous?.locale ?? "auto");
|
|
1036
|
-
const msg = MESSAGES[locale];
|
|
1037
|
-
const localeChanged = !previous || options.locale !== void 0 || options.preset !== void 0;
|
|
1038
|
-
const lights = mergeFeature(base.lights, presetDef.lights, options.lights);
|
|
1039
|
-
const userLights = typeof options.lights === "object" ? options.lights : void 0;
|
|
1040
|
-
if (localeChanged && !userLights?.ariaLabel) {
|
|
1041
|
-
lights.ariaLabel = msg.lightsAriaLabel;
|
|
1042
|
-
}
|
|
1043
1125
|
const toggleButton = mergeFeature(base.toggleButton, presetDef.toggleButton, options.toggleButton);
|
|
1044
1126
|
const userToggle = typeof options.toggleButton === "object" ? options.toggleButton : void 0;
|
|
1045
|
-
if (localeChanged) {
|
|
1046
|
-
if (!userToggle?.labelOn) toggleButton.labelOn = msg.toggleLabelOn;
|
|
1047
|
-
if (!userToggle?.labelOff) toggleButton.labelOff = msg.toggleLabelOff;
|
|
1048
|
-
if (!userToggle?.textOn) toggleButton.textOn = msg.toggleTextOn;
|
|
1049
|
-
if (!userToggle?.textOff) toggleButton.textOff = msg.toggleTextOff;
|
|
1050
|
-
}
|
|
1051
1127
|
if (userToggle?.style && base.toggleButton.style) {
|
|
1052
1128
|
toggleButton.style = { ...base.toggleButton.style, ...userToggle.style };
|
|
1053
1129
|
}
|
|
1054
1130
|
return {
|
|
1055
1131
|
preset: presetName,
|
|
1056
|
-
locale,
|
|
1057
1132
|
enabled: options.enabled ?? base.enabled,
|
|
1058
1133
|
respectReducedMotion: options.respectReducedMotion ?? base.respectReducedMotion,
|
|
1059
1134
|
schedule: options.schedule !== void 0 ? options.schedule : base.schedule,
|
|
1060
1135
|
snow: mergeFeature(base.snow, presetDef.snow, options.snow),
|
|
1061
|
-
lights,
|
|
1136
|
+
lights: mergeFeature(base.lights, presetDef.lights, options.lights),
|
|
1062
1137
|
buttonBurst: mergeFeature(base.buttonBurst, presetDef.buttonBurst, options.buttonBurst),
|
|
1063
1138
|
buttonSnow: mergeFeature(base.buttonSnow, presetDef.buttonSnow, options.buttonSnow),
|
|
1064
1139
|
toggleButton,
|
|
@@ -1259,6 +1334,13 @@ function parseBoolAttr(val) {
|
|
|
1259
1334
|
if (val === "false" || val === "0") return false;
|
|
1260
1335
|
return void 0;
|
|
1261
1336
|
}
|
|
1337
|
+
var VALID_POSITIONS = /* @__PURE__ */ new Set([
|
|
1338
|
+
"bottom-right",
|
|
1339
|
+
"bottom-left",
|
|
1340
|
+
"top-right",
|
|
1341
|
+
"top-left"
|
|
1342
|
+
]);
|
|
1343
|
+
var VALID_ANIMATIONS = /* @__PURE__ */ new Set(["twinkle", "wave", "steady"]);
|
|
1262
1344
|
function autoInitFromScript(script) {
|
|
1263
1345
|
if (typeof document === "undefined") return null;
|
|
1264
1346
|
const el = script ?? document.currentScript ?? document.querySelector("script[data-snowies], script[data-preset]");
|
|
@@ -1267,20 +1349,38 @@ function autoInitFromScript(script) {
|
|
|
1267
1349
|
const options = {};
|
|
1268
1350
|
const preset = el.getAttribute("data-preset");
|
|
1269
1351
|
if (preset) options.preset = preset;
|
|
1270
|
-
const locale = el.getAttribute("data-locale");
|
|
1271
|
-
if (locale === "es" || locale === "en" || locale === "auto") {
|
|
1272
|
-
options.locale = locale;
|
|
1273
|
-
}
|
|
1274
1352
|
const snow = parseBoolAttr(el.getAttribute("data-snow"));
|
|
1275
|
-
|
|
1353
|
+
const mouseWind = parseBoolAttr(el.getAttribute("data-mouse-wind"));
|
|
1354
|
+
if (snow !== void 0 || mouseWind !== void 0) {
|
|
1355
|
+
options.snow = {
|
|
1356
|
+
...snow !== void 0 ? { enabled: snow } : {},
|
|
1357
|
+
...mouseWind !== void 0 ? { mouseWind } : {}
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1276
1360
|
const lights = parseBoolAttr(el.getAttribute("data-lights"));
|
|
1277
|
-
|
|
1361
|
+
const lightsAnim = el.getAttribute("data-lights-animation");
|
|
1362
|
+
if (lights !== void 0 || lightsAnim && VALID_ANIMATIONS.has(lightsAnim)) {
|
|
1363
|
+
options.lights = {
|
|
1364
|
+
...lights !== void 0 ? { enabled: lights } : {},
|
|
1365
|
+
...lightsAnim && VALID_ANIMATIONS.has(lightsAnim) ? { animation: lightsAnim } : {}
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1278
1368
|
const burst = parseBoolAttr(el.getAttribute("data-burst"));
|
|
1279
1369
|
if (burst !== void 0) options.buttonBurst = burst;
|
|
1280
1370
|
const buttonSnow = parseBoolAttr(el.getAttribute("data-button-snow"));
|
|
1281
1371
|
if (buttonSnow !== void 0) options.buttonSnow = buttonSnow;
|
|
1282
1372
|
const toggle = parseBoolAttr(el.getAttribute("data-toggle"));
|
|
1283
|
-
|
|
1373
|
+
const togglePos = el.getAttribute("data-toggle-position");
|
|
1374
|
+
const textOn = el.getAttribute("data-text-on");
|
|
1375
|
+
const textOff = el.getAttribute("data-text-off");
|
|
1376
|
+
if (toggle !== void 0 || togglePos && VALID_POSITIONS.has(togglePos) || textOn || textOff) {
|
|
1377
|
+
options.toggleButton = {
|
|
1378
|
+
...toggle !== void 0 ? { enabled: toggle } : {},
|
|
1379
|
+
...togglePos && VALID_POSITIONS.has(togglePos) ? { position: togglePos } : {},
|
|
1380
|
+
...textOn ? { textOn } : {},
|
|
1381
|
+
...textOff ? { textOff } : {}
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1284
1384
|
const from = el.getAttribute("data-from");
|
|
1285
1385
|
const to = el.getAttribute("data-to");
|
|
1286
1386
|
if (from && to) {
|