snowies 0.0.0-stage → 0.2.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.
package/dist/auto.cjs ADDED
@@ -0,0 +1,1253 @@
1
+ 'use strict';
2
+
3
+ // src/modules/buttonBurst.ts
4
+ var CRYSTAL_SVG = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"><path d="M8 1.5v13M2.4 4.75l11.2 6.5M13.6 4.75l-11.2 6.5"/></svg>`;
5
+ function createButtonBurst(options) {
6
+ if (typeof document === "undefined" || typeof window === "undefined") {
7
+ return { trigger() {
8
+ }, destroy() {
9
+ } };
10
+ }
11
+ const overlayHost = document.createElement("div");
12
+ overlayHost.setAttribute("data-snowies-burst-layer", "");
13
+ overlayHost.setAttribute("aria-hidden", "true");
14
+ Object.assign(overlayHost.style, {
15
+ position: "fixed",
16
+ inset: "0",
17
+ zIndex: String(options.zIndex),
18
+ overflow: "hidden",
19
+ pointerEvents: "none"
20
+ });
21
+ const shadow = overlayHost.attachShadow({ mode: "open" });
22
+ const style = document.createElement("style");
23
+ style.textContent = `
24
+ .burst-group {
25
+ position: fixed;
26
+ inset: 0;
27
+ pointer-events: none;
28
+ }
29
+ .p {
30
+ position: absolute;
31
+ display: block;
32
+ width: var(--s);
33
+ height: var(--s);
34
+ border-radius: 50%;
35
+ background: #fff;
36
+ box-shadow: 0 0 9px #8dd6ff, 0 0 2px #2965b4;
37
+ will-change: transform, opacity;
38
+ animation: snow-burst cubic-bezier(.14, .65, .32, 1) both;
39
+ }
40
+ .p.is-crystal {
41
+ width: calc(var(--s) + 8px);
42
+ height: calc(var(--s) + 8px);
43
+ color: #e8f7ff;
44
+ background: transparent;
45
+ box-shadow: none;
46
+ filter: drop-shadow(0 0 4px rgba(92, 174, 255, 0.85));
47
+ }
48
+ .p.is-crystal svg {
49
+ width: 100%;
50
+ height: 100%;
51
+ display: block;
52
+ }
53
+ @keyframes snow-burst {
54
+ 0% { opacity: 0; transform: translate3d(0, 0, 0) scale(.3); }
55
+ 12% { opacity: 1; }
56
+ 65% { opacity: .95; transform: translate3d(var(--bx), var(--by), 0) scale(1); }
57
+ 100% { opacity: 0; transform: translate3d(var(--bx), var(--bf), 0) rotate(80deg) scale(.4); }
58
+ }
59
+ `;
60
+ shadow.appendChild(style);
61
+ document.body.appendChild(overlayHost);
62
+ const activeTimers = /* @__PURE__ */ new Set();
63
+ const isMobile = () => window.innerWidth <= 640;
64
+ const trigger = (target) => {
65
+ let x;
66
+ let y;
67
+ if ("x" in target && "y" in target && !(target instanceof HTMLElement)) {
68
+ x = target.x;
69
+ y = target.y;
70
+ } else {
71
+ const bounds = target.getBoundingClientRect();
72
+ x = bounds.left + bounds.width / 2;
73
+ y = bounds.top + bounds.height / 2;
74
+ }
75
+ const total = Math.max(8, Math.min(96, Math.round(options.particles)));
76
+ const count = isMobile() ? Math.round(total * 0.65) : total;
77
+ const group = document.createElement("div");
78
+ group.className = "burst-group";
79
+ let maxDuration = 0;
80
+ for (let i = 0; i < count; i++) {
81
+ const angle = i * Math.PI * 2 / count;
82
+ const distance = 90 + i % 7 * 29;
83
+ const bx = Math.cos(angle) * distance;
84
+ const by = Math.sin(angle) * distance;
85
+ const size = 3 + i % 5 * 1.4;
86
+ const duration = 850 + i % 5 * 80;
87
+ const isCrystal = options.crystals && i % 4 === 0;
88
+ if (duration > maxDuration) maxDuration = duration;
89
+ const span = document.createElement("span");
90
+ span.className = isCrystal ? "p is-crystal" : "p";
91
+ span.style.left = `${x}px`;
92
+ span.style.top = `${y}px`;
93
+ span.style.setProperty("--bx", `${bx.toFixed(1)}px`);
94
+ span.style.setProperty("--by", `${by.toFixed(1)}px`);
95
+ span.style.setProperty("--bf", `${(by + 100).toFixed(1)}px`);
96
+ span.style.setProperty("--s", `${size}px`);
97
+ span.style.animationDuration = `${duration}ms`;
98
+ if (isCrystal) span.innerHTML = CRYSTAL_SVG;
99
+ group.appendChild(span);
100
+ }
101
+ shadow.appendChild(group);
102
+ const timer = window.setTimeout(() => {
103
+ group.remove();
104
+ activeTimers.delete(timer);
105
+ }, maxDuration + 120);
106
+ activeTimers.add(timer);
107
+ };
108
+ const handleClick = (event) => {
109
+ const target = event.target;
110
+ if (!(target instanceof Element)) return;
111
+ if (target.closest("[data-snowies-toggle], [data-snowies-lights]")) return;
112
+ const matched = target.closest(options.selector);
113
+ if (!matched) return;
114
+ if (matched instanceof HTMLButtonElement && matched.disabled || matched.getAttribute("aria-disabled") === "true") {
115
+ return;
116
+ }
117
+ trigger(matched);
118
+ };
119
+ document.addEventListener("click", handleClick, { passive: true });
120
+ return {
121
+ trigger,
122
+ destroy() {
123
+ document.removeEventListener("click", handleClick);
124
+ activeTimers.forEach((id) => window.clearTimeout(id));
125
+ activeTimers.clear();
126
+ overlayHost.remove();
127
+ }
128
+ };
129
+ }
130
+
131
+ // src/modules/buttonSnow.ts
132
+ var SUBTLE_SNOW_SVG = encodeURIComponent(
133
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 16" preserveAspectRatio="none">
134
+ <defs>
135
+ <linearGradient id="sg" x1="0" y1="0" x2="0" y2="1">
136
+ <stop offset="0%" stop-color="#ffffff"/>
137
+ <stop offset="72%" stop-color="#f2f8ff"/>
138
+ <stop offset="100%" stop-color="#dceeff"/>
139
+ </linearGradient>
140
+ </defs>
141
+ <path d="M4 9 C6 5.5, 16 4, 30 4.5 C46 5, 62 3.2, 82 4 C102 4.8, 120 3.4, 136 4.6 C148 5.5, 154 6.5, 156 9 C155 11.2, 148 11.5, 140 10 C130 8.2, 122 12.2, 110 11.4 C98 10.6, 90 8.5, 76 10.8 C64 12.6, 54 9.2, 42 10.6 C30 12, 20 8.8, 12 10.6 C7 11.6, 4.5 10.6, 4 9 Z" fill="url(#sg)" stroke="#cbe3fa" stroke-width="0.7" stroke-linejoin="round"/>
142
+ </svg>`
143
+ );
144
+ var FLUFFY_SNOW_SVG = encodeURIComponent(
145
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 24" preserveAspectRatio="none">
146
+ <defs>
147
+ <linearGradient id="fg" x1="0" y1="0" x2="0" y2="1">
148
+ <stop offset="0%" stop-color="#ffffff"/>
149
+ <stop offset="62%" stop-color="#f4f9ff"/>
150
+ <stop offset="100%" stop-color="#d4eaff"/>
151
+ </linearGradient>
152
+ </defs>
153
+ <path d="M3 13 C5 6, 18 3, 34 4.5 C46 5.6, 56 1.5, 74 2.8 C90 4, 102 1.8, 118 3.6 C134 5.4, 150 4.5, 157 12.5 C157 16, 151 17.2, 145 15 C140 13.2, 138 19.5, 131 19.5 C124 19.5, 122 13.8, 112 14.4 C100 15, 95 21.5, 86 21.5 C77 21.5, 74 14.5, 62 14.8 C50 15.1, 46 19.8, 38 19.6 C30 19.4, 28 14.2, 19 15.2 C11 16.2, 3.5 16.2, 3 13 Z" fill="url(#fg)" stroke="#c2dff8" stroke-width="0.85" stroke-linejoin="round"/>
154
+ </svg>`
155
+ );
156
+ var ALL_BUTTONS_SELECTOR = 'button:not([data-snowies-ignore]):not([disabled]), [role="button"]:not([data-snowies-ignore]):not([aria-disabled="true"])';
157
+ function buildSelectors(options) {
158
+ const raw = options.mode === "all" ? ALL_BUTTONS_SELECTOR : options.selector;
159
+ return raw.split(",").map((s) => s.trim()).filter(Boolean);
160
+ }
161
+ function createButtonSnow(options) {
162
+ if (typeof document === "undefined") {
163
+ return { destroy() {
164
+ } };
165
+ }
166
+ const selectors = buildSelectors(options);
167
+ if (selectors.length === 0) {
168
+ return { destroy() {
169
+ } };
170
+ }
171
+ const isFluffy = options.style === "fluffy";
172
+ const svg = isFluffy ? FLUFFY_SNOW_SVG : SUBTLE_SNOW_SVG;
173
+ const height = isFluffy ? "16px" : "11px";
174
+ const topOffset = isFluffy ? "-7px" : "-4px";
175
+ const insetX = isFluffy ? "3px" : "4px";
176
+ const baseRule = selectors.map((s) => `:where(${s})`).join(", ");
177
+ const afterRule = selectors.map((s) => `:where(${s})::after`).join(", ");
178
+ const styleEl = document.createElement("style");
179
+ styleEl.setAttribute("data-snowies-button-snow", "");
180
+ styleEl.textContent = `
181
+ ${baseRule} {
182
+ position: relative;
183
+ overflow: visible;
184
+ }
185
+ ${afterRule} {
186
+ content: "";
187
+ position: absolute;
188
+ top: ${topOffset};
189
+ left: ${insetX};
190
+ right: ${insetX};
191
+ height: ${height};
192
+ pointer-events: none;
193
+ z-index: 1;
194
+ background: url("data:image/svg+xml,${svg}") no-repeat top center / 100% 100%;
195
+ filter: drop-shadow(0 1.5px 2px rgba(30, 64, 110, 0.24));
196
+ }
197
+ `;
198
+ document.head.appendChild(styleEl);
199
+ return {
200
+ destroy() {
201
+ styleEl.remove();
202
+ }
203
+ };
204
+ }
205
+
206
+ // src/utils/motion.ts
207
+ function prefersReducedMotion() {
208
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
209
+ return false;
210
+ }
211
+ return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
212
+ }
213
+ function subscribeReducedMotion(callback) {
214
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
215
+ return () => {
216
+ };
217
+ }
218
+ const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
219
+ const listener = (event) => callback(event.matches);
220
+ if (typeof mq.addEventListener === "function") {
221
+ mq.addEventListener("change", listener);
222
+ return () => mq.removeEventListener("change", listener);
223
+ }
224
+ return () => {
225
+ };
226
+ }
227
+ function resolveContainer(target) {
228
+ if (typeof document === "undefined") {
229
+ throw new Error("Snowies requires a browser DOM environment.");
230
+ }
231
+ if (!target) return document.body;
232
+ if (typeof target === "string") {
233
+ return document.querySelector(target) ?? document.body;
234
+ }
235
+ return target;
236
+ }
237
+
238
+ // src/modules/lights.ts
239
+ var PALETTES = {
240
+ classic: [
241
+ { color: "#ffd16c", core: "#fff4ca" },
242
+ { color: "#ef5262", core: "#ffd0cd" },
243
+ { color: "#ffc35c", core: "#fff3bc" },
244
+ { color: "#53d69d", core: "#d5ffe8" },
245
+ { color: "#7cbaff", core: "#e0f5ff" }
246
+ ],
247
+ warm: [
248
+ { color: "#ffd16c", core: "#fff7d6" },
249
+ { color: "#ffb347", core: "#ffefc2" },
250
+ { color: "#ffe08a", core: "#ffffff" },
251
+ { color: "#f7a440", core: "#fff0c9" }
252
+ ],
253
+ ice: [
254
+ { color: "#7cbaff", core: "#e6f7ff" },
255
+ { color: "#b4e4ff", core: "#ffffff" },
256
+ { color: "#5ce1e6", core: "#e0ffff" },
257
+ { color: "#9ec5ff", core: "#eef6ff" }
258
+ ]
259
+ };
260
+ function resolvePalette(palette) {
261
+ if (Array.isArray(palette) && palette.length > 0) return palette;
262
+ if (typeof palette === "string" && palette in PALETTES) {
263
+ return PALETTES[palette];
264
+ }
265
+ return PALETTES.classic;
266
+ }
267
+ var BACKDROP_STYLES = {
268
+ pine: "radial-gradient(ellipse at 50% 0, #285344, transparent 75%), #0c2d25",
269
+ dark: "linear-gradient(180deg, rgba(10, 15, 26, 0.92), rgba(10, 15, 26, 0.55) 75%, transparent)",
270
+ transparent: "transparent"
271
+ };
272
+ var LIGHTS_HEIGHT = 42;
273
+ function createLights(options) {
274
+ if (typeof document === "undefined" || typeof window === "undefined") {
275
+ return { destroy() {
276
+ } };
277
+ }
278
+ const host = document.createElement("div");
279
+ host.setAttribute("data-snowies-lights", "");
280
+ if (options.position === "fixed") {
281
+ Object.assign(host.style, {
282
+ position: "fixed",
283
+ top: "0",
284
+ left: "0",
285
+ right: "0",
286
+ zIndex: String(options.zIndex),
287
+ pointerEvents: options.interactive ? "auto" : "none"
288
+ });
289
+ } else if (options.position === "sticky") {
290
+ Object.assign(host.style, {
291
+ position: "sticky",
292
+ top: "0",
293
+ left: "0",
294
+ right: "0",
295
+ zIndex: String(options.zIndex),
296
+ pointerEvents: options.interactive ? "auto" : "none"
297
+ });
298
+ } else {
299
+ Object.assign(host.style, {
300
+ position: "relative",
301
+ width: "100%",
302
+ zIndex: String(options.zIndex),
303
+ pointerEvents: options.interactive ? "auto" : "none"
304
+ });
305
+ }
306
+ let prevBodyPaddingTop = null;
307
+ if (options.position === "fixed" && options.pushBody) {
308
+ prevBodyPaddingTop = document.body.style.paddingTop;
309
+ const currentPx = parseFloat(window.getComputedStyle(document.body).paddingTop) || 0;
310
+ document.body.style.paddingTop = `${currentPx + LIGHTS_HEIGHT}px`;
311
+ }
312
+ const shadow = host.attachShadow({ mode: "open" });
313
+ const colors = resolvePalette(options.palette);
314
+ const bulbCount = Math.max(6, Math.min(64, Math.round(options.bulbs)));
315
+ const mobileCutoff = Math.max(10, Math.round(bulbCount * 0.45));
316
+ const bg = BACKDROP_STYLES[options.backdrop] ?? BACKDROP_STYLES.pine;
317
+ const style = document.createElement("style");
318
+ style.textContent = `
319
+ :host { display: block; line-height: 0; }
320
+ .strip {
321
+ position: relative;
322
+ isolation: isolate;
323
+ display: flex;
324
+ align-items: flex-start;
325
+ justify-content: space-around;
326
+ width: 100%;
327
+ height: ${LIGHTS_HEIGHT}px;
328
+ padding: 0 5px;
329
+ margin: 0;
330
+ border: 0;
331
+ box-sizing: border-box;
332
+ overflow: hidden;
333
+ background: ${bg};
334
+ cursor: ${options.interactive ? "pointer" : "default"};
335
+ -webkit-tap-highlight-color: transparent;
336
+ user-select: none;
337
+ }
338
+ .strip:focus-visible {
339
+ outline: 2px solid #ffe5a5;
340
+ outline-offset: -3px;
341
+ }
342
+ .wire {
343
+ position: absolute;
344
+ inset: 0 0 auto;
345
+ width: 100%;
346
+ height: 10px;
347
+ pointer-events: none;
348
+ }
349
+ .lamp {
350
+ position: relative;
351
+ display: flex;
352
+ flex: 1 1 0;
353
+ min-width: 0;
354
+ flex-direction: column;
355
+ align-items: center;
356
+ padding-top: 3px;
357
+ transform-origin: 50% 2px;
358
+ will-change: transform;
359
+ animation: lamp-sway var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;
360
+ }
361
+ .cord {
362
+ z-index: 1;
363
+ width: 1px;
364
+ height: var(--bulb-cord);
365
+ background: #a39871;
366
+ }
367
+ .socket {
368
+ z-index: 2;
369
+ width: 7px;
370
+ height: 5px;
371
+ border-radius: 2px 2px 0 0;
372
+ background: repeating-linear-gradient(180deg, #a99561 0 1px, #51482e 1px 2px);
373
+ }
374
+ .glass {
375
+ position: relative;
376
+ z-index: 2;
377
+ display: flex;
378
+ width: 11px;
379
+ height: 17px;
380
+ align-items: center;
381
+ justify-content: center;
382
+ border: 1px solid var(--bulb-color);
383
+ border-radius: 40% 40% 55% 55%;
384
+ background:
385
+ radial-gradient(ellipse at 30% 22%, #fff 0, transparent 32%),
386
+ radial-gradient(ellipse at 50% 35%, var(--bulb-core) 5%, var(--bulb-color) 80%);
387
+ box-shadow: 0 0 5px var(--bulb-color), 0 0 12px var(--bulb-color);
388
+ will-change: opacity, transform;
389
+ animation: glass-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;
390
+ transition: transform 0.25s ease, opacity 0.25s ease;
391
+ }
392
+ .filament {
393
+ width: 3px;
394
+ height: 8px;
395
+ border-radius: 50%;
396
+ background: var(--bulb-core);
397
+ box-shadow: 0 0 4px #fff;
398
+ }
399
+ .halo {
400
+ position: absolute;
401
+ z-index: 0;
402
+ top: 2px;
403
+ left: 50%;
404
+ width: 50px;
405
+ height: 44px;
406
+ transform: translateX(-50%);
407
+ background: radial-gradient(ellipse, var(--bulb-color), transparent 70%);
408
+ opacity: 0.2;
409
+ pointer-events: none;
410
+ will-change: opacity;
411
+ animation: halo-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;
412
+ transition: opacity 0.25s ease;
413
+ }
414
+ .lamp.is-near .glass,
415
+ .strip.is-celebrating .glass {
416
+ animation: none;
417
+ opacity: 1;
418
+ transform: scale(1.16);
419
+ }
420
+ .lamp.is-near .halo,
421
+ .strip.is-celebrating .halo {
422
+ animation: none;
423
+ opacity: 0.62;
424
+ }
425
+ @keyframes lamp-sway {
426
+ from { transform: rotate(var(--bulb-tilt)); }
427
+ to { transform: rotate(calc(var(--bulb-tilt) * -1)); }
428
+ }
429
+ @keyframes glass-glow {
430
+ from { opacity: 0.72; }
431
+ to { opacity: 1; }
432
+ }
433
+ @keyframes halo-glow {
434
+ from { opacity: 0.12; }
435
+ to { opacity: 0.34; }
436
+ }
437
+ @media (max-width: 640px) {
438
+ .lamp:nth-of-type(n + ${mobileCutoff + 1}) { display: none; }
439
+ }
440
+ @media (prefers-reduced-motion: reduce) {
441
+ .lamp, .glass, .halo { animation: none; transition: none; }
442
+ }
443
+ `;
444
+ const strip = document.createElement(options.interactive ? "button" : "div");
445
+ strip.className = "strip";
446
+ if (options.interactive) {
447
+ strip.setAttribute("type", "button");
448
+ strip.setAttribute("aria-label", "Hacer brillar las luces navide\xF1as");
449
+ } else {
450
+ strip.setAttribute("aria-hidden", "true");
451
+ }
452
+ strip.innerHTML = `
453
+ <svg class="wire" viewBox="0 0 1240 10" preserveAspectRatio="none" focusable="false" aria-hidden="true">
454
+ <path d="M-10 1 Q145 11 300 2 T610 2 T920 2 T1250 1" fill="none" stroke="#071c17" stroke-width="3" />
455
+ <path d="M-10 1 Q145 11 300 2 T610 2 T920 2 T1250 1" fill="none" stroke="#829070" stroke-width=".65" opacity=".7" />
456
+ </svg>
457
+ `;
458
+ const lamps = [];
459
+ for (let i = 0; i < bulbCount; i++) {
460
+ const c = colors[i % colors.length];
461
+ const lamp = document.createElement("span");
462
+ lamp.className = "lamp";
463
+ lamp.setAttribute("aria-hidden", "true");
464
+ lamp.style.setProperty("--bulb-color", c.color);
465
+ lamp.style.setProperty("--bulb-core", c.core);
466
+ lamp.style.setProperty("--bulb-delay", `${i * -0.43}s`);
467
+ lamp.style.setProperty("--bulb-duration", `${3.4 + i % 5 * 0.35}s`);
468
+ lamp.style.setProperty("--bulb-cord", `${4 + i % 3 * 2}px`);
469
+ lamp.style.setProperty("--bulb-tilt", `${i % 2 ? 5 : -5}deg`);
470
+ lamp.innerHTML = `
471
+ <span class="cord"></span>
472
+ <span class="socket"></span>
473
+ <span class="glass"><span class="filament"></span></span>
474
+ <span class="halo"></span>
475
+ `;
476
+ strip.appendChild(lamp);
477
+ lamps.push(lamp);
478
+ }
479
+ let glowTimer;
480
+ let hoveredIndex = null;
481
+ const updateNear = (idx) => {
482
+ hoveredIndex = idx;
483
+ for (let i = 0; i < lamps.length; i++) {
484
+ const near = hoveredIndex !== null && Math.abs(hoveredIndex - i) <= 1;
485
+ lamps[i].classList.toggle("is-near", near);
486
+ }
487
+ };
488
+ const handleCelebrate = () => {
489
+ strip.classList.add("is-celebrating");
490
+ if (glowTimer) window.clearTimeout(glowTimer);
491
+ glowTimer = window.setTimeout(() => {
492
+ strip.classList.remove("is-celebrating");
493
+ }, 1800);
494
+ };
495
+ const cleanups = [];
496
+ if (options.interactive) {
497
+ lamps.forEach((lamp, i) => {
498
+ const onEnter = () => updateNear(i);
499
+ lamp.addEventListener("pointerenter", onEnter);
500
+ cleanups.push(() => lamp.removeEventListener("pointerenter", onEnter));
501
+ });
502
+ const onLeave = () => updateNear(null);
503
+ strip.addEventListener("pointerleave", onLeave);
504
+ strip.addEventListener("blur", onLeave);
505
+ strip.addEventListener("click", handleCelebrate);
506
+ cleanups.push(() => {
507
+ strip.removeEventListener("pointerleave", onLeave);
508
+ strip.removeEventListener("blur", onLeave);
509
+ strip.removeEventListener("click", handleCelebrate);
510
+ });
511
+ }
512
+ shadow.appendChild(style);
513
+ shadow.appendChild(strip);
514
+ const container = resolveContainer(options.container);
515
+ if (options.position === "fixed" || options.position === "sticky") {
516
+ container.prepend(host);
517
+ } else {
518
+ container.appendChild(host);
519
+ }
520
+ return {
521
+ destroy() {
522
+ if (glowTimer) window.clearTimeout(glowTimer);
523
+ cleanups.forEach((fn) => fn());
524
+ host.remove();
525
+ if (prevBodyPaddingTop !== null) {
526
+ document.body.style.paddingTop = prevBodyPaddingTop;
527
+ }
528
+ }
529
+ };
530
+ }
531
+
532
+ // src/modules/snow.ts
533
+ var DENSITY_MAP = {
534
+ light: 48,
535
+ medium: 90,
536
+ heavy: 150
537
+ };
538
+ function resolveCount(density, viewportWidth) {
539
+ const base = typeof density === "number" ? Math.max(0, Math.min(400, Math.round(density))) : DENSITY_MAP[density] ?? 90;
540
+ return viewportWidth <= 640 ? Math.max(12, Math.round(base * 0.53)) : base;
541
+ }
542
+ function createPrng(initialSeed = 202611) {
543
+ let seed = initialSeed;
544
+ return () => {
545
+ seed = Math.imul(seed, 1664525) + 1013904223 >>> 0;
546
+ return seed / 4294967296;
547
+ };
548
+ }
549
+ function createFlakeSprite(contrasting, soft) {
550
+ if (typeof document === "undefined") return null;
551
+ const size = soft ? 32 : 20;
552
+ const sprite = document.createElement("canvas");
553
+ sprite.width = size;
554
+ sprite.height = size;
555
+ const ctx = sprite.getContext("2d");
556
+ if (!ctx) return null;
557
+ const half = size / 2;
558
+ const grad = ctx.createRadialGradient(half, half, 0, half, half, half);
559
+ if (contrasting) {
560
+ grad.addColorStop(0, "rgba(215, 237, 255, 1)");
561
+ grad.addColorStop(soft ? 0.45 : 0.6, "rgba(176, 217, 250, 0.9)");
562
+ grad.addColorStop(soft ? 0.78 : 0.85, "rgba(71, 130, 180, 0.35)");
563
+ grad.addColorStop(1, "rgba(71, 130, 180, 0)");
564
+ } else {
565
+ grad.addColorStop(0, "rgba(255, 255, 255, 1)");
566
+ grad.addColorStop(soft ? 0.42 : 0.62, "rgba(255, 255, 255, 0.88)");
567
+ grad.addColorStop(soft ? 0.76 : 0.88, "rgba(255, 255, 255, 0.25)");
568
+ grad.addColorStop(1, "rgba(255, 255, 255, 0)");
569
+ }
570
+ ctx.fillStyle = grad;
571
+ ctx.fillRect(0, 0, size, size);
572
+ return sprite;
573
+ }
574
+ function createSnow(options) {
575
+ if (typeof document === "undefined" || typeof window === "undefined") {
576
+ return { destroy() {
577
+ } };
578
+ }
579
+ const canvas = document.createElement("canvas");
580
+ canvas.setAttribute("data-snowies-snow", "");
581
+ canvas.setAttribute("aria-hidden", "true");
582
+ Object.assign(canvas.style, {
583
+ position: "fixed",
584
+ inset: "0",
585
+ width: "100%",
586
+ height: "100%",
587
+ pointerEvents: "none",
588
+ zIndex: String(options.zIndex)
589
+ });
590
+ document.body.appendChild(canvas);
591
+ const ctx = canvas.getContext("2d");
592
+ if (!ctx) {
593
+ canvas.remove();
594
+ return { destroy() {
595
+ } };
596
+ }
597
+ const sharpSprite = createFlakeSprite(options.contrasting, false);
598
+ const softSprite = createFlakeSprite(options.contrasting, true);
599
+ let width = window.innerWidth;
600
+ let height = window.innerHeight;
601
+ let flakes = [];
602
+ let rafId = 0;
603
+ let lastTime = 0;
604
+ let paused = document.visibilityState === "hidden";
605
+ let destroyed = false;
606
+ const initFlakes = () => {
607
+ const random = createPrng(202611);
608
+ const count = resolveCount(options.density, width);
609
+ const speedMult = Math.max(0.1, options.speed);
610
+ flakes = Array.from({ length: count }, (_, index) => {
611
+ const depth = index % 9;
612
+ const layer = depth < 4 ? 0 : depth < 7 ? 1 : 2;
613
+ const radius = layer === 0 ? 1.4 + index % 2 * 0.7 : layer === 1 ? 2.4 + index % 3 * 0.8 : 4 + index % 4 * 1;
614
+ const durationSec = (layer === 0 ? 16 : layer === 1 ? 11 : 8) + random() * 6;
615
+ const speedY = (height + 40) / durationSec * speedMult;
616
+ return {
617
+ x: random() * width,
618
+ y: random() * (height + 40) - 20,
619
+ radius,
620
+ speedY,
621
+ driftAmp: options.wind ? (18 + random() * 44) * (layer === 2 ? 1.25 : 0.85) : 0,
622
+ driftFreq: 0.35 + random() * 0.55,
623
+ phase: random() * Math.PI * 2,
624
+ opacity: layer === 0 ? 0.38 : layer === 1 ? 0.68 : 0.84,
625
+ layer
626
+ };
627
+ });
628
+ };
629
+ const resize = () => {
630
+ width = window.innerWidth;
631
+ height = window.innerHeight;
632
+ const dpr = Math.min(window.devicePixelRatio || 1, 2);
633
+ canvas.width = Math.max(1, Math.floor(width * dpr));
634
+ canvas.height = Math.max(1, Math.floor(height * dpr));
635
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
636
+ initFlakes();
637
+ };
638
+ const render = (now) => {
639
+ if (destroyed || paused) return;
640
+ if (!lastTime) lastTime = now;
641
+ const dt = Math.min((now - lastTime) / 1e3, 0.05);
642
+ lastTime = now;
643
+ const t = now / 1e3;
644
+ ctx.clearRect(0, 0, width, height);
645
+ for (let i = 0; i < flakes.length; i++) {
646
+ const f = flakes[i];
647
+ f.y += f.speedY * dt;
648
+ const xOffset = options.wind ? Math.sin(t * f.driftFreq + f.phase) * f.driftAmp : 0;
649
+ const drawX = f.x + xOffset;
650
+ if (f.y > height + f.radius * 2) {
651
+ f.y = -f.radius * 2 - 4;
652
+ f.x = (f.x + 137.5) % Math.max(1, width);
653
+ }
654
+ let edgeFade = 1;
655
+ if (f.y < 36) edgeFade = Math.max(0, (f.y + 12) / 48);
656
+ else if (f.y > height - 60) edgeFade = Math.max(0, (height - f.y) / 60);
657
+ ctx.globalAlpha = f.opacity * edgeFade;
658
+ const sprite = f.layer === 2 ? softSprite : sharpSprite;
659
+ if (sprite) {
660
+ const drawSize = f.radius * (f.layer === 2 ? 3.2 : 2.5);
661
+ ctx.drawImage(sprite, drawX - drawSize / 2, f.y - drawSize / 2, drawSize, drawSize);
662
+ } else {
663
+ ctx.fillStyle = options.contrasting ? "#d7edff" : "#ffffff";
664
+ ctx.beginPath();
665
+ ctx.arc(drawX, f.y, f.radius, 0, Math.PI * 2);
666
+ ctx.fill();
667
+ }
668
+ }
669
+ ctx.globalAlpha = 1;
670
+ rafId = window.requestAnimationFrame(render);
671
+ };
672
+ const handleVisibility = () => {
673
+ paused = document.visibilityState === "hidden";
674
+ if (paused) {
675
+ if (rafId) window.cancelAnimationFrame(rafId);
676
+ rafId = 0;
677
+ lastTime = 0;
678
+ } else if (!destroyed && !rafId) {
679
+ lastTime = 0;
680
+ rafId = window.requestAnimationFrame(render);
681
+ }
682
+ };
683
+ resize();
684
+ window.addEventListener("resize", resize, { passive: true });
685
+ document.addEventListener("visibilitychange", handleVisibility);
686
+ if (!paused) {
687
+ rafId = window.requestAnimationFrame(render);
688
+ }
689
+ return {
690
+ destroy() {
691
+ destroyed = true;
692
+ if (rafId) window.cancelAnimationFrame(rafId);
693
+ window.removeEventListener("resize", resize);
694
+ document.removeEventListener("visibilitychange", handleVisibility);
695
+ canvas.remove();
696
+ }
697
+ };
698
+ }
699
+
700
+ // src/modules/toggle.ts
701
+ var DEFAULT_SNOWFLAKE_SVG = `
702
+ <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
703
+ <path d="M12 2v20M4.93 7l14.14 10M19.07 7L4.93 17"/>
704
+ <path d="M9.5 4.5L12 7l2.5-2.5M9.5 19.5L12 17l2.5 2.5"/>
705
+ <path d="M5.5 10.5L8 10l-.5-2.5M18.5 13.5L16 14l.5 2.5"/>
706
+ </svg>`;
707
+ var THEMES = {
708
+ minimal: {
709
+ bg: "rgba(18, 18, 20, 0.72)",
710
+ bgOff: "rgba(18, 18, 20, 0.45)",
711
+ color: "#e4e4e7",
712
+ border: "rgba(255, 255, 255, 0.14)",
713
+ accent: "#93c5fd"
714
+ },
715
+ dark: {
716
+ bg: "#111113",
717
+ bgOff: "rgba(17, 17, 19, 0.65)",
718
+ color: "#fafafa",
719
+ border: "#27272a",
720
+ accent: "#ffffff"
721
+ },
722
+ light: {
723
+ bg: "rgba(255, 255, 255, 0.88)",
724
+ bgOff: "rgba(255, 255, 255, 0.62)",
725
+ color: "#18181b",
726
+ border: "rgba(24, 24, 27, 0.12)",
727
+ accent: "#2563eb"
728
+ },
729
+ festive: {
730
+ bg: "rgba(12, 45, 37, 0.88)",
731
+ bgOff: "rgba(12, 45, 37, 0.5)",
732
+ color: "#fef3c7",
733
+ border: "rgba(253, 224, 138, 0.28)",
734
+ accent: "#53d69d"
735
+ }
736
+ };
737
+ function createToggleButton(options, initialActive, onToggle) {
738
+ if (typeof document === "undefined") {
739
+ return { setActive() {
740
+ }, destroy() {
741
+ } };
742
+ }
743
+ const host = document.createElement("div");
744
+ host.setAttribute("data-snowies-toggle", "");
745
+ const offset = `${Math.max(0, options.offset)}px`;
746
+ const topOffset = `${Math.max(0, options.offset) + 42}px`;
747
+ const posStyles = {
748
+ "bottom-right": { bottom: offset, right: offset },
749
+ "bottom-left": { bottom: offset, left: offset },
750
+ "top-right": { top: topOffset, right: offset },
751
+ "top-left": { top: topOffset, left: offset }
752
+ };
753
+ Object.assign(host.style, {
754
+ position: "fixed",
755
+ zIndex: String(options.zIndex),
756
+ ...posStyles[options.position] ?? posStyles["bottom-right"]
757
+ });
758
+ const shadow = host.attachShadow({ mode: "open" });
759
+ const baseTheme = THEMES[options.theme] ?? THEMES.minimal;
760
+ const custom = options.style ?? {};
761
+ const bg = custom.background ?? baseTheme.bg;
762
+ const bgOff = custom.backgroundOff ?? baseTheme.bgOff;
763
+ const color = custom.color ?? baseTheme.color;
764
+ const border = custom.borderColor ?? baseTheme.border;
765
+ const accent = custom.accentColor ?? baseTheme.accent;
766
+ const radius = custom.borderRadius ?? "999px";
767
+ const isPill = options.variant === "pill";
768
+ const dim = options.size === "md" ? 40 : 34;
769
+ const iconSize = options.size === "md" ? 16 : 14;
770
+ const style = document.createElement("style");
771
+ style.textContent = `
772
+ :host { display: block; line-height: 0; }
773
+ button {
774
+ all: unset;
775
+ position: relative;
776
+ box-sizing: border-box;
777
+ display: inline-flex;
778
+ align-items: center;
779
+ justify-content: center;
780
+ gap: 7px;
781
+ height: ${dim}px;
782
+ ${isPill ? `padding: 0 ${options.size === "md" ? 13 : 11}px;` : `width: ${dim}px; padding: 0;`}
783
+ border-radius: ${radius};
784
+ border: 1px solid ${border};
785
+ background: ${bg};
786
+ color: ${color};
787
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
788
+ backdrop-filter: blur(10px);
789
+ -webkit-backdrop-filter: blur(10px);
790
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
791
+ font-size: ${options.size === "md" ? "12.5px" : "11.5px"};
792
+ font-weight: 500;
793
+ letter-spacing: 0.01em;
794
+ cursor: pointer;
795
+ user-select: none;
796
+ opacity: 0.72;
797
+ transition: opacity 0.2s ease, transform 0.16s ease, background 0.2s ease, border-color 0.2s ease;
798
+ }
799
+ button:hover {
800
+ opacity: 1;
801
+ transform: translateY(-1px);
802
+ }
803
+ button:active {
804
+ transform: scale(0.95);
805
+ }
806
+ button:focus-visible {
807
+ opacity: 1;
808
+ outline: 2px solid ${accent};
809
+ outline-offset: 2px;
810
+ }
811
+ button[aria-pressed="false"] {
812
+ background: ${bgOff};
813
+ opacity: 0.52;
814
+ }
815
+ button[aria-pressed="false"]:hover {
816
+ opacity: 0.92;
817
+ }
818
+ .icon-wrap {
819
+ display: inline-flex;
820
+ align-items: center;
821
+ justify-content: center;
822
+ width: ${iconSize}px;
823
+ height: ${iconSize}px;
824
+ flex-shrink: 0;
825
+ transition: transform 0.3s ease, opacity 0.2s ease;
826
+ }
827
+ .icon-wrap svg {
828
+ width: 100%;
829
+ height: 100%;
830
+ display: block;
831
+ }
832
+ button[aria-pressed="true"] .icon-wrap {
833
+ transform: rotate(30deg);
834
+ }
835
+ button[aria-pressed="false"] .icon-wrap {
836
+ opacity: 0.55;
837
+ }
838
+ .dot {
839
+ width: 5px;
840
+ height: 5px;
841
+ border-radius: 50%;
842
+ background: ${accent};
843
+ transition: opacity 0.2s ease, transform 0.2s ease;
844
+ ${isPill ? "" : "position: absolute; top: 6px; right: 6px;"}
845
+ }
846
+ button[aria-pressed="false"] .dot {
847
+ opacity: 0;
848
+ transform: scale(0.4);
849
+ }
850
+ .text {
851
+ line-height: 1;
852
+ white-space: nowrap;
853
+ }
854
+ `;
855
+ const button = document.createElement("button");
856
+ button.type = "button";
857
+ button.innerHTML = `
858
+ <span class="icon-wrap" aria-hidden="true">${options.icon ?? DEFAULT_SNOWFLAKE_SVG}</span>
859
+ ${isPill ? '<span class="text"></span>' : ""}
860
+ <span class="dot" aria-hidden="true"></span>
861
+ `;
862
+ const textEl = button.querySelector(".text");
863
+ const setActive = (active) => {
864
+ button.setAttribute("aria-pressed", active ? "true" : "false");
865
+ const label = active ? options.labelOn : options.labelOff;
866
+ button.setAttribute("aria-label", label);
867
+ button.setAttribute("title", label);
868
+ if (textEl) {
869
+ textEl.textContent = active ? options.textOn : options.textOff;
870
+ }
871
+ };
872
+ setActive(initialActive);
873
+ button.addEventListener("click", onToggle);
874
+ shadow.appendChild(style);
875
+ shadow.appendChild(button);
876
+ document.body.appendChild(host);
877
+ return {
878
+ setActive,
879
+ destroy() {
880
+ button.removeEventListener("click", onToggle);
881
+ host.remove();
882
+ }
883
+ };
884
+ }
885
+
886
+ // src/presets.ts
887
+ var DEFAULT_CONFIG = {
888
+ preset: "classic",
889
+ enabled: true,
890
+ respectReducedMotion: true,
891
+ schedule: false,
892
+ snow: {
893
+ enabled: true,
894
+ density: "medium",
895
+ contrasting: false,
896
+ speed: 1,
897
+ wind: true,
898
+ zIndex: 9990
899
+ },
900
+ lights: {
901
+ enabled: true,
902
+ position: "fixed",
903
+ backdrop: "transparent",
904
+ bulbs: 32,
905
+ palette: "classic",
906
+ interactive: true,
907
+ pushBody: false,
908
+ zIndex: 9995,
909
+ container: null
910
+ },
911
+ buttonBurst: {
912
+ enabled: true,
913
+ selector: 'button, [role="button"], [data-snowies-burst]',
914
+ particles: 48,
915
+ crystals: true,
916
+ zIndex: 9998
917
+ },
918
+ buttonSnow: {
919
+ enabled: true,
920
+ mode: "manual",
921
+ style: "subtle",
922
+ selector: "[data-snowies-snow], [data-snowies-btn], .snowies-snow"
923
+ },
924
+ toggleButton: {
925
+ enabled: true,
926
+ position: "bottom-right",
927
+ variant: "icon",
928
+ size: "sm",
929
+ theme: "minimal",
930
+ offset: 16,
931
+ persist: true,
932
+ storageKey: "snowies:enabled",
933
+ labelOn: "Desactivar efectos navide\xF1os",
934
+ labelOff: "Activar efectos navide\xF1os",
935
+ textOn: "Navidad",
936
+ textOff: "Pausado",
937
+ zIndex: 9999
938
+ }
939
+ };
940
+ var PRESETS = {
941
+ classic: {
942
+ snow: { enabled: true, density: "medium", contrasting: false },
943
+ lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
944
+ buttonBurst: { enabled: true },
945
+ buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
946
+ toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
947
+ },
948
+ minimal: {
949
+ snow: { enabled: true, density: "light", contrasting: false, speed: 0.85 },
950
+ lights: { enabled: false },
951
+ buttonBurst: { enabled: false },
952
+ buttonSnow: { enabled: false },
953
+ toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
954
+ },
955
+ festive: {
956
+ snow: { enabled: true, density: "heavy", contrasting: false, speed: 1.1 },
957
+ lights: { enabled: true, position: "fixed", backdrop: "pine", palette: "classic" },
958
+ buttonBurst: { enabled: true, particles: 56, crystals: true },
959
+ buttonSnow: { enabled: true, mode: "manual", style: "fluffy" },
960
+ toggleButton: { enabled: true, variant: "pill", theme: "festive" }
961
+ },
962
+ light: {
963
+ snow: { enabled: true, density: "medium", contrasting: true },
964
+ lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "ice" },
965
+ buttonBurst: { enabled: true },
966
+ buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
967
+ toggleButton: { enabled: true, variant: "icon", theme: "light" }
968
+ },
969
+ "lights-only": {
970
+ snow: { enabled: false },
971
+ lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
972
+ buttonBurst: { enabled: false },
973
+ buttonSnow: { enabled: false },
974
+ toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
975
+ },
976
+ "snow-only": {
977
+ snow: { enabled: true, density: "medium", contrasting: false },
978
+ lights: { enabled: false },
979
+ buttonBurst: { enabled: false },
980
+ buttonSnow: { enabled: false },
981
+ toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
982
+ }
983
+ };
984
+
985
+ // src/utils/config.ts
986
+ function mergeFeature(base, presetOverride, userOverride) {
987
+ let result = { ...base };
988
+ if (typeof presetOverride === "boolean") {
989
+ result.enabled = presetOverride;
990
+ } else if (presetOverride) {
991
+ result = { ...result, ...presetOverride };
992
+ }
993
+ if (typeof userOverride === "boolean") {
994
+ result.enabled = userOverride;
995
+ } else if (userOverride) {
996
+ result = { ...result, ...userOverride };
997
+ }
998
+ return result;
999
+ }
1000
+ function resolveConfig(options = {}, previous) {
1001
+ const presetName = options.preset ?? previous?.preset ?? DEFAULT_CONFIG.preset;
1002
+ const presetDef = options.preset ? PRESETS[presetName] ?? {} : previous ? {} : PRESETS[presetName] ?? {};
1003
+ const base = previous && !options.preset ? previous : DEFAULT_CONFIG;
1004
+ const toggleButton = mergeFeature(base.toggleButton, presetDef.toggleButton, options.toggleButton);
1005
+ if (typeof options.toggleButton === "object" && options.toggleButton?.style && base.toggleButton.style) {
1006
+ toggleButton.style = { ...base.toggleButton.style, ...options.toggleButton.style };
1007
+ }
1008
+ return {
1009
+ preset: presetName,
1010
+ enabled: options.enabled ?? base.enabled,
1011
+ respectReducedMotion: options.respectReducedMotion ?? base.respectReducedMotion,
1012
+ schedule: options.schedule !== void 0 ? options.schedule : base.schedule,
1013
+ snow: mergeFeature(base.snow, presetDef.snow, options.snow),
1014
+ lights: mergeFeature(base.lights, presetDef.lights, options.lights),
1015
+ buttonBurst: mergeFeature(base.buttonBurst, presetDef.buttonBurst, options.buttonBurst),
1016
+ buttonSnow: mergeFeature(base.buttonSnow, presetDef.buttonSnow, options.buttonSnow),
1017
+ toggleButton,
1018
+ onChange: options.onChange ?? base.onChange
1019
+ };
1020
+ }
1021
+
1022
+ // src/utils/schedule.ts
1023
+ var DATE_RE = /^(?:(\d{4})-)?(\d{1,2})-(\d{1,2})$/;
1024
+ function parseDateSpec(spec) {
1025
+ const match = DATE_RE.exec(spec.trim());
1026
+ if (!match) return null;
1027
+ const year = match[1] ? Number(match[1]) : null;
1028
+ const month = Number(match[2]);
1029
+ const day = Number(match[3]);
1030
+ if (month < 1 || month > 12 || day < 1 || day > 31) return null;
1031
+ return { year, month, day };
1032
+ }
1033
+ function toDayOfYearKey(month, day) {
1034
+ return month * 100 + day;
1035
+ }
1036
+ function toFullDateKey(year, month, day) {
1037
+ return year * 1e4 + month * 100 + day;
1038
+ }
1039
+ function isWithinSchedule(schedule) {
1040
+ if (!schedule) return true;
1041
+ const from = parseDateSpec(schedule.from);
1042
+ const to = parseDateSpec(schedule.to);
1043
+ if (!from || !to) return true;
1044
+ const now = schedule.now ?? /* @__PURE__ */ new Date();
1045
+ const currentYear = now.getFullYear();
1046
+ const currentMonth = now.getMonth() + 1;
1047
+ const currentDay = now.getDate();
1048
+ if (from.year !== null && to.year !== null) {
1049
+ const cur2 = toFullDateKey(currentYear, currentMonth, currentDay);
1050
+ const start2 = toFullDateKey(from.year, from.month, from.day);
1051
+ const end2 = toFullDateKey(to.year, to.month, to.day);
1052
+ return cur2 >= start2 && cur2 <= end2;
1053
+ }
1054
+ const cur = toDayOfYearKey(currentMonth, currentDay);
1055
+ const start = toDayOfYearKey(from.month, from.day);
1056
+ const end = toDayOfYearKey(to.month, to.day);
1057
+ if (start <= end) {
1058
+ return cur >= start && cur <= end;
1059
+ }
1060
+ return cur >= start || cur <= end;
1061
+ }
1062
+
1063
+ // src/utils/storage.ts
1064
+ function readPersistedEnabled(storageKey) {
1065
+ try {
1066
+ if (typeof window === "undefined" || !window.localStorage) return null;
1067
+ const raw = window.localStorage.getItem(storageKey);
1068
+ if (raw === "true") return true;
1069
+ if (raw === "false") return false;
1070
+ return null;
1071
+ } catch {
1072
+ return null;
1073
+ }
1074
+ }
1075
+ function writePersistedEnabled(storageKey, enabled) {
1076
+ try {
1077
+ if (typeof window === "undefined" || !window.localStorage) return;
1078
+ window.localStorage.setItem(storageKey, enabled ? "true" : "false");
1079
+ } catch {
1080
+ }
1081
+ }
1082
+
1083
+ // src/core.ts
1084
+ function createSnowies(options = {}) {
1085
+ let config = resolveConfig(options);
1086
+ let destroyed = false;
1087
+ let reducedMotion = prefersReducedMotion();
1088
+ let userOverride = config.toggleButton.persist ? readPersistedEnabled(config.toggleButton.storageKey) : null;
1089
+ let snowMod = null;
1090
+ let lightsMod = null;
1091
+ let burstMod = null;
1092
+ let buttonSnowMod = null;
1093
+ let toggleMod = null;
1094
+ const computeState = () => {
1095
+ const inSchedule = isWithinSchedule(config.schedule);
1096
+ let active = false;
1097
+ if (inSchedule && config.enabled) {
1098
+ if (userOverride !== null) {
1099
+ active = userOverride;
1100
+ } else if (config.respectReducedMotion && reducedMotion) {
1101
+ active = false;
1102
+ } else {
1103
+ active = true;
1104
+ }
1105
+ }
1106
+ return {
1107
+ active,
1108
+ inSchedule,
1109
+ reducedMotion,
1110
+ userDisabled: userOverride === false,
1111
+ config
1112
+ };
1113
+ };
1114
+ const destroyEffects = () => {
1115
+ snowMod?.destroy();
1116
+ snowMod = null;
1117
+ lightsMod?.destroy();
1118
+ lightsMod = null;
1119
+ burstMod?.destroy();
1120
+ burstMod = null;
1121
+ buttonSnowMod?.destroy();
1122
+ buttonSnowMod = null;
1123
+ };
1124
+ const destroyToggle = () => {
1125
+ toggleMod?.destroy();
1126
+ toggleMod = null;
1127
+ };
1128
+ const sync = (notify = true) => {
1129
+ if (destroyed) return;
1130
+ const state = computeState();
1131
+ destroyEffects();
1132
+ if (state.active) {
1133
+ if (config.snow.enabled) snowMod = createSnow(config.snow);
1134
+ if (config.lights.enabled) lightsMod = createLights(config.lights);
1135
+ if (config.buttonBurst.enabled) burstMod = createButtonBurst(config.buttonBurst);
1136
+ if (config.buttonSnow.enabled) buttonSnowMod = createButtonSnow(config.buttonSnow);
1137
+ }
1138
+ const shouldShowToggle = state.inSchedule && config.enabled && config.toggleButton.enabled;
1139
+ destroyToggle();
1140
+ if (shouldShowToggle) {
1141
+ toggleMod = createToggleButton(config.toggleButton, state.active, () => {
1142
+ controller.toggle();
1143
+ });
1144
+ }
1145
+ if (notify && config.onChange) {
1146
+ config.onChange(state);
1147
+ }
1148
+ };
1149
+ const unsubMotion = subscribeReducedMotion((isReduced) => {
1150
+ reducedMotion = isReduced;
1151
+ if (userOverride === null) {
1152
+ sync(true);
1153
+ }
1154
+ });
1155
+ const controller = {
1156
+ enable() {
1157
+ if (destroyed) return;
1158
+ userOverride = true;
1159
+ if (config.toggleButton.persist) {
1160
+ writePersistedEnabled(config.toggleButton.storageKey, true);
1161
+ }
1162
+ sync(true);
1163
+ },
1164
+ disable() {
1165
+ if (destroyed) return;
1166
+ userOverride = false;
1167
+ if (config.toggleButton.persist) {
1168
+ writePersistedEnabled(config.toggleButton.storageKey, false);
1169
+ }
1170
+ sync(true);
1171
+ },
1172
+ toggle() {
1173
+ const next = !computeState().active;
1174
+ if (next) this.enable();
1175
+ else this.disable();
1176
+ return computeState().active;
1177
+ },
1178
+ burst(target) {
1179
+ if (destroyed) return;
1180
+ if (burstMod) {
1181
+ burstMod.trigger(target);
1182
+ } else {
1183
+ const temp = createButtonBurst(config.buttonBurst);
1184
+ temp.trigger(target);
1185
+ window.setTimeout(() => temp.destroy(), 1500);
1186
+ }
1187
+ },
1188
+ update(nextOptions) {
1189
+ if (destroyed) return;
1190
+ config = resolveConfig(nextOptions, config);
1191
+ sync(true);
1192
+ },
1193
+ getState() {
1194
+ return computeState();
1195
+ },
1196
+ destroy() {
1197
+ if (destroyed) return;
1198
+ destroyed = true;
1199
+ unsubMotion();
1200
+ destroyEffects();
1201
+ destroyToggle();
1202
+ }
1203
+ };
1204
+ sync(false);
1205
+ return controller;
1206
+ }
1207
+
1208
+ // src/auto.ts
1209
+ function parseBoolAttr(val) {
1210
+ if (val === null) return void 0;
1211
+ if (val === "" || val === "true" || val === "1") return true;
1212
+ if (val === "false" || val === "0") return false;
1213
+ return void 0;
1214
+ }
1215
+ function autoInitFromScript(script) {
1216
+ if (typeof document === "undefined") return null;
1217
+ const el = script ?? document.currentScript ?? document.querySelector("script[data-snowies], script[data-preset]");
1218
+ if (!el) return null;
1219
+ if (parseBoolAttr(el.getAttribute("data-manual")) === true) return null;
1220
+ const options = {};
1221
+ const preset = el.getAttribute("data-preset");
1222
+ if (preset) options.preset = preset;
1223
+ const snow = parseBoolAttr(el.getAttribute("data-snow"));
1224
+ if (snow !== void 0) options.snow = snow;
1225
+ const lights = parseBoolAttr(el.getAttribute("data-lights"));
1226
+ if (lights !== void 0) options.lights = lights;
1227
+ const burst = parseBoolAttr(el.getAttribute("data-burst"));
1228
+ if (burst !== void 0) options.buttonBurst = burst;
1229
+ const buttonSnow = parseBoolAttr(el.getAttribute("data-button-snow"));
1230
+ if (buttonSnow !== void 0) options.buttonSnow = buttonSnow;
1231
+ const toggle = parseBoolAttr(el.getAttribute("data-toggle"));
1232
+ if (toggle !== void 0) options.toggleButton = toggle;
1233
+ const from = el.getAttribute("data-from");
1234
+ const to = el.getAttribute("data-to");
1235
+ if (from && to) {
1236
+ options.schedule = { from, to };
1237
+ }
1238
+ return createSnowies(options);
1239
+ }
1240
+ if (typeof document !== "undefined") {
1241
+ const run = () => {
1242
+ autoInitFromScript();
1243
+ };
1244
+ if (document.readyState === "loading") {
1245
+ document.addEventListener("DOMContentLoaded", run, { once: true });
1246
+ } else {
1247
+ run();
1248
+ }
1249
+ }
1250
+
1251
+ exports.autoInitFromScript = autoInitFromScript;
1252
+ //# sourceMappingURL=auto.cjs.map
1253
+ //# sourceMappingURL=auto.cjs.map