@hozo/behaviors 0.1.0

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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -0
  3. package/dist/dismissable-layer.d.ts +17 -0
  4. package/dist/dismissable-layer.d.ts.map +1 -0
  5. package/dist/dismissable-layer.js +67 -0
  6. package/dist/dismissable-layer.js.map +1 -0
  7. package/dist/dismissable-layer.native.d.ts +28 -0
  8. package/dist/dismissable-layer.native.d.ts.map +1 -0
  9. package/dist/dismissable-layer.native.js +38 -0
  10. package/dist/dismissable-layer.native.js.map +1 -0
  11. package/dist/floating-geometry.d.ts +63 -0
  12. package/dist/floating-geometry.d.ts.map +1 -0
  13. package/dist/floating-geometry.js +191 -0
  14. package/dist/floating-geometry.js.map +1 -0
  15. package/dist/floating-positioner.d.ts +24 -0
  16. package/dist/floating-positioner.d.ts.map +1 -0
  17. package/dist/floating-positioner.js +110 -0
  18. package/dist/floating-positioner.js.map +1 -0
  19. package/dist/floating-positioner.native.d.ts +43 -0
  20. package/dist/floating-positioner.native.d.ts.map +1 -0
  21. package/dist/floating-positioner.native.js +82 -0
  22. package/dist/floating-positioner.native.js.map +1 -0
  23. package/dist/focus-scope.d.ts +31 -0
  24. package/dist/focus-scope.d.ts.map +1 -0
  25. package/dist/focus-scope.js +96 -0
  26. package/dist/focus-scope.js.map +1 -0
  27. package/dist/focus-scope.native.d.ts +33 -0
  28. package/dist/focus-scope.native.d.ts.map +1 -0
  29. package/dist/focus-scope.native.js +25 -0
  30. package/dist/focus-scope.native.js.map +1 -0
  31. package/dist/hover-geometry.d.ts +64 -0
  32. package/dist/hover-geometry.d.ts.map +1 -0
  33. package/dist/hover-geometry.js +146 -0
  34. package/dist/hover-geometry.js.map +1 -0
  35. package/dist/hover-trigger.d.ts +64 -0
  36. package/dist/hover-trigger.d.ts.map +1 -0
  37. package/dist/hover-trigger.js +174 -0
  38. package/dist/hover-trigger.js.map +1 -0
  39. package/dist/hover-trigger.native.d.ts +45 -0
  40. package/dist/hover-trigger.native.d.ts.map +1 -0
  41. package/dist/hover-trigger.native.js +101 -0
  42. package/dist/hover-trigger.native.js.map +1 -0
  43. package/dist/index.d.ts +12 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/index.native.d.ts +12 -0
  48. package/dist/index.native.d.ts.map +1 -0
  49. package/dist/index.native.js +12 -0
  50. package/dist/index.native.js.map +1 -0
  51. package/dist/live-region.d.ts +19 -0
  52. package/dist/live-region.d.ts.map +1 -0
  53. package/dist/live-region.js +51 -0
  54. package/dist/live-region.js.map +1 -0
  55. package/dist/live-region.native.d.ts +31 -0
  56. package/dist/live-region.native.d.ts.map +1 -0
  57. package/dist/live-region.native.js +38 -0
  58. package/dist/live-region.native.js.map +1 -0
  59. package/dist/native.d.ts +5 -0
  60. package/dist/native.d.ts.map +1 -0
  61. package/dist/native.js +4 -0
  62. package/dist/native.js.map +1 -0
  63. package/dist/portal.d.ts +26 -0
  64. package/dist/portal.d.ts.map +1 -0
  65. package/dist/portal.js +41 -0
  66. package/dist/portal.js.map +1 -0
  67. package/dist/portal.native.d.ts +44 -0
  68. package/dist/portal.native.d.ts.map +1 -0
  69. package/dist/portal.native.js +79 -0
  70. package/dist/portal.native.js.map +1 -0
  71. package/dist/roving-focus-rules.d.ts +13 -0
  72. package/dist/roving-focus-rules.d.ts.map +1 -0
  73. package/dist/roving-focus-rules.js +49 -0
  74. package/dist/roving-focus-rules.js.map +1 -0
  75. package/dist/roving-focus.d.ts +27 -0
  76. package/dist/roving-focus.d.ts.map +1 -0
  77. package/dist/roving-focus.js +52 -0
  78. package/dist/roving-focus.js.map +1 -0
  79. package/dist/roving-focus.native.d.ts +36 -0
  80. package/dist/roving-focus.native.d.ts.map +1 -0
  81. package/dist/roving-focus.native.js +28 -0
  82. package/dist/roving-focus.native.js.map +1 -0
  83. package/dist/text-child.d.ts +4 -0
  84. package/dist/text-child.d.ts.map +1 -0
  85. package/dist/text-child.js +17 -0
  86. package/dist/text-child.js.map +1 -0
  87. package/dist/text-child.native.d.ts +14 -0
  88. package/dist/text-child.native.d.ts.map +1 -0
  89. package/dist/text-child.native.js +42 -0
  90. package/dist/text-child.native.js.map +1 -0
  91. package/dist/typeahead.d.ts +36 -0
  92. package/dist/typeahead.d.ts.map +1 -0
  93. package/dist/typeahead.js +97 -0
  94. package/dist/typeahead.js.map +1 -0
  95. package/package.json +82 -0
  96. package/src/dismissable-layer.native.tsx +72 -0
  97. package/src/dismissable-layer.tsx +106 -0
  98. package/src/floating-geometry.ts +306 -0
  99. package/src/floating-positioner.native.tsx +155 -0
  100. package/src/floating-positioner.tsx +173 -0
  101. package/src/focus-scope.native.tsx +53 -0
  102. package/src/focus-scope.tsx +143 -0
  103. package/src/hover-geometry.ts +182 -0
  104. package/src/hover-trigger.native.tsx +179 -0
  105. package/src/hover-trigger.tsx +303 -0
  106. package/src/index.native.ts +77 -0
  107. package/src/index.ts +77 -0
  108. package/src/live-region.native.tsx +61 -0
  109. package/src/live-region.tsx +74 -0
  110. package/src/native.ts +15 -0
  111. package/src/portal.native.tsx +130 -0
  112. package/src/portal.tsx +68 -0
  113. package/src/roving-focus-rules.ts +79 -0
  114. package/src/roving-focus.native.tsx +81 -0
  115. package/src/roving-focus.tsx +118 -0
  116. package/src/text-child.native.tsx +44 -0
  117. package/src/text-child.ts +19 -0
  118. package/src/typeahead.ts +120 -0
