@vritti/quantum-ui 0.6.0 → 0.6.2

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 (147) hide show
  1. package/dist/ActiveShapeUtils.js +1 -1
  2. package/dist/Alert.js +1 -1
  3. package/dist/Avatar.js +5 -5
  4. package/dist/Badge2.js +2 -2
  5. package/dist/BarChart.js +1 -1
  6. package/dist/Breadcrumb.js +1 -1
  7. package/dist/Button2.js +2 -2
  8. package/dist/CartesianChart.js +1 -1
  9. package/dist/Chart.js +1 -1
  10. package/dist/Checkbox2.js +5 -5
  11. package/dist/DateTimePicker.js +1 -1
  12. package/dist/Dialog.js +1 -1
  13. package/dist/IconSelect.js +596 -609
  14. package/dist/IconSelect.js.map +1 -1
  15. package/dist/Label.js +1 -1
  16. package/dist/LineChart.js +309 -86
  17. package/dist/LineChart.js.map +1 -1
  18. package/dist/Progress.js +2 -2
  19. package/dist/RadarChart.js +1 -1
  20. package/dist/RadioGroup.js +7 -7
  21. package/dist/Select.js +1 -1
  22. package/dist/Sidebar.js +3 -3
  23. package/dist/Sonner.js +1 -1
  24. package/dist/StatusSwitch.js +5 -0
  25. package/dist/StatusSwitch.js.map +1 -1
  26. package/dist/Switch.js +5 -5
  27. package/dist/TabsSkeleton.js +2 -2
  28. package/dist/Toggle.js +2 -2
  29. package/dist/assets/quantum-ui.css +61 -4
  30. package/dist/chart-line.js +18 -0
  31. package/dist/chart-line.js.map +1 -0
  32. package/dist/components/FormattedDate.js +1 -1
  33. package/dist/components/RichTextEditor.js +1 -1
  34. package/dist/components/TreeView.js +5 -5
  35. package/dist/dropdown-menu.js +9 -9
  36. package/dist/field.js +7 -2
  37. package/dist/field.js.map +1 -1
  38. package/dist/hooks/index.js +2 -2
  39. package/dist/image-component.js +1 -1
  40. package/dist/index.js +4 -4
  41. package/dist/index10.js +1499 -102
  42. package/dist/index10.js.map +1 -1
  43. package/dist/index11.js +37 -1499
  44. package/dist/index11.js.map +1 -1
  45. package/dist/index12.js +503 -28
  46. package/dist/index12.js.map +1 -1
  47. package/dist/index13.js +229 -454
  48. package/dist/index13.js.map +1 -1
  49. package/dist/index14.js +22 -281
  50. package/dist/index14.js.map +1 -1
  51. package/dist/index15.js +1139 -20
  52. package/dist/index15.js.map +1 -1
  53. package/dist/index16.js +14 -1139
  54. package/dist/index16.js.map +1 -1
  55. package/dist/index17.js +173 -19
  56. package/dist/index17.js.map +1 -1
  57. package/dist/index18.js +173 -168
  58. package/dist/index18.js.map +1 -1
  59. package/dist/index19.js +201 -171
  60. package/dist/index19.js.map +1 -1
  61. package/dist/index20.js +190 -186
  62. package/dist/index20.js.map +1 -1
  63. package/dist/index21.js +204 -202
  64. package/dist/index21.js.map +1 -1
  65. package/dist/index22.js +68 -209
  66. package/dist/index22.js.map +1 -1
  67. package/dist/index23.js +1128 -70
  68. package/dist/index23.js.map +1 -1
  69. package/dist/index24.js +4 -1133
  70. package/dist/index24.js.map +1 -1
  71. package/dist/index25.js +232 -4
  72. package/dist/index25.js.map +1 -1
  73. package/dist/index26.js +1100 -207
  74. package/dist/index26.js.map +1 -1
  75. package/dist/index27.js +2469 -1023
  76. package/dist/index27.js.map +1 -1
  77. package/dist/index28.js +35 -2569
  78. package/dist/index28.js.map +1 -1
  79. package/dist/index29.js +308 -36
  80. package/dist/index29.js.map +1 -1
  81. package/dist/index30.js +7 -307
  82. package/dist/index30.js.map +1 -1
  83. package/dist/index31.js +30 -8
  84. package/dist/index31.js.map +1 -1
  85. package/dist/index32.js +59 -29
  86. package/dist/index32.js.map +1 -1
  87. package/dist/index33.js +10 -59
  88. package/dist/index33.js.map +1 -1
  89. package/dist/index34.js +35347 -9
  90. package/dist/index34.js.map +1 -1
  91. package/dist/index35.js +72 -35342
  92. package/dist/index35.js.map +1 -1
  93. package/dist/index36.js +187 -72
  94. package/dist/index36.js.map +1 -1
  95. package/dist/index5.js +4 -4
  96. package/dist/index7.js +99 -13
  97. package/dist/index7.js.map +1 -1
  98. package/dist/index8.js +43 -99
  99. package/dist/index8.js.map +1 -1
  100. package/dist/index9.js +102 -42
  101. package/dist/index9.js.map +1 -1
  102. package/dist/lib/components/LineChart/LineChart.d.ts +5 -1
  103. package/dist/lib/components/LineChart/LineChart.d.ts.map +1 -1
  104. package/dist/lib/components/LineChart/LineChartEmpty.d.ts +18 -0
  105. package/dist/lib/components/LineChart/LineChartEmpty.d.ts.map +1 -0
  106. package/dist/lib/components/LineChart/LineChartSkeleton.d.ts +7 -0
  107. package/dist/lib/components/LineChart/LineChartSkeleton.d.ts.map +1 -0
  108. package/dist/lib/components/LineChart/index.d.ts +1 -0
  109. package/dist/lib/components/LineChart/index.d.ts.map +1 -1
  110. package/dist/lib/components/StatusSwitch/StatusSwitch.d.ts +1 -1
  111. package/dist/lib/components/StatusSwitch/StatusSwitch.d.ts.map +1 -1
  112. package/dist/lib/config/index.d.ts +1 -1
  113. package/dist/lib/config/index.d.ts.map +1 -1
  114. package/dist/lib/hooks/useFormatters.d.ts.map +1 -1
  115. package/dist/lib/hooks/useWorkspaceCurrency.d.ts +1 -1
  116. package/dist/lib/hooks/useWorkspaceCurrency.d.ts.map +1 -1
  117. package/dist/lib/utils/currency.d.ts +1 -3
  118. package/dist/lib/utils/currency.d.ts.map +1 -1
  119. package/dist/lib/utils/timezone.d.ts +1 -0
  120. package/dist/lib/utils/timezone.d.ts.map +1 -1
  121. package/dist/popover.js +1 -1
  122. package/dist/select2.js +1 -1
  123. package/dist/separator2.js +1 -1
  124. package/dist/shadcn/shadcnField/field.d.ts.map +1 -1
  125. package/dist/timezone.js +68 -0
  126. package/dist/timezone.js.map +1 -0
  127. package/dist/tooltip2.js +1 -1
  128. package/dist/useDataTable.js +1 -1
  129. package/dist/useFormatters.js +3 -9
  130. package/dist/useFormatters.js.map +1 -1
  131. package/dist/{useTimer.js → useWorkspaceCurrency.js} +16 -4
  132. package/dist/useWorkspaceCurrency.js.map +1 -0
  133. package/dist/useWorkspaceTimeZone.js +1 -1
  134. package/dist/utils/axios.js +1 -1
  135. package/dist/utils/currency.js +5 -18
  136. package/dist/utils/currency.js.map +1 -1
  137. package/dist/utils/format.js +1 -2
  138. package/dist/utils/format.js.map +1 -1
  139. package/dist/utils/money.js +1 -1
  140. package/dist/utils/motion.js +2 -2
  141. package/dist/utils/timezone.js +4 -51
  142. package/dist/utils/timezone.js.map +1 -1
  143. package/dist/value.js +1 -1
  144. package/package.json +1 -1
  145. package/dist/index37.js +0 -199
  146. package/dist/index37.js.map +0 -1
  147. package/dist/useTimer.js.map +0 -1
package/dist/index28.js CHANGED
@@ -1,2575 +1,41 @@
1
1
  import * as React from 'react';
2
- import { useLayoutEffect } from 'react';
3
- import * as ReactDOM from 'react-dom';
4
- import { P as Primitive } from './index20.js';
2
+ import 'react-dom';
3
+ import { c as createSlot } from './index9.js';
5
4
  import { jsx } from 'react/jsx-runtime';
6
- import { u as useComposedRefs } from './index12.js';
7
- import { c as createContextScope } from './index21.js';
8
- import { u as useCallbackRef } from './index31.js';
9
- import { u as useLayoutEffect2 } from './index25.js';
10
5
 
