wulf.js 1.9.0 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +220 -19
  2. package/changelog.md +42 -0
  3. package/dist/focus-trap.esm.js +407 -0
  4. package/dist/focus-trap.esm.js.map +7 -0
  5. package/dist/focus-trap.global.js +433 -0
  6. package/dist/focus-trap.global.js.map +7 -0
  7. package/dist/focus-trap.global.min.js +6 -0
  8. package/dist/focus-trap.global.min.js.map +7 -0
  9. package/dist/index.esm.js +1179 -8
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +1180 -9
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +5 -2
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.esm.js +106 -2
  16. package/dist/mask.esm.js.map +3 -3
  17. package/dist/mask.global.js +107 -3
  18. package/dist/mask.global.js.map +3 -3
  19. package/dist/mask.global.min.js +5 -2
  20. package/dist/mask.global.min.js.map +4 -4
  21. package/dist/masonry.esm.js +78 -3
  22. package/dist/masonry.esm.js.map +3 -3
  23. package/dist/masonry.global.js +79 -4
  24. package/dist/masonry.global.js.map +3 -3
  25. package/dist/masonry.global.min.js +5 -2
  26. package/dist/masonry.global.min.js.map +4 -4
  27. package/dist/scroll.esm.js +78 -3
  28. package/dist/scroll.esm.js.map +3 -3
  29. package/dist/scroll.global.js +79 -4
  30. package/dist/scroll.global.js.map +3 -3
  31. package/dist/scroll.global.min.js +5 -2
  32. package/dist/scroll.global.min.js.map +4 -4
  33. package/dist/shortcut.esm.js +584 -0
  34. package/dist/shortcut.esm.js.map +7 -0
  35. package/dist/shortcut.global.js +610 -0
  36. package/dist/shortcut.global.js.map +7 -0
  37. package/dist/shortcut.global.min.js +3 -0
  38. package/dist/shortcut.global.min.js.map +7 -0
  39. package/dist/toast.esm.js +91 -2
  40. package/dist/toast.esm.js.map +3 -3
  41. package/dist/toast.global.js +92 -3
  42. package/dist/toast.global.js.map +3 -3
  43. package/dist/toast.global.min.js +5 -2
  44. package/dist/toast.global.min.js.map +4 -4
  45. package/dist/types/common/AuditableComponent.d.ts +45 -0
  46. package/dist/types/common/LocalizedComponent.d.ts +3 -2
  47. package/dist/types/focus-trap/FocusTrap.d.ts +64 -0
  48. package/dist/types/focus-trap/index.d.ts +3 -0
  49. package/dist/types/focus-trap/types.d.ts +45 -0
  50. package/dist/types/index.d.ts +5 -0
  51. package/dist/types/mask/BaseInputMask.d.ts +14 -1
  52. package/dist/types/mask/InputMask.d.ts +1 -0
  53. package/dist/types/mask/types.d.ts +5 -2
  54. package/dist/types/masonry/Masonry.d.ts +7 -0
  55. package/dist/types/masonry/types.d.ts +7 -2
  56. package/dist/types/scroll/ScrollBlock.d.ts +7 -0
  57. package/dist/types/scroll/types.d.ts +3 -2
  58. package/dist/types/shortcut/ShortcutFormatter.d.ts +31 -0
  59. package/dist/types/shortcut/ShortcutManager.d.ts +91 -0
  60. package/dist/types/shortcut/index.d.ts +4 -0
  61. package/dist/types/shortcut/types.d.ts +101 -0
  62. package/dist/types/toast/Toast.d.ts +3 -0
  63. package/dist/types/toast/ToastInstance.d.ts +9 -1
  64. package/dist/types/toast/types.d.ts +3 -2
  65. package/package.json +23 -10
  66. package/dist/index.cjs.js +0 -4783
  67. package/dist/index.cjs.js.map +0 -7
  68. package/dist/mask.cjs.js +0 -2982
  69. package/dist/mask.cjs.js.map +0 -7
  70. package/dist/masonry.cjs.js +0 -783
  71. package/dist/masonry.cjs.js.map +0 -7
  72. package/dist/scroll.cjs.js +0 -748
  73. package/dist/scroll.cjs.js.map +0 -7
  74. package/dist/toast.cjs.js +0 -626
  75. package/dist/toast.cjs.js.map +0 -7
