@hozo/primitives 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.
- package/CHANGELOG.md +71 -0
- package/README.md +18 -1
- package/dist/button-host-attributes.d.ts +20 -0
- package/dist/button-host-attributes.d.ts.map +1 -0
- package/dist/button-host-attributes.js +47 -0
- package/dist/button-host-attributes.js.map +1 -0
- package/dist/button-host-props.native.d.ts +8 -0
- package/dist/button-host-props.native.d.ts.map +1 -0
- package/dist/button-host-props.native.js +20 -0
- package/dist/button-host-props.native.js.map +1 -0
- package/dist/foundation.d.ts +27 -6
- package/dist/foundation.d.ts.map +1 -1
- package/dist/foundation.js +72 -19
- package/dist/foundation.js.map +1 -1
- package/dist/foundation.native.d.ts +27 -7
- package/dist/foundation.native.d.ts.map +1 -1
- package/dist/foundation.native.js +18 -3
- package/dist/foundation.native.js.map +1 -1
- package/dist/generated/button-dom-props.d.ts +11 -0
- package/dist/generated/button-dom-props.d.ts.map +1 -0
- package/dist/generated/button-dom-props.js +132 -0
- package/dist/generated/button-dom-props.js.map +1 -0
- package/dist/generated/button-props.d.ts +3 -0
- package/dist/generated/button-props.d.ts.map +1 -0
- package/dist/generated/button-props.js +5 -0
- package/dist/generated/button-props.js.map +1 -0
- package/dist/generated/button-props.native.d.ts +2 -0
- package/dist/generated/button-props.native.d.ts.map +1 -0
- package/dist/generated/button-props.native.js +2 -0
- package/dist/generated/button-props.native.js.map +1 -0
- package/dist/generated/inherited-label.d.ts +2 -0
- package/dist/generated/inherited-label.d.ts.map +1 -0
- package/dist/generated/inherited-label.js +3 -0
- package/dist/generated/inherited-label.js.map +1 -0
- package/dist/generated/inherited-pressable.d.ts +2 -0
- package/dist/generated/inherited-pressable.d.ts.map +1 -0
- package/dist/generated/inherited-pressable.js +3 -0
- package/dist/generated/inherited-pressable.js.map +1 -0
- package/dist/generated/inherited-relative-text.d.ts +2 -0
- package/dist/generated/inherited-relative-text.d.ts.map +1 -0
- package/dist/generated/inherited-relative-text.js +3 -0
- package/dist/generated/inherited-relative-text.js.map +1 -0
- package/dist/generated/inherited-text.d.ts +2 -0
- package/dist/generated/inherited-text.d.ts.map +1 -0
- package/dist/generated/inherited-text.js +3 -0
- package/dist/generated/inherited-text.js.map +1 -0
- package/dist/generated/inherited-view.d.ts +2 -0
- package/dist/generated/inherited-view.d.ts.map +1 -0
- package/dist/generated/inherited-view.js +3 -0
- package/dist/generated/inherited-view.js.map +1 -0
- package/dist/generated/native-disabled.d.ts +2 -0
- package/dist/generated/native-disabled.d.ts.map +1 -0
- package/dist/generated/native-disabled.js +2 -0
- package/dist/generated/native-disabled.js.map +1 -0
- package/dist/generated/text-input-dom-props.d.ts +7 -0
- package/dist/generated/text-input-dom-props.d.ts.map +1 -0
- package/dist/generated/text-input-dom-props.js +130 -0
- package/dist/generated/text-input-dom-props.js.map +1 -0
- package/dist/generated/text-input.native.d.ts +1 -1
- package/dist/generated/text-input.native.d.ts.map +1 -1
- package/dist/generated/text-input.native.js +1 -1
- package/dist/generated/text-input.native.js.map +1 -1
- package/dist/generated/view-dom-props.d.ts +8 -0
- package/dist/generated/view-dom-props.d.ts.map +1 -0
- package/dist/generated/view-dom-props.js +241 -0
- package/dist/generated/view-dom-props.js.map +1 -0
- package/dist/inherited-label.native.d.ts +8 -0
- package/dist/inherited-label.native.d.ts.map +1 -0
- package/dist/inherited-label.native.js +12 -0
- package/dist/inherited-label.native.js.map +1 -0
- package/dist/inherited-pressable.native.d.ts +11 -0
- package/dist/inherited-pressable.native.d.ts.map +1 -0
- package/dist/inherited-pressable.native.js +75 -0
- package/dist/inherited-pressable.native.js.map +1 -0
- package/dist/inherited-relative-text.native.d.ts +13 -0
- package/dist/inherited-relative-text.native.d.ts.map +1 -0
- package/dist/inherited-relative-text.native.js +16 -0
- package/dist/inherited-relative-text.native.js.map +1 -0
- package/dist/inherited-text-scope.d.ts +8 -0
- package/dist/inherited-text-scope.d.ts.map +1 -0
- package/dist/inherited-text-scope.js +10 -0
- package/dist/inherited-text-scope.js.map +1 -0
- package/dist/inherited-text-style.native.d.ts +5 -0
- package/dist/inherited-text-style.native.d.ts.map +1 -0
- package/dist/inherited-text-style.native.js +30 -0
- package/dist/inherited-text-style.native.js.map +1 -0
- package/dist/inherited-text.native.d.ts +5 -0
- package/dist/inherited-text.native.d.ts.map +1 -0
- package/dist/inherited-text.native.js +18 -0
- package/dist/inherited-text.native.js.map +1 -0
- package/dist/inherited-view.native.d.ts +9 -0
- package/dist/inherited-view.native.d.ts.map +1 -0
- package/dist/inherited-view.native.js +17 -0
- package/dist/inherited-view.native.js.map +1 -0
- package/dist/link.d.ts +4 -3
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +9 -1
- package/dist/link.js.map +1 -1
- package/dist/link.native.d.ts +16 -7
- package/dist/link.native.d.ts.map +1 -1
- package/dist/link.native.js +15 -5
- package/dist/link.native.js.map +1 -1
- package/dist/native-disabled.d.ts +13 -0
- package/dist/native-disabled.d.ts.map +1 -0
- package/dist/native-disabled.js +13 -0
- package/dist/native-disabled.js.map +1 -0
- package/dist/presence.native.d.ts.map +1 -1
- package/dist/presence.native.js +1 -1
- package/dist/presence.native.js.map +1 -1
- package/dist/pressable.d.ts +1 -1
- package/dist/pressable.d.ts.map +1 -1
- package/dist/pressable.js +15 -5
- package/dist/pressable.js.map +1 -1
- package/dist/pressable.native.d.ts +10 -1
- package/dist/pressable.native.d.ts.map +1 -1
- package/dist/pressable.native.js +206 -221
- package/dist/pressable.native.js.map +1 -1
- package/dist/runtime-container.native.d.ts +11 -9
- package/dist/runtime-container.native.d.ts.map +1 -1
- package/dist/runtime-container.native.js +8 -6
- package/dist/runtime-container.native.js.map +1 -1
- package/dist/text-color-transition.native.d.ts +12 -0
- package/dist/text-color-transition.native.d.ts.map +1 -0
- package/dist/text-color-transition.native.js +87 -0
- package/dist/text-color-transition.native.js.map +1 -0
- package/dist/text-input-props.native.d.ts +10 -0
- package/dist/text-input-props.native.d.ts.map +1 -0
- package/dist/text-input-props.native.js +15 -0
- package/dist/text-input-props.native.js.map +1 -0
- package/dist/text-input.native.d.ts +19 -0
- package/dist/text-input.native.d.ts.map +1 -0
- package/dist/text-input.native.js +32 -0
- package/dist/text-input.native.js.map +1 -0
- package/dist/view.d.ts +1 -285
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +5 -4
- package/dist/view.js.map +1 -1
- package/package.json +51 -7
- package/src/button-host-attributes.ts +56 -0
- package/src/button-host-props.native.ts +22 -0
- package/src/foundation.native.tsx +45 -6
- package/src/foundation.tsx +139 -28
- package/src/generated/button-dom-props.ts +127 -0
- package/src/generated/button-props.native.ts +1 -0
- package/src/generated/button-props.ts +4 -0
- package/src/generated/inherited-label.ts +2 -0
- package/src/generated/inherited-pressable.ts +2 -0
- package/src/generated/inherited-relative-text.ts +2 -0
- package/src/generated/inherited-text.ts +2 -0
- package/src/generated/inherited-view.ts +2 -0
- package/src/generated/native-disabled.ts +1 -0
- package/src/generated/text-input-dom-props.ts +128 -0
- package/src/generated/text-input.native.ts +1 -4
- package/src/generated/view-dom-props.ts +267 -0
- package/src/inherited-label.native.tsx +28 -0
- package/src/inherited-pressable.native.tsx +152 -0
- package/src/inherited-relative-text.native.tsx +22 -0
- package/src/inherited-text-scope.tsx +27 -0
- package/src/inherited-text-style.native.ts +35 -0
- package/src/inherited-text.native.tsx +32 -0
- package/src/inherited-view.native.tsx +37 -0
- package/src/link.native.tsx +43 -28
- package/src/link.ts +12 -0
- package/src/native-disabled.ts +23 -0
- package/src/presence.native.tsx +1 -1
- package/src/pressable.native.tsx +298 -262
- package/src/pressable.ts +34 -17
- package/src/runtime-container.native.tsx +30 -15
- package/src/text-color-transition.native.ts +96 -0
- package/src/text-input-props.native.ts +26 -0
- package/src/text-input.native.tsx +57 -0
- package/src/view.ts +34 -25
- package/dist/generated/animated.d.ts +0 -2
- package/dist/generated/animated.d.ts.map +0 -1
- package/dist/generated/animated.js +0 -3
- package/dist/generated/animated.js.map +0 -1
- package/dist/presence-context.d.ts +0 -15
- package/dist/presence-context.d.ts.map +0 -1
- package/dist/presence-context.js +0 -11
- package/dist/presence-context.js.map +0 -1
- package/dist/runtime-transition.native.d.ts +0 -30
- package/dist/runtime-transition.native.d.ts.map +0 -1
- package/dist/runtime-transition.native.js +0 -183
- package/dist/runtime-transition.native.js.map +0 -1
- package/src/generated/animated.ts +0 -6
- package/src/presence-context.ts +0 -27
- 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
|
+
}
|
package/src/link.native.tsx
CHANGED
|
@@ -4,17 +4,24 @@ import {
|
|
|
4
4
|
prefetchHozoNavigation,
|
|
5
5
|
useHozoNavigation,
|
|
6
6
|
} from '@hozo/engine/navigation'
|
|
7
|
-
import { type ReactNode, useRef } from 'react'
|
|
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'
|
|
10
|
+
import type { HozoPressable } from './pressable.native.tsx'
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
type LinkHost = typeof Pressable | typeof HozoPressable
|
|
13
|
+
|
|
14
|
+
export type HozoLinkProps<Host extends LinkHost = typeof Pressable> =
|
|
15
|
+
ComponentPropsWithRef<Host> & {
|
|
16
|
+
/** Compiler-only host selection; ordinary links retain RN's cheap path. */
|
|
17
|
+
hozoLinkComponent?: Host
|
|
18
|
+
href: string
|
|
19
|
+
external?: boolean
|
|
20
|
+
replace?: boolean
|
|
21
|
+
prefetch?: boolean
|
|
22
|
+
onPress?: PressableProps['onPress']
|
|
23
|
+
children?: PressableProps['children']
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
/**
|
|
20
27
|
* Native semantic link with the same destination-bearing API as `<a>`.
|
|
@@ -34,37 +41,45 @@ export interface HozoLinkProps extends Omit<PressableProps, 'onPress'> {
|
|
|
34
41
|
* `Link` carried its own copy of exactly this and is why it existed
|
|
35
42
|
* separately at all; it delegates here now.
|
|
36
43
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
44
|
+
* Normalization wraps text runs, not whole arrays: embedded controls remain
|
|
45
|
+
* controls. Function children are still evaluated by React Native itself.
|
|
46
|
+
*
|
|
47
|
+
* State variants select HozoPressable without duplicating its event machine
|
|
48
|
+
* or navigation. The type-only import keeps that machinery out of ordinary
|
|
49
|
+
* links' Metro graph, where unused static imports would still cost modules.
|
|
40
50
|
*/
|
|
41
|
-
export function HozoLink({
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
65
|
+
const Component: ElementType = hozoLinkComponent ?? Pressable
|
|
53
66
|
const navigation = useHozoNavigation()
|
|
54
67
|
const prefetchedHref = useRef<string | null>(null)
|
|
55
68
|
return (
|
|
56
|
-
<
|
|
69
|
+
<Component
|
|
57
70
|
{...props}
|
|
58
71
|
disabled={disabled}
|
|
59
72
|
accessibilityRole={accessibilityRole}
|
|
60
|
-
onPressIn={(event) => {
|
|
73
|
+
onPressIn={(event: Parameters<NonNullable<PressableProps['onPressIn']>>[0]) => {
|
|
74
|
+
if (disabled) return
|
|
61
75
|
onPressIn?.(event)
|
|
62
76
|
if (prefetch && !disabled && prefetchedHref.current !== href) {
|
|
63
77
|
prefetchedHref.current = href
|
|
64
78
|
prefetchHozoNavigation(navigation, { href, external, replace })
|
|
65
79
|
}
|
|
66
80
|
}}
|
|
67
|
-
onPress={(event) => {
|
|
81
|
+
onPress={(event: Parameters<NonNullable<PressableProps['onPress']>>[0]) => {
|
|
82
|
+
if (disabled) return
|
|
68
83
|
onPress?.(event)
|
|
69
84
|
if (!event.defaultPrevented) {
|
|
70
85
|
void activateHozoNavigation(navigation, { href, external, replace }, Linking.openURL)
|
|
@@ -72,6 +87,6 @@ export function HozoLink({
|
|
|
72
87
|
}}
|
|
73
88
|
>
|
|
74
89
|
{typeof children === 'function' ? children : hozoTextChildren(children as ReactNode)}
|
|
75
|
-
</
|
|
90
|
+
</Component>
|
|
76
91
|
)
|
|
77
92
|
}
|
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
|
+
}
|
package/src/presence.native.tsx
CHANGED
|
@@ -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. */
|