@hozo/engine 0.3.0 → 0.5.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 (179) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +8 -4
  3. package/dist/authored-edges.d.ts +24 -0
  4. package/dist/authored-edges.d.ts.map +1 -0
  5. package/dist/authored-edges.js +73 -0
  6. package/dist/authored-edges.js.map +1 -0
  7. package/dist/authored-gap.d.ts +11 -0
  8. package/dist/authored-gap.d.ts.map +1 -0
  9. package/dist/authored-gap.js +45 -0
  10. package/dist/authored-gap.js.map +1 -0
  11. package/dist/class-name.native.d.ts +6 -0
  12. package/dist/class-name.native.d.ts.map +1 -1
  13. package/dist/class-name.native.js.map +1 -1
  14. package/dist/class-resolver.d.ts +77 -4
  15. package/dist/class-resolver.d.ts.map +1 -1
  16. package/dist/class-resolver.js +461 -34
  17. package/dist/class-resolver.js.map +1 -1
  18. package/dist/class-transition.d.ts +32 -0
  19. package/dist/class-transition.d.ts.map +1 -0
  20. package/dist/class-transition.js +48 -0
  21. package/dist/class-transition.js.map +1 -0
  22. package/dist/color-transition.d.ts +2 -0
  23. package/dist/color-transition.d.ts.map +1 -1
  24. package/dist/color-transition.js +4 -0
  25. package/dist/color-transition.js.map +1 -1
  26. package/dist/cx.d.ts +4 -0
  27. package/dist/cx.d.ts.map +1 -0
  28. package/dist/cx.js +17 -0
  29. package/dist/cx.js.map +1 -0
  30. package/dist/dom-style.d.ts +1 -0
  31. package/dist/dom-style.d.ts.map +1 -1
  32. package/dist/dom-style.js +4 -0
  33. package/dist/dom-style.js.map +1 -1
  34. package/dist/filter-slots.d.ts +11 -0
  35. package/dist/filter-slots.d.ts.map +1 -0
  36. package/dist/filter-slots.js +57 -0
  37. package/dist/filter-slots.js.map +1 -0
  38. package/dist/gap-styles.d.ts +3 -0
  39. package/dist/gap-styles.d.ts.map +1 -0
  40. package/dist/gap-styles.js +7 -0
  41. package/dist/gap-styles.js.map +1 -0
  42. package/dist/generated/animated.d.ts +3 -0
  43. package/dist/generated/animated.d.ts.map +1 -0
  44. package/dist/generated/animated.js +7 -0
  45. package/dist/generated/animated.js.map +1 -0
  46. package/dist/generated/authored-edges.d.ts +2 -0
  47. package/dist/generated/authored-edges.d.ts.map +1 -0
  48. package/dist/generated/authored-edges.js +3 -0
  49. package/dist/generated/authored-edges.js.map +1 -0
  50. package/dist/generated/class-resolver.d.ts +1 -1
  51. package/dist/generated/class-resolver.d.ts.map +1 -1
  52. package/dist/generated/class-resolver.js +1 -1
  53. package/dist/generated/class-resolver.js.map +1 -1
  54. package/dist/generated/filter-slots.d.ts +2 -0
  55. package/dist/generated/filter-slots.d.ts.map +1 -0
  56. package/dist/generated/filter-slots.js +3 -0
  57. package/dist/generated/filter-slots.js.map +1 -0
  58. package/dist/generated/gap-styles.d.ts +3 -0
  59. package/dist/generated/gap-styles.d.ts.map +1 -0
  60. package/dist/generated/gap-styles.js +4 -0
  61. package/dist/generated/gap-styles.js.map +1 -0
  62. package/dist/generated/gradient-slots.d.ts +2 -0
  63. package/dist/generated/gradient-slots.d.ts.map +1 -0
  64. package/dist/generated/gradient-slots.js +3 -0
  65. package/dist/generated/gradient-slots.js.map +1 -0
  66. package/dist/generated/safe-area.d.ts +1 -1
  67. package/dist/generated/safe-area.d.ts.map +1 -1
  68. package/dist/generated/safe-area.js +1 -1
  69. package/dist/generated/safe-area.js.map +1 -1
  70. package/dist/generated/shadow-slots.d.ts +2 -0
  71. package/dist/generated/shadow-slots.d.ts.map +1 -0
  72. package/dist/generated/shadow-slots.js +3 -0
  73. package/dist/generated/shadow-slots.js.map +1 -0
  74. package/dist/generated/spread-styles.d.ts +2 -0
  75. package/dist/generated/spread-styles.d.ts.map +1 -0
  76. package/dist/generated/spread-styles.js +3 -0
  77. package/dist/generated/spread-styles.js.map +1 -0
  78. package/dist/generated/text-inheritance-protocol.d.ts +3 -0
  79. package/dist/generated/text-inheritance-protocol.d.ts.map +1 -0
  80. package/dist/generated/text-inheritance-protocol.js +3 -0
  81. package/dist/generated/text-inheritance-protocol.js.map +1 -0
  82. package/dist/generated/text-size-context.d.ts +2 -0
  83. package/dist/generated/text-size-context.d.ts.map +1 -0
  84. package/dist/generated/text-size-context.js +3 -0
  85. package/dist/generated/text-size-context.js.map +1 -0
  86. package/dist/gradient-slots.d.ts +19 -0
  87. package/dist/gradient-slots.d.ts.map +1 -0
  88. package/dist/gradient-slots.js +61 -0
  89. package/dist/gradient-slots.js.map +1 -0
  90. package/dist/hooks.native.js +1 -1
  91. package/dist/index.d.ts +6 -3
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +6 -3
  94. package/dist/index.js.map +1 -1
  95. package/dist/inline-edges.d.ts +8 -0
  96. package/dist/inline-edges.d.ts.map +1 -0
  97. package/dist/inline-edges.js +13 -0
  98. package/dist/inline-edges.js.map +1 -0
  99. package/dist/presence-context.d.ts +15 -0
  100. package/dist/presence-context.d.ts.map +1 -0
  101. package/dist/presence-context.js +11 -0
  102. package/dist/presence-context.js.map +1 -0
  103. package/dist/project.d.ts +8 -0
  104. package/dist/project.d.ts.map +1 -1
  105. package/dist/project.js +7 -0
  106. package/dist/project.js.map +1 -1
  107. package/dist/project.native.d.ts +1 -1
  108. package/dist/project.native.d.ts.map +1 -1
  109. package/dist/project.native.js +1 -1
  110. package/dist/project.native.js.map +1 -1
  111. package/dist/responder.d.ts +34 -0
  112. package/dist/responder.d.ts.map +1 -1
  113. package/dist/responder.js +52 -0
  114. package/dist/responder.js.map +1 -1
  115. package/dist/runtime-transition.native.d.ts +37 -0
  116. package/dist/runtime-transition.native.d.ts.map +1 -0
  117. package/dist/runtime-transition.native.js +252 -0
  118. package/dist/runtime-transition.native.js.map +1 -0
  119. package/dist/safe-area.native.d.ts +12 -0
  120. package/dist/safe-area.native.d.ts.map +1 -1
  121. package/dist/safe-area.native.js +44 -21
  122. package/dist/safe-area.native.js.map +1 -1
  123. package/dist/shadow-slots.d.ts +26 -0
  124. package/dist/shadow-slots.d.ts.map +1 -0
  125. package/dist/shadow-slots.js +59 -0
  126. package/dist/shadow-slots.js.map +1 -0
  127. package/dist/spread-styles.d.ts +16 -0
  128. package/dist/spread-styles.d.ts.map +1 -0
  129. package/dist/spread-styles.js +57 -0
  130. package/dist/spread-styles.js.map +1 -0
  131. package/dist/text-inheritance.d.ts +30 -0
  132. package/dist/text-inheritance.d.ts.map +1 -0
  133. package/dist/text-inheritance.js +42 -0
  134. package/dist/text-inheritance.js.map +1 -0
  135. package/dist/text-style.d.ts +8 -0
  136. package/dist/text-style.d.ts.map +1 -0
  137. package/dist/text-style.js +34 -0
  138. package/dist/text-style.js.map +1 -0
  139. package/dist/transform-slots.d.ts +1 -1
  140. package/dist/transform-slots.d.ts.map +1 -1
  141. package/dist/transform-slots.js +12 -5
  142. package/dist/transform-slots.js.map +1 -1
  143. package/package.json +38 -2
  144. package/src/authored-edges.ts +94 -0
  145. package/src/authored-gap.ts +41 -0
  146. package/src/class-name.native.ts +10 -0
  147. package/src/class-resolver.ts +574 -20
  148. package/src/class-transition.ts +71 -0
  149. package/src/color-transition.ts +5 -0
  150. package/src/cx.ts +18 -0
  151. package/src/dom-style.ts +3 -0
  152. package/src/filter-slots.ts +67 -0
  153. package/src/gap-styles.ts +11 -0
  154. package/src/generated/animated.ts +15 -0
  155. package/src/generated/authored-edges.ts +2 -0
  156. package/src/generated/class-resolver.ts +8 -1
  157. package/src/generated/filter-slots.ts +2 -0
  158. package/src/generated/gap-styles.ts +3 -0
  159. package/src/generated/gradient-slots.ts +2 -0
  160. package/src/generated/safe-area.ts +5 -1
  161. package/src/generated/shadow-slots.ts +2 -0
  162. package/src/generated/spread-styles.ts +2 -0
  163. package/src/generated/text-inheritance-protocol.ts +9 -0
  164. package/src/generated/text-size-context.ts +2 -0
  165. package/src/gradient-slots.ts +73 -0
  166. package/src/hooks.native.ts +1 -1
  167. package/src/index.ts +17 -2
  168. package/src/inline-edges.ts +14 -0
  169. package/src/presence-context.ts +27 -0
  170. package/src/project.native.ts +1 -1
  171. package/src/project.ts +9 -0
  172. package/src/responder.ts +52 -0
  173. package/src/runtime-transition.native.tsx +324 -0
  174. package/src/safe-area.native.ts +59 -24
  175. package/src/shadow-slots.ts +78 -0
  176. package/src/spread-styles.ts +81 -0
  177. package/src/text-inheritance.ts +60 -0
  178. package/src/text-style.ts +35 -0
  179. package/src/transform-slots.ts +11 -3
