wulf.js 1.9.1 → 1.9.3

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.
Files changed (71) hide show
  1. package/README.md +160 -21
  2. package/changelog.md +66 -0
  3. package/dist/focus-trap.esm.js +62 -9
  4. package/dist/focus-trap.esm.js.map +2 -2
  5. package/dist/focus-trap.global.js +64 -11
  6. package/dist/focus-trap.global.js.map +2 -2
  7. package/dist/focus-trap.global.min.js +3 -3
  8. package/dist/focus-trap.global.min.js.map +3 -3
  9. package/dist/index.esm.js +947 -101
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +949 -103
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +3 -3
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.esm.js +66 -22
  16. package/dist/mask.esm.js.map +2 -2
  17. package/dist/mask.global.js +68 -24
  18. package/dist/mask.global.js.map +2 -2
  19. package/dist/mask.global.min.js +3 -3
  20. package/dist/mask.global.min.js.map +3 -3
  21. package/dist/masonry.esm.js +96 -40
  22. package/dist/masonry.esm.js.map +2 -2
  23. package/dist/masonry.global.js +98 -42
  24. package/dist/masonry.global.js.map +2 -2
  25. package/dist/masonry.global.min.js +3 -3
  26. package/dist/masonry.global.min.js.map +3 -3
  27. package/dist/scroll.esm.js +66 -28
  28. package/dist/scroll.esm.js.map +2 -2
  29. package/dist/scroll.global.js +68 -30
  30. package/dist/scroll.global.js.map +2 -2
  31. package/dist/scroll.global.min.js +4 -4
  32. package/dist/scroll.global.min.js.map +3 -3
  33. package/dist/shortcut.esm.js +631 -0
  34. package/dist/shortcut.esm.js.map +7 -0
  35. package/dist/shortcut.global.js +657 -0
  36. package/dist/shortcut.global.js.map +7 -0
  37. package/dist/shortcut.global.min.js +3 -0
  38. package/dist/shortcut.global.min.js.map +7 -0
  39. package/dist/toast.css +1 -1
  40. package/dist/toast.css.map +2 -2
  41. package/dist/toast.esm.js +109 -44
  42. package/dist/toast.esm.js.map +2 -2
  43. package/dist/toast.global.js +111 -46
  44. package/dist/toast.global.js.map +2 -2
  45. package/dist/toast.global.min.js +4 -4
  46. package/dist/toast.global.min.js.map +3 -3
  47. package/dist/types/focus-trap/FocusTrap.d.ts +2 -0
  48. package/dist/types/index.d.ts +2 -0
  49. package/dist/types/mask/AmountEngine.d.ts +1 -0
  50. package/dist/types/mask/BaseInputMask.d.ts +4 -0
  51. package/dist/types/mask/InputAmountMask.d.ts +1 -0
  52. package/dist/types/mask/InputMask.d.ts +1 -0
  53. package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
  54. package/dist/types/shortcut/ShortcutManager.d.ts +95 -0
  55. package/dist/types/shortcut/index.d.ts +4 -0
  56. package/dist/types/shortcut/types.d.ts +101 -0
  57. package/dist/types/toast/ToastInstance.d.ts +1 -1
  58. package/dist/types/toast/types.d.ts +5 -0
  59. package/package.json +20 -11
  60. package/dist/focus-trap.cjs.js +0 -430
  61. package/dist/focus-trap.cjs.js.map +0 -7
  62. package/dist/index.cjs.js +0 -5365
  63. package/dist/index.cjs.js.map +0 -7
  64. package/dist/mask.cjs.js +0 -3086
  65. package/dist/mask.cjs.js.map +0 -7
  66. package/dist/masonry.cjs.js +0 -858
  67. package/dist/masonry.cjs.js.map +0 -7
  68. package/dist/scroll.cjs.js +0 -823
  69. package/dist/scroll.cjs.js.map +0 -7
  70. package/dist/toast.cjs.js +0 -715
  71. package/dist/toast.cjs.js.map +0 -7
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var Wulf = (() => {
2
+ var __WulfIIFE = (() => {
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -36,8 +36,10 @@ var Wulf = (() => {
36
36
  MaskKeyboard: () => MaskKeyboard,
37
37
  Masonry: () => masonry_exports,
38
38
  Scroll: () => scroll_exports,
39
+ Shortcut: () => shortcut_exports,
39
40
  Toast: () => toast_exports,
40
41
  WulfFocusTrap: () => FocusTrap,
42
+ WulfShortcut: () => ShortcutManager,
41
43
  createI18nManager: () => createI18nManager,
42
44
  default: () => mask_default,
43
45
  resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
@@ -309,7 +311,8 @@ var Wulf = (() => {
309
311
  "data-disabled",
310
312
  "data-mask-align",
311
313
  "data-align",
312
- "placeholder"
314
+ "placeholder",
315
+ "type"
313
316
  ]
314
317
  };
315
318
  this.mutationObserver.observe(this.wrapper, config);
@@ -357,7 +360,12 @@ var Wulf = (() => {
357
360
  } else if (attrName === "data-mask-select-on-focus") {
358
361
  this.options.selectAllOnFocus = this.getAttr("data-mask-select-on-focus") === "true";
359
362
  } else if (attrName === "data-mask-copy-raw") {
360
- this.options.copyRaw = this.getAttr("data-mask-copy-raw") === "true";
363
+ this.options.copyRaw = this.input.type === "password" ? false : this.getAttr("data-mask-copy-raw") === "true";
364
+ } else if (attrName === "type") {
365
+ if (this.input.type === "password") {
366
+ this.options.copyRaw = false;
367
+ this.onPasswordModeDetected();
368
+ }
361
369
  } else if (attrName === "data-mask-align" || attrName === "data-align") {
362
370
  const align = this.getAttr("data-mask-align") || this.getAttr("data-align");
363
371
  if (align !== (this.options.align ?? null)) {
@@ -612,6 +620,11 @@ var Wulf = (() => {
612
620
  getSpecificAuditWarnings() {
613
621
  return [];
614
622
  }
623
+ /**
624
+ * Crochet appelé lorsque l'input bascule dynamiquement en type="password" (ex: toggle afficher/masquer).
625
+ */
626
+ onPasswordModeDetected() {
627
+ }
615
628
  /**
616
629
  * Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
617
630
  */
@@ -696,11 +709,11 @@ var Wulf = (() => {
696
709
  compile(newPattern) {
697
710
  if (newPattern !== void 0) {
698
711
  if (Array.isArray(newPattern)) {
699
- this.patterns = [...newPattern];
712
+ this.patterns = newPattern.slice(0, 32).map((p) => String(p ?? "").slice(0, 512));
700
713
  this.pattern = this.patterns[0] || "";
701
714
  } else {
702
715
  this.patterns = [];
703
- this.pattern = newPattern;
716
+ this.pattern = String(newPattern ?? "").slice(0, 512);
704
717
  }
705
718
  }
706
719
  if (this.patterns.length > 0) {
@@ -851,7 +864,8 @@ var Wulf = (() => {
851
864
  return engine.extractRaw(input);
852
865
  }
853
866
  }
854
- const str = String(input ?? "");
867
+ const maxInputLen = Math.max(4096, this.slots.length * 4);
868
+ const str = String(input ?? "").slice(0, maxInputLen);
855
869
  if (!str) return "";
856
870
  let raw = "";
857
871
  let inputIdx = 0;
@@ -920,7 +934,8 @@ var Wulf = (() => {
920
934
  return engine.format(rawValue);
921
935
  }
922
936
  }
923
- const rawStr = String(rawValue ?? "");
937
+ const maxInputLen = Math.max(4096, this.slots.length * 4);
938
+ const rawStr = String(rawValue ?? "").slice(0, maxInputLen);
924
939
  if (!this.slots.length) return rawStr;
925
940
  const cleanRaw = this.extractRaw(rawStr);
926
941
  if (cleanRaw.length === 0) {
@@ -1423,6 +1438,9 @@ var Wulf = (() => {
1423
1438
  extractRawSnippet(snippet) {
1424
1439
  return this.engine.extractRaw(snippet);
1425
1440
  }
1441
+ onPasswordModeDetected() {
1442
+ this.history.clear();
1443
+ }
1426
1444
  /**
1427
1445
  * Formate statiquement une valeur selon un masque donné sans nécessiter d'élément DOM.
1428
1446
  *
@@ -1791,7 +1809,7 @@ var Wulf = (() => {
1791
1809
  }
1792
1810
  e.preventDefault();
1793
1811
  this.history.updateCurrentCursor(this.input.selectionStart ?? 0);
1794
- const rawPasted = e.clipboardData?.getData("text") || "";
1812
+ const rawPasted = (e.clipboardData?.getData("text") || "").slice(0, 4096);
1795
1813
  const pastedText = rawPasted.trim();
1796
1814
  if (!pastedText) return;
1797
1815
  const minPos = this.engine.getPrefixLength();
@@ -1943,7 +1961,10 @@ var Wulf = (() => {
1943
1961
  this.input.setSelectionRange(safeCursor, safeCursor);
1944
1962
  isCompleted = this.isComplete();
1945
1963
  this.wrapper.classList.toggle("is-complete", isCompleted);
1946
- if (!this.isUndoingRedoing && this.input.type !== "password") {
1964
+ if (this.input.type === "password") {
1965
+ this.options.copyRaw = false;
1966
+ this.history.clear();
1967
+ } else if (!this.isUndoingRedoing) {
1947
1968
  this.history.push(this.getRawValue(), safeCursor);
1948
1969
  }
1949
1970
  } finally {
@@ -1994,7 +2015,10 @@ var Wulf = (() => {
1994
2015
  }
1995
2016
  this.isNotifying = true;
1996
2017
  try {
1997
- while (this.input.value !== this.lastValue || this.hasPendingNotification || forceNotify) {
2018
+ let iterations = 0;
2019
+ const MAX_NOTIFICATION_ITERATIONS = 10;
2020
+ while ((this.input.value !== this.lastValue || this.hasPendingNotification || forceNotify) && iterations < MAX_NOTIFICATION_ITERATIONS) {
2021
+ iterations++;
1998
2022
  this.hasPendingNotification = false;
1999
2023
  forceNotify = false;
2000
2024
  const valToNotify = this.input.value;
@@ -2042,13 +2066,15 @@ var Wulf = (() => {
2042
2066
  currency = options.unit;
2043
2067
  }
2044
2068
  const defaultPosition = currency === "$" || currency === "\xA3" || currency === "\xA5" ? "prefix" : "suffix";
2069
+ const rawDecimals = options.decimals !== void 0 ? Number(options.decimals) : 2;
2070
+ const safeDecimals = Number.isFinite(rawDecimals) ? Math.min(20, Math.max(0, Math.floor(rawDecimals))) : 2;
2045
2071
  this.options = {
2046
- currency,
2047
- unit: options.unit ?? currency,
2072
+ currency: String(currency).slice(0, 32),
2073
+ unit: String(options.unit ?? currency).slice(0, 32),
2048
2074
  currencyPosition: options.currencyPosition ?? defaultPosition,
2049
- decimals: options.decimals !== void 0 ? Math.max(0, options.decimals) : 2,
2050
- decimalSeparator: options.decimalSeparator ?? ",",
2051
- thousandSeparator: options.thousandSeparator ?? "\xA0",
2075
+ decimals: safeDecimals,
2076
+ decimalSeparator: String(options.decimalSeparator ?? ",").slice(0, 4) || ",",
2077
+ thousandSeparator: String(options.thousandSeparator ?? "\xA0").slice(0, 4),
2052
2078
  // Espace insécable
2053
2079
  allowNegative: options.allowNegative ?? false,
2054
2080
  min: options.min ?? -Infinity,
@@ -2059,7 +2085,7 @@ var Wulf = (() => {
2059
2085
  * Analyse et nettoie une saisie utilisateur pour extraire ses composantes numériques.
2060
2086
  */
2061
2087
  parse(input) {
2062
- let str = input.trim();
2088
+ let str = String(input ?? "").slice(0, 512).trim();
2063
2089
  let isNegative = false;
2064
2090
  if (this.options.allowNegative && str.includes("-")) {
2065
2091
  isNegative = true;
@@ -2100,7 +2126,9 @@ var Wulf = (() => {
2100
2126
  * @param rawCursor Position actuelle du curseur dans l'input natif
2101
2127
  */
2102
2128
  format(input, rawCursor = input.length, padDecimals = false) {
2103
- if (!input || input.trim() === "" || input === this.options.currency.trim()) {
2129
+ const safeInput = String(input ?? "").slice(0, 512);
2130
+ const safeRawCursor = Math.max(0, Math.min(rawCursor, safeInput.length));
2131
+ if (!safeInput || safeInput.trim() === "" || safeInput === this.options.currency.trim()) {
2104
2132
  return {
2105
2133
  formatted: "",
2106
2134
  rawNumber: null,
@@ -2109,10 +2137,10 @@ var Wulf = (() => {
2109
2137
  isValid: true
2110
2138
  };
2111
2139
  }
2112
- const prefixBeforeCursor = input.substring(0, rawCursor);
2140
+ const prefixBeforeCursor = safeInput.substring(0, safeRawCursor);
2113
2141
  const digitsBeforeCursor = prefixBeforeCursor.replace(/\D/g, "").length;
2114
2142
  const hadDecimalBeforeCursor = this.options.decimals > 0 && /[,.]/.test(prefixBeforeCursor);
2115
- const { isNegative, integerPart, decimalPart, hasDecimal } = this.parse(input);
2143
+ const { isNegative, integerPart, decimalPart, hasDecimal } = this.parse(safeInput);
2116
2144
  let effectiveDecimal = decimalPart;
2117
2145
  let effectiveHasDecimal = hasDecimal;
2118
2146
  if (padDecimals && this.options.decimals > 0 && (integerPart || decimalPart !== null)) {
@@ -2152,7 +2180,7 @@ var Wulf = (() => {
2152
2180
  isValid: true
2153
2181
  };
2154
2182
  }
2155
- const formattedInteger = (integerPart || "0").replace(/\B(?=(\d{3})+(?!\d))/g, this.options.thousandSeparator);
2183
+ const formattedInteger = this.formatThousands(integerPart || "0");
2156
2184
  let numberCore = formattedInteger;
2157
2185
  if (effectiveHasDecimal && this.options.decimals > 0) {
2158
2186
  numberCore += this.options.decimalSeparator + (effectiveDecimal ?? "");
@@ -2225,6 +2253,18 @@ var Wulf = (() => {
2225
2253
  const str = typeof value === "number" ? value.toString() : value;
2226
2254
  return engine.format(str).formatted;
2227
2255
  }
2256
+ formatThousands(digits) {
2257
+ const sep = this.options.thousandSeparator;
2258
+ if (!sep || digits.length <= 3) return digits;
2259
+ const parts = [];
2260
+ let i = digits.length;
2261
+ while (i > 0) {
2262
+ const start = Math.max(0, i - 3);
2263
+ parts.push(digits.slice(start, i));
2264
+ i = start;
2265
+ }
2266
+ return parts.reverse().join(sep);
2267
+ }
2228
2268
  escapeRegExp(string) {
2229
2269
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2230
2270
  }
@@ -2275,6 +2315,9 @@ var Wulf = (() => {
2275
2315
  if (!p.integerPart && !p.decimalPart) return "";
2276
2316
  return (p.isNegative ? "-" : "") + (p.integerPart || "0") + (p.decimalPart ? "." + p.decimalPart : "");
2277
2317
  }
2318
+ onPasswordModeDetected() {
2319
+ this.history.clear();
2320
+ }
2278
2321
  /**
2279
2322
  * Formate statiquement une valeur sans nécessiter d'élément DOM.
2280
2323
  */
@@ -2352,7 +2395,10 @@ var Wulf = (() => {
2352
2395
  const result = this.engine.format(val, cursor);
2353
2396
  this.setNativeValue(result.formatted);
2354
2397
  this.input.setSelectionRange(result.cursor, result.cursor);
2355
- if (!this.isUndoingRedoing && this.input.type !== "password") {
2398
+ if (this.input.type === "password") {
2399
+ this.options.copyRaw = false;
2400
+ this.history.clear();
2401
+ } else if (!this.isUndoingRedoing) {
2356
2402
  this.history.push(result.rawValue, result.cursor);
2357
2403
  }
2358
2404
  this.updateGhost(result);
@@ -2646,7 +2692,7 @@ var Wulf = (() => {
2646
2692
  * Retourne l'ensemble des domaines correspondant à la saisie courante.
2647
2693
  */
2648
2694
  getMatchingDomains(input) {
2649
- const val = input ?? "";
2695
+ const val = String(input ?? "").slice(0, 512);
2650
2696
  if (!val.includes("@")) {
2651
2697
  return this.defaultDomain ? [this.defaultDomain] : [];
2652
2698
  }
@@ -2668,7 +2714,7 @@ var Wulf = (() => {
2668
2714
  * @param matchIndex Index de la suggestion à sélectionner si plusieurs domaines/TLD correspondent (permet le cyclage)
2669
2715
  */
2670
2716
  getSuggestion(input, matchIndex = 0) {
2671
- const val = input ?? "";
2717
+ const val = String(input ?? "").slice(0, 512);
2672
2718
  if (!val.includes("@")) {
2673
2719
  if (this.defaultDomain) {
2674
2720
  return {
@@ -3188,35 +3234,49 @@ var Wulf = (() => {
3188
3234
  };
3189
3235
 
3190
3236
  // src/common/i18n.ts
3237
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
3238
+ function isSafeKey(key) {
3239
+ return Boolean(key) && !FORBIDDEN_KEYS.has(key);
3240
+ }
3191
3241
  function normalizeLocaleCode(locale) {
3192
- return locale.trim().toLowerCase().replace(/_/g, "-");
3242
+ const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
3243
+ return isSafeKey(norm) ? norm : "";
3193
3244
  }
3194
3245
  function getPrimaryLanguage(normalizedLocale) {
3195
3246
  const dashIndex = normalizedLocale.indexOf("-");
3196
- return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
3247
+ const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
3248
+ return primary && isSafeKey(primary) ? primary : null;
3197
3249
  }
3198
3250
  function assignDefined(target, source) {
3199
- if (!source) return target;
3251
+ if (!source || typeof source !== "object") return target;
3200
3252
  for (const key of Object.keys(source)) {
3201
- if (source[key] !== void 0) {
3253
+ if (isSafeKey(String(key)) && Object.prototype.hasOwnProperty.call(source, key) && source[key] !== void 0) {
3202
3254
  target[key] = source[key];
3203
3255
  }
3204
3256
  }
3205
3257
  return target;
3206
3258
  }
3207
3259
  function createI18nManager(defaultLocale, locales) {
3208
- const fallbackLocale = normalizeLocaleCode(defaultLocale);
3209
- const initialLocales = {};
3260
+ const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
3261
+ const initialLocales = /* @__PURE__ */ Object.create(null);
3210
3262
  for (const [loc, dict] of Object.entries(locales)) {
3211
- initialLocales[normalizeLocaleCode(loc)] = { ...dict };
3263
+ const norm = normalizeLocaleCode(loc);
3264
+ if (norm) {
3265
+ initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
3266
+ }
3212
3267
  }
3213
3268
  let currentLocale = fallbackLocale;
3214
- let activeLocales = { ...initialLocales };
3215
- let globalOverrides = {};
3269
+ let activeLocales = /* @__PURE__ */ Object.create(null);
3270
+ for (const [loc, dict] of Object.entries(initialLocales)) {
3271
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
3272
+ }
3273
+ let globalOverrides = /* @__PURE__ */ Object.create(null);
3216
3274
  function resolveActiveDictionaries() {
3217
3275
  const dicts = [];
3218
- const exact = activeLocales[currentLocale];
3219
- if (exact) dicts.push(exact);
3276
+ if (isSafeKey(currentLocale)) {
3277
+ const exact = activeLocales[currentLocale];
3278
+ if (exact) dicts.push(exact);
3279
+ }
3220
3280
  const primary = getPrimaryLanguage(currentLocale);
3221
3281
  if (primary && activeLocales[primary]) {
3222
3282
  dicts.push(activeLocales[primary]);
@@ -3225,24 +3285,33 @@ var Wulf = (() => {
3225
3285
  }
3226
3286
  return {
3227
3287
  setLocale(locale) {
3228
- if (locale && locale.trim()) {
3229
- currentLocale = normalizeLocaleCode(locale);
3288
+ if (locale && typeof locale === "string" && locale.trim()) {
3289
+ const norm = normalizeLocaleCode(locale);
3290
+ if (norm) {
3291
+ currentLocale = norm;
3292
+ }
3230
3293
  }
3231
3294
  },
3232
3295
  getLocale() {
3233
3296
  return currentLocale;
3234
3297
  },
3235
3298
  registerLocale(locale, translations) {
3236
- if (!locale || !locale.trim() || !translations) return;
3299
+ if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
3237
3300
  const norm = normalizeLocaleCode(locale);
3238
- activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
3301
+ if (!norm) return;
3302
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
3303
+ activeLocales[norm] = assignDefined(base, translations);
3239
3304
  },
3240
3305
  setI18n(overrides) {
3241
- if (!overrides) return;
3242
- globalOverrides = assignDefined({ ...globalOverrides }, overrides);
3306
+ if (!overrides || typeof overrides !== "object") return;
3307
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
3308
+ globalOverrides = assignDefined(base, overrides);
3243
3309
  },
3244
3310
  t(key, instanceOverride) {
3245
- if (instanceOverride && instanceOverride[key] !== void 0) {
3311
+ if (!isSafeKey(String(key))) {
3312
+ return "";
3313
+ }
3314
+ if (instanceOverride && typeof instanceOverride === "object" && Object.prototype.hasOwnProperty.call(instanceOverride, key) && instanceOverride[key] !== void 0) {
3246
3315
  return String(instanceOverride[key]);
3247
3316
  }
3248
3317
  if (globalOverrides[key] !== void 0) {
@@ -3273,10 +3342,10 @@ var Wulf = (() => {
3273
3342
  },
3274
3343
  reset() {
3275
3344
  currentLocale = fallbackLocale;
3276
- globalOverrides = {};
3277
- activeLocales = {};
3345
+ globalOverrides = /* @__PURE__ */ Object.create(null);
3346
+ activeLocales = /* @__PURE__ */ Object.create(null);
3278
3347
  for (const [loc, dict] of Object.entries(initialLocales)) {
3279
- activeLocales[loc] = { ...dict };
3348
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
3280
3349
  }
3281
3350
  }
3282
3351
  };
@@ -3320,21 +3389,36 @@ var Wulf = (() => {
3320
3389
  this.atTop = true;
3321
3390
  this.atRight = false;
3322
3391
  this.atLeft = true;
3323
- const resolvedElement = typeof element === "string" ? document.querySelector(element) : element;
3324
- if (!resolvedElement) {
3392
+ let resolvedElement = null;
3393
+ if (typeof element === "string") {
3394
+ try {
3395
+ resolvedElement = document.querySelector(element);
3396
+ } catch {
3397
+ resolvedElement = null;
3398
+ }
3399
+ } else {
3400
+ resolvedElement = element;
3401
+ }
3402
+ if (!resolvedElement || !(resolvedElement instanceof HTMLElement)) {
3325
3403
  throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
3326
3404
  }
3327
3405
  this.root = resolvedElement;
3328
3406
  this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
3407
+ const rawDelay = options?.autoHideDelay;
3408
+ const safeAutoHideDelay = typeof rawDelay === "number" && Number.isFinite(rawDelay) && rawDelay >= 0 ? rawDelay : 1e3;
3409
+ const rawMinThumb = options?.minThumbSize;
3410
+ const safeMinThumbSize = typeof rawMinThumb === "number" && Number.isFinite(rawMinThumb) && rawMinThumb > 0 ? rawMinThumb : 24;
3411
+ const rawEdge = options?.edgeThreshold;
3412
+ const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
3329
3413
  this.options = {
3330
3414
  axis: options?.axis || "y",
3331
3415
  autoHide: options?.autoHide ?? true,
3332
- autoHideDelay: options?.autoHideDelay ?? 1e3,
3416
+ autoHideDelay: safeAutoHideDelay,
3333
3417
  alwaysVisible: options?.alwaysVisible ?? false,
3334
3418
  ariaLabel: options?.ariaLabel || this.t("viewport"),
3335
3419
  i18n: options?.i18n || {},
3336
- minThumbSize: options?.minThumbSize ?? 24,
3337
- edgeThreshold: options?.edgeThreshold ?? 10,
3420
+ minThumbSize: safeMinThumbSize,
3421
+ edgeThreshold: safeEdgeThreshold,
3338
3422
  onScroll: options?.onScroll || (() => {
3339
3423
  }),
3340
3424
  onTotalScroll: options?.onTotalScroll || (() => {
@@ -3772,8 +3856,8 @@ var Wulf = (() => {
3772
3856
  targetLeft = target.left;
3773
3857
  }
3774
3858
  this.viewport.scrollTo({
3775
- top: targetTop !== void 0 ? Math.max(0, Math.min(maxTop, targetTop)) : void 0,
3776
- left: targetLeft !== void 0 ? Math.max(0, Math.min(maxLeft, targetLeft)) : void 0,
3859
+ top: targetTop !== void 0 && Number.isFinite(targetTop) ? Math.max(0, Math.min(maxTop, targetTop)) : void 0,
3860
+ left: targetLeft !== void 0 && Number.isFinite(targetLeft) ? Math.max(0, Math.min(maxLeft, targetLeft)) : void 0,
3777
3861
  behavior
3778
3862
  });
3779
3863
  }
@@ -3889,12 +3973,15 @@ var Wulf = (() => {
3889
3973
  */
3890
3974
  static parseGutter(gutterOption) {
3891
3975
  if (typeof gutterOption === "number") {
3892
- return { x: Math.max(0, gutterOption), y: Math.max(0, gutterOption) };
3976
+ const v = Number.isFinite(gutterOption) ? Math.max(0, gutterOption) : 0;
3977
+ return { x: v, y: v };
3893
3978
  }
3894
3979
  if (gutterOption && typeof gutterOption === "object") {
3980
+ const rawX = Number(gutterOption.x);
3981
+ const rawY = Number(gutterOption.y);
3895
3982
  return {
3896
- x: Math.max(0, Number(gutterOption.x) || 0),
3897
- y: Math.max(0, Number(gutterOption.y) || 0)
3983
+ x: Number.isFinite(rawX) ? Math.max(0, rawX) : 0,
3984
+ y: Number.isFinite(rawY) ? Math.max(0, rawY) : 0
3898
3985
  };
3899
3986
  }
3900
3987
  return { x: 0, y: 0 };
@@ -3903,22 +3990,37 @@ var Wulf = (() => {
3903
3990
  * Résout la largeur effective d'une colonne en pixels.
3904
3991
  */
3905
3992
  static resolveColumnWidth(container, firstItem, columnWidthOption) {
3906
- if (typeof columnWidthOption === "number" && columnWidthOption > 0) {
3993
+ if (typeof columnWidthOption === "number" && Number.isFinite(columnWidthOption) && columnWidthOption > 0) {
3907
3994
  return columnWidthOption;
3908
3995
  }
3909
3996
  if (typeof columnWidthOption === "string") {
3910
- const el = container.querySelector(columnWidthOption);
3911
- if (el) {
3912
- const w = el.getBoundingClientRect().width;
3913
- if (w > 0) return w;
3914
- }
3915
- const parsed = parseFloat(columnWidthOption);
3916
- if (!isNaN(parsed) && parsed > 0) {
3917
- if (columnWidthOption.endsWith("%")) {
3918
- const containerW2 = container.getBoundingClientRect().width;
3919
- return containerW2 * parsed / 100;
3997
+ const trimmed = columnWidthOption.trim();
3998
+ if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
3999
+ const parsed = parseFloat(trimmed);
4000
+ if (Number.isFinite(parsed) && parsed > 0) {
4001
+ if (trimmed.endsWith("%")) {
4002
+ const containerW2 = container.getBoundingClientRect().width;
4003
+ const resolvedPct = containerW2 * parsed / 100;
4004
+ if (resolvedPct > 0) return resolvedPct;
4005
+ } else {
4006
+ return parsed;
4007
+ }
4008
+ }
4009
+ } else if (trimmed) {
4010
+ let el = null;
4011
+ try {
4012
+ el = container.querySelector(trimmed);
4013
+ } catch {
4014
+ el = null;
4015
+ }
4016
+ if (el) {
4017
+ const w = el.getBoundingClientRect().width;
4018
+ if (Number.isFinite(w) && w > 0) return w;
4019
+ }
4020
+ const parsed = parseFloat(trimmed);
4021
+ if (Number.isFinite(parsed) && parsed > 0) {
4022
+ return parsed;
3920
4023
  }
3921
- return parsed;
3922
4024
  }
3923
4025
  }
3924
4026
  if (columnWidthOption instanceof HTMLElement) {
@@ -3972,8 +4074,13 @@ var Wulf = (() => {
3972
4074
  }
3973
4075
  const firstItem = items[0] || null;
3974
4076
  let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);
3975
- let cols = Math.floor((containerWidth + gutterX) / (colWidth + gutterX));
3976
- cols = Math.max(1, cols);
4077
+ const denom = colWidth + gutterX;
4078
+ let cols = denom > 0 ? Math.floor((containerWidth + gutterX) / denom) : 1;
4079
+ if (!Number.isFinite(cols) || cols < 1) {
4080
+ cols = 1;
4081
+ } else if (cols > 1e3) {
4082
+ cols = 1e3;
4083
+ }
3977
4084
  if (!options.columnWidth && cols > 1) {
3978
4085
  colWidth = (containerWidth - (cols - 1) * gutterX) / cols;
3979
4086
  }
@@ -4102,7 +4209,12 @@ var Wulf = (() => {
4102
4209
  this.removeTimers = /* @__PURE__ */ new Set();
4103
4210
  this.pendingImageListeners = [];
4104
4211
  if (typeof target === "string") {
4105
- const el = document.querySelector(target);
4212
+ let el = null;
4213
+ try {
4214
+ el = document.querySelector(target);
4215
+ } catch {
4216
+ el = null;
4217
+ }
4106
4218
  if (!el) {
4107
4219
  throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${target}"`);
4108
4220
  }
@@ -4190,7 +4302,12 @@ var Wulf = (() => {
4190
4302
  */
4191
4303
  applyTransitionDuration() {
4192
4304
  const dur = this.options.transitionDuration;
4193
- const durValue = typeof dur === "number" ? `${dur}ms` : dur;
4305
+ let durValue = "300ms";
4306
+ if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
4307
+ durValue = `${dur}ms`;
4308
+ } else if (typeof dur === "string" && /^\s*\d+(\.\d+)?(ms|s)\s*$/i.test(dur)) {
4309
+ durValue = dur.trim();
4310
+ }
4194
4311
  this.root.style.setProperty("--wulf-masonry-duration", durValue);
4195
4312
  }
4196
4313
  /**
@@ -4536,6 +4653,13 @@ var Wulf = (() => {
4536
4653
 
4537
4654
  // src/toast/ToastInstance.ts
4538
4655
  var nextToastId = 1;
4656
+ function isSafeCssValue(val) {
4657
+ if (!val || typeof val !== "string" || val.length > 128) return false;
4658
+ return !/[;{}<>\\]|url\s*\(/i.test(val);
4659
+ }
4660
+ function sanitizeIconClasses(icon) {
4661
+ return icon.trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
4662
+ }
4539
4663
  var ToastInstance = class extends AuditableComponent {
4540
4664
  constructor(options, onDismiss) {
4541
4665
  super();
@@ -4605,26 +4729,29 @@ var Wulf = (() => {
4605
4729
  el.setAttribute("role", role);
4606
4730
  el.setAttribute("aria-live", role === "alert" ? "assertive" : "polite");
4607
4731
  el.setAttribute("aria-atomic", "true");
4608
- if (this.options.backgroundColor) {
4609
- el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor);
4732
+ if (this.options.backgroundColor && isSafeCssValue(this.options.backgroundColor)) {
4733
+ el.style.setProperty("--wulf-toast-bg", this.options.backgroundColor.trim());
4610
4734
  }
4611
- if (this.options.titleColor) {
4612
- el.style.setProperty("--wulf-toast-title-color", this.options.titleColor);
4735
+ if (this.options.titleColor && isSafeCssValue(this.options.titleColor)) {
4736
+ el.style.setProperty("--wulf-toast-title-color", this.options.titleColor.trim());
4613
4737
  }
4614
- if (this.options.textColor) {
4615
- el.style.setProperty("--wulf-toast-text-color", this.options.textColor);
4738
+ if (this.options.textColor && isSafeCssValue(this.options.textColor)) {
4739
+ el.style.setProperty("--wulf-toast-text-color", this.options.textColor.trim());
4616
4740
  }
4617
- if (this.options.iconColor) {
4618
- el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor);
4741
+ if (this.options.iconColor && isSafeCssValue(this.options.iconColor)) {
4742
+ el.style.setProperty("--wulf-toast-icon-color", this.options.iconColor.trim());
4619
4743
  }
4620
- if (this.options.closeButtonColor) {
4621
- el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor);
4744
+ if (this.options.closeButtonColor && isSafeCssValue(this.options.closeButtonColor)) {
4745
+ el.style.setProperty("--wulf-toast-close-color", this.options.closeButtonColor.trim());
4622
4746
  }
4623
- if (this.options.icon && this.options.icon.trim() !== "") {
4624
- const iconContainer = document.createElement("span");
4625
- iconContainer.className = `wulf-toast-icon ${this.options.icon.trim()}`;
4626
- iconContainer.setAttribute("aria-hidden", "true");
4627
- el.appendChild(iconContainer);
4747
+ if (this.options.icon && typeof this.options.icon === "string" && this.options.icon.trim() !== "") {
4748
+ const safeIcon = sanitizeIconClasses(this.options.icon);
4749
+ if (safeIcon) {
4750
+ const iconContainer = document.createElement("span");
4751
+ iconContainer.className = `wulf-toast-icon ${safeIcon}`;
4752
+ iconContainer.setAttribute("aria-hidden", "true");
4753
+ el.appendChild(iconContainer);
4754
+ }
4628
4755
  }
4629
4756
  const content = document.createElement("div");
4630
4757
  content.className = "wulf-toast-content";
@@ -4659,14 +4786,22 @@ var Wulf = (() => {
4659
4786
  });
4660
4787
  el.appendChild(closeBtn);
4661
4788
  }
4789
+ if (this.options.progressBar && this.remainingTime > 0) {
4790
+ el.style.setProperty("--wulf-toast-duration", `${this.remainingTime}ms`);
4791
+ const progressBar = document.createElement("div");
4792
+ progressBar.className = "wulf-toast-progress";
4793
+ progressBar.setAttribute("aria-hidden", "true");
4794
+ el.appendChild(progressBar);
4795
+ }
4662
4796
  return el;
4663
4797
  }
4664
4798
  /**
4665
4799
  * Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
4666
- * Utilise document.createTextNode et des éléments <br> créés proprement.
4800
+ * Utilise document.createTextNode et des éléments <br> créés proprement (plafonné contre le DoS DOM).
4667
4801
  */
4668
4802
  appendTextWithLineBreaks(container, text) {
4669
- const lines = text.split(/\r\n|\r|\n/);
4803
+ const safeText = String(text ?? "").slice(0, 4096);
4804
+ const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
4670
4805
  lines.forEach((line, index) => {
4671
4806
  if (index > 0) {
4672
4807
  container.appendChild(document.createElement("br"));
@@ -4713,6 +4848,7 @@ var Wulf = (() => {
4713
4848
  const elapsed = Date.now() - this.timerStartTime;
4714
4849
  this.remainingTime = Math.max(0, this.remainingTime - elapsed);
4715
4850
  this.isPaused = true;
4851
+ this.element.classList.add("is-paused");
4716
4852
  }
4717
4853
  /**
4718
4854
  * Reprend le compte à rebours
@@ -4720,6 +4856,7 @@ var Wulf = (() => {
4720
4856
  resumeTimer() {
4721
4857
  if (this._isClosed || this.remainingTime <= 0 || !this.isPaused) return;
4722
4858
  this.isPaused = false;
4859
+ this.element.classList.remove("is-paused");
4723
4860
  this.startTimer();
4724
4861
  }
4725
4862
  /**
@@ -4796,6 +4933,17 @@ var Wulf = (() => {
4796
4933
  };
4797
4934
 
4798
4935
  // src/toast/ToastManager.ts
4936
+ var VALID_POSITIONS = /* @__PURE__ */ new Set([
4937
+ "top-left",
4938
+ "top-center",
4939
+ "top-right",
4940
+ "bottom-left",
4941
+ "bottom-center",
4942
+ "bottom-right"
4943
+ ]);
4944
+ function normalizePosition(pos) {
4945
+ return pos && VALID_POSITIONS.has(pos) ? pos : "top-right";
4946
+ }
4799
4947
  var _ToastManager = class _ToastManager {
4800
4948
  constructor() {
4801
4949
  this.containers = /* @__PURE__ */ new Map();
@@ -4813,7 +4961,7 @@ var Wulf = (() => {
4813
4961
  * Ajoute et affiche une notification Toast.
4814
4962
  */
4815
4963
  add(toast) {
4816
- const position = toast.options.position || "top-right";
4964
+ const position = normalizePosition(toast.options.position);
4817
4965
  let list = this.activeToasts.get(position);
4818
4966
  if (!list) {
4819
4967
  list = [];
@@ -4830,11 +4978,12 @@ var Wulf = (() => {
4830
4978
  if (this.replaceTokens.get(position) !== token) {
4831
4979
  return;
4832
4980
  }
4833
- this.mountToast(toast, position);
4981
+ this.mountToast(toast, position, 5);
4834
4982
  });
4835
4983
  return;
4836
4984
  }
4837
- const maxToasts = typeof toast.options.maxToasts === "number" && toast.options.maxToasts > 0 ? toast.options.maxToasts : 5;
4985
+ const rawMax = toast.options.maxToasts;
4986
+ const maxToasts = typeof rawMax === "number" && Number.isFinite(rawMax) && rawMax > 0 ? Math.min(50, Math.max(1, Math.floor(rawMax))) : 5;
4838
4987
  if (list.length >= maxToasts) {
4839
4988
  const countToRemove = list.length - maxToasts + 1;
4840
4989
  const oldestItems = list.splice(0, countToRemove);
@@ -4842,18 +4991,28 @@ var Wulf = (() => {
4842
4991
  item.close("max-limit", true);
4843
4992
  }
4844
4993
  }
4845
- this.mountToast(toast, position);
4994
+ this.mountToast(toast, position, maxToasts);
4846
4995
  }
4847
4996
  /**
4848
4997
  * Insère l'élément toast dans le DOM et déclenche les callbacks et compteurs.
4849
4998
  */
4850
- mountToast(toast, position) {
4999
+ mountToast(toast, position, maxToasts = 5) {
4851
5000
  const container = this.getOrCreateContainer(position);
4852
5001
  let list = this.activeToasts.get(position);
4853
5002
  if (!list) {
4854
5003
  list = [];
4855
5004
  this.activeToasts.set(position, list);
4856
5005
  }
5006
+ const maxDomNodes = maxToasts + 10;
5007
+ if (container.children.length >= maxDomNodes) {
5008
+ const children = Array.from(container.children);
5009
+ for (const child of children) {
5010
+ if (container.children.length < maxDomNodes) break;
5011
+ if (child.classList.contains("wulf-toast-hiding") || child.classList.contains("wulf-toast-hiding-fast")) {
5012
+ child.remove();
5013
+ }
5014
+ }
5015
+ }
4857
5016
  container.appendChild(toast.element);
4858
5017
  list.push(toast);
4859
5018
  if (toast.options.onOpen) {
@@ -4869,7 +5028,7 @@ var Wulf = (() => {
4869
5028
  * Retire une notification de la pile et nettoie le conteneur s'il est vide.
4870
5029
  */
4871
5030
  remove(toast, _reason) {
4872
- const position = toast.options.position || "top-right";
5031
+ const position = normalizePosition(toast.options.position);
4873
5032
  const list = this.activeToasts.get(position);
4874
5033
  if (list) {
4875
5034
  const index = list.indexOf(toast);
@@ -5011,12 +5170,29 @@ var Wulf = (() => {
5011
5170
  "select:not([disabled])",
5012
5171
  "textarea:not([disabled])",
5013
5172
  "button:not([disabled])",
5173
+ "audio[controls]",
5174
+ "video[controls]",
5175
+ "details > summary:first-of-type",
5014
5176
  "iframe",
5015
5177
  "object",
5016
5178
  "embed",
5017
- '[contenteditable="true"]',
5179
+ '[contenteditable]:not([contenteditable="false"])',
5018
5180
  '[tabindex]:not([tabindex="-1"])'
5019
5181
  ].join(",");
5182
+ function safeCssEscape(value) {
5183
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") {
5184
+ return CSS.escape(value);
5185
+ }
5186
+ return String(value).replace(/["\\]/g, "\\$&");
5187
+ }
5188
+ function safeQuerySelector(root, selector) {
5189
+ if (!selector || typeof selector !== "string") return null;
5190
+ try {
5191
+ return root.querySelector(selector);
5192
+ } catch {
5193
+ return null;
5194
+ }
5195
+ }
5020
5196
  var trapStack = [];
5021
5197
  var FocusTrap = class extends AuditableComponent {
5022
5198
  constructor(target, options = {}) {
@@ -5028,7 +5204,7 @@ var Wulf = (() => {
5028
5204
  // Sentinelles anti-fuite de focus
5029
5205
  this.startSentinel = null;
5030
5206
  this.endSentinel = null;
5031
- const el = typeof target === "string" ? document.querySelector(target) : target;
5207
+ const el = typeof target === "string" ? safeQuerySelector(document, target) : target;
5032
5208
  if (!el || !(el instanceof HTMLElement)) {
5033
5209
  throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
5034
5210
  }
@@ -5068,7 +5244,7 @@ var Wulf = (() => {
5068
5244
  }
5069
5245
  if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
5070
5246
  const group = Array.from(
5071
- this.element.querySelectorAll(`input[type="radio"][name="${CSS.escape(el.name)}"]`)
5247
+ this.element.querySelectorAll(`input[type="radio"][name="${safeCssEscape(el.name)}"]`)
5072
5248
  );
5073
5249
  const checked = group.find((r) => r.checked);
5074
5250
  if (checked) {
@@ -5105,6 +5281,7 @@ var Wulf = (() => {
5105
5281
  document.addEventListener("keydown", this.handleKeyDownBound, true);
5106
5282
  document.addEventListener("focusin", this.handleFocusInBound, true);
5107
5283
  if (!this.options.allowOutsideClick) {
5284
+ document.addEventListener("pointerdown", this.handleClickOutsideBound, true);
5108
5285
  document.addEventListener("mousedown", this.handleClickOutsideBound, true);
5109
5286
  document.addEventListener("touchstart", this.handleClickOutsideBound, true);
5110
5287
  }
@@ -5130,6 +5307,7 @@ var Wulf = (() => {
5130
5307
  }
5131
5308
  document.removeEventListener("keydown", this.handleKeyDownBound, true);
5132
5309
  document.removeEventListener("focusin", this.handleFocusInBound, true);
5310
+ document.removeEventListener("pointerdown", this.handleClickOutsideBound, true);
5133
5311
  document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
5134
5312
  document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
5135
5313
  this.removeSentinels();
@@ -5199,8 +5377,34 @@ var Wulf = (() => {
5199
5377
  this.deactivate();
5200
5378
  }
5201
5379
  // --- Implémentation interne ---
5380
+ isEventInside(e, target) {
5381
+ if (target && this.element.contains(target)) {
5382
+ return true;
5383
+ }
5384
+ if (typeof e.composedPath === "function") {
5385
+ const path = e.composedPath();
5386
+ if (path.includes(this.element)) {
5387
+ return true;
5388
+ }
5389
+ }
5390
+ return false;
5391
+ }
5392
+ applySentinelStyles(el) {
5393
+ const s = el.style;
5394
+ s.position = "fixed";
5395
+ s.top = "0";
5396
+ s.left = "0";
5397
+ s.opacity = "0";
5398
+ s.pointerEvents = "none";
5399
+ s.width = "0";
5400
+ s.height = "0";
5401
+ }
5202
5402
  handleKeyDown(e) {
5203
5403
  if (!this.isActive()) return;
5404
+ if (this.element.isConnected === false) {
5405
+ this.deactivate();
5406
+ return;
5407
+ }
5204
5408
  if (e.key === "Escape" && this.options.escapeDeactivates) {
5205
5409
  e.preventDefault();
5206
5410
  e.stopPropagation();
@@ -5230,6 +5434,10 @@ var Wulf = (() => {
5230
5434
  }
5231
5435
  handleFocusIn(e) {
5232
5436
  if (!this.isActive()) return;
5437
+ if (this.element.isConnected === false) {
5438
+ this.deactivate();
5439
+ return;
5440
+ }
5233
5441
  const target = e.target;
5234
5442
  if (!target) return;
5235
5443
  if (target === this.startSentinel) {
@@ -5250,7 +5458,7 @@ var Wulf = (() => {
5250
5458
  }
5251
5459
  return;
5252
5460
  }
5253
- if (!this.element.contains(target)) {
5461
+ if (!this.isEventInside(e, target)) {
5254
5462
  const focusables = this.getFocusableElements();
5255
5463
  if (focusables.length > 0) {
5256
5464
  focusables[0].focus();
@@ -5264,8 +5472,12 @@ var Wulf = (() => {
5264
5472
  }
5265
5473
  handleClickOutside(e) {
5266
5474
  if (!this.isActive()) return;
5475
+ if (this.element.isConnected === false) {
5476
+ this.deactivate();
5477
+ return;
5478
+ }
5267
5479
  const target = e.target;
5268
- if (target && !this.element.contains(target)) {
5480
+ if (target && !this.isEventInside(e, target)) {
5269
5481
  e.preventDefault();
5270
5482
  e.stopPropagation();
5271
5483
  }
@@ -5276,14 +5488,14 @@ var Wulf = (() => {
5276
5488
  this.startSentinel.setAttribute("tabindex", "0");
5277
5489
  this.startSentinel.setAttribute("aria-hidden", "true");
5278
5490
  this.startSentinel.className = "wulf-sentinel-start";
5279
- this.startSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
5491
+ this.applySentinelStyles(this.startSentinel);
5280
5492
  }
5281
5493
  if (!this.endSentinel) {
5282
5494
  this.endSentinel = document.createElement("span");
5283
5495
  this.endSentinel.setAttribute("tabindex", "0");
5284
5496
  this.endSentinel.setAttribute("aria-hidden", "true");
5285
5497
  this.endSentinel.className = "wulf-sentinel-end";
5286
- this.endSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
5498
+ this.applySentinelStyles(this.endSentinel);
5287
5499
  }
5288
5500
  if (this.element.parentNode) {
5289
5501
  this.element.parentNode.insertBefore(this.startSentinel, this.element);
@@ -5321,7 +5533,7 @@ var Wulf = (() => {
5321
5533
  if (this.options.initialFocus === false) return;
5322
5534
  let targetEl = null;
5323
5535
  if (typeof this.options.initialFocus === "string") {
5324
- targetEl = this.element.querySelector(this.options.initialFocus);
5536
+ targetEl = safeQuerySelector(this.element, this.options.initialFocus);
5325
5537
  } else if (this.options.initialFocus instanceof HTMLElement) {
5326
5538
  targetEl = this.options.initialFocus;
5327
5539
  }
@@ -5345,7 +5557,7 @@ var Wulf = (() => {
5345
5557
  return;
5346
5558
  }
5347
5559
  if (this.options.fallbackReturnFocus) {
5348
- const fallback = typeof this.options.fallbackReturnFocus === "string" ? document.querySelector(this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
5560
+ const fallback = typeof this.options.fallbackReturnFocus === "string" ? safeQuerySelector(document, this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
5349
5561
  if (fallback && fallback.isConnected) {
5350
5562
  fallback.focus();
5351
5563
  }
@@ -5362,7 +5574,641 @@ var Wulf = (() => {
5362
5574
  FocusTrap
5363
5575
  });
5364
5576
  }
5577
+
5578
+ // src/shortcut/index.ts
5579
+ var shortcut_exports = {};
5580
+ __export(shortcut_exports, {
5581
+ ShortcutFormatter: () => ShortcutFormatter,
5582
+ ShortcutManager: () => ShortcutManager,
5583
+ default: () => ShortcutManager
5584
+ });
5585
+
5586
+ // src/shortcut/ShortcutFormatter.ts
5587
+ var ShortcutFormatter = class _ShortcutFormatter {
5588
+ /**
5589
+ * Détecte si l'environnement d'exécution actuel est un environnement Apple (macOS / iOS / iPadOS).
5590
+ */
5591
+ static isApple() {
5592
+ if (typeof navigator === "undefined") {
5593
+ return false;
5594
+ }
5595
+ const uaData = navigator.userAgentData;
5596
+ if (uaData && typeof uaData.platform === "string") {
5597
+ const p = uaData.platform.toLowerCase();
5598
+ if (p.includes("mac") || p.includes("ios")) {
5599
+ return true;
5600
+ }
5601
+ }
5602
+ const platform = (navigator.platform || "").toLowerCase();
5603
+ if (platform.includes("mac") || platform.includes("iphone") || platform.includes("ipad") || platform.includes("ipod")) {
5604
+ return true;
5605
+ }
5606
+ const ua = (navigator.userAgent || "").toLowerCase();
5607
+ return ua.includes("macintosh") || ua.includes("mac os x") || ua.includes("ipad") || ua.includes("iphone");
5608
+ }
5609
+ /**
5610
+ * Normalise un nom de touche unitaire pour les comparaisons.
5611
+ */
5612
+ static normalizeKeyName(key) {
5613
+ const k = key.trim().toLowerCase();
5614
+ switch (k) {
5615
+ case "esc":
5616
+ return "escape";
5617
+ case "return":
5618
+ return "enter";
5619
+ case "space":
5620
+ case "spacebar":
5621
+ return " ";
5622
+ case "del":
5623
+ return "delete";
5624
+ case "ins":
5625
+ return "insert";
5626
+ case "up":
5627
+ return "arrowup";
5628
+ case "down":
5629
+ return "arrowdown";
5630
+ case "left":
5631
+ return "arrowleft";
5632
+ case "right":
5633
+ return "arrowright";
5634
+ default:
5635
+ return k;
5636
+ }
5637
+ }
5638
+ /**
5639
+ * Parse une chaîne de combinaison (ex: "Mod+K", "g i", "Shift+?", "Alt++")
5640
+ * et retourne la liste des étapes normalisées nécessaires au déclenchement.
5641
+ */
5642
+ static parseCombo(combo, isApple = _ShortcutFormatter.isApple()) {
5643
+ if (typeof combo !== "string") {
5644
+ return [];
5645
+ }
5646
+ const trimmed = combo.slice(0, 512).trim();
5647
+ if (!trimmed) {
5648
+ return [];
5649
+ }
5650
+ const stepsRaw = trimmed.split(/\s+/).slice(0, 10);
5651
+ const steps = [];
5652
+ for (const rawStep of stepsRaw) {
5653
+ const tokens = [];
5654
+ let currentToken = "";
5655
+ for (let i = 0; i < rawStep.length; i++) {
5656
+ const char = rawStep[i];
5657
+ if (char === "+") {
5658
+ if (currentToken === "" && tokens.length > 0) {
5659
+ tokens.push("+");
5660
+ } else if (currentToken !== "") {
5661
+ tokens.push(currentToken);
5662
+ currentToken = "";
5663
+ }
5664
+ } else {
5665
+ currentToken += char;
5666
+ }
5667
+ }
5668
+ if (currentToken !== "") {
5669
+ tokens.push(currentToken);
5670
+ }
5671
+ let ctrl = false;
5672
+ let alt = false;
5673
+ let shift = false;
5674
+ let meta = false;
5675
+ let mainKey = "";
5676
+ for (const token of tokens) {
5677
+ const lower = token.trim().toLowerCase();
5678
+ if (lower === "ctrl" || lower === "control") {
5679
+ ctrl = true;
5680
+ } else if (lower === "alt" || lower === "option" || lower === "opt") {
5681
+ alt = true;
5682
+ } else if (lower === "shift" || lower === "maj") {
5683
+ shift = true;
5684
+ } else if (lower === "cmd" || lower === "command" || lower === "meta" || lower === "win" || lower === "super") {
5685
+ meta = true;
5686
+ } else if (lower === "mod" || lower === "$mod") {
5687
+ if (isApple) {
5688
+ meta = true;
5689
+ } else {
5690
+ ctrl = true;
5691
+ }
5692
+ } else {
5693
+ mainKey = _ShortcutFormatter.normalizeKeyName(token);
5694
+ }
5695
+ }
5696
+ steps.push({
5697
+ ctrl,
5698
+ alt,
5699
+ shift,
5700
+ meta,
5701
+ key: mainKey
5702
+ });
5703
+ }
5704
+ return steps;
5705
+ }
5706
+ /**
5707
+ * Formate une combinaison brute en libellé soigné et lisible pour l'OS cible.
5708
+ * Ex: "Mod+Shift+P" -> macOS: "⇧⌘P", Windows: "Ctrl+Shift+P"
5709
+ * Ex: "g i" -> "g puis i" ou "g i"
5710
+ */
5711
+ static format(combo, isApple = _ShortcutFormatter.isApple()) {
5712
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
5713
+ if (steps.length === 0) {
5714
+ return combo;
5715
+ }
5716
+ const formattedSteps = steps.map((step) => {
5717
+ const parts = [];
5718
+ if (isApple) {
5719
+ if (step.ctrl) parts.push("\u2303");
5720
+ if (step.alt) parts.push("\u2325");
5721
+ if (step.shift) parts.push("\u21E7");
5722
+ if (step.meta) parts.push("\u2318");
5723
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, true);
5724
+ parts.push(keyDisplay);
5725
+ return parts.join("");
5726
+ } else {
5727
+ if (step.ctrl) parts.push("Ctrl");
5728
+ if (step.alt) parts.push("Alt");
5729
+ if (step.shift) parts.push("Shift");
5730
+ if (step.meta) parts.push("Win");
5731
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, false);
5732
+ parts.push(keyDisplay);
5733
+ return parts.join("+");
5734
+ }
5735
+ });
5736
+ return formattedSteps.join(" ");
5737
+ }
5738
+ /**
5739
+ * Convertit un combo technique vers le format officiel WAI-ARIA `aria-keyshortcuts`.
5740
+ * Standard W3C : les modificateurs sont 'Control', 'Alt', 'Shift', 'Meta' et le séparateur est '+'.
5741
+ */
5742
+ static toAriaKeyShortcuts(combo, isApple = _ShortcutFormatter.isApple()) {
5743
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
5744
+ return steps.map((step) => {
5745
+ const parts = [];
5746
+ if (step.ctrl) parts.push("Control");
5747
+ if (step.alt) parts.push("Alt");
5748
+ if (step.shift) parts.push("Shift");
5749
+ if (step.meta) parts.push("Meta");
5750
+ parts.push(_ShortcutFormatter.formatKeyDisplay(step.key, false));
5751
+ return parts.join("+");
5752
+ }).join(" ");
5753
+ }
5754
+ static formatKeyDisplay(key, isApple) {
5755
+ if (!key) return "";
5756
+ switch (key.toLowerCase()) {
5757
+ case "escape":
5758
+ return isApple ? "\u238B" : "Esc";
5759
+ case "enter":
5760
+ return isApple ? "\u21A9" : "Enter";
5761
+ case " ":
5762
+ return isApple ? "\u2423" : "Space";
5763
+ case "tab":
5764
+ return isApple ? "\u21E5" : "Tab";
5765
+ case "backspace":
5766
+ return isApple ? "\u232B" : "Backspace";
5767
+ case "delete":
5768
+ return isApple ? "\u2326" : "Suppr";
5769
+ case "arrowup":
5770
+ return "\u2191";
5771
+ case "arrowdown":
5772
+ return "\u2193";
5773
+ case "arrowleft":
5774
+ return "\u2190";
5775
+ case "arrowright":
5776
+ return "\u2192";
5777
+ default:
5778
+ return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
5779
+ }
5780
+ }
5781
+ };
5782
+
5783
+ // src/shortcut/ShortcutManager.ts
5784
+ var ShortcutManager = class _ShortcutManager {
5785
+ constructor(options) {
5786
+ this.shortcuts = /* @__PURE__ */ new Map();
5787
+ this.scopeStack = [];
5788
+ this.sequenceBuffer = [];
5789
+ this.sequenceTimer = null;
5790
+ this.isListening = true;
5791
+ this.boundListener = null;
5792
+ this.idCounter = 0;
5793
+ this.options = {
5794
+ defaultScope: options?.defaultScope || "global",
5795
+ sequenceTimeout: options?.sequenceTimeout ?? 800,
5796
+ target: options?.target || (typeof window !== "undefined" ? window : {}),
5797
+ onError: options?.onError
5798
+ };
5799
+ this.scopeStack = [this.options.defaultScope];
5800
+ this.initListener();
5801
+ }
5802
+ /**
5803
+ * Vérifie si un élément DOM est une zone d'édition où la saisie de l'utilisateur
5804
+ * ne doit JAMAIS être interrompue ou détournée (Axiome Primordial).
5805
+ */
5806
+ static isEditable(target) {
5807
+ if (!target || typeof target.tagName !== "string") {
5808
+ return false;
5809
+ }
5810
+ const el = target;
5811
+ const tagName = el.tagName.toUpperCase();
5812
+ if (tagName === "INPUT") {
5813
+ const type = el.type?.toLowerCase() || "text";
5814
+ const nonTextTypes = ["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"];
5815
+ return !nonTextTypes.includes(type);
5816
+ }
5817
+ if (tagName === "TEXTAREA" || tagName === "SELECT") {
5818
+ return true;
5819
+ }
5820
+ if (el.isContentEditable || el.getAttribute("contenteditable") === "true" || el.getAttribute("contenteditable") === "plaintext-only" || el.getAttribute("contenteditable") === "") {
5821
+ return true;
5822
+ }
5823
+ const role = el.getAttribute("role");
5824
+ if (role === "textbox" || role === "searchbox") {
5825
+ return true;
5826
+ }
5827
+ if (typeof el.closest === "function") {
5828
+ const editableAncestor = el.closest(
5829
+ '[contenteditable="true"], [contenteditable="plaintext-only"], [contenteditable=""], [role="textbox"], [role="searchbox"]'
5830
+ );
5831
+ if (editableAncestor) {
5832
+ return true;
5833
+ }
5834
+ }
5835
+ return false;
5836
+ }
5837
+ /**
5838
+ * Vérifie si la cible est un champ de mot de passe (sanctuaire anti-keylogging).
5839
+ */
5840
+ static isPasswordField(target) {
5841
+ if (!target || typeof target.tagName !== "string") {
5842
+ return false;
5843
+ }
5844
+ const el = target;
5845
+ return el.tagName.toUpperCase() === "INPUT" && (el.type || "").toLowerCase() === "password";
5846
+ }
5847
+ /**
5848
+ * Enregistre un ou plusieurs raccourcis clavier.
5849
+ * Retourne une fonction de nettoyage pour désenregistrer immédiatement.
5850
+ */
5851
+ bind(definition) {
5852
+ const list = Array.isArray(definition) ? definition : [definition];
5853
+ const registeredIds = [];
5854
+ for (const def of list) {
5855
+ if (!def.combo || typeof def.handler !== "function") {
5856
+ continue;
5857
+ }
5858
+ const id = `wulf_shortcut_${++this.idCounter}`;
5859
+ const normalizedSteps = ShortcutFormatter.parseCombo(def.combo);
5860
+ const isSequence = normalizedSteps.length > 1;
5861
+ const formattedCombo = ShortcutFormatter.format(def.combo);
5862
+ const registered = {
5863
+ ...def,
5864
+ id,
5865
+ scope: def.scope || "global",
5866
+ category: def.category || "G\xE9n\xE9ral",
5867
+ allowInEditable: def.allowInEditable ?? false,
5868
+ preventDefault: def.preventDefault ?? true,
5869
+ stopPropagation: def.stopPropagation ?? true,
5870
+ priority: def.priority ?? 0,
5871
+ formattedCombo,
5872
+ normalizedSteps,
5873
+ isSequence
5874
+ };
5875
+ this.shortcuts.set(id, registered);
5876
+ registeredIds.push(id);
5877
+ }
5878
+ return () => {
5879
+ for (const id of registeredIds) {
5880
+ this.shortcuts.delete(id);
5881
+ }
5882
+ };
5883
+ }
5884
+ /**
5885
+ * Retire tous les raccourcis correspondant à une combinaison et éventuellement un scope.
5886
+ */
5887
+ unbind(combo, scope) {
5888
+ const formatted = ShortcutFormatter.format(combo);
5889
+ for (const [id, s] of this.shortcuts.entries()) {
5890
+ if (s.formattedCombo === formatted || s.combo.trim().toLowerCase() === combo.trim().toLowerCase()) {
5891
+ if (!scope || s.scope === scope) {
5892
+ this.shortcuts.delete(id);
5893
+ }
5894
+ }
5895
+ }
5896
+ }
5897
+ /**
5898
+ * Empile un nouveau scope actif (mode LIFO).
5899
+ * Seuls les raccourcis de ce scope (et les omniprésents '*') seront actifs.
5900
+ */
5901
+ pushScope(scope) {
5902
+ if (scope && typeof scope === "string") {
5903
+ if (this.scopeStack.length >= 64) {
5904
+ return;
5905
+ }
5906
+ this.scopeStack.push(scope);
5907
+ this.clearSequenceBuffer();
5908
+ }
5909
+ }
5910
+ /**
5911
+ * Dépile le scope actuel et rétablit le précédent.
5912
+ * Si un paramètre `scope` est passé, ne retire que si le scope actuel correspond.
5913
+ */
5914
+ popScope(scope) {
5915
+ if (this.scopeStack.length <= 1) {
5916
+ return this.scopeStack[0];
5917
+ }
5918
+ if (scope) {
5919
+ if (this.getScope() === scope) {
5920
+ const popped2 = this.scopeStack.pop();
5921
+ this.clearSequenceBuffer();
5922
+ return popped2;
5923
+ }
5924
+ return void 0;
5925
+ }
5926
+ const popped = this.scopeStack.pop();
5927
+ this.clearSequenceBuffer();
5928
+ return popped;
5929
+ }
5930
+ /**
5931
+ * Réinitialise brutalement la pile pour activer le scope spécifié.
5932
+ */
5933
+ setScope(scope) {
5934
+ this.scopeStack = [scope || this.options.defaultScope];
5935
+ this.clearSequenceBuffer();
5936
+ }
5937
+ /**
5938
+ * Retourne le scope actuellement actif au sommet de la pile.
5939
+ */
5940
+ getScope() {
5941
+ return this.scopeStack[this.scopeStack.length - 1] || this.options.defaultScope;
5942
+ }
5943
+ /**
5944
+ * Retourne une copie de la pile complète des scopes.
5945
+ */
5946
+ getScopeStack() {
5947
+ return [...this.scopeStack];
5948
+ }
5949
+ /**
5950
+ * Met en pause l'écoute de tous les raccourcis.
5951
+ */
5952
+ pause() {
5953
+ this.isListening = false;
5954
+ this.clearSequenceBuffer();
5955
+ }
5956
+ /**
5957
+ * Réactive l'écoute des raccourcis.
5958
+ */
5959
+ resume() {
5960
+ this.isListening = true;
5961
+ }
5962
+ /**
5963
+ * Indique si le gestionnaire est actif et à l'écoute.
5964
+ */
5965
+ isActive() {
5966
+ return this.isListening;
5967
+ }
5968
+ /**
5969
+ * Retourne le catalogue des raccourcis enregistrés (optionnellement filtré par scope).
5970
+ */
5971
+ getRegistry(scope) {
5972
+ const list = [];
5973
+ for (const shortcut of this.shortcuts.values()) {
5974
+ if (!scope || shortcut.scope === scope || shortcut.scope === "*") {
5975
+ list.push({ ...shortcut });
5976
+ }
5977
+ }
5978
+ return list;
5979
+ }
5980
+ /**
5981
+ * Associe l'attribut standard WAI-ARIA `aria-keyshortcuts` sur un élément DOM.
5982
+ */
5983
+ attachAria(element, combo) {
5984
+ if (element && typeof element.setAttribute === "function") {
5985
+ const ariaValue = ShortcutFormatter.toAriaKeyShortcuts(combo);
5986
+ element.setAttribute("aria-keyshortcuts", ariaValue);
5987
+ }
5988
+ }
5989
+ /**
5990
+ * Formate une combinaison brute selon l'OS courant ("⌘K" ou "Ctrl+K").
5991
+ */
5992
+ static format(combo, isApple) {
5993
+ return ShortcutFormatter.format(combo, isApple);
5994
+ }
5995
+ /**
5996
+ * Détruit le gestionnaire : supprime les écouteurs du DOM et vide toute la mémoire.
5997
+ */
5998
+ destroy() {
5999
+ this.pause();
6000
+ this.removeListener();
6001
+ this.shortcuts.clear();
6002
+ this.scopeStack = [];
6003
+ this.clearSequenceBuffer();
6004
+ }
6005
+ // --- Implémentation Interne ---
6006
+ initListener() {
6007
+ if (typeof window === "undefined" || !this.options.target) {
6008
+ return;
6009
+ }
6010
+ this.boundListener = (event) => this.handleKeyDown(event);
6011
+ const target = this.options.target;
6012
+ if (typeof target.addEventListener === "function") {
6013
+ target.addEventListener("keydown", this.boundListener, false);
6014
+ }
6015
+ }
6016
+ removeListener() {
6017
+ if (this.boundListener && this.options.target) {
6018
+ const target = this.options.target;
6019
+ if (typeof target.removeEventListener === "function") {
6020
+ target.removeEventListener("keydown", this.boundListener, false);
6021
+ }
6022
+ this.boundListener = null;
6023
+ }
6024
+ }
6025
+ handleKeyDown(event) {
6026
+ if (!this.isListening) {
6027
+ return;
6028
+ }
6029
+ const k = (event.key || "").toLowerCase();
6030
+ if (["control", "alt", "shift", "meta"].includes(k)) {
6031
+ return;
6032
+ }
6033
+ const currentScope = this.getScope();
6034
+ const composed = typeof event.composedPath === "function" ? event.composedPath() : [];
6035
+ const actualTarget = composed.length > 0 ? composed[0] : event.target;
6036
+ const isEditable = _ShortcutManager.isEditable(actualTarget) || _ShortcutManager.isEditable(event.target);
6037
+ const isPasswordInput = _ShortcutManager.isPasswordField(actualTarget) || _ShortcutManager.isPasswordField(event.target);
6038
+ const currentStep = {
6039
+ ctrl: event.ctrlKey,
6040
+ alt: event.altKey,
6041
+ shift: event.shiftKey,
6042
+ meta: event.metaKey,
6043
+ key: ShortcutFormatter.normalizeKeyName(event.key || "")
6044
+ };
6045
+ const now = Date.now();
6046
+ if (this.sequenceBuffer.length > 0) {
6047
+ const last = this.sequenceBuffer[this.sequenceBuffer.length - 1];
6048
+ if (now - last.timestamp > this.options.sequenceTimeout) {
6049
+ this.clearSequenceBuffer();
6050
+ }
6051
+ }
6052
+ const activeCandidates = this.getActiveShortcuts(currentScope, isEditable, isPasswordInput);
6053
+ const proposedSequence = [...this.sequenceBuffer.map((b) => b.step), currentStep];
6054
+ const matchingSequence = this.findMatchingSequence(activeCandidates, proposedSequence);
6055
+ if (matchingSequence) {
6056
+ this.clearSequenceBuffer();
6057
+ this.executeShortcut(matchingSequence, event, currentScope, true);
6058
+ return;
6059
+ }
6060
+ if (this.isPrefixOfAnySequence(activeCandidates, proposedSequence)) {
6061
+ this.sequenceBuffer.push({ step: currentStep, timestamp: now });
6062
+ this.resetSequenceTimer();
6063
+ if (event.key.length === 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !isEditable) {
6064
+ event.preventDefault();
6065
+ }
6066
+ return;
6067
+ }
6068
+ this.clearSequenceBuffer();
6069
+ const matchingChord = this.findMatchingChord(activeCandidates, currentStep, event);
6070
+ if (matchingChord) {
6071
+ this.executeShortcut(matchingChord, event, currentScope, false);
6072
+ }
6073
+ }
6074
+ getActiveShortcuts(currentScope, isEditable, isPasswordInput = false) {
6075
+ const list = [];
6076
+ for (const shortcut of this.shortcuts.values()) {
6077
+ if (shortcut.scope !== currentScope && shortcut.scope !== "*") {
6078
+ continue;
6079
+ }
6080
+ if (isEditable && !shortcut.allowInEditable) {
6081
+ continue;
6082
+ }
6083
+ if (isPasswordInput) {
6084
+ if (shortcut.isSequence) {
6085
+ continue;
6086
+ }
6087
+ const firstStep = shortcut.normalizedSteps[0];
6088
+ if (firstStep && firstStep.key.length === 1 && !firstStep.ctrl && !firstStep.alt && !firstStep.meta) {
6089
+ continue;
6090
+ }
6091
+ }
6092
+ list.push(shortcut);
6093
+ }
6094
+ return list.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
6095
+ }
6096
+ stepMatches(step, eventStep, rawEvent) {
6097
+ if (step.ctrl !== eventStep.ctrl) return false;
6098
+ if (step.alt !== eventStep.alt) return false;
6099
+ if (step.meta !== eventStep.meta) return false;
6100
+ const keyMatches = step.key === eventStep.key || rawEvent && step.key === rawEvent.key.toLowerCase();
6101
+ if (!keyMatches) return false;
6102
+ if (step.shift === eventStep.shift) {
6103
+ return true;
6104
+ }
6105
+ if (!step.shift && eventStep.shift) {
6106
+ if (rawEvent && rawEvent.key === step.key) {
6107
+ return true;
6108
+ }
6109
+ }
6110
+ return false;
6111
+ }
6112
+ findMatchingChord(candidates, currentStep, rawEvent) {
6113
+ for (const candidate of candidates) {
6114
+ if (candidate.isSequence || candidate.normalizedSteps.length !== 1) {
6115
+ continue;
6116
+ }
6117
+ const step = candidate.normalizedSteps[0];
6118
+ if (this.stepMatches(step, currentStep, rawEvent)) {
6119
+ return candidate;
6120
+ }
6121
+ }
6122
+ return null;
6123
+ }
6124
+ findMatchingSequence(candidates, proposed) {
6125
+ for (const candidate of candidates) {
6126
+ if (!candidate.isSequence || candidate.normalizedSteps.length !== proposed.length) {
6127
+ continue;
6128
+ }
6129
+ let allMatch = true;
6130
+ for (let i = 0; i < proposed.length; i++) {
6131
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
6132
+ allMatch = false;
6133
+ break;
6134
+ }
6135
+ }
6136
+ if (allMatch) {
6137
+ return candidate;
6138
+ }
6139
+ }
6140
+ return null;
6141
+ }
6142
+ isPrefixOfAnySequence(candidates, proposed) {
6143
+ for (const candidate of candidates) {
6144
+ if (!candidate.isSequence || candidate.normalizedSteps.length <= proposed.length) {
6145
+ continue;
6146
+ }
6147
+ let prefixMatches = true;
6148
+ for (let i = 0; i < proposed.length; i++) {
6149
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
6150
+ prefixMatches = false;
6151
+ break;
6152
+ }
6153
+ }
6154
+ if (prefixMatches) {
6155
+ return true;
6156
+ }
6157
+ }
6158
+ return false;
6159
+ }
6160
+ executeShortcut(shortcut, event, scope, isSequence) {
6161
+ if (shortcut.preventDefault) {
6162
+ event.preventDefault();
6163
+ }
6164
+ if (shortcut.stopPropagation) {
6165
+ event.stopPropagation();
6166
+ }
6167
+ const info = {
6168
+ combo: shortcut.combo,
6169
+ formattedCombo: shortcut.formattedCombo,
6170
+ scope,
6171
+ target: event.target,
6172
+ isSequence
6173
+ };
6174
+ try {
6175
+ shortcut.handler(event, info);
6176
+ } catch (err) {
6177
+ if (this.options.onError) {
6178
+ this.options.onError(err instanceof Error ? err : new Error(String(err)), shortcut.combo);
6179
+ } else {
6180
+ console.error(`[Wulf.Shortcut] Erreur lors de l'ex\xE9cution du raccourci "${shortcut.combo}":`, err);
6181
+ }
6182
+ }
6183
+ }
6184
+ resetSequenceTimer() {
6185
+ if (this.sequenceTimer) {
6186
+ clearTimeout(this.sequenceTimer);
6187
+ }
6188
+ this.sequenceTimer = setTimeout(() => {
6189
+ this.clearSequenceBuffer();
6190
+ }, this.options.sequenceTimeout);
6191
+ }
6192
+ clearSequenceBuffer() {
6193
+ this.sequenceBuffer = [];
6194
+ if (this.sequenceTimer) {
6195
+ clearTimeout(this.sequenceTimer);
6196
+ this.sequenceTimer = null;
6197
+ }
6198
+ }
6199
+ };
6200
+
6201
+ // src/shortcut/index.ts
6202
+ if (typeof window !== "undefined") {
6203
+ const win = window;
6204
+ const wulfNamespace = win.Wulf || {};
6205
+ win.Wulf = wulfNamespace;
6206
+ wulfNamespace.Shortcut = Object.assign(ShortcutManager, {
6207
+ ShortcutManager,
6208
+ ShortcutFormatter
6209
+ });
6210
+ }
5365
6211
  return __toCommonJS(index_exports);
5366
6212
  })();
5367
- if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
6213
+ if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.prototype.hasOwnProperty.call(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
5368
6214
  //# sourceMappingURL=index.global.js.map