wulf.js 1.9.0 → 1.9.2

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 (75) hide show
  1. package/README.md +220 -19
  2. package/changelog.md +42 -0
  3. package/dist/focus-trap.esm.js +407 -0
  4. package/dist/focus-trap.esm.js.map +7 -0
  5. package/dist/focus-trap.global.js +433 -0
  6. package/dist/focus-trap.global.js.map +7 -0
  7. package/dist/focus-trap.global.min.js +6 -0
  8. package/dist/focus-trap.global.min.js.map +7 -0
  9. package/dist/index.esm.js +1179 -8
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +1180 -9
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +5 -2
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.esm.js +106 -2
  16. package/dist/mask.esm.js.map +3 -3
  17. package/dist/mask.global.js +107 -3
  18. package/dist/mask.global.js.map +3 -3
  19. package/dist/mask.global.min.js +5 -2
  20. package/dist/mask.global.min.js.map +4 -4
  21. package/dist/masonry.esm.js +78 -3
  22. package/dist/masonry.esm.js.map +3 -3
  23. package/dist/masonry.global.js +79 -4
  24. package/dist/masonry.global.js.map +3 -3
  25. package/dist/masonry.global.min.js +5 -2
  26. package/dist/masonry.global.min.js.map +4 -4
  27. package/dist/scroll.esm.js +78 -3
  28. package/dist/scroll.esm.js.map +3 -3
  29. package/dist/scroll.global.js +79 -4
  30. package/dist/scroll.global.js.map +3 -3
  31. package/dist/scroll.global.min.js +5 -2
  32. package/dist/scroll.global.min.js.map +4 -4
  33. package/dist/shortcut.esm.js +584 -0
  34. package/dist/shortcut.esm.js.map +7 -0
  35. package/dist/shortcut.global.js +610 -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.esm.js +91 -2
  40. package/dist/toast.esm.js.map +3 -3
  41. package/dist/toast.global.js +92 -3
  42. package/dist/toast.global.js.map +3 -3
  43. package/dist/toast.global.min.js +5 -2
  44. package/dist/toast.global.min.js.map +4 -4
  45. package/dist/types/common/AuditableComponent.d.ts +45 -0
  46. package/dist/types/common/LocalizedComponent.d.ts +3 -2
  47. package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
  48. package/dist/types/focus-trap/index.d.ts +3 -0
  49. package/dist/types/focus-trap/types.d.ts +45 -0
  50. package/dist/types/index.d.ts +5 -0
  51. package/dist/types/mask/BaseInputMask.d.ts +14 -1
  52. package/dist/types/mask/InputMask.d.ts +1 -0
  53. package/dist/types/mask/types.d.ts +5 -2
  54. package/dist/types/masonry/Masonry.d.ts +7 -0
  55. package/dist/types/masonry/types.d.ts +7 -2
  56. package/dist/types/scroll/ScrollBlock.d.ts +7 -0
  57. package/dist/types/scroll/types.d.ts +3 -2
  58. package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
  59. package/dist/types/shortcut/ShortcutManager.d.ts +91 -0
  60. package/dist/types/shortcut/index.d.ts +4 -0
  61. package/dist/types/shortcut/types.d.ts +101 -0
  62. package/dist/types/toast/Toast.d.ts +3 -0
  63. package/dist/types/toast/ToastInstance.d.ts +9 -1
  64. package/dist/types/toast/types.d.ts +3 -2
  65. package/package.json +23 -10
  66. package/dist/index.cjs.js +0 -4783
  67. package/dist/index.cjs.js.map +0 -7
  68. package/dist/mask.cjs.js +0 -2982
  69. package/dist/mask.cjs.js.map +0 -7
  70. package/dist/masonry.cjs.js +0 -783
  71. package/dist/masonry.cjs.js.map +0 -7
  72. package/dist/scroll.cjs.js +0 -748
  73. package/dist/scroll.cjs.js.map +0 -7
  74. package/dist/toast.cjs.js +0 -626
  75. package/dist/toast.cjs.js.map +0 -7
package/dist/index.esm.js CHANGED
@@ -21,6 +21,49 @@ __export(mask_exports, {
21
21
  resolveMaskConstructorArgs: () => resolveMaskConstructorArgs
22
22
  });
23
23
 
24
+ // src/common/AuditableComponent.ts
25
+ var AuditableComponent = class {
26
+ /**
27
+ * Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
28
+ */
29
+ getAuditDisableHint() {
30
+ return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
31
+ }
32
+ /**
33
+ * Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
34
+ * si l'audit est activé et que des contraintes manquent.
35
+ */
36
+ runAuditWarning(enabled = true) {
37
+ if (!enabled) return [];
38
+ const warnings = this.audit();
39
+ if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
40
+ console.warn(
41
+ `[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
42
+ ` + warnings.map((w) => ` - ${w}`).join("\n") + `
43
+ (${this.getAuditDisableHint()})`
44
+ );
45
+ }
46
+ return warnings;
47
+ }
48
+ /**
49
+ * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
50
+ * pointe vers des éléments réellement présents dans le document.
51
+ */
52
+ checkAriaIdReferences(element, attrName, warnings) {
53
+ const rawValue = element.getAttribute(attrName)?.trim();
54
+ if (!rawValue) return false;
55
+ const doc = element.ownerDocument || document;
56
+ const ids = rawValue.split(/\s+/).filter(Boolean);
57
+ const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
58
+ if (!isValid) {
59
+ warnings.push(
60
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
61
+ );
62
+ }
63
+ return isValid;
64
+ }
65
+ };
66
+
24
67
  // src/mask/BaseInputMask.ts
