@hozo/engine 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +39 -1
  3. package/dist/authored-gap.d.ts +11 -0
  4. package/dist/authored-gap.d.ts.map +1 -0
  5. package/dist/authored-gap.js +45 -0
  6. package/dist/authored-gap.js.map +1 -0
  7. package/dist/class-resolver.d.ts +66 -5
  8. package/dist/class-resolver.d.ts.map +1 -1
  9. package/dist/class-resolver.js +203 -29
  10. package/dist/class-resolver.js.map +1 -1
  11. package/dist/class-transition.d.ts +32 -0
  12. package/dist/class-transition.d.ts.map +1 -0
  13. package/dist/class-transition.js +48 -0
  14. package/dist/class-transition.js.map +1 -0
  15. package/dist/color-transition.d.ts +2 -0
  16. package/dist/color-transition.d.ts.map +1 -1
  17. package/dist/color-transition.js +10 -0
  18. package/dist/color-transition.js.map +1 -1
  19. package/dist/cx.d.ts +4 -0
  20. package/dist/cx.d.ts.map +1 -0
  21. package/dist/cx.js +17 -0
  22. package/dist/cx.js.map +1 -0
  23. package/dist/dom-style.d.ts +1 -0
  24. package/dist/dom-style.d.ts.map +1 -1
  25. package/dist/dom-style.js +4 -0
  26. package/dist/dom-style.js.map +1 -1
  27. package/dist/gap-styles.d.ts +3 -0
  28. package/dist/gap-styles.d.ts.map +1 -0
  29. package/dist/gap-styles.js +7 -0
  30. package/dist/gap-styles.js.map +1 -0
  31. package/dist/generated/animated.d.ts +3 -0
  32. package/dist/generated/animated.d.ts.map +1 -0
  33. package/dist/generated/animated.js +7 -0
  34. package/dist/generated/animated.js.map +1 -0
  35. package/dist/generated/class-resolver.d.ts +1 -1
  36. package/dist/generated/class-resolver.d.ts.map +1 -1
  37. package/dist/generated/class-resolver.js +1 -1
  38. package/dist/generated/class-resolver.js.map +1 -1
  39. package/dist/generated/gap-styles.d.ts +3 -0
  40. package/dist/generated/gap-styles.d.ts.map +1 -0
  41. package/dist/generated/gap-styles.js +4 -0
  42. package/dist/generated/gap-styles.js.map +1 -0
  43. package/dist/generated/safe-area.d.ts +1 -1
  44. package/dist/generated/safe-area.d.ts.map +1 -1
  45. package/dist/generated/safe-area.js +1 -1
  46. package/dist/generated/safe-area.js.map +1 -1
  47. package/dist/generated/spread-styles.d.ts +2 -0
  48. package/dist/generated/spread-styles.d.ts.map +1 -0
  49. package/dist/generated/spread-styles.js +3 -0
  50. package/dist/generated/spread-styles.js.map +1 -0
  51. package/dist/generated/text-inheritance-protocol.d.ts +3 -0
  52. package/dist/generated/text-inheritance-protocol.d.ts.map +1 -0
  53. package/dist/generated/text-inheritance-protocol.js +3 -0
  54. package/dist/generated/text-inheritance-protocol.js.map +1 -0
  55. package/dist/generated/text-size-context.d.ts +2 -0
  56. package/dist/generated/text-size-context.d.ts.map +1 -0
  57. package/dist/generated/text-size-context.js +3 -0
  58. package/dist/generated/text-size-context.js.map +1 -0
  59. package/dist/generated/transform-slots.d.ts +2 -0
  60. package/dist/generated/transform-slots.d.ts.map +1 -0
  61. package/dist/generated/transform-slots.js +4 -0
  62. package/dist/generated/transform-slots.js.map +1 -0
  63. package/dist/hooks.native.js +1 -1
  64. package/dist/index.d.ts +7 -3
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +7 -3
  67. package/dist/index.js.map +1 -1
  68. package/dist/interactive.d.ts +2 -0
  69. package/dist/interactive.d.ts.map +1 -1
  70. package/dist/interactive.js +4 -0
  71. package/dist/interactive.js.map +1 -1
  72. package/dist/presence-context.d.ts +15 -0
  73. package/dist/presence-context.d.ts.map +1 -0
  74. package/dist/presence-context.js +11 -0
  75. package/dist/presence-context.js.map +1 -0
  76. package/dist/project.d.ts +16 -0
  77. package/dist/project.d.ts.map +1 -1
  78. package/dist/project.js +16 -0
  79. package/dist/project.js.map +1 -1
  80. package/dist/project.native.d.ts +1 -1
  81. package/dist/project.native.d.ts.map +1 -1
  82. package/dist/project.native.js +1 -1
  83. package/dist/project.native.js.map +1 -1
  84. package/dist/responder.d.ts +34 -0
  85. package/dist/responder.d.ts.map +1 -1
  86. package/dist/responder.js +52 -0
  87. package/dist/responder.js.map +1 -1
  88. package/dist/runtime-transition.native.d.ts +37 -0
  89. package/dist/runtime-transition.native.d.ts.map +1 -0
  90. package/dist/runtime-transition.native.js +252 -0
  91. package/dist/runtime-transition.native.js.map +1 -0
  92. package/dist/safe-area.native.d.ts +12 -0
  93. package/dist/safe-area.native.d.ts.map +1 -1
  94. package/dist/safe-area.native.js +44 -21
  95. package/dist/safe-area.native.js.map +1 -1
  96. package/dist/spread-styles.d.ts +14 -0
  97. package/dist/spread-styles.d.ts.map +1 -0
  98. package/dist/spread-styles.js +56 -0
  99. package/dist/spread-styles.js.map +1 -0
  100. package/dist/text-inheritance.d.ts +35 -0
  101. package/dist/text-inheritance.d.ts.map +1 -0
  102. package/dist/text-inheritance.js +48 -0
  103. package/dist/text-inheritance.js.map +1 -0
  104. package/dist/text-style.d.ts +8 -0
  105. package/dist/text-style.d.ts.map +1 -0
  106. package/dist/text-style.js +34 -0
  107. package/dist/text-style.js.map +1 -0
  108. package/dist/transform-slots.d.ts +22 -0
  109. package/dist/transform-slots.d.ts.map +1 -0
  110. package/dist/transform-slots.js +108 -0
  111. package/dist/transform-slots.js.map +1 -0
  112. package/dist/view-base-css.d.ts +2 -0
  113. package/dist/view-base-css.d.ts.map +1 -0
  114. package/dist/view-base-css.js +20 -0
  115. package/dist/view-base-css.js.map +1 -0
  116. package/dist/view-base.d.ts +6 -0
  117. package/dist/view-base.d.ts.map +1 -0
  118. package/dist/view-base.js +15 -0
  119. package/dist/view-base.js.map +1 -0
  120. package/package.json +26 -2
  121. package/src/authored-gap.ts +41 -0
  122. package/src/class-resolver.ts +297 -24
  123. package/src/class-transition.ts +71 -0
  124. package/src/color-transition.ts +11 -0
  125. package/src/cx.ts +18 -0
  126. package/src/dom-style.ts +3 -0
  127. package/src/gap-styles.ts +11 -0
  128. package/src/generated/animated.ts +15 -0
  129. package/src/generated/class-resolver.ts +7 -1
  130. package/src/generated/gap-styles.ts +3 -0
  131. package/src/generated/safe-area.ts +5 -1
  132. package/src/generated/spread-styles.ts +2 -0
  133. package/src/generated/text-inheritance-protocol.ts +9 -0
  134. package/src/generated/text-size-context.ts +2 -0
  135. package/src/generated/transform-slots.ts +3 -0
  136. package/src/hooks.native.ts +1 -1
  137. package/src/index.ts +18 -3
  138. package/src/interactive.ts +4 -0
  139. package/src/presence-context.ts +27 -0
  140. package/src/project.native.ts +1 -1
  141. package/src/project.ts +20 -0
  142. package/src/responder.ts +52 -0
  143. package/src/runtime-transition.native.tsx +324 -0
  144. package/src/safe-area.native.ts +59 -24
  145. package/src/spread-styles.ts +74 -0
  146. package/src/text-inheritance.ts +75 -0
  147. package/src/text-style.ts +35 -0
  148. package/src/transform-slots.ts +119 -0
  149. package/src/view-base-css.ts +19 -0
  150. package/src/view-base.ts +20 -0
