@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.
Files changed (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -0
  3. package/dist/activate.d.ts +14 -0
  4. package/dist/activate.d.ts.map +1 -0
  5. package/dist/activate.js +38 -0
  6. package/dist/activate.js.map +1 -0
  7. package/dist/ambient.d.ts +79 -0
  8. package/dist/ambient.d.ts.map +1 -0
  9. package/dist/ambient.js +117 -0
  10. package/dist/ambient.js.map +1 -0
  11. package/dist/backdrop.d.ts +36 -0
  12. package/dist/backdrop.d.ts.map +1 -0
  13. package/dist/backdrop.js +41 -0
  14. package/dist/backdrop.js.map +1 -0
  15. package/dist/class-name.native.d.ts +20 -0
  16. package/dist/class-name.native.d.ts.map +1 -0
  17. package/dist/class-name.native.js +34 -0
  18. package/dist/class-name.native.js.map +1 -0
  19. package/dist/class-resolver.d.ts +26 -0
  20. package/dist/class-resolver.d.ts.map +1 -0
  21. package/dist/class-resolver.js +56 -0
  22. package/dist/class-resolver.js.map +1 -0
  23. package/dist/color-transition.d.ts +3 -0
  24. package/dist/color-transition.d.ts.map +1 -0
  25. package/dist/color-transition.js +31 -0
  26. package/dist/color-transition.js.map +1 -0
  27. package/dist/dom-style.d.ts +10 -0
  28. package/dist/dom-style.d.ts.map +1 -0
  29. package/dist/dom-style.js +145 -0
  30. package/dist/dom-style.js.map +1 -0
  31. package/dist/dom-style.native.d.ts +7 -0
  32. package/dist/dom-style.native.d.ts.map +1 -0
  33. package/dist/dom-style.native.js +9 -0
  34. package/dist/dom-style.native.js.map +1 -0
  35. package/dist/external-link.d.ts +6 -0
  36. package/dist/external-link.d.ts.map +1 -0
  37. package/dist/external-link.js +9 -0
  38. package/dist/external-link.js.map +1 -0
  39. package/dist/generated/animation.d.ts +2 -0
  40. package/dist/generated/animation.d.ts.map +1 -0
  41. package/dist/generated/animation.js +3 -0
  42. package/dist/generated/animation.js.map +1 -0
  43. package/dist/generated/class-resolver.d.ts +2 -0
  44. package/dist/generated/class-resolver.d.ts.map +1 -0
  45. package/dist/generated/class-resolver.js +3 -0
  46. package/dist/generated/class-resolver.js.map +1 -0
  47. package/dist/generated/dom-style.d.ts +2 -0
  48. package/dist/generated/dom-style.d.ts.map +1 -0
  49. package/dist/generated/dom-style.js +2 -0
  50. package/dist/generated/dom-style.js.map +1 -0
  51. package/dist/generated/dom-style.native.d.ts +2 -0
  52. package/dist/generated/dom-style.native.d.ts.map +1 -0
  53. package/dist/generated/dom-style.native.js +2 -0
  54. package/dist/generated/dom-style.native.js.map +1 -0
  55. package/dist/generated/environment.d.ts +2 -0
  56. package/dist/generated/environment.d.ts.map +1 -0
  57. package/dist/generated/environment.js +5 -0
  58. package/dist/generated/environment.js.map +1 -0
  59. package/dist/generated/image-source.d.ts +2 -0
  60. package/dist/generated/image-source.d.ts.map +1 -0
  61. package/dist/generated/image-source.js +3 -0
  62. package/dist/generated/image-source.js.map +1 -0
  63. package/dist/generated/interactive.d.ts +2 -0
  64. package/dist/generated/interactive.d.ts.map +1 -0
  65. package/dist/generated/interactive.js +2 -0
  66. package/dist/generated/interactive.js.map +1 -0
  67. package/dist/generated/safe-area.d.ts +2 -0
  68. package/dist/generated/safe-area.d.ts.map +1 -0
  69. package/dist/generated/safe-area.js +4 -0
  70. package/dist/generated/safe-area.js.map +1 -0
  71. package/dist/generated/scrollable.d.ts +2 -0
  72. package/dist/generated/scrollable.d.ts.map +1 -0
  73. package/dist/generated/scrollable.js +2 -0
  74. package/dist/generated/scrollable.js.map +1 -0
  75. package/dist/hooks.native.d.ts +92 -0
  76. package/dist/hooks.native.d.ts.map +1 -0
  77. package/dist/hooks.native.js +284 -0
  78. package/dist/hooks.native.js.map +1 -0
  79. package/dist/image-source.native.d.ts +5 -0
  80. package/dist/image-source.native.d.ts.map +1 -0
  81. package/dist/image-source.native.js +5 -0
  82. package/dist/image-source.native.js.map +1 -0
  83. package/dist/index.d.ts +11 -0
  84. package/dist/index.d.ts.map +1 -0
  85. package/dist/index.js +30 -0
  86. package/dist/index.js.map +1 -0
  87. package/dist/index.native.d.ts +8 -0
  88. package/dist/index.native.d.ts.map +1 -0
  89. package/dist/index.native.js +28 -0
  90. package/dist/index.native.js.map +1 -0
  91. package/dist/interactive.d.ts +31 -0
  92. package/dist/interactive.d.ts.map +1 -0
  93. package/dist/interactive.js +64 -0
  94. package/dist/interactive.js.map +1 -0
  95. package/dist/navigation-context.d.ts +11 -0
  96. package/dist/navigation-context.d.ts.map +1 -0
  97. package/dist/navigation-context.js +12 -0
  98. package/dist/navigation-context.js.map +1 -0
  99. package/dist/navigation-entry.d.ts +3 -0
  100. package/dist/navigation-entry.d.ts.map +1 -0
  101. package/dist/navigation-entry.js +3 -0
  102. package/dist/navigation-entry.js.map +1 -0
  103. package/dist/navigation-entry.native.d.ts +2 -0
  104. package/dist/navigation-entry.native.d.ts.map +1 -0
  105. package/dist/navigation-entry.native.js +6 -0
  106. package/dist/navigation-entry.native.js.map +1 -0
  107. package/dist/navigation.d.ts +34 -0
  108. package/dist/navigation.d.ts.map +1 -0
  109. package/dist/navigation.js +27 -0
  110. package/dist/navigation.js.map +1 -0
  111. package/dist/project.d.ts +10 -0
  112. package/dist/project.d.ts.map +1 -0
  113. package/dist/project.js +10 -0
  114. package/dist/project.js.map +1 -0
  115. package/dist/project.native.d.ts +2 -0
  116. package/dist/project.native.d.ts.map +1 -0
  117. package/dist/project.native.js +2 -0
  118. package/dist/project.native.js.map +1 -0
  119. package/dist/responder.d.ts +100 -0
  120. package/dist/responder.d.ts.map +1 -0
  121. package/dist/responder.js +256 -0
  122. package/dist/responder.js.map +1 -0
  123. package/dist/safe-area.native.d.ts +18 -0
  124. package/dist/safe-area.native.d.ts.map +1 -0
  125. package/dist/safe-area.native.js +72 -0
  126. package/dist/safe-area.native.js.map +1 -0
  127. package/dist/scrollable.d.ts +16 -0
  128. package/dist/scrollable.d.ts.map +1 -0
  129. package/dist/scrollable.js +114 -0
  130. package/dist/scrollable.js.map +1 -0
  131. package/dist/text-size.d.ts +12 -0
  132. package/dist/text-size.d.ts.map +1 -0
  133. package/dist/text-size.js +22 -0
  134. package/dist/text-size.js.map +1 -0
  135. package/package.json +131 -0
  136. package/src/activate.ts +45 -0
  137. package/src/ambient.ts +199 -0
  138. package/src/backdrop.ts +66 -0
  139. package/src/class-name.native.ts +53 -0
  140. package/src/class-resolver.ts +74 -0
  141. package/src/color-transition.ts +27 -0
  142. package/src/dom-style.native.ts +13 -0
  143. package/src/dom-style.ts +173 -0
  144. package/src/external-link.ts +12 -0
  145. package/src/generated/animation.ts +2 -0
  146. package/src/generated/class-resolver.ts +2 -0
  147. package/src/generated/dom-style.native.ts +1 -0
  148. package/src/generated/dom-style.ts +1 -0
  149. package/src/generated/environment.ts +10 -0
  150. package/src/generated/image-source.ts +2 -0
  151. package/src/generated/interactive.ts +1 -0
  152. package/src/generated/safe-area.ts +3 -0
  153. package/src/generated/scrollable.ts +1 -0
  154. package/src/hooks.native.ts +408 -0
  155. package/src/image-source.native.ts +4 -0
  156. package/src/index.native.ts +38 -0
  157. package/src/index.ts +50 -0
  158. package/src/interactive.ts +68 -0
  159. package/src/navigation-context.tsx +20 -0
  160. package/src/navigation-entry.native.ts +5 -0
  161. package/src/navigation-entry.ts +12 -0
  162. package/src/navigation.ts +55 -0
  163. package/src/project.native.ts +1 -0
  164. package/src/project.ts +9 -0
  165. package/src/responder.ts +372 -0
  166. package/src/safe-area.native.ts +87 -0
  167. package/src/scrollable.ts +119 -0
  168. package/src/text-size.ts +25 -0
@@ -0,0 +1,114 @@
1
+ // Keyboard access for a scroll container, decided where the answer exists.
2
+ //
3
+ // A `div` with `overflow: auto` scrolls under a pointer and is unreachable
4
+ // from a keyboard unless it is focusable itself or holds something that
5
+ // is. React Native's `ScrollView` is scrolled by touch and the platform
6
+ // handles reaching it, so the gap opens on Web only -- see #99.
7
+ //
8
+ // Not decided at compile time, because none of it is a compile-time fact.
9
+ // axe's rule, which is the one browsers and auditors agree on, is:
10
+ //
11
+ // matches scrollWidth > clientWidth + 13
12
+ // or scrollHeight > clientHeight + 13
13
+ // on an axis that actually scrolls
14
+ // any focusable-content OR focusable-element
15
+ //
16
+ // Overflow depends on CSS, content and viewport; whether a subtree holds
17
+ // anything focusable depends on what a runtime expression rendered. A
18
+ // compiler emitting `tabIndex={0}` for every `ScrollView` would add a tab
19
+ // stop to every list that happens to fit, and one emitting a diagnostic
20
+ // would warn about containers that will never overflow. Both teach people
21
+ // to ignore them.
22
+ //
23
+ // So this mirrors the same three conditions at the moment they are true,
24
+ // and re-checks when any of them can have changed.
25
+ /**
26
+ * The attribute marking a tab stop this file added.
27
+ *
28
+ * Load-bearing in two places: nothing removes a stop it did not add, and
29
+ * nothing reads its own stop as proof that one was already there.
30
+ */
31
+ const MARK = 'data-hozo-scroll-stop';
32
+ /** What a browser gives focus to without being asked. */
33
+ const FOCUSABLE = 'a[href], button, input, select, textarea, summary, iframe, audio[controls],' +
34
+ ' video[controls], [contenteditable], [tabindex]';
35
+ /**
36
+ * Whether the element scrolls *and* has nothing focusable to reach.
37
+ *
38
+ * The 13-pixel allowance is axe's, not a guess: a container can exceed its
39
+ * content box by a rounding error or a scrollbar's own width without being
40
+ * scrollable in any useful sense.
41
+ */
42
+ function needsTabStop(element) {
43
+ const style = getComputedStyle(element);
44
+ const scrollsX = element.scrollWidth > element.clientWidth + 13 &&
45
+ (style.overflowX === 'auto' || style.overflowX === 'scroll');
46
+ const scrollsY = element.scrollHeight > element.clientHeight + 13 &&
47
+ (style.overflowY === 'auto' || style.overflowY === 'scroll');
48
+ if (!scrollsX && !scrollsY)
49
+ return false;
50
+ // `focusable-element`, but only when the stop is somebody else's. A
51
+ // tab stop this function added is not evidence that one was already
52
+ // needed, and reading it as such made the answer oscillate: the first
53
+ // call added the attribute, the observer's initial callback saw it and
54
+ // took it straight back off. Two calls, decisions `true` then `false`,
55
+ // and nothing left on the element.
56
+ if (element.hasAttribute('tabindex') && !element.hasAttribute(MARK))
57
+ return false;
58
+ return element.querySelector(FOCUSABLE) === null;
59
+ }
60
+ /**
61
+ * Props for a compiled `ScrollView`, from `{...hozoScrollable()}`.
62
+ *
63
+ * A ref callback rather than state: this sets one attribute on one element
64
+ * and has no business re-rendering the tree to do it. The observers are
65
+ * torn down when React hands back `null`.
66
+ *
67
+ * Not emitted at all when the author wrote their own `tabIndex` -- that
68
+ * precedence is settled by the compiler, which can see the attribute, so
69
+ * there is no branch here to get wrong. An author saying `tabIndex={-1}`
70
+ * means it, and nothing in this file will argue.
71
+ */
72
+ export function hozoScrollable() {
73
+ let observer;
74
+ let mutations;
75
+ const apply = (element) => {
76
+ // `data-hozo-scroll-stop` rather than a bare `tabindex`, so a later
77
+ // read can tell a stop this added from one an author wrote. Without it
78
+ // the removal path could not tell them apart and would take away
79
+ // somebody else's.
80
+ if (needsTabStop(element)) {
81
+ element.setAttribute('tabindex', '0');
82
+ element.setAttribute(MARK, '');
83
+ }
84
+ else if (element.hasAttribute(MARK)) {
85
+ element.removeAttribute('tabindex');
86
+ element.removeAttribute(MARK);
87
+ }
88
+ };
89
+ return {
90
+ ref: (element) => {
91
+ observer?.disconnect();
92
+ mutations?.disconnect();
93
+ observer = undefined;
94
+ mutations = undefined;
95
+ if (!element)
96
+ return;
97
+ apply(element);
98
+ // Resize covers the viewport changing and the content growing;
99
+ // mutation covers a child arriving that is focusable, which changes
100
+ // the answer without changing any size.
101
+ if (typeof ResizeObserver !== 'undefined') {
102
+ observer = new ResizeObserver(() => apply(element));
103
+ observer.observe(element);
104
+ for (const child of element.children)
105
+ observer.observe(child);
106
+ }
107
+ if (typeof MutationObserver !== 'undefined') {
108
+ mutations = new MutationObserver(() => apply(element));
109
+ mutations.observe(element, { childList: true, subtree: true });
110
+ }
111
+ },
112
+ };
113
+ }
114
+ //# sourceMappingURL=scrollable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollable.js","sourceRoot":"","sources":["../src/scrollable.ts"],"names":[],"mappings":"A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AAO,gBAAgB,KAAK,WAAW,EAAE,CAAC;gBAC5C,SAAS,GAAG,IAAI,gBAAgB,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAA;gBACtD,SAAS,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;YAChE,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * React Native's own default, from `RCTFont.mm`:
3
+ * `const CGFloat defaultFontSize = 14`.
4
+ *
5
+ * The base when nothing above has named one, which is what React Native
6
+ * itself would have drawn at.
7
+ */
8
+ export declare const HOZO_DEFAULT_FONT_SIZE = 14;
9
+ export declare const HozoTextSizeContext: import("react").Context<number>;
10
+ /** The size in force here, for a component sizing itself against it. */
11
+ export declare function useHozoTextSize(): number;
12
+ //# sourceMappingURL=text-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-size.d.ts","sourceRoot":"","sources":["../src/text-size.ts"],"names":[],"mappings":"AAUA;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,eAAO,MAAM,mBAAmB,iCAAwC,CAAA;AAExE,wEAAwE;AACxE,wBAAgB,eAAe,WAE9B"}
@@ -0,0 +1,22 @@
1
+ // The base a relative text size scales against.
2
+ //
3
+ // Here rather than beside the components that use it because a React
4
+ // context is not a platform concept, and because `@hozo/typography`
5
+ // reads it: a package resolves this one's types through the Web entry
6
+ // whichever platform it is building for, so a native-only export is one
7
+ // its type checker cannot see.
8
+ import { createContext, useContext } from 'react';
9
+ /**
10
+ * React Native's own default, from `RCTFont.mm`:
11
+ * `const CGFloat defaultFontSize = 14`.
12
+ *
13
+ * The base when nothing above has named one, which is what React Native
14
+ * itself would have drawn at.
15
+ */
16
+ export const HOZO_DEFAULT_FONT_SIZE = 14;
17
+ export const HozoTextSizeContext = createContext(HOZO_DEFAULT_FONT_SIZE);
18
+ /** The size in force here, for a component sizing itself against it. */
19
+ export function useHozoTextSize() {
20
+ return useContext(HozoTextSizeContext);
21
+ }
22
+ //# sourceMappingURL=text-size.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-size.js","sourceRoot":"","sources":["../src/text-size.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,qEAAqE;AACrE,oEAAoE;AACpE,sEAAsE;AACtE,wEAAwE;AACxE,+BAA+B;AAE/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAA;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,aAAa,CAAC,sBAAsB,CAAC,CAAA;AAExE,wEAAwE;AACxE,MAAM,UAAU,eAAe;IAC7B,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAA;AACxC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,131 @@
1
+ {
2
+ "name": "@hozo/engine",
3
+ "version": "0.1.0",
4
+ "description": "Runtime fallback for genuinely dynamic styles, interactive behavior, and accessibility behavior.",
5
+ "keywords": [
6
+ "react-native",
7
+ "runtime",
8
+ "styles",
9
+ "animation"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/iray-tno/hozo.git",
15
+ "directory": "packages/engine"
16
+ },
17
+ "homepage": "https://iray-tno.github.io/hozo/",
18
+ "bugs": {
19
+ "url": "https://github.com/iray-tno/hozo/issues"
20
+ },
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "sideEffects": [
25
+ "./dist/hooks.native.js"
26
+ ],
27
+ "exports": {
28
+ ".": {
29
+ "react-native": {
30
+ "types": "./dist/index.native.d.ts",
31
+ "default": "./dist/index.native.js"
32
+ },
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./navigation": {
37
+ "react-native": {
38
+ "types": "./dist/navigation-entry.native.d.ts",
39
+ "default": "./dist/navigation-entry.native.js"
40
+ },
41
+ "types": "./dist/navigation-entry.d.ts",
42
+ "default": "./dist/navigation-entry.js"
43
+ },
44
+ "./project": {
45
+ "react-native": {
46
+ "types": "./dist/project.native.d.ts",
47
+ "default": "./dist/project.native.js"
48
+ },
49
+ "types": "./dist/project.d.ts",
50
+ "default": "./dist/project.js"
51
+ },
52
+ "./generated/animation": {
53
+ "types": "./dist/generated/animation.d.ts",
54
+ "default": "./dist/generated/animation.js"
55
+ },
56
+ "./generated/class-resolver": {
57
+ "types": "./dist/generated/class-resolver.d.ts",
58
+ "default": "./dist/generated/class-resolver.js"
59
+ },
60
+ "./generated/dom-style": {
61
+ "react-native": {
62
+ "types": "./dist/generated/dom-style.native.d.ts",
63
+ "default": "./dist/generated/dom-style.native.js"
64
+ },
65
+ "types": "./dist/generated/dom-style.d.ts",
66
+ "default": "./dist/generated/dom-style.js"
67
+ },
68
+ "./generated/environment": {
69
+ "types": "./dist/generated/environment.d.ts",
70
+ "default": "./dist/generated/environment.js"
71
+ },
72
+ "./generated/image-source": {
73
+ "types": "./dist/generated/image-source.d.ts",
74
+ "default": "./dist/generated/image-source.js"
75
+ },
76
+ "./generated/interactive": {
77
+ "types": "./dist/generated/interactive.d.ts",
78
+ "default": "./dist/generated/interactive.js"
79
+ },
80
+ "./generated/safe-area": {
81
+ "types": "./dist/generated/safe-area.d.ts",
82
+ "default": "./dist/generated/safe-area.js"
83
+ },
84
+ "./generated/scrollable": {
85
+ "types": "./dist/generated/scrollable.d.ts",
86
+ "default": "./dist/generated/scrollable.js"
87
+ },
88
+ "./package.json": "./package.json"
89
+ },
90
+ "files": [
91
+ "dist",
92
+ "src",
93
+ "!src/**/*.test.ts",
94
+ "!src/**/*.test.tsx",
95
+ "!src/**/*.bench.ts"
96
+ ],
97
+ "publishConfig": {
98
+ "access": "public",
99
+ "provenance": true
100
+ },
101
+ "dependencies": {},
102
+ "peerDependencies": {
103
+ "react": "^19.0.0",
104
+ "react-native": ">=0.86",
105
+ "react-native-safe-area-context": ">=4"
106
+ },
107
+ "peerDependenciesMeta": {
108
+ "react-native": {
109
+ "optional": true
110
+ },
111
+ "react-native-safe-area-context": {
112
+ "optional": true
113
+ }
114
+ },
115
+ "devDependencies": {
116
+ "@types/react": "^19.2.18",
117
+ "@types/react-dom": "^19.2.4",
118
+ "axe-core": "4.13.0",
119
+ "esbuild": "0.28.2",
120
+ "react": "^19.2.8",
121
+ "react-dom": "^19.2.8",
122
+ "react-native": "^0.87.1",
123
+ "react-test-renderer": "^19.2.8"
124
+ },
125
+ "scripts": {
126
+ "build": "node ../../scripts/clean-package-dist.mjs && tsc -p .",
127
+ "typecheck": "tsc -p . --noEmit",
128
+ "test": "node --test src/*.test.ts",
129
+ "test:performance": "node --test src/*.bench.ts"
130
+ }
131
+ }
@@ -0,0 +1,45 @@
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
+
22
+ /** The shape both handlers need, structural so React's event type fits. */
23
+ interface ActivationEvent {
24
+ key: string
25
+ preventDefault(): void
26
+ currentTarget: { click(): void }
27
+ }
28
+
29
+ /** Enter activates; Space is swallowed here so the page does not scroll. */
30
+ export function hozoActivateKeyDown(event: ActivationEvent): void {
31
+ if (event.key === 'Enter') {
32
+ event.preventDefault()
33
+ event.currentTarget.click()
34
+ } else if (event.key === ' ') {
35
+ event.preventDefault()
36
+ }
37
+ }
38
+
39
+ /** Space activates on release, the way a real button does. */
40
+ export function hozoActivateKeyUp(event: ActivationEvent): void {
41
+ if (event.key === ' ') {
42
+ event.preventDefault()
43
+ event.currentTarget.click()
44
+ }
45
+ }
package/src/ambient.ts ADDED
@@ -0,0 +1,199 @@
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
+ type Listener = () => void
23
+
24
+ export interface Store<T> {
25
+ get: () => T
26
+ /** Notifies subscribers only when the value actually changes. */
27
+ set: (next: T) => void
28
+ subscribe: (listener: Listener) => () => void
29
+ }
30
+
31
+ /**
32
+ * `equals` decides what counts as a change, and defaults to `Object.is`.
33
+ *
34
+ * It exists for the snapshots that aren't primitives: `Dimensions` reports
35
+ * a fresh object on every event, so identity comparison would call every
36
+ * event a change -- and on Android those fire on keyboard show/hide, not
37
+ * just rotation. It also matters for `useSyncExternalStore`, which compares
38
+ * snapshots by identity and re-renders whenever they differ.
39
+ */
40
+ export function createStore<T>(initial: T, equals: (a: T, b: T) => boolean = Object.is): Store<T> {
41
+ const listeners = new Set<Listener>()
42
+ let snapshot = initial
43
+ return {
44
+ get: () => snapshot,
45
+ set(next: T) {
46
+ if (equals(next, snapshot)) {
47
+ return
48
+ }
49
+ snapshot = next
50
+ for (const listener of listeners) {
51
+ listener()
52
+ }
53
+ },
54
+ subscribe(listener: Listener) {
55
+ listeners.add(listener)
56
+ return () => {
57
+ listeners.delete(listener)
58
+ }
59
+ },
60
+ }
61
+ }
62
+
63
+ /// Tailwind's default `min-width` breakpoints, widest first. Kept in step
64
+ /// with `hozo_ir::Breakpoint`, whose names the compiler emits.
65
+ export const BREAKPOINTS = [
66
+ ['2xl', 1536],
67
+ ['xl', 1280],
68
+ ['lg', 1024],
69
+ ['md', 768],
70
+ ['sm', 640],
71
+ ] as const
72
+
73
+ export type BreakpointName = (typeof BREAKPOINTS)[number][0]
74
+
75
+ /**
76
+ * The widest breakpoint `width` satisfies, or `''` below all of them.
77
+ *
78
+ * A single coarse string rather than the raw width, and that is the whole
79
+ * point: it makes the store's change check meaningful. Resizing within one
80
+ * bucket produces an identical snapshot, so nothing re-renders.
81
+ */
82
+ export function bucketFor(width: number): BreakpointName | '' {
83
+ for (const [name, min] of BREAKPOINTS) {
84
+ if (width >= min) {
85
+ return name
86
+ }
87
+ }
88
+ return ''
89
+ }
90
+
91
+ /**
92
+ * The window size, as the viewport-relative utilities (`h-screen`) read it.
93
+ *
94
+ * Only the two numbers those need: `Dimensions` also reports `scale` and
95
+ * `fontScale`, and including them would make a text-size change look like a
96
+ * resize.
97
+ */
98
+ export interface Viewport {
99
+ width: number
100
+ height: number
101
+ }
102
+
103
+ /** Whether two viewports describe the same window. */
104
+ export function sameViewport(a: Viewport, b: Viewport): boolean {
105
+ return a.width === b.width && a.height === b.height
106
+ }
107
+
108
+ /** Whether `bucket` is at least as wide as the `name` breakpoint. */
109
+ export function isAtLeast(bucket: BreakpointName | '', name: BreakpointName): boolean {
110
+ if (bucket === '') {
111
+ return false
112
+ }
113
+ // Ascending width is descending index in BREAKPOINTS.
114
+ const indexOf = (want: string) => BREAKPOINTS.findIndex(([n]) => n === want)
115
+ return indexOf(bucket) <= indexOf(name)
116
+ }
117
+
118
+ /**
119
+ * The environment queries React Native can answer.
120
+ *
121
+ * Tailwind's names, because that is what the author wrote and what the
122
+ * generated call carries. The pairs are one fact each -- `motion-safe` is
123
+ * `motion-reduce` negated, `landscape` is `portrait` negated -- so seven
124
+ * queries ride on four subscriptions.
125
+ *
126
+ * `contrast-more`, `contrast-less`, `forced-colors`, `print` and
127
+ * `noscript` are absent on purpose: React Native's nearest to the first
128
+ * two is Android's high-contrast *text* setting, which is a different
129
+ * thing wearing a similar name, and the last three have no meaning on a
130
+ * device at all. Those compile for Web and are reported on Native rather
131
+ * than answered wrongly.
132
+ */
133
+ export type EnvironmentQuery =
134
+ | 'motion-reduce'
135
+ | 'motion-safe'
136
+ | 'portrait'
137
+ | 'landscape'
138
+ | 'ltr'
139
+ | 'rtl'
140
+ | 'inverted-colors'
141
+ // The four React Native reports and Tailwind has no name for. Three are
142
+ // iOS settings; absent on Android reads as `false`, which is the
143
+ // arrangement `inverted-colors` already has and the right one -- a style
144
+ // that does not fire on a platform without the setting is correct rather
145
+ // than missing.
146
+ | 'reduce-transparency'
147
+ | 'bold-text'
148
+ | 'grayscale'
149
+ | 'screen-reader'
150
+ // The one Tailwind does name, and the only query behind which React
151
+ // Native has *two* settings: iOS's Increase Contrast and Android's
152
+ // high-contrast text. `contrast-less:` has no counterpart on either
153
+ // platform and stays Web-only.
154
+ | 'contrast-more'
155
+
156
+ /** The fact behind a query, and whether the query is its negation. */
157
+ export const ENVIRONMENT_FACTS: Record<
158
+ EnvironmentQuery,
159
+ {
160
+ fact:
161
+ | 'reduceMotion'
162
+ | 'portrait'
163
+ | 'rtl'
164
+ | 'invertColors'
165
+ | 'reduceTransparency'
166
+ | 'boldText'
167
+ | 'grayscale'
168
+ | 'screenReader'
169
+ | 'contrastMore'
170
+ negate: boolean
171
+ }
172
+ > = {
173
+ 'motion-reduce': { fact: 'reduceMotion', negate: false },
174
+ 'motion-safe': { fact: 'reduceMotion', negate: true },
175
+ portrait: { fact: 'portrait', negate: false },
176
+ landscape: { fact: 'portrait', negate: true },
177
+ rtl: { fact: 'rtl', negate: false },
178
+ ltr: { fact: 'rtl', negate: true },
179
+ 'inverted-colors': { fact: 'invertColors', negate: false },
180
+ 'reduce-transparency': { fact: 'reduceTransparency', negate: false },
181
+ 'bold-text': { fact: 'boldText', negate: false },
182
+ grayscale: { fact: 'grayscale', negate: false },
183
+ 'screen-reader': { fact: 'screenReader', negate: false },
184
+ 'contrast-more': { fact: 'contrastMore', negate: false },
185
+ }
186
+
187
+ /**
188
+ * Orientation from a window size, as a coarse fact.
189
+ *
190
+ * Square counts as portrait, which is the same tie-break CSS makes: the
191
+ * media query is `(orientation: portrait)` for `height >= width`.
192
+ *
193
+ * Coarse on purpose, for the reason the breakpoint bucket is: a component
194
+ * using only `portrait:` must not re-render on every resize that does not
195
+ * turn the device over, and on Android those fire on keyboard show/hide.
196
+ */
197
+ export function isPortrait(size: { width: number; height: number }): boolean {
198
+ return size.height >= size.width
199
+ }
@@ -0,0 +1,66 @@
1
+ import { type ComponentType, createElement, type ReactNode } from 'react'
2
+
3
+ /** Props handed to a platform component that can blur content behind itself. */
4
+ export interface HozoBackdropFilterAdapterProps {
5
+ blurRadius: number
6
+ children?: ReactNode
7
+ style?: unknown
8
+ [name: string]: unknown
9
+ }
10
+
11
+ export type HozoBackdropFilterAdapter = ComponentType<HozoBackdropFilterAdapterProps>
12
+
13
+ let backdropFilterAdapter: HozoBackdropFilterAdapter | undefined
14
+
15
+ /**
16
+ * Installs the Native implementation used by compiled `backdropFilter` styles.
17
+ *
18
+ * Configuration is explicit because React Native has no backdrop-filter style
19
+ * and loading Expo unconditionally would make it a dependency of every app.
20
+ * Configure this once during application startup. The returned cleanup is
21
+ * primarily useful for isolated tests.
22
+ */
23
+ export function configureHozoBackdropFilter(adapter: HozoBackdropFilterAdapter): () => void {
24
+ const previous = backdropFilterAdapter
25
+ backdropFilterAdapter = adapter
26
+ return () => {
27
+ if (backdropFilterAdapter === adapter) backdropFilterAdapter = previous
28
+ }
29
+ }
30
+
31
+ /** @internal Used by the Native wrapper emitted by the compiler. */
32
+ export function hozoBackdropFilterAdapter(): HozoBackdropFilterAdapter | undefined {
33
+ return backdropFilterAdapter
34
+ }
35
+
36
+ export interface ExpoBlurAdapterOptions<Props extends object> {
37
+ /** Expo intensity is not a CSS pixel radius, so applications may calibrate it. */
38
+ intensityForRadius?: (radius: number) => number
39
+ /** Expo-version-specific props such as Android blurMethod and blurTarget. */
40
+ props?: Partial<Props>
41
+ }
42
+
43
+ /**
44
+ * Adapts Expo BlurView without making `expo-blur` a dependency of Hozo.
45
+ *
46
+ * The default maps the common 0-25px CSS range onto Expo's 0-100 intensity
47
+ * range. Apps that need visual calibration can replace the mapping.
48
+ */
49
+ export function createExpoBlurAdapter<Props extends { intensity?: number }>(
50
+ BlurView: ComponentType<Props>,
51
+ options: ExpoBlurAdapterOptions<Props> = {},
52
+ ): HozoBackdropFilterAdapter {
53
+ const intensityForRadius =
54
+ options.intensityForRadius ?? ((radius: number) => Math.min(100, Math.max(0, radius * 4)))
55
+
56
+ function ExpoBlurAdapter({ blurRadius, ...props }: HozoBackdropFilterAdapterProps) {
57
+ return createElement(BlurView, {
58
+ ...options.props,
59
+ ...props,
60
+ intensity: intensityForRadius(blurRadius),
61
+ } as Props)
62
+ }
63
+
64
+ ExpoBlurAdapter.displayName = 'HozoExpoBlurAdapter'
65
+ return ExpoBlurAdapter
66
+ }
@@ -0,0 +1,53 @@
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
+
34
+ declare module 'react-native' {
35
+ interface ViewProps {
36
+ /** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
37
+ className?: string
38
+ }
39
+ interface TextProps {
40
+ /** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
41
+ className?: string
42
+ }
43
+ interface ImagePropsBase {
44
+ /** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
45
+ className?: string
46
+ }
47
+ interface FlatListProps<ItemT> {
48
+ /** Tailwind classes the compiler lowers to a `StyleSheet` entry. */
49
+ className?: string
50
+ }
51
+ }
52
+
53
+ export {}