11
- /**
12
- * Custom positioning reference element.
13
- * @see https://floating-ui.com/docs/virtual-elements
14
- */
15
-
16
- const sides = ['top', 'right', 'bottom', 'left'];
17
- const min = Math.min;
18
- const max = Math.max;
19
- const round = Math.round;
20
- const floor = Math.floor;
21
- const createCoords = v => ({
22
- x: v,
23
- y: v
24
- });
25
- const oppositeSideMap = {
26
- left: 'right',
27
- right: 'left',
28
- bottom: 'top',
29
- top: 'bottom'
30
- };
31
- function clamp(start, value, end) {
32
- return max(start, min(value, end));
33
- }
34
- function evaluate(value, param) {
35
- return typeof value === 'function' ? value(param) : value;
36
- }
37
- function getSide(placement) {
38
- return placement.split('-')[0];
39
- }
40
- function getAlignment(placement) {
41
- return placement.split('-')[1];
42
- }
43
- function getOppositeAxis(axis) {
44
- return axis === 'x' ? 'y' : 'x';
45
- }
46
- function getAxisLength(axis) {
47
- return axis === 'y' ? 'height' : 'width';
48
- }
49
- function getSideAxis(placement) {
50
- const firstChar = placement[0];
51
- return firstChar === 't' || firstChar === 'b' ? 'y' : 'x';
52
- }
53
- function getAlignmentAxis(placement) {
54
- return getOppositeAxis(getSideAxis(placement));
55
- }
56
- function getAlignmentSides(placement, rects, rtl) {
57
- if (rtl === void 0) {
58
- rtl = false;
59
- }
60
- const alignment = getAlignment(placement);
61
- const alignmentAxis = getAlignmentAxis(placement);
62
- const length = getAxisLength(alignmentAxis);
63
- let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
64
- if (rects.reference[length] > rects.floating[length]) {
65
- mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
66
- }
67
- return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
68
- }
69
- function getExpandedPlacements(placement) {
70
- const oppositePlacement = getOppositePlacement(placement);
71
- return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
72
- }
73
- function getOppositeAlignmentPlacement(placement) {
74
- return placement.includes('start') ? placement.replace('start', 'end') : placement.replace('end', 'start');
75
- }
76
- const lrPlacement = ['left', 'right'];
77
- const rlPlacement = ['right', 'left'];
78
- const tbPlacement = ['top', 'bottom'];
79
- const btPlacement = ['bottom', 'top'];
80
- function getSideList(side, isStart, rtl) {
81
- switch (side) {
82
- case 'top':
83
- case 'bottom':
84
- if (rtl) return isStart ? rlPlacement : lrPlacement;
85
- return isStart ? lrPlacement : rlPlacement;
86
- case 'left':
87
- case 'right':
88
- return isStart ? tbPlacement : btPlacement;
89
- default:
90
- return [];
91
- }
92
- }
93
- function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
94
- const alignment = getAlignment(placement);
95
- let list = getSideList(getSide(placement), direction === 'start', rtl);
96
- if (alignment) {
97
- list = list.map(side => side + "-" + alignment);
98
- if (flipAlignment) {
99
- list = list.concat(list.map(getOppositeAlignmentPlacement));
100
- }
101
- }
102
- return list;
103
- }
104
- function getOppositePlacement(placement) {
105
- const side = getSide(placement);
106
- return oppositeSideMap[side] + placement.slice(side.length);
107
- }
108
- function expandPaddingObject(padding) {
109
- return {
110
- top: 0,
111
- right: 0,
112
- bottom: 0,
113
- left: 0,
114
- ...padding
115
- };
116
- }
117
- function getPaddingObject(padding) {
118
- return typeof padding !== 'number' ? expandPaddingObject(padding) : {
119
- top: padding,
120
- right: padding,
121
- bottom: padding,
122
- left: padding
123
- };
124
- }
125
- function rectToClientRect(rect) {
126
- const {
127
- x,
128
- y,
129
- width,
130
- height
131
- } = rect;
132
- return {
133
- width,
134
- height,
135
- top: y,
136
- left: x,
137
- right: x + width,
138
- bottom: y + height,
139
- x,
140
- y
141
- };
142
- }
143
-
144
- function computeCoordsFromPlacement(_ref, placement, rtl) {
145
- let {
146
- reference,
147
- floating
148
- } = _ref;
149
- const sideAxis = getSideAxis(placement);
150
- const alignmentAxis = getAlignmentAxis(placement);
151
- const alignLength = getAxisLength(alignmentAxis);
152
- const side = getSide(placement);
153
- const isVertical = sideAxis === 'y';
154
- const commonX = reference.x + reference.width / 2 - floating.width / 2;
155
- const commonY = reference.y + reference.height / 2 - floating.height / 2;
156
- const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
157
- let coords;
158
- switch (side) {
159
- case 'top':
160
- coords = {
161
- x: commonX,
162
- y: reference.y - floating.height
163
- };
164
- break;
165
- case 'bottom':
166
- coords = {
167
- x: commonX,
168
- y: reference.y + reference.height
169
- };
170
- break;
171
- case 'right':
172
- coords = {
173
- x: reference.x + reference.width,
174
- y: commonY
175
- };
176
- break;
177
- case 'left':
178
- coords = {
179
- x: reference.x - floating.width,
180
- y: commonY
181
- };
182
- break;
183
- default:
184
- coords = {
185
- x: reference.x,
186
- y: reference.y
187
- };
188
- }
189
- switch (getAlignment(placement)) {
190
- case 'start':
191
- coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
192
- break;
193
- case 'end':
194
- coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
195
- break;
196
- }
197
- return coords;
198
- }
199
-
200
- /**
201
- * Resolves with an object of overflow side offsets that determine how much the
202
- * element is overflowing a given clipping boundary on each side.
203
- * - positive = overflowing the boundary by that number of pixels
204
- * - negative = how many pixels left before it will overflow
205
- * - 0 = lies flush with the boundary
206
- * @see https://floating-ui.com/docs/detectOverflow
207
- */
208
- async function detectOverflow(state, options) {
209
- var _await$platform$isEle;
210
- if (options === void 0) {
211
- options = {};
212
- }
213
- const {
214
- x,
215
- y,
216
- platform,
217
- rects,
218
- elements,
219
- strategy
220
- } = state;
221
- const {
222
- boundary = 'clippingAncestors',
223
- rootBoundary = 'viewport',
224
- elementContext = 'floating',
225
- altBoundary = false,
226
- padding = 0
227
- } = evaluate(options, state);
228
- const paddingObject = getPaddingObject(padding);
229
- const altContext = elementContext === 'floating' ? 'reference' : 'floating';
230
- const element = elements[altBoundary ? altContext : elementContext];
231
- const clippingClientRect = rectToClientRect(await platform.getClippingRect({
232
- element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
233
- boundary,
234
- rootBoundary,
235
- strategy
236
- }));
237
- const rect = elementContext === 'floating' ? {
238
- x,
239
- y,
240
- width: rects.floating.width,
241
- height: rects.floating.height
242
- } : rects.reference;
243
- const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
244
- const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
245
- x: 1,
246
- y: 1
247
- } : {
248
- x: 1,
249
- y: 1
250
- };
251
- const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
252
- elements,
253
- rect,
254
- offsetParent,
255
- strategy
256
- }) : rect);
257
- return {
258
- top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
259
- bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
260
- left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
261
- right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
262
- };
263
- }
264
-
265
- // Maximum number of resets that can occur before bailing to avoid infinite reset loops.
266
- const MAX_RESET_COUNT = 50;
267
-
268
- /**
269
- * Computes the `x` and `y` coordinates that will place the floating element
270
- * next to a given reference element.
271
- *
272
- * This export does not have any `platform` interface logic. You will need to
273
- * write one for the platform you are using Floating UI with.
274
- */
275
- const computePosition$1 = async (reference, floating, config) => {
276
- const {
277
- placement = 'bottom',
278
- strategy = 'absolute',
279
- middleware = [],
280
- platform
281
- } = config;
282
- const platformWithDetectOverflow = platform.detectOverflow ? platform : {
283
- ...platform,
284
- detectOverflow
285
- };
286
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
287
- let rects = await platform.getElementRects({
288
- reference,
289
- floating,
290
- strategy
291
- });
292
- let {
293
- x,
294
- y
295
- } = computeCoordsFromPlacement(rects, placement, rtl);
296
- let statefulPlacement = placement;
297
- let resetCount = 0;
298
- const middlewareData = {};
299
- for (let i = 0; i < middleware.length; i++) {
300
- const currentMiddleware = middleware[i];
301
- if (!currentMiddleware) {
302
- continue;
303
- }
304
- const {
305
- name,
306
- fn
307
- } = currentMiddleware;
308
- const {
309
- x: nextX,
310
- y: nextY,
311
- data,
312
- reset
313
- } = await fn({
314
- x,
315
- y,
316
- initialPlacement: placement,
317
- placement: statefulPlacement,
318
- strategy,
319
- middlewareData,
320
- rects,
321
- platform: platformWithDetectOverflow,
322
- elements: {
323
- reference,
324
- floating
325
- }
326
- });
327
- x = nextX != null ? nextX : x;
328
- y = nextY != null ? nextY : y;
329
- middlewareData[name] = {
330
- ...middlewareData[name],
331
- ...data
332
- };
333
- if (reset && resetCount < MAX_RESET_COUNT) {
334
- resetCount++;
335
- if (typeof reset === 'object') {
336
- if (reset.placement) {
337
- statefulPlacement = reset.placement;
338
- }
339
- if (reset.rects) {
340
- rects = reset.rects === true ? await platform.getElementRects({
341
- reference,
342
- floating,
343
- strategy
344
- }) : reset.rects;
345
- }
346
- ({
347
- x,
348
- y
349
- } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
350
- }
351
- i = -1;
352
- }
353
- }
354
- return {
355
- x,
356
- y,
357
- placement: statefulPlacement,
358
- strategy,
359
- middlewareData
360
- };
361
- };
362
-
363
- /**
364
- * Provides data to position an inner element of the floating element so that it
365
- * appears centered to the reference element.
366
- * @see https://floating-ui.com/docs/arrow
367
- */
368
- const arrow$3 = options => ({
369
- name: 'arrow',
370
- options,
371
- async fn(state) {
372
- const {
373
- x,
374
- y,
375
- placement,
376
- rects,
377
- platform,
378
- elements,
379
- middlewareData
380
- } = state;
381
- // Since `element` is required, we don't Partial<> the type.
382
- const {
383
- element,
384
- padding = 0
385
- } = evaluate(options, state) || {};
386
- if (element == null) {
387
- return {};
388
- }
389
- const paddingObject = getPaddingObject(padding);
390
- const coords = {
391
- x,
392
- y
393
- };
394
- const axis = getAlignmentAxis(placement);
395
- const length = getAxisLength(axis);
396
- const arrowDimensions = await platform.getDimensions(element);
397
- const isYAxis = axis === 'y';
398
- const minProp = isYAxis ? 'top' : 'left';
399
- const maxProp = isYAxis ? 'bottom' : 'right';
400
- const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
401
- const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
402
- const startDiff = coords[axis] - rects.reference[axis];
403
- const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
404
- let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
405
-
406
- // DOM platform can return `window` as the `offsetParent`.
407
- if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
408
- clientSize = elements.floating[clientProp] || rects.floating[length];
409
- }
410
- const centerToReference = endDiff / 2 - startDiff / 2;
411
-
412
- // If the padding is large enough that it causes the arrow to no longer be
413
- // centered, modify the padding so that it is centered.
414
- const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
415
- const minPadding = min(paddingObject[minProp], largestPossiblePadding);
416
- const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
417
-
418
- // Make sure the arrow doesn't overflow the floating element if the center
419
- // point is outside the floating element's bounds.
420
- const min$1 = minPadding;
421
- const max = clientSize - arrowDimensions[length] - maxPadding;
422
- const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
423
- const offset = clamp(min$1, center, max);
424
-
425
- // If the reference is small enough that the arrow's padding causes it to
426
- // to point to nothing for an aligned placement, adjust the offset of the
427
- // floating element itself. To ensure `shift()` continues to take action,
428
- // a single reset is performed when this is true.
429
- const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
430
- const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
431
- return {
432
- [axis]: coords[axis] + alignmentOffset,
433
- data: {
434
- [axis]: offset,
435
- centerOffset: center - offset - alignmentOffset,
436
- ...(shouldAddOffset && {
437
- alignmentOffset
438
- })
439
- },
440
- reset: shouldAddOffset
441
- };
442
- }
443
- });
444
-
445
- /**
446
- * Optimizes the visibility of the floating element by flipping the `placement`
447
- * in order to keep it in view when the preferred placement(s) will overflow the
448
- * clipping boundary. Alternative to `autoPlacement`.
449
- * @see https://floating-ui.com/docs/flip
450
- */
451
- const flip$2 = function (options) {
452
- if (options === void 0) {
453
- options = {};
454
- }
455
- return {
456
- name: 'flip',
457
- options,
458
- async fn(state) {
459
- var _middlewareData$arrow, _middlewareData$flip;
460
- const {
461
- placement,
462
- middlewareData,
463
- rects,
464
- initialPlacement,
465
- platform,
466
- elements
467
- } = state;
468
- const {
469
- mainAxis: checkMainAxis = true,
470
- crossAxis: checkCrossAxis = true,
471
- fallbackPlacements: specifiedFallbackPlacements,
472
- fallbackStrategy = 'bestFit',
473
- fallbackAxisSideDirection = 'none',
474
- flipAlignment = true,
475
- ...detectOverflowOptions
476
- } = evaluate(options, state);
477
-
478
- // If a reset by the arrow was caused due to an alignment offset being
479
- // added, we should skip any logic now since `flip()` has already done its
480
- // work.
481
- // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
482
- if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
483
- return {};
484
- }
485
- const side = getSide(placement);
486
- const initialSideAxis = getSideAxis(initialPlacement);
487
- const isBasePlacement = getSide(initialPlacement) === initialPlacement;
488
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
489
- const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
490
- const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
491
- if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
492
- fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
493
- }
494
- const placements = [initialPlacement, ...fallbackPlacements];
495
- const overflow = await platform.detectOverflow(state, detectOverflowOptions);
496
- const overflows = [];
497
- let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
498
- if (checkMainAxis) {
499
- overflows.push(overflow[side]);
500
- }
501
- if (checkCrossAxis) {
502
- const sides = getAlignmentSides(placement, rects, rtl);
503
- overflows.push(overflow[sides[0]], overflow[sides[1]]);
504
- }
505
- overflowsData = [...overflowsData, {
506
- placement,
507
- overflows
508
- }];
509
-
510
- // One or more sides is overflowing.
511
- if (!overflows.every(side => side <= 0)) {
512
- var _middlewareData$flip2, _overflowsData$filter;
513
- const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
514
- const nextPlacement = placements[nextIndex];
515
- if (nextPlacement) {
516
- const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
517
- if (!ignoreCrossAxisOverflow ||
518
- // We leave the current main axis only if every placement on that axis
519
- // overflows the main axis.
520
- overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
521
- // Try next placement and re-run the lifecycle.
522
- return {
523
- data: {
524
- index: nextIndex,
525
- overflows: overflowsData
526
- },
527
- reset: {
528
- placement: nextPlacement
529
- }
530
- };
531
- }
532
- }
533
-
534
- // First, find the candidates that fit on the mainAxis side of overflow,
535
- // then find the placement that fits the best on the main crossAxis side.
536
- let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
537
-
538
- // Otherwise fallback.
539
- if (!resetPlacement) {
540
- switch (fallbackStrategy) {
541
- case 'bestFit':
542
- {
543
- var _overflowsData$filter2;
544
- const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
545
- if (hasFallbackAxisSideDirection) {
546
- const currentSideAxis = getSideAxis(d.placement);
547
- return currentSideAxis === initialSideAxis ||
548
- // Create a bias to the `y` side axis due to horizontal
549
- // reading directions favoring greater width.
550
- currentSideAxis === 'y';
551
- }
552
- return true;
553
- }).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
554
- if (placement) {
555
- resetPlacement = placement;
556
- }
557
- break;
558
- }
559
- case 'initialPlacement':
560
- resetPlacement = initialPlacement;
561
- break;
562
- }
563
- }
564
- if (placement !== resetPlacement) {
565
- return {
566
- reset: {
567
- placement: resetPlacement
568
- }
569
- };
570
- }
571
- }
572
- return {};
573
- }
574
- };
575
- };
576
-
577
- function getSideOffsets(overflow, rect) {
578
- return {
579
- top: overflow.top - rect.height,
580
- right: overflow.right - rect.width,
581
- bottom: overflow.bottom - rect.height,
582
- left: overflow.left - rect.width
583
- };
584
- }
585
- function isAnySideFullyClipped(overflow) {
586
- return sides.some(side => overflow[side] >= 0);
587
- }
588
- /**
589
- * Provides data to hide the floating element in applicable situations, such as
590
- * when it is not in the same clipping context as the reference element.
591
- * @see https://floating-ui.com/docs/hide
592
- */
593
- const hide$2 = function (options) {
594
- if (options === void 0) {
595
- options = {};
596
- }
597
- return {
598
- name: 'hide',
599
- options,
600
- async fn(state) {
601
- const {
602
- rects,
603
- platform
604
- } = state;
605
- const {
606
- strategy = 'referenceHidden',
607
- ...detectOverflowOptions
608
- } = evaluate(options, state);
609
- switch (strategy) {
610
- case 'referenceHidden':
611
- {
612
- const overflow = await platform.detectOverflow(state, {
613
- ...detectOverflowOptions,
614
- elementContext: 'reference'
615
- });
616
- const offsets = getSideOffsets(overflow, rects.reference);
617
- return {
618
- data: {
619
- referenceHiddenOffsets: offsets,
620
- referenceHidden: isAnySideFullyClipped(offsets)
621
- }
622
- };
623
- }
624
- case 'escaped':
625
- {
626
- const overflow = await platform.detectOverflow(state, {
627
- ...detectOverflowOptions,
628
- altBoundary: true
629
- });
630
- const offsets = getSideOffsets(overflow, rects.floating);
631
- return {
632
- data: {
633
- escapedOffsets: offsets,
634
- escaped: isAnySideFullyClipped(offsets)
635
- }
636
- };
637
- }
638
- default:
639
- {
640
- return {};
641
- }
642
- }
643
- }
644
- };
645
- };
646
-
647
- const originSides = /*#__PURE__*/new Set(['left', 'top']);
648
-
649
- // For type backwards-compatibility, the `OffsetOptions` type was also
650
- // Derivable.
651
-
652
- async function convertValueToCoords(state, options) {
653
- const {
654
- placement,
655
- platform,
656
- elements
657
- } = state;
658
- const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
659
- const side = getSide(placement);
660
- const alignment = getAlignment(placement);
661
- const isVertical = getSideAxis(placement) === 'y';
662
- const mainAxisMulti = originSides.has(side) ? -1 : 1;
663
- const crossAxisMulti = rtl && isVertical ? -1 : 1;
664
- const rawValue = evaluate(options, state);
665
-
666
- // eslint-disable-next-line prefer-const
667
- let {
668
- mainAxis,
669
- crossAxis,
670
- alignmentAxis
671
- } = typeof rawValue === 'number' ? {
672
- mainAxis: rawValue,
673
- crossAxis: 0,
674
- alignmentAxis: null
675
- } : {
676
- mainAxis: rawValue.mainAxis || 0,
677
- crossAxis: rawValue.crossAxis || 0,
678
- alignmentAxis: rawValue.alignmentAxis
679
- };
680
- if (alignment && typeof alignmentAxis === 'number') {
681
- crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
682
- }
683
- return isVertical ? {
684
- x: crossAxis * crossAxisMulti,
685
- y: mainAxis * mainAxisMulti
686
- } : {
687
- x: mainAxis * mainAxisMulti,
688
- y: crossAxis * crossAxisMulti
689
- };
690
- }
691
-
692
- /**
693
- * Modifies the placement by translating the floating element along the
694
- * specified axes.
695
- * A number (shorthand for `mainAxis` or distance), or an axes configuration
696
- * object may be passed.
697
- * @see https://floating-ui.com/docs/offset
698
- */
699
- const offset$2 = function (options) {
700
- if (options === void 0) {
701
- options = 0;
702
- }
703
- return {
704
- name: 'offset',
705
- options,
706
- async fn(state) {
707
- var _middlewareData$offse, _middlewareData$arrow;
708
- const {
709
- x,
710
- y,
711
- placement,
712
- middlewareData
713
- } = state;
714
- const diffCoords = await convertValueToCoords(state, options);
715
-
716
- // If the placement is the same and the arrow caused an alignment offset
717
- // then we don't need to change the positioning coordinates.
718
- if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
719
- return {};
720
- }
721
- return {
722
- x: x + diffCoords.x,
723
- y: y + diffCoords.y,
724
- data: {
725
- ...diffCoords,
726
- placement
727
- }
728
- };
729
- }
730
- };
731
- };
732
-
733
- /**
734
- * Optimizes the visibility of the floating element by shifting it in order to
735
- * keep it in view when it will overflow the clipping boundary.
736
- * @see https://floating-ui.com/docs/shift
737
- */
738
- const shift$2 = function (options) {
739
- if (options === void 0) {
740
- options = {};
741
- }
742
- return {
743
- name: 'shift',
744
- options,
745
- async fn(state) {
746
- const {
747
- x,
748
- y,
749
- placement,
750
- platform
751
- } = state;
752
- const {
753
- mainAxis: checkMainAxis = true,
754
- crossAxis: checkCrossAxis = false,
755
- limiter = {
756
- fn: _ref => {
757
- let {
758
- x,
759
- y
760
- } = _ref;
761
- return {
762
- x,
763
- y
764
- };
765
- }
766
- },
767
- ...detectOverflowOptions
768
- } = evaluate(options, state);
769
- const coords = {
770
- x,
771
- y
772
- };
773
- const overflow = await platform.detectOverflow(state, detectOverflowOptions);
774
- const crossAxis = getSideAxis(getSide(placement));
775
- const mainAxis = getOppositeAxis(crossAxis);
776
- let mainAxisCoord = coords[mainAxis];
777
- let crossAxisCoord = coords[crossAxis];
778
- if (checkMainAxis) {
779
- const minSide = mainAxis === 'y' ? 'top' : 'left';
780
- const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
781
- const min = mainAxisCoord + overflow[minSide];
782
- const max = mainAxisCoord - overflow[maxSide];
783
- mainAxisCoord = clamp(min, mainAxisCoord, max);
784
- }
785
- if (checkCrossAxis) {
786
- const minSide = crossAxis === 'y' ? 'top' : 'left';
787
- const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
788
- const min = crossAxisCoord + overflow[minSide];
789
- const max = crossAxisCoord - overflow[maxSide];
790
- crossAxisCoord = clamp(min, crossAxisCoord, max);
791
- }
792
- const limitedCoords = limiter.fn({
793
- ...state,
794
- [mainAxis]: mainAxisCoord,
795
- [crossAxis]: crossAxisCoord
796
- });
797
- return {
798
- ...limitedCoords,
799
- data: {
800
- x: limitedCoords.x - x,
801
- y: limitedCoords.y - y,
802
- enabled: {
803
- [mainAxis]: checkMainAxis,
804
- [crossAxis]: checkCrossAxis
805
- }
806
- }
807
- };
808
- }
809
- };
810
- };
811
- /**
812
- * Built-in `limiter` that will stop `shift()` at a certain point.
813
- */
814
- const limitShift$2 = function (options) {
815
- if (options === void 0) {
816
- options = {};
817
- }
818
- return {
819
- options,
820
- fn(state) {
821
- const {
822
- x,
823
- y,
824
- placement,
825
- rects,
826
- middlewareData
827
- } = state;
828
- const {
829
- offset = 0,
830
- mainAxis: checkMainAxis = true,
831
- crossAxis: checkCrossAxis = true
832
- } = evaluate(options, state);
833
- const coords = {
834
- x,
835
- y
836
- };
837
- const crossAxis = getSideAxis(placement);
838
- const mainAxis = getOppositeAxis(crossAxis);
839
- let mainAxisCoord = coords[mainAxis];
840
- let crossAxisCoord = coords[crossAxis];
841
- const rawOffset = evaluate(offset, state);
842
- const computedOffset = typeof rawOffset === 'number' ? {
843
- mainAxis: rawOffset,
844
- crossAxis: 0
845
- } : {
846
- mainAxis: 0,
847
- crossAxis: 0,
848
- ...rawOffset
849
- };
850
- if (checkMainAxis) {
851
- const len = mainAxis === 'y' ? 'height' : 'width';
852
- const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
853
- const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
854
- if (mainAxisCoord < limitMin) {
855
- mainAxisCoord = limitMin;
856
- } else if (mainAxisCoord > limitMax) {
857
- mainAxisCoord = limitMax;
858
- }
859
- }
860
- if (checkCrossAxis) {
861
- var _middlewareData$offse, _middlewareData$offse2;
862
- const len = mainAxis === 'y' ? 'width' : 'height';
863
- const isOriginSide = originSides.has(getSide(placement));
864
- const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
865
- const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
866
- if (crossAxisCoord < limitMin) {
867
- crossAxisCoord = limitMin;
868
- } else if (crossAxisCoord > limitMax) {
869
- crossAxisCoord = limitMax;
870
- }
871
- }
872
- return {
873
- [mainAxis]: mainAxisCoord,
874
- [crossAxis]: crossAxisCoord
875
- };
876
- }
877
- };
878
- };
879
-
880
- /**
881
- * Provides data that allows you to change the size of the floating element —
882
- * for instance, prevent it from overflowing the clipping boundary or match the
883
- * width of the reference element.
884
- * @see https://floating-ui.com/docs/size
885
- */
886
- const size$2 = function (options) {
887
- if (options === void 0) {
888
- options = {};
889
- }
890
- return {
891
- name: 'size',
892
- options,
893
- async fn(state) {
894
- var _state$middlewareData, _state$middlewareData2;
895
- const {
896
- placement,
897
- rects,
898
- platform,
899
- elements
900
- } = state;
901
- const {
902
- apply = () => {},
903
- ...detectOverflowOptions
904
- } = evaluate(options, state);
905
- const overflow = await platform.detectOverflow(state, detectOverflowOptions);
906
- const side = getSide(placement);
907
- const alignment = getAlignment(placement);
908
- const isYAxis = getSideAxis(placement) === 'y';
909
- const {
910
- width,
911
- height
912
- } = rects.floating;
913
- let heightSide;
914
- let widthSide;
915
- if (side === 'top' || side === 'bottom') {
916
- heightSide = side;
917
- widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
918
- } else {
919
- widthSide = side;
920
- heightSide = alignment === 'end' ? 'top' : 'bottom';
921
- }
922
- const maximumClippingHeight = height - overflow.top - overflow.bottom;
923
- const maximumClippingWidth = width - overflow.left - overflow.right;
924
- const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
925
- const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
926
- const noShift = !state.middlewareData.shift;
927
- let availableHeight = overflowAvailableHeight;
928
- let availableWidth = overflowAvailableWidth;
929
- if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
930
- availableWidth = maximumClippingWidth;
931
- }
932
- if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
933
- availableHeight = maximumClippingHeight;
934
- }
935
- if (noShift && !alignment) {
936
- const xMin = max(overflow.left, 0);
937
- const xMax = max(overflow.right, 0);
938
- const yMin = max(overflow.top, 0);
939
- const yMax = max(overflow.bottom, 0);
940
- if (isYAxis) {
941
- availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
942
- } else {
943
- availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
944
- }
945
- }
946
- await apply({
947
- ...state,
948
- availableWidth,
949
- availableHeight
950
- });
951
- const nextDimensions = await platform.getDimensions(elements.floating);
952
- if (width !== nextDimensions.width || height !== nextDimensions.height) {
953
- return {
954
- reset: {
955
- rects: true
956
- }
957
- };
958
- }
959
- return {};
960
- }
961
- };
962
- };
963
-
964
- function hasWindow() {
965
- return typeof window !== 'undefined';
966
- }
967
- function getNodeName(node) {
968
- if (isNode(node)) {
969
- return (node.nodeName || '').toLowerCase();
970
- }
971
- // Mocked nodes in testing environments may not be instances of Node. By
972
- // returning `#document` an infinite loop won't occur.
973
- // https://github.com/floating-ui/floating-ui/issues/2317
974
- return '#document';
975
- }
976
- function getWindow(node) {
977
- var _node$ownerDocument;
978
- return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
979
- }
980
- function getDocumentElement(node) {
981
- var _ref;
982
- return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
983
- }
984
- function isNode(value) {
985
- if (!hasWindow()) {
986
- return false;
987
- }
988
- return value instanceof Node || value instanceof getWindow(value).Node;
989
- }
990
- function isElement(value) {
991
- if (!hasWindow()) {
992
- return false;
993
- }
994
- return value instanceof Element || value instanceof getWindow(value).Element;
995
- }
996
- function isHTMLElement(value) {
997
- if (!hasWindow()) {
998
- return false;
999
- }
1000
- return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
1001
- }
1002
- function isShadowRoot(value) {
1003
- if (!hasWindow() || typeof ShadowRoot === 'undefined') {
1004
- return false;
1005
- }
1006
- return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
1007
- }
1008
- function isOverflowElement(element) {
1009
- const {
1010
- overflow,
1011
- overflowX,
1012
- overflowY,
1013
- display
1014
- } = getComputedStyle$1(element);
1015
- return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== 'inline' && display !== 'contents';
1016
- }
1017
- function isTableElement(element) {
1018
- return /^(table|td|th)$/.test(getNodeName(element));
1019
- }
1020
- function isTopLayer(element) {
1021
- try {
1022
- if (element.matches(':popover-open')) {
1023
- return true;
1024
- }
1025
- } catch (_e) {
1026
- // no-op
1027
- }
1028
- try {
1029
- return element.matches(':modal');
1030
- } catch (_e) {
1031
- return false;
1032
- }
1033
- }
1034
- const willChangeRe = /transform|translate|scale|rotate|perspective|filter/;
1035
- const containRe = /paint|layout|strict|content/;
1036
- const isNotNone = value => !!value && value !== 'none';
1037
- let isWebKitValue;
1038
- function isContainingBlock(elementOrCss) {
1039
- const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
1040
-
1041
- // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1042
- // https://drafts.csswg.org/css-transforms-2/#individual-transforms
1043
- return isNotNone(css.transform) || isNotNone(css.translate) || isNotNone(css.scale) || isNotNone(css.rotate) || isNotNone(css.perspective) || !isWebKit() && (isNotNone(css.backdropFilter) || isNotNone(css.filter)) || willChangeRe.test(css.willChange || '') || containRe.test(css.contain || '');
1044
- }
1045
- function getContainingBlock(element) {
1046
- let currentNode = getParentNode(element);
1047
- while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
1048
- if (isContainingBlock(currentNode)) {
1049
- return currentNode;
1050
- } else if (isTopLayer(currentNode)) {
1051
- return null;
1052
- }
1053
- currentNode = getParentNode(currentNode);
1054
- }
1055
- return null;
1056
- }
1057
- function isWebKit() {
1058
- if (isWebKitValue == null) {
1059
- isWebKitValue = typeof CSS !== 'undefined' && CSS.supports && CSS.supports('-webkit-backdrop-filter', 'none');
1060
- }
1061
- return isWebKitValue;
1062
- }
1063
- function isLastTraversableNode(node) {
1064
- return /^(html|body|#document)$/.test(getNodeName(node));
1065
- }
1066
- function getComputedStyle$1(element) {
1067
- return getWindow(element).getComputedStyle(element);
1068
- }
1069
- function getNodeScroll(element) {
1070
- if (isElement(element)) {
1071
- return {
1072
- scrollLeft: element.scrollLeft,
1073
- scrollTop: element.scrollTop
1074
- };
1075
- }
1076
- return {
1077
- scrollLeft: element.scrollX,
1078
- scrollTop: element.scrollY
1079
- };
1080
- }
1081
- function getParentNode(node) {
1082
- if (getNodeName(node) === 'html') {
1083
- return node;
1084
- }
1085
- const result =
1086
- // Step into the shadow DOM of the parent of a slotted node.
1087
- node.assignedSlot ||
1088
- // DOM Element detected.
1089
- node.parentNode ||
1090
- // ShadowRoot detected.
1091
- isShadowRoot(node) && node.host ||
1092
- // Fallback.
1093
- getDocumentElement(node);
1094
- return isShadowRoot(result) ? result.host : result;
1095
- }
1096
- function getNearestOverflowAncestor(node) {
1097
- const parentNode = getParentNode(node);
1098
- if (isLastTraversableNode(parentNode)) {
1099
- return node.ownerDocument ? node.ownerDocument.body : node.body;
1100
- }
1101
- if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
1102
- return parentNode;
1103
- }
1104
- return getNearestOverflowAncestor(parentNode);
1105
- }
1106
- function getOverflowAncestors(node, list, traverseIframes) {
1107
- var _node$ownerDocument2;
1108
- if (list === void 0) {
1109
- list = [];
1110
- }
1111
- if (traverseIframes === void 0) {
1112
- traverseIframes = true;
1113
- }
1114
- const scrollableAncestor = getNearestOverflowAncestor(node);
1115
- const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
1116
- const win = getWindow(scrollableAncestor);
1117
- if (isBody) {
1118
- const frameElement = getFrameElement(win);
1119
- return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
1120
- } else {
1121
- return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
1122
- }
1123
- }
1124
- function getFrameElement(win) {
1125
- return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
1126
- }
1127
-
1128
- function getCssDimensions(element) {
1129
- const css = getComputedStyle$1(element);
1130
- // In testing environments, the `width` and `height` properties are empty
1131
- // strings for SVG elements, returning NaN. Fallback to `0` in this case.
1132
- let width = parseFloat(css.width) || 0;
1133
- let height = parseFloat(css.height) || 0;
1134
- const hasOffset = isHTMLElement(element);
1135
- const offsetWidth = hasOffset ? element.offsetWidth : width;
1136
- const offsetHeight = hasOffset ? element.offsetHeight : height;
1137
- const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1138
- if (shouldFallback) {
1139
- width = offsetWidth;
1140
- height = offsetHeight;
1141
- }
1142
- return {
1143
- width,
1144
- height,
1145
- $: shouldFallback
1146
- };
1147
- }
1148
-
1149
- function unwrapElement(element) {
1150
- return !isElement(element) ? element.contextElement : element;
1151
- }
1152
-
1153
- function getScale(element) {
1154
- const domElement = unwrapElement(element);
1155
- if (!isHTMLElement(domElement)) {
1156
- return createCoords(1);
1157
- }
1158
- const rect = domElement.getBoundingClientRect();
1159
- const {
1160
- width,
1161
- height,
1162
- $
1163
- } = getCssDimensions(domElement);
1164
- let x = ($ ? round(rect.width) : rect.width) / width;
1165
- let y = ($ ? round(rect.height) : rect.height) / height;
1166
-
1167
- // 0, NaN, or Infinity should always fallback to 1.
1168
-
1169
- if (!x || !Number.isFinite(x)) {
1170
- x = 1;
1171
- }
1172
- if (!y || !Number.isFinite(y)) {
1173
- y = 1;
1174
- }
1175
- return {
1176
- x,
1177
- y
1178
- };
1179
- }
1180
-
1181
- const noOffsets = /*#__PURE__*/createCoords(0);
1182
- function getVisualOffsets(element) {
1183
- const win = getWindow(element);
1184
- if (!isWebKit() || !win.visualViewport) {
1185
- return noOffsets;
1186
- }
1187
- return {
1188
- x: win.visualViewport.offsetLeft,
1189
- y: win.visualViewport.offsetTop
1190
- };
1191
- }
1192
- function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1193
- if (isFixed === void 0) {
1194
- isFixed = false;
1195
- }
1196
- if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1197
- return false;
1198
- }
1199
- return isFixed;
1200
- }
1201
-
1202
- function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1203
- if (includeScale === void 0) {
1204
- includeScale = false;
1205
- }
1206
- if (isFixedStrategy === void 0) {
1207
- isFixedStrategy = false;
1208
- }
1209
- const clientRect = element.getBoundingClientRect();
1210
- const domElement = unwrapElement(element);
1211
- let scale = createCoords(1);
1212
- if (includeScale) {
1213
- if (offsetParent) {
1214
- if (isElement(offsetParent)) {
1215
- scale = getScale(offsetParent);
1216
- }
1217
- } else {
1218
- scale = getScale(element);
1219
- }
1220
- }
1221
- const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1222
- let x = (clientRect.left + visualOffsets.x) / scale.x;
1223
- let y = (clientRect.top + visualOffsets.y) / scale.y;
1224
- let width = clientRect.width / scale.x;
1225
- let height = clientRect.height / scale.y;
1226
- if (domElement) {
1227
- const win = getWindow(domElement);
1228
- const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1229
- let currentWin = win;
1230
- let currentIFrame = getFrameElement(currentWin);
1231
- while (currentIFrame && offsetParent && offsetWin !== currentWin) {
1232
- const iframeScale = getScale(currentIFrame);
1233
- const iframeRect = currentIFrame.getBoundingClientRect();
1234
- const css = getComputedStyle$1(currentIFrame);
1235
- const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1236
- const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1237
- x *= iframeScale.x;
1238
- y *= iframeScale.y;
1239
- width *= iframeScale.x;
1240
- height *= iframeScale.y;
1241
- x += left;
1242
- y += top;
1243
- currentWin = getWindow(currentIFrame);
1244
- currentIFrame = getFrameElement(currentWin);
1245
- }
1246
- }
1247
- return rectToClientRect({
1248
- width,
1249
- height,
1250
- x,
1251
- y
6
+ // src/primitive.tsx
7
+ var NODES = [
8
+ "a",
9
+ "button",
10
+ "div",
11
+ "form",
12
+ "h2",
13
+ "h3",
14
+ "img",
15
+ "input",
16
+ "label",
17
+ "li",
18
+ "nav",
19
+ "ol",
20
+ "p",
21
+ "select",
22
+ "span",
23
+ "svg",
24
+ "ul"
25
+ ];
26
+ var Primitive = NODES.reduce((primitive, node) => {
27
+ const Slot = createSlot(`Primitive.${node}`);
28
+ const Node = React.forwardRef((props, forwardedRef) => {
29
+ const { asChild, ...primitiveProps } = props;
30
+ const Comp = asChild ? Slot : node;
31
+ if (typeof window !== "undefined") {
32
+ window[Symbol.for("radix-ui")] = true;
33
+ }
34
+ return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
1252
35
  });
1253
- }
1254
-
1255
- // If <html> has a CSS width greater than the viewport, then this will be
1256
- // incorrect for RTL.
1257
- function getWindowScrollBarX(element, rect) {
1258
- const leftScroll = getNodeScroll(element).scrollLeft;
1259
- if (!rect) {
1260
- return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
1261
- }
1262
- return rect.left + leftScroll;
1263
- }
1264
-
1265
- function getHTMLOffset(documentElement, scroll) {
1266
- const htmlRect = documentElement.getBoundingClientRect();
1267
- const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
1268
- const y = htmlRect.top + scroll.scrollTop;
1269
- return {
1270
- x,
1271
- y
1272
- };
1273
- }
1274
-
1275
- function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1276
- let {
1277
- elements,
1278
- rect,
1279
- offsetParent,
1280
- strategy
1281
- } = _ref;
1282
- const isFixed = strategy === 'fixed';
1283
- const documentElement = getDocumentElement(offsetParent);
1284
- const topLayer = elements ? isTopLayer(elements.floating) : false;
1285
- if (offsetParent === documentElement || topLayer && isFixed) {
1286
- return rect;
1287
- }
1288
- let scroll = {
1289
- scrollLeft: 0,
1290
- scrollTop: 0
1291
- };
1292
- let scale = createCoords(1);
1293
- const offsets = createCoords(0);
1294
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
1295
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1296
- if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1297
- scroll = getNodeScroll(offsetParent);
1298
- }
1299
- if (isOffsetParentAnElement) {
1300
- const offsetRect = getBoundingClientRect(offsetParent);
1301
- scale = getScale(offsetParent);
1302
- offsets.x = offsetRect.x + offsetParent.clientLeft;
1303
- offsets.y = offsetRect.y + offsetParent.clientTop;
1304
- }
1305
- }
1306
- const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1307
- return {
1308
- width: rect.width * scale.x,
1309
- height: rect.height * scale.y,
1310
- x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
1311
- y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
1312
- };
1313
- }
1314
-
1315
- function getClientRects(element) {
1316
- return Array.from(element.getClientRects());
1317
- }
1318
-
1319
- // Gets the entire size of the scrollable document area, even extending outside
1320
- // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
1321
- function getDocumentRect(element) {
1322
- const html = getDocumentElement(element);
1323
- const scroll = getNodeScroll(element);
1324
- const body = element.ownerDocument.body;
1325
- const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1326
- const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1327
- let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1328
- const y = -scroll.scrollTop;
1329
- if (getComputedStyle$1(body).direction === 'rtl') {
1330
- x += max(html.clientWidth, body.clientWidth) - width;
1331
- }
1332
- return {
1333
- width,
1334
- height,
1335
- x,
1336
- y
1337
- };
1338
- }
1339
-
1340
- // Safety check: ensure the scrollbar space is reasonable in case this
1341
- // calculation is affected by unusual styles.
1342
- // Most scrollbars leave 15-18px of space.
1343
- const SCROLLBAR_MAX = 25;
1344
- function getViewportRect(element, strategy) {
1345
- const win = getWindow(element);
1346
- const html = getDocumentElement(element);
1347
- const visualViewport = win.visualViewport;
1348
- let width = html.clientWidth;
1349
- let height = html.clientHeight;
1350
- let x = 0;
1351
- let y = 0;
1352
- if (visualViewport) {
1353
- width = visualViewport.width;
1354
- height = visualViewport.height;
1355
- const visualViewportBased = isWebKit();
1356
- if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
1357
- x = visualViewport.offsetLeft;
1358
- y = visualViewport.offsetTop;
1359
- }
1360
- }
1361
- const windowScrollbarX = getWindowScrollBarX(html);
1362
- // <html> `overflow: hidden` + `scrollbar-gutter: stable` reduces the
1363
- // visual width of the <html> but this is not considered in the size
1364
- // of `html.clientWidth`.
1365
- if (windowScrollbarX <= 0) {
1366
- const doc = html.ownerDocument;
1367
- const body = doc.body;
1368
- const bodyStyles = getComputedStyle(body);
1369
- const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
1370
- const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
1371
- if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
1372
- width -= clippingStableScrollbarWidth;
1373
- }
1374
- } else if (windowScrollbarX <= SCROLLBAR_MAX) {
1375
- // If the <body> scrollbar is on the left, the width needs to be extended
1376
- // by the scrollbar amount so there isn't extra space on the right.
1377
- width += windowScrollbarX;
1378
- }
1379
- return {
1380
- width,
1381
- height,
1382
- x,
1383
- y
1384
- };
1385
- }
1386
-
1387
- // Returns the inner client rect, subtracting scrollbars if present.
1388
- function getInnerBoundingClientRect(element, strategy) {
1389
- const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
1390
- const top = clientRect.top + element.clientTop;
1391
- const left = clientRect.left + element.clientLeft;
1392
- const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1393
- const width = element.clientWidth * scale.x;
1394
- const height = element.clientHeight * scale.y;
1395
- const x = left * scale.x;
1396
- const y = top * scale.y;
1397
- return {
1398
- width,
1399
- height,
1400
- x,
1401
- y
1402
- };
1403
- }
1404
- function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1405
- let rect;
1406
- if (clippingAncestor === 'viewport') {
1407
- rect = getViewportRect(element, strategy);
1408
- } else if (clippingAncestor === 'document') {
1409
- rect = getDocumentRect(getDocumentElement(element));
1410
- } else if (isElement(clippingAncestor)) {
1411
- rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1412
- } else {
1413
- const visualOffsets = getVisualOffsets(element);
1414
- rect = {
1415
- x: clippingAncestor.x - visualOffsets.x,
1416
- y: clippingAncestor.y - visualOffsets.y,
1417
- width: clippingAncestor.width,
1418
- height: clippingAncestor.height
1419
- };
1420
- }
1421
- return rectToClientRect(rect);
1422
- }
1423
- function hasFixedPositionAncestor(element, stopNode) {
1424
- const parentNode = getParentNode(element);
1425
- if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1426
- return false;
1427
- }
1428
- return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
1429
- }
1430
-
1431
- // A "clipping ancestor" is an `overflow` element with the characteristic of
1432
- // clipping (or hiding) child elements. This returns all clipping ancestors
1433
- // of the given element up the tree.
1434
- function getClippingElementAncestors(element, cache) {
1435
- const cachedResult = cache.get(element);
1436
- if (cachedResult) {
1437
- return cachedResult;
1438
- }
1439
- let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
1440
- let currentContainingBlockComputedStyle = null;
1441
- const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
1442
- let currentNode = elementIsFixed ? getParentNode(element) : element;
1443
-
1444
- // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
1445
- while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1446
- const computedStyle = getComputedStyle$1(currentNode);
1447
- const currentNodeIsContaining = isContainingBlock(currentNode);
1448
- if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
1449
- currentContainingBlockComputedStyle = null;
1450
- }
1451
- const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === 'absolute' || currentContainingBlockComputedStyle.position === 'fixed') || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1452
- if (shouldDropCurrentNode) {
1453
- // Drop non-containing blocks.
1454
- result = result.filter(ancestor => ancestor !== currentNode);
1455
- } else {
1456
- // Record last containing block for next iteration.
1457
- currentContainingBlockComputedStyle = computedStyle;
1458
- }
1459
- currentNode = getParentNode(currentNode);
1460
- }
1461
- cache.set(element, result);
1462
- return result;
1463
- }
1464
-
1465
- // Gets the maximum area that the element is visible in due to any number of
1466
- // clipping ancestors.
1467
- function getClippingRect(_ref) {
1468
- let {
1469
- element,
1470
- boundary,
1471
- rootBoundary,
1472
- strategy
1473
- } = _ref;
1474
- const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
1475
- const clippingAncestors = [...elementClippingAncestors, rootBoundary];
1476
- const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
1477
- let top = firstRect.top;
1478
- let right = firstRect.right;
1479
- let bottom = firstRect.bottom;
1480
- let left = firstRect.left;
1481
- for (let i = 1; i < clippingAncestors.length; i++) {
1482
- const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
1483
- top = max(rect.top, top);
1484
- right = min(rect.right, right);
1485
- bottom = min(rect.bottom, bottom);
1486
- left = max(rect.left, left);
1487
- }
1488
- return {
1489
- width: right - left,
1490
- height: bottom - top,
1491
- x: left,
1492
- y: top
1493
- };
1494
- }
1495
-
1496
- function getDimensions(element) {
1497
- const {
1498
- width,
1499
- height
1500
- } = getCssDimensions(element);
1501
- return {
1502
- width,
1503
- height
1504
- };
1505
- }
1506
-
1507
- function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1508
- const isOffsetParentAnElement = isHTMLElement(offsetParent);
1509
- const documentElement = getDocumentElement(offsetParent);
1510
- const isFixed = strategy === 'fixed';
1511
- const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1512
- let scroll = {
1513
- scrollLeft: 0,
1514
- scrollTop: 0
1515
- };
1516
- const offsets = createCoords(0);
1517
-
1518
- // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
1519
- // Firefox with layout.scrollbar.side = 3 in about:config to test this.
1520
- function setLeftRTLScrollbarOffset() {
1521
- offsets.x = getWindowScrollBarX(documentElement);
1522
- }
1523
- if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1524
- if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
1525
- scroll = getNodeScroll(offsetParent);
1526
- }
1527
- if (isOffsetParentAnElement) {
1528
- const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1529
- offsets.x = offsetRect.x + offsetParent.clientLeft;
1530
- offsets.y = offsetRect.y + offsetParent.clientTop;
1531
- } else if (documentElement) {
1532
- setLeftRTLScrollbarOffset();
1533
- }
1534
- }
1535
- if (isFixed && !isOffsetParentAnElement && documentElement) {
1536
- setLeftRTLScrollbarOffset();
1537
- }
1538
- const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1539
- const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
1540
- const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
1541
- return {
1542
- x,
1543
- y,
1544
- width: rect.width,
1545
- height: rect.height
1546
- };
1547
- }
1548
-
1549
- function isStaticPositioned(element) {
1550
- return getComputedStyle$1(element).position === 'static';
1551
- }
1552
-
1553
- function getTrueOffsetParent(element, polyfill) {
1554
- if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
1555
- return null;
1556
- }
1557
- if (polyfill) {
1558
- return polyfill(element);
1559
- }
1560
- let rawOffsetParent = element.offsetParent;
1561
-
1562
- // Firefox returns the <html> element as the offsetParent if it's non-static,
1563
- // while Chrome and Safari return the <body> element. The <body> element must
1564
- // be used to perform the correct calculations even if the <html> element is
1565
- // non-static.
1566
- if (getDocumentElement(element) === rawOffsetParent) {
1567
- rawOffsetParent = rawOffsetParent.ownerDocument.body;
1568
- }
1569
- return rawOffsetParent;
1570
- }
1571
-
1572
- // Gets the closest ancestor positioned element. Handles some edge cases,
1573
- // such as table ancestors and cross browser bugs.
1574
- function getOffsetParent(element, polyfill) {
1575
- const win = getWindow(element);
1576
- if (isTopLayer(element)) {
1577
- return win;
1578
- }
1579
- if (!isHTMLElement(element)) {
1580
- let svgOffsetParent = getParentNode(element);
1581
- while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
1582
- if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
1583
- return svgOffsetParent;
1584
- }
1585
- svgOffsetParent = getParentNode(svgOffsetParent);
1586
- }
1587
- return win;
1588
- }
1589
- let offsetParent = getTrueOffsetParent(element, polyfill);
1590
- while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
1591
- offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1592
- }
1593
- if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
1594
- return win;
1595
- }
1596
- return offsetParent || getContainingBlock(element) || win;
1597
- }
1598
-
1599
- const getElementRects = async function (data) {
1600
- const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1601
- const getDimensionsFn = this.getDimensions;
1602
- const floatingDimensions = await getDimensionsFn(data.floating);
1603
- return {
1604
- reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
1605
- floating: {
1606
- x: 0,
1607
- y: 0,
1608
- width: floatingDimensions.width,
1609
- height: floatingDimensions.height
1610
- }
1611
- };
1612
- };
1613
-
1614
- function isRTL(element) {
1615
- return getComputedStyle$1(element).direction === 'rtl';
1616
- }
1617
-
1618
- const platform = {
1619
- convertOffsetParentRelativeRectToViewportRelativeRect,
1620
- getDocumentElement,
1621
- getClippingRect,
1622
- getOffsetParent,
1623
- getElementRects,
1624
- getClientRects,
1625
- getDimensions,
1626
- getScale,
1627
- isElement,
1628
- isRTL
1629
- };
1630
-
1631
- function rectsAreEqual(a, b) {
1632
- return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
1633
- }
1634
-
1635
- // https://samthor.au/2021/observing-dom/
1636
- function observeMove(element, onMove) {
1637
- let io = null;
1638
- let timeoutId;
1639
- const root = getDocumentElement(element);
1640
- function cleanup() {
1641
- var _io;
1642
- clearTimeout(timeoutId);
1643
- (_io = io) == null || _io.disconnect();
1644
- io = null;
1645
- }
1646
- function refresh(skip, threshold) {
1647
- if (skip === void 0) {
1648
- skip = false;
1649
- }
1650
- if (threshold === void 0) {
1651
- threshold = 1;
1652
- }
1653
- cleanup();
1654
- const elementRectForRootMargin = element.getBoundingClientRect();
1655
- const {
1656
- left,
1657
- top,
1658
- width,
1659
- height
1660
- } = elementRectForRootMargin;
1661
- if (!skip) {
1662
- onMove();
1663
- }
1664
- if (!width || !height) {
1665
- return;
1666
- }
1667
- const insetTop = floor(top);
1668
- const insetRight = floor(root.clientWidth - (left + width));
1669
- const insetBottom = floor(root.clientHeight - (top + height));
1670
- const insetLeft = floor(left);
1671
- const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
1672
- const options = {
1673
- rootMargin,
1674
- threshold: max(0, min(1, threshold)) || 1
1675
- };
1676
- let isFirstUpdate = true;
1677
- function handleObserve(entries) {
1678
- const ratio = entries[0].intersectionRatio;
1679
- if (ratio !== threshold) {
1680
- if (!isFirstUpdate) {
1681
- return refresh();
1682
- }
1683
- if (!ratio) {
1684
- // If the reference is clipped, the ratio is 0. Throttle the refresh
1685
- // to prevent an infinite loop of updates.
1686
- timeoutId = setTimeout(() => {
1687
- refresh(false, 1e-7);
1688
- }, 1000);
1689
- } else {
1690
- refresh(false, ratio);
1691
- }
1692
- }
1693
- if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
1694
- // It's possible that even though the ratio is reported as 1, the
1695
- // element is not actually fully within the IntersectionObserver's root
1696
- // area anymore. This can happen under performance constraints. This may
1697
- // be a bug in the browser's IntersectionObserver implementation. To
1698
- // work around this, we compare the element's bounding rect now with
1699
- // what it was at the time we created the IntersectionObserver. If they
1700
- // are not equal then the element moved, so we refresh.
1701
- refresh();
1702
- }
1703
- isFirstUpdate = false;
1704
- }
1705
-
1706
- // Older browsers don't support a `document` as the root and will throw an
1707
- // error.
1708
- try {
1709
- io = new IntersectionObserver(handleObserve, {
1710
- ...options,
1711
- // Handle <iframe>s
1712
- root: root.ownerDocument
1713
- });
1714
- } catch (_e) {
1715
- io = new IntersectionObserver(handleObserve, options);
1716
- }
1717
- io.observe(element);
1718
- }
1719
- refresh(true);
1720
- return cleanup;
1721
- }
1722
-
1723
- /**
1724
- * Automatically updates the position of the floating element when necessary.
1725
- * Should only be called when the floating element is mounted on the DOM or
1726
- * visible on the screen.
1727
- * @returns cleanup function that should be invoked when the floating element is
1728
- * removed from the DOM or hidden from the screen.
1729
- * @see https://floating-ui.com/docs/autoUpdate
1730
- */
1731
- function autoUpdate(reference, floating, update, options) {
1732
- if (options === void 0) {
1733
- options = {};
1734
- }
1735
- const {
1736
- ancestorScroll = true,
1737
- ancestorResize = true,
1738
- elementResize = typeof ResizeObserver === 'function',
1739
- layoutShift = typeof IntersectionObserver === 'function',
1740
- animationFrame = false
1741
- } = options;
1742
- const referenceEl = unwrapElement(reference);
1743
- const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...(floating ? getOverflowAncestors(floating) : [])] : [];
1744
- ancestors.forEach(ancestor => {
1745
- ancestorScroll && ancestor.addEventListener('scroll', update, {
1746
- passive: true
1747
- });
1748
- ancestorResize && ancestor.addEventListener('resize', update);
1749
- });
1750
- const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
1751
- let reobserveFrame = -1;
1752
- let resizeObserver = null;
1753
- if (elementResize) {
1754
- resizeObserver = new ResizeObserver(_ref => {
1755
- let [firstEntry] = _ref;
1756
- if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
1757
- // Prevent update loops when using the `size` middleware.
1758
- // https://github.com/floating-ui/floating-ui/issues/1740
1759
- resizeObserver.unobserve(floating);
1760
- cancelAnimationFrame(reobserveFrame);
1761
- reobserveFrame = requestAnimationFrame(() => {
1762
- var _resizeObserver;
1763
- (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
1764
- });
1765
- }
1766
- update();
1767
- });
1768
- if (referenceEl && !animationFrame) {
1769
- resizeObserver.observe(referenceEl);
1770
- }
1771
- if (floating) {
1772
- resizeObserver.observe(floating);
1773
- }
1774
- }
1775
- let frameId;
1776
- let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
1777
- if (animationFrame) {
1778
- frameLoop();
1779
- }
1780
- function frameLoop() {
1781
- const nextRefRect = getBoundingClientRect(reference);
1782
- if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
1783
- update();
1784
- }
1785
- prevRefRect = nextRefRect;
1786
- frameId = requestAnimationFrame(frameLoop);
1787
- }
1788
- update();
1789
- return () => {
1790
- var _resizeObserver2;
1791
- ancestors.forEach(ancestor => {
1792
- ancestorScroll && ancestor.removeEventListener('scroll', update);
1793
- ancestorResize && ancestor.removeEventListener('resize', update);
1794
- });
1795
- cleanupIo == null || cleanupIo();
1796
- (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
1797
- resizeObserver = null;
1798
- if (animationFrame) {
1799
- cancelAnimationFrame(frameId);
1800
- }
1801
- };
1802
- }
1803
-
1804
- /**
1805
- * Modifies the placement by translating the floating element along the
1806
- * specified axes.
1807
- * A number (shorthand for `mainAxis` or distance), or an axes configuration
1808
- * object may be passed.
1809
- * @see https://floating-ui.com/docs/offset
1810
- */
1811
- const offset$1 = offset$2;
1812
-
1813
- /**
1814
- * Optimizes the visibility of the floating element by shifting it in order to
1815
- * keep it in view when it will overflow the clipping boundary.
1816
- * @see https://floating-ui.com/docs/shift
1817
- */
1818
- const shift$1 = shift$2;
1819
-
1820
- /**
1821
- * Optimizes the visibility of the floating element by flipping the `placement`
1822
- * in order to keep it in view when the preferred placement(s) will overflow the
1823
- * clipping boundary. Alternative to `autoPlacement`.
1824
- * @see https://floating-ui.com/docs/flip
1825
- */
1826
- const flip$1 = flip$2;
1827
-
1828
- /**
1829
- * Provides data that allows you to change the size of the floating element —
1830
- * for instance, prevent it from overflowing the clipping boundary or match the
1831
- * width of the reference element.
1832
- * @see https://floating-ui.com/docs/size
1833
- */
1834
- const size$1 = size$2;
1835
-
1836
- /**
1837
- * Provides data to hide the floating element in applicable situations, such as
1838
- * when it is not in the same clipping context as the reference element.
1839
- * @see https://floating-ui.com/docs/hide
1840
- */
1841
- const hide$1 = hide$2;
1842
-
1843
- /**
1844
- * Provides data to position an inner element of the floating element so that it
1845
- * appears centered to the reference element.
1846
- * @see https://floating-ui.com/docs/arrow
1847
- */
1848
- const arrow$2 = arrow$3;
1849
-
1850
- /**
1851
- * Built-in `limiter` that will stop `shift()` at a certain point.
1852
- */
1853
- const limitShift$1 = limitShift$2;
1854
-
1855
- /**
1856
- * Computes the `x` and `y` coordinates that will place the floating element
1857
- * next to a given reference element.
1858
- */
1859
- const computePosition = (reference, floating, options) => {
1860
- // This caches the expensive `getClippingElementAncestors` function so that
1861
- // multiple lifecycle resets re-use the same result. It only lives for a
1862
- // single call. If other functions become expensive, we can add them as well.
1863
- const cache = new Map();
1864
- const mergedOptions = {
1865
- platform,
1866
- ...options
1867
- };
1868
- const platformWithCache = {
1869
- ...mergedOptions.platform,
1870
- _c: cache
1871
- };
1872
- return computePosition$1(reference, floating, {
1873
- ...mergedOptions,
1874
- platform: platformWithCache
1875
- });
1876
- };
1877
-
1878
- var isClient = typeof document !== 'undefined';
1879
-
1880
- var noop = function noop() {};
1881
- var index = isClient ? useLayoutEffect : noop;
1882
-
1883
- // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1884
- // functions
1885
- function deepEqual(a, b) {
1886
- if (a === b) {
1887
- return true;
1888
- }
1889
- if (typeof a !== typeof b) {
1890
- return false;
1891
- }
1892
- if (typeof a === 'function' && a.toString() === b.toString()) {
1893
- return true;
1894
- }
1895
- let length;
1896
- let i;
1897
- let keys;
1898
- if (a && b && typeof a === 'object') {
1899
- if (Array.isArray(a)) {
1900
- length = a.length;
1901
- if (length !== b.length) return false;
1902
- for (i = length; i-- !== 0;) {
1903
- if (!deepEqual(a[i], b[i])) {
1904
- return false;
1905
- }
1906
- }
1907
- return true;
1908
- }
1909
- keys = Object.keys(a);
1910
- length = keys.length;
1911
- if (length !== Object.keys(b).length) {
1912
- return false;
1913
- }
1914
- for (i = length; i-- !== 0;) {
1915
- if (!{}.hasOwnProperty.call(b, keys[i])) {
1916
- return false;
1917
- }
1918
- }
1919
- for (i = length; i-- !== 0;) {
1920
- const key = keys[i];
1921
- if (key === '_owner' && a.$$typeof) {
1922
- continue;
1923
- }
1924
- if (!deepEqual(a[key], b[key])) {
1925
- return false;
1926
- }
1927
- }
1928
- return true;
1929
- }
1930
- return a !== a && b !== b;
1931
- }
1932
-
1933
- function getDPR(element) {
1934
- if (typeof window === 'undefined') {
1935
- return 1;
1936
- }
1937
- const win = element.ownerDocument.defaultView || window;
1938
- return win.devicePixelRatio || 1;
1939
- }
1940
-
1941
- function roundByDPR(element, value) {
1942
- const dpr = getDPR(element);
1943
- return Math.round(value * dpr) / dpr;
1944
- }
1945
-
1946
- function useLatestRef(value) {
1947
- const ref = React.useRef(value);
1948
- index(() => {
1949
- ref.current = value;
1950
- });
1951
- return ref;
1952
- }
1953
-
1954
- /**
1955
- * Provides data to position a floating element.
1956
- * @see https://floating-ui.com/docs/useFloating
1957
- */
1958
- function useFloating(options) {
1959
- if (options === void 0) {
1960
- options = {};
1961
- }
1962
- const {
1963
- placement = 'bottom',
1964
- strategy = 'absolute',
1965
- middleware = [],
1966
- platform,
1967
- elements: {
1968
- reference: externalReference,
1969
- floating: externalFloating
1970
- } = {},
1971
- transform = true,
1972
- whileElementsMounted,
1973
- open
1974
- } = options;
1975
- const [data, setData] = React.useState({
1976
- x: 0,
1977
- y: 0,
1978
- strategy,
1979
- placement,
1980
- middlewareData: {},
1981
- isPositioned: false
1982
- });
1983
- const [latestMiddleware, setLatestMiddleware] = React.useState(middleware);
1984
- if (!deepEqual(latestMiddleware, middleware)) {
1985
- setLatestMiddleware(middleware);
1986
- }
1987
- const [_reference, _setReference] = React.useState(null);
1988
- const [_floating, _setFloating] = React.useState(null);
1989
- const setReference = React.useCallback(node => {
1990
- if (node !== referenceRef.current) {
1991
- referenceRef.current = node;
1992
- _setReference(node);
1993
- }
1994
- }, []);
1995
- const setFloating = React.useCallback(node => {
1996
- if (node !== floatingRef.current) {
1997
- floatingRef.current = node;
1998
- _setFloating(node);
1999
- }
2000
- }, []);
2001
- const referenceEl = externalReference || _reference;
2002
- const floatingEl = externalFloating || _floating;
2003
- const referenceRef = React.useRef(null);
2004
- const floatingRef = React.useRef(null);
2005
- const dataRef = React.useRef(data);
2006
- const hasWhileElementsMounted = whileElementsMounted != null;
2007
- const whileElementsMountedRef = useLatestRef(whileElementsMounted);
2008
- const platformRef = useLatestRef(platform);
2009
- const openRef = useLatestRef(open);
2010
- const update = React.useCallback(() => {
2011
- if (!referenceRef.current || !floatingRef.current) {
2012
- return;
2013
- }
2014
- const config = {
2015
- placement,
2016
- strategy,
2017
- middleware: latestMiddleware
2018
- };
2019
- if (platformRef.current) {
2020
- config.platform = platformRef.current;
2021
- }
2022
- computePosition(referenceRef.current, floatingRef.current, config).then(data => {
2023
- const fullData = {
2024
- ...data,
2025
- // The floating element's position may be recomputed while it's closed
2026
- // but still mounted (such as when transitioning out). To ensure
2027
- // `isPositioned` will be `false` initially on the next open, avoid
2028
- // setting it to `true` when `open === false` (must be specified).
2029
- isPositioned: openRef.current !== false
2030
- };
2031
- if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
2032
- dataRef.current = fullData;
2033
- ReactDOM.flushSync(() => {
2034
- setData(fullData);
2035
- });
2036
- }
2037
- });
2038
- }, [latestMiddleware, placement, strategy, platformRef, openRef]);
2039
- index(() => {
2040
- if (open === false && dataRef.current.isPositioned) {
2041
- dataRef.current.isPositioned = false;
2042
- setData(data => ({
2043
- ...data,
2044
- isPositioned: false
2045
- }));
2046
- }
2047
- }, [open]);
2048
- const isMountedRef = React.useRef(false);
2049
- index(() => {
2050
- isMountedRef.current = true;
2051
- return () => {
2052
- isMountedRef.current = false;
2053
- };
2054
- }, []);
2055
- index(() => {
2056
- if (referenceEl) referenceRef.current = referenceEl;
2057
- if (floatingEl) floatingRef.current = floatingEl;
2058
- if (referenceEl && floatingEl) {
2059
- if (whileElementsMountedRef.current) {
2060
- return whileElementsMountedRef.current(referenceEl, floatingEl, update);
2061
- }
2062
- update();
2063
- }
2064
- }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
2065
- const refs = React.useMemo(() => ({
2066
- reference: referenceRef,
2067
- floating: floatingRef,
2068
- setReference,
2069
- setFloating
2070
- }), [setReference, setFloating]);
2071
- const elements = React.useMemo(() => ({
2072
- reference: referenceEl,
2073
- floating: floatingEl
2074
- }), [referenceEl, floatingEl]);
2075
- const floatingStyles = React.useMemo(() => {
2076
- const initialStyles = {
2077
- position: strategy,
2078
- left: 0,
2079
- top: 0
2080
- };
2081
- if (!elements.floating) {
2082
- return initialStyles;
2083
- }
2084
- const x = roundByDPR(elements.floating, data.x);
2085
- const y = roundByDPR(elements.floating, data.y);
2086
- if (transform) {
2087
- return {
2088
- ...initialStyles,
2089
- transform: "translate(" + x + "px, " + y + "px)",
2090
- ...(getDPR(elements.floating) >= 1.5 && {
2091
- willChange: 'transform'
2092
- })
2093
- };
2094
- }
2095
- return {
2096
- position: strategy,
2097
- left: x,
2098
- top: y
2099
- };
2100
- }, [strategy, transform, elements.floating, data.x, data.y]);
2101
- return React.useMemo(() => ({
2102
- ...data,
2103
- update,
2104
- refs,
2105
- elements,
2106
- floatingStyles
2107
- }), [data, update, refs, elements, floatingStyles]);
2108
- }
2109
-
2110
- /**
2111
- * Provides data to position an inner element of the floating element so that it
2112
- * appears centered to the reference element.
2113
- * This wraps the core `arrow` middleware to allow React refs as the element.
2114
- * @see https://floating-ui.com/docs/arrow
2115
- */
2116
- const arrow$1 = options => {
2117
- function isRef(value) {
2118
- return {}.hasOwnProperty.call(value, 'current');
2119
- }
2120
- return {
2121
- name: 'arrow',
2122
- options,
2123
- fn(state) {
2124
- const {
2125
- element,
2126
- padding
2127
- } = typeof options === 'function' ? options(state) : options;
2128
- if (element && isRef(element)) {
2129
- if (element.current != null) {
2130
- return arrow$2({
2131
- element: element.current,
2132
- padding
2133
- }).fn(state);
2134
- }
2135
- return {};
2136
- }
2137
- if (element) {
2138
- return arrow$2({
2139
- element,
2140
- padding
2141
- }).fn(state);
2142
- }
2143
- return {};
2144
- }
2145
- };
2146
- };
2147
-
2148
- /**
2149
- * Modifies the placement by translating the floating element along the
2150
- * specified axes.
2151
- * A number (shorthand for `mainAxis` or distance), or an axes configuration
2152
- * object may be passed.
2153
- * @see https://floating-ui.com/docs/offset
2154
- */
2155
- const offset = (options, deps) => {
2156
- const result = offset$1(options);
2157
- return {
2158
- name: result.name,
2159
- fn: result.fn,
2160
- options: [options, deps]
2161
- };
2162
- };
2163
-
2164
- /**
2165
- * Optimizes the visibility of the floating element by shifting it in order to
2166
- * keep it in view when it will overflow the clipping boundary.
2167
- * @see https://floating-ui.com/docs/shift
2168
- */
2169
- const shift = (options, deps) => {
2170
- const result = shift$1(options);
2171
- return {
2172
- name: result.name,
2173
- fn: result.fn,
2174
- options: [options, deps]
2175
- };
2176
- };
2177
-
2178
- /**
2179
- * Built-in `limiter` that will stop `shift()` at a certain point.
2180
- */
2181
- const limitShift = (options, deps) => {
2182
- const result = limitShift$1(options);
2183
- return {
2184
- fn: result.fn,
2185
- options: [options, deps]
2186
- };
2187
- };
2188
-
2189
- /**
2190
- * Optimizes the visibility of the floating element by flipping the `placement`
2191
- * in order to keep it in view when the preferred placement(s) will overflow the
2192
- * clipping boundary. Alternative to `autoPlacement`.
2193
- * @see https://floating-ui.com/docs/flip
2194
- */
2195
- const flip = (options, deps) => {
2196
- const result = flip$1(options);
2197
- return {
2198
- name: result.name,
2199
- fn: result.fn,
2200
- options: [options, deps]
2201
- };
2202
- };
2203
-
2204
- /**
2205
- * Provides data that allows you to change the size of the floating element —
2206
- * for instance, prevent it from overflowing the clipping boundary or match the
2207
- * width of the reference element.
2208
- * @see https://floating-ui.com/docs/size
2209
- */
2210
- const size = (options, deps) => {
2211
- const result = size$1(options);
2212
- return {
2213
- name: result.name,
2214
- fn: result.fn,
2215
- options: [options, deps]
2216
- };
2217
- };
2218
-
2219
- /**
2220
- * Provides data to hide the floating element in applicable situations, such as
2221
- * when it is not in the same clipping context as the reference element.
2222
- * @see https://floating-ui.com/docs/hide
2223
- */
2224
- const hide = (options, deps) => {
2225
- const result = hide$1(options);
2226
- return {
2227
- name: result.name,
2228
- fn: result.fn,
2229
- options: [options, deps]
2230
- };
2231
- };
2232
-
2233
- /**
2234
- * Provides data to position an inner element of the floating element so that it
2235
- * appears centered to the reference element.
2236
- * This wraps the core `arrow` middleware to allow React refs as the element.
2237
- * @see https://floating-ui.com/docs/arrow
2238
- */
2239
- const arrow = (options, deps) => {
2240
- const result = arrow$1(options);
2241
- return {
2242
- name: result.name,
2243
- fn: result.fn,
2244
- options: [options, deps]
2245
- };
2246
- };
2247
-
2248
- // src/arrow.tsx
2249
- var NAME = "Arrow";
2250
- var Arrow$1 = React.forwardRef((props, forwardedRef) => {
2251
- const { children, width = 10, height = 5, ...arrowProps } = props;
2252
- return /* @__PURE__ */ jsx(
2253
- Primitive.svg,
2254
- {
2255
- ...arrowProps,
2256
- ref: forwardedRef,
2257
- width,
2258
- height,
2259
- viewBox: "0 0 30 10",
2260
- preserveAspectRatio: "none",
2261
- children: props.asChild ? children : /* @__PURE__ */ jsx("polygon", { points: "0,0 30,0 15,10" })
2262
- }
2263
- );
2264
- });
2265
- Arrow$1.displayName = NAME;
2266
- var Root = Arrow$1;
2267
-
2268
- // packages/react/use-size/src/use-size.tsx
2269
- function useSize(element) {
2270
- const [size, setSize] = React.useState(void 0);
2271
- useLayoutEffect2(() => {
2272
- if (element) {
2273
- setSize({ width: element.offsetWidth, height: element.offsetHeight });
2274
- const resizeObserver = new ResizeObserver((entries) => {
2275
- if (!Array.isArray(entries)) {
2276
- return;
2277
- }
2278
- if (!entries.length) {
2279
- return;
2280
- }
2281
- const entry = entries[0];
2282
- let width;
2283
- let height;
2284
- if ("borderBoxSize" in entry) {
2285
- const borderSizeEntry = entry["borderBoxSize"];
2286
- const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
2287
- width = borderSize["inlineSize"];
2288
- height = borderSize["blockSize"];
2289
- } else {
2290
- width = element.offsetWidth;
2291
- height = element.offsetHeight;
2292
- }
2293
- setSize({ width, height });
2294
- });
2295
- resizeObserver.observe(element, { box: "border-box" });
2296
- return () => resizeObserver.unobserve(element);
2297
- } else {
2298
- setSize(void 0);
2299
- }
2300
- }, [element]);
2301
- return size;
2302
- }
2303
-
2304
- var POPPER_NAME = "Popper";
2305
- var [createPopperContext, createPopperScope] = createContextScope(POPPER_NAME);
2306
- var [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
2307
- var Popper = (props) => {
2308
- const { __scopePopper, children } = props;
2309
- const [anchor, setAnchor] = React.useState(null);
2310
- return /* @__PURE__ */ jsx(PopperProvider, { scope: __scopePopper, anchor, onAnchorChange: setAnchor, children });
2311
- };
2312
- Popper.displayName = POPPER_NAME;
2313
- var ANCHOR_NAME = "PopperAnchor";
2314
- var PopperAnchor = React.forwardRef(
2315
- (props, forwardedRef) => {
2316
- const { __scopePopper, virtualRef, ...anchorProps } = props;
2317
- const context = usePopperContext(ANCHOR_NAME, __scopePopper);
2318
- const ref = React.useRef(null);
2319
- const composedRefs = useComposedRefs(forwardedRef, ref);
2320
- const anchorRef = React.useRef(null);
2321
- React.useEffect(() => {
2322
- const previousAnchor = anchorRef.current;
2323
- anchorRef.current = virtualRef?.current || ref.current;
2324
- if (previousAnchor !== anchorRef.current) {
2325
- context.onAnchorChange(anchorRef.current);
2326
- }
2327
- });
2328
- return virtualRef ? null : /* @__PURE__ */ jsx(Primitive.div, { ...anchorProps, ref: composedRefs });
2329
- }
2330
- );
2331
- PopperAnchor.displayName = ANCHOR_NAME;
2332
- var CONTENT_NAME = "PopperContent";
2333
- var [PopperContentProvider, useContentContext] = createPopperContext(CONTENT_NAME);
2334
- var PopperContent = React.forwardRef(
2335
- (props, forwardedRef) => {
2336
- const {
2337
- __scopePopper,
2338
- side = "bottom",
2339
- sideOffset = 0,
2340
- align = "center",
2341
- alignOffset = 0,
2342
- arrowPadding = 0,
2343
- avoidCollisions = true,
2344
- collisionBoundary = [],
2345
- collisionPadding: collisionPaddingProp = 0,
2346
- sticky = "partial",
2347
- hideWhenDetached = false,
2348
- updatePositionStrategy = "optimized",
2349
- onPlaced,
2350
- ...contentProps
2351
- } = props;
2352
- const context = usePopperContext(CONTENT_NAME, __scopePopper);
2353
- const [content, setContent] = React.useState(null);
2354
- const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
2355
- const [arrow$1, setArrow] = React.useState(null);
2356
- const arrowSize = useSize(arrow$1);
2357
- const arrowWidth = arrowSize?.width ?? 0;
2358
- const arrowHeight = arrowSize?.height ?? 0;
2359
- const desiredPlacement = side + (align !== "center" ? "-" + align : "");
2360
- const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };
2361
- const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
2362
- const hasExplicitBoundaries = boundary.length > 0;
2363
- const detectOverflowOptions = {
2364
- padding: collisionPadding,
2365
- boundary: boundary.filter(isNotNull),
2366
- // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
2367
- altBoundary: hasExplicitBoundaries
2368
- };
2369
- const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({
2370
- // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
2371
- strategy: "fixed",
2372
- placement: desiredPlacement,
2373
- whileElementsMounted: (...args) => {
2374
- const cleanup = autoUpdate(...args, {
2375
- animationFrame: updatePositionStrategy === "always"
2376
- });
2377
- return cleanup;
2378
- },
2379
- elements: {
2380
- reference: context.anchor
2381
- },
2382
- middleware: [
2383
- offset({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),
2384
- avoidCollisions && shift({
2385
- mainAxis: true,
2386
- crossAxis: false,
2387
- limiter: sticky === "partial" ? limitShift() : void 0,
2388
- ...detectOverflowOptions
2389
- }),
2390
- avoidCollisions && flip({ ...detectOverflowOptions }),
2391
- size({
2392
- ...detectOverflowOptions,
2393
- apply: ({ elements, rects, availableWidth, availableHeight }) => {
2394
- const { width: anchorWidth, height: anchorHeight } = rects.reference;
2395
- const contentStyle = elements.floating.style;
2396
- contentStyle.setProperty("--radix-popper-available-width", `${availableWidth}px`);
2397
- contentStyle.setProperty("--radix-popper-available-height", `${availableHeight}px`);
2398
- contentStyle.setProperty("--radix-popper-anchor-width", `${anchorWidth}px`);
2399
- contentStyle.setProperty("--radix-popper-anchor-height", `${anchorHeight}px`);
2400
- }
2401
- }),
2402
- arrow$1 && arrow({ element: arrow$1, padding: arrowPadding }),
2403
- transformOrigin({ arrowWidth, arrowHeight }),
2404
- hideWhenDetached && hide({ strategy: "referenceHidden", ...detectOverflowOptions })
2405
- ]
2406
- });
2407
- const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
2408
- const handlePlaced = useCallbackRef(onPlaced);
2409
- useLayoutEffect2(() => {
2410
- if (isPositioned) {
2411
- handlePlaced?.();
2412
- }
2413
- }, [isPositioned, handlePlaced]);
2414
- const arrowX = middlewareData.arrow?.x;
2415
- const arrowY = middlewareData.arrow?.y;
2416
- const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
2417
- const [contentZIndex, setContentZIndex] = React.useState();
2418
- useLayoutEffect2(() => {
2419
- if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
2420
- }, [content]);
2421
- return /* @__PURE__ */ jsx(
2422
- "div",
2423
- {
2424
- ref: refs.setFloating,
2425
- "data-radix-popper-content-wrapper": "",
2426
- style: {
2427
- ...floatingStyles,
2428
- transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
2429
- // keep off the page when measuring
2430
- minWidth: "max-content",
2431
- zIndex: contentZIndex,
2432
- ["--radix-popper-transform-origin"]: [
2433
- middlewareData.transformOrigin?.x,
2434
- middlewareData.transformOrigin?.y
2435
- ].join(" "),
2436
- // hide the content if using the hide middleware and should be hidden
2437
- // set visibility to hidden and disable pointer events so the UI behaves
2438
- // as if the PopperContent isn't there at all
2439
- ...middlewareData.hide?.referenceHidden && {
2440
- visibility: "hidden",
2441
- pointerEvents: "none"
2442
- }
2443
- },
2444
- dir: props.dir,
2445
- children: /* @__PURE__ */ jsx(
2446
- PopperContentProvider,
2447
- {
2448
- scope: __scopePopper,
2449
- placedSide,
2450
- onArrowChange: setArrow,
2451
- arrowX,
2452
- arrowY,
2453
- shouldHideArrow: cannotCenterArrow,
2454
- children: /* @__PURE__ */ jsx(
2455
- Primitive.div,
2456
- {
2457
- "data-side": placedSide,
2458
- "data-align": placedAlign,
2459
- ...contentProps,
2460
- ref: composedRefs,
2461
- style: {
2462
- ...contentProps.style,
2463
- // if the PopperContent hasn't been placed yet (not all measurements done)
2464
- // we prevent animations so that users's animation don't kick in too early referring wrong sides
2465
- animation: !isPositioned ? "none" : void 0
2466
- }
2467
- }
2468
- )
2469
- }
2470
- )
2471
- }
2472
- );
2473
- }
2474
- );
2475
- PopperContent.displayName = CONTENT_NAME;
2476
- var ARROW_NAME = "PopperArrow";
2477
- var OPPOSITE_SIDE = {
2478
- top: "bottom",
2479
- right: "left",
2480
- bottom: "top",
2481
- left: "right"
2482
- };
2483
- var PopperArrow = React.forwardRef(function PopperArrow2(props, forwardedRef) {
2484
- const { __scopePopper, ...arrowProps } = props;
2485
- const contentContext = useContentContext(ARROW_NAME, __scopePopper);
2486
- const baseSide = OPPOSITE_SIDE[contentContext.placedSide];
2487
- return (
2488
- // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
2489
- // doesn't report size as we'd expect on SVG elements.
2490
- // it reports their bounding box which is effectively the largest path inside the SVG.
2491
- /* @__PURE__ */ jsx(
2492
- "span",
2493
- {
2494
- ref: contentContext.onArrowChange,
2495
- style: {
2496
- position: "absolute",
2497
- left: contentContext.arrowX,
2498
- top: contentContext.arrowY,
2499
- [baseSide]: 0,
2500
- transformOrigin: {
2501
- top: "",
2502
- right: "0 0",
2503
- bottom: "center 0",
2504
- left: "100% 0"
2505
- }[contentContext.placedSide],
2506
- transform: {
2507
- top: "translateY(100%)",
2508
- right: "translateY(50%) rotate(90deg) translateX(-50%)",
2509
- bottom: `rotate(180deg)`,
2510
- left: "translateY(50%) rotate(-90deg) translateX(50%)"
2511
- }[contentContext.placedSide],
2512
- visibility: contentContext.shouldHideArrow ? "hidden" : void 0
2513
- },
2514
- children: /* @__PURE__ */ jsx(
2515
- Root,
2516
- {
2517
- ...arrowProps,
2518
- ref: forwardedRef,
2519
- style: {
2520
- ...arrowProps.style,
2521
- // ensures the element can be measured correctly (mostly for if SVG)
2522
- display: "block"
2523
- }
2524
- }
2525
- )
2526
- }
2527
- )
2528
- );
2529
- });
2530
- PopperArrow.displayName = ARROW_NAME;
2531
- function isNotNull(value) {
2532
- return value !== null;
2533
- }
2534
- var transformOrigin = (options) => ({
2535
- name: "transformOrigin",
2536
- options,
2537
- fn(data) {
2538
- const { placement, rects, middlewareData } = data;
2539
- const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
2540
- const isArrowHidden = cannotCenterArrow;
2541
- const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
2542
- const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
2543
- const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
2544
- const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
2545
- const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
2546
- const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
2547
- let x = "";
2548
- let y = "";
2549
- if (placedSide === "bottom") {
2550
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
2551
- y = `${-arrowHeight}px`;
2552
- } else if (placedSide === "top") {
2553
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
2554
- y = `${rects.floating.height + arrowHeight}px`;
2555
- } else if (placedSide === "right") {
2556
- x = `${-arrowHeight}px`;
2557
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
2558
- } else if (placedSide === "left") {
2559
- x = `${rects.floating.width + arrowHeight}px`;
2560
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
2561
- }
2562
- return { data: { x, y } };
2563
- }
2564
- });
2565
- function getSideAndAlignFromPlacement(placement) {
2566
- const [side, align = "center"] = placement.split("-");
2567
- return [side, align];
2568
- }
2569
- var Root2 = Popper;
2570
- var Anchor = PopperAnchor;
2571
- var Content = PopperContent;
2572
- var Arrow = PopperArrow;
36
+ Node.displayName = `Primitive.${node}`;
37
+ return { ...primitive, [node]: Node };
38
+ }, {});
2573
39
 
2574
- export { Anchor as A, Content as C, Root2 as R, Arrow as a, isHTMLElement as b, createPopperScope as c, useFloating as d, isElement as e, floor as f, getOverflowAncestors as g, isWebKit as h, isShadowRoot as i, isLastTraversableNode as j, getParentNode as k, getComputedStyle$1 as l, isNode as m, getNodeName as n, autoUpdate as o, offset as p, flip as q, shift as s, useSize as u };
40
+ export { Primitive as P };
2575
41
  //# sourceMappingURL=index28.js.map