@hozo/behaviors 0.2.0 → 0.4.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 (86) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +17 -3
  3. package/dist/command-shortcut.d.ts +23 -0
  4. package/dist/command-shortcut.d.ts.map +1 -0
  5. package/dist/command-shortcut.js +47 -0
  6. package/dist/command-shortcut.js.map +1 -0
  7. package/dist/command-shortcut.native.d.ts +11 -0
  8. package/dist/command-shortcut.native.d.ts.map +1 -0
  9. package/dist/command-shortcut.native.js +11 -0
  10. package/dist/command-shortcut.native.js.map +1 -0
  11. package/dist/drag-1d-session.d.ts +26 -0
  12. package/dist/drag-1d-session.d.ts.map +1 -0
  13. package/dist/drag-1d-session.js +65 -0
  14. package/dist/drag-1d-session.js.map +1 -0
  15. package/dist/drag-1d.d.ts +14 -0
  16. package/dist/drag-1d.d.ts.map +1 -0
  17. package/dist/drag-1d.js +93 -0
  18. package/dist/drag-1d.js.map +1 -0
  19. package/dist/drag-1d.native.d.ts +8 -0
  20. package/dist/drag-1d.native.d.ts.map +1 -0
  21. package/dist/drag-1d.native.js +52 -0
  22. package/dist/drag-1d.native.js.map +1 -0
  23. package/dist/floating-geometry.d.ts +19 -0
  24. package/dist/floating-geometry.d.ts.map +1 -1
  25. package/dist/floating-geometry.js +19 -0
  26. package/dist/floating-geometry.js.map +1 -1
  27. package/dist/floating-positioner.d.ts +4 -1
  28. package/dist/floating-positioner.d.ts.map +1 -1
  29. package/dist/floating-positioner.js +42 -4
  30. package/dist/floating-positioner.js.map +1 -1
  31. package/dist/floating-positioner.native.d.ts +5 -0
  32. package/dist/floating-positioner.native.d.ts.map +1 -1
  33. package/dist/floating-positioner.native.js +26 -8
  34. package/dist/floating-positioner.native.js.map +1 -1
  35. package/dist/i18n.d.ts +154 -0
  36. package/dist/i18n.d.ts.map +1 -0
  37. package/dist/i18n.js +158 -0
  38. package/dist/i18n.js.map +1 -0
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.native.d.ts +3 -0
  44. package/dist/index.native.d.ts.map +1 -1
  45. package/dist/index.native.js +3 -0
  46. package/dist/index.native.js.map +1 -1
  47. package/dist/native.d.ts +2 -0
  48. package/dist/native.d.ts.map +1 -1
  49. package/dist/native.js +2 -0
  50. package/dist/native.js.map +1 -1
  51. package/dist/portal.native.d.ts.map +1 -1
  52. package/dist/portal.native.js +24 -21
  53. package/dist/portal.native.js.map +1 -1
  54. package/dist/presence.d.ts.map +1 -1
  55. package/dist/presence.js +8 -1
  56. package/dist/presence.js.map +1 -1
  57. package/dist/pressable-interaction.d.ts +41 -0
  58. package/dist/pressable-interaction.d.ts.map +1 -0
  59. package/dist/pressable-interaction.js +72 -0
  60. package/dist/pressable-interaction.js.map +1 -0
  61. package/dist/text-child.d.ts +1 -1
  62. package/dist/text-child.d.ts.map +1 -1
  63. package/dist/text-child.js +1 -1
  64. package/dist/text-child.js.map +1 -1
  65. package/dist/text-child.native.d.ts +7 -1
  66. package/dist/text-child.native.d.ts.map +1 -1
  67. package/dist/text-child.native.js +17 -3
  68. package/dist/text-child.native.js.map +1 -1
  69. package/package.json +7 -3
  70. package/src/command-shortcut.native.ts +15 -0
  71. package/src/command-shortcut.ts +51 -0
  72. package/src/drag-1d-session.ts +77 -0
  73. package/src/drag-1d.native.ts +65 -0
  74. package/src/drag-1d.ts +108 -0
  75. package/src/floating-geometry.ts +24 -0
  76. package/src/floating-positioner.native.tsx +27 -7
  77. package/src/floating-positioner.tsx +48 -2
  78. package/src/i18n.ts +212 -0
  79. package/src/index.native.ts +20 -0
  80. package/src/index.ts +20 -0
  81. package/src/native.ts +15 -0
  82. package/src/portal.native.tsx +30 -22
  83. package/src/presence.ts +7 -1
  84. package/src/pressable-interaction.ts +92 -0
  85. package/src/text-child.native.tsx +18 -6
  86. package/src/text-child.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,75 @@
