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/scroll.global.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var __WulfIIFE = (() => {
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -31,6 +31,33 @@ var Wulf = (() => {
|
|
|
31
31
|
scrollI18n: () => scrollI18n
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
+
// src/common/dom.ts
|
|
35
|
+
function getSafeWulfNamespace() {
|
|
36
|
+
if (typeof window === "undefined") return null;
|
|
37
|
+
const win = window;
|
|
38
|
+
const existing = win.Wulf;
|
|
39
|
+
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
40
|
+
const fresh = {};
|
|
41
|
+
win.Wulf = fresh;
|
|
42
|
+
return fresh;
|
|
43
|
+
}
|
|
44
|
+
return existing;
|
|
45
|
+
}
|
|
46
|
+
function safeMove(parent, node, referenceNode = null) {
|
|
47
|
+
const moveBefore = parent.moveBefore;
|
|
48
|
+
if (typeof moveBefore === "function" && node.isConnected && parent.isConnected && typeof parent.getRootNode === "function" && typeof node.getRootNode === "function" && parent.getRootNode() === node.getRootNode()) {
|
|
49
|
+
try {
|
|
50
|
+
moveBefore.call(parent, node, referenceNode);
|
|
51
|
+
return;
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
parent.insertBefore(node, referenceNode);
|
|
56
|
+
}
|
|
57
|
+
function prefersReducedMotion() {
|
|
58
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
59
|
+
}
|
|
60
|
+
|
|
34
61
|
// src/common/AuditableComponent.ts
|
|
35
62
|
var AuditableComponent = class {
|
|
36
63
|
/**
|
|
@@ -63,8 +90,11 @@ var Wulf = (() => {
|
|
|
63
90
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
64
91
|
if (!rawValue) return false;
|
|
65
92
|
const doc = element.ownerDocument || document;
|
|
93
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
66
94
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
67
|
-
const isValid = ids.length > 0 && ids.every(
|
|
95
|
+
const isValid = ids.length > 0 && ids.every(
|
|
96
|
+
(id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
|
|
97
|
+
);
|
|
68
98
|
if (!isValid) {
|
|
69
99
|
warnings.push(
|
|
70
100
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -76,6 +106,7 @@ var Wulf = (() => {
|
|
|
76
106
|
|
|
77
107
|
// src/common/LocalizedComponent.ts
|
|
78
108
|
var LocalizedComponent = class extends AuditableComponent {
|
|
109
|
+
static _i18n;
|
|
79
110
|
/**
|
|
80
111
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
81
112
|
*/
|
|
@@ -126,6 +157,10 @@ var Wulf = (() => {
|
|
|
126
157
|
static t(key, instanceOverride) {
|
|
127
158
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
128
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Surcharges de localisation spécifiques à cette instance.
|
|
162
|
+
*/
|
|
163
|
+
i18nOverrides;
|
|
129
164
|
constructor(i18nOverrides) {
|
|
130
165
|
super();
|
|
131
166
|
this.i18nOverrides = i18nOverrides;
|
|
@@ -140,35 +175,49 @@ var Wulf = (() => {
|
|
|
140
175
|
};
|
|
141
176
|
|
|
142
177
|
// src/common/i18n.ts
|
|
178
|
+
var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
179
|
+
function isSafeKey(key) {
|
|
180
|
+
return Boolean(key) && !FORBIDDEN_KEYS.has(key);
|
|
181
|
+
}
|
|
143
182
|
function normalizeLocaleCode(locale) {
|
|
144
|
-
|
|
183
|
+
const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
|
|
184
|
+
return isSafeKey(norm) ? norm : "";
|
|
145
185
|
}
|
|
146
186
|
function getPrimaryLanguage(normalizedLocale) {
|
|
147
187
|
const dashIndex = normalizedLocale.indexOf("-");
|
|
148
|
-
|
|
188
|
+
const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
|
|
189
|
+
return primary && isSafeKey(primary) ? primary : null;
|
|
149
190
|
}
|
|
150
191
|
function assignDefined(target, source) {
|
|
151
|
-
if (!source) return target;
|
|
192
|
+
if (!source || typeof source !== "object") return target;
|
|
152
193
|
for (const key of Object.keys(source)) {
|
|
153
|
-
if (source[key] !== void 0) {
|
|
194
|
+
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
154
195
|
target[key] = source[key];
|
|
155
196
|
}
|
|
156
197
|
}
|
|
157
198
|
return target;
|
|
158
199
|
}
|
|
159
200
|
function createI18nManager(defaultLocale, locales) {
|
|
160
|
-
const fallbackLocale = normalizeLocaleCode(defaultLocale);
|
|
161
|
-
const initialLocales =
|
|
201
|
+
const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
|
|
202
|
+
const initialLocales = /* @__PURE__ */ Object.create(null);
|
|
162
203
|
for (const [loc, dict] of Object.entries(locales)) {
|
|
163
|
-
|
|
204
|
+
const norm = normalizeLocaleCode(loc);
|
|
205
|
+
if (norm) {
|
|
206
|
+
initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
207
|
+
}
|
|
164
208
|
}
|
|
165
209
|
let currentLocale = fallbackLocale;
|
|
166
|
-
let activeLocales =
|
|
167
|
-
|
|
210
|
+
let activeLocales = /* @__PURE__ */ Object.create(null);
|
|
211
|
+
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
212
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
213
|
+
}
|
|
214
|
+
let globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
168
215
|
function resolveActiveDictionaries() {
|
|
169
216
|
const dicts = [];
|
|
170
|
-
|
|
171
|
-
|
|
217
|
+
if (isSafeKey(currentLocale)) {
|
|
218
|
+
const exact = activeLocales[currentLocale];
|
|
219
|
+
if (exact) dicts.push(exact);
|
|
220
|
+
}
|
|
172
221
|
const primary = getPrimaryLanguage(currentLocale);
|
|
173
222
|
if (primary && activeLocales[primary]) {
|
|
174
223
|
dicts.push(activeLocales[primary]);
|
|
@@ -177,24 +226,33 @@ var Wulf = (() => {
|
|
|
177
226
|
}
|
|
178
227
|
return {
|
|
179
228
|
setLocale(locale) {
|
|
180
|
-
if (locale && locale.trim()) {
|
|
181
|
-
|
|
229
|
+
if (locale && typeof locale === "string" && locale.trim()) {
|
|
230
|
+
const norm = normalizeLocaleCode(locale);
|
|
231
|
+
if (norm) {
|
|
232
|
+
currentLocale = norm;
|
|
233
|
+
}
|
|
182
234
|
}
|
|
183
235
|
},
|
|
184
236
|
getLocale() {
|
|
185
237
|
return currentLocale;
|
|
186
238
|
},
|
|
187
239
|
registerLocale(locale, translations) {
|
|
188
|
-
if (!locale || !locale.trim() || !translations) return;
|
|
240
|
+
if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
|
|
189
241
|
const norm = normalizeLocaleCode(locale);
|
|
190
|
-
|
|
242
|
+
if (!norm) return;
|
|
243
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
|
|
244
|
+
activeLocales[norm] = assignDefined(base, translations);
|
|
191
245
|
},
|
|
192
246
|
setI18n(overrides) {
|
|
193
|
-
if (!overrides) return;
|
|
194
|
-
|
|
247
|
+
if (!overrides || typeof overrides !== "object") return;
|
|
248
|
+
const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
|
|
249
|
+
globalOverrides = assignDefined(base, overrides);
|
|
195
250
|
},
|
|
196
251
|
t(key, instanceOverride) {
|
|
197
|
-
if (
|
|
252
|
+
if (!isSafeKey(String(key))) {
|
|
253
|
+
return "";
|
|
254
|
+
}
|
|
255
|
+
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
198
256
|
return String(instanceOverride[key]);
|
|
199
257
|
}
|
|
200
258
|
if (globalOverrides[key] !== void 0) {
|
|
@@ -225,10 +283,10 @@ var Wulf = (() => {
|
|
|
225
283
|
},
|
|
226
284
|
reset() {
|
|
227
285
|
currentLocale = fallbackLocale;
|
|
228
|
-
globalOverrides =
|
|
229
|
-
activeLocales =
|
|
286
|
+
globalOverrides = /* @__PURE__ */ Object.create(null);
|
|
287
|
+
activeLocales = /* @__PURE__ */ Object.create(null);
|
|
230
288
|
for (const [loc, dict] of Object.entries(initialLocales)) {
|
|
231
|
-
activeLocales[loc] =
|
|
289
|
+
activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
|
|
232
290
|
}
|
|
233
291
|
}
|
|
234
292
|
};
|
|
@@ -257,38 +315,95 @@ var Wulf = (() => {
|
|
|
257
315
|
// src/scroll/ScrollBlock.ts
|
|
258
316
|
var idCounter = 0;
|
|
259
317
|
var ScrollBlock = class extends LocalizedComponent {
|
|
318
|
+
static _i18n = scrollI18n;
|
|
319
|
+
static i18n = scrollI18n;
|
|
320
|
+
root;
|
|
321
|
+
viewport;
|
|
322
|
+
options;
|
|
323
|
+
createdViewport = false;
|
|
324
|
+
isDestroyed = false;
|
|
325
|
+
wasIdGenerated = false;
|
|
326
|
+
wasRoleInferred = false;
|
|
327
|
+
wasAriaLabelInferred = false;
|
|
328
|
+
hasExplicitAriaLabel = false;
|
|
329
|
+
hasRootAriaLabel = false;
|
|
330
|
+
propagatedRootLabel = null;
|
|
331
|
+
lastInferredAriaLabel = "";
|
|
332
|
+
trackY;
|
|
333
|
+
thumbY;
|
|
334
|
+
trackX;
|
|
335
|
+
thumbX;
|
|
336
|
+
resizeObserver;
|
|
337
|
+
hideTimer;
|
|
338
|
+
scrollEndFallbackTimer;
|
|
339
|
+
rafId = null;
|
|
340
|
+
resizeRafId = null;
|
|
341
|
+
abortController = new AbortController();
|
|
342
|
+
dragAbortController;
|
|
343
|
+
activeScrollToController;
|
|
344
|
+
supportsScrollEnd = typeof window !== "undefined" && "onscrollend" in window;
|
|
345
|
+
// Cache de métriques géométriques mis à jour dans update() pour éviter tout forced reflow en cours de scroll
|
|
346
|
+
cachedMaxTop = 0;
|
|
347
|
+
cachedMaxLeft = 0;
|
|
348
|
+
cachedTrackHeight = 0;
|
|
349
|
+
cachedThumbHeight = 0;
|
|
350
|
+
cachedTrackWidth = 0;
|
|
351
|
+
cachedThumbWidth = 0;
|
|
352
|
+
isDragging = false;
|
|
353
|
+
dragAxis;
|
|
354
|
+
dragPointerId;
|
|
355
|
+
dragStartPos = 0;
|
|
356
|
+
dragStartScroll = 0;
|
|
357
|
+
atBottom = false;
|
|
358
|
+
atTop = true;
|
|
359
|
+
atRight = false;
|
|
360
|
+
atLeft = true;
|
|
361
|
+
// Références d'écouteurs d'événements pour les callbacks et le drag
|
|
362
|
+
boundOnScroll;
|
|
363
|
+
boundOnScrollEnd;
|
|
364
|
+
boundOnMouseEnter;
|
|
365
|
+
boundOnMouseLeave;
|
|
366
|
+
boundOnFocusIn;
|
|
367
|
+
boundOnFocusOut;
|
|
368
|
+
boundPointerMove;
|
|
369
|
+
boundPointerUp;
|
|
260
370
|
constructor(element, options) {
|
|
261
371
|
super(options?.i18n);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.atRight = false;
|
|
274
|
-
this.atLeft = true;
|
|
275
|
-
const resolvedElement = typeof element === "string" ? document.querySelector(element) : element;
|
|
276
|
-
if (!resolvedElement) {
|
|
372
|
+
let resolvedElement = null;
|
|
373
|
+
if (typeof element === "string") {
|
|
374
|
+
try {
|
|
375
|
+
resolvedElement = document.querySelector(element);
|
|
376
|
+
} catch {
|
|
377
|
+
resolvedElement = null;
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
resolvedElement = element;
|
|
381
|
+
}
|
|
382
|
+
if (!resolvedElement || !(resolvedElement instanceof HTMLElement)) {
|
|
277
383
|
throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
|
|
278
384
|
}
|
|
279
385
|
this.root = resolvedElement;
|
|
280
386
|
this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
|
|
387
|
+
const rawDelay = options?.autoHideDelay;
|
|
388
|
+
const safeAutoHideDelay = typeof rawDelay === "number" && Number.isFinite(rawDelay) && rawDelay >= 0 ? rawDelay : 1e3;
|
|
389
|
+
const rawMinThumb = options?.minThumbSize;
|
|
390
|
+
const safeMinThumbSize = typeof rawMinThumb === "number" && Number.isFinite(rawMinThumb) && rawMinThumb > 0 ? rawMinThumb : 24;
|
|
391
|
+
const rawEdge = options?.edgeThreshold;
|
|
392
|
+
const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
|
|
281
393
|
this.options = {
|
|
282
394
|
axis: options?.axis || "y",
|
|
395
|
+
mode: options?.mode || "custom",
|
|
283
396
|
autoHide: options?.autoHide ?? true,
|
|
284
|
-
autoHideDelay:
|
|
397
|
+
autoHideDelay: safeAutoHideDelay,
|
|
285
398
|
alwaysVisible: options?.alwaysVisible ?? false,
|
|
286
399
|
ariaLabel: options?.ariaLabel || this.t("viewport"),
|
|
287
400
|
i18n: options?.i18n || {},
|
|
288
|
-
minThumbSize:
|
|
289
|
-
edgeThreshold:
|
|
401
|
+
minThumbSize: safeMinThumbSize,
|
|
402
|
+
edgeThreshold: safeEdgeThreshold,
|
|
290
403
|
onScroll: options?.onScroll || (() => {
|
|
291
404
|
}),
|
|
405
|
+
onScrollEnd: options?.onScrollEnd || (() => {
|
|
406
|
+
}),
|
|
292
407
|
onTotalScroll: options?.onTotalScroll || (() => {
|
|
293
408
|
}),
|
|
294
409
|
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
@@ -296,6 +411,7 @@ var Wulf = (() => {
|
|
|
296
411
|
audit: options?.audit ?? true
|
|
297
412
|
};
|
|
298
413
|
this.boundOnScroll = this.handleScroll.bind(this);
|
|
414
|
+
this.boundOnScrollEnd = this.handleScrollEnd.bind(this);
|
|
299
415
|
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
300
416
|
this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
|
|
301
417
|
this.boundOnFocusIn = this.handleFocusIn.bind(this);
|
|
@@ -315,6 +431,9 @@ var Wulf = (() => {
|
|
|
315
431
|
*/
|
|
316
432
|
setupViewport() {
|
|
317
433
|
this.root.classList.add("wulf-scrollblock");
|
|
434
|
+
if (this.options.mode === "native") {
|
|
435
|
+
this.root.classList.add("wulf-scrollblock--native");
|
|
436
|
+
}
|
|
318
437
|
if (this.options.alwaysVisible) {
|
|
319
438
|
this.root.classList.add("is-always-visible");
|
|
320
439
|
}
|
|
@@ -325,12 +444,13 @@ var Wulf = (() => {
|
|
|
325
444
|
if (existingViewport) {
|
|
326
445
|
return existingViewport;
|
|
327
446
|
}
|
|
447
|
+
const existingChildren = Array.from(this.root.childNodes);
|
|
328
448
|
const viewport = document.createElement("div");
|
|
329
449
|
viewport.className = "wulf-scrollblock-viewport";
|
|
330
|
-
while (this.root.firstChild) {
|
|
331
|
-
viewport.appendChild(this.root.firstChild);
|
|
332
|
-
}
|
|
333
450
|
this.root.appendChild(viewport);
|
|
451
|
+
for (const child of existingChildren) {
|
|
452
|
+
safeMove(viewport, child, null);
|
|
453
|
+
}
|
|
334
454
|
this.createdViewport = true;
|
|
335
455
|
return viewport;
|
|
336
456
|
}
|
|
@@ -347,8 +467,27 @@ var Wulf = (() => {
|
|
|
347
467
|
this.viewport.setAttribute("role", "region");
|
|
348
468
|
this.wasRoleInferred = true;
|
|
349
469
|
}
|
|
350
|
-
|
|
351
|
-
|
|
470
|
+
const rootLabelledBy = this.root.getAttribute("aria-labelledby")?.trim();
|
|
471
|
+
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
472
|
+
if (rootLabelledBy) {
|
|
473
|
+
this.hasRootAriaLabel = true;
|
|
474
|
+
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-labelledby") && !this.viewport.hasAttribute("aria-label")) {
|
|
475
|
+
this.viewport.setAttribute("aria-labelledby", rootLabelledBy);
|
|
476
|
+
this.propagatedRootLabel = "aria-labelledby";
|
|
477
|
+
}
|
|
478
|
+
} else if (rootAriaLabel) {
|
|
479
|
+
this.hasRootAriaLabel = true;
|
|
480
|
+
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
481
|
+
this.viewport.setAttribute("aria-label", rootAriaLabel);
|
|
482
|
+
this.propagatedRootLabel = "aria-label";
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label")) {
|
|
486
|
+
this.viewport.setAttribute("aria-label", this.options.ariaLabel);
|
|
487
|
+
this.lastInferredAriaLabel = this.options.ariaLabel;
|
|
488
|
+
this.wasAriaLabelInferred = true;
|
|
489
|
+
} else if (!this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
490
|
+
const label = this.t("viewport");
|
|
352
491
|
this.viewport.setAttribute("aria-label", label);
|
|
353
492
|
this.lastInferredAriaLabel = label;
|
|
354
493
|
this.wasAriaLabelInferred = true;
|
|
@@ -378,10 +517,12 @@ var Wulf = (() => {
|
|
|
378
517
|
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
379
518
|
*/
|
|
380
519
|
setupScrollbars() {
|
|
520
|
+
if (this.options.mode === "native") {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
381
523
|
if (this.options.axis === "y" || this.options.axis === "both") {
|
|
382
524
|
this.trackY = document.createElement("div");
|
|
383
525
|
this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
|
|
384
|
-
this.trackY.setAttribute("aria-hidden", "true");
|
|
385
526
|
this.thumbY = document.createElement("div");
|
|
386
527
|
this.thumbY.className = "wulf-scrollblock-thumb";
|
|
387
528
|
this.thumbY.setAttribute("role", "scrollbar");
|
|
@@ -398,7 +539,6 @@ var Wulf = (() => {
|
|
|
398
539
|
if (this.options.axis === "x" || this.options.axis === "both") {
|
|
399
540
|
this.trackX = document.createElement("div");
|
|
400
541
|
this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
|
|
401
|
-
this.trackX.setAttribute("aria-hidden", "true");
|
|
402
542
|
this.thumbX = document.createElement("div");
|
|
403
543
|
this.thumbX.className = "wulf-scrollblock-thumb";
|
|
404
544
|
this.thumbX.setAttribute("role", "scrollbar");
|
|
@@ -413,48 +553,129 @@ var Wulf = (() => {
|
|
|
413
553
|
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
414
554
|
}
|
|
415
555
|
}
|
|
556
|
+
isRtl() {
|
|
557
|
+
return typeof window !== "undefined" && window.getComputedStyle(this.viewport).direction === "rtl";
|
|
558
|
+
}
|
|
416
559
|
/**
|
|
417
|
-
* Attache les écouteurs sur un rail et son curseur.
|
|
560
|
+
* Attache les écouteurs souris/pointeur et clavier WAI-ARIA sur un rail et son curseur.
|
|
418
561
|
*/
|
|
419
562
|
attachTrackListeners(track, thumb, axis) {
|
|
563
|
+
const { signal } = this.abortController;
|
|
420
564
|
thumb.addEventListener("pointerdown", (e) => {
|
|
565
|
+
if (e.button !== 0) return;
|
|
421
566
|
e.preventDefault();
|
|
422
567
|
e.stopPropagation();
|
|
568
|
+
this.dragAbortController?.abort();
|
|
569
|
+
this.dragAbortController = new AbortController();
|
|
570
|
+
const dragSignal = this.dragAbortController.signal;
|
|
423
571
|
this.isDragging = true;
|
|
424
572
|
this.dragAxis = axis;
|
|
425
573
|
this.dragPointerId = e.pointerId;
|
|
426
574
|
this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
|
|
427
575
|
this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
428
|
-
|
|
576
|
+
try {
|
|
577
|
+
thumb.setPointerCapture(e.pointerId);
|
|
578
|
+
} catch {
|
|
579
|
+
}
|
|
429
580
|
thumb.classList.add("is-active");
|
|
430
581
|
this.root.classList.add("is-dragging");
|
|
431
|
-
window.addEventListener("pointermove", this.boundPointerMove);
|
|
432
|
-
window.addEventListener("pointerup", this.boundPointerUp);
|
|
433
|
-
window.addEventListener("pointercancel", this.boundPointerUp);
|
|
434
|
-
|
|
582
|
+
window.addEventListener("pointermove", this.boundPointerMove, { signal: dragSignal });
|
|
583
|
+
window.addEventListener("pointerup", this.boundPointerUp, { signal: dragSignal });
|
|
584
|
+
window.addEventListener("pointercancel", this.boundPointerUp, { signal: dragSignal });
|
|
585
|
+
thumb.addEventListener("lostpointercapture", this.boundPointerUp, { signal: dragSignal });
|
|
586
|
+
}, { signal });
|
|
587
|
+
thumb.addEventListener("keydown", (e) => {
|
|
588
|
+
if (e.ctrlKey || e.altKey || e.metaKey) return;
|
|
589
|
+
const step = 40;
|
|
590
|
+
const page = axis === "y" ? Math.max(step, Math.round(this.viewport.clientHeight * 0.9)) : Math.max(step, Math.round(this.viewport.clientWidth * 0.9));
|
|
591
|
+
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
592
|
+
if (maxScroll <= 0) return;
|
|
593
|
+
const rtl = axis === "x" && this.isRtl();
|
|
594
|
+
const current = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
595
|
+
let target = null;
|
|
596
|
+
if (axis === "y") {
|
|
597
|
+
switch (e.key) {
|
|
598
|
+
case "ArrowDown":
|
|
599
|
+
target = current + step;
|
|
600
|
+
break;
|
|
601
|
+
case "ArrowUp":
|
|
602
|
+
target = current - step;
|
|
603
|
+
break;
|
|
604
|
+
case "PageDown":
|
|
605
|
+
target = current + page;
|
|
606
|
+
break;
|
|
607
|
+
case "PageUp":
|
|
608
|
+
target = current - page;
|
|
609
|
+
break;
|
|
610
|
+
case " ":
|
|
611
|
+
target = current + (e.shiftKey ? -page : page);
|
|
612
|
+
break;
|
|
613
|
+
case "Home":
|
|
614
|
+
target = 0;
|
|
615
|
+
break;
|
|
616
|
+
case "End":
|
|
617
|
+
target = maxScroll;
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
} else {
|
|
621
|
+
switch (e.key) {
|
|
622
|
+
case "ArrowRight":
|
|
623
|
+
target = current + step;
|
|
624
|
+
break;
|
|
625
|
+
case "ArrowLeft":
|
|
626
|
+
target = current - step;
|
|
627
|
+
break;
|
|
628
|
+
case "PageDown":
|
|
629
|
+
target = current + (rtl ? -page : page);
|
|
630
|
+
break;
|
|
631
|
+
case "PageUp":
|
|
632
|
+
target = current + (rtl ? page : -page);
|
|
633
|
+
break;
|
|
634
|
+
case " ":
|
|
635
|
+
target = current + (e.shiftKey ? rtl ? page : -page : rtl ? -page : page);
|
|
636
|
+
break;
|
|
637
|
+
case "Home":
|
|
638
|
+
target = 0;
|
|
639
|
+
break;
|
|
640
|
+
case "End":
|
|
641
|
+
target = rtl ? -maxScroll : maxScroll;
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (target === null) return;
|
|
646
|
+
e.preventDefault();
|
|
647
|
+
e.stopPropagation();
|
|
648
|
+
void this.scrollTo(axis === "y" ? { top: target } : { left: target }, { smooth: false });
|
|
649
|
+
this.syncThumbs();
|
|
650
|
+
}, { signal });
|
|
435
651
|
track.addEventListener("pointerdown", (e) => {
|
|
436
|
-
if (e.target === thumb) return;
|
|
652
|
+
if (e.button !== 0 || e.target === thumb) return;
|
|
437
653
|
e.preventDefault();
|
|
654
|
+
const rtl = axis === "x" && this.isRtl();
|
|
438
655
|
const rect = track.getBoundingClientRect();
|
|
439
|
-
const clickPos = axis === "y" ? e.clientY - rect.top : e.clientX - rect.left;
|
|
656
|
+
const clickPos = axis === "y" ? e.clientY - rect.top : rtl ? rect.right - e.clientX : e.clientX - rect.left;
|
|
440
657
|
const trackSize = axis === "y" ? rect.height : rect.width;
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
const ratio = clickPos / trackSize;
|
|
444
|
-
const targetScroll = ratio *
|
|
445
|
-
this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
446
|
-
});
|
|
658
|
+
if (trackSize <= 0) return;
|
|
659
|
+
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
660
|
+
const ratio = Math.max(0, Math.min(1, clickPos / trackSize));
|
|
661
|
+
const targetScroll = rtl ? -(ratio * maxScroll) : ratio * maxScroll;
|
|
662
|
+
void this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
663
|
+
}, { signal });
|
|
447
664
|
}
|
|
448
665
|
/**
|
|
449
666
|
* Écouteurs globaux sur le viewport et les interactions.
|
|
450
667
|
*/
|
|
451
668
|
setupEventListeners() {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
this.
|
|
456
|
-
|
|
457
|
-
|
|
669
|
+
const { signal } = this.abortController;
|
|
670
|
+
this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true, signal });
|
|
671
|
+
if (this.supportsScrollEnd) {
|
|
672
|
+
this.viewport.addEventListener("scrollend", this.boundOnScrollEnd, { passive: true, signal });
|
|
673
|
+
}
|
|
674
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
675
|
+
this.root.addEventListener("mouseenter", this.boundOnMouseEnter, { signal });
|
|
676
|
+
this.root.addEventListener("mouseleave", this.boundOnMouseLeave, { signal });
|
|
677
|
+
this.root.addEventListener("focusin", this.boundOnFocusIn, { signal });
|
|
678
|
+
this.root.addEventListener("focusout", this.boundOnFocusOut, { signal });
|
|
458
679
|
}
|
|
459
680
|
}
|
|
460
681
|
/**
|
|
@@ -463,7 +684,13 @@ var Wulf = (() => {
|
|
|
463
684
|
setupObserver() {
|
|
464
685
|
if (typeof ResizeObserver !== "undefined") {
|
|
465
686
|
this.resizeObserver = new ResizeObserver(() => {
|
|
466
|
-
|
|
687
|
+
if (this.isDestroyed || this.resizeRafId !== null) return;
|
|
688
|
+
this.resizeRafId = window.requestAnimationFrame(() => {
|
|
689
|
+
this.resizeRafId = null;
|
|
690
|
+
if (!this.isDestroyed) {
|
|
691
|
+
this.update();
|
|
692
|
+
}
|
|
693
|
+
});
|
|
467
694
|
});
|
|
468
695
|
this.resizeObserver.observe(this.root);
|
|
469
696
|
this.resizeObserver.observe(this.viewport);
|
|
@@ -477,22 +704,20 @@ var Wulf = (() => {
|
|
|
477
704
|
*/
|
|
478
705
|
handlePointerMove(e) {
|
|
479
706
|
if (!this.isDragging || !this.dragAxis) return;
|
|
707
|
+
if (this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) return;
|
|
480
708
|
const isY = this.dragAxis === "y";
|
|
481
709
|
const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
|
|
482
|
-
const
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
const trackSize = isY ? track.clientHeight : track.clientWidth;
|
|
486
|
-
const thumbSize = isY ? thumb.clientHeight : thumb.clientWidth;
|
|
487
|
-
const clientSize = isY ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
488
|
-
const scrollSize = isY ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
489
|
-
const maxScroll = scrollSize - clientSize;
|
|
710
|
+
const trackSize = isY ? this.cachedTrackHeight : this.cachedTrackWidth;
|
|
711
|
+
const thumbSize = isY ? this.cachedThumbHeight : this.cachedThumbWidth;
|
|
712
|
+
const maxScroll = isY ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
490
713
|
const maxThumbTravel = trackSize - thumbSize;
|
|
491
714
|
if (maxThumbTravel <= 0 || maxScroll <= 0) return;
|
|
492
715
|
const ratio = maxScroll / maxThumbTravel;
|
|
493
716
|
const nextScroll = this.dragStartScroll + delta * ratio;
|
|
494
717
|
if (isY) {
|
|
495
718
|
this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
719
|
+
} else if (this.isRtl()) {
|
|
720
|
+
this.viewport.scrollLeft = Math.max(-maxScroll, Math.min(0, nextScroll));
|
|
496
721
|
} else {
|
|
497
722
|
this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
498
723
|
}
|
|
@@ -502,15 +727,20 @@ var Wulf = (() => {
|
|
|
502
727
|
*/
|
|
503
728
|
handlePointerUp(e) {
|
|
504
729
|
if (!this.isDragging) return;
|
|
730
|
+
if (e && e.type !== "lostpointercapture" && this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
505
733
|
if (this.dragPointerId !== void 0) {
|
|
506
734
|
const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
|
|
507
|
-
|
|
508
|
-
activeThumb.
|
|
735
|
+
try {
|
|
736
|
+
if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
|
|
737
|
+
activeThumb.releasePointerCapture(this.dragPointerId);
|
|
738
|
+
}
|
|
739
|
+
} catch {
|
|
509
740
|
}
|
|
510
741
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
742
|
+
this.dragAbortController?.abort();
|
|
743
|
+
this.dragAbortController = void 0;
|
|
514
744
|
this.isDragging = false;
|
|
515
745
|
this.dragAxis = void 0;
|
|
516
746
|
this.dragPointerId = void 0;
|
|
@@ -519,24 +749,31 @@ var Wulf = (() => {
|
|
|
519
749
|
this.root.classList.remove("is-dragging");
|
|
520
750
|
this.scheduleAutoHide();
|
|
521
751
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
this.
|
|
527
|
-
const
|
|
528
|
-
const
|
|
529
|
-
const
|
|
530
|
-
|
|
531
|
-
const progressX = maxLeft > 0 ? scrollLeft / maxLeft : 0;
|
|
532
|
-
this.options.onScroll({
|
|
752
|
+
getScrollInfo() {
|
|
753
|
+
const { scrollTop, scrollLeft } = this.viewport;
|
|
754
|
+
const maxTop = this.cachedMaxTop;
|
|
755
|
+
const maxLeft = this.cachedMaxLeft;
|
|
756
|
+
const rtl = this.isRtl();
|
|
757
|
+
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
758
|
+
const progressY = maxTop > 0 ? Math.max(0, Math.min(1, scrollTop / maxTop)) : 0;
|
|
759
|
+
const progressX = maxLeft > 0 ? Math.max(0, Math.min(1, logicalLeft / maxLeft)) : 0;
|
|
760
|
+
return {
|
|
533
761
|
top: scrollTop,
|
|
534
762
|
left: scrollLeft,
|
|
535
763
|
maxTop,
|
|
536
764
|
maxLeft,
|
|
537
765
|
progressY: Math.round(progressY * 100),
|
|
538
766
|
progressX: Math.round(progressX * 100)
|
|
539
|
-
}
|
|
767
|
+
};
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Gestionnaire d'événement de défilement natif.
|
|
771
|
+
*/
|
|
772
|
+
handleScroll() {
|
|
773
|
+
this.scheduleSyncThumbs();
|
|
774
|
+
const info = this.getScrollInfo();
|
|
775
|
+
const { top: scrollTop, left: scrollLeft, maxTop, maxLeft } = info;
|
|
776
|
+
this.options.onScroll(info);
|
|
540
777
|
const threshold = this.options.edgeThreshold;
|
|
541
778
|
if (maxTop > 0) {
|
|
542
779
|
const nowBottom = scrollTop >= maxTop - threshold;
|
|
@@ -551,8 +788,9 @@ var Wulf = (() => {
|
|
|
551
788
|
this.atTop = nowTop;
|
|
552
789
|
}
|
|
553
790
|
if (maxLeft > 0) {
|
|
554
|
-
const
|
|
555
|
-
const
|
|
791
|
+
const rtl = this.isRtl();
|
|
792
|
+
const nowRight = rtl ? scrollLeft >= -threshold : scrollLeft >= maxLeft - threshold;
|
|
793
|
+
const nowLeft = rtl ? scrollLeft <= -maxLeft + threshold : scrollLeft <= threshold;
|
|
556
794
|
if (nowRight && !this.atRight) {
|
|
557
795
|
this.options.onTotalScroll("right");
|
|
558
796
|
}
|
|
@@ -562,37 +800,71 @@ var Wulf = (() => {
|
|
|
562
800
|
this.atRight = nowRight;
|
|
563
801
|
this.atLeft = nowLeft;
|
|
564
802
|
}
|
|
565
|
-
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
803
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
804
|
+
this.clearAutoHideTimer();
|
|
566
805
|
this.root.classList.add("is-scrolling");
|
|
806
|
+
if (!this.supportsScrollEnd) {
|
|
807
|
+
this.scheduleAutoHide();
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (!this.supportsScrollEnd) {
|
|
811
|
+
if (this.scrollEndFallbackTimer !== void 0) {
|
|
812
|
+
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
813
|
+
}
|
|
814
|
+
this.scrollEndFallbackTimer = window.setTimeout(() => {
|
|
815
|
+
this.scrollEndFallbackTimer = void 0;
|
|
816
|
+
this.handleScrollEnd();
|
|
817
|
+
}, 150);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Gestionnaire de fin de défilement (`scrollend` natif ou repli temporisé).
|
|
822
|
+
*/
|
|
823
|
+
handleScrollEnd() {
|
|
824
|
+
this.options.onScrollEnd(this.getScrollInfo());
|
|
825
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
567
826
|
this.scheduleAutoHide();
|
|
568
827
|
}
|
|
569
828
|
}
|
|
570
829
|
/**
|
|
571
|
-
*
|
|
830
|
+
* Planifie une synchronisation des curseurs calée sur la prochaine trame d'affichage.
|
|
831
|
+
*/
|
|
832
|
+
scheduleSyncThumbs() {
|
|
833
|
+
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
834
|
+
if (this.rafId !== null) return;
|
|
835
|
+
this.rafId = window.requestAnimationFrame(() => {
|
|
836
|
+
this.rafId = null;
|
|
837
|
+
if (!this.isDestroyed) {
|
|
838
|
+
this.syncThumbs();
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Synchronise la position physique (via variables CSS) et ARIA des curseurs à partir des métriques en cache.
|
|
572
844
|
*/
|
|
573
845
|
syncThumbs() {
|
|
574
|
-
|
|
846
|
+
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
847
|
+
const { scrollTop, scrollLeft } = this.viewport;
|
|
575
848
|
if (this.thumbY && this.trackY) {
|
|
576
|
-
const maxScrollY =
|
|
577
|
-
const
|
|
578
|
-
const thumbHeight = this.thumbY.clientHeight;
|
|
579
|
-
const maxTravelY = trackHeight - thumbHeight;
|
|
849
|
+
const maxScrollY = this.cachedMaxTop;
|
|
850
|
+
const maxTravelY = this.cachedTrackHeight - this.cachedThumbHeight;
|
|
580
851
|
if (maxScrollY > 0 && maxTravelY > 0) {
|
|
581
|
-
const ratioY = scrollTop / maxScrollY;
|
|
852
|
+
const ratioY = Math.max(0, Math.min(1, scrollTop / maxScrollY));
|
|
582
853
|
const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
|
|
583
|
-
this.thumbY.style.
|
|
854
|
+
this.thumbY.style.setProperty("--scrollblock-thumb-y", `${posY}px`);
|
|
584
855
|
this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
|
|
585
856
|
}
|
|
586
857
|
}
|
|
587
858
|
if (this.thumbX && this.trackX) {
|
|
588
|
-
const maxScrollX =
|
|
589
|
-
const
|
|
590
|
-
const thumbWidth = this.thumbX.clientWidth;
|
|
591
|
-
const maxTravelX = trackWidth - thumbWidth;
|
|
859
|
+
const maxScrollX = this.cachedMaxLeft;
|
|
860
|
+
const maxTravelX = this.cachedTrackWidth - this.cachedThumbWidth;
|
|
592
861
|
if (maxScrollX > 0 && maxTravelX > 0) {
|
|
593
|
-
const
|
|
862
|
+
const rtl = this.isRtl();
|
|
863
|
+
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
864
|
+
const ratioX = Math.max(0, Math.min(1, logicalLeft / maxScrollX));
|
|
594
865
|
const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
|
|
595
|
-
|
|
866
|
+
const signedPosX = rtl ? -posX : posX;
|
|
867
|
+
this.thumbX.style.setProperty("--scrollblock-thumb-x", `${signedPosX}px`);
|
|
596
868
|
this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
|
|
597
869
|
}
|
|
598
870
|
}
|
|
@@ -629,10 +901,37 @@ var Wulf = (() => {
|
|
|
629
901
|
* Recalcule les dimensions et la visibilité des barres.
|
|
630
902
|
*/
|
|
631
903
|
update() {
|
|
904
|
+
if (this.isDestroyed) return;
|
|
632
905
|
this.syncAccessibilityLabels();
|
|
633
906
|
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
907
|
+
const trackHeight = this.trackY ? this.trackY.clientHeight : 0;
|
|
908
|
+
const trackWidth = this.trackX ? this.trackX.clientWidth : 0;
|
|
909
|
+
const cssMinY = this.thumbY && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbY).minBlockSize) || 0 : 0;
|
|
910
|
+
const cssMinX = this.thumbX && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbX).minInlineSize) || 0 : 0;
|
|
911
|
+
this.cachedMaxTop = Math.max(0, scrollHeight - clientHeight);
|
|
912
|
+
this.cachedMaxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
913
|
+
this.cachedTrackHeight = trackHeight;
|
|
914
|
+
this.cachedTrackWidth = trackWidth;
|
|
634
915
|
const canScrollY = scrollHeight > clientHeight;
|
|
635
916
|
const canScrollX = scrollWidth > clientWidth;
|
|
917
|
+
let calculatedHeight = this.cachedThumbHeight;
|
|
918
|
+
if (this.trackY && this.thumbY && canScrollY && scrollHeight > 0) {
|
|
919
|
+
const effectiveMinY = Math.max(this.options.minThumbSize, cssMinY);
|
|
920
|
+
calculatedHeight = Math.max(
|
|
921
|
+
effectiveMinY,
|
|
922
|
+
trackHeight * (clientHeight / scrollHeight)
|
|
923
|
+
);
|
|
924
|
+
this.cachedThumbHeight = calculatedHeight;
|
|
925
|
+
}
|
|
926
|
+
let calculatedWidth = this.cachedThumbWidth;
|
|
927
|
+
if (this.trackX && this.thumbX && canScrollX && scrollWidth > 0) {
|
|
928
|
+
const effectiveMinX = Math.max(this.options.minThumbSize, cssMinX);
|
|
929
|
+
calculatedWidth = Math.max(
|
|
930
|
+
effectiveMinX,
|
|
931
|
+
trackWidth * (clientWidth / scrollWidth)
|
|
932
|
+
);
|
|
933
|
+
this.cachedThumbWidth = calculatedWidth;
|
|
934
|
+
}
|
|
636
935
|
this.root.classList.toggle("has-scroll-y", canScrollY);
|
|
637
936
|
this.root.classList.toggle("has-scroll-x", canScrollX);
|
|
638
937
|
if (canScrollY || canScrollX) {
|
|
@@ -641,37 +940,40 @@ var Wulf = (() => {
|
|
|
641
940
|
this.viewport.removeAttribute("tabindex");
|
|
642
941
|
}
|
|
643
942
|
if (this.trackY && this.thumbY) {
|
|
943
|
+
this.trackY.hidden = !canScrollY;
|
|
644
944
|
if (canScrollY) {
|
|
645
|
-
|
|
646
|
-
const calculatedHeight = Math.max(
|
|
647
|
-
this.options.minThumbSize,
|
|
648
|
-
trackHeight * (clientHeight / scrollHeight)
|
|
649
|
-
);
|
|
945
|
+
this.thumbY.setAttribute("tabindex", "0");
|
|
650
946
|
this.thumbY.style.height = `${calculatedHeight}px`;
|
|
947
|
+
} else {
|
|
948
|
+
this.thumbY.removeAttribute("tabindex");
|
|
651
949
|
}
|
|
652
950
|
}
|
|
653
951
|
if (this.trackX && this.thumbX) {
|
|
952
|
+
this.trackX.hidden = !canScrollX;
|
|
654
953
|
if (canScrollX) {
|
|
655
|
-
|
|
656
|
-
const calculatedWidth = Math.max(
|
|
657
|
-
this.options.minThumbSize,
|
|
658
|
-
trackWidth * (clientWidth / scrollWidth)
|
|
659
|
-
);
|
|
954
|
+
this.thumbX.setAttribute("tabindex", "0");
|
|
660
955
|
this.thumbX.style.width = `${calculatedWidth}px`;
|
|
956
|
+
} else {
|
|
957
|
+
this.thumbX.removeAttribute("tabindex");
|
|
661
958
|
}
|
|
662
959
|
}
|
|
663
960
|
this.syncThumbs();
|
|
664
961
|
}
|
|
665
962
|
/**
|
|
666
963
|
* Défilement programmatique direct ou lissé.
|
|
964
|
+
* Retourne une Promesse résolue lorsque le défilement atteint sa cible.
|
|
667
965
|
*/
|
|
668
966
|
scrollTo(target, options) {
|
|
669
|
-
|
|
967
|
+
if (this.isDestroyed) return Promise.resolve();
|
|
670
968
|
const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
|
|
671
|
-
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion;
|
|
969
|
+
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion();
|
|
672
970
|
const behavior = shouldSmooth ? "smooth" : "auto";
|
|
673
|
-
const
|
|
674
|
-
const
|
|
971
|
+
const rtl = this.isRtl();
|
|
972
|
+
const { scrollHeight, clientHeight, scrollWidth, clientWidth, scrollTop, scrollLeft } = this.viewport;
|
|
973
|
+
const maxTop = Math.max(0, scrollHeight - clientHeight);
|
|
974
|
+
const maxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
975
|
+
this.cachedMaxTop = maxTop;
|
|
976
|
+
this.cachedMaxLeft = maxLeft;
|
|
675
977
|
let targetTop;
|
|
676
978
|
let targetLeft;
|
|
677
979
|
if (typeof target === "number") {
|
|
@@ -685,19 +987,19 @@ var Wulf = (() => {
|
|
|
685
987
|
targetTop = maxTop;
|
|
686
988
|
break;
|
|
687
989
|
case "left":
|
|
688
|
-
targetLeft = 0;
|
|
990
|
+
targetLeft = rtl ? -maxLeft : 0;
|
|
689
991
|
break;
|
|
690
992
|
case "right":
|
|
691
|
-
targetLeft = maxLeft;
|
|
993
|
+
targetLeft = rtl ? 0 : maxLeft;
|
|
692
994
|
break;
|
|
693
995
|
default: {
|
|
694
996
|
if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
|
|
695
997
|
const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
|
|
696
998
|
if (this.options.axis === "x") {
|
|
697
|
-
targetLeft = maxLeft * pct;
|
|
999
|
+
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
698
1000
|
} else if (this.options.axis === "both") {
|
|
699
1001
|
targetTop = maxTop * pct;
|
|
700
|
-
targetLeft = maxLeft * pct;
|
|
1002
|
+
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
701
1003
|
} else {
|
|
702
1004
|
targetTop = maxTop * pct;
|
|
703
1005
|
}
|
|
@@ -710,24 +1012,82 @@ var Wulf = (() => {
|
|
|
710
1012
|
el = null;
|
|
711
1013
|
}
|
|
712
1014
|
if (el) {
|
|
713
|
-
|
|
714
|
-
|
|
1015
|
+
const vpRect = this.viewport.getBoundingClientRect();
|
|
1016
|
+
const elRect = el.getBoundingClientRect();
|
|
1017
|
+
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
1018
|
+
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
715
1019
|
}
|
|
716
1020
|
break;
|
|
717
1021
|
}
|
|
718
1022
|
}
|
|
719
1023
|
} else if (target instanceof HTMLElement) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
1024
|
+
const vpRect = this.viewport.getBoundingClientRect();
|
|
1025
|
+
const elRect = target.getBoundingClientRect();
|
|
1026
|
+
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
1027
|
+
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
1028
|
+
} else if (typeof target === "object" && target !== null) {
|
|
723
1029
|
targetTop = target.top;
|
|
724
1030
|
targetLeft = target.left;
|
|
725
1031
|
}
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
1032
|
+
const clampedTop = targetTop !== void 0 && Number.isFinite(targetTop) ? Math.max(0, Math.min(maxTop, targetTop)) : void 0;
|
|
1033
|
+
const minLeftBound = rtl ? -maxLeft : 0;
|
|
1034
|
+
const maxLeftBound = rtl ? 0 : maxLeft;
|
|
1035
|
+
const clampedLeft = targetLeft !== void 0 && Number.isFinite(targetLeft) ? Math.max(minLeftBound, Math.min(maxLeftBound, targetLeft)) : void 0;
|
|
1036
|
+
const destTop = clampedTop ?? scrollTop;
|
|
1037
|
+
const destLeft = clampedLeft ?? scrollLeft;
|
|
1038
|
+
if (Math.abs(destTop - scrollTop) <= 1 && Math.abs(destLeft - scrollLeft) <= 1) {
|
|
1039
|
+
return Promise.resolve();
|
|
1040
|
+
}
|
|
1041
|
+
this.activeScrollToController?.abort();
|
|
1042
|
+
const waitController = new AbortController();
|
|
1043
|
+
this.activeScrollToController = waitController;
|
|
1044
|
+
const nativeResult = this.viewport.scrollTo({
|
|
1045
|
+
top: clampedTop,
|
|
1046
|
+
left: clampedLeft,
|
|
729
1047
|
behavior
|
|
730
1048
|
});
|
|
1049
|
+
if (nativeResult instanceof Promise) {
|
|
1050
|
+
return nativeResult.then(() => {
|
|
1051
|
+
if (this.activeScrollToController === waitController) {
|
|
1052
|
+
this.activeScrollToController = void 0;
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
if (behavior !== "smooth") {
|
|
1057
|
+
if (this.activeScrollToController === waitController) {
|
|
1058
|
+
this.activeScrollToController = void 0;
|
|
1059
|
+
}
|
|
1060
|
+
return Promise.resolve();
|
|
1061
|
+
}
|
|
1062
|
+
return new Promise((resolve) => {
|
|
1063
|
+
let settled = false;
|
|
1064
|
+
let idleTimerId;
|
|
1065
|
+
let maxTimerId;
|
|
1066
|
+
const finish = () => {
|
|
1067
|
+
if (settled) return;
|
|
1068
|
+
settled = true;
|
|
1069
|
+
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1070
|
+
if (maxTimerId !== void 0) window.clearTimeout(maxTimerId);
|
|
1071
|
+
if (this.activeScrollToController === waitController) {
|
|
1072
|
+
this.activeScrollToController = void 0;
|
|
1073
|
+
}
|
|
1074
|
+
waitController.abort();
|
|
1075
|
+
resolve();
|
|
1076
|
+
};
|
|
1077
|
+
waitController.signal.addEventListener("abort", finish, { once: true });
|
|
1078
|
+
this.abortController.signal.addEventListener("abort", finish, { once: true, signal: waitController.signal });
|
|
1079
|
+
if (this.supportsScrollEnd) {
|
|
1080
|
+
this.viewport.addEventListener("scrollend", finish, { once: true, signal: waitController.signal });
|
|
1081
|
+
} else {
|
|
1082
|
+
const bumpIdle = () => {
|
|
1083
|
+
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1084
|
+
idleTimerId = window.setTimeout(finish, 150);
|
|
1085
|
+
};
|
|
1086
|
+
this.viewport.addEventListener("scroll", bumpIdle, { passive: true, signal: waitController.signal });
|
|
1087
|
+
bumpIdle();
|
|
1088
|
+
}
|
|
1089
|
+
maxTimerId = window.setTimeout(finish, 2500);
|
|
1090
|
+
});
|
|
731
1091
|
}
|
|
732
1092
|
/**
|
|
733
1093
|
* Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
|
|
@@ -740,12 +1100,12 @@ var Wulf = (() => {
|
|
|
740
1100
|
const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
|
|
741
1101
|
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
742
1102
|
const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
|
|
743
|
-
if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
1103
|
+
if (!this.hasExplicitAriaLabel && !this.hasRootAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
744
1104
|
warnings.push(
|
|
745
1105
|
"Libell\xE9 contextuel manquant : d\xE9finissez l'option ariaLabel (ou un attribut aria-label / aria-labelledby sur le conteneur) pour d\xE9crire la zone d\xE9filable (WCAG 4.1.2)."
|
|
746
1106
|
);
|
|
747
1107
|
}
|
|
748
|
-
if (this.options.minThumbSize < 24) {
|
|
1108
|
+
if (this.options.mode !== "native" && this.options.minThumbSize < 24) {
|
|
749
1109
|
warnings.push(
|
|
750
1110
|
`Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
|
|
751
1111
|
);
|
|
@@ -762,22 +1122,34 @@ var Wulf = (() => {
|
|
|
762
1122
|
* Détruit le composant et libère toutes les ressources.
|
|
763
1123
|
*/
|
|
764
1124
|
destroy() {
|
|
1125
|
+
if (this.isDestroyed) return;
|
|
1126
|
+
this.isDestroyed = true;
|
|
765
1127
|
this.clearAutoHideTimer();
|
|
1128
|
+
if (this.scrollEndFallbackTimer !== void 0) {
|
|
1129
|
+
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
1130
|
+
this.scrollEndFallbackTimer = void 0;
|
|
1131
|
+
}
|
|
1132
|
+
if (this.rafId !== null) {
|
|
1133
|
+
window.cancelAnimationFrame(this.rafId);
|
|
1134
|
+
this.rafId = null;
|
|
1135
|
+
}
|
|
1136
|
+
if (this.resizeRafId !== null) {
|
|
1137
|
+
window.cancelAnimationFrame(this.resizeRafId);
|
|
1138
|
+
this.resizeRafId = null;
|
|
1139
|
+
}
|
|
1140
|
+
this.activeScrollToController?.abort();
|
|
1141
|
+
this.activeScrollToController = void 0;
|
|
1142
|
+
this.dragAbortController?.abort();
|
|
1143
|
+
this.dragAbortController = void 0;
|
|
1144
|
+
this.abortController.abort();
|
|
766
1145
|
if (this.resizeObserver) {
|
|
767
1146
|
this.resizeObserver.disconnect();
|
|
768
1147
|
}
|
|
769
|
-
this.viewport.removeEventListener("scroll", this.boundOnScroll);
|
|
770
|
-
this.root.removeEventListener("mouseenter", this.boundOnMouseEnter);
|
|
771
|
-
this.root.removeEventListener("mouseleave", this.boundOnMouseLeave);
|
|
772
|
-
this.root.removeEventListener("focusin", this.boundOnFocusIn);
|
|
773
|
-
this.root.removeEventListener("focusout", this.boundOnFocusOut);
|
|
774
|
-
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
775
|
-
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
776
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
777
1148
|
this.trackY?.remove();
|
|
778
1149
|
this.trackX?.remove();
|
|
779
1150
|
this.root.classList.remove(
|
|
780
1151
|
"wulf-scrollblock",
|
|
1152
|
+
"wulf-scrollblock--native",
|
|
781
1153
|
"has-scroll-y",
|
|
782
1154
|
"has-scroll-x",
|
|
783
1155
|
"has-both-axes",
|
|
@@ -788,7 +1160,7 @@ var Wulf = (() => {
|
|
|
788
1160
|
);
|
|
789
1161
|
if (this.createdViewport && this.viewport.parentElement === this.root) {
|
|
790
1162
|
while (this.viewport.firstChild) {
|
|
791
|
-
this.root
|
|
1163
|
+
safeMove(this.root, this.viewport.firstChild, this.viewport);
|
|
792
1164
|
}
|
|
793
1165
|
this.viewport.remove();
|
|
794
1166
|
} else {
|
|
@@ -799,14 +1171,15 @@ var Wulf = (() => {
|
|
|
799
1171
|
if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
|
|
800
1172
|
this.viewport.removeAttribute("role");
|
|
801
1173
|
}
|
|
1174
|
+
if (this.propagatedRootLabel) {
|
|
1175
|
+
this.viewport.removeAttribute(this.propagatedRootLabel);
|
|
1176
|
+
}
|
|
802
1177
|
if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
803
1178
|
this.viewport.removeAttribute("aria-label");
|
|
804
1179
|
}
|
|
805
1180
|
}
|
|
806
1181
|
}
|
|
807
1182
|
};
|
|
808
|
-
ScrollBlock._i18n = scrollI18n;
|
|
809
|
-
ScrollBlock.i18n = scrollI18n;
|
|
810
1183
|
|
|
811
1184
|
// src/scroll/index.ts
|
|
812
1185
|
var Scroll = {
|
|
@@ -814,13 +1187,11 @@ var Wulf = (() => {
|
|
|
814
1187
|
i18n: scrollI18n
|
|
815
1188
|
};
|
|
816
1189
|
var index_default = ScrollBlock;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
const wulfNamespace = win.Wulf || {};
|
|
820
|
-
win.Wulf = wulfNamespace;
|
|
1190
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
1191
|
+
if (wulfNamespace) {
|
|
821
1192
|
wulfNamespace.Scroll = Scroll;
|
|
822
1193
|
}
|
|
823
1194
|
return __toCommonJS(index_exports);
|
|
824
1195
|
})();
|
|
825
|
-
if (typeof window !== "undefined") {
|
|
1196
|
+
if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { for (var k in __WulfIIFE) { if (Object.hasOwn(__WulfIIFE, k) && k !== "__proto__" && k !== "constructor" && k !== "prototype" && __w[k] === undefined) { try { Object.defineProperty(__w, k, { value: __WulfIIFE[k], writable: true, configurable: true, enumerable: true }); } catch (_) { try { __w[k] = __WulfIIFE[k]; } catch (__) {} } } } } }
|
|
826
1197
|
//# sourceMappingURL=scroll.global.js.map
|