wulf.js 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +217 -11
  2. package/changelog.md +50 -0
  3. package/dist/anchor.esm.js +9 -0
  4. package/dist/anchor.esm.js.map +7 -0
  5. package/dist/anchor.global.js +695 -0
  6. package/dist/anchor.global.js.map +7 -0
  7. package/dist/anchor.global.min.js +6 -0
  8. package/dist/anchor.global.min.js.map +7 -0
  9. package/dist/autosize.css +1 -0
  10. package/dist/autosize.css.map +7 -0
  11. package/dist/autosize.esm.js +10 -0
  12. package/dist/autosize.esm.js.map +7 -0
  13. package/dist/autosize.global.js +657 -0
  14. package/dist/autosize.global.js.map +7 -0
  15. package/dist/autosize.global.min.js +6 -0
  16. package/dist/autosize.global.min.js.map +7 -0
  17. package/dist/autosize.layered.css +1 -0
  18. package/dist/autosize.layered.css.map +7 -0
  19. package/dist/chunks/chunk-22AIMRD5.js +119 -0
  20. package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
  21. package/dist/chunks/chunk-5N2IRGDM.js +766 -0
  22. package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
  23. package/dist/chunks/chunk-72FVCNNZ.js +863 -0
  24. package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
  25. package/dist/chunks/chunk-AXZYYW7H.js +865 -0
  26. package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
  27. package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
  28. package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
  29. package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
  30. package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
  31. package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
  32. package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
  33. package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
  34. package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
  35. package/dist/chunks/chunk-QV46A7FV.js +197 -0
  36. package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
  37. package/dist/chunks/chunk-SXLUXN6W.js +612 -0
  38. package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
  39. package/dist/chunks/chunk-T2H4EJCW.js +621 -0
  40. package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
  41. package/dist/chunks/chunk-TILLYEF2.js +6044 -0
  42. package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
  43. package/dist/chunks/chunk-VJO22BAT.js +72 -0
  44. package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
  45. package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
  46. package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
  47. package/dist/focus-trap.esm.js +6 -594
  48. package/dist/focus-trap.esm.js.map +3 -3
  49. package/dist/focus-trap.global.js +176 -61
  50. package/dist/focus-trap.global.js.map +3 -3
  51. package/dist/focus-trap.global.min.js +4 -4
  52. package/dist/focus-trap.global.min.js.map +4 -4
  53. package/dist/index.esm.js +79 -10448
  54. package/dist/index.esm.js.map +4 -4
  55. package/dist/index.global.js +3660 -202
  56. package/dist/index.global.js.map +4 -4
  57. package/dist/index.global.min.js +6 -3
  58. package/dist/index.global.min.js.map +4 -4
  59. package/dist/mask.esm.js +16 -6094
  60. package/dist/mask.esm.js.map +4 -4
  61. package/dist/mask.global.js +44 -55
  62. package/dist/mask.global.js.map +3 -3
  63. package/dist/mask.global.min.js +3 -3
  64. package/dist/mask.global.min.js.map +4 -4
  65. package/dist/masonry.esm.js +15 -1158
  66. package/dist/masonry.esm.js.map +4 -4
  67. package/dist/masonry.global.js +84 -94
  68. package/dist/masonry.global.js.map +3 -3
  69. package/dist/masonry.global.min.js +4 -4
  70. package/dist/masonry.global.min.js.map +4 -4
  71. package/dist/scroll.css +1 -1
  72. package/dist/scroll.css.map +2 -2
  73. package/dist/scroll.esm.js +14 -1252
  74. package/dist/scroll.esm.js.map +3 -3
  75. package/dist/scroll.global.js +64 -58
  76. package/dist/scroll.global.js.map +3 -3
  77. package/dist/scroll.global.min.js +3 -3
  78. package/dist/scroll.global.min.js.map +4 -4
  79. package/dist/scroll.layered.css +1 -1
  80. package/dist/scroll.layered.css.map +2 -2
  81. package/dist/shortcut.esm.js +6 -901
  82. package/dist/shortcut.esm.js.map +4 -4
  83. package/dist/shortcut.global.js +43 -36
  84. package/dist/shortcut.global.js.map +3 -3
  85. package/dist/shortcut.global.min.js +6 -3
  86. package/dist/shortcut.global.min.js.map +4 -4
  87. package/dist/size-report.json +319 -0
  88. package/dist/sortable.css +1 -0
  89. package/dist/sortable.css.map +7 -0
  90. package/dist/sortable.esm.js +22 -0
  91. package/dist/sortable.esm.js.map +7 -0
  92. package/dist/sortable.global.js +1477 -0
  93. package/dist/sortable.global.js.map +7 -0
  94. package/dist/sortable.global.min.js +6 -0
  95. package/dist/sortable.global.min.js.map +7 -0
  96. package/dist/sortable.layered.css +1 -0
  97. package/dist/sortable.layered.css.map +7 -0
  98. package/dist/sri-manifest.json +64 -0
  99. package/dist/toast.css +1 -1
  100. package/dist/toast.css.map +2 -2
  101. package/dist/toast.esm.js +19 -1208
  102. package/dist/toast.esm.js.map +3 -3
  103. package/dist/toast.global.js +314 -111
  104. package/dist/toast.global.js.map +3 -3
  105. package/dist/toast.global.min.js +3 -3
  106. package/dist/toast.global.min.js.map +4 -4
  107. package/dist/toast.layered.css +1 -1
  108. package/dist/toast.layered.css.map +2 -2
  109. package/dist/types/anchor/Anchor.d.ts +41 -0
  110. package/dist/types/anchor/index.d.ts +3 -0
  111. package/dist/types/anchor/types.d.ts +115 -0
  112. package/dist/types/autosize/Autosize.d.ts +71 -0
  113. package/dist/types/autosize/index.d.ts +3 -0
  114. package/dist/types/autosize/types.d.ts +66 -0
  115. package/dist/types/common/AuditableComponent.d.ts +1 -1
  116. package/dist/types/common/registry.d.ts +40 -0
  117. package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
  118. package/dist/types/index.d.ts +13 -1
  119. package/dist/types/scroll/types.d.ts +6 -0
  120. package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
  121. package/dist/types/shortcut/types.d.ts +5 -0
  122. package/dist/types/sortable/Sortable.d.ts +75 -0
  123. package/dist/types/sortable/i18n/en.d.ts +2 -0
  124. package/dist/types/sortable/i18n/fr.d.ts +2 -0
  125. package/dist/types/sortable/i18n/index.d.ts +9 -0
  126. package/dist/types/sortable/i18n/types.d.ts +15 -0
  127. package/dist/types/sortable/index.d.ts +4 -0
  128. package/dist/types/sortable/types.d.ts +112 -0
  129. package/dist/types/toast/Toast.d.ts +6 -1
  130. package/dist/types/toast/ToastInstance.d.ts +7 -0
  131. package/dist/types/toast/ToastManager.d.ts +2 -2
  132. package/dist/types/toast/types.d.ts +27 -1
  133. package/dist/types/undo/UndoManager.d.ts +112 -0
  134. package/dist/types/undo/i18n/en.d.ts +2 -0
  135. package/dist/types/undo/i18n/fr.d.ts +2 -0
  136. package/dist/types/undo/i18n/index.d.ts +9 -0
  137. package/dist/types/undo/i18n/types.d.ts +6 -0
  138. package/dist/types/undo/index.d.ts +5 -0
  139. package/dist/types/undo/types.d.ts +106 -0
  140. package/dist/undo.esm.js +23 -0
  141. package/dist/undo.esm.js.map +7 -0
  142. package/dist/undo.global.js +1029 -0
  143. package/dist/undo.global.js.map +7 -0
  144. package/dist/undo.global.min.js +6 -0
  145. package/dist/undo.global.min.js.map +7 -0
  146. package/package.json +54 -5
