@hozo/primitives 0.3.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 (176) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/README.md +1 -1
  3. package/dist/button-host-attributes.d.ts +20 -0
  4. package/dist/button-host-attributes.d.ts.map +1 -0
  5. package/dist/button-host-attributes.js +47 -0
  6. package/dist/button-host-attributes.js.map +1 -0
  7. package/dist/button-host-props.native.d.ts +8 -0
  8. package/dist/button-host-props.native.d.ts.map +1 -0
  9. package/dist/button-host-props.native.js +20 -0
  10. package/dist/button-host-props.native.js.map +1 -0
  11. package/dist/foundation.d.ts +21 -3
  12. package/dist/foundation.d.ts.map +1 -1
  13. package/dist/foundation.js +41 -5
  14. package/dist/foundation.js.map +1 -1
  15. package/dist/foundation.native.d.ts +27 -7
  16. package/dist/foundation.native.d.ts.map +1 -1
  17. package/dist/foundation.native.js +18 -3
  18. package/dist/foundation.native.js.map +1 -1
  19. package/dist/generated/button-dom-props.d.ts +11 -0
  20. package/dist/generated/button-dom-props.d.ts.map +1 -0
  21. package/dist/generated/button-dom-props.js +132 -0
  22. package/dist/generated/button-dom-props.js.map +1 -0
  23. package/dist/generated/button-props.d.ts +3 -0
  24. package/dist/generated/button-props.d.ts.map +1 -0
  25. package/dist/generated/button-props.js +5 -0
  26. package/dist/generated/button-props.js.map +1 -0
  27. package/dist/generated/button-props.native.d.ts +2 -0
  28. package/dist/generated/button-props.native.d.ts.map +1 -0
  29. package/dist/generated/button-props.native.js +2 -0
  30. package/dist/generated/button-props.native.js.map +1 -0
  31. package/dist/generated/inherited-label.d.ts +2 -0
  32. package/dist/generated/inherited-label.d.ts.map +1 -0
  33. package/dist/generated/inherited-label.js +3 -0
  34. package/dist/generated/inherited-label.js.map +1 -0
  35. package/dist/generated/inherited-pressable.d.ts +2 -0
  36. package/dist/generated/inherited-pressable.d.ts.map +1 -0
  37. package/dist/generated/inherited-pressable.js +3 -0
  38. package/dist/generated/inherited-pressable.js.map +1 -0
  39. package/dist/generated/inherited-relative-text.d.ts +2 -0
  40. package/dist/generated/inherited-relative-text.d.ts.map +1 -0
  41. package/dist/generated/inherited-relative-text.js +3 -0
  42. package/dist/generated/inherited-relative-text.js.map +1 -0
  43. package/dist/generated/inherited-text.d.ts +2 -0
  44. package/dist/generated/inherited-text.d.ts.map +1 -0
  45. package/dist/generated/inherited-text.js +3 -0
  46. package/dist/generated/inherited-text.js.map +1 -0
  47. package/dist/generated/inherited-view.d.ts +2 -0
  48. package/dist/generated/inherited-view.d.ts.map +1 -0
  49. package/dist/generated/inherited-view.js +3 -0
  50. package/dist/generated/inherited-view.js.map +1 -0
  51. package/dist/generated/native-disabled.d.ts +2 -0
  52. package/dist/generated/native-disabled.d.ts.map +1 -0
  53. package/dist/generated/native-disabled.js +2 -0
  54. package/dist/generated/native-disabled.js.map +1 -0
  55. package/dist/generated/text-input-dom-props.d.ts +7 -0
  56. package/dist/generated/text-input-dom-props.d.ts.map +1 -0
  57. package/dist/generated/text-input-dom-props.js +130 -0
  58. package/dist/generated/text-input-dom-props.js.map +1 -0
  59. package/dist/generated/text-input.native.d.ts +1 -1
  60. package/dist/generated/text-input.native.d.ts.map +1 -1
  61. package/dist/generated/text-input.native.js +1 -1
  62. package/dist/generated/text-input.native.js.map +1 -1
  63. package/dist/generated/view-dom-props.d.ts +8 -0
  64. package/dist/generated/view-dom-props.d.ts.map +1 -0
  65. package/dist/generated/view-dom-props.js +241 -0
  66. package/dist/generated/view-dom-props.js.map +1 -0
  67. package/dist/inherited-label.native.d.ts +8 -0
  68. package/dist/inherited-label.native.d.ts.map +1 -0
  69. package/dist/inherited-label.native.js +12 -0
  70. package/dist/inherited-label.native.js.map +1 -0
  71. package/dist/inherited-pressable.native.d.ts +11 -0
  72. package/dist/inherited-pressable.native.d.ts.map +1 -0
  73. package/dist/inherited-pressable.native.js +75 -0
  74. package/dist/inherited-pressable.native.js.map +1 -0
  75. package/dist/inherited-relative-text.native.d.ts +13 -0
  76. package/dist/inherited-relative-text.native.d.ts.map +1 -0
  77. package/dist/inherited-relative-text.native.js +16 -0
  78. package/dist/inherited-relative-text.native.js.map +1 -0
  79. package/dist/inherited-text-scope.d.ts +8 -0
  80. package/dist/inherited-text-scope.d.ts.map +1 -0
  81. package/dist/inherited-text-scope.js +10 -0
  82. package/dist/inherited-text-scope.js.map +1 -0
  83. package/dist/inherited-text-style.native.d.ts +5 -0
  84. package/dist/inherited-text-style.native.d.ts.map +1 -0
  85. package/dist/inherited-text-style.native.js +30 -0
  86. package/dist/inherited-text-style.native.js.map +1 -0
  87. package/dist/inherited-text.native.d.ts +5 -0
  88. package/dist/inherited-text.native.d.ts.map +1 -0
  89. package/dist/inherited-text.native.js +18 -0
  90. package/dist/inherited-text.native.js.map +1 -0
  91. package/dist/inherited-view.native.d.ts +9 -0
  92. package/dist/inherited-view.native.d.ts.map +1 -0
  93. package/dist/inherited-view.native.js +17 -0
  94. package/dist/inherited-view.native.js.map +1 -0
  95. package/dist/link.d.ts +4 -3
  96. package/dist/link.d.ts.map +1 -1
  97. package/dist/link.js +9 -1
  98. package/dist/link.js.map +1 -1
  99. package/dist/link.native.d.ts +1 -1
  100. package/dist/link.native.d.ts.map +1 -1
  101. package/dist/link.native.js +7 -1
  102. package/dist/link.native.js.map +1 -1
  103. package/dist/native-disabled.d.ts +13 -0
  104. package/dist/native-disabled.d.ts.map +1 -0
  105. package/dist/native-disabled.js +13 -0
  106. package/dist/native-disabled.js.map +1 -0
  107. package/dist/presence.native.d.ts.map +1 -1
  108. package/dist/presence.native.js +1 -1
  109. package/dist/presence.native.js.map +1 -1
  110. package/dist/pressable.d.ts.map +1 -1
  111. package/dist/pressable.js +8 -1
  112. package/dist/pressable.js.map +1 -1
  113. package/dist/pressable.native.d.ts +10 -1
  114. package/dist/pressable.native.d.ts.map +1 -1
  115. package/dist/pressable.native.js +44 -45
  116. package/dist/pressable.native.js.map +1 -1
  117. package/dist/text-color-transition.native.d.ts +12 -0
  118. package/dist/text-color-transition.native.d.ts.map +1 -0
  119. package/dist/text-color-transition.native.js +87 -0
  120. package/dist/text-color-transition.native.js.map +1 -0
  121. package/dist/text-input-props.native.d.ts +10 -0
  122. package/dist/text-input-props.native.d.ts.map +1 -0
  123. package/dist/text-input-props.native.js +15 -0
  124. package/dist/text-input-props.native.js.map +1 -0
  125. package/dist/text-input.native.d.ts +19 -0
  126. package/dist/text-input.native.d.ts.map +1 -0
  127. package/dist/text-input.native.js +32 -0
  128. package/dist/text-input.native.js.map +1 -0
  129. package/package.json +51 -7
  130. package/src/button-host-attributes.ts +56 -0
  131. package/src/button-host-props.native.ts +22 -0
  132. package/src/foundation.native.tsx +45 -6
  133. package/src/foundation.tsx +74 -4
  134. package/src/generated/button-dom-props.ts +127 -0
  135. package/src/generated/button-props.native.ts +1 -0
  136. package/src/generated/button-props.ts +4 -0
  137. package/src/generated/inherited-label.ts +2 -0
  138. package/src/generated/inherited-pressable.ts +2 -0
  139. package/src/generated/inherited-relative-text.ts +2 -0
  140. package/src/generated/inherited-text.ts +2 -0
  141. package/src/generated/inherited-view.ts +2 -0
  142. package/src/generated/native-disabled.ts +1 -0
  143. package/src/generated/text-input-dom-props.ts +128 -0
  144. package/src/generated/text-input.native.ts +1 -4
  145. package/src/generated/view-dom-props.ts +267 -0
  146. package/src/inherited-label.native.tsx +28 -0
  147. package/src/inherited-pressable.native.tsx +152 -0
  148. package/src/inherited-relative-text.native.tsx +22 -0
  149. package/src/inherited-text-scope.tsx +27 -0
  150. package/src/inherited-text-style.native.ts +35 -0
  151. package/src/inherited-text.native.tsx +32 -0
  152. package/src/inherited-view.native.tsx +37 -0
  153. package/src/link.native.tsx +17 -13
  154. package/src/link.ts +12 -0
  155. package/src/native-disabled.ts +23 -0
  156. package/src/presence.native.tsx +1 -1
  157. package/src/pressable.native.tsx +70 -42
  158. package/src/pressable.ts +8 -1
  159. package/src/text-color-transition.native.ts +96 -0
  160. package/src/text-input-props.native.ts +26 -0
  161. package/src/text-input.native.tsx +57 -0
  162. package/dist/generated/animated.d.ts +0 -2
  163. package/dist/generated/animated.d.ts.map +0 -1
  164. package/dist/generated/animated.js +0 -3
  165. package/dist/generated/animated.js.map +0 -1
  166. package/dist/presence-context.d.ts +0 -15
  167. package/dist/presence-context.d.ts.map +0 -1
  168. package/dist/presence-context.js +0 -11
  169. package/dist/presence-context.js.map +0 -1
  170. package/dist/runtime-transition.native.d.ts +0 -30
  171. package/dist/runtime-transition.native.d.ts.map +0 -1
  172. package/dist/runtime-transition.native.js +0 -183
  173. package/dist/runtime-transition.native.js.map +0 -1
  174. package/src/generated/animated.ts +0 -6
  175. package/src/presence-context.ts +0 -27
  176. package/src/runtime-transition.native.tsx +0 -244