@@ -1,74 +1,347 @@
1
1
  /** A React Native style object, as the compiler emits it. */
2
2
  export type StyleObject = Record<string, unknown>
3
3
 
4
+ /**
5
+ * Compiler-owned text-size fallbacks are not explicit line heights. CSS's
6
+ * --tw-leading register survives a later font-size rule; RN has one numeric
7
+ * slot. The map marks actual generated objects, never class names or private
8
+ * style keys. Only maps containing these fallbacks install this composition.
9
+ */
10
+ export function hozoTextMetricStyles(
11
+ styles: StyleObject[],
12
+ defaults: ReadonlyMap<StyleObject, StyleObject>,
13
+ ): StyleObject[] {
14
+ if (
15
+ !styles.some((style) => defaults.has(style)) ||
16
+ !styles.some((style) => Object.hasOwn(style, 'lineHeight') && !defaults.has(style))
17
+ )
18
+ return styles
19
+ // Default-free objects are built once by the generated factory. A state
20
+ // update selects them; it never clones a style object or inspects ranks.
21
+ return styles.map((style) => defaults.get(style) ?? style)
22
+ }
23
+
24
+ /**
25
+ * The state an element is in when its runtime classes are resolved: what
26
+ * its pressable reports (`pressed`, `hovered`, `focused`, `focusVisible`)
27
+ * and what its props say: `disabled`, and `aria-checked`, `aria-selected` and
28
+ * the rest under their attribute names, so `aria-pressed` cannot be read as
29
+ * the pointer's `pressed`. Plain data-presence conditions use `data-foo`
30
+ * booleans supplied by the actual owner: true means the attribute is present,
31
+ * false means absent, and a missing key is unassessed (and diagnosed).
32
+ * Simple equality predicates use `data-foo=value` booleans, with case-sensitive
33
+ * safe token values normalized at build time. Presence cannot satisfy equality.
34
+ * These are normalized facts, not raw HTML attribute values or selectors.
35
+ */
36
+ export type ClassState = Readonly<Record<string, unknown>>
37
+
38
+ /**
39
+ * A class that applies only in a state: the state keys that all have to
40
+ * hold, and the style it applies then. `active:opacity-80` is
41
+ * `[['pressed'], { opacity: 0.8 }]`.
42
+ * Generated Tailwind owner states may append a cached cascade rank; legacy
43
+ * two-entry groups and mixed/unranked conditional domains keep their order.
44
+ * `!aria-…` is compiler-owned negative-predicate data. It still requires the
45
+ * underlying owner fact; an absent fact is not a measured false value.
46
+ */
47
+ export type StateGroup = readonly [readonly string[], StyleObject, number?]
48
+
4
49
  /**
5
50
  * Resolves whitespace-separated class names to React Native style objects.
6
51
  *
7
52
  * Returns an array, which is a valid `style` value on its own and also
8
53
  * nests inside one -- RN flattens arbitrarily nested style arrays, so
9
54
  * callers never have to spread it.
55
+ *
56
+ * `state` is what the element is in. Without it, a class that applies only
57
+ * in a state is reported as it always was; with it, that class applies
58
+ * when its state holds, after the unconditional ones.
10
59
  */