@@ -27,75 +27,12 @@ var __WulfIIFE = (() => {
27
27
  ToastManager: () => ToastManager,
28
28
  createI18nManager: () => createI18nManager,
29
29
  default: () => index_default,
30
+ isSafeCssValue: () => isSafeCssValue,
30
31
  toastEn: () => toastEn,
31
32
  toastFr: () => toastFr,
32
33
  toastI18n: () => toastI18n
33
34
  });
34
35
 
35
- // src/common/dom.ts
36
- function getSafeWulfNamespace() {
37
- if (typeof window === "undefined") return null;
38
- const win = window;
39
- const existing = win.Wulf;
40
- if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
41
- const fresh = {};
42
- win.Wulf = fresh;
43
- return fresh;
44
- }
45
- return existing;
46
- }
47
- function stripBidiAndInvisibles(raw, maxLength = 4096) {
48
- const safeLimit = Math.max(0, maxLength);
49
- return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
50
- }
51
- function getDeepActiveElement(root) {
52
- if (typeof document === "undefined") return null;
53
- let active = (root ?? document).activeElement;
54
- while (active && active.shadowRoot && active.shadowRoot.activeElement) {
55
- active = active.shadowRoot.activeElement;
56
- }
57
- return active && typeof active.focus === "function" ? active : null;
58
- }
59
- function isImeComposing(event) {
60
- return Boolean(
61
- event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
62
- );
63
- }
64
- function prefersReducedMotion() {
65
- return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
66
- }
67
- function waitForAnimations(element, fallbackMs, signal) {
68
- const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
69
- if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
70
- return Promise.resolve();
71
- }
72
- const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
73
- if (a.playState !== "running") return false;
74
- const timing = a.effect?.getComputedTiming?.();
75
- return timing ? Number.isFinite(timing.endTime) : true;
76
- }) : [];
77
- if (animations.length === 0) {
78
- return Promise.resolve();
79
- }
80
- return new Promise((resolve) => {
81
- let settled = false;
82
- let timerId = null;
83
- const finish = () => {
84
- if (settled) return;
85
- settled = true;
86
- if (timerId !== null) {
87
- clearTimeout(timerId);
88
- timerId = null;
89
- }
90
- signal?.removeEventListener("abort", finish);
91
- resolve();
92
- };
93
- signal?.addEventListener("abort", finish, { once: true });
94
- timerId = setTimeout(finish, safeFallback);
95
- Promise.allSettled(animations.map((a) => a.finished)).then(finish);
96
- });
97
- }
98
-
99
36
  // src/common/i18n.ts
