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.
@@ -311,7 +311,10 @@ function createLights(options) {
311
311
  const colors = resolvePalette(options.palette);
312
312
  const bulbCount = Math.max(6, Math.min(64, Math.round(options.bulbs)));
313
313
  const mobileCutoff = Math.max(10, Math.round(bulbCount * 0.45));
314
- const bg = BACKDROP_STYLES[options.backdrop] ?? BACKDROP_STYLES.pine;
314
+ const bg = BACKDROP_STYLES[options.backdrop] ?? BACKDROP_STYLES.transparent;
315
+ const animMode = options.animation ?? "twinkle";
316
+ 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;";
317
+ 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;";
315
318
  const style = document.createElement("style");
316
319
  style.textContent = `
317
320
  :host { display: block; line-height: 0; }
@@ -327,7 +330,8 @@ function createLights(options) {
327
330
  margin: 0;
328
331
  border: 0;
329
332
  box-sizing: border-box;
330
- overflow: hidden;
333
+ overflow-x: clip;
334
+ overflow-y: visible;
331
335
  background: ${bg};
332
336
  cursor: ${options.interactive ? "pointer" : "default"};
333
337
  -webkit-tap-highlight-color: transparent;
@@ -384,7 +388,7 @@ function createLights(options) {
384
388
  radial-gradient(ellipse at 50% 35%, var(--bulb-core) 5%, var(--bulb-color) 80%);
385
389
  box-shadow: 0 0 5px var(--bulb-color), 0 0 12px var(--bulb-color);
386
390
  will-change: opacity, transform;
387
- animation: glass-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;
391
+ ${glassAnimCss}
388
392
  transition: transform 0.25s ease, opacity 0.25s ease;
389
393
  }
390
394
  .filament {
@@ -397,16 +401,16 @@ function createLights(options) {
397
401
  .halo {
398
402
  position: absolute;
399
403
  z-index: 0;
400
- top: 2px;
404
+ top: -2px;
401
405
  left: 50%;
402
- width: 50px;
403
- height: 44px;
406
+ width: 58px;
407
+ height: 58px;
404
408
  transform: translateX(-50%);
405
- background: radial-gradient(ellipse, var(--bulb-color), transparent 70%);
409
+ background: radial-gradient(ellipse at 50% 44%, var(--bulb-color) 0%, transparent 66%);
406
410
  opacity: 0.2;
407
411
  pointer-events: none;
408
412
  will-change: opacity;
409
- animation: halo-glow var(--bulb-duration) ease-in-out var(--bulb-delay) infinite alternate;
413
+ ${haloAnimCss}
410
414
  transition: opacity 0.25s ease;
411
415
  }
412
416
  .lamp.is-near .glass,
@@ -432,6 +436,14 @@ function createLights(options) {
432
436
  from { opacity: 0.12; }
433
437
  to { opacity: 0.34; }
434
438
  }
439
+ @keyframes glass-wave {
440
+ 0%, 58%, 100% { opacity: 0.58; transform: scale(0.97); }
441
+ 22% { opacity: 1; transform: scale(1.1); }
442
+ }
443
+ @keyframes halo-wave {
444
+ 0%, 58%, 100% { opacity: 0.08; }
445
+ 22% { opacity: 0.52; }
446
+ }
435
447
  @media (max-width: 640px) {
436
448
  .lamp:nth-of-type(n + ${mobileCutoff + 1}) { display: none; }
437
449
  }
@@ -441,9 +453,10 @@ function createLights(options) {
441
453
  `;
442
454
  const strip = document.createElement(options.interactive ? "button" : "div");
443
455
  strip.className = "strip";
456
+ strip.setAttribute("data-animation", animMode);
444
457
  if (options.interactive) {
445
458
  strip.setAttribute("type", "button");
446
- strip.setAttribute("aria-label", options.ariaLabel ?? "Illuminate Christmas lights");
459
+ strip.setAttribute("aria-label", options.ariaLabel || "Illuminate Christmas lights");
447
460
  } else {
448
461
  strip.setAttribute("aria-hidden", "true");
449
462
  }
@@ -462,6 +475,7 @@ function createLights(options) {
462
475
  lamp.style.setProperty("--bulb-color", c.color);
463
476
  lamp.style.setProperty("--bulb-core", c.core);
464
477
  lamp.style.setProperty("--bulb-delay", `${i * -0.43}s`);
478
+ lamp.style.setProperty("--wave-delay", `${(i * -0.1).toFixed(2)}s`);
465
479
  lamp.style.setProperty("--bulb-duration", `${3.4 + i % 5 * 0.35}s`);
466
480
  lamp.style.setProperty("--bulb-cord", `${4 + i % 3 * 2}px`);
467
481
  lamp.style.setProperty("--bulb-tilt", `${i % 2 ? 5 : -5}deg`);
@@ -544,6 +558,37 @@ function createPrng(initialSeed = 202611) {
544
558
  return seed / 4294967296;
545
559
  };
546
560
  }
561
+ function parseRgbLuminance(color) {
562
+ const match = /rgba?\(\s*(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*(\d*(?:\.\d+)?))?\s*\)/i.exec(
563
+ color
564
+ );
565
+ if (!match) return null;
566
+ const alpha = match[4] !== void 0 && match[4] !== "" ? Number(match[4]) : 1;
567
+ if (Number.isNaN(alpha) || alpha < 0.1) return null;
568
+ const r = Number(match[1]);
569
+ const g = Number(match[2]);
570
+ const b = Number(match[3]);
571
+ return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
572
+ }
573
+ function detectLightBackground() {
574
+ if (typeof window === "undefined" || typeof document === "undefined") return false;
575
+ const candidates = [document.body, document.documentElement];
576
+ for (const el of candidates) {
577
+ if (!el) continue;
578
+ const bg = window.getComputedStyle(el).backgroundColor;
579
+ const lum = parseRgbLuminance(bg);
580
+ if (lum !== null) {
581
+ return lum > 0.55;
582
+ }
583
+ }
584
+ if (typeof window.matchMedia === "function") {
585
+ return window.matchMedia("(prefers-color-scheme: light)").matches;
586
+ }
587
+ return false;
588
+ }
589
+ function resolveContrasting(setting) {
590
+ return setting === "auto" ? detectLightBackground() : Boolean(setting);
591
+ }
547
592
  function createFlakeSprite(contrasting, soft) {
548
593
  if (typeof document === "undefined") return null;
549
594
  const size = soft ? 32 : 20;
@@ -592,8 +637,18 @@ function createSnow(options) {
592
637
  return { destroy() {
593
638
  } };
594
639
  }
595
- const sharpSprite = createFlakeSprite(options.contrasting, false);
596
- const softSprite = createFlakeSprite(options.contrasting, true);
640
+ let isContrasting = resolveContrasting(options.contrasting);
641
+ let sharpSprite = createFlakeSprite(isContrasting, false);
642
+ let softSprite = createFlakeSprite(isContrasting, true);
643
+ const refreshContrasting = () => {
644
+ if (options.contrasting !== "auto") return;
645
+ const next = detectLightBackground();
646
+ if (next !== isContrasting) {
647
+ isContrasting = next;
648
+ sharpSprite = createFlakeSprite(isContrasting, false);
649
+ softSprite = createFlakeSprite(isContrasting, true);
650
+ }
651
+ };
597
652
  let width = window.innerWidth;
598
653
  let height = window.innerHeight;
599
654
  let flakes = [];
@@ -601,6 +656,8 @@ function createSnow(options) {
601
656
  let lastTime = 0;
602
657
  let paused = document.visibilityState === "hidden";
603
658
  let destroyed = false;
659
+ let targetWind = 0;
660
+ let currentWind = 0;
604
661
  const initFlakes = () => {
605
662
  const random = createPrng(202611);
606
663
  const count = resolveCount(options.density, width);
@@ -639,10 +696,18 @@ function createSnow(options) {
639
696
  const dt = Math.min((now - lastTime) / 1e3, 0.05);
640
697
  lastTime = now;
641
698
  const t = now / 1e3;
699
+ if (options.mouseWind) {
700
+ currentWind += (targetWind - currentWind) * Math.min(1, dt * 3.2);
701
+ }
642
702
  ctx.clearRect(0, 0, width, height);
643
703
  for (let i = 0; i < flakes.length; i++) {
644
704
  const f = flakes[i];
645
705
  f.y += f.speedY * dt;
706
+ if (options.mouseWind && Math.abs(currentWind) > 2e-3) {
707
+ f.x += currentWind * 58 * (0.45 + f.layer * 0.42) * dt;
708
+ if (f.x < -24) f.x += width + 48;
709
+ else if (f.x > width + 24) f.x -= width + 48;
710
+ }
646
711
  const xOffset = options.wind ? Math.sin(t * f.driftFreq + f.phase) * f.driftAmp : 0;
647
712
  const drawX = f.x + xOffset;
648
713
  if (f.y > height + f.radius * 2) {
@@ -658,7 +723,7 @@ function createSnow(options) {
658
723
  const drawSize = f.radius * (f.layer === 2 ? 3.2 : 2.5);
659
724
  ctx.drawImage(sprite, drawX - drawSize / 2, f.y - drawSize / 2, drawSize, drawSize);
660
725
  } else {
661
- ctx.fillStyle = options.contrasting ? "#d7edff" : "#ffffff";
726
+ ctx.fillStyle = isContrasting ? "#d7edff" : "#ffffff";
662
727
  ctx.beginPath();
663
728
  ctx.arc(drawX, f.y, f.radius, 0, Math.PI * 2);
664
729
  ctx.fill();
@@ -678,9 +743,33 @@ function createSnow(options) {
678
743
  rafId = window.requestAnimationFrame(render);
679
744
  }
680
745
  };
746
+ const handlePointerMove = (event) => {
747
+ targetWind = (event.clientX / Math.max(1, width) - 0.5) * 2;
748
+ };
749
+ const handlePointerLeave = () => {
750
+ targetWind = 0;
751
+ };
681
752
  resize();
682
753
  window.addEventListener("resize", resize, { passive: true });
683
754
  document.addEventListener("visibilitychange", handleVisibility);
755
+ if (options.mouseWind) {
756
+ window.addEventListener("pointermove", handlePointerMove, { passive: true });
757
+ document.documentElement.addEventListener("pointerleave", handlePointerLeave, { passive: true });
758
+ }
759
+ let observer = null;
760
+ if (options.contrasting === "auto" && typeof MutationObserver !== "undefined") {
761
+ observer = new MutationObserver(refreshContrasting);
762
+ observer.observe(document.documentElement, {
763
+ attributes: true,
764
+ attributeFilter: ["class", "style", "data-theme"]
765
+ });
766
+ if (document.body) {
767
+ observer.observe(document.body, {
768
+ attributes: true,
769
+ attributeFilter: ["class", "style", "data-theme"]
770
+ });
771
+ }
772
+ }
684
773
  if (!paused) {
685
774
  rafId = window.requestAnimationFrame(render);
686
775
  }
@@ -690,6 +779,11 @@ function createSnow(options) {
690
779
  if (rafId) window.cancelAnimationFrame(rafId);
691
780
  window.removeEventListener("resize", resize);
692
781
  document.removeEventListener("visibilitychange", handleVisibility);
782
+ if (options.mouseWind) {
783
+ window.removeEventListener("pointermove", handlePointerMove);
784
+ document.documentElement.removeEventListener("pointerleave", handlePointerLeave);
785
+ }
786
+ observer?.disconnect();
693
787
  canvas.remove();
694
788
  }
695
789
  };
@@ -884,16 +978,16 @@ function createToggleButton(options, initialActive, onToggle) {
884
978
  // src/presets.ts
885
979
  var DEFAULT_CONFIG = {
886
980
  preset: "classic",
887
- locale: "en",
888
981
  enabled: true,
889
982
  respectReducedMotion: true,
890
983
  schedule: false,
891
984
  snow: {
892
985
  enabled: true,
893
986
  density: "medium",
894
- contrasting: false,
987
+ contrasting: "auto",
895
988
  speed: 1,
896
989
  wind: true,
990
+ mouseWind: true,
897
991
  zIndex: 9990
898
992
  },
899
993
  lights: {
@@ -902,9 +996,11 @@ var DEFAULT_CONFIG = {
902
996
  backdrop: "transparent",
903
997
  bulbs: 32,
904
998
  palette: "classic",
999
+ animation: "twinkle",
905
1000
  interactive: true,
906
1001
  pushBody: false,
907
1002
  zIndex: 9995,
1003
+ ariaLabel: "Illuminate Christmas lights",
908
1004
  container: null
909
1005
  },
910
1006
  buttonBurst: {
@@ -929,51 +1025,75 @@ var DEFAULT_CONFIG = {
929
1025
  offset: 16,
930
1026
  persist: true,
931
1027
  storageKey: "snowies:enabled",
932
- labelOn: "Desactivar efectos navide\xF1os",
933
- labelOff: "Activar efectos navide\xF1os",
934
- textOn: "Navidad",
935
- textOff: "Pausado",
1028
+ labelOn: "Disable Christmas effects",
1029
+ labelOff: "Enable Christmas effects",
1030
+ textOn: "Holiday",
1031
+ textOff: "Paused",
936
1032
  zIndex: 9999
937
1033
  }
938
1034
  };
939
1035
  var PRESETS = {
940
1036
  classic: {
941
- snow: { enabled: true, density: "medium", contrasting: false },
942
- lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
1037
+ snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
1038
+ lights: {
1039
+ enabled: true,
1040
+ position: "fixed",
1041
+ backdrop: "transparent",
1042
+ palette: "classic",
1043
+ animation: "twinkle"
1044
+ },
943
1045
  buttonBurst: { enabled: true },
944
1046
  buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
945
1047
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
946
1048
  },
947
1049
  minimal: {
948
- snow: { enabled: true, density: "light", contrasting: false, speed: 0.85 },
1050
+ snow: { enabled: true, density: "light", contrasting: "auto", speed: 0.85, mouseWind: false },
949
1051
  lights: { enabled: false },
950
1052
  buttonBurst: { enabled: false },
951
1053
  buttonSnow: { enabled: false },
952
1054
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
953
1055
  },
954
1056
  festive: {
955
- snow: { enabled: true, density: "heavy", contrasting: false, speed: 1.1 },
956
- lights: { enabled: true, position: "fixed", backdrop: "pine", palette: "classic" },
1057
+ snow: { enabled: true, density: "heavy", contrasting: "auto", speed: 1.1, mouseWind: true },
1058
+ lights: {
1059
+ enabled: true,
1060
+ position: "fixed",
1061
+ backdrop: "pine",
1062
+ palette: "classic",
1063
+ animation: "wave"
1064
+ },
957
1065
  buttonBurst: { enabled: true, particles: 56, crystals: true },
958
1066
  buttonSnow: { enabled: true, mode: "manual", style: "fluffy" },
959
1067
  toggleButton: { enabled: true, variant: "pill", theme: "festive" }
960
1068
  },
961
1069
  light: {
962
- snow: { enabled: true, density: "medium", contrasting: true },
963
- lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "ice" },
1070
+ snow: { enabled: true, density: "medium", contrasting: true, mouseWind: true },
1071
+ lights: {
1072
+ enabled: true,
1073
+ position: "fixed",
1074
+ backdrop: "transparent",
1075
+ palette: "ice",
1076
+ animation: "twinkle"
1077
+ },
964
1078
  buttonBurst: { enabled: true },
965
1079
  buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
966
1080
  toggleButton: { enabled: true, variant: "icon", theme: "light" }
967
1081
  },
968
1082
  "lights-only": {
969
1083
  snow: { enabled: false },
970
- lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
1084
+ lights: {
1085
+ enabled: true,
1086
+ position: "fixed",
1087
+ backdrop: "transparent",
1088
+ palette: "classic",
1089
+ animation: "twinkle"
1090
+ },
971
1091
  buttonBurst: { enabled: false },
972
1092
  buttonSnow: { enabled: false },
973
1093
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
974
1094
  },
975
1095
  "snow-only": {
976
- snow: { enabled: true, density: "medium", contrasting: false },
1096
+ snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
977
1097
  lights: { enabled: false },
978
1098
  buttonBurst: { enabled: false },
979
1099
  buttonSnow: { enabled: false },
@@ -981,40 +1101,6 @@ var PRESETS = {
981
1101
  }
982
1102
  };
983
1103
 
984
- // src/utils/i18n.ts
985
- var MESSAGES = {
986
- en: {
987
- toggleLabelOn: "Disable Christmas effects",
988
- toggleLabelOff: "Enable Christmas effects",
989
- toggleTextOn: "Holiday",
990
- toggleTextOff: "Paused",
991
- lightsAriaLabel: "Illuminate Christmas lights"
992
- },
993
- es: {
994
- toggleLabelOn: "Desactivar efectos navide\xF1os",
995
- toggleLabelOff: "Activar efectos navide\xF1os",
996
- toggleTextOn: "Navidad",
997
- toggleTextOff: "Pausado",
998
- lightsAriaLabel: "Hacer brillar las luces navide\xF1as"
999
- }
1000
- };
1001
- function resolveLocale(locale = "auto") {
1002
- if (locale === "es" || locale === "en") return locale;
1003
- if (typeof document !== "undefined") {
1004
- const docLang = document.documentElement?.lang?.toLowerCase();
1005
- if (docLang) {
1006
- return docLang.startsWith("es") ? "es" : "en";
1007
- }
1008
- }
1009
- if (typeof navigator !== "undefined" && navigator.language) {
1010
- return navigator.language.toLowerCase().startsWith("es") ? "es" : "en";
1011
- }
1012
- return "en";
1013
- }
1014
- function getMessages(locale = "auto") {
1015
- return MESSAGES[resolveLocale(locale)];
1016
- }
1017
-
1018
1104
  // src/utils/schedule.ts
1019
1105
  var DATE_RE = /^(?:(\d{4})-)?(\d{1,2})-(\d{1,2})$/;
1020
1106
  function parseDateSpec(spec) {
@@ -1075,33 +1161,18 @@ function resolveConfig(options = {}, previous) {
1075
1161
  const presetName = options.preset ?? previous?.preset ?? DEFAULT_CONFIG.preset;
1076
1162
  const presetDef = options.preset ? PRESETS[presetName] ?? {} : previous ? {} : PRESETS[presetName] ?? {};
1077
1163
  const base = previous && !options.preset ? previous : DEFAULT_CONFIG;
1078
- const locale = resolveLocale(options.locale ?? previous?.locale ?? "auto");
1079
- const msg = MESSAGES[locale];
1080
- const localeChanged = !previous || options.locale !== void 0 || options.preset !== void 0;
1081
- const lights = mergeFeature(base.lights, presetDef.lights, options.lights);
1082
- const userLights = typeof options.lights === "object" ? options.lights : void 0;
1083
- if (localeChanged && !userLights?.ariaLabel) {
1084
- lights.ariaLabel = msg.lightsAriaLabel;
1085
- }
1086
1164
  const toggleButton = mergeFeature(base.toggleButton, presetDef.toggleButton, options.toggleButton);
1087
1165
  const userToggle = typeof options.toggleButton === "object" ? options.toggleButton : void 0;
1088
- if (localeChanged) {
1089
- if (!userToggle?.labelOn) toggleButton.labelOn = msg.toggleLabelOn;
1090
- if (!userToggle?.labelOff) toggleButton.labelOff = msg.toggleLabelOff;
1091
- if (!userToggle?.textOn) toggleButton.textOn = msg.toggleTextOn;
1092
- if (!userToggle?.textOff) toggleButton.textOff = msg.toggleTextOff;
1093
- }
1094
1166
  if (userToggle?.style && base.toggleButton.style) {
1095
1167
  toggleButton.style = { ...base.toggleButton.style, ...userToggle.style };
1096
1168
  }
1097
1169
  return {
1098
1170
  preset: presetName,
1099
- locale,
1100
1171
  enabled: options.enabled ?? base.enabled,
1101
1172
  respectReducedMotion: options.respectReducedMotion ?? base.respectReducedMotion,
1102
1173
  schedule: options.schedule !== void 0 ? options.schedule : base.schedule,
1103
1174
  snow: mergeFeature(base.snow, presetDef.snow, options.snow),
1104
- lights,
1175
+ lights: mergeFeature(base.lights, presetDef.lights, options.lights),
1105
1176
  buttonBurst: mergeFeature(base.buttonBurst, presetDef.buttonBurst, options.buttonBurst),
1106
1177
  buttonSnow: mergeFeature(base.buttonSnow, presetDef.buttonSnow, options.buttonSnow),
1107
1178
  toggleButton,
@@ -1254,6 +1325,6 @@ function createSnowies(options = {}) {
1254
1325
  return controller;
1255
1326
  }
1256
1327
 
1257
- export { DEFAULT_CONFIG, MESSAGES, PRESETS, createButtonBurst, createButtonSnow, createLights, createSnow, createSnowies, createToggleButton, getMessages, isWithinSchedule, resolveLocale };
1258
- //# sourceMappingURL=chunk-FUI4H26T.js.map
1259
- //# sourceMappingURL=chunk-FUI4H26T.js.map
1328
+ export { DEFAULT_CONFIG, PRESETS, createButtonBurst, createButtonSnow, createLights, createSnow, createSnowies, createToggleButton, isWithinSchedule };
1329
+ //# sourceMappingURL=chunk-XZHF76OT.js.map
1330
+ //# sourceMappingURL=chunk-XZHF76OT.js.map