@@ -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
+ }
@@ -19,6 +19,11 @@ function rgba(color: string): [number, number, number, number] | null {
19
19
  ]
20
20
  }
21
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
+
22
27
  /** The visible colour at `progress`, used when an interrupted transition restarts. */
23
28
  export function blendColor(from: string, to: string, progress: number) {
24
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,67 @@
1
+ // Slot numbers and function strings come from the compiler, not a second
2
+ // Tailwind ordering table. Only split filters and candidate maps import this.
3
+ type Style = Record<string, unknown>
4
+ type FilterStyle = Style | false | null | undefined | readonly FilterStyle[]
5
+ export interface FilterSlots {
6
+ mode: 'slots' | 'none' | 'authored'
7
+ slots?: readonly (readonly [number, string])[]
8
+ authored?: string
9
+ }
10
+ export type FilterSpec = readonly [Style, FilterSlots]
11
+
12
+ export function hozoFilterStyles(
13
+ styles: readonly FilterStyle[],
14
+ specs: readonly FilterSpec[] | ReadonlyMap<Style, FilterSlots>,
15
+ candidates?: ReadonlyMap<Style, FilterSlots> | null,
16
+ ): Style[] {
17
+ const metadata: ReadonlyMap<Style, FilterSlots> = Array.isArray(specs)
18
+ ? new Map(specs)
19
+ : (specs as ReadonlyMap<Style, FilterSlots>)
20
+ const result: Style[] = []
21
+ const slots = new Map<number, string>()
22
+ const state = { mode: 'slots' as FilterSlots['mode'], authored: '' }
23
+ let touched = false
24
+ let opaque = false
25
+ function visit(style: FilterStyle): void {
26
+ if (!style) return
27
+ if (Array.isArray(style)) {
28
+ for (const part of style) visit(part)
29
+ return
30
+ }
31
+ const object = style as Style
32
+ // Preserve identity: transform metadata may refer to the very same entry.
33
+ // The final filter wins over these intermediate whole-chain strings.
34
+ result.push(object)
35
+ const spec = metadata.get(object) ?? candidates?.get(object)
36
+ if (!spec) {
37
+ if ('filter' in object) {
38
+ // A mixed chain with an unassessed candidate (e.g. drop-shadow)
39
+ // must retain whole-property replacement, not compose partially.
40
+ opaque = true
41
+ slots.clear()
42
+ touched = false
43
+ }
44
+ return
45
+ }
46
+ touched = true
47
+ for (const [key, value] of spec.slots ?? []) slots.set(key, value)
48
+ state.mode = spec.mode
49
+ if (spec.authored !== undefined) state.authored = spec.authored
50
+ }
51
+ for (const style of styles) visit(style)
52
+ if (touched && !(opaque && candidates !== undefined)) {
53
+ result.push({
54
+ filter:
55
+ state.mode === 'none'
56
+ ? 'none'
57
+ : state.mode === 'authored'
58
+ ? state.authored
59
+ : [...slots]
60
+ .sort(([a], [b]) => a - b)
61
+ .map(([, value]) => value)
62
+ .filter(Boolean)
63
+ .join(' '),
64
+ })
65
+ }
66
+ return result
67
+ }
@@ -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'
@@ -0,0 +1,2 @@
1
+ // Native-only: on the Web an inline style beats a class by the cascade.
2
+ export { hozoAuthoredEdges, hozoEdgeSpreadStyles } from '../authored-edges.ts'
@@ -1,2 +1,9 @@
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
+ hozoMixedTextMetricStyles,
7
+ hozoTextMetricStyles,
8
+ type StyleObject,
9
+ } from '../class-resolver.ts'
@@ -0,0 +1,2 @@
1
+ // Ordinary static filters need no runtime import.
2
+ export { hozoFilterStyles } from '../filter-slots.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'
@@ -0,0 +1,2 @@
1
+ // Only boundaries with independently active gradient registers import this.
2
+ export { hozoGradientStyles } from '../gradient-slots.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
+ // Only independently composed Native shadows need this generated leaf.
2
+ export { hozoShadowStyles } from '../shadow-slots.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,73 @@
1
+ // Values/defaults are compiler data. This joins selected gradient registers;
2
+ // it neither parses CSS nor chooses classes, conditions or precedence.
3
+ type Style = Record<string, unknown>
4
+ type Image = { kind: string; prelude: string } | string | null
5
+ export interface GradientSlots {
6
+ image?: Image
7
+ colors?: readonly (readonly [number, string | null])[]
8
+ positions?: readonly (readonly [number, string])[]
9
+ }
10
+ export interface GradientDefaults {
11
+ color: string
12
+ positions: readonly string[]
13
+ }
14
+ export type GradientSpec = readonly [Style, GradientSlots]
15
+ export type GradientStyle = Style | number | false | null | undefined | readonly GradientStyle[]
16
+
17
+ export function hozoGradientStyles(
18
+ styles: readonly GradientStyle[],
19
+ specs: readonly GradientSpec[] | ReadonlyMap<Style, GradientSlots>,
20
+ defaults: GradientDefaults,
21
+ candidates?: ReadonlyMap<Style, GradientSlots>,
22
+ ): (Style | number)[] {
23
+ const metadata: ReadonlyMap<Style, GradientSlots> = Array.isArray(specs)
24
+ ? new Map(specs)
25
+ : (specs as ReadonlyMap<Style, GradientSlots>)
26
+ const result: (Style | number)[] = []
27
+ const state: { image?: Image } = {}
28
+ const colors = new Map<number, string | null>()
29
+ const positions = new Map<number, string>()
30
+ let opaque = false
31
+ function visit(style: GradientStyle): void {
32
+ if (!style) return
33
+ if (Array.isArray(style)) {
34
+ for (const part of style) visit(part)
35
+ return
36
+ }
37
+ if (typeof style === 'number') {
38
+ // A registered RN style ID cannot be inspected without RN. Preserve
39
+ // the previous whole-property path rather than overriding unseen data.
40
+ opaque = true
41
+ result.push(style)
42
+ return
43
+ }
44
+ const object = style as Style
45
+ result.push(object)
46
+ const slots = metadata.get(object) ?? candidates?.get(object)
47
+ if (!slots) {
48
+ if ('backgroundImage' in object) {
49
+ state.image = undefined
50
+ colors.clear()
51
+ positions.clear()
52
+ }
53
+ return
54
+ }
55
+ if (slots.image !== undefined) state.image = slots.image
56
+ for (const [key, value] of slots.colors ?? []) colors.set(key, value)
57
+ for (const [key, value] of slots.positions ?? []) positions.set(key, value)
58
+ }
59
+ for (const style of styles) visit(style)
60
+ const image = state.image
61
+ if (opaque || image === undefined) return result
62
+ let value: string
63
+ if (image === null) value = 'none'
64
+ else if (typeof image === 'string') value = image
65
+ else {
66
+ const stop = (index: number) =>
67
+ `${colors.get(index) ?? defaults.color} ${positions.get(index) ?? defaults.positions[index]}`
68
+ const stops = [stop(0), ...(colors.get(1) ? [stop(1)] : []), stop(2)]
69
+ value = `${image.kind}(${[...(image.prelude ? [image.prelude] : []), ...stops].join(', ')})`
70
+ }
71
+ result.push({ backgroundImage: value })
72
+ return result
73
+ }
@@ -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,16 +28,30 @@ 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'
@@ -47,4 +61,5 @@ export {
47
61
  HozoTextSizeContext,
48
62
  useHozoTextSize,
49
63
  } from './text-size.ts'
