@xhsreds/reds-rn-next 0.0.1-beta-3

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 (59) hide show
  1. package/cjs/_chunks/DOz-p6oh.js +467 -0
  2. package/cjs/_chunks/DOz-p6oh.js.map +1 -0
  3. package/cjs/_chunks/Dx-JjEWA.js +115 -0
  4. package/cjs/_chunks/Dx-JjEWA.js.map +1 -0
  5. package/cjs/components/Button/common/index.js +12 -0
  6. package/cjs/components/Button/common/index.js.map +1 -0
  7. package/cjs/components/Button/interface/index.js +3 -0
  8. package/cjs/components/Button/interface/index.js.map +1 -0
  9. package/cjs/components/Button/rn/index.js +25 -0
  10. package/cjs/components/Button/rn/index.js.map +1 -0
  11. package/cjs/components/Popover/common/index.js +12 -0
  12. package/cjs/components/Popover/common/index.js.map +1 -0
  13. package/cjs/components/Popover/interface/index.js +3 -0
  14. package/cjs/components/Popover/interface/index.js.map +1 -0
  15. package/cjs/components/Popover/rn/component.js +59 -0
  16. package/cjs/components/Popover/rn/component.js.map +1 -0
  17. package/cjs/components/Popover/rn/hook.js +1414 -0
  18. package/cjs/components/Popover/rn/hook.js.map +1 -0
  19. package/cjs/components/Popover/rn/index.js +114 -0
  20. package/cjs/components/Popover/rn/index.js.map +1 -0
  21. package/cjs/index.rn.js +17 -0
  22. package/cjs/index.rn.js.map +1 -0
  23. package/cjs/utils/hook.js +7 -0
  24. package/cjs/utils/hook.js.map +1 -0
  25. package/esm/_chunks/BdytNqoo.js +458 -0
  26. package/esm/_chunks/BdytNqoo.js.map +1 -0
  27. package/esm/_chunks/C8kshcql.js +111 -0
  28. package/esm/_chunks/C8kshcql.js.map +1 -0
  29. package/esm/components/Button/common/index.js +10 -0
  30. package/esm/components/Button/common/index.js.map +1 -0
  31. package/esm/components/Button/interface/index.js +2 -0
  32. package/esm/components/Button/interface/index.js.map +1 -0
  33. package/esm/components/Button/rn/index.js +21 -0
  34. package/esm/components/Button/rn/index.js.map +1 -0
  35. package/esm/components/Popover/common/index.js +10 -0
  36. package/esm/components/Popover/common/index.js.map +1 -0
  37. package/esm/components/Popover/interface/index.js +2 -0
  38. package/esm/components/Popover/interface/index.js.map +1 -0
  39. package/esm/components/Popover/rn/component.js +56 -0
  40. package/esm/components/Popover/rn/component.js.map +1 -0
  41. package/esm/components/Popover/rn/hook.js +1394 -0
  42. package/esm/components/Popover/rn/hook.js.map +1 -0
  43. package/esm/components/Popover/rn/index.js +110 -0
  44. package/esm/components/Popover/rn/index.js.map +1 -0
  45. package/esm/index.rn.js +10 -0
  46. package/esm/index.rn.js.map +1 -0
  47. package/esm/utils/hook.js +5 -0
  48. package/esm/utils/hook.js.map +1 -0
  49. package/package.json +34 -0
  50. package/types/index.rn.d.ts +3 -0
  51. package/types/src/components/Button/common/index.d.ts +1 -0
  52. package/types/src/components/Button/interface/index.d.ts +31 -0
  53. package/types/src/components/Button/rn/index.d.ts +4 -0
  54. package/types/src/components/Popover/common/index.d.ts +1 -0
  55. package/types/src/components/Popover/interface/index.d.ts +12 -0
  56. package/types/src/components/Popover/rn/component.d.ts +13 -0
  57. package/types/src/components/Popover/rn/hook.d.ts +51 -0
  58. package/types/src/components/Popover/rn/index.d.ts +4 -0
  59. package/types/src/utils/hook.d.ts +1 -0
