wulf.js 2.0.1 → 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 (75) hide show
  1. package/README.md +240 -4
  2. package/changelog.md +37 -0
  3. package/dist/focus-trap.esm.js +110 -37
  4. package/dist/focus-trap.esm.js.map +2 -2
  5. package/dist/focus-trap.global.js +110 -37
  6. package/dist/focus-trap.global.js.map +2 -2
  7. package/dist/focus-trap.global.min.js +2 -2
  8. package/dist/focus-trap.global.min.js.map +3 -3
  9. package/dist/index.esm.js +3370 -337
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +3370 -337
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +2 -2
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.css +1 -1
  16. package/dist/mask.css.map +2 -2
  17. package/dist/mask.esm.js +2826 -171
  18. package/dist/mask.esm.js.map +4 -4
  19. package/dist/mask.global.js +2816 -161
  20. package/dist/mask.global.js.map +4 -4
  21. package/dist/mask.global.min.js +2 -2
  22. package/dist/mask.global.min.js.map +4 -4
  23. package/dist/mask.layered.css +1 -1
  24. package/dist/mask.layered.css.map +2 -2
  25. package/dist/masonry.esm.js +175 -69
  26. package/dist/masonry.esm.js.map +2 -2
  27. package/dist/masonry.global.js +175 -69
  28. package/dist/masonry.global.js.map +2 -2
  29. package/dist/masonry.global.min.js +3 -3
  30. package/dist/masonry.global.min.js.map +3 -3
  31. package/dist/scroll.css +1 -1
  32. package/dist/scroll.css.map +2 -2
  33. package/dist/scroll.esm.js +132 -40
  34. package/dist/scroll.esm.js.map +2 -2
  35. package/dist/scroll.global.js +132 -40
  36. package/dist/scroll.global.js.map +2 -2
  37. package/dist/scroll.global.min.js +2 -2
  38. package/dist/scroll.global.min.js.map +3 -3
  39. package/dist/scroll.layered.css +1 -1
  40. package/dist/scroll.layered.css.map +2 -2
  41. package/dist/shortcut.esm.js +182 -22
  42. package/dist/shortcut.esm.js.map +3 -3
  43. package/dist/shortcut.global.js +182 -22
  44. package/dist/shortcut.global.js.map +3 -3
  45. package/dist/shortcut.global.min.js +4 -1
  46. package/dist/shortcut.global.min.js.map +4 -4
  47. package/dist/toast.css +1 -1
  48. package/dist/toast.css.map +2 -2
  49. package/dist/toast.esm.js +116 -19
  50. package/dist/toast.esm.js.map +2 -2
  51. package/dist/toast.global.js +116 -19
  52. package/dist/toast.global.js.map +2 -2
  53. package/dist/toast.global.min.js +3 -3
  54. package/dist/toast.global.min.js.map +3 -3
  55. package/dist/toast.layered.css +1 -1
  56. package/dist/toast.layered.css.map +2 -2
  57. package/dist/types/common/AuditableComponent.d.ts +3 -3
  58. package/dist/types/common/dom.d.ts +5 -0
  59. package/dist/types/focus-trap/FocusTrap.d.ts +5 -2
  60. package/dist/types/mask/AmountEngine.d.ts +8 -0
  61. package/dist/types/mask/BaseInputMask.d.ts +18 -0
  62. package/dist/types/mask/DateUTCEngine.d.ts +187 -0
  63. package/dist/types/mask/InputAmountMask.d.ts +5 -0
  64. package/dist/types/mask/InputDateUTCMask.d.ts +110 -0
  65. package/dist/types/mask/InputEmailMask.d.ts +7 -0
  66. package/dist/types/mask/InputMask.d.ts +7 -5
  67. package/dist/types/mask/MaskEngine.d.ts +39 -7
  68. package/dist/types/mask/index.d.ts +12 -6
  69. package/dist/types/mask/paste.d.ts +15 -0
  70. package/dist/types/mask/types.d.ts +27 -2
  71. package/dist/types/masonry/Masonry.d.ts +2 -0
  72. package/dist/types/scroll/ScrollBlock.d.ts +2 -0
  73. package/dist/types/shortcut/ShortcutManager.d.ts +14 -3
  74. package/dist/types/toast/ToastManager.d.ts +2 -0
  75. package/package.json +1 -1
@@ -44,6 +44,23 @@ var __WulfIIFE = (() => {
44
44
  }
45
45
  return existing;
46
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
+ }
47
64
  function prefersReducedMotion() {
48
65
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
49
66
  }
