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.
Files changed (81) hide show
  1. package/README.md +124 -78
  2. package/changelog.md +105 -0
  3. package/dist/focus-trap.esm.js +245 -126
  4. package/dist/focus-trap.esm.js.map +3 -3
  5. package/dist/focus-trap.global.js +247 -128
  6. package/dist/focus-trap.global.js.map +3 -3
  7. package/dist/focus-trap.global.min.js +4 -4
  8. package/dist/focus-trap.global.min.js.map +4 -4
  9. package/dist/index.esm.js +2434 -905
  10. package/dist/index.esm.js.map +4 -4
  11. package/dist/index.global.js +2436 -907
  12. package/dist/index.global.js.map +4 -4
  13. package/dist/index.global.min.js +4 -4
  14. package/dist/index.global.min.js.map +4 -4
  15. package/dist/mask.css +1 -1
  16. package/dist/mask.css.map +2 -2
  17. package/dist/mask.esm.js +746 -346
  18. package/dist/mask.esm.js.map +3 -3
  19. package/dist/mask.global.js +748 -348
  20. package/dist/mask.global.js.map +3 -3
  21. package/dist/mask.global.min.js +4 -4
  22. package/dist/mask.global.min.js.map +4 -4
  23. package/dist/mask.layered.css +1 -0
  24. package/dist/mask.layered.css.map +7 -0
  25. package/dist/masonry.css +1 -1
  26. package/dist/masonry.css.map +2 -2
  27. package/dist/masonry.esm.js +341 -114
  28. package/dist/masonry.esm.js.map +3 -3
  29. package/dist/masonry.global.js +343 -116
  30. package/dist/masonry.global.js.map +3 -3
  31. package/dist/masonry.global.min.js +4 -4
  32. package/dist/masonry.global.min.js.map +4 -4
  33. package/dist/masonry.layered.css +1 -0
  34. package/dist/masonry.layered.css.map +7 -0
  35. package/dist/scroll.css +1 -1
  36. package/dist/scroll.css.map +2 -2
  37. package/dist/scroll.esm.js +524 -153
  38. package/dist/scroll.esm.js.map +3 -3
  39. package/dist/scroll.global.js +526 -155
  40. package/dist/scroll.global.js.map +3 -3
  41. package/dist/scroll.global.min.js +4 -4
  42. package/dist/scroll.global.min.js.map +4 -4
  43. package/dist/scroll.layered.css +1 -0
  44. package/dist/scroll.layered.css.map +7 -0
  45. package/dist/shortcut.esm.js +209 -46
  46. package/dist/shortcut.esm.js.map +3 -3
  47. package/dist/shortcut.global.js +211 -48
  48. package/dist/shortcut.global.js.map +3 -3
  49. package/dist/shortcut.global.min.js +2 -2
  50. package/dist/shortcut.global.min.js.map +4 -4
  51. package/dist/toast.css +1 -1
  52. package/dist/toast.css.map +2 -2
  53. package/dist/toast.esm.js +590 -160
  54. package/dist/toast.esm.js.map +3 -3
  55. package/dist/toast.global.js +592 -162
  56. package/dist/toast.global.js.map +3 -3
  57. package/dist/toast.global.min.js +4 -4
  58. package/dist/toast.global.min.js.map +4 -4
  59. package/dist/toast.layered.css +1 -0
  60. package/dist/toast.layered.css.map +7 -0
  61. package/dist/types/common/dom.d.ts +38 -0
  62. package/dist/types/focus-trap/FocusTrap.d.ts +15 -5
  63. package/dist/types/focus-trap/types.d.ts +2 -2
  64. package/dist/types/index.d.ts +10 -0
  65. package/dist/types/mask/AmountEngine.d.ts +1 -0
  66. package/dist/types/mask/BaseInputMask.d.ts +24 -0
  67. package/dist/types/mask/InputAmountMask.d.ts +3 -0
  68. package/dist/types/mask/InputEmailMask.d.ts +16 -1
  69. package/dist/types/mask/InputMask.d.ts +1 -0
  70. package/dist/types/mask/MaskEngine.d.ts +4 -0
  71. package/dist/types/masonry/Masonry.d.ts +10 -3
  72. package/dist/types/scroll/ScrollBlock.d.ts +31 -3
  73. package/dist/types/scroll/types.d.ts +13 -1
  74. package/dist/types/shortcut/ShortcutFormatter.d.ts +6 -0
  75. package/dist/types/shortcut/ShortcutManager.d.ts +5 -0
  76. package/dist/types/toast/Toast.d.ts +4 -0
  77. package/dist/types/toast/ToastInstance.d.ts +22 -10
  78. package/dist/types/toast/ToastManager.d.ts +37 -4
  79. package/dist/types/toast/i18n/types.d.ts +2 -0
  80. package/dist/types/toast/types.d.ts +14 -2
  81. package/package.json +20 -5
