wulf.js 1.9.3 → 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 +118 -78
- package/changelog.md +60 -0
- package/dist/focus-trap.esm.js +202 -136
- package/dist/focus-trap.esm.js.map +3 -3
- package/dist/focus-trap.global.js +203 -137
- 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 +2130 -858
- package/dist/index.esm.js.map +4 -4
- package/dist/index.global.js +2124 -852
- 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 +686 -330
- package/dist/mask.esm.js.map +3 -3
- package/dist/mask.global.js +687 -331
- 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 +248 -77
- package/dist/masonry.esm.js.map +3 -3
- package/dist/masonry.global.js +249 -78
- 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 +462 -129
- package/dist/scroll.esm.js.map +3 -3
- package/dist/scroll.global.js +463 -130
- 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 +164 -48
- package/dist/shortcut.esm.js.map +3 -3
- package/dist/shortcut.global.js +165 -49
- 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 +489 -124
- package/dist/toast.esm.js.map +3 -3
- package/dist/toast.global.js +490 -125
- 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 -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 +14 -6
- package/dist/types/focus-trap/types.d.ts +2 -2
- package/dist/types/index.d.ts +10 -0
- package/dist/types/mask/BaseInputMask.d.ts +20 -0
- package/dist/types/mask/InputAmountMask.d.ts +2 -0
- package/dist/types/mask/InputEmailMask.d.ts +16 -1
- 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 +1 -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 +9 -2
- package/package.json +16 -3
package/dist/scroll.esm.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
// src/common/dom.ts
|
|
2
|
+
function getSafeWulfNamespace() {
|
|
3
|
+
if (typeof window === "undefined") return null;
|
|
4
|
+
const win = window;
|
|
5
|
+
const existing = win.Wulf;
|
|
6
|
+
if (!existing || typeof existing !== "object" || typeof Node !== "undefined" && existing instanceof Node || typeof HTMLCollection !== "undefined" && existing instanceof HTMLCollection) {
|
|
7
|
+
const fresh = {};
|
|
8
|
+
win.Wulf = fresh;
|
|
9
|
+
return fresh;
|
|
10
|
+
}
|
|
11
|
+
return existing;
|
|
12
|
+
}
|
|
13
|
+
function safeMove(parent, node, referenceNode = null) {
|
|
14
|
+
const moveBefore = parent.moveBefore;
|
|
15
|
+
if (typeof moveBefore === "function" && node.isConnected && parent.isConnected && typeof parent.getRootNode === "function" && typeof node.getRootNode === "function" && parent.getRootNode() === node.getRootNode()) {
|
|
16
|
+
try {
|
|
17
|
+
moveBefore.call(parent, node, referenceNode);
|
|
18
|
+
return;
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
parent.insertBefore(node, referenceNode);
|
|
23
|
+
}
|
|
24
|
+
function prefersReducedMotion() {
|
|
25
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
26
|
+
}
|
|
27
|
+
|
|
1
28
|
// src/common/AuditableComponent.ts
|
|
2
29
|
var AuditableComponent = class {
|
|
3
30
|
/**
|
|
@@ -30,8 +57,11 @@ var AuditableComponent = class {
|
|
|
30
57
|
const rawValue = element.getAttribute(attrName)?.trim();
|
|
31
58
|
if (!rawValue) return false;
|
|
32
59
|
const doc = element.ownerDocument || document;
|
|
60
|
+
const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
|
|
33
61
|
const ids = rawValue.split(/\s+/).filter(Boolean);
|
|
34
|
-
const isValid = ids.length > 0 && ids.every(
|
|
62
|
+
const isValid = ids.length > 0 && ids.every(
|
|
63
|
+
(id) => Boolean(typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id))
|
|
64
|
+
);
|
|
35
65
|
if (!isValid) {
|
|
36
66
|
warnings.push(
|
|
37
67
|
`Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
|
|
@@ -43,6 +73,7 @@ var AuditableComponent = class {
|
|
|
43
73
|
|
|
44
74
|
// src/common/LocalizedComponent.ts
|
|
45
75
|
var LocalizedComponent = class extends AuditableComponent {
|
|
76
|
+
static _i18n;
|
|
46
77
|
/**
|
|
47
78
|
* Définit la langue globale du composant (ex: 'fr', 'en', 'es').
|
|
48
79
|
*/
|
|
@@ -93,6 +124,10 @@ var LocalizedComponent = class extends AuditableComponent {
|
|
|
93
124
|
static t(key, instanceOverride) {
|
|
94
125
|
return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
|
|
95
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Surcharges de localisation spécifiques à cette instance.
|
|
129
|
+
*/
|
|
130
|
+
i18nOverrides;
|
|
96
131
|
constructor(i18nOverrides) {
|
|
97
132
|
super();
|
|
98
133
|
this.i18nOverrides = i18nOverrides;
|
|
@@ -123,7 +158,7 @@ function getPrimaryLanguage(normalizedLocale) {
|
|
|
123
158
|
function assignDefined(target, source) {
|
|
124
159
|
if (!source || typeof source !== "object") return target;
|
|
125
160
|
for (const key of Object.keys(source)) {
|
|
126
|
-
if (isSafeKey(String(key)) && Object.
|
|
161
|
+
if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
|
|
127
162
|
target[key] = source[key];
|
|
128
163
|
}
|
|
129
164
|
}
|
|
@@ -184,7 +219,7 @@ function createI18nManager(defaultLocale, locales) {
|
|
|
184
219
|
if (!isSafeKey(String(key))) {
|
|
185
220
|
return "";
|
|
186
221
|
}
|
|
187
|
-
if (instanceOverride && typeof instanceOverride === "object" && Object.
|
|
222
|
+
if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
|
|
188
223
|
return String(instanceOverride[key]);
|
|
189
224
|
}
|
|
190
225
|
if (globalOverrides[key] !== void 0) {
|
|
@@ -247,21 +282,60 @@ var scrollI18n = createI18nManager("fr", {
|
|
|
247
282
|
// src/scroll/ScrollBlock.ts
|
|
248
283
|
var idCounter = 0;
|
|
249
284
|
var ScrollBlock = class extends LocalizedComponent {
|
|
285
|
+
static _i18n = scrollI18n;
|
|
286
|
+
static i18n = scrollI18n;
|
|
287
|
+
root;
|
|
288
|
+
viewport;
|
|
289
|
+
options;
|
|
290
|
+
createdViewport = false;
|
|
291
|
+
isDestroyed = false;
|
|
292
|
+
wasIdGenerated = false;
|
|
293
|
+
wasRoleInferred = false;
|
|
294
|
+
wasAriaLabelInferred = false;
|
|
295
|
+
hasExplicitAriaLabel = false;
|
|
296
|
+
hasRootAriaLabel = false;
|
|
297
|
+
propagatedRootLabel = null;
|
|
298
|
+
lastInferredAriaLabel = "";
|
|
299
|
+
trackY;
|
|
300
|
+
thumbY;
|
|
301
|
+
trackX;
|
|
302
|
+
thumbX;
|
|
303
|
+
resizeObserver;
|
|
304
|
+
hideTimer;
|
|
305
|
+
scrollEndFallbackTimer;
|
|
306
|
+
rafId = null;
|
|
307
|
+
resizeRafId = null;
|
|
308
|
+
abortController = new AbortController();
|
|
309
|
+
dragAbortController;
|
|
310
|
+
activeScrollToController;
|
|
311
|
+
supportsScrollEnd = typeof window !== "undefined" && "onscrollend" in window;
|
|
312
|
+
// Cache de métriques géométriques mis à jour dans update() pour éviter tout forced reflow en cours de scroll
|
|
313
|
+
cachedMaxTop = 0;
|
|
314
|
+
cachedMaxLeft = 0;
|
|
315
|
+
cachedTrackHeight = 0;
|
|
316
|
+
cachedThumbHeight = 0;
|
|
317
|
+
cachedTrackWidth = 0;
|
|
318
|
+
cachedThumbWidth = 0;
|
|
319
|
+
isDragging = false;
|
|
320
|
+
dragAxis;
|
|
321
|
+
dragPointerId;
|
|
322
|
+
dragStartPos = 0;
|
|
323
|
+
dragStartScroll = 0;
|
|
324
|
+
atBottom = false;
|
|
325
|
+
atTop = true;
|
|
326
|
+
atRight = false;
|
|
327
|
+
atLeft = true;
|
|
328
|
+
// Références d'écouteurs d'événements pour les callbacks et le drag
|
|
329
|
+
boundOnScroll;
|
|
330
|
+
boundOnScrollEnd;
|
|
331
|
+
boundOnMouseEnter;
|
|
332
|
+
boundOnMouseLeave;
|
|
333
|
+
boundOnFocusIn;
|
|
334
|
+
boundOnFocusOut;
|
|
335
|
+
boundPointerMove;
|
|
336
|
+
boundPointerUp;
|
|
250
337
|
constructor(element, options) {
|
|
251
338
|
super(options?.i18n);
|
|
252
|
-
this.createdViewport = false;
|
|
253
|
-
this.wasIdGenerated = false;
|
|
254
|
-
this.wasRoleInferred = false;
|
|
255
|
-
this.wasAriaLabelInferred = false;
|
|
256
|
-
this.hasExplicitAriaLabel = false;
|
|
257
|
-
this.lastInferredAriaLabel = "";
|
|
258
|
-
this.isDragging = false;
|
|
259
|
-
this.dragStartPos = 0;
|
|
260
|
-
this.dragStartScroll = 0;
|
|
261
|
-
this.atBottom = false;
|
|
262
|
-
this.atTop = true;
|
|
263
|
-
this.atRight = false;
|
|
264
|
-
this.atLeft = true;
|
|
265
339
|
let resolvedElement = null;
|
|
266
340
|
if (typeof element === "string") {
|
|
267
341
|
try {
|
|
@@ -285,6 +359,7 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
285
359
|
const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
|
|
286
360
|
this.options = {
|
|
287
361
|
axis: options?.axis || "y",
|
|
362
|
+
mode: options?.mode || "custom",
|
|
288
363
|
autoHide: options?.autoHide ?? true,
|
|
289
364
|
autoHideDelay: safeAutoHideDelay,
|
|
290
365
|
alwaysVisible: options?.alwaysVisible ?? false,
|
|
@@ -294,6 +369,8 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
294
369
|
edgeThreshold: safeEdgeThreshold,
|
|
295
370
|
onScroll: options?.onScroll || (() => {
|
|
296
371
|
}),
|
|
372
|
+
onScrollEnd: options?.onScrollEnd || (() => {
|
|
373
|
+
}),
|
|
297
374
|
onTotalScroll: options?.onTotalScroll || (() => {
|
|
298
375
|
}),
|
|
299
376
|
onTotalScrollBack: options?.onTotalScrollBack || (() => {
|
|
@@ -301,6 +378,7 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
301
378
|
audit: options?.audit ?? true
|
|
302
379
|
};
|
|
303
380
|
this.boundOnScroll = this.handleScroll.bind(this);
|
|
381
|
+
this.boundOnScrollEnd = this.handleScrollEnd.bind(this);
|
|
304
382
|
this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
|
|
305
383
|
this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
|
|
306
384
|
this.boundOnFocusIn = this.handleFocusIn.bind(this);
|
|
@@ -320,6 +398,9 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
320
398
|
*/
|
|
321
399
|
setupViewport() {
|
|
322
400
|
this.root.classList.add("wulf-scrollblock");
|
|
401
|
+
if (this.options.mode === "native") {
|
|
402
|
+
this.root.classList.add("wulf-scrollblock--native");
|
|
403
|
+
}
|
|
323
404
|
if (this.options.alwaysVisible) {
|
|
324
405
|
this.root.classList.add("is-always-visible");
|
|
325
406
|
}
|
|
@@ -330,12 +411,13 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
330
411
|
if (existingViewport) {
|
|
331
412
|
return existingViewport;
|
|
332
413
|
}
|
|
414
|
+
const existingChildren = Array.from(this.root.childNodes);
|
|
333
415
|
const viewport = document.createElement("div");
|
|
334
416
|
viewport.className = "wulf-scrollblock-viewport";
|
|
335
|
-
while (this.root.firstChild) {
|
|
336
|
-
viewport.appendChild(this.root.firstChild);
|
|
337
|
-
}
|
|
338
417
|
this.root.appendChild(viewport);
|
|
418
|
+
for (const child of existingChildren) {
|
|
419
|
+
safeMove(viewport, child, null);
|
|
420
|
+
}
|
|
339
421
|
this.createdViewport = true;
|
|
340
422
|
return viewport;
|
|
341
423
|
}
|
|
@@ -352,8 +434,27 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
352
434
|
this.viewport.setAttribute("role", "region");
|
|
353
435
|
this.wasRoleInferred = true;
|
|
354
436
|
}
|
|
355
|
-
|
|
356
|
-
|
|
437
|
+
const rootLabelledBy = this.root.getAttribute("aria-labelledby")?.trim();
|
|
438
|
+
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
439
|
+
if (rootLabelledBy) {
|
|
440
|
+
this.hasRootAriaLabel = true;
|
|
441
|
+
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-labelledby") && !this.viewport.hasAttribute("aria-label")) {
|
|
442
|
+
this.viewport.setAttribute("aria-labelledby", rootLabelledBy);
|
|
443
|
+
this.propagatedRootLabel = "aria-labelledby";
|
|
444
|
+
}
|
|
445
|
+
} else if (rootAriaLabel) {
|
|
446
|
+
this.hasRootAriaLabel = true;
|
|
447
|
+
if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
448
|
+
this.viewport.setAttribute("aria-label", rootAriaLabel);
|
|
449
|
+
this.propagatedRootLabel = "aria-label";
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label")) {
|
|
453
|
+
this.viewport.setAttribute("aria-label", this.options.ariaLabel);
|
|
454
|
+
this.lastInferredAriaLabel = this.options.ariaLabel;
|
|
455
|
+
this.wasAriaLabelInferred = true;
|
|
456
|
+
} else if (!this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
|
|
457
|
+
const label = this.t("viewport");
|
|
357
458
|
this.viewport.setAttribute("aria-label", label);
|
|
358
459
|
this.lastInferredAriaLabel = label;
|
|
359
460
|
this.wasAriaLabelInferred = true;
|
|
@@ -383,10 +484,12 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
383
484
|
* Crée les rails et curseurs selon l'axe sélectionné.
|
|
384
485
|
*/
|
|
385
486
|
setupScrollbars() {
|
|
487
|
+
if (this.options.mode === "native") {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
386
490
|
if (this.options.axis === "y" || this.options.axis === "both") {
|
|
387
491
|
this.trackY = document.createElement("div");
|
|
388
492
|
this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
|
|
389
|
-
this.trackY.setAttribute("aria-hidden", "true");
|
|
390
493
|
this.thumbY = document.createElement("div");
|
|
391
494
|
this.thumbY.className = "wulf-scrollblock-thumb";
|
|
392
495
|
this.thumbY.setAttribute("role", "scrollbar");
|
|
@@ -403,7 +506,6 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
403
506
|
if (this.options.axis === "x" || this.options.axis === "both") {
|
|
404
507
|
this.trackX = document.createElement("div");
|
|
405
508
|
this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
|
|
406
|
-
this.trackX.setAttribute("aria-hidden", "true");
|
|
407
509
|
this.thumbX = document.createElement("div");
|
|
408
510
|
this.thumbX.className = "wulf-scrollblock-thumb";
|
|
409
511
|
this.thumbX.setAttribute("role", "scrollbar");
|
|
@@ -418,48 +520,129 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
418
520
|
this.attachTrackListeners(this.trackX, this.thumbX, "x");
|
|
419
521
|
}
|
|
420
522
|
}
|
|
523
|
+
isRtl() {
|
|
524
|
+
return typeof window !== "undefined" && window.getComputedStyle(this.viewport).direction === "rtl";
|
|
525
|
+
}
|
|
421
526
|
/**
|
|
422
|
-
* Attache les écouteurs sur un rail et son curseur.
|
|
527
|
+
* Attache les écouteurs souris/pointeur et clavier WAI-ARIA sur un rail et son curseur.
|
|
423
528
|
*/
|
|
424
529
|
attachTrackListeners(track, thumb, axis) {
|
|
530
|
+
const { signal } = this.abortController;
|
|
425
531
|
thumb.addEventListener("pointerdown", (e) => {
|
|
532
|
+
if (e.button !== 0) return;
|
|
426
533
|
e.preventDefault();
|
|
427
534
|
e.stopPropagation();
|
|
535
|
+
this.dragAbortController?.abort();
|
|
536
|
+
this.dragAbortController = new AbortController();
|
|
537
|
+
const dragSignal = this.dragAbortController.signal;
|
|
428
538
|
this.isDragging = true;
|
|
429
539
|
this.dragAxis = axis;
|
|
430
540
|
this.dragPointerId = e.pointerId;
|
|
431
541
|
this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
|
|
432
542
|
this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
433
|
-
|
|
543
|
+
try {
|
|
544
|
+
thumb.setPointerCapture(e.pointerId);
|
|
545
|
+
} catch {
|
|
546
|
+
}
|
|
434
547
|
thumb.classList.add("is-active");
|
|
435
548
|
this.root.classList.add("is-dragging");
|
|
436
|
-
window.addEventListener("pointermove", this.boundPointerMove);
|
|
437
|
-
window.addEventListener("pointerup", this.boundPointerUp);
|
|
438
|
-
window.addEventListener("pointercancel", this.boundPointerUp);
|
|
439
|
-
|
|
549
|
+
window.addEventListener("pointermove", this.boundPointerMove, { signal: dragSignal });
|
|
550
|
+
window.addEventListener("pointerup", this.boundPointerUp, { signal: dragSignal });
|
|
551
|
+
window.addEventListener("pointercancel", this.boundPointerUp, { signal: dragSignal });
|
|
552
|
+
thumb.addEventListener("lostpointercapture", this.boundPointerUp, { signal: dragSignal });
|
|
553
|
+
}, { signal });
|
|
554
|
+
thumb.addEventListener("keydown", (e) => {
|
|
555
|
+
if (e.ctrlKey || e.altKey || e.metaKey) return;
|
|
556
|
+
const step = 40;
|
|
557
|
+
const page = axis === "y" ? Math.max(step, Math.round(this.viewport.clientHeight * 0.9)) : Math.max(step, Math.round(this.viewport.clientWidth * 0.9));
|
|
558
|
+
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
559
|
+
if (maxScroll <= 0) return;
|
|
560
|
+
const rtl = axis === "x" && this.isRtl();
|
|
561
|
+
const current = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
|
|
562
|
+
let target = null;
|
|
563
|
+
if (axis === "y") {
|
|
564
|
+
switch (e.key) {
|
|
565
|
+
case "ArrowDown":
|
|
566
|
+
target = current + step;
|
|
567
|
+
break;
|
|
568
|
+
case "ArrowUp":
|
|
569
|
+
target = current - step;
|
|
570
|
+
break;
|
|
571
|
+
case "PageDown":
|
|
572
|
+
target = current + page;
|
|
573
|
+
break;
|
|
574
|
+
case "PageUp":
|
|
575
|
+
target = current - page;
|
|
576
|
+
break;
|
|
577
|
+
case " ":
|
|
578
|
+
target = current + (e.shiftKey ? -page : page);
|
|
579
|
+
break;
|
|
580
|
+
case "Home":
|
|
581
|
+
target = 0;
|
|
582
|
+
break;
|
|
583
|
+
case "End":
|
|
584
|
+
target = maxScroll;
|
|
585
|
+
break;
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
switch (e.key) {
|
|
589
|
+
case "ArrowRight":
|
|
590
|
+
target = current + step;
|
|
591
|
+
break;
|
|
592
|
+
case "ArrowLeft":
|
|
593
|
+
target = current - step;
|
|
594
|
+
break;
|
|
595
|
+
case "PageDown":
|
|
596
|
+
target = current + (rtl ? -page : page);
|
|
597
|
+
break;
|
|
598
|
+
case "PageUp":
|
|
599
|
+
target = current + (rtl ? page : -page);
|
|
600
|
+
break;
|
|
601
|
+
case " ":
|
|
602
|
+
target = current + (e.shiftKey ? rtl ? page : -page : rtl ? -page : page);
|
|
603
|
+
break;
|
|
604
|
+
case "Home":
|
|
605
|
+
target = 0;
|
|
606
|
+
break;
|
|
607
|
+
case "End":
|
|
608
|
+
target = rtl ? -maxScroll : maxScroll;
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
if (target === null) return;
|
|
613
|
+
e.preventDefault();
|
|
614
|
+
e.stopPropagation();
|
|
615
|
+
void this.scrollTo(axis === "y" ? { top: target } : { left: target }, { smooth: false });
|
|
616
|
+
this.syncThumbs();
|
|
617
|
+
}, { signal });
|
|
440
618
|
track.addEventListener("pointerdown", (e) => {
|
|
441
|
-
if (e.target === thumb) return;
|
|
619
|
+
if (e.button !== 0 || e.target === thumb) return;
|
|
442
620
|
e.preventDefault();
|
|
621
|
+
const rtl = axis === "x" && this.isRtl();
|
|
443
622
|
const rect = track.getBoundingClientRect();
|
|
444
|
-
const clickPos = axis === "y" ? e.clientY - rect.top : e.clientX - rect.left;
|
|
623
|
+
const clickPos = axis === "y" ? e.clientY - rect.top : rtl ? rect.right - e.clientX : e.clientX - rect.left;
|
|
445
624
|
const trackSize = axis === "y" ? rect.height : rect.width;
|
|
446
|
-
|
|
447
|
-
const
|
|
448
|
-
const ratio = clickPos / trackSize;
|
|
449
|
-
const targetScroll = ratio *
|
|
450
|
-
this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
451
|
-
});
|
|
625
|
+
if (trackSize <= 0) return;
|
|
626
|
+
const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
627
|
+
const ratio = Math.max(0, Math.min(1, clickPos / trackSize));
|
|
628
|
+
const targetScroll = rtl ? -(ratio * maxScroll) : ratio * maxScroll;
|
|
629
|
+
void this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
|
|
630
|
+
}, { signal });
|
|
452
631
|
}
|
|
453
632
|
/**
|
|
454
633
|
* Écouteurs globaux sur le viewport et les interactions.
|
|
455
634
|
*/
|
|
456
635
|
setupEventListeners() {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
this.
|
|
461
|
-
|
|
462
|
-
|
|
636
|
+
const { signal } = this.abortController;
|
|
637
|
+
this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true, signal });
|
|
638
|
+
if (this.supportsScrollEnd) {
|
|
639
|
+
this.viewport.addEventListener("scrollend", this.boundOnScrollEnd, { passive: true, signal });
|
|
640
|
+
}
|
|
641
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
642
|
+
this.root.addEventListener("mouseenter", this.boundOnMouseEnter, { signal });
|
|
643
|
+
this.root.addEventListener("mouseleave", this.boundOnMouseLeave, { signal });
|
|
644
|
+
this.root.addEventListener("focusin", this.boundOnFocusIn, { signal });
|
|
645
|
+
this.root.addEventListener("focusout", this.boundOnFocusOut, { signal });
|
|
463
646
|
}
|
|
464
647
|
}
|
|
465
648
|
/**
|
|
@@ -468,7 +651,13 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
468
651
|
setupObserver() {
|
|
469
652
|
if (typeof ResizeObserver !== "undefined") {
|
|
470
653
|
this.resizeObserver = new ResizeObserver(() => {
|
|
471
|
-
|
|
654
|
+
if (this.isDestroyed || this.resizeRafId !== null) return;
|
|
655
|
+
this.resizeRafId = window.requestAnimationFrame(() => {
|
|
656
|
+
this.resizeRafId = null;
|
|
657
|
+
if (!this.isDestroyed) {
|
|
658
|
+
this.update();
|
|
659
|
+
}
|
|
660
|
+
});
|
|
472
661
|
});
|
|
473
662
|
this.resizeObserver.observe(this.root);
|
|
474
663
|
this.resizeObserver.observe(this.viewport);
|
|
@@ -482,22 +671,20 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
482
671
|
*/
|
|
483
672
|
handlePointerMove(e) {
|
|
484
673
|
if (!this.isDragging || !this.dragAxis) return;
|
|
674
|
+
if (this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) return;
|
|
485
675
|
const isY = this.dragAxis === "y";
|
|
486
676
|
const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
|
|
487
|
-
const
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
const trackSize = isY ? track.clientHeight : track.clientWidth;
|
|
491
|
-
const thumbSize = isY ? thumb.clientHeight : thumb.clientWidth;
|
|
492
|
-
const clientSize = isY ? this.viewport.clientHeight : this.viewport.clientWidth;
|
|
493
|
-
const scrollSize = isY ? this.viewport.scrollHeight : this.viewport.scrollWidth;
|
|
494
|
-
const maxScroll = scrollSize - clientSize;
|
|
677
|
+
const trackSize = isY ? this.cachedTrackHeight : this.cachedTrackWidth;
|
|
678
|
+
const thumbSize = isY ? this.cachedThumbHeight : this.cachedThumbWidth;
|
|
679
|
+
const maxScroll = isY ? this.cachedMaxTop : this.cachedMaxLeft;
|
|
495
680
|
const maxThumbTravel = trackSize - thumbSize;
|
|
496
681
|
if (maxThumbTravel <= 0 || maxScroll <= 0) return;
|
|
497
682
|
const ratio = maxScroll / maxThumbTravel;
|
|
498
683
|
const nextScroll = this.dragStartScroll + delta * ratio;
|
|
499
684
|
if (isY) {
|
|
500
685
|
this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
686
|
+
} else if (this.isRtl()) {
|
|
687
|
+
this.viewport.scrollLeft = Math.max(-maxScroll, Math.min(0, nextScroll));
|
|
501
688
|
} else {
|
|
502
689
|
this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
|
|
503
690
|
}
|
|
@@ -507,15 +694,20 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
507
694
|
*/
|
|
508
695
|
handlePointerUp(e) {
|
|
509
696
|
if (!this.isDragging) return;
|
|
697
|
+
if (e && e.type !== "lostpointercapture" && this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
510
700
|
if (this.dragPointerId !== void 0) {
|
|
511
701
|
const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
|
|
512
|
-
|
|
513
|
-
activeThumb.
|
|
702
|
+
try {
|
|
703
|
+
if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
|
|
704
|
+
activeThumb.releasePointerCapture(this.dragPointerId);
|
|
705
|
+
}
|
|
706
|
+
} catch {
|
|
514
707
|
}
|
|
515
708
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
709
|
+
this.dragAbortController?.abort();
|
|
710
|
+
this.dragAbortController = void 0;
|
|
519
711
|
this.isDragging = false;
|
|
520
712
|
this.dragAxis = void 0;
|
|
521
713
|
this.dragPointerId = void 0;
|
|
@@ -524,24 +716,31 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
524
716
|
this.root.classList.remove("is-dragging");
|
|
525
717
|
this.scheduleAutoHide();
|
|
526
718
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
this.
|
|
532
|
-
const
|
|
533
|
-
const
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
const progressX = maxLeft > 0 ? scrollLeft / maxLeft : 0;
|
|
537
|
-
this.options.onScroll({
|
|
719
|
+
getScrollInfo() {
|
|
720
|
+
const { scrollTop, scrollLeft } = this.viewport;
|
|
721
|
+
const maxTop = this.cachedMaxTop;
|
|
722
|
+
const maxLeft = this.cachedMaxLeft;
|
|
723
|
+
const rtl = this.isRtl();
|
|
724
|
+
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
725
|
+
const progressY = maxTop > 0 ? Math.max(0, Math.min(1, scrollTop / maxTop)) : 0;
|
|
726
|
+
const progressX = maxLeft > 0 ? Math.max(0, Math.min(1, logicalLeft / maxLeft)) : 0;
|
|
727
|
+
return {
|
|
538
728
|
top: scrollTop,
|
|
539
729
|
left: scrollLeft,
|
|
540
730
|
maxTop,
|
|
541
731
|
maxLeft,
|
|
542
732
|
progressY: Math.round(progressY * 100),
|
|
543
733
|
progressX: Math.round(progressX * 100)
|
|
544
|
-
}
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Gestionnaire d'événement de défilement natif.
|
|
738
|
+
*/
|
|
739
|
+
handleScroll() {
|
|
740
|
+
this.scheduleSyncThumbs();
|
|
741
|
+
const info = this.getScrollInfo();
|
|
742
|
+
const { top: scrollTop, left: scrollLeft, maxTop, maxLeft } = info;
|
|
743
|
+
this.options.onScroll(info);
|
|
545
744
|
const threshold = this.options.edgeThreshold;
|
|
546
745
|
if (maxTop > 0) {
|
|
547
746
|
const nowBottom = scrollTop >= maxTop - threshold;
|
|
@@ -556,8 +755,9 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
556
755
|
this.atTop = nowTop;
|
|
557
756
|
}
|
|
558
757
|
if (maxLeft > 0) {
|
|
559
|
-
const
|
|
560
|
-
const
|
|
758
|
+
const rtl = this.isRtl();
|
|
759
|
+
const nowRight = rtl ? scrollLeft >= -threshold : scrollLeft >= maxLeft - threshold;
|
|
760
|
+
const nowLeft = rtl ? scrollLeft <= -maxLeft + threshold : scrollLeft <= threshold;
|
|
561
761
|
if (nowRight && !this.atRight) {
|
|
562
762
|
this.options.onTotalScroll("right");
|
|
563
763
|
}
|
|
@@ -567,37 +767,71 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
567
767
|
this.atRight = nowRight;
|
|
568
768
|
this.atLeft = nowLeft;
|
|
569
769
|
}
|
|
570
|
-
if (this.options.autoHide && !this.options.alwaysVisible) {
|
|
770
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
771
|
+
this.clearAutoHideTimer();
|
|
571
772
|
this.root.classList.add("is-scrolling");
|
|
773
|
+
if (!this.supportsScrollEnd) {
|
|
774
|
+
this.scheduleAutoHide();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (!this.supportsScrollEnd) {
|
|
778
|
+
if (this.scrollEndFallbackTimer !== void 0) {
|
|
779
|
+
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
780
|
+
}
|
|
781
|
+
this.scrollEndFallbackTimer = window.setTimeout(() => {
|
|
782
|
+
this.scrollEndFallbackTimer = void 0;
|
|
783
|
+
this.handleScrollEnd();
|
|
784
|
+
}, 150);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Gestionnaire de fin de défilement (`scrollend` natif ou repli temporisé).
|
|
789
|
+
*/
|
|
790
|
+
handleScrollEnd() {
|
|
791
|
+
this.options.onScrollEnd(this.getScrollInfo());
|
|
792
|
+
if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
|
|
572
793
|
this.scheduleAutoHide();
|
|
573
794
|
}
|
|
574
795
|
}
|
|
575
796
|
/**
|
|
576
|
-
*
|
|
797
|
+
* Planifie une synchronisation des curseurs calée sur la prochaine trame d'affichage.
|
|
798
|
+
*/
|
|
799
|
+
scheduleSyncThumbs() {
|
|
800
|
+
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
801
|
+
if (this.rafId !== null) return;
|
|
802
|
+
this.rafId = window.requestAnimationFrame(() => {
|
|
803
|
+
this.rafId = null;
|
|
804
|
+
if (!this.isDestroyed) {
|
|
805
|
+
this.syncThumbs();
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Synchronise la position physique (via variables CSS) et ARIA des curseurs à partir des métriques en cache.
|
|
577
811
|
*/
|
|
578
812
|
syncThumbs() {
|
|
579
|
-
|
|
813
|
+
if (this.options.mode === "native" || this.isDestroyed) return;
|
|
814
|
+
const { scrollTop, scrollLeft } = this.viewport;
|
|
580
815
|
if (this.thumbY && this.trackY) {
|
|
581
|
-
const maxScrollY =
|
|
582
|
-
const
|
|
583
|
-
const thumbHeight = this.thumbY.clientHeight;
|
|
584
|
-
const maxTravelY = trackHeight - thumbHeight;
|
|
816
|
+
const maxScrollY = this.cachedMaxTop;
|
|
817
|
+
const maxTravelY = this.cachedTrackHeight - this.cachedThumbHeight;
|
|
585
818
|
if (maxScrollY > 0 && maxTravelY > 0) {
|
|
586
|
-
const ratioY = scrollTop / maxScrollY;
|
|
819
|
+
const ratioY = Math.max(0, Math.min(1, scrollTop / maxScrollY));
|
|
587
820
|
const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
|
|
588
|
-
this.thumbY.style.
|
|
821
|
+
this.thumbY.style.setProperty("--scrollblock-thumb-y", `${posY}px`);
|
|
589
822
|
this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
|
|
590
823
|
}
|
|
591
824
|
}
|
|
592
825
|
if (this.thumbX && this.trackX) {
|
|
593
|
-
const maxScrollX =
|
|
594
|
-
const
|
|
595
|
-
const thumbWidth = this.thumbX.clientWidth;
|
|
596
|
-
const maxTravelX = trackWidth - thumbWidth;
|
|
826
|
+
const maxScrollX = this.cachedMaxLeft;
|
|
827
|
+
const maxTravelX = this.cachedTrackWidth - this.cachedThumbWidth;
|
|
597
828
|
if (maxScrollX > 0 && maxTravelX > 0) {
|
|
598
|
-
const
|
|
829
|
+
const rtl = this.isRtl();
|
|
830
|
+
const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
|
|
831
|
+
const ratioX = Math.max(0, Math.min(1, logicalLeft / maxScrollX));
|
|
599
832
|
const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
|
|
600
|
-
|
|
833
|
+
const signedPosX = rtl ? -posX : posX;
|
|
834
|
+
this.thumbX.style.setProperty("--scrollblock-thumb-x", `${signedPosX}px`);
|
|
601
835
|
this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
|
|
602
836
|
}
|
|
603
837
|
}
|
|
@@ -634,10 +868,37 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
634
868
|
* Recalcule les dimensions et la visibilité des barres.
|
|
635
869
|
*/
|
|
636
870
|
update() {
|
|
871
|
+
if (this.isDestroyed) return;
|
|
637
872
|
this.syncAccessibilityLabels();
|
|
638
873
|
const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
|
|
874
|
+
const trackHeight = this.trackY ? this.trackY.clientHeight : 0;
|
|
875
|
+
const trackWidth = this.trackX ? this.trackX.clientWidth : 0;
|
|
876
|
+
const cssMinY = this.thumbY && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbY).minBlockSize) || 0 : 0;
|
|
877
|
+
const cssMinX = this.thumbX && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbX).minInlineSize) || 0 : 0;
|
|
878
|
+
this.cachedMaxTop = Math.max(0, scrollHeight - clientHeight);
|
|
879
|
+
this.cachedMaxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
880
|
+
this.cachedTrackHeight = trackHeight;
|
|
881
|
+
this.cachedTrackWidth = trackWidth;
|
|
639
882
|
const canScrollY = scrollHeight > clientHeight;
|
|
640
883
|
const canScrollX = scrollWidth > clientWidth;
|
|
884
|
+
let calculatedHeight = this.cachedThumbHeight;
|
|
885
|
+
if (this.trackY && this.thumbY && canScrollY && scrollHeight > 0) {
|
|
886
|
+
const effectiveMinY = Math.max(this.options.minThumbSize, cssMinY);
|
|
887
|
+
calculatedHeight = Math.max(
|
|
888
|
+
effectiveMinY,
|
|
889
|
+
trackHeight * (clientHeight / scrollHeight)
|
|
890
|
+
);
|
|
891
|
+
this.cachedThumbHeight = calculatedHeight;
|
|
892
|
+
}
|
|
893
|
+
let calculatedWidth = this.cachedThumbWidth;
|
|
894
|
+
if (this.trackX && this.thumbX && canScrollX && scrollWidth > 0) {
|
|
895
|
+
const effectiveMinX = Math.max(this.options.minThumbSize, cssMinX);
|
|
896
|
+
calculatedWidth = Math.max(
|
|
897
|
+
effectiveMinX,
|
|
898
|
+
trackWidth * (clientWidth / scrollWidth)
|
|
899
|
+
);
|
|
900
|
+
this.cachedThumbWidth = calculatedWidth;
|
|
901
|
+
}
|
|
641
902
|
this.root.classList.toggle("has-scroll-y", canScrollY);
|
|
642
903
|
this.root.classList.toggle("has-scroll-x", canScrollX);
|
|
643
904
|
if (canScrollY || canScrollX) {
|
|
@@ -646,37 +907,40 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
646
907
|
this.viewport.removeAttribute("tabindex");
|
|
647
908
|
}
|
|
648
909
|
if (this.trackY && this.thumbY) {
|
|
910
|
+
this.trackY.hidden = !canScrollY;
|
|
649
911
|
if (canScrollY) {
|
|
650
|
-
|
|
651
|
-
const calculatedHeight = Math.max(
|
|
652
|
-
this.options.minThumbSize,
|
|
653
|
-
trackHeight * (clientHeight / scrollHeight)
|
|
654
|
-
);
|
|
912
|
+
this.thumbY.setAttribute("tabindex", "0");
|
|
655
913
|
this.thumbY.style.height = `${calculatedHeight}px`;
|
|
914
|
+
} else {
|
|
915
|
+
this.thumbY.removeAttribute("tabindex");
|
|
656
916
|
}
|
|
657
917
|
}
|
|
658
918
|
if (this.trackX && this.thumbX) {
|
|
919
|
+
this.trackX.hidden = !canScrollX;
|
|
659
920
|
if (canScrollX) {
|
|
660
|
-
|
|
661
|
-
const calculatedWidth = Math.max(
|
|
662
|
-
this.options.minThumbSize,
|
|
663
|
-
trackWidth * (clientWidth / scrollWidth)
|
|
664
|
-
);
|
|
921
|
+
this.thumbX.setAttribute("tabindex", "0");
|
|
665
922
|
this.thumbX.style.width = `${calculatedWidth}px`;
|
|
923
|
+
} else {
|
|
924
|
+
this.thumbX.removeAttribute("tabindex");
|
|
666
925
|
}
|
|
667
926
|
}
|
|
668
927
|
this.syncThumbs();
|
|
669
928
|
}
|
|
670
929
|
/**
|
|
671
930
|
* Défilement programmatique direct ou lissé.
|
|
931
|
+
* Retourne une Promesse résolue lorsque le défilement atteint sa cible.
|
|
672
932
|
*/
|
|
673
933
|
scrollTo(target, options) {
|
|
674
|
-
|
|
934
|
+
if (this.isDestroyed) return Promise.resolve();
|
|
675
935
|
const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
|
|
676
|
-
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion;
|
|
936
|
+
const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion();
|
|
677
937
|
const behavior = shouldSmooth ? "smooth" : "auto";
|
|
678
|
-
const
|
|
679
|
-
const
|
|
938
|
+
const rtl = this.isRtl();
|
|
939
|
+
const { scrollHeight, clientHeight, scrollWidth, clientWidth, scrollTop, scrollLeft } = this.viewport;
|
|
940
|
+
const maxTop = Math.max(0, scrollHeight - clientHeight);
|
|
941
|
+
const maxLeft = Math.max(0, scrollWidth - clientWidth);
|
|
942
|
+
this.cachedMaxTop = maxTop;
|
|
943
|
+
this.cachedMaxLeft = maxLeft;
|
|
680
944
|
let targetTop;
|
|
681
945
|
let targetLeft;
|
|
682
946
|
if (typeof target === "number") {
|
|
@@ -690,19 +954,19 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
690
954
|
targetTop = maxTop;
|
|
691
955
|
break;
|
|
692
956
|
case "left":
|
|
693
|
-
targetLeft = 0;
|
|
957
|
+
targetLeft = rtl ? -maxLeft : 0;
|
|
694
958
|
break;
|
|
695
959
|
case "right":
|
|
696
|
-
targetLeft = maxLeft;
|
|
960
|
+
targetLeft = rtl ? 0 : maxLeft;
|
|
697
961
|
break;
|
|
698
962
|
default: {
|
|
699
963
|
if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
|
|
700
964
|
const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
|
|
701
965
|
if (this.options.axis === "x") {
|
|
702
|
-
targetLeft = maxLeft * pct;
|
|
966
|
+
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
703
967
|
} else if (this.options.axis === "both") {
|
|
704
968
|
targetTop = maxTop * pct;
|
|
705
|
-
targetLeft = maxLeft * pct;
|
|
969
|
+
targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
|
|
706
970
|
} else {
|
|
707
971
|
targetTop = maxTop * pct;
|
|
708
972
|
}
|
|
@@ -715,24 +979,82 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
715
979
|
el = null;
|
|
716
980
|
}
|
|
717
981
|
if (el) {
|
|
718
|
-
|
|
719
|
-
|
|
982
|
+
const vpRect = this.viewport.getBoundingClientRect();
|
|
983
|
+
const elRect = el.getBoundingClientRect();
|
|
984
|
+
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
985
|
+
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
720
986
|
}
|
|
721
987
|
break;
|
|
722
988
|
}
|
|
723
989
|
}
|
|
724
990
|
} else if (target instanceof HTMLElement) {
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
991
|
+
const vpRect = this.viewport.getBoundingClientRect();
|
|
992
|
+
const elRect = target.getBoundingClientRect();
|
|
993
|
+
targetTop = elRect.top - vpRect.top + scrollTop;
|
|
994
|
+
targetLeft = elRect.left - vpRect.left + scrollLeft;
|
|
995
|
+
} else if (typeof target === "object" && target !== null) {
|
|
728
996
|
targetTop = target.top;
|
|
729
997
|
targetLeft = target.left;
|
|
730
998
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
999
|
+
const clampedTop = targetTop !== void 0 && Number.isFinite(targetTop) ? Math.max(0, Math.min(maxTop, targetTop)) : void 0;
|
|
1000
|
+
const minLeftBound = rtl ? -maxLeft : 0;
|
|
1001
|
+
const maxLeftBound = rtl ? 0 : maxLeft;
|
|
1002
|
+
const clampedLeft = targetLeft !== void 0 && Number.isFinite(targetLeft) ? Math.max(minLeftBound, Math.min(maxLeftBound, targetLeft)) : void 0;
|
|
1003
|
+
const destTop = clampedTop ?? scrollTop;
|
|
1004
|
+
const destLeft = clampedLeft ?? scrollLeft;
|
|
1005
|
+
if (Math.abs(destTop - scrollTop) <= 1 && Math.abs(destLeft - scrollLeft) <= 1) {
|
|
1006
|
+
return Promise.resolve();
|
|
1007
|
+
}
|
|
1008
|
+
this.activeScrollToController?.abort();
|
|
1009
|
+
const waitController = new AbortController();
|
|
1010
|
+
this.activeScrollToController = waitController;
|
|
1011
|
+
const nativeResult = this.viewport.scrollTo({
|
|
1012
|
+
top: clampedTop,
|
|
1013
|
+
left: clampedLeft,
|
|
734
1014
|
behavior
|
|
735
1015
|
});
|
|
1016
|
+
if (nativeResult instanceof Promise) {
|
|
1017
|
+
return nativeResult.then(() => {
|
|
1018
|
+
if (this.activeScrollToController === waitController) {
|
|
1019
|
+
this.activeScrollToController = void 0;
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
if (behavior !== "smooth") {
|
|
1024
|
+
if (this.activeScrollToController === waitController) {
|
|
1025
|
+
this.activeScrollToController = void 0;
|
|
1026
|
+
}
|
|
1027
|
+
return Promise.resolve();
|
|
1028
|
+
}
|
|
1029
|
+
return new Promise((resolve) => {
|
|
1030
|
+
let settled = false;
|
|
1031
|
+
let idleTimerId;
|
|
1032
|
+
let maxTimerId;
|
|
1033
|
+
const finish = () => {
|
|
1034
|
+
if (settled) return;
|
|
1035
|
+
settled = true;
|
|
1036
|
+
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1037
|
+
if (maxTimerId !== void 0) window.clearTimeout(maxTimerId);
|
|
1038
|
+
if (this.activeScrollToController === waitController) {
|
|
1039
|
+
this.activeScrollToController = void 0;
|
|
1040
|
+
}
|
|
1041
|
+
waitController.abort();
|
|
1042
|
+
resolve();
|
|
1043
|
+
};
|
|
1044
|
+
waitController.signal.addEventListener("abort", finish, { once: true });
|
|
1045
|
+
this.abortController.signal.addEventListener("abort", finish, { once: true, signal: waitController.signal });
|
|
1046
|
+
if (this.supportsScrollEnd) {
|
|
1047
|
+
this.viewport.addEventListener("scrollend", finish, { once: true, signal: waitController.signal });
|
|
1048
|
+
} else {
|
|
1049
|
+
const bumpIdle = () => {
|
|
1050
|
+
if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
|
|
1051
|
+
idleTimerId = window.setTimeout(finish, 150);
|
|
1052
|
+
};
|
|
1053
|
+
this.viewport.addEventListener("scroll", bumpIdle, { passive: true, signal: waitController.signal });
|
|
1054
|
+
bumpIdle();
|
|
1055
|
+
}
|
|
1056
|
+
maxTimerId = window.setTimeout(finish, 2500);
|
|
1057
|
+
});
|
|
736
1058
|
}
|
|
737
1059
|
/**
|
|
738
1060
|
* Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
|
|
@@ -745,12 +1067,12 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
745
1067
|
const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
|
|
746
1068
|
const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
|
|
747
1069
|
const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
|
|
748
|
-
if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
1070
|
+
if (!this.hasExplicitAriaLabel && !this.hasRootAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
|
|
749
1071
|
warnings.push(
|
|
750
1072
|
"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)."
|
|
751
1073
|
);
|
|
752
1074
|
}
|
|
753
|
-
if (this.options.minThumbSize < 24) {
|
|
1075
|
+
if (this.options.mode !== "native" && this.options.minThumbSize < 24) {
|
|
754
1076
|
warnings.push(
|
|
755
1077
|
`Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
|
|
756
1078
|
);
|
|
@@ -767,22 +1089,34 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
767
1089
|
* Détruit le composant et libère toutes les ressources.
|
|
768
1090
|
*/
|
|
769
1091
|
destroy() {
|
|
1092
|
+
if (this.isDestroyed) return;
|
|
1093
|
+
this.isDestroyed = true;
|
|
770
1094
|
this.clearAutoHideTimer();
|
|
1095
|
+
if (this.scrollEndFallbackTimer !== void 0) {
|
|
1096
|
+
window.clearTimeout(this.scrollEndFallbackTimer);
|
|
1097
|
+
this.scrollEndFallbackTimer = void 0;
|
|
1098
|
+
}
|
|
1099
|
+
if (this.rafId !== null) {
|
|
1100
|
+
window.cancelAnimationFrame(this.rafId);
|
|
1101
|
+
this.rafId = null;
|
|
1102
|
+
}
|
|
1103
|
+
if (this.resizeRafId !== null) {
|
|
1104
|
+
window.cancelAnimationFrame(this.resizeRafId);
|
|
1105
|
+
this.resizeRafId = null;
|
|
1106
|
+
}
|
|
1107
|
+
this.activeScrollToController?.abort();
|
|
1108
|
+
this.activeScrollToController = void 0;
|
|
1109
|
+
this.dragAbortController?.abort();
|
|
1110
|
+
this.dragAbortController = void 0;
|
|
1111
|
+
this.abortController.abort();
|
|
771
1112
|
if (this.resizeObserver) {
|
|
772
1113
|
this.resizeObserver.disconnect();
|
|
773
1114
|
}
|
|
774
|
-
this.viewport.removeEventListener("scroll", this.boundOnScroll);
|
|
775
|
-
this.root.removeEventListener("mouseenter", this.boundOnMouseEnter);
|
|
776
|
-
this.root.removeEventListener("mouseleave", this.boundOnMouseLeave);
|
|
777
|
-
this.root.removeEventListener("focusin", this.boundOnFocusIn);
|
|
778
|
-
this.root.removeEventListener("focusout", this.boundOnFocusOut);
|
|
779
|
-
window.removeEventListener("pointermove", this.boundPointerMove);
|
|
780
|
-
window.removeEventListener("pointerup", this.boundPointerUp);
|
|
781
|
-
window.removeEventListener("pointercancel", this.boundPointerUp);
|
|
782
1115
|
this.trackY?.remove();
|
|
783
1116
|
this.trackX?.remove();
|
|
784
1117
|
this.root.classList.remove(
|
|
785
1118
|
"wulf-scrollblock",
|
|
1119
|
+
"wulf-scrollblock--native",
|
|
786
1120
|
"has-scroll-y",
|
|
787
1121
|
"has-scroll-x",
|
|
788
1122
|
"has-both-axes",
|
|
@@ -793,7 +1127,7 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
793
1127
|
);
|
|
794
1128
|
if (this.createdViewport && this.viewport.parentElement === this.root) {
|
|
795
1129
|
while (this.viewport.firstChild) {
|
|
796
|
-
this.root
|
|
1130
|
+
safeMove(this.root, this.viewport.firstChild, this.viewport);
|
|
797
1131
|
}
|
|
798
1132
|
this.viewport.remove();
|
|
799
1133
|
} else {
|
|
@@ -804,14 +1138,15 @@ var ScrollBlock = class extends LocalizedComponent {
|
|
|
804
1138
|
if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
|
|
805
1139
|
this.viewport.removeAttribute("role");
|
|
806
1140
|
}
|
|
1141
|
+
if (this.propagatedRootLabel) {
|
|
1142
|
+
this.viewport.removeAttribute(this.propagatedRootLabel);
|
|
1143
|
+
}
|
|
807
1144
|
if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
|
|
808
1145
|
this.viewport.removeAttribute("aria-label");
|
|
809
1146
|
}
|
|
810
1147
|
}
|
|
811
1148
|
}
|
|
812
1149
|
};
|
|
813
|
-
ScrollBlock._i18n = scrollI18n;
|
|
814
|
-
ScrollBlock.i18n = scrollI18n;
|
|
815
1150
|
|
|
816
1151
|
// src/scroll/index.ts
|
|
817
1152
|
var Scroll = {
|
|
@@ -819,10 +1154,8 @@ var Scroll = {
|
|
|
819
1154
|
i18n: scrollI18n
|
|
820
1155
|
};
|
|
821
1156
|
var index_default = ScrollBlock;
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
const wulfNamespace = win.Wulf || {};
|
|
825
|
-
win.Wulf = wulfNamespace;
|
|
1157
|
+
var wulfNamespace = getSafeWulfNamespace();
|
|
1158
|
+
if (wulfNamespace) {
|
|
826
1159
|
wulfNamespace.Scroll = Scroll;
|
|
827
1160
|
}
|
|
828
1161
|
export {
|