1
1
  # @hozo/behaviors
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1243](https://github.com/iray-tno/hozo/pull/1243) [`480e00a`](https://github.com/iray-tno/hozo/commit/480e00a0d6e165b92beb8dbf9310710fcceb7fd1) Thanks [@iray-tno](https://github.com/iray-tno)! - Add a portable one-axis drag behavior, Splitter and ResizablePane. Panes resize with captured pointer drags, Web keyboard commands and Native accessibility actions, support logical sides and collapse/restore, and expose change/commit callbacks for application-owned persistence.
8
+
9
+ - [#1597](https://github.com/iray-tno/hozo/pull/1597) [`b3df5b7`](https://github.com/iray-tno/hozo/commit/b3df5b73a8ec104fe407d89472e4339411de311d) Thanks [@iray-tno](https://github.com/iray-tno)! - React Native 0.87 is now the lowest supported version (`react-native: >=0.87`), and `@hozo/media`'s Expo peers move to SDK 58 (`expo-video`, `expo-audio` and `expo-asset` `>=58 <59`). Native gradients go under `backgroundImage` again: the `experimental_backgroundImage` spelling existed only for React Native 0.86, which read nothing else.
10
+
11
+ - [#1245](https://github.com/iray-tno/hozo/pull/1245) [`37a9151`](https://github.com/iray-tno/hozo/commit/37a915152634d8e25dfa9b2958661d4bc8f0a134) Thanks [@iray-tno](https://github.com/iray-tno)! - Add portable CodeLines and CodeBlock with application-supplied tokens, semantic line marks, hidden gutters, line numbers, wrapping, accessible scrolling and copy feedback. Supply Native clipboard access through CodeClipboardProvider. Pure model, Shiki connection and fence metadata helpers have independent subpaths; no highlighter or diff runtime is included.
12
+
13
+ Del now renders a semantic `<del>` on Web instead of `<s>`. Strikethrough retains `<s>`; Ins adds `<ins>` with underline on Native.
14
+
15
+ ### Patch Changes
16
+
17
+ - [#1256](https://github.com/iray-tno/hozo/pull/1256) [`4270a72`](https://github.com/iray-tno/hozo/commit/4270a727b14605d7ff5c9831238e60cb518e3ed6) Thanks [@iray-tno](https://github.com/iray-tno)! - Share BottomSheet drag capture, frame coalescing and cancellation through useDrag1D on Web and Native. Settle from the final release position and velocity, restore the starting detent on cancellation, and discard pending movement when closing or unmounting. Keep handle taps and keyboard activation separate from the click generated after a drag.
18
+
19
+ Expose drag velocity details, an optional geometry validation callback and a Native movement threshold without changing existing delta-only callbacks.
20
+
21
+ - [#1419](https://github.com/iray-tno/hozo/pull/1419) [`1c052da`](https://github.com/iray-tno/hozo/commit/1c052dad66426e8a4acd462c776f161249330c35) Thanks [@iray-tno](https://github.com/iray-tno)! - A windowed Native `CodeBlock`'s accessible name now gives its length, for example "Code, 4000 lines", from the new `hozo.code.lines` message.
22
+
23
+ - [#1343](https://github.com/iray-tno/hozo/pull/1343) [`e4734c8`](https://github.com/iray-tno/hozo/commit/e4734c832c6469edc4ba88a7e09209b2b2ccd29b) Thanks [@iray-tno](https://github.com/iray-tno)! - On React Native, `FloatingPositioner` flips and shifts its panel against the real window size instead of a fixed 400×800, and positions it again when the window changes.
24
+
25
+ - [#1336](https://github.com/iray-tno/hozo/pull/1336) [`d5a1a1e`](https://github.com/iray-tno/hozo/commit/d5a1a1ee6a55dd50c6c2f91289a11a8665dd9d74) Thanks [@iray-tno](https://github.com/iray-tno)! - On React Native, `FloatingPositioner` places its panel against the parent it is laid out in, not the window. Without a `PortalProvider` a Popover rendered inside its own wrapper and opened that wrapper's offset away from its trigger.
26
+
27
+ - [#1306](https://github.com/iray-tno/hozo/pull/1306) [`5cbbb5d`](https://github.com/iray-tno/hozo/commit/5cbbb5de2ba68dd8e44c1939535a84f5325bb950) Thanks [@iray-tno](https://github.com/iray-tno)! - On React Native, a string given to `Dialog`, `Drawer`, `BottomSheet` or `Popover` as children, to `Tooltip` as `content`, to `Avatar` as `fallback` or to `Combobox` as `emptyMessage` is drawn inside a `Text`, with the box's text classes. It sat bare in a `View`, which React Native rejects. `hozoTextChildren` takes an optional text style for this.
28
+
29
+ - [#1039](https://github.com/iray-tno/hozo/pull/1039) [`cf7773e`](https://github.com/iray-tno/hozo/commit/cf7773edcfd5f9d9cb42e35489ce1b15e35312bb) Thanks [@iray-tno](https://github.com/iray-tno)! - A Text nested in `@hozo/ui`'s `Checkbox` or `Switch` label now takes their `hover:`, `active:` and `focus-visible:` text classes on Native. `@hozo/patterns`' pressable provides its state through `HozoInteractionContext`, now in `@hozo/behaviors/pressable-interaction` and shared with `@hozo/primitives`, so the `HozoText` a caller's Text compiles to reads it.
30
+
31
+ - [#1473](https://github.com/iray-tno/hozo/pull/1473) [`c4696a4`](https://github.com/iray-tno/hozo/commit/c4696a4660ceb546fc9e29bc18d1fe73979681e5) Thanks [@iray-tno](https://github.com/iray-tno)! - `usePresence` on the Web ends an exit at once when the element's `transition-property` is `none`, as `motion-reduce:transition-none` makes it. It used to wait out the duration the other classes left behind, keeping a closed element mounted for that long under reduced motion.
32
+
33
+ ## 0.3.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [`80f2686`](https://github.com/iray-tno/hozo/commit/80f2686ace0922e27502695d0b88c1dba2e08be0) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Avatar`: a person's picture, or their initials when it is absent or fails to load, read as one image named for the person, with an optional status read after the name ("Ada Lovelace, online"). The headless version lives in `@hozo/patterns`, and the look (three sizes and a status dot) in `@hozo/ui`. Its class lists compile on both platforms, as `Chip`'s do. `@hozo/core` now also exports `Chip`, which it previously reached only through compiled output.
38
+
39
+ - [#818](https://github.com/iray-tno/hozo/pull/818) [`adfe1fd`](https://github.com/iray-tno/hozo/commit/adfe1fd914d60effc27677efdaee6edf19feaf6b) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `ColorPicker`. It offers:
40
+ - preset swatches as a radio group;
41
+ - hue, saturation and lightness (and opacity, with `alpha`) as ordinary sliders rather than a two-dimensional square, which a keyboard and a screen reader can reach but not operate;
42
+ - a hex field;
43
+ - on the Web, an optional eyedropper where the browser has one.
44
+
45
+ Every colour is read named and numbered, for example "dark blue, #1e3a8a", and the names go through the i18n connection. `Slider` on the Web now also takes a track `style`.
46
+
47
+ - [#817](https://github.com/iray-tno/hozo/pull/817) [`496f1b7`](https://github.com/iray-tno/hozo/commit/496f1b75e06bc5f5b079870ce566754e7161c21a) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `CommandPalette` and `useCommandShortcut`.
48
+
49
+ **`CommandPalette`** is a searchable list of commands in a modal.
50
+ - On the Web it is a dialog holding a combobox and a grouped listbox. The arrow keys move through the matching commands while focus stays in the field (`aria-activedescendant`), Enter runs one, and Escape closes it and returns focus.
51
+ - On React Native it is a full-screen modal with a button per command.
52
+ - On both platforms, matches are ranked (starts with, then a word that starts with, then contains, then the letters in order), and the number of matches is announced as the query narrows them.
53
+ - The headless version lives in `@hozo/patterns` and the look in `@hozo/ui`.
54
+
55
+ **`useCommandShortcut`** (`@hozo/behaviors`) calls a function for ⌘K on a Mac and Ctrl+K elsewhere. It does nothing on React Native.
56
+
57
+ - [#821](https://github.com/iray-tno/hozo/pull/821) [`ad1ad0b`](https://github.com/iray-tno/hozo/commit/ad1ad0b355c6ecae07372f44a65aed279e539e22) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `FileDropzone`. It is a button that opens the file picker, with dropping files on it as a shortcut on the Web. Every pick is sorted by `accept`, the size limits and the count, and what was added and what was refused (with each reason) is announced in one sentence. On React Native it opens the application's `pickFiles`, or `expo-document-picker` when installed. With neither, it is disabled and says no picker is available.
58
+
59
+ - [#923](https://github.com/iray-tno/hozo/pull/923) [`8d58223`](https://github.com/iray-tno/hozo/commit/8d5822322607b6214fa7f57d233a9173a45815b6) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `HozoI18nProvider`, `hozoMessages`, locale/direction hooks and structural adapters for i18next and react-intl. Hozo's component labels, status descriptions and announcements can use the application's existing translation catalog, with English fallback messages. Hozo connects to an i18n library; it does not introduce a second translation engine or require one of these libraries as a dependency.
60
+
61
+ - [#923](https://github.com/iray-tno/hozo/pull/923) [`8d58223`](https://github.com/iray-tno/hozo/commit/8d5822322607b6214fa7f57d233a9173a45815b6) Thanks [@iray-tno](https://github.com/iray-tno)! - Resolve Native pattern class-name slots through the project's runtime class resolver. Pattern controls now share the primitive interaction engine and deliver hover, focus, focus-visible and pressed facts to their actual owners instead of reporting pressed alone.
62
+
63
+ Static interaction styles are additionally wired for Chip, ColorPicker swatches, Pagination page controls and CommandPalette pointer-state item slots. Selection slots and nested controls retain their own ownership: a remove button does not inherit its row's focus, and a command item does not borrow the input's focus. Other static state slots and semantic predicates remain subject to their existing diagnostics.
64
+
65
+ Styled Button receives a pressed look; Checkbox and Switch indicators are real elements on both platforms rather than Native-invisible pseudo-elements. Non-transition Native Pressables and their Text children no longer allocate animation values/listeners. Interaction ownership remains mounted when transitions are added or removed. This removes idle animation work, not every initial-mount cost or every platform delivery difference; measured list mount/update tradeoffs remain tracked separately.
66
+
67
+ - [#809](https://github.com/iray-tno/hozo/pull/809) [`70cc763`](https://github.com/iray-tno/hozo/commit/70cc763166d3f3aa04c466c5a12e7a8a4dba0a0f) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `OtpInput`, for a one-time code or a PIN. It is one real input drawn as cells, so a screen reader finds one field ("Verification code, 6 characters"), and a pasted or autofilled code lands at once. It asks each platform for a one-time code: `autocomplete="one-time-code"` on the Web, `textContentType="oneTimeCode"` on iOS and `autoComplete="sms-otp"` on Android. `mask` turns it into a PIN. The active and filled cells are styled by class lists the pattern applies, so the look reaches React Native as well.
68
+
69
+ - [#797](https://github.com/iray-tno/hozo/pull/797) [`9a33076`](https://github.com/iray-tno/hozo/commit/9a3307689c1a37847d45bea9083cee1f63c7edba) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Pagination`: numbered pages with previous and next, inside a `<nav>` named "Pagination". The current page is marked with `aria-current="page"` (`selected` on Native), and the ends are disabled in place rather than removed. With `getPageHref` every page is a link, which on Native goes through the installed router. The current page and the disabled ends are styled by class lists the pattern applies (`currentItemClassName`, `disabledItemClassName`), so the same look reaches React Native, where there are no selectors.
70
+
71
+ - [#798](https://github.com/iray-tno/hozo/pull/798) [`030d179`](https://github.com/iray-tno/hozo/commit/030d1791515ef5523560c38c1788e4b23f6bfd92) Thanks [@iray-tno](https://github.com/iray-tno)! - Add `Stepper`: where a person is in a process of several steps. Each step is read with its position and status in words ("Step 2 of 3: Profile, current"), so the status is never carried by colour alone. The current step is marked `aria-current="step"` on the Web and `selected` on Native. With `onStepPress` the steps are buttons. Each status has class lists for the step and its indicator, applied by the pattern, so the look reaches React Native as well.
72
+
3
73
  ## 0.2.0
4
74
 
5
75
  - Add headless `usePresence` with `PresenceBinding` / `PresenceState` for shared exit lifecycles.
package/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # @hozo/behaviors
2
2
 
3
- Universal headless runtime behaviors and positioning primitives for Hozo.
3
+ Universal headless runtime behaviors for Hozo: the layer where **accessibility and internationalisation are first-class behaviours**.
4
4
 
5
- These primitives provide the essential interaction mechanics — focus management, outside click handling, keyboard navigation, collision-aware floating positioning, disclosure states, phonetic reading control, and hover delay groups — on both Web and React Native.
5
+ Those are the two concerns that should be designed in from the start and are usually added at the end. Defining them here, below every component, is how Hozo makes "from the start" the default ([decision 008](../../docs/decisions/008-i18n-is-a-connection.md)).
6
+
7
+ The behaviours cover focus management, outside click handling, keyboard navigation, collision-aware floating positioning, disclosure states, screen reader announcements, phonetic reading control, text direction, and hover delay groups, on both Web and React Native.
6
8
 
7
9
  ## Included Behaviors
8
10
 
@@ -71,10 +73,22 @@ export function HoverPreview() {
71
73
  }
72
74
  ```
73
75
 
76
+ ## Native pressable interaction facts
77
+
78
+ `@hozo/behaviors/pressable-interaction` exports `usePressableInteraction`.
79
+ It returns `state` (`pressed`, `hovered`, `focused`, `focusVisible`) and
80
+ eventless `handlers` for hover, focus, pointer/key modality and press changes.
81
+ The host delivers those events and composes any caller handlers afterwards.
82
+ Focus-visible inference is opt-in. The optional `onChange` callback receives
83
+ the next facts synchronously for the existing Native animation driver.
84
+ This is shared by the primitive and patterns; it has no listeners, subscriptions
85
+ or animation allocations of its own, and does not subscribe to environment
86
+ conditions such as media queries or colour scheme.
87
+
74
88
  <!-- generated: package-footer -->
75
89
 
76
90
  ---
77
91
 
78
- Part of [Hozo](https://iray-tno.github.io/hozo/), a Rust-powered universal UI compiler and accessibility-first layer for React Native. Most applications install [`@hozo/core`](https://www.npmjs.com/package/@hozo/core) and one build integration; see [Getting started](https://github.com/iray-tno/hozo#getting-started). Source and issues: [github.com/iray-tno/hozo](https://github.com/iray-tno/hozo).
92
+ Part of [Hozo](https://iray-tno.github.io/hozo/), a universal UI framework for React Native, compiled by Rust, with native semantics on every platform, first-class accessibility, and diagnostics for humans and AI agents alike. Most applications install [`@hozo/core`](https://www.npmjs.com/package/@hozo/core) and one build integration; see [Getting started](https://iray-tno.github.io/hozo/docs/getting-started/). Source and issues: [github.com/iray-tno/hozo](https://github.com/iray-tno/hozo).
79
93
 
80
94
  <!-- /generated: package-footer -->
@@ -0,0 +1,23 @@
1
+ export interface CommandShortcutOptions {
2
+ /** The letter, pressed with ⌘ on Apple platforms and Ctrl elsewhere; `k` by default. */
3
+ key?: string;
4
+ /** Off while something else owns the keyboard. */
5
+ enabled?: boolean;
6
+ }
7
+ /** ⌘ on an Apple platform, Ctrl elsewhere -- the modifier each one's own shortcuts use. */
8
+ export declare function isApplePlatform(): boolean;
9
+ /**
10
+ * Calls `onTrigger` for ⌘K on a Mac and Ctrl+K elsewhere, from anywhere on the
11
+ * page (#152).
12
+ *
13
+ * The browser's default is prevented only for the press that is handled:
14
+ * Ctrl+K is Chrome's "search from the address bar", and taking it away when
15
+ * nothing opens would be taking it for nothing. A press during IME
16
+ * composition is not a shortcut -- the composition owns the keyboard -- and
17
+ * neither is a held key repeating.
18
+ *
19
+ * A behaviour rather than part of `CommandPalette`, because a shortcut is
20
+ * useful without one: to focus a search field, or open a different panel.
21
+ */
22
+ export declare function useCommandShortcut(onTrigger: () => void, options?: CommandShortcutOptions): void;
23
+ //# sourceMappingURL=command-shortcut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.d.ts","sourceRoot":"","sources":["../src/command-shortcut.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,sBAAsB;IACrC,wFAAwF;IACxF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,OAAO,GAAE,sBAA2B,QAkB7F"}
@@ -0,0 +1,47 @@
1
+ import { useEffect, useRef } from 'react';
2
+ /** ⌘ on an Apple platform, Ctrl elsewhere -- the modifier each one's own shortcuts use. */
3
+ export function isApplePlatform() {
4
+ if (typeof navigator === 'undefined')
5
+ return false;
6
+ const platform = navigator.userAgentData?.platform ??
7
+ navigator.platform ??
8
+ '';
9
+ return /mac|iphone|ipad|ipod/i.test(platform);
10
+ }
11
+ /**
12
+ * Calls `onTrigger` for ⌘K on a Mac and Ctrl+K elsewhere, from anywhere on the
13
+ * page (#152).
14
+ *
15
+ * The browser's default is prevented only for the press that is handled:
16
+ * Ctrl+K is Chrome's "search from the address bar", and taking it away when
17
+ * nothing opens would be taking it for nothing. A press during IME
18
+ * composition is not a shortcut -- the composition owns the keyboard -- and
19
+ * neither is a held key repeating.
20
+ *
21
+ * A behaviour rather than part of `CommandPalette`, because a shortcut is
22
+ * useful without one: to focus a search field, or open a different panel.
23
+ */
24
+ export function useCommandShortcut(onTrigger, options = {}) {
25
+ const { key = 'k', enabled = true } = options;
26
+ const latest = useRef(onTrigger);
27
+ latest.current = onTrigger;
28
+ useEffect(() => {
29
+ if (!enabled || typeof document === 'undefined')
30
+ return;
31
+ const apple = isApplePlatform();
32
+ const handle = (event) => {
33
+ if (event.isComposing || event.repeat)
34
+ return;
35
+ const modifier = apple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
36
+ if (!modifier || event.altKey || event.shiftKey)
37
+ return;
38
+ if (event.key.toLowerCase() !== key.toLowerCase())
39
+ return;
40
+ event.preventDefault();
41
+ latest.current();
42
+ };
43
+ document.addEventListener('keydown', handle);
44
+ return () => document.removeEventListener('keydown', handle);
45
+ }, [enabled, key]);
46
+ }
47
+ //# sourceMappingURL=command-shortcut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.js","sourceRoot":"","sources":["../src/command-shortcut.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AASzC,2FAA2F;AAC3F,MAAM,UAAU,eAAe;IAC7B,IAAI,OAAO,SAAS,KAAK,WAAW;QAAE,OAAO,KAAK,CAAA;IAClD,MAAM,QAAQ,GACX,SAAuD,CAAC,aAAa,EAAE,QAAQ;QAChF,SAAS,CAAC,QAAQ;QAClB,EAAE,CAAA;IACJ,OAAO,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAqB,EAAE,OAAO,GAA2B,EAAE;IAC5F,MAAM,EAAE,GAAG,GAAG,GAAG,EAAE,OAAO,GAAG,IAAI,EAAE,GAAG,OAAO,CAAA;IAC7C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;IAChC,MAAM,CAAC,OAAO,GAAG,SAAS,CAAA;IAC1B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE,OAAM;QACvD,MAAM,KAAK,GAAG,eAAe,EAAE,CAAA;QAC/B,MAAM,MAAM,GAAG,CAAC,KAAoB,EAAE,EAAE;YACtC,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM;gBAAE,OAAM;YAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAA;YAC1F,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ;gBAAE,OAAM;YACvD,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE;gBAAE,OAAM;YACzD,KAAK,CAAC,cAAc,EAAE,CAAA;YACtB,MAAM,CAAC,OAAO,EAAE,CAAA;QAClB,CAAC,CAAA;QACD,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC5C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;IAC9D,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;AACpB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CommandShortcutOptions } from './command-shortcut.ts';
2
+ export type { CommandShortcutOptions };
3
+ export declare function isApplePlatform(): boolean;
4
+ /**
5
+ * Nothing on React Native: a phone has no ⌘K, and a hardware keyboard reaches
6
+ * an application through APIs React Native does not expose as one event. The
7
+ * palette is opened from a control the application draws. Kept as a hook so a
8
+ * screen written once calls it on both platforms.
9
+ */
10
+ export declare function useCommandShortcut(_onTrigger: () => void, _options?: CommandShortcutOptions): void;
11
+ //# sourceMappingURL=command-shortcut.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.native.d.ts","sourceRoot":"","sources":["../src/command-shortcut.native.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAEnE,YAAY,EAAE,sBAAsB,EAAE,CAAA;AAEtC,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,IAAI,EAAE,QAAQ,GAAE,sBAA2B,QAAI"}
@@ -0,0 +1,11 @@
1
+ export function isApplePlatform() {
2
+ return false;
3
+ }
4
+ /**
5
+ * Nothing on React Native: a phone has no ⌘K, and a hardware keyboard reaches
6
+ * an application through APIs React Native does not expose as one event. The
7
+ * palette is opened from a control the application draws. Kept as a hook so a
8
+ * screen written once calls it on both platforms.
9
+ */
10
+ export function useCommandShortcut(_onTrigger, _options = {}) { }
11
+ //# sourceMappingURL=command-shortcut.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-shortcut.native.js","sourceRoot":"","sources":["../src/command-shortcut.native.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,eAAe;IAC7B,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAsB,EAAE,QAAQ,GAA2B,EAAE,IAAG,CAAC"}
@@ -0,0 +1,26 @@
1
+ export interface Drag1DOptions {
2
+ axis: 'x' | 'y';
3
+ disabled?: boolean;
4
+ /** Native can wait for movement so a Pressable still receives ordinary taps. */
5
+ nativeActivationDistance?: number;
6
+ /** Validate measured geometry before starting a session. */
7
+ canStart?: () => boolean;
8
+ /** Horizontal deltas follow the platform's writing direction. */
9
+ onStart?: () => void;
10
+ onMove?: (delta: number, details: Drag1DDetails) => void;
11
+ onEnd?: (delta: number, details: Drag1DDetails) => void;
12
+ onCancel?: () => void;
13
+ }
14
+ export interface Drag1DDetails {
15
+ /** Pixels per millisecond along the same logical axis as delta. */
16
+ velocity: number;
17
+ }
18
+ /** Shared lifecycle: moves are coalesced, but release always flushes its final delta. */
19
+ export declare function createDrag1DSession(options: () => Drag1DOptions, schedule: (callback: () => void) => number, unschedule: (id: number) => void): {
20
+ readonly active: boolean;
21
+ start(): boolean;
22
+ move(next: number, sample?: Drag1DDetails): void;
23
+ end(next: number, sample?: Drag1DDetails): void;
24
+ cancel: () => void;
25
+ };
26
+ //# sourceMappingURL=drag-1d-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d-session.d.ts","sourceRoot":"","sources":["../src/drag-1d-session.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,GAAG,GAAG,GAAG,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gFAAgF;IAChF,wBAAwB,CAAC,EAAE,MAAM,CAAA;IACjC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAA;IACxB,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAA;IACxD,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,KAAK,IAAI,CAAA;IACvD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,yFAAyF;AACzF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,aAAa,EAC5B,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,EAC1C,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;;;eAkCnB,MAAM,WAAU,aAAa;cAO9B,MAAM,WAAU,aAAa;;EAY1C"}
@@ -0,0 +1,65 @@
1
+ /** Shared lifecycle: moves are coalesced, but release always flushes its final delta. */
2
+ export function createDrag1DSession(options, schedule, unschedule) {
3
+ let active = false;
4
+ let pending;
5
+ let delta = 0;
6
+ let delivered = 0;
7
+ let details = { velocity: 0 };
8
+ const flush = () => {
9
+ if (pending !== undefined)
10
+ unschedule(pending);
11
+ pending = undefined;
12
+ if (active && delta !== delivered) {
13
+ delivered = delta;
14
+ options().onMove?.(delta, details);
15
+ }
16
+ };
17
+ const cancel = () => {
18
+ if (!active)
19
+ return;
20
+ active = false;
21
+ if (pending !== undefined)
22
+ unschedule(pending);
23
+ pending = undefined;
24
+ options().onCancel?.();
25
+ };
26
+ return {
27
+ get active() {
28
+ return active;
29
+ },
30
+ start() {
31
+ if (active || options().disabled || options().canStart?.() === false)
32
+ return false;
33
+ active = true;
34
+ delta = delivered = 0;
35
+ details = { velocity: 0 };
36
+ options().onStart?.();
37
+ return active;
38
+ },
39
+ move(next, sample = { velocity: 0 }) {
40
+ if (!active)
41
+ return;
42
+ if (options().disabled)
43
+ return cancel();
44
+ delta = next;
45
+ details = sample;
46
+ if (pending === undefined)
47
+ pending = schedule(flush);
48
+ },
49
+ end(next, sample = details) {
50
+ if (!active)
51
+ return;
52
+ if (options().disabled)
53
+ return cancel();
54
+ delta = next;
55
+ details = sample;
56
+ flush();
57
+ if (!active)
58
+ return;
59
+ active = false;
60
+ options().onEnd?.(delta, details);
61
+ },
62
+ cancel,
63
+ };
64
+ }
65
+ //# sourceMappingURL=drag-1d-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d-session.js","sourceRoot":"","sources":["../src/drag-1d-session.ts"],"names":[],"mappings":"AAmBA,yFAAyF;AACzF,MAAM,UAAU,mBAAmB,CACjC,OAA4B,EAC5B,QAA0C,EAC1C,UAAgC;IAEhC,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,IAAI,OAA2B,CAAA;IAC/B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,SAAS,GAAG,CAAC,CAAA;IACjB,IAAI,OAAO,GAAkB,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAA;IAC5C,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,IAAI,OAAO,KAAK,SAAS;YAAE,UAAU,CAAC,OAAO,CAAC,CAAA;QAC9C,OAAO,GAAG,SAAS,CAAA;QACnB,IAAI,MAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAClC,SAAS,GAAG,KAAK,CAAA;Y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BAAE,OAAO,MAAM,EAAE,CAAA;YACvC,KAAK,GAAG,IAAI,CAAA;YACZ,OAAO,GAAG,MAAM,CAAA;YAChB,KAAK,EAAE,CAAA;YACP,IAAI,CAAC,MAAM;gBAAE,OAAM;YACnB,MAAM,GAAG,KAAK,CAAA;YACd,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QACnC,CAAC;QACD,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type PointerEvent } from 'react';
2
+ import { type Drag1DOptions } from './drag-1d-session.ts';
3
+ export type { Drag1DDetails, Drag1DOptions } from './drag-1d-session.ts';
4
+ export declare function useDrag1D(options: Drag1DOptions): {
5
+ dragging: boolean;
6
+ handlers: {
7
+ onPointerDown(event: PointerEvent<HTMLElement>): void;
8
+ onPointerMove(event: PointerEvent<HTMLElement>): void;
9
+ onPointerUp(event: PointerEvent<HTMLElement>): void;
10
+ onPointerCancel(event: PointerEvent<HTMLElement>): void;
11
+ onLostPointerCapture(event: PointerEvent<HTMLElement>): void;
12
+ };
13
+ };
14
+ //# sourceMappingURL=drag-1d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d.d.ts","sourceRoot":"","sources":["../src/drag-1d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAqD,MAAM,OAAO,CAAA;AAC5F,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAE9E,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAExE,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa;;;QA6D1C,aAAa,QAAQ,YAAY,CAAC,WAAW,CAAC;QAwB9C,aAAa,QAAQ,YAAY,CAAC,WAAW,CAAC;QAG9C,WAAW,QAAQ,YAAY,CAAC,WAAW,CAAC;QAM5C,eAAe,QAAQ,YAAY,CAAC,WAAW,CAAC;QAGhD,oBAAoB,QAAQ,YAAY,CAAC,WAAW,CAAC;;EAK1D"}
@@ -0,0 +1,93 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { createDrag1DSession } from './drag-1d-session.js';
3
+ export function useDrag1D(options) {
4
+ const live = useRef(options);
5
+ live.current = options;
6
+ const [dragging, setDragging] = useState(false);
7
+ const gesture = useRef(null);
8
+ const session = useMemo(() => createDrag1DSession(() => live.current, (callback) => requestAnimationFrame(callback), (id) => cancelAnimationFrame(id)), []);
9
+ const release = useCallback(() => {
10
+ const current = gesture.current;
11
+ gesture.current = null;
12
+ if (current?.host.hasPointerCapture(current.id))
13
+ current.host.releasePointerCapture(current.id);
14
+ }, []);
15
+ const cancel = useCallback(() => {
16
+ session.cancel();
17
+ release();
18
+ setDragging(false);
19
+ }, [session, release]);
20
+ useEffect(() => {
21
+ if (options.disabled)
22
+ cancel();
23
+ }, [options.disabled, cancel]);
24
+ useEffect(() => () => {
25
+ session.cancel();
26
+ release();
27
+ }, [session, release]);
28
+ const delta = (event) => {
29
+ const at = gesture.current;
30
+ return ((at.axis === 'x' ? event.clientX : event.clientY) - at.start) * at.sign;
31
+ };
32
+ const matches = (event) => gesture.current?.id === event.pointerId;
33
+ const sample = (event, retainVelocity = false) => {
34
+ const at = gesture.current;
35
+ const position = at.axis === 'x' ? event.clientX : event.clientY;
36
+ if (position !== at.last || !retainVelocity) {
37
+ at.velocity = ((position - at.last) * at.sign) / Math.max(1, event.timeStamp - at.lastAt);
38
+ }
39
+ at.last = position;
40
+ at.lastAt = event.timeStamp;
41
+ return { velocity: at.velocity };
42
+ };
43
+ return {
44
+ dragging,
45
+ handlers: {
46
+ onPointerDown(event) {
47
+ if (gesture.current || event.button !== 0 || !event.isPrimary || options.disabled)
48
+ return;
49
+ const host = event.currentTarget;
50
+ const axis = options.axis;
51
+ const sign = axis === 'x' && getComputedStyle(host).direction === 'rtl' ? -1 : 1;
52
+ gesture.current = {
53
+ id: event.pointerId,
54
+ host,
55
+ axis,
56
+ sign,
57
+ start: axis === 'x' ? event.clientX : event.clientY,
58
+ last: axis === 'x' ? event.clientX : event.clientY,
59
+ lastAt: event.timeStamp,
60
+ velocity: 0,
61
+ };
62
+ if (!session.start()) {
63
+ gesture.current = null;
64
+ return;
65
+ }
66
+ host.setPointerCapture(event.pointerId);
67
+ host.focus();
68
+ event.preventDefault();
69
+ setDragging(true);
70
+ },
71
+ onPointerMove(event) {
72
+ if (matches(event))
73
+ session.move(delta(event), sample(event));
74
+ },
75
+ onPointerUp(event) {
76
+ if (!matches(event))
77
+ return;
78
+ session.end(delta(event), sample(event, true));
79
+ release();
80
+ setDragging(false);
81
+ },
82
+ onPointerCancel(event) {
83
+ if (matches(event))
84
+ cancel();
85
+ },
86
+ onLostPointerCapture(event) {
87
+ if (matches(event))
88
+ cancel();
89
+ },
90
+ },
91
+ };
92
+ }
93
+ //# sourceMappingURL=drag-1d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d.js","sourceRoot":"","sources":["../src/drag-1d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5F,OAAO,EAAE,mBAAmB,EAAsB,MAAM,sBAAsB,CAAA;AAI9E,MAAM,UAAU,SAAS,CAAC,OAAsB;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACtB,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAC/C,MAAM,OAAO,GAAG,MAAM,CASZ,IAAI,CAAC,CAAA;IACf,MAAM,OAAO,GAAG,OAAO,CACrB,GAAG,EAAE,CACH,mBAAmB,CACjB,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAClB,CAAC,QAAQ,EAAE,EAAE,CAAC,qBAAqB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,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;YACD,eAAe,CAAC,KAAgC;gBAC9C,IAAI,OAAO,CAAC,KAAK,CAAC;oBAAE,MAAM,EAAE,CAAA;YAC9B,CAAC;YACD,oBAAoB,CAAC,KAAgC;gBACnD,IAAI,OAAO,CAAC,KAAK,CAAC;oBAAE,MAAM,EAAE,CAAA;YAC9B,CAAC;SACF;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type PanResponderInstance } from 'react-native';
2
+ import { type Drag1DOptions } from './drag-1d-session.ts';
3
+ export type { Drag1DDetails, Drag1DOptions } from './drag-1d-session.ts';
4
+ export declare function useDrag1D(options: Drag1DOptions): {
5
+ dragging: boolean;
6
+ handlers: PanResponderInstance['panHandlers'];
7
+ };
8
+ //# sourceMappingURL=drag-1d.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d.native.d.ts","sourceRoot":"","sources":["../src/drag-1d.native.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnF,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAE9E,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAExE,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG;IACjD,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE,oBAAoB,CAAC,aAAa,CAAC,CAAA;CAC9C,CAuDA"}
@@ -0,0 +1,52 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { I18nManager, PanResponder } from 'react-native';
3
+ import { createDrag1DSession } from './drag-1d-session.js';
4
+ export function useDrag1D(options) {
5
+ const live = useRef(options);
6
+ live.current = options;
7
+ const [dragging, setDragging] = useState(false);
8
+ const session = useMemo(() => createDrag1DSession(() => live.current, (callback) => requestAnimationFrame(callback), (id) => cancelAnimationFrame(id)), []);
9
+ const responder = useMemo(() => {
10
+ let axis = 'x';
11
+ let sign = 1;
12
+ const delta = (dx, dy) => (axis === 'x' ? dx : dy) * sign;
13
+ return PanResponder.create({
14
+ onStartShouldSetPanResponder: () => !live.current.disabled && (live.current.nativeActivationDistance ?? 0) <= 0,
15
+ onMoveShouldSetPanResponder: (_, state) => {
16
+ if (live.current.disabled)
17
+ return false;
18
+ const distance = live.current.nativeActivationDistance ?? 0;
19
+ return distance <= 0 || Math.abs(live.current.axis === 'x' ? state.dx : state.dy) > distance;
20
+ },
21
+ onPanResponderGrant: () => {
22
+ axis = live.current.axis;
23
+ sign = axis === 'x' && I18nManager.isRTL ? -1 : 1;
24
+ if (session.start())
25
+ setDragging(true);
26
+ },
27
+ onPanResponderMove: (_, state) => session.move(delta(state.dx, state.dy), {
28
+ velocity: ((axis === 'x' ? state.vx : state.vy) ?? 0) * sign,
29
+ }),
30
+ onPanResponderRelease: (_, state) => {
31
+ session.end(delta(state.dx, state.dy), {
32
+ velocity: ((axis === 'x' ? state.vx : state.vy) ?? 0) * sign,
33
+ });
34
+ setDragging(false);
35
+ },
36
+ onPanResponderTerminate: () => {
37
+ session.cancel();
38
+ setDragging(false);
39
+ },
40
+ onPanResponderTerminationRequest: () => true,
41
+ });
42
+ }, [session]);
43
+ useEffect(() => {
44
+ if (options.disabled) {
45
+ session.cancel();
46
+ setDragging(false);
47
+ }
48
+ }, [options.disabled, session]);
49
+ useEffect(() => () => session.cancel(), [session]);
50
+ return { dragging, handlers: responder.panHandlers };
51
+ }
52
+ //# sourceMappingURL=drag-1d.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-1d.native.js","sourceRoot":"","sources":["../src/drag-1d.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,YAAY,EAA6B,MAAM,cAAc,CAAA;AACnF,OAAO,EAAE,m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AAE,CAAA;gBAChB,WAAW,CAAC,KAAK,CAAC,CAAA;YACpB,CAAC;YACD,gCAAgC,EAAE,GAAG,EAAE,CAAC,IAAI;SAC7C,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IACb,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACrB,OAAO,CAAC,MAAM,EAAE,CAAA;YAChB,WAAW,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAA;IAC/B,SAAS,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,WAAW,EAAE,CAAA;AACtD,CAAC"}
@@ -60,4 +60,23 @@ export declare function parsePlacement(placement: Placement): {
60
60
  * Supports Popper/Floating-UI equivalent placement, flip, shift, size limits, and arrow calculation.
61
61
  */
62
62
  export declare function computePosition(anchor: Rect, floating: Rect, viewport: Viewport, options?: ComputePositionOptions): PositionResult;
63
+ /**
64
+ * A position computed in window coordinates, moved into the coordinates of the
65
+ * box the floating element is laid out in.
66
+ *
67
+ * React Native measures in the window but places `position: absolute` against
68
+ * the parent, so the two agree only when the parent sits at the window's
69
+ * origin. Without a `PortalProvider` the panel renders where it was written,
70
+ * inside its own pattern's padding, and landed that far from its anchor
71
+ * (#1326). The parent's origin is not measurable from the floating element
72
+ * directly, but it is where the element is in the window less where it was
73
+ * placed: `floatingInWindow - placed`.
74
+ */
75
+ export declare function toContainingBlock(position: PositionResult, floatingInWindow: {
76
+ x: number;
77
+ y: number;
78
+ }, placed: {
79
+ x: number;
80
+ y: number;
81
+ }): PositionResult;
63
82
  //# sourceMappingURL=floating-geometry.d.ts.map
@@ -1 +1 @@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AAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC1C,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B,cAAc,CAMhB"}
@@ -188,4 +188,23 @@ export function computePosition(anchor, floating, viewport, options = {}) {
188
188
  arrow,
189
189
  };
190
190
  }
191
+ /**
192
+ * A position computed in window coordinates, moved into the coordinates of the
193
+ * box the floating element is laid out in.
194
+ *
195
+ * React Native measures in the window but places `position: absolute` against
196
+ * the parent, so the two agree only when the parent sits at the window's
197
+ * origin. Without a `PortalProvider` the panel renders where it was written,
198
+ * inside its own pattern's padding, and landed that far from its anchor
199
+ * (#1326). The parent's origin is not measurable from the floating element
200
+ * directly, but it is where the element is in the window less where it was
201
+ * placed: `floatingInWindow - placed`.
202
+ */
203
+ export function toContainingBlock(position, floatingInWindow, placed) {
204
+ return {
205
+ ...position,
206
+ x: position.x - (floatingInWindow.x - placed.x),
207
+ y: position.y - (floatingInWindow.y - placed.y),
208
+ };
209
+ }
191
210
  //# sourceMappingURL=floating-geometry.js.map