@@ -1,783 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/masonry/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- LayoutEngine: () => LayoutEngine,
24
- LocalizedComponent: () => LocalizedComponent,
25
- Masonry: () => Masonry,
26
- createI18nManager: () => createI18nManager,
27
- default: () => index_default,
28
- masonryEn: () => masonryEn,
29
- masonryFr: () => masonryFr,
30
- masonryI18n: () => masonryI18n
31
- });
32
- module.exports = __toCommonJS(index_exports);
33
-
34
- // src/masonry/LayoutEngine.ts
35
- var LayoutEngine = class {
36
- /**
37
- * Normalise les gouttières horizontales et verticales.
38
- */
39
- static parseGutter(gutterOption) {
40
- if (typeof gutterOption === "number") {
41
- return { x: Math.max(0, gutterOption), y: Math.max(0, gutterOption) };
42
- }
43
- if (gutterOption && typeof gutterOption === "object") {
44
- return {
45
- x: Math.max(0, Number(gutterOption.x) || 0),
46
- y: Math.max(0, Number(gutterOption.y) || 0)
47
- };
48
- }
49
- return { x: 0, y: 0 };
50
- }
51
- /**
52
- * Résout la largeur effective d'une colonne en pixels.
53
- */
54
- static resolveColumnWidth(container, firstItem, columnWidthOption) {
55
- if (typeof columnWidthOption === "number" && columnWidthOption > 0) {
56
- return columnWidthOption;
57
- }
58
- 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;
69
- }
70
- return parsed;
71
- }
72
- }
73
- if (columnWidthOption instanceof HTMLElement) {
74
- const w = columnWidthOption.getBoundingClientRect().width;
75
- if (w > 0) return w;
76
- }
77
- if (firstItem) {
78
- const w = firstItem.getBoundingClientRect().width;
79
- if (w > 0) return w;
80
- }
81
- const containerW = container.getBoundingClientRect().width;
82
- return containerW > 0 ? containerW : 200;
83
- }
84
- /**
85
- * Extrait le facteur d'étalement (span) d'un item sur plusieurs colonnes.
86
- */
87
- static getItemSpan(item, colWidth, gutterX, maxCols) {
88
- const dataSpan = item.getAttribute("data-masonry-span") || item.dataset.masonrySpan;
89
- if (dataSpan) {
90
- const parsed = parseInt(dataSpan, 10);
91
- if (!isNaN(parsed) && parsed > 0) {
92
- return Math.min(maxCols, parsed);
93
- }
94
- }
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);
100
- }
101
- }
102
- return 1;
103
- }
104
- /**
105
- * Calcule les positions optimales de tous les items.
106
- */
107
- static calculate(container, items, options) {
108
- const containerRect = container.getBoundingClientRect();
109
- const containerWidth = containerRect.width;
110
- const { x: gutterX, y: gutterY } = this.parseGutter(options.gutter);
111
- if (containerWidth <= 0 || items.length === 0) {
112
- return {
113
- cols: 1,
114
- colWidth: containerWidth,
115
- gutterX,
116
- gutterY,
117
- containerHeight: 0,
118
- containerWidth,
119
- positions: []
120
- };
121
- }
122
- const firstItem = items[0] || null;
123
- let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);
124
- let cols = Math.floor((containerWidth + gutterX) / (colWidth + gutterX));
125
- cols = Math.max(1, cols);
126
- if (!options.columnWidth && cols > 1) {
127
- colWidth = (containerWidth - (cols - 1) * gutterX) / cols;
128
- }
129
- const fittedWidth = options.fitWidth ? cols * colWidth + (cols - 1) * gutterX : void 0;
130
- const colHeights = new Array(cols).fill(0);
131
- const positions = [];
132
- const itemHeights = items.map((item) => {
133
- const h = item.getBoundingClientRect().height;
134
- return h > 0 ? h : 50;
135
- });
136
- let currentHCol = 0;
137
- for (let i = 0; i < items.length; i++) {
138
- const item = items[i];
139
- const itemH = itemHeights[i];
140
- const span = this.getItemSpan(item, colWidth, gutterX, cols);
141
- let targetCol = 0;
142
- let targetY = 0;
143
- if (options.horizontalOrder) {
144
- if (currentHCol + span > cols) {
145
- currentHCol = 0;
146
- }
147
- targetCol = currentHCol;
148
- let maxY = 0;
149
- for (let s = 0; s < span; s++) {
150
- if (colHeights[targetCol + s] > maxY) {
151
- maxY = colHeights[targetCol + s];
152
- }
153
- }
154
- targetY = maxY;
155
- currentHCol = (targetCol + span) % cols;
156
- } else {
157
- if (span === 1) {
158
- let minH = colHeights[0];
159
- targetCol = 0;
160
- for (let c = 1; c < cols; c++) {
161
- if (colHeights[c] < minH) {
162
- minH = colHeights[c];
163
- targetCol = c;
164
- }
165
- }
166
- targetY = minH;
167
- } else {
168
- let bestMax = Infinity;
169
- targetCol = 0;
170
- for (let c = 0; c <= cols - span; c++) {
171
- let maxInSpan = 0;
172
- for (let s = 0; s < span; s++) {
173
- if (colHeights[c + s] > maxInSpan) {
174
- maxInSpan = colHeights[c + s];
175
- }
176
- }
177
- if (maxInSpan < bestMax) {
178
- bestMax = maxInSpan;
179
- targetCol = c;
180
- }
181
- }
182
- targetY = bestMax;
183
- }
184
- }
185
- const itemW = span * colWidth + (span - 1) * gutterX;
186
- const targetX = targetCol * (colWidth + gutterX);
187
- positions.push({
188
- element: item,
189
- x: targetX,
190
- y: targetY,
191
- width: itemW,
192
- height: itemH,
193
- column: targetCol,
194
- span
195
- });
196
- const nextY = targetY + itemH + gutterY;
197
- for (let s = 0; s < span; s++) {
198
- colHeights[targetCol + s] = nextY;
199
- }
200
- }
201
- let maxColH = 0;
202
- for (let c = 0; c < cols; c++) {
203
- if (colHeights[c] > maxColH) {
204
- maxColH = colHeights[c];
205
- }
206
- }
207
- const containerHeight = Math.max(0, maxColH > 0 ? maxColH - gutterY : 0);
208
- return {
209
- cols,
210
- colWidth,
211
- gutterX,
212
- gutterY,
213
- containerHeight,
214
- containerWidth,
215
- fittedWidth,
216
- positions
217
- };
218
- }
219
- };
220
-
221
- // src/common/LocalizedComponent.ts
222
- var LocalizedComponent = class {
223
- /**
224
- * Définit la langue globale du composant (ex: 'fr', 'en', 'es').
225
- */
226
- static setLocale(locale) {
227
- if (this._i18n) {
228
- this._i18n.setLocale(locale);
229
- }
230
- }
231
- /**
232
- * Retourne la langue globale active du composant.
233
- */
234
- static getLocale() {
235
- return this._i18n ? this._i18n.getLocale() : "";
236
- }
237
- /**
238
- * Enregistre un dictionnaire de traduction pour une langue donnée.
239
- */
240
- static registerLocale(locale, translations) {
241
- if (this._i18n) {
242
- this._i18n.registerLocale(locale, translations);
243
- }
244
- }
245
- /**
246
- * Surcharge les libellés globalement pour ce composant.
247
- */
248
- static setI18n(overrides) {
249
- if (this._i18n) {
250
- this._i18n.setI18n(overrides);
251
- }
252
- }
253
- /**
254
- * Retourne l'ensemble des libellés actifs résolus du composant.
255
- */
256
- static getI18n() {
257
- return this._i18n ? this._i18n.getAll() : {};
258
- }
259
- /**
260
- * Réinitialise les réglages de langue et surcharges globales.
261
- */
262
- static resetI18n() {
263
- if (this._i18n) {
264
- this._i18n.reset();
265
- }
266
- }
267
- /**
268
- * Résout une clé au niveau statique de la classe.
269
- */
270
- static t(key, instanceOverride) {
271
- return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
272
- }
273
- constructor(i18nOverrides) {
274
- this.i18nOverrides = i18nOverrides;
275
- }
276
- /**
277
- * Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
278
- */
279
- t(key) {
280
- const ctor = this.constructor;
281
- return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
282
- }
283
- };
284
-
285
- // src/common/i18n.ts
286
- function normalizeLocaleCode(locale) {
287
- return locale.trim().toLowerCase().replace(/_/g, "-");
288
- }
289
- function getPrimaryLanguage(normalizedLocale) {
290
- const dashIndex = normalizedLocale.indexOf("-");
291
- return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
292
- }
293
- function assignDefined(target, source) {
294
- if (!source) return target;
295
- for (const key of Object.keys(source)) {
296
- if (source[key] !== void 0) {
297
- target[key] = source[key];
298
- }
299
- }
300
- return target;
301
- }
302
- function createI18nManager(defaultLocale, locales) {
303
- const fallbackLocale = normalizeLocaleCode(defaultLocale);
304
- const initialLocales = {};
305
- for (const [loc, dict] of Object.entries(locales)) {
306
- initialLocales[normalizeLocaleCode(loc)] = { ...dict };
307
- }
308
- let currentLocale = fallbackLocale;
309
- let activeLocales = { ...initialLocales };
310
- let globalOverrides = {};
311
- function resolveActiveDictionaries() {
312
- const dicts = [];
313
- const exact = activeLocales[currentLocale];
314
- if (exact) dicts.push(exact);
315
- const primary = getPrimaryLanguage(currentLocale);
316
- if (primary && activeLocales[primary]) {
317
- dicts.push(activeLocales[primary]);
318
- }
319
- return dicts;
320
- }
321
- return {
322
- setLocale(locale) {
323
- if (locale && locale.trim()) {
324
- currentLocale = normalizeLocaleCode(locale);
325
- }
326
- },
327
- getLocale() {
328
- return currentLocale;
329
- },
330
- registerLocale(locale, translations) {
331
- if (!locale || !locale.trim() || !translations) return;
332
- const norm = normalizeLocaleCode(locale);
333
- activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
334
- },
335
- setI18n(overrides) {
336
- if (!overrides) return;
337
- globalOverrides = assignDefined({ ...globalOverrides }, overrides);
338
- },
339
- t(key, instanceOverride) {
340
- if (instanceOverride && instanceOverride[key] !== void 0) {
341
- return String(instanceOverride[key]);
342
- }
343
- if (globalOverrides[key] !== void 0) {
344
- return String(globalOverrides[key]);
345
- }
346
- for (const dict of resolveActiveDictionaries()) {
347
- if (dict[key] !== void 0) {
348
- return String(dict[key]);
349
- }
350
- }
351
- const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
352
- if (fallbackDict && fallbackDict[key] !== void 0) {
353
- return String(fallbackDict[key]);
354
- }
355
- return String(key);
356
- },
357
- getAll(instanceOverride) {
358
- const result = {};
359
- const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
360
- assignDefined(result, fallback);
361
- const activeDicts = resolveActiveDictionaries().reverse();
362
- for (const dict of activeDicts) {
363
- assignDefined(result, dict);
364
- }
365
- assignDefined(result, globalOverrides);
366
- assignDefined(result, instanceOverride);
367
- return result;
368
- },
369
- reset() {
370
- currentLocale = fallbackLocale;
371
- globalOverrides = {};
372
- activeLocales = {};
373
- for (const [loc, dict] of Object.entries(initialLocales)) {
374
- activeLocales[loc] = { ...dict };
375
- }
376
- }
377
- };
378
- }
379
-
380
- // src/masonry/i18n/fr.ts
381
- var masonryFr = {
382
- gallery: "Galerie en grille asym\xE9trique"
383
- };
384
-
385
- // src/masonry/i18n/en.ts
386
- var masonryEn = {
387
- gallery: "Masonry grid gallery"
388
- };
389
-
390
- // src/masonry/i18n/index.ts
391
- var masonryI18n = createI18nManager("fr", {
392
- fr: masonryFr,
393
- en: masonryEn
394
- });
395
-
396
- // src/masonry/Masonry.ts
397
- var Masonry = class extends LocalizedComponent {
398
- constructor(target, options = {}) {
399
- super(options.i18n);
400
- this.isNativeCSSGrid = false;
401
- this._items = [];
402
- this.resizeObserver = null;
403
- this.itemResizeObserver = null;
404
- this.layoutRafId = null;
405
- this.isDestroyed = false;
406
- this.wasRoleInferred = false;
407
- this.wasAriaLabelInferred = false;
408
- this.hasExplicitAriaLabel = false;
409
- this.lastInferredAriaLabel = "";
410
- this.removeTimers = /* @__PURE__ */ new Set();
411
- this.pendingImageListeners = [];
412
- if (typeof target === "string") {
413
- const el = document.querySelector(target);
414
- if (!el) {
415
- throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${target}"`);
416
- }
417
- this.root = el;
418
- } else if (target instanceof HTMLElement) {
419
- this.root = target;
420
- } else {
421
- throw new Error("[Wulf.Masonry] Cible invalide : fournissez un \xE9l\xE9ment HTMLElement ou un s\xE9lecteur valide.");
422
- }
423
- this.originalContainerStyles = {
424
- height: this.root.style.height,
425
- width: this.root.style.width
426
- };
427
- this.hasExplicitAriaLabel = Boolean(options.ariaLabel);
428
- this.options = {
429
- itemSelector: options.itemSelector || "> *",
430
- columnWidth: options.columnWidth ?? 0,
431
- gutter: options.gutter ?? 0,
432
- percentPosition: Boolean(options.percentPosition),
433
- fitWidth: Boolean(options.fitWidth),
434
- horizontalOrder: Boolean(options.horizontalOrder),
435
- transitionDuration: options.transitionDuration !== void 0 ? options.transitionDuration : 300,
436
- stagger: options.stagger || 0,
437
- resize: options.resize !== false,
438
- autoImages: options.autoImages !== false,
439
- useNativeCSSGrid: options.useNativeCSSGrid !== false,
440
- ariaRole: options.ariaRole || "region",
441
- ariaLabel: options.ariaLabel || this.t("gallery"),
442
- i18n: options.i18n || {},
443
- onLayout: options.onLayout || (() => {
444
- }),
445
- onItemPlaced: options.onItemPlaced || (() => {
446
- })
447
- };
448
- const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("grid-template-rows", "masonry");
449
- if (this.options.useNativeCSSGrid && supportsNativeCSS) {
450
- this.isNativeCSSGrid = true;
451
- this.root.classList.add("wulf-masonry", "wulf-masonry--native");
452
- } else {
453
- this.root.classList.add("wulf-masonry");
454
- }
455
- this.initAccessibility();
456
- this.applyTransitionDuration();
457
- this.reloadItems();
458
- this.initObservers();
459
- this.initImages();
460
- this.layout();
461
- }
462
- get items() {
463
- return [...this._items];
464
- }
465
- /**
466
- * Initialise les attributs WAI-ARIA du conteneur.
467
- */
468
- initAccessibility() {
469
- if (this.options.ariaRole && !this.root.hasAttribute("role")) {
470
- this.root.setAttribute("role", this.options.ariaRole);
471
- this.wasRoleInferred = true;
472
- }
473
- const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("gallery");
474
- if (label && !this.root.hasAttribute("aria-label")) {
475
- this.root.setAttribute("aria-label", label);
476
- this.lastInferredAriaLabel = label;
477
- this.wasAriaLabelInferred = true;
478
- }
479
- }
480
- /**
481
- * Synchronise dynamiquement le libellé ARIA si la langue globale change après montage.
482
- */
483
- syncAccessibilityLabels() {
484
- if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
485
- const currentAttr = this.root.getAttribute("aria-label");
486
- if (currentAttr === this.lastInferredAriaLabel) {
487
- const nextLabel = this.t("gallery");
488
- this.root.setAttribute("aria-label", nextLabel);
489
- this.lastInferredAriaLabel = nextLabel;
490
- this.options.ariaLabel = nextLabel;
491
- }
492
- }
493
- }
494
- /**
495
- * Configure les variables CSS de transition sur le conteneur.
496
- */
497
- applyTransitionDuration() {
498
- const dur = this.options.transitionDuration;
499
- const durValue = typeof dur === "number" ? `${dur}ms` : dur;
500
- this.root.style.setProperty("--wulf-masonry-duration", durValue);
501
- }
502
- /**
503
- * Réindexe les éléments enfants ciblés par la disposition.
504
- */
505
- reloadItems() {
506
- if (this.isDestroyed) return;
507
- let matched = [];
508
- if (this.options.itemSelector === "> *") {
509
- matched = Array.from(this.root.children).filter(
510
- (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
511
- );
512
- } else {
513
- try {
514
- matched = Array.from(this.root.querySelectorAll(this.options.itemSelector)).filter(
515
- (el) => el.parentElement === this.root && !el.hasAttribute("data-masonry-ignore")
516
- );
517
- } catch {
518
- matched = Array.from(this.root.children).filter(
519
- (el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore")
520
- );
521
- }
522
- }
523
- this._items = matched;
524
- for (const item of this._items) {
525
- item.classList.add("wulf-masonry-item");
526
- if (this.itemResizeObserver) {
527
- this.itemResizeObserver.observe(item);
528
- }
529
- }
530
- }
531
- /**
532
- * Active ResizeObserver sur le conteneur et les éléments individuels.
533
- */
534
- initObservers() {
535
- if (!this.options.resize || typeof ResizeObserver === "undefined") return;
536
- let prevWidth = this.root.getBoundingClientRect().width;
537
- this.resizeObserver = new ResizeObserver((entries) => {
538
- for (const entry of entries) {
539
- const currentWidth = entry.contentRect.width;
540
- if (Math.abs(currentWidth - prevWidth) >= 1) {
541
- prevWidth = currentWidth;
542
- this.scheduleLayout();
543
- }
544
- }
545
- });
546
- this.resizeObserver.observe(this.root);
547
- this.itemResizeObserver = new ResizeObserver(() => {
548
- this.scheduleLayout();
549
- });
550
- for (const item of this._items) {
551
- this.itemResizeObserver.observe(item);
552
- }
553
- }
554
- /**
555
- * Détecte les balises <img> sans dimensions prédéfinies et attend leur décodage/chargement.
556
- */
557
- initImages() {
558
- if (!this.options.autoImages) return;
559
- const images = Array.from(this.root.querySelectorAll("img"));
560
- for (const img of images) {
561
- if (!img.complete) {
562
- const attachLoadListener = () => {
563
- const onLoad = () => {
564
- this.pendingImageListeners = this.pendingImageListeners.filter((l) => l.handler !== onLoad);
565
- if (!this.isDestroyed) this.scheduleLayout();
566
- };
567
- this.pendingImageListeners.push({ img, handler: onLoad });
568
- img.addEventListener("load", onLoad, { once: true });
569
- };
570
- if (typeof img.decode === "function") {
571
- img.decode().then(() => {
572
- if (!this.isDestroyed) this.scheduleLayout();
573
- }).catch(() => {
574
- attachLoadListener();
575
- });
576
- } else {
577
- attachLoadListener();
578
- }
579
- }
580
- }
581
- }
582
- /**
583
- * Planifie un recalcul au prochain tick d'animation via requestAnimationFrame.
584
- */
585
- scheduleLayout() {
586
- if (this.isDestroyed) return;
587
- if (this.layoutRafId !== null) {
588
- cancelAnimationFrame(this.layoutRafId);
589
- }
590
- this.layoutRafId = requestAnimationFrame(() => {
591
- this.layoutRafId = null;
592
- this.layout();
593
- });
594
- }
595
- /**
596
- * Calcule et applique les nouvelles coordonnées GPU de chaque item.
597
- */
598
- layout() {
599
- if (this.isDestroyed) return;
600
- this.syncAccessibilityLabels();
601
- if (this.isNativeCSSGrid) {
602
- this.options.onLayout([]);
603
- return;
604
- }
605
- this.root.setAttribute("aria-busy", "true");
606
- const result = LayoutEngine.calculate(this.root, this._items, this.options);
607
- this.root.style.height = `${result.containerHeight}px`;
608
- if (this.options.fitWidth && result.fittedWidth !== void 0) {
609
- this.root.style.width = `${result.fittedWidth}px`;
610
- this.root.classList.add("wulf-masonry--fit-width");
611
- } else {
612
- this.root.classList.remove("wulf-masonry--fit-width");
613
- }
614
- const stagger = this.options.stagger;
615
- const usePercent = this.options.percentPosition && result.containerWidth > 0;
616
- for (let i = 0; i < result.positions.length; i++) {
617
- const pos = result.positions[i];
618
- const item = pos.element;
619
- if (usePercent) {
620
- const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
621
- item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
622
- } else {
623
- item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
624
- }
625
- item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
626
- item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
627
- if (stagger > 0) {
628
- item.style.transitionDelay = `${i * stagger}ms`;
629
- } else {
630
- item.style.removeProperty("transition-delay");
631
- }
632
- item.classList.remove("wulf-masonry-item--hidden");
633
- this.options.onItemPlaced(item, pos);
634
- }
635
- this.root.setAttribute("aria-busy", "false");
636
- this.options.onLayout(result.positions);
637
- }
638
- /**
639
- * Ajoute de nouveaux éléments à la fin du conteneur.
640
- */
641
- append(elements) {
642
- if (this.isDestroyed) return;
643
- const list = Array.isArray(elements) ? elements : [elements];
644
- if (list.length === 0) return;
645
- const frag = document.createDocumentFragment();
646
- for (const el of list) {
647
- el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
648
- frag.appendChild(el);
649
- }
650
- this.root.appendChild(frag);
651
- this.reloadItems();
652
- this.initImages();
653
- this.layout();
654
- }
655
- /**
656
- * Ajoute de nouveaux éléments au début du conteneur.
657
- */
658
- prepend(elements) {
659
- if (this.isDestroyed) return;
660
- const list = Array.isArray(elements) ? elements : [elements];
661
- if (list.length === 0) return;
662
- const first = this.root.firstChild;
663
- const frag = document.createDocumentFragment();
664
- for (const el of list) {
665
- el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
666
- frag.appendChild(el);
667
- }
668
- this.root.insertBefore(frag, first);
669
- this.reloadItems();
670
- this.initImages();
671
- this.layout();
672
- }
673
- /**
674
- * Supprime des éléments avec animation de fondu/sortie.
675
- */
676
- remove(elements) {
677
- if (this.isDestroyed) return;
678
- const list = Array.isArray(elements) ? elements : [elements];
679
- if (list.length === 0) return;
680
- for (const el of list) {
681
- el.classList.add("wulf-masonry-item--hidden");
682
- }
683
- const dur = typeof this.options.transitionDuration === "number" ? this.options.transitionDuration : 300;
684
- if (dur <= 0) {
685
- for (const el of list) {
686
- if (el.parentElement === this.root) {
687
- if (this.itemResizeObserver) {
688
- this.itemResizeObserver.unobserve(el);
689
- }
690
- this.root.removeChild(el);
691
- }
692
- }
693
- this.reloadItems();
694
- this.layout();
695
- return;
696
- }
697
- const timerId = window.setTimeout(() => {
698
- this.removeTimers.delete(timerId);
699
- if (this.isDestroyed) return;
700
- for (const el of list) {
701
- if (el.parentElement === this.root) {
702
- if (this.itemResizeObserver) {
703
- this.itemResizeObserver.unobserve(el);
704
- }
705
- this.root.removeChild(el);
706
- }
707
- }
708
- this.reloadItems();
709
- this.layout();
710
- }, dur);
711
- this.removeTimers.add(timerId);
712
- }
713
- /**
714
- * Libère les ressources, déconnecte les observateurs et nettoie les styles injectés.
715
- */
716
- destroy() {
717
- if (this.isDestroyed) return;
718
- this.isDestroyed = true;
719
- for (const timerId of this.removeTimers) {
720
- clearTimeout(timerId);
721
- }
722
- this.removeTimers.clear();
723
- for (const { img, handler } of this.pendingImageListeners) {
724
- img.removeEventListener("load", handler);
725
- }
726
- this.pendingImageListeners = [];
727
- if (this.layoutRafId !== null) {
728
- cancelAnimationFrame(this.layoutRafId);
729
- this.layoutRafId = null;
730
- }
731
- if (this.resizeObserver) {
732
- this.resizeObserver.disconnect();
733
- this.resizeObserver = null;
734
- }
735
- if (this.itemResizeObserver) {
736
- this.itemResizeObserver.disconnect();
737
- this.itemResizeObserver = null;
738
- }
739
- this.root.classList.remove("wulf-masonry", "wulf-masonry--native", "wulf-masonry--fit-width");
740
- this.root.removeAttribute("aria-busy");
741
- if (this.wasRoleInferred && this.root.getAttribute("role") === this.options.ariaRole) {
742
- this.root.removeAttribute("role");
743
- }
744
- if (this.wasAriaLabelInferred && this.root.getAttribute("aria-label") === this.lastInferredAriaLabel) {
745
- this.root.removeAttribute("aria-label");
746
- }
747
- this.root.style.removeProperty("--wulf-masonry-duration");
748
- if (this.originalContainerStyles.height) {
749
- this.root.style.height = this.originalContainerStyles.height;
750
- } else {
751
- this.root.style.removeProperty("height");
752
- }
753
- if (this.originalContainerStyles.width) {
754
- this.root.style.width = this.originalContainerStyles.width;
755
- } else {
756
- this.root.style.removeProperty("width");
757
- }
758
- for (const item of this._items) {
759
- item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
760
- item.style.removeProperty("--wulf-masonry-w");
761
- item.style.removeProperty("--wulf-masonry-x");
762
- item.style.removeProperty("--wulf-masonry-y");
763
- item.style.removeProperty("transition-delay");
764
- }
765
- this._items = [];
766
- }
767
- };
768
- Masonry._i18n = masonryI18n;
769
- Masonry.i18n = masonryI18n;
770
-
771
- // src/masonry/index.ts
772
- var index_default = Masonry;
773
- if (typeof window !== "undefined") {
774
- const win = window;
775
- const wulfNamespace = win.Wulf || {};
776
- win.Wulf = wulfNamespace;
777
- wulfNamespace.Masonry = Object.assign(Masonry, {
778
- Masonry,
779
- LayoutEngine,
780
- i18n: masonryI18n
781
- });
782
- }
783
- //# sourceMappingURL=masonry.cjs.js.map