@xaui/native 0.9.1-alpha.38 → 0.9.1-alpha.39

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 (35) hide show
  1. package/dist/chunk-2EGR4LWD.js +145 -0
  2. package/dist/chunk-37L7YGZV.cjs +425 -0
  3. package/dist/chunk-64MXEVT3.js +66 -0
  4. package/dist/{chunk-RAWGK2XK.cjs → chunk-76XDVA24.cjs} +43 -133
  5. package/dist/{chunk-Q3MQ7S2D.cjs → chunk-7KLBTMXV.cjs} +6 -4
  6. package/dist/chunk-EKS3W46M.cjs +66 -0
  7. package/dist/{chunk-ZF6KIHXH.js → chunk-GJSFKH4L.js} +15 -20
  8. package/dist/{chunk-ZNZ7HVRW.js → chunk-JKP4TPIL.js} +51 -217
  9. package/dist/chunk-LUPCPLND.cjs +145 -0
  10. package/dist/chunk-XAFP5JLK.js +425 -0
  11. package/dist/components/accordion/index.cjs +3 -2
  12. package/dist/components/accordion/index.js +2 -1
  13. package/dist/components/badge/index.d.cts +1 -1
  14. package/dist/components/badge/index.d.ts +1 -1
  15. package/dist/components/popover/index.cjs +37 -0
  16. package/dist/components/popover/index.d.cts +254 -0
  17. package/dist/components/popover/index.d.ts +254 -0
  18. package/dist/components/popover/index.js +37 -0
  19. package/dist/components/select/index.cjs +4 -2
  20. package/dist/components/select/index.d.cts +14 -25
  21. package/dist/components/select/index.d.ts +14 -25
  22. package/dist/components/select/index.js +3 -1
  23. package/dist/index.cjs +42 -5
  24. package/dist/index.d.cts +3 -1
  25. package/dist/index.d.ts +3 -1
  26. package/dist/index.js +44 -7
  27. package/dist/placement-DHa0Rrh1.d.cts +38 -0
  28. package/dist/placement-DHa0Rrh1.d.ts +38 -0
  29. package/dist/system/index.cjs +16 -2
  30. package/dist/system/index.d.cts +38 -2
  31. package/dist/system/index.d.ts +38 -2
  32. package/dist/system/index.js +15 -1
  33. package/package.json +11 -1
  34. /package/dist/{chunk-OJCCV65P.cjs → chunk-GGW43Q37.cjs} +0 -0
  35. /package/dist/{chunk-MESKS6AI.js → chunk-WHJTBTYM.js} +0 -0
@@ -1,4 +1,6 @@
1
- import { Portal, PortalContext } from "./chunk-2PMXMKS5.js";
1
+ import { useAnchoredPosition } from "./chunk-2EGR4LWD.js";
2
+ import { Portal } from "./chunk-2PMXMKS5.js";
3
+ import { INDICATOR_ROTATION, INDICATOR_SPRING, anchoredEntering, anchoredExiting, overlayEntering, overlayExiting } from "./chunk-64MXEVT3.js";
2
4
  import { useMergedRef } from "./chunk-NCTOTTVW.js";
3
5
  import { ChevronDownIcon, Icon, IconContext } from "./chunk-FHUYHV6J.js";
4
6
  import { useControllableState } from "./chunk-F6W3JQ7K.js";
@@ -10,91 +12,22 @@ import { useXAUITheme } from "./chunk-A3EGFI6T.js";
10
12
  import { useStyleProps } from "./chunk-M63GFNKV.js";
11
13
 
12
14
  // src/components/select/select-content.tsx
13
- import { forwardRef as forwardRef3, useContext, useEffect as useEffect2, useState } from "react";
14
- import { ScrollView, useWindowDimensions } from "react-native";
15
+ import { forwardRef as forwardRef3 } from "react";
16
+ import { ScrollView } from "react-native";
15
17
  import Animated from "react-native-reanimated";
