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.
- package/README.md +124 -78
- package/changelog.md +105 -0
- package/dist/focus-trap.esm.js +245 -126
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +247 -128
- package/dist/focus-trap.global.js.map +3 -3
- package/dist/focus-trap.global.min.js +4 -4
- package/dist/focus-trap.global.min.js.map +4 -4
- package/dist/index.esm.js +2434 -905
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2436 -907
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +4 -4
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.css +1 -1
- package/dist/mask.css.map +2 -2
- package/dist/mask.esm.js +746 -346
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +748 -348
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +4 -4
- package/dist/mask.global.min.js.map +4 -4
- package/dist/mask.layered.css +1 -0
- package/dist/mask.layered.css.map +7 -0
- package/dist/masonry.css +1 -1
- package/dist/masonry.css.map +2 -2
- package/dist/masonry.esm.js +341 -114
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +343 -116
- package/dist/masonry.global.js.map +3 -3
- package/dist/masonry.global.min.js +4 -4
- package/dist/masonry.global.min.js.map +4 -4
- package/dist/masonry.layered.css +1 -0
- package/dist/masonry.layered.css.map +7 -0
- package/dist/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +524 -153
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +526 -155
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +4 -4
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -0
- package/dist/scroll.layered.css.map +7 -0
- package/dist/shortcut.esm.js +209 -46
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +211 -48
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +2 -2
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +590 -160
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +592 -162
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +4 -4
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -0
- package/dist/toast.layered.css.map +7 -0
- package/dist/types/common/dom.d.ts +38 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +15 -5
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/AmountEngine.d.ts +1 -0
- package/dist/types/mask/BaseInputMask.d.ts +24 -0
- package/dist/types/mask/InputAmountMask.d.ts +3 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- package/dist/types/mask/InputMask.d.ts +1 -0
- package/dist/types/mask/MaskEngine.d.ts +4 -0
- package/dist/types/masonry/Masonry.d.ts +10 -3
- package/dist/types/scroll/ScrollBlock.d.ts +31 -3
- package/dist/types/scroll/types.d.ts +13 -1
- package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +5 -0
- package/dist/types/toast/Toast.d.ts +4 -0
- package/dist/types/toast/ToastInstance.d.ts +22 -10
- package/dist/types/toast/ToastManager.d.ts +37 -4
- package/dist/types/toast/i18n/types.d.ts +2 -0
- package/dist/types/toast/types.d.ts +14 -2
- package/package.json +20 -5
package/dist/masonry.esm.js
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
+
// src/common/dom.ts
|
|
2
|
+
function getSafeWulfNamespace() {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const win = window;
|
|
5
|
+
const existing = win.Wulf;
|
|
6
|
+
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
7
|
+
const fresh = {};
|
|
8
|
+
win.Wulf = fresh;
|
|
9
|
+
return fresh;
|
|
10
|
+
}
|
|
11
|
+
return existing;
|
|
12
|
+
}
|
|
13
|
+
function parseCssDurationMs(duration, fallbackMs = 300, maxMs = 6e4) {
|
|
14
|
+
const safeFallback = Number.isFinite(fallbackMs) && fallbackMs >= 0 ? Math.min(fallbackMs, maxMs) : 300;
|
|
15
|
+
if (typeof duration === "number") {
|
|
16
|
+
return Number.isFinite(duration) && duration >= 0 ? Math.min(duration, maxMs) : safeFallback;
|
|
17
|
+
}
|
|
18
|
+
if (typeof duration === "string") {
|
|
19
|
+
const parts = duration.split(",");
|
|
20
|
+
let maxParsed = -1;
|
|
21
|
+
for (const part of parts) {
|
|
22
|
+
const match = /^\+?(\d+(?:\.\d+)?|\.\d+)(ms|s)?$/i.exec(part.trim());
|
|
23
|
+
if (match) {
|
|
24
|
+
const raw = parseFloat(match[1]);
|
|
25
|
+
if (Number.isFinite(raw) && raw >= 0) {
|
|
26
|
+
const ms = match[2]?.toLowerCase() === "s" ? raw * 1e3 : raw;
|
|
27
|
+
if (ms > maxParsed) {
|
|
28
|
+
maxParsed = ms;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (maxParsed >= 0) {
|
|
34
|
+
return Math.min(maxParsed, maxMs);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return safeFallback;
|
|
38
|
+
}
|
|
39
|
+
function prefersReducedMotion() {
|
|
40
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
41
|
+
}
|
|
42
|
+
function waitForAnimations(element, fallbackMs, signal) {
|
|
43
|
+
const safeFallback = Number.isFinite(fallbackMs) ? Math.min(fallbackMs, 6e4) : 300;
|
|
44
|
+
if (signal?.aborted || safeFallback <= 0 || prefersReducedMotion()) {
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
const animations = typeof element.getAnimations === "function" ? element.getAnimations().filter((a) => {
|
|
48
|
+
if (a.playState !== "running") return false;
|
|
49
|
+
const timing = a.effect?.getComputedTiming?.();
|
|
50
|
+
return timing ? Number.isFinite(timing.endTime) : true;
|
|
51
|
+
}) : [];
|
|
52
|
+
if (animations.length === 0) {
|
|
53
|
+
return Promise.resolve();
|
|
54
|
+
}
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
let settled = false;
|
|
57
|
+
let timerId = null;
|
|
58
|
+
const finish = () => {
|
|
59
|
+
if (settled) return;
|
|
60
|
+
settled = true;
|
|
61
|
+
if (timerId !== null) {
|
|
62
|
+
clearTimeout(timerId);
|
|
63
|
+
timerId = null;
|
|
64
|
+
}
|
|
65
|
+
signal?.removeEventListener("abort", finish);
|
|
66
|
+
resolve();
|
|
67
|
+
};
|
|
68
|
+
signal?.addEventListener("abort", finish, { once: true });
|
|
69
|
+
timerId = setTimeout(finish, safeFallback);
|
|
70
|
+
Promise.allSettled(animations.map((a) => a.finished)).then(finish);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
1
74
|
// src/masonry/LayoutEngine.ts
|
|
2
75
|
var LayoutEngine = class {
|
|
3
76
|
/**
|
|
@@ -5,12 +78,15 @@ var LayoutEngine = class {
|
|
|
5
78
|
*/
|
|
6
79
|
static parseGutter(gutterOption) {
|
|
7
80
|
if (typeof gutterOption === "number") {
|
|
8
|
-
|
|
81
|
+
const v = Number.isFinite(gutterOption) ? Math.max(0, gutterOption) : 0;
|
|
82
|
+
return { x: v, y: v };
|
|
9
83
|
}
|
|
10
84
|
if (gutterOption && typeof gutterOption === "object") {
|
|
85
|
+
const rawX = Number(gutterOption.x);
|
|
86
|
+
const rawY = Number(gutterOption.y);
|
|
11
87
|
return {
|
|
12
|
-
x: Math.max(0,
|
|
13
|
-
y: Math.max(0,
|
|
88
|
+
x: Number.isFinite(rawX) ? Math.max(0, rawX) : 0,
|
|
89
|
+
y: Number.isFinite(rawY) ? Math.max(0, rawY) : 0
|
|
14
90
|
};
|
|
15
91
|
}
|
|
16
92
|
return { x: 0, y: 0 };
|
|
@@ -19,22 +95,37 @@ var LayoutEngine = class {
|
|
|
19
95
|
* Résout la largeur effective d'une colonne en pixels.
|
|
20
96
|
*/
|
|
21
97
|
static resolveColumnWidth(container, firstItem, columnWidthOption) {
|
|
22
|
-
if (typeof columnWidthOption === "number" && columnWidthOption > 0) {
|
|
98
|
+
if (typeof columnWidthOption === "number" && Number.isFinite(columnWidthOption) && columnWidthOption > 0) {
|
|
23
99
|
return columnWidthOption;
|
|
24
100
|
}
|
|
25
101
|
if (typeof columnWidthOption === "string") {
|
|
26
|
-
const
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
102
|
+
const trimmed = columnWidthOption.trim();
|
|
103
|
+
if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
|
|
104
|
+
const parsed = parseFloat(trimmed);
|
|
105
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
106
|
+
if (trimmed.endsWith("%")) {
|
|
107
|
+
const containerW2 = container.getBoundingClientRect().width;
|
|
108
|
+
const resolvedPct = containerW2 * parsed / 100;
|
|
109
|
+
if (resolvedPct > 0) return resolvedPct;
|
|
110
|
+
} else {
|
|
111
|
+
return parsed;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else if (trimmed) {
|
|
115
|
+
let el = null;
|
|
116
|
+
try {
|
|
117
|
+
el = container.querySelector(trimmed);
|
|
118
|
+
} catch {
|
|
119
|
+
el = null;
|
|
120
|
+
}
|
|
121
|
+
if (el) {
|
|
122
|
+
const w = el.getBoundingClientRect().width;
|
|
123
|
+
if (Number.isFinite(w) && w > 0) return w;
|
|
124
|
+
}
|
|
125
|
+
const parsed = parseFloat(trimmed);
|
|
126
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
127
|
+
return parsed;
|
|
36
128
|
}
|
|
37
|
-
return parsed;
|
|
38
129
|
}
|
|
39
130
|
}
|
|
40
131
|
if (columnWidthOption instanceof HTMLElement) {
|
|
@@ -59,11 +150,13 @@ var LayoutEngine = class {
|
|
|
59
150
|
return Math.min(maxCols, parsed);
|
|
60
151
|
}
|
|
61
152
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
153
|
+
for (const cls of item.classList) {
|
|
154
|
+
const match = /^(?:span|col-span)-(\d+)$/.exec(cls);
|
|
155
|
+
if (match && match[1]) {
|
|
156
|
+
const parsed = parseInt(match[1], 10);
|
|
157
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
158
|
+
return Math.min(maxCols, parsed);
|
|
159
|
+
}
|
|
67
160
|
}
|
|
68
161
|
}
|
|
69
162
|
return 1;
|
|
@@ -88,8 +181,13 @@ var LayoutEngine = class {
|
|
|
88
181
|
}
|
|
89
182
|
const firstItem = items[0] || null;
|
|
90
183
|
let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);
|
|
91
|
-
|
|
92
|
-
cols = Math.
|
|
184
|
+
const denom = colWidth + gutterX;
|
|
185
|
+
let cols = denom > 0 ? Math.floor((containerWidth + gutterX) / denom) : 1;
|
|
186
|
+
if (!Number.isFinite(cols) || cols < 1) {
|
|
187
|
+
cols = 1;
|
|
188
|
+
} else if (cols > 1e3) {
|
|
189
|
+
cols = 1e3;
|
|
190
|
+
}
|
|
93
191
|
if (!options.columnWidth && cols > 1) {
|
|
94
192
|
colWidth = (containerWidth - (cols - 1) * gutterX) / cols;
|
|
95
193
|
}
|
|
@@ -150,7 +248,10 @@ var LayoutEngine = class {
|
|
|
150
248
|
}
|
|
151
249
|
}
|
|
152
250
|
const itemW = span * colWidth + (span - 1) * gutterX;
|
|
153
|
-
const
|
|
251
|
+
const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
|
|
252
|
+
const effectiveWidth = fittedWidth !== void 0 ? fittedWidth : containerWidth;
|
|
253
|
+
const rawX = targetCol * (colWidth + gutterX);
|
|
254
|
+
const targetX = isRtl ? Math.max(0, effectiveWidth - rawX - itemW) : rawX;
|
|
154
255
|
positions.push({
|
|
155
256
|
element: item,
|
|
156
257
|
x: targetX,
|
|
@@ -217,8 +318,11 @@ var AuditableComponent = class {
|
|
|
217
318
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
218
319
|
if (!rawValue) return false;
|
|
219
320
|
const doc = element.ownerDocument || document;
|
|
321
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
220
322
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
221
|
-
const isValid = ids.length > 0 && ids.every(
|
|
323
|
+
const isValid = ids.length > 0 && ids.every(
|
|
324
|
+
(id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
|
|
325
|
+
);
|
|
222
326
|
if (!isValid) {
|
|
223
327
|
warnings.push(
|
|
224
328
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -230,6 +334,7 @@ var AuditableComponent = class {
|
|
|
230
334
|
|
|
231
335
|
// src/common/LocalizedComponent.ts
|
|
232
336
|
var LocalizedComponent = class extends AuditableComponent {
|
|
337
|
+
static _i18n;
|
|
233
338
|
/**
|
|
234
339
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
235
340
|
*/
|
|
@@ -280,6 +385,10 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
280
385
|
static t(key, instanceOverride) {
|
|
281
386
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
282
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Surcharges de localisation spécifiques à cette instance.
|
|
390
|
+
*/
|
|
391
|
+
i18nOverrides;
|
|
283
392
|
constructor(i18nOverrides) {
|
|
284
393
|
super();
|
|
285
394
|
this.i18nOverrides = i18nOverrides;
|
|
@@ -294,35 +403,49 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
294
403
|
};
|
|
295
404
|
|
|
296
405
|
// src/common/i18n.ts
|
|
406
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
407
|
+
function isSafeKey(key) {
|
|
408
|
+
return Boolean(key) && !FORBIDDEN_KEYS.has(key);
|
|
409
|
+
}
|
|
297
410
|
function normalizeLocaleCode(locale) {
|
|
298
|
-
|
|
411
|
+
const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
412
|
+
return isSafeKey(norm) ? norm : "";
|
|
299
413
|
}
|
|
300
414
|
function getPrimaryLanguage(normalizedLocale) {
|
|
301
415
|
const dashIndex = normalizedLocale.indexOf("-");
|
|
302
|
-
|
|
416
|
+
const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
417
|
+
return primary && isSafeKey(primary) ? primary : null;
|
|
303
418
|
}
|
|
304
419
|
function assignDefined(target, source) {
|
|
305
|
-
if (!source) return target;
|
|
420
|
+
if (!source || typeof source !== "object") return target;
|
|
306
421
|
for (const key of Object.keys(source)) {
|
|
307
|
-
if (source[key] !== void 0) {
|
|
422
|
+
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
308
423
|
target[key] = source[key];
|
|
309
424
|
}
|
|
310
425
|
}
|
|
311
426
|
return target;
|
|
312
427
|
}
|
|
313
428
|
function createI18nManager(defaultLocale, locales) {
|
|
314
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
315
|
-
const initialLocales =
|
|
429
|
+
const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
|
|
430
|
+
const initialLocales = /* @__PURE__ */ Object.create(null);
|
|
316
431
|
for (const [loc, dict] of Object.entries(locales)) {
|
|
317
|
-
|
|
432
|
+
const norm = normalizeLocaleCode(loc);
|
|
433
|
+
if (norm) {
|
|
434
|
+
initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
435
|
+
}
|
|
318
436
|
}
|
|
319
437
|
let currentLocale = fallbackLocale;
|
|
320
|
-
let activeLocales =
|
|
321
|
-
|
|
438
|
+
let activeLocales = /* @__PURE__ */ Object.create(null);
|
|
439
|
+
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
440
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
441
|
+
}
|
|
442
|
+
let globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
322
443
|
function resolveActiveDictionaries() {
|
|
323
444
|
const dicts = [];
|
|
324
|
-
|
|
325
|
-
|
|
445
|
+
if (isSafeKey(currentLocale)) {
|
|
446
|
+
const exact = activeLocales[currentLocale];
|
|
447
|
+
if (exact) dicts.push(exact);
|
|
448
|
+
}
|
|
326
449
|
const primary = getPrimaryLanguage(currentLocale);
|
|
327
450
|
if (primary && activeLocales[primary]) {
|
|
328
451
|
dicts.push(activeLocales[primary]);
|
|
@@ -331,24 +454,33 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
331
454
|
}
|
|
332
455
|
return {
|
|
333
456
|
setLocale(locale) {
|
|
334
|
-
if (locale && locale.trim()) {
|
|
335
|
-
|
|
457
|
+
if (locale && typeof locale === "string" && locale.trim()) {
|
|
458
|
+
const norm = normalizeLocaleCode(locale);
|
|
459
|
+
if (norm) {
|
|
460
|
+
currentLocale = norm;
|
|
461
|
+
}
|
|
336
462
|
}
|
|
337
463
|
},
|
|
338
464
|
getLocale() {
|
|
339
465
|
return currentLocale;
|
|
340
466
|
},
|
|
341
467
|
registerLocale(locale, translations) {
|
|
342
|
-
if (!locale || !locale.trim() || !translations) return;
|
|
468
|
+
if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
|
|
343
469
|
const norm = normalizeLocaleCode(locale);
|
|
344
|
-
|
|
470
|
+
if (!norm) return;
|
|
471
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
|
|
472
|
+
activeLocales[norm] = assignDefined(base, translations);
|
|
345
473
|
},
|
|
346
474
|
setI18n(overrides) {
|
|
347
|
-
if (!overrides) return;
|
|
348
|
-
|
|
475
|
+
if (!overrides || typeof overrides !== "object") return;
|
|
476
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
|
|
477
|
+
globalOverrides = assignDefined(base, overrides);
|
|
349
478
|
},
|
|
350
479
|
t(key, instanceOverride) {
|
|
351
|
-
if (
|
|
480
|
+
if (!isSafeKey(String(key))) {
|
|
481
|
+
return "";
|
|
482
|
+
}
|
|
483
|
+
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
352
484
|
return String(instanceOverride[key]);
|
|
353
485
|
}
|
|
354
486
|
if (globalOverrides[key] !== void 0) {
|
|
@@ -379,10 +511,10 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
379
511
|
},
|
|
380
512
|
reset() {
|
|
381
513
|
currentLocale = fallbackLocale;
|
|
382
|
-
globalOverrides =
|
|
383
|
-
activeLocales =
|
|
514
|
+
globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
515
|
+
activeLocales = /* @__PURE__ */ Object.create(null);
|
|
384
516
|
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
385
|
-
activeLocales[loc] =
|
|
517
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
386
518
|
}
|
|
387
519
|
}
|
|
388
520
|
};
|
|
@@ -406,22 +538,35 @@ var masonryI18n = createI18nManager("fr", {
|
|
|
406
538
|
|
|
407
539
|
// src/masonry/Masonry.ts
|
|
408
540
|
var Masonry = class extends LocalizedComponent {
|
|
541
|
+
static _i18n = masonryI18n;
|
|
542
|
+
static i18n = masonryI18n;
|
|
543
|
+
root;
|
|
544
|
+
isNativeCSSGrid = false;
|
|
545
|
+
_items = [];
|
|
546
|
+
options;
|
|
547
|
+
resizeObserver = null;
|
|
548
|
+
itemResizeObserver = null;
|
|
549
|
+
observedItems = /* @__PURE__ */ new Set();
|
|
550
|
+
observedItemHeights = /* @__PURE__ */ new WeakMap();
|
|
551
|
+
removingItems = /* @__PURE__ */ new WeakSet();
|
|
552
|
+
layoutRafId = null;
|
|
553
|
+
isDestroyed = false;
|
|
554
|
+
wasRoleInferred = false;
|
|
555
|
+
wasAriaLabelInferred = false;
|
|
556
|
+
hasExplicitAriaLabel = false;
|
|
557
|
+
lastInferredAriaLabel = "";
|
|
558
|
+
abortController = new AbortController();
|
|
559
|
+
watchedImages = /* @__PURE__ */ new WeakSet();
|
|
560
|
+
originalContainerStyles;
|
|
409
561
|
constructor(target, options = {}) {
|
|
410
562
|
super(options.i18n);
|
|
411
|
-
this.isNativeCSSGrid = false;
|
|
412
|
-
this._items = [];
|
|
413
|
-
this.resizeObserver = null;
|
|
414
|
-
this.itemResizeObserver = null;
|
|
415
|
-
this.layoutRafId = null;
|
|
416
|
-
this.isDestroyed = false;
|
|
417
|
-
this.wasRoleInferred = false;
|
|
418
|
-
this.wasAriaLabelInferred = false;
|
|
419
|
-
this.hasExplicitAriaLabel = false;
|
|
420
|
-
this.lastInferredAriaLabel = "";
|
|
421
|
-
this.removeTimers = /* @__PURE__ */ new Set();
|
|
422
|
-
this.pendingImageListeners = [];
|
|
423
563
|
if (typeof target === "string") {
|
|
424
|
-
|
|
564
|
+
let el = null;
|
|
565
|
+
try {
|
|
566
|
+
el = document.querySelector(target);
|
|
567
|
+
} catch {
|
|
568
|
+
el = null;
|
|
569
|
+
}
|
|
425
570
|
if (!el) {
|
|
426
571
|
throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${target}"`);
|
|
427
572
|
}
|
|
@@ -457,10 +602,11 @@ var Masonry = class extends LocalizedComponent {
|
|
|
457
602
|
}),
|
|
458
603
|
audit: options.audit ?? true
|
|
459
604
|
};
|
|
460
|
-
const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
|
|
605
|
+
const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && (CSS.supports("display", "grid-lanes") || CSS.supports("grid-template-rows", "masonry"));
|
|
461
606
|
if (this.options.useNativeCSSGrid && supportsNativeCSS) {
|
|
462
607
|
this.isNativeCSSGrid = true;
|
|
463
608
|
this.root.classList.add("wulf-masonry", "wulf-masonry--native");
|
|
609
|
+
this.syncNativeGridVariables();
|
|
464
610
|
} else {
|
|
465
611
|
this.root.classList.add("wulf-masonry");
|
|
466
612
|
}
|
|
@@ -484,7 +630,7 @@ var Masonry = class extends LocalizedComponent {
|
|
|
484
630
|
this.wasRoleInferred = true;
|
|
485
631
|
}
|
|
486
632
|
const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("gallery");
|
|
487
|
-
if (label && !this.root.hasAttribute("aria-label")) {
|
|
633
|
+
if (label && !this.root.hasAttribute("aria-label") && !this.root.hasAttribute("aria-labelledby")) {
|
|
488
634
|
this.root.setAttribute("aria-label", label);
|
|
489
635
|
this.lastInferredAriaLabel = label;
|
|
490
636
|
this.wasAriaLabelInferred = true;
|
|
@@ -509,7 +655,12 @@ var Masonry = class extends LocalizedComponent {
|
|
|
509
655
|
*/
|
|
510
656
|
applyTransitionDuration() {
|
|
511
657
|
const dur = this.options.transitionDuration;
|
|
512
|
-
|
|
658
|
+
let durValue = "300ms";
|
|
659
|
+
if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
|
|
660
|
+
durValue = `${dur}ms`;
|
|
661
|
+
} else if (typeof dur === "string" && /^\s*(?:\d+(?:\.\d+)?|\.\d+)(ms|s)\s*$/i.test(dur)) {
|
|
662
|
+
durValue = dur.trim();
|
|
663
|
+
}
|
|
513
664
|
this.root.style.setProperty("--wulf-masonry-duration", durValue);
|
|
514
665
|
}
|
|
515
666
|
/**
|
|
@@ -520,24 +671,37 @@ var Masonry = class extends LocalizedComponent {
|
|
|
520
671
|
let matched = [];
|
|
521
672
|
if (this.options.itemSelector === "> *") {
|
|
522
673
|
matched = Array.from(this.root.children).filter(
|
|
523
|
-
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
|
|
674
|
+
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
524
675
|
);
|
|
525
676
|
} else {
|
|
526
677
|
try {
|
|
527
|
-
|
|
528
|
-
|
|
678
|
+
const rawSelector = this.options.itemSelector.trim();
|
|
679
|
+
const selector = rawSelector.startsWith(">") ? `:scope ${rawSelector}` : rawSelector;
|
|
680
|
+
matched = Array.from(this.root.querySelectorAll(selector)).filter(
|
|
681
|
+
(el) => el.parentElement === this.root && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
529
682
|
);
|
|
530
683
|
} catch {
|
|
531
684
|
matched = Array.from(this.root.children).filter(
|
|
532
|
-
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
|
|
685
|
+
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
533
686
|
);
|
|
534
687
|
}
|
|
535
688
|
}
|
|
689
|
+
if (this.itemResizeObserver) {
|
|
690
|
+
const nextSet = new Set(matched);
|
|
691
|
+
for (const prevEl of this.observedItems) {
|
|
692
|
+
if (!nextSet.has(prevEl)) {
|
|
693
|
+
this.itemResizeObserver.unobserve(prevEl);
|
|
694
|
+
this.observedItems.delete(prevEl);
|
|
695
|
+
this.observedItemHeights.delete(prevEl);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
536
699
|
this._items = matched;
|
|
537
700
|
for (const item of this._items) {
|
|
538
701
|
item.classList.add("wulf-masonry-item");
|
|
539
|
-
if (this.itemResizeObserver) {
|
|
702
|
+
if (this.itemResizeObserver && !this.observedItems.has(item)) {
|
|
540
703
|
this.itemResizeObserver.observe(item);
|
|
704
|
+
this.observedItems.add(item);
|
|
541
705
|
}
|
|
542
706
|
}
|
|
543
707
|
}
|
|
@@ -557,11 +721,52 @@ var Masonry = class extends LocalizedComponent {
|
|
|
557
721
|
}
|
|
558
722
|
});
|
|
559
723
|
this.resizeObserver.observe(this.root);
|
|
560
|
-
this.itemResizeObserver = new ResizeObserver(() => {
|
|
561
|
-
|
|
724
|
+
this.itemResizeObserver = new ResizeObserver((entries) => {
|
|
725
|
+
let heightChanged = false;
|
|
726
|
+
for (const entry of entries) {
|
|
727
|
+
const newH = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;
|
|
728
|
+
const prevH = this.observedItemHeights.get(entry.target);
|
|
729
|
+
if (prevH === void 0 || Math.abs(newH - prevH) >= 1) {
|
|
730
|
+
this.observedItemHeights.set(entry.target, newH);
|
|
731
|
+
if (prevH !== void 0) {
|
|
732
|
+
heightChanged = true;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (heightChanged) {
|
|
737
|
+
this.scheduleLayout();
|
|
738
|
+
}
|
|
562
739
|
});
|
|
563
740
|
for (const item of this._items) {
|
|
564
741
|
this.itemResizeObserver.observe(item);
|
|
742
|
+
this.observedItems.add(item);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Synchronise les variables CSS du mode natif CSS Grid Level 3 depuis les options JS.
|
|
747
|
+
*/
|
|
748
|
+
syncNativeGridVariables() {
|
|
749
|
+
const { x: gutterX, y: gutterY } = LayoutEngine.parseGutter(this.options.gutter);
|
|
750
|
+
this.root.style.setProperty("--wulf-masonry-gutter-x", `${gutterX}px`);
|
|
751
|
+
this.root.style.setProperty("--wulf-masonry-gutter-y", `${gutterY}px`);
|
|
752
|
+
if (typeof this.options.columnWidth === "number" && Number.isFinite(this.options.columnWidth) && this.options.columnWidth > 0) {
|
|
753
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${this.options.columnWidth}px`);
|
|
754
|
+
} else if (this.options.columnWidth instanceof HTMLElement) {
|
|
755
|
+
const w = this.options.columnWidth.getBoundingClientRect().width;
|
|
756
|
+
if (w > 0) {
|
|
757
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
|
|
758
|
+
}
|
|
759
|
+
} else if (typeof this.options.columnWidth === "string" && this.options.columnWidth.trim()) {
|
|
760
|
+
try {
|
|
761
|
+
const el = this.root.querySelector(this.options.columnWidth);
|
|
762
|
+
if (el) {
|
|
763
|
+
const w = el.getBoundingClientRect().width;
|
|
764
|
+
if (w > 0) {
|
|
765
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
} catch {
|
|
769
|
+
}
|
|
565
770
|
}
|
|
566
771
|
}
|
|
567
772
|
/**
|
|
@@ -571,14 +776,12 @@ var Masonry = class extends LocalizedComponent {
|
|
|
571
776
|
if (!this.options.autoImages) return;
|
|
572
777
|
const images = Array.from(this.root.querySelectorAll("img"));
|
|
573
778
|
for (const img of images) {
|
|
574
|
-
if (!img.complete) {
|
|
779
|
+
if (!img.complete && !this.watchedImages.has(img)) {
|
|
780
|
+
this.watchedImages.add(img);
|
|
575
781
|
const attachLoadListener = () => {
|
|
576
|
-
|
|
577
|
-
this.pendingImageListeners = this.pendingImageListeners.filter((l) => l.handler !== onLoad);
|
|
782
|
+
img.addEventListener("load", () => {
|
|
578
783
|
if (!this.isDestroyed) this.scheduleLayout();
|
|
579
|
-
};
|
|
580
|
-
this.pendingImageListeners.push({ img, handler: onLoad });
|
|
581
|
-
img.addEventListener("load", onLoad, { once: true });
|
|
784
|
+
}, { once: true, signal: this.abortController.signal });
|
|
582
785
|
};
|
|
583
786
|
if (typeof img.decode === "function") {
|
|
584
787
|
img.decode().then(() => {
|
|
@@ -612,10 +815,17 @@ var Masonry = class extends LocalizedComponent {
|
|
|
612
815
|
if (this.isDestroyed) return;
|
|
613
816
|
this.syncAccessibilityLabels();
|
|
614
817
|
if (this.isNativeCSSGrid) {
|
|
818
|
+
this.syncNativeGridVariables();
|
|
819
|
+
for (const el of this._items) {
|
|
820
|
+
el.classList.remove("wulf-masonry-item--hidden");
|
|
821
|
+
}
|
|
615
822
|
this.options.onLayout([]);
|
|
616
823
|
return;
|
|
617
824
|
}
|
|
618
825
|
this.root.setAttribute("aria-busy", "true");
|
|
826
|
+
if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
|
|
827
|
+
this.root.style.width = "";
|
|
828
|
+
}
|
|
619
829
|
const result = LayoutEngine.calculate(this.root, this._items, this.options);
|
|
620
830
|
this.root.style.height = `${result.containerHeight}px`;
|
|
621
831
|
if (this.options.fitWidth && result.fittedWidth !== void 0) {
|
|
@@ -625,6 +835,14 @@ var Masonry = class extends LocalizedComponent {
|
|
|
625
835
|
this.root.classList.remove("wulf-masonry--fit-width");
|
|
626
836
|
}
|
|
627
837
|
const stagger = this.options.stagger;
|
|
838
|
+
const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
|
|
839
|
+
if (validStagger) {
|
|
840
|
+
this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
|
|
841
|
+
} else {
|
|
842
|
+
this.root.style.removeProperty("--wulf-masonry-stagger");
|
|
843
|
+
}
|
|
844
|
+
const hasIgnoredChildren = this._items.length !== this.root.children.length;
|
|
845
|
+
const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
|
|
628
846
|
const usePercent = this.options.percentPosition && result.containerWidth > 0;
|
|
629
847
|
for (let i = 0; i < result.positions.length; i++) {
|
|
630
848
|
const pos = result.positions[i];
|
|
@@ -637,12 +855,13 @@ var Masonry = class extends LocalizedComponent {
|
|
|
637
855
|
}
|
|
638
856
|
item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
|
|
639
857
|
item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
|
|
640
|
-
if (
|
|
641
|
-
item.style.
|
|
858
|
+
if (validStagger && !supportsSiblingIndex) {
|
|
859
|
+
item.style.setProperty("--wulf-masonry-index", String(i));
|
|
642
860
|
} else {
|
|
643
|
-
item.style.removeProperty("
|
|
861
|
+
item.style.removeProperty("--wulf-masonry-index");
|
|
644
862
|
}
|
|
645
863
|
item.classList.remove("wulf-masonry-item--hidden");
|
|
864
|
+
this.observedItemHeights.set(item, pos.height);
|
|
646
865
|
this.options.onItemPlaced(item, pos);
|
|
647
866
|
}
|
|
648
867
|
this.root.setAttribute("aria-busy", "false");
|
|
@@ -657,7 +876,11 @@ var Masonry = class extends LocalizedComponent {
|
|
|
657
876
|
if (list.length === 0) return;
|
|
658
877
|
const frag = document.createDocumentFragment();
|
|
659
878
|
for (const el of list) {
|
|
660
|
-
|
|
879
|
+
if (this.isNativeCSSGrid) {
|
|
880
|
+
el.classList.add("wulf-masonry-item");
|
|
881
|
+
} else {
|
|
882
|
+
el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
883
|
+
}
|
|
661
884
|
frag.appendChild(el);
|
|
662
885
|
}
|
|
663
886
|
this.root.appendChild(frag);
|
|
@@ -675,7 +898,11 @@ var Masonry = class extends LocalizedComponent {
|
|
|
675
898
|
const first = this.root.firstChild;
|
|
676
899
|
const frag = document.createDocumentFragment();
|
|
677
900
|
for (const el of list) {
|
|
678
|
-
|
|
901
|
+
if (this.isNativeCSSGrid) {
|
|
902
|
+
el.classList.add("wulf-masonry-item");
|
|
903
|
+
} else {
|
|
904
|
+
el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
905
|
+
}
|
|
679
906
|
frag.appendChild(el);
|
|
680
907
|
}
|
|
681
908
|
this.root.insertBefore(frag, first);
|
|
@@ -684,44 +911,51 @@ var Masonry = class extends LocalizedComponent {
|
|
|
684
911
|
this.layout();
|
|
685
912
|
}
|
|
686
913
|
/**
|
|
687
|
-
* Supprime des éléments avec animation de fondu/sortie.
|
|
914
|
+
* Supprime des éléments avec animation de fondu/sortie synchronisée via Web Animations API.
|
|
688
915
|
*/
|
|
689
916
|
remove(elements) {
|
|
690
917
|
if (this.isDestroyed) return;
|
|
691
918
|
const list = Array.isArray(elements) ? elements : [elements];
|
|
692
919
|
if (list.length === 0) return;
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
696
|
-
const dur = typeof this.options.transitionDuration === "number" ? this.options.transitionDuration : 300;
|
|
697
|
-
if (dur <= 0) {
|
|
920
|
+
const finalizeRemoval = () => {
|
|
921
|
+
if (this.isDestroyed) return;
|
|
698
922
|
for (const el of list) {
|
|
923
|
+
this.removingItems.delete(el);
|
|
699
924
|
if (el.parentElement === this.root) {
|
|
700
925
|
if (this.itemResizeObserver) {
|
|
701
926
|
this.itemResizeObserver.unobserve(el);
|
|
927
|
+
this.observedItems.delete(el);
|
|
928
|
+
this.observedItemHeights.delete(el);
|
|
702
929
|
}
|
|
703
930
|
this.root.removeChild(el);
|
|
704
931
|
}
|
|
705
932
|
}
|
|
706
933
|
this.reloadItems();
|
|
707
934
|
this.layout();
|
|
935
|
+
};
|
|
936
|
+
for (const el of list) {
|
|
937
|
+
this.removingItems.add(el);
|
|
938
|
+
if (typeof document !== "undefined" && document.activeElement && el.contains(document.activeElement)) {
|
|
939
|
+
document.activeElement.blur?.();
|
|
940
|
+
}
|
|
941
|
+
el.setAttribute("inert", "");
|
|
942
|
+
el.style.transitionDelay = "0ms";
|
|
943
|
+
el.classList.add("wulf-masonry-item--hidden");
|
|
944
|
+
}
|
|
945
|
+
const dur = parseCssDurationMs(this.options.transitionDuration, 300);
|
|
946
|
+
if (dur <= 0 || this.isNativeCSSGrid) {
|
|
947
|
+
finalizeRemoval();
|
|
708
948
|
return;
|
|
709
949
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
}
|
|
718
|
-
this.root.removeChild(el);
|
|
719
|
-
}
|
|
950
|
+
this.reloadItems();
|
|
951
|
+
this.layout();
|
|
952
|
+
Promise.all(
|
|
953
|
+
list.map((el) => waitForAnimations(el, dur, this.abortController.signal))
|
|
954
|
+
).then(() => {
|
|
955
|
+
if (!this.abortController.signal.aborted) {
|
|
956
|
+
finalizeRemoval();
|
|
720
957
|
}
|
|
721
|
-
|
|
722
|
-
this.layout();
|
|
723
|
-
}, dur);
|
|
724
|
-
this.removeTimers.add(timerId);
|
|
958
|
+
});
|
|
725
959
|
}
|
|
726
960
|
/**
|
|
727
961
|
* Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
|
|
@@ -758,14 +992,7 @@ var Masonry = class extends LocalizedComponent {
|
|
|
758
992
|
destroy() {
|
|
759
993
|
if (this.isDestroyed) return;
|
|
760
994
|
this.isDestroyed = true;
|
|
761
|
-
|
|
762
|
-
clearTimeout(timerId);
|
|
763
|
-
}
|
|
764
|
-
this.removeTimers.clear();
|
|
765
|
-
for (const { img, handler } of this.pendingImageListeners) {
|
|
766
|
-
img.removeEventListener("load", handler);
|
|
767
|
-
}
|
|
768
|
-
this.pendingImageListeners = [];
|
|
995
|
+
this.abortController.abort();
|
|
769
996
|
if (this.layoutRafId !== null) {
|
|
770
997
|
cancelAnimationFrame(this.layoutRafId);
|
|
771
998
|
this.layoutRafId = null;
|
|
@@ -787,6 +1014,10 @@ var Masonry = class extends LocalizedComponent {
|
|
|
787
1014
|
this.root.removeAttribute("aria-label");
|
|
788
1015
|
}
|
|
789
1016
|
this.root.style.removeProperty("--wulf-masonry-duration");
|
|
1017
|
+
this.root.style.removeProperty("--wulf-masonry-stagger");
|
|
1018
|
+
this.root.style.removeProperty("--wulf-masonry-col-min");
|
|
1019
|
+
this.root.style.removeProperty("--wulf-masonry-gutter-x");
|
|
1020
|
+
this.root.style.removeProperty("--wulf-masonry-gutter-y");
|
|
790
1021
|
if (this.originalContainerStyles.height) {
|
|
791
1022
|
this.root.style.height = this.originalContainerStyles.height;
|
|
792
1023
|
} else {
|
|
@@ -802,20 +1033,16 @@ var Masonry = class extends LocalizedComponent {
|
|
|
802
1033
|
item.style.removeProperty("--wulf-masonry-w");
|
|
803
1034
|
item.style.removeProperty("--wulf-masonry-x");
|
|
804
1035
|
item.style.removeProperty("--wulf-masonry-y");
|
|
805
|
-
item.style.removeProperty("
|
|
1036
|
+
item.style.removeProperty("--wulf-masonry-index");
|
|
806
1037
|
}
|
|
807
1038
|
this._items = [];
|
|
808
1039
|
}
|
|
809
1040
|
};
|
|
810
|
-
Masonry._i18n = masonryI18n;
|
|
811
|
-
Masonry.i18n = masonryI18n;
|
|
812
1041
|
|
|
813
1042
|
// src/masonry/index.ts
|
|
814
1043
|
var index_default = Masonry;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
const wulfNamespace = win.Wulf || {};
|
|
818
|
-
win.Wulf = wulfNamespace;
|
|
1044
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
1045
|
+
if (wulfNamespace) {
|
|
819
1046
|
wulfNamespace.Masonry = Object.assign(Masonry, {
|
|
820
1047
|
Masonry,
|
|
821
1048
|
LayoutEngine,
|