snowies 0.1.0 → 0.3.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/index.cjs CHANGED
@@ -1,9 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  // src/modules/buttonBurst.ts
4
- var SNOW_CAP_SVG = encodeURIComponent(
5
- `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 14" preserveAspectRatio="none"><path d="M0 10 Q10 2 22 7 T48 6 T76 8 T102 5 T120 9 L120 0 L0 0 Z" fill="#ffffff"/><path d="M0 10 Q10 2 22 7 T48 6 T76 8 T102 5 T120 9" fill="none" stroke="#d7edff" stroke-width="1.2"/></svg>`
6
- );
7
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>`;
8
5
  function createButtonBurst(options) {
9
6
  if (typeof document === "undefined" || typeof window === "undefined") {
@@ -62,33 +59,6 @@ function createButtonBurst(options) {
62
59
  `;
63
60
  shadow.appendChild(style);
64
61
  document.body.appendChild(overlayHost);
65
- let snowCapStyleEl = null;
66
- if (options.snowCap && options.snowCapSelector) {
67
- const capSelectors = options.snowCapSelector.split(",").map((s) => s.trim()).filter(Boolean);
68
- if (capSelectors.length > 0) {
69
- const baseSelector = capSelectors.join(", ");
70
- const afterSelector = capSelectors.map((s) => `${s}::after`).join(", ");
71
- snowCapStyleEl = document.createElement("style");
72
- snowCapStyleEl.setAttribute("data-snowies-snowcap", "");
73
- snowCapStyleEl.textContent = `
74
- ${baseSelector} {
75
- position: relative;
76
- }
77
- ${afterSelector} {
78
- content: "";
79
- position: absolute;
80
- top: -3px;
81
- left: 8px;
82
- right: 8px;
83
- height: 9px;
84
- pointer-events: none;
85
- background: url("data:image/svg+xml,${SNOW_CAP_SVG}") no-repeat top center / 100% 100%;
86
- filter: drop-shadow(0 1px 2px rgba(71, 130, 180, 0.45));
87
- }
88
- `;
89
- document.head.appendChild(snowCapStyleEl);
90
- }
91
- }
92
62
  const activeTimers = /* @__PURE__ */ new Set();
93
63
  const isMobile = () => window.innerWidth <= 640;
94
64
  const trigger = (target) => {
@@ -154,7 +124,81 @@ function createButtonBurst(options) {
154
124
  activeTimers.forEach((id) => window.clearTimeout(id));
155
125
  activeTimers.clear();
156
126
  overlayHost.remove();
157
- snowCapStyleEl?.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();
158
202
  }
159
203
  };
160
204
  }
