wulf.js 2.1.0 → 2.1.1

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 (59) hide show
  1. package/changelog.md +10 -0
  2. package/dist/focus-trap.esm.js +88 -30
  3. package/dist/focus-trap.esm.js.map +2 -2
  4. package/dist/focus-trap.global.js +88 -30
  5. package/dist/focus-trap.global.js.map +2 -2
  6. package/dist/focus-trap.global.min.js +2 -2
  7. package/dist/focus-trap.global.min.js.map +3 -3
  8. package/dist/index.esm.js +541 -162
  9. package/dist/index.esm.js.map +2 -2
  10. package/dist/index.global.js +541 -162
  11. package/dist/index.global.js.map +2 -2
  12. package/dist/index.global.min.js +2 -2
  13. package/dist/index.global.min.js.map +3 -3
  14. package/dist/mask.esm.js +4 -4
  15. package/dist/mask.esm.js.map +2 -2
  16. package/dist/mask.global.js +4 -4
  17. package/dist/mask.global.js.map +2 -2
  18. package/dist/mask.global.min.js +2 -2
  19. package/dist/mask.global.min.js.map +3 -3
  20. package/dist/masonry.esm.js +153 -62
  21. package/dist/masonry.esm.js.map +2 -2
  22. package/dist/masonry.global.js +153 -62
  23. package/dist/masonry.global.js.map +2 -2
  24. package/dist/masonry.global.min.js +3 -3
  25. package/dist/masonry.global.min.js.map +3 -3
  26. package/dist/scroll.css +1 -1
  27. package/dist/scroll.css.map +2 -2
  28. package/dist/scroll.esm.js +108 -31
  29. package/dist/scroll.esm.js.map +2 -2
  30. package/dist/scroll.global.js +108 -31
  31. package/dist/scroll.global.js.map +2 -2
  32. package/dist/scroll.global.min.js +2 -2
  33. package/dist/scroll.global.min.js.map +3 -3
  34. package/dist/scroll.layered.css +1 -1
  35. package/dist/scroll.layered.css.map +2 -2
  36. package/dist/shortcut.esm.js +182 -22
  37. package/dist/shortcut.esm.js.map +3 -3
  38. package/dist/shortcut.global.js +182 -22
  39. package/dist/shortcut.global.js.map +3 -3
  40. package/dist/shortcut.global.min.js +4 -1
  41. package/dist/shortcut.global.min.js.map +4 -4
  42. package/dist/toast.css +1 -1
  43. package/dist/toast.css.map +2 -2
  44. package/dist/toast.esm.js +92 -13
  45. package/dist/toast.esm.js.map +2 -2
  46. package/dist/toast.global.js +92 -13
  47. package/dist/toast.global.js.map +2 -2
  48. package/dist/toast.global.min.js +3 -3
  49. package/dist/toast.global.min.js.map +3 -3
  50. package/dist/toast.layered.css +1 -1
  51. package/dist/toast.layered.css.map +2 -2
  52. package/dist/types/common/dom.d.ts +5 -0
  53. package/dist/types/focus-trap/FocusTrap.d.ts +5 -2
  54. package/dist/types/mask/paste.d.ts +2 -5
  55. package/dist/types/masonry/Masonry.d.ts +2 -0
  56. package/dist/types/scroll/ScrollBlock.d.ts +2 -0
  57. package/dist/types/shortcut/ShortcutManager.d.ts +14 -3
  58. package/dist/types/toast/ToastManager.d.ts +2 -0
  59. package/package.json +1 -1
package/dist/toast.esm.js CHANGED
@@ -10,6 +10,23 @@ function getSafeWulfNamespace() {
10
10
  }
11
11
  return existing;
12
12
  }