100
37
  var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
101
38
  function isSafeKey(key) {
@@ -363,10 +300,63 @@ var __WulfIIFE = (() => {
363
300
  en: toastEn
364
301
  });
365
302
 
303
+ // src/common/dom.ts
304
+ function stripBidiAndInvisibles(raw, maxLength = 4096) {
305
+ const safeLimit = Math.max(0, maxLength);
306
+ return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
307
+ }
308
+ function getDeepActiveElement(root) {
309
+ if (typeof document === "undefined") return null;
310
+ let active = (root ?? document).activeElement;
311
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
312
+ active = active.shadowRoot.activeElement;
313
+ }
314
+ return active && typeof active.focus === "function" ? active : null;
315
+ }
316
+ function isImeComposing(event) {
317
+ return Boolean(
318
+ event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
319
+ );
320
+ }
321
+ function prefersReducedMotion() {
322
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
323
+ }
324
+ function waitForAnimations(element, fallbackMs, signal) {
325
+ const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
326
+ if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
327
+ return Promise.resolve();
328
+ }
329
+ const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
330
+ if (a.playState !== "running") return false;
331
+ const timing = a.effect?.getComputedTiming?.();
332
+ return timing ? Number.isFinite(timing.endTime) : true;
333
+ }) : [];
334
+ if (animations.length === 0) {
335
+ return Promise.resolve();
336
+ }
337
+ return new Promise((resolve) => {
338
+ let settled = false;
339
+ let timerId = null;
340
+ const finish = () => {
341
+ if (settled) return;
342
+ settled = true;
343
+ if (timerId !== null) {
344
+ clearTimeout(timerId);
345
+ timerId = null;
346
+ }
347
+ signal?.removeEventListener("abort", finish);
348
+ resolve();
349
+ };
350
+ signal?.addEventListener("abort", finish, { once: true });
351
+ timerId = setTimeout(finish, safeFallback);
352
+ Promise.allSettled(animations.map((a) => a.finished)).then(finish);
353
+ });
354
+ }
355
+
366
356
  // src/toast/ToastInstance.ts
367
357
  var nextToastId = 1;
368
358
  var DEFAULT_TOAST_DURATION = 5e3;