@@ -222,24 +239,39 @@ var __WulfIIFE = (() => {
222
239
  return warnings;
223
240
  }
224
241
  /**
225
- * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby)
226
- * pointe vers des éléments réellement présents dans le document.
242
+ * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
243
+ * pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
227
244
  */
228
- checkAriaIdReferences(element, attrName, warnings) {
245
+ checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
229
246
  const rawValue = element.getAttribute(attrName)?.trim();
230
247
  if (!rawValue) return false;
231
248
  const doc = element.ownerDocument || document;
232
249
  const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
233
250
  const ids = rawValue.split(/\s+/).filter(Boolean);
234
- const isValid = ids.length > 0 && ids.every(
235
- (id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
251
+ const targets = ids.map(
252
+ (id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
236
253
  );
237
- if (!isValid) {
254
+ const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
255
+ if (!allFound) {
238
256
  warnings.push(
239
257
  `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
240
258
  );
259
+ return false;
241
260
  }
242
- return isValid;
261
+ if (requireNonEmptyText) {
262
+ const hasNonEmptyText = targets.some((el) => {
263
+ if (!el) return false;
264
+ const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
265
+ return text.length > 0;
266
+ });
267
+ if (!hasNonEmptyText) {
268
+ warnings.push(
269
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
270
+ );
271
+ return false;
272
+ }
273
+ }
274
+ return true;
243
275
  }
244
276
  };
245
277
 
@@ -334,17 +366,18 @@ var __WulfIIFE = (() => {
334
366
  // src/toast/ToastInstance.ts
335
367
  var nextToastId = 1;
336
368
  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;
337
370
  function isSafeCssValue(val) {
338
371
  if (!val || typeof val !== "string" || val.length > 128) return false;
339
372
  const trimmed = val.trim();
340
373
  if (!trimmed) return false;
341
- if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env)\s*\(/i.test(trimmed)) {
374
+ if (/[\u0000-\u001F\u007F;{}<>\\]|(?:url|image-set|-webkit-image-set|image|src|expression|attr|env|var)\s*\(/i.test(trimmed)) {
342
375
  return false;
343
376
  }
344
377
  if (typeof CSS !== "undefined" && typeof CSS.supports === "function") {
345
378
  return CSS.supports("color", trimmed) || CSS.supports("background-color", trimmed);
346
379
  }
347
- return true;
380
+ return SAFE_COLOR_FALLBACK_RE.test(trimmed);
348
381
  }
349
382
  function sanitizeIconClasses(icon) {
350
383
  return icon.slice(0, 128).trim().split(/\s+/).filter((token) => /^[a-zA-Z0-9_-]+$/.test(token) && !token.startsWith("wulf-toast")).slice(0, 8).join(" ");
@@ -373,7 +406,7 @@ var __WulfIIFE = (() => {
373
406
  this.id = `wulf-toast-${nextToastId++}`;
374
407
  this.options = Object.freeze({ ...options });
375
408
  this.onDismissCallback = onDismiss;
376
- this.previousActiveElement = typeof document !== "undefined" && document.activeElement instanceof HTMLElement ? document.activeElement : null;
409
+ this.previousActiveElement = getDeepActiveElement();
377
410
  const duration = options.duration === void 0 ? DEFAULT_TOAST_DURATION : options.duration;
378
411
  if (typeof duration === "number" && Number.isFinite(duration) && duration > 0) {
379
412
  this.remainingTime = Math.min(duration, 2147483647);
@@ -460,7 +493,30 @@ var __WulfIIFE = (() => {
460
493
  }
461
494
  }
462
495
  const content = document.createElement("div");
463
- content.className = "wulf-toast-content";
496
+ const isInteractiveContent = Boolean(this.options.onClick || this.options.closeOnClick);
497
+ content.className = isInteractiveContent ? "wulf-toast-content wulf-toast-content--interactive" : "wulf-toast-content";
498
+ if (isInteractiveContent) {
499
+ content.setAttribute("role", "button");
500
+ content.setAttribute("tabindex", "0");
501
+ content.addEventListener("keydown", (e) => {
502
+ if (isImeComposing(e)) return;
503
+ if (e.key === "Enter") {
504
+ e.preventDefault();
505
+ e.stopPropagation();
506
+ content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
507
+ } else if (e.key === " ") {
508
+ e.preventDefault();
509
+ e.stopPropagation();
510
+ }
511
+ }, { signal: this.eventsAbortController.signal });
512
+ content.addEventListener("keyup", (e) => {
513
+ if (e.key === " ") {
514
+ e.preventDefault();
515
+ e.stopPropagation();
516
+ content.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
517
+ }
518
+ }, { signal: this.eventsAbortController.signal });
519
+ }
464
520
  if (this.options.title && this.options.title.trim() !== "") {
465
521
  const titleEl = document.createElement("div");
466
522
  titleEl.className = "wulf-toast-title";
@@ -504,7 +560,7 @@ var __WulfIIFE = (() => {
504
560
  * Injection de texte sécurisée gérant nativement les retours à la ligne (\n et \r\n).
505
561
  */
506
562
  appendTextWithLineBreaks(container, text) {
507
- const safeText = String(text ?? "").slice(0, 4096);
563
+ const safeText = stripBidiAndInvisibles(String(text ?? ""), 4096);
508
564
  const lines = safeText.split(/\r\n|\r|\n/).slice(0, 100);
509
565
  lines.forEach((line, index) => {
510
566
  if (index > 0) {
@@ -520,7 +576,11 @@ var __WulfIIFE = (() => {
520
576
  const { signal } = this.eventsAbortController;
521
577
  this.element.addEventListener("click", (e) => {
522
578
  if (this.options.onClick) {
523
- this.options.onClick(this, e);
579
+ try {
580
+ this.options.onClick(this, e);
581
+ } catch (err) {
582
+ console.error("[Wulf.Toast] Erreur dans le callback onClick:", err);
583
+ }
524
584
  }
525
585
  if (this.options.closeOnClick) {
526
586
  this.close("toast-click");
@@ -543,6 +603,7 @@ var __WulfIIFE = (() => {
543
603
  }, { signal });
544
604
  this.element.addEventListener("keydown", (e) => {
545
605
  if (e.key === "Escape" && (this.options.closable ?? true)) {
606
+ if (isImeComposing(e)) return;
546
607
  e.stopPropagation();
547
608
  this.close("close-button");
548
609
  }
@@ -577,7 +638,8 @@ var __WulfIIFE = (() => {
577
638
  this.timerStartTime = performance.now();
578
639
  this.timerId = window.setTimeout(() => {
579
640
  this.timerId = null;
580
- if (typeof document !== "undefined" && this.element.contains(document.activeElement)) {
641
+ const active = getDeepActiveElement();
642
+ if (active && this.element.contains(active)) {
581
643
  this.isPendingFocusDismiss = true;
582
644
  return;
583
645
  }
@@ -617,6 +679,10 @@ var __WulfIIFE = (() => {
617
679
  this.isPausedByFocus = false;
618
680
  } else if (source === "hover") {
619
681
  this.isPausedByHover = false;
682
+ const active = getDeepActiveElement();
683
+ if (active && this.element.contains(active)) {
684
+ this.isPausedByFocus = true;
685
+ }
620
686
  } else {
621
687
  this.isPausedByHover = false;
622
688
  this.isPausedByFocus = false;
@@ -640,7 +706,11 @@ var __WulfIIFE = (() => {
640
706
  this.element.parentNode.removeChild(this.element);
641
707
  }
642
708
  if (this.options.onClose) {
643
- this.options.onClose(this, reason);
709
+ try {
710
+ this.options.onClose(this, reason);
711
+ } catch (err) {
712
+ console.error("[Wulf.Toast] Erreur dans le callback onClose:", err);
713
+ }
644
714
  }
645
715
  }
646
716
  /**
@@ -700,6 +770,7 @@ var __WulfIIFE = (() => {
700
770
  var ToastManager = class _ToastManager {
701
771
  static instance = null;
702
772
  containers = /* @__PURE__ */ new Map();
773
+ containerBaseLabels = /* @__PURE__ */ new WeakMap();
703
774
  activeToasts = /* @__PURE__ */ new Map();
704
775
  announcerEl = null;
705
776
  politeRegion = null;
@@ -821,7 +892,7 @@ var __WulfIIFE = (() => {
821
892
  * Annonce la notification sur un canal unique pour éviter les doubles lectures AT.
822
893
  */
823
894
  announce(toast) {
824
- const parts = [toast.options.title, toast.options.message].filter((val) => typeof val === "string" && val.trim().length > 0).map((val) => val.trim());
895
+ 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);
825
896
  if (parts.length === 0) return;
826
897
  const rawText = parts.join(". ");
827
898
  const text = rawText.length > 512 ? `${rawText.slice(0, 509)}...` : rawText;
@@ -933,7 +1004,8 @@ var __WulfIIFE = (() => {
933
1004
  * Transfère le focus avant de retirer un toast focalisé pour éviter que le focus ne retombe sur <body>.
934
1005
  */
935
1006
  handleFocusHandoff(toast, list) {
936
- if (!toast.element.contains(document.activeElement)) {
1007
+ const active = getDeepActiveElement();
1008
+ if (!active || !toast.element.contains(active)) {
937
1009
  return;
938
1010
  }
939
1011
  for (let i = list.length - 1; i >= 0; i--) {
@@ -946,7 +1018,15 @@ var __WulfIIFE = (() => {
946
1018
  }
947
1019
  }
948
1020
  const prev = toast.getPreviousActiveElement();
949
- if (prev && prev.isConnected && typeof prev.focus === "function" && !prev.disabled && !prev.closest("[inert]") && prev.getAttribute("aria-hidden") !== "true") {
1021
+ 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)) {
1022
+ const prevWithCheck = prev;
1023
+ if (typeof prevWithCheck.checkVisibility === "function" && !prevWithCheck.checkVisibility({
1024
+ checkOpacity: false,
1025
+ checkVisibilityCSS: true,
1026
+ visibilityProperty: true
1027
+ })) {
1028
+ return;
1029
+ }
950
1030
  try {
951
1031
  prev.focus();
952
1032
  } catch {
@@ -974,6 +1054,7 @@ var __WulfIIFE = (() => {
974
1054
  this.disposeContainer(container);
975
1055
  this.containers.delete(position);
976
1056
  this.activeToasts.delete(position);
1057
+ this.syncContainerRegionLabels();
977
1058
  }
978
1059
  }
979
1060
  } else if (toast.element.parentNode) {
@@ -1012,6 +1093,7 @@ var __WulfIIFE = (() => {
1012
1093
  this.disposeContainer(container);
1013
1094
  this.containers.delete(position);
1014
1095
  this.activeToasts.delete(position);
1096
+ this.syncContainerRegionLabels();
1015
1097
  }
1016
1098
  }
1017
1099
  } else {
@@ -1044,6 +1126,7 @@ var __WulfIIFE = (() => {
1044
1126
  this.activeToasts.delete(pos);
1045
1127
  }
1046
1128
  }
1129
+ this.syncContainerRegionLabels();
1047
1130
  }
1048
1131
  });
1049
1132
  }
@@ -1055,6 +1138,10 @@ var __WulfIIFE = (() => {
1055
1138
  window.clearTimeout(timerId);
1056
1139
  }
1057
1140
  this.announceTimers = [];
1141
+ this.politeAnnounceTimerId = null;
1142
+ this.assertiveAnnounceTimerId = null;
1143
+ this.politeClearTimerId = null;
1144
+ this.assertiveClearTimerId = null;
1058
1145
  for (const list of Array.from(this.activeToasts.values())) {
1059
1146
  for (const toast of [...list]) {
1060
1147
  toast.destroyImmediate("programmatic");
@@ -1075,6 +1162,13 @@ var __WulfIIFE = (() => {
1075
1162
  }
1076
1163
  _ToastManager.instance = null;
1077
1164
  }
1165
+ syncContainerRegionLabels() {
1166
+ const useSuffix = this.containers.size > 1;
1167
+ for (const [pos, container] of this.containers.entries()) {
1168
+ const baseLabel = this.containerBaseLabels.get(container) || toastI18n.t("notificationsRegion");
1169
+ container.setAttribute("aria-label", useSuffix ? `${baseLabel} (${pos})` : baseLabel);
1170
+ }
1171
+ }
1078
1172
  /**
1079
1173
  * Récupère ou crée le conteneur DOM pour une position d'affichage.
1080
1174
  */
@@ -1084,12 +1178,15 @@ var __WulfIIFE = (() => {
1084
1178
  container = document.createElement("div");
1085
1179
  container.className = `wulf-toast-container wulf-toast-${position}`;
1086
1180
  container.setAttribute("role", "region");
1087
- container.setAttribute("aria-label", toastI18n.t("notificationsRegion", toast.options.i18n));
1181
+ const baseLabel = toastI18n.t("notificationsRegion", toast.options.i18n);
1182
+ this.containerBaseLabels.set(container, baseLabel);
1183
+ container.setAttribute("aria-label", baseLabel);
1088
1184
  if (useTopLayer && typeof container.showPopover === "function") {
1089
1185
  container.setAttribute("popover", "manual");
1090
1186
  }
1091
1187
  document.body.appendChild(container);
1092
1188
  this.containers.set(position, container);
1189
+ this.syncContainerRegionLabels();
1093
1190
  }
1094
1191
  return container;
1095
1192
  }