wulf.js 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +217 -11
  2. package/changelog.md +50 -0
  3. package/dist/anchor.esm.js +9 -0
  4. package/dist/anchor.esm.js.map +7 -0
  5. package/dist/anchor.global.js +695 -0
  6. package/dist/anchor.global.js.map +7 -0
  7. package/dist/anchor.global.min.js +6 -0
  8. package/dist/anchor.global.min.js.map +7 -0
  9. package/dist/autosize.css +1 -0
  10. package/dist/autosize.css.map +7 -0
  11. package/dist/autosize.esm.js +10 -0
  12. package/dist/autosize.esm.js.map +7 -0
  13. package/dist/autosize.global.js +657 -0
  14. package/dist/autosize.global.js.map +7 -0
  15. package/dist/autosize.global.min.js +6 -0
  16. package/dist/autosize.global.min.js.map +7 -0
  17. package/dist/autosize.layered.css +1 -0
  18. package/dist/autosize.layered.css.map +7 -0
  19. package/dist/chunks/chunk-22AIMRD5.js +119 -0
  20. package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
  21. package/dist/chunks/chunk-5N2IRGDM.js +766 -0
  22. package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
  23. package/dist/chunks/chunk-72FVCNNZ.js +863 -0
  24. package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
  25. package/dist/chunks/chunk-AXZYYW7H.js +865 -0
  26. package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
  27. package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
  28. package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
  29. package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
  30. package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
  31. package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
  32. package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
  33. package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
  34. package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
  35. package/dist/chunks/chunk-QV46A7FV.js +197 -0
  36. package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
  37. package/dist/chunks/chunk-SXLUXN6W.js +612 -0
  38. package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
  39. package/dist/chunks/chunk-T2H4EJCW.js +621 -0
  40. package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
  41. package/dist/chunks/chunk-TILLYEF2.js +6044 -0
  42. package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
  43. package/dist/chunks/chunk-VJO22BAT.js +72 -0
  44. package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
  45. package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
  46. package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
  47. package/dist/focus-trap.esm.js +6 -594
  48. package/dist/focus-trap.esm.js.map +3 -3
  49. package/dist/focus-trap.global.js +176 -61
  50. package/dist/focus-trap.global.js.map +3 -3
  51. package/dist/focus-trap.global.min.js +4 -4
  52. package/dist/focus-trap.global.min.js.map +4 -4
  53. package/dist/index.esm.js +79 -10448
  54. package/dist/index.esm.js.map +4 -4
  55. package/dist/index.global.js +3660 -202
  56. package/dist/index.global.js.map +4 -4
  57. package/dist/index.global.min.js +6 -3
  58. package/dist/index.global.min.js.map +4 -4
  59. package/dist/mask.esm.js +16 -6094
  60. package/dist/mask.esm.js.map +4 -4
  61. package/dist/mask.global.js +44 -55
  62. package/dist/mask.global.js.map +3 -3
  63. package/dist/mask.global.min.js +3 -3
  64. package/dist/mask.global.min.js.map +4 -4
  65. package/dist/masonry.esm.js +15 -1158
  66. package/dist/masonry.esm.js.map +4 -4
  67. package/dist/masonry.global.js +84 -94
  68. package/dist/masonry.global.js.map +3 -3
  69. package/dist/masonry.global.min.js +4 -4
  70. package/dist/masonry.global.min.js.map +4 -4
  71. package/dist/scroll.css +1 -1
  72. package/dist/scroll.css.map +2 -2
  73. package/dist/scroll.esm.js +14 -1252
  74. package/dist/scroll.esm.js.map +3 -3
  75. package/dist/scroll.global.js +64 -58
  76. package/dist/scroll.global.js.map +3 -3
  77. package/dist/scroll.global.min.js +3 -3
  78. package/dist/scroll.global.min.js.map +4 -4
  79. package/dist/scroll.layered.css +1 -1
  80. package/dist/scroll.layered.css.map +2 -2
  81. package/dist/shortcut.esm.js +6 -901
  82. package/dist/shortcut.esm.js.map +4 -4
  83. package/dist/shortcut.global.js +43 -36
  84. package/dist/shortcut.global.js.map +3 -3
  85. package/dist/shortcut.global.min.js +6 -3
  86. package/dist/shortcut.global.min.js.map +4 -4
  87. package/dist/size-report.json +319 -0
  88. package/dist/sortable.css +1 -0
  89. package/dist/sortable.css.map +7 -0
  90. package/dist/sortable.esm.js +22 -0
  91. package/dist/sortable.esm.js.map +7 -0
  92. package/dist/sortable.global.js +1477 -0
  93. package/dist/sortable.global.js.map +7 -0
  94. package/dist/sortable.global.min.js +6 -0
  95. package/dist/sortable.global.min.js.map +7 -0
  96. package/dist/sortable.layered.css +1 -0
  97. package/dist/sortable.layered.css.map +7 -0
  98. package/dist/sri-manifest.json +64 -0
  99. package/dist/toast.css +1 -1
  100. package/dist/toast.css.map +2 -2
  101. package/dist/toast.esm.js +19 -1208
  102. package/dist/toast.esm.js.map +3 -3
  103. package/dist/toast.global.js +314 -111
  104. package/dist/toast.global.js.map +3 -3
  105. package/dist/toast.global.min.js +3 -3
  106. package/dist/toast.global.min.js.map +4 -4
  107. package/dist/toast.layered.css +1 -1
  108. package/dist/toast.layered.css.map +2 -2
  109. package/dist/types/anchor/Anchor.d.ts +41 -0
  110. package/dist/types/anchor/index.d.ts +3 -0
  111. package/dist/types/anchor/types.d.ts +115 -0
  112. package/dist/types/autosize/Autosize.d.ts +71 -0
  113. package/dist/types/autosize/index.d.ts +3 -0
  114. package/dist/types/autosize/types.d.ts +66 -0
  115. package/dist/types/common/AuditableComponent.d.ts +1 -1
  116. package/dist/types/common/registry.d.ts +40 -0
  117. package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
  118. package/dist/types/index.d.ts +13 -1
  119. package/dist/types/scroll/types.d.ts +6 -0
  120. package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
  121. package/dist/types/shortcut/types.d.ts +5 -0
  122. package/dist/types/sortable/Sortable.d.ts +75 -0
  123. package/dist/types/sortable/i18n/en.d.ts +2 -0
  124. package/dist/types/sortable/i18n/fr.d.ts +2 -0
  125. package/dist/types/sortable/i18n/index.d.ts +9 -0
  126. package/dist/types/sortable/i18n/types.d.ts +15 -0
  127. package/dist/types/sortable/index.d.ts +4 -0
  128. package/dist/types/sortable/types.d.ts +112 -0
  129. package/dist/types/toast/Toast.d.ts +6 -1
  130. package/dist/types/toast/ToastInstance.d.ts +7 -0
  131. package/dist/types/toast/ToastManager.d.ts +2 -2
  132. package/dist/types/toast/types.d.ts +27 -1
  133. package/dist/types/undo/UndoManager.d.ts +112 -0
  134. package/dist/types/undo/i18n/en.d.ts +2 -0
  135. package/dist/types/undo/i18n/fr.d.ts +2 -0
  136. package/dist/types/undo/i18n/index.d.ts +9 -0
  137. package/dist/types/undo/i18n/types.d.ts +6 -0
  138. package/dist/types/undo/index.d.ts +5 -0
  139. package/dist/types/undo/types.d.ts +106 -0
  140. package/dist/undo.esm.js +23 -0
  141. package/dist/undo.esm.js.map +7 -0
  142. package/dist/undo.global.js +1029 -0
  143. package/dist/undo.global.js.map +7 -0
  144. package/dist/undo.global.min.js +6 -0
  145. package/dist/undo.global.min.js.map +7 -0
  146. package/package.json +54 -5
