snowies 0.2.0 → 0.4.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/README.md +35 -24
- package/dist/auto.cjs +176 -26
- 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 -4
- package/dist/auto.js.map +1 -1
- package/dist/{chunk-MOABF6MI.js → chunk-NMPQEPAT.js} +146 -25
- package/dist/chunk-NMPQEPAT.js.map +1 -0
- package/dist/index.cjs +144 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/snowies.global.js +44 -36
- package/dist/snowies.global.js.map +1 -1
- package/dist/{types-DQkmf0l1.d.cts → types-DE9NRAb4.d.cts} +19 -7
- package/dist/{types-DQkmf0l1.d.ts → types-DE9NRAb4.d.ts} +19 -7
- package/package.json +1 -1
- package/dist/chunk-MOABF6MI.js.map +0 -1
package/dist/index.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; }
|
|
@@ -386,7 +389,7 @@ function createLights(options) {
|
|
|
386
389
|
radial-gradient(ellipse at 50% 35%, var(--bulb-core) 5%, var(--bulb-color) 80%);
|
|
387
390
|
box-shadow: 0 0 5px var(--bulb-color), 0 0 12px var(--bulb-color);
|
|
388
391
|
will-change: opacity, transform;
|
|
389
|
-
|
|
392
|
+
${glassAnimCss}
|
|
390
393
|
transition: transform 0.25s ease, opacity 0.25s ease;
|
|
391
394
|
}
|
|
392
395
|
.filament {
|
|
@@ -408,7 +411,7 @@ function createLights(options) {
|
|
|
408
411
|
opacity: 0.2;
|
|
409
412
|
pointer-events: none;
|
|
410
413
|
will-change: opacity;
|
|
411
|
-
|
|
414
|
+
${haloAnimCss}
|
|
412
415
|
transition: opacity 0.25s ease;
|
|
413
416
|
}
|
|
414
417
|
.lamp.is-near .glass,
|
|
@@ -434,6 +437,14 @@ function createLights(options) {
|
|
|
434
437
|
from { opacity: 0.12; }
|
|
435
438
|
to { opacity: 0.34; }
|
|
436
439
|
}
|
|
440
|
+
@keyframes glass-wave {
|
|
441
|
+
0%, 58%, 100% { opacity: 0.58; transform: scale(0.97); }
|
|
442
|
+
22% { opacity: 1; transform: scale(1.1); }
|
|
443
|
+
}
|
|
444
|
+
@keyframes halo-wave {
|
|
445
|
+
0%, 58%, 100% { opacity: 0.08; }
|
|
446
|
+
22% { opacity: 0.52; }
|
|
447
|
+
}
|
|
437
448
|
@media (max-width: 640px) {
|
|
438
449
|
.lamp:nth-of-type(n + ${mobileCutoff + 1}) { display: none; }
|
|
439
450
|
}
|
|
@@ -443,9 +454,10 @@ function createLights(options) {
|
|
|
443
454
|
`;
|
|
444
455
|
const strip = document.createElement(options.interactive ? "button" : "div");
|
|
445
456
|
strip.className = "strip";
|
|
457
|
+
strip.setAttribute("data-animation", animMode);
|
|
446
458
|
if (options.interactive) {
|
|
447
459
|
strip.setAttribute("type", "button");
|
|
448
|
-
strip.setAttribute("aria-label",
|
|
460
|
+
strip.setAttribute("aria-label", options.ariaLabel || "Illuminate Christmas lights");
|
|
449
461
|
} else {
|
|
450
462
|
strip.setAttribute("aria-hidden", "true");
|
|
451
463
|
}
|
|
@@ -464,6 +476,7 @@ function createLights(options) {
|
|
|
464
476
|
lamp.style.setProperty("--bulb-color", c.color);
|
|
465
477
|
lamp.style.setProperty("--bulb-core", c.core);
|
|
466
478
|
lamp.style.setProperty("--bulb-delay", `${i * -0.43}s`);
|
|
479
|
+
lamp.style.setProperty("--wave-delay", `${(i * -0.1).toFixed(2)}s`);
|
|
467
480
|
lamp.style.setProperty("--bulb-duration", `${3.4 + i % 5 * 0.35}s`);
|
|
468
481
|
lamp.style.setProperty("--bulb-cord", `${4 + i % 3 * 2}px`);
|
|
469
482
|
lamp.style.setProperty("--bulb-tilt", `${i % 2 ? 5 : -5}deg`);
|
|
@@ -546,6 +559,37 @@ function createPrng(initialSeed = 202611) {
|
|
|
546
559
|
return seed / 4294967296;
|
|
547
560
|
};
|
|
548
561
|
}
|
|
562
|
+
function parseRgbLuminance(color) {
|
|
563
|
+
const match = /rgba?\(\s*(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)[,\s]+(\d+(?:\.\d+)?)(?:\s*[,/]\s*(\d*(?:\.\d+)?))?\s*\)/i.exec(
|
|
564
|
+
color
|
|
565
|
+
);
|
|
566
|
+
if (!match) return null;
|
|
567
|
+
const alpha = match[4] !== void 0 && match[4] !== "" ? Number(match[4]) : 1;
|
|
568
|
+
if (Number.isNaN(alpha) || alpha < 0.1) return null;
|
|
569
|
+
const r = Number(match[1]);
|
|
570
|
+
const g = Number(match[2]);
|
|
571
|
+
const b = Number(match[3]);
|
|
572
|
+
return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
573
|
+
}
|
|
574
|
+
function detectLightBackground() {
|
|
575
|
+
if (typeof window === "undefined" || typeof document === "undefined") return false;
|
|
576
|
+
const candidates = [document.body, document.documentElement];
|
|
577
|
+
for (const el of candidates) {
|
|
578
|
+
if (!el) continue;
|
|
579
|
+
const bg = window.getComputedStyle(el).backgroundColor;
|
|
580
|
+
const lum = parseRgbLuminance(bg);
|
|
581
|
+
if (lum !== null) {
|
|
582
|
+
return lum > 0.55;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (typeof window.matchMedia === "function") {
|
|
586
|
+
return window.matchMedia("(prefers-color-scheme: light)").matches;
|
|
587
|
+
}
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
function resolveContrasting(setting) {
|
|
591
|
+
return setting === "auto" ? detectLightBackground() : Boolean(setting);
|
|
592
|
+
}
|
|
549
593
|
function createFlakeSprite(contrasting, soft) {
|
|
550
594
|
if (typeof document === "undefined") return null;
|
|
551
595
|
const size = soft ? 32 : 20;
|
|
@@ -594,8 +638,18 @@ function createSnow(options) {
|
|
|
594
638
|
return { destroy() {
|
|
595
639
|
} };
|
|
596
640
|
}
|
|
597
|
-
|
|
598
|
-
|
|
641
|
+
let isContrasting = resolveContrasting(options.contrasting);
|
|
642
|
+
let sharpSprite = createFlakeSprite(isContrasting, false);
|
|
643
|
+
let softSprite = createFlakeSprite(isContrasting, true);
|
|
644
|
+
const refreshContrasting = () => {
|
|
645
|
+
if (options.contrasting !== "auto") return;
|
|
646
|
+
const next = detectLightBackground();
|
|
647
|
+
if (next !== isContrasting) {
|
|
648
|
+
isContrasting = next;
|
|
649
|
+
sharpSprite = createFlakeSprite(isContrasting, false);
|
|
650
|
+
softSprite = createFlakeSprite(isContrasting, true);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
599
653
|
let width = window.innerWidth;
|
|
600
654
|
let height = window.innerHeight;
|
|
601
655
|
let flakes = [];
|
|
@@ -603,6 +657,8 @@ function createSnow(options) {
|
|
|
603
657
|
let lastTime = 0;
|
|
604
658
|
let paused = document.visibilityState === "hidden";
|
|
605
659
|
let destroyed = false;
|
|
660
|
+
let targetWind = 0;
|
|
661
|
+
let currentWind = 0;
|
|
606
662
|
const initFlakes = () => {
|
|
607
663
|
const random = createPrng(202611);
|
|
608
664
|
const count = resolveCount(options.density, width);
|
|
@@ -641,10 +697,18 @@ function createSnow(options) {
|
|
|
641
697
|
const dt = Math.min((now - lastTime) / 1e3, 0.05);
|
|
642
698
|
lastTime = now;
|
|
643
699
|
const t = now / 1e3;
|
|
700
|
+
if (options.mouseWind) {
|
|
701
|
+
currentWind += (targetWind - currentWind) * Math.min(1, dt * 3.2);
|
|
702
|
+
}
|
|
644
703
|
ctx.clearRect(0, 0, width, height);
|
|
645
704
|
for (let i = 0; i < flakes.length; i++) {
|
|
646
705
|
const f = flakes[i];
|
|
647
706
|
f.y += f.speedY * dt;
|
|
707
|
+
if (options.mouseWind && Math.abs(currentWind) > 2e-3) {
|
|
708
|
+
f.x += currentWind * 58 * (0.45 + f.layer * 0.42) * dt;
|
|
709
|
+
if (f.x < -24) f.x += width + 48;
|
|
710
|
+
else if (f.x > width + 24) f.x -= width + 48;
|
|
711
|
+
}
|
|
648
712
|
const xOffset = options.wind ? Math.sin(t * f.driftFreq + f.phase) * f.driftAmp : 0;
|
|
649
713
|
const drawX = f.x + xOffset;
|
|
650
714
|
if (f.y > height + f.radius * 2) {
|
|
@@ -660,7 +724,7 @@ function createSnow(options) {
|
|
|
660
724
|
const drawSize = f.radius * (f.layer === 2 ? 3.2 : 2.5);
|
|
661
725
|
ctx.drawImage(sprite, drawX - drawSize / 2, f.y - drawSize / 2, drawSize, drawSize);
|
|
662
726
|
} else {
|
|
663
|
-
ctx.fillStyle =
|
|
727
|
+
ctx.fillStyle = isContrasting ? "#d7edff" : "#ffffff";
|
|
664
728
|
ctx.beginPath();
|
|
665
729
|
ctx.arc(drawX, f.y, f.radius, 0, Math.PI * 2);
|
|
666
730
|
ctx.fill();
|
|
@@ -680,9 +744,33 @@ function createSnow(options) {
|
|
|
680
744
|
rafId = window.requestAnimationFrame(render);
|
|
681
745
|
}
|
|
682
746
|
};
|
|
747
|
+
const handlePointerMove = (event) => {
|
|
748
|
+
targetWind = (event.clientX / Math.max(1, width) - 0.5) * 2;
|
|
749
|
+
};
|
|
750
|
+
const handlePointerLeave = () => {
|
|
751
|
+
targetWind = 0;
|
|
752
|
+
};
|
|
683
753
|
resize();
|
|
684
754
|
window.addEventListener("resize", resize, { passive: true });
|
|
685
755
|
document.addEventListener("visibilitychange", handleVisibility);
|
|
756
|
+
if (options.mouseWind) {
|
|
757
|
+
window.addEventListener("pointermove", handlePointerMove, { passive: true });
|
|
758
|
+
document.documentElement.addEventListener("pointerleave", handlePointerLeave, { passive: true });
|
|
759
|
+
}
|
|
760
|
+
let observer = null;
|
|
761
|
+
if (options.contrasting === "auto" && typeof MutationObserver !== "undefined") {
|
|
762
|
+
observer = new MutationObserver(refreshContrasting);
|
|
763
|
+
observer.observe(document.documentElement, {
|
|
764
|
+
attributes: true,
|
|
765
|
+
attributeFilter: ["class", "style", "data-theme"]
|
|
766
|
+
});
|
|
767
|
+
if (document.body) {
|
|
768
|
+
observer.observe(document.body, {
|
|
769
|
+
attributes: true,
|
|
770
|
+
attributeFilter: ["class", "style", "data-theme"]
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
}
|
|
686
774
|
if (!paused) {
|
|
687
775
|
rafId = window.requestAnimationFrame(render);
|
|
688
776
|
}
|
|
@@ -692,6 +780,11 @@ function createSnow(options) {
|
|
|
692
780
|
if (rafId) window.cancelAnimationFrame(rafId);
|
|
693
781
|
window.removeEventListener("resize", resize);
|
|
694
782
|
document.removeEventListener("visibilitychange", handleVisibility);
|
|
783
|
+
if (options.mouseWind) {
|
|
784
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
785
|
+
document.documentElement.removeEventListener("pointerleave", handlePointerLeave);
|
|
786
|
+
}
|
|
787
|
+
observer?.disconnect();
|
|
695
788
|
canvas.remove();
|
|
696
789
|
}
|
|
697
790
|
};
|
|
@@ -892,9 +985,10 @@ var DEFAULT_CONFIG = {
|
|
|
892
985
|
snow: {
|
|
893
986
|
enabled: true,
|
|
894
987
|
density: "medium",
|
|
895
|
-
contrasting:
|
|
988
|
+
contrasting: "auto",
|
|
896
989
|
speed: 1,
|
|
897
990
|
wind: true,
|
|
991
|
+
mouseWind: true,
|
|
898
992
|
zIndex: 9990
|
|
899
993
|
},
|
|
900
994
|
lights: {
|
|
@@ -903,9 +997,11 @@ var DEFAULT_CONFIG = {
|
|
|
903
997
|
backdrop: "transparent",
|
|
904
998
|
bulbs: 32,
|
|
905
999
|
palette: "classic",
|
|
1000
|
+
animation: "twinkle",
|
|
906
1001
|
interactive: true,
|
|
907
1002
|
pushBody: false,
|
|
908
1003
|
zIndex: 9995,
|
|
1004
|
+
ariaLabel: "Illuminate Christmas lights",
|
|
909
1005
|
container: null
|
|
910
1006
|
},
|
|
911
1007
|
buttonBurst: {
|
|
@@ -930,51 +1026,75 @@ var DEFAULT_CONFIG = {
|
|
|
930
1026
|
offset: 16,
|
|
931
1027
|
persist: true,
|
|
932
1028
|
storageKey: "snowies:enabled",
|
|
933
|
-
labelOn: "
|
|
934
|
-
labelOff: "
|
|
935
|
-
textOn: "
|
|
936
|
-
textOff: "
|
|
1029
|
+
labelOn: "Disable Christmas effects",
|
|
1030
|
+
labelOff: "Enable Christmas effects",
|
|
1031
|
+
textOn: "Holiday",
|
|
1032
|
+
textOff: "Paused",
|
|
937
1033
|
zIndex: 9999
|
|
938
1034
|
}
|
|
939
1035
|
};
|
|
940
1036
|
var PRESETS = {
|
|
941
1037
|
classic: {
|
|
942
|
-
snow: { enabled: true, density: "medium", contrasting:
|
|
943
|
-
lights: {
|
|
1038
|
+
snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
|
|
1039
|
+
lights: {
|
|
1040
|
+
enabled: true,
|
|
1041
|
+
position: "fixed",
|
|
1042
|
+
backdrop: "transparent",
|
|
1043
|
+
palette: "classic",
|
|
1044
|
+
animation: "twinkle"
|
|
1045
|
+
},
|
|
944
1046
|
buttonBurst: { enabled: true },
|
|
945
1047
|
buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
|
|
946
1048
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
947
1049
|
},
|
|
948
1050
|
minimal: {
|
|
949
|
-
snow: { enabled: true, density: "light", contrasting:
|
|
1051
|
+
snow: { enabled: true, density: "light", contrasting: "auto", speed: 0.85, mouseWind: false },
|
|
950
1052
|
lights: { enabled: false },
|
|
951
1053
|
buttonBurst: { enabled: false },
|
|
952
1054
|
buttonSnow: { enabled: false },
|
|
953
1055
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
954
1056
|
},
|
|
955
1057
|
festive: {
|
|
956
|
-
snow: { enabled: true, density: "heavy", contrasting:
|
|
957
|
-
lights: {
|
|
1058
|
+
snow: { enabled: true, density: "heavy", contrasting: "auto", speed: 1.1, mouseWind: true },
|
|
1059
|
+
lights: {
|
|
1060
|
+
enabled: true,
|
|
1061
|
+
position: "fixed",
|
|
1062
|
+
backdrop: "pine",
|
|
1063
|
+
palette: "classic",
|
|
1064
|
+
animation: "wave"
|
|
1065
|
+
},
|
|
958
1066
|
buttonBurst: { enabled: true, particles: 56, crystals: true },
|
|
959
1067
|
buttonSnow: { enabled: true, mode: "manual", style: "fluffy" },
|
|
960
1068
|
toggleButton: { enabled: true, variant: "pill", theme: "festive" }
|
|
961
1069
|
},
|
|
962
1070
|
light: {
|
|
963
|
-
snow: { enabled: true, density: "medium", contrasting: true },
|
|
964
|
-
lights: {
|
|
1071
|
+
snow: { enabled: true, density: "medium", contrasting: true, mouseWind: true },
|
|
1072
|
+
lights: {
|
|
1073
|
+
enabled: true,
|
|
1074
|
+
position: "fixed",
|
|
1075
|
+
backdrop: "transparent",
|
|
1076
|
+
palette: "ice",
|
|
1077
|
+
animation: "twinkle"
|
|
1078
|
+
},
|
|
965
1079
|
buttonBurst: { enabled: true },
|
|
966
1080
|
buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
|
|
967
1081
|
toggleButton: { enabled: true, variant: "icon", theme: "light" }
|
|
968
1082
|
},
|
|
969
1083
|
"lights-only": {
|
|
970
1084
|
snow: { enabled: false },
|
|
971
|
-
lights: {
|
|
1085
|
+
lights: {
|
|
1086
|
+
enabled: true,
|
|
1087
|
+
position: "fixed",
|
|
1088
|
+
backdrop: "transparent",
|
|
1089
|
+
palette: "classic",
|
|
1090
|
+
animation: "twinkle"
|
|
1091
|
+
},
|
|
972
1092
|
buttonBurst: { enabled: false },
|
|
973
1093
|
buttonSnow: { enabled: false },
|
|
974
1094
|
toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
|
|
975
1095
|
},
|
|
976
1096
|
"snow-only": {
|
|
977
|
-
snow: { enabled: true, density: "medium", contrasting:
|
|
1097
|
+
snow: { enabled: true, density: "medium", contrasting: "auto", mouseWind: true },
|
|
978
1098
|
lights: { enabled: false },
|
|
979
1099
|
buttonBurst: { enabled: false },
|
|
980
1100
|
buttonSnow: { enabled: false },
|
|
@@ -1002,8 +1122,9 @@ function resolveConfig(options = {}, previous) {
|
|
|
1002
1122
|
const presetDef = options.preset ? PRESETS[presetName] ?? {} : previous ? {} : PRESETS[presetName] ?? {};
|
|
1003
1123
|
const base = previous && !options.preset ? previous : DEFAULT_CONFIG;
|
|
1004
1124
|
const toggleButton = mergeFeature(base.toggleButton, presetDef.toggleButton, options.toggleButton);
|
|
1005
|
-
|
|
1006
|
-
|
|
1125
|
+
const userToggle = typeof options.toggleButton === "object" ? options.toggleButton : void 0;
|
|
1126
|
+
if (userToggle?.style && base.toggleButton.style) {
|
|
1127
|
+
toggleButton.style = { ...base.toggleButton.style, ...userToggle.style };
|
|
1007
1128
|
}
|
|
1008
1129
|
return {
|
|
1009
1130
|
preset: presetName,
|