wulf.js 1.9.2 → 2.0.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 (81) hide show
  1. package/README.md +124 -78
  2. package/changelog.md +105 -0
  3. package/dist/focus-trap.esm.js +245 -126
  4. package/dist/focus-trap.esm.js.map +3 -3
  5. package/dist/focus-trap.global.js +247 -128
  6. package/dist/focus-trap.global.js.map +3 -3
  7. package/dist/focus-trap.global.min.js +4 -4
  8. package/dist/focus-trap.global.min.js.map +4 -4
  9. package/dist/index.esm.js +2434 -905
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +2436 -907
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +4 -4
  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 +746 -346
  18. package/dist/mask.esm.js.map +3 -3
  19. package/dist/mask.global.js +748 -348
  20. package/dist/mask.global.js.map +3 -3
  21. package/dist/mask.global.min.js +4 -4
  22. package/dist/mask.global.min.js.map +4 -4
  23. package/dist/mask.layered.css +1 -0
  24. package/dist/mask.layered.css.map +7 -0
  25. package/dist/masonry.css +1 -1
  26. package/dist/masonry.css.map +2 -2
  27. package/dist/masonry.esm.js +341 -114
  28. package/dist/masonry.esm.js.map +3 -3
  29. package/dist/masonry.global.js +343 -116
  30. package/dist/masonry.global.js.map +3 -3
  31. package/dist/masonry.global.min.js +4 -4
  32. package/dist/masonry.global.min.js.map +4 -4
  33. package/dist/masonry.layered.css +1 -0
  34. package/dist/masonry.layered.css.map +7 -0
  35. package/dist/scroll.css +1 -1
  36. package/dist/scroll.css.map +2 -2
  37. package/dist/scroll.esm.js +524 -153
  38. package/dist/scroll.esm.js.map +3 -3
  39. package/dist/scroll.global.js +526 -155
  40. package/dist/scroll.global.js.map +3 -3
  41. package/dist/scroll.global.min.js +4 -4
  42. package/dist/scroll.global.min.js.map +4 -4
  43. package/dist/scroll.layered.css +1 -0
  44. package/dist/scroll.layered.css.map +7 -0
  45. package/dist/shortcut.esm.js +209 -46
  46. package/dist/shortcut.esm.js.map +3 -3
  47. package/dist/shortcut.global.js +211 -48
  48. package/dist/shortcut.global.js.map +3 -3
  49. package/dist/shortcut.global.min.js +2 -2
  50. package/dist/shortcut.global.min.js.map +4 -4
  51. package/dist/toast.css +1 -1
  52. package/dist/toast.css.map +2 -2
  53. package/dist/toast.esm.js +590 -160
  54. package/dist/toast.esm.js.map +3 -3
  55. package/dist/toast.global.js +592 -162
  56. package/dist/toast.global.js.map +3 -3
  57. package/dist/toast.global.min.js +4 -4
  58. package/dist/toast.global.min.js.map +4 -4
  59. package/dist/toast.layered.css +1 -0
  60. package/dist/toast.layered.css.map +7 -0
  61. package/dist/types/common/dom.d.ts +38 -0
  62. package/dist/types/focus-trap/FocusTrap.d.ts +15 -5
  63. package/dist/types/focus-trap/types.d.ts +2 -2
  64. package/dist/types/index.d.ts +10 -0
  65. package/dist/types/mask/AmountEngine.d.ts +1 -0
  66. package/dist/types/mask/BaseInputMask.d.ts +24 -0
  67. package/dist/types/mask/InputAmountMask.d.ts +3 -0
  68. package/dist/types/mask/InputEmailMask.d.ts +16 -1
  69. package/dist/types/mask/InputMask.d.ts +1 -0
  70. package/dist/types/mask/MaskEngine.d.ts +4 -0
  71. package/dist/types/masonry/Masonry.d.ts +10 -3
  72. package/dist/types/scroll/ScrollBlock.d.ts +31 -3
  73. package/dist/types/scroll/types.d.ts +13 -1
  74. package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
  75. package/dist/types/shortcut/ShortcutManager.d.ts +5 -0
  76. package/dist/types/toast/Toast.d.ts +4 -0
  77. package/dist/types/toast/ToastInstance.d.ts +22 -10
  78. package/dist/types/toast/ToastManager.d.ts +37 -4
  79. package/dist/types/toast/i18n/types.d.ts +2 -0
  80. package/dist/types/toast/types.d.ts +14 -2
  81. package/package.json +20 -5
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- var Wulf = (() => {
2
+ var __WulfIIFE = (() => {
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -31,6 +31,79 @@ var Wulf = (() => {
31
31
  masonryI18n: () => masonryI18n
32
32
  });
33
33
 
34
+ // src/common/dom.ts
35
+ function getSafeWulfNamespace() {
36
+ if (typeof window === "undefined") return null;
37
+ const win = window;
38
+ const existing = win.Wulf;
39
+ if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
40
+ const fresh = {};
41
+ win.Wulf = fresh;
42
+ return fresh;
43
+ }
44
+ return existing;
45
+ }
46
+ function parseCssDurationMs(duration, fallbackMs = 300, maxMs = 6e4) {
47
+ const safeFallback = Number.isFinite(fallbackMs) && fallbackMs >= 0 ? Math.min(fallbackMs, maxMs) : 300;
48
+ if (typeof duration === "number") {
49
+ return Number.isFinite(duration) && duration >= 0 ? Math.min(duration, maxMs) : safeFallback;
50
+ }
51
+ if (typeof duration === "string") {
52
+ const parts = duration.split(",");
53
+ let maxParsed = -1;
54
+ for (const part of parts) {
55
+ const match = /^\+?(\d+(?:\.\d+)?|\.\d+)(ms|s)?$/i.exec(part.trim());
56
+ if (match) {
57
+ const raw = parseFloat(match[1]);
58
+ if (Number.isFinite(raw) && raw >= 0) {
59
+ const ms = match[2]?.toLowerCase() === "s" ? raw * 1e3 : raw;
60
+ if (ms > maxParsed) {
61
+ maxParsed = ms;
62
+ }
63
+ }
64
+ }
65
+ }
66
+ if (maxParsed >= 0) {
67
+ return Math.min(maxParsed, maxMs);
68
+ }
69
+ }
70
+ return safeFallback;
71
+ }
72
+ function prefersReducedMotion() {
73
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
74
+ }
75
+ function waitForAnimations(element, fallbackMs, signal) {
76
+ const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
77
+ if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
78
+ return Promise.resolve();
79
+ }
80
+ const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
81
+ if (a.playState !== "running") return false;
82
+ const timing = a.effect?.getComputedTiming?.();
83
+ return timing ? Number.isFinite(timing.endTime) : true;
84
+ }) : [];
85
+ if (animations.length === 0) {
86
+ return Promise.resolve();
87
+ }
88
+ return new Promise((resolve) => {
89
+ let settled = false;
90
+ let timerId = null;
91
+ const finish = () => {
92
+ if (settled) return;
93
+ settled = true;
94
+ if (timerId !== null) {
95
+ clearTimeout(timerId);
96
+ timerId = null;
97
+ }
98
+ signal?.removeEventListener("abort", finish);
99
+ resolve();
100
+ };
101
+ signal?.addEventListener("abort", finish, { once: true });
102
+ timerId = setTimeout(finish, safeFallback);
103
+ Promise.allSettled(animations.map((a) => a.finished)).then(finish);
104
+ });
105
+ }
106
+
34
107
  // src/masonry/LayoutEngine.ts
