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,621 @@
1
+ import {
2
+ AuditableComponent,
3
+ __export
4
+ } from "./chunk-VJO22BAT.js";
5
+
6
+ // src/anchor/index.ts
7
+ var anchor_exports = {};
8
+ __export(anchor_exports, {
9
+ Anchor: () => Anchor,
10
+ default: () => Anchor
11
+ });
12
+
13
+ // src/anchor/Anchor.ts
14
+ var anchorIdCounter = 0;
15
+ var ALL_PLACEMENTS = [
16
+ "bottom-start",
17
+ "bottom",
18
+ "bottom-end",
19
+ "top-start",
20
+ "top",
21
+ "top-end",
22
+ "right-start",
23
+ "right",
24
+ "right-end",
25
+ "left-start",
26
+ "left",
27
+ "left-end"
28
+ ];
29
+ var PLACEMENT_SET = new Set(ALL_PLACEMENTS);
30
+ function resolveCandidatePlacements(preferred) {
31
+ const seen = /* @__PURE__ */ new Set();
32
+ const out = [];
33
+ if (Array.isArray(preferred)) {
34
+ for (const p of preferred) {
35
+ if (typeof p === "string" && PLACEMENT_SET.has(p) && !seen.has(p)) {
36
+ seen.add(p);
37
+ out.push(p);
38
+ }
39
+ }
40
+ }
41
+ for (const p of ALL_PLACEMENTS) {
42
+ if (!seen.has(p)) out.push(p);
43
+ }
44
+ return out;
45
+ }
46
+ var OPPOSITE_SIDE = {
47
+ top: "bottom",
48
+ bottom: "top",
49
+ left: "right",
50
+ right: "left"
51
+ };
52
+ var ROLE_BY_HASPOPUP = {
53
+ menu: "menu",
54
+ listbox: "listbox",
55
+ tree: "tree",
56
+ grid: "grid",
57
+ dialog: "dialog"
58
+ };
59
+ function resolveEl(target, root) {
60
+ if (typeof target !== "string") {
61
+ return typeof HTMLElement !== "undefined" && target instanceof HTMLElement ? target : null;
62
+ }
63
+ if (!target || typeof document === "undefined") return null;
64
+ try {
65
+ return (root ?? document).querySelector(target);
66
+ } catch {
67
+ return null;
68
+ }
69
+ }
70
+ function getParentCrossingShadow(el) {
71
+ if (el.parentElement) return el.parentElement;
72
+ const root = typeof el.getRootNode === "function" ? el.getRootNode() : null;
73
+ if (typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot && root.host instanceof HTMLElement) {
74
+ return root.host;
75
+ }
76
+ return null;
77
+ }
78
+ function isTopLayerElement(el) {
79
+ try {
80
+ return el.matches(":popover-open") || el.matches(":modal");
81
+ } catch {
82
+ return el.classList.contains(":popover-open");
83
+ }
84
+ }
85
+ function isRtlElement(el) {
86
+ if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return false;
87
+ return window.getComputedStyle(el).direction === "rtl";
88
+ }
89
+ function parsePlacement(placement) {
90
+ const idx = placement.indexOf("-");
91
+ if (idx === -1) return [placement, null];
92
+ return [placement.slice(0, idx), placement.slice(idx + 1)];
93
+ }
94
+ function toLogicalPositionArea(side, alignment, rtl) {
95
+ const inlineStart = rtl ? "right" : "left";
96
+ const blockPos = side === "top" ? "block-start" : side === "bottom" ? "block-end" : null;
97
+ if (blockPos) {
98
+ if (!alignment) return blockPos;
99
+ return `${blockPos} ${alignment === "start" ? "span-inline-end" : "span-inline-start"}`;
100
+ }
101
+ const inlinePos = side === inlineStart ? "inline-start" : "inline-end";
102
+ if (!alignment) return inlinePos;
103
+ return `${inlinePos} ${alignment === "start" ? "span-block-end" : "span-block-start"}`;
104
+ }
105
+ function intersectRects(a, b) {
106
+ const x = Math.max(a.x, b.x);
107
+ const y = Math.max(a.y, b.y);
108
+ const right = Math.min(a.x + a.width, b.x + b.width);
109
+ const bottom = Math.min(a.y + a.height, b.y + b.height);
110
+ return { x, y, width: Math.max(0, right - x), height: Math.max(0, bottom - y) };
111
+ }
112
+ function getViewportRect() {
113
+ if (typeof window === "undefined" || typeof document === "undefined") {
114
+ return { x: 0, y: 0, width: 0, height: 0 };
115
+ }
116
+ const vv = window.visualViewport;
117
+ if (vv) {
118
+ return { x: vv.offsetLeft, y: vv.offsetTop, width: vv.width, height: vv.height };
119
+ }
120
+ return {
121
+ x: 0,
122
+ y: 0,
123
+ width: document.documentElement.clientWidth || window.innerWidth,
124
+ height: document.documentElement.clientHeight || window.innerHeight
125
+ };
126
+ }
127
+ function getBoundaryRect(floating, boundary) {
128
+ if (boundary && typeof boundary === "object" && !("nodeType" in boundary)) {
129
+ return { ...boundary };
130
+ }
131
+ if (typeof HTMLElement !== "undefined" && boundary instanceof HTMLElement) {
132
+ const r = boundary.getBoundingClientRect();
133
+ return { x: r.left, y: r.top, width: r.width, height: r.height };
134
+ }
135
+ let rect = getViewportRect();
136
+ if (boundary === "viewport" || isTopLayerElement(floating) || typeof window === "undefined") {
137
+ return rect;
138
+ }
139
+ const clipRe = /(hidden|clip|auto|scroll)/;
140
+ let cur = getParentCrossingShadow(floating);
141
+ while (cur && cur !== document.body && cur !== document.documentElement) {
142
+ const cs = window.getComputedStyle(cur);
143
+ if (clipRe.test(cs.overflow + cs.overflowX + cs.overflowY)) {
144
+ const cr = cur.getBoundingClientRect();
145
+ rect = intersectRects(rect, {
146
+ x: cr.left + cur.clientLeft,
147
+ y: cr.top + cur.clientTop,
148
+ width: cur.clientWidth || cr.width,
149
+ height: cur.clientHeight || cr.height
150
+ });
151
+ }
152
+ cur = getParentCrossingShadow(cur);
153
+ }
154
+ return rect;
155
+ }
156
+ function getContainingBlockOffset(floating, strategy) {
157
+ if (typeof window === "undefined") return { x: 0, y: 0 };
158
+ if (strategy === "absolute") {
159
+ const op = floating.offsetParent;
160
+ if (op instanceof HTMLElement && op !== document.body && op !== document.documentElement) {
161
+ const r = op.getBoundingClientRect();
162
+ return { x: r.left + op.clientLeft - op.scrollLeft, y: r.top + op.clientTop - op.scrollTop };
163
+ }
164
+ return { x: -window.scrollX, y: -window.scrollY };
165
+ }
166
+ if (isTopLayerElement(floating)) return { x: 0, y: 0 };
167
+ let cur = getParentCrossingShadow(floating);
168
+ while (cur && cur !== document.documentElement) {
169
+ const cs = window.getComputedStyle(cur);
170
+ if (cs.transform !== "none" || cs.perspective !== "none" || cs.filter !== "none" || cs.backdropFilter && cs.backdropFilter !== "none" || /layout|paint|strict|content/.test(cs.contain) || /transform|perspective|filter/.test(cs.willChange)) {
171
+ const r = cur.getBoundingClientRect();
172
+ return {
173
+ x: r.left + cur.clientLeft - cur.scrollLeft,
174
+ y: r.top + cur.clientTop - cur.scrollTop
175
+ };
176
+ }
177
+ cur = getParentCrossingShadow(cur);
178
+ }
179
+ return { x: 0, y: 0 };
180
+ }
181
+ var Anchor = class _Anchor extends AuditableComponent {
182
+ reference;
183
+ floating;
184
+ options;
185
+ anchorName;
186
+ isDestroyed = false;
187
+ isRunning = false;
188
+ nativeApplied = false;
189
+ rafId = null;
190
+ resizeObserver = null;
191
+ abortController = null;
192
+ savedRefAnchorName = "";
193
+ savedFloatingStyles = {};
194
+ savedPlacementAttr = null;
195
+ savedArrowStyles = null;
196
+ constructor(reference, floating, options = {}) {
197
+ super();
198
+ const refEl = resolveEl(reference);
199
+ const floatEl = resolveEl(floating);
200
+ if (!refEl || !floatEl) {
201
+ throw new Error("[Wulf.Anchor] \xC9l\xE9ments reference et floating valides requis.");
202
+ }
203
+ this.reference = refEl;
204
+ this.floating = floatEl;
205
+ this.anchorName = `--wulf-anchor-${++anchorIdCounter}`;
206
+ const arrowEl = options.arrow ? typeof options.arrow === "string" ? resolveEl(options.arrow, floatEl) ?? resolveEl(options.arrow) : resolveEl(options.arrow) : null;
207
+ const rawPad = options.padding;
208
+ const padding = typeof rawPad === "number" && Number.isFinite(rawPad) && rawPad >= 0 ? rawPad : 8;
209
+ const rawArrowPad = options.arrowPadding;
210
+ const arrowPadding = typeof rawArrowPad === "number" && Number.isFinite(rawArrowPad) && rawArrowPad >= 0 ? rawArrowPad : 6;
211
+ this.options = {
212
+ placement: options.placement ?? "bottom-start",
213
+ strategy: options.strategy ?? "fixed",
214
+ offset: options.offset ?? 8,
215
+ flip: options.flip ?? true,
216
+ shift: options.shift ?? true,
217
+ padding,
218
+ arrow: arrowEl,
219
+ arrowPadding,
220
+ boundary: options.boundary ?? "clippingAncestors",
221
+ autoUpdate: options.autoUpdate ?? true,
222
+ useNativeAnchor: options.useNativeAnchor ?? false,
223
+ preferredPlacements: Array.isArray(options.preferredPlacements) ? [...options.preferredPlacements] : void 0,
224
+ onPosition: options.onPosition,
225
+ audit: options.audit ?? true
226
+ };
227
+ this.saveInitialState();
228
+ this.update();
229
+ if (this.options.autoUpdate) {
230
+ this.start();
231
+ }
232
+ this.runAuditWarning(this.options.audit);
233
+ }
234
+ /**
235
+ * Détecte si CSS Anchor Positioning natif (anchor-name + position-area) est supporté.
236
+ */
237
+ static supportsNativeAnchor() {
238
+ return typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("anchor-name", "--wulf-a") && CSS.supports("position-area", "block-end");
239
+ }
240
+ /**
241
+ * Calcule la position géométrique optimale sans muter le DOM.
242
+ */
243
+ static computePosition(reference, floating, options = {}) {
244
+ const placement = options.placement ?? "bottom-start";
245
+ const strategy = options.strategy ?? "fixed";
246
+ const flip = options.flip ?? true;
247
+ const shift = options.shift ?? true;
248
+ const padding = typeof options.padding === "number" && Number.isFinite(options.padding) ? Math.max(0, options.padding) : 8;
249
+ const arrowPadding = typeof options.arrowPadding === "number" && Number.isFinite(options.arrowPadding) ? Math.max(0, options.arrowPadding) : 6;
250
+ const rawOffset = options.offset ?? 8;
251
+ const mainOffset = typeof rawOffset === "number" ? rawOffset : rawOffset.mainAxis ?? 8;
252
+ const crossOffset = typeof rawOffset === "number" ? 0 : rawOffset.crossAxis ?? 0;
253
+ const refRect = reference.getBoundingClientRect();
254
+ const floatRect = floating.getBoundingClientRect();
255
+ const boundary = getBoundaryRect(floating, options.boundary ?? "clippingAncestors");
256
+ const cb = getContainingBlockOffset(floating, strategy);
257
+ const rtl = isRtlElement(floating) || isRtlElement(reference);
258
+ const placeFor = (s, al) => {
259
+ let vx2 = 0;
260
+ let vy2 = 0;
261
+ if (s === "top" || s === "bottom") {
262
+ vy2 = s === "bottom" ? refRect.bottom + mainOffset : refRect.top - floatRect.height - mainOffset;
263
+ if (!al) {
264
+ vx2 = refRect.left + (refRect.width - floatRect.width) / 2;
265
+ } else {
266
+ const alignLeft = al === "start" !== rtl;
267
+ vx2 = alignLeft ? refRect.left : refRect.right - floatRect.width;
268
+ }
269
+ vx2 += rtl ? -crossOffset : crossOffset;
270
+ } else {
271
+ vx2 = s === "right" ? refRect.right + mainOffset : refRect.left - floatRect.width - mainOffset;
272
+ if (!al) {
273
+ vy2 = refRect.top + (refRect.height - floatRect.height) / 2;
274
+ } else {
275
+ vy2 = al === "start" ? refRect.top : refRect.bottom - floatRect.height;
276
+ }
277
+ vy2 += crossOffset;
278
+ }
279
+ return { vx: vx2, vy: vy2 };
280
+ };
281
+ let side;
282
+ let alignment;
283
+ let vx;
284
+ let vy;
285
+ if (placement === "best") {
286
+ const candidates = resolveCandidatePlacements(options.preferredPlacements);
287
+ let chosen = candidates[0];
288
+ if (floatRect.width > 0 || floatRect.height > 0) {
289
+ const minX = boundary.x + padding - 0.5;
290
+ const maxX = boundary.x + boundary.width - padding + 0.5;
291
+ const minY = boundary.y + padding - 0.5;
292
+ const maxY = boundary.y + boundary.height - padding + 0.5;
293
+ for (const cand of candidates) {
294
+ const [cs, ca] = parsePlacement(cand);
295
+ const pos = placeFor(cs, ca);
296
+ if (pos.vx >= minX && pos.vx + floatRect.width <= maxX && pos.vy >= minY && pos.vy + floatRect.height <= maxY) {
297
+ chosen = cand;
298
+ break;
299
+ }
300
+ }
301
+ }
302
+ [side, alignment] = parsePlacement(chosen);
303
+ ({ vx, vy } = placeFor(side, alignment));
304
+ } else {
305
+ [side, alignment] = parsePlacement(placement);
306
+ ({ vx, vy } = placeFor(side, alignment));
307
+ if (flip) {
308
+ const opp = OPPOSITE_SIDE[side];
309
+ const availCurrent = side === "bottom" ? boundary.y + boundary.height - padding - (refRect.bottom + mainOffset) : side === "top" ? refRect.top - mainOffset - (boundary.y + padding) : side === "right" ? boundary.x + boundary.width - padding - (refRect.right + mainOffset) : refRect.left - mainOffset - (boundary.x + padding);
310
+ const availOpp = opp === "bottom" ? boundary.y + boundary.height - padding - (refRect.bottom + mainOffset) : opp === "top" ? refRect.top - mainOffset - (boundary.y + padding) : opp === "right" ? boundary.x + boundary.width - padding - (refRect.right + mainOffset) : refRect.left - mainOffset - (boundary.x + padding);
311
+ const needed = side === "top" || side === "bottom" ? floatRect.height : floatRect.width;
312
+ if (availCurrent < needed && availOpp > availCurrent) {
313
+ side = opp;
314
+ ({ vx, vy } = placeFor(side, alignment));
315
+ }
316
+ }
317
+ }
318
+ if (shift) {
319
+ if (side === "top" || side === "bottom") {
320
+ const minX = boundary.x + padding;
321
+ const maxX = Math.max(minX, boundary.x + boundary.width - floatRect.width - padding);
322
+ vx = Math.min(Math.max(vx, minX), maxX);
323
+ } else {
324
+ const minY = boundary.y + padding;
325
+ const maxY = Math.max(minY, boundary.y + boundary.height - floatRect.height - padding);
326
+ vy = Math.min(Math.max(vy, minY), maxY);
327
+ }
328
+ }
329
+ const effectivePlacement = alignment ? `${side}-${alignment}` : side;
330
+ const x = Math.round((vx - cb.x) * 100) / 100;
331
+ const y = Math.round((vy - cb.y) * 100) / 100;
332
+ let arrowX = null;
333
+ let arrowY = null;
334
+ const arrowEl = options.arrow instanceof HTMLElement ? options.arrow : null;
335
+ if (arrowEl) {
336
+ const ar = arrowEl.getBoundingClientRect();
337
+ if (side === "top" || side === "bottom") {
338
+ const maxAx = Math.max(arrowPadding, floatRect.width - ar.width - arrowPadding);
339
+ arrowX = Math.round(Math.min(Math.max(refRect.left + refRect.width / 2 - vx - ar.width / 2, arrowPadding), maxAx) * 100) / 100;
340
+ } else {
341
+ const maxAy = Math.max(arrowPadding, floatRect.height - ar.height - arrowPadding);
342
+ arrowY = Math.round(Math.min(Math.max(refRect.top + refRect.height / 2 - vy - ar.height / 2, arrowPadding), maxAy) * 100) / 100;
343
+ }
344
+ }
345
+ const isReferenceClipped = refRect.right <= boundary.x || refRect.left >= boundary.x + boundary.width || refRect.bottom <= boundary.y || refRect.top >= boundary.y + boundary.height;
346
+ return {
347
+ x,
348
+ y,
349
+ viewportX: Math.round(vx * 100) / 100,
350
+ viewportY: Math.round(vy * 100) / 100,
351
+ placement: effectivePlacement,
352
+ side,
353
+ alignment,
354
+ arrowX,
355
+ arrowY,
356
+ isNative: false,
357
+ isReferenceClipped
358
+ };
359
+ }
360
+ update() {
361
+ if (this.isDestroyed) {
362
+ const fallbackPlacement = this.options.placement === "best" ? resolveCandidatePlacements(this.options.preferredPlacements)[0] : this.options.placement;
363
+ const [side, alignment] = parsePlacement(fallbackPlacement);
364
+ return {
365
+ x: 0,
366
+ y: 0,
367
+ viewportX: 0,
368
+ viewportY: 0,
369
+ placement: fallbackPlacement,
370
+ side,
371
+ alignment,
372
+ arrowX: null,
373
+ arrowY: null,
374
+ isNative: false,
375
+ isReferenceClipped: false
376
+ };
377
+ }
378
+ const canUseNative = this.options.useNativeAnchor && this.options.placement !== "best" && !this.options.arrow && this.options.strategy === "fixed" && _Anchor.supportsNativeAnchor();
379
+ let result;
380
+ if (canUseNative) {
381
+ const nativePlacement = this.options.placement;
382
+ const [side, alignment] = parsePlacement(nativePlacement);
383
+ const rtl = isRtlElement(this.floating) || isRtlElement(this.reference);
384
+ const fStyle = this.floating.style;
385
+ const rStyle = this.reference.style;
386
+ rStyle.anchorName = this.anchorName;
387
+ fStyle.position = "fixed";
388
+ fStyle.inset = "auto";
389
+ fStyle.margin = "0";
390
+ fStyle.positionAnchor = this.anchorName;
391
+ fStyle.positionArea = toLogicalPositionArea(side, alignment, rtl);
392
+ if (this.options.flip) {
393
+ fStyle.positionTryFallbacks = "flip-block, flip-inline, flip-block flip-inline";
394
+ }
395
+ this.nativeApplied = true;
396
+ this.floating.setAttribute("data-anchor-placement", nativePlacement);
397
+ const fr = this.floating.getBoundingClientRect();
398
+ result = {
399
+ x: fr.left,
400
+ y: fr.top,
401
+ viewportX: fr.left,
402
+ viewportY: fr.top,
403
+ placement: nativePlacement,
404
+ side,
405
+ alignment,
406
+ arrowX: null,
407
+ arrowY: null,
408
+ isNative: true,
409
+ isReferenceClipped: false
410
+ };
411
+ } else {
412
+ if (this.nativeApplied) {
413
+ this.restoreNativeStyles();
414
+ }
415
+ result = _Anchor.computePosition(this.reference, this.floating, {
416
+ ...this.options,
417
+ arrow: this.options.arrow
418
+ });
419
+ this.floating.style.position = this.options.strategy;
420
+ this.floating.style.left = `${result.x}px`;
421
+ this.floating.style.top = `${result.y}px`;
422
+ this.floating.style.setProperty("--wulf-anchor-x", `${result.x}px`);
423
+ this.floating.style.setProperty("--wulf-anchor-y", `${result.y}px`);
424
+ this.floating.setAttribute("data-anchor-placement", result.placement);
425
+ if (this.options.arrow) {
426
+ if (result.arrowX !== null) {
427
+ this.options.arrow.style.left = `${result.arrowX}px`;
428
+ this.options.arrow.style.top = "";
429
+ this.options.arrow.style.setProperty("--wulf-anchor-arrow-x", `${result.arrowX}px`);
430
+ } else if (result.arrowY !== null) {
431
+ this.options.arrow.style.top = `${result.arrowY}px`;
432
+ this.options.arrow.style.left = "";
433
+ this.options.arrow.style.setProperty("--wulf-anchor-arrow-y", `${result.arrowY}px`);
434
+ }
435
+ }
436
+ }
437
+ if (this.options.onPosition) {
438
+ try {
439
+ this.options.onPosition(result);
440
+ } catch (err) {
441
+ console.error("[Wulf.Anchor] Erreur dans onPosition:", err);
442
+ }
443
+ }
444
+ return result;
445
+ }
446
+ setPlacement(placement) {
447
+ if (!this.isDestroyed) {
448
+ this.options.placement = placement;
449
+ this.update();
450
+ }
451
+ return this;
452
+ }
453
+ start() {
454
+ if (this.isDestroyed || this.isRunning || typeof window === "undefined") return this;
455
+ this.isRunning = true;
456
+ this.abortController = new AbortController();
457
+ const { signal } = this.abortController;
458
+ const schedule = () => {
459
+ if (this.isDestroyed || this.rafId !== null) return;
460
+ this.rafId = window.requestAnimationFrame(() => {
461
+ this.rafId = null;
462
+ if (!this.isDestroyed) this.update();
463
+ });
464
+ };
465
+ if (typeof ResizeObserver !== "undefined") {
466
+ const lastSizes = /* @__PURE__ */ new WeakMap();
467
+ this.resizeObserver = new ResizeObserver((entries) => {
468
+ if (this.isDestroyed) return;
469
+ let changed = false;
470
+ for (const entry of entries) {
471
+ const w = entry.borderBoxSize?.[0]?.inlineSize ?? entry.contentRect.width;
472
+ const h = entry.borderBoxSize?.[0]?.blockSize ?? entry.contentRect.height;
473
+ const prev = lastSizes.get(entry.target);
474
+ if (!prev || Math.abs(w - prev.w) >= 0.5 || Math.abs(h - prev.h) >= 0.5) {
475
+ lastSizes.set(entry.target, { w, h });
476
+ changed = true;
477
+ }
478
+ }
479
+ if (changed) {
480
+ this.update();
481
+ }
482
+ });
483
+ this.resizeObserver.observe(this.reference);
484
+ this.resizeObserver.observe(this.floating);
485
+ }
486
+ const seenScrollParents = /* @__PURE__ */ new Set();
487
+ for (const startNode of [this.reference, this.floating]) {
488
+ let cur = startNode;
489
+ while (cur) {
490
+ if (!seenScrollParents.has(cur)) {
491
+ seenScrollParents.add(cur);
492
+ cur.addEventListener("scroll", schedule, { passive: true, signal });
493
+ }
494
+ cur = getParentCrossingShadow(cur);
495
+ }
496
+ }
497
+ window.addEventListener("scroll", schedule, { passive: true, signal });
498
+ window.addEventListener("resize", schedule, { passive: true, signal });
499
+ if (window.visualViewport) {
500
+ window.visualViewport.addEventListener("scroll", schedule, { passive: true, signal });
501
+ window.visualViewport.addEventListener("resize", schedule, { passive: true, signal });
502
+ }
503
+ this.floating.addEventListener(
504
+ "beforetoggle",
505
+ (ev) => {
506
+ if (ev.newState === "open") {
507
+ schedule();
508
+ queueMicrotask(() => {
509
+ if (!this.isDestroyed && isTopLayerElement(this.floating)) {
510
+ this.update();
511
+ }
512
+ });
513
+ }
514
+ },
515
+ { signal }
516
+ );
517
+ return this;
518
+ }
519
+ stop() {
520
+ this.isRunning = false;
521
+ if (this.rafId !== null && typeof window !== "undefined") {
522
+ window.cancelAnimationFrame(this.rafId);
523
+ this.rafId = null;
524
+ }
525
+ this.abortController?.abort();
526
+ this.abortController = null;
527
+ this.resizeObserver?.disconnect();
528
+ this.resizeObserver = null;
529
+ return this;
530
+ }
531
+ audit() {
532
+ const warnings = [];
533
+ const floatRole = this.floating.getAttribute("role");
534
+ if (floatRole === "tooltip") {
535
+ const hasDesc = this.checkAriaIdReferences(this.reference, "aria-describedby", warnings, true);
536
+ if (!hasDesc) {
537
+ warnings.push('\xC9l\xE9ment role="tooltip" sans liaison aria-describedby valide sur la r\xE9f\xE9rence (WCAG 4.1.2).');
538
+ }
539
+ } else if (this.reference.hasAttribute("aria-describedby")) {
540
+ this.checkAriaIdReferences(this.reference, "aria-describedby", warnings, true);
541
+ }
542
+ if (this.reference.hasAttribute("aria-controls")) {
543
+ this.checkAriaIdReferences(this.reference, "aria-controls", warnings, false);
544
+ }
545
+ const hasPopup = this.reference.getAttribute("aria-haspopup");
546
+ if (hasPopup && ROLE_BY_HASPOPUP[hasPopup] && floatRole !== ROLE_BY_HASPOPUP[hasPopup]) {
547
+ warnings.push(
548
+ `Attribut aria-haspopup="${hasPopup}" sur la r\xE9f\xE9rence sans role="${ROLE_BY_HASPOPUP[hasPopup]}" correspondant sur le panneau.`
549
+ );
550
+ }
551
+ return warnings;
552
+ }
553
+ getAuditPrefix() {
554
+ return "Wulf.Anchor";
555
+ }
556
+ getAuditTargetLabel() {
557
+ return this.floating.id ? `#${this.floating.id}` : `<${this.floating.tagName.toLowerCase()}>`;
558
+ }
559
+ destroy() {
560
+ if (this.isDestroyed) return;
561
+ this.isDestroyed = true;
562
+ this.stop();
563
+ this.restoreNativeStyles();
564
+ const fStyle = this.floating.style;
565
+ fStyle.position = this.savedFloatingStyles.position;
566
+ fStyle.left = this.savedFloatingStyles.left;
567
+ fStyle.top = this.savedFloatingStyles.top;
568
+ this.floating.style.removeProperty("--wulf-anchor-x");
569
+ this.floating.style.removeProperty("--wulf-anchor-y");
570
+ if (this.savedPlacementAttr === null) {
571
+ this.floating.removeAttribute("data-anchor-placement");
572
+ } else {
573
+ this.floating.setAttribute("data-anchor-placement", this.savedPlacementAttr);
574
+ }
575
+ if (this.options.arrow && this.savedArrowStyles) {
576
+ this.options.arrow.style.left = this.savedArrowStyles.left;
577
+ this.options.arrow.style.top = this.savedArrowStyles.top;
578
+ this.options.arrow.style.removeProperty("--wulf-anchor-arrow-x");
579
+ this.options.arrow.style.removeProperty("--wulf-anchor-arrow-y");
580
+ }
581
+ }
582
+ restoreNativeStyles() {
583
+ const rStyle = this.reference.style;
584
+ rStyle.anchorName = this.savedRefAnchorName;
585
+ const fStyle = this.floating.style;
586
+ fStyle.inset = this.savedFloatingStyles.inset;
587
+ fStyle.margin = this.savedFloatingStyles.margin;
588
+ fStyle.positionAnchor = this.savedFloatingStyles.positionAnchor;
589
+ fStyle.positionArea = this.savedFloatingStyles.positionArea;
590
+ fStyle.positionTryFallbacks = this.savedFloatingStyles.positionTryFallbacks;
591
+ this.nativeApplied = false;
592
+ }
593
+ saveInitialState() {
594
+ const rStyle = this.reference.style;
595
+ this.savedRefAnchorName = rStyle.anchorName ?? "";
596
+ const fStyle = this.floating.style;
597
+ this.savedFloatingStyles = {
598
+ position: fStyle.position,
599
+ left: fStyle.left,
600
+ top: fStyle.top,
601
+ inset: fStyle.inset,
602
+ margin: fStyle.margin,
603
+ positionAnchor: fStyle.positionAnchor ?? "",
604
+ positionArea: fStyle.positionArea ?? "",
605
+ positionTryFallbacks: fStyle.positionTryFallbacks ?? ""
606
+ };
607
+ this.savedPlacementAttr = this.floating.getAttribute("data-anchor-placement");
608
+ if (this.options.arrow) {
609
+ this.savedArrowStyles = {
610
+ left: this.options.arrow.style.left,
611
+ top: this.options.arrow.style.top
612
+ };
613
+ }
614
+ }
615
+ };
616
+
617
+ export {
618
+ Anchor,
619
+ anchor_exports
620
+ };
621
+ //# sourceMappingURL=chunk-T2H4EJCW.js.map