poetry-core 0.0.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 (166) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/DESIGN.md +145 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +30 -0
  6. data/THIRD_PARTY_NOTICES.md +507 -0
  7. data/app/components/poetry/core/box/component.rb +82 -0
  8. data/app/components/poetry/core/component.rb +390 -0
  9. data/app/components/poetry/core/concerns/agent_tools.rb +418 -0
  10. data/app/components/poetry/core/concerns/declared_attributes.rb +267 -0
  11. data/app/components/poetry/core/concerns/introspection.rb +533 -0
  12. data/app/components/poetry/core/concerns/options.rb +262 -0
  13. data/app/components/poetry/core/concerns/parts.rb +148 -0
  14. data/app/components/poetry/core/concerns/stimulus.rb +363 -0
  15. data/app/components/poetry/core/concerns/styles.rb +323 -0
  16. data/app/components/poetry/core/style.rb +150 -0
  17. data/app/components/poetry/core/wrapper/component.rb +90 -0
  18. data/app/javascript/poetry/core/accordion_controller.js +165 -0
  19. data/app/javascript/poetry/core/action_bar_controller.js +109 -0
  20. data/app/javascript/poetry/core/autocomplete_controller.js +220 -0
  21. data/app/javascript/poetry/core/calendar_controller.js +406 -0
  22. data/app/javascript/poetry/core/carousel_controller.js +167 -0
  23. data/app/javascript/poetry/core/checkbox_group_controller.js +97 -0
  24. data/app/javascript/poetry/core/checked_controller.js +208 -0
  25. data/app/javascript/poetry/core/clipboard_text_controller.js +111 -0
  26. data/app/javascript/poetry/core/combobox_controller.js +1095 -0
  27. data/app/javascript/poetry/core/command_controller.js +510 -0
  28. data/app/javascript/poetry/core/context_menu_controller.js +204 -0
  29. data/app/javascript/poetry/core/date_field_controller.js +584 -0
  30. data/app/javascript/poetry/core/date_picker_controller.js +111 -0
  31. data/app/javascript/poetry/core/deferred_controller.js +111 -0
  32. data/app/javascript/poetry/core/dialog_controller.js +206 -0
  33. data/app/javascript/poetry/core/dismissable_controller.js +182 -0
  34. data/app/javascript/poetry/core/drawer_controller.js +365 -0
  35. data/app/javascript/poetry/core/file_input_controller.js +191 -0
  36. data/app/javascript/poetry/core/focus_scope_controller.js +162 -0
  37. data/app/javascript/poetry/core/helpers/announce.js +228 -0
  38. data/app/javascript/poetry/core/helpers/breakpoint.js +28 -0
  39. data/app/javascript/poetry/core/helpers/collection.js +18 -0
  40. data/app/javascript/poetry/core/helpers/direction.js +15 -0
  41. data/app/javascript/poetry/core/helpers/escape.js +38 -0
  42. data/app/javascript/poetry/core/helpers/filter_rank.js +104 -0
  43. data/app/javascript/poetry/core/helpers/focus_guards.js +46 -0
  44. data/app/javascript/poetry/core/helpers/hotkey.js +43 -0
  45. data/app/javascript/poetry/core/helpers/id_integrity.js +65 -0
  46. data/app/javascript/poetry/core/helpers/incomplete_date.js +328 -0
  47. data/app/javascript/poetry/core/helpers/mask.js +283 -0
  48. data/app/javascript/poetry/core/helpers/portal.js +217 -0
  49. data/app/javascript/poetry/core/helpers/presence.js +210 -0
  50. data/app/javascript/poetry/core/helpers/registration_guard.js +76 -0
  51. data/app/javascript/poetry/core/helpers/scroll_lock.js +67 -0
  52. data/app/javascript/poetry/core/helpers/scroller_geometry.js +422 -0
  53. data/app/javascript/poetry/core/helpers/state.js +80 -0
  54. data/app/javascript/poetry/core/helpers/tabbable.js +56 -0
  55. data/app/javascript/poetry/core/helpers/turbo_cache.js +21 -0
  56. data/app/javascript/poetry/core/helpers/typeahead.js +85 -0
  57. data/app/javascript/poetry/core/hotkey_controller.js +55 -0
  58. data/app/javascript/poetry/core/hover_card_controller.js +431 -0
  59. data/app/javascript/poetry/core/index.js +218 -0
  60. data/app/javascript/poetry/core/mask_controller.js +500 -0
  61. data/app/javascript/poetry/core/menu_controller.js +1050 -0
  62. data/app/javascript/poetry/core/menubar_controller.js +329 -0
  63. data/app/javascript/poetry/core/message_scroller_controller.js +930 -0
  64. data/app/javascript/poetry/core/navigation_menu_controller.js +458 -0
  65. data/app/javascript/poetry/core/number_field_controller.js +404 -0
  66. data/app/javascript/poetry/core/optimistic_form_controller.js +56 -0
  67. data/app/javascript/poetry/core/otp_controller.js +219 -0
  68. data/app/javascript/poetry/core/popover_controller.js +300 -0
  69. data/app/javascript/poetry/core/popper_controller.js +439 -0
  70. data/app/javascript/poetry/core/pressed_controller.js +74 -0
  71. data/app/javascript/poetry/core/questionnaire_controller.js +468 -0
  72. data/app/javascript/poetry/core/radio_group_controller.js +197 -0
  73. data/app/javascript/poetry/core/resizable_controller.js +202 -0
  74. data/app/javascript/poetry/core/roving_focus_controller.js +215 -0
  75. data/app/javascript/poetry/core/scroll_spy_controller.js +84 -0
  76. data/app/javascript/poetry/core/search_field_controller.js +95 -0
  77. data/app/javascript/poetry/core/select_controller.js +924 -0
  78. data/app/javascript/poetry/core/sensitive_input_controller.js +195 -0
  79. data/app/javascript/poetry/core/sheet_controller.js +24 -0
  80. data/app/javascript/poetry/core/sidebar_controller.js +272 -0
  81. data/app/javascript/poetry/core/slider_controller.js +419 -0
  82. data/app/javascript/poetry/core/state_controller.js +82 -0
  83. data/app/javascript/poetry/core/table_selection_controller.js +153 -0
  84. data/app/javascript/poetry/core/tabs_controller.js +151 -0
  85. data/app/javascript/poetry/core/tag_group_controller.js +134 -0
  86. data/app/javascript/poetry/core/toast_controller.js +228 -0
  87. data/app/javascript/poetry/core/toast_trigger_controller.js +26 -0
  88. data/app/javascript/poetry/core/toaster_controller.js +197 -0
  89. data/app/javascript/poetry/core/toggle_group_controller.js +206 -0
  90. data/app/javascript/poetry/core/tooltip_controller.js +541 -0
  91. data/app/javascript/poetry/core/tree_controller.js +265 -0
  92. data/app/javascript/poetry/core/vendor/floating_ui_core.js +1043 -0
  93. data/app/javascript/poetry/core/vendor/floating_ui_dom.js +794 -0
  94. data/app/javascript/poetry/core/vendor/floating_ui_utils.js +141 -0
  95. data/app/javascript/poetry/core/vendor/floating_ui_utils_dom.js +170 -0
  96. data/app/views/poetry/core/preview.html.erb +13 -0
  97. data/config/component_registry.yml +20 -0
  98. data/config/controllers_manifest.json +1528 -0
  99. data/config/importmap.rb +11 -0
  100. data/config/state_vocabulary.json +31 -0
  101. data/lib/active_model/type/list.rb +33 -0
  102. data/lib/active_model/type/symbol.rb +36 -0
  103. data/lib/poetry/core/check/stable_identity.rb +104 -0
  104. data/lib/poetry/core/check.rb +1445 -0
  105. data/lib/poetry/core/config.rb +286 -0
  106. data/lib/poetry/core/contrib/wrapped_helper.rb +68 -0
  107. data/lib/poetry/core/css/bem_merger.rb +45 -0
  108. data/lib/poetry/core/css/bem_reference.rb +87 -0
  109. data/lib/poetry/core/css/override_scan.rb +110 -0
  110. data/lib/poetry/core/css/resolver.rb +161 -0
  111. data/lib/poetry/core/css/safelist.rb +41 -0
  112. data/lib/poetry/core/css/tailwind_merger.rb +102 -0
  113. data/lib/poetry/core/css/template_classes.rb +102 -0
  114. data/lib/poetry/core/css/theme_coverage.rb +72 -0
  115. data/lib/poetry/core/css/var_coverage.rb +75 -0
  116. data/lib/poetry/core/css/verifier.rb +106 -0
  117. data/lib/poetry/core/design_lint.rb +720 -0
  118. data/lib/poetry/core/design_md/import.rb +250 -0
  119. data/lib/poetry/core/design_md.rb +461 -0
  120. data/lib/poetry/core/engine.rb +71 -0
  121. data/lib/poetry/core/errors.rb +53 -0
  122. data/lib/poetry/core/html/attributes.rb +667 -0
  123. data/lib/poetry/core/icons.rb +157 -0
  124. data/lib/poetry/core/llms_text.rb +354 -0
  125. data/lib/poetry/core/page_architectures.rb +304 -0
  126. data/lib/poetry/core/part_contract.rb +285 -0
  127. data/lib/poetry/core/preview/abstract.rb +121 -0
  128. data/lib/poetry/core/preview/base.rb +227 -0
  129. data/lib/poetry/core/preview/sidecarable.rb +136 -0
  130. data/lib/poetry/core/preview/template.rb +186 -0
  131. data/lib/poetry/core/recipe_items.rb +82 -0
  132. data/lib/poetry/core/registry.rb +363 -0
  133. data/lib/poetry/core/registry_address.rb +115 -0
  134. data/lib/poetry/core/registry_client.rb +217 -0
  135. data/lib/poetry/core/registry_installer.rb +234 -0
  136. data/lib/poetry/core/registry_items.rb +184 -0
  137. data/lib/poetry/core/skill_text.rb +288 -0
  138. data/lib/poetry/core/stable_id.rb +110 -0
  139. data/lib/poetry/core/stimulus/builder.rb +395 -0
  140. data/lib/poetry/core/stimulus/declarations.rb +444 -0
  141. data/lib/poetry/core/stimulus/manifest.rb +68 -0
  142. data/lib/poetry/core/stimulus/merger.rb +131 -0
  143. data/lib/poetry/core/stimulus_contract.rb +263 -0
  144. data/lib/poetry/core/tag_helper.rb +10 -0
  145. data/lib/poetry/core/template_compile.rb +74 -0
  146. data/lib/poetry/core/token_import.rb +317 -0
  147. data/lib/poetry/core/tokens/color.rb +215 -0
  148. data/lib/poetry/core/tokens/contrast_gate.rb +120 -0
  149. data/lib/poetry/core/tokens/generator.rb +211 -0
  150. data/lib/poetry/core/tokens.rb +117 -0
  151. data/lib/poetry/core/version.rb +9 -0
  152. data/lib/poetry/core.rb +52 -0
  153. data/lib/poetry-core.rb +5 -0
  154. data/tokens/aliases.css +145 -0
  155. data/tokens/tailwind-theme.css +47 -0
  156. data/tokens/tokens.css +78 -0
  157. data/tokens/tokens.dtcg.json +779 -0
  158. data/vendor/floating-ui/LICENSE +20 -0
  159. data/vendor/floating-ui/VENDORED_VERSIONS +15 -0
  160. data/vendor/shadcn-tailwind/LICENSE +21 -0
  161. data/vendor/shadcn-tailwind/VENDORED_COMMIT +1 -0
  162. data/vendor/shadcn-tailwind/tailwind.css +629 -0
  163. data/vendor/tw-animate-css/LICENSE +21 -0
  164. data/vendor/tw-animate-css/VENDORED_VERSION +1 -0
  165. data/vendor/tw-animate-css/tw-animate.css +1 -0
  166. metadata +267 -0