16
18
 
17
- // src/components/select/select.context.ts
18
- var [SelectProvider, useSelect] = createSlotContext("Select");
19
- var [SelectItemProvider, useSelectItem] = createSlotContext("Select.Item");
20
-
21
- // src/components/select/select.animation.ts
22
- import { Easing, Keyframe } from "react-native-reanimated";
23
- var INDICATOR_SPRING = {
24
- damping: 140,
25
- stiffness: 1e3,
26
- mass: 4
27
- };
28
- var INDICATOR_ROTATION = [0, -180];
29
- var ENTER_MS = 200;
30
- var EXIT_MS = 150;
31
- function contentEntering(placement) {
32
- const from = placement === "bottom" ? -8 : 8;
33
- return new Keyframe({
34
- 0: {
35
- opacity: 0,
36
- transform: [{
37
- translateY: from
38
- }, {
39
- scale: 0.95
40
- }]
41
- },
42
- 100: {
43
- opacity: 1,
44
- transform: [{
45
- translateY: 0
46
- }, {
47
- scale: 1
48
- }],
49
- easing: Easing.out(Easing.cubic)
50
- }
51
- }).duration(ENTER_MS);
52
- }
53
- function contentExiting(placement) {
54
- const to = placement === "bottom" ? -8 : 8;
55
- return new Keyframe({
56
- 0: {
57
- opacity: 1,
58
- transform: [{
59
- translateY: 0
60
- }, {
61
- scale: 1
62
- }]
63
- },
64
- 100: {
65
- opacity: 0,
66
- transform: [{
67
- translateY: to
68
- }, {
69
- scale: 0.95
70
- }],
71
- easing: Easing.in(Easing.cubic)
72
- }
73
- }).duration(EXIT_MS);
74
- }
75
- var overlayEntering = new Keyframe({
76
- 0: {
77
- opacity: 0
78
- },
79
- 100: {
80
- opacity: 1
81
- }
82
- }).duration(ENTER_MS);
83
- var overlayExiting = new Keyframe({
84
- 0: {
85
- opacity: 1
86
- },
87
- 100: {
88
- opacity: 0
89
- }
90
- }).duration(EXIT_MS);
91
-
92
19
  // src/components/select/select-item.tsx
93
20
  import { forwardRef as forwardRef2, useCallback, useEffect, useMemo } from "react";
94
21
 
95
22
  // src/components/select/select-item-label.tsx
96
23
  import { forwardRef } from "react";
97
24
  import { Text } from "react-native";
25
+
26
+ // src/components/select/select.context.ts
27
+ var [SelectProvider, useSelect] = createSlotContext("Select");
28
+ var [SelectItemProvider, useSelectItem] = createSlotContext("Select.Item");
29
+
30
+ // src/components/select/select-item-label.tsx
98
31
  import { jsx } from "react/jsx-runtime";
