@hozo/behaviors 0.2.0 → 0.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # @hozo/behaviors
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`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.
8
+
9
+ - [#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:
10
+ - preset swatches as a radio group;
11
+ - 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;
12
+ - a hex field;
13
+ - on the Web, an optional eyedropper where the browser has one.
14
+
15
+ 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`.
16
+
17
+ - [#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`.
18
+
19
+ **`CommandPalette`** is a searchable list of commands in a modal.
20
+ - 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.
21
+ - On React Native it is a full-screen modal with a button per command.
22
+ - 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.
23
+ - The headless version lives in `@hozo/patterns` and the look in `@hozo/ui`.
24
+
25
+ **`useCommandShortcut`** (`@hozo/behaviors`) calls a function for ⌘K on a Mac and Ctrl+K elsewhere. It does nothing on React Native.
26
+
27
+ - [#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.
28
+
29
+ - [#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.
30
+
31
+ - [#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.
32
+
33
+ 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.
34
+
35
+ 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.
36
+
37
+ - [#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.
38
+
39
+ - [#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.
40
+
41
+ - [#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.
42
+
3
43
  ## 0.2.0
4
44
 
5
45
  - 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,6 +73,18 @@ 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
  ---
@@ -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"}
package/dist/i18n.d.ts ADDED
@@ -0,0 +1,140 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * Every string Hozo's components show or announce, in English, by key.
4
+ *
5
+ * Exported so a project can seed its catalogue from it, and so a test can
6
+ * check none is missing. Parameters are named (`{remaining}`), because every
7
+ * library this connects to interpolates by name.
8
+ */
9
+ export declare const hozoMessages: {
10
+ readonly 'hozo.avatar.label': '{name}, {status}';
11
+ readonly 'hozo.avatar.statusBusy': 'busy';
12
+ readonly 'hozo.avatar.statusOffline': 'offline';
13
+ readonly 'hozo.avatar.statusOnline': 'online';
14
+ readonly 'hozo.badge.overflow': 'more than {max}';
15
+ readonly 'hozo.bottomSheet.handle': 'Resize';
16
+ readonly 'hozo.calendar.nextMonth': 'Next month';
17
+ readonly 'hozo.calendar.previousMonth': 'Previous month';
18
+ readonly 'hozo.calendar.rangeEnd': 'end of range';
19
+ readonly 'hozo.calendar.rangeStart': 'start of range';
20
+ readonly 'hozo.calendar.today': 'today';
21
+ readonly 'hozo.chip.remove': 'Remove {label}';
22
+ readonly 'hozo.color.black': 'black';
23
+ readonly 'hozo.color.blue': 'blue';
24
+ readonly 'hozo.color.cyan': 'cyan';
25
+ readonly 'hozo.color.dark': 'dark {color}';
26
+ readonly 'hozo.color.gray': 'gray';
27
+ readonly 'hozo.color.green': 'green';
28
+ readonly 'hozo.color.light': 'light {color}';
29
+ readonly 'hozo.color.orange': 'orange';
30
+ readonly 'hozo.color.pink': 'pink';
31
+ readonly 'hozo.color.purple': 'purple';
32
+ readonly 'hozo.color.red': 'red';
33
+ readonly 'hozo.color.white': 'white';
34
+ readonly 'hozo.color.yellow': 'yellow';
35
+ readonly 'hozo.colorPicker.alpha': 'Opacity';
36
+ readonly 'hozo.colorPicker.alphaValue': '{value}% opaque';
37
+ readonly 'hozo.colorPicker.described': '{name}, {hex}';
38
+ readonly 'hozo.colorPicker.eyeDropper': 'Pick a colour from the screen';
39
+ readonly 'hozo.colorPicker.hex': 'Hex colour';
40
+ readonly 'hozo.colorPicker.hue': 'Hue';
41
+ readonly 'hozo.colorPicker.hueValue': '{degrees} degrees, {name}';
42
+ readonly 'hozo.colorPicker.lightness': 'Lightness';
43
+ readonly 'hozo.colorPicker.percent': '{value}%';
44
+ readonly 'hozo.colorPicker.presets': 'Presets';
45
+ readonly 'hozo.colorPicker.saturation': 'Saturation';
46
+ readonly 'hozo.commandPalette.empty': 'No results';
47
+ readonly 'hozo.commandPalette.label': 'Command palette';
48
+ readonly 'hozo.commandPalette.oneResult': '1 result';
49
+ readonly 'hozo.commandPalette.results': '{count} results';
50
+ readonly 'hozo.datePicker.dialog': 'Choose a date';
51
+ readonly 'hozo.dateRangePicker.dialog': 'Choose a range of dates';
52
+ readonly 'hozo.dateTimePicker.dialog': 'Choose a date and time';
53
+ readonly 'hozo.dateTimePicker.done': 'Done';
54
+ readonly 'hozo.fileDropzone.selectedMany': '{count} files selected';
55
+ readonly 'hozo.fileDropzone.selectedOne': '{name} selected, {size}';
56
+ readonly 'hozo.fileDropzone.tooLarge': '{name} is too large: {size}, and the limit is {limit}';
57
+ readonly 'hozo.fileDropzone.tooMany': '{name} was not added: one pick takes {max}';
58
+ readonly 'hozo.fileDropzone.tooSmall': '{name} is too small: {size}';
59
+ readonly 'hozo.fileDropzone.unavailable': 'No file picker is available';
60
+ readonly 'hozo.fileDropzone.wrongType': '{name} is not an accepted kind of file';
61
+ readonly 'hozo.nativeSelect.cancel': 'Cancel';
62
+ readonly 'hozo.otpInput.hint': '{length} characters';
63
+ readonly 'hozo.pagination.label': 'Pagination';
64
+ readonly 'hozo.pagination.next': 'Next page';
65
+ readonly 'hozo.pagination.page': 'Page {page}';
66
+ readonly 'hozo.pagination.previous': 'Previous page';
67
+ readonly 'hozo.stepper.completed': 'completed';
68
+ readonly 'hozo.stepper.current': 'current';
69
+ readonly 'hozo.stepper.error': 'has an error';
70
+ readonly 'hozo.stepper.label': 'Progress';
71
+ readonly 'hozo.stepper.step': 'Step {step} of {count}: {label}, {status}';
72
+ readonly 'hozo.stepper.upcoming': 'not started';
73
+ readonly 'hozo.textArea.remaining': '{remaining} of {maxLength} characters left';
74
+ readonly 'hozo.timePicker.decrease': 'Decrease';
75
+ readonly 'hozo.timePicker.empty': '--';
76
+ readonly 'hozo.timePicker.hour': 'Hour';
77
+ readonly 'hozo.timePicker.increase': 'Increase';
78
+ readonly 'hozo.timePicker.minute': 'Minute';
79
+ readonly 'hozo.timePicker.period': 'AM or PM';
80
+ };
81
+ export type HozoMessageKey = keyof typeof hozoMessages;
82
+ export type HozoMessageParams = Readonly<Record<string, string | number>>;
83
+ export interface HozoI18n {
84
+ /** BCP 47. Used for `Intl`: dates, numbers, the first day of the week. */
85
+ locale?: string;
86
+ /**
87
+ * Which way the content runs. Read by behaviours that cannot ask the
88
+ * platform; never applied. The Web's direction is `<html dir>` and
89
+ * Native's is `I18nManager`, and both are the application's to set.
90
+ */
91
+ dir?: 'ltr' | 'rtl';
92
+ /**
93
+ * The project's translation of `key`. `fallback` is Hozo's English with
94
+ * `params` already filled in, for a library that shows its default when a
95
+ * key is missing.
96
+ */
97
+ translate?: (key: HozoMessageKey, params: HozoMessageParams, fallback: string) => string;
98
+ }
99
+ export interface HozoI18nProviderProps {
100
+ value: HozoI18n;
101
+ children?: ReactNode;
102
+ }
103
+ /**
104
+ * Puts a project's i18n where Hozo's components can read it.
105
+ *
106
+ * Give it a new `value` when the language changes -- `useMemo` on the
107
+ * language -- and every Hozo string below re-renders in it.
108
+ */
109
+ export declare function HozoI18nProvider({ value, children }: HozoI18nProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<HozoI18n>>;
110
+ export declare function useHozoI18n(): HozoI18n;
111
+ /**
112
+ * A function resolving one of Hozo's strings: the component's own prop if
113
+ * there is one, then the project's translation, then Hozo's English.
114
+ */
115
+ export declare function useHozoMessage(): (key: HozoMessageKey, params?: HozoMessageParams, explicit?: string) => string;
116
+ /** The part of an i18next instance this reads. */
117
+ export interface I18nextLike {
118
+ t(key: string, options?: Record<string, unknown>): string;
119
+ language?: string;
120
+ dir?(language?: string): 'ltr' | 'rtl';
121
+ }
122
+ /**
123
+ * Hozo's i18n from an i18next instance: Hozo's keys are i18next keys, and
124
+ * Hozo's English is i18next's `defaultValue`.
125
+ */
126
+ export declare function fromI18next(i18n: I18nextLike): HozoI18n;
127
+ /** The part of a react-intl `IntlShape` this reads. */
128
+ export interface ReactIntlLike {
129
+ formatMessage(descriptor: {
130
+ id: string;
131
+ defaultMessage?: string;
132
+ }, values?: Record<string, string | number>): string;
133
+ locale?: string;
134
+ }
135
+ /**
136
+ * Hozo's i18n from react-intl: Hozo's keys are message ids, and Hozo's
137
+ * English is the `defaultMessage`.
138
+ */
139
+ export declare function fromReactIntl(intl: ReactIntlLike): HozoI18n;
140
+ //# sourceMappingURL=i18n.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAcA,OAAO,EAAgC,KAAK,SAAS,EAA2B,MAAM,OAAO,CAAA;AAE7F;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;aACvB,mBAAmB,EAAE,kBAAkB;aACvC,wBAAwB,EAAE,MAAM;aAChC,2BAA2B,EAAE,SAAS;aACtC,0BAA0B,EAAE,QAAQ;aACpC,qBAAqB,EAAE,iBAAiB;aACxC,yBAAyB,EAAE,QAAQ;aACnC,yBAAyB,EAAE,YAAY;aACvC,6BAA6B,EAAE,gBAAgB;aAC/C,wBAAwB,EAAE,cAAc;aACxC,0BAA0B,EAAE,gBAAgB;aAC5C,qBAAqB,EAAE,OAAO;aAC9B,kBAAkB,EAAE,gBAAgB;aACpC,kBAAkB,EAAE,OAAO;aAC3B,iBAAiB,EAAE,MAAM;aACzB,iBAAiB,EAAE,MAAM;aACzB,iBAAiB,EAAE,cAAc;aACjC,iBAAiB,EAAE,MAAM;aACzB,kBAAkB,EAAE,OAAO;aAC3B,kBAAkB,EAAE,eAAe;aACnC,mBAAmB,EAAE,QAAQ;aAC7B,iBAAiB,EAAE,MAAM;aACzB,mBAAmB,EAAE,QAAQ;aAC7B,gBAAgB,EAAE,KAAK;aACvB,kBAAkB,EAAE,OAAO;aAC3B,mBAAmB,EAAE,QAAQ;aAC7B,wBAAwB,EAAE,SAAS;aACnC,6BAA6B,EAAE,iBAAiB;aAChD,4BAA4B,EAAE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AC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GACvC,MAAM,CAAA;IACT,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,QAAQ,CAM3D"}
package/dist/i18n.js ADDED
@@ -0,0 +1,144 @@
1
+ // How Hozo's own strings and locale reach an application's i18n library
2
+ // (decision 008).
3
+ //
4
+ // Hozo does not translate. Applications already have a library for that --
5
+ // i18next, react-intl, Lingui -- with plural rules, interpolation and
6
+ // catalogues, and Hozo's strings belong in the same catalogue as the rest.
7
+ // So this is only the connection: a context carrying `locale`, `dir` and a
8
+ // `translate` function, the English every component falls back to, and two
9
+ // adapters that are a few lines each and typed structurally, so no
10
+ // `@hozo/*` package depends on any library.
11
+ //
12
+ // Platform-neutral on purpose: one file, imported by both entry points, so a
13
+ // provider on one side is the same object on the other.
14
+ import { createContext, createElement, useCallback, useContext } from 'react';
15
+ /**
16
+ * Every string Hozo's components show or announce, in English, by key.
17
+ *
18
+ * Exported so a project can seed its catalogue from it, and so a test can
19
+ * check none is missing. Parameters are named (`{remaining}`), because every
20
+ * library this connects to interpolates by name.
21
+ */
22
+ export const hozoMessages = {
23
+ 'hozo.avatar.label': '{name}, {status}',
24
+ 'hozo.avatar.statusBusy': 'busy',
25
+ 'hozo.avatar.statusOffline': 'offline',
26
+ 'hozo.avatar.statusOnline': 'online',
27
+ 'hozo.badge.overflow': 'more than {max}',
28
+ 'hozo.bottomSheet.handle': 'Resize',
29
+ 'hozo.calendar.nextMonth': 'Next month',
30
+ 'hozo.calendar.previousMonth': 'Previous month',
31
+ 'hozo.calendar.rangeEnd': 'end of range',
32
+ 'hozo.calendar.rangeStart': 'start of range',
33
+ 'hozo.calendar.today': 'today',
34
+ 'hozo.chip.remove': 'Remove {label}',
35
+ 'hozo.color.black': 'black',
36
+ 'hozo.color.blue': 'blue',
37
+ 'hozo.color.cyan': 'cyan',
38
+ 'hozo.color.dark': 'dark {color}',
39
+ 'hozo.color.gray': 'gray',
40
+ 'hozo.color.green': 'green',
41
+ 'hozo.color.light': 'light {color}',
42
+ 'hozo.color.orange': 'orange',
43
+ 'hozo.color.pink': 'pink',
44
+ 'hozo.color.purple': 'purple',
45
+ 'hozo.color.red': 'red',
46
+ 'hozo.color.white': 'white',
47
+ 'hozo.color.yellow': 'yellow',
48
+ 'hozo.colorPicker.alpha': 'Opacity',
49
+ 'hozo.colorPicker.alphaValue': '{value}% opaque',
50
+ 'hozo.colorPicker.described': '{name}, {hex}',
51
+ 'hozo.colorPicker.eyeDropper': 'Pick a colour from the screen',
52
+ 'hozo.colorPicker.hex': 'Hex colour',
53
+ 'hozo.colorPicker.hue': 'Hue',
54
+ 'hozo.colorPicker.hueValue': '{degrees} degrees, {name}',
55
+ 'hozo.colorPicker.lightness': 'Lightness',
56
+ 'hozo.colorPicker.percent': '{value}%',
57
+ 'hozo.colorPicker.presets': 'Presets',
58
+ 'hozo.colorPicker.saturation': 'Saturation',
59
+ 'hozo.commandPalette.empty': 'No results',
60
+ 'hozo.commandPalette.label': 'Command palette',
61
+ 'hozo.commandPalette.oneResult': '1 result',
62
+ 'hozo.commandPalette.results': '{count} results',
63
+ 'hozo.datePicker.dialog': 'Choose a date',
64
+ 'hozo.dateRangePicker.dialog': 'Choose a range of dates',
65
+ 'hozo.dateTimePicker.dialog': 'Choose a date and time',
66
+ 'hozo.dateTimePicker.done': 'Done',
67
+ 'hozo.fileDropzone.selectedMany': '{count} files selected',
68
+ 'hozo.fileDropzone.selectedOne': '{name} selected, {size}',
69
+ 'hozo.fileDropzone.tooLarge': '{name} is too large: {size}, and the limit is {limit}',
70
+ 'hozo.fileDropzone.tooMany': '{name} was not added: one pick takes {max}',
71
+ 'hozo.fileDropzone.tooSmall': '{name} is too small: {size}',
72
+ 'hozo.fileDropzone.unavailable': 'No file picker is available',
73
+ 'hozo.fileDropzone.wrongType': '{name} is not an accepted kind of file',
74
+ 'hozo.nativeSelect.cancel': 'Cancel',
75
+ 'hozo.otpInput.hint': '{length} characters',
76
+ 'hozo.pagination.label': 'Pagination',
77
+ 'hozo.pagination.next': 'Next page',
78
+ 'hozo.pagination.page': 'Page {page}',
79
+ 'hozo.pagination.previous': 'Previous page',
80
+ 'hozo.stepper.completed': 'completed',
81
+ 'hozo.stepper.current': 'current',
82
+ 'hozo.stepper.error': 'has an error',
83
+ 'hozo.stepper.label': 'Progress',
84
+ 'hozo.stepper.step': 'Step {step} of {count}: {label}, {status}',
85
+ 'hozo.stepper.upcoming': 'not started',
86
+ 'hozo.textArea.remaining': '{remaining} of {maxLength} characters left',
87
+ 'hozo.timePicker.decrease': 'Decrease',
88
+ 'hozo.timePicker.empty': '--',
89
+ 'hozo.timePicker.hour': 'Hour',
90
+ 'hozo.timePicker.increase': 'Increase',
91
+ 'hozo.timePicker.minute': 'Minute',
92
+ 'hozo.timePicker.period': 'AM or PM',
93
+ };
94
+ const HozoI18nContext = createContext({});
95
+ /**
96
+ * Puts a project's i18n where Hozo's components can read it.
97
+ *
98
+ * Give it a new `value` when the language changes -- `useMemo` on the
99
+ * language -- and every Hozo string below re-renders in it.
100
+ */
101
+ export function HozoI18nProvider({ value, children }) {
102
+ return createElement(HozoI18nContext.Provider, { value }, children);
103
+ }
104
+ export function useHozoI18n() {
105
+ return useContext(HozoI18nContext);
106
+ }
107
+ function interpolate(template, params) {
108
+ return template.replace(/\{(\w+)\}/g, (whole, name) => name in params ? String(params[name]) : whole);
109
+ }
110
+ /**
111
+ * A function resolving one of Hozo's strings: the component's own prop if
112
+ * there is one, then the project's translation, then Hozo's English.
113
+ */
114
+ export function useHozoMessage() {
115
+ const { translate } = useHozoI18n();
116
+ return useCallback((key, params = {}, explicit) => {
117
+ if (explicit !== undefined)
118
+ return explicit;
119
+ const fallback = interpolate(hozoMessages[key], params);
120
+ return translate ? translate(key, params, fallback) : fallback;
121
+ }, [translate]);
122
+ }
123
+ /**
124
+ * Hozo's i18n from an i18next instance: Hozo's keys are i18next keys, and
125
+ * Hozo's English is i18next's `defaultValue`.
126
+ */
127
+ export function fromI18next(i18n) {
128
+ return {
129
+ locale: i18n.language,
130
+ dir: i18n.dir?.(i18n.language),
131
+ translate: (key, params, fallback) => i18n.t(key, { ...params, defaultValue: fallback }),
132
+ };
133
+ }
134
+ /**
135
+ * Hozo's i18n from react-intl: Hozo's keys are message ids, and Hozo's
136
+ * English is the `defaultMessage`.
137
+ */
138
+ export function fromReactIntl(intl) {
139
+ return {
140
+ locale: intl.locale,
141
+ translate: (key, params, fallback) => intl.formatMessage({ id: key, defaultMessage: fallback }, params),
142
+ };
143
+ }
144
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../src/i18n.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,kBAAkB;AAClB,EAAE;AACF,2EAA2E;AAC3E,sEAAsE;AACtE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,mEAAmE;AACnE,4CAA4C;AAC5C,EAAE;AACF,6EAA6E;AAC7E,wDAAwD;AAExD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAkB,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAE7F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,mBAAmB,EAAE,kBAAkB;IACvC,wBAAwB,EAAE,MAAM;IAChC,2BAA2B,EAAE,SAAS;IACtC,0BAA0B,EAAE,QAAQ;IACpC,qBAAqB,EAAE,iBAAiB;IACxC,yBAAyB,EAAE,QAAQ;IACnC,yBAAyB,EAAE,YAAY;IACvC,6BAA6B,EAAE,gBAAgB;IAC/C,wBAAwB,EAAE,cAAc;IACxC,0BAA0B,EAAE,gBAAgB;IAC5C,qBAAqB,EAAE,OAAO;IAC9B,kBAAkB,EAAE,gBAAgB;IACpC,kBAAkB,EAAE,OAAO;IAC3B,iBAAiB,EAAE,MAAM;IACzB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;QACvD,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IAChE,CAAC,EACD,CAAC,SAAS,CAAC,CACZ,CAAA;AACH,CAAC;AASD;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAiB;IAC3C,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,QAAQ;QACrB,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC9B,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;KACzF,CAAA;AACH,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CACnC,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC;KACpE,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
+ export { type CommandShortcutOptions, isApplePlatform, useCommandShortcut, } from './command-shortcut.ts';
1
2
  export { DismissableLayer, type DismissableLayerProps, } from './dismissable-layer.tsx';
2
3
  export { type Alignment, type BasePlacement, type ComputePositionOptions, computePosition, type Placement, type PositionResult, parsePlacement, type Rect, type Viewport, } from './floating-geometry.ts';
3
4
  export { FloatingPositioner, type FloatingPositionerProps, type UseFloatingPositionOptions, useFloatingPosition, } from './floating-positioner.tsx';
4
5
  export { type FocusCandidate, FocusScope, type FocusScopeProps, initialFocusIndex, shouldRestoreFocus, } from './focus-scope.tsx';
5
6
  export { computeSafePolygon, type DelayGroupConfig, DelayGroupMachine, isPointInPolygon, type Point, type Polygon, } from './hover-geometry.ts';
6
7
  export { type ContentProps, TooltipGroupProvider, type TooltipGroupProviderProps, type TriggerProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, useTooltipGroup, } from './hover-trigger.tsx';
8
+ export { fromI18next, fromReactIntl, type HozoI18n, HozoI18nProvider, type HozoI18nProviderProps, type HozoMessageKey, type HozoMessageParams, hozoMessages, type I18nextLike, type ReactIntlLike, useHozoI18n, useHozoMessage, } from './i18n.ts';
7
9
  export { LiveRegion, type LiveRegionMode, type LiveRegionProps, useAnnounce, } from './live-region.tsx';
8
10
  export { Portal, PortalHost, type PortalProps, PortalProvider, } from './portal.tsx';
9
11
  export { type PresenceBinding, type PresenceState, usePresence, } from './presence.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACL,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,eAAe,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,YAAY,EACjB,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,EACR,aAAa,GACd,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,K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BAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ export { isApplePlatform, useCommandShortcut, } from './command-shortcut.js';
1
2
  export { DismissableLayer, } from './dismissable-layer.js';
2
3
  export { computePosition, parsePlacement, } from './floating-geometry.js';
3
4
  export { FloatingPositioner, useFloatingPosition, } from './floating-positioner.js';
4
5
  export { FocusScope, initialFocusIndex, shouldRestoreFocus, } from './focus-scope.js';
5
6
  export { computeSafePolygon, DelayGroupMachine, isPointInPolygon, } from './hover-geometry.js';
6
7
  export { TooltipGroupProvider, useHoverTrigger, useTooltipGroup, } from './hover-trigger.js';
8
+ export { fromI18next, fromReactIntl, HozoI18nProvider, hozoMessages, useHozoI18n, useHozoMessage, } from './i18n.js';
7
9
  export { LiveRegion, useAnnounce, } from './live-region.js';
8
10
  export { Portal, PortalHost, PortalProvider, } from './portal.js';
9
11
  export { usePresence, } from './presence.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAyB,CAAA;AAChC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAmB,CAAA;AAC1B,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEL,oBAAoB,EAKpB,eAAe,EACf,eAAe,GAChB,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,kBAAmB,CAAA;AAC1B,OAAO,EACL,MAAM,EACN,UAAU,E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,mBAAoB,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
@@ -1,9 +1,11 @@
1
+ export { type CommandShortcutOptions, isApplePlatform, useCommandShortcut, } from './command-shortcut.native.ts';
1
2
  export { DismissableLayer, type DismissableLayerProps, } from './dismissable-layer.native.tsx';
2
3
  export { type Alignment, type BasePlacement, type ComputePositionOptions, computePosition, type Placement, type PositionResult, parsePlacement, type Rect, type Viewport, } from './floating-geometry.ts';
3
4
  export { FloatingPositioner, type FloatingPositionerProps, type UseFloatingPositionOptions, useFloatingPosition, } from './floating-positioner.native.tsx';
4
5
  export { type FocusCandidate, FocusScope, type FocusScopeProps, initialFocusIndex, shouldRestoreFocus, } from './focus-scope.native.tsx';
5
6
  export { computeSafePolygon, type DelayGroupConfig, DelayGroupMachine, isPointInPolygon, type Point, type Polygon, } from './hover-geometry.ts';
6
7
  export { type NativeContentProps as ContentProps, type NativeTriggerProps as TriggerProps, TooltipGroupProvider, type TooltipGroupProviderProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, useTooltipGroup, } from './hover-trigger.native.tsx';
8
+ export { fromI18next, fromReactIntl, type HozoI18n, HozoI18nProvider, type HozoI18nProviderProps, type HozoMessageKey, type HozoMessageParams, hozoMessages, type I18nextLike, type ReactIntlLike, useHozoI18n, useHozoMessage, } from './i18n.ts';
7
9
  export { LiveRegion, type LiveRegionMode, type LiveRegionProps, useAnnounce, } from './live-region.native.tsx';
8
10
  export { Portal, PortalHost, type PortalProps, PortalProvider, } from './portal.native.tsx';
9
11
  export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,KA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O,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,eAAe,EACf,kBAAkB,GACnB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,gBAAgB,EAChB,KAAK,qBAAqB,GAC3B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,eAAe,EACf,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,IAAI,EACT,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,cAAc,EACnB,UAAU,EACV,KAAK,eAAe,EACpB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,KAAK,EACV,KAAK,OAAO,GACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,KAAK,kBAAkB,IAAI,YAAY,EACvC,KAAK,kBAAkB,IAAI,YAAY,EACvC,oBAAoB,EACpB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,WAAW,EACX,aAAa,EACb,KAAK,QAAQ,EACb,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,WAAW,EACX,cAAc,GACf,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,WAAW,GACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EACV,KAAK,WAAW,EAChB,cAAc,GACf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EACL,SAAS,EACT,KAAK,WAAW,EAChB,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,QAAQ,EACR,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
@@ -1,9 +1,11 @@
1
+ export { isApplePlatform, useCommandShortcut, } from './command-shortcut.native.js';
1
2
  export { DismissableLayer, } from './dismissable-layer.native.js';
2
3
  export { computePosition, parsePlacement, } from './floating-geometry.js';
3
4
  export { FloatingPositioner, useFloatingPosition, } from './floating-positioner.native.js';
4
5
  export { FocusScope, initialFocusIndex, shouldRestoreFocus, } from './focus-scope.native.js';
5
6
  export { computeSafePolygon, DelayGroupMachine, isPointInPolygon, } from './hover-geometry.js';
6
7
  export { TooltipGroupProvider, useHoverTrigger, useTooltipGroup, } from './hover-trigger.native.js';
8
+ export { fromI18next, fromReactIntl, HozoI18nProvider, hozoMessages, useHozoI18n, useHozoMessage, } from './i18n.js';
7
9
  export { LiveRegion, useAnnounce, } from './live-region.native.js';
8
10
  export { Portal, PortalHost, PortalProvider, } from './portal.native.js';
9
11
  export { usePresence } from './presence.native.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAAgC,CAAA;AACvC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,oBAAoB,EAIpB,eAAe,EACf,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EAEV,cAAc,GACf,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EACL,SAAS,EAET,gBAAgB,EAIhB,QAAQ,EACR,aAAa,GACd,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
1
+ {"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,eAAe,EACf,kBAAkB,GACnB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAAgC,CAAA;AACvC,OAAO,EAIL,eAAe,EAGf,cAAc,GAGf,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAEL,UAAU,EAEV,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EACjB,gBAAgB,GAGjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAGL,oBAAoB,EAIpB,eAAe,EACf,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,WAAW,EACX,aAAa,EAEb,gBAAgB,EAIhB,YAAY,EAGZ,WAAW,EACX,cAAc,GACf,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,UAAU,EAGV,WAAW,GACZ,MAAM,yBAA0B,CAAA;AACjC,OAAO,EACL,MAAM,EACN,UAAU,EAEV,cAAc,GACf,MAAM,oBAAqB,CAAA;AAC5B,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAC5F,OAAO,EACL,SAAS,EAET,gBAAgB,EAIhB,QAAQ,EACR,aAAa,GACd,MAAM,0BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAyB,CAAA;AAC1D,OAAO,EACL,cAAc,EACd,UAAU,EACV,WAAW,EACX,oBAAoB,EAEpB,YAAY,GACb,MAAM,gBAAgB,CAAA"}
package/dist/native.d.ts CHANGED
@@ -2,6 +2,7 @@ export { type HozoFocusMover, type HozoFocusTarget, hasAccessibilityFocusMover,
2
2
  export type { Placement } from './floating-geometry.ts';
3
3
  export { FloatingPositioner, type FloatingPositionerProps, type UseFloatingPositionOptions, useFloatingPosition, } from './floating-positioner.native.tsx';
4
4
  export { type NativeContentProps, type NativeTriggerProps, type UseHoverTriggerOptions, type UseHoverTriggerReturn, useHoverTrigger, } from './hover-trigger.native.tsx';
5
+ export { fromI18next, fromReactIntl, type HozoI18n, HozoI18nProvider, type HozoI18nProviderProps, type HozoMessageKey, type HozoMessageParams, hozoMessages, type I18nextLike, type ReactIntlLike, useHozoI18n, useHozoMessage, } from './i18n.ts';
5
6
  export { Portal, PortalHost, type PortalProps, PortalProvider } from './portal.native.tsx';
6
7
  export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts';
7
8
  //# sourceMappingURL=native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AACxC,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AACxC,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EACL,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,mBAAmB,GACpB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,eAAe,GAChB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,WAAW,EACX,aAAa,EACb,KAAK,QAAQ,EACb,gBAAgB,EAChB,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,WAAW,EACX,cAAc,GACf,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
package/dist/native.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { hasAccessibilityFocusMover, moveAccessibilityFocus, setAccessibilityFocusMover, } from './accessibility-focus.native.js';
2
2
  export { FloatingPositioner, useFloatingPosition, } from './floating-positioner.native.js';
3
3
  export { useHoverTrigger, } from './hover-trigger.native.js';
4
+ export { fromI18next, fromReactIntl, HozoI18nProvider, hozoMessages, useHozoI18n, useHozoMessage, } from './i18n.js';
4
5
  export { Portal, PortalHost, PortalProvider } from './portal.native.js';
5
6
  export { usePresence } from './presence.native.js';
6
7
  //# sourceMappingURL=native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AAExC,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAKL,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,oBAAqB,CAAA;AAC1F,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,iCAAiC,CAAA;AAExC,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,iCAAkC,CAAA;AACzC,OAAO,EAKL,eAAe,GAChB,MAAM,2BAA4B,CAAA;AACnC,OAAO,EACL,WAAW,EACX,aAAa,EAEb,gBAAgB,EAIhB,YAAY,EAGZ,WAAW,EACX,cAAc,GACf,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAoB,cAAc,EAAE,MAAM,oBAAqB,CAAA;AAC1F,OAAO,EAA4C,WAAW,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,30 @@
1
+ export interface HozoPressableInteractionState {
2
+ pressed: boolean;
3
+ hovered: boolean;
4
+ focused: boolean;
5
+ focusVisible: boolean;
6
+ }
7
+ /**
8
+ * The Native pressable's event-driven facts, shared with patterns (#897).
9
+ * No subscriptions, animation nodes or global modality listeners. Hosts own
10
+ * event delivery and compose their caller's handlers after these callbacks.
11
+ * onChange runs synchronously for the existing native animation driver;
12
+ * React state drives the ordinary style/children callbacks.
13
+ */
14
+ export declare function usePressableInteraction({ focusVisible, onChange, }?: {
15
+ focusVisible?: boolean;
16
+ onChange?: (state: HozoPressableInteractionState) => void;
17
+ }): {
18
+ state: HozoPressableInteractionState;
19
+ handlers: {
20
+ hoverIn: () => void;
21
+ hoverOut: () => void;
22
+ focus: () => void;
23
+ blur: () => void;
24
+ pointerDown: () => void;
25
+ keyDown: () => void;
26
+ pressIn: () => void;
27
+ pressOut: () => void;
28
+ };
29
+ };
30
+ //# sourceMappingURL=pressable-interaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pressable-interaction.d.ts","sourceRoot":"","sources":["../src/pressable-interaction.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,6BAA6B;IAC5C,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,OAAO,CAAA;CACtB;AAaD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,YAAoB,EACpB,QAAQ,GACT,GAAE;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,IAAI,CAAA;CACrD;;;;;;;;;;;;EA6CL"}
@@ -0,0 +1,64 @@
1
+ import { useCallback, useMemo, useRef, useState } from 'react';
2
+ const HOVERED = 1;
3
+ const FOCUSED = 2;
4
+ const PRESSED = 4;
5
+ const FOCUS_VISIBLE = 8;
6
+ const read = (mask) => ({
7
+ pressed: (mask & PRESSED) !== 0,
8
+ hovered: (mask & HOVERED) !== 0,
9
+ focused: (mask & FOCUSED) !== 0,
10
+ focusVisible: (mask & FOCUS_VISIBLE) !== 0,
11
+ });
12
+ /**
13
+ * The Native pressable's event-driven facts, shared with patterns (#897).
14
+ * No subscriptions, animation nodes or global modality listeners. Hosts own
15
+ * event delivery and compose their caller's handlers after these callbacks.
16
+ * onChange runs synchronously for the existing native animation driver;
17
+ * React state drives the ordinary style/children callbacks.
18
+ */
19
+ export function usePressableInteraction({ focusVisible = false, onChange, } = {}) {
20
+ const [mask, setMask] = useState(0);
21
+ const live = useRef(0);
22
+ // Matches the primitive's existing policy: initial focus is keyboard-like;
23
+ // a pointer/press clears it, and a key makes a currently focused host visible.
24
+ const modality = useRef('keyboard');
25
+ const set = useCallback((flag, active) => {
26
+ const next = active ? live.current | flag : live.current & ~flag;
27
+ live.current = next;
28
+ onChange?.(read(next));
29
+ setMask(next);
30
+ }, [onChange]);
31
+ const handlers = useMemo(() => ({
32
+ hoverIn: () => set(HOVERED, true),
33
+ hoverOut: () => set(HOVERED, false),
34
+ focus: () => {
35
+ set(FOCUSED, true);
36
+ if (focusVisible)
37
+ set(FOCUS_VISIBLE, modality.current === 'keyboard');
38
+ },
39
+ blur: () => {
40
+ set(FOCUSED, false);
41
+ if (focusVisible)
42
+ set(FOCUS_VISIBLE, false);
43
+ },
44
+ pointerDown: () => {
45
+ modality.current = 'pointer';
46
+ if (focusVisible)
47
+ set(FOCUS_VISIBLE, false);
48
+ },
49
+ keyDown: () => {
50
+ modality.current = 'keyboard';
51
+ if (focusVisible && (live.current & FOCUSED) !== 0)
52
+ set(FOCUS_VISIBLE, true);
53
+ },
54
+ pressIn: () => {
55
+ modality.current = 'pointer';
56
+ if (focusVisible)
57
+ set(FOCUS_VISIBLE, false);
58
+ set(PRESSED, true);
59
+ },
60
+ pressOut: () => set(PRESSED, false),
61
+ }), [focusVisible, set]);
62
+ return { state: useMemo(() => read(mask), [mask]), handlers };
63
+ }
64
+ //# sourceMappingURL=pressable-interaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pressable-interaction.js","sourceRoot":"","sources":["../src/pressable-interaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAS9D,MAAM,OAAO,GAAG,CAAC,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAA;AACjB,MAAM,aAAa,GAAG,CAAC,CAAA;AACvB,MAAM,IAAI,GAAG,CAAC,IAAY,EAAiC,EAAE,CAAC,CAAC;IAC7D,OAAO,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC;IAC/B,YAAY,EAAE,CAAC,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC;CAC3C,CAAC,C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EAAE,KAAK,CAAC,CAAA;QAC7C,CAAC;QACD,WAAW,EAAE,GAAG,EAAE;YAChB,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;YAC5B,IAAI,YAAY;gBAAE,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;QAC7C,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,OAAO,GAAG,UAAU,CAAA;YAC7B,IAAI,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;gBAAE,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;QAC9E,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;YAC5B,IAAI,YAAY;gBAAE,GAAG,CAAC,aAAa,EAAE,KAAK,CAAC,CAAA;YAC3C,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;QACpB,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC;KACpC,CAAC,EACF,CAAC,YAAY,EAAE,GAAG,CAAC,CACpB,CAAA;IACD,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAA;AAC/D,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hozo/behaviors",
3
- "version": "0.2.0",
4
- "description": "Universal runtime behaviors substrate (LiveRegion, Portal, DismissableLayer, FocusScope, RovingFocus, FloatingPositioner) for Hozo.",
3
+ "version": "0.3.0",
4
+ "description": "Hozo's accessibility and internationalisation behaviours (FocusScope, RovingFocus, LiveRegion, Portal, DismissableLayer, FloatingPositioner), shared by Web and React Native.",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "behaviors",
@@ -40,6 +40,10 @@
40
40
  "types": "./dist/native.d.ts",
41
41
  "default": "./dist/native.js"
42
42
  },
43
+ "./pressable-interaction": {
44
+ "types": "./dist/pressable-interaction.d.ts",
45
+ "default": "./dist/pressable-interaction.js"
46
+ },
43
47
  "./package.json": "./package.json"
44
48
  },
45
49
  "files": [
@@ -0,0 +1,15 @@
1
+ import type { CommandShortcutOptions } from './command-shortcut.ts'
2
+
3
+ export type { CommandShortcutOptions }
4
+
5
+ export function isApplePlatform(): boolean {
6
+ return false
7
+ }
8
+
9
+ /**
10
+ * Nothing on React Native: a phone has no ⌘K, and a hardware keyboard reaches
11
+ * an application through APIs React Native does not expose as one event. The
12
+ * palette is opened from a control the application draws. Kept as a hook so a
13
+ * screen written once calls it on both platforms.
14
+ */
15
+ export function useCommandShortcut(_onTrigger: () => void, _options: CommandShortcutOptions = {}) {}
@@ -0,0 +1,51 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export interface CommandShortcutOptions {
4
+ /** The letter, pressed with ⌘ on Apple platforms and Ctrl elsewhere; `k` by default. */
5
+ key?: string
6
+ /** Off while something else owns the keyboard. */
7
+ enabled?: boolean
8
+ }
9
+
10
+ /** ⌘ on an Apple platform, Ctrl elsewhere -- the modifier each one's own shortcuts use. */
11
+ export function isApplePlatform(): boolean {
12
+ if (typeof navigator === 'undefined') return false
13
+ const platform =
14
+ (navigator as { userAgentData?: { platform?: string } }).userAgentData?.platform ??
15
+ navigator.platform ??
16
+ ''
17
+ return /mac|iphone|ipad|ipod/i.test(platform)
18
+ }
19
+
20
+ /**
21
+ * Calls `onTrigger` for ⌘K on a Mac and Ctrl+K elsewhere, from anywhere on the
22
+ * page (#152).
23
+ *
24
+ * The browser's default is prevented only for the press that is handled:
25
+ * Ctrl+K is Chrome's "search from the address bar", and taking it away when
26
+ * nothing opens would be taking it for nothing. A press during IME
27
+ * composition is not a shortcut -- the composition owns the keyboard -- and
28
+ * neither is a held key repeating.
29
+ *
30
+ * A behaviour rather than part of `CommandPalette`, because a shortcut is
31
+ * useful without one: to focus a search field, or open a different panel.
32
+ */
33
+ export function useCommandShortcut(onTrigger: () => void, options: CommandShortcutOptions = {}) {
34
+ const { key = 'k', enabled = true } = options
35
+ const latest = useRef(onTrigger)
36
+ latest.current = onTrigger
37
+ useEffect(() => {
38
+ if (!enabled || typeof document === 'undefined') return
39
+ const apple = isApplePlatform()
40
+ const handle = (event: KeyboardEvent) => {
41
+ if (event.isComposing || event.repeat) return
42
+ const modifier = apple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey
43
+ if (!modifier || event.altKey || event.shiftKey) return
44
+ if (event.key.toLowerCase() !== key.toLowerCase()) return
45
+ event.preventDefault()
46
+ latest.current()
47
+ }
48
+ document.addEventListener('keydown', handle)
49
+ return () => document.removeEventListener('keydown', handle)
50
+ }, [enabled, key])
51
+ }
package/src/i18n.ts ADDED
@@ -0,0 +1,198 @@
1
+ // How Hozo's own strings and locale reach an application's i18n library
2
+ // (decision 008).
3
+ //
4
+ // Hozo does not translate. Applications already have a library for that --
5
+ // i18next, react-intl, Lingui -- with plural rules, interpolation and
6
+ // catalogues, and Hozo's strings belong in the same catalogue as the rest.
7
+ // So this is only the connection: a context carrying `locale`, `dir` and a
8
+ // `translate` function, the English every component falls back to, and two
9
+ // adapters that are a few lines each and typed structurally, so no
10
+ // `@hozo/*` package depends on any library.
11
+ //
12
+ // Platform-neutral on purpose: one file, imported by both entry points, so a
13
+ // provider on one side is the same object on the other.
14
+
15
+ import { createContext, createElement, type ReactNode, useCallback, useContext } from 'react'
16
+
17
+ /**
18
+ * Every string Hozo's components show or announce, in English, by key.
19
+ *
20
+ * Exported so a project can seed its catalogue from it, and so a test can
21
+ * check none is missing. Parameters are named (`{remaining}`), because every
22
+ * library this connects to interpolates by name.
23
+ */
24
+ export const hozoMessages = {
25
+ 'hozo.avatar.label': '{name}, {status}',
26
+ 'hozo.avatar.statusBusy': 'busy',
27
+ 'hozo.avatar.statusOffline': 'offline',
28
+ 'hozo.avatar.statusOnline': 'online',
29
+ 'hozo.badge.overflow': 'more than {max}',
30
+ 'hozo.bottomSheet.handle': 'Resize',
31
+ 'hozo.calendar.nextMonth': 'Next month',
32
+ 'hozo.calendar.previousMonth': 'Previous month',
33
+ 'hozo.calendar.rangeEnd': 'end of range',
34
+ 'hozo.calendar.rangeStart': 'start of range',
35
+ 'hozo.calendar.today': 'today',
36
+ 'hozo.chip.remove': 'Remove {label}',
37
+ 'hozo.color.black': 'black',
38
+ 'hozo.color.blue': 'blue',
39
+ 'hozo.color.cyan': 'cyan',
40
+ 'hozo.color.dark': 'dark {color}',
41
+ 'hozo.color.gray': 'gray',
42
+ 'hozo.color.green': 'green',
43
+ 'hozo.color.light': 'light {color}',
44
+ 'hozo.color.orange': 'orange',
45
+ 'hozo.color.pink': 'pink',
46
+ 'hozo.color.purple': 'purple',
47
+ 'hozo.color.red': 'red',
48
+ 'hozo.color.white': 'white',
49
+ 'hozo.color.yellow': 'yellow',
50
+ 'hozo.colorPicker.alpha': 'Opacity',
51
+ 'hozo.colorPicker.alphaValue': '{value}% opaque',
52
+ 'hozo.colorPicker.described': '{name}, {hex}',
53
+ 'hozo.colorPicker.eyeDropper': 'Pick a colour from the screen',
54
+ 'hozo.colorPicker.hex': 'Hex colour',
55
+ 'hozo.colorPicker.hue': 'Hue',
56
+ 'hozo.colorPicker.hueValue': '{degrees} degrees, {name}',
57
+ 'hozo.colorPicker.lightness': 'Lightness',
58
+ 'hozo.colorPicker.percent': '{value}%',
59
+ 'hozo.colorPicker.presets': 'Presets',
60
+ 'hozo.colorPicker.saturation': 'Saturation',
61
+ 'hozo.commandPalette.empty': 'No results',
62
+ 'hozo.commandPalette.label': 'Command palette',
63
+ 'hozo.commandPalette.oneResult': '1 result',
64
+ 'hozo.commandPalette.results': '{count} results',
65
+ 'hozo.datePicker.dialog': 'Choose a date',
66
+ 'hozo.dateRangePicker.dialog': 'Choose a range of dates',
67
+ 'hozo.dateTimePicker.dialog': 'Choose a date and time',
68
+ 'hozo.dateTimePicker.done': 'Done',
69
+ 'hozo.fileDropzone.selectedMany': '{count} files selected',
70
+ 'hozo.fileDropzone.selectedOne': '{name} selected, {size}',
71
+ 'hozo.fileDropzone.tooLarge': '{name} is too large: {size}, and the limit is {limit}',
72
+ 'hozo.fileDropzone.tooMany': '{name} was not added: one pick takes {max}',
73
+ 'hozo.fileDropzone.tooSmall': '{name} is too small: {size}',
74
+ 'hozo.fileDropzone.unavailable': 'No file picker is available',
75
+ 'hozo.fileDropzone.wrongType': '{name} is not an accepted kind of file',
76
+ 'hozo.nativeSelect.cancel': 'Cancel',
77
+ 'hozo.otpInput.hint': '{length} characters',
78
+ 'hozo.pagination.label': 'Pagination',
79
+ 'hozo.pagination.next': 'Next page',
80
+ 'hozo.pagination.page': 'Page {page}',
81
+ 'hozo.pagination.previous': 'Previous page',
82
+ 'hozo.stepper.completed': 'completed',
83
+ 'hozo.stepper.current': 'current',
84
+ 'hozo.stepper.error': 'has an error',
85
+ 'hozo.stepper.label': 'Progress',
86
+ 'hozo.stepper.step': 'Step {step} of {count}: {label}, {status}',
87
+ 'hozo.stepper.upcoming': 'not started',
88
+ 'hozo.textArea.remaining': '{remaining} of {maxLength} characters left',
89
+ 'hozo.timePicker.decrease': 'Decrease',
90
+ 'hozo.timePicker.empty': '--',
91
+ 'hozo.timePicker.hour': 'Hour',
92
+ 'hozo.timePicker.increase': 'Increase',
93
+ 'hozo.timePicker.minute': 'Minute',
94
+ 'hozo.timePicker.period': 'AM or PM',
95
+ } as const
96
+
97
+ export type HozoMessageKey = keyof typeof hozoMessages
98
+ export type HozoMessageParams = Readonly<Record<string, string | number>>
99
+
100
+ export interface HozoI18n {
101
+ /** BCP 47. Used for `Intl`: dates, numbers, the first day of the week. */
102
+ locale?: string
103
+ /**
104
+ * Which way the content runs. Read by behaviours that cannot ask the
105
+ * platform; never applied. The Web's direction is `<html dir>` and
106
+ * Native's is `I18nManager`, and both are the application's to set.
107
+ */
108
+ dir?: 'ltr' | 'rtl'
109
+ /**
110
+ * The project's translation of `key`. `fallback` is Hozo's English with
111
+ * `params` already filled in, for a library that shows its default when a
112
+ * key is missing.
113
+ */
114
+ translate?: (key: HozoMessageKey, params: HozoMessageParams, fallback: string) => string
115
+ }
116
+
117
+ const HozoI18nContext = createContext<HozoI18n>({})
118
+
119
+ export interface HozoI18nProviderProps {
120
+ value: HozoI18n
121
+ children?: ReactNode
122
+ }
123
+
124
+ /**
125
+ * Puts a project's i18n where Hozo's components can read it.
126
+ *
127
+ * Give it a new `value` when the language changes -- `useMemo` on the
128
+ * language -- and every Hozo string below re-renders in it.
129
+ */
130
+ export function HozoI18nProvider({ value, children }: HozoI18nProviderProps) {
131
+ return createElement(HozoI18nContext.Provider, { value }, children)
132
+ }
133
+
134
+ export function useHozoI18n(): HozoI18n {
135
+ return useContext(HozoI18nContext)
136
+ }
137
+
138
+ function interpolate(template: string, params: HozoMessageParams): string {
139
+ return template.replace(/\{(\w+)\}/g, (whole, name: string) =>
140
+ name in params ? String(params[name]) : whole,
141
+ )
142
+ }
143
+
144
+ /**
145
+ * A function resolving one of Hozo's strings: the component's own prop if
146
+ * there is one, then the project's translation, then Hozo's English.
147
+ */
148
+ export function useHozoMessage() {
149
+ const { translate } = useHozoI18n()
150
+ return useCallback(
151
+ (key: HozoMessageKey, params: HozoMessageParams = {}, explicit?: string): string => {
152
+ if (explicit !== undefined) return explicit
153
+ const fallback = interpolate(hozoMessages[key], params)
154
+ return translate ? translate(key, params, fallback) : fallback
155
+ },
156
+ [translate],
157
+ )
158
+ }
159
+
160
+ /** The part of an i18next instance this reads. */
161
+ export interface I18nextLike {
162
+ t(key: string, options?: Record<string, unknown>): string
163
+ language?: string
164
+ dir?(language?: string): 'ltr' | 'rtl'
165
+ }
166
+
167
+ /**
168
+ * Hozo's i18n from an i18next instance: Hozo's keys are i18next keys, and
169
+ * Hozo's English is i18next's `defaultValue`.
170
+ */
171
+ export function fromI18next(i18n: I18nextLike): HozoI18n {
172
+ return {
173
+ locale: i18n.language,
174
+ dir: i18n.dir?.(i18n.language),
175
+ translate: (key, params, fallback) => i18n.t(key, { ...params, defaultValue: fallback }),
176
+ }
177
+ }
178
+
179
+ /** The part of a react-intl `IntlShape` this reads. */
180
+ export interface ReactIntlLike {
181
+ formatMessage(
182
+ descriptor: { id: string; defaultMessage?: string },
183
+ values?: Record<string, string | number>,
184
+ ): string
185
+ locale?: string
186
+ }
187
+
188
+ /**
189
+ * Hozo's i18n from react-intl: Hozo's keys are message ids, and Hozo's
190
+ * English is the `defaultMessage`.
191
+ */
192
+ export function fromReactIntl(intl: ReactIntlLike): HozoI18n {
193
+ return {
194
+ locale: intl.locale,
195
+ translate: (key, params, fallback) =>
196
+ intl.formatMessage({ id: key, defaultMessage: fallback }, params),
197
+ }
198
+ }
@@ -1,3 +1,8 @@
1
+ export {
2
+ type CommandShortcutOptions,
3
+ isApplePlatform,
4
+ useCommandShortcut,
5
+ } from './command-shortcut.native.ts'
1
6
  export {
2
7
  DismissableLayer,
3
8
  type DismissableLayerProps,
@@ -44,6 +49,20 @@ export {
44
49
  useHoverTrigger,
45
50
  useTooltipGroup,
46
51
  } from './hover-trigger.native.tsx'
52
+ export {
53
+ fromI18next,
54
+ fromReactIntl,
55
+ type HozoI18n,
56
+ HozoI18nProvider,
57
+ type HozoI18nProviderProps,
58
+ type HozoMessageKey,
59
+ type HozoMessageParams,
60
+ hozoMessages,
61
+ type I18nextLike,
62
+ type ReactIntlLike,
63
+ useHozoI18n,
64
+ useHozoMessage,
65
+ } from './i18n.ts'
47
66
  export {
48
67
  LiveRegion,
49
68
  type LiveRegionMode,
package/src/index.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export {
2
+ type CommandShortcutOptions,
3
+ isApplePlatform,
4
+ useCommandShortcut,
5
+ } from './command-shortcut.ts'
1
6
  export {
2
7
  DismissableLayer,
3
8
  type DismissableLayerProps,
@@ -44,6 +49,20 @@ export {
44
49
  useHoverTrigger,
45
50
  useTooltipGroup,
46
51
  } from './hover-trigger.tsx'
52
+ export {
53
+ fromI18next,
54
+ fromReactIntl,
55
+ type HozoI18n,
56
+ HozoI18nProvider,
57
+ type HozoI18nProviderProps,
58
+ type HozoMessageKey,
59
+ type HozoMessageParams,
60
+ hozoMessages,
61
+ type I18nextLike,
62
+ type ReactIntlLike,
63
+ useHozoI18n,
64
+ useHozoMessage,
65
+ } from './i18n.ts'
47
66
  export {
48
67
  LiveRegion,
49
68
  type LiveRegionMode,
package/src/native.ts CHANGED
@@ -19,5 +19,19 @@ export {
19
19
  type UseHoverTriggerReturn,
20
20
  useHoverTrigger,
21
21
  } from './hover-trigger.native.tsx'
22
+ export {
23
+ fromI18next,
24
+ fromReactIntl,
25
+ type HozoI18n,
26
+ HozoI18nProvider,
27
+ type HozoI18nProviderProps,
28
+ type HozoMessageKey,
29
+ type HozoMessageParams,
30
+ hozoMessages,
31
+ type I18nextLike,
32
+ type ReactIntlLike,
33
+ useHozoI18n,
34
+ useHozoMessage,
35
+ } from './i18n.ts'
22
36
  export { Portal, PortalHost, type PortalProps, PortalProvider } from './portal.native.tsx'
23
37
  export { type PresenceBinding, type PresenceState, usePresence } from './presence.native.ts'
@@ -0,0 +1,79 @@
1
+ import { useCallback, useMemo, useRef, useState } from 'react'
2
+
3
+ export interface HozoPressableInteractionState {
4
+ pressed: boolean
5
+ hovered: boolean
6
+ focused: boolean
7
+ focusVisible: boolean
8
+ }
9
+
10
+ const HOVERED = 1
11
+ const FOCUSED = 2
12
+ const PRESSED = 4
13
+ const FOCUS_VISIBLE = 8
14
+ const read = (mask: number): HozoPressableInteractionState => ({
15
+ pressed: (mask & PRESSED) !== 0,
16
+ hovered: (mask & HOVERED) !== 0,
17
+ focused: (mask & FOCUSED) !== 0,
18
+ focusVisible: (mask & FOCUS_VISIBLE) !== 0,
19
+ })
20
+
21
+ /**
22
+ * The Native pressable's event-driven facts, shared with patterns (#897).
23
+ * No subscriptions, animation nodes or global modality listeners. Hosts own
24
+ * event delivery and compose their caller's handlers after these callbacks.
25
+ * onChange runs synchronously for the existing native animation driver;
26
+ * React state drives the ordinary style/children callbacks.
27
+ */
28
+ export function usePressableInteraction({
29
+ focusVisible = false,
30
+ onChange,
31
+ }: {
32
+ focusVisible?: boolean
33
+ onChange?: (state: HozoPressableInteractionState) => void
34
+ } = {}) {
35
+ const [mask, setMask] = useState(0)
36
+ const live = useRef(0)
37
+ // Matches the primitive's existing policy: initial focus is keyboard-like;
38
+ // a pointer/press clears it, and a key makes a currently focused host visible.
39
+ const modality = useRef<'keyboard' | 'pointer'>('keyboard')
40
+ const set = useCallback(
41
+ (flag: number, active: boolean) => {
42
+ const next = active ? live.current | flag : live.current & ~flag
43
+ live.current = next
44
+ onChange?.(read(next))
45
+ setMask(next)
46
+ },
47
+ [onChange],
48
+ )
49
+ const handlers = useMemo(
50
+ () => ({
51
+ hoverIn: () => set(HOVERED, true),
52
+ hoverOut: () => set(HOVERED, false),
53
+ focus: () => {
54
+ set(FOCUSED, true)
55
+ if (focusVisible) set(FOCUS_VISIBLE, modality.current === 'keyboard')
56
+ },
57
+ blur: () => {
58
+ set(FOCUSED, false)
59
+ if (focusVisible) set(FOCUS_VISIBLE, false)
60
+ },
61
+ pointerDown: () => {
62
+ modality.current = 'pointer'
63
+ if (focusVisible) set(FOCUS_VISIBLE, false)
64
+ },
65
+ keyDown: () => {
66
+ modality.current = 'keyboard'
67
+ if (focusVisible && (live.current & FOCUSED) !== 0) set(FOCUS_VISIBLE, true)
68
+ },
69
+ pressIn: () => {
70
+ modality.current = 'pointer'
71
+ if (focusVisible) set(FOCUS_VISIBLE, false)
72
+ set(PRESSED, true)
73
+ },
74
+ pressOut: () => set(PRESSED, false),
75
+ }),
76
+ [focusVisible, set],
77
+ )
78
+ return { state: useMemo(() => read(mask), [mask]), handlers }
79
+ }