@@ -0,0 +1,110 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useEffect, useRef, useState, } from 'react';
3
+ import { computePosition, } from './floating-geometry.js';
4
+ /**
5
+ * Universal React hook for floating element positioning on Web.
6
+ * Automatically recalculates position on scroll, resize, and element dimension changes.
7
+ */
8
+ export function useFloatingPosition({ anchorRef, floatingRef, enabled = true, placement = 'bottom', offset = 8, crossAxisOffset = 0, flip = true, shift = true, viewportPadding = 8, arrowPadding = 4, matchAnchorWidth = false, }) {
9
+ const [position, setPosition] = useState(null);
10
+ const update = useCallback(() => {
11
+ if (!enabled || typeof window === 'undefined')
12
+ return;
13
+ const anchor = anchorRef.current;
14
+ const floating = floatingRef.current;
15
+ if (!anchor || !floating)
16
+ return;
17
+ const anchorDomRect = anchor.getBoundingClientRect();
18
+ const floatingDomRect = floating.getBoundingClientRect();
19
+ const anchorRect = {
20
+ x: anchorDomRect.left,
21
+ y: anchorDomRect.top,
22
+ width: anchorDomRect.width,
23
+ height: anchorDomRect.height,
24
+ };
25
+ const floatingRect = {
26
+ x: floatingDomRect.left,
27
+ y: floatingDomRect.top,
28
+ width: floatingDomRect.width,
29
+ height: floatingDomRect.height,
30
+ };
31
+ const viewport = {
32
+ width: window.innerWidth,
33
+ height: window.innerHeight,
34
+ };
35
+ const result = computePosition(anchorRect, floatingRect, viewport, {
36
+ placement,
37
+ offset,
38
+ crossAxisOffset,
39
+ flip,
40
+ shift,
41
+ viewportPadding,
42
+ arrowPadding,
43
+ matchAnchorWidth,
44
+ });
45
+ setPosition(result);
46
+ }, [
47
+ enabled,
48
+ anchorRef,
49
+ floatingRef,
50
+ placement,
51
+ offset,
52
+ crossAxisOffset,
53
+ flip,
54
+ shift,
55
+ viewportPadding,
56
+ arrowPadding,
57
+ matchAnchorWidth,
58
+ ]);
59
+ useEffect(() => {
60
+ if (!enabled || typeof window === 'undefined')
61
+ return;
62
+ update();
63
+ const handleScrollOrResize = () => update();
64
+ window.addEventListener('resize', handleScrollOrResize);
65
+ window.addEventListener('scroll', handleScrollOrResize, true);
66
+ let resizeObserver = null;
67
+ if (typeof ResizeObserver !== 'undefined') {
68
+ resizeObserver = new ResizeObserver(() => update());
69
+ if (anchorRef.current)
70
+ resizeObserver.observe(anchorRef.current);
71
+ if (floatingRef.current)
72
+ resizeObserver.observe(floatingRef.current);
73
+ }
74
+ return () => {
75
+ window.removeEventListener('resize', handleScrollOrResize);
76
+ window.removeEventListener('scroll', handleScrollOrResize, true);
77
+ resizeObserver?.disconnect();
78
+ };
79
+ }, [enabled, update, anchorRef, floatingRef]);
80
+ return position;
81
+ }
82
+ /**
83
+ * Universal `<FloatingPositioner>` component for Web.
84
+ * Popper/Floating-UI equivalent positioning container that attaches to an anchor element.
85
+ */
86
+ export function FloatingPositioner({ children, anchorRef, className, style, ...options }) {
87
+ const floatingRef = useRef(null);
88
+ const position = useFloatingPosition({
89
+ anchorRef,
90
+ floatingRef,
91
+ ...options,
92
+ });
93
+ const positionStyles = position
94
+ ? {
95
+ position: 'fixed',
96
+ left: `${position.x}px`,
97
+ top: `${position.y}px`,
98
+ width: options.matchAnchorWidth ? `${position.anchorWidth}px` : undefined,
99
+ willChange: 'transform',
100
+ display: position.referenceHidden ? 'none' : undefined,
101
+ }
102
+ : {
103
+ position: 'fixed',
104
+ left: '-9999px',
105
+ top: '-9999px',
106
+ visibility: 'hidden',
107
+ };
108
+ return (_jsx("div", { ref: floatingRef, className: className, style: { ...positionStyles, ...style }, "data-placement": position?.placement, "data-flipped": position?.flipped ? '' : undefined, "data-shifted": position?.shifted ? '' : undefined, "data-reference-hidden": position?.referenceHidden ? '' : undefined, children: typeof children === 'function' ? children(position) : children }));
109
+ }
110
+ //# sourceMappingURL=floating-positioner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floating-positioner.js","sourceRoot":"","sources":["../src/floating-positioner.tsx"],"names":[],"mappings":";AAAA,OAAO,EAIL,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,EAEL,eAAe,GAEhB,MAAM,wBAAwB,CAAA;AAQ/B;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,WAAW,EACX,OAAO,GAAG,IAAI,EACd,SAAS,GAAG,QAAQ,EACpB,MAAM,GAAG,CAAC,EACV,eAAe,GAAG,CAAC,EACnB,IAAI,GAAG,IAAI,EACX,KAAK,GAAG,IAAI,EACZ,eAAe,GAAG,CAAC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AAC"}
@@ -0,0 +1,43 @@
1
+ import React, { type ComponentRef, type ReactNode, type RefObject } from 'react';
2
+ import { type StyleProp, View, type ViewStyle } from 'react-native';
3
+ import { type ComputePositionOptions, type PositionResult } from './floating-geometry.ts';
4
+ /**
5
+ * What React Native hands back for a `<View>`, rather than a shape of our
6
+ * own that happens to have `measureInWindow` on it.
7
+ *
8
+ * The hand-rolled one could not be passed to a `<View ref>` -- this file
9
+ * did exactly that, and the erasure around it hid the mismatch.
10
+ */
11
+ type MeasurableRef = RefObject<ComponentRef<typeof View> | null>;
12
+ export interface UseFloatingPositionOptions extends ComputePositionOptions {
13
+ anchorRef: MeasurableRef;
14
+ floatingRef: MeasurableRef;
15
+ enabled?: boolean;
16
+ }
17
+ /**
18
+ * Universal React hook for floating element positioning on React Native.
19
+ */
20
+ export declare function useFloatingPosition({ anchorRef, floatingRef, enabled, placement, offset, crossAxisOffset, flip, shift, viewportPadding, arrowPadding, }: UseFloatingPositionOptions): PositionResult | null;
21
+ export interface FloatingPositionerProps extends ComputePositionOptions {
22
+ /**
23
+ * Tailwind classes, the same prop the Web half takes.
24
+ *
25
+ * On a tag the compiler lowers it is gone by runtime, replaced by a
26
+ * `StyleSheet` entry. Anywhere else it is carried and ignored here --
27
+ * this side has no CSS engine to resolve a class list against -- and
28
+ * the type still has to accept it, because an app is type-checked
29
+ * against the source the compiler reads rather than its output.
30
+ */
31
+ className?: string;
32
+ children?: ReactNode | ((position: PositionResult | null) => ReactNode);
33
+ anchorRef: MeasurableRef;
34
+ style?: StyleProp<ViewStyle>;
35
+ }
36
+ /**
37
+ * Universal `<FloatingPositioner>` component for React Native.
38
+ */
39
+ export declare function FloatingPositioner({ children, anchorRef, style, ...options }: FloatingPositionerProps): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
40
+ ref?: React.Ref<import("react-native").ViewInstance> | undefined;
41
+ }>;
42
+ export {};
43
+ //# sourceMappingURL=floating-positioner.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floating-positioner.native.d.ts","sourceRoot":"","sources":["../src/floating-positioner.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,SAAS,EAKf,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EACL,KAAK,sBAAsB,EAE3B,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAA;AAE/B;;;;;;GAMG;AACH,KAAK,aAAa,GAAG,SAAS,CAAC,YAAY,CAAC,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;AAEhE,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,SAAS,EAAE,aAAa,CAAA;IACxB,WAAW,EAAE,aAAa,CAAA;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,WAAW,EACX,OAAc,EACd,SAAoB,EACpB,MAAU,EACV,eAAmB,EACnB,IAAW,EACX,KAAY,EACZ,eAAmB,EACnB,YAAgB,GACjB,EAAE,0BAA0B,GAAG,cAAc,GAAG,IAAI,CAmDpD;AAED,MAAM,WAAW,uBAAwB,SAAQ,sBAAsB;IACrE;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,KAAK,SAAS,CAAC,CAAA;IACvE,SAAS,EAAE,aAAa,CAAA;IACxB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,OAAO,EACX,EAAE,uBAAuB;;GAgCzB"}
@@ -0,0 +1,82 @@
1
+ import React, { useCallback, useEffect, useRef, useState, } from 'react';
2
+ import { View } from 'react-native';
3
+ import { computePosition, } from './floating-geometry.js';
4
+ /**
5
+ * Universal React hook for floating element positioning on React Native.
6
+ */
7
+ export function useFloatingPosition({ anchorRef, floatingRef, enabled = true, placement = 'bottom', offset = 8, crossAxisOffset = 0, flip = true, shift = true, viewportPadding = 8, arrowPadding = 4, }) {
8
+ const [position, setPosition] = useState(null);
9
+ const update = useCallback(() => {
10
+ if (!enabled)
11
+ return;
12
+ const anchor = anchorRef.current;
13
+ if (!anchor?.measureInWindow)
14
+ return;
15
+ anchor.measureInWindow((ax, ay, aw, ah) => {
16
+ const floating = floatingRef.current;
17
+ if (floating?.measureInWindow) {
18
+ floating.measureInWindow((_fx, _fy, fw, fh) => {
19
+ // Assume standard device screen dimensions fallback
20
+ const viewport = { width: 400, height: 800 };
21
+ const result = computePosition({ x: ax, y: ay, width: aw, height: ah }, { x: 0, y: 0, width: fw, height: fh }, viewport, {
22
+ placement,
23
+ offset,
24
+ crossAxisOffset,
25
+ flip,
26
+ shift,
27
+ viewportPadding,
28
+ arrowPadding,
29
+ });
30
+ setPosition(result);
31
+ });
32
+ }
33
+ });
34
+ }, [
35
+ enabled,
36
+ anchorRef,
37
+ floatingRef,
38
+ placement,
39
+ offset,
40
+ crossAxisOffset,
41
+ flip,
42
+ shift,
43
+ viewportPadding,
44
+ arrowPadding,
45
+ ]);
46
+ useEffect(() => {
47
+ if (!enabled)
48
+ return;
49
+ update();
50
+ }, [enabled, update]);
51
+ return position;
52
+ }
53
+ /**
54
+ * Universal `<FloatingPositioner>` component for React Native.
55
+ */
56
+ export function FloatingPositioner({ children, anchorRef, style, ...options }) {
57
+ const floatingRef = useRef(null);
58
+ const position = useFloatingPosition({
59
+ anchorRef,
60
+ floatingRef,
61
+ ...options,
62
+ });
63
+ const positionStyles = position
64
+ ? {
65
+ position: 'absolute',
66
+ left: position.x,
67
+ top: position.y,
68
+ width: options.matchAnchorWidth ? position.anchorWidth : undefined,
69
+ opacity: position.referenceHidden ? 0 : 1,
70
+ }
71
+ : {
72
+ position: 'absolute',
73
+ left: -9999,
74
+ top: -9999,
75
+ opacity: 0,
76
+ };
77
+ return React.createElement(View, {
78
+ ref: floatingRef,
79
+ style: [positionStyles, style],
80
+ }, typeof children === 'function' ? children(position) : children);
81
+ }
82
+ //# sourceMappingURL=floating-positioner.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"floating-positioner.native.js","sourceRoot":"","sources":["../src/floating-positioner.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAIZ,WAAW,EACX,SAAS,EACT,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,EAAkB,IAAI,EAAkB,MAAM,cAAc,CAAA;AACnE,OAAO,EAEL,eAAe,GAEhB,MAAM,wBAAwB,CAAA;AAiB/B;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,SAAS,EACT,WAAW,EACX,OAAO,GAAG,IAAI,EACd,SAAS,GAAG,QAAQ,EACpB,MAAM,GAAG,CAAC,EACV,eAAe,GAAG,CAAC,EACnB,IAAI,GAAG,IAAI,EACX,KAAK,GAAG,IAAI,EACZ,eAAe,GAAG,CAAC,EACnB,YAAY,GAAG,CAAC,GACW;IAC3B,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC,CAAA;IAErE,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,IAAI,CAAC,OAAO;YAAE,OAAM;QACpB,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;QAChC,IAAI,CAAC,MAAM,EAAE,eAAe;YAAE,OAAM;QAEpC,MAAM,CAAC,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;YACxC,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAA;YACpC,IAAI,QAAQ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T,WAAW;QACX,GAAG,OAAO;KACX,CAAC,CAAA;IAEF,MAAM,cAAc,GAAG,QAAQ;QAC7B,CAAC,CAAC;YACE,QAAQ,EAAE,UAAmB;YAC7B,IAAI,EAAE,QAAQ,CAAC,CAAC;YAChB,GAAG,EAAE,QAAQ,CAAC,CAAC;YACf,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;YAClE,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC1C;QACH,CAAC,CAAC;YACE,QAAQ,EAAE,UAAmB;YAC7B,IAAI,EAAE,CAAC,IAAI;YACX,GAAG,EAAE,CAAC,IAAI;YACV,OAAO,EAAE,CAAC;SACX,CAAA;IAEL,OAAO,KAAK,CAAC,aAAa,CACxB,IAAI,EACJ;QACE,GAAG,EAAE,WAAW;QAChB,KAAK,EAAE,CAAC,cAAc,EAAE,KAAK,CAAC;KAC/B,EACD,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAC/D,CAAA;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ export interface FocusCandidate {
3
+ autofocus?: boolean;
4
+ focusable?: boolean;
5
+ }
6
+ /**
7
+ * Resolves which candidate receives focus when the scope activates.
8
+ * 1. Explicit autofocus control (if focusable)
9
+ * 2. First focusable descendant
10
+ * 3. null -> focuses the scope container itself
11
+ */
12
+ export declare function initialFocusIndex(candidates: readonly FocusCandidate[]): number | null;
13
+ /**
14
+ * Checks whether focus can be safely restored to opener element.
15
+ * Must be connected to DOM and not disabled to prevent focus dropping to document.body.
16
+ */
17
+ export declare function shouldRestoreFocus(opener: FocusCandidate | null | undefined): boolean;
18
+ export interface FocusScopeProps {
19
+ children?: ReactNode;
20
+ trapped?: boolean;
21
+ autoFocus?: boolean;
22
+ restoreFocus?: boolean;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ }
26
+ /**
27
+ * Universal `<FocusScope>` component for Web.
28
+ * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
29
+ */
30
+ export declare function FocusScope({ children, trapped, autoFocus, restoreFocus, className, style, }: FocusScopeProps): import("react").JSX.Element;
31
+ //# sourceMappingURL=focus-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-scope.d.ts","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,SAAS,EAAqB,MAAM,OAAO,CAAA;AAE7E,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,GAAG,IAAI,CAKtF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAErF;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACzB,QAAQ,EACR,OAAc,EACd,SAAgB,EAChB,YAAmB,EACnB,SAAS,EACT,KAAK,GACN,EAAE,eAAe,+BA2FjB"}
@@ -0,0 +1,96 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from 'react';
3
+ /**
4
+ * Resolves which candidate receives focus when the scope activates.
5
+ * 1. Explicit autofocus control (if focusable)
6
+ * 2. First focusable descendant
7
+ * 3. null -> focuses the scope container itself
8
+ */
9
+ export function initialFocusIndex(candidates) {
10
+ const requested = candidates.findIndex((c) => c.autofocus && c.focusable);
11
+ if (requested !== -1)
12
+ return requested;
13
+ const first = candidates.findIndex((c) => c.focusable);
14
+ return first === -1 ? null : first;
15
+ }
16
+ /**
17
+ * Checks whether focus can be safely restored to opener element.
18
+ * Must be connected to DOM and not disabled to prevent focus dropping to document.body.
19
+ */
20
+ export function shouldRestoreFocus(opener) {
21
+ return opener?.focusable === true;
22
+ }
23
+ const FOCUSABLE_SELECTOR = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
24
+ /**
25
+ * Universal `<FocusScope>` component for Web.
26
+ * Traps Tab key navigation, moves initial focus, and safely restores focus on unmount.
27
+ */
28
+ export function FocusScope({ children, trapped = true, autoFocus = true, restoreFocus = true, className, style, }) {
29
+ const containerRef = useRef(null);
30
+ const openerRef = useRef(null);
31
+ useEffect(() => {
32
+ if (typeof document === 'undefined')
33
+ return;
34
+ // Capture the trigger element that opened this scope
35
+ if (restoreFocus && document.activeElement instanceof HTMLElement) {
36
+ openerRef.current = document.activeElement;
37
+ }
38
+ const container = containerRef.current;
39
+ if (!container)
40
+ return;
41
+ if (autoFocus) {
42
+ const focusables = Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((el) => el.offsetParent !== null || el.getClientRects().length > 0);
43
+ const candidates = focusables.map((el) => ({
44
+ autofocus: el.hasAttribute('autofocus'),
45
+ focusable: !el.hasAttribute('disabled') && el.tabIndex !== -1,
46
+ }));
47
+ const targetIdx = initialFocusIndex(candidates);
48
+ if (targetIdx !== null && focusables[targetIdx]) {
49
+ focusables[targetIdx].focus();
50
+ }
51
+ else {
52
+ // Fallback: focus container itself (tabIndex="-1") so screen readers announce dialog role/label
53
+ container.focus();
54
+ }
55
+ }
56
+ const handleKeyDown = (event) => {
57
+ if (!trapped || event.key !== 'Tab')
58
+ return;
59
+ const focusables = Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter((el) => el.offsetParent !== null || el.getClientRects().length > 0);
60
+ if (focusables.length === 0) {
61
+ event.preventDefault();
62
+ container.focus();
63
+ return;
64
+ }
65
+ const first = focusables[0];
66
+ const last = focusables[focusables.length - 1];
67
+ if (event.shiftKey) {
68
+ if (document.activeElement === first || document.activeElement === container) {
69
+ event.preventDefault();
70
+ last?.focus();
71
+ }
72
+ }
73
+ else {
74
+ if (document.activeElement === last) {
75
+ event.preventDefault();
76
+ first?.focus();
77
+ }
78
+ }
79
+ };
80
+ container.addEventListener('keydown', handleKeyDown);
81
+ return () => {
82
+ container.removeEventListener('keydown', handleKeyDown);
83
+ if (restoreFocus) {
84
+ const opener = openerRef.current;
85
+ if (opener &&
86
+ shouldRestoreFocus({
87
+ focusable: opener.isConnected && !opener.hasAttribute('disabled'),
88
+ })) {
89
+ opener.focus();
90
+ }
91
+ }
92
+ };
93
+ }, [trapped, autoFocus, restoreFocus]);
94
+ return (_jsx("div", { ref: containerRef, tabIndex: -1, className: className, style: { outline: 'none', ...style }, children: children }));
95
+ }
96
+ //# sourceMappingURL=focus-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-scope.js","sourceRoot":"","sources":["../src/focus-scope.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAO7E;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAqC;IACrE,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAA;IACzE,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAA;IACtC,MAAM,KAAK,GAAG,UAAU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CAAC,aAAa,KAAK,KAAK,IAAI,QAAQ,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;oBAC7E,KAAK,CAAC,cAAc,EAAE,CAAA;oBACtB,IAAI,EAAE,KAAK,EAAE,CAAA;gBACf,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;oBACpC,KAAK,CAAC,cAAc,EAAE,CAAA;oBACtB,KAAK,EAAE,KAAK,EAAE,CAAA;gBAChB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;QAED,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;QAEpD,OAAO,GAAG,EAAE;YACV,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;YACvD,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAA;gBAChC,IACE,MAAM;oBACN,kBAAkB,CAAC;wBACjB,SAAS,EAAE,MAAM,CAAC,WAAW,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC;qBAClE,CAAC,EACF,CAAC;oBACD,MAAM,CAAC,KAAK,EAAE,CAAA;gBAChB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAA;IAEtC,OAAO,CACL,cACE,GAAG,EAAE,YAAY,EACjB,QAAQ,EAAE,CAAC,CAAC,EACZ,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,YAEnC,QAAQ,GACL,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import { type StyleProp, type ViewStyle } from 'react-native';
3
+ export interface FocusCandidate {
4
+ autofocus?: boolean;
5
+ focusable?: boolean;
6
+ }
7
+ export declare function initialFocusIndex(candidates: readonly FocusCandidate[]): number | null;
8
+ export declare function shouldRestoreFocus(opener: FocusCandidate | null | undefined): boolean;
9
+ export interface FocusScopeProps {
10
+ /**
11
+ * Tailwind classes, the same prop the Web half takes.
12
+ *
13
+ * On a tag the compiler lowers it is gone by runtime, replaced by a
14
+ * `StyleSheet` entry. Anywhere else it is carried and ignored here --
15
+ * this side has no CSS engine to resolve a class list against -- and
16
+ * the type still has to accept it, because an app is type-checked
17
+ * against the source the compiler reads rather than its output.
18
+ */
19
+ className?: string;
20
+ children?: ReactNode;
21
+ trapped?: boolean;
22
+ autoFocus?: boolean;
23
+ restoreFocus?: boolean;
24
+ style?: StyleProp<ViewStyle>;
25
+ }
26
+ /**
27
+ * Universal `<FocusScope>` component for React Native.
28
+ * Renders an accessible trapping container for modal dialogs and overlays.
29
+ */
30
+ export declare function FocusScope({ children, trapped, style, ...props }: FocusScopeProps): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
31
+ ref?: React.Ref<import("react-native").ViewInstance> | undefined;
32
+ }>;
33
+ //# sourceMappingURL=focus-scope.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-scope.native.d.ts","sourceRoot":"","sources":["../src/focus-scope.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAE,KAAK,SAAS,EAAQ,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAEnE,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,GAAG,IAAI,CAKtF;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAErF;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAC7B;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAc,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,eAAe;;GAWxF"}
@@ -0,0 +1,25 @@
1
+ import React, {} from 'react';
2
+ import { View } from 'react-native';
3
+ export function initialFocusIndex(candidates) {
4
+ const requested = candidates.findIndex((c) => c.autofocus && c.focusable);
5
+ if (requested !== -1)
6
+ return requested;
7
+ const first = candidates.findIndex((c) => c.focusable);
8
+ return first === -1 ? null : first;
9
+ }
10
+ export function shouldRestoreFocus(opener) {
11
+ return opener?.focusable === true;
12
+ }
13
+ /**
14
+ * Universal `<FocusScope>` component for React Native.
15
+ * Renders an accessible trapping container for modal dialogs and overlays.
16
+ */
17
+ export function FocusScope({ children, trapped = true, style, ...props }) {
18
+ return React.createElement(View, {
19
+ accessible: true,
20
+ accessibilityViewIsModal: trapped,
21
+ style,
22
+ ...props,
23
+ }, children);
24
+ }
25
+ //# sourceMappingURL=focus-scope.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"focus-scope.native.js","sourceRoot":"","sources":["../src/focus-scope.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAkB,MAAM,OAAO,CAAA;AAC7C,OAAO,EAAkB,IAAI,EAAkB,MAAM,cAAc,CAAA;AAOnE,MAAM,UAAU,iBAAiB,CAAC,UAAqC;IACrE,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAA;IACzE,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAA;IACtC,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;IACtD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAyC;IAC1E,OAAO,MAAM,EAAE,SAAS,KAAK,IAAI,CAAA;AACnC,CAAC;AAoBD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,KAAK,EAAmB;IACvF,OAAO,KAAK,CAAC,aAAa,CACxB,IAAI,EACJ;QACE,UAAU,EAAE,IAAI;QAChB,wBAAwB,EAAE,OAAO;QACjC,KAAK;QACL,GAAG,KAAK;KACT,EACD,QAAQ,CACT,CAAA;AACH,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { BasePlacement, Rect } from './floating-geometry.ts';
2
+ export interface Point {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ export type Polygon = Point[];
7
+ /**
8
+ * Determines whether a point lies within a polygon using the Ray-Casting algorithm.
9
+ * Used for Safe Polygon calculation between trigger and floating content.
10
+ */
11
+ export declare function isPointInPolygon(point: Point, polygon: Polygon): boolean;
12
+ /**
13
+ * Computes a safe polygon connecting the anchor to the floating element.
14
+ * Moving the pointer within this polygon will prevent the floating content from closing prematurely.
15
+ */
16
+ export declare function computeSafePolygon(anchorRect: Rect, floatingRect: Rect, placement: BasePlacement, buffer?: number): Polygon;
17
+ /**
18
+ * State machine for Tooltip Delay Grouping (Warmup / Grace period).
19
+ * When one tooltip opens, subsequent tooltips within the group open instantly (delay = 0ms).
20
+ */
21
+ export interface DelayGroupConfig {
22
+ /** Delay in milliseconds before opening an un-warmed tooltip. Default: 700ms. */
23
+ openDelay?: number;
24
+ /** Delay in milliseconds before closing when pointer leaves. Default: 300ms. */
25
+ closeDelay?: number;
26
+ /** Grace duration in ms after a tooltip closes where the group remains 'warm'. Default: 300ms. */
27
+ skipDelayDuration?: number;
28
+ }
29
+ export declare class DelayGroupMachine {
30
+ private openDelay;
31
+ private closeDelay;
32
+ private skipDelayDuration;
33
+ private activeId;
34
+ private isWarm;
35
+ private cooldownTimer;
36
+ constructor(config?: DelayGroupConfig);
37
+ /**
38
+ * Returns whether the group is currently warm (i.e. delays should be skipped).
39
+ */
40
+ getIsWarm(): boolean;
41
+ /**
42
+ * Gets the effective open delay for a tooltip.
43
+ * Returns 0 if warm, or standard openDelay otherwise.
44
+ */
45
+ getEffectiveOpenDelay(): number;
46
+ /**
47
+ * Gets the close delay.
48
+ */
49
+ getCloseDelay(): number;
50
+ /**
51
+ * Called when a tooltip in the group opens.
52
+ */
53
+ onOpen(id: string): void;
54
+ /**
55
+ * Called when a tooltip in the group closes.
56
+ * Keeps warm state for `skipDelayDuration` before going cold.
57
+ */
58
+ onClose(id: string, onCooldownExpired?: () => void): void;
59
+ /**
60
+ * Disposes of any pending cooldown timer.
61
+ */
62
+ dispose(): void;
63
+ }
64
+ //# sourceMappingURL=hover-geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hover-geometry.d.ts","sourceRoot":"","sources":["../src/hover-geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAEjE,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV;AAED,MAAM,MAAM,OAAO,GAAG,KAAK,EAAE,CAAA;AAE7B;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAoBxE;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