@@ -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((id) => Boolean(doc.getElementById(id)));
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;
@@ -107,35 +142,49 @@ var LocalizedComponent = class extends AuditableComponent {
107
142
  };
108
143
 
109
144
  // src/common/i18n.ts
145
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
146
+ function isSafeKey(key) {
147
+ return Boolean(key) && !FORBIDDEN_KEYS.has(key);
148
+ }
110
149
  function normalizeLocaleCode(locale) {
111
- return locale.trim().toLowerCase().replace(/_/g, "-");
150
+ const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
151
+ return isSafeKey(norm) ? norm : "";
112
152
  }
113
153
  function getPrimaryLanguage(normalizedLocale) {
114
154
  const dashIndex = normalizedLocale.indexOf("-");
115
- return dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
155
+ const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
156
+ return primary && isSafeKey(primary) ? primary : null;
116
157
  }
117
158
  function assignDefined(target, source) {
118
- if (!source) return target;
159
+ if (!source || typeof source !== "object") return target;
119
160
  for (const key of Object.keys(source)) {
120
- if (source[key] !== void 0) {
161
+ if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
121
162
  target[key] = source[key];
122
163
  }
123
164
  }
124
165
  return target;
125
166
  }
126
167
  function createI18nManager(defaultLocale, locales) {
127
- const fallbackLocale = normalizeLocaleCode(defaultLocale);
128
- const initialLocales = {};
168
+ const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
169
+ const initialLocales = /* @__PURE__ */ Object.create(null);
129
170
  for (const [loc, dict] of Object.entries(locales)) {
130
- initialLocales[normalizeLocaleCode(loc)] = { ...dict };
171
+ const norm = normalizeLocaleCode(loc);
172
+ if (norm) {
173
+ initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
174
+ }
131
175
  }
132
176
  let currentLocale = fallbackLocale;
133
- let activeLocales = { ...initialLocales };
134
- let globalOverrides = {};
177
+ let activeLocales = /* @__PURE__ */ Object.create(null);
178
+ for (const [loc, dict] of Object.entries(initialLocales)) {
179
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
180
+ }
181
+ let globalOverrides = /* @__PURE__ */ Object.create(null);
135
182
  function resolveActiveDictionaries() {
136
183
  const dicts = [];
137
- const exact = activeLocales[currentLocale];
138
- if (exact) dicts.push(exact);
184
+ if (isSafeKey(currentLocale)) {
185
+ const exact = activeLocales[currentLocale];
186
+ if (exact) dicts.push(exact);
187
+ }
139
188
  const primary = getPrimaryLanguage(currentLocale);
140
189
  if (primary && activeLocales[primary]) {
141
190
  dicts.push(activeLocales[primary]);
@@ -144,24 +193,33 @@ function createI18nManager(defaultLocale, locales) {
144
193
  }
145
194
  return {
146
195
  setLocale(locale) {
147
- if (locale && locale.trim()) {
148
- currentLocale = normalizeLocaleCode(locale);
196
+ if (locale && typeof locale === "string" && locale.trim()) {
197
+ const norm = normalizeLocaleCode(locale);
198
+ if (norm) {
199
+ currentLocale = norm;
200
+ }
149
201
  }
150
202
  },
151
203
  getLocale() {
152
204
  return currentLocale;
153
205
  },
154
206
  registerLocale(locale, translations) {
155
- if (!locale || !locale.trim() || !translations) return;
207
+ if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
156
208
  const norm = normalizeLocaleCode(locale);
157
- activeLocales[norm] = assignDefined({ ...activeLocales[norm] || {} }, translations);
209
+ if (!norm) return;
210
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
211
+ activeLocales[norm] = assignDefined(base, translations);
158
212
  },
159
213
  setI18n(overrides) {
160
- if (!overrides) return;
161
- globalOverrides = assignDefined({ ...globalOverrides }, overrides);
214
+ if (!overrides || typeof overrides !== "object") return;
215
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
216
+ globalOverrides = assignDefined(base, overrides);
162
217
  },
163
218
  t(key, instanceOverride) {
164
- if (instanceOverride && instanceOverride[key] !== void 0) {
219
+ if (!isSafeKey(String(key))) {
220
+ return "";
221
+ }
222
+ if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
165
223
  return String(instanceOverride[key]);
166
224
  }
167
225
  if (globalOverrides[key] !== void 0) {
@@ -192,10 +250,10 @@ function createI18nManager(defaultLocale, locales) {
192
250
  },
193
251
  reset() {
194
252
  currentLocale = fallbackLocale;
195
- globalOverrides = {};
196
- activeLocales = {};
253
+ globalOverrides = /* @__PURE__ */ Object.create(null);
254
+ activeLocales = /* @__PURE__ */ Object.create(null);
197
255
  for (const [loc, dict] of Object.entries(initialLocales)) {
198
- activeLocales[loc] = { ...dict };
256
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
199
257
  }
200
258
  }
201
259
  };
@@ -224,38 +282,95 @@ var scrollI18n = createI18nManager("fr", {
224
282
  // src/scroll/ScrollBlock.ts
225
283
  var idCounter = 0;
226
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;
227
337
  constructor(element, options) {
228
338
  super(options?.i18n);
229
- this.createdViewport = false;
230
- this.wasIdGenerated = false;
231
- this.wasRoleInferred = false;
232
- this.wasAriaLabelInferred = false;
233
- this.hasExplicitAriaLabel = false;
234
- this.lastInferredAriaLabel = "";
235
- this.isDragging = false;
236
- this.dragStartPos = 0;
237
- this.dragStartScroll = 0;
238
- this.atBottom = false;
239
- this.atTop = true;
240
- this.atRight = false;
241
- this.atLeft = true;
242
- const resolvedElement = typeof element === "string" ? document.querySelector(element) : element;
243
- if (!resolvedElement) {
339
+ let resolvedElement = null;
340
+ if (typeof element === "string") {
341
+ try {
342
+ resolvedElement = document.querySelector(element);
343
+ } catch {
344
+ resolvedElement = null;
345
+ }
346
+ } else {
347
+ resolvedElement = element;
348
+ }
349
+ if (!resolvedElement || !(resolvedElement instanceof HTMLElement)) {
244
350
  throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
245
351
  }
246
352
  this.root = resolvedElement;
247
353
  this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
354
+ const rawDelay = options?.autoHideDelay;
355
+ const safeAutoHideDelay = typeof rawDelay === "number" && Number.isFinite(rawDelay) && rawDelay >= 0 ? rawDelay : 1e3;
356
+ const rawMinThumb = options?.minThumbSize;
357
+ const safeMinThumbSize = typeof rawMinThumb === "number" && Number.isFinite(rawMinThumb) && rawMinThumb > 0 ? rawMinThumb : 24;
358
+ const rawEdge = options?.edgeThreshold;
359
+ const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
248
360
  this.options = {
249
361
  axis: options?.axis || "y",
362
+ mode: options?.mode || "custom",
250
363
  autoHide: options?.autoHide ?? true,
251
- autoHideDelay: options?.autoHideDelay ?? 1e3,
364
+ autoHideDelay: safeAutoHideDelay,
252
365
  alwaysVisible: options?.alwaysVisible ?? false,
253
366
  ariaLabel: options?.ariaLabel || this.t("viewport"),
254
367
  i18n: options?.i18n || {},
255
- minThumbSize: options?.minThumbSize ?? 24,
256
- edgeThreshold: options?.edgeThreshold ?? 10,
368
+ minThumbSize: safeMinThumbSize,
369
+ edgeThreshold: safeEdgeThreshold,
257
370
  onScroll: options?.onScroll || (() => {
258
371
  }),
372
+ onScrollEnd: options?.onScrollEnd || (() => {
373
+ }),
259
374
  onTotalScroll: options?.onTotalScroll || (() => {
260
375
  }),
261
376
  onTotalScrollBack: options?.onTotalScrollBack || (() => {
@@ -263,6 +378,7 @@ var ScrollBlock = class extends LocalizedComponent {
263
378
  audit: options?.audit ?? true
264
379
  };
265
380
  this.boundOnScroll = this.handleScroll.bind(this);
381
+ this.boundOnScrollEnd = this.handleScrollEnd.bind(this);
266
382
  this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
267
383
  this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
268
384
  this.boundOnFocusIn = this.handleFocusIn.bind(this);
@@ -282,6 +398,9 @@ var ScrollBlock = class extends LocalizedComponent {
282
398
  */
283
399
  setupViewport() {
284
400
  this.root.classList.add("wulf-scrollblock");
401
+ if (this.options.mode === "native") {
402
+ this.root.classList.add("wulf-scrollblock--native");
403
+ }
285
404
  if (this.options.alwaysVisible) {
286
405
  this.root.classList.add("is-always-visible");
287
406
  }
@@ -292,12 +411,13 @@ var ScrollBlock = class extends LocalizedComponent {
292
411
  if (existingViewport) {
293
412
  return existingViewport;
294
413
  }
414
+ const existingChildren = Array.from(this.root.childNodes);
295
415
  const viewport = document.createElement("div");
296
416
  viewport.className = "wulf-scrollblock-viewport";
297
- while (this.root.firstChild) {
298
- viewport.appendChild(this.root.firstChild);
299
- }
300
417
  this.root.appendChild(viewport);
418
+ for (const child of existingChildren) {
419
+ safeMove(viewport, child, null);
420
+ }
301
421
  this.createdViewport = true;
302
422
  return viewport;
303
423
  }
@@ -314,8 +434,27 @@ var ScrollBlock = class extends LocalizedComponent {
314
434
  this.viewport.setAttribute("role", "region");
315
435
  this.wasRoleInferred = true;
316
436
  }
317
- if (!this.viewport.hasAttribute("aria-label")) {
318
- const label = this.hasExplicitAriaLabel ? this.options.ariaLabel : this.t("viewport");
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");
319
458
  this.viewport.setAttribute("aria-label", label);
320
459
  this.lastInferredAriaLabel = label;
321
460
  this.wasAriaLabelInferred = true;
@@ -345,10 +484,12 @@ var ScrollBlock = class extends LocalizedComponent {
345
484
  * Crée les rails et curseurs selon l'axe sélectionné.
346
485
  */
347
486
  setupScrollbars() {
487
+ if (this.options.mode === "native") {
488
+ return;
489
+ }
348
490
  if (this.options.axis === "y" || this.options.axis === "both") {
349
491
  this.trackY = document.createElement("div");
350
492
  this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
351
- this.trackY.setAttribute("aria-hidden", "true");
352
493
  this.thumbY = document.createElement("div");
353
494
  this.thumbY.className = "wulf-scrollblock-thumb";
354
495
  this.thumbY.setAttribute("role", "scrollbar");
@@ -365,7 +506,6 @@ var ScrollBlock = class extends LocalizedComponent {
365
506
  if (this.options.axis === "x" || this.options.axis === "both") {
366
507
  this.trackX = document.createElement("div");
367
508
  this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
368
- this.trackX.setAttribute("aria-hidden", "true");
369
509
  this.thumbX = document.createElement("div");
370
510
  this.thumbX.className = "wulf-scrollblock-thumb";
371
511
  this.thumbX.setAttribute("role", "scrollbar");
@@ -380,48 +520,129 @@ var ScrollBlock = class extends LocalizedComponent {
380
520
  this.attachTrackListeners(this.trackX, this.thumbX, "x");
381
521
  }
382
522
  }
523
+ isRtl() {
524
+ return typeof window !== "undefined" && window.getComputedStyle(this.viewport).direction === "rtl";
525
+ }
383
526
  /**
384
- * 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.
385
528
  */
386
529
  attachTrackListeners(track, thumb, axis) {
530
+ const { signal } = this.abortController;
387
531
  thumb.addEventListener("pointerdown", (e) => {
532
+ if (e.button !== 0) return;
388
533
  e.preventDefault();
389
534
  e.stopPropagation();
535
+ this.dragAbortController?.abort();
536
+ this.dragAbortController = new AbortController();
537
+ const dragSignal = this.dragAbortController.signal;
390
538
  this.isDragging = true;
391
539
  this.dragAxis = axis;
392
540
  this.dragPointerId = e.pointerId;
393
541
  this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
394
542
  this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
395
- thumb.setPointerCapture(e.pointerId);
543
+ try {
544
+ thumb.setPointerCapture(e.pointerId);
545
+ } catch {
546
+ }
396
547
  thumb.classList.add("is-active");
397
548
  this.root.classList.add("is-dragging");
398
- window.addEventListener("pointermove", this.boundPointerMove);
399
- window.addEventListener("pointerup", this.boundPointerUp);
400
- window.addEventListener("pointercancel", this.boundPointerUp);
401
- });
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 });
402
618
  track.addEventListener("pointerdown", (e) => {
403
- if (e.target === thumb) return;
619
+ if (e.button !== 0 || e.target === thumb) return;
404
620
  e.preventDefault();
621
+ const rtl = axis === "x" && this.isRtl();
405
622
  const rect = track.getBoundingClientRect();
406
- 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;
407
624
  const trackSize = axis === "y" ? rect.height : rect.width;
408
- const clientSize = axis === "y" ? this.viewport.clientHeight : this.viewport.clientWidth;
409
- const scrollSize = axis === "y" ? this.viewport.scrollHeight : this.viewport.scrollWidth;
410
- const ratio = clickPos / trackSize;
411
- const targetScroll = ratio * (scrollSize - clientSize);
412
- this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
413
- });
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 });
414
631
  }
415
632
  /**
416
633
  * Écouteurs globaux sur le viewport et les interactions.
417
634
  */
418
635
  setupEventListeners() {
419
- this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true });
420
- if (this.options.autoHide && !this.options.alwaysVisible) {
421
- this.root.addEventListener("mouseenter", this.boundOnMouseEnter);
422
- this.root.addEventListener("mouseleave", this.boundOnMouseLeave);
423
- this.root.addEventListener("focusin", this.boundOnFocusIn);
424
- this.root.addEventListener("focusout", this.boundOnFocusOut);
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 });
425
646
  }
426
647
  }
427
648
  /**
@@ -430,7 +651,13 @@ var ScrollBlock = class extends LocalizedComponent {
430
651
  setupObserver() {
431
652
  if (typeof ResizeObserver !== "undefined") {
432
653
  this.resizeObserver = new ResizeObserver(() => {
433
- window.requestAnimationFrame(() => this.update());
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
+ });
434
661
  });
435
662
  this.resizeObserver.observe(this.root);
436
663
  this.resizeObserver.observe(this.viewport);
@@ -444,22 +671,20 @@ var ScrollBlock = class extends LocalizedComponent {
444
671
  */
445
672
  handlePointerMove(e) {
446
673
  if (!this.isDragging || !this.dragAxis) return;
674
+ if (this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) return;
447
675
  const isY = this.dragAxis === "y";
448
676
  const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
449
- const track = isY ? this.trackY : this.trackX;
450
- const thumb = isY ? this.thumbY : this.thumbX;
451
- if (!track || !thumb) return;
452
- const trackSize = isY ? track.clientHeight : track.clientWidth;
453
- const thumbSize = isY ? thumb.clientHeight : thumb.clientWidth;
454
- const clientSize = isY ? this.viewport.clientHeight : this.viewport.clientWidth;
455
- const scrollSize = isY ? this.viewport.scrollHeight : this.viewport.scrollWidth;
456
- 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;
457
680
  const maxThumbTravel = trackSize - thumbSize;
458
681
  if (maxThumbTravel <= 0 || maxScroll <= 0) return;
459
682
  const ratio = maxScroll / maxThumbTravel;
460
683
  const nextScroll = this.dragStartScroll + delta * ratio;
461
684
  if (isY) {
462
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));
463
688
  } else {
464
689
  this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
465
690
  }
@@ -469,15 +694,20 @@ var ScrollBlock = class extends LocalizedComponent {
469
694
  */
470
695
  handlePointerUp(e) {
471
696
  if (!this.isDragging) return;
697
+ if (e && e.type !== "lostpointercapture" && this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) {
698
+ return;
699
+ }
472
700
  if (this.dragPointerId !== void 0) {
473
701
  const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
474
- if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
475
- activeThumb.releasePointerCapture(this.dragPointerId);
702
+ try {
703
+ if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
704
+ activeThumb.releasePointerCapture(this.dragPointerId);
705
+ }
706
+ } catch {
476
707
  }
477
708
  }
478
- window.removeEventListener("pointermove", this.boundPointerMove);
479
- window.removeEventListener("pointerup", this.boundPointerUp);
480
- window.removeEventListener("pointercancel", this.boundPointerUp);
709
+ this.dragAbortController?.abort();
710
+ this.dragAbortController = void 0;
481
711
  this.isDragging = false;
482
712
  this.dragAxis = void 0;
483
713
  this.dragPointerId = void 0;
@@ -486,24 +716,31 @@ var ScrollBlock = class extends LocalizedComponent {
486
716
  this.root.classList.remove("is-dragging");
487
717
  this.scheduleAutoHide();
488
718
  }
489
- /**
490
- * Gestionnaire d'événement de défilement natif.
491
- */
492
- handleScroll() {
493
- this.syncThumbs();
494
- const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
495
- const maxTop = Math.max(0, scrollHeight - clientHeight);
496
- const maxLeft = Math.max(0, scrollWidth - clientWidth);
497
- const progressY = maxTop > 0 ? scrollTop / maxTop : 0;
498
- const progressX = maxLeft > 0 ? scrollLeft / maxLeft : 0;
499
- 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 {
500
728
  top: scrollTop,
501
729
  left: scrollLeft,
502
730
  maxTop,
503
731
  maxLeft,
504
732
  progressY: Math.round(progressY * 100),
505
733
  progressX: Math.round(progressX * 100)
506
- });
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);
507
744
  const threshold = this.options.edgeThreshold;
508
745
  if (maxTop > 0) {
509
746
  const nowBottom = scrollTop >= maxTop - threshold;
@@ -518,8 +755,9 @@ var ScrollBlock = class extends LocalizedComponent {
518
755
  this.atTop = nowTop;
519
756
  }
520
757
  if (maxLeft > 0) {
521
- const nowRight = scrollLeft >= maxLeft - threshold;
522
- const nowLeft = scrollLeft <= threshold;
758
+ const rtl = this.isRtl();
759
+ const nowRight = rtl ? scrollLeft >= -threshold : scrollLeft >= maxLeft - threshold;
760
+ const nowLeft = rtl ? scrollLeft <= -maxLeft + threshold : scrollLeft <= threshold;
523
761
  if (nowRight && !this.atRight) {
524
762
  this.options.onTotalScroll("right");
525
763
  }
@@ -529,37 +767,71 @@ var ScrollBlock = class extends LocalizedComponent {
529
767
  this.atRight = nowRight;
530
768
  this.atLeft = nowLeft;
531
769
  }
532
- if (this.options.autoHide && !this.options.alwaysVisible) {
770
+ if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
771
+ this.clearAutoHideTimer();
533
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) {
534
793
  this.scheduleAutoHide();
535
794
  }
536
795
  }
537
796
  /**
538
- * Synchronise la position physique et ARIA des curseurs.
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.
539
811
  */
540
812
  syncThumbs() {
541
- const { scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth } = this.viewport;
813
+ if (this.options.mode === "native" || this.isDestroyed) return;
814
+ const { scrollTop, scrollLeft } = this.viewport;
542
815
  if (this.thumbY && this.trackY) {
543
- const maxScrollY = scrollHeight - clientHeight;
544
- const trackHeight = this.trackY.clientHeight;
545
- const thumbHeight = this.thumbY.clientHeight;
546
- const maxTravelY = trackHeight - thumbHeight;
816
+ const maxScrollY = this.cachedMaxTop;
817
+ const maxTravelY = this.cachedTrackHeight - this.cachedThumbHeight;
547
818
  if (maxScrollY > 0 && maxTravelY > 0) {
548
- const ratioY = scrollTop / maxScrollY;
819
+ const ratioY = Math.max(0, Math.min(1, scrollTop / maxScrollY));
549
820
  const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
550
- this.thumbY.style.transform = `translate3d(0, ${posY}px, 0)`;
821
+ this.thumbY.style.setProperty("--scrollblock-thumb-y", `${posY}px`);
551
822
  this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
552
823
  }
553
824
  }
554
825
  if (this.thumbX && this.trackX) {
555
- const maxScrollX = scrollWidth - clientWidth;
556
- const trackWidth = this.trackX.clientWidth;
557
- const thumbWidth = this.thumbX.clientWidth;
558
- const maxTravelX = trackWidth - thumbWidth;
826
+ const maxScrollX = this.cachedMaxLeft;
827
+ const maxTravelX = this.cachedTrackWidth - this.cachedThumbWidth;
559
828
  if (maxScrollX > 0 && maxTravelX > 0) {
560
- const ratioX = scrollLeft / maxScrollX;
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));
561
832
  const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
562
- this.thumbX.style.transform = `translate3d(${posX}px, 0, 0)`;
833
+ const signedPosX = rtl ? -posX : posX;
834
+ this.thumbX.style.setProperty("--scrollblock-thumb-x", `${signedPosX}px`);
563
835
  this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
564
836
  }
565
837
  }
@@ -596,10 +868,37 @@ var ScrollBlock = class extends LocalizedComponent {
596
868
  * Recalcule les dimensions et la visibilité des barres.
597
869
  */
598
870
  update() {
871
+ if (this.isDestroyed) return;
599
872
  this.syncAccessibilityLabels();
600
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;
601
882
  const canScrollY = scrollHeight > clientHeight;
602
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
+ }
603
902
  this.root.classList.toggle("has-scroll-y", canScrollY);
604
903
  this.root.classList.toggle("has-scroll-x", canScrollX);
605
904
  if (canScrollY || canScrollX) {
@@ -608,37 +907,40 @@ var ScrollBlock = class extends LocalizedComponent {
608
907
  this.viewport.removeAttribute("tabindex");
609
908
  }
610
909
  if (this.trackY && this.thumbY) {
910
+ this.trackY.hidden = !canScrollY;
611
911
  if (canScrollY) {
612
- const trackHeight = this.trackY.clientHeight;
613
- const calculatedHeight = Math.max(
614
- this.options.minThumbSize,
615
- trackHeight * (clientHeight / scrollHeight)
616
- );
912
+ this.thumbY.setAttribute("tabindex", "0");
617
913
  this.thumbY.style.height = `${calculatedHeight}px`;
914
+ } else {
915
+ this.thumbY.removeAttribute("tabindex");
618
916
  }
619
917
  }
620
918
  if (this.trackX && this.thumbX) {
919
+ this.trackX.hidden = !canScrollX;
621
920
  if (canScrollX) {
622
- const trackWidth = this.trackX.clientWidth;
623
- const calculatedWidth = Math.max(
624
- this.options.minThumbSize,
625
- trackWidth * (clientWidth / scrollWidth)
626
- );
921
+ this.thumbX.setAttribute("tabindex", "0");
627
922
  this.thumbX.style.width = `${calculatedWidth}px`;
923
+ } else {
924
+ this.thumbX.removeAttribute("tabindex");
628
925
  }
629
926
  }
630
927
  this.syncThumbs();
631
928
  }
632
929
  /**
633
930
  * Défilement programmatique direct ou lissé.
931
+ * Retourne une Promesse résolue lorsque le défilement atteint sa cible.
634
932
  */
635
933
  scrollTo(target, options) {
636
- const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
934
+ if (this.isDestroyed) return Promise.resolve();
637
935
  const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
638
- const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion;
936
+ const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion();
639
937
  const behavior = shouldSmooth ? "smooth" : "auto";
640
- const maxTop = Math.max(0, this.viewport.scrollHeight - this.viewport.clientHeight);
641
- const maxLeft = Math.max(0, this.viewport.scrollWidth - this.viewport.clientWidth);
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;
642
944
  let targetTop;
643
945
  let targetLeft;
644
946
  if (typeof target === "number") {
@@ -652,19 +954,19 @@ var ScrollBlock = class extends LocalizedComponent {
652
954
  targetTop = maxTop;
653
955
  break;
654
956
  case "left":
655
- targetLeft = 0;
957
+ targetLeft = rtl ? -maxLeft : 0;
656
958
  break;
657
959
  case "right":
658
- targetLeft = maxLeft;
960
+ targetLeft = rtl ? 0 : maxLeft;
659
961
  break;
660
962
  default: {
661
963
  if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
662
964
  const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
663
965
  if (this.options.axis === "x") {
664
- targetLeft = maxLeft * pct;
966
+ targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
665
967
  } else if (this.options.axis === "both") {
666
968
  targetTop = maxTop * pct;
667
- targetLeft = maxLeft * pct;
969
+ targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
668
970
  } else {
669
971
  targetTop = maxTop * pct;
670
972
  }
@@ -677,24 +979,82 @@ var ScrollBlock = class extends LocalizedComponent {
677
979
  el = null;
678
980
  }
679
981
  if (el) {
680
- targetTop = el.offsetTop;
681
- targetLeft = el.offsetLeft;
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;
682
986
  }
683
987
  break;
684
988
  }
685
989
  }
686
990
  } else if (target instanceof HTMLElement) {
687
- targetTop = target.offsetTop;
688
- targetLeft = target.offsetLeft;
689
- } else if (typeof target === "object") {
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) {
690
996
  targetTop = target.top;
691
997
  targetLeft = target.left;
692
998
  }
693
- this.viewport.scrollTo({
694
- top: targetTop !== void 0 ? Math.max(0, Math.min(maxTop, targetTop)) : void 0,
695
- left: targetLeft !== void 0 ? Math.max(0, Math.min(maxLeft, targetLeft)) : void 0,
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,
696
1014
  behavior
697
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
+ });
698
1058
  }
699
1059
  /**
700
1060
  * Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
@@ -707,12 +1067,12 @@ var ScrollBlock = class extends LocalizedComponent {
707
1067
  const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
708
1068
  const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
709
1069
  const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
710
- if (!this.hasExplicitAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
1070
+ if (!this.hasExplicitAriaLabel && !this.hasRootAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
711
1071
  warnings.push(
712
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)."
713
1073
  );
714
1074
  }
715
- if (this.options.minThumbSize < 24) {
1075
+ if (this.options.mode !== "native" && this.options.minThumbSize < 24) {
716
1076
  warnings.push(
717
1077
  `Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
718
1078
  );
@@ -729,22 +1089,34 @@ var ScrollBlock = class extends LocalizedComponent {
729
1089
  * Détruit le composant et libère toutes les ressources.
730
1090
  */
731
1091
  destroy() {
1092
+ if (this.isDestroyed) return;
1093
+ this.isDestroyed = true;
732
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();
733
1112
  if (this.resizeObserver) {
734
1113
  this.resizeObserver.disconnect();
735
1114
  }
736
- this.viewport.removeEventListener("scroll", this.boundOnScroll);
737
- this.root.removeEventListener("mouseenter", this.boundOnMouseEnter);
738
- this.root.removeEventListener("mouseleave", this.boundOnMouseLeave);
739
- this.root.removeEventListener("focusin", this.boundOnFocusIn);
740
- this.root.removeEventListener("focusout", this.boundOnFocusOut);
741
- window.removeEventListener("pointermove", this.boundPointerMove);
742
- window.removeEventListener("pointerup", this.boundPointerUp);
743
- window.removeEventListener("pointercancel", this.boundPointerUp);
744
1115
  this.trackY?.remove();
745
1116
  this.trackX?.remove();
746
1117
  this.root.classList.remove(
747
1118
  "wulf-scrollblock",
1119
+ "wulf-scrollblock--native",
748
1120
  "has-scroll-y",
749
1121
  "has-scroll-x",
750
1122
  "has-both-axes",
@@ -755,7 +1127,7 @@ var ScrollBlock = class extends LocalizedComponent {
755
1127
  );
756
1128
  if (this.createdViewport && this.viewport.parentElement === this.root) {
757
1129
  while (this.viewport.firstChild) {
758
- this.root.insertBefore(this.viewport.firstChild, this.viewport);
1130
+ safeMove(this.root, this.viewport.firstChild, this.viewport);
759
1131
  }
760
1132
  this.viewport.remove();
761
1133
  } else {
@@ -766,14 +1138,15 @@ var ScrollBlock = class extends LocalizedComponent {
766
1138
  if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
767
1139
  this.viewport.removeAttribute("role");
768
1140
  }
1141
+ if (this.propagatedRootLabel) {
1142
+ this.viewport.removeAttribute(this.propagatedRootLabel);
1143
+ }
769
1144
  if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
770
1145
  this.viewport.removeAttribute("aria-label");
771
1146
  }
772
1147
  }
773
1148
  }
774
1149
  };
775
- ScrollBlock._i18n = scrollI18n;
776
- ScrollBlock.i18n = scrollI18n;
777
1150
 
778
1151
  // src/scroll/index.ts
779
1152
  var Scroll = {
@@ -781,10 +1154,8 @@ var Scroll = {
781
1154
  i18n: scrollI18n
782
1155
  };
783
1156
  var index_default = ScrollBlock;
784
- if (typeof window !== "undefined") {
785
- const win = window;
786
- const wulfNamespace = win.Wulf || {};
787
- win.Wulf = wulfNamespace;
1157
+ var wulfNamespace = getSafeWulfNamespace();
1158
+ if (wulfNamespace) {
788
1159
  wulfNamespace.Scroll = Scroll;
789
1160
  }
790
1161
  export {