@hozo/engine 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +78 -0
- package/dist/activate.d.ts +14 -0
- package/dist/activate.d.ts.map +1 -0
- package/dist/activate.js +38 -0
- package/dist/activate.js.map +1 -0
- package/dist/ambient.d.ts +79 -0
- package/dist/ambient.d.ts.map +1 -0
- package/dist/ambient.js +117 -0
- package/dist/ambient.js.map +1 -0
- package/dist/backdrop.d.ts +36 -0
- package/dist/backdrop.d.ts.map +1 -0
- package/dist/backdrop.js +41 -0
- package/dist/backdrop.js.map +1 -0
- package/dist/class-name.native.d.ts +20 -0
- package/dist/class-name.native.d.ts.map +1 -0
- package/dist/class-name.native.js +34 -0
- package/dist/class-name.native.js.map +1 -0
- package/dist/class-resolver.d.ts +26 -0
- package/dist/class-resolver.d.ts.map +1 -0
- package/dist/class-resolver.js +56 -0
- package/dist/class-resolver.js.map +1 -0
- package/dist/color-transition.d.ts +3 -0
- package/dist/color-transition.d.ts.map +1 -0
- package/dist/color-transition.js +31 -0
- package/dist/color-transition.js.map +1 -0
- package/dist/dom-style.d.ts +10 -0
- package/dist/dom-style.d.ts.map +1 -0
- package/dist/dom-style.js +145 -0
- package/dist/dom-style.js.map +1 -0
- package/dist/dom-style.native.d.ts +7 -0
- package/dist/dom-style.native.d.ts.map +1 -0
- package/dist/dom-style.native.js +9 -0
- package/dist/dom-style.native.js.map +1 -0
- package/dist/external-link.d.ts +6 -0
- package/dist/external-link.d.ts.map +1 -0
- package/dist/external-link.js +9 -0
- package/dist/external-link.js.map +1 -0
- package/dist/generated/animation.d.ts +2 -0
- package/dist/generated/animation.d.ts.map +1 -0
- package/dist/generated/animation.js +3 -0
- package/dist/generated/animation.js.map +1 -0
- package/dist/generated/class-resolver.d.ts +2 -0
- package/dist/generated/class-resolver.d.ts.map +1 -0
- package/dist/generated/class-resolver.js +3 -0
- package/dist/generated/class-resolver.js.map +1 -0
- package/dist/generated/dom-style.d.ts +2 -0
- package/dist/generated/dom-style.d.ts.map +1 -0
- package/dist/generated/dom-style.js +2 -0
- package/dist/generated/dom-style.js.map +1 -0
- package/dist/generated/dom-style.native.d.ts +2 -0
- package/dist/generated/dom-style.native.d.ts.map +1 -0
- package/dist/generated/dom-style.native.js +2 -0
- package/dist/generated/dom-style.native.js.map +1 -0
- package/dist/generated/environment.d.ts +2 -0
- package/dist/generated/environment.d.ts.map +1 -0
- package/dist/generated/environment.js +5 -0
- package/dist/generated/environment.js.map +1 -0
- package/dist/generated/image-source.d.ts +2 -0
- package/dist/generated/image-source.d.ts.map +1 -0
- package/dist/generated/image-source.js +3 -0
- package/dist/generated/image-source.js.map +1 -0
- package/dist/generated/interactive.d.ts +2 -0
- package/dist/generated/interactive.d.ts.map +1 -0
- package/dist/generated/interactive.js +2 -0
- package/dist/generated/interactive.js.map +1 -0
- package/dist/generated/safe-area.d.ts +2 -0
- package/dist/generated/safe-area.d.ts.map +1 -0
- package/dist/generated/safe-area.js +4 -0
- package/dist/generated/safe-area.js.map +1 -0
- package/dist/generated/scrollable.d.ts +2 -0
- package/dist/generated/scrollable.d.ts.map +1 -0
- package/dist/generated/scrollable.js +2 -0
- package/dist/generated/scrollable.js.map +1 -0
- package/dist/hooks.native.d.ts +92 -0
- package/dist/hooks.native.d.ts.map +1 -0
- package/dist/hooks.native.js +284 -0
- package/dist/hooks.native.js.map +1 -0
- package/dist/image-source.native.d.ts +5 -0
- package/dist/image-source.native.d.ts.map +1 -0
- package/dist/image-source.native.js +5 -0
- package/dist/image-source.native.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +8 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +28 -0
- package/dist/index.native.js.map +1 -0
- package/dist/interactive.d.ts +31 -0
- package/dist/interactive.d.ts.map +1 -0
- package/dist/interactive.js +64 -0
- package/dist/interactive.js.map +1 -0
- package/dist/navigation-context.d.ts +11 -0
- package/dist/navigation-context.d.ts.map +1 -0
- package/dist/navigation-context.js +12 -0
- package/dist/navigation-context.js.map +1 -0
- package/dist/navigation-entry.d.ts +3 -0
- package/dist/navigation-entry.d.ts.map +1 -0
- package/dist/navigation-entry.js +3 -0
- package/dist/navigation-entry.js.map +1 -0
- package/dist/navigation-entry.native.d.ts +2 -0
- package/dist/navigation-entry.native.d.ts.map +1 -0
- package/dist/navigation-entry.native.js +6 -0
- package/dist/navigation-entry.native.js.map +1 -0
- package/dist/navigation.d.ts +34 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/navigation.js +27 -0
- package/dist/navigation.js.map +1 -0
- package/dist/project.d.ts +10 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +10 -0
- package/dist/project.js.map +1 -0
- package/dist/project.native.d.ts +2 -0
- package/dist/project.native.d.ts.map +1 -0
- package/dist/project.native.js +2 -0
- package/dist/project.native.js.map +1 -0
- package/dist/responder.d.ts +100 -0
- package/dist/responder.d.ts.map +1 -0
- package/dist/responder.js +256 -0
- package/dist/responder.js.map +1 -0
- package/dist/safe-area.native.d.ts +18 -0
- package/dist/safe-area.native.d.ts.map +1 -0
- package/dist/safe-area.native.js +72 -0
- package/dist/safe-area.native.js.map +1 -0
- package/dist/scrollable.d.ts +16 -0
- package/dist/scrollable.d.ts.map +1 -0
- package/dist/scrollable.js +114 -0
- package/dist/scrollable.js.map +1 -0
- package/dist/text-size.d.ts +12 -0
- package/dist/text-size.d.ts.map +1 -0
- package/dist/text-size.js +22 -0
- package/dist/text-size.js.map +1 -0
- package/package.json +131 -0
- package/src/activate.ts +45 -0
- package/src/ambient.ts +199 -0
- package/src/backdrop.ts +66 -0
- package/src/class-name.native.ts +53 -0
- package/src/class-resolver.ts +74 -0
- package/src/color-transition.ts +27 -0
- package/src/dom-style.native.ts +13 -0
- package/src/dom-style.ts +173 -0
- package/src/external-link.ts +12 -0
- package/src/generated/animation.ts +2 -0
- package/src/generated/class-resolver.ts +2 -0
- package/src/generated/dom-style.native.ts +1 -0
- package/src/generated/dom-style.ts +1 -0
- package/src/generated/environment.ts +10 -0
- package/src/generated/image-source.ts +2 -0
- package/src/generated/interactive.ts +1 -0
- package/src/generated/safe-area.ts +3 -0
- package/src/generated/scrollable.ts +1 -0
- package/src/hooks.native.ts +408 -0
- package/src/image-source.native.ts +4 -0
- package/src/index.native.ts +38 -0
- package/src/index.ts +50 -0
- package/src/interactive.ts +68 -0
- package/src/navigation-context.tsx +20 -0
- package/src/navigation-entry.native.ts +5 -0
- package/src/navigation-entry.ts +12 -0
- package/src/navigation.ts +55 -0
- package/src/project.native.ts +1 -0
- package/src/project.ts +9 -0
- package/src/responder.ts +372 -0
- package/src/safe-area.native.ts +87 -0
- package/src/scrollable.ts +119 -0
- package/src/text-size.ts +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 iray-tno
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# @hozo/engine
|
|
2
|
+
|
|
3
|
+
The small amount that genuinely has to happen at runtime.
|
|
4
|
+
|
|
5
|
+
Hozo compiles away everything it can. What is left is here: styles the compiler could not resolve statically, the interaction states CSS pseudo-classes give you for free on Web and nothing gives you on Native, and the accessibility behaviour that is behaviour rather than markup.
|
|
6
|
+
|
|
7
|
+
Generated components import what they need. The exception is explicit setup for an optional
|
|
8
|
+
platform adapter, because Hozo does not add a native module to every application automatically.
|
|
9
|
+
|
|
10
|
+
## What lives here
|
|
11
|
+
|
|
12
|
+
**Dynamic class resolution.** A `className` the compiler could not read — `<View className={getVariant()} />` — is resolved on device against a project-wide map that `@hozo/metro` generates at config time. React Native has no CSS engine, so this is the one place a class name becomes a style object at runtime.
|
|
13
|
+
|
|
14
|
+
**Contextual variants.** `dark:`, `sm:`/`md:`/`lg:`, and viewport-relative sizes are media queries on Web and subscriptions on Native. `useHozoDark`, `useHozoBreakpoint` and `useHozoViewport` are separate stores on purpose: a component using only `md:` must not re-render on every resize that does not cross a breakpoint.
|
|
15
|
+
|
|
16
|
+
**Interaction state infrastructure.** The canonical `HozoPressable` in `@hozo/primitives` tracks
|
|
17
|
+
pressed, hovered, focused and focus-visible state using the shared helpers owned here. Focus-visible
|
|
18
|
+
follows the input modality, so a tap does not draw a focus ring and a Tab key does.
|
|
19
|
+
|
|
20
|
+
**Web responder negotiation.** Canonical `View`, `Pressable`, and `ScrollView`, plus the optional
|
|
21
|
+
touchables in `@hozo/rn-compat`, use one responder state machine. Pointer capture and
|
|
22
|
+
bubble negotiation map to React Native's grant, start, move, end, release, rejection, and
|
|
23
|
+
termination callbacks; one winning surface retains all active pointers until the final release.
|
|
24
|
+
`ScrollView` installs these handlers only when the author supplied a responder contract, so an
|
|
25
|
+
ordinary scroll container keeps the browser's unmediated scrolling path.
|
|
26
|
+
|
|
27
|
+
This is a lifecycle compatibility layer, not an attempt to make browser input delivery identical
|
|
28
|
+
to React Native. Pointer/touch coalescing, native dispatch timing, gesture recognition, and the
|
|
29
|
+
platform's choice of synthesized mouse events remain platform behavior. Hozo normalizes ownership
|
|
30
|
+
and callback order where an application explicitly asks for the responder API; it does not replace
|
|
31
|
+
Pointer Events or the native input system.
|
|
32
|
+
|
|
33
|
+
**Transitions.** `transition-*` utilities compile to `Animated` timings, including colour interpolation, with the blend point preserved when an interrupted transition restarts.
|
|
34
|
+
|
|
35
|
+
**Generated-code infrastructure.** Project facts, style normalization, navigation protocol,
|
|
36
|
+
responder state and optional adapter configuration live here, and what compiled output calls is
|
|
37
|
+
published leaf by leaf under `./generated/*`. React components emitted only to reproduce browser
|
|
38
|
+
layout on Native live behind `@hozo/primitives/generated/*` instead.
|
|
39
|
+
|
|
40
|
+
**Optional backdrop blur.** Static StyleX `backdropFilter: 'blur(Npx)'` on an ordinary `View`
|
|
41
|
+
uses a configured Native component. Expo users can keep `expo-blur` in the application rather
|
|
42
|
+
than making it a Hozo dependency:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { BlurView } from 'expo-blur'
|
|
46
|
+
import {
|
|
47
|
+
configureHozoBackdropFilter,
|
|
48
|
+
createExpoBlurAdapter,
|
|
49
|
+
} from '@hozo/engine'
|
|
50
|
+
|
|
51
|
+
configureHozoBackdropFilter(
|
|
52
|
+
createExpoBlurAdapter(BlurView, {
|
|
53
|
+
props: { tint: 'default' },
|
|
54
|
+
// Optional: Expo intensity and a CSS pixel radius are different scales.
|
|
55
|
+
intensityForRadius: (radius) => Math.min(100, radius * 4),
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
On Android, Expo's real background blur additionally needs a `BlurTargetView` around the content
|
|
61
|
+
and its ref passed as `blurTarget`; pass that and the selected `blurMethod` through `props`. The
|
|
62
|
+
adapter cannot infer the target across the React tree. Hozo supports one static non-negative
|
|
63
|
+
`blur(px)` (plus the no-op `none`); filter chains, conditional blur, and non-View contexts remain
|
|
64
|
+
explicit diagnostics or official StyleX residuals.
|
|
65
|
+
|
|
66
|
+
## Platform split
|
|
67
|
+
|
|
68
|
+
`index.ts` is the Web build and `index.native.ts` the React Native one, selected by the
|
|
69
|
+
`react-native` export condition. Platform-free infrastructure stays independently testable;
|
|
70
|
+
rendering boundaries and their layout solvers are owned by `@hozo/primitives`.
|
|
71
|
+
|
|
72
|
+
<!-- generated: package-footer -->
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
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).
|
|
77
|
+
|
|
78
|
+
<!-- /generated: package-footer -->
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The shape both handlers need, structural so React's event type fits. */
|
|
2
|
+
interface ActivationEvent {
|
|
3
|
+
key: string;
|
|
4
|
+
preventDefault(): void;
|
|
5
|
+
currentTarget: {
|
|
6
|
+
click(): void;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** Enter activates; Space is swallowed here so the page does not scroll. */
|
|
10
|
+
export declare function hozoActivateKeyDown(event: ActivationEvent): void;
|
|
11
|
+
/** Space activates on release, the way a real button does. */
|
|
12
|
+
export declare function hozoActivateKeyUp(event: ActivationEvent): void;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=activate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activate.d.ts","sourceRoot":"","sources":["../src/activate.ts"],"names":[],"mappings":"AAqBA,2EAA2E;AAC3E,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,cAAc,IAAI,IAAI,CAAA;IACtB,aAAa,EAAE;QAAE,KAAK,IAAI,IAAI,CAAA;KAAE,CAAA;CACjC;AAED,4EAA4E;AAC5E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAOhE;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAK9D"}
|
package/dist/activate.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Keyboard activation for elements Hozo made interactive itself.
|
|
2
|
+
//
|
|
3
|
+
// A `<button>` gets Enter and Space from the browser. A
|
|
4
|
+
// `<div role="button" tabindex="0">` gets nothing, and a control a keyboard
|
|
5
|
+
// user can reach but cannot operate fails WCAG 2.1.1. Hozo lowers
|
|
6
|
+
// `Pressable` to a `<div>` -- no HTML element carries its semantics, and
|
|
7
|
+
// `<button>` cannot hold one because its content model is phrasing content
|
|
8
|
+
// while a `View` is a `<div>` -- so this is the part that has to be script.
|
|
9
|
+
//
|
|
10
|
+
// The behaviour mirrors a native button exactly, which is more than one
|
|
11
|
+
// keydown branch: Enter activates on key *down*, Space activates on key
|
|
12
|
+
// *up* and only suppresses scrolling on the way down. Half of that is the
|
|
13
|
+
// kind of nearly-right that reads as working and is not.
|
|
14
|
+
//
|
|
15
|
+
// `currentTarget.click()` rather than calling the author's handler: it
|
|
16
|
+
// dispatches a real click, so the handler that the compiler wired to
|
|
17
|
+
// `onClick` receives a genuine MouseEvent rather than a keyboard one it
|
|
18
|
+
// was never typed for. It also means these two functions close over
|
|
19
|
+
// nothing, so they are module-level constants -- one stable reference per
|
|
20
|
+
// module, no allocation per render, and no dependency array to get wrong.
|
|
21
|
+
/** Enter activates; Space is swallowed here so the page does not scroll. */
|
|
22
|
+
export function hozoActivateKeyDown(event) {
|
|
23
|
+
if (event.key === 'Enter') {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
event.currentTarget.click();
|
|
26
|
+
}
|
|
27
|
+
else if (event.key === ' ') {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Space activates on release, the way a real button does. */
|
|
32
|
+
export function hozoActivateKeyUp(event) {
|
|
33
|
+
if (event.key === ' ') {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
event.currentTarget.click();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=activate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activate.js","sourceRoot":"","sources":["../src/activate.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,wDAAwD;AACxD,4EAA4E;AAC5E,kEAAkE;AAClE,yEAAyE;AACzE,2EAA2E;AAC3E,4EAA4E;AAC5E,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,0EAA0E;AAC1E,yDAAyD;AACzD,EAAE;AACF,uEAAuE;AACvE,qEAAqE;AACrE,wEAAwE;AACxE,oEAAoE;AACpE,0EAA0E;AAC1E,0EAA0E;AAS1E,4EAA4E;AAC5E,MAAM,UAAU,mBAAmB,CAAC,KAAsB;IACxD,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;QAC1B,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;SAAM,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;QAC7B,KAAK,CAAC,cAAc,EAAE,CAAA;IACxB,CAAC;AACH,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAAC,KAAsB;IACtD,IAAI,KAAK,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;QACtB,KAAK,CAAC,cAAc,EAAE,CAAA;QACtB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type Listener = () => void;
|
|
2
|
+
export interface Store<T> {
|
|
3
|
+
get: () => T;
|
|
4
|
+
/** Notifies subscribers only when the value actually changes. */
|
|
5
|
+
set: (next: T) => void;
|
|
6
|
+
subscribe: (listener: Listener) => () => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `equals` decides what counts as a change, and defaults to `Object.is`.
|
|
10
|
+
*
|
|
11
|
+
* It exists for the snapshots that aren't primitives: `Dimensions` reports
|
|
12
|
+
* a fresh object on every event, so identity comparison would call every
|
|
13
|
+
* event a change -- and on Android those fire on keyboard show/hide, not
|
|
14
|
+
* just rotation. It also matters for `useSyncExternalStore`, which compares
|
|
15
|
+
* snapshots by identity and re-renders whenever they differ.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createStore<T>(initial: T, equals?: (a: T, b: T) => boolean): Store<T>;
|
|
18
|
+
export declare const BREAKPOINTS: readonly [readonly ['2xl', 1536], readonly ['xl', 1280], readonly ['lg', 1024], readonly ['md', 768], readonly ['sm', 640]];
|
|
19
|
+
export type BreakpointName = (typeof BREAKPOINTS)[number][0];
|
|
20
|
+
/**
|
|
21
|
+
* The widest breakpoint `width` satisfies, or `''` below all of them.
|
|
22
|
+
*
|
|
23
|
+
* A single coarse string rather than the raw width, and that is the whole
|
|
24
|
+
* point: it makes the store's change check meaningful. Resizing within one
|
|
25
|
+
* bucket produces an identical snapshot, so nothing re-renders.
|
|
26
|
+
*/
|
|
27
|
+
export declare function bucketFor(width: number): BreakpointName | '';
|
|
28
|
+
/**
|
|
29
|
+
* The window size, as the viewport-relative utilities (`h-screen`) read it.
|
|
30
|
+
*
|
|
31
|
+
* Only the two numbers those need: `Dimensions` also reports `scale` and
|
|
32
|
+
* `fontScale`, and including them would make a text-size change look like a
|
|
33
|
+
* resize.
|
|
34
|
+
*/
|
|
35
|
+
export interface Viewport {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
}
|
|
39
|
+
/** Whether two viewports describe the same window. */
|
|
40
|
+
export declare function sameViewport(a: Viewport, b: Viewport): boolean;
|
|
41
|
+
/** Whether `bucket` is at least as wide as the `name` breakpoint. */
|
|
42
|
+
export declare function isAtLeast(bucket: BreakpointName | '', name: BreakpointName): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The environment queries React Native can answer.
|
|
45
|
+
*
|
|
46
|
+
* Tailwind's names, because that is what the author wrote and what the
|
|
47
|
+
* generated call carries. The pairs are one fact each -- `motion-safe` is
|
|
48
|
+
* `motion-reduce` negated, `landscape` is `portrait` negated -- so seven
|
|
49
|
+
* queries ride on four subscriptions.
|
|
50
|
+
*
|
|
51
|
+
* `contrast-more`, `contrast-less`, `forced-colors`, `print` and
|
|
52
|
+
* `noscript` are absent on purpose: React Native's nearest to the first
|
|
53
|
+
* two is Android's high-contrast *text* setting, which is a different
|
|
54
|
+
* thing wearing a similar name, and the last three have no meaning on a
|
|
55
|
+
* device at all. Those compile for Web and are reported on Native rather
|
|
56
|
+
* than answered wrongly.
|
|
57
|
+
*/
|
|
58
|
+
export type EnvironmentQuery = 'motion-reduce' | 'motion-safe' | 'portrait' | 'landscape' | 'ltr' | 'rtl' | 'inverted-colors' | 'reduce-transparency' | 'bold-text' | 'grayscale' | 'screen-reader' | 'contrast-more';
|
|
59
|
+
/** The fact behind a query, and whether the query is its negation. */
|
|
60
|
+
export declare const ENVIRONMENT_FACTS: Record<EnvironmentQuery, {
|
|
61
|
+
fact: 'reduceMotion' | 'portrait' | 'rtl' | 'invertColors' | 'reduceTransparency' | 'boldText' | 'grayscale' | 'screenReader' | 'contrastMore';
|
|
62
|
+
negate: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Orientation from a window size, as a coarse fact.
|
|
66
|
+
*
|
|
67
|
+
* Square counts as portrait, which is the same tie-break CSS makes: the
|
|
68
|
+
* media query is `(orientation: portrait)` for `height >= width`.
|
|
69
|
+
*
|
|
70
|
+
* Coarse on purpose, for the reason the breakpoint bucket is: a component
|
|
71
|
+
* using only `portrait:` must not re-render on every resize that does not
|
|
72
|
+
* turn the device over, and on Android those fire on keyboard show/hide.
|
|
73
|
+
*/
|
|
74
|
+
export declare function isPortrait(size: {
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}): boolean;
|
|
78
|
+
export {};
|
|
79
|
+
//# sourceMappingURL=ambient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambient.d.ts","sourceRoot":"","sources":["../src/ambient.ts"],"names":[],"mappings":"AAqBA,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAA;AAE1B,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC,CAAA;IACZ,iEAAiE;IACjE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IACtB,SAAS,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,MAAM,IAAI,CAAA;CAC9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,GAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAmB,GAAG,KAAK,CAAC,CAAC,CAAC,CAqBhG;AAID,eAAO,MAAM,WAAW,sBACrB,KAAK,EAAE,IAAI,aACX,IAAI,EAAE,IAAI,aACV,IAAI,EAAE,IAAI,aACV,IAAI,EAAE,GAAG,aACT,IAAI,EAAE,GAAG,EACF,CAAA;AAEV,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAE5D;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,EAAE,CAO5D;AAED;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,sDAAsD;AACtD,wBAAgB,YAAY,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE9D;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,EAAE,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAOpF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,gBAAgB,GACxB,eAAe,GACf,aAAa,GACb,UAAU,GACV,WAAW,GACX,KAAK,GACL,KAAK,GACL,iBAAiB,GAMjB,qBAAqB,GACrB,WAAW,GACX,WAAW,GACX,eAAe,GAKf,eAAe,CAAA;AAEnB,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,EAAE,MAAM,CACpC,gBAAgB,EAChB;IACE,IAAI,EACA,cAAc,GACd,UAAU,GACV,KAAK,GACL,cAAc,GACd,oBAAoB,GACpB,UAAU,GACV,WAAW,GACX,cAAc,GACd,cAAc,CAAA;IAClB,MAAM,EAAE,OAAO,CAAA;CAChB,CAcF,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAE3E"}
|
package/dist/ambient.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Ambient conditions: the ones whose value is the same for the whole app
|
|
2
|
+
// at any moment -- colour scheme and viewport width.
|
|
3
|
+
//
|
|
4
|
+
// These are what make `dark:` and `md:` workable on React Native without
|
|
5
|
+
// the reactive engine Hozo deliberately doesn't ship. They aren't
|
|
6
|
+
// per-element state, so a single module-level subscription serves every
|
|
7
|
+
// component; each one only needs React to re-render it when the value
|
|
8
|
+
// changes, which is what `useSyncExternalStore` is for.
|
|
9
|
+
//
|
|
10
|
+
// Why not RN's own `useColorScheme()` / `useWindowDimensions()`: those
|
|
11
|
+
// subscribe *per component*. A list of 200 rows using `md:` would open 200
|
|
12
|
+
// subscriptions and re-render all 200 on every dimension event -- and on
|
|
13
|
+
// Android those fire on keyboard show/hide, not just rotation. Here there
|
|
14
|
+
// is one subscription, and the snapshot is a coarse string, so React's
|
|
15
|
+
// `Object.is` bail-out means a resize that doesn't cross a breakpoint
|
|
16
|
+
// re-renders nothing at all.
|
|
17
|
+
//
|
|
18
|
+
// This module is deliberately free of `react` and `react-native` imports
|
|
19
|
+
// so it can be tested without either. `./hooks.native.ts` is the glue that
|
|
20
|
+
// connects it to both.
|
|
21
|
+
/**
|
|
22
|
+
* `equals` decides what counts as a change, and defaults to `Object.is`.
|
|
23
|
+
*
|
|
24
|
+
* It exists for the snapshots that aren't primitives: `Dimensions` reports
|
|
25
|
+
* a fresh object on every event, so identity comparison would call every
|
|
26
|
+
* event a change -- and on Android those fire on keyboard show/hide, not
|
|
27
|
+
* just rotation. It also matters for `useSyncExternalStore`, which compares
|
|
28
|
+
* snapshots by identity and re-renders whenever they differ.
|
|
29
|
+
*/
|
|
30
|
+
export function createStore(initial, equals = Object.is) {
|
|
31
|
+
const listeners = new Set();
|
|
32
|
+
let snapshot = initial;
|
|
33
|
+
return {
|
|
34
|
+
get: () => snapshot,
|
|
35
|
+
set(next) {
|
|
36
|
+
if (equals(next, snapshot)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
snapshot = next;
|
|
40
|
+
for (const listener of listeners) {
|
|
41
|
+
listener();
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
subscribe(listener) {
|
|
45
|
+
listeners.add(listener);
|
|
46
|
+
return () => {
|
|
47
|
+
listeners.delete(listener);
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/// Tailwind's default `min-width` breakpoints, widest first. Kept in step
|
|
53
|
+
/// with `hozo_ir::Breakpoint`, whose names the compiler emits.
|
|
54
|
+
export const BREAKPOINTS = [
|
|
55
|
+
['2xl', 1536],
|
|
56
|
+
['xl', 1280],
|
|
57
|
+
['lg', 1024],
|
|
58
|
+
['md', 768],
|
|
59
|
+
['sm', 640],
|
|
60
|
+
];
|
|
61
|
+
/**
|
|
62
|
+
* The widest breakpoint `width` satisfies, or `''` below all of them.
|
|
63
|
+
*
|
|
64
|
+
* A single coarse string rather than the raw width, and that is the whole
|
|
65
|
+
* point: it makes the store's change check meaningful. Resizing within one
|
|
66
|
+
* bucket produces an identical snapshot, so nothing re-renders.
|
|
67
|
+
*/
|
|
68
|
+
export function bucketFor(width) {
|
|
69
|
+
for (const [name, min] of BREAKPOINTS) {
|
|
70
|
+
if (width >= min) {
|
|
71
|
+
return name;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
/** Whether two viewports describe the same window. */
|
|
77
|
+
export function sameViewport(a, b) {
|
|
78
|
+
return a.width === b.width && a.height === b.height;
|
|
79
|
+
}
|
|
80
|
+
/** Whether `bucket` is at least as wide as the `name` breakpoint. */
|
|
81
|
+
export function isAtLeast(bucket, name) {
|
|
82
|
+
if (bucket === '') {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
// Ascending width is descending index in BREAKPOINTS.
|
|
86
|
+
const indexOf = (want) => BREAKPOINTS.findIndex(([n]) => n === want);
|
|
87
|
+
return indexOf(bucket) <= indexOf(name);
|
|
88
|
+
}
|
|
89
|
+
/** The fact behind a query, and whether the query is its negation. */
|
|
90
|
+
export const ENVIRONMENT_FACTS = {
|
|
91
|
+
'motion-reduce': { fact: 'reduceMotion', negate: false },
|
|
92
|
+
'motion-safe': { fact: 'reduceMotion', negate: true },
|
|
93
|
+
portrait: { fact: 'portrait', negate: false },
|
|
94
|
+
landscape: { fact: 'portrait', negate: true },
|
|
95
|
+
rtl: { fact: 'rtl', negate: false },
|
|
96
|
+
ltr: { fact: 'rtl', negate: true },
|
|
97
|
+
'inverted-colors': { fact: 'invertColors', negate: false },
|
|
98
|
+
'reduce-transparency': { fact: 'reduceTransparency', negate: false },
|
|
99
|
+
'bold-text': { fact: 'boldText', negate: false },
|
|
100
|
+
grayscale: { fact: 'grayscale', negate: false },
|
|
101
|
+
'screen-reader': { fact: 'screenReader', negate: false },
|
|
102
|
+
'contrast-more': { fact: 'contrastMore', negate: false },
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Orientation from a window size, as a coarse fact.
|
|
106
|
+
*
|
|
107
|
+
* Square counts as portrait, which is the same tie-break CSS makes: the
|
|
108
|
+
* media query is `(orientation: portrait)` for `height >= width`.
|
|
109
|
+
*
|
|
110
|
+
* Coarse on purpose, for the reason the breakpoint bucket is: a component
|
|
111
|
+
* using only `portrait:` must not re-render on every resize that does not
|
|
112
|
+
* turn the device over, and on Android those fire on keyboard show/hide.
|
|
113
|
+
*/
|
|
114
|
+
export function isPortrait(size) {
|
|
115
|
+
return size.height >= size.width;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=ambient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambient.js","sourceRoot":"","sources":["../src/ambient.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,qDAAqD;AACrD,EAAE;AACF,yEAAyE;AACzE,kEAAkE;AAClE,wEAAwE;AACxE,sEAAsE;AACtE,wDAAwD;AACxD,EAAE;AACF,uEAAuE;AACvE,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,uEAAuE;AACvE,sEAAsE;AACtE,6BAA6B;AAC7B,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,uBAAuB;AAWvB;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAI,OAAU,EAAE,MAAM,GAA4B,MAAM,CAAC,EAAE;IACpF,MAAM,SAAS,GAAG,IA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AM,EAAE,KAAK,EAAE;IACxD,eAAe,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE;CACzD,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,IAAuC;IAChE,OAAO,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ComponentType, type ReactNode } from 'react';
|
|
2
|
+
/** Props handed to a platform component that can blur content behind itself. */
|
|
3
|
+
export interface HozoBackdropFilterAdapterProps {
|
|
4
|
+
blurRadius: number;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
style?: unknown;
|
|
7
|
+
[name: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export type HozoBackdropFilterAdapter = ComponentType<HozoBackdropFilterAdapterProps>;
|
|
10
|
+
/**
|
|
11
|
+
* Installs the Native implementation used by compiled `backdropFilter` styles.
|
|
12
|
+
*
|
|
13
|
+
* Configuration is explicit because React Native has no backdrop-filter style
|
|
14
|
+
* and loading Expo unconditionally would make it a dependency of every app.
|
|
15
|
+
* Configure this once during application startup. The returned cleanup is
|
|
16
|
+
* primarily useful for isolated tests.
|
|
17
|
+
*/
|
|
18
|
+
export declare function configureHozoBackdropFilter(adapter: HozoBackdropFilterAdapter): () => void;
|
|
19
|
+
/** @internal Used by the Native wrapper emitted by the compiler. */
|
|
20
|
+
export declare function hozoBackdropFilterAdapter(): HozoBackdropFilterAdapter | undefined;
|
|
21
|
+
export interface ExpoBlurAdapterOptions<Props extends object> {
|
|
22
|
+
/** Expo intensity is not a CSS pixel radius, so applications may calibrate it. */
|
|
23
|
+
intensityForRadius?: (radius: number) => number;
|
|
24
|
+
/** Expo-version-specific props such as Android blurMethod and blurTarget. */
|
|
25
|
+
props?: Partial<Props>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Adapts Expo BlurView without making `expo-blur` a dependency of Hozo.
|
|
29
|
+
*
|
|
30
|
+
* The default maps the common 0-25px CSS range onto Expo's 0-100 intensity
|
|
31
|
+
* range. Apps that need visual calibration can replace the mapping.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExpoBlurAdapter<Props extends {
|
|
34
|
+
intensity?: number;
|
|
35
|
+
}>(BlurView: ComponentType<Props>, options?: ExpoBlurAdapterOptions<Props>): HozoBackdropFilterAdapter;
|
|
36
|
+
//# sourceMappingURL=backdrop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backdrop.d.ts","sourceRoot":"","sources":["../src/backdrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAiB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEzE,gFAAgF;AAChF,MAAM,WAAW,8BAA8B;IAC7C,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CACxB;AAED,MAAM,MAAM,yBAAyB,GAAG,aAAa,CAAC,8BAA8B,CAAC,CAAA;AAIrF;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,IAAI,CAM1F;AAED,oEAAoE;AACpE,wBAAgB,yBAAyB,IAAI,yBAAyB,GAAG,SAAS,CAEjF;AAED,MAAM,WAAW,sBAAsB,CAAC,KAAK,SAAS,MAAM;IAC1D,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;IAC/C,6EAA6E;IAC7E,KAAK,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,SAAS;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,EACxE,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,EAC9B,OAAO,GAAE,sBAAsB,CAAC,KAAK,CAAM,GAC1C,yBAAyB,CAc3B"}
|
package/dist/backdrop.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
let backdropFilterAdapter;
|
|
3
|
+
/**
|
|
4
|
+
* Installs the Native implementation used by compiled `backdropFilter` styles.
|
|
5
|
+
*
|
|
6
|
+
* Configuration is explicit because React Native has no backdrop-filter style
|
|
7
|
+
* and loading Expo unconditionally would make it a dependency of every app.
|
|
8
|
+
* Configure this once during application startup. The returned cleanup is
|
|
9
|
+
* primarily useful for isolated tests.
|
|
10
|
+
*/
|
|
11
|
+
export function configureHozoBackdropFilter(adapter) {
|
|
12
|
+
const previous = backdropFilterAdapter;
|
|
13
|
+
backdropFilterAdapter = adapter;
|
|
14
|
+
return () => {
|
|
15
|
+
if (backdropFilterAdapter === adapter)
|
|
16
|
+
backdropFilterAdapter = previous;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** @internal Used by the Native wrapper emitted by the compiler. */
|
|
20
|
+
export function hozoBackdropFilterAdapter() {
|
|
21
|
+
return backdropFilterAdapter;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Adapts Expo BlurView without making `expo-blur` a dependency of Hozo.
|
|
25
|
+
*
|
|
26
|
+
* The default maps the common 0-25px CSS range onto Expo's 0-100 intensity
|
|
27
|
+
* range. Apps that need visual calibration can replace the mapping.
|
|
28
|
+
*/
|
|
29
|
+
export function createExpoBlurAdapter(BlurView, options = {}) {
|
|
30
|
+
const intensityForRadius = options.intensityForRadius ?? ((radius) => Math.min(100, Math.max(0, radius * 4)));
|
|
31
|
+
function ExpoBlurAdapter({ blurRadius, ...props }) {
|
|
32
|
+
return createElement(BlurView, {
|
|
33
|
+
...options.props,
|
|
34
|
+
...props,
|
|
35
|
+
intensity: intensityForRadius(blurRadius),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
ExpoBlurAdapter.displayName = 'HozoExpoBlurAdapter';
|
|
39
|
+
return ExpoBlurAdapter;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=backdrop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backdrop.js","sourceRoot":"","sources":["../src/backdrop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,aAAa,EAAkB,MAAM,OAAO,CAAA;AAYzE,IAAI,qBAA4D,CAAA;AAEhE;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAAkC;IAC5E,MAAM,QAAQ,GAAG,qBAAqB,CAAA;IACtC,qBAAqB,GAAG,OAAO,CAAA;IAC/B,OAAO,GAAG,EAAE;QACV,IAAI,qBAAqB,KAAK,OAAO;YAAE,qBAAqB,GAAG,QAAQ,CAAA;IACzE,CAAC,CAAA;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,yBAAyB;IACvC,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAA8B,EAC9B,OAAO,GAAkC,EAAE;IAE3C,MAAM,kBAAkB,GACtB,OAAO,CAAC,kBAAkB,IAAI,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAE5F,SAAS,eAAe,CAAC,EAAE,UAAU,EAAE,GAAG,KAAK,EAAkC;QAC/E,OAAO,aAAa,CAAC,QAAQ,EAAE;YAC7B,GAAG,OAAO,CAAC,KAAK;YAChB,GAAG,KAAK;YACR,SAAS,EAAE,kBAAkB,CAAC,UAAU,CAAC;SACjC,CAAC,CAAA;IACb,CAAC;IAED,eAAe,CAAC,WAAW,GAAG,qBAAqB,CAAA;IACnD,OAAO,eAAe,CAAA;AACxB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare module 'react-native' {
|
|
2
|
+
interface ViewProps {
|
|
3
|
+
/** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
|
|
4
|
+
className?: string;
|
|
5
|
+
}
|
|
6
|
+
interface TextProps {
|
|
7
|
+
/** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
interface ImagePropsBase {
|
|
11
|
+
/** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
interface FlatListProps<ItemT> {
|
|
15
|
+
/** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=class-name.native.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-name.native.d.ts","sourceRoot":"","sources":["../src/class-name.native.ts"],"names":[],"mappings":"AAiCA,OAAO,QAAQ,cAAc,CAAC;IAC5B,UAAU,SAAS;QACjB,oEAAoE;QACpE,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB;IACD,UAAU,SAAS;QACjB,oEAAoE;QACpE,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB;IACD,UAAU,cAAc;QACtB,oEAAoE;QACpE,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB;IACD,UAAU,aAAa,CAAC,KAAK;QAC3B,oEAAoE;QACpE,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB;CACF;AAED,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// `className` on React Native's own primitives, for TypeScript.
|
|
2
|
+
//
|
|
3
|
+
// Hozo's authoring surface is a class list. The compiler reads
|
|
4
|
+
// `className` off the tag and replaces it with a `StyleSheet` entry, so
|
|
5
|
+
// the prop exists at *compile* time and never reaches a component -- which
|
|
6
|
+
// is why no runtime declares it.
|
|
7
|
+
//
|
|
8
|
+
// TypeScript still has to accept it, because TypeScript sees the source
|
|
9
|
+
// and not the output. On the Web side it always did: `@hozo/core`'s
|
|
10
|
+
// browser components declare `className?: string` themselves. On this side
|
|
11
|
+
// nothing did, and nothing noticed, because the `react-native` export
|
|
12
|
+
// condition carried no `types` -- so `tsc` in a React Native app resolved
|
|
13
|
+
// the *Web* declarations and asked them instead. Fixing that resolution is
|
|
14
|
+
// what made the omission visible: `examples/native-demo` went from clean
|
|
15
|
+
// to 54 errors, every one of them `className`.
|
|
16
|
+
//
|
|
17
|
+
// React Native's own components are here rather than only Hozo's because
|
|
18
|
+
// `DEFAULT_PRIMITIVE_SOURCES` includes `react-native`:
|
|
19
|
+
//
|
|
20
|
+
// import { View, Text } from 'react-native'
|
|
21
|
+
// <View className="p-4" />
|
|
22
|
+
//
|
|
23
|
+
// compiles exactly as the `@hozo/core` spelling does -- that is proposal
|
|
24
|
+
// §2.1, an existing React Native file compiling as written. A type error
|
|
25
|
+
// on the pattern the proposal is built around would be the wrong answer.
|
|
26
|
+
//
|
|
27
|
+
// Only the interfaces that do not already inherit one: `ScrollViewProps`,
|
|
28
|
+
// `TextInputProps` and `ActivityIndicatorProps` extend `ViewProps`, and
|
|
29
|
+
// `PressableProps` extends an `Omit` of it, so all four follow from the
|
|
30
|
+
// first. React Native declares the Touchable props as type aliases, which
|
|
31
|
+
// cannot be augmented; Hozo's wrappers add the authoring prop themselves.
|
|
32
|
+
// `SectionList` is not a Hozo primitive and is not here.
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=class-name.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-name.native.js","sourceRoot":"","sources":["../src/class-name.native.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,+DAA+D;AAC/D,wEAAwE;AACxE,2EAA2E;AAC3E,iCAAiC;AACjC,EAAE;AACF,wEAAwE;AACxE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AACzE,+CAA+C;AAC/C,EAAE;AACF,yEAAyE;AACzE,uDAAuD;AACvD,EAAE;AACF,gDAAgD;AAChD,+BAA+B;AAC/B,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,wEAAwE;AACxE,0EAA0E;AAC1E,0EAA0E;AAC1E,yDAAyD;AAqBzD,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A React Native style object, as the compiler emits it. */
|
|
2
|
+
export type StyleObject = Record<string, unknown>;
|
|
3
|
+
/**
|
|
4
|
+
* Resolves whitespace-separated class names to React Native style objects.
|
|
5
|
+
*
|
|
6
|
+
* Returns an array, which is a valid `style` value on its own and also
|
|
7
|
+
* nests inside one -- RN flattens arbitrarily nested style arrays, so
|
|
8
|
+
* callers never have to spread it.
|
|
9
|
+
*/
|
|
10
|
+
export type ClassResolver = (value: unknown) => StyleObject[];
|
|
11
|
+
/**
|
|
12
|
+
* Builds a resolver over one project's candidate map.
|
|
13
|
+
*
|
|
14
|
+
* Called by the generated candidate module rather than by application
|
|
15
|
+
* code: `styles` and `unsupported` are build output, and binding them here
|
|
16
|
+
* keeps the generated file to data plus one call.
|
|
17
|
+
*
|
|
18
|
+
* `unsupported` maps a class the compiler *recognized but can't express*
|
|
19
|
+
* as a plain style object -- a conditional utility (`hover:`, `md:`), or
|
|
20
|
+
* one that's Web-only -- to the reason. Those are reported when they're
|
|
21
|
+
* actually used rather than at build time, because a class appearing in
|
|
22
|
+
* the project's candidate scan doesn't mean any dynamic expression ever
|
|
23
|
+
* produces it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createClassResolver(styles: Record<string, StyleObject>, unsupported?: Record<string, string>): ClassResolver;
|
|
26
|
+
//# sourceMappingURL=class-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-resolver.d.ts","sourceRoot":"","sources":["../src/class-resolver.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,WAAW,EAAE,CAAA;AAE7D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,WAAW,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACvC,aAAa,CA4Cf"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a resolver over one project's candidate map.
|
|
3
|
+
*
|
|
4
|
+
* Called by the generated candidate module rather than by application
|
|
5
|
+
* code: `styles` and `unsupported` are build output, and binding them here
|
|
6
|
+
* keeps the generated file to data plus one call.
|
|
7
|
+
*
|
|
8
|
+
* `unsupported` maps a class the compiler *recognized but can't express*
|
|
9
|
+
* as a plain style object -- a conditional utility (`hover:`, `md:`), or
|
|
10
|
+
* one that's Web-only -- to the reason. Those are reported when they're
|
|
11
|
+
* actually used rather than at build time, because a class appearing in
|
|
12
|
+
* the project's candidate scan doesn't mean any dynamic expression ever
|
|
13
|
+
* produces it.
|
|
14
|
+
*/
|
|
15
|
+
export function createClassResolver(styles, unsupported = {}) {
|
|
16
|
+
// Class strings repeat constantly across renders and list items, and the
|
|
17
|
+
// result is immutable, so each distinct string is resolved once.
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
// Warn once per class, not once per render -- a warning inside a list's
|
|
20
|
+
// render path would otherwise repeat for every row, every frame.
|
|
21
|
+
const warned = new Set();
|
|
22
|
+
return function hozoClasses(value) {
|
|
23
|
+
// Falsy is the normal case, not an error: `cond && 'p-4'` yields
|
|
24
|
+
// `false` whenever the condition is off.
|
|
25
|
+
if (typeof value !== 'string' || value === '') {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const cached = cache.get(value);
|
|
29
|
+
if (cached) {
|
|
30
|
+
return cached;
|
|
31
|
+
}
|
|
32
|
+
const resolved = [];
|
|
33
|
+
for (const name of value.split(/\s+/)) {
|
|
34
|
+
if (name === '') {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const style = styles[name];
|
|
38
|
+
if (style) {
|
|
39
|
+
resolved.push(style);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// An unknown class isn't necessarily a Hozo problem -- it may be an
|
|
43
|
+
// app's own non-Tailwind class, or a testID-ish marker -- so only the
|
|
44
|
+
// ones the compiler recognized and refused are reported.
|
|
45
|
+
const reason = unsupported[name];
|
|
46
|
+
if (reason && !warned.has(name)) {
|
|
47
|
+
warned.add(name);
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.warn(`[hozo] ${reason}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
cache.set(value, resolved);
|
|
53
|
+
return resolved;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=class-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"class-resolver.js","sourceRoot":"","sources":["../src/class-resolver.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAmC,EACnC,WAAW,GAA2B,EAAE;IAExC,yEAAyE;IACzE,iEAAiE;IACjE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC9C,wEAAwE;IACxE,iEAAiE;IACjE,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAA;IAEhC,OAAO,SAAS,WAAW,CAAC,KAAc;QACxC,iEAAiE;QACjE,yCAAyC;QACzC,IAAI,OAAO,KAA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