369
- var SAFE_COLOR_FALLBACK_RE = /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\([^;{}<>\\]+\)|[a-z]{3,20})$/i;
359
+ var SAFE_COLOR_FALLBACK_RE = /^(?:#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\(\s*(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:%|deg|rad|grad|turn)?|none)(?:\s*[,/\s]\s*(?:[+-]?(?:\d+\.?\d*|\.\d+)(?:%|deg|rad|grad|turn)?|none)){2,3}\s*\)|[a-z]{3,20})$/i;
370
360
  function isSafeCssValue(val) {
371
361
  if (!val || typeof val !== "string" || val.length > 128) return false;
372
362
  const trimmed = val.trim();
@@ -397,12 +387,16 @@ var __WulfIIFE = (() => {
397
387
  isPausedByFocus = false;
398
388
  isPausedByVisibility = false;
399
389
  isPendingFocusDismiss = false;
390
+ actionPending = false;
400
391
  previousActiveElement = null;
401
392
  eventsAbortController = new AbortController();
402
393
  disposeAbortController = new AbortController();
403
394
  onDismissCallback;
404
395
  constructor(options, onDismiss) {
405
396
  super();
397
+ if (typeof document === "undefined") {
398
+ throw new Error("[Wulf.Toast] Impossible d'instancier une notification Toast sans environnement DOM (document).");
399
+ }
406
400
  this.id = `wulf-toast-${nextToastId++}`;
407
401
  this.options = Object.freeze({ ...options });
408
402
  this.onDismissCallback = onDismiss;
@@ -451,6 +445,14 @@ var __WulfIIFE = (() => {
451
445
  "Notification persistante impossible \xE0 fermer au clavier : activez closable: true lorsque duration est d\xE9sactiv\xE9 (WCAG 2.1.1)."
452
446
  );
453
447
  }
448
+ if (this.options.action) {
449
+ const safeActionLabel = stripBidiAndInvisibles(String(this.options.action.label ?? ""), 128).trim();
450
+ if (!safeActionLabel) {
451
+ warnings.push(
452
+ "Bouton d'action invalide : action.label doit contenir un texte non vide (WCAG 4.1.2)."
453
+ );
454
+ }
455
+ }
454
456
  return warnings;
455
457
  }
456
458
  getAuditPrefix() {
@@ -530,6 +532,63 @@ var __WulfIIFE = (() => {
530
532
  content.appendChild(messageEl);
531
533
  }
532
534
  el.appendChild(content);
535
+ const actionDef = this.options.action;
536
+ if (actionDef && typeof actionDef.onClick === "function") {
537
+ const safeLabel = stripBidiAndInvisibles(String(actionDef.label ?? ""), 128).trim();
538
+ if (safeLabel) {
539
+ const actionBtn = document.createElement("button");
540
+ actionBtn.type = "button";
541
+ actionBtn.className = "wulf-toast-action";
542
+ actionBtn.textContent = safeLabel;
543
+ if (typeof actionDef.ariaLabel === "string") {
544
+ const safeAriaLabel = stripBidiAndInvisibles(actionDef.ariaLabel, 256).trim();
545
+ if (safeAriaLabel) {
546
+ actionBtn.setAttribute("aria-label", safeAriaLabel);
547
+ }
548
+ }
549
+ const resetActionState = () => {
550
+ this.actionPending = false;
551
+ if (!this._isClosed) {
552
+ actionBtn.disabled = false;
553
+ actionBtn.removeAttribute("aria-busy");
554
+ }
555
+ };
556
+ actionBtn.addEventListener("click", (e) => {
557
+ e.stopPropagation();
558
+ if (this._isClosed || this.actionPending) return;
559
+ this.actionPending = true;
560
+ actionBtn.disabled = true;
561
+ actionBtn.setAttribute("aria-busy", "true");
562
+ const shouldClose = actionDef.closeOnClick !== false;
563
+ try {
564
+ const result = actionDef.onClick(this, e);
565
+ if (result && typeof result.then === "function") {
566
+ result.then(
567
+ () => {
568
+ if (shouldClose && !this._isClosed) {
569
+ this.close("action");
570
+ } else {
571
+ resetActionState();
572
+ }
573
+ },
574
+ (err) => {
575
+ console.error("[Wulf.Toast] Erreur dans action.onClick:", err);
576
+ resetActionState();
577
+ }
578
+ );
579
+ } else if (shouldClose && !this._isClosed) {
580
+ this.close("action");
581
+ } else {
582
+ resetActionState();
583
+ }
584
+ } catch (err) {
585
+ console.error("[Wulf.Toast] Erreur dans action.onClick:", err);
586
+ resetActionState();
587
+ }
588
+ }, { signal: this.eventsAbortController.signal });
589
+ el.appendChild(actionBtn);
590
+ }
591
+ }
533
592
  const closable = this.options.closable ?? true;
534
593
  if (closable) {
535
594
  const closeBtn = document.createElement("button");
@@ -632,10 +691,11 @@ var __WulfIIFE = (() => {
632
691
  return;
633
692
  }
634
693
  if (this.timerId !== null) {
635
- window.clearTimeout(this.timerId);
694
+ if (typeof window !== "undefined") window.clearTimeout(this.timerId);
636
695
  this.timerId = null;
637
696
  }
638
- this.timerStartTime = performance.now();
697
+ if (typeof window === "undefined") return;
698
+ this.timerStartTime = typeof performance !== "undefined" ? performance.now() : Date.now();
639
699
  this.timerId = window.setTimeout(() => {
640
700
  this.timerId = null;
641
701
  const active = getDeepActiveElement();
@@ -661,9 +721,10 @@ var __WulfIIFE = (() => {
661
721
  }
662
722
  if (wasPaused) return;
663
723
  if (this.timerId !== null) {
664
- window.clearTimeout(this.timerId);
724
+ if (typeof window !== "undefined") window.clearTimeout(this.timerId);
665
725
  this.timerId = null;
666
- const elapsed = performance.now() - this.timerStartTime;
726
+ const now = typeof performance !== "undefined" ? performance.now() : Date.now();
727
+ const elapsed = now - this.timerStartTime;
667
728
  this.remainingTime = Math.max(0, this.remainingTime - elapsed);
668
729
  }
669
730
  this.element.classList.add("is-paused");
@@ -719,7 +780,7 @@ var __WulfIIFE = (() => {
719
780
  destroyImmediate(reason = "replace") {
720
781
  this._isClosed = true;
721
782
  if (this.timerId !== null) {
722
- window.clearTimeout(this.timerId);
783
+ if (typeof window !== "undefined") window.clearTimeout(this.timerId);
723
784
  this.timerId = null;
724
785
  }
725
786
  this.disposeAbortController.abort();
@@ -735,7 +796,7 @@ var __WulfIIFE = (() => {
735
796
  }
736
797
  this._isClosed = true;
737
798
  if (this.timerId !== null) {
738
- window.clearTimeout(this.timerId);
799
+ if (typeof window !== "undefined") window.clearTimeout(this.timerId);
739
800
  this.timerId = null;
740
801
  }
741
802
  this.eventsAbortController.abort();
@@ -754,6 +815,49 @@ var __WulfIIFE = (() => {
754
815
  }
755
816
  };
756
817
 
818
+ // src/common/registry.ts
819
+ var WULF_TRAP_STACK_SYMBOL = Symbol.for("wulf.focusTrap.stack.v1");
820
+ var WULF_TOAST_MANAGER_SYMBOL = Symbol.for("wulf.toast.manager.v1");
821
+ var WULF_TOAST_CONTAINERS_SYMBOL = Symbol.for("wulf.toast.containers.v1");
822
+ var WULF_TOAST_ANNOUNCERS_SYMBOL = Symbol.for("wulf.toast.announcers.v1");
823
+ function getGlobalRegistry() {
824
+ if (typeof globalThis === "undefined") return null;
825
+ return globalThis;
826
+ }
827
+ function getSharedToastManager() {
828
+ const reg = getGlobalRegistry();
829
+ if (!reg) return null;
830
+ return reg[WULF_TOAST_MANAGER_SYMBOL] ?? null;
831
+ }
832
+ function setSharedToastManager(instance) {
833
+ const reg = getGlobalRegistry();
834
+ if (!reg) return;
835
+ reg[WULF_TOAST_MANAGER_SYMBOL] = instance;
836
+ }
837
+ function getWeakSetRegistry(sym) {
838
+ if (typeof WeakSet === "undefined") return null;
839
+ const reg = getGlobalRegistry();
840
+ if (!reg) return null;
841
+ let set = reg[sym];
842
+ if (!(set instanceof WeakSet)) {
843
+ set = /* @__PURE__ */ new WeakSet();
844
+ reg[sym] = set;
845
+ }
846
+ return set;
847
+ }
848
+ function registerToastContainer(el) {
849
+ getWeakSetRegistry(WULF_TOAST_CONTAINERS_SYMBOL)?.add(el);
850
+ }
851
+ function unregisterToastContainer(el) {
852
+ getWeakSetRegistry(WULF_TOAST_CONTAINERS_SYMBOL)?.delete(el);
853
+ }
854
+ function registerToastAnnouncer(el) {
855
+ getWeakSetRegistry(WULF_TOAST_ANNOUNCERS_SYMBOL)?.add(el);
856
+ }
857
+ function unregisterToastAnnouncer(el) {
858
+ getWeakSetRegistry(WULF_TOAST_ANNOUNCERS_SYMBOL)?.delete(el);
859
+ }
860
+
757
861
  // src/toast/ToastManager.ts
758
862
  var VALID_POSITIONS = /* @__PURE__ */ new Set([
759
863
  "top-left",
@@ -768,7 +872,6 @@ var __WulfIIFE = (() => {
768
872
  }
769
873
  var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';
770
874
  var ToastManager = class _ToastManager {
771
- static instance = null;
772
875
  containers = /* @__PURE__ */ new Map();
773
876
  containerBaseLabels = /* @__PURE__ */ new WeakMap();
774
877
  activeToasts = /* @__PURE__ */ new Map();
@@ -798,15 +901,21 @@ var __WulfIIFE = (() => {
798
901
  constructor() {
799
902
  }
800
903
  static getInstance() {
801
- if (!_ToastManager.instance) {
802
- _ToastManager.instance = new _ToastManager();
904
+ let instance = getSharedToastManager();
905
+ if (!instance) {
906
+ instance = new _ToastManager();
907
+ setSharedToastManager(instance);
803
908
  }
804
- return _ToastManager.instance;
909
+ return instance;
910
+ }
911
+ getContainerKey(position, useTopLayer) {
912
+ return `${position}:${useTopLayer ? "top" : "fixed"}`;
805
913
  }
806
914
  /**
807
915
  * Ajoute et affiche une notification Toast.
808
916
  */
809
917
  add(toast) {
918
+ if (typeof document === "undefined" || typeof window === "undefined") return;
810
919
  const position = normalizePosition(toast.options.position);
811
920
  let list = this.activeToasts.get(position);
812
921
  if (!list) {
@@ -848,7 +957,7 @@ var __WulfIIFE = (() => {
848
957
  * Insère l'élément toast dans le conteneur Top Layer, annonce le message et démarre le minuteur.
849
958
  */
850
959
  mountToast(toast, position, maxToasts = 5) {
851
- if (toast.isClosed) return;
960
+ if (toast.isClosed || typeof document === "undefined") return;
852
961
  const useTopLayer = toast.options.useTopLayer ?? true;
853
962
  const container = this.getOrCreateContainer(position, toast, useTopLayer);
854
963
  let list = this.activeToasts.get(position);
@@ -892,6 +1001,7 @@ var __WulfIIFE = (() => {
892
1001
  * Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
893
1002
  */
894
1003
  announce(toast) {
1004
+ if (typeof document === "undefined" || typeof window === "undefined") return;
895
1005
  const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => stripBidiAndInvisibles(val, 512).trim()).filter(Boolean);
896
1006
  if (parts.length === 0) return;
897
1007
  const rawText = parts.join(". ");
@@ -979,12 +1089,14 @@ var __WulfIIFE = (() => {
979
1089
  * Crée ou reconnecte le conteneur persistant des annonces ARIA hors du popover.
980
1090
  */
981
1091
  ensureAnnouncer() {
1092
+ if (typeof document === "undefined" || !document.body) return;
982
1093
  if (this.announcerEl && document.body.contains(this.announcerEl)) {
983
1094
  return;
984
1095
  }
985
1096
  const wrapper = document.createElement("div");
986
1097
  wrapper.className = "wulf-toast-announcer";
987
1098
  wrapper.setAttribute("data-wulf-toast-announcer", "true");
1099
+ registerToastAnnouncer(wrapper);
988
1100
  const polite = document.createElement("div");
989
1101
  polite.setAttribute("role", "status");
990
1102
  polite.setAttribute("aria-live", "polite");
@@ -1039,6 +1151,9 @@ var __WulfIIFE = (() => {
1039
1151
  remove(toast, _reason) {
1040
1152
  const position = normalizePosition(toast.options.position);
1041
1153
  const list = this.activeToasts.get(position);
1154
+ const useTopLayer = toast.options.useTopLayer ?? true;
1155
+ const containerKey = this.getContainerKey(position, useTopLayer);
1156
+ const parentContainer = toast.element.parentElement;
1042
1157
  if (list) {
1043
1158
  const index = list.indexOf(toast);
1044
1159
  if (index !== -1) {
@@ -1048,20 +1163,34 @@ var __WulfIIFE = (() => {
1048
1163
  if (toast.element.parentNode) {
1049
1164
  toast.element.parentNode.removeChild(toast.element);
1050
1165
  }
1166
+ const targetContainer = this.containers.get(containerKey) || (parentContainer instanceof HTMLElement ? parentContainer : void 0);
1167
+ if (targetContainer && (!targetContainer.firstChild || targetContainer.children.length === 0)) {
1168
+ for (const [k, c] of Array.from(this.containers.entries())) {
1169
+ if (c === targetContainer) {
1170
+ this.containers.delete(k);
1171
+ }
1172
+ }
1173
+ this.disposeContainer(targetContainer);
1174
+ this.syncContainerRegionLabels();
1175
+ }
1051
1176
  if (list.length === 0 && !this.pendingReplacements.has(position)) {
1052
- const container = this.containers.get(position);
1053
- if (container && (!container.firstChild || container.children.length === 0)) {
1054
- this.disposeContainer(container);
1055
- this.containers.delete(position);
1056
- this.activeToasts.delete(position);
1057
- this.syncContainerRegionLabels();
1177
+ for (const mode of [true, false]) {
1178
+ const k = this.getContainerKey(position, mode);
1179
+ const container = this.containers.get(k);
1180
+ if (container && (!container.firstChild || container.children.length === 0)) {
1181
+ this.disposeContainer(container);
1182
+ this.containers.delete(k);
1183
+ }
1058
1184
  }
1185
+ this.activeToasts.delete(position);
1186
+ this.syncContainerRegionLabels();
1059
1187
  }
1060
1188
  } else if (toast.element.parentNode) {
1061
1189
  toast.element.parentNode.removeChild(toast.element);
1062
1190
  }
1063
1191
  }
1064
1192
  disposeContainer(container) {
1193
+ unregisterToastContainer(container);
1065
1194
  try {
1066
1195
  const popoverEl = container;
1067
1196
  if (typeof popoverEl.hidePopover === "function" && this.isPopoverOpen(container)) {
@@ -1077,6 +1206,9 @@ var __WulfIIFE = (() => {
1077
1206
  * Ferme l'ensemble des toasts actifs (sur une position ou partout) et attend leur retrait complet.
1078
1207
  */
1079
1208
  clearAll(position) {
1209
+ if (typeof document === "undefined" || typeof window === "undefined") {
1210
+ return Promise.resolve();
1211
+ }
1080
1212
  const promises = [];
1081
1213
  if (position) {
1082
1214
  this.replaceTokens.set(position, (this.replaceTokens.get(position) || 0) + 1);
@@ -1088,11 +1220,18 @@ var __WulfIIFE = (() => {
1088
1220
  promises.push(t.close("programmatic"));
1089
1221
  }
1090
1222
  } else {
1091
- const container = this.containers.get(position);
1092
- if (container && (!container.firstChild || container.children.length === 0)) {
1093
- this.disposeContainer(container);
1094
- this.containers.delete(position);
1095
- this.activeToasts.delete(position);
1223
+ let removedAny = false;
1224
+ for (const mode of [true, false]) {
1225
+ const k = this.getContainerKey(position, mode);
1226
+ const container = this.containers.get(k);
1227
+ if (container && (!container.firstChild || container.children.length === 0)) {
1228
+ this.disposeContainer(container);
1229
+ this.containers.delete(k);
1230
+ removedAny = true;
1231
+ }
1232
+ }
1233
+ this.activeToasts.delete(position);
1234
+ if (removedAny) {
1096
1235
  this.syncContainerRegionLabels();
1097
1236
  }
1098
1237
  }
@@ -1109,23 +1248,26 @@ var __WulfIIFE = (() => {
1109
1248
  this.assertiveAnnounceTimerId = null;
1110
1249
  this.politeClearTimerId = null;
1111
1250
  this.assertiveClearTimerId = null;
1112
- const allPositions = /* @__PURE__ */ new Set([
1113
- ...Array.from(this.containers.keys()),
1114
- ...Array.from(this.activeToasts.keys())
1115
- ]);
1116
- for (const pos of allPositions) {
1251
+ const positionSet = new Set(Array.from(this.activeToasts.keys()));
1252
+ for (const key of this.containers.keys()) {
1253
+ const pos = key.slice(0, key.lastIndexOf(":"));
1254
+ if (VALID_POSITIONS.has(pos)) {
1255
+ positionSet.add(pos);
1256
+ }
1257
+ }
1258
+ for (const pos of positionSet) {
1117
1259
  promises.push(this.clearAll(pos));
1118
1260
  }
1119
1261
  }
1120
1262
  return Promise.all(promises).then(() => {
1121
1263
  if (!position) {
1122
- for (const [pos, container] of Array.from(this.containers.entries())) {
1264
+ for (const [key, container] of Array.from(this.containers.entries())) {
1123
1265
  if (!container.firstChild || container.children.length === 0) {
1124
1266
  this.disposeContainer(container);
1125
- this.containers.delete(pos);
1126
- this.activeToasts.delete(pos);
1267
+ this.containers.delete(key);
1127
1268
  }
1128
1269
  }
1270
+ this.activeToasts.clear();
1129
1271
  this.syncContainerRegionLabels();
1130
1272
  }
1131
1273
  });
@@ -1134,8 +1276,10 @@ var __WulfIIFE = (() => {
1134
1276
  * Détruit immédiatement tous les toasts, conteneurs, annonceurs ARIA et temporisations en cours.
1135
1277
  */
1136
1278
  destroy() {
1137
- for (const timerId of this.announceTimers) {
1138
- window.clearTimeout(timerId);
1279
+ if (typeof window !== "undefined") {
1280
+ for (const timerId of this.announceTimers) {
1281
+ window.clearTimeout(timerId);
1282
+ }
1139
1283
  }
1140
1284
  this.announceTimers = [];
1141
1285
  this.politeAnnounceTimerId = null;
@@ -1155,26 +1299,32 @@ var __WulfIIFE = (() => {
1155
1299
  this.replaceTokens.clear();
1156
1300
  this.pendingReplacements.clear();
1157
1301
  if (this.announcerEl) {
1302
+ unregisterToastAnnouncer(this.announcerEl);
1158
1303
  this.announcerEl.remove();
1159
1304
  this.announcerEl = null;
1160
1305
  this.politeRegion = null;
1161
1306
  this.assertiveRegion = null;
1162
1307
  }
1163
- _ToastManager.instance = null;
1308
+ setSharedToastManager(null);
1164
1309
  }
1165
1310
  syncContainerRegionLabels() {
1166
1311
  const useSuffix = this.containers.size > 1;
1167
- for (const [pos, container] of this.containers.entries()) {
1312
+ for (const [key, container] of this.containers.entries()) {
1168
1313
  const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
1314
+ const pos = key.slice(0, key.lastIndexOf(":"));
1169
1315
  container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
1170
1316
  }
1171
1317
  }
1172
1318
  /**
1173
- * Récupère ou crée le conteneur DOM pour une position d'affichage.
1319
+ * Récupère ou crée le conteneur DOM pour une position et un mode Top Layer donnés.
1174
1320
  */
1175
1321
  getOrCreateContainer(position, toast, useTopLayer) {
1176
- let container = this.containers.get(position);
1322
+ const key = this.getContainerKey(position, useTopLayer);
1323
+ let container = this.containers.get(key);
1177
1324
  if (!container || !document.body.contains(container)) {
1325
+ if (container) {
1326
+ unregisterToastContainer(container);
1327
+ }
1178
1328
  container = document.createElement("div");
1179
1329
  container.className = `wulf-toast-container wulf-toast-${position}`;
1180
1330
  container.setAttribute("role", "region");
@@ -1184,8 +1334,9 @@ var __WulfIIFE = (() => {
1184
1334
  if (useTopLayer && typeof container.showPopover === "function") {
1185
1335
  container.setAttribute("popover", "manual");
1186
1336
  }
1337
+ registerToastContainer(container);
1187
1338
  document.body.appendChild(container);
1188
- this.containers.set(position, container);
1339
+ this.containers.set(key, container);
1189
1340
  this.syncContainerRegionLabels();
1190
1341
  }
1191
1342
  return container;
@@ -1193,7 +1344,7 @@ var __WulfIIFE = (() => {
1193
1344
  };
1194
1345
 
1195
1346
  // src/toast/Toast.ts
1196
- var Toast = class extends LocalizedComponent {
1347
+ var Toast = class _Toast extends LocalizedComponent {
1197
1348
  static _i18n = toastI18n;
1198
1349
  static i18n = toastI18n;
1199
1350
  audit() {
@@ -1216,6 +1367,65 @@ var __WulfIIFE = (() => {
1216
1367
  manager.add(instance);
1217
1368
  return instance;
1218
1369
  }
1370
+ /**
1371
+ * Accompagne une promesse asynchrone avec une notification de chargement puis un résultat succès ou erreur.
1372
+ * Seul le toast de chargement est fermé à la résolution/rejet ; tout rejet est toujours repropagé.
1373
+ */
1374
+ static async promise(promiseOrFactory, options) {
1375
+ const resolveMessage = (spec, arg) => {
1376
+ let resolved;
1377
+ if (typeof spec === "function") {
1378
+ try {
1379
+ resolved = spec(arg);
1380
+ } catch (err) {
1381
+ console.error("[Wulf.Toast] Erreur lors de la r\xE9solution du message Toast.promise:", err);
1382
+ return {};
1383
+ }
1384
+ } else {
1385
+ resolved = spec;
1386
+ }
1387
+ if (typeof resolved === "string") {
1388
+ return { message: resolved };
1389
+ }
1390
+ if (resolved && typeof resolved === "object") {
1391
+ return { ...resolved };
1392
+ }
1393
+ return {};
1394
+ };
1395
+ const baseOpts = options.baseOptions ? { ...options.baseOptions } : {};
1396
+ const loadingOpts = resolveMessage(options.loading, void 0);
1397
+ const loadingToast = _Toast.show({
1398
+ ...baseOpts,
1399
+ duration: false,
1400
+ closable: true,
1401
+ role: "status",
1402
+ ...loadingOpts,
1403
+ replace: false
1404
+ });
1405
+ const targetPromise = typeof promiseOrFactory === "function" ? Promise.resolve().then(() => promiseOrFactory()) : Promise.resolve(promiseOrFactory);
1406
+ try {
1407
+ const data = await targetPromise;
1408
+ await loadingToast.close("replace", true);
1409
+ const successOpts = resolveMessage(options.success, data);
1410
+ _Toast.show({
1411
+ ...baseOpts,
1412
+ role: "status",
1413
+ ...successOpts,
1414
+ replace: false
1415
+ });
1416
+ return data;
1417
+ } catch (err) {
1418
+ await loadingToast.close("replace", true);
1419
+ const errorOpts = resolveMessage(options.error, err);
1420
+ _Toast.show({
1421
+ ...baseOpts,
1422
+ role: "alert",
1423
+ ...errorOpts,
1424
+ replace: false
1425
+ });
1426
+ throw err;
1427
+ }
1428
+ }
1219
1429
  /**
1220
1430
  * Ferme immédiatement l'ensemble des toasts actifs (globalement ou par position) et attend leur retrait complet.
1221
1431
  */
@@ -1232,14 +1442,7 @@ var __WulfIIFE = (() => {
1232
1442
 
1233
1443
  // src/toast/index.ts
1234
1444
  var index_default = Toast;
1235
- var wulfNamespace = getSafeWulfNamespace();
1236
- if (wulfNamespace) {
1237
- wulfNamespace.Toast = Object.assign(Toast, {
1238
- Toast,
1239
- i18n: toastI18n
1240
- });
1241
- }
1242
1445
  return __toCommonJS(index_exports);
1243
1446
  })();
1244
- if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.hasOwn(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && __w[k] === undefined) { try { Object.defineProperty(__w, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { __w[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
1447
+ if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } var __set = function(obj, key, val) { try { Object.defineProperty(obj, key, { value: val, writable: true, configurable: true, enumerable: true }); } catch (_) { try { obj[key] = val; } catch (__) {} } }; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { var __e = __WulfIIFE; var __skip = ["__proto__","constructor","prototype"]; for (var k in __e) { if (Object.hasOwn(__e, k) && __skip.indexOf(k) === -1 && __w[k] === undefined) { __set(__w, k, __e[k]); } } if (__e.Toast) __set(__w, "Toast", Object.assign(__e.Toast, { Toast: __e.Toast, ToastInstance: __e.ToastInstance, ToastManager: __e.ToastManager, i18n: __e.toastI18n })); }}
1245
1448
  //# sourceMappingURL=toast.global.js.map