@@ -0,0 +1,152 @@
1
+ import { HozoInteractionContext } from '@hozo/behaviors/pressable-interaction'
2
+ import { canBlendColor } from '@hozo/engine'
3
+ import {
4
+ HOZO_INHERITED_TEXT_FIELDS,
5
+ type HozoInheritedTextFrame,
6
+ useHozoInheritedTextFrame,
7
+ } from '@hozo/engine/generated/text-inheritance-protocol'
8
+ import {
9
+ Children,
10
+ type ComponentPropsWithRef,
11
+ type ReactNode,
12
+ useContext,
13
+ useMemo,
14
+ useRef,
15
+ } from 'react'
16
+ import type { Pressable, StyleProp, TextStyle, ViewStyle } from 'react-native'
17
+ import { HozoInheritedText } from './inherited-text.native.tsx'
18
+ import { HozoInheritedTextScope } from './inherited-text-scope.tsx'
19
+ import { flattenInheritedTextStyle } from './inherited-text-style.native.ts'
20
+ import { HozoPressable, type HozoPressableProps } from './pressable.native.tsx'
21
+ import { useHozoTextColorTransition } from './text-color-transition.native.ts'
22
+
23
+ type Props = Omit<HozoPressableProps, 'style'> & {
24
+ style?: StyleProp<ViewStyle & TextStyle> | Exclude<HozoPressableProps['style'], undefined>
25
+ ref?: ComponentPropsWithRef<typeof Pressable>['ref']
26
+ }
27
+
28
+ /** Only the label reads/publishes typography; there is no extra native box. */
29
+ function LabelScope({
30
+ own,
31
+ resolve,
32
+ transition,
33
+ children,
34
+ }: {
35
+ own: TextStyle
36
+ resolve: HozoPressableProps['hozoTextStyle']
37
+ transition?: HozoPressableProps['hozoTransition']
38
+ children?: ReactNode
39
+ }) {
40
+ const interaction = useContext(HozoInteractionContext)
41
+ if (!interaction) throw new Error('Inherited label requires the existing Pressable owner')
42
+ // The existing owner is the only state machine. Resolve the class label
43
+ // once from its committed snapshot, then apply the owner's explicit style.
44
+ const frame = useHozoInheritedTextFrame(
45
+ flattenInheritedTextStyle([resolve?.({ ...interaction }), own]),
46
+ )
47
+ const labelled = Children.map(children, (child) =>
48
+ typeof child === 'string' || typeof child === 'number' ? (
49
+ <HozoInheritedText>{child}</HozoInheritedText>
50
+ ) : (
51
+ child
52
+ ),
53
+ )
54
+ return transition ? (
55
+ <MotionScope frame={frame} transition={transition}>
56
+ {labelled}
57
+ </MotionScope>
58
+ ) : (
59
+ <HozoInheritedTextScope frame={frame}>{labelled}</HozoInheritedTextScope>
60
+ )
61
+ }
62
+
63
+ function MotionScope({
64
+ frame,
65
+ transition,
66
+ children,
67
+ }: {
68
+ frame: HozoInheritedTextFrame
69
+ transition: NonNullable<HozoPressableProps['hozoTransition']>
70
+ children?: ReactNode
71
+ }) {
72
+ if (
73
+ typeof frame.paint.color !== 'string' ||
74
+ !canBlendColor(frame.paint.color) ||
75
+ frame.paint.motion?.color != null
76
+ )
77
+ throw new Error(
78
+ 'Native text inheritance does not assess unresolved colours or nested inherited motion',
79
+ )
80
+ const color = useHozoTextColorTransition(frame.paint.color, '', transition)
81
+ const paint = useMemo(
82
+ () => Object.freeze({ color: frame.paint.color, motion: Object.freeze({ color }) }),
83
+ [color, frame.paint.color],
84
+ )
85
+ return (
86
+ <HozoInheritedTextScope frame={{ metrics: frame.metrics, paint }}>
87
+ {children}
88
+ </HozoInheritedTextScope>
89
+ )
90
+ }
91
+
92
+ /** Internal generated ABI. Ordinary Pressable is unchanged. */
93
+ export function HozoInheritedPressable({
94
+ style,
95
+ children,
96
+ hozoTextStyle,
97
+ hozoTransition,
98
+ ...props
99
+ }: Props) {
100
+ const motion = Boolean(hozoTransition)
101
+ const initialMotion = useRef(motion)
102
+ const callback = typeof style === 'function'
103
+ const initialCallback = useRef(callback)
104
+ if (motion !== initialMotion.current)
105
+ throw new Error('Inherited colour motion does not assess changing transition presence')
106
+ if (motion && callback !== initialCallback.current)
107
+ throw new Error('Inherited colour motion does not assess changing box style ownership')
108
+ if (
109
+ hozoTransition &&
110
+ (!hozoTransition.colors || hozoTransition.opacity || hozoTransition.transform)
111
+ )
112
+ throw new Error('Native text inheritance does not assess non-colour label transitions')
113
+ const { box, own } = useMemo(() => {
114
+ if (typeof style === 'function') {
115
+ if (!hozoTransition)
116
+ throw new Error('Native text inheritance does not assess style callbacks without motion')
117
+ // Only compiler-owned box callbacks are admitted. Label classes already
118
+ // have their own resolved channel: do not run or merge them twice here.
119
+ return {
120
+ box: (state: Parameters<typeof style>[0]) => {
121
+ const flat = flattenInheritedTextStyle(style(state))
122
+ if (HOZO_INHERITED_TEXT_FIELDS.some((field) => Object.hasOwn(flat, field)))
123
+ throw new Error('Native text inheritance does not assess text in box callbacks')
124
+ if (
125
+ flat.backgroundColor != null &&
126
+ (typeof flat.backgroundColor !== 'string' || !canBlendColor(flat.backgroundColor))
127
+ )
128
+ throw new Error('Native text inheritance does not assess unresolved background colours')
129
+ return flat as ViewStyle
130
+ },
131
+ own: {},
132
+ }
133
+ }
134
+ const flat = flattenInheritedTextStyle(style)
135
+ const box = { ...flat }
136
+ const own: Record<string, unknown> = {}
137
+ for (const field of HOZO_INHERITED_TEXT_FIELDS) {
138
+ if (Object.hasOwn(flat, field)) own[field] = flat[field]
139
+ delete box[field]
140
+ }
141
+ return { box: box as ViewStyle, own }
142
+ }, [style, hozoTransition])
143
+ return (
144
+ <HozoPressable {...props} style={box} hozoTransition={callback ? hozoTransition : undefined}>
145
+ {(state) => (
146
+ <LabelScope own={own as TextStyle} resolve={hozoTextStyle} transition={hozoTransition}>
147
+ {typeof children === 'function' ? children(state) : children}
148
+ </LabelScope>
149
+ )}
150
+ </HozoPressable>
151
+ )
152
+ }
@@ -0,0 +1,22 @@
1
+ import { HozoTextSizeContext } from '@hozo/engine/generated/text-size-context'
2
+ import { type ComponentPropsWithRef, useContext } from 'react'
3
+ import type { Text } from 'react-native'
4
+ import { HozoInheritedText } from './inherited-text.native.tsx'
5
+
6
+ /**
7
+ * A semantic size ratio, not a second style resolver. The scope's legacy
8
+ * size bridge comes from the same effective metrics as the seven-field frame.
9
+ * Resolve the default once; the element's own class/explicit size wins after
10
+ * it and the shared Text publishes the result for opaque descendants too.
11
+ * Kept separate so passive Text pays no new hook or import for relative text.
12
+ */
13
+ export function HozoInheritedRelativeText({
14
+ hozoRelative,
15
+ style,
16
+ ...props
17
+ }: ComponentPropsWithRef<typeof Text> & { hozoRelative: number }) {
18
+ const base = useContext(HozoTextSizeContext)
19
+ return (
20
+ <HozoInheritedText {...props} style={[{ fontSize: Math.round(base * hozoRelative) }, style]} />
21
+ )
22
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ HozoInheritedMetricsContext,
3
+ HozoInheritedPaintContext,
4
+ type HozoInheritedTextFrame,
5
+ } from '@hozo/engine/generated/text-inheritance-protocol'
6
+ import { HozoTextSizeContext } from '@hozo/engine/generated/text-size-context'
7
+ import { type ReactNode, useContext } from 'react'
8
+
9
+ /** One stable shape, even when every local declaration is removed. */
10
+ export function HozoInheritedTextScope({
11
+ frame,
12
+ children,
13
+ }: {
14
+ frame: HozoInheritedTextFrame
15
+ children?: ReactNode
16
+ }) {
17
+ const legacy = useContext(HozoTextSizeContext)
18
+ return (
19
+ <HozoInheritedMetricsContext.Provider value={frame.metrics}>
20
+ <HozoInheritedPaintContext.Provider value={frame.paint}>
21
+ <HozoTextSizeContext.Provider value={frame.metrics.fontSize ?? legacy}>
22
+ {children}
23
+ </HozoTextSizeContext.Provider>
24
+ </HozoInheritedPaintContext.Provider>
25
+ </HozoInheritedMetricsContext.Provider>
26
+ )
27
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ HOZO_INHERITED_TEXT_FIELDS,
3
+ type HozoInheritedTextOwn,
4
+ } from '@hozo/engine/generated/text-inheritance-protocol'
5
+ import { type StyleProp, StyleSheet, type TextStyle, type ViewStyle } from 'react-native'
6
+
7
+ export type InheritedNativeStyle = StyleProp<TextStyle & ViewStyle>
8
+ const EMPTY = Object.freeze({})
9
+
10
+ export function flattenInheritedTextStyle(style: InheritedNativeStyle) {
11
+ if (typeof style === 'function')
12
+ throw new Error('Native text inheritance does not assess style callbacks')
13
+ // Read static records without cloning them. Only the View host needs its
14
+ // own normalized copy; the compiler's/source owner's style is never edited.
15
+ const flat = (StyleSheet.flatten(style) ?? EMPTY) as Record<string, unknown>
16
+ for (const name of ['fontFamily', 'fontVariant', 'fontStyle']) {
17
+ if (flat[name] != null) throw new Error(`Native text inheritance does not assess ${name}`)
18
+ }
19
+ // This internal first slice accepts resolved seven-field frames, not
20
+ // Animated nodes or opaque platform colors. Do not silently certify them.
21
+ for (const name of HOZO_INHERITED_TEXT_FIELDS) {
22
+ const value = flat[name]
23
+ if (value == null) continue
24
+ const numeric = name === 'fontSize' || name === 'lineHeight' || name === 'letterSpacing'
25
+ const textual = name === 'textAlign' || name === 'textTransform'
26
+ if (
27
+ (numeric && typeof value !== 'number') ||
28
+ (textual && typeof value !== 'string') ||
29
+ (!numeric && !textual && typeof value !== 'string' && typeof value !== 'number') ||
30
+ (typeof value === 'number' && !Number.isFinite(value))
31
+ )
32
+ throw new Error(`Native text inheritance does not assess ${name}`)
33
+ }
34
+ return flat as typeof flat & HozoInheritedTextOwn
35
+ }
@@ -0,0 +1,32 @@
1
+ import { useHozoInheritedTextFrame } from '@hozo/engine/generated/text-inheritance-protocol'
2
+ import type { ComponentPropsWithRef, ElementType } from 'react'
3
+ import { Animated, Text, type TextProps } from 'react-native'
4
+ import { HozoInheritedTextScope } from './inherited-text-scope.tsx'
5
+ import { flattenInheritedTextStyle } from './inherited-text-style.native.ts'
6
+
7
+ const AnimatedText: ElementType = Animated.createAnimatedComponent(Text)
8
+
9
+ /** @internal Generated ABI; ordinary output does not import it. */
10
+ export function HozoInheritedText({
11
+ style,
12
+ children,
13
+ ...props
14
+ }: ComponentPropsWithRef<typeof Text>) {
15
+ const frame = useHozoInheritedTextFrame(flattenInheritedTextStyle(style))
16
+ // Local overrides mask the shared value but retain this host kind. Toggling
17
+ // an own colour must not remount nested state or allocate another timeline.
18
+ const Component = frame.paint.motion ? AnimatedText : Text
19
+ const paint = frame.paint.motion
20
+ ? { color: frame.paint.motion.color ?? frame.paint.color }
21
+ : frame.paint
22
+ return (
23
+ <HozoInheritedTextScope frame={frame}>
24
+ <Component
25
+ {...props}
26
+ style={[style, frame.metrics as TextProps['style'], paint as TextProps['style']]}
27
+ >
28
+ {children}
29
+ </Component>
30
+ </HozoInheritedTextScope>
31
+ )
32
+ }
@@ -0,0 +1,37 @@
1
+ import {
2
+ HOZO_INHERITED_TEXT_FIELDS,
3
+ useHozoInheritedTextFrame,
4
+ } from '@hozo/engine/generated/text-inheritance-protocol'
5
+ import { Children, type ComponentPropsWithRef } from 'react'
6
+ import { View, type ViewProps } from 'react-native'
7
+ import { HozoInheritedText } from './inherited-text.native.tsx'
8
+ import { HozoInheritedTextScope } from './inherited-text-scope.tsx'
9
+ import {
10
+ flattenInheritedTextStyle,
11
+ type InheritedNativeStyle,
12
+ } from './inherited-text-style.native.ts'
13
+
14
+ export interface HozoInheritedViewProps extends Omit<ComponentPropsWithRef<typeof View>, 'style'> {
15
+ style?: InheritedNativeStyle
16
+ }
17
+
18
+ /** @internal Publish owner data before removing invalid host View fields. */
19
+ export function HozoInheritedView({ style, children, ...props }: HozoInheritedViewProps) {
20
+ const own = flattenInheritedTextStyle(style)
21
+ const frame = useHozoInheritedTextFrame(own)
22
+ const rendered = { ...own }
23
+ for (const name of HOZO_INHERITED_TEXT_FIELDS) delete rendered[name]
24
+ return (
25
+ <HozoInheritedTextScope frame={frame}>
26
+ <View {...props} style={rendered as ViewProps['style']}>
27
+ {Children.map(children, (child) =>
28
+ typeof child === 'string' || typeof child === 'number' ? (
29
+ <HozoInheritedText>{child}</HozoInheritedText>
30
+ ) : (
31
+ child
32
+ ),
33
+ )}
34
+ </View>
35
+ </HozoInheritedTextScope>
36
+ )
37
+ }
@@ -6,6 +6,7 @@ import {
6
6
  } from '@hozo/engine/navigation'