@@ -0,0 +1,1043 @@
1
+ // Vendored from @floating-ui/core@1.8.0 (dist/floating-ui.core.mjs, MIT) - DO NOT EDIT.
2
+ // Import specifiers rewritten to @poetry/controllers/vendor/* so the file
3
+ // resolves via the importmap pins AND the npm exports map.
4
+ // Versions + license: vendor/floating-ui/ (repo root). Update by re-running
5
+ // the vendoring steps there against a newer npm tarball.
6
+ import { getSideAxis, getAlignmentAxis, getAxisLength, getSide, getAlignment, evaluate, getPaddingObject, rectToClientRect, min, clamp, placements, getAlignmentSides, getOppositeAlignmentPlacement, getOppositePlacement, getExpandedPlacements, getOppositeAxisPlacements, sides, max, getOppositeAxis } from '@poetry/controllers/vendor/floating_ui_utils';
7
+ export { rectToClientRect } from '@poetry/controllers/vendor/floating_ui_utils';
8
+
9
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
10
+ let {
11
+ reference,
12
+ floating
13
+ } = _ref;
14
+ const sideAxis = getSideAxis(placement);
15
+ const alignmentAxis = getAlignmentAxis(placement);
16
+ const alignLength = getAxisLength(alignmentAxis);
17
+ const side = getSide(placement);
18
+ const isVertical = sideAxis === 'y';
19
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
20
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
21
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
22
+ let coords;
23
+ switch (side) {
24
+ case 'top':
25
+ coords = {
26
+ x: commonX,
27
+ y: reference.y - floating.height
28
+ };
29
+ break;
30
+ case 'bottom':
31
+ coords = {
32
+ x: commonX,
33
+ y: reference.y + reference.height
34
+ };
35
+ break;
36
+ case 'right':
37
+ coords = {
38
+ x: reference.x + reference.width,
39
+ y: commonY
40
+ };
41
+ break;
42
+ case 'left':
43
+ coords = {
44
+ x: reference.x - floating.width,
45
+ y: commonY
46
+ };
47
+ break;
48
+ default:
49
+ coords = {
50
+ x: reference.x,
51
+ y: reference.y
52
+ };
53
+ }
54
+ const alignment = getAlignment(placement);
55
+ if (alignment) {
56
+ coords[alignmentAxis] += commonAlign * (alignment === 'end' ? 1 : -1) * (rtl && isVertical ? -1 : 1);
57
+ }
58
+ return coords;
59
+ }
60
+
61
+ /**
62
+ * Resolves with an object of overflow side offsets that determine how much the
63
+ * element is overflowing a given clipping boundary on each side.
64
+ * - positive = overflowing the boundary by that number of pixels
65
+ * - negative = how many pixels left before it will overflow
66
+ * - 0 = lies flush with the boundary
67
+ * @see https://floating-ui.com/docs/detectOverflow
68
+ */
69
+ async function detectOverflow(state, options) {
70
+ var _await$platform$isEle;
71
+ if (options === void 0) {
72
+ options = {};
73
+ }
74
+ const {
75
+ x,
76
+ y,
77
+ platform,
78
+ rects,
79
+ elements,
80
+ strategy
81
+ } = state;
82
+ const {
83
+ boundary = 'clippingAncestors',
84
+ rootBoundary = 'viewport',
85
+ elementContext = 'floating',
86
+ altBoundary = false,
87
+ padding = 0
88
+ } = evaluate(options, state);
89
+ const paddingObject = getPaddingObject(padding);
90
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
91
+ const element = elements[altBoundary ? altContext : elementContext];
92
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
93
+ 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))),
94
+ boundary,
95
+ rootBoundary,
96
+ strategy
97
+ }));
98
+ const rect = elementContext === 'floating' ? {
99
+ x,
100
+ y,
101
+ width: rects.floating.width,
102
+ height: rects.floating.height
103
+ } : rects.reference;
104
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
105
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) && (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
106
+ x: 1,
107
+ y: 1
108
+ };
109
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
110
+ elements,
111
+ rect,
112
+ offsetParent,
113
+ strategy
114
+ }) : rect);
115
+ return {
116
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
117
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
118
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
119
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
120
+ };
121
+ }
122
+
123
+ // Maximum number of resets that can occur before bailing to avoid infinite reset loops.
124
+ const MAX_RESET_COUNT = 50;
125
+
126
+ /**
127
+ * Computes the `x` and `y` coordinates that will place the floating element
128
+ * next to a given reference element.
129
+ *
130
+ * This export does not have any `platform` interface logic. You will need to
131
+ * write one for the platform you are using Floating UI with.
132
+ */
133
+ const computePosition = async (reference, floating, config) => {
134
+ const {
135
+ placement = 'bottom',
136
+ strategy = 'absolute',
137
+ middleware = [],
138
+ platform
139
+ } = config;
140
+ const platformWithDetectOverflow = platform.detectOverflow ? platform : {
141
+ ...platform,
142
+ detectOverflow
143
+ };
144
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
145
+ let rects = await platform.getElementRects({
146
+ reference,
147
+ floating,
148
+ strategy
149
+ });
150
+ let {
151
+ x,
152
+ y
153
+ } = computeCoordsFromPlacement(rects, placement, rtl);
154
+ let statefulPlacement = placement;
155
+ let resetCount = 0;
156
+ const middlewareData = {};
157
+ for (let i = 0; i < middleware.length; i++) {
158
+ const currentMiddleware = middleware[i];
159
+ if (!currentMiddleware) {
160
+ continue;
161
+ }
162
+ const {
163
+ name,
164
+ fn
165
+ } = currentMiddleware;
166
+ const {
167
+ x: nextX,
168
+ y: nextY,
169
+ data,
170
+ reset
171
+ } = await fn({
172
+ x,
173
+ y,
174
+ initialPlacement: placement,
175
+ placement: statefulPlacement,
176
+ strategy,
177
+ middlewareData,
178
+ rects,
179
+ platform: platformWithDetectOverflow,
180
+ elements: {
181
+ reference,
182
+ floating
183
+ }
184
+ });
185
+ x = nextX != null ? nextX : x;
186
+ y = nextY != null ? nextY : y;
187
+ middlewareData[name] = {
188
+ ...middlewareData[name],
189
+ ...data
190
+ };
191
+ if (reset && resetCount < MAX_RESET_COUNT) {
192
+ resetCount++;
193
+ if (typeof reset === 'object') {
194
+ if (reset.placement) {
195
+ statefulPlacement = reset.placement;
196
+ }
197
+ if (reset.rects) {
198
+ rects = reset.rects === true ? await platform.getElementRects({
199
+ reference,
200
+ floating,
201
+ strategy
202
+ }) : reset.rects;
203
+ }
204
+ ({
205
+ x,
206
+ y
207
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
208
+ }
209
+ i = -1;
210
+ }
211
+ }
212
+ return {
213
+ x,
214
+ y,
215
+ placement: statefulPlacement,
216
+ strategy,
217
+ middlewareData
218
+ };
219
+ };
220
+
221
+ /**
222
+ * Provides data to position an inner element of the floating element so that it
223
+ * appears centered to the reference element.
224
+ * @see https://floating-ui.com/docs/arrow
225
+ */
226
+ const arrow = options => ({
227
+ name: 'arrow',
228
+ options,
229
+ async fn(state) {
230
+ const {
231
+ x,
232
+ y,
233
+ placement,
234
+ rects,
235
+ platform,
236
+ elements,
237
+ middlewareData
238
+ } = state;
239
+ // Since `element` is required, we don't Partial<> the type.
240
+ const {
241
+ element,
242
+ padding = 0
243
+ } = evaluate(options, state) || {};
244
+ if (element == null) {
245
+ return {};
246
+ }
247
+ const paddingObject = getPaddingObject(padding);
248
+ const coords = {
249
+ x,
250
+ y
251
+ };
252
+ const axis = getAlignmentAxis(placement);
253
+ const length = getAxisLength(axis);
254
+ const arrowDimensions = await platform.getDimensions(element);
255
+ const isYAxis = axis === 'y';
256
+ const minProp = isYAxis ? 'top' : 'left';
257
+ const maxProp = isYAxis ? 'bottom' : 'right';
258
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
259
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
260
+ const startDiff = coords[axis] - rects.reference[axis];
261
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
262
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
263
+
264
+ // DOM platform can return `window` as the `offsetParent`.
265
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
266
+ clientSize = elements.floating[clientProp] || rects.floating[length];
267
+ }
268
+ const centerToReference = endDiff / 2 - startDiff / 2;
269
+
270
+ // If the padding is large enough that it causes the arrow to no longer be
271
+ // centered, modify the padding so that it is centered.
272
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
273
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
274
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
275
+
276
+ // Make sure the arrow doesn't overflow the floating element if the center
277
+ // point is outside the floating element's bounds.
278
+ const max = clientSize - arrowDimensions[length] - maxPadding;
279
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
280
+ const offset = clamp(minPadding, center, max);
281
+
282
+ // If the reference is small enough that the arrow's padding causes it to
283
+ // to point to nothing for an aligned placement, adjust the offset of the
284
+ // floating element itself. To ensure `shift()` continues to take action,
285
+ // a single reset is performed when this is true.
286
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < minPadding ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
287
+ const alignmentOffset = shouldAddOffset ? center < minPadding ? center - minPadding : center - max : 0;
288
+ return {
289
+ [axis]: coords[axis] + alignmentOffset,
290
+ data: {
291
+ [axis]: offset,
292
+ centerOffset: center - offset - alignmentOffset,
293
+ ...(shouldAddOffset && {
294
+ alignmentOffset
295
+ })
296
+ },
297
+ reset: shouldAddOffset
298
+ };
299
+ }
300
+ });
301
+
302
+ function getPlacementList(alignment, autoAlignment, allowedPlacements) {
303
+ const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);
304
+ return allowedPlacementsSortedByAlignment.filter(placement => {
305
+ if (alignment) {
306
+ return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
307
+ }
308
+ return true;
309
+ });
310
+ }
311
+ /**
312
+ * Optimizes the visibility of the floating element by choosing the placement
313
+ * that has the most space available automatically, without needing to specify a
314
+ * preferred placement. Alternative to `flip`.
315
+ * @see https://floating-ui.com/docs/autoPlacement
316
+ */
317
+ const autoPlacement = function (options) {
318
+ if (options === void 0) {
319
+ options = {};
320
+ }
321
+ return {
322
+ name: 'autoPlacement',
323
+ options,
324
+ async fn(state) {
325
+ var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
326
+ const {
327
+ rects,
328
+ middlewareData,
329
+ placement,
330
+ platform,
331
+ elements
332
+ } = state;
333
+ const {
334
+ crossAxis = false,
335
+ alignment,
336
+ allowedPlacements = placements,
337
+ autoAlignment = true,
338
+ ...detectOverflowOptions
339
+ } = evaluate(options, state);
340
+ const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
341
+ const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
342
+ const currentPlacement = placements$1[currentIndex];
343
+ if (currentPlacement == null) {
344
+ return {};
345
+ }
346
+
347
+ // Make `computeCoords` start from the right place.
348
+ if (placement !== currentPlacement) {
349
+ return {
350
+ reset: {
351
+ placement: placements$1[0]
352
+ }
353
+ };
354
+ }
355
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
356
+ const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
357
+ const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
358
+ const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {
359
+ placement: currentPlacement,
360
+ overflows: currentOverflows
361
+ }];
362
+ const nextPlacement = placements$1[currentIndex + 1];
363
+
364
+ // There are more placements to check.
365
+ if (nextPlacement) {
366
+ return {
367
+ data: {
368
+ index: currentIndex + 1,
369
+ overflows: allOverflows
370
+ },
371
+ reset: {
372
+ placement: nextPlacement
373
+ }
374
+ };
375
+ }
376
+ const placementsSortedByMostSpace = allOverflows.map(d => {
377
+ const alignment = getAlignment(d.placement);
378
+ return [d.placement, alignment && crossAxis ?
379
+ // Check along the mainAxis and main crossAxis side.
380
+ d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :
381
+ // Check only the mainAxis.
382
+ d.overflows[0], d.overflows];
383
+ }).sort((a, b) => a[1] - b[1]);
384
+ const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,
385
+ // Aligned placements should not check their opposite crossAxis
386
+ // side.
387
+ getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));
388
+ const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
389
+ if (resetPlacement !== placement) {
390
+ return {
391
+ data: {
392
+ index: currentIndex + 1,
393
+ overflows: allOverflows
394
+ },
395
+ reset: {
396
+ placement: resetPlacement
397
+ }
398
+ };
399
+ }
400
+ return {};
401
+ }
402
+ };
403
+ };
404
+
405
+ /**
406
+ * Optimizes the visibility of the floating element by flipping the `placement`
407
+ * in order to keep it in view when the preferred placement(s) will overflow the
408
+ * clipping boundary. Alternative to `autoPlacement`.
409
+ * @see https://floating-ui.com/docs/flip
410
+ */
411
+ const flip = function (options) {
412
+ if (options === void 0) {
413
+ options = {};
414
+ }
415
+ return {
416
+ name: 'flip',
417
+ options,
418
+ async fn(state) {
419
+ var _middlewareData$arrow, _middlewareData$flip;
420
+ const {
421
+ placement,
422
+ middlewareData,
423
+ rects,
424
+ initialPlacement,
425
+ platform,
426
+ elements
427
+ } = state;
428
+ const {
429
+ mainAxis: checkMainAxis = true,
430
+ crossAxis: checkCrossAxis = true,
431
+ fallbackPlacements: specifiedFallbackPlacements,
432
+ fallbackStrategy = 'bestFit',
433
+ fallbackAxisSideDirection = 'none',
434
+ flipAlignment = true,
435
+ ...detectOverflowOptions
436
+ } = evaluate(options, state);
437
+
438
+ // If a reset by the arrow was caused due to an alignment offset being
439
+ // added, we should skip any logic now since `flip()` has already done its
440
+ // work.
441
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
442
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
443
+ return {};
444
+ }
445
+ const side = getSide(placement);
446
+ const initialSideAxis = getSideAxis(initialPlacement);
447
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
448
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
449
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
450
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
451
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
452
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
453
+ }
454
+ const placements = [initialPlacement, ...fallbackPlacements];
455
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
456
+ const overflows = [];
457
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
458
+ if (checkMainAxis) {
459
+ overflows.push(overflow[side]);
460
+ }
461
+ if (checkCrossAxis) {
462
+ const sides = getAlignmentSides(placement, rects, rtl);
463
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
464
+ }
465
+ overflowsData = [...overflowsData, {
466
+ placement,
467
+ overflows
468
+ }];
469
+
470
+ // One or more sides is overflowing.
471
+ if (!overflows.every(side => side <= 0)) {
472
+ var _middlewareData$flip2, _overflowsData$filter;
473
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
474
+ const nextPlacement = placements[nextIndex];
475
+ if (nextPlacement) {
476
+ const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
477
+ if (!ignoreCrossAxisOverflow ||
478
+ // We leave the current main axis only if every placement on that axis
479
+ // overflows the main axis.
480
+ overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
481
+ // Try next placement and re-run the lifecycle.
482
+ return {
483
+ data: {
484
+ index: nextIndex,
485
+ overflows: overflowsData
486
+ },
487
+ reset: {
488
+ placement: nextPlacement
489
+ }
490
+ };
491
+ }
492
+ }
493
+
494
+ // First, find the candidates that fit on the mainAxis side of overflow,
495
+ // then find the placement that fits the best on the main crossAxis side.
496
+ 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;
497
+
498
+ // Otherwise fallback.
499
+ if (!resetPlacement) {
500
+ switch (fallbackStrategy) {
501
+ case 'bestFit':
502
+ {
503
+ var _overflowsData$filter2;
504
+ const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
505
+ if (hasFallbackAxisSideDirection) {
506
+ const currentSideAxis = getSideAxis(d.placement);
507
+ return currentSideAxis === initialSideAxis ||
508
+ // Create a bias to the `y` side axis due to horizontal
509
+ // reading directions favoring greater width.
510
+ currentSideAxis === 'y';
511
+ }
512
+ return true;
513
+ }).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];
514
+ if (placement) {
515
+ resetPlacement = placement;
516
+ }
517
+ break;
518
+ }
519
+ case 'initialPlacement':
520
+ resetPlacement = initialPlacement;
521
+ break;
522
+ }
523
+ }
524
+ if (placement !== resetPlacement) {
525
+ return {
526
+ reset: {
527
+ placement: resetPlacement
528
+ }
529
+ };
530
+ }
531
+ }
532
+ return {};
533
+ }
534
+ };
535
+ };
536
+
537
+ function getSideOffsets(overflow, rect) {
538
+ return {
539
+ top: overflow.top - rect.height,
540
+ right: overflow.right - rect.width,
541
+ bottom: overflow.bottom - rect.height,
542
+ left: overflow.left - rect.width
543
+ };
544
+ }
545
+ function isAnySideFullyClipped(overflow) {
546
+ return sides.some(side => overflow[side] >= 0);
547
+ }
548
+ /**
549
+ * Provides data to hide the floating element in applicable situations, such as
550
+ * when it is not in the same clipping context as the reference element.
551
+ * @see https://floating-ui.com/docs/hide
552
+ */
553
+ const hide = function (options) {
554
+ if (options === void 0) {
555
+ options = {};
556
+ }
557
+ return {
558
+ name: 'hide',
559
+ options,
560
+ async fn(state) {
561
+ const {
562
+ rects,
563
+ platform
564
+ } = state;
565
+ const {
566
+ strategy = 'referenceHidden',
567
+ ...detectOverflowOptions
568
+ } = evaluate(options, state);
569
+ switch (strategy) {
570
+ case 'referenceHidden':
571
+ {
572
+ const overflow = await platform.detectOverflow(state, {
573
+ ...detectOverflowOptions,
574
+ elementContext: 'reference'
575
+ });
576
+ const offsets = getSideOffsets(overflow, rects.reference);
577
+ return {
578
+ data: {
579
+ referenceHiddenOffsets: offsets,
580
+ referenceHidden: isAnySideFullyClipped(offsets)
581
+ }
582
+ };
583
+ }
584
+ case 'escaped':
585
+ {
586
+ const overflow = await platform.detectOverflow(state, {
587
+ ...detectOverflowOptions,
588
+ altBoundary: true
589
+ });
590
+ const offsets = getSideOffsets(overflow, rects.floating);
591
+ return {
592
+ data: {
593
+ escapedOffsets: offsets,
594
+ escaped: isAnySideFullyClipped(offsets)
595
+ }
596
+ };
597
+ }
598
+ default:
599
+ {
600
+ return {};
601
+ }
602
+ }
603
+ }
604
+ };
605
+ };
606
+
607
+ function getBoundingRect(rects) {
608
+ const minX = min(...rects.map(rect => rect.left));
609
+ const minY = min(...rects.map(rect => rect.top));
610
+ const maxX = max(...rects.map(rect => rect.right));
611
+ const maxY = max(...rects.map(rect => rect.bottom));
612
+ return {
613
+ x: minX,
614
+ y: minY,
615
+ width: maxX - minX,
616
+ height: maxY - minY
617
+ };
618
+ }
619
+ function getRectsByLine(rects) {
620
+ const sortedRects = rects.slice().sort((a, b) => a.y - b.y);
621
+ const groups = [];
622
+ let prevRect = null;
623
+ for (let i = 0; i < sortedRects.length; i++) {
624
+ const rect = sortedRects[i];
625
+ if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
626
+ groups.push([rect]);
627
+ } else {
628
+ groups[groups.length - 1].push(rect);
629
+ }
630
+ prevRect = rect;
631
+ }
632
+ return groups.map(rect => rectToClientRect(getBoundingRect(rect)));
633
+ }
634
+ /**
635
+ * Provides improved positioning for inline reference elements that can span
636
+ * over multiple lines, such as hyperlinks or range selections.
637
+ * @see https://floating-ui.com/docs/inline
638
+ */
639
+ const inline = function (options) {
640
+ if (options === void 0) {
641
+ options = {};
642
+ }
643
+ return {
644
+ name: 'inline',
645
+ options,
646
+ async fn(state) {
647
+ const {
648
+ placement,
649
+ elements,
650
+ rects,
651
+ platform,
652
+ strategy
653
+ } = state;
654
+ // A MouseEvent's client{X,Y} coords can be up to 2 pixels off a
655
+ // ClientRect's bounds, despite the event listener being triggered. A
656
+ // padding of 2 seems to handle this issue.
657
+ const {
658
+ padding = 2,
659
+ x,
660
+ y
661
+ } = evaluate(options, state);
662
+ const nativeClientRects = Array.from((await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference))) || []);
663
+
664
+ // No rects (e.g. a hidden or detached reference, or a collapsed range) —
665
+ // keep the existing reference rect rather than resetting to an invalid
666
+ // one with non-finite values.
667
+ if (!nativeClientRects.length) {
668
+ return {};
669
+ }
670
+ const clientRects = getRectsByLine(nativeClientRects);
671
+ const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
672
+ const paddingObject = getPaddingObject(padding);
673
+ function getBoundingClientRect() {
674
+ // There are two rects and they are disjoined.
675
+ if (clientRects.length === 2 && (clientRects[0].left > clientRects[1].right || clientRects[1].left > clientRects[0].right) && x != null && y != null) {
676
+ // Find the first rect in which the point is fully inside.
677
+ return clientRects.find(rect => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom) || fallback;
678
+ }
679
+
680
+ // There are 2 or more connected rects.
681
+ if (clientRects.length >= 2) {
682
+ if (getSideAxis(placement) === 'y') {
683
+ const firstRect = clientRects[0];
684
+ const lastRect = clientRects[clientRects.length - 1];
685
+ const isTop = getSide(placement) === 'top';
686
+ const top = firstRect.top;
687
+ const bottom = lastRect.bottom;
688
+ const left = isTop ? firstRect.left : lastRect.left;
689
+ const right = isTop ? firstRect.right : lastRect.right;
690
+ return rectToClientRect({
691
+ x: left,
692
+ y: top,
693
+ width: right - left,
694
+ height: bottom - top
695
+ });
696
+ }
697
+ const isLeftSide = getSide(placement) === 'left';
698
+ const maxRight = max(...clientRects.map(rect => rect.right));
699
+ const minLeft = min(...clientRects.map(rect => rect.left));
700
+ const measureRects = clientRects.filter(rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight);
701
+ const top = measureRects[0].top;
702
+ const bottom = measureRects[measureRects.length - 1].bottom;
703
+ return rectToClientRect({
704
+ x: minLeft,
705
+ y: top,
706
+ width: maxRight - minLeft,
707
+ height: bottom - top
708
+ });
709
+ }
710
+ return fallback;
711
+ }
712
+ const resetRects = await platform.getElementRects({
713
+ reference: {
714
+ getBoundingClientRect
715
+ },
716
+ floating: elements.floating,
717
+ strategy
718
+ });
719
+ if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
720
+ return {
721
+ reset: {
722
+ rects: resetRects
723
+ }
724
+ };
725
+ }
726
+ return {};
727
+ }
728
+ };
729
+ };
730
+
731
+ const originSides = /*#__PURE__*/new Set(['left', 'top']);
732
+
733
+ // For type backwards-compatibility, the `OffsetOptions` type was also
734
+ // Derivable.
735
+
736
+ async function convertValueToCoords(state, options) {
737
+ const {
738
+ placement,
739
+ platform,
740
+ elements
741
+ } = state;
742
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
743
+ const side = getSide(placement);
744
+ const alignment = getAlignment(placement);
745
+ const isVertical = getSideAxis(placement) === 'y';
746
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
747
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
748
+ const rawValue = evaluate(options, state);
749
+
750
+ // eslint-disable-next-line prefer-const
751
+ let {
752
+ mainAxis,
753
+ crossAxis,
754
+ alignmentAxis
755
+ } = typeof rawValue === 'number' ? {
756
+ mainAxis: rawValue,
757
+ crossAxis: 0,
758
+ alignmentAxis: null
759
+ } : {
760
+ mainAxis: rawValue.mainAxis || 0,
761
+ crossAxis: rawValue.crossAxis || 0,
762
+ alignmentAxis: rawValue.alignmentAxis
763
+ };
764
+ if (alignment && typeof alignmentAxis === 'number') {
765
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
766
+ }
767
+ return isVertical ? {
768
+ x: crossAxis * crossAxisMulti,
769
+ y: mainAxis * mainAxisMulti
770
+ } : {
771
+ x: mainAxis * mainAxisMulti,
772
+ y: crossAxis * crossAxisMulti
773
+ };
774
+ }
775
+
776
+ /**
777
+ * Modifies the placement by translating the floating element along the
778
+ * specified axes.
779
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
780
+ * object may be passed.
781
+ * @see https://floating-ui.com/docs/offset
782
+ */
783
+ const offset = function (options) {
784
+ if (options === void 0) {
785
+ options = 0;
786
+ }
787
+ return {
788
+ name: 'offset',
789
+ options,
790
+ async fn(state) {
791
+ var _middlewareData$offse, _middlewareData$arrow;
792
+ const {
793
+ x,
794
+ y,
795
+ placement,
796
+ middlewareData
797
+ } = state;
798
+ const diffCoords = await convertValueToCoords(state, options);
799
+
800
+ // If the placement is the same and the arrow caused an alignment offset
801
+ // then we don't need to change the positioning coordinates.
802
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
803
+ return {};
804
+ }
805
+ return {
806
+ x: x + diffCoords.x,
807
+ y: y + diffCoords.y,
808
+ data: {
809
+ ...diffCoords,
810
+ placement
811
+ }
812
+ };
813
+ }
814
+ };
815
+ };
816
+
817
+ /**
818
+ * Optimizes the visibility of the floating element by shifting it in order to
819
+ * keep it in view when it will overflow the clipping boundary.
820
+ * @see https://floating-ui.com/docs/shift
821
+ */
822
+ const shift = function (options) {
823
+ if (options === void 0) {
824
+ options = {};
825
+ }
826
+ return {
827
+ name: 'shift',
828
+ options,
829
+ async fn(state) {
830
+ const {
831
+ x,
832
+ y,
833
+ placement,
834
+ platform
835
+ } = state;
836
+ const {
837
+ mainAxis: checkMainAxis = true,
838
+ crossAxis: checkCrossAxis = false,
839
+ limiter = {
840
+ fn: _ref => {
841
+ let {
842
+ x,
843
+ y
844
+ } = _ref;
845
+ return {
846
+ x,
847
+ y
848
+ };
849
+ }
850
+ },
851
+ ...detectOverflowOptions
852
+ } = evaluate(options, state);
853
+ const coords = {
854
+ x,
855
+ y
856
+ };
857
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
858
+ const crossAxis = getSideAxis(placement);
859
+ const mainAxis = getOppositeAxis(crossAxis);
860
+ let mainAxisCoord = coords[mainAxis];
861
+ let crossAxisCoord = coords[crossAxis];
862
+ const clampCoord = (axis, coord) => clamp(coord + overflow[axis === 'y' ? 'top' : 'left'], coord, coord - overflow[axis === 'y' ? 'bottom' : 'right']);
863
+ if (checkMainAxis) {
864
+ mainAxisCoord = clampCoord(mainAxis, mainAxisCoord);
865
+ }
866
+ if (checkCrossAxis) {
867
+ crossAxisCoord = clampCoord(crossAxis, crossAxisCoord);
868
+ }
869
+ const limitedCoords = limiter.fn({
870
+ ...state,
871
+ [mainAxis]: mainAxisCoord,
872
+ [crossAxis]: crossAxisCoord
873
+ });
874
+ return {
875
+ ...limitedCoords,
876
+ data: {
877
+ x: limitedCoords.x - x,
878
+ y: limitedCoords.y - y,
879
+ enabled: {
880
+ [mainAxis]: checkMainAxis,
881
+ [crossAxis]: checkCrossAxis
882
+ }
883
+ }
884
+ };
885
+ }
886
+ };
887
+ };
888
+ /**
889
+ * Built-in `limiter` that will stop `shift()` at a certain point.
890
+ */
891
+ const limitShift = function (options) {
892
+ if (options === void 0) {
893
+ options = {};
894
+ }
895
+ return {
896
+ options,
897
+ fn(state) {
898
+ var _rawOffset$mainAxis, _rawOffset$crossAxis;
899
+ const {
900
+ x,
901
+ y,
902
+ placement,
903
+ rects,
904
+ middlewareData
905
+ } = state;
906
+ const {
907
+ offset = 0,
908
+ mainAxis: checkMainAxis = true,
909
+ crossAxis: checkCrossAxis = true
910
+ } = evaluate(options, state);
911
+ const coords = {
912
+ x,
913
+ y
914
+ };
915
+ const crossAxis = getSideAxis(placement);
916
+ const mainAxis = getOppositeAxis(crossAxis);
917
+ let mainAxisCoord = coords[mainAxis];
918
+ let crossAxisCoord = coords[crossAxis];
919
+ const rawOffset = evaluate(offset, state);
920
+ const computedOffset = typeof rawOffset === 'number' ? {
921
+ mainAxis: rawOffset,
922
+ crossAxis: 0
923
+ } : {
924
+ mainAxis: (_rawOffset$mainAxis = rawOffset.mainAxis) != null ? _rawOffset$mainAxis : 0,
925
+ crossAxis: (_rawOffset$crossAxis = rawOffset.crossAxis) != null ? _rawOffset$crossAxis : 0
926
+ };
927
+ if (checkMainAxis) {
928
+ const len = mainAxis === 'y' ? 'height' : 'width';
929
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
930
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
931
+ if (mainAxisCoord < limitMin) {
932
+ mainAxisCoord = limitMin;
933
+ } else if (mainAxisCoord > limitMax) {
934
+ mainAxisCoord = limitMax;
935
+ }
936
+ }
937
+ if (checkCrossAxis) {
938
+ var _middlewareData$offse, _middlewareData$offse2;
939
+ const len = mainAxis === 'y' ? 'width' : 'height';
940
+ const isOriginSide = originSides.has(getSide(placement));
941
+ 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);
942
+ 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);
943
+ if (crossAxisCoord < limitMin) {
944
+ crossAxisCoord = limitMin;
945
+ } else if (crossAxisCoord > limitMax) {
946
+ crossAxisCoord = limitMax;
947
+ }
948
+ }
949
+ return {
950
+ [mainAxis]: mainAxisCoord,
951
+ [crossAxis]: crossAxisCoord
952
+ };
953
+ }
954
+ };
955
+ };
956
+
957
+ // Method syntax keeps callback parameters bivariant, but expressing the
958
+ // explicit `| undefined` required by `exactOptionalPropertyTypes` needs
959
+ // property syntax, which is contravariant under `strictFunctionTypes`.
960
+ // Extracting the function from a method position restores that bivariance so
961
+ // consumers can still assign callbacks with narrower parameter types.
962
+
963
+ /**
964
+ * Provides data that allows you to change the size of the floating element —
965
+ * for instance, prevent it from overflowing the clipping boundary or match the
966
+ * width of the reference element.
967
+ * @see https://floating-ui.com/docs/size
968
+ */
969
+ const size = function (options) {
970
+ if (options === void 0) {
971
+ options = {};
972
+ }
973
+ return {
974
+ name: 'size',
975
+ options,
976
+ async fn(state) {
977
+ const {
978
+ placement,
979
+ rects,
980
+ platform,
981
+ elements
982
+ } = state;
983
+ const {
984
+ apply = () => {},
985
+ ...detectOverflowOptions
986
+ } = evaluate(options, state);
987
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
988
+ const side = getSide(placement);
989
+ const alignment = getAlignment(placement);
990
+ const isYAxis = getSideAxis(placement) === 'y';
991
+ const {
992
+ width,
993
+ height
994
+ } = rects.floating;
995
+ let heightSide;
996
+ let widthSide;
997
+ if (side === 'top' || side === 'bottom') {
998
+ heightSide = side;
999
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
1000
+ } else {
1001
+ widthSide = side;
1002
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
1003
+ }
1004
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
1005
+ const maximumClippingWidth = width - overflow.left - overflow.right;
1006
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
1007
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
1008
+ const shiftData = state.middlewareData.shift;
1009
+ const noShift = !shiftData;
1010
+ let availableHeight = overflowAvailableHeight;
1011
+ let availableWidth = overflowAvailableWidth;
1012
+ if (shiftData != null && shiftData.enabled.x) {
1013
+ availableWidth = maximumClippingWidth;
1014
+ }
1015
+ if (shiftData != null && shiftData.enabled.y) {
1016
+ availableHeight = maximumClippingHeight;
1017
+ }
1018
+ if (noShift && !alignment) {
1019
+ if (isYAxis) {
1020
+ availableWidth = width - 2 * max(overflow.left, overflow.right);
1021
+ } else {
1022
+ availableHeight = height - 2 * max(overflow.top, overflow.bottom);
1023
+ }
1024
+ }
1025
+ await apply({
1026
+ ...state,
1027
+ availableWidth,
1028
+ availableHeight
1029
+ });
1030
+ const nextDimensions = await platform.getDimensions(elements.floating);
1031
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
1032
+ return {
1033
+ reset: {
1034
+ rects: true
1035
+ }
1036
+ };
1037
+ }
1038
+ return {};
1039
+ }
1040
+ };
1041
+ };
1042
+
1043
+ export { arrow, autoPlacement, computePosition, detectOverflow, flip, hide, inline, limitShift, offset, shift, size };