wulf.js 2.1.0 → 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 (150) hide show
  1. package/README.md +217 -11
  2. package/changelog.md +60 -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 -536
  48. package/dist/focus-trap.esm.js.map +3 -3
  49. package/dist/focus-trap.global.js +260 -87
  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 -10069
  54. package/dist/index.esm.js.map +4 -4
  55. package/dist/index.global.js +4192 -355
  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 -1067
  66. package/dist/masonry.esm.js.map +4 -4
  67. package/dist/masonry.global.js +229 -148
  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 -1175
  74. package/dist/scroll.esm.js.map +3 -3
  75. package/dist/scroll.global.js +171 -88
  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 -741
  82. package/dist/shortcut.esm.js.map +4 -4
  83. package/dist/shortcut.global.js +225 -58
  84. package/dist/shortcut.global.js.map +3 -3
  85. package/dist/shortcut.global.min.js +8 -2
  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 -1129
  102. package/dist/toast.esm.js.map +3 -3
  103. package/dist/toast.global.js +386 -104
  104. package/dist/toast.global.js.map +3 -3
  105. package/dist/toast.global.min.js +4 -4
  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/dom.d.ts +5 -0
  117. package/dist/types/common/registry.d.ts +40 -0
  118. package/dist/types/focus-trap/FocusTrap.d.ts +8 -3
  119. package/dist/types/index.d.ts +13 -1
  120. package/dist/types/mask/paste.d.ts +2 -5
  121. package/dist/types/masonry/Masonry.d.ts +2 -0
  122. package/dist/types/scroll/ScrollBlock.d.ts +2 -0
  123. package/dist/types/scroll/types.d.ts +6 -0
  124. package/dist/types/shortcut/ShortcutManager.d.ts +16 -3
  125. package/dist/types/shortcut/types.d.ts +5 -0
  126. package/dist/types/sortable/Sortable.d.ts +75 -0
  127. package/dist/types/sortable/i18n/en.d.ts +2 -0
  128. package/dist/types/sortable/i18n/fr.d.ts +2 -0
  129. package/dist/types/sortable/i18n/index.d.ts +9 -0
  130. package/dist/types/sortable/i18n/types.d.ts +15 -0
  131. package/dist/types/sortable/index.d.ts +4 -0
  132. package/dist/types/sortable/types.d.ts +112 -0
  133. package/dist/types/toast/Toast.d.ts +6 -1
  134. package/dist/types/toast/ToastInstance.d.ts +7 -0
  135. package/dist/types/toast/ToastManager.d.ts +4 -2
  136. package/dist/types/toast/types.d.ts +27 -1
  137. package/dist/types/undo/UndoManager.d.ts +112 -0
  138. package/dist/types/undo/i18n/en.d.ts +2 -0
  139. package/dist/types/undo/i18n/fr.d.ts +2 -0
  140. package/dist/types/undo/i18n/index.d.ts +9 -0
  141. package/dist/types/undo/i18n/types.d.ts +6 -0
  142. package/dist/types/undo/index.d.ts +5 -0
  143. package/dist/types/undo/types.d.ts +106 -0
  144. package/dist/undo.esm.js +23 -0
  145. package/dist/undo.esm.js.map +7 -0
  146. package/dist/undo.global.js +1029 -0
  147. package/dist/undo.global.js.map +7 -0
  148. package/dist/undo.global.min.js +6 -0
  149. package/dist/undo.global.min.js.map +7 -0
  150. package/package.json +54 -5