11
- export type ClassResolver = (value: unknown) => StyleObject[]
60
+ export type ClassResolver = (value: unknown, state?: ClassState) => StyleObject[]
61
+
62
+ /** @internal Generated-data ABI, not a utility parser or a public cascade API. */
63
+ export interface ClassResolverPlan {
64
+ schema: 1
65
+ styles: Record<string, StyleObject>
66
+ unsupported?: Record<string, string>
67
+ states?: Record<string, readonly StateGroup[]>
68
+ ambient?: ClassState
69
+ compose?: (styles: StyleObject[]) => StyleObject[]
70
+ /** Ordinals from one complete compiler namespace. Missing means barrier. */
71
+ ordering: { schema: 1; ranks: Readonly<Record<string, readonly number[]>> }
72
+ }
73
+
74
+ interface TemplateEntry {
75
+ keys: readonly string[]
76
+ style: StyleObject
77
+ name: string
78
+ }
79
+
80
+ interface Resolved {
81
+ /** The unconditional styles, composed: what a string with no state classes returns. */
82
+ base: StyleObject[]
83
+ /** The same, before `compose`, for composing again with state styles. */
84
+ raw: StyleObject[]
85
+ groups: StateGroup[]
86
+ /** Parallel to groups: retain the candidate name for missing-fact warnings. */
87
+ groupClasses: string[]
88
+ /** State classes in this string, named if it is resolved without a state. */
89
+ stateClasses: string[]
90
+ /** Rank-free cached template: state updates only select applicable entries. */
91
+ ordered?: TemplateEntry[]
92
+ }
12
93
 
13
94
  /**
14
95
  * Builds a resolver over one project's candidate map.
15
96
  *
16
97
  * Called by the generated candidate module rather than by application
17
- * code: `styles` and `unsupported` are build output, and binding them here
18
- * keeps the generated file to data plus one call.
98
+ * code: `styles`, `unsupported` and `states` are build output, and binding
99
+ * them here keeps the generated file to data plus one call.
19
100
  *
20
101
  * `unsupported` maps a class the compiler *recognized but can't express*
21
- * as a plain style object -- a conditional utility (`hover:`, `md:`), or
102
+ * as a plain style object -- a utility under a breakpoint or `dark:`, or
22
103
  * one that's Web-only -- to the reason. Those are reported when they're
23
104
  * actually used rather than at build time, because a class appearing in
24
105
  * the project's candidate scan doesn't mean any dynamic expression ever
25
106
  * produces it.
107
+ *
108
+ * `states` holds the classes whose only condition is the element's own
109
+ * state (#886). Those need no tracking here: the pressable that renders
110
+ * the element already tracks it and hands it in, so this stays a function
111
+ * of the class string and that state.
112
+ *
113
+ * `ambient` holds facts that cannot change while the app runs, so no
114
+ * element has to supply them: `rtl` and `ltr`, because React Native needs
115
+ * a reload for a direction change to take effect. A class conditioned on
116
+ * them alone is decided once, when its string is first resolved, and then
117
+ * cached like an unconditional one -- after the unconditional ones, which is
118
+ * where Tailwind puts a variant too.
26
119
  */