@@ -401,7 +445,7 @@ function createLights(options) {
401
445
  strip.className = "strip";
402
446
  if (options.interactive) {
403
447
  strip.setAttribute("type", "button");
404
- strip.setAttribute("aria-label", "Hacer brillar las luces navide\xF1as");
448
+ strip.setAttribute("aria-label", options.ariaLabel ?? "Illuminate Christmas lights");
405
449
  } else {
406
450
  strip.setAttribute("aria-hidden", "true");
407
451
  }
@@ -842,6 +886,7 @@ function createToggleButton(options, initialActive, onToggle) {
842
886
  // src/presets.ts
843
887
  var DEFAULT_CONFIG = {
844
888
  preset: "classic",
889
+ locale: "en",
845
890
  enabled: true,
846
891
  respectReducedMotion: true,
847
892
  schedule: false,
@@ -869,10 +914,14 @@ var DEFAULT_CONFIG = {
869
914
  selector: 'button, [role="button"], [data-snowies-burst]',
870
915
  particles: 48,
871
916
  crystals: true,
872
- snowCap: true,
873
- snowCapSelector: "[data-snowies-btn], .snowies-btn",
874
917
  zIndex: 9998
875
918
  },
919
+ buttonSnow: {
920
+ enabled: true,
921
+ mode: "manual",
922
+ style: "subtle",
923
+ selector: "[data-snowies-snow], [data-snowies-btn], .snowies-snow"
924
+ },
876
925
  toggleButton: {
877
926
  enabled: true,
878
927
  position: "bottom-right",
@@ -893,41 +942,81 @@ var PRESETS = {
893
942
  classic: {
894
943
  snow: { enabled: true, density: "medium", contrasting: false },
895
944
  lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
896
- buttonBurst: { enabled: true, snowCap: true },
945
+ buttonBurst: { enabled: true },
946
+ buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
897
947
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
898
948
  },
899
949
  minimal: {
900
950
  snow: { enabled: true, density: "light", contrasting: false, speed: 0.85 },
901
951
  lights: { enabled: false },
902
- buttonBurst: { enabled: false, snowCap: false },
952
+ buttonBurst: { enabled: false },
953
+ buttonSnow: { enabled: false },
903
954
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
904
955
  },
905
956
  festive: {
906
957
  snow: { enabled: true, density: "heavy", contrasting: false, speed: 1.1 },
907
958
  lights: { enabled: true, position: "fixed", backdrop: "pine", palette: "classic" },
908
- buttonBurst: { enabled: true, particles: 56, crystals: true, snowCap: true },
959
+ buttonBurst: { enabled: true, particles: 56, crystals: true },
960
+ buttonSnow: { enabled: true, mode: "manual", style: "fluffy" },
909
961
  toggleButton: { enabled: true, variant: "pill", theme: "festive" }
910
962
  },
911
963
  light: {
912
964
  snow: { enabled: true, density: "medium", contrasting: true },
913
965
  lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "ice" },
914
- buttonBurst: { enabled: true, snowCap: true },
966
+ buttonBurst: { enabled: true },
967
+ buttonSnow: { enabled: true, mode: "manual", style: "subtle" },
915
968
  toggleButton: { enabled: true, variant: "icon", theme: "light" }
916
969
  },
917
970
  "lights-only": {
918
971
  snow: { enabled: false },
919
972
  lights: { enabled: true, position: "fixed", backdrop: "transparent", palette: "classic" },
920
- buttonBurst: { enabled: false, snowCap: false },
973
+ buttonBurst: { enabled: false },
974
+ buttonSnow: { enabled: false },
921
975
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
922
976
  },
923
977
  "snow-only": {
924
978
  snow: { enabled: true, density: "medium", contrasting: false },
925
979
  lights: { enabled: false },
926
- buttonBurst: { enabled: false, snowCap: false },
980
+ buttonBurst: { enabled: false },
981
+ buttonSnow: { enabled: false },
927
982
  toggleButton: { enabled: true, variant: "icon", theme: "minimal" }
928
983
  }
929
984
  };
930
985
 
986
+ // src/utils/i18n.ts
987
+ var MESSAGES = {
988
+ en: {
989
+ toggleLabelOn: "Disable Christmas effects",
990
+ toggleLabelOff: "Enable Christmas effects",
991
+ toggleTextOn: "Holiday",
992
+ toggleTextOff: "Paused",
993
+ lightsAriaLabel: "Illuminate Christmas lights"
994
+ },
995
+ es: {
996
+ toggleLabelOn: "Desactivar efectos navide\xF1os",
997
+ toggleLabelOff: "Activar efectos navide\xF1os",
998
+ toggleTextOn: "Navidad",
999
+ toggleTextOff: "Pausado",
1000
+ lightsAriaLabel: "Hacer brillar las luces navide\xF1as"
1001
+ }
1002
+ };
1003
+ function resolveLocale(locale = "auto") {
1004
+ if (locale === "es" || locale === "en") return locale;
1005
+ if (typeof document !== "undefined") {
1006
+ const docLang = document.documentElement?.lang?.toLowerCase();
1007
+ if (docLang) {
1008
+ return docLang.startsWith("es") ? "es" : "en";
1009
+ }
1010
+ }
1011
+ if (typeof navigator !== "undefined" && navigator.language) {
1012
+ return navigator.language.toLowerCase().startsWith("es") ? "es" : "en";
1013
+ }
1014
+ return "en";
1015
+ }
1016
+ function getMessages(locale = "auto") {
1017
+ return MESSAGES[resolveLocale(locale)];
1018
+ }
1019
+
931
1020
  // src/utils/config.ts
932
1021
  function mergeFeature(base, presetOverride, userOverride) {
933
1022
  let result = { ...base };
@@ -947,18 +1036,35 @@ function resolveConfig(options = {}, previous) {
947
1036
  const presetName = options.preset ?? previous?.preset ?? DEFAULT_CONFIG.preset;
948
1037
  const presetDef = options.preset ? PRESETS[presetName] ?? {} : previous ? {} : PRESETS[presetName] ?? {};
949
1038
  const base = previous && !options.preset ? previous : DEFAULT_CONFIG;
1039
+ const locale = resolveLocale(options.locale ?? previous?.locale ?? "auto");
1040
+ const msg = MESSAGES[locale];
1041
+ const localeChanged = !previous || options.locale !== void 0 || options.preset !== void 0;
1042
+ const lights = mergeFeature(base.lights, presetDef.lights, options.lights);
1043
+ const userLights = typeof options.lights === "object" ? options.lights : void 0;
1044
+ if (localeChanged && !userLights?.ariaLabel) {
1045
+ lights.ariaLabel = msg.lightsAriaLabel;
1046
+ }
950
1047
  const toggleButton = mergeFeature(base.toggleButton, presetDef.toggleButton, options.toggleButton);
951
- if (typeof options.toggleButton === "object" && options.toggleButton?.style && base.toggleButton.style) {
952
- toggleButton.style = { ...base.toggleButton.style, ...options.toggleButton.style };
1048
+ const userToggle = typeof options.toggleButton === "object" ? options.toggleButton : void 0;
1049
+ if (localeChanged) {
1050
+ if (!userToggle?.labelOn) toggleButton.labelOn = msg.toggleLabelOn;
1051
+ if (!userToggle?.labelOff) toggleButton.labelOff = msg.toggleLabelOff;
1052
+ if (!userToggle?.textOn) toggleButton.textOn = msg.toggleTextOn;
1053
+ if (!userToggle?.textOff) toggleButton.textOff = msg.toggleTextOff;
1054
+ }
1055
+ if (userToggle?.style && base.toggleButton.style) {
1056
+ toggleButton.style = { ...base.toggleButton.style, ...userToggle.style };
953
1057
  }
954
1058
  return {
955
1059
  preset: presetName,
1060
+ locale,
956
1061
  enabled: options.enabled ?? base.enabled,
957
1062
  respectReducedMotion: options.respectReducedMotion ?? base.respectReducedMotion,
958
1063
  schedule: options.schedule !== void 0 ? options.schedule : base.schedule,
959
1064
  snow: mergeFeature(base.snow, presetDef.snow, options.snow),
960
- lights: mergeFeature(base.lights, presetDef.lights, options.lights),
1065
+ lights,
961
1066
  buttonBurst: mergeFeature(base.buttonBurst, presetDef.buttonBurst, options.buttonBurst),
1067
+ buttonSnow: mergeFeature(base.buttonSnow, presetDef.buttonSnow, options.buttonSnow),
962
1068
  toggleButton,
963
1069
  onChange: options.onChange ?? base.onChange
964
1070
  };
@@ -1034,6 +1140,7 @@ function createSnowies(options = {}) {
1034
1140
  let snowMod = null;
1035
1141
  let lightsMod = null;
1036
1142
  let burstMod = null;
1143
+ let buttonSnowMod = null;
1037
1144
  let toggleMod = null;
1038
1145
  const computeState = () => {
1039
1146
  const inSchedule = isWithinSchedule(config.schedule);
@@ -1062,6 +1169,8 @@ function createSnowies(options = {}) {
1062
1169
  lightsMod = null;
1063
1170
  burstMod?.destroy();
1064
1171
  burstMod = null;
1172
+ buttonSnowMod?.destroy();
1173
+ buttonSnowMod = null;
1065
1174
  };
1066
1175
  const destroyToggle = () => {
1067
1176
  toggleMod?.destroy();
@@ -1075,6 +1184,7 @@ function createSnowies(options = {}) {
1075
1184
  if (config.snow.enabled) snowMod = createSnow(config.snow);
1076
1185
  if (config.lights.enabled) lightsMod = createLights(config.lights);
1077
1186
  if (config.buttonBurst.enabled) burstMod = createButtonBurst(config.buttonBurst);
1187
+ if (config.buttonSnow.enabled) buttonSnowMod = createButtonSnow(config.buttonSnow);
1078
1188
  }
1079
1189
  const shouldShowToggle = state.inSchedule && config.enabled && config.toggleButton.enabled;
1080
1190
  destroyToggle();
@@ -1121,7 +1231,7 @@ function createSnowies(options = {}) {
1121
1231
  if (burstMod) {
1122
1232
  burstMod.trigger(target);
1123
1233
  } else {
1124
- const temp = createButtonBurst({ ...config.buttonBurst, snowCap: false });
1234
+ const temp = createButtonBurst(config.buttonBurst);
1125
1235
  temp.trigger(target);
1126
1236
  window.setTimeout(() => temp.destroy(), 1500);
1127
1237
  }
@@ -1147,12 +1257,16 @@ function createSnowies(options = {}) {
1147
1257
  }
1148
1258
 
1149
1259
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
1260
+ exports.MESSAGES = MESSAGES;
1150
1261
  exports.PRESETS = PRESETS;
1151
1262
  exports.createButtonBurst = createButtonBurst;
1263
+ exports.createButtonSnow = createButtonSnow;
1152
1264
  exports.createLights = createLights;
1153
1265
  exports.createSnow = createSnow;
1154
1266
  exports.createSnowies = createSnowies;
1155
1267
  exports.createToggleButton = createToggleButton;
1268
+ exports.getMessages = getMessages;
1156
1269
  exports.isWithinSchedule = isWithinSchedule;
1270
+ exports.resolveLocale = resolveLocale;
1157
1271
  //# sourceMappingURL=index.cjs.map
1158
1272
  //# sourceMappingURL=index.cjs.map