@@ -0,0 +1,1394 @@
1
+ import { a as _objectSpread2, b as _asyncToGenerator, c as _defineProperty, d as _regeneratorRuntime, e as _typeof, f as _toConsumableArray, g as _objectWithoutProperties, _ as _slicedToArray } from '../../../_chunks/BdytNqoo.js';
2
+ import * as React from 'react';
3
+ import { useState, useRef, useEffect } from 'react';
4
+ import { Dimensions } from 'react-native';
5
+
6
+ var min = Math.min;
7
+ var max = Math.max;
8
+ var oppositeSideMap = {
9
+ left: 'right',
10
+ right: 'left',
11
+ bottom: 'top',
12
+ top: 'bottom'
13
+ };
14
+ var oppositeAlignmentMap = {
15
+ start: 'end',
16
+ end: 'start'
17
+ };
18
+ function clamp(start, value, end) {
19
+ return max(start, min(value, end));
20
+ }
21
+ function evaluate(value, param) {
22
+ return typeof value === 'function' ? value(param) : value;
23
+ }
24
+ function getSide(placement) {
25
+ return placement.split('-')[0];
26
+ }
27
+ function getAlignment(placement) {
28
+ return placement.split('-')[1];
29
+ }
30
+ function getOppositeAxis(axis) {
31
+ return axis === 'x' ? 'y' : 'x';
32
+ }
33
+ function getAxisLength(axis) {
34
+ return axis === 'y' ? 'height' : 'width';
35
+ }
36
+ function getSideAxis(placement) {
37
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
38
+ }
39
+ function getAlignmentAxis(placement) {
40
+ return getOppositeAxis(getSideAxis(placement));
41
+ }
42
+ function getAlignmentSides(placement, rects, rtl) {
43
+ if (rtl === void 0) {
44
+ rtl = false;
45
+ }
46
+ var alignment = getAlignment(placement);
47
+ var alignmentAxis = getAlignmentAxis(placement);
48
+ var length = getAxisLength(alignmentAxis);
49
+ var mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
50
+ if (rects.reference[length] > rects.floating[length]) {
51
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
52
+ }
53
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
54
+ }
55
+ function getExpandedPlacements(placement) {
56
+ var oppositePlacement = getOppositePlacement(placement);
57
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
58
+ }
59
+ function getOppositeAlignmentPlacement(placement) {
60
+ return placement.replace(/start|end/g, function (alignment) {
61
+ return oppositeAlignmentMap[alignment];
62
+ });
63
+ }
64
+ function getSideList(side, isStart, rtl) {
65
+ var lr = ['left', 'right'];
66
+ var rl = ['right', 'left'];
67
+ var tb = ['top', 'bottom'];
68
+ var bt = ['bottom', 'top'];
69
+ switch (side) {
70
+ case 'top':
71
+ case 'bottom':
72
+ if (rtl) return isStart ? rl : lr;
73
+ return isStart ? lr : rl;
74
+ case 'left':
75
+ case 'right':
76
+ return isStart ? tb : bt;
77
+ default:
78
+ return [];
79
+ }
80
+ }
81
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
82
+ var alignment = getAlignment(placement);
83
+ var list = getSideList(getSide(placement), direction === 'start', rtl);
84
+ if (alignment) {
85
+ list = list.map(function (side) {
86
+ return side + "-" + alignment;
87
+ });
88
+ if (flipAlignment) {
89
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
90
+ }
91
+ }
92
+ return list;
93
+ }
94
+ function getOppositePlacement(placement) {
95
+ return placement.replace(/left|right|bottom|top/g, function (side) {
96
+ return oppositeSideMap[side];
97
+ });
98
+ }
99
+ function expandPaddingObject(padding) {
100
+ return _objectSpread2({
101
+ top: 0,
102
+ right: 0,
103
+ bottom: 0,
104
+ left: 0
105
+ }, padding);
106
+ }
107
+ function getPaddingObject(padding) {
108
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
109
+ top: padding,
110
+ right: padding,
111
+ bottom: padding,
112
+ left: padding
113
+ };
114
+ }
115
+ function rectToClientRect(rect) {
116
+ var x = rect.x,
117
+ y = rect.y,
118
+ width = rect.width,
119
+ height = rect.height;
120
+ return {
121
+ width: width,
122
+ height: height,
123
+ top: y,
124
+ left: x,
125
+ right: x + width,
126
+ bottom: y + height,
127
+ x: x,
128
+ y: y
129
+ };
130
+ }
131
+
132
+ var _excluded2 = ["mainAxis", "crossAxis", "fallbackPlacements", "fallbackStrategy", "fallbackAxisSideDirection", "flipAlignment"],
133
+ _excluded4 = ["mainAxis", "crossAxis", "limiter"];
134
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
135
+ var reference = _ref.reference,
136
+ floating = _ref.floating;
137
+ var sideAxis = getSideAxis(placement);
138
+ var alignmentAxis = getAlignmentAxis(placement);
139
+ var alignLength = getAxisLength(alignmentAxis);
140
+ var side = getSide(placement);
141
+ var isVertical = sideAxis === 'y';
142
+ var commonX = reference.x + reference.width / 2 - floating.width / 2;
143
+ var commonY = reference.y + reference.height / 2 - floating.height / 2;
144
+ var commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
145
+ var coords;
146
+ switch (side) {
147
+ case 'top':
148
+ coords = {
149
+ x: commonX,
150
+ y: reference.y - floating.height
151
+ };
152
+ break;
153
+ case 'bottom':
154
+ coords = {
155
+ x: commonX,
156
+ y: reference.y + reference.height
157
+ };
158
+ break;
159
+ case 'right':
160
+ coords = {
161
+ x: reference.x + reference.width,
162
+ y: commonY
163
+ };
164
+ break;
165
+ case 'left':
166
+ coords = {
167
+ x: reference.x - floating.width,
168
+ y: commonY
169
+ };
170
+ break;
171
+ default:
172
+ coords = {
173
+ x: reference.x,
174
+ y: reference.y
175
+ };
176
+ }
177
+ switch (getAlignment(placement)) {
178
+ case 'start':
179
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
180
+ break;
181
+ case 'end':
182
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
183
+ break;
184
+ }
185
+ return coords;
186
+ }
187
+
188
+ /**
189
+ * Computes the `x` and `y` coordinates that will place the floating element
190
+ * next to a given reference element.
191
+ *
192
+ * This export does not have any `platform` interface logic. You will need to
193
+ * write one for the platform you are using Floating UI with.
194
+ */
195
+ var computePosition = /*#__PURE__*/function () {
196
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(reference, floating, config) {
197
+ var _config$placement, placement, _config$strategy, strategy, _config$middleware, middleware, platform, validMiddleware, rtl, rects, _computeCoordsFromPla, x, y, statefulPlacement, middlewareData, resetCount, i, _validMiddleware$i, name, fn, _yield$fn, nextX, nextY, data, reset, _computeCoordsFromPla2;
198
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
199
+ while (1) switch (_context.prev = _context.next) {
200
+ case 0:
201
+ _config$placement = config.placement, placement = _config$placement === void 0 ? 'bottom' : _config$placement, _config$strategy = config.strategy, strategy = _config$strategy === void 0 ? 'absolute' : _config$strategy, _config$middleware = config.middleware, middleware = _config$middleware === void 0 ? [] : _config$middleware, platform = config.platform;
202
+ validMiddleware = middleware.filter(Boolean);
203
+ _context.next = 4;
204
+ return platform.isRTL == null ? void 0 : platform.isRTL(floating);
205
+ case 4:
206
+ rtl = _context.sent;
207
+ _context.next = 7;
208
+ return platform.getElementRects({
209
+ reference: reference,
210
+ floating: floating,
211
+ strategy: strategy
212
+ });
213
+ case 7:
214
+ rects = _context.sent;
215
+ _computeCoordsFromPla = computeCoordsFromPlacement(rects, placement, rtl), x = _computeCoordsFromPla.x, y = _computeCoordsFromPla.y;
216
+ statefulPlacement = placement;
217
+ middlewareData = {};
218
+ resetCount = 0;
219
+ i = 0;
220
+ case 13:
221
+ if (!(i < validMiddleware.length)) {
222
+ _context.next = 45;
223
+ break;
224
+ }
225
+ _validMiddleware$i = validMiddleware[i], name = _validMiddleware$i.name, fn = _validMiddleware$i.fn;
226
+ _context.next = 17;
227
+ return fn({
228
+ x: x,
229
+ y: y,
230
+ initialPlacement: placement,
231
+ placement: statefulPlacement,
232
+ strategy: strategy,
233
+ middlewareData: middlewareData,
234
+ rects: rects,
235
+ platform: platform,
236
+ elements: {
237
+ reference: reference,
238
+ floating: floating
239
+ }
240
+ });
241
+ case 17:
242
+ _yield$fn = _context.sent;
243
+ nextX = _yield$fn.x;
244
+ nextY = _yield$fn.y;
245
+ data = _yield$fn.data;
246
+ reset = _yield$fn.reset;
247
+ x = nextX != null ? nextX : x;
248
+ y = nextY != null ? nextY : y;
249
+ middlewareData = _objectSpread2(_objectSpread2({}, middlewareData), {}, _defineProperty({}, name, _objectSpread2(_objectSpread2({}, middlewareData[name]), data)));
250
+ if (!(reset && resetCount <= 50)) {
251
+ _context.next = 42;
252
+ break;
253
+ }
254
+ resetCount++;
255
+ if (!(_typeof(reset) === 'object')) {
256
+ _context.next = 41;
257
+ break;
258
+ }
259
+ if (reset.placement) {
260
+ statefulPlacement = reset.placement;
261
+ }
262
+ if (!reset.rects) {
263
+ _context.next = 38;
264
+ break;
265
+ }
266
+ if (!(reset.rects === true)) {
267
+ _context.next = 36;
268
+ break;
269
+ }
270
+ _context.next = 33;
271
+ return platform.getElementRects({
272
+ reference: reference,
273
+ floating: floating,
274
+ strategy: strategy
275
+ });
276
+ case 33:
277
+ _context.t0 = _context.sent;
278
+ _context.next = 37;
279
+ break;
280
+ case 36:
281
+ _context.t0 = reset.rects;
282
+ case 37:
283
+ rects = _context.t0;
284
+ case 38:
285
+ _computeCoordsFromPla2 = computeCoordsFromPlacement(rects, statefulPlacement, rtl);
286
+ x = _computeCoordsFromPla2.x;
287
+ y = _computeCoordsFromPla2.y;
288
+ case 41:
289
+ i = -1;
290
+ case 42:
291
+ i++;
292
+ _context.next = 13;
293
+ break;
294
+ case 45:
295
+ return _context.abrupt("return", {
296
+ x: x,
297
+ y: y,
298
+ placement: statefulPlacement,
299
+ strategy: strategy,
300
+ middlewareData: middlewareData
301
+ });
302
+ case 46:
303
+ case "end":
304
+ return _context.stop();
305
+ }
306
+ }, _callee);
307
+ }));
308
+ return function computePosition(_x, _x2, _x3) {
309
+ return _ref2.apply(this, arguments);
310
+ };
311
+ }();
312
+
313
+ /**
314
+ * Resolves with an object of overflow side offsets that determine how much the
315
+ * element is overflowing a given clipping boundary on each side.
316
+ * - positive = overflowing the boundary by that number of pixels
317
+ * - negative = how many pixels left before it will overflow
318
+ * - 0 = lies flush with the boundary
319
+ * @see https://floating-ui.com/docs/detectOverflow
320
+ */
321
+ function detectOverflow(_x4, _x5) {
322
+ return _detectOverflow.apply(this, arguments);
323
+ }
324
+ /**
325
+ * Provides data to position an inner element of the floating element so that it
326
+ * appears centered to the reference element.
327
+ * @see https://floating-ui.com/docs/arrow
328
+ */
329
+ function _detectOverflow() {
330
+ _detectOverflow = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(state, options) {
331
+ var _await$platform$isEle, x, y, platform, rects, elements, strategy, _evaluate8, _evaluate8$boundary, boundary, _evaluate8$rootBounda, rootBoundary, _evaluate8$elementCon, elementContext, _evaluate8$altBoundar, altBoundary, _evaluate8$padding, padding, paddingObject, altContext, element, clippingClientRect, rect, offsetParent, offsetScale, elementClientRect;
332
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
333
+ while (1) switch (_context10.prev = _context10.next) {
334
+ case 0:
335
+ if (options === void 0) {
336
+ options = {};
337
+ }
338
+ x = state.x, y = state.y, platform = state.platform, rects = state.rects, elements = state.elements, strategy = state.strategy;
339
+ _evaluate8 = evaluate(options, state), _evaluate8$boundary = _evaluate8.boundary, boundary = _evaluate8$boundary === void 0 ? 'clippingAncestors' : _evaluate8$boundary, _evaluate8$rootBounda = _evaluate8.rootBoundary, rootBoundary = _evaluate8$rootBounda === void 0 ? 'viewport' : _evaluate8$rootBounda, _evaluate8$elementCon = _evaluate8.elementContext, elementContext = _evaluate8$elementCon === void 0 ? 'floating' : _evaluate8$elementCon, _evaluate8$altBoundar = _evaluate8.altBoundary, altBoundary = _evaluate8$altBoundar === void 0 ? false : _evaluate8$altBoundar, _evaluate8$padding = _evaluate8.padding, padding = _evaluate8$padding === void 0 ? 0 : _evaluate8$padding;
340
+ paddingObject = getPaddingObject(padding);
341
+ altContext = elementContext === 'floating' ? 'reference' : 'floating';
342
+ element = elements[altBoundary ? altContext : elementContext];
343
+ _context10.t0 = rectToClientRect;
344
+ _context10.t1 = platform;
345
+ _context10.next = 10;
346
+ return platform.isElement == null ? void 0 : platform.isElement(element);
347
+ case 10:
348
+ _context10.t2 = _await$platform$isEle = _context10.sent;
349
+ if (!(_context10.t2 != null)) {
350
+ _context10.next = 15;
351
+ break;
352
+ }
353
+ _context10.t3 = _await$platform$isEle;
354
+ _context10.next = 16;
355
+ break;
356
+ case 15:
357
+ _context10.t3 = true;
358
+ case 16:
359
+ if (!_context10.t3) {
360
+ _context10.next = 20;
361
+ break;
362
+ }
363
+ _context10.t4 = element;
364
+ _context10.next = 26;
365
+ break;
366
+ case 20:
367
+ _context10.t5 = element.contextElement;
368
+ if (_context10.t5) {
369
+ _context10.next = 25;
370
+ break;
371
+ }
372
+ _context10.next = 24;
373
+ return platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating);
374
+ case 24:
375
+ _context10.t5 = _context10.sent;
376
+ case 25:
377
+ _context10.t4 = _context10.t5;
378
+ case 26:
379
+ _context10.t6 = _context10.t4;
380
+ _context10.t7 = boundary;
381
+ _context10.t8 = rootBoundary;
382
+ _context10.t9 = strategy;
383
+ _context10.t10 = {
384
+ element: _context10.t6,
385
+ boundary: _context10.t7,
386
+ rootBoundary: _context10.t8,
387
+ strategy: _context10.t9
388
+ };
389
+ _context10.next = 33;
390
+ return _context10.t1.getClippingRect.call(_context10.t1, _context10.t10);
391
+ case 33:
392
+ _context10.t11 = _context10.sent;
393
+ clippingClientRect = (0, _context10.t0)(_context10.t11);
394
+ rect = elementContext === 'floating' ? {
395
+ x: x,
396
+ y: y,
397
+ width: rects.floating.width,
398
+ height: rects.floating.height
399
+ } : rects.reference;
400
+ _context10.next = 38;
401
+ return platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating);
402
+ case 38:
403
+ offsetParent = _context10.sent;
404
+ _context10.next = 41;
405
+ return platform.isElement == null ? void 0 : platform.isElement(offsetParent);
406
+ case 41:
407
+ if (!_context10.sent) {
408
+ _context10.next = 50;
409
+ break;
410
+ }
411
+ _context10.next = 44;
412
+ return platform.getScale == null ? void 0 : platform.getScale(offsetParent);
413
+ case 44:
414
+ _context10.t13 = _context10.sent;
415
+ if (_context10.t13) {
416
+ _context10.next = 47;
417
+ break;
418
+ }
419
+ _context10.t13 = {
420
+ x: 1,
421
+ y: 1
422
+ };
423
+ case 47:
424
+ _context10.t12 = _context10.t13;
425
+ _context10.next = 51;
426
+ break;
427
+ case 50:
428
+ _context10.t12 = {
429
+ x: 1,
430
+ y: 1
431
+ };
432
+ case 51:
433
+ offsetScale = _context10.t12;
434
+ _context10.t14 = rectToClientRect;
435
+ if (!platform.convertOffsetParentRelativeRectToViewportRelativeRect) {
436
+ _context10.next = 59;
437
+ break;
438
+ }
439
+ _context10.next = 56;
440
+ return platform.convertOffsetParentRelativeRectToViewportRelativeRect({
441
+ elements: elements,
442
+ rect: rect,
443
+ offsetParent: offsetParent,
444
+ strategy: strategy
445
+ });
446
+ case 56:
447
+ _context10.t15 = _context10.sent;
448
+ _context10.next = 60;
449
+ break;
450
+ case 59:
451
+ _context10.t15 = rect;
452
+ case 60:
453
+ _context10.t16 = _context10.t15;
454
+ elementClientRect = (0, _context10.t14)(_context10.t16);
455
+ return _context10.abrupt("return", {
456
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
457
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
458
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
459
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
460
+ });
461
+ case 63:
462
+ case "end":
463
+ return _context10.stop();
464
+ }
465
+ }, _callee10);
466
+ }));
467
+ return _detectOverflow.apply(this, arguments);
468
+ }
469
+ var arrow$2 = function arrow(options) {
470
+ return {
471
+ name: 'arrow',
472
+ options: options,
473
+ fn: function fn(state) {
474
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
475
+ var x, y, placement, rects, platform, elements, middlewareData, _ref3, element, _ref3$padding, padding, paddingObject, coords, axis, length, arrowDimensions, isYAxis, minProp, maxProp, clientProp, endDiff, startDiff, arrowOffsetParent, clientSize, centerToReference, largestPossiblePadding, minPadding, maxPadding, min$1, max, center, offset, shouldAddOffset, alignmentOffset;
476
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
477
+ while (1) switch (_context2.prev = _context2.next) {
478
+ case 0:
479
+ x = state.x, y = state.y, placement = state.placement, rects = state.rects, platform = state.platform, elements = state.elements, middlewareData = state.middlewareData; // Since `element` is required, we don't Partial<> the type.
480
+ _ref3 = evaluate(options, state) || {}, element = _ref3.element, _ref3$padding = _ref3.padding, padding = _ref3$padding === void 0 ? 0 : _ref3$padding;
481
+ if (!(element == null)) {
482
+ _context2.next = 4;
483
+ break;
484
+ }
485
+ return _context2.abrupt("return", {});
486
+ case 4:
487
+ paddingObject = getPaddingObject(padding);
488
+ coords = {
489
+ x: x,
490
+ y: y
491
+ };
492
+ axis = getAlignmentAxis(placement);
493
+ length = getAxisLength(axis);
494
+ _context2.next = 10;
495
+ return platform.getDimensions(element);
496
+ case 10:
497
+ arrowDimensions = _context2.sent;
498
+ isYAxis = axis === 'y';
499
+ minProp = isYAxis ? 'top' : 'left';
500
+ maxProp = isYAxis ? 'bottom' : 'right';
501
+ clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
502
+ endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
503
+ startDiff = coords[axis] - rects.reference[axis];
504
+ _context2.next = 19;
505
+ return platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element);
506
+ case 19:
507
+ arrowOffsetParent = _context2.sent;
508
+ clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0; // DOM platform can return `window` as the `offsetParent`.
509
+ _context2.t0 = !clientSize;
510
+ if (_context2.t0) {
511
+ _context2.next = 26;
512
+ break;
513
+ }
514
+ _context2.next = 25;
515
+ return platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent);
516
+ case 25:
517
+ _context2.t0 = !_context2.sent;
518
+ case 26:
519
+ if (!_context2.t0) {
520
+ _context2.next = 28;
521
+ break;
522
+ }
523
+ clientSize = elements.floating[clientProp] || rects.floating[length];
524
+ case 28:
525
+ centerToReference = endDiff / 2 - startDiff / 2; // If the padding is large enough that it causes the arrow to no longer be
526
+ // centered, modify the padding so that it is centered.
527
+ largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
528
+ minPadding = min(paddingObject[minProp], largestPossiblePadding);
529
+ maxPadding = min(paddingObject[maxProp], largestPossiblePadding); // Make sure the arrow doesn't overflow the floating element if the center
530
+ // point is outside the floating element's bounds.
531
+ min$1 = minPadding;
532
+ max = clientSize - arrowDimensions[length] - maxPadding;
533
+ center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
534
+ offset = clamp(min$1, center, max); // If the reference is small enough that the arrow's padding causes it to
535
+ // to point to nothing for an aligned placement, adjust the offset of the
536
+ // floating element itself. To ensure `shift()` continues to take action,
537
+ // a single reset is performed when this is true.
538
+ shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
539
+ alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
540
+ return _context2.abrupt("return", _defineProperty(_defineProperty(_defineProperty({}, axis, coords[axis] + alignmentOffset), "data", _objectSpread2(_defineProperty(_defineProperty({}, axis, offset), "centerOffset", center - offset - alignmentOffset), shouldAddOffset && {
541
+ alignmentOffset: alignmentOffset
542
+ })), "reset", shouldAddOffset));
543
+ case 39:
544
+ case "end":
545
+ return _context2.stop();
546
+ }
547
+ }, _callee2);
548
+ }))();
549
+ }
550
+ };
551
+ };
552
+
553
+ /**
554
+ * Optimizes the visibility of the floating element by flipping the `placement`
555
+ * in order to keep it in view when the preferred placement(s) will overflow the
556
+ * clipping boundary. Alternative to `autoPlacement`.
557
+ * @see https://floating-ui.com/docs/flip
558
+ */
559
+ var flip$1 = function flip(options) {
560
+ if (options === void 0) {
561
+ options = {};
562
+ }
563
+ return {
564
+ name: 'flip',
565
+ options: options,
566
+ fn: function fn(state) {
567
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
568
+ var _middlewareData$arrow, _middlewareData$flip, placement, middlewareData, rects, initialPlacement, platform, elements, _evaluate2, _evaluate2$mainAxis, checkMainAxis, _evaluate2$crossAxis, checkCrossAxis, specifiedFallbackPlacements, _evaluate2$fallbackSt, fallbackStrategy, _evaluate2$fallbackAx, fallbackAxisSideDirection, _evaluate2$flipAlignm, flipAlignment, detectOverflowOptions, side, isBasePlacement, rtl, fallbackPlacements, placements, overflow, overflows, overflowsData, _sides, _middlewareData$flip2, _overflowsData$filter, nextIndex, nextPlacement, resetPlacement, _overflowsData$map$so, _placement;
569
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
570
+ while (1) switch (_context4.prev = _context4.next) {
571
+ case 0:
572
+ placement = state.placement, middlewareData = state.middlewareData, rects = state.rects, initialPlacement = state.initialPlacement, platform = state.platform, elements = state.elements;
573
+ _evaluate2 = evaluate(options, state), _evaluate2$mainAxis = _evaluate2.mainAxis, checkMainAxis = _evaluate2$mainAxis === void 0 ? true : _evaluate2$mainAxis, _evaluate2$crossAxis = _evaluate2.crossAxis, checkCrossAxis = _evaluate2$crossAxis === void 0 ? true : _evaluate2$crossAxis, specifiedFallbackPlacements = _evaluate2.fallbackPlacements, _evaluate2$fallbackSt = _evaluate2.fallbackStrategy, fallbackStrategy = _evaluate2$fallbackSt === void 0 ? 'bestFit' : _evaluate2$fallbackSt, _evaluate2$fallbackAx = _evaluate2.fallbackAxisSideDirection, fallbackAxisSideDirection = _evaluate2$fallbackAx === void 0 ? 'none' : _evaluate2$fallbackAx, _evaluate2$flipAlignm = _evaluate2.flipAlignment, flipAlignment = _evaluate2$flipAlignm === void 0 ? true : _evaluate2$flipAlignm, detectOverflowOptions = _objectWithoutProperties(_evaluate2, _excluded2); // If a reset by the arrow was caused due to an alignment offset being
574
+ // added, we should skip any logic now since `flip()` has already done its
575
+ // work.
576
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
577
+ if (!((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset)) {
578
+ _context4.next = 4;
579
+ break;
580
+ }
581
+ return _context4.abrupt("return", {});
582
+ case 4:
583
+ side = getSide(placement);
584
+ isBasePlacement = getSide(initialPlacement) === initialPlacement;
585
+ _context4.next = 8;
586
+ return platform.isRTL == null ? void 0 : platform.isRTL(elements.floating);
587
+ case 8:
588
+ rtl = _context4.sent;
589
+ fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
590
+ if (!specifiedFallbackPlacements && fallbackAxisSideDirection !== 'none') {
591
+ fallbackPlacements.push.apply(fallbackPlacements, _toConsumableArray(getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl)));
592
+ }
593
+ placements = [initialPlacement].concat(_toConsumableArray(fallbackPlacements));
594
+ _context4.next = 14;
595
+ return detectOverflow(state, detectOverflowOptions);
596
+ case 14:
597
+ overflow = _context4.sent;
598
+ overflows = [];
599
+ overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
600
+ if (checkMainAxis) {
601
+ overflows.push(overflow[side]);
602
+ }
603
+ if (checkCrossAxis) {
604
+ _sides = getAlignmentSides(placement, rects, rtl);
605
+ overflows.push(overflow[_sides[0]], overflow[_sides[1]]);
606
+ }
607
+ overflowsData = [].concat(_toConsumableArray(overflowsData), [{
608
+ placement: placement,
609
+ overflows: overflows
610
+ }]);
611
+
612
+ // One or more sides is overflowing.
613
+ if (overflows.every(function (side) {
614
+ return side <= 0;
615
+ })) {
616
+ _context4.next = 37;
617
+ break;
618
+ }
619
+ nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
620
+ nextPlacement = placements[nextIndex];
621
+ if (!nextPlacement) {
622
+ _context4.next = 25;
623
+ break;
624
+ }
625
+ return _context4.abrupt("return", {
626
+ data: {
627
+ index: nextIndex,
628
+ overflows: overflowsData
629
+ },
630
+ reset: {
631
+ placement: nextPlacement
632
+ }
633
+ });
634
+ case 25:
635
+ // First, find the candidates that fit on the mainAxis side of overflow,
636
+ // then find the placement that fits the best on the main crossAxis side.
637
+ resetPlacement = (_overflowsData$filter = overflowsData.filter(function (d) {
638
+ return d.overflows[0] <= 0;
639
+ }).sort(function (a, b) {
640
+ return a.overflows[1] - b.overflows[1];
641
+ })[0]) == null ? void 0 : _overflowsData$filter.placement; // Otherwise fallback.
642
+ if (resetPlacement) {
643
+ _context4.next = 35;
644
+ break;
645
+ }
646
+ _context4.t0 = fallbackStrategy;
647
+ _context4.next = _context4.t0 === 'bestFit' ? 30 : _context4.t0 === 'initialPlacement' ? 33 : 35;
648
+ break;
649
+ case 30:
650
+ _placement = (_overflowsData$map$so = overflowsData.map(function (d) {
651
+ return [d.placement, d.overflows.filter(function (overflow) {
652
+ return overflow > 0;
653
+ }).reduce(function (acc, overflow) {
654
+ return acc + overflow;
655
+ }, 0)];
656
+ }).sort(function (a, b) {
657
+ return a[1] - b[1];
658
+ })[0]) == null ? void 0 : _overflowsData$map$so[0];
659
+ if (_placement) {
660
+ resetPlacement = _placement;
661
+ }
662
+ return _context4.abrupt("break", 35);
663
+ case 33:
664
+ resetPlacement = initialPlacement;
665
+ return _context4.abrupt("break", 35);
666
+ case 35:
667
+ if (!(placement !== resetPlacement)) {
668
+ _context4.next = 37;
669
+ break;
670
+ }
671
+ return _context4.abrupt("return", {
672
+ reset: {
673
+ placement: resetPlacement
674
+ }
675
+ });
676
+ case 37:
677
+ return _context4.abrupt("return", {});
678
+ case 38:
679
+ case "end":
680
+ return _context4.stop();
681
+ }
682
+ }, _callee4);
683
+ }))();
684
+ }
685
+ };
686
+ };
687
+
688
+ // For type backwards-compatibility, the `OffsetOptions` type was also
689
+ // Derivable.
690
+ function convertValueToCoords(_x6, _x7) {
691
+ return _convertValueToCoords.apply(this, arguments);
692
+ }
693
+ /**
694
+ * Modifies the placement by translating the floating element along the
695
+ * specified axes.
696
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
697
+ * object may be passed.
698
+ * @see https://floating-ui.com/docs/offset
699
+ */
700
+ function _convertValueToCoords() {
701
+ _convertValueToCoords = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(state, options) {
702
+ var placement, platform, elements, rtl, side, alignment, isVertical, mainAxisMulti, crossAxisMulti, rawValue, _ref6, mainAxis, crossAxis, alignmentAxis;
703
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
704
+ while (1) switch (_context11.prev = _context11.next) {
705
+ case 0:
706
+ placement = state.placement, platform = state.platform, elements = state.elements;
707
+ _context11.next = 3;
708
+ return platform.isRTL == null ? void 0 : platform.isRTL(elements.floating);
709
+ case 3:
710
+ rtl = _context11.sent;
711
+ side = getSide(placement);
712
+ alignment = getAlignment(placement);
713
+ isVertical = getSideAxis(placement) === 'y';
714
+ mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
715
+ crossAxisMulti = rtl && isVertical ? -1 : 1;
716
+ rawValue = evaluate(options, state); // eslint-disable-next-line prefer-const
717
+ _ref6 = typeof rawValue === 'number' ? {
718
+ mainAxis: rawValue,
719
+ crossAxis: 0,
720
+ alignmentAxis: null
721
+ } : _objectSpread2({
722
+ mainAxis: 0,
723
+ crossAxis: 0,
724
+ alignmentAxis: null
725
+ }, rawValue), mainAxis = _ref6.mainAxis, crossAxis = _ref6.crossAxis, alignmentAxis = _ref6.alignmentAxis;
726
+ if (alignment && typeof alignmentAxis === 'number') {
727
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
728
+ }
729
+ return _context11.abrupt("return", isVertical ? {
730
+ x: crossAxis * crossAxisMulti,
731
+ y: mainAxis * mainAxisMulti
732
+ } : {
733
+ x: mainAxis * mainAxisMulti,
734
+ y: crossAxis * crossAxisMulti
735
+ });
736
+ case 13:
737
+ case "end":
738
+ return _context11.stop();
739
+ }
740
+ }, _callee11);
741
+ }));
742
+ return _convertValueToCoords.apply(this, arguments);
743
+ }
744
+ var offset$1 = function offset(options) {
745
+ return {
746
+ name: 'offset',
747
+ options: options,
748
+ fn: function fn(state) {
749
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
750
+ var _middlewareData$offse, _middlewareData$arrow, x, y, placement, middlewareData, diffCoords;
751
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
752
+ while (1) switch (_context7.prev = _context7.next) {
753
+ case 0:
754
+ x = state.x, y = state.y, placement = state.placement, middlewareData = state.middlewareData;
755
+ _context7.next = 3;
756
+ return convertValueToCoords(state, options);
757
+ case 3:
758
+ diffCoords = _context7.sent;
759
+ if (!(placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset)) {
760
+ _context7.next = 6;
761
+ break;
762
+ }
763
+ return _context7.abrupt("return", {});
764
+ case 6:
765
+ return _context7.abrupt("return", {
766
+ x: x + diffCoords.x,
767
+ y: y + diffCoords.y,
768
+ data: _objectSpread2(_objectSpread2({}, diffCoords), {}, {
769
+ placement: placement
770
+ })
771
+ });
772
+ case 7:
773
+ case "end":
774
+ return _context7.stop();
775
+ }
776
+ }, _callee7);
777
+ }))();
778
+ }
779
+ };
780
+ };
781
+
782
+ /**
783
+ * Optimizes the visibility of the floating element by shifting it in order to
784
+ * keep it in view when it will overflow the clipping boundary.
785
+ * @see https://floating-ui.com/docs/shift
786
+ */
787
+ var shift$1 = function shift(options) {
788
+ if (options === void 0) {
789
+ options = {};
790
+ }
791
+ return {
792
+ name: 'shift',
793
+ options: options,
794
+ fn: function fn(state) {
795
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
796
+ var x, y, placement, _evaluate5, _evaluate5$mainAxis, checkMainAxis, _evaluate5$crossAxis, checkCrossAxis, _evaluate5$limiter, limiter, detectOverflowOptions, coords, overflow, crossAxis, mainAxis, mainAxisCoord, crossAxisCoord, minSide, maxSide, _min, _max, _minSide, _maxSide, _min2, _max2, limitedCoords;
797
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
798
+ while (1) switch (_context8.prev = _context8.next) {
799
+ case 0:
800
+ x = state.x, y = state.y, placement = state.placement;
801
+ _evaluate5 = evaluate(options, state), _evaluate5$mainAxis = _evaluate5.mainAxis, checkMainAxis = _evaluate5$mainAxis === void 0 ? true : _evaluate5$mainAxis, _evaluate5$crossAxis = _evaluate5.crossAxis, checkCrossAxis = _evaluate5$crossAxis === void 0 ? false : _evaluate5$crossAxis, _evaluate5$limiter = _evaluate5.limiter, limiter = _evaluate5$limiter === void 0 ? {
802
+ fn: function fn(_ref) {
803
+ var x = _ref.x,
804
+ y = _ref.y;
805
+ return {
806
+ x: x,
807
+ y: y
808
+ };
809
+ }
810
+ } : _evaluate5$limiter, detectOverflowOptions = _objectWithoutProperties(_evaluate5, _excluded4);
811
+ coords = {
812
+ x: x,
813
+ y: y
814
+ };
815
+ _context8.next = 5;
816
+ return detectOverflow(state, detectOverflowOptions);
817
+ case 5:
818
+ overflow = _context8.sent;
819
+ crossAxis = getSideAxis(getSide(placement));
820
+ mainAxis = getOppositeAxis(crossAxis);
821
+ mainAxisCoord = coords[mainAxis];
822
+ crossAxisCoord = coords[crossAxis];
823
+ if (checkMainAxis) {
824
+ minSide = mainAxis === 'y' ? 'top' : 'left';
825
+ maxSide = mainAxis === 'y' ? 'bottom' : 'right';
826
+ _min = mainAxisCoord + overflow[minSide];
827
+ _max = mainAxisCoord - overflow[maxSide];
828
+ mainAxisCoord = clamp(_min, mainAxisCoord, _max);
829
+ }
830
+ if (checkCrossAxis) {
831
+ _minSide = crossAxis === 'y' ? 'top' : 'left';
832
+ _maxSide = crossAxis === 'y' ? 'bottom' : 'right';
833
+ _min2 = crossAxisCoord + overflow[_minSide];
834
+ _max2 = crossAxisCoord - overflow[_maxSide];
835
+ crossAxisCoord = clamp(_min2, crossAxisCoord, _max2);
836
+ }
837
+ limitedCoords = limiter.fn(_objectSpread2(_objectSpread2({}, state), {}, _defineProperty(_defineProperty({}, mainAxis, mainAxisCoord), crossAxis, crossAxisCoord)));
838
+ return _context8.abrupt("return", _objectSpread2(_objectSpread2({}, limitedCoords), {}, {
839
+ data: {
840
+ x: limitedCoords.x - x,
841
+ y: limitedCoords.y - y
842
+ }
843
+ }));
844
+ case 14:
845
+ case "end":
846
+ return _context8.stop();
847
+ }
848
+ }, _callee8);
849
+ }))();
850
+ }
851
+ };
852
+ };
853
+ /**
854
+ * Built-in `limiter` that will stop `shift()` at a certain point.
855
+ */
856
+ var limitShift$1 = function limitShift(options) {
857
+ if (options === void 0) {
858
+ options = {};
859
+ }
860
+ return {
861
+ options: options,
862
+ fn: function fn(state) {
863
+ var x = state.x,
864
+ y = state.y,
865
+ placement = state.placement,
866
+ rects = state.rects,
867
+ middlewareData = state.middlewareData;
868
+ var _evaluate6 = evaluate(options, state),
869
+ _evaluate6$offset = _evaluate6.offset,
870
+ offset = _evaluate6$offset === void 0 ? 0 : _evaluate6$offset,
871
+ _evaluate6$mainAxis = _evaluate6.mainAxis,
872
+ checkMainAxis = _evaluate6$mainAxis === void 0 ? true : _evaluate6$mainAxis,
873
+ _evaluate6$crossAxis = _evaluate6.crossAxis,
874
+ checkCrossAxis = _evaluate6$crossAxis === void 0 ? true : _evaluate6$crossAxis;
875
+ var coords = {
876
+ x: x,
877
+ y: y
878
+ };
879
+ var crossAxis = getSideAxis(placement);
880
+ var mainAxis = getOppositeAxis(crossAxis);
881
+ var mainAxisCoord = coords[mainAxis];
882
+ var crossAxisCoord = coords[crossAxis];
883
+ var rawOffset = evaluate(offset, state);
884
+ var computedOffset = typeof rawOffset === 'number' ? {
885
+ mainAxis: rawOffset,
886
+ crossAxis: 0
887
+ } : _objectSpread2({
888
+ mainAxis: 0,
889
+ crossAxis: 0
890
+ }, rawOffset);
891
+ if (checkMainAxis) {
892
+ var len = mainAxis === 'y' ? 'height' : 'width';
893
+ var limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
894
+ var limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
895
+ if (mainAxisCoord < limitMin) {
896
+ mainAxisCoord = limitMin;
897
+ } else if (mainAxisCoord > limitMax) {
898
+ mainAxisCoord = limitMax;
899
+ }
900
+ }
901
+ if (checkCrossAxis) {
902
+ var _middlewareData$offse, _middlewareData$offse2;
903
+ var _len = mainAxis === 'y' ? 'width' : 'height';
904
+ var isOriginSide = ['top', 'left'].includes(getSide(placement));
905
+ var _limitMin = rects.reference[crossAxis] - rects.floating[_len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
906
+ var _limitMax = rects.reference[crossAxis] + rects.reference[_len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
907
+ if (crossAxisCoord < _limitMin) {
908
+ crossAxisCoord = _limitMin;
909
+ } else if (crossAxisCoord > _limitMax) {
910
+ crossAxisCoord = _limitMax;
911
+ }
912
+ }
913
+ return _defineProperty(_defineProperty({}, mainAxis, mainAxisCoord), crossAxis, crossAxisCoord);
914
+ }
915
+ };
916
+ };
917
+
918
+ var ORIGIN$1 = {
919
+ x: 0,
920
+ y: 0
921
+ };
922
+ function isView(reference) {
923
+ return 'measure' in reference;
924
+ }
925
+ var createPlatform = function createPlatform(_ref) {
926
+ var offsetParent = _ref.offsetParent,
927
+ _ref$sameScrollView = _ref.sameScrollView,
928
+ sameScrollView = _ref$sameScrollView === void 0 ? true : _ref$sameScrollView,
929
+ _ref$scrollOffsets = _ref.scrollOffsets,
930
+ scrollOffsets = _ref$scrollOffsets === void 0 ? ORIGIN$1 : _ref$scrollOffsets;
931
+ return {
932
+ getElementRects: function getElementRects(_ref2) {
933
+ var reference = _ref2.reference,
934
+ floating = _ref2.floating;
935
+ return new Promise(function (resolve) {
936
+ var onMeasure = function onMeasure(offsetX, offsetY) {
937
+ if (offsetX === void 0) {
938
+ offsetX = 0;
939
+ }
940
+ if (offsetY === void 0) {
941
+ offsetY = 0;
942
+ }
943
+ floating.measure(function (x, y, width, height) {
944
+ var floatingRect = _objectSpread2({
945
+ width: width,
946
+ height: height
947
+ }, ORIGIN$1);
948
+ var method = sameScrollView ? 'measure' : 'measureInWindow';
949
+ if (isView(reference)) {
950
+ reference[method](function (x, y, width, height) {
951
+ var referenceRect = {
952
+ width: width,
953
+ height: height,
954
+ x: x - offsetX,
955
+ y: y - offsetY
956
+ };
957
+ resolve({
958
+ reference: referenceRect,
959
+ floating: floatingRect
960
+ });
961
+ });
962
+ } else {
963
+ var boundingRect = reference.getBoundingClientRect();
964
+ var referenceRect = {
965
+ width: boundingRect.width,
966
+ height: boundingRect.height,
967
+ x: boundingRect.x - offsetX,
968
+ y: boundingRect.y - offsetY
969
+ };
970
+ resolve({
971
+ reference: referenceRect,
972
+ floating: floatingRect
973
+ });
974
+ }
975
+ });
976
+ };
977
+ if (offsetParent) {
978
+ offsetParent.measure(onMeasure);
979
+ } else {
980
+ onMeasure();
981
+ }
982
+ });
983
+ },
984
+ getClippingRect: function getClippingRect() {
985
+ var _Dimensions$get = Dimensions.get('window'),
986
+ width = _Dimensions$get.width,
987
+ height = _Dimensions$get.height;
988
+ return Promise.resolve(_objectSpread2({
989
+ width: width,
990
+ height: height
991
+ }, sameScrollView ? scrollOffsets : ORIGIN$1));
992
+ },
993
+ convertOffsetParentRelativeRectToViewportRelativeRect: function convertOffsetParentRelativeRectToViewportRelativeRect(_ref3) {
994
+ var rect = _ref3.rect;
995
+ return new Promise(function (resolve) {
996
+ var onMeasure = function onMeasure(offsetX, offsetY) {
997
+ if (offsetX === void 0) {
998
+ offsetX = 0;
999
+ }
1000
+ if (offsetY === void 0) {
1001
+ offsetY = 0;
1002
+ }
1003
+ resolve(_objectSpread2(_objectSpread2({}, rect), {}, {
1004
+ x: rect.x + offsetX,
1005
+ y: rect.y + offsetY
1006
+ }));
1007
+ };
1008
+ if (offsetParent) {
1009
+ offsetParent.measure(onMeasure);
1010
+ } else {
1011
+ onMeasure();
1012
+ }
1013
+ });
1014
+ },
1015
+ getDimensions: function getDimensions(element) {
1016
+ return new Promise(function (resolve) {
1017
+ return element.measure(function (x, y, width, height) {
1018
+ return resolve({
1019
+ width: width,
1020
+ height: height
1021
+ });
1022
+ });
1023
+ });
1024
+ }
1025
+ };
1026
+ };
1027
+
1028
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
1029
+ // functions
1030
+ function deepEqual(a, b) {
1031
+ if (a === b) {
1032
+ return true;
1033
+ }
1034
+ if (_typeof(a) !== _typeof(b)) {
1035
+ return false;
1036
+ }
1037
+ if (typeof a === 'function' && a.toString() === b.toString()) {
1038
+ return true;
1039
+ }
1040
+ var length;
1041
+ var i;
1042
+ var keys;
1043
+ if (a && b && _typeof(a) === 'object') {
1044
+ if (Array.isArray(a)) {
1045
+ length = a.length;
1046
+ if (length !== b.length) return false;
1047
+ for (i = length; i-- !== 0;) {
1048
+ if (!deepEqual(a[i], b[i])) {
1049
+ return false;
1050
+ }
1051
+ }
1052
+ return true;
1053
+ }
1054
+ keys = Object.keys(a);
1055
+ length = keys.length;
1056
+ if (length !== Object.keys(b).length) {
1057
+ return false;
1058
+ }
1059
+ for (i = length; i-- !== 0;) {
1060
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
1061
+ return false;
1062
+ }
1063
+ }
1064
+ for (i = length; i-- !== 0;) {
1065
+ var key = keys[i];
1066
+ if (key === '_owner' && a.$$typeof) {
1067
+ continue;
1068
+ }
1069
+ if (!deepEqual(a[key], b[key])) {
1070
+ return false;
1071
+ }
1072
+ }
1073
+ return true;
1074
+ }
1075
+ return a !== a && b !== b;
1076
+ }
1077
+ var ORIGIN = {
1078
+ x: 0,
1079
+ y: 0
1080
+ };
1081
+ function useFloating$1(options) {
1082
+ if (options === void 0) {
1083
+ options = {};
1084
+ }
1085
+ var _options = options,
1086
+ _options$placement = _options.placement,
1087
+ placement = _options$placement === void 0 ? 'bottom' : _options$placement,
1088
+ _options$middleware = _options.middleware,
1089
+ middleware = _options$middleware === void 0 ? [] : _options$middleware,
1090
+ _options$sameScrollVi = _options.sameScrollView,
1091
+ sameScrollView = _options$sameScrollVi === void 0 ? true : _options$sameScrollVi,
1092
+ _options$elements = _options.elements,
1093
+ _options$elements2 = _options$elements === void 0 ? {} : _options$elements,
1094
+ externalReference = _options$elements2.reference,
1095
+ externalFloating = _options$elements2.floating,
1096
+ externalOffsetParent = _options$elements2.offsetParent;
1097
+ var _React$useState = React.useState(null),
1098
+ _React$useState2 = _slicedToArray(_React$useState, 2),
1099
+ _reference = _React$useState2[0],
1100
+ _setReference = _React$useState2[1];
1101
+ var _React$useState3 = React.useState(null),
1102
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
1103
+ _floating = _React$useState4[0],
1104
+ _setFloating = _React$useState4[1];
1105
+ var _React$useState5 = React.useState(null),
1106
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
1107
+ _offsetParent = _React$useState6[0],
1108
+ _setOffsetParent = _React$useState6[1];
1109
+ var referenceEl = externalReference || _reference;
1110
+ var floatingEl = externalFloating || _floating;
1111
+ var offsetParentEl = externalOffsetParent || _offsetParent;
1112
+ var setReference = React.useCallback(function (node) {
1113
+ if (node !== referenceRef.current) {
1114
+ referenceRef.current = node;
1115
+ _setReference(node);
1116
+ }
1117
+ }, []);
1118
+ var setFloating = React.useCallback(function (node) {
1119
+ if (node !== floatingRef.current) {
1120
+ floatingRef.current = node;
1121
+ _setFloating(node);
1122
+ }
1123
+ }, []);
1124
+ var setOffsetParent = React.useCallback(function (node) {
1125
+ if (node !== offsetParentRef.current) {
1126
+ offsetParentRef.current = node;
1127
+ _setOffsetParent(node);
1128
+ }
1129
+ }, []);
1130
+ var referenceRef = React.useRef(null);
1131
+ var floatingRef = React.useRef(null);
1132
+ var offsetParentRef = React.useRef(null);
1133
+ var _React$useState7 = React.useState({
1134
+ x: 0,
1135
+ y: 0,
1136
+ placement: placement,
1137
+ strategy: 'absolute',
1138
+ middlewareData: {}
1139
+ }),
1140
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
1141
+ data = _React$useState8[0],
1142
+ setData = _React$useState8[1];
1143
+ var _React$useState9 = React.useState(ORIGIN),
1144
+ _React$useState10 = _slicedToArray(_React$useState9, 2),
1145
+ scrollOffsets = _React$useState10[0],
1146
+ setScrollOffsets = _React$useState10[1];
1147
+ var _React$useState11 = React.useState(middleware),
1148
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
1149
+ latestMiddleware = _React$useState12[0],
1150
+ setLatestMiddleware = _React$useState12[1];
1151
+ if (!deepEqual(latestMiddleware, middleware)) {
1152
+ setLatestMiddleware(middleware);
1153
+ }
1154
+ var platform = React.useMemo(function () {
1155
+ return createPlatform({
1156
+ offsetParent: offsetParentEl,
1157
+ scrollOffsets: scrollOffsets,
1158
+ sameScrollView: sameScrollView
1159
+ });
1160
+ }, [offsetParentEl, scrollOffsets, sameScrollView]);
1161
+ var update = React.useCallback(function () {
1162
+ if (!referenceRef.current || !floatingRef.current) {
1163
+ return;
1164
+ }
1165
+ computePosition(referenceRef.current, floatingRef.current, {
1166
+ middleware: latestMiddleware,
1167
+ platform: platform,
1168
+ placement: placement
1169
+ }).then(function (data) {
1170
+ if (isMountedRef.current) {
1171
+ setData(data);
1172
+ }
1173
+ });
1174
+ }, [latestMiddleware, platform, placement]);
1175
+ React.useLayoutEffect(function () {
1176
+ if (referenceEl) referenceRef.current = referenceEl;
1177
+ if (floatingEl) floatingRef.current = floatingEl;
1178
+ if (offsetParentEl) offsetParentRef.current = offsetParentEl;
1179
+ var frame = requestAnimationFrame(update);
1180
+ return function () {
1181
+ cancelAnimationFrame(frame);
1182
+ };
1183
+ }, [referenceEl, floatingEl, offsetParentEl, update]);
1184
+ var isMountedRef = React.useRef(true);
1185
+ React.useLayoutEffect(function () {
1186
+ isMountedRef.current = true;
1187
+ return function () {
1188
+ isMountedRef.current = false;
1189
+ };
1190
+ }, []);
1191
+ var refs = React.useMemo(function () {
1192
+ return {
1193
+ reference: referenceRef,
1194
+ floating: floatingRef,
1195
+ offsetParent: offsetParentRef,
1196
+ setReference: setReference,
1197
+ setFloating: setFloating,
1198
+ setOffsetParent: setOffsetParent
1199
+ };
1200
+ }, [setReference, setFloating, setOffsetParent]);
1201
+ var elements = React.useMemo(function () {
1202
+ return {
1203
+ reference: referenceEl,
1204
+ floating: floatingEl,
1205
+ offsetParent: offsetParentEl
1206
+ };
1207
+ }, [referenceEl, floatingEl, offsetParentEl]);
1208
+ var floatingStyles = React.useMemo(function () {
1209
+ if (!elements.floating) {
1210
+ return {
1211
+ position: 'absolute',
1212
+ left: 0,
1213
+ top: 0
1214
+ };
1215
+ }
1216
+ return {
1217
+ position: 'absolute',
1218
+ left: data.x,
1219
+ top: data.y
1220
+ };
1221
+ }, [elements.floating, data.x, data.y]);
1222
+ return React.useMemo(function () {
1223
+ return _objectSpread2(_objectSpread2({}, data), {}, {
1224
+ update: update,
1225
+ refs: refs,
1226
+ elements: elements,
1227
+ floatingStyles: floatingStyles,
1228
+ offsetParent: setOffsetParent,
1229
+ reference: setReference,
1230
+ floating: setFloating,
1231
+ scrollProps: {
1232
+ onScroll: function onScroll(event) {
1233
+ return setScrollOffsets(event.nativeEvent.contentOffset);
1234
+ },
1235
+ scrollEventThrottle: 16
1236
+ }
1237
+ });
1238
+ }, [data, refs, elements, floatingStyles, setReference, setFloating, setOffsetParent, update]);
1239
+ }
1240
+
1241
+ /**
1242
+ * A data provider that provides data to position an inner element of the
1243
+ * floating element (usually a triangle or caret) so that it is centered to the
1244
+ * reference element.
1245
+ * This wraps the core `arrow` middleware to allow React refs as the element.
1246
+ * @see https://floating-ui.com/docs/arrow
1247
+ */
1248
+ var arrow$1 = function arrow$1(options) {
1249
+ function isRef(value) {
1250
+ return {}.hasOwnProperty.call(value, 'current');
1251
+ }
1252
+ return {
1253
+ name: 'arrow',
1254
+ options: options,
1255
+ fn: function fn(state) {
1256
+ var _ref4 = typeof options === 'function' ? options(state) : options,
1257
+ element = _ref4.element,
1258
+ padding = _ref4.padding;
1259
+ if (element && isRef(element)) {
1260
+ if (element.current != null) {
1261
+ return arrow$2({
1262
+ element: element.current,
1263
+ padding: padding
1264
+ }).fn(state);
1265
+ }
1266
+ return {};
1267
+ }
1268
+ if (element) {
1269
+ return arrow$2({
1270
+ element: element,
1271
+ padding: padding
1272
+ }).fn(state);
1273
+ }
1274
+ return {};
1275
+ }
1276
+ };
1277
+ };
1278
+
1279
+ /**
1280
+ * Modifies the placement by translating the floating element along the
1281
+ * specified axes.
1282
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
1283
+ * object may be passed.
1284
+ * @see https://floating-ui.com/docs/offset
1285
+ */
1286
+ var offset = function offset(options, deps) {
1287
+ return _objectSpread2(_objectSpread2({}, offset$1(options)), {}, {
1288
+ options: [options, deps]
1289
+ });
1290
+ };
1291
+
1292
+ /**
1293
+ * Optimizes the visibility of the floating element by shifting it in order to
1294
+ * keep it in view when it will overflow the clipping boundary.
1295
+ * @see https://floating-ui.com/docs/shift
1296
+ */
1297
+ var shift = function shift(options, deps) {
1298
+ return _objectSpread2(_objectSpread2({}, shift$1(options)), {}, {
1299
+ options: [options, deps]
1300
+ });
1301
+ };
1302
+
1303
+ /**
1304
+ * Built-in `limiter` that will stop `shift()` at a certain point.
1305
+ */
1306
+ var limitShift = function limitShift(options, deps) {
1307
+ return _objectSpread2(_objectSpread2({}, limitShift$1(options)), {}, {
1308
+ options: [options, deps]
1309
+ });
1310
+ };
1311
+
1312
+ /**
1313
+ * Optimizes the visibility of the floating element by flipping the `placement`
1314
+ * in order to keep it in view when the preferred placement(s) will overflow the
1315
+ * clipping boundary. Alternative to `autoPlacement`.
1316
+ * @see https://floating-ui.com/docs/flip
1317
+ */
1318
+ var flip = function flip(options, deps) {
1319
+ return _objectSpread2(_objectSpread2({}, flip$1(options)), {}, {
1320
+ options: [options, deps]
1321
+ });
1322
+ };
1323
+
1324
+ /**
1325
+ * Provides data to position an inner element of the floating element so that it
1326
+ * appears centered to the reference element.
1327
+ * This wraps the core `arrow` middleware to allow React refs as the element.
1328
+ * @see https://floating-ui.com/docs/arrow
1329
+ */
1330
+ var arrow = function arrow(options, deps) {
1331
+ return _objectSpread2(_objectSpread2({}, arrow$1(options)), {}, {
1332
+ options: [options, deps]
1333
+ });
1334
+ };
1335
+
1336
+ var _excluded = ["refs", "floatingStyles", "middlewareData", "elements"];
1337
+ var useFloating = function useFloating(_ref) {
1338
+ var _middlewareData$arrow, _middlewareData$offse, _middlewareData$offse2;
1339
+ var placement = _ref.placement,
1340
+ needModal = _ref.needModal;
1341
+ var _useState = useState(0),
1342
+ _useState2 = _slicedToArray(_useState, 2),
1343
+ floatingHeight = _useState2[0],
1344
+ setfloatingHeight = _useState2[1];
1345
+ var arrowRef = useRef(null);
1346
+ var _useFloatingUI = useFloating$1({
1347
+ placement: placement,
1348
+ sameScrollView: !needModal,
1349
+ // offset 9,箭头加空隙的宽度
1350
+ middleware: [shift({
1351
+ limiter: limitShift({
1352
+ offset: 9
1353
+ }),
1354
+ padding: 8
1355
+ }), flip(), offset(9), arrow({
1356
+ element: arrowRef,
1357
+ padding: 8
1358
+ })]
1359
+ }),
1360
+ refs = _useFloatingUI.refs,
1361
+ floatingStyles = _useFloatingUI.floatingStyles,
1362
+ middlewareData = _useFloatingUI.middlewareData,
1363
+ elements = _useFloatingUI.elements,
1364
+ other = _objectWithoutProperties(_useFloatingUI, _excluded);
1365
+ useEffect(function () {
1366
+ var _elements$floating;
1367
+ (_elements$floating = elements.floating) === null || _elements$floating === void 0 || _elements$floating.measure(function (x, y, width, height, pageX, pageY) {
1368
+ setfloatingHeight(height);
1369
+ });
1370
+ });
1371
+ return _objectSpread2({
1372
+ setFloatingRef: function setFloatingRef(ref) {
1373
+ return refs.setFloating(ref);
1374
+ },
1375
+ setReferenceRef: function setReferenceRef(ref) {
1376
+ return refs.setReference(ref);
1377
+ },
1378
+ setOffsetParentRef: refs.offsetParent,
1379
+ setArrowRef: arrowRef,
1380
+ refs: refs,
1381
+ elements: elements,
1382
+ middlewareData: middlewareData,
1383
+ floatingStyles: floatingStyles,
1384
+ arrowStyles: {
1385
+ position: "absolute",
1386
+ left: ((_middlewareData$arrow = middlewareData.arrow) === null || _middlewareData$arrow === void 0 ? void 0 : _middlewareData$arrow.x) != null ? middlewareData.arrow.x : null,
1387
+ top: (_middlewareData$offse = middlewareData.offset) !== null && _middlewareData$offse !== void 0 && _middlewareData$offse.placement.includes("top") ? floatingHeight : -12,
1388
+ transform: (_middlewareData$offse2 = middlewareData.offset) !== null && _middlewareData$offse2 !== void 0 && _middlewareData$offse2.placement.includes("top") ? "rotate(180deg)" : "rotate(0deg)"
1389
+ }
1390
+ }, other);
1391
+ };
1392
+
1393
+ export { useFloating };
1394
+ //# sourceMappingURL=hook.js.map