@@ -0,0 +1,1195 @@
1
+ import {
2
+ LocalizedComponent,
3
+ createI18nManager
4
+ } from "./chunk-QV46A7FV.js";
5
+ import {
6
+ getDeepActiveElement,
7
+ isImeComposing,
8
+ prefersReducedMotion,
9
+ safeMove,
10
+ stripBidiAndInvisibles
11
+ } from "./chunk-22AIMRD5.js";
12
+ import {
13
+ __export
14
+ } from "./chunk-VJO22BAT.js";
15
+
16
+ // src/sortable/index.ts
17
+ var sortable_exports = {};
18
+ __export(sortable_exports, {
19
+ LocalizedComponent: () => LocalizedComponent,
20
+ Sortable: () => Sortable,
21
+ createI18nManager: () => createI18nManager,
22
+ default: () => Sortable,
23
+ sortableEn: () => sortableEn,
24
+ sortableFr: () => sortableFr,
25
+ sortableI18n: () => sortableI18n
26
+ });
27
+
28
+ // src/sortable/i18n/fr.ts
29
+ var sortableFr = {
30
+ grabbed: (label, position, total) => `${label} saisi en position ${position} sur ${total}. Utilisez les fl\xE8ches pour d\xE9placer, Entr\xE9e ou Espace pour d\xE9poser, \xC9chap pour annuler.`,
31
+ moved: (label, position, total) => `${label} d\xE9plac\xE9 en position ${position} sur ${total}.`,
32
+ dropped: (label, position, total) => `${label} d\xE9pos\xE9 en position ${position} sur ${total}.`,
33
+ cancelled: (label, position, total) => `D\xE9placement annul\xE9. ${label} replac\xE9 en position ${position} sur ${total}.`,
34
+ defaultItemLabel: (position) => `\xC9l\xE9ment ${position}`
35
+ };
36
+
37
+ // src/sortable/i18n/en.ts
38
+ var sortableEn = {
39
+ grabbed: (label, position, total) => `${label} grabbed at position ${position} of ${total}. Use arrow keys to move, Enter or Space to drop, Escape to cancel.`,
40
+ moved: (label, position, total) => `${label} moved to position ${position} of ${total}.`,
41
+ dropped: (label, position, total) => `${label} dropped at position ${position} of ${total}.`,
42
+ cancelled: (label, position, total) => `Reordering cancelled. ${label} returned to position ${position} of ${total}.`,
43
+ defaultItemLabel: (position) => `Item ${position}`
44
+ };
45
+
46
+ // src/sortable/i18n/index.ts
47
+ var sortableI18n = createI18nManager("fr", {
48
+ fr: sortableFr,
49
+ en: sortableEn
50
+ });
51
+
52
+ // src/sortable/Sortable.ts
53
+ var INTERACTIVE_DESCENDANT_SELECTOR = 'input, textarea, select, button, a[href], label, [contenteditable], [role="button"], [role="textbox"], [role="searchbox"], [role="combobox"], [role="spinbutton"], [role="slider"]';
54
+ var NATIVELY_FOCUSABLE_SELECTOR = "button, a[href], input, select, textarea, summary, [tabindex]";
55
+ function clampNumber(value, fallback, min, max) {
56
+ if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
57
+ return Math.min(max, Math.max(min, value));
58
+ }
59
+ function resolveContainer(target) {
60
+ if (typeof target === "string") {
61
+ if (!target) return null;
62
+ try {
63
+ return document.querySelector(target);
64
+ } catch {
65
+ return null;
66
+ }
67
+ }
68
+ if (typeof HTMLElement !== "undefined" && target instanceof HTMLElement) {
69
+ return target;
70
+ }
71
+ return null;
72
+ }
73
+ function isEditableTarget(target) {
74
+ if (!target || typeof target.tagName !== "string") return false;
75
+ const el = target;
76
+ const tag = el.tagName.toUpperCase();
77
+ if (tag === "INPUT") {
78
+ const type = el.type?.toLowerCase() || "text";
79
+ return !["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"].includes(type);
80
+ }
81
+ if (tag === "TEXTAREA" || tag === "SELECT") return true;
82
+ const ce = el.getAttribute?.("contenteditable")?.toLowerCase();
83
+ if (el.isContentEditable || ce === "true" || ce === "plaintext-only" || ce === "") {
84
+ return true;
85
+ }
86
+ const role = el.getAttribute?.("role");
87
+ if (role === "textbox" || role === "searchbox" || role === "combobox" || role === "spinbutton") {
88
+ return true;
89
+ }
90
+ return Boolean(
91
+ el.closest?.(
92
+ '[contenteditable="true"], [contenteditable="plaintext-only"], [contenteditable=""], [role="textbox"], [role="searchbox"], [role="combobox"], [role="spinbutton"]'
93
+ )
94
+ );
95
+ }
96
+ function moveItemInDom(container, item, siblings, targetIndex) {
97
+ if (siblings.length === 0) return;
98
+ const clamped = Math.max(0, Math.min(targetIndex, siblings.length));
99
+ const referenceNode = clamped < siblings.length ? siblings[clamped] : siblings[siblings.length - 1].nextSibling;
100
+ if (item.nextSibling !== referenceNode) {
101
+ safeMove(container, item, referenceNode);
102
+ }
103
+ }
104
+ function computeReorderedArray(items, fromIndex, toIndex) {
105
+ const next = items.slice();
106
+ if (fromIndex < 0 || fromIndex >= next.length) return next;
107
+ const clampedTo = Math.max(0, Math.min(toIndex, next.length - 1));
108
+ const [moved] = next.splice(fromIndex, 1);
109
+ next.splice(clampedTo, 0, moved);
110
+ return next;
111
+ }
112
+ var Sortable = class extends LocalizedComponent {
113
+ static _i18n = sortableI18n;
114
+ static i18n = sortableI18n;
115
+ container;
116
+ options;
117
+ isDestroyed = false;
118
+ isMovingFocus = false;
119
+ dragSessionSeq = 0;
120
+ rootAbort = new AbortController();
121
+ pointerDrag = null;
122
+ keyboardGrab = null;
123
+ hadRootClass = false;
124
+ savedAttributes = /* @__PURE__ */ new Map();
125
+ addedHandles = /* @__PURE__ */ new Set();
126
+ activeAnimations = /* @__PURE__ */ new WeakMap();
127
+ srStatusEl = null;
128
+ announceTimerId = null;
129
+ mutationObserver = null;
130
+ constructor(target, options = {}) {
131
+ super(options.i18n);
132
+ this.options = {
133
+ itemSelector: options.itemSelector,
134
+ handleSelector: options.handleSelector,
135
+ axis: options.axis ?? "y",
136
+ autoMove: options.autoMove ?? true,
137
+ threshold: clampNumber(options.threshold, 5, 0, 100),
138
+ animationDuration: clampNumber(options.animationDuration, 180, 0, 2e3),
139
+ autoScroll: options.autoScroll ?? true,
140
+ autoScrollSpeed: clampNumber(options.autoScrollSpeed, 12, 1, 30),
141
+ disabled: Boolean(options.disabled),
142
+ lang: options.lang,
143
+ getItemLabel: options.getItemLabel,
144
+ onStart: options.onStart,
145
+ onMove: options.onMove,
146
+ onReorder: options.onReorder,
147
+ onCancel: options.onCancel,
148
+ audit: options.audit ?? true
149
+ };
150
+ if (typeof document === "undefined" || typeof window === "undefined") {
151
+ this.container = null;
152
+ return;
153
+ }
154
+ const resolved = resolveContainer(target);
155
+ if (!resolved) {
156
+ throw new Error("[Wulf.Sortable] Conteneur HTMLElement ou s\xE9lecteur CSS valide requis.");
157
+ }
158
+ this.container = resolved;
159
+ this.hadRootClass = resolved.classList.contains("wulf-sortable");
160
+ resolved.classList.add("wulf-sortable");
161
+ this.mountStatusRegion();
162
+ this.refresh();
163
+ this.bindContainerEvents();
164
+ this.observeDomChanges();
165
+ this.runAuditWarning(this.options.audit);
166
+ }
167
+ getAuditPrefix() {
168
+ return "Wulf.Sortable";
169
+ }
170
+ getAuditTargetLabel() {
171
+ if (!this.container) return "<ssr>";
172
+ if (this.container.id) return `#${this.container.id}`;
173
+ return `<${this.container.tagName.toLowerCase()}>`;
174
+ }
175
+ getItems() {
176
+ if (!this.container || this.isDestroyed) return [];
177
+ if (this.options.itemSelector) {
178
+ try {
179
+ return Array.from(this.container.querySelectorAll(this.options.itemSelector)).filter(
180
+ (el) => !el.hasAttribute("data-wulf-sortable-ignore") && !el.classList.contains("wulf-sortable-sr-status")
181
+ );
182
+ } catch {
183
+ return [];
184
+ }
185
+ }
186
+ const result = [];
187
+ for (const child of Array.from(this.container.children)) {
188
+ if (typeof HTMLElement !== "undefined" && child instanceof HTMLElement && !child.hasAttribute("data-wulf-sortable-ignore") && !child.classList.contains("wulf-sortable-sr-status")) {
189
+ result.push(child);
190
+ }
191
+ }
192
+ return result;
193
+ }
194
+ isDisabled() {
195
+ return this.options.disabled;
196
+ }
197
+ isDragging() {
198
+ return Boolean(this.pointerDrag?.started || this.keyboardGrab);
199
+ }
200
+ setDisabled(disabled) {
201
+ const next = Boolean(disabled);
202
+ if (this.options.disabled === next) return;
203
+ this.options.disabled = next;
204
+ if (next) {
205
+ this.cancel();
206
+ }
207
+ }
208
+ updateOptions(options) {
209
+ if (this.isDestroyed || !options) return;
210
+ if (options.i18n !== void 0) this.i18nOverrides = options.i18n;
211
+ if (options.itemSelector !== void 0) this.options.itemSelector = options.itemSelector;
212
+ if (options.handleSelector !== void 0) this.options.handleSelector = options.handleSelector;
213
+ if (options.axis !== void 0) this.options.axis = options.axis;
214
+ if (options.autoMove !== void 0) this.options.autoMove = Boolean(options.autoMove);
215
+ if (options.threshold !== void 0) {
216
+ this.options.threshold = clampNumber(options.threshold, 5, 0, 100);
217
+ }
218
+ if (options.animationDuration !== void 0) {
219
+ this.options.animationDuration = clampNumber(options.animationDuration, 180, 0, 2e3);
220
+ }
221
+ if (options.autoScroll !== void 0) this.options.autoScroll = Boolean(options.autoScroll);
222
+ if (options.autoScrollSpeed !== void 0) {
223
+ this.options.autoScrollSpeed = clampNumber(options.autoScrollSpeed, 12, 1, 30);
224
+ }
225
+ if (options.lang !== void 0) this.options.lang = options.lang;
226
+ if (options.getItemLabel !== void 0) this.options.getItemLabel = options.getItemLabel;
227
+ if (options.onStart !== void 0) this.options.onStart = options.onStart;
228
+ if (options.onMove !== void 0) this.options.onMove = options.onMove;
229
+ if (options.onReorder !== void 0) this.options.onReorder = options.onReorder;
230
+ if (options.onCancel !== void 0) this.options.onCancel = options.onCancel;
231
+ if (options.disabled !== void 0) this.setDisabled(options.disabled);
232
+ this.refresh();
233
+ }
234
+ refresh() {
235
+ if (!this.container || this.isDestroyed) return;
236
+ const items = this.getItems();
237
+ for (const item of items) {
238
+ const target = this.resolveTriggerForItem(item);
239
+ if (target) {
240
+ if (this.options.handleSelector && target !== item) {
241
+ target.classList.add("wulf-sortable-handle");
242
+ this.addedHandles.add(target);
243
+ }
244
+ if (!this.savedAttributes.has(target)) {
245
+ this.savedAttributes.set(target, {
246
+ hadTabIndex: target.hasAttribute("tabindex"),
247
+ prevTabIndex: target.getAttribute("tabindex"),
248
+ hadAriaPressed: target.hasAttribute("aria-pressed"),
249
+ prevAriaPressed: target.getAttribute("aria-pressed")
250
+ });
251
+ }
252
+ if (!target.matches(NATIVELY_FOCUSABLE_SELECTOR) && !target.hasAttribute("tabindex")) {
253
+ target.setAttribute("tabindex", "0");
254
+ }
255
+ }
256
+ }
257
+ }
258
+ move(fromIndex, toIndex) {
259
+ if (!this.container || this.isDestroyed) return false;
260
+ const items = this.getItems();
261
+ if (!Number.isInteger(fromIndex) || !Number.isInteger(toIndex) || fromIndex < 0 || toIndex < 0 || fromIndex >= items.length || toIndex >= items.length || fromIndex === toIndex) {
262
+ return false;
263
+ }
264
+ const item = items[fromIndex];
265
+ const siblings = items.filter((el) => el !== item);
266
+ const ordered = computeReorderedArray(items, fromIndex, toIndex);
267
+ if (this.options.autoMove) {
268
+ const beforeRects = this.snapshotRects(items);
269
+ moveItemInDom(this.container, item, siblings, toIndex);
270
+ this.animateFlip(items, beforeRects);
271
+ }
272
+ this.emitReorder({
273
+ item,
274
+ oldIndex: fromIndex,
275
+ newIndex: toIndex,
276
+ items: ordered,
277
+ trigger: "programmatic"
278
+ });
279
+ return true;
280
+ }
281
+ cancel() {
282
+ if (this.isDestroyed) return;
283
+ if (this.pointerDrag) {
284
+ this.endPointerDrag(true);
285
+ }
286
+ if (this.keyboardGrab) {
287
+ this.cancelKeyboardGrab();
288
+ }
289
+ }
290
+ audit() {
291
+ if (!this.container || this.isDestroyed) return [];
292
+ const warnings = [];
293
+ const hasAriaLabel = Boolean(this.container.getAttribute("aria-label")?.trim());
294
+ const hasLabelledBy = this.checkAriaIdReferences(this.container, "aria-labelledby", warnings, true);
295
+ this.checkAriaIdReferences(this.container, "aria-describedby", warnings, true);
296
+ if (!hasAriaLabel && !hasLabelledBy) {
297
+ warnings.push(
298
+ "Aucun nom accessible d\xE9tect\xE9 sur le conteneur triable (ajoutez aria-label ou aria-labelledby)."
299
+ );
300
+ }
301
+ if (this.container.hasAttribute("aria-live")) {
302
+ warnings.push(
303
+ "\xC9vitez aria-live directement sur le conteneur triable (annoncez via une r\xE9gion status d\xE9di\xE9e ou ariaNotify)."
304
+ );
305
+ }
306
+ const items = this.getItems();
307
+ items.forEach((item, index) => {
308
+ const rawTab = item.getAttribute("tabindex");
309
+ if (rawTab !== null && Number.parseInt(rawTab, 10) > 0) {
310
+ warnings.push(
311
+ `\xC9vitez tabindex="${rawTab}" (> 0) sur l'\xE9l\xE9ment #${index + 1} pour pr\xE9server l'ordre de tabulation naturel.`
312
+ );
313
+ }
314
+ if (this.options.handleSelector) {
315
+ const handle = this.resolveTriggerForItem(item);
316
+ if (!handle || handle === item) {
317
+ warnings.push(`Poign\xE9e introuvable ("${this.options.handleSelector}") dans l'\xE9l\xE9ment #${index + 1}.`);
318
+ return;
319
+ }
320
+ const hTab = handle.getAttribute("tabindex");
321
+ if (hTab !== null && Number.parseInt(hTab, 10) > 0) {
322
+ warnings.push(`\xC9vitez tabindex="${hTab}" (> 0) sur la poign\xE9e de l'\xE9l\xE9ment #${index + 1}.`);
323
+ }
324
+ const isFocusable = handle.matches("button:not([disabled]), a[href], input:not([disabled]), [tabindex]") && handle.getAttribute("tabindex") !== "-1";
325
+ if (!isFocusable) {
326
+ warnings.push(`La poign\xE9e de l'\xE9l\xE9ment #${index + 1} doit \xEAtre focusable au clavier.`);
327
+ }
328
+ const hLabel = handle.getAttribute("aria-label")?.trim() || handle.textContent?.trim() || "";
329
+ const hLabelledBy = this.checkAriaIdReferences(handle, "aria-labelledby", warnings, true);
330
+ if (!hLabel && !hLabelledBy) {
331
+ warnings.push(`La poign\xE9e de l'\xE9l\xE9ment #${index + 1} ne poss\xE8de aucun nom accessible.`);
332
+ }
333
+ }
334
+ });
335
+ return warnings;
336
+ }
337
+ destroy() {
338
+ if (this.isDestroyed) return;
339
+ this.isDestroyed = true;
340
+ this.cancel();
341
+ this.rootAbort.abort();
342
+ if (this.mutationObserver) {
343
+ this.mutationObserver.disconnect();
344
+ this.mutationObserver = null;
345
+ }
346
+ if (this.announceTimerId !== null) {
347
+ clearTimeout(this.announceTimerId);
348
+ this.announceTimerId = null;
349
+ }
350
+ if (this.srStatusEl) {
351
+ this.srStatusEl.remove();
352
+ this.srStatusEl = null;
353
+ }
354
+ if (this.container) {
355
+ this.clearDropMarker();
356
+ this.container.classList.remove("wulf-sortable--dragging");
357
+ if (!this.hadRootClass) {
358
+ this.container.classList.remove("wulf-sortable");
359
+ }
360
+ }
361
+ for (const handle of this.addedHandles) {
362
+ handle.classList.remove("wulf-sortable-handle");
363
+ }
364
+ this.addedHandles.clear();
365
+ for (const [el, saved] of this.savedAttributes.entries()) {
366
+ el.classList.remove("wulf-sortable-item--dragging", "wulf-sortable-item--grabbed");
367
+ el.removeAttribute("data-wulf-dragging");
368
+ el.removeAttribute("data-wulf-grabbed");
369
+ if (saved.hadTabIndex && saved.prevTabIndex !== null) {
370
+ el.setAttribute("tabindex", saved.prevTabIndex);
371
+ } else if (!saved.hadTabIndex) {
372
+ el.removeAttribute("tabindex");
373
+ }
374
+ if (saved.hadAriaPressed && saved.prevAriaPressed !== null) {
375
+ el.setAttribute("aria-pressed", saved.prevAriaPressed);
376
+ } else if (!saved.hadAriaPressed) {
377
+ el.removeAttribute("aria-pressed");
378
+ }
379
+ }
380
+ this.savedAttributes.clear();
381
+ }
382
+ resolveI18n() {
383
+ if (this.options.lang) {
384
+ const prev = sortableI18n.getLocale();
385
+ sortableI18n.setLocale(this.options.lang);
386
+ const dict = sortableI18n.getAll(this.i18nOverrides);
387
+ sortableI18n.setLocale(prev);
388
+ return dict;
389
+ }
390
+ return sortableI18n.getAll(this.i18nOverrides);
391
+ }
392
+ getItemLabelText(item, index) {
393
+ if (typeof this.options.getItemLabel === "function") {
394
+ try {
395
+ const custom = stripBidiAndInvisibles(this.options.getItemLabel(item, index), 200).trim();
396
+ if (custom) return custom;
397
+ } catch {
398
+ }
399
+ }
400
+ const raw = item.getAttribute("aria-label") || item.getAttribute("data-label") || item.textContent || "";
401
+ const clean = stripBidiAndInvisibles(raw, 200).replace(/\s+/g, " ").trim();
402
+ if (clean) return clean.slice(0, 80);
403
+ return this.resolveI18n().defaultItemLabel(index + 1);
404
+ }
405
+ mountStatusRegion() {
406
+ if (!this.container || typeof document === "undefined") return;
407
+ if (typeof document.ariaNotify === "function") {
408
+ return;
409
+ }
410
+ const status = document.createElement("div");
411
+ status.className = "wulf-sortable-sr-status";
412
+ status.setAttribute("role", "status");
413
+ status.setAttribute("aria-live", "polite");
414
+ status.setAttribute("aria-atomic", "true");
415
+ status.setAttribute("data-wulf-sortable-ignore", "true");
416
+ const root = typeof this.container.getRootNode === "function" ? this.container.getRootNode() : document;
417
+ const mountTarget = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root : document.body || this.container;
418
+ mountTarget.appendChild(status);
419
+ this.srStatusEl = status;
420
+ }
421
+ announce(message) {
422
+ if (this.isDestroyed || typeof document === "undefined") return;
423
+ const clean = stripBidiAndInvisibles(message, 400).trim();
424
+ if (!clean) return;
425
+ const docWithNotify = document;
426
+ if (typeof docWithNotify.ariaNotify === "function") {
427
+ try {
428
+ docWithNotify.ariaNotify(clean, { priority: "normal" });
429
+ return;
430
+ } catch {
431
+ }
432
+ }
433
+ if (!this.srStatusEl) {
434
+ this.mountStatusRegion();
435
+ }
436
+ if (!this.srStatusEl) return;
437
+ if (this.announceTimerId !== null) {
438
+ clearTimeout(this.announceTimerId);
439
+ this.announceTimerId = null;
440
+ }
441
+ this.srStatusEl.textContent = "";
442
+ this.announceTimerId = setTimeout(() => {
443
+ this.announceTimerId = null;
444
+ if (!this.isDestroyed && this.srStatusEl) {
445
+ this.srStatusEl.textContent = clean;
446
+ }
447
+ }, 40);
448
+ }
449
+ resolveTriggerForItem(item) {
450
+ if (!this.options.handleSelector) return item;
451
+ try {
452
+ const handle = item.querySelector(this.options.handleSelector);
453
+ return handle ?? null;
454
+ } catch {
455
+ return null;
456
+ }
457
+ }
458
+ findItemForEvent(event) {
459
+ if (!this.container) return null;
460
+ const items = this.getItems();
461
+ if (items.length === 0) return null;
462
+ const itemSet = new Set(items);
463
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [event.target];
464
+ for (const node of path) {
465
+ if (node && itemSet.has(node)) {
466
+ return node;
467
+ }
468
+ if (node === this.container) break;
469
+ }
470
+ return null;
471
+ }
472
+ hasInteractiveDescendantBeforeItem(event, item) {
473
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [event.target];
474
+ for (const node of path) {
475
+ if (!node || node === item) break;
476
+ if (typeof Element !== "undefined" && node instanceof Element) {
477
+ if (isEditableTarget(node) || node.matches(INTERACTIVE_DESCENDANT_SELECTOR)) {
478
+ return true;
479
+ }
480
+ }
481
+ }
482
+ return false;
483
+ }
484
+ findHandleInPath(event, item) {
485
+ if (!this.options.handleSelector) return item;
486
+ const path = typeof event.composedPath === "function" ? event.composedPath() : [event.target];
487
+ for (const node of path) {
488
+ if (!node) continue;
489
+ if (typeof HTMLElement !== "undefined" && node instanceof HTMLElement) {
490
+ try {
491
+ if (node.matches(this.options.handleSelector) && item.contains(node)) {
492
+ if (node.hasAttribute("disabled") || node.getAttribute("aria-disabled") === "true") {
493
+ return null;
494
+ }
495
+ return node;
496
+ }
497
+ } catch {
498
+ return null;
499
+ }
500
+ }
501
+ if (node === item) break;
502
+ }
503
+ return null;
504
+ }
505
+ bindContainerEvents() {
506
+ if (!this.container) return;
507
+ const signal = this.rootAbort.signal;
508
+ this.container.addEventListener("pointerdown", (e) => this.handlePointerDown(e), { signal });
509
+ this.container.addEventListener("keydown", (e) => this.handleKeyDown(e), { signal });
510
+ this.container.addEventListener("focusout", (e) => this.handleFocusOut(e), { signal });
511
+ this.container.addEventListener("focusin", (e) => this.handleFocusIn(e), { signal });
512
+ }
513
+ observeDomChanges() {
514
+ if (!this.container || typeof MutationObserver === "undefined") return;
515
+ this.mutationObserver = new MutationObserver(() => {
516
+ if (!this.isDestroyed && !this.pointerDrag?.started) {
517
+ this.refresh();
518
+ }
519
+ });
520
+ this.mutationObserver.observe(this.container, { childList: true });
521
+ }
522
+ handleFocusIn(event) {
523
+ if (!this.container || this.isDestroyed) return;
524
+ const target = event.target;
525
+ if (!target || typeof target.matches !== "function") return;
526
+ let isFocusVisible = false;
527
+ try {
528
+ isFocusVisible = target.matches(":focus-visible");
529
+ } catch {
530
+ isFocusVisible = false;
531
+ }
532
+ if (!isFocusVisible) return;
533
+ const item = this.findItemForEvent(event);
534
+ if (!item || typeof item.scrollIntoView !== "function") return;
535
+ const running = typeof item.getAnimations === "function" && item.getAnimations().some((a) => a.playState === "running");
536
+ if (!running) {
537
+ item.scrollIntoView({ block: "nearest", inline: "nearest" });
538
+ }
539
+ }
540
+ handlePointerDown(event) {
541
+ if (!this.container || this.isDestroyed || this.options.disabled) return;
542
+ if (this.pointerDrag || event.button !== 0 || event.isPrimary === false) return;
543
+ if (isEditableTarget(event.target)) return;
544
+ const item = this.findItemForEvent(event);
545
+ if (!item) return;
546
+ let handle = item;
547
+ if (this.options.handleSelector) {
548
+ handle = this.findHandleInPath(event, item);
549
+ if (!handle) return;
550
+ } else if (this.hasInteractiveDescendantBeforeItem(event, item)) {
551
+ return;
552
+ }
553
+ if (this.keyboardGrab) {
554
+ this.commitKeyboardGrab();
555
+ }
556
+ const items = this.getItems();
557
+ const oldIndex = items.indexOf(item);
558
+ if (oldIndex === -1 || items.length < 2) return;
559
+ const siblings = items.filter((el) => el !== item);
560
+ const dragAbort = new AbortController();
561
+ this.pointerDrag = {
562
+ sessionId: ++this.dragSessionSeq,
563
+ pointerId: event.pointerId,
564
+ item,
565
+ handle,
566
+ oldIndex,
567
+ targetIndex: oldIndex,
568
+ startX: event.clientX,
569
+ startY: event.clientY,
570
+ lastClientX: event.clientX,
571
+ lastClientY: event.clientY,
572
+ startScrollLeft: this.container.scrollLeft,
573
+ startScrollTop: this.container.scrollTop,
574
+ started: false,
575
+ prevTranslate: item.style.translate,
576
+ slotRect: item.getBoundingClientRect(),
577
+ siblings,
578
+ items,
579
+ abortController: dragAbort,
580
+ rafId: null,
581
+ lastFrameTime: typeof performance !== "undefined" ? performance.now() : Date.now()
582
+ };
583
+ const sig = dragAbort.signal;
584
+ document.addEventListener("pointermove", (e) => this.handlePointerMove(e), { signal: sig });
585
+ document.addEventListener("pointerup", (e) => this.handlePointerUp(e), { signal: sig });
586
+ document.addEventListener("pointercancel", (e) => this.handlePointerCancel(e), { signal: sig });
587
+ document.addEventListener("keydown", (e) => this.handlePointerEscape(e), { signal: sig });
588
+ if (this.options.threshold === 0) {
589
+ this.activatePointerDrag(this.pointerDrag);
590
+ }
591
+ }
592
+ activatePointerDrag(drag) {
593
+ if (!this.container || drag.started) return;
594
+ drag.started = true;
595
+ const activeAnim = this.activeAnimations.get(drag.item);
596
+ if (activeAnim) {
597
+ try {
598
+ activeAnim.cancel();
599
+ } catch {
600
+ }
601
+ this.activeAnimations.delete(drag.item);
602
+ }
603
+ try {
604
+ drag.handle.setPointerCapture?.(drag.pointerId);
605
+ } catch {
606
+ }
607
+ drag.handle.addEventListener(
608
+ "lostpointercapture",
609
+ () => {
610
+ if (this.pointerDrag === drag && drag.started) {
611
+ this.endPointerDrag(true);
612
+ }
613
+ },
614
+ { signal: drag.abortController.signal }
615
+ );
616
+ this.container.classList.add("wulf-sortable--dragging");
617
+ drag.item.classList.add("wulf-sortable-item--dragging");
618
+ drag.item.setAttribute("data-wulf-dragging", "true");
619
+ this.safeInvoke(this.options.onStart, {
620
+ item: drag.item,
621
+ index: drag.oldIndex,
622
+ trigger: "pointer"
623
+ });
624
+ if (this.options.autoScroll) {
625
+ this.startAutoScrollLoop(drag);
626
+ }
627
+ }
628
+ handlePointerMove(event) {
629
+ const drag = this.pointerDrag;
630
+ if (!drag || event.pointerId !== drag.pointerId || !this.container) return;
631
+ drag.lastClientX = event.clientX;
632
+ drag.lastClientY = event.clientY;
633
+ if (!drag.started) {
634
+ const dist = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
635
+ if (dist < this.options.threshold) return;
636
+ this.activatePointerDrag(drag);
637
+ }
638
+ this.updatePointerPosition(drag);
639
+ }
640
+ updatePointerPosition(drag) {
641
+ if (!this.container) return;
642
+ const axis = this.options.axis;
643
+ const scrollDx = this.container.scrollLeft - drag.startScrollLeft;
644
+ const scrollDy = this.container.scrollTop - drag.startScrollTop;
645
+ const tx = axis === "y" ? 0 : drag.lastClientX - drag.startX + scrollDx;
646
+ const ty = axis === "x" ? 0 : drag.lastClientY - drag.startY + scrollDy;
647
+ drag.item.style.translate = `${tx}px ${ty}px`;
648
+ const nextTarget = this.computePointerTargetIndex(drag, tx, ty);
649
+ this.updateDropMarker(drag, nextTarget);
650
+ if (nextTarget !== drag.targetIndex) {
651
+ const fromIndex = drag.targetIndex;
652
+ drag.targetIndex = nextTarget;
653
+ this.safeInvoke(this.options.onMove, {
654
+ item: drag.item,
655
+ oldIndex: drag.oldIndex,
656
+ fromIndex,
657
+ toIndex: nextTarget,
658
+ items: computeReorderedArray(drag.items, drag.oldIndex, nextTarget),
659
+ trigger: "pointer"
660
+ });
661
+ }
662
+ }
663
+ computePointerTargetIndex(drag, tx, ty) {
664
+ if (!this.container) return drag.oldIndex;
665
+ const axis = this.options.axis;
666
+ const containerRect = this.container.getBoundingClientRect();
667
+ const isRtl = this.isRtl();
668
+ if (axis === "y") {
669
+ const py2 = Math.max(containerRect.top, Math.min(containerRect.bottom, drag.lastClientY));
670
+ let idx = 0;
671
+ for (const sibling of drag.siblings) {
672
+ const r = sibling.getBoundingClientRect();
673
+ if (r.top + r.height / 2 < py2) {
674
+ idx++;
675
+ }
676
+ }
677
+ return idx;
678
+ }
679
+ if (axis === "x") {
680
+ const px2 = Math.max(containerRect.left, Math.min(containerRect.right, drag.lastClientX));
681
+ let idx = 0;
682
+ for (const sibling of drag.siblings) {
683
+ const r = sibling.getBoundingClientRect();
684
+ const midX = r.left + r.width / 2;
685
+ if (isRtl ? midX > px2 : midX < px2) {
686
+ idx++;
687
+ }
688
+ }
689
+ return idx;
690
+ }
691
+ const px = drag.lastClientX;
692
+ const py = drag.lastClientY;
693
+ let bestIdx = drag.oldIndex;
694
+ let bestDistSq = Number.POSITIVE_INFINITY;
695
+ for (let i = 0; i < drag.items.length; i++) {
696
+ const el = drag.items[i];
697
+ let r = el.getBoundingClientRect();
698
+ if (el === drag.item) {
699
+ r = new DOMRect(r.left - tx, r.top - ty, r.width, r.height);
700
+ }
701
+ if (px >= r.left && px <= r.right && py >= r.top && py <= r.bottom) {
702
+ return i;
703
+ }
704
+ const cx = r.left + r.width / 2;
705
+ const cy = r.top + r.height / 2;
706
+ const dSq = (px - cx) * (px - cx) + (py - cy) * (py - cy);
707
+ if (dSq < bestDistSq) {
708
+ bestDistSq = dSq;
709
+ bestIdx = i;
710
+ }
711
+ }
712
+ return bestIdx;
713
+ }
714
+ updateDropMarker(drag, targetIndex) {
715
+ if (!this.container) return;
716
+ if (targetIndex === drag.oldIndex || drag.siblings.length === 0) {
717
+ this.clearDropMarker();
718
+ return;
719
+ }
720
+ const axis = this.options.axis;
721
+ this.container.setAttribute("data-wulf-drop", axis);
722
+ const size = 3;
723
+ if (axis === "both") {
724
+ const targetSlotEl = drag.items[targetIndex];
725
+ if (targetSlotEl) {
726
+ const r = targetSlotEl.getBoundingClientRect();
727
+ this.setDropMarkerVars(r.left, r.top, r.width, r.height);
728
+ }
729
+ return;
730
+ }
731
+ const sibs = drag.siblings;
732
+ const refRect = sibs[Math.min(targetIndex, sibs.length - 1)].getBoundingClientRect();
733
+ if (axis === "y") {
734
+ let y;
735
+ if (targetIndex === 0) {
736
+ y = sibs[0].getBoundingClientRect().top - size;
737
+ } else if (targetIndex >= sibs.length) {
738
+ y = sibs[sibs.length - 1].getBoundingClientRect().bottom;
739
+ } else {
740
+ const prevR = sibs[targetIndex - 1].getBoundingClientRect();
741
+ const nextR = sibs[targetIndex].getBoundingClientRect();
742
+ y = (prevR.bottom + nextR.top - size) / 2;
743
+ }
744
+ this.setDropMarkerVars(refRect.left, y, refRect.width, size);
745
+ return;
746
+ }
747
+ const isRtl = this.isRtl();
748
+ let x;
749
+ if (targetIndex === 0) {
750
+ const firstR = sibs[0].getBoundingClientRect();
751
+ x = isRtl ? firstR.right : firstR.left - size;
752
+ } else if (targetIndex >= sibs.length) {
753
+ const lastR = sibs[sibs.length - 1].getBoundingClientRect();
754
+ x = isRtl ? lastR.left - size : lastR.right;
755
+ } else {
756
+ const prevR = sibs[targetIndex - 1].getBoundingClientRect();
757
+ const nextR = sibs[targetIndex].getBoundingClientRect();
758
+ x = isRtl ? (nextR.right + prevR.left - size) / 2 : (prevR.right + nextR.left - size) / 2;
759
+ }
760
+ this.setDropMarkerVars(x, refRect.top, size, refRect.height);
761
+ }
762
+ setDropMarkerVars(x, y, w, h) {
763
+ if (!this.container) return;
764
+ this.container.style.setProperty("--wulf-drop-x", `${Math.round(x)}px`);
765
+ this.container.style.setProperty("--wulf-drop-y", `${Math.round(y)}px`);
766
+ this.container.style.setProperty("--wulf-drop-w", `${Math.max(1, Math.round(w))}px`);
767
+ this.container.style.setProperty("--wulf-drop-h", `${Math.max(1, Math.round(h))}px`);
768
+ }
769
+ clearDropMarker() {
770
+ if (!this.container) return;
771
+ this.container.removeAttribute("data-wulf-drop");
772
+ this.container.style.removeProperty("--wulf-drop-x");
773
+ this.container.style.removeProperty("--wulf-drop-y");
774
+ this.container.style.removeProperty("--wulf-drop-w");
775
+ this.container.style.removeProperty("--wulf-drop-h");
776
+ }
777
+ startAutoScrollLoop(drag) {
778
+ const tick = (now) => {
779
+ if (this.pointerDrag !== drag || !drag.started || !this.container || this.isDestroyed) return;
780
+ const dt = Math.min(64, Math.max(0, now - drag.lastFrameTime)) / 16.6667;
781
+ drag.lastFrameTime = now;
782
+ const cRect = this.container.getBoundingClientRect();
783
+ const axis = this.options.axis;
784
+ const maxSpeed = this.options.autoScrollSpeed * dt;
785
+ let scrolled = false;
786
+ if (axis === "y" || axis === "both") {
787
+ const edge = Math.min(drag.slotRect.height || 40, cRect.height / 3);
788
+ if (edge > 0) {
789
+ if (drag.lastClientY < cRect.top + edge && this.container.scrollTop > 0) {
790
+ const ratio = Math.min(2, (cRect.top + edge - drag.lastClientY) / edge);
791
+ this.container.scrollTop -= maxSpeed * ratio;
792
+ scrolled = true;
793
+ } else if (drag.lastClientY > cRect.bottom - edge && this.container.scrollTop < this.container.scrollHeight - this.container.clientHeight) {
794
+ const ratio = Math.min(2, (drag.lastClientY - (cRect.bottom - edge)) / edge);
795
+ this.container.scrollTop += maxSpeed * ratio;
796
+ scrolled = true;
797
+ }
798
+ }
799
+ }
800
+ if (axis === "x" || axis === "both") {
801
+ const edge = Math.min(drag.slotRect.width || 40, cRect.width / 3);
802
+ if (edge > 0) {
803
+ if (drag.lastClientX < cRect.left + edge) {
804
+ const ratio = Math.min(2, (cRect.left + edge - drag.lastClientX) / edge);
805
+ this.container.scrollLeft -= maxSpeed * ratio;
806
+ scrolled = true;
807
+ } else if (drag.lastClientX > cRect.right - edge) {
808
+ const ratio = Math.min(2, (drag.lastClientX - (cRect.right - edge)) / edge);
809
+ this.container.scrollLeft += maxSpeed * ratio;
810
+ scrolled = true;
811
+ }
812
+ }
813
+ }
814
+ if (scrolled) {
815
+ this.updatePointerPosition(drag);
816
+ }
817
+ drag.rafId = requestAnimationFrame(tick);
818
+ };
819
+ drag.rafId = requestAnimationFrame(tick);
820
+ }
821
+ handlePointerUp(event) {
822
+ const drag = this.pointerDrag;
823
+ if (!drag || event.pointerId !== drag.pointerId) return;
824
+ this.endPointerDrag(false);
825
+ }
826
+ handlePointerCancel(event) {
827
+ const drag = this.pointerDrag;
828
+ if (!drag || event.pointerId !== drag.pointerId) return;
829
+ this.endPointerDrag(true);
830
+ }
831
+ handlePointerEscape(event) {
832
+ if (event.key !== "Escape" || isImeComposing(event)) return;
833
+ const drag = this.pointerDrag;
834
+ if (!drag) return;
835
+ event.preventDefault();
836
+ this.endPointerDrag(true);
837
+ }
838
+ endPointerDrag(cancelled) {
839
+ const drag = this.pointerDrag;
840
+ if (!drag || !this.container) return;
841
+ this.pointerDrag = null;
842
+ drag.abortController.abort();
843
+ if (drag.rafId !== null) {
844
+ cancelAnimationFrame(drag.rafId);
845
+ drag.rafId = null;
846
+ }
847
+ try {
848
+ if (drag.handle.hasPointerCapture?.(drag.pointerId)) {
849
+ drag.handle.releasePointerCapture(drag.pointerId);
850
+ }
851
+ } catch {
852
+ }
853
+ if (!drag.started) return;
854
+ const releasedRect = drag.item.getBoundingClientRect();
855
+ this.clearDropMarker();
856
+ this.container.classList.remove("wulf-sortable--dragging");
857
+ drag.item.classList.remove("wulf-sortable-item--dragging");
858
+ drag.item.removeAttribute("data-wulf-dragging");
859
+ drag.item.style.translate = drag.prevTranslate;
860
+ const changed = !cancelled && drag.targetIndex !== drag.oldIndex;
861
+ if (cancelled) {
862
+ const snap = /* @__PURE__ */ new Map([[drag.item, releasedRect]]);
863
+ this.animateFlip([drag.item], snap);
864
+ this.safeInvoke(this.options.onCancel, {
865
+ item: drag.item,
866
+ index: drag.oldIndex,
867
+ trigger: "pointer"
868
+ });
869
+ const label2 = this.getItemLabelText(drag.item, drag.oldIndex);
870
+ this.announce(this.resolveI18n().cancelled(label2, drag.oldIndex + 1, drag.items.length));
871
+ return;
872
+ }
873
+ if (!changed) {
874
+ const snap = /* @__PURE__ */ new Map([[drag.item, releasedRect]]);
875
+ this.animateFlip([drag.item], snap);
876
+ return;
877
+ }
878
+ const ordered = computeReorderedArray(drag.items, drag.oldIndex, drag.targetIndex);
879
+ if (this.options.autoMove) {
880
+ const beforeRects = this.snapshotRects(drag.siblings);
881
+ beforeRects.set(drag.item, releasedRect);
882
+ moveItemInDom(this.container, drag.item, drag.siblings, drag.targetIndex);
883
+ drag.item.scrollIntoView?.({ block: "nearest", inline: "nearest" });
884
+ this.animateFlip(ordered, beforeRects);
885
+ }
886
+ this.emitReorder({
887
+ item: drag.item,
888
+ oldIndex: drag.oldIndex,
889
+ newIndex: drag.targetIndex,
890
+ items: ordered,
891
+ trigger: "pointer"
892
+ });
893
+ const label = this.getItemLabelText(drag.item, drag.targetIndex);
894
+ this.announce(this.resolveI18n().dropped(label, drag.targetIndex + 1, drag.items.length));
895
+ }
896
+ handleKeyDown(event) {
897
+ if (!this.container || this.isDestroyed || this.options.disabled) return;
898
+ if (isImeComposing(event)) return;
899
+ if (event.ctrlKey || event.altKey || event.metaKey) return;
900
+ if (isEditableTarget(event.target)) return;
901
+ const item = this.findItemForEvent(event);
902
+ if (!item) return;
903
+ const activeTrigger = this.resolveTriggerForItem(item);
904
+ const eventTarget = event.target;
905
+ if (!this.options.handleSelector) {
906
+ if (eventTarget !== item && this.hasInteractiveDescendantBeforeItem(event, item)) {
907
+ return;
908
+ }
909
+ } else if (!activeTrigger || eventTarget !== activeTrigger && !activeTrigger.contains(eventTarget)) {
910
+ return;
911
+ }
912
+ const triggerEl = activeTrigger ?? item;
913
+ if (event.key === " " || event.key === "Enter") {
914
+ event.preventDefault();
915
+ if (this.keyboardGrab && this.keyboardGrab.item === item) {
916
+ this.commitKeyboardGrab();
917
+ } else {
918
+ this.startKeyboardGrab(item, triggerEl);
919
+ }
920
+ return;
921
+ }
922
+ if (!this.keyboardGrab || this.keyboardGrab.item !== item) return;
923
+ if (event.key === "Escape") {
924
+ event.preventDefault();
925
+ this.cancelKeyboardGrab();
926
+ return;
927
+ }
928
+ const nextIndex = this.computeKeyboardNextIndex(event.key, this.keyboardGrab);
929
+ if (nextIndex === null) return;
930
+ event.preventDefault();
931
+ this.stepKeyboardGrab(nextIndex);
932
+ }
933
+ startKeyboardGrab(item, trigger) {
934
+ if (!this.container) return;
935
+ if (this.keyboardGrab) {
936
+ this.commitKeyboardGrab();
937
+ }
938
+ const items = this.getItems();
939
+ const index = items.indexOf(item);
940
+ if (index === -1 || items.length < 2) return;
941
+ this.keyboardGrab = {
942
+ item,
943
+ trigger,
944
+ originIndex: index,
945
+ currentIndex: index,
946
+ initialOrder: items.slice(),
947
+ tailRef: items[items.length - 1]?.nextSibling ?? null
948
+ };
949
+ this.container.classList.add("wulf-sortable--dragging");
950
+ item.classList.add("wulf-sortable-item--grabbed");
951
+ item.setAttribute("data-wulf-grabbed", "true");
952
+ trigger.setAttribute("aria-pressed", "true");
953
+ this.safeInvoke(this.options.onStart, {
954
+ item,
955
+ index,
956
+ trigger: "keyboard"
957
+ });
958
+ const label = this.getItemLabelText(item, index);
959
+ this.announce(this.resolveI18n().grabbed(label, index + 1, items.length));
960
+ }
961
+ computeKeyboardNextIndex(key, grab) {
962
+ const axis = this.options.axis;
963
+ const isRtl = this.isRtl();
964
+ const items = this.options.autoMove ? this.getItems() : computeReorderedArray(grab.initialOrder, grab.originIndex, grab.currentIndex);
965
+ const total = items.length;
966
+ const idx = grab.currentIndex;
967
+ if (key === "Home") return 0;
968
+ if (key === "End") return total - 1;
969
+ if (axis === "y") {
970
+ if (key === "ArrowUp") return Math.max(0, idx - 1);
971
+ if (key === "ArrowDown") return Math.min(total - 1, idx + 1);
972
+ return null;
973
+ }
974
+ if (axis === "x") {
975
+ if (key === "ArrowLeft") return isRtl ? Math.min(total - 1, idx + 1) : Math.max(0, idx - 1);
976
+ if (key === "ArrowRight") return isRtl ? Math.max(0, idx - 1) : Math.min(total - 1, idx + 1);
977
+ return null;
978
+ }
979
+ if (key === "ArrowLeft") return isRtl ? Math.min(total - 1, idx + 1) : Math.max(0, idx - 1);
980
+ if (key === "ArrowRight") return isRtl ? Math.max(0, idx - 1) : Math.min(total - 1, idx + 1);
981
+ if (key !== "ArrowUp" && key !== "ArrowDown") return null;
982
+ const currentRect = grab.item.getBoundingClientRect();
983
+ const cx0 = currentRect.left + currentRect.width / 2;
984
+ const cy0 = currentRect.top + currentRect.height / 2;
985
+ const minRowDelta = Math.max(4, currentRect.height * 0.35);
986
+ const candidates = [];
987
+ for (let i = 0; i < total; i++) {
988
+ if (i === idx) continue;
989
+ const r = items[i].getBoundingClientRect();
990
+ const cy = r.top + r.height / 2;
991
+ if (key === "ArrowDown" && cy - cy0 > minRowDelta) {
992
+ candidates.push({ index: i, cx: r.left + r.width / 2, cy });
993
+ } else if (key === "ArrowUp" && cy0 - cy > minRowDelta) {
994
+ candidates.push({ index: i, cx: r.left + r.width / 2, cy });
995
+ }
996
+ }
997
+ if (candidates.length === 0) return idx;
998
+ const targetRowCy = key === "ArrowDown" ? Math.min(...candidates.map((c) => c.cy)) : Math.max(...candidates.map((c) => c.cy));
999
+ const rowTolerance = Math.max(8, currentRect.height * 0.5);
1000
+ const sameRow = candidates.filter((c) => Math.abs(c.cy - targetRowCy) <= rowTolerance);
1001
+ let best = sameRow[0];
1002
+ let bestDx = Math.abs(best.cx - cx0);
1003
+ for (let i = 1; i < sameRow.length; i++) {
1004
+ const dx = Math.abs(sameRow[i].cx - cx0);
1005
+ if (dx < bestDx) {
1006
+ bestDx = dx;
1007
+ best = sameRow[i];
1008
+ }
1009
+ }
1010
+ return best.index;
1011
+ }
1012
+ stepKeyboardGrab(nextIndex) {
1013
+ const grab = this.keyboardGrab;
1014
+ if (!grab || !this.container || nextIndex === grab.currentIndex) return;
1015
+ const fromIndex = grab.currentIndex;
1016
+ const currentItems = this.getItems();
1017
+ const total = currentItems.length;
1018
+ if (this.options.autoMove) {
1019
+ const beforeRects = this.snapshotRects(currentItems);
1020
+ const siblings = currentItems.filter((el) => el !== grab.item);
1021
+ this.isMovingFocus = true;
1022
+ try {
1023
+ moveItemInDom(this.container, grab.item, siblings, nextIndex);
1024
+ grab.item.scrollIntoView?.({ block: "nearest", inline: "nearest" });
1025
+ if (getDeepActiveElement() !== grab.trigger) {
1026
+ grab.trigger.focus({ preventScroll: true });
1027
+ }
1028
+ } finally {
1029
+ this.isMovingFocus = false;
1030
+ }
1031
+ this.animateFlip(currentItems, beforeRects);
1032
+ }
1033
+ grab.currentIndex = nextIndex;
1034
+ const ordered = this.options.autoMove ? this.getItems() : computeReorderedArray(grab.initialOrder, grab.originIndex, nextIndex);
1035
+ this.safeInvoke(this.options.onMove, {
1036
+ item: grab.item,
1037
+ oldIndex: grab.originIndex,
1038
+ fromIndex,
1039
+ toIndex: nextIndex,
1040
+ items: ordered,
1041
+ trigger: "keyboard"
1042
+ });
1043
+ const label = this.getItemLabelText(grab.item, nextIndex);
1044
+ this.announce(this.resolveI18n().moved(label, nextIndex + 1, total));
1045
+ }
1046
+ clearKeyboardGrabVisuals(grab) {
1047
+ this.container?.classList.remove("wulf-sortable--dragging");
1048
+ grab.item.classList.remove("wulf-sortable-item--grabbed");
1049
+ grab.item.removeAttribute("data-wulf-grabbed");
1050
+ const saved = this.savedAttributes.get(grab.trigger);
1051
+ if (saved?.hadAriaPressed && saved.prevAriaPressed !== null) {
1052
+ grab.trigger.setAttribute("aria-pressed", saved.prevAriaPressed);
1053
+ } else {
1054
+ grab.trigger.removeAttribute("aria-pressed");
1055
+ }
1056
+ }
1057
+ commitKeyboardGrab() {
1058
+ const grab = this.keyboardGrab;
1059
+ if (!grab) return;
1060
+ this.keyboardGrab = null;
1061
+ this.clearKeyboardGrabVisuals(grab);
1062
+ if (grab.currentIndex !== grab.originIndex) {
1063
+ const ordered = this.options.autoMove ? this.getItems() : computeReorderedArray(grab.initialOrder, grab.originIndex, grab.currentIndex);
1064
+ this.emitReorder({
1065
+ item: grab.item,
1066
+ oldIndex: grab.originIndex,
1067
+ newIndex: grab.currentIndex,
1068
+ items: ordered,
1069
+ trigger: "keyboard"
1070
+ });
1071
+ const label = this.getItemLabelText(grab.item, grab.currentIndex);
1072
+ this.announce(this.resolveI18n().dropped(label, grab.currentIndex + 1, ordered.length));
1073
+ }
1074
+ }
1075
+ cancelKeyboardGrab() {
1076
+ const grab = this.keyboardGrab;
1077
+ if (!grab || !this.container) return;
1078
+ this.keyboardGrab = null;
1079
+ if (this.options.autoMove && grab.currentIndex !== grab.originIndex) {
1080
+ const currentItems = this.getItems();
1081
+ const beforeRects = this.snapshotRects(currentItems);
1082
+ this.isMovingFocus = true;
1083
+ try {
1084
+ const ref = grab.tailRef && grab.tailRef.parentNode === this.container ? grab.tailRef : null;
1085
+ for (const node of grab.initialOrder) {
1086
+ if (node.parentNode === this.container && node !== ref) {
1087
+ safeMove(this.container, node, ref);
1088
+ }
1089
+ }
1090
+ grab.item.scrollIntoView?.({ block: "nearest", inline: "nearest" });
1091
+ if (getDeepActiveElement() !== grab.trigger) {
1092
+ grab.trigger.focus({ preventScroll: true });
1093
+ }
1094
+ } finally {
1095
+ this.isMovingFocus = false;
1096
+ }
1097
+ this.animateFlip(grab.initialOrder, beforeRects);
1098
+ }
1099
+ this.clearKeyboardGrabVisuals(grab);
1100
+ this.safeInvoke(this.options.onCancel, {
1101
+ item: grab.item,
1102
+ index: grab.originIndex,
1103
+ trigger: "keyboard"
1104
+ });
1105
+ const total = this.getItems().length || grab.initialOrder.length;
1106
+ const label = this.getItemLabelText(grab.item, grab.originIndex);
1107
+ this.announce(this.resolveI18n().cancelled(label, grab.originIndex + 1, total));
1108
+ }
1109
+ handleFocusOut(event) {
1110
+ if (this.isMovingFocus || !this.keyboardGrab) return;
1111
+ const grab = this.keyboardGrab;
1112
+ const nextFocus = event.relatedTarget;
1113
+ if (!nextFocus || nextFocus !== grab.trigger && !grab.trigger.contains(nextFocus)) {
1114
+ this.commitKeyboardGrab();
1115
+ }
1116
+ }
1117
+ snapshotRects(elements) {
1118
+ const map = /* @__PURE__ */ new Map();
1119
+ for (const el of elements) {
1120
+ const prev = this.activeAnimations.get(el);
1121
+ if (prev) {
1122
+ try {
1123
+ prev.finish();
1124
+ } catch {
1125
+ }
1126
+ this.activeAnimations.delete(el);
1127
+ }
1128
+ map.set(el, el.getBoundingClientRect());
1129
+ }
1130
+ return map;
1131
+ }
1132
+ animateFlip(elements, beforeRects) {
1133
+ const duration = this.options.animationDuration;
1134
+ if (duration <= 0 || prefersReducedMotion()) return;
1135
+ for (const el of elements) {
1136
+ if (typeof el.animate !== "function") continue;
1137
+ const oldRect = beforeRects.get(el);
1138
+ if (!oldRect) continue;
1139
+ const newRect = el.getBoundingClientRect();
1140
+ const dx = oldRect.left - newRect.left;
1141
+ const dy = oldRect.top - newRect.top;
1142
+ if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) continue;
1143
+ try {
1144
+ const anim = el.animate(
1145
+ [{ translate: `${dx}px ${dy}px` }, { translate: "0px 0px" }],
1146
+ { duration, easing: "cubic-bezier(0.2, 0.8, 0.2, 1)" }
1147
+ );
1148
+ this.activeAnimations.set(el, anim);
1149
+ anim.addEventListener(
1150
+ "finish",
1151
+ () => {
1152
+ if (this.activeAnimations.get(el) === anim) {
1153
+ this.activeAnimations.delete(el);
1154
+ }
1155
+ },
1156
+ { once: true }
1157
+ );
1158
+ } catch {
1159
+ }
1160
+ }
1161
+ }
1162
+ isRtl() {
1163
+ if (!this.container || typeof window === "undefined" || typeof window.getComputedStyle !== "function") {
1164
+ return false;
1165
+ }
1166
+ return window.getComputedStyle(this.container).direction === "rtl";
1167
+ }
1168
+ emitReorder(detail) {
1169
+ this.safeInvoke(this.options.onReorder, detail);
1170
+ if (this.container && typeof CustomEvent === "function") {
1171
+ this.container.dispatchEvent(
1172
+ new CustomEvent("wulf:sortable:reorder", {
1173
+ bubbles: true,
1174
+ detail
1175
+ })
1176
+ );
1177
+ }
1178
+ }
1179
+ safeInvoke(fn, detail) {
1180
+ if (typeof fn !== "function") return;
1181
+ try {
1182
+ fn(detail);
1183
+ } catch {
1184
+ }
1185
+ }
1186
+ };
1187
+
1188
+ export {
1189
+ sortableFr,
1190
+ sortableEn,
1191
+ sortableI18n,
1192
+ Sortable,
1193
+ sortable_exports
1194
+ };
1195
+ //# sourceMappingURL=chunk-ITRU2RFV.js.map