@sia.soul/sia-react-ui 0.1.142 → 0.1.143

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 (47) hide show
  1. package/dist/{Button-BiL3Wjsd.d.ts → Button-C8W8ZHWV.d.ts} +1 -1
  2. package/dist/{Button-O_pNB3SQ.d.cts → Button-CxKBjLda.d.cts} +1 -1
  3. package/dist/{Select-DeD4O8FL.d.ts → Select-CTSd8zum.d.ts} +14 -10
  4. package/dist/{Select-Y0e9kaxE.d.cts → Select-bKLket9n.d.cts} +14 -10
  5. package/dist/chart.cjs +1051 -335
  6. package/dist/chart.js +5 -5
  7. package/dist/chunk-4OHS7RXE.js +1004 -0
  8. package/dist/{chunk-WIRIEIRO.js → chunk-4TYHSAR3.js} +5 -5
  9. package/dist/{chunk-TUGCP3GB.js → chunk-566S64IP.js} +5 -5
  10. package/dist/{chunk-CZ2ITBRW.js → chunk-7SEGBB6V.js} +34 -5
  11. package/dist/{chunk-KY6A5IJH.js → chunk-ETQJ2DQ2.js} +1 -1
  12. package/dist/{chunk-WD56MJO2.js → chunk-F52O2MOV.js} +7 -3
  13. package/dist/{chunk-PQBCD54U.js → chunk-JRXYM5YH.js} +167 -64
  14. package/dist/{chunk-SCEHVGKV.js → chunk-LKLPCYEP.js} +2 -2
  15. package/dist/{chunk-3KYG7IU7.js → chunk-MD4CGSOR.js} +105 -61
  16. package/dist/{chunk-PGP4TEPP.js → chunk-ORSQAJ22.js} +154 -494
  17. package/dist/{chunk-SO7IJZIR.js → chunk-PD3K5U5Y.js} +2 -2
  18. package/dist/{chunk-UVHC6OEX.js → chunk-WCYVBO2N.js} +342 -123
  19. package/dist/{core-DYo5C4Si.d.cts → core-COaZfusa.d.cts} +51 -24
  20. package/dist/{core-sWwvVAmP.d.ts → core-CvfsQGuT.d.ts} +51 -24
  21. package/dist/core.cjs +1996 -1250
  22. package/dist/core.css +413 -344
  23. package/dist/core.d.cts +3 -3
  24. package/dist/core.d.ts +3 -3
  25. package/dist/core.js +18 -9
  26. package/dist/game.cjs +1984 -1169
  27. package/dist/game.css +182 -177
  28. package/dist/game.d.cts +1 -1
  29. package/dist/game.d.ts +1 -1
  30. package/dist/game.js +8 -3
  31. package/dist/index.cjs +4654 -3541
  32. package/dist/index.css +413 -344
  33. package/dist/index.d.cts +77 -80
  34. package/dist/index.d.ts +77 -80
  35. package/dist/index.js +1075 -713
  36. package/dist/markdown-editor.cjs +727 -40
  37. package/dist/markdown-editor.js +8 -3
  38. package/dist/rich-text-editor.cjs +1265 -308
  39. package/dist/rich-text-editor.js +12 -7
  40. package/dist/{select-date-range-X6a9Y-Te.d.ts → select-date-range-C8cacfmb.d.ts} +1 -1
  41. package/dist/{select-date-range-DiBQQ0Rn.d.cts → select-date-range-Dad0IdD4.d.cts} +1 -1
  42. package/dist/select-date-range.cjs +1277 -806
  43. package/dist/select-date-range.d.cts +3 -3
  44. package/dist/select-date-range.d.ts +3 -3
  45. package/dist/select-date-range.js +13 -8
  46. package/package.json +9 -2
  47. package/dist/chunk-NZMUW5XI.js +0 -292