13
+ function stripBidiAndInvisibles(raw, maxLength = 4096) {
14
+ const safeLimit = Math.max(0, maxLength);
15
+ return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
16
+ }
17
+ function getDeepActiveElement(root) {
18
+ if (typeof document === "undefined") return null;
19
+ let active = (root ?? document).activeElement;
20
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
21
+ active = active.shadowRoot.activeElement;
22
+ }
23
+ return active && typeof active.focus === "function" ? active : null;
24
+ }
25
+ function isImeComposing(event) {
26
+ return Boolean(
27
+ event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
28
+ );
29
+ }
13
30
  function prefersReducedMotion() {
14
31
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
15
32
  }
@@ -315,17 +332,18 @@ var toastI18n = createI18nManager("fr", {
315
332
  // src/toast/ToastInstance.ts
316
333
  var nextToastId = 1;
317
334
  var DEFAULT_TOAST_DURATION = 5e3;
335
+ var SAFE_COLOR_FALLBACK_RE = /^(?:#[0-9a-f]{3,8}|(?:rgb|rgba|hsl|hsla|oklch|oklab|lch|lab)\([^;{}<>\\]+\)|[a-z]{3,20})$/i;
318
336
  function isSafeCssValue(val) {
319
337
  if (!val || typeof val !== "string" || val.length > 128) return false;
320
338
  const trimmed = val.trim();
321
339
  if (!trimmed) return false;
322
- if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
340
+ if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env|var)\s*\(/i.test(trimmed)) {
323
341
  return false;
324
342
  }
325
343
  if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
326
344
  return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
327
345
  }
328
- return true;
346
+ return SAFE_COLOR_FALLBACK_RE.test(trimmed);
329
347
  }
330
348
  function sanitizeIconClasses(icon) {
331
349
  return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
@@ -354,7 +372,7 @@ var ToastInstance = class extends AuditableComponent {
354
372
  this.id = `wulf-toast-${nextToastId++}`;
355
373
  this.options = Object.freeze({ ...options });
356
374
  this.onDismissCallback = onDismiss;
357
- this.previousActiveElement = typeof document !== "undefined" && document.activeElement instanceof HTMLElement ? document.activeElement : null;
375
+ this.previousActiveElement = getDeepActiveElement();
358
376
  const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
359
377
  if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
360
378
  this.remainingTime = Math.min(duration, 2147483647);
@@ -441,7 +459,30 @@ var ToastInstance = class extends AuditableComponent {
441
459
  }
442
460
  }
443
461
  const content = document.createElement("div");
444
- content.className = "wulf-toast-content";
462
+ const isInteractiveContent = Boolean(this.options.onClick || this.options.closeOnClick);
463
+ content.className = isInteractiveContent ? "wulf-toast-content wulf-toast-content--interactive" : "wulf-toast-content";
464
+ if (isInteractiveContent) {
465
+ content.setAttribute("role", "button");
466
+ content.setAttribute("tabindex", "0");
467
+ content.addEventListener("keydown", (e) => {
468
+ if (isImeComposing(e)) return;
469
+ if (e.key === "Enter") {
470
+ e.preventDefault();
471
+ e.stopPropagation();
472
+ content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
473
+ } else if (e.key === " ") {
474
+ e.preventDefault();
475
+ e.stopPropagation();
476
+ }
477
+ }, { signal: this.eventsAbortController.signal });
478
+ content.addEventListener("keyup", (e) => {
479
+ if (e.key === " ") {
480
+ e.preventDefault();
481
+ e.stopPropagation();
482
+ content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
483
+ }
484
+ }, { signal: this.eventsAbortController.signal });
485
+ }
445
486
  if (this.options.title && this.options.title.trim() !== "") {
446
487
  const titleEl = document.createElement("div");
447
488
  titleEl.className = "wulf-toast-title";
@@ -485,7 +526,7 @@ var ToastInstance = class extends AuditableComponent {
485
526
  * Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
486
527
  */
487
528
  appendTextWithLineBreaks(container, text) {
488
- const safeText = String(text ?? "").slice(0, 4096);
529
+ const safeText = stripBidiAndInvisibles(String(text ?? ""), 4096);
489
530
  const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
490
531
  lines.forEach((line, index) => {
491
532
  if (index > 0) {
@@ -501,7 +542,11 @@ var ToastInstance = class extends AuditableComponent {
501
542
  const { signal } = this.eventsAbortController;
502
543
  this.element.addEventListener("click", (e) => {
503
544
  if (this.options.onClick) {
504
- this.options.onClick(this, e);
545
+ try {
546
+ this.options.onClick(this, e);
547
+ } catch (err) {
548
+ console.error("[Wulf.Toast] Erreur dans le callback onClick:", err);
549
+ }
505
550
  }
506
551
  if (this.options.closeOnClick) {
507
552
  this.close("toast-click");
@@ -524,6 +569,7 @@ var ToastInstance = class extends AuditableComponent {
524
569
  }, { signal });
525
570
  this.element.addEventListener("keydown", (e) => {
526
571
  if (e.key === "Escape" && (this.options.closable ?? true)) {
572
+ if (isImeComposing(e)) return;
527
573
  e.stopPropagation();
528
574
  this.close("close-button");
529
575
  }
@@ -558,7 +604,8 @@ var ToastInstance = class extends AuditableComponent {
558
604
  this.timerStartTime = performance.now();
559
605
  this.timerId = window.setTimeout(() => {
560
606
  this.timerId = null;
561
- if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
607
+ const active = getDeepActiveElement();
608
+ if (active && this.element.contains(active)) {
562
609
  this.isPendingFocusDismiss = true;
563
610
  return;
564
611
  }
@@ -598,7 +645,8 @@ var ToastInstance = class extends AuditableComponent {
598
645
  this.isPausedByFocus = false;
599
646
  } else if (source === "hover") {
600
647
  this.isPausedByHover = false;
601
- if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
648
+ const active = getDeepActiveElement();
649
+ if (active && this.element.contains(active)) {
602
650
  this.isPausedByFocus = true;
603
651
  }
604
652
  } else {
@@ -624,7 +672,11 @@ var ToastInstance = class extends AuditableComponent {
624
672
  this.element.parentNode.removeChild(this.element);
625
673
  }
626
674
  if (this.options.onClose) {
627
- this.options.onClose(this, reason);
675
+ try {
676
+ this.options.onClose(this, reason);
677
+ } catch (err) {
678
+ console.error("[Wulf.Toast] Erreur dans le callback onClose:", err);
679
+ }
628
680
  }
629
681
  }
630
682
  /**
@@ -684,6 +736,7 @@ var FOCUSABLE_IN_TOAST = 'button:not([disabled]), [href], [tabindex]:not([tabind
684
736
  var ToastManager = class _ToastManager {
685
737
  static instance = null;
686
738
  containers = /* @__PURE__ */ new Map();
739
+ containerBaseLabels = /* @__PURE__ */ new WeakMap();
687
740
  activeToasts = /* @__PURE__ */ new Map();
688
741
  announcerEl = null;
689
742
  politeRegion = null;
@@ -805,7 +858,7 @@ var ToastManager = class _ToastManager {
805
858
  * Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
806
859
  */
807
860
  announce(toast) {
808
- const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
861
+ 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);
809
862
  if (parts.length === 0) return;
810
863
  const rawText = parts.join(". ");
811
864
  const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
@@ -917,7 +970,8 @@ var ToastManager = class _ToastManager {
917
970
  * Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
918
971
  */
919
972
  handleFocusHandoff(toast, list) {
920
- if (!toast.element.contains(document.activeElement)) {
973
+ const active = getDeepActiveElement();
974
+ if (!active || !toast.element.contains(active)) {
921
975
  return;
922
976
  }
923
977
  for (let i = list.length - 1; i >= 0; i--) {
@@ -930,7 +984,15 @@ var ToastManager = class _ToastManager {
930
984
  }
931
985
  }
932
986
  const prev = toast.getPreviousActiveElement();
933
- if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
987
+ if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.hidden && !prev.closest("[hidden]") && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true" && (prev.tabIndex >= 0 || prev.getAttribute("tabindex") !== null)) {
988
+ const prevWithCheck = prev;
989
+ if (typeof prevWithCheck.checkVisibility === "function" && !prevWithCheck.checkVisibility({
990
+ checkOpacity: false,
991
+ checkVisibilityCSS: true,
992
+ visibilityProperty: true
993
+ })) {
994
+ return;
995
+ }
934
996
  try {
935
997
  prev.focus();
936
998
  } catch {
@@ -958,6 +1020,7 @@ var ToastManager = class _ToastManager {
958
1020
  this.disposeContainer(container);
959
1021
  this.containers.delete(position);
960
1022
  this.activeToasts.delete(position);
1023
+ this.syncContainerRegionLabels();
961
1024
  }
962
1025
  }
963
1026
  } else if (toast.element.parentNode) {
@@ -996,6 +1059,7 @@ var ToastManager = class _ToastManager {
996
1059
  this.disposeContainer(container);
997
1060
  this.containers.delete(position);
998
1061
  this.activeToasts.delete(position);
1062
+ this.syncContainerRegionLabels();
999
1063
  }
1000
1064
  }
1001
1065
  } else {
@@ -1028,6 +1092,7 @@ var ToastManager = class _ToastManager {
1028
1092
  this.activeToasts.delete(pos);
1029
1093
  }
1030
1094
  }
1095
+ this.syncContainerRegionLabels();
1031
1096
  }
1032
1097
  });
1033
1098
  }
@@ -1039,6 +1104,10 @@ var ToastManager = class _ToastManager {
1039
1104
  window.clearTimeout(timerId);
1040
1105
  }
1041
1106
  this.announceTimers = [];
1107
+ this.politeAnnounceTimerId = null;
1108
+ this.assertiveAnnounceTimerId = null;
1109
+ this.politeClearTimerId = null;
1110
+ this.assertiveClearTimerId = null;
1042
1111
  for (const list of Array.from(this.activeToasts.values())) {
1043
1112
  for (const toast of [...list]) {
1044
1113
  toast.destroyImmediate("programmatic");
@@ -1059,6 +1128,13 @@ var ToastManager = class _ToastManager {
1059
1128
  }
1060
1129
  _ToastManager.instance = null;
1061
1130
  }
1131
+ syncContainerRegionLabels() {
1132
+ const useSuffix = this.containers.size > 1;
1133
+ for (const [pos, container] of this.containers.entries()) {
1134
+ const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
1135
+ container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
1136
+ }
1137
+ }
1062
1138
  /**
1063
1139
  * Récupère ou crée le conteneur DOM pour une position d'affichage.
1064
1140
  */
@@ -1068,12 +1144,15 @@ var ToastManager = class _ToastManager {
1068
1144
  container = document.createElement("div");
1069
1145
  container.className = `wulf-toast-container wulf-toast-${position}`;
1070
1146
  container.setAttribute("role", "region");
1071
- container.setAttribute("aria-label", toastI18n.t("notificationsRegion", toast.options.i18n));
1147
+ const baseLabel = toastI18n.t("notificationsRegion", toast.options.i18n);
1148
+ this.containerBaseLabels.set(container, baseLabel);
1149
+ container.setAttribute("aria-label", baseLabel);
1072
1150
  if (useTopLayer && typeof container.showPopover === "function") {
1073
1151
  container.setAttribute("popover", "manual");
1074
1152
  }
1075
1153
  document.body.appendChild(container);
1076
1154
  this.containers.set(position, container);
1155
+ this.syncContainerRegionLabels();
1077
1156
  }
1078
1157
  return container;
1079
1158
  }