@@ -0,0 +1,1029 @@
1
+ import {
2
+ LocalizedComponent,
3
+ createI18nManager
4
+ } from "./chunk-QV46A7FV.js";
5
+ import {
6
+ prefersReducedMotion,
7
+ safeMove
8
+ } from "./chunk-22AIMRD5.js";
9
+ import {
10
+ __export
11
+ } from "./chunk-VJO22BAT.js";
12
+
13
+ // src/scroll/index.ts
14
+ var scroll_exports = {};
15
+ __export(scroll_exports, {
16
+ LocalizedComponent: () => LocalizedComponent,
17
+ Scroll: () => Scroll,
18
+ ScrollBlock: () => ScrollBlock,
19
+ createI18nManager: () => createI18nManager,
20
+ default: () => scroll_default,
21
+ scrollEn: () => scrollEn,
22
+ scrollFr: () => scrollFr,
23
+ scrollI18n: () => scrollI18n
24
+ });
25
+
26
+ // src/scroll/i18n/fr.ts
27
+ var scrollFr = {
28
+ viewport: "Zone de contenu d\xE9filable",
29
+ verticalThumb: "D\xE9filement vertical",
30
+ horizontalThumb: "D\xE9filement horizontal"
31
+ };
32
+
33
+ // src/scroll/i18n/en.ts
34
+ var scrollEn = {
35
+ viewport: "Scrollable content area",
36
+ verticalThumb: "Vertical scroll",
37
+ horizontalThumb: "Horizontal scroll"
38
+ };
39
+
40
+ // src/scroll/i18n/index.ts
41
+ var scrollI18n = createI18nManager("fr", {
42
+ fr: scrollFr,
43
+ en: scrollEn
44
+ });
45
+
46
+ // src/scroll/ScrollBlock.ts
47
+ var idCounter = 0;
48
+ var ScrollBlock = class extends LocalizedComponent {
49
+ static _i18n = scrollI18n;
50
+ static i18n = scrollI18n;
51
+ root;
52
+ viewport;
53
+ options;
54
+ createdViewport = false;
55
+ isDestroyed = false;
56
+ wasIdGenerated = false;
57
+ wasRoleInferred = false;
58
+ wasAriaLabelInferred = false;
59
+ hasExplicitAriaLabel = false;
60
+ hasRootAriaLabel = false;
61
+ propagatedRootLabel = null;
62
+ lastInferredAriaLabel = "";
63
+ trackY;
64
+ thumbY;
65
+ trackX;
66
+ thumbX;
67
+ resizeObserver;
68
+ mutationObserver;
69
+ observedChildren = /* @__PURE__ */ new Set();
70
+ hideTimer;
71
+ scrollEndFallbackTimer;
72
+ rafId = null;
73
+ resizeRafId = null;
74
+ abortController = new AbortController();
75
+ dragAbortController;
76
+ activeScrollToController;
77
+ supportsScrollEnd = typeof window !== "undefined" && "onscrollend" in window;
78
+ // Cache de métriques géométriques mis à jour dans update() pour éviter tout forced reflow en cours de scroll
79
+ cachedMaxTop = 0;
80
+ cachedMaxLeft = 0;
81
+ cachedTrackHeight = 0;
82
+ cachedThumbHeight = 0;
83
+ cachedTrackWidth = 0;
84
+ cachedThumbWidth = 0;
85
+ isDragging = false;
86
+ dragAxis;
87
+ dragPointerId;
88
+ dragStartPos = 0;
89
+ dragStartScroll = 0;
90
+ atBottom = false;
91
+ atTop = true;
92
+ atRight = false;
93
+ atLeft = true;
94
+ // Références d'écouteurs d'événements pour les callbacks et le drag
95
+ boundOnScroll;
96
+ boundOnScrollEnd;
97
+ boundOnMouseEnter;
98
+ boundOnMouseLeave;
99
+ boundOnFocusIn;
100
+ boundOnFocusOut;
101
+ boundPointerMove;
102
+ boundPointerUp;
103
+ constructor(element, options) {
104
+ super(options?.i18n);
105
+ let resolvedElement = null;
106
+ if (typeof element === "string") {
107
+ if (typeof document === "undefined") {
108
+ throw new Error("[ScrollBlock] Impossible de r\xE9soudre un s\xE9lecteur CSS sans environnement DOM (document).");
109
+ }
110
+ try {
111
+ resolvedElement = document.querySelector(element);
112
+ } catch {
113
+ resolvedElement = null;
114
+ }
115
+ } else {
116
+ resolvedElement = element;
117
+ }
118
+ if (!resolvedElement || typeof HTMLElement === "undefined" || !(resolvedElement instanceof HTMLElement)) {
119
+ throw new Error(`[ScrollBlock] \xC9l\xE9ment introuvable : "${element}".`);
120
+ }
121
+ this.root = resolvedElement;
122
+ this.hasExplicitAriaLabel = Boolean(options?.ariaLabel || options?.i18n?.viewport);
123
+ const rawDelay = options?.autoHideDelay;
124
+ const safeAutoHideDelay = typeof rawDelay === "number" && Number.isFinite(rawDelay) && rawDelay >= 0 ? Math.min(rawDelay, 2147483647) : 1e3;
125
+ const rawMinThumb = options?.minThumbSize;
126
+ const safeMinThumbSize = typeof rawMinThumb === "number" && Number.isFinite(rawMinThumb) && rawMinThumb > 0 ? rawMinThumb : 24;
127
+ const rawEdge = options?.edgeThreshold;
128
+ const safeEdgeThreshold = typeof rawEdge === "number" && Number.isFinite(rawEdge) && rawEdge >= 0 ? rawEdge : 10;
129
+ this.options = {
130
+ axis: options?.axis || "y",
131
+ mode: options?.mode || "custom",
132
+ autoHide: options?.autoHide ?? true,
133
+ autoHideDelay: safeAutoHideDelay,
134
+ alwaysVisible: options?.alwaysVisible ?? false,
135
+ scrollShadows: options?.scrollShadows ?? false,
136
+ ariaLabel: options?.ariaLabel || this.t("viewport"),
137
+ i18n: options?.i18n || {},
138
+ minThumbSize: safeMinThumbSize,
139
+ edgeThreshold: safeEdgeThreshold,
140
+ onScroll: options?.onScroll || (() => {
141
+ }),
142
+ onScrollEnd: options?.onScrollEnd || (() => {
143
+ }),
144
+ onTotalScroll: options?.onTotalScroll || (() => {
145
+ }),
146
+ onTotalScrollBack: options?.onTotalScrollBack || (() => {
147
+ }),
148
+ audit: options?.audit ?? true
149
+ };
150
+ this.boundOnScroll = this.handleScroll.bind(this);
151
+ this.boundOnScrollEnd = this.handleScrollEnd.bind(this);
152
+ this.boundOnMouseEnter = this.handleMouseEnter.bind(this);
153
+ this.boundOnMouseLeave = this.handleMouseLeave.bind(this);
154
+ this.boundOnFocusIn = this.handleFocusIn.bind(this);
155
+ this.boundOnFocusOut = this.handleFocusOut.bind(this);
156
+ this.boundPointerMove = this.handlePointerMove.bind(this);
157
+ this.boundPointerUp = this.handlePointerUp.bind(this);
158
+ this.viewport = this.setupViewport();
159
+ this.setupAccessibility();
160
+ this.setupScrollbars();
161
+ this.setupEventListeners();
162
+ this.setupObserver();
163
+ this.update();
164
+ this.runAuditWarning(this.options.audit);
165
+ }
166
+ /**
167
+ * Prépare le viewport défilant sans altérer les éléments enfants.
168
+ */
169
+ setupViewport() {
170
+ this.root.classList.add("wulf-scrollblock", `wulf-scrollblock--axis-${this.options.axis}`);
171
+ if (this.options.scrollShadows) {
172
+ this.root.classList.add("wulf-scrollblock--shadows");
173
+ }
174
+ if (this.options.mode === "native") {
175
+ this.root.classList.add("wulf-scrollblock--native");
176
+ }
177
+ if (this.options.alwaysVisible) {
178
+ this.root.classList.add("is-always-visible");
179
+ }
180
+ if (this.options.axis === "both") {
181
+ this.root.classList.add("has-both-axes");
182
+ }
183
+ const existingViewport = this.root.querySelector(":scope > .wulf-scrollblock-viewport");
184
+ if (existingViewport) {
185
+ return existingViewport;
186
+ }
187
+ const existingChildren = Array.from(this.root.childNodes);
188
+ const viewport = document.createElement("div");
189
+ viewport.className = "wulf-scrollblock-viewport";
190
+ this.root.appendChild(viewport);
191
+ for (const child of existingChildren) {
192
+ safeMove(viewport, child, null);
193
+ }
194
+ this.createdViewport = true;
195
+ return viewport;
196
+ }
197
+ /**
198
+ * Configure les attributs WAI-ARIA pour une accessibilité maximale.
199
+ */
200
+ setupAccessibility() {
201
+ if (!this.viewport.id) {
202
+ idCounter += 1;
203
+ this.viewport.id = `wulf-scrollblock-vp-${idCounter}`;
204
+ this.wasIdGenerated = true;
205
+ }
206
+ if (!this.viewport.hasAttribute("role")) {
207
+ this.viewport.setAttribute("role", "region");
208
+ this.wasRoleInferred = true;
209
+ }
210
+ const rootLabelledBy = this.root.getAttribute("aria-labelledby")?.trim();
211
+ const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
212
+ if (rootLabelledBy) {
213
+ this.hasRootAriaLabel = true;
214
+ if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-labelledby") && !this.viewport.hasAttribute("aria-label")) {
215
+ this.viewport.setAttribute("aria-labelledby", rootLabelledBy);
216
+ this.propagatedRootLabel = "aria-labelledby";
217
+ }
218
+ } else if (rootAriaLabel) {
219
+ this.hasRootAriaLabel = true;
220
+ if (!this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
221
+ this.viewport.setAttribute("aria-label", rootAriaLabel);
222
+ this.propagatedRootLabel = "aria-label";
223
+ }
224
+ }
225
+ if (this.hasExplicitAriaLabel && !this.viewport.hasAttribute("aria-label")) {
226
+ this.viewport.setAttribute("aria-label", this.options.ariaLabel);
227
+ this.lastInferredAriaLabel = this.options.ariaLabel;
228
+ this.wasAriaLabelInferred = true;
229
+ } else if (!this.viewport.hasAttribute("aria-label") && !this.viewport.hasAttribute("aria-labelledby")) {
230
+ const label = this.t("viewport");
231
+ this.viewport.setAttribute("aria-label", label);
232
+ this.lastInferredAriaLabel = label;
233
+ this.wasAriaLabelInferred = true;
234
+ }
235
+ }
236
+ /**
237
+ * Synchronise dynamiquement les libellés ARIA si la langue globale change après montage.
238
+ */
239
+ syncAccessibilityLabels() {
240
+ if (this.wasAriaLabelInferred && !this.hasExplicitAriaLabel) {
241
+ const currentAttr = this.viewport.getAttribute("aria-label");
242
+ if (currentAttr === this.lastInferredAriaLabel) {
243
+ const nextLabel = this.t("viewport");
244
+ this.viewport.setAttribute("aria-label", nextLabel);
245
+ this.lastInferredAriaLabel = nextLabel;
246
+ this.options.ariaLabel = nextLabel;
247
+ }
248
+ }
249
+ if (this.thumbY) {
250
+ this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
251
+ }
252
+ if (this.thumbX) {
253
+ this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
254
+ }
255
+ }
256
+ /**
257
+ * Crée les rails et curseurs selon l'axe sélectionné.
258
+ */
259
+ setupScrollbars() {
260
+ if (this.options.mode === "native") {
261
+ return;
262
+ }
263
+ if (this.options.axis === "y" || this.options.axis === "both") {
264
+ this.trackY = document.createElement("div");
265
+ this.trackY.className = "wulf-scrollblock-track wulf-scrollblock-vertical";
266
+ this.thumbY = document.createElement("div");
267
+ this.thumbY.className = "wulf-scrollblock-thumb";
268
+ this.thumbY.setAttribute("role", "scrollbar");
269
+ this.thumbY.setAttribute("aria-orientation", "vertical");
270
+ this.thumbY.setAttribute("aria-controls", this.viewport.id);
271
+ this.thumbY.setAttribute("aria-valuenow", "0");
272
+ this.thumbY.setAttribute("aria-valuemin", "0");
273
+ this.thumbY.setAttribute("aria-valuemax", "100");
274
+ this.thumbY.setAttribute("aria-label", this.t("verticalThumb"));
275
+ this.trackY.appendChild(this.thumbY);
276
+ this.root.appendChild(this.trackY);
277
+ this.attachTrackListeners(this.trackY, this.thumbY, "y");
278
+ }
279
+ if (this.options.axis === "x" || this.options.axis === "both") {
280
+ this.trackX = document.createElement("div");
281
+ this.trackX.className = "wulf-scrollblock-track wulf-scrollblock-horizontal";
282
+ this.thumbX = document.createElement("div");
283
+ this.thumbX.className = "wulf-scrollblock-thumb";
284
+ this.thumbX.setAttribute("role", "scrollbar");
285
+ this.thumbX.setAttribute("aria-orientation", "horizontal");
286
+ this.thumbX.setAttribute("aria-controls", this.viewport.id);
287
+ this.thumbX.setAttribute("aria-valuenow", "0");
288
+ this.thumbX.setAttribute("aria-valuemin", "0");
289
+ this.thumbX.setAttribute("aria-valuemax", "100");
290
+ this.thumbX.setAttribute("aria-label", this.t("horizontalThumb"));
291
+ this.trackX.appendChild(this.thumbX);
292
+ this.root.appendChild(this.trackX);
293
+ this.attachTrackListeners(this.trackX, this.thumbX, "x");
294
+ }
295
+ }
296
+ isRtl() {
297
+ return typeof window !== "undefined" && window.getComputedStyle(this.viewport).direction === "rtl";
298
+ }
299
+ /**
300
+ * Attache les écouteurs souris/pointeur et clavier WAI-ARIA sur un rail et son curseur.
301
+ */
302
+ attachTrackListeners(track, thumb, axis) {
303
+ const { signal } = this.abortController;
304
+ thumb.addEventListener("pointerdown", (e) => {
305
+ if (e.button !== 0) return;
306
+ e.preventDefault();
307
+ e.stopPropagation();
308
+ this.dragAbortController?.abort();
309
+ this.dragAbortController = new AbortController();
310
+ const dragSignal = this.dragAbortController.signal;
311
+ this.isDragging = true;
312
+ this.dragAxis = axis;
313
+ this.dragPointerId = e.pointerId;
314
+ this.dragStartPos = axis === "y" ? e.clientY : e.clientX;
315
+ this.dragStartScroll = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
316
+ try {
317
+ thumb.setPointerCapture(e.pointerId);
318
+ } catch {
319
+ }
320
+ thumb.classList.add("is-active");
321
+ this.root.classList.add("is-dragging");
322
+ if (typeof window !== "undefined") {
323
+ window.addEventListener("pointermove", this.boundPointerMove, { signal: dragSignal });
324
+ window.addEventListener("pointerup", this.boundPointerUp, { signal: dragSignal });
325
+ window.addEventListener("pointercancel", this.boundPointerUp, { signal: dragSignal });
326
+ }
327
+ thumb.addEventListener("lostpointercapture", this.boundPointerUp, { signal: dragSignal });
328
+ }, { signal });
329
+ thumb.addEventListener("keydown", (e) => {
330
+ if (e.ctrlKey || e.altKey || e.metaKey) return;
331
+ const step = 40;
332
+ const page = axis === "y" ? Math.max(step, Math.round(this.viewport.clientHeight * 0.9)) : Math.max(step, Math.round(this.viewport.clientWidth * 0.9));
333
+ const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
334
+ if (maxScroll <= 0) return;
335
+ const rtl = axis === "x" && this.isRtl();
336
+ const current = axis === "y" ? this.viewport.scrollTop : this.viewport.scrollLeft;
337
+ let target = null;
338
+ if (axis === "y") {
339
+ switch (e.key) {
340
+ case "ArrowDown":
341
+ target = current + step;
342
+ break;
343
+ case "ArrowUp":
344
+ target = current - step;
345
+ break;
346
+ case "PageDown":
347
+ target = current + page;
348
+ break;
349
+ case "PageUp":
350
+ target = current - page;
351
+ break;
352
+ case " ":
353
+ target = current + (e.shiftKey ? -page : page);
354
+ break;
355
+ case "Home":
356
+ target = 0;
357
+ break;
358
+ case "End":
359
+ target = maxScroll;
360
+ break;
361
+ }
362
+ } else {
363
+ switch (e.key) {
364
+ case "ArrowRight":
365
+ target = current + step;
366
+ break;
367
+ case "ArrowLeft":
368
+ target = current - step;
369
+ break;
370
+ case "PageDown":
371
+ target = current + (rtl ? -page : page);
372
+ break;
373
+ case "PageUp":
374
+ target = current + (rtl ? page : -page);
375
+ break;
376
+ case " ":
377
+ target = current + (e.shiftKey ? rtl ? page : -page : rtl ? -page : page);
378
+ break;
379
+ case "Home":
380
+ target = 0;
381
+ break;
382
+ case "End":
383
+ target = rtl ? -maxScroll : maxScroll;
384
+ break;
385
+ }
386
+ }
387
+ if (target === null) return;
388
+ e.preventDefault();
389
+ e.stopPropagation();
390
+ void this.scrollTo(axis === "y" ? { top: target } : { left: target }, { smooth: false });
391
+ this.syncThumbs();
392
+ }, { signal });
393
+ track.addEventListener("pointerdown", (e) => {
394
+ if (e.button !== 0 || e.target === thumb) return;
395
+ e.preventDefault();
396
+ const rtl = axis === "x" && this.isRtl();
397
+ const rect = track.getBoundingClientRect();
398
+ const clickPos = axis === "y" ? e.clientY - rect.top : rtl ? rect.right - e.clientX : e.clientX - rect.left;
399
+ const trackSize = axis === "y" ? rect.height : rect.width;
400
+ if (trackSize <= 0) return;
401
+ const maxScroll = axis === "y" ? this.cachedMaxTop : this.cachedMaxLeft;
402
+ const ratio = Math.max(0, Math.min(1, clickPos / trackSize));
403
+ const targetScroll = rtl ? -(ratio * maxScroll) : ratio * maxScroll;
404
+ void this.scrollTo(axis === "y" ? { top: targetScroll } : { left: targetScroll }, { smooth: true });
405
+ }, { signal });
406
+ }
407
+ /**
408
+ * Écouteurs globaux sur le viewport et les interactions.
409
+ */
410
+ setupEventListeners() {
411
+ const { signal } = this.abortController;
412
+ this.viewport.addEventListener("scroll", this.boundOnScroll, { passive: true, signal });
413
+ if (this.supportsScrollEnd) {
414
+ this.viewport.addEventListener("scrollend", this.boundOnScrollEnd, { passive: true, signal });
415
+ }
416
+ if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
417
+ this.root.addEventListener("mouseenter", this.boundOnMouseEnter, { signal });
418
+ this.root.addEventListener("mouseleave", this.boundOnMouseLeave, { signal });
419
+ this.root.addEventListener("focusin", this.boundOnFocusIn, { signal });
420
+ this.root.addEventListener("focusout", this.boundOnFocusOut, { signal });
421
+ }
422
+ }
423
+ /**
424
+ * Initialise le ResizeObserver réactif.
425
+ */
426
+ setupObserver() {
427
+ const scheduleUpdate = () => {
428
+ if (this.isDestroyed || this.resizeRafId !== null || typeof window === "undefined") return;
429
+ this.resizeRafId = window.requestAnimationFrame(() => {
430
+ this.resizeRafId = null;
431
+ if (!this.isDestroyed) {
432
+ this.update();
433
+ }
434
+ });
435
+ };
436
+ if (typeof ResizeObserver !== "undefined") {
437
+ this.resizeObserver = new ResizeObserver(scheduleUpdate);
438
+ this.resizeObserver.observe(this.root);
439
+ this.resizeObserver.observe(this.viewport);
440
+ for (const child of Array.from(this.viewport.children)) {
441
+ this.resizeObserver.observe(child);
442
+ this.observedChildren.add(child);
443
+ }
444
+ }
445
+ if (typeof MutationObserver !== "undefined") {
446
+ this.mutationObserver = new MutationObserver(scheduleUpdate);
447
+ this.mutationObserver.observe(this.viewport, { childList: true });
448
+ }
449
+ }
450
+ /**
451
+ * Déplacement lors du glissement du curseur.
452
+ */
453
+ handlePointerMove(e) {
454
+ if (!this.isDragging || !this.dragAxis) return;
455
+ if (this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) return;
456
+ const isY = this.dragAxis === "y";
457
+ const delta = (isY ? e.clientY : e.clientX) - this.dragStartPos;
458
+ const trackSize = isY ? this.cachedTrackHeight : this.cachedTrackWidth;
459
+ const thumbSize = isY ? this.cachedThumbHeight : this.cachedThumbWidth;
460
+ const maxScroll = isY ? this.cachedMaxTop : this.cachedMaxLeft;
461
+ const maxThumbTravel = trackSize - thumbSize;
462
+ if (maxThumbTravel <= 0 || maxScroll <= 0) return;
463
+ const ratio = maxScroll / maxThumbTravel;
464
+ const nextScroll = this.dragStartScroll + delta * ratio;
465
+ if (isY) {
466
+ this.viewport.scrollTop = Math.max(0, Math.min(maxScroll, nextScroll));
467
+ } else if (this.isRtl()) {
468
+ this.viewport.scrollLeft = Math.max(-maxScroll, Math.min(0, nextScroll));
469
+ } else {
470
+ this.viewport.scrollLeft = Math.max(0, Math.min(maxScroll, nextScroll));
471
+ }
472
+ }
473
+ /**
474
+ * Relâchement de la capture du pointeur.
475
+ */
476
+ handlePointerUp(e) {
477
+ if (!this.isDragging) return;
478
+ if (e && e.type !== "lostpointercapture" && this.dragPointerId !== void 0 && e.pointerId !== this.dragPointerId) {
479
+ return;
480
+ }
481
+ if (this.dragPointerId !== void 0) {
482
+ const activeThumb = this.dragAxis === "y" ? this.thumbY : this.thumbX;
483
+ try {
484
+ if (activeThumb && activeThumb.hasPointerCapture(this.dragPointerId)) {
485
+ activeThumb.releasePointerCapture(this.dragPointerId);
486
+ }
487
+ } catch {
488
+ }
489
+ }
490
+ this.dragAbortController?.abort();
491
+ this.dragAbortController = void 0;
492
+ this.isDragging = false;
493
+ this.dragAxis = void 0;
494
+ this.dragPointerId = void 0;
495
+ this.thumbY?.classList.remove("is-active");
496
+ this.thumbX?.classList.remove("is-active");
497
+ this.root.classList.remove("is-dragging");
498
+ this.scheduleAutoHide();
499
+ }
500
+ getScrollInfo() {
501
+ const { scrollTop, scrollLeft } = this.viewport;
502
+ const maxTop = this.cachedMaxTop;
503
+ const maxLeft = this.cachedMaxLeft;
504
+ const rtl = this.isRtl();
505
+ const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
506
+ const progressY = maxTop > 0 ? Math.max(0, Math.min(1, scrollTop / maxTop)) : 0;
507
+ const progressX = maxLeft > 0 ? Math.max(0, Math.min(1, logicalLeft / maxLeft)) : 0;
508
+ return {
509
+ top: scrollTop,
510
+ left: scrollLeft,
511
+ maxTop,
512
+ maxLeft,
513
+ progressY: Math.round(progressY * 100),
514
+ progressX: Math.round(progressX * 100)
515
+ };
516
+ }
517
+ /**
518
+ * Gestionnaire d'événement de défilement natif.
519
+ */
520
+ handleScroll() {
521
+ this.scheduleSyncThumbs();
522
+ const info = this.getScrollInfo();
523
+ const { top: scrollTop, left: scrollLeft, maxTop, maxLeft } = info;
524
+ try {
525
+ this.options.onScroll(info);
526
+ } catch (err) {
527
+ console.error("[Wulf.Scroll] Erreur dans onScroll:", err);
528
+ }
529
+ const threshold = this.options.edgeThreshold;
530
+ if (maxTop > 0) {
531
+ const nowBottom = scrollTop >= maxTop - threshold;
532
+ const nowTop = scrollTop <= threshold;
533
+ if (nowBottom && !this.atBottom) {
534
+ try {
535
+ this.options.onTotalScroll("bottom");
536
+ } catch (err) {
537
+ console.error("[Wulf.Scroll] Erreur dans onTotalScroll:", err);
538
+ }
539
+ }
540
+ if (nowTop && !this.atTop) {
541
+ try {
542
+ this.options.onTotalScrollBack("top");
543
+ } catch (err) {
544
+ console.error("[Wulf.Scroll] Erreur dans onTotalScrollBack:", err);
545
+ }
546
+ }
547
+ this.atBottom = nowBottom;
548
+ this.atTop = nowTop;
549
+ }
550
+ if (maxLeft > 0) {
551
+ const rtl = this.isRtl();
552
+ const nowRight = rtl ? scrollLeft >= -threshold : scrollLeft >= maxLeft - threshold;
553
+ const nowLeft = rtl ? scrollLeft <= -maxLeft + threshold : scrollLeft <= threshold;
554
+ if (nowRight && !this.atRight) {
555
+ try {
556
+ this.options.onTotalScroll("right");
557
+ } catch (err) {
558
+ console.error("[Wulf.Scroll] Erreur dans onTotalScroll:", err);
559
+ }
560
+ }
561
+ if (nowLeft && !this.atLeft) {
562
+ try {
563
+ this.options.onTotalScrollBack("left");
564
+ } catch (err) {
565
+ console.error("[Wulf.Scroll] Erreur dans onTotalScrollBack:", err);
566
+ }
567
+ }
568
+ this.atRight = nowRight;
569
+ this.atLeft = nowLeft;
570
+ }
571
+ if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
572
+ this.clearAutoHideTimer();
573
+ this.root.classList.add("is-scrolling");
574
+ if (!this.supportsScrollEnd) {
575
+ this.scheduleAutoHide();
576
+ }
577
+ }
578
+ if (!this.supportsScrollEnd && typeof window !== "undefined") {
579
+ if (this.scrollEndFallbackTimer !== void 0) {
580
+ window.clearTimeout(this.scrollEndFallbackTimer);
581
+ }
582
+ this.scrollEndFallbackTimer = window.setTimeout(() => {
583
+ this.scrollEndFallbackTimer = void 0;
584
+ this.handleScrollEnd();
585
+ }, 150);
586
+ }
587
+ }
588
+ /**
589
+ * Gestionnaire de fin de défilement (`scrollend` natif ou repli temporisé).
590
+ */
591
+ handleScrollEnd() {
592
+ try {
593
+ this.options.onScrollEnd(this.getScrollInfo());
594
+ } catch (err) {
595
+ console.error("[Wulf.Scroll] Erreur dans onScrollEnd:", err);
596
+ }
597
+ if (this.options.mode !== "native" && this.options.autoHide && !this.options.alwaysVisible) {
598
+ this.scheduleAutoHide();
599
+ }
600
+ }
601
+ /**
602
+ * Planifie une synchronisation des curseurs calée sur la prochaine trame d'affichage.
603
+ */
604
+ scheduleSyncThumbs() {
605
+ if (this.options.mode === "native" || this.isDestroyed || typeof window === "undefined") return;
606
+ if (this.rafId !== null) return;
607
+ this.rafId = window.requestAnimationFrame(() => {
608
+ this.rafId = null;
609
+ if (!this.isDestroyed) {
610
+ this.syncThumbs();
611
+ }
612
+ });
613
+ }
614
+ /**
615
+ * Synchronise la position physique (via variables CSS) et ARIA des curseurs à partir des métriques en cache.
616
+ */
617
+ syncThumbs() {
618
+ if (this.options.mode === "native" || this.isDestroyed) return;
619
+ const { scrollTop, scrollLeft } = this.viewport;
620
+ if (this.thumbY && this.trackY) {
621
+ const maxScrollY = this.cachedMaxTop;
622
+ const maxTravelY = this.cachedTrackHeight - this.cachedThumbHeight;
623
+ if (maxScrollY > 0) {
624
+ const ratioY = Math.max(0, Math.min(1, scrollTop / maxScrollY));
625
+ this.thumbY.setAttribute("aria-valuenow", String(Math.round(ratioY * 100)));
626
+ if (maxTravelY > 0) {
627
+ const posY = Math.max(0, Math.min(maxTravelY, ratioY * maxTravelY));
628
+ this.thumbY.style.setProperty("--scrollblock-thumb-y", `${posY}px`);
629
+ }
630
+ } else {
631
+ this.thumbY.setAttribute("aria-valuenow", "0");
632
+ this.thumbY.style.setProperty("--scrollblock-thumb-y", "0px");
633
+ }
634
+ }
635
+ if (this.thumbX && this.trackX) {
636
+ const maxScrollX = this.cachedMaxLeft;
637
+ const maxTravelX = this.cachedTrackWidth - this.cachedThumbWidth;
638
+ if (maxScrollX > 0) {
639
+ const rtl = this.isRtl();
640
+ const logicalLeft = rtl ? Math.max(0, -scrollLeft) : Math.max(0, scrollLeft);
641
+ const ratioX = Math.max(0, Math.min(1, logicalLeft / maxScrollX));
642
+ this.thumbX.setAttribute("aria-valuenow", String(Math.round(ratioX * 100)));
643
+ if (maxTravelX > 0) {
644
+ const posX = Math.max(0, Math.min(maxTravelX, ratioX * maxTravelX));
645
+ const signedPosX = rtl ? -posX : posX;
646
+ this.thumbX.style.setProperty("--scrollblock-thumb-x", `${signedPosX}px`);
647
+ }
648
+ } else {
649
+ this.thumbX.setAttribute("aria-valuenow", "0");
650
+ this.thumbX.style.setProperty("--scrollblock-thumb-x", "0px");
651
+ }
652
+ }
653
+ }
654
+ handleMouseEnter() {
655
+ this.root.classList.add("is-visible");
656
+ this.clearAutoHideTimer();
657
+ }
658
+ handleMouseLeave() {
659
+ this.scheduleAutoHide();
660
+ }
661
+ handleFocusIn() {
662
+ this.root.classList.add("is-visible");
663
+ this.clearAutoHideTimer();
664
+ }
665
+ handleFocusOut() {
666
+ this.scheduleAutoHide();
667
+ }
668
+ clearAutoHideTimer() {
669
+ if (this.hideTimer && typeof window !== "undefined") {
670
+ window.clearTimeout(this.hideTimer);
671
+ }
672
+ this.hideTimer = void 0;
673
+ }
674
+ scheduleAutoHide() {
675
+ if (this.options.alwaysVisible || !this.options.autoHide || this.isDragging || typeof window === "undefined") return;
676
+ this.clearAutoHideTimer();
677
+ this.hideTimer = window.setTimeout(() => {
678
+ this.root.classList.remove("is-scrolling");
679
+ this.root.classList.remove("is-visible");
680
+ }, this.options.autoHideDelay);
681
+ }
682
+ /**
683
+ * Recalcule les dimensions et la visibilité des barres.
684
+ */
685
+ update() {
686
+ if (this.isDestroyed) return;
687
+ this.syncAccessibilityLabels();
688
+ if (this.resizeObserver) {
689
+ const currentChildren = new Set(Array.from(this.viewport.children));
690
+ for (const prev of this.observedChildren) {
691
+ if (!currentChildren.has(prev)) {
692
+ this.resizeObserver.unobserve(prev);
693
+ this.observedChildren.delete(prev);
694
+ }
695
+ }
696
+ for (const child of currentChildren) {
697
+ if (!this.observedChildren.has(child)) {
698
+ this.resizeObserver.observe(child);
699
+ this.observedChildren.add(child);
700
+ }
701
+ }
702
+ }
703
+ const { scrollHeight, clientHeight, scrollWidth, clientWidth } = this.viewport;
704
+ const trackHeight = this.trackY ? this.trackY.clientHeight : 0;
705
+ const trackWidth = this.trackX ? this.trackX.clientWidth : 0;
706
+ const cssMinY = this.thumbY && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbY).minBlockSize) || 0 : 0;
707
+ const cssMinX = this.thumbX && typeof window !== "undefined" ? parseFloat(window.getComputedStyle(this.thumbX).minInlineSize) || 0 : 0;
708
+ this.cachedMaxTop = Math.max(0, scrollHeight - clientHeight);
709
+ this.cachedMaxLeft = Math.max(0, scrollWidth - clientWidth);
710
+ this.cachedTrackHeight = trackHeight;
711
+ this.cachedTrackWidth = trackWidth;
712
+ const canScrollY = scrollHeight > clientHeight;
713
+ const canScrollX = scrollWidth > clientWidth;
714
+ let calculatedHeight = this.cachedThumbHeight;
715
+ if (this.trackY && this.thumbY && canScrollY && scrollHeight > 0) {
716
+ const effectiveMinY = Math.max(this.options.minThumbSize, cssMinY);
717
+ calculatedHeight = Math.max(
718
+ effectiveMinY,
719
+ trackHeight * (clientHeight / scrollHeight)
720
+ );
721
+ this.cachedThumbHeight = calculatedHeight;
722
+ }
723
+ let calculatedWidth = this.cachedThumbWidth;
724
+ if (this.trackX && this.thumbX && canScrollX && scrollWidth > 0) {
725
+ const effectiveMinX = Math.max(this.options.minThumbSize, cssMinX);
726
+ calculatedWidth = Math.max(
727
+ effectiveMinX,
728
+ trackWidth * (clientWidth / scrollWidth)
729
+ );
730
+ this.cachedThumbWidth = calculatedWidth;
731
+ }
732
+ this.root.classList.toggle("has-scroll-y", canScrollY);
733
+ this.root.classList.toggle("has-scroll-x", canScrollX);
734
+ if (canScrollY || canScrollX) {
735
+ this.viewport.setAttribute("tabindex", "0");
736
+ } else {
737
+ this.viewport.removeAttribute("tabindex");
738
+ }
739
+ if (this.trackY && this.thumbY) {
740
+ this.trackY.hidden = !canScrollY;
741
+ if (canScrollY) {
742
+ this.thumbY.setAttribute("tabindex", "0");
743
+ this.thumbY.style.height = `${calculatedHeight}px`;
744
+ } else {
745
+ this.thumbY.removeAttribute("tabindex");
746
+ }
747
+ }
748
+ if (this.trackX && this.thumbX) {
749
+ this.trackX.hidden = !canScrollX;
750
+ if (canScrollX) {
751
+ this.thumbX.setAttribute("tabindex", "0");
752
+ this.thumbX.style.width = `${calculatedWidth}px`;
753
+ } else {
754
+ this.thumbX.removeAttribute("tabindex");
755
+ }
756
+ }
757
+ this.syncThumbs();
758
+ }
759
+ /**
760
+ * Défilement programmatique direct ou lissé.
761
+ * Retourne une Promesse résolue lorsque le défilement atteint sa cible.
762
+ */
763
+ scrollTo(target, options) {
764
+ if (this.isDestroyed) return Promise.resolve();
765
+ const targetSmooth = typeof target === "object" && target !== null && !(target instanceof HTMLElement) ? target.smooth : void 0;
766
+ const shouldSmooth = (options?.smooth ?? targetSmooth ?? true) && !prefersReducedMotion();
767
+ const behavior = shouldSmooth ? "smooth" : "auto";
768
+ const rtl = this.isRtl();
769
+ const { scrollHeight, clientHeight, scrollWidth, clientWidth, scrollTop, scrollLeft } = this.viewport;
770
+ const maxTop = Math.max(0, scrollHeight - clientHeight);
771
+ const maxLeft = Math.max(0, scrollWidth - clientWidth);
772
+ this.cachedMaxTop = maxTop;
773
+ this.cachedMaxLeft = maxLeft;
774
+ let targetTop;
775
+ let targetLeft;
776
+ if (typeof target === "number") {
777
+ targetTop = target;
778
+ } else if (typeof target === "string") {
779
+ switch (target) {
780
+ case "top":
781
+ targetTop = 0;
782
+ break;
783
+ case "bottom":
784
+ targetTop = maxTop;
785
+ break;
786
+ case "left":
787
+ targetLeft = rtl ? -maxLeft : 0;
788
+ break;
789
+ case "right":
790
+ targetLeft = rtl ? 0 : maxLeft;
791
+ break;
792
+ default: {
793
+ if (/^-?\d+(\.\d+)?%$/.test(target.trim())) {
794
+ const pct = Math.max(0, Math.min(100, parseFloat(target.trim()))) / 100;
795
+ if (this.options.axis === "x") {
796
+ targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
797
+ } else if (this.options.axis === "both") {
798
+ targetTop = maxTop * pct;
799
+ targetLeft = rtl ? -maxLeft * pct : maxLeft * pct;
800
+ } else {
801
+ targetTop = maxTop * pct;
802
+ }
803
+ break;
804
+ }
805
+ let el = null;
806
+ try {
807
+ el = this.viewport.querySelector(target);
808
+ } catch {
809
+ el = null;
810
+ }
811
+ if (el) {
812
+ const vpRect = this.viewport.getBoundingClientRect();
813
+ const elRect = el.getBoundingClientRect();
814
+ targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
815
+ targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
816
+ }
817
+ break;
818
+ }
819
+ }
820
+ } else if (target instanceof HTMLElement) {
821
+ if (target.isConnected && this.viewport.contains(target)) {
822
+ const vpRect = this.viewport.getBoundingClientRect();
823
+ const elRect = target.getBoundingClientRect();
824
+ targetTop = elRect.top - vpRect.top - this.viewport.clientTop + scrollTop;
825
+ targetLeft = elRect.left - vpRect.left - this.viewport.clientLeft + scrollLeft;
826
+ }
827
+ } else if (typeof target === "object" && target !== null) {
828
+ targetTop = target.top;
829
+ targetLeft = target.left;
830
+ }
831
+ const clampedTop = targetTop !== void 0 && Number.isFinite(targetTop) ? Math.max(0, Math.min(maxTop, targetTop)) : void 0;
832
+ const minLeftBound = rtl ? -maxLeft : 0;
833
+ const maxLeftBound = rtl ? 0 : maxLeft;
834
+ const clampedLeft = targetLeft !== void 0 && Number.isFinite(targetLeft) ? Math.max(minLeftBound, Math.min(maxLeftBound, targetLeft)) : void 0;
835
+ const destTop = clampedTop ?? scrollTop;
836
+ const destLeft = clampedLeft ?? scrollLeft;
837
+ if (Math.abs(destTop - scrollTop) <= 1 && Math.abs(destLeft - scrollLeft) <= 1) {
838
+ return Promise.resolve();
839
+ }
840
+ this.activeScrollToController?.abort();
841
+ const waitController = new AbortController();
842
+ this.activeScrollToController = waitController;
843
+ const nativeResult = this.viewport.scrollTo({
844
+ top: clampedTop,
845
+ left: clampedLeft,
846
+ behavior
847
+ });
848
+ if (nativeResult instanceof Promise) {
849
+ return nativeResult.then(() => {
850
+ if (this.activeScrollToController === waitController) {
851
+ this.activeScrollToController = void 0;
852
+ }
853
+ });
854
+ }
855
+ if (behavior !== "smooth") {
856
+ if (this.activeScrollToController === waitController) {
857
+ this.activeScrollToController = void 0;
858
+ }
859
+ return Promise.resolve();
860
+ }
861
+ return new Promise((resolve) => {
862
+ let settled = false;
863
+ let idleTimerId;
864
+ let maxTimerId;
865
+ const finish = () => {
866
+ if (settled) return;
867
+ settled = true;
868
+ if (typeof window !== "undefined") {
869
+ if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
870
+ if (maxTimerId !== void 0) window.clearTimeout(maxTimerId);
871
+ }
872
+ if (this.activeScrollToController === waitController) {
873
+ this.activeScrollToController = void 0;
874
+ }
875
+ waitController.abort();
876
+ resolve();
877
+ };
878
+ waitController.signal.addEventListener("abort", finish, { once: true });
879
+ this.abortController.signal.addEventListener("abort", finish, { once: true, signal: waitController.signal });
880
+ if (this.supportsScrollEnd) {
881
+ this.viewport.addEventListener("scrollend", finish, { once: true, signal: waitController.signal });
882
+ } else if (typeof window !== "undefined") {
883
+ const bumpIdle = () => {
884
+ if (idleTimerId !== void 0) window.clearTimeout(idleTimerId);
885
+ idleTimerId = window.setTimeout(finish, 150);
886
+ };
887
+ this.viewport.addEventListener("scroll", bumpIdle, { passive: true, signal: waitController.signal });
888
+ bumpIdle();
889
+ }
890
+ if (typeof window !== "undefined") {
891
+ maxTimerId = window.setTimeout(finish, 2500);
892
+ } else {
893
+ finish();
894
+ }
895
+ });
896
+ }
897
+ /**
898
+ * Vérifie la conformité d'accessibilité WAI-ARIA de la zone défilable
899
+ * et retourne la liste des contraintes manquantes.
900
+ */
901
+ audit() {
902
+ const warnings = [];
903
+ const hasViewportLabelledby = this.checkAriaIdReferences(this.viewport, "aria-labelledby", warnings, true);
904
+ const hasRootLabelledby = this.checkAriaIdReferences(this.root, "aria-labelledby", warnings, true);
905
+ const hasValidLabelledby = hasViewportLabelledby || hasRootLabelledby;
906
+ const rootAriaLabel = this.root.getAttribute("aria-label")?.trim();
907
+ const hasCustomViewportAriaLabel = !this.wasAriaLabelInferred && Boolean(this.viewport.getAttribute("aria-label")?.trim());
908
+ if (!this.hasExplicitAriaLabel && !this.hasRootAriaLabel && !hasCustomViewportAriaLabel && !rootAriaLabel && !hasValidLabelledby) {
909
+ warnings.push(
910
+ "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)."
911
+ );
912
+ }
913
+ if (this.options.mode !== "native" && this.options.minThumbSize < 24) {
914
+ warnings.push(
915
+ `Taille minimale du curseur insuffisante (minThumbSize: ${this.options.minThumbSize}px) : utilisez au moins 24px pour respecter WCAG 2.5.8.`
916
+ );
917
+ }
918
+ if (this.root.tabIndex > 0 || this.viewport.tabIndex > 0) {
919
+ warnings.push(
920
+ 'Attribut tabindex > 0 d\xE9tect\xE9 sur la zone d\xE9filable : utilisez uniquement tabindex="0" ou "-1" (WCAG 2.4.3).'
921
+ );
922
+ }
923
+ if (this.root.getAttribute("role") === "region" && this.viewport.getAttribute("role") === "region") {
924
+ warnings.push(
925
+ 'Landmark role="region" redondant : \xE9vitez de d\xE9clarer role="region" \xE0 la fois sur le conteneur racine et sur le viewport interne.'
926
+ );
927
+ }
928
+ return warnings;
929
+ }
930
+ getAuditPrefix() {
931
+ return "Wulf.Scroll";
932
+ }
933
+ getAuditTargetLabel() {
934
+ return this.root.id ? `#${this.root.id}` : `<${this.root.tagName.toLowerCase()}.wulf-scrollblock>`;
935
+ }
936
+ /**
937
+ * Détruit le composant et libère toutes les ressources.
938
+ */
939
+ destroy() {
940
+ if (this.isDestroyed) return;
941
+ if (this.isDragging) {
942
+ this.handlePointerUp();
943
+ }
944
+ this.isDestroyed = true;
945
+ this.clearAutoHideTimer();
946
+ if (typeof window !== "undefined") {
947
+ if (this.scrollEndFallbackTimer !== void 0) {
948
+ window.clearTimeout(this.scrollEndFallbackTimer);
949
+ }
950
+ if (this.rafId !== null) {
951
+ window.cancelAnimationFrame(this.rafId);
952
+ }
953
+ if (this.resizeRafId !== null) {
954
+ window.cancelAnimationFrame(this.resizeRafId);
955
+ }
956
+ }
957
+ this.scrollEndFallbackTimer = void 0;
958
+ this.rafId = null;
959
+ this.resizeRafId = null;
960
+ this.activeScrollToController?.abort();
961
+ this.activeScrollToController = void 0;
962
+ this.dragAbortController?.abort();
963
+ this.dragAbortController = void 0;
964
+ this.abortController.abort();
965
+ if (this.resizeObserver) {
966
+ this.resizeObserver.disconnect();
967
+ }
968
+ if (this.mutationObserver) {
969
+ this.mutationObserver.disconnect();
970
+ this.mutationObserver = void 0;
971
+ }
972
+ this.observedChildren.clear();
973
+ this.trackY?.remove();
974
+ this.trackX?.remove();
975
+ this.root.classList.remove(
976
+ "wulf-scrollblock",
977
+ "wulf-scrollblock--native",
978
+ "wulf-scrollblock--shadows",
979
+ "wulf-scrollblock--axis-y",
980
+ "wulf-scrollblock--axis-x",
981
+ "wulf-scrollblock--axis-both",
982
+ "has-scroll-y",
983
+ "has-scroll-x",
984
+ "has-both-axes",
985
+ "is-visible",
986
+ "is-scrolling",
987
+ "is-dragging",
988
+ "is-always-visible"
989
+ );
990
+ if (this.createdViewport && this.viewport.parentElement === this.root) {
991
+ while (this.viewport.firstChild) {
992
+ safeMove(this.root, this.viewport.firstChild, this.viewport);
993
+ }
994
+ this.viewport.remove();
995
+ } else {
996
+ this.viewport.removeAttribute("tabindex");
997
+ if (this.wasIdGenerated) {
998
+ this.viewport.removeAttribute("id");
999
+ }
1000
+ if (this.wasRoleInferred && this.viewport.getAttribute("role") === "region") {
1001
+ this.viewport.removeAttribute("role");
1002
+ }
1003
+ if (this.propagatedRootLabel) {
1004
+ this.viewport.removeAttribute(this.propagatedRootLabel);
1005
+ }
1006
+ if (this.wasAriaLabelInferred && this.viewport.getAttribute("aria-label") === this.lastInferredAriaLabel) {
1007
+ this.viewport.removeAttribute("aria-label");
1008
+ }
1009
+ }
1010
+ }
1011
+ };
1012
+
1013
+ // src/scroll/index.ts
1014
+ var Scroll = {
1015
+ ScrollBlock,
1016
+ i18n: scrollI18n
1017
+ };
1018
+ var scroll_default = ScrollBlock;
1019
+
1020
+ export {
1021
+ scrollFr,
1022
+ scrollEn,
1023
+ scrollI18n,
1024
+ ScrollBlock,
1025
+ Scroll,
1026
+ scroll_default,
1027
+ scroll_exports
1028
+ };
1029
+ //# sourceMappingURL=chunk-NLUQZEL4.js.map