25
68
  function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOptions) {
26
69
  const isSecondArgInput = Boolean(
@@ -39,8 +82,9 @@ function resolveMaskConstructorArgs(targetOrWrapper, inputOrOptions, maybeOption
39
82
  options: inputOrOptions && typeof inputOrOptions === "object" && !("tagName" in inputOrOptions) ? inputOrOptions : {}
40
83
  };
41
84
  }
42
- var BaseInputMask = class {
85
+ var BaseInputMask = class extends AuditableComponent {
43
86
  constructor(targetOrWrapper, inputOrOptions, maybeOptions) {
87
+ super();
44
88
  this.ghost = null;
45
89
  this.isWrapperCreated = false;
46
90
  this.isDestroyed = false;
@@ -128,8 +172,10 @@ var BaseInputMask = class {
128
172
  const dataSelectAll = this.getAttr("data-mask-select-on-focus") === "true";
129
173
  const dataCopyRaw = this.getAttr("data-mask-copy-raw") === "true";
130
174
  const dataAlign = this.getAttr("data-mask-align") || this.getAttr("data-align");
175
+ const dataAudit = this.getAttr("data-mask-audit");
131
176
  const { disabled: optDisabled, align: optAlign, ...otherOptions } = options;
132
177
  const resolvedDisabled = optDisabled !== void 0 ? optDisabled : dataDisabled ? true : false;
178
+ const resolvedAudit = options.audit ?? (dataAudit !== null ? dataAudit !== "false" : true);
133
179
  const isPassword = this.input.type === "password";
134
180
  this.options = {
135
181
  ...otherOptions,
@@ -139,7 +185,8 @@ var BaseInputMask = class {
139
185
  copyRaw: isPassword ? false : options.copyRaw ?? dataCopyRaw ?? false,
140
186
  disabled: resolvedDisabled,
141
187
  align: optAlign ?? (dataAlign || void 0),
142
- emitNativeInput: options.emitNativeInput ?? true
188
+ emitNativeInput: options.emitNativeInput ?? true,
189
+ audit: resolvedAudit
143
190
  };
144
191
  if (this.options.showMaskOnFocus) {
145
192
  this.wrapper.classList.add("mask-focus-only");
@@ -484,6 +531,48 @@ var BaseInputMask = class {
484
531
  getRawValue() {
485
532
  return this.input.value;
486
533
  }
534
+ /**
535
+ * Vérifie la conformité d'accessibilité WAI-ARIA du champ de saisie (étiquetage, format attendu)
536
+ * et retourne la liste des contraintes manquantes.
537
+ */
538
+ audit() {
539
+ const warnings = [];
540
+ const doc = this.input.ownerDocument || document;
541
+ const ariaLabel = this.input.getAttribute("aria-label")?.trim();
542
+ const hasValidLabelledby = this.checkAriaIdReferences(this.input, "aria-labelledby", warnings);
543
+ const hasWrappingLabel = Boolean(this.input.closest("label"));
544
+ const hasNativeLabels = Boolean(this.input.labels && this.input.labels.length > 0);
545
+ let hasExplicitLabelFor = false;
546
+ if (this.input.id && typeof CSS !== "undefined" && typeof CSS.escape === "function") {
547
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${CSS.escape(this.input.id)}"]`));
548
+ } else if (this.input.id) {
549
+ hasExplicitLabelFor = Boolean(doc.querySelector(`label[for="${this.input.id}"]`));
550
+ }
551
+ if (!ariaLabel && !hasValidLabelledby && !hasWrappingLabel && !hasNativeLabels && !hasExplicitLabelFor) {
552
+ warnings.push(
553
+ `\xC9tiquetage accessible manquant : associez un <label for="id"> (ou d\xE9finissez aria-label / aria-labelledby) sur l'input (WCAG 4.1.2).`
554
+ );
555
+ }
556
+ this.checkAriaIdReferences(this.input, "aria-describedby", warnings);
557
+ const extraWarnings = this.getSpecificAuditWarnings();
558
+ warnings.push(...extraWarnings);
559
+ return warnings;
560
+ }
561
+ getAuditPrefix() {
562
+ return `Wulf.Mask.${this.constructor.name || "InputMask"}`;
563
+ }
564
+ getAuditTargetLabel() {
565
+ return this.input.id ? `#${this.input.id}` : this.input.name ? `input[name="${this.input.name}"]` : "<input>";
566
+ }
567
+ getAuditDisableHint() {
568
+ return 'Passez { audit: false } ou data-mask-audit="false" pour d\xE9sactiver cet avertissement';
569
+ }
570
+ /**
571
+ * Crochet permettant aux classes filles d'ajouter des vérifications d'audit spécifiques.
572
+ */
573
+ getSpecificAuditWarnings() {
574
+ return [];
575
+ }
487
576
  /**
488
577
  * Supprime les éléments fantômes, restaure les propriétés et nettoie les attributs.
489
578
  */
@@ -1278,6 +1367,19 @@ var InputMask = class extends BaseInputMask {
1278
1367
  this.bindEvents();
1279
1368
  this.lastValue = this.input.value;
1280
1369
  this.syncInitialValue();
1370
+ this.runAuditWarning(this.options.audit);
1371
+ }
1372
+ getSpecificAuditWarnings() {
1373
+ const warnings = [];
1374
+ const hasDescribedby = Boolean(this.input.getAttribute("aria-describedby")?.trim());
1375
+ const hasPlaceholder = Boolean(this.input.getAttribute("placeholder")?.trim());
1376
+ const hasAriaPlaceholder = Boolean(this.input.getAttribute("aria-placeholder")?.trim());
1377
+ if (!hasDescribedby && !hasPlaceholder && !hasAriaPlaceholder && !this.options.disabled) {
1378
+ warnings.push(
1379
+ "Indication du format attendu manquante : d\xE9finissez aria-describedby, placeholder ou aria-placeholder pour informer les technologies d'assistance (WCAG 3.3.2)."
1380
+ );
1381
+ }
1382
+ return warnings;
1281
1383
  }
1282
1384
  extractRawSnippet(snippet) {
1283
1385
  return this.engine.extractRaw(snippet);
@@ -2127,6 +2229,7 @@ var InputAmountMask = class extends BaseInputMask {
2127
2229
  isValid: true
2128
2230
  });
2129
2231
  }
2232
+ this.runAuditWarning(this.options.audit);
2130
2233
  }
2131
2234
  extractRawSnippet(snippet) {
2132
2235
  const p = this.engine.parse(snippet);
@@ -2709,6 +2812,7 @@ var InputEmailMask = class extends BaseInputMask {
2709
2812
  if (!this.options.disabled) {
2710
2813
  this.updateSuggestion();
2711
2814
  }
2815
+ this.runAuditWarning(this.options.audit);
2712
2816
  }
2713
2817
  onNativeValueSet(_strVal) {
2714
2818
  if (this.options.disabled) return;
@@ -2980,7 +3084,7 @@ __export(scroll_exports, {
2980
3084
  });
2981
3085
 
2982
3086
  // src/common/LocalizedComponent.ts
2983
- var LocalizedComponent = class {
3087
+ var LocalizedComponent = class extends AuditableComponent {
2984
3088
  /**
2985
3089
  * Définit la langue globale du composant (ex: 'fr', 'en', 'es').
2986
3090
  */
@@ -3032,6 +3136,7 @@ var LocalizedComponent = class {
3032
3136
  return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
3033
3137
  }
3034
3138
  constructor(i18nOverrides) {
3139
+ super();
3035
3140
  this.i18nOverrides = i18nOverrides;
3036
3141
  }
3037
3142
  /**
@@ -3181,7 +3286,7 @@ var ScrollBlock = class extends LocalizedComponent {
3181
3286
  throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
3182
3287
  }
3183
3288
  this.root = resolvedElement;
3184
- this.hasExplicitAriaLabel = Boolean(options?.ariaLabel);
3289
+ this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
3185
3290
  this.options = {
3186
3291
  axis: options?.axis || "y",
3187
3292
  autoHide: options?.autoHide ?? true,
@@ -3196,7 +3301,8 @@ var ScrollBlock = class extends LocalizedComponent {
3196
3301
  onTotalScroll: options?.onTotalScroll || (() => {
3197
3302
  }),
3198
3303
  onTotalScrollBack: options?.onTotalScrollBack || (() => {
3199
- })
3304
+ }),
3305
+ audit: options?.audit ?? true
3200
3306
  };
3201
3307
  this.boundOnScroll = this.handleScroll.bind(this);
3202
3308
  this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
@@ -3211,6 +3317,7 @@ var ScrollBlock = class extends LocalizedComponent {
3211
3317
  this.setupEventListeners();
3212
3318
  this.setupObserver();
3213
3319
  this.update();
3320
+ this.runAuditWarning(this.options.audit);
3214
3321
  }
3215
3322
  /**
3216
3323
  * Prépare le viewport défilant sans altérer les éléments enfants.
@@ -3631,6 +3738,35 @@ var ScrollBlock = class extends LocalizedComponent {
3631
3738
  behavior
3632
3739
  });
3633
3740
  }
3741
+ /**
3742
+ * Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
3743
+ * et retourne la liste des contraintes manquantes.
3744
+ */
3745
+ audit() {
3746
+ const warnings = [];
3747
+ const hasViewportLabelledby = this.checkAriaIdReferences(this.viewport, "aria-labelledby", warnings);
3748
+ const hasRootLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
3749
+ const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
3750
+ const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
3751
+ const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
3752
+ if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
3753
+ warnings.push(
3754
+ "Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour d\xE9crire la zone d\xE9filable (WCAG 4.1.2)."
3755
+ );
3756
+ }
3757
+ if (this.options.minThumbSize < 24) {
3758
+ warnings.push(
3759
+ `Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
3760
+ );
3761
+ }
3762
+ return warnings;
3763
+ }
3764
+ getAuditPrefix() {
3765
+ return "Wulf.Scroll";
3766
+ }
3767
+ getAuditTargetLabel() {
3768
+ return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-scrollblock>`;
3769
+ }
3634
3770
  /**
3635
3771
  * Détruit le composant et libère toutes les ressources.
3636
3772
  */
@@ -3941,7 +4077,7 @@ var Masonry = class extends LocalizedComponent {
3941
4077
  height: this.root.style.height,
3942
4078
  width: this.root.style.width
3943
4079
  };
3944
- this.hasExplicitAriaLabel = Boolean(options.ariaLabel);
4080
+ this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
3945
4081
  this.options = {
3946
4082
  itemSelector: options.itemSelector || "> *",
3947
4083
  columnWidth: options.columnWidth ?? 0,
@@ -3960,7 +4096,8 @@ var Masonry = class extends LocalizedComponent {
3960
4096
  onLayout: options.onLayout || (() => {
3961
4097
  }),
3962
4098
  onItemPlaced: options.onItemPlaced || (() => {
3963
- })
4099
+ }),
4100
+ audit: options.audit ?? true
3964
4101
  };
3965
4102
  const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
3966
4103
  if (this.options.useNativeCSSGrid && supportsNativeCSS) {
@@ -3975,6 +4112,7 @@ var Masonry = class extends LocalizedComponent {
3975
4112
  this.initObservers();
3976
4113
  this.initImages();
3977
4114
  this.layout();
4115
+ this.runAuditWarning(this.options.audit);
3978
4116
  }
3979
4117
  get items() {
3980
4118
  return [...this._items];
@@ -4227,6 +4365,35 @@ var Masonry = class extends LocalizedComponent {
4227
4365
  }, dur);
4228
4366
  this.removeTimers.add(timerId);
4229
4367
  }
4368
+ /**
4369
+ * Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
4370
+ * et retourne la liste des contraintes manquantes.
4371
+ */
4372
+ audit() {
4373
+ const warnings = [];
4374
+ const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
4375
+ const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
4376
+ if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
4377
+ warnings.push(
4378
+ "Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour qualifier la grille (WCAG 4.1.2)."
4379
+ );
4380
+ }
4381
+ const imagesWithoutAlt = Array.from(this.root.querySelectorAll("img")).filter(
4382
+ (img) => !img.hasAttribute("alt") && img.getAttribute("aria-hidden") !== "true"
4383
+ );
4384
+ if (imagesWithoutAlt.length > 0) {
4385
+ warnings.push(
4386
+ `${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
4387
+ );
4388
+ }
4389
+ return warnings;
4390
+ }
4391
+ getAuditPrefix() {
4392
+ return "Wulf.Masonry";
4393
+ }
4394
+ getAuditTargetLabel() {
4395
+ return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-masonry>`;
4396
+ }
4230
4397
  /**
4231
4398
  * Libère les ressources, déconnecte les observateurs et nettoie les styles injectés.
4232
4399
  */
@@ -4330,8 +4497,9 @@ var toastI18n = createI18nManager("fr", {
4330
4497
 
4331
4498
  // src/toast/ToastInstance.ts
4332
4499
  var nextToastId = 1;
4333
- var ToastInstance = class {
4500
+ var ToastInstance = class extends AuditableComponent {
4334
4501
  constructor(options, onDismiss) {
4502
+ super();
4335
4503
  this._isClosed = false;
4336
4504
  this.timerId = null;
4337
4505
  this.remainingTime = 0;
@@ -4348,10 +4516,45 @@ var ToastInstance = class {
4348
4516
  }
4349
4517
  this.element = this.createDOM();
4350
4518
  this.bindEvents();
4519
+ this.runAuditWarning(options.audit !== false);
4351
4520
  }
4352
4521
  get isClosed() {
4353
4522
  return this._isClosed;
4354
4523
  }
4524
+ /**
4525
+ * Vérifie la conformité d'accessibilité WAI-ARIA de la notification Toast
4526
+ * et retourne la liste des contraintes manquantes.
4527
+ */
4528
+ audit() {
4529
+ const warnings = [];
4530
+ const hasTitle = Boolean(this.options.title && this.options.title.trim().length > 0);
4531
+ const hasMessage = Boolean(this.options.message && this.options.message.trim().length > 0);
4532
+ if (!hasTitle && !hasMessage) {
4533
+ warnings.push(
4534
+ "Contenu textuel vide : d\xE9finissez au moins un title ou un message pour que le lecteur d'\xE9cran puisse annoncer la notification (WCAG 4.1.3)."
4535
+ );
4536
+ }
4537
+ const duration = this.options.duration === void 0 ? 4e3 : this.options.duration;
4538
+ if (typeof duration === "number" && duration > 0 && duration < 5e3) {
4539
+ warnings.push(
4540
+ `Dur\xE9e d'affichage trop courte (duration: ${duration}ms) : pr\xE9voyez au moins 5000ms ou duration: false pour laisser le temps de lecture aux utilisateurs (WCAG 2.2.1).`
4541
+ );
4542
+ }
4543
+ const closable = this.options.closable ?? true;
4544
+ const isPersistent = duration === false || typeof duration === "number" && duration <= 0;
4545
+ if (isPersistent && !closable && !this.options.closeOnClick) {
4546
+ warnings.push(
4547
+ "Notification persistante impossible \xE0 fermer : activez closable: true ou closeOnClick: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
4548
+ );
4549
+ }
4550
+ return warnings;
4551
+ }
4552
+ getAuditPrefix() {
4553
+ return "Wulf.Toast";
4554
+ }
4555
+ getAuditTargetLabel() {
4556
+ return `#${this.id}`;
4557
+ }
4355
4558
  /**
4356
4559
  * Construction du DOM de manière 100% sécurisée sans aucun `innerHTML`.
4357
4560
  */
@@ -4712,6 +4915,15 @@ var ToastManager = _ToastManager;
4712
4915
 
4713
4916
  // src/toast/Toast.ts
4714
4917
  var Toast = class extends LocalizedComponent {
4918
+ audit() {
4919
+ return [];
4920
+ }
4921
+ getAuditPrefix() {
4922
+ return "Wulf.Toast";
4923
+ }
4924
+ getAuditTargetLabel() {
4925
+ return "Toast";
4926
+ }
4715
4927
  /**
4716
4928
  * Affiche une nouvelle notification Toast avec les options spécifiées.
4717
4929
  */
@@ -4744,10 +4956,966 @@ if (typeof window !== "undefined") {
4744
4956
  i18n: toastI18n
4745
4957
  });
4746
4958
  }
4959
+
4960
+ // src/focus-trap/index.ts
4961
+ var focus_trap_exports = {};
4962
+ __export(focus_trap_exports, {
4963
+ FocusTrap: () => FocusTrap,
4964
+ default: () => FocusTrap
4965
+ });
4966
+
4967
+ // src/focus-trap/FocusTrap.ts
4968
+ var FOCUSABLE_SELECTOR = [
4969
+ "a[href]",
4970
+ "area[href]",
4971
+ "input:not([disabled])",
4972
+ "select:not([disabled])",
4973
+ "textarea:not([disabled])",
4974
+ "button:not([disabled])",
4975
+ "iframe",
4976
+ "object",
4977
+ "embed",
4978
+ '[contenteditable="true"]',
4979
+ '[tabindex]:not([tabindex="-1"])'
4980
+ ].join(",");
4981
+ var trapStack = [];
4982
+ var FocusTrap = class extends AuditableComponent {
4983
+ constructor(target, options = {}) {
4984
+ super();
4985
+ this.active = false;
4986
+ this.paused = false;
4987
+ this.previousActiveElement = null;
4988
+ this.inertSiblings = [];
4989
+ // Sentinelles anti-fuite de focus
4990
+ this.startSentinel = null;
4991
+ this.endSentinel = null;
4992
+ const el = typeof target === "string" ? document.querySelector(target) : target;
4993
+ if (!el || !(el instanceof HTMLElement)) {
4994
+ throw new Error(`[Wulf.FocusTrap] Conteneur introuvable ou invalide : "${target}"`);
4995
+ }
4996
+ this.element = el;
4997
+ this.options = {
4998
+ initialFocus: options.initialFocus !== void 0 ? options.initialFocus : "[data-autofocus], [autofocus]",
4999
+ returnFocus: options.returnFocus ?? true,
5000
+ fallbackReturnFocus: options.fallbackReturnFocus ?? "",
5001
+ escapeDeactivates: options.escapeDeactivates ?? true,
5002
+ allowOutsideClick: options.allowOutsideClick ?? false,
5003
+ setInert: options.setInert ?? false,
5004
+ onActivate: options.onActivate ?? (() => {
5005
+ }),
5006
+ onDeactivate: options.onDeactivate ?? (() => {
5007
+ }),
5008
+ audit: options.audit ?? true
5009
+ };
5010
+ this.handleKeyDownBound = this.handleKeyDown.bind(this);
5011
+ this.handleClickOutsideBound = this.handleClickOutside.bind(this);
5012
+ this.handleFocusInBound = this.handleFocusIn.bind(this);
5013
+ this.runAuditWarning(this.options.audit);
5014
+ }
5015
+ /**
5016
+ * Vérifie si un élément est réellement focusable, visible et actif dans le DOM.
5017
+ */
5018
+ isFocusable(el) {
5019
+ if (!el || !el.isConnected) return false;
5020
+ if (el.disabled) return false;
5021
+ if (el.closest("fieldset[disabled]") && !el.closest("legend")) return false;
5022
+ if (el.hasAttribute("inert") || el.closest("[inert]")) return false;
5023
+ if (el.hidden || el.closest("[hidden]")) return false;
5024
+ if (el.style.display === "none" || el.style.visibility === "hidden") return false;
5025
+ const style = window.getComputedStyle(el);
5026
+ if (style.display === "none" || style.visibility === "hidden") return false;
5027
+ if (el.offsetWidth === 0 && el.offsetHeight === 0 && style.position !== "fixed") {
5028
+ return false;
5029
+ }
5030
+ if (el instanceof HTMLInputElement && el.type === "radio" && el.name) {
5031
+ const group = Array.from(
5032
+ this.element.querySelectorAll(`input[type="radio"][name="${CSS.escape(el.name)}"]`)
5033
+ );
5034
+ const checked = group.find((r) => r.checked);
5035
+ if (checked) {
5036
+ return el === checked;
5037
+ }
5038
+ return el === group[0];
5039
+ }
5040
+ return true;
5041
+ }
5042
+ /**
5043
+ * Retourne tous les éléments focusables réels ordonnés dans le conteneur.
5044
+ */
5045
+ getFocusableElements() {
5046
+ const rawElements = Array.from(this.element.querySelectorAll(FOCUSABLE_SELECTOR));
5047
+ return rawElements.filter((el) => this.isFocusable(el));
5048
+ }
5049
+ /**
5050
+ * Active le trap.
5051
+ */
5052
+ activate() {
5053
+ if (this.active) return this;
5054
+ const currentTop = trapStack[trapStack.length - 1];
5055
+ if (currentTop) {
5056
+ currentTop.pause();
5057
+ }
5058
+ this.active = true;
5059
+ this.paused = false;
5060
+ trapStack.push(this);
5061
+ this.previousActiveElement = document.activeElement;
5062
+ this.setupSentinels();
5063
+ if (this.options.setInert) {
5064
+ this.applyInert();
5065
+ }
5066
+ document.addEventListener("keydown", this.handleKeyDownBound, true);
5067
+ document.addEventListener("focusin", this.handleFocusInBound, true);
5068
+ if (!this.options.allowOutsideClick) {
5069
+ document.addEventListener("mousedown", this.handleClickOutsideBound, true);
5070
+ document.addEventListener("touchstart", this.handleClickOutsideBound, true);
5071
+ }
5072
+ this.applyInitialFocus();
5073
+ this.runAuditWarning(this.options.audit);
5074
+ this.options.onActivate();
5075
+ return this;
5076
+ }
5077
+ /**
5078
+ * Désactive le trap et libère les écouteurs.
5079
+ */
5080
+ deactivate() {
5081
+ if (!this.active) return this;
5082
+ this.active = false;
5083
+ this.paused = false;
5084
+ const index = trapStack.indexOf(this);
5085
+ if (index !== -1) {
5086
+ trapStack.splice(index, 1);
5087
+ }
5088
+ const nextTop = trapStack[trapStack.length - 1];
5089
+ if (nextTop) {
5090
+ nextTop.unpause();
5091
+ }
5092
+ document.removeEventListener("keydown", this.handleKeyDownBound, true);
5093
+ document.removeEventListener("focusin", this.handleFocusInBound, true);
5094
+ document.removeEventListener("mousedown", this.handleClickOutsideBound, true);
5095
+ document.removeEventListener("touchstart", this.handleClickOutsideBound, true);
5096
+ this.removeSentinels();
5097
+ this.removeInert();
5098
+ if (this.options.returnFocus) {
5099
+ this.restoreFocus();
5100
+ }
5101
+ this.options.onDeactivate();
5102
+ return this;
5103
+ }
5104
+ /**
5105
+ * Met en pause le trap (utilisé quand un trap fils s'ouvre au-dessus).
5106
+ */
5107
+ pause() {
5108
+ this.paused = true;
5109
+ }
5110
+ /**
5111
+ * Sort de pause.
5112
+ */
5113
+ unpause() {
5114
+ this.paused = false;
5115
+ }
5116
+ /**
5117
+ * Indique si le trap est actuellement actif et non en pause.
5118
+ */
5119
+ isActive() {
5120
+ return this.active && !this.paused;
5121
+ }
5122
+ /**
5123
+ * Vérifie la conformité d'accessibilité WAI-ARIA du conteneur FocusTrap
5124
+ * et retourne la liste des contraintes manquantes.
5125
+ */
5126
+ audit() {
5127
+ const warnings = [];
5128
+ const role = this.element.getAttribute("role");
5129
+ const isNativeDialog = this.element.tagName.toLowerCase() === "dialog";
5130
+ const validRoles = ["dialog", "alertdialog", "menu", "listbox", "tree", "grid"];
5131
+ if (!isNativeDialog && (!role || !validRoles.includes(role))) {
5132
+ warnings.push(
5133
+ 'R\xF4le s\xE9mantique manquant ou inadapt\xE9 : d\xE9finissez role="dialog" (ou "alertdialog", "menu", "listbox") sur le conteneur.'
5134
+ );
5135
+ }
5136
+ if ((isNativeDialog || role === "dialog" || role === "alertdialog") && this.element.getAttribute("aria-modal") !== "true") {
5137
+ warnings.push(
5138
+ 'Isolation modale manquante : d\xE9finissez aria-modal="true" sur le conteneur de dialogue (WCAG 4.1.2).'
5139
+ );
5140
+ }
5141
+ const ariaLabel = this.element.getAttribute("aria-label")?.trim();
5142
+ const hasValidLabelledby = this.checkAriaIdReferences(this.element, "aria-labelledby", warnings);
5143
+ if (!ariaLabel && !hasValidLabelledby) {
5144
+ warnings.push(
5145
+ 'Nom accessible manquant : d\xE9finissez aria-labelledby="id-titre" ou aria-label="..." sur le conteneur (WCAG 4.1.2).'
5146
+ );
5147
+ }
5148
+ return warnings;
5149
+ }
5150
+ getAuditPrefix() {
5151
+ return "Wulf.FocusTrap";
5152
+ }
5153
+ getAuditTargetLabel() {
5154
+ return this.element.id ? `#${this.element.id}` : `<${this.element.tagName.toLowerCase()}>`;
5155
+ }
5156
+ /**
5157
+ * Détruit l'instance proprement.
5158
+ */
5159
+ destroy() {
5160
+ this.deactivate();
5161
+ }
5162
+ // --- Implémentation interne ---
5163
+ handleKeyDown(e) {
5164
+ if (!this.isActive()) return;
5165
+ if (e.key === "Escape" && this.options.escapeDeactivates) {
5166
+ e.preventDefault();
5167
+ e.stopPropagation();
5168
+ this.deactivate();
5169
+ return;
5170
+ }
5171
+ if (e.key !== "Tab") return;
5172
+ const focusables = this.getFocusableElements();
5173
+ if (focusables.length === 0) {
5174
+ e.preventDefault();
5175
+ if (this.element.getAttribute("tabindex") === null) {
5176
+ this.element.setAttribute("tabindex", "-1");
5177
+ }
5178
+ this.element.focus();
5179
+ return;
5180
+ }
5181
+ const first = focusables[0];
5182
+ const last = focusables[focusables.length - 1];
5183
+ const current = document.activeElement;
5184
+ if (!e.shiftKey && (current === last || !this.element.contains(current))) {
5185
+ e.preventDefault();
5186
+ first.focus();
5187
+ } else if (e.shiftKey && (current === first || !this.element.contains(current))) {
5188
+ e.preventDefault();
5189
+ last.focus();
5190
+ }
5191
+ }
5192
+ handleFocusIn(e) {
5193
+ if (!this.isActive()) return;
5194
+ const target = e.target;
5195
+ if (!target) return;
5196
+ if (target === this.startSentinel) {
5197
+ const focusables = this.getFocusableElements();
5198
+ if (focusables.length > 0) {
5199
+ focusables[focusables.length - 1].focus();
5200
+ } else {
5201
+ this.element.focus();
5202
+ }
5203
+ return;
5204
+ }
5205
+ if (target === this.endSentinel) {
5206
+ const focusables = this.getFocusableElements();
5207
+ if (focusables.length > 0) {
5208
+ focusables[0].focus();
5209
+ } else {
5210
+ this.element.focus();
5211
+ }
5212
+ return;
5213
+ }
5214
+ if (!this.element.contains(target)) {
5215
+ const focusables = this.getFocusableElements();
5216
+ if (focusables.length > 0) {
5217
+ focusables[0].focus();
5218
+ } else {
5219
+ if (this.element.getAttribute("tabindex") === null) {
5220
+ this.element.setAttribute("tabindex", "-1");
5221
+ }
5222
+ this.element.focus();
5223
+ }
5224
+ }
5225
+ }
5226
+ handleClickOutside(e) {
5227
+ if (!this.isActive()) return;
5228
+ const target = e.target;
5229
+ if (target && !this.element.contains(target)) {
5230
+ e.preventDefault();
5231
+ e.stopPropagation();
5232
+ }
5233
+ }
5234
+ setupSentinels() {
5235
+ if (!this.startSentinel) {
5236
+ this.startSentinel = document.createElement("span");
5237
+ this.startSentinel.setAttribute("tabindex", "0");
5238
+ this.startSentinel.setAttribute("aria-hidden", "true");
5239
+ this.startSentinel.className = "wulf-sentinel-start";
5240
+ this.startSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
5241
+ }
5242
+ if (!this.endSentinel) {
5243
+ this.endSentinel = document.createElement("span");
5244
+ this.endSentinel.setAttribute("tabindex", "0");
5245
+ this.endSentinel.setAttribute("aria-hidden", "true");
5246
+ this.endSentinel.className = "wulf-sentinel-end";
5247
+ this.endSentinel.style.cssText = "position:fixed;top:0;left:0;opacity:0;pointer-events:none;width:0;height:0;";
5248
+ }
5249
+ if (this.element.parentNode) {
5250
+ this.element.parentNode.insertBefore(this.startSentinel, this.element);
5251
+ this.element.parentNode.insertBefore(this.endSentinel, this.element.nextSibling);
5252
+ }
5253
+ }
5254
+ removeSentinels() {
5255
+ this.startSentinel?.remove();
5256
+ this.endSentinel?.remove();
5257
+ this.startSentinel = null;
5258
+ this.endSentinel = null;
5259
+ }
5260
+ applyInert() {
5261
+ this.inertSiblings = [];
5262
+ let parent = this.element.parentElement;
5263
+ let currentChild = this.element;
5264
+ while (parent && parent !== document.body) {
5265
+ currentChild = parent;
5266
+ parent = parent.parentElement;
5267
+ }
5268
+ if (parent === document.body) {
5269
+ Array.from(document.body.children).forEach((child) => {
5270
+ if (child instanceof HTMLElement && child !== currentChild && child !== this.startSentinel && child !== this.endSentinel && !child.hasAttribute("inert")) {
5271
+ child.setAttribute("inert", "");
5272
+ this.inertSiblings.push(child);
5273
+ }
5274
+ });
5275
+ }
5276
+ }
5277
+ removeInert() {
5278
+ this.inertSiblings.forEach((el) => el.removeAttribute("inert"));
5279
+ this.inertSiblings = [];
5280
+ }
5281
+ applyInitialFocus() {
5282
+ if (this.options.initialFocus === false) return;
5283
+ let targetEl = null;
5284
+ if (typeof this.options.initialFocus === "string") {
5285
+ targetEl = this.element.querySelector(this.options.initialFocus);
5286
+ } else if (this.options.initialFocus instanceof HTMLElement) {
5287
+ targetEl = this.options.initialFocus;
5288
+ }
5289
+ if (targetEl && this.isFocusable(targetEl)) {
5290
+ targetEl.focus();
5291
+ return;
5292
+ }
5293
+ const focusables = this.getFocusableElements();
5294
+ if (focusables.length > 0) {
5295
+ focusables[0].focus();
5296
+ } else {
5297
+ if (this.element.getAttribute("tabindex") === null) {
5298
+ this.element.setAttribute("tabindex", "-1");
5299
+ }
5300
+ this.element.focus();
5301
+ }
5302
+ }
5303
+ restoreFocus() {
5304
+ if (this.previousActiveElement && this.previousActiveElement.isConnected) {
5305
+ this.previousActiveElement.focus();
5306
+ return;
5307
+ }
5308
+ if (this.options.fallbackReturnFocus) {
5309
+ const fallback = typeof this.options.fallbackReturnFocus === "string" ? document.querySelector(this.options.fallbackReturnFocus) : this.options.fallbackReturnFocus;
5310
+ if (fallback && fallback.isConnected) {
5311
+ fallback.focus();
5312
+ }
5313
+ }
5314
+ }
5315
+ };
5316
+
5317
+ // src/focus-trap/index.ts
5318
+ if (typeof window !== "undefined") {
5319
+ const win = window;
5320
+ const wulfNamespace = win.Wulf || {};
5321
+ win.Wulf = wulfNamespace;
5322
+ wulfNamespace.FocusTrap = Object.assign(FocusTrap, {
5323
+ FocusTrap
5324
+ });
5325
+ }
5326
+
5327
+ // src/shortcut/index.ts
5328
+ var shortcut_exports = {};
5329
+ __export(shortcut_exports, {
5330
+ ShortcutFormatter: () => ShortcutFormatter,
5331
+ ShortcutManager: () => ShortcutManager,
5332
+ default: () => ShortcutManager
5333
+ });
5334
+
5335
+ // src/shortcut/ShortcutFormatter.ts
5336
+ var ShortcutFormatter = class _ShortcutFormatter {
5337
+ /**
5338
+ * Détecte si l'environnement d'exécution actuel est un environnement Apple (macOS / iOS / iPadOS).
5339
+ */
5340
+ static isApple() {
5341
+ if (typeof navigator === "undefined") {
5342
+ return false;
5343
+ }
5344
+ const uaData = navigator.userAgentData;
5345
+ if (uaData && typeof uaData.platform === "string") {
5346
+ const p = uaData.platform.toLowerCase();
5347
+ if (p.includes("mac") || p.includes("ios")) {
5348
+ return true;
5349
+ }
5350
+ }
5351
+ const platform = (navigator.platform || "").toLowerCase();
5352
+ if (platform.includes("mac") || platform.includes("iphone") || platform.includes("ipad") || platform.includes("ipod")) {
5353
+ return true;
5354
+ }
5355
+ const ua = (navigator.userAgent || "").toLowerCase();
5356
+ return ua.includes("macintosh") || ua.includes("mac os x") || ua.includes("ipad") || ua.includes("iphone");
5357
+ }
5358
+ /**
5359
+ * Normalise un nom de touche unitaire pour les comparaisons.
5360
+ */
5361
+ static normalizeKeyName(key) {
5362
+ const k = key.trim().toLowerCase();
5363
+ switch (k) {
5364
+ case "esc":
5365
+ return "escape";
5366
+ case "return":
5367
+ return "enter";
5368
+ case "space":
5369
+ case "spacebar":
5370
+ return " ";
5371
+ case "del":
5372
+ return "delete";
5373
+ case "ins":
5374
+ return "insert";
5375
+ case "up":
5376
+ return "arrowup";
5377
+ case "down":
5378
+ return "arrowdown";
5379
+ case "left":
5380
+ return "arrowleft";
5381
+ case "right":
5382
+ return "arrowright";
5383
+ default:
5384
+ return k;
5385
+ }
5386
+ }
5387
+ /**
5388
+ * Parse une chaîne de combinaison (ex: "Mod+K", "g i", "Shift+?", "Alt++")
5389
+ * et retourne la liste des étapes normalisées nécessaires au déclenchement.
5390
+ */
5391
+ static parseCombo(combo, isApple = _ShortcutFormatter.isApple()) {
5392
+ const trimmed = combo.trim();
5393
+ if (!trimmed) {
5394
+ return [];
5395
+ }
5396
+ const stepsRaw = trimmed.split(/\s+/);
5397
+ const steps = [];
5398
+ for (const rawStep of stepsRaw) {
5399
+ const tokens = [];
5400
+ let currentToken = "";
5401
+ for (let i = 0; i < rawStep.length; i++) {
5402
+ const char = rawStep[i];
5403
+ if (char === "+") {
5404
+ if (currentToken === "" && tokens.length > 0) {
5405
+ tokens.push("+");
5406
+ } else if (currentToken !== "") {
5407
+ tokens.push(currentToken);
5408
+ currentToken = "";
5409
+ }
5410
+ } else {
5411
+ currentToken += char;
5412
+ }
5413
+ }
5414
+ if (currentToken !== "") {
5415
+ tokens.push(currentToken);
5416
+ }
5417
+ let ctrl = false;
5418
+ let alt = false;
5419
+ let shift = false;
5420
+ let meta = false;
5421
+ let mainKey = "";
5422
+ for (const token of tokens) {
5423
+ const lower = token.trim().toLowerCase();
5424
+ if (lower === "ctrl" || lower === "control") {
5425
+ ctrl = true;
5426
+ } else if (lower === "alt" || lower === "option" || lower === "opt") {
5427
+ alt = true;
5428
+ } else if (lower === "shift" || lower === "maj") {
5429
+ shift = true;
5430
+ } else if (lower === "cmd" || lower === "command" || lower === "meta" || lower === "win" || lower === "super") {
5431
+ meta = true;
5432
+ } else if (lower === "mod" || lower === "$mod") {
5433
+ if (isApple) {
5434
+ meta = true;
5435
+ } else {
5436
+ ctrl = true;
5437
+ }
5438
+ } else {
5439
+ mainKey = _ShortcutFormatter.normalizeKeyName(token);
5440
+ }
5441
+ }
5442
+ steps.push({
5443
+ ctrl,
5444
+ alt,
5445
+ shift,
5446
+ meta,
5447
+ key: mainKey
5448
+ });
5449
+ }
5450
+ return steps;
5451
+ }
5452
+ /**
5453
+ * Formate une combinaison brute en libellé soigné et lisible pour l'OS cible.
5454
+ * Ex: "Mod+Shift+P" -> macOS: "⇧⌘P", Windows: "Ctrl+Shift+P"
5455
+ * Ex: "g i" -> "g puis i" ou "g i"
5456
+ */
5457
+ static format(combo, isApple = _ShortcutFormatter.isApple()) {
5458
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
5459
+ if (steps.length === 0) {
5460
+ return combo;
5461
+ }
5462
+ const formattedSteps = steps.map((step) => {
5463
+ const parts = [];
5464
+ if (isApple) {
5465
+ if (step.ctrl) parts.push("\u2303");
5466
+ if (step.alt) parts.push("\u2325");
5467
+ if (step.shift) parts.push("\u21E7");
5468
+ if (step.meta) parts.push("\u2318");
5469
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, true);
5470
+ parts.push(keyDisplay);
5471
+ return parts.join("");
5472
+ } else {
5473
+ if (step.ctrl) parts.push("Ctrl");
5474
+ if (step.alt) parts.push("Alt");
5475
+ if (step.shift) parts.push("Shift");
5476
+ if (step.meta) parts.push("Win");
5477
+ const keyDisplay = _ShortcutFormatter.formatKeyDisplay(step.key, false);
5478
+ parts.push(keyDisplay);
5479
+ return parts.join("+");
5480
+ }
5481
+ });
5482
+ return formattedSteps.join(" ");
5483
+ }
5484
+ /**
5485
+ * Convertit un combo technique vers le format officiel WAI-ARIA `aria-keyshortcuts`.
5486
+ * Standard W3C : les modificateurs sont 'Control', 'Alt', 'Shift', 'Meta' et le séparateur est '+'.
5487
+ */
5488
+ static toAriaKeyShortcuts(combo, isApple = _ShortcutFormatter.isApple()) {
5489
+ const steps = _ShortcutFormatter.parseCombo(combo, isApple);
5490
+ return steps.map((step) => {
5491
+ const parts = [];
5492
+ if (step.ctrl) parts.push("Control");
5493
+ if (step.alt) parts.push("Alt");
5494
+ if (step.shift) parts.push("Shift");
5495
+ if (step.meta) parts.push("Meta");
5496
+ parts.push(_ShortcutFormatter.formatKeyDisplay(step.key, false));
5497
+ return parts.join("+");
5498
+ }).join(" ");
5499
+ }
5500
+ static formatKeyDisplay(key, isApple) {
5501
+ if (!key) return "";
5502
+ switch (key.toLowerCase()) {
5503
+ case "escape":
5504
+ return isApple ? "\u238B" : "Esc";
5505
+ case "enter":
5506
+ return isApple ? "\u21A9" : "Enter";
5507
+ case " ":
5508
+ return isApple ? "\u2423" : "Space";
5509
+ case "tab":
5510
+ return isApple ? "\u21E5" : "Tab";
5511
+ case "backspace":
5512
+ return isApple ? "\u232B" : "Backspace";
5513
+ case "delete":
5514
+ return isApple ? "\u2326" : "Suppr";
5515
+ case "arrowup":
5516
+ return "\u2191";
5517
+ case "arrowdown":
5518
+ return "\u2193";
5519
+ case "arrowleft":
5520
+ return "\u2190";
5521
+ case "arrowright":
5522
+ return "\u2192";
5523
+ default:
5524
+ return key.length === 1 ? key.toUpperCase() : key.charAt(0).toUpperCase() + key.slice(1);
5525
+ }
5526
+ }
5527
+ };
5528
+
5529
+ // src/shortcut/ShortcutManager.ts
5530
+ var ShortcutManager = class _ShortcutManager {
5531
+ constructor(options) {
5532
+ this.shortcuts = /* @__PURE__ */ new Map();
5533
+ this.scopeStack = [];
5534
+ this.sequenceBuffer = [];
5535
+ this.sequenceTimer = null;
5536
+ this.isListening = true;
5537
+ this.boundListener = null;
5538
+ this.idCounter = 0;
5539
+ this.options = {
5540
+ defaultScope: options?.defaultScope || "global",
5541
+ sequenceTimeout: options?.sequenceTimeout ?? 800,
5542
+ target: options?.target || (typeof window !== "undefined" ? window : {}),
5543
+ onError: options?.onError
5544
+ };
5545
+ this.scopeStack = [this.options.defaultScope];
5546
+ this.initListener();
5547
+ }
5548
+ /**
5549
+ * Vérifie si un élément DOM est une zone d'édition où la saisie de l'utilisateur
5550
+ * ne doit JAMAIS être interrompue ou détournée (Axiome Primordial).
5551
+ */
5552
+ static isEditable(target) {
5553
+ if (!target || typeof target.tagName !== "string") {
5554
+ return false;
5555
+ }
5556
+ const el = target;
5557
+ const tagName = el.tagName.toUpperCase();
5558
+ if (tagName === "INPUT") {
5559
+ const type = el.type?.toLowerCase() || "text";
5560
+ const nonTextTypes = ["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"];
5561
+ return !nonTextTypes.includes(type);
5562
+ }
5563
+ if (tagName === "TEXTAREA" || tagName === "SELECT") {
5564
+ return true;
5565
+ }
5566
+ if (el.isContentEditable || el.getAttribute("contenteditable") === "true" || el.getAttribute("contenteditable") === "plaintext-only") {
5567
+ return true;
5568
+ }
5569
+ const role = el.getAttribute("role");
5570
+ if (role === "textbox" || role === "searchbox") {
5571
+ return true;
5572
+ }
5573
+ return false;
5574
+ }
5575
+ /**
5576
+ * Enregistre un ou plusieurs raccourcis clavier.
5577
+ * Retourne une fonction de nettoyage pour désenregistrer immédiatement.
5578
+ */
5579
+ bind(definition) {
5580
+ const list = Array.isArray(definition) ? definition : [definition];
5581
+ const registeredIds = [];
5582
+ for (const def of list) {
5583
+ if (!def.combo || typeof def.handler !== "function") {
5584
+ continue;
5585
+ }
5586
+ const id = `wulf_shortcut_${++this.idCounter}`;
5587
+ const normalizedSteps = ShortcutFormatter.parseCombo(def.combo);
5588
+ const isSequence = normalizedSteps.length > 1;
5589
+ const formattedCombo = ShortcutFormatter.format(def.combo);
5590
+ const registered = {
5591
+ ...def,
5592
+ id,
5593
+ scope: def.scope || "global",
5594
+ category: def.category || "G\xE9n\xE9ral",
5595
+ allowInEditable: def.allowInEditable ?? false,
5596
+ preventDefault: def.preventDefault ?? true,
5597
+ stopPropagation: def.stopPropagation ?? true,
5598
+ priority: def.priority ?? 0,
5599
+ formattedCombo,
5600
+ normalizedSteps,
5601
+ isSequence
5602
+ };
5603
+ this.shortcuts.set(id, registered);
5604
+ registeredIds.push(id);
5605
+ }
5606
+ return () => {
5607
+ for (const id of registeredIds) {
5608
+ this.shortcuts.delete(id);
5609
+ }
5610
+ };
5611
+ }
5612
+ /**
5613
+ * Retire tous les raccourcis correspondant à une combinaison et éventuellement un scope.
5614
+ */
5615
+ unbind(combo, scope) {
5616
+ const formatted = ShortcutFormatter.format(combo);
5617
+ for (const [id, s] of this.shortcuts.entries()) {
5618
+ if (s.formattedCombo === formatted || s.combo.trim().toLowerCase() === combo.trim().toLowerCase()) {
5619
+ if (!scope || s.scope === scope) {
5620
+ this.shortcuts.delete(id);
5621
+ }
5622
+ }
5623
+ }
5624
+ }
5625
+ /**
5626
+ * Empile un nouveau scope actif (mode LIFO).
5627
+ * Seuls les raccourcis de ce scope (et les omniprésents '*') seront actifs.
5628
+ */
5629
+ pushScope(scope) {
5630
+ if (scope && typeof scope === "string") {
5631
+ this.scopeStack.push(scope);
5632
+ this.clearSequenceBuffer();
5633
+ }
5634
+ }
5635
+ /**
5636
+ * Dépile le scope actuel et rétablit le précédent.
5637
+ * Si un paramètre `scope` est passé, ne retire que si le scope actuel correspond.
5638
+ */
5639
+ popScope(scope) {
5640
+ if (this.scopeStack.length <= 1) {
5641
+ return this.scopeStack[0];
5642
+ }
5643
+ if (scope) {
5644
+ if (this.getScope() === scope) {
5645
+ const popped2 = this.scopeStack.pop();
5646
+ this.clearSequenceBuffer();
5647
+ return popped2;
5648
+ }
5649
+ return void 0;
5650
+ }
5651
+ const popped = this.scopeStack.pop();
5652
+ this.clearSequenceBuffer();
5653
+ return popped;
5654
+ }
5655
+ /**
5656
+ * Réinitialise brutalement la pile pour activer le scope spécifié.
5657
+ */
5658
+ setScope(scope) {
5659
+ this.scopeStack = [scope || this.options.defaultScope];
5660
+ this.clearSequenceBuffer();
5661
+ }
5662
+ /**
5663
+ * Retourne le scope actuellement actif au sommet de la pile.
5664
+ */
5665
+ getScope() {
5666
+ return this.scopeStack[this.scopeStack.length - 1] || this.options.defaultScope;
5667
+ }
5668
+ /**
5669
+ * Retourne une copie de la pile complète des scopes.
5670
+ */
5671
+ getScopeStack() {
5672
+ return [...this.scopeStack];
5673
+ }
5674
+ /**
5675
+ * Met en pause l'écoute de tous les raccourcis.
5676
+ */
5677
+ pause() {
5678
+ this.isListening = false;
5679
+ this.clearSequenceBuffer();
5680
+ }
5681
+ /**
5682
+ * Réactive l'écoute des raccourcis.
5683
+ */
5684
+ resume() {
5685
+ this.isListening = true;
5686
+ }
5687
+ /**
5688
+ * Indique si le gestionnaire est actif et à l'écoute.
5689
+ */
5690
+ isActive() {
5691
+ return this.isListening;
5692
+ }
5693
+ /**
5694
+ * Retourne le catalogue des raccourcis enregistrés (optionnellement filtré par scope).
5695
+ */
5696
+ getRegistry(scope) {
5697
+ const list = [];
5698
+ for (const shortcut of this.shortcuts.values()) {
5699
+ if (!scope || shortcut.scope === scope || shortcut.scope === "*") {
5700
+ list.push({ ...shortcut });
5701
+ }
5702
+ }
5703
+ return list;
5704
+ }
5705
+ /**
5706
+ * Associe l'attribut standard WAI-ARIA `aria-keyshortcuts` sur un élément DOM.
5707
+ */
5708
+ attachAria(element, combo) {
5709
+ if (element && typeof element.setAttribute === "function") {
5710
+ const ariaValue = ShortcutFormatter.toAriaKeyShortcuts(combo);
5711
+ element.setAttribute("aria-keyshortcuts", ariaValue);
5712
+ }
5713
+ }
5714
+ /**
5715
+ * Formate une combinaison brute selon l'OS courant ("⌘K" ou "Ctrl+K").
5716
+ */
5717
+ static format(combo, isApple) {
5718
+ return ShortcutFormatter.format(combo, isApple);
5719
+ }
5720
+ /**
5721
+ * Détruit le gestionnaire : supprime les écouteurs du DOM et vide toute la mémoire.
5722
+ */
5723
+ destroy() {
5724
+ this.pause();
5725
+ this.removeListener();
5726
+ this.shortcuts.clear();
5727
+ this.scopeStack = [];
5728
+ this.clearSequenceBuffer();
5729
+ }
5730
+ // --- Implémentation Interne ---
5731
+ initListener() {
5732
+ if (typeof window === "undefined" || !this.options.target) {
5733
+ return;
5734
+ }
5735
+ this.boundListener = (event) => this.handleKeyDown(event);
5736
+ const target = this.options.target;
5737
+ if (typeof target.addEventListener === "function") {
5738
+ target.addEventListener("keydown", this.boundListener, false);
5739
+ }
5740
+ }
5741
+ removeListener() {
5742
+ if (this.boundListener && this.options.target) {
5743
+ const target = this.options.target;
5744
+ if (typeof target.removeEventListener === "function") {
5745
+ target.removeEventListener("keydown", this.boundListener, false);
5746
+ }
5747
+ this.boundListener = null;
5748
+ }
5749
+ }
5750
+ handleKeyDown(event) {
5751
+ if (!this.isListening) {
5752
+ return;
5753
+ }
5754
+ const k = (event.key || "").toLowerCase();
5755
+ if (["control", "alt", "shift", "meta"].includes(k)) {
5756
+ return;
5757
+ }
5758
+ const currentScope = this.getScope();
5759
+ const isEditable = _ShortcutManager.isEditable(event.target);
5760
+ const currentStep = {
5761
+ ctrl: event.ctrlKey,
5762
+ alt: event.altKey,
5763
+ shift: event.shiftKey,
5764
+ meta: event.metaKey,
5765
+ key: ShortcutFormatter.normalizeKeyName(event.key || "")
5766
+ };
5767
+ const now = Date.now();
5768
+ if (this.sequenceBuffer.length > 0) {
5769
+ const last = this.sequenceBuffer[this.sequenceBuffer.length - 1];
5770
+ if (now - last.timestamp > this.options.sequenceTimeout) {
5771
+ this.clearSequenceBuffer();
5772
+ }
5773
+ }
5774
+ const activeCandidates = this.getActiveShortcuts(currentScope, isEditable);
5775
+ const proposedSequence = [...this.sequenceBuffer.map((b) => b.step), currentStep];
5776
+ const matchingSequence = this.findMatchingSequence(activeCandidates, proposedSequence);
5777
+ if (matchingSequence) {
5778
+ this.clearSequenceBuffer();
5779
+ this.executeShortcut(matchingSequence, event, currentScope, true);
5780
+ return;
5781
+ }
5782
+ if (this.isPrefixOfAnySequence(activeCandidates, proposedSequence)) {
5783
+ this.sequenceBuffer.push({ step: currentStep, timestamp: now });
5784
+ this.resetSequenceTimer();
5785
+ if (event.key.length === 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !isEditable) {
5786
+ event.preventDefault();
5787
+ }
5788
+ return;
5789
+ }
5790
+ this.clearSequenceBuffer();
5791
+ const matchingChord = this.findMatchingChord(activeCandidates, currentStep, event);
5792
+ if (matchingChord) {
5793
+ this.executeShortcut(matchingChord, event, currentScope, false);
5794
+ }
5795
+ }
5796
+ getActiveShortcuts(currentScope, isEditable) {
5797
+ const list = [];
5798
+ for (const shortcut of this.shortcuts.values()) {
5799
+ if (shortcut.scope !== currentScope && shortcut.scope !== "*") {
5800
+ continue;
5801
+ }
5802
+ if (isEditable && !shortcut.allowInEditable) {
5803
+ continue;
5804
+ }
5805
+ list.push(shortcut);
5806
+ }
5807
+ return list.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
5808
+ }
5809
+ stepMatches(step, eventStep, rawEvent) {
5810
+ if (step.ctrl !== eventStep.ctrl) return false;
5811
+ if (step.alt !== eventStep.alt) return false;
5812
+ if (step.meta !== eventStep.meta) return false;
5813
+ const keyMatches = step.key === eventStep.key || rawEvent && step.key === rawEvent.key.toLowerCase();
5814
+ if (!keyMatches) return false;
5815
+ if (step.shift === eventStep.shift) {
5816
+ return true;
5817
+ }
5818
+ if (!step.shift && eventStep.shift) {
5819
+ if (rawEvent && rawEvent.key === step.key) {
5820
+ return true;
5821
+ }
5822
+ }
5823
+ return false;
5824
+ }
5825
+ findMatchingChord(candidates, currentStep, rawEvent) {
5826
+ for (const candidate of candidates) {
5827
+ if (candidate.isSequence || candidate.normalizedSteps.length !== 1) {
5828
+ continue;
5829
+ }
5830
+ const step = candidate.normalizedSteps[0];
5831
+ if (this.stepMatches(step, currentStep, rawEvent)) {
5832
+ return candidate;
5833
+ }
5834
+ }
5835
+ return null;
5836
+ }
5837
+ findMatchingSequence(candidates, proposed) {
5838
+ for (const candidate of candidates) {
5839
+ if (!candidate.isSequence || candidate.normalizedSteps.length !== proposed.length) {
5840
+ continue;
5841
+ }
5842
+ let allMatch = true;
5843
+ for (let i = 0; i < proposed.length; i++) {
5844
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
5845
+ allMatch = false;
5846
+ break;
5847
+ }
5848
+ }
5849
+ if (allMatch) {
5850
+ return candidate;
5851
+ }
5852
+ }
5853
+ return null;
5854
+ }
5855
+ isPrefixOfAnySequence(candidates, proposed) {
5856
+ for (const candidate of candidates) {
5857
+ if (!candidate.isSequence || candidate.normalizedSteps.length <= proposed.length) {
5858
+ continue;
5859
+ }
5860
+ let prefixMatches = true;
5861
+ for (let i = 0; i < proposed.length; i++) {
5862
+ if (!this.stepMatches(candidate.normalizedSteps[i], proposed[i])) {
5863
+ prefixMatches = false;
5864
+ break;
5865
+ }
5866
+ }
5867
+ if (prefixMatches) {
5868
+ return true;
5869
+ }
5870
+ }
5871
+ return false;
5872
+ }
5873
+ executeShortcut(shortcut, event, scope, isSequence) {
5874
+ if (shortcut.preventDefault) {
5875
+ event.preventDefault();
5876
+ }
5877
+ if (shortcut.stopPropagation) {
5878
+ event.stopPropagation();
5879
+ }
5880
+ const info = {
5881
+ combo: shortcut.combo,
5882
+ formattedCombo: shortcut.formattedCombo,
5883
+ scope,
5884
+ target: event.target,
5885
+ isSequence
5886
+ };
5887
+ try {
5888
+ shortcut.handler(event, info);
5889
+ } catch (err) {
5890
+ if (this.options.onError) {
5891
+ this.options.onError(err instanceof Error ? err : new Error(String(err)), shortcut.combo);
5892
+ } else {
5893
+ console.error(`[Wulf.Shortcut] Erreur lors de l'ex\xE9cution du raccourci "${shortcut.combo}":`, err);
5894
+ }
5895
+ }
5896
+ }
5897
+ resetSequenceTimer() {
5898
+ if (this.sequenceTimer) {
5899
+ clearTimeout(this.sequenceTimer);
5900
+ }
5901
+ this.sequenceTimer = setTimeout(() => {
5902
+ this.clearSequenceBuffer();
5903
+ }, this.options.sequenceTimeout);
5904
+ }
5905
+ clearSequenceBuffer() {
5906
+ this.sequenceBuffer = [];
5907
+ if (this.sequenceTimer) {
5908
+ clearTimeout(this.sequenceTimer);
5909
+ this.sequenceTimer = null;
5910
+ }
5911
+ }
5912
+ };
4747
5913
  export {
4748
5914
  AmountEngine,
5915
+ AuditableComponent,
4749
5916
  BaseInputMask,
4750
5917
  EmailEngine,
5918
+ focus_trap_exports as FocusTrap,
4751
5919
  InputAmountMask,
4752
5920
  InputEmailMask,
4753
5921
  InputMask,
@@ -4758,7 +5926,10 @@ export {
4758
5926
  MaskKeyboard,
4759
5927
  masonry_exports as Masonry,
4760
5928
  scroll_exports as Scroll,
5929
+ shortcut_exports as Shortcut,
4761
5930
  toast_exports as Toast,
5931
+ FocusTrap as WulfFocusTrap,
5932
+ ShortcutManager as WulfShortcut,
4762
5933
  createI18nManager,
4763
5934
  mask_default as default,
4764
5935
  resolveMaskConstructorArgs