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
@@ -10,6 +10,14 @@ function getSafeWulfNamespace() {
10
10
  }
11
11
  return existing;
12
12
  }
13
+ function getDeepActiveElement(root) {
14
+ if (typeof document === "undefined") return null;
15
+ let active = (root ?? document).activeElement;
16
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
17
+ active = active.shadowRoot.activeElement;
18
+ }
19
+ return active && typeof active.focus === "function" ? active : null;
20
+ }
13
21
  function parseCssDurationMs(duration, fallbackMs = 300, maxMs = 6e4) {
14
22
  const safeFallback = Number.isFinite(fallbackMs) && fallbackMs >= 0 ? Math.min(fallbackMs, maxMs) : 300;
15
23
  if (typeof duration === "number") {
@@ -195,9 +203,10 @@ var LayoutEngine = class {
195
203
  const colHeights = new Array(cols).fill(0);
196
204
  const positions = [];
197
205
  const itemHeights = items.map((item) => {
198
- const h = item.getBoundingClientRect().height;
206
+ const h = item.classList.contains("wulf-masonry-item--hidden") && item.offsetHeight > 0 ? item.offsetHeight : item.getBoundingClientRect().height;
199
207
  return h > 0 ? h : 50;
200
208
  });
209
+ const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
201
210
  let currentHCol = 0;
202
211
  for (let i = 0; i < items.length; i++) {
203
212
  const item = items[i];
@@ -248,7 +257,6 @@ var LayoutEngine = class {
248
257
  }
249
258
  }
250
259
  const itemW = span * colWidth + (span - 1) * gutterX;
251
- const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
252
260
  const effectiveWidth = fittedWidth !== void 0 ? fittedWidth : containerWidth;
253
261
  const rawX = targetCol * (colWidth + gutterX);
254
262
  const targetX = isRtl ? Math.max(0, effectiveWidth - rawX - itemW) : rawX;
@@ -552,6 +560,7 @@ var masonryI18n = createI18nManager("fr", {
552
560
  });
553
561
 
554
562
  // src/masonry/Masonry.ts
563
+ var NATIVE_STRUCTURAL_TAGS = /* @__PURE__ */ new Set(["UL", "OL", "MAIN", "NAV", "ASIDE", "ARTICLE", "SECTION"]);
555
564
  var Masonry = class extends LocalizedComponent {
556
565
  static _i18n = masonryI18n;
557
566
  static i18n = masonryI18n;
@@ -563,9 +572,11 @@ var Masonry = class extends LocalizedComponent {
563
572
  itemResizeObserver = null;
564
573
  observedItems = /* @__PURE__ */ new Set();
565
574
  observedItemHeights = /* @__PURE__ */ new WeakMap();
566
- removingItems = /* @__PURE__ */ new WeakSet();
575
+ removingItems = /* @__PURE__ */ new Set();
567
576
  layoutRafId = null;
577
+ lastObservedWidth = 0;
568
578
  isDestroyed = false;
579
+ hasExplicitAriaRole = false;
569
580
  wasRoleInferred = false;
570
581
  wasAriaLabelInferred = false;
571
582
  hasExplicitAriaLabel = false;
@@ -595,6 +606,7 @@ var Masonry = class extends LocalizedComponent {
595
606
  height: this.root.style.height,
596
607
  width: this.root.style.width
597
608
  };
609
+ this.hasExplicitAriaRole = Boolean(options.ariaRole);
598
610
  this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
599
611
  this.options = {
600
612
  itemSelector: options.itemSelector || "> *",
@@ -640,7 +652,7 @@ var Masonry = class extends LocalizedComponent {
640
652
  * Initialise les attributs WAI-ARIA du conteneur.
641
653
  */
642
654
  initAccessibility() {
643
- if (this.options.ariaRole && !this.root.hasAttribute("role")) {
655
+ if (this.options.ariaRole && !this.root.hasAttribute("role") && (this.hasExplicitAriaRole || !NATIVE_STRUCTURAL_TAGS.has(this.root.tagName))) {
644
656
  this.root.setAttribute("role", this.options.ariaRole);
645
657
  this.wasRoleInferred = true;
646
658
  }
@@ -672,9 +684,10 @@ var Masonry = class extends LocalizedComponent {
672
684
  const dur = this.options.transitionDuration;
673
685
  let durValue = "300ms";
674
686
  if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
675
- durValue = `${dur}ms`;
687
+ durValue = `${Math.min(dur, 6e4)}ms`;
676
688
  } else if (typeof dur === "string" && /^\s*(?:\d+(?:\.\d+)?|\.\d+)(ms|s)\s*$/i.test(dur)) {
677
- durValue = dur.trim();
689
+ const parsedMs = parseCssDurationMs(dur, 300, 6e4);
690
+ durValue = parsedMs >= 6e4 ? "60000ms" : dur.trim();
678
691
  }
679
692
  this.root.style.setProperty("--wulf-masonry-duration", durValue);
680
693
  }
@@ -725,12 +738,12 @@ var Masonry = class extends LocalizedComponent {
725
738
  */
726
739
  initObservers() {
727
740
  if (!this.options.resize || typeof ResizeObserver === "undefined") return;
728
- let prevWidth = this.root.getBoundingClientRect().width;
741
+ this.lastObservedWidth = this.root.getBoundingClientRect().width;
729
742
  this.resizeObserver = new ResizeObserver((entries) => {
730
743
  for (const entry of entries) {
731
744
  const currentWidth = entry.contentRect.width;
732
- if (Math.abs(currentWidth - prevWidth) >= 1) {
733
- prevWidth = currentWidth;
745
+ if (Math.abs(currentWidth - this.lastObservedWidth) >= 1) {
746
+ this.lastObservedWidth = currentWidth;
734
747
  this.scheduleLayout();
735
748
  }
736
749
  }
@@ -772,15 +785,23 @@ var Masonry = class extends LocalizedComponent {
772
785
  this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
773
786
  }
774
787
  } else if (typeof this.options.columnWidth === "string" && this.options.columnWidth.trim()) {
775
- try {
776
- const el = this.root.querySelector(this.options.columnWidth);
777
- if (el) {
778
- const w = el.getBoundingClientRect().width;
779
- if (w > 0) {
780
- this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
788
+ const trimmed = this.options.columnWidth.trim();
789
+ if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
790
+ const w = LayoutEngine.resolveColumnWidth(this.root, null, trimmed);
791
+ if (w > 0) {
792
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
793
+ }
794
+ } else {
795
+ try {
796
+ const el = this.root.querySelector(trimmed);
797
+ if (el) {
798
+ const w = el.getBoundingClientRect().width;
799
+ if (w > 0) {
800
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
801
+ }
781
802
  }
803
+ } catch {
782
804
  }
783
- } catch {
784
805
  }
785
806
  }
786
807
  }
@@ -834,60 +855,80 @@ var Masonry = class extends LocalizedComponent {
834
855
  for (const el of this._items) {
835
856
  el.classList.remove("wulf-masonry-item--hidden");
836
857
  }
837
- this.options.onLayout([]);
858
+ try {
859
+ this.options.onLayout([]);
860
+ } catch (err) {
861
+ console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
862
+ }
838
863
  return;
839
864
  }
840
865
  this.root.setAttribute("aria-busy", "true");
841
- if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
842
- this.root.style.width = "";
843
- }
844
- const result = LayoutEngine.calculate(this.root, this._items, this.options);
845
- this.root.style.height = `${result.containerHeight}px`;
846
- if (this.options.fitWidth && result.fittedWidth !== void 0) {
847
- this.root.style.width = `${result.fittedWidth}px`;
848
- this.root.classList.add("wulf-masonry--fit-width");
849
- } else {
850
- this.root.classList.remove("wulf-masonry--fit-width");
851
- }
852
- const stagger = this.options.stagger;
853
- const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
854
- if (validStagger) {
855
- this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
856
- } else {
857
- this.root.style.removeProperty("--wulf-masonry-stagger");
858
- }
859
- const hasIgnoredChildren = this._items.length !== this.root.children.length;
860
- const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
861
- const usePercent = this.options.percentPosition && result.containerWidth > 0;
862
- for (let i = 0; i < result.positions.length; i++) {
863
- const pos = result.positions[i];
864
- const item = pos.element;
865
- if (usePercent) {
866
- const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
867
- item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
866
+ let positionsResult = [];
867
+ try {
868
+ if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
869
+ this.root.style.width = "";
870
+ }
871
+ const result = LayoutEngine.calculate(this.root, this._items, this.options);
872
+ positionsResult = result.positions;
873
+ this.root.style.height = `${result.containerHeight}px`;
874
+ if (this.options.fitWidth && result.fittedWidth !== void 0) {
875
+ this.root.style.width = `${result.fittedWidth}px`;
876
+ this.lastObservedWidth = result.fittedWidth;
877
+ this.root.classList.add("wulf-masonry--fit-width");
868
878
  } else {
869
- item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
879
+ this.root.classList.remove("wulf-masonry--fit-width");
870
880
  }
871
- item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
872
- item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
873
- if (validStagger && !supportsSiblingIndex) {
874
- item.style.setProperty("--wulf-masonry-index", String(i));
881
+ const stagger = this.options.stagger;
882
+ const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
883
+ if (validStagger) {
884
+ this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
875
885
  } else {
876
- item.style.removeProperty("--wulf-masonry-index");
886
+ this.root.style.removeProperty("--wulf-masonry-stagger");
877
887
  }
878
- item.classList.remove("wulf-masonry-item--hidden");
879
- this.observedItemHeights.set(item, pos.height);
880
- this.options.onItemPlaced(item, pos);
888
+ const hasIgnoredChildren = this._items.length !== this.root.children.length;
889
+ const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
890
+ const usePercent = this.options.percentPosition && result.containerWidth > 0;
891
+ for (let i = 0; i < result.positions.length; i++) {
892
+ const pos = result.positions[i];
893
+ const item = pos.element;
894
+ if (usePercent) {
895
+ const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
896
+ item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
897
+ } else {
898
+ item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
899
+ }
900
+ item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
901
+ item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
902
+ if (validStagger && !supportsSiblingIndex) {
903
+ item.style.setProperty("--wulf-masonry-index", String(i));
904
+ } else {
905
+ item.style.removeProperty("--wulf-masonry-index");
906
+ }
907
+ item.classList.remove("wulf-masonry-item--hidden");
908
+ this.observedItemHeights.set(item, pos.height);
909
+ try {
910
+ this.options.onItemPlaced(item, pos);
911
+ } catch (err) {
912
+ console.error("[Wulf.Masonry] Erreur dans onItemPlaced:", err);
913
+ }
914
+ }
915
+ } finally {
916
+ this.root.setAttribute("aria-busy", "false");
917
+ }
918
+ try {
919
+ this.options.onLayout(positionsResult);
920
+ } catch (err) {
921
+ console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
881
922
  }
882
- this.root.setAttribute("aria-busy", "false");
883
- this.options.onLayout(result.positions);
884
923
  }
885
924
  /**
886
925
  * Ajoute de nouveaux éléments à la fin du conteneur.
887
926
  */
888
927
  append(elements) {
889
928
  if (this.isDestroyed) return;
890
- const list = Array.isArray(elements) ? elements : [elements];
929
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
930
+ (el) => el instanceof HTMLElement && !el.contains(this.root)
931
+ );
891
932
  if (list.length === 0) return;
892
933
  const frag = document.createDocumentFragment();
893
934
  for (const el of list) {
@@ -908,7 +949,9 @@ var Masonry = class extends LocalizedComponent {
908
949
  */
909
950
  prepend(elements) {
910
951
  if (this.isDestroyed) return;
911
- const list = Array.isArray(elements) ? elements : [elements];
952
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
953
+ (el) => el instanceof HTMLElement && !el.contains(this.root)
954
+ );
912
955
  if (list.length === 0) return;
913
956
  const first = this.root.firstChild;
914
957
  const frag = document.createDocumentFragment();
@@ -930,7 +973,9 @@ var Masonry = class extends LocalizedComponent {
930
973
  */
931
974
  remove(elements) {
932
975
  if (this.isDestroyed) return;
933
- const list = Array.isArray(elements) ? elements : [elements];
976
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
977
+ (el) => el instanceof HTMLElement
978
+ );
934
979
  if (list.length === 0) return;
935
980
  const finalizeRemoval = () => {
936
981
  if (this.isDestroyed) return;
@@ -948,11 +993,34 @@ var Masonry = class extends LocalizedComponent {
948
993
  this.reloadItems();
949
994
  this.layout();
950
995
  };
996
+ const activeEl = getDeepActiveElement();
997
+ if (activeEl && list.some((el) => el.contains(activeEl))) {
998
+ const removeSet = new Set(list);
999
+ const firstRemovedIdx = this._items.findIndex((item) => removeSet.has(item));
1000
+ const survivorsAfter = firstRemovedIdx >= 0 ? this._items.slice(firstRemovedIdx + 1).filter((item) => !removeSet.has(item)) : [];
1001
+ const survivorsBefore = firstRemovedIdx > 0 ? this._items.slice(0, firstRemovedIdx).filter((item) => !removeSet.has(item)).reverse() : [];
1002
+ const candidateItem = survivorsAfter[0] || survivorsBefore[0] || null;
1003
+ let handoffDone = false;
1004
+ if (candidateItem) {
1005
+ const focusableChild = candidateItem.querySelector(
1006
+ 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
1007
+ );
1008
+ const focusTarget = focusableChild || (candidateItem.tabIndex >= 0 ? candidateItem : null);
1009
+ if (focusTarget) {
1010
+ try {
1011
+ focusTarget.focus({ preventScroll: true });
1012
+ handoffDone = true;
1013
+ } catch {
1014
+ handoffDone = false;
1015
+ }
1016
+ }
1017
+ }
1018
+ if (!handoffDone) {
1019
+ activeEl.blur?.();
1020
+ }
1021
+ }
951
1022
  for (const el of list) {
952
1023
  this.removingItems.add(el);
953
- if (typeof document !== "undefined" && document.activeElement && el.contains(document.activeElement)) {
954
- document.activeElement.blur?.();
955
- }
956
1024
  el.setAttribute("inert", "");
957
1025
  el.style.transitionDelay = "0ms";
958
1026
  el.classList.add("wulf-masonry-item--hidden");
@@ -978,7 +1046,7 @@ var Masonry = class extends LocalizedComponent {
978
1046
  */
979
1047
  audit() {
980
1048
  const warnings = [];
981
- const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
1049
+ const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings, true);
982
1050
  const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
983
1051
  if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
984
1052
  warnings.push(
@@ -993,6 +1061,19 @@ var Masonry = class extends LocalizedComponent {
993
1061
  `${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
994
1062
  );
995
1063
  }
1064
+ const positiveTabIndexEls = Array.from(this.root.querySelectorAll("[tabindex]")).filter(
1065
+ (el) => el.tabIndex > 0
1066
+ );
1067
+ if (positiveTabIndexEls.length > 0) {
1068
+ warnings.push(
1069
+ `${positiveTabIndexEls.length} \xE9l\xE9ment(s) avec tabindex > 0 d\xE9tect\xE9(s) : utilisez uniquement tabindex="0" ou "-1" (WCAG 2.4.3).`
1070
+ );
1071
+ }
1072
+ if (!this.options.horizontalOrder && this.root.querySelector('a[href], button, input, select, textarea, [tabindex="0"]') !== null) {
1073
+ warnings.push(
1074
+ "Grille interactive avec horizontalOrder: false : l'ordre visuel peut diverger de l'ordre de tabulation ; envisagez horizontalOrder: true (WCAG 1.3.2 / 2.4.3)."
1075
+ );
1076
+ }
996
1077
  return warnings;
997
1078
  }
998
1079
  getAuditPrefix() {
@@ -1043,6 +1124,16 @@ var Masonry = class extends LocalizedComponent {
1043
1124
  } else {
1044
1125
  this.root.style.removeProperty("width");
1045
1126
  }
1127
+ for (const item of this.removingItems) {
1128
+ item.removeAttribute("inert");
1129
+ item.style.removeProperty("transition-delay");
1130
+ item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
1131
+ item.style.removeProperty("--wulf-masonry-w");
1132
+ item.style.removeProperty("--wulf-masonry-x");
1133
+ item.style.removeProperty("--wulf-masonry-y");
1134
+ item.style.removeProperty("--wulf-masonry-index");
1135
+ }
1136
+ this.removingItems.clear();
1046
1137
  for (const item of this._items) {
1047
1138
  item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
1048
1139
  item.style.removeProperty("--wulf-masonry-w");