35
108
  var LayoutEngine = class {
36
109
  /**
@@ -38,12 +111,15 @@ var Wulf = (() => {
38
111
  */
39
112
  static parseGutter(gutterOption) {
40
113
  if (typeof gutterOption === "number") {
41
- return { x: Math.max(0, gutterOption), y: Math.max(0, gutterOption) };
114
+ const v = Number.isFinite(gutterOption) ? Math.max(0, gutterOption) : 0;
115
+ return { x: v, y: v };
42
116
  }
43
117
  if (gutterOption && typeof gutterOption === "object") {
118
+ const rawX = Number(gutterOption.x);
119
+ const rawY = Number(gutterOption.y);
44
120
  return {
45
- x: Math.max(0, Number(gutterOption.x) || 0),
46
- y: Math.max(0, Number(gutterOption.y) || 0)
121
+ x: Number.isFinite(rawX) ? Math.max(0, rawX) : 0,
122
+ y: Number.isFinite(rawY) ? Math.max(0, rawY) : 0
47
123
  };
48
124
  }
49
125
  return { x: 0, y: 0 };
@@ -52,22 +128,37 @@ var Wulf = (() => {
52
128
  * Résout la largeur effective d'une colonne en pixels.
53
129
  */
54
130
  static resolveColumnWidth(container, firstItem, columnWidthOption) {
55
- if (typeof columnWidthOption === "number" && columnWidthOption > 0) {
131
+ if (typeof columnWidthOption === "number" && Number.isFinite(columnWidthOption) && columnWidthOption > 0) {
56
132
  return columnWidthOption;
57
133
  }
58
134
  if (typeof columnWidthOption === "string") {
59
- const el = container.querySelector(columnWidthOption);
60
- if (el) {
61
- const w = el.getBoundingClientRect().width;
62
- if (w > 0) return w;
63
- }
64
- const parsed = parseFloat(columnWidthOption);
65
- if (!isNaN(parsed) && parsed > 0) {
66
- if (columnWidthOption.endsWith("%")) {
67
- const containerW2 = container.getBoundingClientRect().width;
68
- return containerW2 * parsed / 100;
135
+ const trimmed = columnWidthOption.trim();
136
+ if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
137
+ const parsed = parseFloat(trimmed);
138
+ if (Number.isFinite(parsed) && parsed > 0) {
139
+ if (trimmed.endsWith("%")) {
140
+ const containerW2 = container.getBoundingClientRect().width;
141
+ const resolvedPct = containerW2 * parsed / 100;
142
+ if (resolvedPct > 0) return resolvedPct;
143
+ } else {
144
+ return parsed;
145
+ }
146
+ }
147
+ } else if (trimmed) {
148
+ let el = null;
149
+ try {
150
+ el = container.querySelector(trimmed);
151
+ } catch {
152
+ el = null;
153
+ }
154
+ if (el) {
155
+ const w = el.getBoundingClientRect().width;
156
+ if (Number.isFinite(w) && w > 0) return w;
157
+ }
158
+ const parsed = parseFloat(trimmed);
159
+ if (Number.isFinite(parsed) && parsed > 0) {
160
+ return parsed;
69
161
  }
70
- return parsed;
71
162
  }
72
163
  }
73
164
  if (columnWidthOption instanceof HTMLElement) {
@@ -92,11 +183,13 @@ var Wulf = (() => {
92
183
  return Math.min(maxCols, parsed);
93
184
  }
94
185
  }
95
- const match = item.className.match(/(?:^|\s)(?:span|col-span)-(\d+)(?:\s|$)/);
96
- if (match && match[1]) {
97
- const parsed = parseInt(match[1], 10);
98
- if (!isNaN(parsed) && parsed > 0) {
99
- return Math.min(maxCols, parsed);
186
+ for (const cls of item.classList) {
187
+ const match = /^(?:span|col-span)-(\d+)$/.exec(cls);
188
+ if (match && match[1]) {
189
+ const parsed = parseInt(match[1], 10);
190
+ if (!isNaN(parsed) && parsed > 0) {
191
+ return Math.min(maxCols, parsed);
192
+ }
100
193
  }
101
194
  }
102
195
  return 1;
@@ -121,8 +214,13 @@ var Wulf = (() => {
121
214
  }
122
215
  const firstItem = items[0] || null;
123
216
  let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);
124
- let cols = Math.floor((containerWidth + gutterX) / (colWidth + gutterX));
125
- cols = Math.max(1, cols);
217
+ const denom = colWidth + gutterX;
218
+ let cols = denom > 0 ? Math.floor((containerWidth + gutterX) / denom) : 1;
219
+ if (!Number.isFinite(cols) || cols < 1) {
220
+ cols = 1;
221
+ } else if (cols > 1e3) {
222
+ cols = 1e3;
223
+ }
126
224
  if (!options.columnWidth && cols > 1) {
127
225
  colWidth = (containerWidth - (cols - 1) * gutterX) / cols;
128
226
  }
@@ -183,7 +281,10 @@ var Wulf = (() => {
183
281
  }
184
282
  }
185
283
  const itemW = span * colWidth + (span - 1) * gutterX;
186
- const targetX = targetCol * (colWidth + gutterX);
284
+ const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
285
+ const effectiveWidth = fittedWidth !== void 0 ? fittedWidth : containerWidth;
286
+ const rawX = targetCol * (colWidth + gutterX);
287
+ const targetX = isRtl ? Math.max(0, effectiveWidth - rawX - itemW) : rawX;
187
288
  positions.push({
188
289
  element: item,
189
290
  x: targetX,
@@ -250,8 +351,11 @@ var Wulf = (() => {
250
351
  const rawValue = element.getAttribute(attrName)?.trim();
251
352
  if (!rawValue) return false;
252
353
  const doc = element.ownerDocument || document;
354
+ const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
253
355
  const ids = rawValue.split(/\s+/).filter(Boolean);
254
- const isValid = ids.length > 0 && ids.every((id) => Boolean(doc.getElementById(id)));
356
+ const isValid = ids.length > 0 && ids.every(
357
+ (id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
358
+ );
255
359
  if (!isValid) {
256
360
  warnings.push(
257
361
  `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
@@ -263,6 +367,7 @@ var Wulf = (() => {
263
367
 
264
368
  // src/common/LocalizedComponent.ts
265
369
  var LocalizedComponent = class extends AuditableComponent {
370
+ static _i18n;
266
371
  /**
267
372
  * Définit la langue globale du composant (ex: 'fr', 'en', 'es').
268
373
  */
@@ -313,6 +418,10 @@ var Wulf = (() => {
313
418
  static t(key, instanceOverride) {
314
419
  return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
315
420
  }
421
+ /**
422
+ * Surcharges de localisation spécifiques à cette instance.
423
+ */
424
+ i18nOverrides;
316
425
  constructor(i18nOverrides) {
317
426
  super();
318
427
  this.i18nOverrides = i18nOverrides;
@@ -327,35 +436,49 @@ var Wulf = (() => {
327
436
  };
328
437
 
329
438
  // src/common/i18n.ts
439
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
440
+ function isSafeKey(key) {
441
+ return Boolean(key) && !FORBIDDEN_KEYS.has(key);
442
+ }
330
443
  function normalizeLocaleCode(locale) {
331
- return locale.trim().toLowerCase().replace(/_/g, "-");
444
+ const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
445
+ return isSafeKey(norm) ? norm : "";
332
446
  }
333
447
  function getPrimaryLanguage(normalizedLocale) {
334
448
  const dashIndex = normalizedLocale.indexOf("-");
335
- return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
449
+ const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
450
+ return primary && isSafeKey(primary) ? primary : null;
336
451
  }
337
452
  function assignDefined(target, source) {
338
- if (!source) return target;
453
+ if (!source || typeof source !== "object") return target;
339
454
  for (const key of Object.keys(source)) {
340
- if (source[key] !== void 0) {
455
+ if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
341
456
  target[key] = source[key];
342
457
  }
343
458
  }
344
459
  return target;
345
460
  }
346
461
  function createI18nManager(defaultLocale, locales) {
347
- const fallbackLocale = normalizeLocaleCode(defaultLocale);
348
- const initialLocales = {};
462
+ const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
463
+ const initialLocales = /* @__PURE__ */ Object.create(null);
349
464
  for (const [loc, dict] of Object.entries(locales)) {
350
- initialLocales[normalizeLocaleCode(loc)] = { ...dict };
465
+ const norm = normalizeLocaleCode(loc);
466
+ if (norm) {
467
+ initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
468
+ }
351
469
  }
352
470
  let currentLocale = fallbackLocale;
353
- let activeLocales = { ...initialLocales };
354
- let globalOverrides = {};
471
+ let activeLocales = /* @__PURE__ */ Object.create(null);
472
+ for (const [loc, dict] of Object.entries(initialLocales)) {
473
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
474
+ }
475
+ let globalOverrides = /* @__PURE__ */ Object.create(null);
355
476
  function resolveActiveDictionaries() {
356
477
  const dicts = [];
357
- const exact = activeLocales[currentLocale];
358
- if (exact) dicts.push(exact);
478
+ if (isSafeKey(currentLocale)) {
479
+ const exact = activeLocales[currentLocale];
480
+ if (exact) dicts.push(exact);
481
+ }
359
482
  const primary = getPrimaryLanguage(currentLocale);
360
483
  if (primary && activeLocales[primary]) {
361
484
  dicts.push(activeLocales[primary]);
@@ -364,24 +487,33 @@ var Wulf = (() => {
364
487
  }
365
488
  return {
366
489
  setLocale(locale) {
367
- if (locale && locale.trim()) {
368
- currentLocale = normalizeLocaleCode(locale);
490
+ if (locale && typeof locale === "string" && locale.trim()) {
491
+ const norm = normalizeLocaleCode(locale);
492
+ if (norm) {
493
+ currentLocale = norm;
494
+ }
369
495
  }
370
496
  },
371
497
  getLocale() {
372
498
  return currentLocale;
373
499
  },
374
500
  registerLocale(locale, translations) {
375
- if (!locale || !locale.trim() || !translations) return;
501
+ if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
376
502
  const norm = normalizeLocaleCode(locale);
377
- activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
503
+ if (!norm) return;
504
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
505
+ activeLocales[norm] = assignDefined(base, translations);
378
506
  },
379
507
  setI18n(overrides) {
380
- if (!overrides) return;
381
- globalOverrides = assignDefined({ ...globalOverrides }, overrides);
508
+ if (!overrides || typeof overrides !== "object") return;
509
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
510
+ globalOverrides = assignDefined(base, overrides);
382
511
  },
383
512
  t(key, instanceOverride) {
384
- if (instanceOverride && instanceOverride[key] !== void 0) {
513
+ if (!isSafeKey(String(key))) {
514
+ return "";
515
+ }
516
+ if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
385
517
  return String(instanceOverride[key]);
386
518
  }
387
519
  if (globalOverrides[key] !== void 0) {
@@ -412,10 +544,10 @@ var Wulf = (() => {
412
544
  },
413
545
  reset() {
414
546
  currentLocale = fallbackLocale;
415
- globalOverrides = {};
416
- activeLocales = {};
547
+ globalOverrides = /* @__PURE__ */ Object.create(null);
548
+ activeLocales = /* @__PURE__ */ Object.create(null);
417
549
  for (const [loc, dict] of Object.entries(initialLocales)) {
418
- activeLocales[loc] = { ...dict };
550
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
419
551
  }
420
552
  }
421
553
  };
@@ -439,22 +571,35 @@ var Wulf = (() => {
439
571
 
440
572
  // src/masonry/Masonry.ts
441
573
  var Masonry = class extends LocalizedComponent {
574
+ static _i18n = masonryI18n;
575
+ static i18n = masonryI18n;
576
+ root;
577
+ isNativeCSSGrid = false;
578
+ _items = [];
579
+ options;
580
+ resizeObserver = null;
581
+ itemResizeObserver = null;
582
+ observedItems = /* @__PURE__ */ new Set();
583
+ observedItemHeights = /* @__PURE__ */ new WeakMap();
584
+ removingItems = /* @__PURE__ */ new WeakSet();
585
+ layoutRafId = null;
586
+ isDestroyed = false;
587
+ wasRoleInferred = false;
588
+ wasAriaLabelInferred = false;
589
+ hasExplicitAriaLabel = false;
590
+ lastInferredAriaLabel = "";
591
+ abortController = new AbortController();
592
+ watchedImages = /* @__PURE__ */ new WeakSet();
593
+ originalContainerStyles;
442
594
  constructor(target, options = {}) {
443
595
  super(options.i18n);
444
- this.isNativeCSSGrid = false;
445
- this._items = [];
446
- this.resizeObserver = null;
447
- this.itemResizeObserver = null;
448
- this.layoutRafId = null;
449
- this.isDestroyed = false;
450
- this.wasRoleInferred = false;
451
- this.wasAriaLabelInferred = false;
452
- this.hasExplicitAriaLabel = false;
453
- this.lastInferredAriaLabel = "";
454
- this.removeTimers = /* @__PURE__ */ new Set();
455
- this.pendingImageListeners = [];
456
596
  if (typeof target === "string") {
457
- const el = document.querySelector(target);
597
+ let el = null;
598
+ try {
599
+ el = document.querySelector(target);
600
+ } catch {
601
+ el = null;
602
+ }
458
603
  if (!el) {
459
604
  throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${target}"`);
460
605
  }
@@ -490,10 +635,11 @@ var Wulf = (() => {
490
635
  }),
491
636
  audit: options.audit ?? true
492
637
  };
493
- const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
638
+ const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && (CSS.supports("display", "grid-lanes") || CSS.supports("grid-template-rows", "masonry"));
494
639
  if (this.options.useNativeCSSGrid && supportsNativeCSS) {
495
640
  this.isNativeCSSGrid = true;
496
641
  this.root.classList.add("wulf-masonry", "wulf-masonry--native");
642
+ this.syncNativeGridVariables();
497
643
  } else {
498
644
  this.root.classList.add("wulf-masonry");
499
645
  }
@@ -517,7 +663,7 @@ var Wulf = (() => {
517
663
  this.wasRoleInferred = true;
518
664
  }
519
665
  const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("gallery");
520
- if (label && !this.root.hasAttribute("aria-label")) {
666
+ if (label && !this.root.hasAttribute("aria-label") && !this.root.hasAttribute("aria-labelledby")) {
521
667
  this.root.setAttribute("aria-label", label);
522
668
  this.lastInferredAriaLabel = label;
523
669
  this.wasAriaLabelInferred = true;
@@ -542,7 +688,12 @@ var Wulf = (() => {
542
688
  */
543
689
  applyTransitionDuration() {
544
690
  const dur = this.options.transitionDuration;
545
- const durValue = typeof dur === "number" ? `${dur}ms` : dur;
691
+ let durValue = "300ms";
692
+ if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
693
+ durValue = `${dur}ms`;
694
+ } else if (typeof dur === "string" && /^\s*(?:\d+(?:\.\d+)?|\.\d+)(ms|s)\s*$/i.test(dur)) {
695
+ durValue = dur.trim();
696
+ }
546
697
  this.root.style.setProperty("--wulf-masonry-duration", durValue);
547
698
  }
548
699
  /**
@@ -553,24 +704,37 @@ var Wulf = (() => {
553
704
  let matched = [];
554
705
  if (this.options.itemSelector === "> *") {
555
706
  matched = Array.from(this.root.children).filter(
556
- (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
707
+ (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
557
708
  );
558
709
  } else {
559
710
  try {
560
- matched = Array.from(this.root.querySelectorAll(this.options.itemSelector)).filter(
561
- (el) => el.parentElement === this.root && !el.hasAttribute("data-masonry-ignore")
711
+ const rawSelector = this.options.itemSelector.trim();
712
+ const selector = rawSelector.startsWith(">") ? `:scope ${rawSelector}` : rawSelector;
713
+ matched = Array.from(this.root.querySelectorAll(selector)).filter(
714
+ (el) => el.parentElement === this.root && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
562
715
  );
563
716
  } catch {
564
717
  matched = Array.from(this.root.children).filter(
565
- (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
718
+ (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
566
719
  );
567
720
  }
568
721
  }
722
+ if (this.itemResizeObserver) {
723
+ const nextSet = new Set(matched);
724
+ for (const prevEl of this.observedItems) {
725
+ if (!nextSet.has(prevEl)) {
726
+ this.itemResizeObserver.unobserve(prevEl);
727
+ this.observedItems.delete(prevEl);
728
+ this.observedItemHeights.delete(prevEl);
729
+ }
730
+ }
731
+ }
569
732
  this._items = matched;
570
733
  for (const item of this._items) {
571
734
  item.classList.add("wulf-masonry-item");
572
- if (this.itemResizeObserver) {
735
+ if (this.itemResizeObserver && !this.observedItems.has(item)) {
573
736
  this.itemResizeObserver.observe(item);
737
+ this.observedItems.add(item);
574
738
  }
575
739
  }
576
740
  }
@@ -590,11 +754,52 @@ var Wulf = (() => {
590
754
  }
591
755
  });
592
756
  this.resizeObserver.observe(this.root);
593
- this.itemResizeObserver = new ResizeObserver(() => {
594
- this.scheduleLayout();
757
+ this.itemResizeObserver = new ResizeObserver((entries) => {
758
+ let heightChanged = false;
759
+ for (const entry of entries) {
760
+ const newH = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;
761
+ const prevH = this.observedItemHeights.get(entry.target);
762
+ if (prevH === void 0 || Math.abs(newH - prevH) >= 1) {
763
+ this.observedItemHeights.set(entry.target, newH);
764
+ if (prevH !== void 0) {
765
+ heightChanged = true;
766
+ }
767
+ }
768
+ }
769
+ if (heightChanged) {
770
+ this.scheduleLayout();
771
+ }
595
772
  });
596
773
  for (const item of this._items) {
597
774
  this.itemResizeObserver.observe(item);
775
+ this.observedItems.add(item);
776
+ }
777
+ }
778
+ /**
779
+ * Synchronise les variables CSS du mode natif CSS Grid Level 3 depuis les options JS.
780
+ */
781
+ syncNativeGridVariables() {
782
+ const { x: gutterX, y: gutterY } = LayoutEngine.parseGutter(this.options.gutter);
783
+ this.root.style.setProperty("--wulf-masonry-gutter-x", `${gutterX}px`);
784
+ this.root.style.setProperty("--wulf-masonry-gutter-y", `${gutterY}px`);
785
+ if (typeof this.options.columnWidth === "number" && Number.isFinite(this.options.columnWidth) && this.options.columnWidth > 0) {
786
+ this.root.style.setProperty("--wulf-masonry-col-min", `${this.options.columnWidth}px`);
787
+ } else if (this.options.columnWidth instanceof HTMLElement) {
788
+ const w = this.options.columnWidth.getBoundingClientRect().width;
789
+ if (w > 0) {
790
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
791
+ }
792
+ } else if (typeof this.options.columnWidth === "string" && this.options.columnWidth.trim()) {
793
+ try {
794
+ const el = this.root.querySelector(this.options.columnWidth);
795
+ if (el) {
796
+ const w = el.getBoundingClientRect().width;
797
+ if (w > 0) {
798
+ this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
799
+ }
800
+ }
801
+ } catch {
802
+ }
598
803
  }
599
804
  }
600
805
  /**
@@ -604,14 +809,12 @@ var Wulf = (() => {
604
809
  if (!this.options.autoImages) return;
605
810
  const images = Array.from(this.root.querySelectorAll("img"));
606
811
  for (const img of images) {
607
- if (!img.complete) {
812
+ if (!img.complete && !this.watchedImages.has(img)) {
813
+ this.watchedImages.add(img);
608
814
  const attachLoadListener = () => {
609
- const onLoad = () => {
610
- this.pendingImageListeners = this.pendingImageListeners.filter((l) => l.handler !== onLoad);
815
+ img.addEventListener("load", () => {
611
816
  if (!this.isDestroyed) this.scheduleLayout();
612
- };
613
- this.pendingImageListeners.push({ img, handler: onLoad });
614
- img.addEventListener("load", onLoad, { once: true });
817
+ }, { once: true, signal: this.abortController.signal });
615
818
  };
616
819
  if (typeof img.decode === "function") {
617
820
  img.decode().then(() => {
@@ -645,10 +848,17 @@ var Wulf = (() => {
645
848
  if (this.isDestroyed) return;
646
849
  this.syncAccessibilityLabels();
647
850
  if (this.isNativeCSSGrid) {
851
+ this.syncNativeGridVariables();
852
+ for (const el of this._items) {
853
+ el.classList.remove("wulf-masonry-item--hidden");
854
+ }
648
855
  this.options.onLayout([]);
649
856
  return;
650
857
  }
651
858
  this.root.setAttribute("aria-busy", "true");
859
+ if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
860
+ this.root.style.width = "";
861
+ }
652
862
  const result = LayoutEngine.calculate(this.root, this._items, this.options);
653
863
  this.root.style.height = `${result.containerHeight}px`;
654
864
  if (this.options.fitWidth && result.fittedWidth !== void 0) {
@@ -658,6 +868,14 @@ var Wulf = (() => {
658
868
  this.root.classList.remove("wulf-masonry--fit-width");
659
869
  }
660
870
  const stagger = this.options.stagger;
871
+ const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
872
+ if (validStagger) {
873
+ this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
874
+ } else {
875
+ this.root.style.removeProperty("--wulf-masonry-stagger");
876
+ }
877
+ const hasIgnoredChildren = this._items.length !== this.root.children.length;
878
+ const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
661
879
  const usePercent = this.options.percentPosition && result.containerWidth > 0;
662
880
  for (let i = 0; i < result.positions.length; i++) {
663
881
  const pos = result.positions[i];
@@ -670,12 +888,13 @@ var Wulf = (() => {
670
888
  }
671
889
  item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
672
890
  item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
673
- if (stagger > 0) {
674
- item.style.transitionDelay = `${i * stagger}ms`;
891
+ if (validStagger && !supportsSiblingIndex) {
892
+ item.style.setProperty("--wulf-masonry-index", String(i));
675
893
  } else {
676
- item.style.removeProperty("transition-delay");
894
+ item.style.removeProperty("--wulf-masonry-index");
677
895
  }
678
896
  item.classList.remove("wulf-masonry-item--hidden");
897
+ this.observedItemHeights.set(item, pos.height);
679
898
  this.options.onItemPlaced(item, pos);
680
899
  }
681
900
  this.root.setAttribute("aria-busy", "false");
@@ -690,7 +909,11 @@ var Wulf = (() => {
690
909
  if (list.length === 0) return;
691
910
  const frag = document.createDocumentFragment();
692
911
  for (const el of list) {
693
- el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
912
+ if (this.isNativeCSSGrid) {
913
+ el.classList.add("wulf-masonry-item");
914
+ } else {
915
+ el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
916
+ }
694
917
  frag.appendChild(el);
695
918
  }
696
919
  this.root.appendChild(frag);
@@ -708,7 +931,11 @@ var Wulf = (() => {
708
931
  const first = this.root.firstChild;
709
932
  const frag = document.createDocumentFragment();
710
933
  for (const el of list) {
711
- el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
934
+ if (this.isNativeCSSGrid) {
935
+ el.classList.add("wulf-masonry-item");
936
+ } else {
937
+ el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
938
+ }
712
939
  frag.appendChild(el);
713
940
  }
714
941
  this.root.insertBefore(frag, first);
@@ -717,44 +944,51 @@ var Wulf = (() => {
717
944
  this.layout();
718
945
  }
719
946
  /**
720
- * Supprime des éléments avec animation de fondu/sortie.
947
+ * Supprime des éléments avec animation de fondu/sortie synchronisée via Web Animations API.
721
948
  */
722
949
  remove(elements) {
723
950
  if (this.isDestroyed) return;
724
951
  const list = Array.isArray(elements) ? elements : [elements];
725
952
  if (list.length === 0) return;
726
- for (const el of list) {
727
- el.classList.add("wulf-masonry-item--hidden");
728
- }
729
- const dur = typeof this.options.transitionDuration === "number" ? this.options.transitionDuration : 300;
730
- if (dur <= 0) {
953
+ const finalizeRemoval = () => {
954
+ if (this.isDestroyed) return;
731
955
  for (const el of list) {
956
+ this.removingItems.delete(el);
732
957
  if (el.parentElement === this.root) {
733
958
  if (this.itemResizeObserver) {
734
959
  this.itemResizeObserver.unobserve(el);
960
+ this.observedItems.delete(el);
961
+ this.observedItemHeights.delete(el);
735
962
  }
736
963
  this.root.removeChild(el);
737
964
  }
738
965
  }
739
966
  this.reloadItems();
740
967
  this.layout();
968
+ };
969
+ for (const el of list) {
970
+ this.removingItems.add(el);
971
+ if (typeof document !== "undefined" && document.activeElement && el.contains(document.activeElement)) {
972
+ document.activeElement.blur?.();
973
+ }
974
+ el.setAttribute("inert", "");
975
+ el.style.transitionDelay = "0ms";
976
+ el.classList.add("wulf-masonry-item--hidden");
977
+ }
978
+ const dur = parseCssDurationMs(this.options.transitionDuration, 300);
979
+ if (dur <= 0 || this.isNativeCSSGrid) {
980
+ finalizeRemoval();
741
981
  return;
742
982
  }
743
- const timerId = window.setTimeout(() => {
744
- this.removeTimers.delete(timerId);
745
- if (this.isDestroyed) return;
746
- for (const el of list) {
747
- if (el.parentElement === this.root) {
748
- if (this.itemResizeObserver) {
749
- this.itemResizeObserver.unobserve(el);
750
- }
751
- this.root.removeChild(el);
752
- }
983
+ this.reloadItems();
984
+ this.layout();
985
+ Promise.all(
986
+ list.map((el) => waitForAnimations(el, dur, this.abortController.signal))
987
+ ).then(() => {
988
+ if (!this.abortController.signal.aborted) {
989
+ finalizeRemoval();
753
990
  }
754
- this.reloadItems();
755
- this.layout();
756
- }, dur);
757
- this.removeTimers.add(timerId);
991
+ });
758
992
  }
759
993
  /**
760
994
  * Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
@@ -791,14 +1025,7 @@ var Wulf = (() => {
791
1025
  destroy() {
792
1026
  if (this.isDestroyed) return;
793
1027
  this.isDestroyed = true;
794
- for (const timerId of this.removeTimers) {
795
- clearTimeout(timerId);
796
- }
797
- this.removeTimers.clear();
798
- for (const { img, handler } of this.pendingImageListeners) {
799
- img.removeEventListener("load", handler);
800
- }
801
- this.pendingImageListeners = [];
1028
+ this.abortController.abort();
802
1029
  if (this.layoutRafId !== null) {
803
1030
  cancelAnimationFrame(this.layoutRafId);
804
1031
  this.layoutRafId = null;
@@ -820,6 +1047,10 @@ var Wulf = (() => {
820
1047
  this.root.removeAttribute("aria-label");
821
1048
  }
822
1049
  this.root.style.removeProperty("--wulf-masonry-duration");
1050
+ this.root.style.removeProperty("--wulf-masonry-stagger");
1051
+ this.root.style.removeProperty("--wulf-masonry-col-min");
1052
+ this.root.style.removeProperty("--wulf-masonry-gutter-x");
1053
+ this.root.style.removeProperty("--wulf-masonry-gutter-y");
823
1054
  if (this.originalContainerStyles.height) {
824
1055
  this.root.style.height = this.originalContainerStyles.height;
825
1056
  } else {
@@ -835,20 +1066,16 @@ var Wulf = (() => {
835
1066
  item.style.removeProperty("--wulf-masonry-w");
836
1067
  item.style.removeProperty("--wulf-masonry-x");
837
1068
  item.style.removeProperty("--wulf-masonry-y");
838
- item.style.removeProperty("transition-delay");
1069
+ item.style.removeProperty("--wulf-masonry-index");
839
1070
  }
840
1071
  this._items = [];
841
1072
  }
842
1073
  };
843
- Masonry._i18n = masonryI18n;
844
- Masonry.i18n = masonryI18n;
845
1074
 
846
1075
  // src/masonry/index.ts
847
1076
  var index_default = Masonry;
848
- if (typeof window !== "undefined") {
849
- const win = window;
850
- const wulfNamespace = win.Wulf || {};
851
- win.Wulf = wulfNamespace;
1077
+ var wulfNamespace = getSafeWulfNamespace();
1078
+ if (wulfNamespace) {
852
1079
  wulfNamespace.Masonry = Object.assign(Masonry, {
853
1080
  Masonry,
854
1081
  LayoutEngine,
@@ -857,5 +1084,5 @@ var Wulf = (() => {
857
1084
  }
858
1085
  return __toCommonJS(index_exports);
859
1086
  })();
860
- if (typeof window !== "undefined") { window.Wulf = window.Wulf || {}; if (typeof Wulf !== "undefined" && Wulf) { var targets = ["Mask", "Scroll", "Masonry", "Toast", "FocusTrap", "Shortcut"]; for (var i = 0; i < targets.length; i++) { var t = targets[i]; if (Wulf[t] && window.Wulf[t] !== Wulf[t]) { try { Object.defineProperty(window.Wulf, t, { value: Wulf[t], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[t] = Wulf[t]; } catch (__) {} } } } for (var k in Wulf) { if (window.Wulf[k] === undefined) { try { Object.defineProperty(window.Wulf, k, { value: Wulf[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { window.Wulf[k] = Wulf[k]; } catch (__) {} } } } } }
1087
+ 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 (__) {} } } } } }
861
1088
  //# sourceMappingURL=masonry.global.js.map