99
32
  var SelectItemLabel = forwardRef(function SelectItemLabel2({
100
33
  children,
@@ -191,70 +124,6 @@ SelectItem.displayName = "XAUI.Select.Item";
191
124
 
192
125
  // src/components/select/select.utils.ts
193
126
  import { Children, isValidElement } from "react";
194
- function resolvePlacement(input) {
195
- const {
196
- anchor,
197
- content,
198
- window,
199
- offset,
200
- alignOffset,
201
- insets
202
- } = input;
203
- const available = window.width - insets.start - insets.end;
204
- const width = Math.min(resolveWidth(input), Math.max(available, 0));
205
- const placement = choosePlacement(input);
206
- const maxHeight = Math.max(roomFor(placement, input), 0);
207
- const height = Math.min(content.height, maxHeight);
208
- const top = placement === "bottom" ? anchor.y + anchor.height + offset : anchor.y - offset - height;
209
- const start = clamp(alignedStart(input, width) + alignOffset, insets.start, Math.max(window.width - insets.end - width, insets.start));
210
- return {
211
- top,
212
- start,
213
- width,
214
- maxHeight,
215
- placement
216
- };
217
- }
218
- function resolveWidth({
219
- width,
220
- anchor,
221
- content
222
- }) {
223
- if (width === "trigger") return anchor.width;
224
- if (width === "content-fit") return content.width;
225
- return width;
226
- }
227
- function choosePlacement(input) {
228
- const {
229
- placement,
230
- avoidCollisions,
231
- content
232
- } = input;
233
- if (!avoidCollisions) return placement;
234
- if (roomFor(placement, input) >= content.height) return placement;
235
- const other = placement === "bottom" ? "top" : "bottom";
236
- return roomFor(other, input) > roomFor(placement, input) ? other : placement;
237
- }
238
- function roomFor(placement, input) {
239
- const {
240
- anchor,
241
- window,
242
- offset,
243
- insets
244
- } = input;
245
- return placement === "bottom" ? window.height - insets.bottom - (anchor.y + anchor.height) - offset : anchor.y - insets.top - offset;
246
- }
247
- function alignedStart({
248
- align,
249
- anchor
250
- }, width) {
251
- if (align === "start") return anchor.x;
252
- if (align === "end") return anchor.x + anchor.width - width;
253
- return anchor.x + (anchor.width - width) / 2;
254
- }
255
- function clamp(value, min, max) {
256
- return Math.min(Math.max(value, min), max);
257
- }
258
127
  function collectItemLabels(children, isItem) {
259
128
  const found = [];
260
129
  const walk = node => {
@@ -274,19 +143,16 @@ function collectItemLabels(children, isItem) {
274
143
  }
275
144
 
276
145
  // src/components/select/select-content.tsx
146
+ import { useEffect as useEffect2 } from "react";
277
147
  import { jsx as jsx3 } from "react/jsx-runtime";
278
148
  var DEFAULT_OFFSET = 8;
279
- var ZERO = {
280
- x: 0,
281
- y: 0
282
- };
283
- var isSelectItem = type => type === SelectItem;
284
149
  var DEFAULT_INSETS = {
285
150
  top: 12,
286
151
  bottom: 12,
287
152
  start: 12,
288
153
  end: 12
289
154
  };
155
+ var isSelectItem = type => type === SelectItem;
290
156
  var SelectContent = forwardRef3(function SelectContent2({
291
157
  children,
292
158
  placement = "bottom",
@@ -304,48 +170,17 @@ var SelectContent = forwardRef3(function SelectContent2({
304
170
  const {
305
171
  contentStyle,
306
172
  isOpen,
307
- anchor
173
+ anchor,
174
+ registerLabel
308
175
  } = context;
309
176
  const [styleProps, rest] = useStyleProps(props);
310
- const window = useWindowDimensions();
311
- const origin = useContext(PortalContext)?.origin ?? ZERO;
312
- const [measured, setMeasured] = useState(null);
313
177
  const {
314
- registerLabel
315
- } = context;
316
- useEffect2(() => {
317
- for (const [value, label] of collectItemLabels(children, isSelectItem)) {
318
- registerLabel(value, label);
319
- }
320
- }, [children, registerLabel]);
321
- if (!isOpen && measured !== null) setMeasured(null);
322
- if (!isOpen || anchor === null) return null;
323
- const measure = event => {
324
- onLayout?.(event);
325
- const {
326
- width: w,
327
- height: h
328
- } = event.nativeEvent.layout;
329
- if (measured === null || measured.height !== h || measured.width !== w) {
330
- setMeasured({
331
- width: w,
332
- height: h
333
- });
334
- }
335
- };
336
- const local = {
337
- ...anchor,
338
- x: anchor.x - origin.x,
339
- y: anchor.y - origin.y
340
- };
341
- const position = measured && resolvePlacement({
342
- anchor: local,
343
- content: measured,
344
- // The window in the host's own coordinates, for the same reason as the anchor.
345
- window: {
346
- width: window.width - origin.x,
347
- height: window.height - origin.y
348
- },
178
+ position,
179
+ onContentLayout,
180
+ measuringStyle
181
+ } = useAnchoredPosition({
182
+ anchor,
183
+ isOpen,
349
184
  placement,
350
185
  align,
351
186
  width,
@@ -355,26 +190,25 @@ var SelectContent = forwardRef3(function SelectContent2({
355
190
  insets: {
356
191
  ...DEFAULT_INSETS,
357
192
  ...insets
358
- }
193
+ },
194
+ onLayout
359
195
  });
196
+ useEffect2(() => {
197
+ for (const [value, label] of collectItemLabels(children, isSelectItem)) {
198
+ registerLabel(value, label);
199
+ }
200
+ }, [children, registerLabel]);
201
+ if (!isOpen || anchor === null) return null;
360
202
  return /* @__PURE__ */jsx3(Portal, {
361
203
  children: /* @__PURE__ */jsx3(SelectProvider, {
362
204
  value: context,
363
205
  children: /* @__PURE__ */jsx3(Animated.View, {
364
206
  ref,
365
- entering: position ? contentEntering(position.placement) : void 0,
366
- exiting: position ? contentExiting(position.placement) : void 0,
367
- onLayout: measure,
207
+ entering: position ? anchoredEntering(position.placement) : void 0,
208
+ exiting: position ? anchoredExiting(position.placement) : void 0,
209
+ onLayout: onContentLayout,
368
210
  ...rest,
369
- style: [contentStyle,
370
- // The measuring pass: laid out at the trigger's width so the rows wrap as they
371
- // finally will, and invisible so the reader never sees it at the wrong place.
372
- position === null ? {
373
- opacity: 0,
374
- top: 0,
375
- start: 0,
376
- width: local.width
377
- } : {
211
+ style: [contentStyle, position === null ? measuringStyle : {
378
212
  top: position.top,
379
213
  start: position.start,
380
214
  width: position.width,
@@ -396,10 +230,10 @@ SelectContent.displayName = "XAUI.Select.Content";
396
230
  import { useEffect as useEffect3 } from "react";
397
231
  import Animated2, { interpolate, useAnimatedStyle, useSharedValue, withSpring } from "react-native-reanimated";
398
232
  import { jsx as jsx4 } from "react/jsx-runtime";
399
- const _worklet_1818497961394_init_data = {
400
- code: "function chunkZNZ7HVRWJs1(){const{interpolate,progress,INDICATOR_ROTATION}=this.__closure;return{transform:[{rotate:interpolate(progress.get(),[0,1],[INDICATOR_ROTATION[0],INDICATOR_ROTATION[1]])+\"deg\"}]};}",
401
- location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-ZNZ7HVRW.js",
402
- sourceMap: "{\"version\":3,\"names\":[\"chunkZNZ7HVRWJs1\",\"interpolate\",\"progress\",\"INDICATOR_ROTATION\",\"__closure\",\"transform\",\"rotate\",\"get\"],\"sources\":[\"/home/runner/work/xaui/xaui/packages/native/dist/chunk-ZNZ7HVRW.js\"],\"mappings\":\"AA0WoC,SAAAA,iBAAA,QAAAC,WAAA,CAAAC,QAAA,CAAAC,kBAAA,OAAAC,SAAA,OAAO,CACvCC,SAAS,CAAE,CACT,CACEC,MAAM,CAAKL,WAAW,CAACC,QAAQ,CAACK,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAACJ,kBAAkB,CAAC,CAAC,CAAC,CAAEA,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,MAChG,CAAC,CAEL,CAAC\",\"ignoreList\":[]}"
233
+ const _worklet_11125272119572_init_data = {
234
+ code: "function chunkJKP4TPILJs1(){const{interpolate,progress,INDICATOR_ROTATION}=this.__closure;return{transform:[{rotate:interpolate(progress.get(),[0,1],[INDICATOR_ROTATION[0],INDICATOR_ROTATION[1]])+\"deg\"}]};}",
235
+ location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-JKP4TPIL.js",
236
+ sourceMap: "{\"version\":3,\"names\":[\"chunkJKP4TPILJs1\",\"interpolate\",\"progress\",\"INDICATOR_ROTATION\",\"__closure\",\"transform\",\"rotate\",\"get\"],\"sources\":[\"/home/runner/work/xaui/xaui/packages/native/dist/chunk-JKP4TPIL.js\"],\"mappings\":\"AAgRoC,SAAAA,iBAAA,QAAAC,WAAA,CAAAC,QAAA,CAAAC,kBAAA,OAAAC,SAAA,OAAO,CACvCC,SAAS,CAAE,CACT,CACEC,MAAM,CAAKL,WAAW,CAACC,QAAQ,CAACK,GAAG,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAACJ,kBAAkB,CAAC,CAAC,CAAC,CAAEA,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,MAChG,CAAC,CAEL,CAAC\",\"ignoreList\":[]}"
403
237
  };
404
238
  function SelectIndicator({
405
239
  as = ChevronDownIcon,
@@ -413,30 +247,30 @@ function SelectIndicator({
413
247
  useEffect3(() => {
414
248
  progress.set(withSpring(isOpen ? 1 : 0, INDICATOR_SPRING));
415
249
  }, [isOpen, progress]);
416
- const rotation = useAnimatedStyle(function chunkZNZ7HVRWJs1Factory({
417
- _worklet_1818497961394_init_data,
250
+ const rotation = useAnimatedStyle(function chunkJKP4TPILJs1Factory({
251
+ _worklet_11125272119572_init_data,
418
252
  interpolate,
419
253
  progress,
420
254
  INDICATOR_ROTATION
421
255
  }) {
422
256
  const _e = [new global.Error(), -4, -27];
423
- const chunkZNZ7HVRWJs1 = () => ({
257
+ const chunkJKP4TPILJs1 = () => ({
424
258
  transform: [{
425
259
  rotate: `${interpolate(progress.get(), [0, 1], [INDICATOR_ROTATION[0], INDICATOR_ROTATION[1]])}deg`
426
260
  }]
427
261
  });
428
- chunkZNZ7HVRWJs1.__closure = {
262
+ chunkJKP4TPILJs1.__closure = {
429
263
  interpolate,
430
264
  progress,
431
265
  INDICATOR_ROTATION
432
266
  };
433
- chunkZNZ7HVRWJs1.__workletHash = 1818497961394;
434
- chunkZNZ7HVRWJs1.__pluginVersion = "0.7.4";
435
- chunkZNZ7HVRWJs1.__initData = _worklet_1818497961394_init_data;
436
- chunkZNZ7HVRWJs1.__stackDetails = _e;
437
- return chunkZNZ7HVRWJs1;
267
+ chunkJKP4TPILJs1.__workletHash = 11125272119572;
268
+ chunkJKP4TPILJs1.__pluginVersion = "0.7.4";
269
+ chunkJKP4TPILJs1.__initData = _worklet_11125272119572_init_data;
270
+ chunkJKP4TPILJs1.__stackDetails = _e;
271
+ return chunkJKP4TPILJs1;
438
272
  }({
439
- _worklet_1818497961394_init_data,
273
+ _worklet_11125272119572_init_data,
440
274
  interpolate,
441
275
  progress,
442
276
  INDICATOR_ROTATION
@@ -700,14 +534,14 @@ var SelectValue = forwardRef8(function SelectValue2({
700
534
  SelectValue.displayName = "XAUI.Select.Value";
701
535
 
702
536
  // src/components/select/select.tsx
703
- import { useCallback as useCallback4, useMemo as useMemo3, useState as useState3 } from "react";
537
+ import { useCallback as useCallback4, useMemo as useMemo3, useState as useState2 } from "react";
704
538
  import { StyleSheet } from "react-native";
705
539
 
706
540
  // src/components/select/select.hook.ts
707
- import { useCallback as useCallback3, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
541
+ import { useCallback as useCallback3, useMemo as useMemo2, useRef as useRef2, useState } from "react";
708
542
  function useLabelRegistry() {
709
543
  const labels = useRef2(/* @__PURE__ */new Map());
710
- const [, force] = useState2(0);
544
+ const [, force] = useState(0);
711
545
  const registerLabel = useCallback3((value, label) => {
712
546
  if (labels.current.get(value) === label) return;
713
547
  labels.current.set(value, label);
@@ -995,7 +829,7 @@ function Select({
995
829
  labelFor,
996
830
  registerLabel
997
831
  } = useLabelRegistry();
998
- const [anchor, setAnchor] = useState3(null);
832
+ const [anchor, setAnchor] = useState2(null);
999
833
  const [value, setValue] = useControllableState({
1000
834
  value: controlledValue,
1001
835
  defaultValue,
@@ -0,0 +1,145 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkWDDXU3OHcjs = require('./chunk-WDDXU3OH.cjs');
4
+
5
+ // src/hooks/use-anchored-position.ts
6
+ var _react = require('react');
7
+ var _reactnative = require('react-native');
8
+
9
+ // src/utils/placement.ts
10
+ var OPPOSITE = {
11
+ top: "bottom",
12
+ bottom: "top",
13
+ start: "end",
14
+ end: "start"
15
+ };
16
+ function axisOf(placement) {
17
+ return placement === "top" || placement === "bottom" ? "vertical" : "horizontal";
18
+ }
19
+ function resolvePlacement(input) {
20
+ const { anchor, content, window, offset, alignOffset, insets } = input;
21
+ const available = window.width - insets.start - insets.end;
22
+ const width = Math.min(resolveWidth(input), Math.max(available, 0));
23
+ const placement = choosePlacement(input);
24
+ const room = Math.max(roomFor(placement, input), 0);
25
+ const vertical = axisOf(placement) === "vertical";
26
+ const maxHeight = vertical ? room : Math.max(window.height - insets.top - insets.bottom, 0);
27
+ const height = Math.min(content.height, maxHeight);
28
+ const top = clamp(
29
+ vertical ? placement === "bottom" ? anchor.y + anchor.height + offset : anchor.y - offset - height : alignedCross(input, height) + alignOffset,
30
+ insets.top,
31
+ Math.max(window.height - insets.bottom - height, insets.top)
32
+ );
33
+ const start = clamp(
34
+ vertical ? alignedCross(input, width) + alignOffset : placement === "end" ? anchor.x + anchor.width + offset : anchor.x - offset - width,
35
+ insets.start,
36
+ Math.max(window.width - insets.end - width, insets.start)
37
+ );
38
+ return { top, start, width, maxHeight, placement };
39
+ }
40
+ function resolveWidth(input) {
41
+ const { width, anchor, content, placement, window, insets } = input;
42
+ if (width === "trigger") {
43
+ return axisOf(placement) === "vertical" ? anchor.width : content.width;
44
+ }
45
+ if (width === "full") return Math.max(window.width - insets.start - insets.end, 0);
46
+ if (width === "content-fit") return content.width;
47
+ return width;
48
+ }
49
+ function choosePlacement(input) {
50
+ const { placement, avoidCollisions, content } = input;
51
+ if (!avoidCollisions) return placement;
52
+ const wanted = axisOf(placement) === "vertical" ? content.height : content.width;
53
+ if (roomFor(placement, input) >= wanted) return placement;
54
+ const other = OPPOSITE[placement];
55
+ return roomFor(other, input) > roomFor(placement, input) ? other : placement;
56
+ }
57
+ function roomFor(placement, input) {
58
+ const { anchor, window, offset, insets } = input;
59
+ switch (placement) {
60
+ case "bottom":
61
+ return window.height - insets.bottom - (anchor.y + anchor.height) - offset;
62
+ case "top":
63
+ return anchor.y - insets.top - offset;
64
+ case "end":
65
+ return window.width - insets.end - (anchor.x + anchor.width) - offset;
66
+ case "start":
67
+ return anchor.x - insets.start - offset;
68
+ }
69
+ }
70
+ function alignedCross({ align, anchor, placement }, size) {
71
+ const vertical = axisOf(placement) === "vertical";
72
+ const origin = vertical ? anchor.x : anchor.y;
73
+ const extent = vertical ? anchor.width : anchor.height;
74
+ if (align === "start") return origin;
75
+ if (align === "end") return origin + extent - size;
76
+ return origin + (extent - size) / 2;
77
+ }
78
+ function clamp(value, min, max) {
79
+ return Math.min(Math.max(value, min), max);
80
+ }
81
+
82
+ // src/hooks/use-anchored-position.ts
83
+ function useAnchoredPosition({
84
+ anchor,
85
+ isOpen,
86
+ onLayout,
87
+ ...options
88
+ }) {
89
+ const window = _reactnative.useWindowDimensions.call(void 0, );
90
+ const origin = _nullishCoalesce(_optionalChain([_react.useContext.call(void 0, _chunkWDDXU3OHcjs.PortalContext), 'optionalAccess', _ => _.origin]), () => ( ZERO));
91
+ const [measured, setMeasured] = _react.useState.call(void 0, null);
92
+ const onContentLayout = _react.useCallback.call(void 0,
93
+ (event) => {
94
+ _optionalChain([onLayout, 'optionalCall', _2 => _2(event)]);
95
+ const { width, height } = event.nativeEvent.layout;
96
+ setMeasured(
97
+ (current) => current !== null && current.width === width && current.height === height ? current : { width, height }
98
+ );
99
+ },
100
+ [onLayout]
101
+ );
102
+ if (!isOpen && measured !== null) setMeasured(null);
103
+ const local = anchor && {
104
+ ...anchor,
105
+ x: anchor.x - origin.x,
106
+ y: anchor.y - origin.y
107
+ };
108
+ const position = local && measured ? resolvePlacement({
109
+ anchor: local,
110
+ content: measured,
111
+ window: {
112
+ width: window.width - origin.x,
113
+ height: window.height - origin.y
114
+ },
115
+ ...options
116
+ }) : null;
117
+ return {
118
+ position,
119
+ onContentLayout,
120
+ measuringStyle: {
121
+ // Invisible, and at the start of the host, so the reader never sees the panel at
122
+ // the wrong place during the frame it is being measured in.
123
+ opacity: 0,
124
+ top: 0,
125
+ start: 0,
126
+ ...measuringWidth(options, _optionalChain([local, 'optionalAccess', _3 => _3.width]), window)
127
+ }
128
+ };
129
+ }
130
+ function measuringWidth({
131
+ width,
132
+ maxWidth,
133
+ insets
134
+ }, anchorWidth, window) {
135
+ const screen = Math.max(window.width - insets.start - insets.end, 0);
136
+ if (width === "trigger") return { width: anchorWidth };
137
+ if (width === "full") return { width: screen };
138
+ if (typeof width === "number") return { width };
139
+ return { maxWidth: Math.min(_nullishCoalesce(maxWidth, () => ( Number.POSITIVE_INFINITY)), screen) };
140
+ }
141
+ var ZERO = { x: 0, y: 0 };
142
+
143
+
144
+
145
+ exports.useAnchoredPosition = useAnchoredPosition;