wulf.js 2.1.1 → 2.2.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 +217 -11
- package/changelog.md +50 -0
- package/dist/anchor.esm.js +9 -0
- package/dist/anchor.esm.js.map +7 -0
- package/dist/anchor.global.js +695 -0
- package/dist/anchor.global.js.map +7 -0
- package/dist/anchor.global.min.js +6 -0
- package/dist/anchor.global.min.js.map +7 -0
- package/dist/autosize.css +1 -0
- package/dist/autosize.css.map +7 -0
- package/dist/autosize.esm.js +10 -0
- package/dist/autosize.esm.js.map +7 -0
- package/dist/autosize.global.js +657 -0
- package/dist/autosize.global.js.map +7 -0
- package/dist/autosize.global.min.js +6 -0
- package/dist/autosize.global.min.js.map +7 -0
- package/dist/autosize.layered.css +1 -0
- package/dist/autosize.layered.css.map +7 -0
- package/dist/chunks/chunk-22AIMRD5.js +119 -0
- package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
- package/dist/chunks/chunk-5N2IRGDM.js +766 -0
- package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
- package/dist/chunks/chunk-72FVCNNZ.js +863 -0
- package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
- package/dist/chunks/chunk-AXZYYW7H.js +865 -0
- package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
- package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
- package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
- package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
- package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
- package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
- package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
- package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
- package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
- package/dist/chunks/chunk-QV46A7FV.js +197 -0
- package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
- package/dist/chunks/chunk-SXLUXN6W.js +612 -0
- package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
- package/dist/chunks/chunk-T2H4EJCW.js +621 -0
- package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
- package/dist/chunks/chunk-TILLYEF2.js +6044 -0
- package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
- package/dist/chunks/chunk-VJO22BAT.js +72 -0
- package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
- package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
- package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
- package/dist/focus-trap.esm.js +6 -594
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +176 -61
- 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 +79 -10448
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +3660 -202
- package/dist/index.global.js.map +4 -4
- package/dist/index.global.min.js +6 -3
- package/dist/index.global.min.js.map +4 -4
- package/dist/mask.esm.js +16 -6094
- package/dist/mask.esm.js.map +4 -4
- package/dist/mask.global.js +44 -55
- package/dist/mask.global.js.map +3 -3
- package/dist/mask.global.min.js +3 -3
- package/dist/mask.global.min.js.map +4 -4
- package/dist/masonry.esm.js +15 -1158
- package/dist/masonry.esm.js.map +4 -4
- package/dist/masonry.global.js +84 -94
- 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/scroll.css +1 -1
- package/dist/scroll.css.map +2 -2
- package/dist/scroll.esm.js +14 -1252
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +64 -58
- package/dist/scroll.global.js.map +3 -3
- package/dist/scroll.global.min.js +3 -3
- package/dist/scroll.global.min.js.map +4 -4
- package/dist/scroll.layered.css +1 -1
- package/dist/scroll.layered.css.map +2 -2
- package/dist/shortcut.esm.js +6 -901
- package/dist/shortcut.esm.js.map +4 -4
- package/dist/shortcut.global.js +43 -36
- package/dist/shortcut.global.js.map +3 -3
- package/dist/shortcut.global.min.js +6 -3
- package/dist/shortcut.global.min.js.map +4 -4
- package/dist/size-report.json +319 -0
- package/dist/sortable.css +1 -0
- package/dist/sortable.css.map +7 -0
- package/dist/sortable.esm.js +22 -0
- package/dist/sortable.esm.js.map +7 -0
- package/dist/sortable.global.js +1477 -0
- package/dist/sortable.global.js.map +7 -0
- package/dist/sortable.global.min.js +6 -0
- package/dist/sortable.global.min.js.map +7 -0
- package/dist/sortable.layered.css +1 -0
- package/dist/sortable.layered.css.map +7 -0
- package/dist/sri-manifest.json +64 -0
- package/dist/toast.css +1 -1
- package/dist/toast.css.map +2 -2
- package/dist/toast.esm.js +19 -1208
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +314 -111
- package/dist/toast.global.js.map +3 -3
- package/dist/toast.global.min.js +3 -3
- package/dist/toast.global.min.js.map +4 -4
- package/dist/toast.layered.css +1 -1
- package/dist/toast.layered.css.map +2 -2
- package/dist/types/anchor/Anchor.d.ts +41 -0
- package/dist/types/anchor/index.d.ts +3 -0
- package/dist/types/anchor/types.d.ts +115 -0
- package/dist/types/autosize/Autosize.d.ts +71 -0
- package/dist/types/autosize/index.d.ts +3 -0
- package/dist/types/autosize/types.d.ts +66 -0
- package/dist/types/common/AuditableComponent.d.ts +1 -1
- package/dist/types/common/registry.d.ts +40 -0
- package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
- package/dist/types/index.d.ts +13 -1
- package/dist/types/scroll/types.d.ts +6 -0
- package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
- package/dist/types/shortcut/types.d.ts +5 -0
- package/dist/types/sortable/Sortable.d.ts +75 -0
- package/dist/types/sortable/i18n/en.d.ts +2 -0
- package/dist/types/sortable/i18n/fr.d.ts +2 -0
- package/dist/types/sortable/i18n/index.d.ts +9 -0
- package/dist/types/sortable/i18n/types.d.ts +15 -0
- package/dist/types/sortable/index.d.ts +4 -0
- package/dist/types/sortable/types.d.ts +112 -0
- package/dist/types/toast/Toast.d.ts +6 -1
- package/dist/types/toast/ToastInstance.d.ts +7 -0
- package/dist/types/toast/ToastManager.d.ts +2 -2
- package/dist/types/toast/types.d.ts +27 -1
- package/dist/types/undo/UndoManager.d.ts +112 -0
- package/dist/types/undo/i18n/en.d.ts +2 -0
- package/dist/types/undo/i18n/fr.d.ts +2 -0
- package/dist/types/undo/i18n/index.d.ts +9 -0
- package/dist/types/undo/i18n/types.d.ts +6 -0
- package/dist/types/undo/index.d.ts +5 -0
- package/dist/types/undo/types.d.ts +106 -0
- package/dist/undo.esm.js +23 -0
- package/dist/undo.esm.js.map +7 -0
- package/dist/undo.global.js +1029 -0
- package/dist/undo.global.js.map +7 -0
- package/dist/undo.global.min.js +6 -0
- package/dist/undo.global.min.js.map +7 -0
- package/package.json +54 -5
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LocalizedComponent,
|
|
3
|
+
createI18nManager
|
|
4
|
+
} from "./chunk-QV46A7FV.js";
|
|
5
|
+
import {
|
|
6
|
+
getDeepActiveElement,
|
|
7
|
+
parseCssDurationMs,
|
|
8
|
+
waitForAnimations
|
|
9
|
+
} from "./chunk-22AIMRD5.js";
|
|
10
|
+
import {
|
|
11
|
+
__export
|
|
12
|
+
} from "./chunk-VJO22BAT.js";
|
|
13
|
+
|
|
14
|
+
// src/masonry/index.ts
|
|
15
|
+
var masonry_exports = {};
|
|
16
|
+
__export(masonry_exports, {
|
|
17
|
+
LayoutEngine: () => LayoutEngine,
|
|
18
|
+
LocalizedComponent: () => LocalizedComponent,
|
|
19
|
+
Masonry: () => Masonry,
|
|
20
|
+
createI18nManager: () => createI18nManager,
|
|
21
|
+
default: () => masonry_default,
|
|
22
|
+
masonryEn: () => masonryEn,
|
|
23
|
+
masonryFr: () => masonryFr,
|
|
24
|
+
masonryI18n: () => masonryI18n
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// src/masonry/LayoutEngine.ts
|
|
28
|
+
var LayoutEngine = class {
|
|
29
|
+
/**
|
|
30
|
+
* Normalise les gouttières horizontales et verticales.
|
|
31
|
+
*/
|
|
32
|
+
static parseGutter(gutterOption) {
|
|
33
|
+
if (typeof gutterOption === "number") {
|
|
34
|
+
const v = Number.isFinite(gutterOption) ? Math.max(0, gutterOption) : 0;
|
|
35
|
+
return { x: v, y: v };
|
|
36
|
+
}
|
|
37
|
+
if (gutterOption && typeof gutterOption === "object") {
|
|
38
|
+
const rawX = Number(gutterOption.x);
|
|
39
|
+
const rawY = Number(gutterOption.y);
|
|
40
|
+
return {
|
|
41
|
+
x: Number.isFinite(rawX) ? Math.max(0, rawX) : 0,
|
|
42
|
+
y: Number.isFinite(rawY) ? Math.max(0, rawY) : 0
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return { x: 0, y: 0 };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Résout la largeur effective d'une colonne en pixels.
|
|
49
|
+
*/
|
|
50
|
+
static resolveColumnWidth(container, firstItem, columnWidthOption) {
|
|
51
|
+
if (typeof columnWidthOption === "number" && Number.isFinite(columnWidthOption) && columnWidthOption > 0) {
|
|
52
|
+
return columnWidthOption;
|
|
53
|
+
}
|
|
54
|
+
if (typeof columnWidthOption === "string") {
|
|
55
|
+
const trimmed = columnWidthOption.trim();
|
|
56
|
+
if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
|
|
57
|
+
const parsed = parseFloat(trimmed);
|
|
58
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
59
|
+
if (trimmed.endsWith("%")) {
|
|
60
|
+
const containerW2 = container.getBoundingClientRect().width;
|
|
61
|
+
const resolvedPct = containerW2 * parsed / 100;
|
|
62
|
+
if (resolvedPct > 0) return resolvedPct;
|
|
63
|
+
} else {
|
|
64
|
+
return parsed;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else if (trimmed) {
|
|
68
|
+
let el = null;
|
|
69
|
+
try {
|
|
70
|
+
el = container.querySelector(trimmed);
|
|
71
|
+
} catch {
|
|
72
|
+
el = null;
|
|
73
|
+
}
|
|
74
|
+
if (el) {
|
|
75
|
+
const w = el.getBoundingClientRect().width;
|
|
76
|
+
if (Number.isFinite(w) && w > 0) return w;
|
|
77
|
+
}
|
|
78
|
+
const parsed = parseFloat(trimmed);
|
|
79
|
+
if (Number.isFinite(parsed) && parsed > 0) {
|
|
80
|
+
return parsed;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (columnWidthOption instanceof HTMLElement) {
|
|
85
|
+
const w = columnWidthOption.getBoundingClientRect().width;
|
|
86
|
+
if (w > 0) return w;
|
|
87
|
+
}
|
|
88
|
+
if (firstItem) {
|
|
89
|
+
const w = firstItem.getBoundingClientRect().width;
|
|
90
|
+
if (w > 0) return w;
|
|
91
|
+
}
|
|
92
|
+
const containerW = container.getBoundingClientRect().width;
|
|
93
|
+
return containerW > 0 ? containerW : 200;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Extrait le facteur d'étalement (span) d'un item sur plusieurs colonnes.
|
|
97
|
+
*/
|
|
98
|
+
static getItemSpan(item, colWidth, gutterX, maxCols) {
|
|
99
|
+
const dataSpan = item.getAttribute("data-masonry-span") || item.dataset.masonrySpan;
|
|
100
|
+
if (dataSpan) {
|
|
101
|
+
const parsed = parseInt(dataSpan, 10);
|
|
102
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
103
|
+
return Math.min(maxCols, parsed);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const cls of item.classList) {
|
|
107
|
+
const match = /^(?:span|col-span)-(\d+)$/.exec(cls);
|
|
108
|
+
if (match && match[1]) {
|
|
109
|
+
const parsed = parseInt(match[1], 10);
|
|
110
|
+
if (!isNaN(parsed) && parsed > 0) {
|
|
111
|
+
return Math.min(maxCols, parsed);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Calcule les positions optimales de tous les items.
|
|
119
|
+
*/
|
|
120
|
+
static calculate(container, items, options) {
|
|
121
|
+
const containerRect = container.getBoundingClientRect();
|
|
122
|
+
const containerWidth = containerRect.width;
|
|
123
|
+
const { x: gutterX, y: gutterY } = this.parseGutter(options.gutter);
|
|
124
|
+
if (containerWidth <= 0 || items.length === 0) {
|
|
125
|
+
return {
|
|
126
|
+
cols: 1,
|
|
127
|
+
colWidth: containerWidth,
|
|
128
|
+
gutterX,
|
|
129
|
+
gutterY,
|
|
130
|
+
containerHeight: 0,
|
|
131
|
+
containerWidth,
|
|
132
|
+
positions: []
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const firstItem = items[0] || null;
|
|
136
|
+
let colWidth = this.resolveColumnWidth(container, firstItem, options.columnWidth);
|
|
137
|
+
const denom = colWidth + gutterX;
|
|
138
|
+
let cols = denom > 0 ? Math.floor((containerWidth + gutterX) / denom) : 1;
|
|
139
|
+
if (!Number.isFinite(cols) || cols < 1) {
|
|
140
|
+
cols = 1;
|
|
141
|
+
} else if (cols > 1e3) {
|
|
142
|
+
cols = 1e3;
|
|
143
|
+
}
|
|
144
|
+
if (!options.columnWidth && cols > 1) {
|
|
145
|
+
colWidth = (containerWidth - (cols - 1) * gutterX) / cols;
|
|
146
|
+
}
|
|
147
|
+
const fittedWidth = options.fitWidth ? cols * colWidth + (cols - 1) * gutterX : void 0;
|
|
148
|
+
const colHeights = new Array(cols).fill(0);
|
|
149
|
+
const positions = [];
|
|
150
|
+
const itemHeights = items.map((item) => {
|
|
151
|
+
const h = item.classList.contains("wulf-masonry-item--hidden") && item.offsetHeight > 0 ? item.offsetHeight : item.getBoundingClientRect().height;
|
|
152
|
+
return h > 0 ? h : 50;
|
|
153
|
+
});
|
|
154
|
+
const isRtl = typeof window !== "undefined" && typeof window.getComputedStyle === "function" && window.getComputedStyle(container).direction === "rtl";
|
|
155
|
+
let currentHCol = 0;
|
|
156
|
+
for (let i = 0; i < items.length; i++) {
|
|
157
|
+
const item = items[i];
|
|
158
|
+
const itemH = itemHeights[i];
|
|
159
|
+
const span = this.getItemSpan(item, colWidth, gutterX, cols);
|
|
160
|
+
let targetCol = 0;
|
|
161
|
+
let targetY = 0;
|
|
162
|
+
if (options.horizontalOrder) {
|
|
163
|
+
if (currentHCol + span > cols) {
|
|
164
|
+
currentHCol = 0;
|
|
165
|
+
}
|
|
166
|
+
targetCol = currentHCol;
|
|
167
|
+
let maxY = 0;
|
|
168
|
+
for (let s = 0; s < span; s++) {
|
|
169
|
+
if (colHeights[targetCol + s] > maxY) {
|
|
170
|
+
maxY = colHeights[targetCol + s];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
targetY = maxY;
|
|
174
|
+
currentHCol = (targetCol + span) % cols;
|
|
175
|
+
} else {
|
|
176
|
+
if (span === 1) {
|
|
177
|
+
let minH = colHeights[0];
|
|
178
|
+
targetCol = 0;
|
|
179
|
+
for (let c = 1; c < cols; c++) {
|
|
180
|
+
if (colHeights[c] < minH) {
|
|
181
|
+
minH = colHeights[c];
|
|
182
|
+
targetCol = c;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
targetY = minH;
|
|
186
|
+
} else {
|
|
187
|
+
let bestMax = Infinity;
|
|
188
|
+
targetCol = 0;
|
|
189
|
+
for (let c = 0; c <= cols - span; c++) {
|
|
190
|
+
let maxInSpan = 0;
|
|
191
|
+
for (let s = 0; s < span; s++) {
|
|
192
|
+
if (colHeights[c + s] > maxInSpan) {
|
|
193
|
+
maxInSpan = colHeights[c + s];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (maxInSpan < bestMax) {
|
|
197
|
+
bestMax = maxInSpan;
|
|
198
|
+
targetCol = c;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
targetY = bestMax;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const itemW = span * colWidth + (span - 1) * gutterX;
|
|
205
|
+
const effectiveWidth = fittedWidth !== void 0 ? fittedWidth : containerWidth;
|
|
206
|
+
const rawX = targetCol * (colWidth + gutterX);
|
|
207
|
+
const targetX = isRtl ? Math.max(0, effectiveWidth - rawX - itemW) : rawX;
|
|
208
|
+
positions.push({
|
|
209
|
+
element: item,
|
|
210
|
+
x: targetX,
|
|
211
|
+
y: targetY,
|
|
212
|
+
width: itemW,
|
|
213
|
+
height: itemH,
|
|
214
|
+
column: targetCol,
|
|
215
|
+
span
|
|
216
|
+
});
|
|
217
|
+
const nextY = targetY + itemH + gutterY;
|
|
218
|
+
for (let s = 0; s < span; s++) {
|
|
219
|
+
colHeights[targetCol + s] = nextY;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let maxColH = 0;
|
|
223
|
+
for (let c = 0; c < cols; c++) {
|
|
224
|
+
if (colHeights[c] > maxColH) {
|
|
225
|
+
maxColH = colHeights[c];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const containerHeight = Math.max(0, maxColH > 0 ? maxColH - gutterY : 0);
|
|
229
|
+
return {
|
|
230
|
+
cols,
|
|
231
|
+
colWidth,
|
|
232
|
+
gutterX,
|
|
233
|
+
gutterY,
|
|
234
|
+
containerHeight,
|
|
235
|
+
containerWidth,
|
|
236
|
+
fittedWidth,
|
|
237
|
+
positions
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/masonry/i18n/fr.ts
|
|
243
|
+
var masonryFr = {
|
|
244
|
+
gallery: "Galerie en grille asym\xE9trique"
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/masonry/i18n/en.ts
|
|
248
|
+
var masonryEn = {
|
|
249
|
+
gallery: "Masonry grid gallery"
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
// src/masonry/i18n/index.ts
|
|
253
|
+
var masonryI18n = createI18nManager("fr", {
|
|
254
|
+
fr: masonryFr,
|
|
255
|
+
en: masonryEn
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// src/masonry/Masonry.ts
|
|
259
|
+
var NATIVE_STRUCTURAL_TAGS = /* @__PURE__ */ new Set(["UL", "OL", "MAIN", "NAV", "ASIDE", "ARTICLE", "SECTION"]);
|
|
260
|
+
var Masonry = class extends LocalizedComponent {
|
|
261
|
+
static _i18n = masonryI18n;
|
|
262
|
+
static i18n = masonryI18n;
|
|
263
|
+
root;
|
|
264
|
+
isNativeCSSGrid = false;
|
|
265
|
+
_items = [];
|
|
266
|
+
options;
|
|
267
|
+
resizeObserver = null;
|
|
268
|
+
itemResizeObserver = null;
|
|
269
|
+
observedItems = /* @__PURE__ */ new Set();
|
|
270
|
+
observedItemHeights = /* @__PURE__ */ new WeakMap();
|
|
271
|
+
removingItems = /* @__PURE__ */ new Set();
|
|
272
|
+
layoutRafId = null;
|
|
273
|
+
lastObservedWidth = 0;
|
|
274
|
+
isDestroyed = false;
|
|
275
|
+
hasExplicitAriaRole = false;
|
|
276
|
+
wasRoleInferred = false;
|
|
277
|
+
wasAriaLabelInferred = false;
|
|
278
|
+
hasExplicitAriaLabel = false;
|
|
279
|
+
lastInferredAriaLabel = "";
|
|
280
|
+
abortController = new AbortController();
|
|
281
|
+
watchedImages = /* @__PURE__ */ new WeakSet();
|
|
282
|
+
originalContainerStyles;
|
|
283
|
+
constructor(target, options = {}) {
|
|
284
|
+
super(options.i18n);
|
|
285
|
+
if (typeof target === "string") {
|
|
286
|
+
if (typeof document === "undefined") {
|
|
287
|
+
throw new Error("[Wulf.Masonry] Impossible de r\xE9soudre un s\xE9lecteur CSS sans environnement DOM (document).");
|
|
288
|
+
}
|
|
289
|
+
let el = null;
|
|
290
|
+
try {
|
|
291
|
+
el = document.querySelector(target);
|
|
292
|
+
} catch {
|
|
293
|
+
el = null;
|
|
294
|
+
}
|
|
295
|
+
if (!el) {
|
|
296
|
+
throw new Error(`[Wulf.Masonry] Conteneur introuvable pour le s\xE9lecteur : "${target}"`);
|
|
297
|
+
}
|
|
298
|
+
this.root = el;
|
|
299
|
+
} else if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
|
|
300
|
+
this.root = target;
|
|
301
|
+
} else {
|
|
302
|
+
throw new Error("[Wulf.Masonry] Cible invalide : fournissez un \xE9l\xE9ment HTMLElement ou un s\xE9lecteur valide.");
|
|
303
|
+
}
|
|
304
|
+
this.originalContainerStyles = {
|
|
305
|
+
height: this.root.style.height,
|
|
306
|
+
width: this.root.style.width
|
|
307
|
+
};
|
|
308
|
+
this.hasExplicitAriaRole = Boolean(options.ariaRole);
|
|
309
|
+
this.hasExplicitAriaLabel = Boolean(options.ariaLabel || options.i18n?.gallery);
|
|
310
|
+
this.options = {
|
|
311
|
+
itemSelector: options.itemSelector || "> *",
|
|
312
|
+
columnWidth: options.columnWidth ?? 0,
|
|
313
|
+
gutter: options.gutter ?? 0,
|
|
314
|
+
percentPosition: Boolean(options.percentPosition),
|
|
315
|
+
fitWidth: Boolean(options.fitWidth),
|
|
316
|
+
horizontalOrder: Boolean(options.horizontalOrder),
|
|
317
|
+
transitionDuration: options.transitionDuration !== void 0 ? options.transitionDuration : 300,
|
|
318
|
+
stagger: options.stagger || 0,
|
|
319
|
+
resize: options.resize !== false,
|
|
320
|
+
autoImages: options.autoImages !== false,
|
|
321
|
+
useNativeCSSGrid: options.useNativeCSSGrid !== false,
|
|
322
|
+
ariaRole: options.ariaRole || "region",
|
|
323
|
+
ariaLabel: options.ariaLabel || this.t("gallery"),
|
|
324
|
+
i18n: options.i18n || {},
|
|
325
|
+
onLayout: options.onLayout || (() => {
|
|
326
|
+
}),
|
|
327
|
+
onItemPlaced: options.onItemPlaced || (() => {
|
|
328
|
+
}),
|
|
329
|
+
audit: options.audit ?? true
|
|
330
|
+
};
|
|
331
|
+
const supportsNativeCSS = typeof CSS !== "undefined" && typeof CSS.supports === "function" && (CSS.supports("display", "grid-lanes") || CSS.supports("grid-template-rows", "masonry"));
|
|
332
|
+
if (this.options.useNativeCSSGrid && supportsNativeCSS) {
|
|
333
|
+
this.isNativeCSSGrid = true;
|
|
334
|
+
this.root.classList.add("wulf-masonry", "wulf-masonry--native");
|
|
335
|
+
this.syncNativeGridVariables();
|
|
336
|
+
} else {
|
|
337
|
+
this.root.classList.add("wulf-masonry");
|
|
338
|
+
}
|
|
339
|
+
this.initAccessibility();
|
|
340
|
+
this.applyTransitionDuration();
|
|
341
|
+
this.reloadItems();
|
|
342
|
+
this.initObservers();
|
|
343
|
+
this.initImages();
|
|
344
|
+
this.layout();
|
|
345
|
+
this.runAuditWarning(this.options.audit);
|
|
346
|
+
}
|
|
347
|
+
get items() {
|
|
348
|
+
return [...this._items];
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Initialise les attributs WAI-ARIA du conteneur.
|
|
352
|
+
*/
|
|
353
|
+
initAccessibility() {
|
|
354
|
+
if (this.options.ariaRole && !this.root.hasAttribute("role") && (this.hasExplicitAriaRole || !NATIVE_STRUCTURAL_TAGS.has(this.root.tagName))) {
|
|
355
|
+
this.root.setAttribute("role", this.options.ariaRole);
|
|
356
|
+
this.wasRoleInferred = true;
|
|
357
|
+
}
|
|
358
|
+
const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("gallery");
|
|
359
|
+
if (label && !this.root.hasAttribute("aria-label") && !this.root.hasAttribute("aria-labelledby")) {
|
|
360
|
+
this.root.setAttribute("aria-label", label);
|
|
361
|
+
this.lastInferredAriaLabel = label;
|
|
362
|
+
this.wasAriaLabelInferred = true;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Synchronise dynamiquement le libellé ARIA si la langue globale change après montage.
|
|
367
|
+
*/
|
|
368
|
+
syncAccessibilityLabels() {
|
|
369
|
+
if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
|
|
370
|
+
const currentAttr = this.root.getAttribute("aria-label");
|
|
371
|
+
if (currentAttr === this.lastInferredAriaLabel) {
|
|
372
|
+
const nextLabel = this.t("gallery");
|
|
373
|
+
this.root.setAttribute("aria-label", nextLabel);
|
|
374
|
+
this.lastInferredAriaLabel = nextLabel;
|
|
375
|
+
this.options.ariaLabel = nextLabel;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Configure les variables CSS de transition sur le conteneur.
|
|
381
|
+
*/
|
|
382
|
+
applyTransitionDuration() {
|
|
383
|
+
const dur = this.options.transitionDuration;
|
|
384
|
+
let durValue = "300ms";
|
|
385
|
+
if (typeof dur === "number" && Number.isFinite(dur) && dur >= 0) {
|
|
386
|
+
durValue = `${Math.min(dur, 6e4)}ms`;
|
|
387
|
+
} else if (typeof dur === "string" && /^\s*(?:\d+(?:\.\d+)?|\.\d+)(ms|s)\s*$/i.test(dur)) {
|
|
388
|
+
const parsedMs = parseCssDurationMs(dur, 300, 6e4);
|
|
389
|
+
durValue = parsedMs >= 6e4 ? "60000ms" : dur.trim();
|
|
390
|
+
}
|
|
391
|
+
this.root.style.setProperty("--wulf-masonry-duration", durValue);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Réindexe les éléments enfants ciblés par la disposition.
|
|
395
|
+
*/
|
|
396
|
+
reloadItems() {
|
|
397
|
+
if (this.isDestroyed) return;
|
|
398
|
+
let matched = [];
|
|
399
|
+
if (this.options.itemSelector === "> *") {
|
|
400
|
+
matched = Array.from(this.root.children).filter(
|
|
401
|
+
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
402
|
+
);
|
|
403
|
+
} else {
|
|
404
|
+
try {
|
|
405
|
+
const rawSelector = this.options.itemSelector.trim();
|
|
406
|
+
const selector = rawSelector.startsWith(">") ? `:scope ${rawSelector}` : rawSelector;
|
|
407
|
+
matched = Array.from(this.root.querySelectorAll(selector)).filter(
|
|
408
|
+
(el) => el.parentElement === this.root && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
409
|
+
);
|
|
410
|
+
} catch {
|
|
411
|
+
matched = Array.from(this.root.children).filter(
|
|
412
|
+
(el) => el instanceof HTMLElement && !el.hasAttribute("data-masonry-ignore") && !this.removingItems.has(el)
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (this.itemResizeObserver) {
|
|
417
|
+
const nextSet = new Set(matched);
|
|
418
|
+
for (const prevEl of this.observedItems) {
|
|
419
|
+
if (!nextSet.has(prevEl)) {
|
|
420
|
+
this.itemResizeObserver.unobserve(prevEl);
|
|
421
|
+
this.observedItems.delete(prevEl);
|
|
422
|
+
this.observedItemHeights.delete(prevEl);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
this._items = matched;
|
|
427
|
+
for (const item of this._items) {
|
|
428
|
+
item.classList.add("wulf-masonry-item");
|
|
429
|
+
if (this.itemResizeObserver && !this.observedItems.has(item)) {
|
|
430
|
+
this.itemResizeObserver.observe(item);
|
|
431
|
+
this.observedItems.add(item);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Active ResizeObserver sur le conteneur et les éléments individuels.
|
|
437
|
+
*/
|
|
438
|
+
initObservers() {
|
|
439
|
+
if (!this.options.resize || typeof ResizeObserver === "undefined") return;
|
|
440
|
+
this.lastObservedWidth = this.root.getBoundingClientRect().width;
|
|
441
|
+
this.resizeObserver = new ResizeObserver((entries) => {
|
|
442
|
+
for (const entry of entries) {
|
|
443
|
+
const currentWidth = entry.contentRect.width;
|
|
444
|
+
if (Math.abs(currentWidth - this.lastObservedWidth) >= 1) {
|
|
445
|
+
this.lastObservedWidth = currentWidth;
|
|
446
|
+
this.scheduleLayout();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
this.resizeObserver.observe(this.root);
|
|
451
|
+
this.itemResizeObserver = new ResizeObserver((entries) => {
|
|
452
|
+
let heightChanged = false;
|
|
453
|
+
for (const entry of entries) {
|
|
454
|
+
const newH = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;
|
|
455
|
+
const prevH = this.observedItemHeights.get(entry.target);
|
|
456
|
+
if (prevH === void 0 || Math.abs(newH - prevH) >= 1) {
|
|
457
|
+
this.observedItemHeights.set(entry.target, newH);
|
|
458
|
+
if (prevH !== void 0) {
|
|
459
|
+
heightChanged = true;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (heightChanged) {
|
|
464
|
+
this.scheduleLayout();
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
for (const item of this._items) {
|
|
468
|
+
this.itemResizeObserver.observe(item);
|
|
469
|
+
this.observedItems.add(item);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Synchronise les variables CSS du mode natif CSS Grid Level 3 depuis les options JS.
|
|
474
|
+
*/
|
|
475
|
+
syncNativeGridVariables() {
|
|
476
|
+
const { x: gutterX, y: gutterY } = LayoutEngine.parseGutter(this.options.gutter);
|
|
477
|
+
this.root.style.setProperty("--wulf-masonry-gutter-x", `${gutterX}px`);
|
|
478
|
+
this.root.style.setProperty("--wulf-masonry-gutter-y", `${gutterY}px`);
|
|
479
|
+
if (typeof this.options.columnWidth === "number" && Number.isFinite(this.options.columnWidth) && this.options.columnWidth > 0) {
|
|
480
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${this.options.columnWidth}px`);
|
|
481
|
+
} else if (this.options.columnWidth instanceof HTMLElement) {
|
|
482
|
+
const w = this.options.columnWidth.getBoundingClientRect().width;
|
|
483
|
+
if (w > 0) {
|
|
484
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
|
|
485
|
+
}
|
|
486
|
+
} else if (typeof this.options.columnWidth === "string" && this.options.columnWidth.trim()) {
|
|
487
|
+
const trimmed = this.options.columnWidth.trim();
|
|
488
|
+
if (/^\d+(\.\d+)?(px|%)?$/i.test(trimmed)) {
|
|
489
|
+
const w = LayoutEngine.resolveColumnWidth(this.root, null, trimmed);
|
|
490
|
+
if (w > 0) {
|
|
491
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
|
|
492
|
+
}
|
|
493
|
+
} else {
|
|
494
|
+
try {
|
|
495
|
+
const el = this.root.querySelector(trimmed);
|
|
496
|
+
if (el) {
|
|
497
|
+
const w = el.getBoundingClientRect().width;
|
|
498
|
+
if (w > 0) {
|
|
499
|
+
this.root.style.setProperty("--wulf-masonry-col-min", `${w}px`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
} catch {
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Détecte les balises <img> sans dimensions prédéfinies et attend leur décodage/chargement.
|
|
509
|
+
*/
|
|
510
|
+
initImages() {
|
|
511
|
+
if (!this.options.autoImages) return;
|
|
512
|
+
const images = Array.from(this.root.querySelectorAll("img"));
|
|
513
|
+
for (const img of images) {
|
|
514
|
+
if (!img.complete && !this.watchedImages.has(img)) {
|
|
515
|
+
this.watchedImages.add(img);
|
|
516
|
+
const attachLoadListener = () => {
|
|
517
|
+
img.addEventListener("load", () => {
|
|
518
|
+
if (!this.isDestroyed) this.scheduleLayout();
|
|
519
|
+
}, { once: true, signal: this.abortController.signal });
|
|
520
|
+
};
|
|
521
|
+
if (typeof img.decode === "function") {
|
|
522
|
+
img.decode().then(() => {
|
|
523
|
+
if (!this.isDestroyed) this.scheduleLayout();
|
|
524
|
+
}).catch(() => {
|
|
525
|
+
attachLoadListener();
|
|
526
|
+
});
|
|
527
|
+
} else {
|
|
528
|
+
attachLoadListener();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Planifie un recalcul au prochain tick d'animation via requestAnimationFrame.
|
|
535
|
+
*/
|
|
536
|
+
scheduleLayout() {
|
|
537
|
+
if (this.isDestroyed) return;
|
|
538
|
+
if (typeof window === "undefined" || typeof window.requestAnimationFrame !== "function") {
|
|
539
|
+
this.layout();
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
if (this.layoutRafId !== null) {
|
|
543
|
+
window.cancelAnimationFrame(this.layoutRafId);
|
|
544
|
+
}
|
|
545
|
+
this.layoutRafId = window.requestAnimationFrame(() => {
|
|
546
|
+
this.layoutRafId = null;
|
|
547
|
+
this.layout();
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Calcule et applique les nouvelles coordonnées GPU de chaque item.
|
|
552
|
+
*/
|
|
553
|
+
layout() {
|
|
554
|
+
if (this.isDestroyed) return;
|
|
555
|
+
this.syncAccessibilityLabels();
|
|
556
|
+
if (this.isNativeCSSGrid) {
|
|
557
|
+
this.syncNativeGridVariables();
|
|
558
|
+
for (const el of this._items) {
|
|
559
|
+
el.classList.remove("wulf-masonry-item--hidden");
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
this.options.onLayout([]);
|
|
563
|
+
} catch (err) {
|
|
564
|
+
console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
|
|
565
|
+
}
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
this.root.setAttribute("aria-busy", "true");
|
|
569
|
+
let positionsResult = [];
|
|
570
|
+
try {
|
|
571
|
+
if (this.options.fitWidth && this.root.classList.contains("wulf-masonry--fit-width")) {
|
|
572
|
+
this.root.style.width = "";
|
|
573
|
+
}
|
|
574
|
+
const result = LayoutEngine.calculate(this.root, this._items, this.options);
|
|
575
|
+
positionsResult = result.positions;
|
|
576
|
+
this.root.style.height = `${result.containerHeight}px`;
|
|
577
|
+
if (this.options.fitWidth && result.fittedWidth !== void 0) {
|
|
578
|
+
this.root.style.width = `${result.fittedWidth}px`;
|
|
579
|
+
this.lastObservedWidth = result.fittedWidth;
|
|
580
|
+
this.root.classList.add("wulf-masonry--fit-width");
|
|
581
|
+
} else {
|
|
582
|
+
this.root.classList.remove("wulf-masonry--fit-width");
|
|
583
|
+
}
|
|
584
|
+
const stagger = this.options.stagger;
|
|
585
|
+
const validStagger = typeof stagger === "number" && Number.isFinite(stagger) && stagger > 0;
|
|
586
|
+
if (validStagger) {
|
|
587
|
+
this.root.style.setProperty("--wulf-masonry-stagger", `${stagger}ms`);
|
|
588
|
+
} else {
|
|
589
|
+
this.root.style.removeProperty("--wulf-masonry-stagger");
|
|
590
|
+
}
|
|
591
|
+
const hasIgnoredChildren = this._items.length !== this.root.children.length;
|
|
592
|
+
const supportsSiblingIndex = !hasIgnoredChildren && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("transition-delay", "calc(sibling-index() * 1ms)");
|
|
593
|
+
const usePercent = this.options.percentPosition && result.containerWidth > 0;
|
|
594
|
+
for (let i = 0; i < result.positions.length; i++) {
|
|
595
|
+
const pos = result.positions[i];
|
|
596
|
+
const item = pos.element;
|
|
597
|
+
if (usePercent) {
|
|
598
|
+
const wPct = Number((pos.width / result.containerWidth * 100).toFixed(4));
|
|
599
|
+
item.style.setProperty("--wulf-masonry-w", `${wPct}%`);
|
|
600
|
+
} else {
|
|
601
|
+
item.style.setProperty("--wulf-masonry-w", `${pos.width}px`);
|
|
602
|
+
}
|
|
603
|
+
item.style.setProperty("--wulf-masonry-x", `${pos.x}px`);
|
|
604
|
+
item.style.setProperty("--wulf-masonry-y", `${pos.y}px`);
|
|
605
|
+
if (validStagger && !supportsSiblingIndex) {
|
|
606
|
+
item.style.setProperty("--wulf-masonry-index", String(i));
|
|
607
|
+
} else {
|
|
608
|
+
item.style.removeProperty("--wulf-masonry-index");
|
|
609
|
+
}
|
|
610
|
+
item.classList.remove("wulf-masonry-item--hidden");
|
|
611
|
+
this.observedItemHeights.set(item, pos.height);
|
|
612
|
+
try {
|
|
613
|
+
this.options.onItemPlaced(item, pos);
|
|
614
|
+
} catch (err) {
|
|
615
|
+
console.error("[Wulf.Masonry] Erreur dans onItemPlaced:", err);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
} finally {
|
|
619
|
+
this.root.setAttribute("aria-busy", "false");
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
this.options.onLayout(positionsResult);
|
|
623
|
+
} catch (err) {
|
|
624
|
+
console.error("[Wulf.Masonry] Erreur dans onLayout:", err);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Ajoute de nouveaux éléments à la fin du conteneur.
|
|
629
|
+
*/
|
|
630
|
+
append(elements) {
|
|
631
|
+
if (this.isDestroyed) return;
|
|
632
|
+
const list = (Array.isArray(elements) ? elements : [elements]).filter(
|
|
633
|
+
(el) => el instanceof HTMLElement && !el.contains(this.root)
|
|
634
|
+
);
|
|
635
|
+
if (list.length === 0) return;
|
|
636
|
+
const frag = document.createDocumentFragment();
|
|
637
|
+
for (const el of list) {
|
|
638
|
+
if (this.isNativeCSSGrid) {
|
|
639
|
+
el.classList.add("wulf-masonry-item");
|
|
640
|
+
} else {
|
|
641
|
+
el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
642
|
+
}
|
|
643
|
+
frag.appendChild(el);
|
|
644
|
+
}
|
|
645
|
+
this.root.appendChild(frag);
|
|
646
|
+
this.reloadItems();
|
|
647
|
+
this.initImages();
|
|
648
|
+
this.layout();
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Ajoute de nouveaux éléments au début du conteneur.
|
|
652
|
+
*/
|
|
653
|
+
prepend(elements) {
|
|
654
|
+
if (this.isDestroyed) return;
|
|
655
|
+
const list = (Array.isArray(elements) ? elements : [elements]).filter(
|
|
656
|
+
(el) => el instanceof HTMLElement && !el.contains(this.root)
|
|
657
|
+
);
|
|
658
|
+
if (list.length === 0) return;
|
|
659
|
+
const first = this.root.firstChild;
|
|
660
|
+
const frag = document.createDocumentFragment();
|
|
661
|
+
for (const el of list) {
|
|
662
|
+
if (this.isNativeCSSGrid) {
|
|
663
|
+
el.classList.add("wulf-masonry-item");
|
|
664
|
+
} else {
|
|
665
|
+
el.classList.add("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
666
|
+
}
|
|
667
|
+
frag.appendChild(el);
|
|
668
|
+
}
|
|
669
|
+
this.root.insertBefore(frag, first);
|
|
670
|
+
this.reloadItems();
|
|
671
|
+
this.initImages();
|
|
672
|
+
this.layout();
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Supprime des éléments avec animation de fondu/sortie synchronisée via Web Animations API.
|
|
676
|
+
*/
|
|
677
|
+
remove(elements) {
|
|
678
|
+
if (this.isDestroyed) return;
|
|
679
|
+
const list = (Array.isArray(elements) ? elements : [elements]).filter(
|
|
680
|
+
(el) => el instanceof HTMLElement
|
|
681
|
+
);
|
|
682
|
+
if (list.length === 0) return;
|
|
683
|
+
const finalizeRemoval = () => {
|
|
684
|
+
if (this.isDestroyed) return;
|
|
685
|
+
for (const el of list) {
|
|
686
|
+
this.removingItems.delete(el);
|
|
687
|
+
if (el.parentElement === this.root) {
|
|
688
|
+
if (this.itemResizeObserver) {
|
|
689
|
+
this.itemResizeObserver.unobserve(el);
|
|
690
|
+
this.observedItems.delete(el);
|
|
691
|
+
this.observedItemHeights.delete(el);
|
|
692
|
+
}
|
|
693
|
+
this.root.removeChild(el);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
this.reloadItems();
|
|
697
|
+
this.layout();
|
|
698
|
+
};
|
|
699
|
+
const activeEl = getDeepActiveElement();
|
|
700
|
+
if (activeEl && list.some((el) => el.contains(activeEl))) {
|
|
701
|
+
const removeSet = new Set(list);
|
|
702
|
+
const firstRemovedIdx = this._items.findIndex((item) => removeSet.has(item));
|
|
703
|
+
const survivorsAfter = firstRemovedIdx >= 0 ? this._items.slice(firstRemovedIdx + 1).filter((item) => !removeSet.has(item)) : [];
|
|
704
|
+
const survivorsBefore = firstRemovedIdx > 0 ? this._items.slice(0, firstRemovedIdx).filter((item) => !removeSet.has(item)).reverse() : [];
|
|
705
|
+
const candidateItem = survivorsAfter[0] || survivorsBefore[0] || null;
|
|
706
|
+
let handoffDone = false;
|
|
707
|
+
if (candidateItem) {
|
|
708
|
+
const focusableChild = candidateItem.querySelector(
|
|
709
|
+
'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
710
|
+
);
|
|
711
|
+
const focusTarget = focusableChild || (candidateItem.tabIndex >= 0 ? candidateItem : null);
|
|
712
|
+
if (focusTarget) {
|
|
713
|
+
try {
|
|
714
|
+
focusTarget.focus({ preventScroll: true });
|
|
715
|
+
handoffDone = true;
|
|
716
|
+
} catch {
|
|
717
|
+
handoffDone = false;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
if (!handoffDone) {
|
|
722
|
+
activeEl.blur?.();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
for (const el of list) {
|
|
726
|
+
this.removingItems.add(el);
|
|
727
|
+
el.setAttribute("inert", "");
|
|
728
|
+
el.style.transitionDelay = "0ms";
|
|
729
|
+
el.classList.add("wulf-masonry-item--hidden");
|
|
730
|
+
}
|
|
731
|
+
const dur = parseCssDurationMs(this.options.transitionDuration, 300);
|
|
732
|
+
if (dur <= 0 || this.isNativeCSSGrid) {
|
|
733
|
+
finalizeRemoval();
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
this.reloadItems();
|
|
737
|
+
this.layout();
|
|
738
|
+
Promise.all(
|
|
739
|
+
list.map((el) => waitForAnimations(el, dur, this.abortController.signal))
|
|
740
|
+
).then(() => {
|
|
741
|
+
if (!this.abortController.signal.aborted) {
|
|
742
|
+
finalizeRemoval();
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Vérifie la conformité d'accessibilité WAI-ARIA de la grille Masonry
|
|
748
|
+
* et retourne la liste des contraintes manquantes.
|
|
749
|
+
*/
|
|
750
|
+
audit() {
|
|
751
|
+
const warnings = [];
|
|
752
|
+
const hasValidLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings, true);
|
|
753
|
+
const hasCustomRootAriaLabel = !this.wasAriaLabelInferred && Boolean(this.root.getAttribute("aria-label")?.trim());
|
|
754
|
+
if (!this.hasExplicitAriaLabel && !hasCustomRootAriaLabel && !hasValidLabelledby) {
|
|
755
|
+
warnings.push(
|
|
756
|
+
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour qualifier la grille (WCAG 4.1.2)."
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
const imagesWithoutAlt = Array.from(this.root.querySelectorAll("img")).filter(
|
|
760
|
+
(img) => !img.hasAttribute("alt") && img.getAttribute("aria-hidden") !== "true"
|
|
761
|
+
);
|
|
762
|
+
if (imagesWithoutAlt.length > 0) {
|
|
763
|
+
warnings.push(
|
|
764
|
+
`${imagesWithoutAlt.length} image(s) <img> d\xE9pourvue(s) d'attribut alt : renseignez alt="description" (ou alt="" si d\xE9corative) (WCAG 1.1.1).`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
const positiveTabIndexEls = Array.from(this.root.querySelectorAll("[tabindex]")).filter(
|
|
768
|
+
(el) => el.tabIndex > 0
|
|
769
|
+
);
|
|
770
|
+
if (positiveTabIndexEls.length > 0) {
|
|
771
|
+
warnings.push(
|
|
772
|
+
`${positiveTabIndexEls.length} \xE9l\xE9ment(s) avec tabindex > 0 d\xE9tect\xE9(s) : utilisez uniquement tabindex="0" ou "-1" (WCAG 2.4.3).`
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
if (!this.options.horizontalOrder && this.root.querySelector('a[href], button, input, select, textarea, [tabindex="0"]') !== null) {
|
|
776
|
+
warnings.push(
|
|
777
|
+
"Grille interactive avec horizontalOrder: false : l'ordre visuel peut diverger de l'ordre de tabulation ; envisagez horizontalOrder: true (WCAG 1.3.2 / 2.4.3)."
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
return warnings;
|
|
781
|
+
}
|
|
782
|
+
getAuditPrefix() {
|
|
783
|
+
return "Wulf.Masonry";
|
|
784
|
+
}
|
|
785
|
+
getAuditTargetLabel() {
|
|
786
|
+
return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-masonry>`;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Libère les ressources, déconnecte les observateurs et nettoie les styles injectés.
|
|
790
|
+
*/
|
|
791
|
+
destroy() {
|
|
792
|
+
if (this.isDestroyed) return;
|
|
793
|
+
this.isDestroyed = true;
|
|
794
|
+
this.abortController.abort();
|
|
795
|
+
if (this.layoutRafId !== null) {
|
|
796
|
+
if (typeof window !== "undefined" && typeof window.cancelAnimationFrame === "function") {
|
|
797
|
+
window.cancelAnimationFrame(this.layoutRafId);
|
|
798
|
+
}
|
|
799
|
+
this.layoutRafId = null;
|
|
800
|
+
}
|
|
801
|
+
if (this.resizeObserver) {
|
|
802
|
+
this.resizeObserver.disconnect();
|
|
803
|
+
this.resizeObserver = null;
|
|
804
|
+
}
|
|
805
|
+
if (this.itemResizeObserver) {
|
|
806
|
+
this.itemResizeObserver.disconnect();
|
|
807
|
+
this.itemResizeObserver = null;
|
|
808
|
+
}
|
|
809
|
+
this.root.classList.remove("wulf-masonry", "wulf-masonry--native", "wulf-masonry--fit-width");
|
|
810
|
+
this.root.removeAttribute("aria-busy");
|
|
811
|
+
if (this.wasRoleInferred && this.root.getAttribute("role") === this.options.ariaRole) {
|
|
812
|
+
this.root.removeAttribute("role");
|
|
813
|
+
}
|
|
814
|
+
if (this.wasAriaLabelInferred && this.root.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
815
|
+
this.root.removeAttribute("aria-label");
|
|
816
|
+
}
|
|
817
|
+
this.root.style.removeProperty("--wulf-masonry-duration");
|
|
818
|
+
this.root.style.removeProperty("--wulf-masonry-stagger");
|
|
819
|
+
this.root.style.removeProperty("--wulf-masonry-col-min");
|
|
820
|
+
this.root.style.removeProperty("--wulf-masonry-gutter-x");
|
|
821
|
+
this.root.style.removeProperty("--wulf-masonry-gutter-y");
|
|
822
|
+
if (this.originalContainerStyles.height) {
|
|
823
|
+
this.root.style.height = this.originalContainerStyles.height;
|
|
824
|
+
} else {
|
|
825
|
+
this.root.style.removeProperty("height");
|
|
826
|
+
}
|
|
827
|
+
if (this.originalContainerStyles.width) {
|
|
828
|
+
this.root.style.width = this.originalContainerStyles.width;
|
|
829
|
+
} else {
|
|
830
|
+
this.root.style.removeProperty("width");
|
|
831
|
+
}
|
|
832
|
+
for (const item of this.removingItems) {
|
|
833
|
+
item.removeAttribute("inert");
|
|
834
|
+
item.style.removeProperty("transition-delay");
|
|
835
|
+
item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
836
|
+
item.style.removeProperty("--wulf-masonry-w");
|
|
837
|
+
item.style.removeProperty("--wulf-masonry-x");
|
|
838
|
+
item.style.removeProperty("--wulf-masonry-y");
|
|
839
|
+
item.style.removeProperty("--wulf-masonry-index");
|
|
840
|
+
}
|
|
841
|
+
this.removingItems.clear();
|
|
842
|
+
for (const item of this._items) {
|
|
843
|
+
item.classList.remove("wulf-masonry-item", "wulf-masonry-item--hidden");
|
|
844
|
+
item.style.removeProperty("--wulf-masonry-w");
|
|
845
|
+
item.style.removeProperty("--wulf-masonry-x");
|
|
846
|
+
item.style.removeProperty("--wulf-masonry-y");
|
|
847
|
+
item.style.removeProperty("--wulf-masonry-index");
|
|
848
|
+
}
|
|
849
|
+
this._items = [];
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
// src/masonry/index.ts
|
|
854
|
+
var masonry_default = Masonry;
|
|
855
|
+
|
|
856
|
+
export {
|
|
857
|
+
LayoutEngine,
|
|
858
|
+
masonryFr,
|
|
859
|
+
masonryEn,
|
|
860
|
+
masonryI18n,
|
|
861
|
+
Masonry,
|
|
862
|
+
masonry_default,
|
|
863
|
+
masonry_exports
|
|
864
|
+
};
|
|
865
|
+
//# sourceMappingURL=chunk-AXZYYW7H.js.map
|