64
+ export { hozoSplitTextStyle } from './text-style.ts'
50
65
  export { hozoViewBase, hozoViewClassName } from './view-base.ts'
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Each inline family as `[start, end, left, right]`, in React Native's keys.
3
+ * Its own module so the class resolver, which reads it, does not also load
4
+ * the authored-edge and spread composers.
5
+ */
6
+ export const INLINE_EDGES = [
7
+ ['paddingStart', 'paddingEnd', 'paddingLeft', 'paddingRight'],
8
+ ['marginStart', 'marginEnd', 'marginLeft', 'marginRight'],
9
+ ['start', 'end', 'left', 'right'],
10
+ ['borderStartWidth', 'borderEndWidth', 'borderLeftWidth', 'borderRightWidth'],
11
+ ['borderStartColor', 'borderEndColor', 'borderLeftColor', 'borderRightColor'],
12
+ ] as const
13
+
14
+ export type InlineFamily = (typeof INLINE_EDGES)[number]
@@ -0,0 +1,27 @@
1
+ // What `Presence` tells the elements that animate out inside it, on
2
+ // Native (decision 007, amendment 1).
3
+ //
4
+ // On Web the same thing travels as an attribute, `data-state`, and CSS
5
+ // does the rest. React Native has no attributes to select on, so the
6
+ // state is a context instead, and `HozoAnimated` -- the component the
7
+ // compiler puts in place of an element with a `data-[state=closed]:`
8
+ // class -- reads it.
9
+
10
+ import { createContext } from 'react'
11
+
12
+ export type PresenceState = 'open' | 'closed'
13
+
14
+ export interface PresenceContextValue {
15
+ state: PresenceState
16
+ /**
17
+ * Called by an element that will animate out, once, on mount. `Presence`
18
+ * waits for every registered element before it removes its child, and
19
+ * removes it at once when none registered. The returned function
20
+ * unregisters.
21
+ */
22
+ register(id: symbol, durationMs: number): () => void
23
+ /** Called by a registered element when its exit animation has ended. */
24
+ done(id: symbol): void
25
+ }
26
+
27
+ export const PresenceContext = createContext<PresenceContextValue | null>(null)
@@ -1 +1 @@
1
- export { hozoClasses, hozoPreflight } from './project.ts'
1
+ export { hozoClasses, hozoClassTransitions, hozoPreflight } from './project.ts'
package/src/project.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createClassResolver } from './class-resolver.ts'
2
+ import type { ClassTransitionTable } from './class-transition.ts'
2
3
 