120
+ export function createClassResolver(plan: ClassResolverPlan): ClassResolver
27
121
  export function createClassResolver(
28
122
  styles: Record<string, StyleObject>,
123
+ unsupported?: Record<string, string>,
124
+ compose?: (styles: StyleObject[]) => StyleObject[],
125
+ states?: Record<string, readonly StateGroup[]>,
126
+ ambient?: ClassState,
127
+ ): ClassResolver
128
+ export function createClassResolver(
129
+ stylesOrPlan: Record<string, StyleObject> | ClassResolverPlan,
29
130
  unsupported: Record<string, string> = {},
131
+ compose?: (styles: StyleObject[]) => StyleObject[],
132
+ states: Record<string, readonly StateGroup[]> = {},
133
+ ambient: ClassState = {},
30
134
  ): ClassResolver {
135
+ let styles: Record<string, StyleObject>
136
+ let ranks: ClassResolverPlan['ordering']['ranks'] | undefined
137
+ if (typeof stylesOrPlan.schema === 'number') {
138
+ const plan = stylesOrPlan as ClassResolverPlan
139
+ if (
140
+ plan.schema !== 1 ||
141
+ plan.ordering?.schema !== 1 ||
142
+ !plan.ordering.ranks ||
143
+ typeof plan.ordering.ranks !== 'object'
144
+ )
145
+ throw new Error('Unsupported Hozo class plan schema')
146
+ styles = plan.styles
147
+ unsupported = plan.unsupported ?? {}
148
+ compose = plan.compose
149
+ states = plan.states ?? {}
150
+ ambient = plan.ambient ?? {}
151
+ ranks = plan.ordering.ranks
152
+ } else styles = stylesOrPlan as Record<string, StyleObject>
153
+ const isAmbient = (key: string) => Object.hasOwn(ambient, key)
31
154
  // Class strings repeat constantly across renders and list items, and the
32
155
  // result is immutable, so each distinct string is resolved once.
33
- const cache = new Map<string, StyleObject[]>()
156
+ const cache = new Map<string, Resolved>()
34
157
  // Warn once per class, not once per render -- a warning inside a list's
35
158
  // render path would otherwise repeat for every row, every frame.
36
159
  const warned = new Set<string>()
37
-
38
- return function hozoClasses(value: unknown): StyleObject[] {
39
- // Falsy is the normal case, not an error: `cond && 'p-4'` yields
40
- // `false` whenever the condition is off.
41
- if (typeof value !== 'string' || value === '') {
42
- return []
43
- }
44
-
45
- const cached = cache.get(value)
46
- if (cached) {
47
- return cached
160
+ const warn = (name: string, reason: string) => {
161
+ if (warned.has(name)) return
162
+ warned.add(name)
163
+ // eslint-disable-next-line no-console
164
+ console.warn(`[hozo] ${reason}`)
165
+ }
166
+ // Absent is not false. A focused field must not silently claim that it
167
+ // measured hover/press, or that a spread supplied a disabled driver.
168
+ const supplied = (keys: readonly string[], name: string, facts: ClassState) => {
169
+ if (!keys.every((key) => Object.hasOwn(facts, key))) {
170
+ if (!warned.has(name)) {
171
+ const missing = keys.filter((key) => !Object.hasOwn(facts, key))
172
+ warn(name, `\`${name}\` needs state (${missing.join(', ')}) this element does not supply.`)
173
+ }
174
+ return false
48
175
  }
176
+ return true
177
+ }
178
+ const positive = (keys: readonly string[], name: string, facts: ClassState) =>
179
+ supplied(keys, name, facts) && keys.every((key) => Boolean(facts[key]))
180
+ // Prepare only negative maps' exceptional groups once, not during state
181
+ // updates or for every authored class lookup. Positive-only maps retain
182
+ // their existing boolean matcher and allocate no predicate side table.
183
+ let negative: Map<readonly string[], { keys: string[]; expected: boolean[] }> | undefined
184
+ for (const groups of Object.values(states))
185
+ for (const [keys] of groups)
186
+ if (keys.some((key) => key.startsWith('!aria-')))
187
+ (negative ??= new Map()).set(keys, {
188
+ keys: keys.map((key) => (key.startsWith('!aria-') ? key.slice(1) : key)),
189
+ expected: keys.map((key) => !key.startsWith('!aria-')),
190
+ })
191
+ const negativePredicates = negative
192
+ const matches = negativePredicates
193
+ ? (keys: readonly string[], name: string, facts: ClassState) => {
194
+ const predicate = negativePredicates.get(keys)
195
+ return predicate
196
+ ? supplied(predicate.keys, name, facts) &&
197
+ predicate.keys.every(
198
+ (key, index) => Boolean(facts[key]) === predicate.expected[index],
199
+ )
200
+ : positive(keys, name, facts)
201
+ }
202
+ : positive
49
203
 
50
- const resolved: StyleObject[] = []
204
+ function resolve(value: string): Resolved {
205
+ const base: StyleObject[] = []
206
+ const groups: StateGroup[] = []
207
+ const groupClasses: string[] = []
208
+ const stateClasses: string[] = []
209
+ const decided: StyleObject[] = []
210
+ // Build transient ranked entries only for the generated-plan ABI. A
211
+ // single unassessed object makes this whole string use the old path.
212
+ let ranked: { rank: number; entry: TemplateEntry }[] | undefined = ranks ? [] : undefined
213
+ const take = ranks
214
+ ? (name: string, index: number, style: StyleObject, keys: readonly string[]) => {
215
+ if (!ranked) return
216
+ const rank = ranks![name]?.[index]
217
+ if (rank === undefined) {
218
+ ranked = undefined
219
+ return
220
+ }
221
+ if (!Number.isSafeInteger(rank) || rank < 0)
222
+ throw new Error('Invalid Hozo class plan rank')
223
+ ranked.push({ rank, entry: { name, style, keys } })
224
+ }
225
+ : undefined
51
226
  for (const name of value.split(/\s+/)) {
52
227
  if (name === '') {
53
228
  continue
54
229
  }
55
230
  const style = styles[name]
56
231
  if (style) {
57
- resolved.push(style)
232
+ base.push(style)
233
+ take?.(name, 0, style, [])
234
+ continue
235
+ }
236
+ const conditional = states[name]
237
+ if (conditional) {
238
+ let needsState = false
239
+ for (let index = 0; index < conditional.length; index++) {
240
+ const group = conditional[index]!
241
+ take?.(name, index, group[1], group[0])
242
+ if ((negativePredicates?.get(group[0])?.keys ?? group[0]).every(isAmbient)) {
243
+ if (matches(group[0], name, ambient)) decided.push(group[1])
244
+ continue
245
+ }
246
+ groups.push(group)
247
+ groupClasses.push(name)
248
+ needsState = true
249
+ }
250
+ if (needsState) stateClasses.push(name)
58
251
  continue
59
252
  }
60
253
  // An unknown class isn't necessarily a Hozo problem -- it may be an
61
254
  // app's own non-Tailwind class, or a testID-ish marker -- so only the
62
255
  // ones the compiler recognized and refused are reported.
63
256
  const reason = unsupported[name]
64
- if (reason && !warned.has(name)) {
65
- warned.add(name)
66
- // eslint-disable-next-line no-console
67
- console.warn(`[hozo] ${reason}`)
257
+ if (reason) warn(name, reason)
258
+ }
259
+ if (ranked) {
260
+ // Stable ties keep input order. Strip rank objects before caching, so
261
+ // neither cache hits nor state-only changes can read/sort priorities.
262
+ ranked.sort((a, b) => a.rank - b.rank)
263
+ const ordered: TemplateEntry[] = []
264
+ for (const { entry } of ranked) {
265
+ if ((negativePredicates?.get(entry.keys)?.keys ?? entry.keys).every(isAmbient)) {
266
+ if (matches(entry.keys, entry.name, ambient)) ordered.push({ ...entry, keys: [] })
267
+ } else ordered.push(entry)
268
+ }
269
+ const raw = ordered.filter((entry) => !entry.keys.length).map((entry) => entry.style)
270
+ return {
271
+ base: compose ? compose(raw) : raw,
272
+ raw,
273
+ groups,
274
+ groupClasses,
275
+ stateClasses,
276
+ ordered,
277
+ }
278
+ }
279
+ // Build-time Tailwind owner-state rank, sorted once per cached class string,
280
+ // never on every state update. Mixed/unranked domains are left alone; ties
281
+ // retain authored/caller order. Keep warning provenance beside each group.
282
+ if (groups.length > 1 && groups.every((group) => group[2] !== undefined)) {
283
+ if (groups.some((group, index) => index > 0 && groups[index - 1]![2]! > group[2]!)) {
284
+ const sorted = groups
285
+ .map((group, index) => ({ group, name: groupClasses[index]! }))
286
+ .sort((a, b) => a.group[2]! - b.group[2]!)
287
+ for (const [index, entry] of sorted.entries()) {
288
+ groups[index] = entry.group
289
+ groupClasses[index] = entry.name
290
+ }
68
291
  }
69
292
  }
293
+ base.push(...decided)
294
+ return { base: compose ? compose(base) : base, raw: base, groups, groupClasses, stateClasses }
295
+ }
296
+
297
+ return function hozoClasses(value: unknown, state?: ClassState): StyleObject[] {
298
+ // Falsy is the normal case, not an error: `cond && 'p-4'` yields
299
+ // `false` whenever the condition is off.
300
+ if (typeof value !== 'string' || value === '') {
301
+ return []
302
+ }
70
303
 
71
- cache.set(value, resolved)
72
- return resolved
304
+ let resolved = cache.get(value)
305
+ if (!resolved) {
306
+ resolved = resolve(value)
307
+ cache.set(value, resolved)
308
+ }
309
+ if (resolved.groups.length === 0) return resolved.base
310
+ if (state === undefined) {
311
+ for (const name of resolved.stateClasses) {
312
+ warn(
313
+ name,
314
+ `\`${name}\` applies in a state, and this element hands its classes no state to ` +
315
+ 'resolve it against. Put it on an owner that supplies this state, or write it as a static ' +
316
+ 'className so it compiles to a real style variant.',
317
+ )
318
+ }
319
+ return resolved.base
320
+ }
321
+ // A group can name an ambient fact beside the element's own, as
322
+ // `rtl:hover:` does; the element supplies only its part.
323
+ const facts = { ...ambient, ...state }
324
+ if (resolved.ordered) {
325
+ const all: StyleObject[] = []
326
+ let active = false
327
+ for (const entry of resolved.ordered) {
328
+ if (!entry.keys.length) all.push(entry.style)
329
+ else if (matches(entry.keys, entry.name, facts)) {
330
+ all.push(entry.style)
331
+ active = true
332
+ }
333
+ }
334
+ if (!active) return resolved.base
335
+ return compose ? compose(all) : all
336
+ }
337
+ const active = resolved.groups.filter(([keys], index) =>
338
+ matches(keys, resolved.groupClasses[index]!, facts),
339
+ )
340
+ if (active.length === 0) return resolved.base
341
+ const all = [...resolved.raw, ...active.map(([, style]) => style)]
342
+ // A state style can carry a transform, which `compose` folds into one;
343
+ // so it runs over the whole list, and the result is per render rather
344
+ // than cached -- it changes with the state.
345
+ return compose ? compose(all) : all
73
346
  }
74
347
  }
@@ -0,0 +1,71 @@
1
+ // What a runtime-resolved class string says about transitions.
2
+ //
3
+ // A transition utility draws nothing on React Native, so the class resolver
4
+ // has nothing to return for one, and it used to be reported as Web-only and
5
+ // dropped. A component that resolves its look at run time -- a pattern's
6
+ // indicator, say -- then had no way to animate on Native what its classes
7
+ // animate on the Web (#1450). The candidate module now emits each transition
8
+ // utility's part of a spec, and this reads a class string into one spec for
9
+ // `HozoAnimated` to run.
10
+
11
+ /** `HozoAnimated`'s spec, as `@hozo/primitives` defines it. */
12
+ export interface ClassTransitionSpec {
13
+ duration: number
14
+ delay?: number
15
+ easing: 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out'
16
+ properties?: readonly string[]
17
+ }
18
+
19
+ /** @internal Generated-data ABI: one transition utility's condition and part. */
20
+ export type ClassTransitionTable = Readonly<
21
+ Record<
22
+ string,
23
+ readonly [condition: 'motion-reduce' | 'motion-safe' | null, Partial<ClassTransitionSpec>]
24
+ >
25
+ >
26
+
27
+ /**
28
+ * Reads the transition a class string asks for, or `undefined` when it asks
29
+ * for none.
30
+ *
31
+ * `reduceMotion` decides the `motion-reduce:` and `motion-safe:` parts, as
32
+ * the media query does on the Web; the caller reads it, so this stays a pure
33
+ * function of its arguments.
34
+ */
35
+ export type ClassTransition = (
36
+ value: unknown,
37
+ environment: { reduceMotion: boolean },
38
+ ) => ClassTransitionSpec | undefined
39
+
40
+ /**
41
+ * Builds the reader over one project's transition table.
42
+ *
43
+ * Later classes win, field by field, as later declarations do in a
44
+ * stylesheet. A string with no `transition*` utility asks for no
45
+ * transition, whatever its duration says: on the Web `transition-property`
46
+ * is what turns one on. Its defaults are Tailwind's: 150ms and
47
+ * `ease-in-out`'s curve, which `transition-*` utilities normally set
48
+ * themselves.
49
+ */
50
+ export function createClassTransitions(table: ClassTransitionTable): ClassTransition {
51
+ return (value, { reduceMotion }) => {
52
+ if (typeof value !== 'string' || value === '') return undefined
53
+ let spec: Partial<ClassTransitionSpec> | undefined
54
+ for (const name of value.split(/\s+/)) {
55
+ const entry = table[name]
56
+ if (!entry) continue
57
+ const [condition, part] = entry
58
+ if (condition === 'motion-reduce' && !reduceMotion) continue
59
+ if (condition === 'motion-safe' && reduceMotion) continue
60
+ spec = { ...spec, ...part }
61
+ }
62
+ if (!spec?.properties || spec.properties.length === 0) return undefined
63
+ if (spec.properties.length === 1 && spec.properties[0] === 'none') return undefined
64
+ return {
65
+ duration: spec.duration ?? 150,
66
+ delay: spec.delay,
67
+ easing: spec.easing ?? 'ease-in-out',
68
+ properties: spec.properties,
69
+ }
70
+ }
71
+ }
@@ -1,5 +1,11 @@
1
1
  function rgba(color: string): [number, number, number, number] | null {
2
2
  if (color === 'transparent') return [0, 0, 0, 0]
3
+ // An interrupted blend must be able to read its own serialized result.
4
+ const blended = /^rgba\((\d+), (\d+), (\d+), ([\d.e+-]+)\)$/.exec(color)
5
+ if (blended) {
6
+ const channels = blended.slice(1).map(Number) as [number, number, number, number]
7
+ return channels.every(Number.isFinite) ? channels : null
8
+ }
3
9
  const match = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(color)
4
10
  if (!match) return null
5
11
  let hex = match[1]!
@@ -13,6 +19,11 @@ function rgba(color: string): [number, number, number, number] | null {
13
19
  ]
14
20
  }
15
21
 
22
+ /** @internal Whether interrupted blending can read this colour without a snap fallback. */
23
+ export function canBlendColor(color: string) {
24
+ return rgba(color) !== null
25
+ }
26
+
16
27
  /** The visible colour at `progress`, used when an interrupted transition restarts. */
17
28
  export function blendColor(from: string, to: string, progress: number) {
18
29
  const a = rgba(from)
package/src/cx.ts ADDED
@@ -0,0 +1,18 @@
1
+ // The compiler reads a `cx(...)` call argument by argument, as it reads
2
+ // `clsx`, so a component can merge a caller's className and still have its
3
+ // own classes compiled, `hover:` and `disabled:` included on Native (#873).
4
+ // This body only runs where the compiler did not take the call apart. It
5
+ // has to agree with the compiler's reading, which is why it accepts strings
6
+ // and nothing that clsx would expand, such as objects and arrays.
7
+
8
+ export type CxValue = string | false | null | undefined
9
+
10
+ /** Joins the truthy class strings with a space, as `clsx` does for strings. */
11
+ export function cx(...classes: CxValue[]): string {
12
+ let joined = ''
13
+ for (const value of classes) {
14
+ if (!value) continue
15
+ joined = joined ? `${joined} ${value}` : value
16
+ }
17
+ return joined
18
+ }
package/src/dom-style.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { CSSProperties } from 'react'
2
+ import { projectAuthoredGap } from './authored-gap.ts'
2
3
 
3
4
  export type HozoDomStyle =
4
5
  | CSSProperties
@@ -119,10 +120,12 @@ const unsupported = new Map<string, string>([
119
120
  /**
120
121
  * Converts React Native's StyleProp shape to the single object React DOM requires.
121
122
  * Arrays are recursively flattened, falsy entries are ignored, and later objects win.
123
+ * Gap aliases are projected afterwards, retaining Yoga's axis-over-generic priority.
122
124
  */
123
125
  export function hozoDomStyle(input: HozoDomStyle): CSSProperties | undefined {
124
126
  const flat: Record<string, unknown> = {}
125
127
  flattenInto(input, flat)
128
+ if (flat.gap !== undefined) projectAuthoredGap(flat)
126
129
 
127
130
  if ('transform' in flat) {
128
131
  const transform = normalizeTransform(flat.transform)
@@ -0,0 +1,11 @@
1
+ import { hozoAuthoredStyle } from './authored-gap.ts'
2
+ import { composeSpreadStyles } from './spread-styles.ts'
3
+
4
+ /** Only compiler-assessed possible gap owners import the gap-aware boundary. */
5
+ export function hozoGapSpreadStyles(
6
+ styles: Readonly<Record<string, unknown>>,
7
+ writtenLast: readonly string[],
8
+ ...sources: readonly unknown[]
9
+ ): Record<string, unknown> {
10
+ return composeSpreadStyles(styles, writtenLast, sources, hozoAuthoredStyle)
11
+ }
@@ -0,0 +1,15 @@
1
+ // Native-only, like the layout boundaries: the Web backend animates with CSS
2
+ // and never asks for it. In the engine rather than `@hozo/primitives`
3
+ // because `@hozo/patterns` runs it too, for a look resolved at run time
4
+ // (#1450), and patterns are built on the engine, not on primitives.
5
+
6
+ export {
7
+ PresenceContext,
8
+ type PresenceContextValue,
9
+ type PresenceState,
10
+ } from '../presence-context.ts'
11
+ export {
12
+ HozoAnimated,
13
+ type HozoAnimatedProps,
14
+ type HozoTransitionSpec,
15
+ } from '../runtime-transition.native.tsx'
@@ -1,2 +1,8 @@
1
1
  // Imported by the Metro candidate module rather than by a component.
2
- export { type ClassResolver, createClassResolver, type StyleObject } from '../class-resolver.ts'
2
+ export {
3
+ type ClassResolver,
4
+ type ClassResolverPlan,
5
+ createClassResolver,
6
+ hozoTextMetricStyles,
7
+ type StyleObject,
8
+ } from '../class-resolver.ts'
@@ -0,0 +1,3 @@
1
+ // A separate leaf keeps gap projection out of ordinary Native spread imports.
2
+ export { hozoAuthoredStyle } from '../authored-gap.ts'
3
+ export { hozoGapSpreadStyles } from '../gap-styles.ts'
@@ -1,3 +1,7 @@
1
1
  // Native-only. A module of its own because it is one: nothing else in the
2
2
  // environment hooks needs the safe-area provider.
3
- export { type HozoSafeAreaInsets, useHozoSafeArea } from '../safe-area.native.ts'
3
+ export {
4
+ type HozoSafeAreaInsets,
5
+ useHozoProvidedSafeArea,
6
+ useHozoSafeArea,
7
+ } from '../safe-area.native.ts'
@@ -0,0 +1,2 @@
1
+ // Ordinary spread composition must not load the gap normalizer on Native.
2
+ export { hozoSpreadStyles } from '../spread-styles.ts'
@@ -0,0 +1,9 @@
1
+ /** @internal Generated Native text owners/readers share one protocol. */
2
+ export {
3
+ HOZO_INHERITED_TEXT_FIELDS,
4
+ HozoInheritedMetricsContext,
5
+ HozoInheritedPaintContext,
6
+ type HozoInheritedTextFrame,
7
+ type HozoInheritedTextOwn,
8
+ useHozoInheritedTextFrame,
9
+ } from '../text-inheritance.ts'
@@ -0,0 +1,2 @@
1
+ // Same singleton as the root export, without importing the whole engine in Metro.
2
+ export { HozoTextSizeContext } from '../text-size.ts'
@@ -0,0 +1,3 @@
1
+ // Only reset-bearing generated code imports the slot composer. Ordinary
2
+ // dynamic resolution must not pull this module into a Native bundle.
3
+ export { hozoTransformStyles } from '../transform-slots.ts'
@@ -241,7 +241,7 @@ export function useHozoAnimation(name: HozoAnimation) {
241
241
  // A percentage, because Tailwind's bounce is -25% of the
242
242
  // element's own height and a pixel figure would be right at
243
243
  // one size only. React Native has taken percentages in
244
- // `translateY` since 0.76, below this package's floor of 0.86.
244
+ // `translateY` since 0.76, below this package's floor of 0.87.
245
245
  //
246
246
  // The two halves are not symmetric: Tailwind eases the rise
247
247
  // with `cubic-bezier(.8,0,1,1)` and the fall with
package/src/index.ts CHANGED
@@ -28,23 +28,38 @@ export {
28
28
  hozoBackdropFilterAdapter,
29
29
  } from './backdrop.ts'
30
30
 
31
- export { type ClassResolver, createClassResolver, type StyleObject } from './class-resolver.ts'
32
- export { blendColor } from './color-transition.ts'
31
+ export {
32
+ type ClassResolver,
33
+ type ClassResolverPlan,
34
+ createClassResolver,
35
+ type StyleObject,
36
+ } from './class-resolver.ts'
37
+ export {
38
+ type ClassTransition,
39
+ type ClassTransitionSpec,
40
+ type ClassTransitionTable,
41
+ createClassTransitions,
42
+ } from './class-transition.ts'
43
+ export { blendColor, canBlendColor } from './color-transition.ts'
44
+ export { type CxValue, cx } from './cx.ts'
33
45
  export { type HozoDomStyle, hozoDomProps, hozoDomStyle } from './dom-style.ts'
34
46
  export { externalLinkAttributes } from './external-link.ts'
35
47
  export { hozoInteractive } from './interactive.ts'
36
48
  export {
49
+ createSpreadResponder,
37
50
  type HozoResponderEvent,
38
51
  type HozoResponderTouch,
39
52
  type HozoTouchHistory,
40
53
  type HozoTouchTrack,
54
+ RESPONDER_PROPS,
41
55
  type ResponderProps,
42
56
  useResponderDomProps,
43
57
  } from './responder.ts'
44
58
  export { hozoScrollable } from './scrollable.ts'
45
-
46
59
  export {
47
60
  HOZO_DEFAULT_FONT_SIZE,
48
61
  HozoTextSizeContext,
49
62
  useHozoTextSize,
50
63
  } from './text-size.ts'
64
+ export { hozoSplitTextStyle } from './text-style.ts'
65
+ export { hozoViewBase, hozoViewClassName } from './view-base.ts'
@@ -49,6 +49,7 @@ export function hozoInteractive(onPress?: PressHandler, disabled?: unknown) {
49
49
  // a boolean here would have made every control permanently
50
50
  // disabled-looking. `undefined` is the only value React omits.
51
51
  'data-hozo-disabled': '',
52
+ 'data-hozo-pressable': undefined,
52
53
  tabIndex: -1,
53
54
  onClick: undefined,
54
55
  onKeyDown: undefined,
@@ -60,6 +61,9 @@ export function hozoInteractive(onPress?: PressHandler, disabled?: unknown) {
60
61
  // is noise a screen reader has to read past.
61
62
  'aria-disabled': undefined,
62
63
  'data-hozo-disabled': undefined,
64
+ // The pointer cursor's hook (see the view base CSS): present only
65
+ // while clicking does something.
66
+ 'data-hozo-pressable': onPress ? '' : undefined,
63
67
  tabIndex: 0,
64
68
  onClick: onPress,
65
69
  onKeyDown: hozoActivateKeyDown,