7
7
  import { type ComponentPropsWithRef, type ElementType, type ReactNode, useRef } from 'react'
8
8
  import { Linking, Pressable, type PressableProps } from 'react-native'
9
+ import { nativeDisabledProps } from './native-disabled.ts'
9
10
  import type { HozoPressable } from './pressable.native.tsx'
10
11
 
11
12
  type LinkHost = typeof Pressable | typeof HozoPressable
@@ -47,19 +48,20 @@ export type HozoLinkProps<Host extends LinkHost = typeof Pressable> =
47
48
  * or navigation. The type-only import keeps that machinery out of ordinary
48
49
  * links' Metro graph, where unused static imports would still cost modules.
49
50
  */
50
- export function HozoLink<Host extends LinkHost = typeof Pressable>({
51
- hozoLinkComponent,
52
- href,
53
- external,
54
- replace,
55
- prefetch,
56
- onPress,
57
- onPressIn,
58
- disabled,
59
- children,
60
- accessibilityRole = 'link',
61
- ...props
62
- }: HozoLinkProps<Host>) {
51
+ export function HozoLink<Host extends LinkHost = typeof Pressable>(input: HozoLinkProps<Host>) {
52
+ const {
53
+ hozoLinkComponent,
54
+ href,
55
+ external,
56
+ replace,
57
+ prefetch,
58
+ onPress,
59
+ onPressIn,
60
+ disabled,
61
+ children,
62
+ accessibilityRole = 'link',
63
+ ...props
64
+ } = nativeDisabledProps(input)
63
65
  const Component: ElementType = hozoLinkComponent ?? Pressable
64
66
  const navigation = useHozoNavigation()
65
67
  const prefetchedHref = useRef<string | null>(null)
@@ -69,6 +71,7 @@ export function HozoLink<Host extends LinkHost = typeof Pressable>({
69
71
  disabled={disabled}
70
72
  accessibilityRole={accessibilityRole}
71
73
  onPressIn={(event: Parameters<NonNullable<PressableProps['onPressIn']>>[0]) => {
74
+ if (disabled) return
72
75
  onPressIn?.(event)
73
76
  if (prefetch && !disabled && prefetchedHref.current !== href) {
74
77
  prefetchedHref.current = href
@@ -76,6 +79,7 @@ export function HozoLink<Host extends LinkHost = typeof Pressable>({
76
79
  }
77
80
  }}
78
81
  onPress={(event: Parameters<NonNullable<PressableProps['onPress']>>[0]) => {
82
+ if (disabled) return
79
83
  onPress?.(event)
80
84
  if (!event.defaultPrevented) {
81
85
  void activateHozoNavigation(navigation, { href, external, replace }, Linking.openURL)
package/src/link.ts CHANGED
@@ -46,6 +46,7 @@ export interface HozoLinkProps
46
46
  accessibilityHint?: string
47
47
  accessibilityRole?: string
48
48
  disabled?: boolean
49
+ focusable?: boolean
49
50
  /** Leaves the app: `_blank` and a `rel` that severs `window.opener`. */
50
51
  external?: boolean
51
52
  /** Ask an installed router to replace its current history entry. */
@@ -71,6 +72,9 @@ export function HozoLink({
71
72
  accessibilityHint,
72
73
  accessibilityRole,
73
74
  disabled,
75
+ focusable,
76
+ tabIndex,
77
+ onAuxClick,
74
78
  external,
75
79
  replace,
76
80
  prefetch,
@@ -104,6 +108,11 @@ export function HozoLink({
104
108
  // There is no `disabled` on an anchor. The pair below is what a
105
109
  // disabled link is: announced as unavailable, and not followed.
106
110
  'aria-disabled': disabled ? true : undefined,
111
+ // HTML anchors have no disabled state. Do not let even an explicit
112
+ // positive tabindex put an unavailable destination in the Tab order.
113
+ tabIndex: disabled
114
+ ? -1
115
+ : (tabIndex ?? (focusable === undefined ? undefined : focusable ? 0 : -1)),
107
116
  // `disabled:` compiles to `[data-hozo-disabled]` rather than to
108
117
  // `:disabled`, which matches form controls only. Without the
109
118
  // attribute the utility silently stops matching on this element
@@ -119,6 +128,9 @@ export function HozoLink({
119
128
  event.preventDefault()
120
129
  }
121
130
  : onPress,
131
+ onAuxClick: disabled
132
+ ? (event: React.MouseEvent<HTMLAnchorElement>) => event.preventDefault()
133
+ : onAuxClick,
122
134
  },
123
135
  children,
124
136
  )
@@ -0,0 +1,23 @@
1
+ import type { AccessibilityState } from 'react-native'
2
+
3
+ interface DisabledOwner {
4
+ disabled?: boolean | null
5
+ accessibilityState?: AccessibilityState | null
6
+ }
7
+
8
+ type DisabledResult<T extends DisabledOwner> = Omit<T, keyof DisabledOwner> & {
9
+ disabled?: T['disabled'] | boolean
10
+ accessibilityState?: T['accessibilityState'] | AccessibilityState
11
+ }
12
+
13
+ /** Keep behavior and announcement on the same canonical unavailable fact. */
14
+ export function nativeDisabledProps<T extends DisabledOwner>(props: T): DisabledResult<T> {
15
+ const state = props.accessibilityState
16
+ const flag = props.disabled
17
+ const stateDisabled = state?.disabled === true
18
+ const disabled = Boolean(flag || stateDisabled)
19
+ // Ordinary enabled controls and already-normalized compiled props need
20
+ // neither a new props object nor a second accessibility-state object.
21
+ if (!disabled || (flag === true && stateDisabled)) return props
22
+ return { ...props, disabled, accessibilityState: stateDisabled ? state : { ...state, disabled } }
23
+ }
@@ -8,8 +8,8 @@
8
8
  // The Web half is `./presence.tsx`. Both are written against the same
9
9
  // class: `data-[state=closed]:`.
10
10
 
11
+ import { PresenceContext, type PresenceContextValue } from '@hozo/engine/generated/animated'
11
12
  import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'
12
- import { PresenceContext, type PresenceContextValue } from './presence-context.ts'
13
13
 
14
14
  export interface PresenceProps {
15
15
  /** Whether the child is shown. Turning it false starts the exit. */
@@ -1,8 +1,16 @@
1
- import { usePressableInteraction } from '@hozo/behaviors/pressable-interaction'
1
+ import {
2
+ HozoInteractionContext,
3
+ usePressableInteraction,
4
+ } from '@hozo/behaviors/pressable-interaction'
2
5
  import { blendColor } from '@hozo/engine'
3
6
  import {
7
+ Children,
8
+ type Context,
9
+ cloneElement,
4
10
  createContext,
5
11
  type ElementType,
12
+ isValidElement,
13
+ type ReactElement,
6
14
  type ReactNode,
7
15
  useCallback,
8
16
  useContext,
@@ -28,6 +36,8 @@ import {
28
36
  type TextStyle,
29
37
  type ViewStyle,
30
38
  } from 'react-native'
39
+ import { nativeDisabledProps } from './native-disabled.ts'
40
+ import { useHozoTextColorTransition } from './text-color-transition.native.ts'
31
41
 
32
42
  export interface HozoTransition {
33
43
  duration: number
@@ -49,6 +59,43 @@ export interface HozoPressableProps extends Omit<PressableProps, 'style'> {
49
59
  hozoTransition?: HozoTransition
50
60
  /** Enables per-element pointer/keyboard modality inference. */
51
61
  hozoFocusVisible?: boolean
62
+ /**
63
+ * The text styles this element's class list carries for its label, by
64
+ * state -- what a `<button>` passes to its text on the Web (#876). The
65
+ * compiler writes it when the label is not in the source it can see, so
66
+ * it arrives as `children` and is styled here: a string is put in a
67
+ * `Text`, and a direct `Text` child has these merged ahead of its own.
68
+ * A `Text` deeper inside is not reached (#950).
69
+ */
70
+ hozoTextStyle?: (state: HozoPressableState) => StyleProp<TextStyle>
71
+ }
72
+
73
+ /** A component a label can be: React Native's `Text`, `HozoText`, or one marked so. */
74
+ function isLabelText(child: ReactElement): boolean {
75
+ const type = child.type as { hozoLabelText?: boolean } | string
76
+ return (
77
+ type === Text || type === HozoText || (typeof type !== 'string' && type?.hozoLabelText === true)
78
+ )
79
+ }
80
+
81
+ /** `children` with `label` handed to the text among them, one level deep. */
82
+ function withLabelStyle(children: ReactNode, label: StyleProp<TextStyle>): ReactNode {
83
+ return Children.map(children, (child) => {
84
+ if (typeof child === 'string' || typeof child === 'number') {
85
+ return <Text style={label}>{child}</Text>
86
+ }
87
+ if (!isValidElement<{ style?: unknown }>(child) || !isLabelText(child)) return child
88
+ const own = child.props.style
89
+ return cloneElement(child, {
90
+ style:
91
+ typeof own === 'function'
92
+ ? (state: HozoPressableState) => [
93
+ label,
94
+ (own as (s: HozoPressableState) => unknown)(state),
95
+ ]
96
+ : [label, own],
97
+ } as { style: unknown })
98
+ })
52
99
  }
53
100
 
54
101
  const AnimatedPressable = Animated.createAnimatedComponent(Pressable)
@@ -87,7 +134,8 @@ export function pressableFor(transition: HozoTransition | undefined): ElementTyp
87
134
  }
88
135
  const AnimatedText = Animated.createAnimatedComponent(Text)
89
136
  type InteractionContextValue = HozoPressableState & { transition?: HozoTransition }
90
- const InteractionContext = createContext<InteractionContextValue | null>(null)
137
+ // Shared with `@hozo/patterns`' pressable, which provides it too (#974).
138
+ const InteractionContext = HozoInteractionContext as Context<InteractionContextValue | null>
91
139
  type AnimationDriver = { current: ((state: HozoPressableState) => void) | null }
92
140
  const AnimationDriverContext = createContext<AnimationDriver | null>(null)
93
141
 
@@ -193,8 +241,11 @@ export function HozoPressable({
193
241
  onKeyDown,
194
242
  hozoTransition,
195
243
  hozoFocusVisible = false,
244
+ hozoTextStyle,
245
+ children,
196
246
  ...props
197
247
  }: HozoPressableProps) {
248
+ props = nativeDisabledProps(props)
198
249
  // Keep the event/context owner mounted when motion is added or removed.
199
250
  // Only the optional animation child owns nodes and progress listeners.
200
251
  const driver = useRef<((state: HozoPressableState) => void) | null>(null)
@@ -218,9 +269,21 @@ export function HozoPressable({
218
269
  // Assemble native props once, with no trailing conditional spread on the
219
270
  // hot no-motion path. Private animation data never goes through RN props.
220
271
  const Component: ElementType = hozoTransition ? TransitionPressable : Pressable
272
+ // The label's styles for the state this element is in; children given
273
+ // as a function of React Native's own press state get them too.
274
+ const label = hozoTextStyle?.({ ...interaction })
275
+ const labelled =
276
+ hozoTextStyle === undefined
277
+ ? children
278
+ : typeof children === 'function'
279
+ ? (state: PressableStateCallbackType) =>
280
+ withLabelStyle((children as (s: PressableStateCallbackType) => ReactNode)(state), label)
281
+ : withLabelStyle(children, label)
221
282
  const host = (
222
283
  <Component
223
284
  {...props}
285
+ // biome-ignore lint/correctness/noChildrenProp: a function child is React Native's own form
286
+ children={labelled}
224
287
  onHoverIn={(event: MouseEvent) => {
225
288
  handlers.hoverIn()
226
289
  onHoverIn?.(event)
@@ -499,47 +562,12 @@ function TransitionText({
499
562
  const transition = context.transition!
500
563
  const state = context
501
564
  const target = StyleSheet.flatten(resolved)?.color
502
- const progress = useRef(new Animated.Value(1)).current
503
- const animation = useRef<Animated.CompositeAnimation | null>(null)
504
- const fraction = useRef(1)
505
- const initialColor = typeof target === 'string' ? target : ''
506
- const range = useRef<ColorRange>({ from: initialColor, to: initialColor })
507
565
  const interaction = `${state.pressed}:${state.hovered}:${state.focused}:${state.focusVisible}`
508
- const previousInteraction = useRef(interaction)
509
- // Carry the state key, not just true/false. Consecutive interaction
510
- // changes can both be pending: a boolean effect dependency would skip
511
- // the second transition, even though its colour target changed.
512
- const pending =
513
- previousInteraction.current !== interaction && typeof target === 'string' ? interaction : null
514
- if (pending) {
515
- range.current = {
516
- from: blendColor(range.current.from, range.current.to, fraction.current),
517
- to: target as string,
518
- }
519
- previousInteraction.current = interaction
520
- }
521
- useEffect(() => {
522
- const listener = progress.addListener(({ value }) => {
523
- fraction.current = value
524
- })
525
- return () => {
526
- progress.removeListener(listener)
527
- animation.current?.stop()
528
- }
529
- }, [progress])
530
- useLayoutEffect(() => {
531
- if (!pending) return
532
- progress.setValue(0)
533
- fraction.current = 0
534
- animation.current = transitionTiming(progress, 1, transition, false)
535
- animation.current.start()
536
- }, [transition, pending, progress])
537
- const animatedColor = range.current.from
538
- ? progress.interpolate({
539
- inputRange: [0, 1],
540
- outputRange: [range.current.from, range.current.to],
541
- })
542
- : undefined
566
+ const animatedColor = useHozoTextColorTransition(
567
+ typeof target === 'string' ? target : undefined,
568
+ interaction,
569
+ transition,
570
+ )
543
571
  return (
544
572
  <AnimatedText {...props} style={[resolved, animatedColor ? { color: animatedColor } : null]} />
545
573
  )
package/src/pressable.ts CHANGED
@@ -326,6 +326,13 @@ export function HozoPressable({
326
326
  HozoLink,
327
327
  {
328
328
  ...common,
329
+ // common is already DOM-shaped. HozoLink normalizes its canonical
330
+ // identity/name props itself; omitting these let its undefined
331
+ // defaults overwrite the id and label just passed in common.
332
+ nativeID,
333
+ testID,
334
+ accessibilityLabel,
335
+ accessibilityHint,
329
336
  ref: setRef as Ref<HTMLAnchorElement>,
330
337
  href,
331
338
  external,
@@ -335,7 +342,7 @@ export function HozoPressable({
335
342
  rel,
336
343
  download,
337
344
  disabled: unavailable,
338
- accessibilityRole,
345
+ accessibilityRole: accessibilityRole ?? role,
339
346
  onPress: unavailable ? undefined : (activate as never),
340
347
  onKeyDown,
341
348
  onKeyUp,