3
4
  /**
4
5
  * Project-wide Native defaults when no bundler integration supplies them.
@@ -18,3 +19,11 @@ export const hozoPreflight = true
18
19
  * what those props did before.
19
20
  */
20
21
  export const hozoClasses = createClassResolver({})
22
+
23
+ /**
24
+ * What the project's runtime-resolved classes say about transitions (#1450),
25
+ * for the same components, read through `createClassTransitions`.
26
+ * Redirected like `hozoClasses`; unconfigured, it is empty, so those
27
+ * components keep switching at once.
28
+ */
29
+ export const hozoClassTransitions: ClassTransitionTable = {}
package/src/responder.ts CHANGED
@@ -370,3 +370,55 @@ export function createResponderDomProps<T extends HTMLElement>(
370
370
  onLostPointerCapture,
371
371
  }
372
372
  }
373
+
374
+ /** The responder props by name, for a caller that has them in an untyped bag. */
375
+ export const RESPONDER_PROPS = [
376
+ 'onStartShouldSetResponder',
377
+ 'onStartShouldSetResponderCapture',
378
+ 'onMoveShouldSetResponder',
379
+ 'onMoveShouldSetResponderCapture',
380
+ 'onResponderGrant',
381
+ 'onResponderStart',
382
+ 'onResponderMove',
383
+ 'onResponderEnd',
384
+ 'onResponderRelease',
385
+ 'onResponderReject',
386
+ 'onResponderTerminate',
387
+ 'onResponderTerminationRequest',
388
+ ] as const satisfies readonly (keyof ResponderProps)[]
389
+
390
+ const latestResponderProps = new WeakMap<HTMLElement, { current: ResponderProps }>()
391
+
392
+ /**
393
+ * The responder without a hook, for a spread translated during render (#1126).
394
+ *
395
+ * `useResponderDomProps` keeps the latest props in a ref and releases the
396
+ * pointer in an effect. A compiled element's spread has neither, so the
397
+ * element it lands on holds the latest props instead: `attach` (from a
398
+ * callback ref) records them against the element, and the handlers read
399
+ * them from there, so a re-render during a gesture does not leave the
400
+ * registration with the props of the render that began it. `release`, when
401
+ * the element goes, is the hook's effect cleanup.
402
+ */
403
+ export function createSpreadResponder(props: ResponderProps) {
404
+ const elementRef: { current: HTMLElement | null } = { current: null }
405
+ const propsRef = {
406
+ get current(): ResponderProps {
407
+ const element = elementRef.current
408
+ return (element && latestResponderProps.get(element)?.current) || props
409
+ },
410
+ }
411
+ return {
412
+ handlers: createResponderDomProps(elementRef, propsRef),
413
+ attach(element: HTMLElement) {
414
+ elementRef.current = element
415
+ const box = latestResponderProps.get(element)
416
+ if (box) box.current = props
417
+ else latestResponderProps.set(element, { current: props })
418
+ },
419
+ release(element: HTMLElement) {
420
+ latestResponderProps.delete(element)
421
+ if (activeResponder?.element === element) releaseRegistration(activeResponder.props)
422
+ },
423
+ }
424
+ }