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
@@ -43,6 +43,14 @@ var __WulfIIFE = (() => {
43
43
  }
44
44
  return existing;
45
45
  }
46
+ function getDeepActiveElement(root) {
47
+ if (typeof document === "undefined") return null;
48
+ let active = (root ?? document).activeElement;
49
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
50
+ active = active.shadowRoot.activeElement;
51
+ }
52
+ return active && typeof active.focus === "function" ? active : null;
53
+ }
46
54
  function parseCssDurationMs(duration, fallbackMs = 300, maxMs = 6e4) {
47
55
  const safeFallback = Number.isFinite(fallbackMs) && fallbackMs >= 0 ? Math.min(fallbackMs, maxMs) : 300;
48
56
  if (typeof duration === "number") {
@@ -228,9 +236,10 @@ var __WulfIIFE = (() => {
228
236
  const colHeights = new Array(cols).fill(0);
229
237
  const positions = [];
230
238
  const itemHeights = items.map((item) => {
231
- const h = item.getBoundingClientRect().height;
239
+ const h = item.classList.contains("wulf-masonry-item--hidden") && item.offsetHeight > 0 ? item.offsetHeight : item.getBoundingClientRect().height;
232
240
  return h > 0 ? h : 50;
233
241
  });
242
+ const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
234
243
  let currentHCol = 0;
235
244
  for (let i = 0; i < items.length; i++) {
236
245
  const item = items[i];
@@ -281,7 +290,6 @@ var __WulfIIFE = (() => {
281
290
  }
282
291
  }
283
292
  const itemW = span * colWidth + (span - 1) * gutterX;
284
- const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
285
293
  const effectiveWidth = fittedWidth !== void 0 ? fittedWidth : containerWidth;
286
294
  const rawX = targetCol * (colWidth + gutterX);
287
295
  const targetX = isRtl ? Math.max(0, effectiveWidth - rawX - itemW) : rawX;
@@ -585,6 +593,7 @@ var __WulfIIFE = (() => {
585
593
  });
586
594
 
587
595
  // src/masonry/Masonry.ts
596
+ var NATIVE_STRUCTURAL_TAGS = /* @__PURE__ */ new Set(["UL", "OL", "MAIN", "NAV", "ASIDE", "ARTICLE", "SECTION"]);
588
597
  var Masonry = class extends LocalizedComponent {
589
598
  static _i18n = masonryI18n;
590
599
  static i18n = masonryI18n;
@@ -596,9 +605,11 @@ var __WulfIIFE = (() => {
596
605
  itemResizeObserver = null;
597
606
  observedItems = /* @__PURE__ */ new Set();
598
607
  observedItemHeights = /* @__PURE__ */ new WeakMap();
599
- removingItems = /* @__PURE__ */ new WeakSet();
608
+ removingItems = /* @__PURE__ */ new Set();
600
609
  layoutRafId = null;
610
+ lastObservedWidth = 0;
601
611
  isDestroyed = false;
612
+ hasExplicitAriaRole = false;
602
613
  wasRoleInferred = false;
603
614
  wasAriaLabelInferred = false;
604
615
  hasExplicitAriaLabel = false;
@@ -628,6 +639,7 @@ var __WulfIIFE = (() => {
628
639
  height: this.root.style.height,
629
640
  width: this.root.style.width
630
641
  };
642
+ this.hasExplicitAriaRole = Boolean(options.ariaRole);
631
643
  this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
632
644
  this.options = {
633
645
  itemSelector: options.itemSelector || "> *",
@@ -673,7 +685,7 @@ var __WulfIIFE = (() => {
673
685
  * Initialise les attributs WAI-ARIA du conteneur.
674
686
  */
675
687
  initAccessibility() {
676
- if (this.options.ariaRole && !this.root.hasAttribute("role")) {
688
+ if (this.options.ariaRole && !this.root.hasAttribute("role") && (this.hasExplicitAriaRole || !NATIVE_STRUCTURAL_TAGS.has(this.root.tagName))) {
677
689
  this.root.setAttribute("role", this.options.ariaRole);
678
690
  this.wasRoleInferred = true;
679
691
  }
@@ -705,9 +717,10 @@ var __WulfIIFE = (() => {
705
717
  const dur = this.options.transitionDuration;
706
718
  let durValue = "300ms";
707
719
  if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
708
- durValue = `${dur}ms`;
720
+ durValue = `${Math.min(dur, 6e4)}ms`;
709
721
  } else if (typeof dur === "string" && /^\s*(?:\d+(?:\.\d+)?|\.\d+)(ms|s)\s*$/i.test(dur)) {
710
- durValue = dur.trim();
722
+ const parsedMs = parseCssDurationMs(dur, 300, 6e4);
723
+ durValue = parsedMs >= 6e4 ? "60000ms" : dur.trim();
711
724
  }
712
725
  this.root.style.setProperty("--wulf-masonry-duration", durValue);
713
726
  }
@@ -758,12 +771,12 @@ var __WulfIIFE = (() => {
758
771
  */
759
772
  initObservers() {
760
773
  if (!this.options.resize || typeof ResizeObserver === "undefined") return;
761
- let prevWidth = this.root.getBoundingClientRect().width;
774
+ this.lastObservedWidth = this.root.getBoundingClientRect().width;
762
775
  this.resizeObserver = new ResizeObserver((entries) => {
763
776
  for (const entry of entries) {
764
777
  const currentWidth = entry.contentRect.width;
765
- if (Math.abs(currentWidth - prevWidth) >= 1) {
766
- prevWidth = currentWidth;
778
+ if (Math.abs(currentWidth - this.lastObservedWidth) >= 1) {
779
+ this.lastObservedWidth = currentWidth;
767
780
  this.scheduleLayout();
768
781
  }
769
782
  }
@@ -805,15 +818,23 @@ var __WulfIIFE = (() => {
805
818
  this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
806
819
  }
807
820
  } else if (typeof this.options.columnWidth === "string" && this.options.columnWidth.trim()) {
808
- try {
809
- const el = this.root.querySelector(this.options.columnWidth);
810
- if (el) {
811
- const w = el.getBoundingClientRect().width;
812
- if (w > 0) {
813
- this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
821
+ const trimmed = this.options.columnWidth.trim();
822
+ if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
823
+ const w = LayoutEngine.resolveColumnWidth(this.root, null, trimmed);
824
+ if (w > 0) {
825
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
826
+ }
827
+ } else {
828
+ try {
829
+ const el = this.root.querySelector(trimmed);
830
+ if (el) {
831
+ const w = el.getBoundingClientRect().width;
832
+ if (w > 0) {
833
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
834
+ }
814
835
  }
836
+ } catch {
815
837
  }
816
- } catch {
817
838
  }
818
839
  }
819
840
  }
@@ -867,60 +888,80 @@ var __WulfIIFE = (() => {
867
888
  for (const el of this._items) {
868
889
  el.classList.remove("wulf-masonry-item--hidden");
869
890
  }
870
- this.options.onLayout([]);
891
+ try {
892
+ this.options.onLayout([]);
893
+ } catch (err) {
894
+ console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
895
+ }
871
896
  return;
872
897
  }
873
898
  this.root.setAttribute("aria-busy", "true");
874
- if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
875
- this.root.style.width = "";
876
- }
877
- const result = LayoutEngine.calculate(this.root, this._items, this.options);
878
- this.root.style.height = `${result.containerHeight}px`;
879
- if (this.options.fitWidth && result.fittedWidth !== void 0) {
880
- this.root.style.width = `${result.fittedWidth}px`;
881
- this.root.classList.add("wulf-masonry--fit-width");
882
- } else {
883
- this.root.classList.remove("wulf-masonry--fit-width");
884
- }
885
- const stagger = this.options.stagger;
886
- const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
887
- if (validStagger) {
888
- this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
889
- } else {
890
- this.root.style.removeProperty("--wulf-masonry-stagger");
891
- }
892
- const hasIgnoredChildren = this._items.length !== this.root.children.length;
893
- const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
894
- const usePercent = this.options.percentPosition && result.containerWidth > 0;
895
- for (let i = 0; i < result.positions.length; i++) {
896
- const pos = result.positions[i];
897
- const item = pos.element;
898
- if (usePercent) {
899
- const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
900
- item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
899
+ let positionsResult = [];
900
+ try {
901
+ if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
902
+ this.root.style.width = "";
903
+ }
904
+ const result = LayoutEngine.calculate(this.root, this._items, this.options);
905
+ positionsResult = result.positions;
906
+ this.root.style.height = `${result.containerHeight}px`;
907
+ if (this.options.fitWidth && result.fittedWidth !== void 0) {
908
+ this.root.style.width = `${result.fittedWidth}px`;
909
+ this.lastObservedWidth = result.fittedWidth;
910
+ this.root.classList.add("wulf-masonry--fit-width");
901
911
  } else {
902
- item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
912
+ this.root.classList.remove("wulf-masonry--fit-width");
903
913
  }
904
- item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
905
- item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
906
- if (validStagger && !supportsSiblingIndex) {
907
- item.style.setProperty("--wulf-masonry-index", String(i));
914
+ const stagger = this.options.stagger;
915
+ const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
916
+ if (validStagger) {
917
+ this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
908
918
  } else {
909
- item.style.removeProperty("--wulf-masonry-index");
919
+ this.root.style.removeProperty("--wulf-masonry-stagger");
910
920
  }
911
- item.classList.remove("wulf-masonry-item--hidden");
912
- this.observedItemHeights.set(item, pos.height);
913
- this.options.onItemPlaced(item, pos);
921
+ const hasIgnoredChildren = this._items.length !== this.root.children.length;
922
+ const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
923
+ const usePercent = this.options.percentPosition && result.containerWidth > 0;
924
+ for (let i = 0; i < result.positions.length; i++) {
925
+ const pos = result.positions[i];
926
+ const item = pos.element;
927
+ if (usePercent) {
928
+ const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
929
+ item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
930
+ } else {
931
+ item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
932
+ }
933
+ item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
934
+ item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
935
+ if (validStagger && !supportsSiblingIndex) {
936
+ item.style.setProperty("--wulf-masonry-index", String(i));
937
+ } else {
938
+ item.style.removeProperty("--wulf-masonry-index");
939
+ }
940
+ item.classList.remove("wulf-masonry-item--hidden");
941
+ this.observedItemHeights.set(item, pos.height);
942
+ try {
943
+ this.options.onItemPlaced(item, pos);
944
+ } catch (err) {
945
+ console.error("[Wulf.Masonry] Erreur dans onItemPlaced:", err);
946
+ }
947
+ }
948
+ } finally {
949
+ this.root.setAttribute("aria-busy", "false");
950
+ }
951
+ try {
952
+ this.options.onLayout(positionsResult);
953
+ } catch (err) {
954
+ console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
914
955
  }
915
- this.root.setAttribute("aria-busy", "false");
916
- this.options.onLayout(result.positions);
917
956
  }
918
957
  /**
919
958
  * Ajoute de nouveaux éléments à la fin du conteneur.
920
959
  */
921
960
  append(elements) {
922
961
  if (this.isDestroyed) return;
923
- const list = Array.isArray(elements) ? elements : [elements];
962
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
963
+ (el) => el instanceof HTMLElement && !el.contains(this.root)
964
+ );
924
965
  if (list.length === 0) return;
925
966
  const frag = document.createDocumentFragment();
926
967
  for (const el of list) {
@@ -941,7 +982,9 @@ var __WulfIIFE = (() => {
941
982
  */
942
983
  prepend(elements) {
943
984
  if (this.isDestroyed) return;
944
- const list = Array.isArray(elements) ? elements : [elements];
985
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
986
+ (el) => el instanceof HTMLElement && !el.contains(this.root)
987
+ );
945
988
  if (list.length === 0) return;
946
989
  const first = this.root.firstChild;
947
990
  const frag = document.createDocumentFragment();
@@ -963,7 +1006,9 @@ var __WulfIIFE = (() => {
963
1006
  */
964
1007
  remove(elements) {
965
1008
  if (this.isDestroyed) return;
966
- const list = Array.isArray(elements) ? elements : [elements];
1009
+ const list = (Array.isArray(elements) ? elements : [elements]).filter(
1010
+ (el) => el instanceof HTMLElement
1011
+ );
967
1012
  if (list.length === 0) return;
968
1013
  const finalizeRemoval = () => {
969
1014
  if (this.isDestroyed) return;
@@ -981,11 +1026,34 @@ var __WulfIIFE = (() => {
981
1026
  this.reloadItems();
982
1027
  this.layout();
983
1028
  };
1029
+ const activeEl = getDeepActiveElement();
1030
+ if (activeEl && list.some((el) => el.contains(activeEl))) {
1031
+ const removeSet = new Set(list);
1032
+ const firstRemovedIdx = this._items.findIndex((item) => removeSet.has(item));
1033
+ const survivorsAfter = firstRemovedIdx >= 0 ? this._items.slice(firstRemovedIdx + 1).filter((item) => !removeSet.has(item)) : [];
1034
+ const survivorsBefore = firstRemovedIdx > 0 ? this._items.slice(0, firstRemovedIdx).filter((item) => !removeSet.has(item)).reverse() : [];
1035
+ const candidateItem = survivorsAfter[0] || survivorsBefore[0] || null;
1036
+ let handoffDone = false;
1037
+ if (candidateItem) {
1038
+ const focusableChild = candidateItem.querySelector(
1039
+ 'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
1040
+ );
1041
+ const focusTarget = focusableChild || (candidateItem.tabIndex >= 0 ? candidateItem : null);
1042
+ if (focusTarget) {
1043
+ try {
1044
+ focusTarget.focus({ preventScroll: true });
1045
+ handoffDone = true;
1046
+ } catch {
1047
+ handoffDone = false;
1048
+ }
1049
+ }
1050
+ }
1051
+ if (!handoffDone) {
1052
+ activeEl.blur?.();
1053
+ }
1054
+ }
984
1055
  for (const el of list) {
985
1056
  this.removingItems.add(el);
986
- if (typeof document !== "undefined" && document.activeElement && el.contains(document.activeElement)) {
987
- document.activeElement.blur?.();
988
- }
989
1057
  el.setAttribute("inert", "");
990
1058
  el.style.transitionDelay = "0ms";
991
1059
  el.classList.add("wulf-masonry-item--hidden");
@@ -1011,7 +1079,7 @@ var __WulfIIFE = (() => {
1011
1079
  */
1012
1080
  audit() {
1013
1081
  const warnings = [];
1014
- const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings);
1082
+ const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings, true);
1015
1083
  const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
1016
1084
  if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
1017
1085
  warnings.push(
@@ -1026,6 +1094,19 @@ var __WulfIIFE = (() => {
1026
1094
  `${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
1027
1095
  );
1028
1096
  }
1097
+ const positiveTabIndexEls = Array.from(this.root.querySelectorAll("[tabindex]")).filter(
1098
+ (el) => el.tabIndex > 0
1099
+ );
1100
+ if (positiveTabIndexEls.length > 0) {
1101
+ warnings.push(
1102
+ `${positiveTabIndexEls.length} \xE9l\xE9ment(s) avec tabindex > 0 d\xE9tect\xE9(s) : utilisez uniquement tabindex="0" ou "-1" (WCAG 2.4.3).`
1103
+ );
1104
+ }
1105
+ if (!this.options.horizontalOrder && this.root.querySelector('a[href], button, input, select, textarea, [tabindex="0"]') !== null) {
1106
+ warnings.push(
1107
+ "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)."
1108
+ );
1109
+ }
1029
1110
  return warnings;
1030
1111
  }
1031
1112
  getAuditPrefix() {
@@ -1076,6 +1157,16 @@ var __WulfIIFE = (() => {
1076
1157
  } else {
1077
1158
  this.root.style.removeProperty("width");
1078
1159
  }
1160
+ for (const item of this.removingItems) {
1161
+ item.removeAttribute("inert");
1162
+ item.style.removeProperty("transition-delay");
1163
+ item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
1164
+ item.style.removeProperty("--wulf-masonry-w");
1165
+ item.style.removeProperty("--wulf-masonry-x");
1166
+ item.style.removeProperty("--wulf-masonry-y");
1167
+ item.style.removeProperty("--wulf-masonry-index");
1168
+ }
1169
+ this.removingItems.clear();
1079
1170
  for (const item of this._items) {
1080
1171
  item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
1081
1172
  item.style.removeProperty("--wulf-masonry-w");