@@ -0,0 +1,1004 @@
1
+ // src/components/FloatingScrollbarProvider.tsx
2
+ import { useEffect as useEffect2 } from "react";
3
+
4
+ // src/components/useScrollbarProximity.ts
5
+ import { useEffect } from "react";
6
+ var users = 0;
7
+ var cleanup;
8
+ function useScrollbarProximity() {
9
+ useEffect(acquireScrollbarProximity, []);
10
+ }
11
+ function acquireScrollbarProximity() {
12
+ if (users++ === 0) {
13
+ let frame = 0;
14
+ let x = -Infinity;
15
+ let y = -Infinity;
16
+ const nearby = /* @__PURE__ */ new Set();
17
+ const clear = () => {
18
+ nearby.forEach((track) => track.removeAttribute("data-scrollbar-near"));
19
+ nearby.clear();
20
+ };
21
+ const update = () => {
22
+ frame = 0;
23
+ const next = /* @__PURE__ */ new Set();
24
+ document.querySelectorAll(".sia-scrollbar-track").forEach((track) => {
25
+ const rect = track.getBoundingClientRect();
26
+ const proximity = Number.parseFloat(getComputedStyle(track).getPropertyValue("--sia-scrollbar-proximity")) || 16;
27
+ if (rect.width && rect.height && x >= rect.left - proximity && x <= rect.right + proximity && y >= rect.top - proximity && y <= rect.bottom + proximity) {
28
+ next.add(track);
29
+ if (!nearby.has(track)) track.setAttribute("data-scrollbar-near", "true");
30
+ }
31
+ });
32
+ nearby.forEach((track) => {
33
+ if (!next.has(track)) track.removeAttribute("data-scrollbar-near");
34
+ });
35
+ nearby.clear();
36
+ next.forEach((track) => nearby.add(track));
37
+ };
38
+ const move = (event) => {
39
+ if (event.pointerType === "touch") return;
40
+ x = event.clientX;
41
+ y = event.clientY;
42
+ if (!frame) frame = requestAnimationFrame(update);
43
+ };
44
+ const leave = () => {
45
+ x = y = -Infinity;
46
+ clear();
47
+ };
48
+ document.addEventListener("pointermove", move, { passive: true });
49
+ document.documentElement.addEventListener("pointerleave", leave);
50
+ window.addEventListener("blur", leave);
51
+ cleanup = () => {
52
+ if (frame) cancelAnimationFrame(frame);
53
+ document.removeEventListener("pointermove", move);
54
+ document.documentElement.removeEventListener("pointerleave", leave);
55
+ window.removeEventListener("blur", leave);
56
+ clear();
57
+ };
58
+ }
59
+ return () => {
60
+ if (--users === 0) {
61
+ cleanup?.();
62
+ cleanup = void 0;
63
+ }
64
+ };
65
+ }
66
+
67
+ // src/components/floatingScrollbarOwnership.ts
68
+ var targets = /* @__PURE__ */ new Map();
69
+ function registerFloatingScrollbar(track, target) {
70
+ targets.set(track, { target, dragging: false });
71
+ return () => {
72
+ targets.delete(track);
73
+ };
74
+ }
75
+ function setFloatingScrollbarDragging(track, dragging) {
76
+ const entry = targets.get(track);
77
+ if (entry) entry.dragging = dragging;
78
+ }
79
+ function resolveFloatingScrollbarTarget(target) {
80
+ const track = target instanceof Element ? target.closest(".sia-floating-scrollbar") : null;
81
+ return track && targets.get(track)?.target || target;
82
+ }
83
+ function hasFloatingScrollbarInteraction(container) {
84
+ if (!container) return false;
85
+ return [...targets].some(([track, entry]) => container.contains(entry.target) && (entry.dragging || track.matches(":hover")));
86
+ }
87
+
88
+ // src/components/FloatingScrollbarProvider.tsx
89
+ var scrollableOverflow = /* @__PURE__ */ new Set(["auto", "scroll", "overlay"]);
90
+ var clippingOverflow = /* @__PURE__ */ new Set(["auto", "scroll", "overlay", "hidden", "clip"]);
91
+ function isRootScroller(target) {
92
+ return target === document.scrollingElement || target === document.documentElement;
93
+ }
94
+ function canScroll(target, axis) {
95
+ if (target.matches(".sia-table__viewport, [data-sia-native-scrollbar]")) return false;
96
+ if (isRootScroller(target)) {
97
+ const rootStyle = getComputedStyle(target);
98
+ const bodyStyle = getComputedStyle(document.body);
99
+ const overflow2 = axis === "horizontal" ? [rootStyle.overflowX, bodyStyle.overflowX] : [rootStyle.overflowY, bodyStyle.overflowY];
100
+ if (overflow2.some((value) => value === "hidden" || value === "clip")) return false;
101
+ return axis === "horizontal" ? target.scrollWidth > target.clientWidth + 1 : target.scrollHeight > target.clientHeight + 1;
102
+ }
103
+ const style = getComputedStyle(target);
104
+ const overflow = axis === "horizontal" ? style.overflowX : style.overflowY;
105
+ if (!scrollableOverflow.has(overflow)) return false;
106
+ const hasOverflow = axis === "horizontal" ? target.scrollWidth > target.clientWidth + 1 : target.scrollHeight > target.clientHeight + 1;
107
+ return hasOverflow;
108
+ }
109
+ function visibleRect(target) {
110
+ if (isRootScroller(target)) {
111
+ return { top: 0, right: window.innerWidth, bottom: window.innerHeight, left: 0, width: window.innerWidth, height: window.innerHeight };
112
+ }
113
+ const ownRect = target.getBoundingClientRect();
114
+ let top = Math.max(0, ownRect.top);
115
+ let right = Math.min(window.innerWidth, ownRect.right);
116
+ let bottom = Math.min(window.innerHeight, ownRect.bottom);
117
+ let left = Math.max(0, ownRect.left);
118
+ let parent = target.parentElement;
119
+ while (parent && parent !== document.body && parent !== document.documentElement) {
120
+ const style = getComputedStyle(parent);
121
+ const clipX = clippingOverflow.has(style.overflowX);
122
+ const clipY = clippingOverflow.has(style.overflowY);
123
+ if (clipX || clipY) {
124
+ const rect = parent.getBoundingClientRect();
125
+ if (clipX) {
126
+ left = Math.max(left, rect.left);
127
+ right = Math.min(right, rect.right);
128
+ }
129
+ if (clipY) {
130
+ top = Math.max(top, rect.top);
131
+ bottom = Math.min(bottom, rect.bottom);
132
+ }
133
+ }
134
+ parent = parent.parentElement;
135
+ }
136
+ return {
137
+ top,
138
+ right,
139
+ bottom,
140
+ left,
141
+ width: Math.max(0, right - left),
142
+ height: Math.max(0, bottom - top)
143
+ };
144
+ }
145
+ function createTrack(axis) {
146
+ const track = document.createElement("div");
147
+ const thumb = document.createElement("div");
148
+ track.className = `sia-scrollbar-track sia-floating-scrollbar sia-floating-scrollbar--${axis}`;
149
+ thumb.className = "sia-floating-scrollbar__thumb";
150
+ track.dataset.axis = axis;
151
+ track.setAttribute("aria-hidden", "true");
152
+ track.append(thumb);
153
+ return { track, thumb };
154
+ }
155
+ function FloatingScrollbarProvider({ disabled = false, targetRef }) {
156
+ useEffect2(() => {
157
+ if (targetRef) return disabled ? void 0 : startFloatingScrollbars(targetRef);
158
+ const token = /* @__PURE__ */ Symbol();
159
+ globalProviders.set(token, !disabled);
160
+ syncDefaultScrollbars();
161
+ return () => {
162
+ globalProviders.delete(token);
163
+ syncDefaultScrollbars();
164
+ };
165
+ }, [disabled, targetRef]);
166
+ return null;
167
+ }
168
+ var automatic = false;
169
+ var stopGlobal;
170
+ var globalProviders = /* @__PURE__ */ new Map();
171
+ function syncDefaultScrollbars() {
172
+ if (typeof document === "undefined" || !document.body) return;
173
+ const enabled = (automatic || globalProviders.size > 0) && ![...globalProviders.values()].includes(false);
174
+ if (enabled && !stopGlobal) stopGlobal = startFloatingScrollbars();
175
+ if (!enabled && stopGlobal) {
176
+ stopGlobal();
177
+ stopGlobal = void 0;
178
+ }
179
+ }
180
+ function initializeDefaultScrollbars() {
181
+ if (typeof document === "undefined" || automatic) return;
182
+ automatic = true;
183
+ if (document.body) syncDefaultScrollbars();
184
+ else document.addEventListener("DOMContentLoaded", syncDefaultScrollbars, { once: true });
185
+ }
186
+ function startFloatingScrollbars(targetRef) {
187
+ const releaseProximity = acquireScrollbarProximity();
188
+ const layer = document.createElement("div");
189
+ layer.className = "sia-floating-scrollbar-layer";
190
+ layer.setAttribute("aria-hidden", "true");
191
+ document.body.append(layer);
192
+ const entries = /* @__PURE__ */ new Map();
193
+ let scanFrame = 0;
194
+ let updateFrame = 0;
195
+ const dirtyStyles = /* @__PURE__ */ new Set();
196
+ let fullScan = true;
197
+ const setEntryVisible = (entry, visible) => {
198
+ entry.horizontalTrack.classList.toggle("sia-floating-scrollbar--visible", visible);
199
+ entry.verticalTrack.classList.toggle("sia-floating-scrollbar--visible", visible);
200
+ };
201
+ const showEntry = (entry) => {
202
+ if (entry.hideTimer !== null) window.clearTimeout(entry.hideTimer);
203
+ entry.hideTimer = null;
204
+ setEntryVisible(entry, true);
205
+ };
206
+ const scheduleHide = (entry, delay = 500) => {
207
+ if (entry.hideTimer !== null) window.clearTimeout(entry.hideTimer);
208
+ entry.hideTimer = window.setTimeout(() => {
209
+ entry.hideTimer = null;
210
+ if (!entry.hoveringTarget && !entry.hoveringTrack && !entry.dragging) setEntryVisible(entry, false);
211
+ }, delay);
212
+ };
213
+ const updateEntry = (entry) => {
214
+ const { target, horizontalTrack, horizontalThumb, verticalTrack, verticalThumb } = entry;
215
+ const hasHorizontal = canScroll(target, "horizontal");
216
+ const hasVertical = canScroll(target, "vertical");
217
+ const rect = visibleRect(target);
218
+ const thickness = 10;
219
+ horizontalTrack.hidden = !hasHorizontal || rect.width <= thickness || rect.height <= 0;
220
+ verticalTrack.hidden = !hasVertical || rect.height <= thickness || rect.width <= 0;
221
+ if (!horizontalTrack.hidden) {
222
+ const trackWidth = Math.max(0, rect.width - (hasVertical ? thickness : 0));
223
+ const thumbWidth = Math.max(24, Math.min(trackWidth, trackWidth * target.clientWidth / target.scrollWidth));
224
+ const travel = Math.max(0, trackWidth - thumbWidth);
225
+ const maxScroll = Math.max(1, target.scrollWidth - target.clientWidth);
226
+ horizontalTrack.style.left = `${rect.left}px`;
227
+ horizontalTrack.style.top = `${rect.bottom - thickness}px`;
228
+ horizontalTrack.style.width = `${trackWidth}px`;
229
+ horizontalTrack.style.height = `${thickness}px`;
230
+ horizontalThumb.style.width = `${thumbWidth}px`;
231
+ horizontalThumb.style.transform = `translate3d(${travel * target.scrollLeft / maxScroll}px, 0, 0)`;
232
+ }
233
+ if (!verticalTrack.hidden) {
234
+ const trackHeight = Math.max(0, rect.height - (hasHorizontal ? thickness : 0));
235
+ const thumbHeight = Math.max(24, Math.min(trackHeight, trackHeight * target.clientHeight / target.scrollHeight));
236
+ const travel = Math.max(0, trackHeight - thumbHeight);
237
+ const maxScroll = Math.max(1, target.scrollHeight - target.clientHeight);
238
+ verticalTrack.style.left = `${rect.right - thickness}px`;
239
+ verticalTrack.style.top = `${rect.top}px`;
240
+ verticalTrack.style.width = `${thickness}px`;
241
+ verticalTrack.style.height = `${trackHeight}px`;
242
+ verticalThumb.style.height = `${thumbHeight}px`;
243
+ verticalThumb.style.transform = `translate3d(0, ${travel * target.scrollTop / maxScroll}px, 0)`;
244
+ }
245
+ };
246
+ const scheduleUpdateAll = () => {
247
+ if (updateFrame) return;
248
+ updateFrame = window.requestAnimationFrame(() => {
249
+ updateFrame = 0;
250
+ entries.forEach(updateEntry);
251
+ });
252
+ };
253
+ const bindTrackDrag = (entry, axis, track, thumb) => {
254
+ const target = entry.target;
255
+ const onTrackPointerEnter = () => {
256
+ entry.hoveringTrack = true;
257
+ showEntry(entry);
258
+ };
259
+ const onTrackPointerLeave = () => {
260
+ entry.hoveringTrack = false;
261
+ scheduleHide(entry);
262
+ };
263
+ const onTrackPointerDown = (event) => {
264
+ if (event.target === thumb || event.button !== 0) return;
265
+ event.preventDefault();
266
+ event.stopPropagation();
267
+ const trackRect = track.getBoundingClientRect();
268
+ const thumbRect = thumb.getBoundingClientRect();
269
+ const trackLength = axis === "vertical" ? trackRect.height : trackRect.width;
270
+ const thumbLength = axis === "vertical" ? thumbRect.height : thumbRect.width;
271
+ const pointer = axis === "vertical" ? event.clientY - trackRect.top : event.clientX - trackRect.left;
272
+ const ratio = Math.max(0, Math.min(1, (pointer - thumbLength / 2) / Math.max(1, trackLength - thumbLength)));
273
+ if (axis === "vertical") target.scrollTop = ratio * (target.scrollHeight - target.clientHeight);
274
+ else target.scrollLeft = ratio * (target.scrollWidth - target.clientWidth);
275
+ };
276
+ const onThumbPointerDown = (event) => {
277
+ if (event.button !== 0) return;
278
+ event.preventDefault();
279
+ event.stopPropagation();
280
+ entry.dragging = true;
281
+ setFloatingScrollbarDragging(track, true);
282
+ showEntry(entry);
283
+ thumb.setPointerCapture(event.pointerId);
284
+ const startPointer = axis === "vertical" ? event.clientY : event.clientX;
285
+ const startScroll = axis === "vertical" ? target.scrollTop : target.scrollLeft;
286
+ const trackRect = track.getBoundingClientRect();
287
+ const thumbRect = thumb.getBoundingClientRect();
288
+ const trackLength = axis === "vertical" ? trackRect.height : trackRect.width;
289
+ const thumbLength = axis === "vertical" ? thumbRect.height : thumbRect.width;
290
+ const maxScroll = axis === "vertical" ? target.scrollHeight - target.clientHeight : target.scrollWidth - target.clientWidth;
291
+ const travel = Math.max(1, trackLength - thumbLength);
292
+ const onPointerMove = (moveEvent) => {
293
+ if (moveEvent.pointerId !== event.pointerId) return;
294
+ const pointer = axis === "vertical" ? moveEvent.clientY : moveEvent.clientX;
295
+ const nextScroll = startScroll + (pointer - startPointer) * maxScroll / travel;
296
+ if (axis === "vertical") target.scrollTop = nextScroll;
297
+ else target.scrollLeft = nextScroll;
298
+ };
299
+ const onPointerUp = (upEvent) => {
300
+ if (upEvent.pointerId !== event.pointerId) return;
301
+ entry.dragging = false;
302
+ setFloatingScrollbarDragging(track, false);
303
+ thumb.releasePointerCapture(event.pointerId);
304
+ window.removeEventListener("pointermove", onPointerMove);
305
+ window.removeEventListener("pointerup", onPointerUp);
306
+ window.removeEventListener("pointercancel", onPointerUp);
307
+ scheduleHide(entry);
308
+ };
309
+ window.addEventListener("pointermove", onPointerMove);
310
+ window.addEventListener("pointerup", onPointerUp);
311
+ window.addEventListener("pointercancel", onPointerUp);
312
+ };
313
+ track.addEventListener("pointerenter", onTrackPointerEnter);
314
+ track.addEventListener("pointerleave", onTrackPointerLeave);
315
+ track.addEventListener("pointerdown", onTrackPointerDown);
316
+ thumb.addEventListener("pointerdown", onThumbPointerDown);
317
+ return () => {
318
+ track.removeEventListener("pointerenter", onTrackPointerEnter);
319
+ track.removeEventListener("pointerleave", onTrackPointerLeave);
320
+ track.removeEventListener("pointerdown", onTrackPointerDown);
321
+ thumb.removeEventListener("pointerdown", onThumbPointerDown);
322
+ };
323
+ };
324
+ const resizeObserver = new ResizeObserver((observedEntries) => {
325
+ observedEntries.forEach(({ target }) => {
326
+ const entry = entries.get(target);
327
+ if (entry) updateEntry(entry);
328
+ });
329
+ });
330
+ const addTarget = (target) => {
331
+ if (entries.has(target)) return;
332
+ const horizontal = createTrack("horizontal");
333
+ const vertical = createTrack("vertical");
334
+ const releaseHorizontalOwner = registerFloatingScrollbar(horizontal.track, target);
335
+ const releaseVerticalOwner = registerFloatingScrollbar(vertical.track, target);
336
+ layer.append(horizontal.track, vertical.track);
337
+ const onPointerEnter = () => {
338
+ const entry2 = entries.get(target);
339
+ if (!entry2) return;
340
+ entry2.hoveringTarget = true;
341
+ showEntry(entry2);
342
+ };
343
+ const onPointerLeave = () => {
344
+ const entry2 = entries.get(target);
345
+ if (!entry2) return;
346
+ entry2.hoveringTarget = false;
347
+ scheduleHide(entry2);
348
+ };
349
+ const onScroll = () => {
350
+ const entry2 = entries.get(target);
351
+ if (!entry2) return;
352
+ updateEntry(entry2);
353
+ showEntry(entry2);
354
+ scheduleHide(entry2, 700);
355
+ };
356
+ target.addEventListener("pointerenter", onPointerEnter);
357
+ target.addEventListener("pointerleave", onPointerLeave);
358
+ target.addEventListener("scroll", onScroll, { passive: true });
359
+ const entry = {
360
+ target,
361
+ horizontalTrack: horizontal.track,
362
+ horizontalThumb: horizontal.thumb,
363
+ verticalTrack: vertical.track,
364
+ verticalThumb: vertical.thumb,
365
+ hideTimer: null,
366
+ hoveringTarget: target.matches(":hover"),
367
+ hoveringTrack: false,
368
+ dragging: false,
369
+ cleanup: () => void 0
370
+ };
371
+ const cleanupHorizontal = bindTrackDrag(entry, "horizontal", horizontal.track, horizontal.thumb);
372
+ const cleanupVertical = bindTrackDrag(entry, "vertical", vertical.track, vertical.thumb);
373
+ entry.cleanup = () => {
374
+ if (entry.hideTimer !== null) window.clearTimeout(entry.hideTimer);
375
+ cleanupHorizontal();
376
+ cleanupVertical();
377
+ releaseHorizontalOwner();
378
+ releaseVerticalOwner();
379
+ target.removeEventListener("pointerenter", onPointerEnter);
380
+ target.removeEventListener("pointerleave", onPointerLeave);
381
+ target.removeEventListener("scroll", onScroll);
382
+ resizeObserver.unobserve(target);
383
+ target.removeAttribute("data-sia-floating-scrollbar");
384
+ horizontal.track.remove();
385
+ vertical.track.remove();
386
+ };
387
+ entries.set(target, entry);
388
+ target.setAttribute("data-sia-floating-scrollbar", "");
389
+ resizeObserver.observe(target);
390
+ updateEntry(entry);
391
+ if (entry.hoveringTarget) showEntry(entry);
392
+ };
393
+ const removeTarget = (target) => {
394
+ const entry = entries.get(target);
395
+ if (!entry) return;
396
+ entry.cleanup();
397
+ entries.delete(target);
398
+ };
399
+ const scanTargets = () => {
400
+ scanFrame = 0;
401
+ const managedSelector = ".sia-table__viewport, .sia-scrollbar-track, .sia-floating-scrollbar-layer";
402
+ const discovered = /* @__PURE__ */ new Set();
403
+ if (!targetRef) {
404
+ const roots = fullScan ? [document.body] : [...dirtyStyles].filter((node) => node.isConnected);
405
+ for (const root of roots) {
406
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
407
+ acceptNode: (node) => node.matches(managedSelector) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT
408
+ });
409
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
410
+ if (node instanceof HTMLElement) discovered.add(node);
411
+ }
412
+ for (let node = root; node; node = node.parentElement) discovered.add(node);
413
+ }
414
+ }
415
+ const candidates = (targetRef ? [targetRef.current] : [document.scrollingElement, ...discovered]).filter((target) => target instanceof HTMLElement);
416
+ const nextTargets = /* @__PURE__ */ new Set();
417
+ candidates.forEach((target) => {
418
+ if (canScroll(target, "horizontal") || canScroll(target, "vertical")) {
419
+ nextTargets.add(target);
420
+ }
421
+ });
422
+ nextTargets.forEach((target) => {
423
+ if (entries.has(target) || !target.hasAttribute("data-sia-floating-scrollbar")) addTarget(target);
424
+ });
425
+ entries.forEach((_entry, target) => {
426
+ if (!target.isConnected || (fullScan || candidates.includes(target)) && !nextTargets.has(target)) removeTarget(target);
427
+ else updateEntry(_entry);
428
+ });
429
+ dirtyStyles.clear();
430
+ fullScan = false;
431
+ };
432
+ const scheduleScan = (complete = true) => {
433
+ fullScan ||= complete;
434
+ if (scanFrame) return;
435
+ scanFrame = window.requestAnimationFrame(scanTargets);
436
+ };
437
+ const previousStyle = document.createElement("div").style;
438
+ const positionProperties = /* @__PURE__ */ new Set(["left", "top", "transform"]);
439
+ const mutationObserver = new MutationObserver((mutations) => {
440
+ let relevant = false;
441
+ for (const mutation of mutations) {
442
+ const target = mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
443
+ if (!target || layer.contains(target) || target.closest(".sia-table__viewport, .sia-scrollbar-track, .sia-floating-scrollbar-layer")) continue;
444
+ if (mutation.type === "childList") {
445
+ const changed = [...mutation.addedNodes, ...mutation.removedNodes];
446
+ if (changed.length && changed.every((node) => node instanceof Element && node.matches(".sia-floating-scrollbar-layer, .sia-scrollbar-track"))) continue;
447
+ if (target === document.body && changed.length && changed.every((node) => node instanceof HTMLElement && node.matches(".sia-popup-portal"))) {
448
+ changed.forEach((node) => {
449
+ if (node instanceof HTMLElement && node.isConnected) dirtyStyles.add(node);
450
+ });
451
+ relevant = true;
452
+ continue;
453
+ }
454
+ }
455
+ const popup = target.closest(".sia-popup-portal");
456
+ if (popup) {
457
+ dirtyStyles.add(popup);
458
+ relevant = true;
459
+ continue;
460
+ }
461
+ if (mutation.type === "attributes" && mutation.attributeName === "class" && target instanceof HTMLElement && target.matches(".sia-select")) {
462
+ const oldClasses = new Set((mutation.oldValue ?? "").split(/\s+/).filter(Boolean));
463
+ const newClasses = new Set(target.classList);
464
+ const changed = [.../* @__PURE__ */ new Set([...oldClasses, ...newClasses])].filter((name) => oldClasses.has(name) !== newClasses.has(name));
465
+ if (changed.every((name) => name === "is-open")) {
466
+ dirtyStyles.add(target);
467
+ relevant = true;
468
+ continue;
469
+ }
470
+ }
471
+ relevant = true;
472
+ let positionOnly = false;
473
+ if (mutation.type === "attributes" && mutation.attributeName === "style" && target instanceof HTMLElement) {
474
+ previousStyle.cssText = mutation.oldValue ?? "";
475
+ const keys = /* @__PURE__ */ new Set([...Array.from(previousStyle), ...Array.from(target.style)]);
476
+ const changed = [...keys].filter((key) => previousStyle.getPropertyValue(key) !== target.style.getPropertyValue(key) || previousStyle.getPropertyPriority(key) !== target.style.getPropertyPriority(key));
477
+ if (!changed.length) continue;
478
+ const fixedSize = target.style.width.endsWith("px") && target.style.height.endsWith("px");
479
+ positionOnly = fixedSize && changed.every((key) => positionProperties.has(key)) && ["absolute", "fixed"].includes(getComputedStyle(target).position);
480
+ }
481
+ if (positionOnly && target instanceof HTMLElement) dirtyStyles.add(target);
482
+ else fullScan = true;
483
+ }
484
+ if (relevant) scheduleScan(false);
485
+ });
486
+ mutationObserver.observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeOldValue: true, attributeFilter: ["class", "style", "hidden", "data-sia-native-scrollbar", "data-sia-floating-scrollbar"] });
487
+ const onResize = () => scheduleScan();
488
+ window.addEventListener("resize", onResize);
489
+ window.addEventListener("scroll", scheduleUpdateAll, true);
490
+ scheduleScan();
491
+ return () => {
492
+ releaseProximity();
493
+ mutationObserver.disconnect();
494
+ resizeObserver.disconnect();
495
+ window.removeEventListener("resize", onResize);
496
+ window.removeEventListener("scroll", scheduleUpdateAll, true);
497
+ if (scanFrame) window.cancelAnimationFrame(scanFrame);
498
+ if (updateFrame) window.cancelAnimationFrame(updateFrame);
499
+ entries.forEach((entry) => entry.cleanup());
500
+ entries.clear();
501
+ layer.remove();
502
+ };
503
+ }
504
+
505
+ // src/components/overlayMotion.ts
506
+ import { useEffect as useEffect3, useLayoutEffect, useRef, useState } from "react";
507
+
508
+ // src/components/popupFluidMotion.ts
509
+ var popupEnterDuration = 260;
510
+ var popupExitDuration = 140;
511
+ var popupInitialScale = 0.88;
512
+ var popupTravelOffset = 6;
513
+ function popupFluidFrames(placement, open = true) {
514
+ const side = placement.split("-")[0];
515
+ const axis = side === "left" || side === "right" ? "X" : "Y";
516
+ const sign = side === "left" || side === "top" ? 1 : -1;
517
+ const hidden = { opacity: 0, transform: `translate${axis}(${sign * popupTravelOffset}px) scale(${popupInitialScale})` };
518
+ const visible = { opacity: 1, transform: "none" };
519
+ return open ? [
520
+ { ...hidden, offset: 0 },
521
+ { opacity: 1, transform: "scale(1.11, 1.085)", offset: 0.68 },
522
+ { opacity: 1, transform: "scale(.945, .965)", offset: 0.86 },
523
+ { ...visible, offset: 1 }
524
+ ] : [{ ...visible, offset: 0 }, { ...hidden, offset: 1 }];
525
+ }
526
+
527
+ // src/components/overlayMotion.ts
528
+ function motionFrames(kind, placement) {
529
+ if (kind === "fade") return [{ opacity: 0 }, { opacity: 1 }];
530
+ if (kind === "toast") return [
531
+ { opacity: 0, transform: "translateY(-6px)", offset: 0 },
532
+ { opacity: 1, transform: "translateY(3px)", offset: 0.68 },
533
+ { opacity: 1, transform: "translateY(-1px)", offset: 0.86 },
534
+ { opacity: 1, transform: "none", offset: 1 }
535
+ ];
536
+ if (kind === "drawer") {
537
+ const axis = placement === "left" || placement === "right" ? "X" : "Y";
538
+ const sign = placement === "left" || placement === "top" ? -1 : 1;
539
+ const outside = `translate${axis}(${sign * 100}%)`;
540
+ return [
541
+ { transform: outside, offset: 0 },
542
+ { transform: `translate${axis}(0) scale${axis}(1.065)`, offset: 0.68 },
543
+ { transform: `translate${axis}(0) scale${axis}(.975)`, offset: 0.86 },
544
+ { transform: "none", offset: 1 }
545
+ ];
546
+ }
547
+ const modal = kind === "modal";
548
+ return [
549
+ { opacity: 0, transform: `translateY(${modal ? 18 : -6}px) scale(${modal ? 0.9 : 0.88})`, offset: 0 },
550
+ { opacity: 1, transform: modal ? "scale(1.075, 1.05)" : "scale(1.11, 1.085)", offset: 0.68 },
551
+ { opacity: 1, transform: modal ? "scale(.965, .98)" : "scale(.945, .965)", offset: 0.86 },
552
+ { opacity: 1, transform: "none", offset: 1 }
553
+ ];
554
+ }
555
+ function useOverlayMotion(open, ref, kind, placement = "bottom", ready = true, onFinish, enabled = true) {
556
+ const [phase, setPhase] = useState(open ? "entering" : "closed");
557
+ const present = open || phase !== "closed";
558
+ const [entered, setEntered] = useState(false);
559
+ const position = useRef();
560
+ const snapshot = useRef();
561
+ const notify = useRef();
562
+ const callback = useRef(onFinish);
563
+ callback.current = onFinish;
564
+ useLayoutEffect(() => {
565
+ const node = ref.current;
566
+ if (!present || !ready || !node) return;
567
+ let cancelled = false;
568
+ let animation;
569
+ let surfaceAnimation;
570
+ let maskAnimation;
571
+ const panel = kind === "drawer" || kind === "modal";
572
+ const fluid = kind === "popup";
573
+ const mask = kind === "modal" ? node.closest(".sia-modal-root") : kind === "drawer" ? node.closest(".sia-drawer-root")?.querySelector(".sia-drawer__mask") : null;
574
+ setPhase(open ? "entering" : "closing");
575
+ const finish = () => {
576
+ if (cancelled) return;
577
+ position.current = void 0;
578
+ snapshot.current = void 0;
579
+ if (open) {
580
+ animation?.cancel();
581
+ surfaceAnimation?.cancel();
582
+ maskAnimation?.cancel();
583
+ }
584
+ notify.current = open;
585
+ setEntered(open);
586
+ setPhase(open ? "open" : "closed");
587
+ node.dispatchEvent(new Event("sia-overlay-motion-end", { bubbles: true }));
588
+ };
589
+ const reduced = node.ownerDocument.defaultView?.matchMedia("(prefers-reduced-motion: reduce)");
590
+ const completeImmediately = () => {
591
+ animation?.cancel();
592
+ surfaceAnimation?.cancel();
593
+ maskAnimation?.cancel();
594
+ finish();
595
+ };
596
+ if (!enabled || reduced?.matches || !node.animate) {
597
+ finish();
598
+ } else {
599
+ let frames = fluid ? popupFluidFrames(placement, open) : motionFrames(kind, placement);
600
+ const start = snapshot.current;
601
+ const enterDuration = fluid ? popupEnterDuration : kind === "drawer" ? 320 : kind === "modal" ? 240 : kind === "fade" ? 180 : 280;
602
+ let duration = fluid && !open ? popupExitDuration : panel && !open ? kind === "drawer" ? 180 : 160 : enterDuration;
603
+ if (fluid && start) {
604
+ const current = new DOMMatrix(start.transform);
605
+ const destination = new DOMMatrix(String(frames[frames.length - 1].transform));
606
+ const remaining = Math.min(1, Math.max(0.15, Math.max(Math.abs(destination.a - current.a), Math.abs(destination.d - current.d)) / (1 - popupInitialScale), Math.hypot(current.e - destination.e, current.f - destination.f) / popupTravelOffset));
607
+ frames = [{ offset: 0, transform: start.transform, opacity: start.opacity }, { ...frames[frames.length - 1], offset: 1 }];
608
+ duration *= remaining;
609
+ }
610
+ if (panel) {
611
+ if (!open) frames = [{ transform: start?.transform ?? "none", opacity: start?.opacity ?? 1 }, { ...frames[0], offset: 1 }];
612
+ else if (start) frames = [{ ...frames[0], transform: start.transform, opacity: start.opacity }, ...frames.slice(1)];
613
+ }
614
+ const options = {
615
+ duration,
616
+ easing: fluid ? open ? "cubic-bezier(.2,.7,.2,1)" : "cubic-bezier(.4,0,1,1)" : panel && !open ? "cubic-bezier(.4,0,1,1)" : kind === "fade" ? "ease-in-out" : "cubic-bezier(.2,.7,.2,1)",
617
+ direction: panel || fluid || open ? "normal" : "reverse",
618
+ fill: "both"
619
+ };
620
+ animation = node.animate(frames, options);
621
+ if (!panel && !fluid && position.current !== void 0) animation.currentTime = open ? position.current : duration - position.current;
622
+ position.current = void 0;
623
+ snapshot.current = void 0;
624
+ if (mask) {
625
+ maskAnimation = mask.animate([{ opacity: start?.maskOpacity ?? (open ? 0 : 1) }, { opacity: open ? 1 : 0 }], { ...options, pseudoElement: kind === "modal" ? "::before" : void 0 });
626
+ maskAnimation.currentTime = animation.currentTime;
627
+ if (animation.startTime !== null) maskAnimation.startTime = animation.startTime;
628
+ }
629
+ if (kind === "toast") {
630
+ const surfaceFrames = motionFrames("message", placement).map((frame) => ({
631
+ offset: frame.offset,
632
+ transform: String(frame.transform).replace(/translateY\([^)]*\)\s*/g, "")
633
+ }));
634
+ surfaceAnimation = node.animate(surfaceFrames, { ...options, pseudoElement: "::before" });
635
+ surfaceAnimation.currentTime = animation.currentTime;
636
+ if (animation.startTime !== null) surfaceAnimation.startTime = animation.startTime;
637
+ }
638
+ animation.finished.then(finish, () => {
639
+ });
640
+ reduced?.addEventListener("change", completeImmediately, { once: true });
641
+ }
642
+ return () => {
643
+ cancelled = true;
644
+ reduced?.removeEventListener("change", completeImmediately);
645
+ if (animation && (animation.playState === "running" || animation.playState === "paused")) {
646
+ if (panel || fluid) {
647
+ const css = node.ownerDocument.defaultView.getComputedStyle(node);
648
+ snapshot.current = {
649
+ transform: css.transform,
650
+ opacity: css.opacity,
651
+ maskOpacity: mask ? node.ownerDocument.defaultView.getComputedStyle(mask, kind === "modal" ? "::before" : null).opacity : void 0
652
+ };
653
+ } else {
654
+ const time = Number(animation.currentTime ?? 0);
655
+ const duration = Number(animation.effect?.getTiming().duration ?? 0);
656
+ position.current = open ? time : duration - time;
657
+ }
658
+ }
659
+ animation?.cancel();
660
+ surfaceAnimation?.cancel();
661
+ maskAnimation?.cancel();
662
+ };
663
+ }, [open, present, ready, kind, placement, enabled, ref]);
664
+ useEffect3(() => {
665
+ if (notify.current === void 0) return;
666
+ const completedOpen = notify.current;
667
+ notify.current = void 0;
668
+ if (completedOpen === open) callback.current?.(completedOpen);
669
+ }, [phase, open]);
670
+ return { present, entered, settled: phase === "open", closing: !open, phase };
671
+ }
672
+
673
+ // src/components/titleTooltip.tsx
674
+ import { createRoot } from "react-dom/client";
675
+ import { jsx } from "react/jsx-runtime";
676
+ var installedKey = /* @__PURE__ */ Symbol.for("sia.ui.titleTooltip.installed");
677
+ function withTitleTooltip(props) {
678
+ if (!props || typeof props !== "object" || !("title" in props)) return props;
679
+ const { title, ...rest } = props;
680
+ if (typeof document !== "undefined") installTitleTooltips(document);
681
+ return { ...rest, "data-sia-title": title == null ? void 0 : String(title) };
682
+ }
683
+ function installTitleTooltips(doc) {
684
+ const owner = doc;
685
+ if (owner[installedKey]) return;
686
+ owner[installedKey] = true;
687
+ let hovered = null;
688
+ let focused = null;
689
+ let keyboardFocus = true;
690
+ let active = null;
691
+ let pending = null;
692
+ let timer;
693
+ let root;
694
+ let observer;
695
+ let tooltipId = "";
696
+ const canShow = (element) => {
697
+ if (!element.hasAttribute("data-sia-title-overflow-only")) return true;
698
+ return [element, ...element.querySelectorAll("*")].some((node) => {
699
+ if (node.clientWidth <= 0 || node.scrollWidth <= node.clientWidth) return false;
700
+ const style = doc.defaultView?.getComputedStyle(node);
701
+ return style?.textOverflow === "ellipsis" && (style.overflowX === "hidden" || style.overflowX === "clip");
702
+ });
703
+ };
704
+ const candidate = (target) => {
705
+ if (!(target instanceof Element)) return null;
706
+ const element = target.closest("[data-sia-title]");
707
+ return element?.getAttribute("data-sia-title") && !element.closest(".sia-floating") && canShow(element) ? element : null;
708
+ };
709
+ const hasExplicitTooltip = (target) => target instanceof Element && Boolean(target.closest(".sia-floating"));
710
+ const hide = () => {
711
+ clearTimeout(timer);
712
+ pending = null;
713
+ observer?.disconnect();
714
+ observer = void 0;
715
+ if (active) {
716
+ const ids = (active.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((id) => id && id !== tooltipId);
717
+ if (ids.length) active.setAttribute("aria-describedby", ids.join(" "));
718
+ else active.removeAttribute("aria-describedby");
719
+ }
720
+ const closing = active;
721
+ active = null;
722
+ if (closing && root) root.render(/* @__PURE__ */ jsx(
723
+ PopupPortal,
724
+ {
725
+ anchorRef: { current: closing },
726
+ open: false,
727
+ placement: "top-start",
728
+ id: tooltipId,
729
+ role: "tooltip",
730
+ className: "sia-title-tooltip",
731
+ afterOpenChange: (opened) => {
732
+ if (!opened && !active) root?.render(null);
733
+ },
734
+ children: closing.getAttribute("data-sia-title")
735
+ }
736
+ ));
737
+ };
738
+ const render = () => {
739
+ const text = active?.getAttribute("data-sia-title");
740
+ if (!active?.isConnected || !text || !canShow(active)) {
741
+ hide();
742
+ return;
743
+ }
744
+ if (!root) {
745
+ const host = doc.createElement("div");
746
+ host.setAttribute("data-sia-title-tooltip-host", "");
747
+ doc.body.append(host);
748
+ root = createRoot(host);
749
+ tooltipId = `sia-title-tooltip-${Math.random().toString(36).slice(2)}`;
750
+ }
751
+ const ids = new Set((active.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean));
752
+ ids.add(tooltipId);
753
+ active.setAttribute("aria-describedby", [...ids].join(" "));
754
+ root.render(/* @__PURE__ */ jsx(
755
+ PopupPortal,
756
+ {
757
+ anchorRef: { current: active },
758
+ placement: "top-start",
759
+ id: tooltipId,
760
+ role: "tooltip",
761
+ className: "sia-title-tooltip",
762
+ children: text
763
+ }
764
+ ));
765
+ };
766
+ const show = (element) => {
767
+ if (!element && !active && !pending) return;
768
+ if (element && (element === active || element === pending)) return;
769
+ hide();
770
+ if (!element) return;
771
+ pending = element;
772
+ timer = setTimeout(() => {
773
+ pending = null;
774
+ if (!element.isConnected) return;
775
+ active = element;
776
+ render();
777
+ if (!active) return;
778
+ observer = new MutationObserver(() => {
779
+ if (!active?.isConnected) hide();
780
+ else if (active.getAttribute("data-sia-title") !== doc.getElementById(tooltipId)?.textContent) render();
781
+ });
782
+ observer.observe(doc.body, { childList: true, subtree: true, attributes: true, attributeFilter: ["data-sia-title"] });
783
+ }, 600);
784
+ };
785
+ doc.addEventListener("pointerover", (event) => {
786
+ if (event.pointerType === "touch") return;
787
+ hovered = candidate(event.target);
788
+ if (hasExplicitTooltip(event.target)) hide();
789
+ else show(hovered ?? focused);
790
+ }, true);
791
+ doc.addEventListener("pointermove", (event) => {
792
+ if (event.pointerType === "touch" || event.buttons) return;
793
+ hovered = candidate(event.target);
794
+ if (!hasExplicitTooltip(event.target)) show(hovered ?? focused);
795
+ }, true);
796
+ doc.addEventListener("pointerout", (event) => {
797
+ if (event.pointerType === "touch") return;
798
+ hovered = candidate(event.relatedTarget);
799
+ if (hasExplicitTooltip(event.relatedTarget)) hide();
800
+ else show(hovered ?? focused);
801
+ }, true);
802
+ doc.addEventListener("focusin", (event) => {
803
+ focused = keyboardFocus ? candidate(event.target) : null;
804
+ if (hasExplicitTooltip(event.target)) hide();
805
+ else if (keyboardFocus) show(focused ?? hovered);
806
+ }, true);
807
+ doc.addEventListener("focusout", (event) => {
808
+ focused = keyboardFocus ? candidate(event.relatedTarget) : null;
809
+ show(hovered ?? focused);
810
+ }, true);
811
+ doc.addEventListener("pointerdown", () => {
812
+ keyboardFocus = false;
813
+ focused = null;
814
+ hide();
815
+ }, true);
816
+ doc.addEventListener("keydown", (event) => {
817
+ if (event.key === "Escape") hide();
818
+ else if (event.key === "Tab") keyboardFocus = true;
819
+ }, true);
820
+ doc.addEventListener("scroll", hide, true);
821
+ doc.addEventListener("visibilitychange", () => {
822
+ if (doc.hidden) {
823
+ hovered = focused = null;
824
+ hide();
825
+ }
826
+ });
827
+ doc.defaultView?.addEventListener("blur", () => {
828
+ hovered = focused = null;
829
+ hide();
830
+ });
831
+ }
832
+
833
+ // src/components/PopupPortal.tsx
834
+ import { forwardRef, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
835
+ import { createPortal } from "react-dom";
836
+ import { jsx as jsx2 } from "react/jsx-runtime";
837
+ function setForwardedRef(ref, value) {
838
+ if (typeof ref === "function") ref(value);
839
+ else if (ref) ref.current = value;
840
+ }
841
+ function clamp(value, min, max) {
842
+ return Math.min(Math.max(value, min), Math.max(min, max));
843
+ }
844
+ var PopupPortal = forwardRef(function PopupPortal2({
845
+ anchorRef,
846
+ open = true,
847
+ placement = "bottom-start",
848
+ offset = 6,
849
+ viewportPadding = 8,
850
+ afterOpenChange,
851
+ className = "",
852
+ style,
853
+ children,
854
+ ...props
855
+ }, forwardedRef) {
856
+ const popupRef = useRef2(null);
857
+ const [position, setPosition] = useState2();
858
+ const motion = useOverlayMotion(open, popupRef, "popup", position?.placement ?? placement, !!position, afterOpenChange);
859
+ useLayoutEffect2(() => {
860
+ if (!motion.present || typeof document === "undefined") {
861
+ setPosition(void 0);
862
+ return;
863
+ }
864
+ const update = () => {
865
+ const anchor = anchorRef.current;
866
+ const popup = popupRef.current;
867
+ if (!anchor || !popup) return;
868
+ const anchorRect = anchor.getBoundingClientRect();
869
+ const popupRect = { width: popup.offsetWidth, height: popup.offsetHeight };
870
+ const viewportWidth = document.documentElement.clientWidth;
871
+ const viewportHeight = document.documentElement.clientHeight;
872
+ let resolvedPlacement = placement;
873
+ const availableBelow = Math.max(0, viewportHeight - viewportPadding - anchorRect.bottom - offset);
874
+ const availableAbove = Math.max(0, anchorRect.top - offset - viewportPadding);
875
+ const availableRight = Math.max(0, viewportWidth - viewportPadding - anchorRect.right - offset);
876
+ const availableLeft = Math.max(0, anchorRect.left - offset - viewportPadding);
877
+ const horizontalSide = placement.startsWith("right") || placement.startsWith("left");
878
+ if (horizontalSide) {
879
+ const prefersRight = placement.startsWith("right");
880
+ const fitsRight = popupRect.width <= availableRight;
881
+ const fitsLeft = popupRect.width <= availableLeft;
882
+ if (prefersRight && !fitsRight && (fitsLeft || availableLeft > availableRight)) {
883
+ resolvedPlacement = placement.replace("right", "left");
884
+ } else if (!prefersRight && !fitsLeft && (fitsRight || availableRight > availableLeft)) {
885
+ resolvedPlacement = placement.replace("left", "right");
886
+ }
887
+ } else {
888
+ const prefersBottom = placement.startsWith("bottom");
889
+ const fitsBelow = popupRect.height <= availableBelow;
890
+ const fitsAbove = popupRect.height <= availableAbove;
891
+ if (prefersBottom && !fitsBelow && (fitsAbove || availableAbove > availableBelow)) {
892
+ resolvedPlacement = placement.replace("bottom", "top");
893
+ } else if (!prefersBottom && !fitsAbove && (fitsBelow || availableBelow > availableAbove)) {
894
+ resolvedPlacement = placement.replace("top", "bottom");
895
+ }
896
+ }
897
+ const resolvedHorizontalSide = resolvedPlacement.startsWith("right") || resolvedPlacement.startsWith("left");
898
+ const top = resolvedHorizontalSide ? resolvedPlacement.endsWith("end") ? anchorRect.bottom - popupRect.height : anchorRect.top : resolvedPlacement.startsWith("bottom") ? anchorRect.bottom + offset : anchorRect.top - popupRect.height - offset;
899
+ const availableHeight = resolvedHorizontalSide ? Math.max(0, viewportHeight - viewportPadding * 2) : resolvedPlacement.startsWith("bottom") ? availableBelow : availableAbove;
900
+ const alignedLeft = resolvedHorizontalSide ? resolvedPlacement.startsWith("right") ? anchorRect.right + offset : anchorRect.left - popupRect.width - offset : resolvedPlacement.endsWith("end") ? anchorRect.right - popupRect.width : anchorRect.left;
901
+ const next = {
902
+ top: clamp(top, viewportPadding, viewportHeight - popupRect.height - viewportPadding),
903
+ left: clamp(alignedLeft, viewportPadding, viewportWidth - popupRect.width - viewportPadding),
904
+ anchorWidth: anchorRect.width,
905
+ availableHeight,
906
+ placement: resolvedPlacement
907
+ };
908
+ setPosition((current) => current && current.top === next.top && current.left === next.left && current.anchorWidth === next.anchorWidth && current.availableHeight === next.availableHeight && current.placement === next.placement ? current : next);
909
+ };
910
+ update();
911
+ let frame = 0;
912
+ const schedule = () => {
913
+ if (!frame) frame = requestAnimationFrame(() => {
914
+ frame = 0;
915
+ update();
916
+ });
917
+ };
918
+ window.addEventListener("resize", schedule);
919
+ window.addEventListener("scroll", schedule, true);
920
+ window.addEventListener("sia-overlay-motion-end", schedule);
921
+ const observer = new ResizeObserver(schedule);
922
+ if (anchorRef.current) observer.observe(anchorRef.current);
923
+ if (popupRef.current) observer.observe(popupRef.current);
924
+ return () => {
925
+ window.removeEventListener("resize", schedule);
926
+ window.removeEventListener("scroll", schedule, true);
927
+ window.removeEventListener("sia-overlay-motion-end", schedule);
928
+ cancelAnimationFrame(frame);
929
+ observer.disconnect();
930
+ };
931
+ }, [anchorRef, offset, motion.present, placement, viewportPadding]);
932
+ if (!motion.present || typeof document === "undefined") return null;
933
+ return createPortal(
934
+ /* @__PURE__ */ jsx2(
935
+ "div",
936
+ {
937
+ ref: (node) => {
938
+ popupRef.current = node;
939
+ setForwardedRef(forwardedRef, node);
940
+ },
941
+ className: `sia-popup-portal ${className}`.trim(),
942
+ "data-sia-popup-layer": "",
943
+ "data-placement": position?.placement ?? placement,
944
+ "data-state": motion.closing ? "closing" : "open",
945
+ "aria-hidden": motion.closing || void 0,
946
+ style: {
947
+ ...style,
948
+ "--sia-popup-anchor-width": `${position?.anchorWidth ?? anchorRef.current?.getBoundingClientRect().width ?? 0}px`,
949
+ "--sia-popup-available-height": position ? `${position.availableHeight}px` : void 0,
950
+ top: position?.top ?? 0,
951
+ left: position?.left ?? 0,
952
+ visibility: position ? "visible" : "hidden",
953
+ animation: "none",
954
+ pointerEvents: motion.closing ? "none" : style?.pointerEvents,
955
+ // 以靠近触发器的边缘中心为缩放原点,业务显式原点优先。
956
+ transformOrigin: style?.transformOrigin ?? ((position?.placement ?? placement).startsWith("left") ? "right center" : (position?.placement ?? placement).startsWith("right") ? "left center" : (position?.placement ?? placement).startsWith("top") ? "center bottom" : "center top")
957
+ },
958
+ ...withTitleTooltip(props),
959
+ children
960
+ }
961
+ ),
962
+ document.body
963
+ );
964
+ });
965
+
966
+ // src/components/shared.ts
967
+ import { createContext, useCallback, useContext, useState as useState3 } from "react";
968
+ var ControlSizeContext = createContext("medium");
969
+ function useControlSize(size) {
970
+ const inherited = useContext(ControlSizeContext);
971
+ return size ?? inherited;
972
+ }
973
+ var PlaceholderModeContext = createContext("default");
974
+ function usePlaceholderMode(mode) {
975
+ const inherited = useContext(PlaceholderModeContext);
976
+ return mode ?? inherited;
977
+ }
978
+ function useControllableState({ value, defaultValue, onChange }) {
979
+ const [internalValue, setInternalValue] = useState3(defaultValue);
980
+ const controlled = value !== void 0;
981
+ const currentValue = controlled ? value : internalValue;
982
+ const setValue = useCallback((nextValue) => {
983
+ if (Object.is(currentValue, nextValue)) return;
984
+ if (!controlled) setInternalValue(nextValue);
985
+ onChange?.(nextValue);
986
+ }, [controlled, currentValue, onChange]);
987
+ return [currentValue, setValue];
988
+ }
989
+
990
+ export {
991
+ useScrollbarProximity,
992
+ resolveFloatingScrollbarTarget,
993
+ hasFloatingScrollbarInteraction,
994
+ FloatingScrollbarProvider,
995
+ initializeDefaultScrollbars,
996
+ useOverlayMotion,
997
+ PopupPortal,
998
+ withTitleTooltip,
999
+ ControlSizeContext,
1000
+ useControlSize,
1001
+ PlaceholderModeContext,
1002
+ usePlaceholderMode,
1003
+ useControllableState
1004
+ };