@hozo/engine 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.
- package/CHANGELOG.md +26 -0
- package/README.md +8 -4
- package/dist/authored-gap.d.ts +11 -0
- package/dist/authored-gap.d.ts.map +1 -0
- package/dist/authored-gap.js +45 -0
- package/dist/authored-gap.js.map +1 -0
- package/dist/class-resolver.d.ts +41 -3
- package/dist/class-resolver.d.ts.map +1 -1
- package/dist/class-resolver.js +160 -23
- package/dist/class-resolver.js.map +1 -1
- package/dist/class-transition.d.ts +32 -0
- package/dist/class-transition.d.ts.map +1 -0
- package/dist/class-transition.js +48 -0
- package/dist/class-transition.js.map +1 -0
- package/dist/color-transition.d.ts +2 -0
- package/dist/color-transition.d.ts.map +1 -1
- package/dist/color-transition.js +4 -0
- package/dist/color-transition.js.map +1 -1
- package/dist/cx.d.ts +4 -0
- package/dist/cx.d.ts.map +1 -0
- package/dist/cx.js +17 -0
- package/dist/cx.js.map +1 -0
- package/dist/dom-style.d.ts +1 -0
- package/dist/dom-style.d.ts.map +1 -1
- package/dist/dom-style.js +4 -0
- package/dist/dom-style.js.map +1 -1
- package/dist/gap-styles.d.ts +3 -0
- package/dist/gap-styles.d.ts.map +1 -0
- package/dist/gap-styles.js +7 -0
- package/dist/gap-styles.js.map +1 -0
- package/dist/generated/animated.d.ts +3 -0
- package/dist/generated/animated.d.ts.map +1 -0
- package/dist/generated/animated.js +7 -0
- package/dist/generated/animated.js.map +1 -0
- package/dist/generated/class-resolver.d.ts +1 -1
- package/dist/generated/class-resolver.d.ts.map +1 -1
- package/dist/generated/class-resolver.js +1 -1
- package/dist/generated/class-resolver.js.map +1 -1
- package/dist/generated/gap-styles.d.ts +3 -0
- package/dist/generated/gap-styles.d.ts.map +1 -0
- package/dist/generated/gap-styles.js +4 -0
- package/dist/generated/gap-styles.js.map +1 -0
- package/dist/generated/safe-area.d.ts +1 -1
- package/dist/generated/safe-area.d.ts.map +1 -1
- package/dist/generated/safe-area.js +1 -1
- package/dist/generated/safe-area.js.map +1 -1
- package/dist/generated/spread-styles.d.ts +2 -0
- package/dist/generated/spread-styles.d.ts.map +1 -0
- package/dist/generated/spread-styles.js +3 -0
- package/dist/generated/spread-styles.js.map +1 -0
- package/dist/generated/text-inheritance-protocol.d.ts +3 -0
- package/dist/generated/text-inheritance-protocol.d.ts.map +1 -0
- package/dist/generated/text-inheritance-protocol.js +3 -0
- package/dist/generated/text-inheritance-protocol.js.map +1 -0
- package/dist/generated/text-size-context.d.ts +2 -0
- package/dist/generated/text-size-context.d.ts.map +1 -0
- package/dist/generated/text-size-context.js +3 -0
- package/dist/generated/text-size-context.js.map +1 -0
- package/dist/hooks.native.js +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/presence-context.d.ts +15 -0
- package/dist/presence-context.d.ts.map +1 -0
- package/dist/presence-context.js +11 -0
- package/dist/presence-context.js.map +1 -0
- package/dist/project.d.ts +8 -0
- package/dist/project.d.ts.map +1 -1
- package/dist/project.js +7 -0
- package/dist/project.js.map +1 -1
- package/dist/project.native.d.ts +1 -1
- package/dist/project.native.d.ts.map +1 -1
- package/dist/project.native.js +1 -1
- package/dist/project.native.js.map +1 -1
- package/dist/responder.d.ts +34 -0
- package/dist/responder.d.ts.map +1 -1
- package/dist/responder.js +52 -0
- package/dist/responder.js.map +1 -1
- package/dist/runtime-transition.native.d.ts +37 -0
- package/dist/runtime-transition.native.d.ts.map +1 -0
- package/dist/runtime-transition.native.js +252 -0
- package/dist/runtime-transition.native.js.map +1 -0
- package/dist/safe-area.native.d.ts +12 -0
- package/dist/safe-area.native.d.ts.map +1 -1
- package/dist/safe-area.native.js +44 -21
- package/dist/safe-area.native.js.map +1 -1
- package/dist/spread-styles.d.ts +14 -0
- package/dist/spread-styles.d.ts.map +1 -0
- package/dist/spread-styles.js +56 -0
- package/dist/spread-styles.js.map +1 -0
- package/dist/text-inheritance.d.ts +35 -0
- package/dist/text-inheritance.d.ts.map +1 -0
- package/dist/text-inheritance.js +48 -0
- package/dist/text-inheritance.js.map +1 -0
- package/dist/text-style.d.ts +8 -0
- package/dist/text-style.d.ts.map +1 -0
- package/dist/text-style.js +34 -0
- package/dist/text-style.js.map +1 -0
- package/package.json +22 -2
- package/src/authored-gap.ts +41 -0
- package/src/class-resolver.ts +213 -7
- package/src/class-transition.ts +71 -0
- package/src/color-transition.ts +5 -0
- package/src/cx.ts +18 -0
- package/src/dom-style.ts +3 -0
- package/src/gap-styles.ts +11 -0
- package/src/generated/animated.ts +15 -0
- package/src/generated/class-resolver.ts +7 -1
- package/src/generated/gap-styles.ts +3 -0
- package/src/generated/safe-area.ts +5 -1
- package/src/generated/spread-styles.ts +2 -0
- package/src/generated/text-inheritance-protocol.ts +9 -0
- package/src/generated/text-size-context.ts +2 -0
- package/src/hooks.native.ts +1 -1
- package/src/index.ts +17 -2
- package/src/presence-context.ts +27 -0
- package/src/project.native.ts +1 -1
- package/src/project.ts +9 -0
- package/src/responder.ts +52 -0
- package/src/runtime-transition.native.tsx +324 -0
- package/src/safe-area.native.ts +59 -24
- package/src/spread-styles.ts +74 -0
- package/src/text-inheritance.ts +75 -0
- package/src/text-style.ts +35 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Properties drawn by a Native Text rather than by its containing View. */
|
|
2
|
+
const TEXT_KEYS = new Set([
|
|
3
|
+
'color',
|
|
4
|
+
'fontFamily',
|
|
5
|
+
'fontSize',
|
|
6
|
+
'fontStyle',
|
|
7
|
+
'fontVariant',
|
|
8
|
+
'fontWeight',
|
|
9
|
+
'letterSpacing',
|
|
10
|
+
'lineHeight',
|
|
11
|
+
'textAlign',
|
|
12
|
+
'textDecorationColor',
|
|
13
|
+
'textDecorationLine',
|
|
14
|
+
'textDecorationStyle',
|
|
15
|
+
'textShadowColor',
|
|
16
|
+
'textShadowOffset',
|
|
17
|
+
'textShadowRadius',
|
|
18
|
+
'textTransform',
|
|
19
|
+
]);
|
|
20
|
+
/**
|
|
21
|
+
* Partition an already resolved, flattened Native style. Resolution and
|
|
22
|
+
* last-wins composition remain the caller's existing platform operations;
|
|
23
|
+
* this neither interprets classes nor publishes inherited text context.
|
|
24
|
+
*/
|
|
25
|
+
export function hozoSplitTextStyle(style) {
|
|
26
|
+
const box = {};
|
|
27
|
+
const text = {};
|
|
28
|
+
for (const [key, value] of Object.entries(style)) {
|
|
29
|
+
;
|
|
30
|
+
(TEXT_KEYS.has(key) ? text : box)[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return [box, text];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=text-style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-style.js","sourceRoot":"","sources":["../src/text-style.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,OAAO;IACP,YAAY;IACZ,UAAU;IACV,WAAW;IACX,aAAa;IACb,YAAY;IACZ,eAAe;IACf,YAAY;IACZ,WAAW;IACX,qBAAqB;IACrB,oBAAoB;IACpB,qBAAqB;IACrB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,eAAe;CAChB,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA4B;IAC7D,MAAM,GAAG,GAAgB,EAAE,CAAA;IAC3B,MAAM,IAAI,GAAgB,EAAE,CAAA;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjD,CAAC;QAAA,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACjD,CAAC;IACD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hozo/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Runtime fallback for genuinely dynamic styles, interactive behavior, and accessibility behavior.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -49,6 +49,10 @@
|
|
|
49
49
|
"types": "./dist/project.d.ts",
|
|
50
50
|
"default": "./dist/project.js"
|
|
51
51
|
},
|
|
52
|
+
"./generated/animated": {
|
|
53
|
+
"types": "./dist/generated/animated.d.ts",
|
|
54
|
+
"default": "./dist/generated/animated.js"
|
|
55
|
+
},
|
|
52
56
|
"./generated/animation": {
|
|
53
57
|
"types": "./dist/generated/animation.d.ts",
|
|
54
58
|
"default": "./dist/generated/animation.js"
|
|
@@ -69,6 +73,10 @@
|
|
|
69
73
|
"types": "./dist/generated/environment.d.ts",
|
|
70
74
|
"default": "./dist/generated/environment.js"
|
|
71
75
|
},
|
|
76
|
+
"./generated/gap-styles": {
|
|
77
|
+
"types": "./dist/generated/gap-styles.d.ts",
|
|
78
|
+
"default": "./dist/generated/gap-styles.js"
|
|
79
|
+
},
|
|
72
80
|
"./generated/image-source": {
|
|
73
81
|
"types": "./dist/generated/image-source.d.ts",
|
|
74
82
|
"default": "./dist/generated/image-source.js"
|
|
@@ -85,6 +93,18 @@
|
|
|
85
93
|
"types": "./dist/generated/scrollable.d.ts",
|
|
86
94
|
"default": "./dist/generated/scrollable.js"
|
|
87
95
|
},
|
|
96
|
+
"./generated/spread-styles": {
|
|
97
|
+
"types": "./dist/generated/spread-styles.d.ts",
|
|
98
|
+
"default": "./dist/generated/spread-styles.js"
|
|
99
|
+
},
|
|
100
|
+
"./generated/text-inheritance-protocol": {
|
|
101
|
+
"types": "./dist/generated/text-inheritance-protocol.d.ts",
|
|
102
|
+
"default": "./dist/generated/text-inheritance-protocol.js"
|
|
103
|
+
},
|
|
104
|
+
"./generated/text-size-context": {
|
|
105
|
+
"types": "./dist/generated/text-size-context.d.ts",
|
|
106
|
+
"default": "./dist/generated/text-size-context.js"
|
|
107
|
+
},
|
|
88
108
|
"./generated/transform-slots": {
|
|
89
109
|
"types": "./dist/generated/transform-slots.d.ts",
|
|
90
110
|
"default": "./dist/generated/transform-slots.js"
|
|
@@ -106,7 +126,7 @@
|
|
|
106
126
|
"dependencies": {},
|
|
107
127
|
"peerDependencies": {
|
|
108
128
|
"react": "^19.0.0",
|
|
109
|
-
"react-native": ">=0.
|
|
129
|
+
"react-native": ">=0.87",
|
|
110
130
|
"react-native-safe-area-context": ">=4"
|
|
111
131
|
},
|
|
112
132
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project a flattened author's StyleProp, not a mixture with compiled styles.
|
|
3
|
+
* Yoga prefers an axis gutter to `gap` regardless of object key/array order.
|
|
4
|
+
* CSS needs the effective longhands instead, or a later shorthand erases the
|
|
5
|
+
* axis. The caller owns this flat object; authored objects are never mutated.
|
|
6
|
+
* Keep CSS-only strings untouched rather than pretending RN accepts them.
|
|
7
|
+
*/
|
|
8
|
+
export function projectAuthoredGap(style: Record<string, unknown>): void {
|
|
9
|
+
const gap = style.gap
|
|
10
|
+
if (gap === undefined) return
|
|
11
|
+
if (
|
|
12
|
+
!(typeof gap === 'number' && Number.isFinite(gap) && gap >= 0) &&
|
|
13
|
+
!(typeof gap === 'string' && /^(?:\d+(?:\.\d+)?|\.\d+)%$/.test(gap))
|
|
14
|
+
)
|
|
15
|
+
return
|
|
16
|
+
if (!Object.hasOwn(style, 'gap')) return
|
|
17
|
+
const row = style.rowGap ?? gap
|
|
18
|
+
const column = style.columnGap ?? gap
|
|
19
|
+
delete style.gap
|
|
20
|
+
style.rowGap = row
|
|
21
|
+
style.columnGap = column
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Generated Native code calls this before mixing an author with class axes. */
|
|
25
|
+
export function hozoAuthoredStyle<T>(input: T): T {
|
|
26
|
+
if (!input || typeof input !== 'object') return input
|
|
27
|
+
if (!Array.isArray(input) && (!('gap' in input) || !Object.hasOwn(input, 'gap'))) return input
|
|
28
|
+
// Flatten only the author's contribution. Reading it once also avoids a
|
|
29
|
+
// pre-scan that would evaluate style accessors again during composition.
|
|
30
|
+
const flat: Record<string, unknown> = {}
|
|
31
|
+
function visit(value: unknown): void {
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
for (const item of value) visit(item)
|
|
34
|
+
} else if (value && typeof value === 'object') {
|
|
35
|
+
Object.assign(flat, value)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
visit(input)
|
|
39
|
+
projectAuthoredGap(flat)
|
|
40
|
+
return flat as T
|
|
41
|
+
}
|
package/src/class-resolver.ts
CHANGED
|
@@ -1,12 +1,37 @@
|
|
|
1
1
|
/** A React Native style object, as the compiler emits it. */
|
|
2
2
|
export type StyleObject = Record<string, unknown>
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Compiler-owned text-size fallbacks are not explicit line heights. CSS's
|
|
6
|
+
* --tw-leading register survives a later font-size rule; RN has one numeric
|
|
7
|
+
* slot. The map marks actual generated objects, never class names or private
|
|
8
|
+
* style keys. Only maps containing these fallbacks install this composition.
|
|
9
|
+
*/
|
|
10
|
+
export function hozoTextMetricStyles(
|
|
11
|
+
styles: StyleObject[],
|
|
12
|
+
defaults: ReadonlyMap<StyleObject, StyleObject>,
|
|
13
|
+
): StyleObject[] {
|
|
14
|
+
if (
|
|
15
|
+
!styles.some((style) => defaults.has(style)) ||
|
|
16
|
+
!styles.some((style) => Object.hasOwn(style, 'lineHeight') && !defaults.has(style))
|
|
17
|
+
)
|
|
18
|
+
return styles
|
|
19
|
+
// Default-free objects are built once by the generated factory. A state
|
|
20
|
+
// update selects them; it never clones a style object or inspects ranks.
|
|
21
|
+
return styles.map((style) => defaults.get(style) ?? style)
|
|
22
|
+
}
|
|
23
|
+
|
|
4
24
|
/**
|
|
5
25
|
* The state an element is in when its runtime classes are resolved: what
|
|
6
26
|
* its pressable reports (`pressed`, `hovered`, `focused`, `focusVisible`)
|
|
7
27
|
* and what its props say: `disabled`, and `aria-checked`, `aria-selected` and
|
|
8
28
|
* the rest under their attribute names, so `aria-pressed` cannot be read as
|
|
9
|
-
* the pointer's `pressed`.
|
|
29
|
+
* the pointer's `pressed`. Plain data-presence conditions use `data-foo`
|
|
30
|
+
* booleans supplied by the actual owner: true means the attribute is present,
|
|
31
|
+
* false means absent, and a missing key is unassessed (and diagnosed).
|
|
32
|
+
* Simple equality predicates use `data-foo=value` booleans, with case-sensitive
|
|
33
|
+
* safe token values normalized at build time. Presence cannot satisfy equality.
|
|
34
|
+
* These are normalized facts, not raw HTML attribute values or selectors.
|
|
10
35
|
*/
|
|
11
36
|
export type ClassState = Readonly<Record<string, unknown>>
|
|
12
37
|
|
|
@@ -14,8 +39,12 @@ export type ClassState = Readonly<Record<string, unknown>>
|
|
|
14
39
|
* A class that applies only in a state: the state keys that all have to
|
|
15
40
|
* hold, and the style it applies then. `active:opacity-80` is
|
|
16
41
|
* `[['pressed'], { opacity: 0.8 }]`.
|
|
42
|
+
* Generated Tailwind owner states may append a cached cascade rank; legacy
|
|
43
|
+
* two-entry groups and mixed/unranked conditional domains keep their order.
|
|
44
|
+
* `!aria-…` is compiler-owned negative-predicate data. It still requires the
|
|
45
|
+
* underlying owner fact; an absent fact is not a measured false value.
|
|
17
46
|
*/
|
|
18
|
-
export type StateGroup = readonly [readonly string[], StyleObject]
|
|
47
|
+
export type StateGroup = readonly [readonly string[], StyleObject, number?]
|
|
19
48
|
|
|
20
49
|
/**
|
|
21
50
|
* Resolves whitespace-separated class names to React Native style objects.
|
|
@@ -30,14 +59,36 @@ export type StateGroup = readonly [readonly string[], StyleObject]
|
|
|
30
59
|
*/
|
|
31
60
|
export type ClassResolver = (value: unknown, state?: ClassState) => StyleObject[]
|
|
32
61
|
|
|
62
|
+
/** @internal Generated-data ABI, not a utility parser or a public cascade API. */
|
|
63
|
+
export interface ClassResolverPlan {
|
|
64
|
+
schema: 1
|
|
65
|
+
styles: Record<string, StyleObject>
|
|
66
|
+
unsupported?: Record<string, string>
|
|
67
|
+
states?: Record<string, readonly StateGroup[]>
|
|
68
|
+
ambient?: ClassState
|
|
69
|
+
compose?: (styles: StyleObject[]) => StyleObject[]
|
|
70
|
+
/** Ordinals from one complete compiler namespace. Missing means barrier. */
|
|
71
|
+
ordering: { schema: 1; ranks: Readonly<Record<string, readonly number[]>> }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface TemplateEntry {
|
|
75
|
+
keys: readonly string[]
|
|
76
|
+
style: StyleObject
|
|
77
|
+
name: string
|
|
78
|
+
}
|
|
79
|
+
|
|
33
80
|
interface Resolved {
|
|
34
81
|
/** The unconditional styles, composed: what a string with no state classes returns. */
|
|
35
82
|
base: StyleObject[]
|
|
36
83
|
/** The same, before `compose`, for composing again with state styles. */
|
|
37
84
|
raw: StyleObject[]
|
|
38
85
|
groups: StateGroup[]
|
|
86
|
+
/** Parallel to groups: retain the candidate name for missing-fact warnings. */
|
|
87
|
+
groupClasses: string[]
|
|
39
88
|
/** State classes in this string, named if it is resolved without a state. */
|
|
40
89
|
stateClasses: string[]
|
|
90
|
+
/** Rank-free cached template: state updates only select applicable entries. */
|
|
91
|
+
ordered?: TemplateEntry[]
|
|
41
92
|
}
|
|
42
93
|
|
|
43
94
|
/**
|
|
@@ -58,13 +109,48 @@ interface Resolved {
|
|
|
58
109
|
* state (#886). Those need no tracking here: the pressable that renders
|
|
59
110
|
* the element already tracks it and hands it in, so this stays a function
|
|
60
111
|
* of the class string and that state.
|
|
112
|
+
*
|
|
113
|
+
* `ambient` holds facts that cannot change while the app runs, so no
|
|
114
|
+
* element has to supply them: `rtl` and `ltr`, because React Native needs
|
|
115
|
+
* a reload for a direction change to take effect. A class conditioned on
|
|
116
|
+
* them alone is decided once, when its string is first resolved, and then
|
|
117
|
+
* cached like an unconditional one -- after the unconditional ones, which is
|
|
118
|
+
* where Tailwind puts a variant too.
|
|
61
119
|
*/
|
|
120
|
+
export function createClassResolver(plan: ClassResolverPlan): ClassResolver
|
|
62
121
|
export function createClassResolver(
|
|
63
122
|
styles: Record<string, StyleObject>,
|
|
123
|
+
unsupported?: Record<string, string>,
|
|
124
|
+
compose?: (styles: StyleObject[]) => StyleObject[],
|
|
125
|
+
states?: Record<string, readonly StateGroup[]>,
|
|
126
|
+
ambient?: ClassState,
|
|
127
|
+
): ClassResolver
|
|
128
|
+
export function createClassResolver(
|
|
129
|
+
stylesOrPlan: Record<string, StyleObject> | ClassResolverPlan,
|
|
64
130
|
unsupported: Record<string, string> = {},
|
|
65
131
|
compose?: (styles: StyleObject[]) => StyleObject[],
|
|
66
132
|
states: Record<string, readonly StateGroup[]> = {},
|
|
133
|
+
ambient: ClassState = {},
|
|
67
134
|
): ClassResolver {
|
|
135
|
+
let styles: Record<string, StyleObject>
|
|
136
|
+
let ranks: ClassResolverPlan['ordering']['ranks'] | undefined
|
|
137
|
+
if (typeof stylesOrPlan.schema === 'number') {
|
|
138
|
+
const plan = stylesOrPlan as ClassResolverPlan
|
|
139
|
+
if (
|
|
140
|
+
plan.schema !== 1 ||
|
|
141
|
+
plan.ordering?.schema !== 1 ||
|
|
142
|
+
!plan.ordering.ranks ||
|
|
143
|
+
typeof plan.ordering.ranks !== 'object'
|
|
144
|
+
)
|
|
145
|
+
throw new Error('Unsupported Hozo class plan schema')
|
|
146
|
+
styles = plan.styles
|
|
147
|
+
unsupported = plan.unsupported ?? {}
|
|
148
|
+
compose = plan.compose
|
|
149
|
+
states = plan.states ?? {}
|
|
150
|
+
ambient = plan.ambient ?? {}
|
|
151
|
+
ranks = plan.ordering.ranks
|
|
152
|
+
} else styles = stylesOrPlan as Record<string, StyleObject>
|
|
153
|
+
const isAmbient = (key: string) => Object.hasOwn(ambient, key)
|
|
68
154
|
// Class strings repeat constantly across renders and list items, and the
|
|
69
155
|
// result is immutable, so each distinct string is resolved once.
|
|
70
156
|
const cache = new Map<string, Resolved>()
|
|
@@ -77,11 +163,66 @@ export function createClassResolver(
|
|
|
77
163
|
// eslint-disable-next-line no-console
|
|
78
164
|
console.warn(`[hozo] ${reason}`)
|
|
79
165
|
}
|
|
166
|
+
// Absent is not false. A focused field must not silently claim that it
|
|
167
|
+
// measured hover/press, or that a spread supplied a disabled driver.
|
|
168
|
+
const supplied = (keys: readonly string[], name: string, facts: ClassState) => {
|
|
169
|
+
if (!keys.every((key) => Object.hasOwn(facts, key))) {
|
|
170
|
+
if (!warned.has(name)) {
|
|
171
|
+
const missing = keys.filter((key) => !Object.hasOwn(facts, key))
|
|
172
|
+
warn(name, `\`${name}\` needs state (${missing.join(', ')}) this element does not supply.`)
|
|
173
|
+
}
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
return true
|
|
177
|
+
}
|
|
178
|
+
const positive = (keys: readonly string[], name: string, facts: ClassState) =>
|
|
179
|
+
supplied(keys, name, facts) && keys.every((key) => Boolean(facts[key]))
|
|
180
|
+
// Prepare only negative maps' exceptional groups once, not during state
|
|
181
|
+
// updates or for every authored class lookup. Positive-only maps retain
|
|
182
|
+
// their existing boolean matcher and allocate no predicate side table.
|
|
183
|
+
let negative: Map<readonly string[], { keys: string[]; expected: boolean[] }> | undefined
|
|
184
|
+
for (const groups of Object.values(states))
|
|
185
|
+
for (const [keys] of groups)
|
|
186
|
+
if (keys.some((key) => key.startsWith('!aria-')))
|
|
187
|
+
(negative ??= new Map()).set(keys, {
|
|
188
|
+
keys: keys.map((key) => (key.startsWith('!aria-') ? key.slice(1) : key)),
|
|
189
|
+
expected: keys.map((key) => !key.startsWith('!aria-')),
|
|
190
|
+
})
|
|
191
|
+
const negativePredicates = negative
|
|
192
|
+
const matches = negativePredicates
|
|
193
|
+
? (keys: readonly string[], name: string, facts: ClassState) => {
|
|
194
|
+
const predicate = negativePredicates.get(keys)
|
|
195
|
+
return predicate
|
|
196
|
+
? supplied(predicate.keys, name, facts) &&
|
|
197
|
+
predicate.keys.every(
|
|
198
|
+
(key, index) => Boolean(facts[key]) === predicate.expected[index],
|
|
199
|
+
)
|
|
200
|
+
: positive(keys, name, facts)
|
|
201
|
+
}
|
|
202
|
+
: positive
|
|
80
203
|
|
|
81
204
|
function resolve(value: string): Resolved {
|
|
82
205
|
const base: StyleObject[] = []
|
|
83
206
|
const groups: StateGroup[] = []
|
|
207
|
+
const groupClasses: string[] = []
|
|
84
208
|
const stateClasses: string[] = []
|
|
209
|
+
const decided: StyleObject[] = []
|
|
210
|
+
// Build transient ranked entries only for the generated-plan ABI. A
|
|
211
|
+
// single unassessed object makes this whole string use the old path.
|
|
212
|
+
let ranked: { rank: number; entry: TemplateEntry }[] | undefined = ranks ? [] : undefined
|
|
213
|
+
const take = ranks
|
|
214
|
+
? (name: string, index: number, style: StyleObject, keys: readonly string[]) => {
|
|
215
|
+
if (!ranked) return
|
|
216
|
+
const rank = ranks![name]?.[index]
|
|
217
|
+
if (rank === undefined) {
|
|
218
|
+
ranked = undefined
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
if (!Number.isSafeInteger(rank) || rank < 0)
|
|
222
|
+
throw new Error('Invalid Hozo class plan rank')
|
|
223
|
+
ranked.push({ rank, entry: { name, style, keys } })
|
|
224
|
+
}
|
|
225
|
+
: undefined
|
|
85
226
|
for (const name of value.split(/\s+/)) {
|
|
86
227
|
if (name === '') {
|
|
87
228
|
continue
|
|
@@ -89,12 +230,24 @@ export function createClassResolver(
|
|
|
89
230
|
const style = styles[name]
|
|
90
231
|
if (style) {
|
|
91
232
|
base.push(style)
|
|
233
|
+
take?.(name, 0, style, [])
|
|
92
234
|
continue
|
|
93
235
|
}
|
|
94
236
|
const conditional = states[name]
|
|
95
237
|
if (conditional) {
|
|
96
|
-
|
|
97
|
-
|
|
238
|
+
let needsState = false
|
|
239
|
+
for (let index = 0; index < conditional.length; index++) {
|
|
240
|
+
const group = conditional[index]!
|
|
241
|
+
take?.(name, index, group[1], group[0])
|
|
242
|
+
if ((negativePredicates?.get(group[0])?.keys ?? group[0]).every(isAmbient)) {
|
|
243
|
+
if (matches(group[0], name, ambient)) decided.push(group[1])
|
|
244
|
+
continue
|
|
245
|
+
}
|
|
246
|
+
groups.push(group)
|
|
247
|
+
groupClasses.push(name)
|
|
248
|
+
needsState = true
|
|
249
|
+
}
|
|
250
|
+
if (needsState) stateClasses.push(name)
|
|
98
251
|
continue
|
|
99
252
|
}
|
|
100
253
|
// An unknown class isn't necessarily a Hozo problem -- it may be an
|
|
@@ -103,7 +256,42 @@ export function createClassResolver(
|
|
|
103
256
|
const reason = unsupported[name]
|
|
104
257
|
if (reason) warn(name, reason)
|
|
105
258
|
}
|
|
106
|
-
|
|
259
|
+
if (ranked) {
|
|
260
|
+
// Stable ties keep input order. Strip rank objects before caching, so
|
|
261
|
+
// neither cache hits nor state-only changes can read/sort priorities.
|
|
262
|
+
ranked.sort((a, b) => a.rank - b.rank)
|
|
263
|
+
const ordered: TemplateEntry[] = []
|
|
264
|
+
for (const { entry } of ranked) {
|
|
265
|
+
if ((negativePredicates?.get(entry.keys)?.keys ?? entry.keys).every(isAmbient)) {
|
|
266
|
+
if (matches(entry.keys, entry.name, ambient)) ordered.push({ ...entry, keys: [] })
|
|
267
|
+
} else ordered.push(entry)
|
|
268
|
+
}
|
|
269
|
+
const raw = ordered.filter((entry) => !entry.keys.length).map((entry) => entry.style)
|
|
270
|
+
return {
|
|
271
|
+
base: compose ? compose(raw) : raw,
|
|
272
|
+
raw,
|
|
273
|
+
groups,
|
|
274
|
+
groupClasses,
|
|
275
|
+
stateClasses,
|
|
276
|
+
ordered,
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// Build-time Tailwind owner-state rank, sorted once per cached class string,
|
|
280
|
+
// never on every state update. Mixed/unranked domains are left alone; ties
|
|
281
|
+
// retain authored/caller order. Keep warning provenance beside each group.
|
|
282
|
+
if (groups.length > 1 && groups.every((group) => group[2] !== undefined)) {
|
|
283
|
+
if (groups.some((group, index) => index > 0 && groups[index - 1]![2]! > group[2]!)) {
|
|
284
|
+
const sorted = groups
|
|
285
|
+
.map((group, index) => ({ group, name: groupClasses[index]! }))
|
|
286
|
+
.sort((a, b) => a.group[2]! - b.group[2]!)
|
|
287
|
+
for (const [index, entry] of sorted.entries()) {
|
|
288
|
+
groups[index] = entry.group
|
|
289
|
+
groupClasses[index] = entry.name
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
base.push(...decided)
|
|
294
|
+
return { base: compose ? compose(base) : base, raw: base, groups, groupClasses, stateClasses }
|
|
107
295
|
}
|
|
108
296
|
|
|
109
297
|
return function hozoClasses(value: unknown, state?: ClassState): StyleObject[] {
|
|
@@ -124,13 +312,31 @@ export function createClassResolver(
|
|
|
124
312
|
warn(
|
|
125
313
|
name,
|
|
126
314
|
`\`${name}\` applies in a state, and this element hands its classes no state to ` +
|
|
127
|
-
'resolve it against. Put it on
|
|
315
|
+
'resolve it against. Put it on an owner that supplies this state, or write it as a static ' +
|
|
128
316
|
'className so it compiles to a real style variant.',
|
|
129
317
|
)
|
|
130
318
|
}
|
|
131
319
|
return resolved.base
|
|
132
320
|
}
|
|
133
|
-
|
|
321
|
+
// A group can name an ambient fact beside the element's own, as
|
|
322
|
+
// `rtl:hover:` does; the element supplies only its part.
|
|
323
|
+
const facts = { ...ambient, ...state }
|
|
324
|
+
if (resolved.ordered) {
|
|
325
|
+
const all: StyleObject[] = []
|
|
326
|
+
let active = false
|
|
327
|
+
for (const entry of resolved.ordered) {
|
|
328
|
+
if (!entry.keys.length) all.push(entry.style)
|
|
329
|
+
else if (matches(entry.keys, entry.name, facts)) {
|
|
330
|
+
all.push(entry.style)
|
|
331
|
+
active = true
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (!active) return resolved.base
|
|
335
|
+
return compose ? compose(all) : all
|
|
336
|
+
}
|
|
337
|
+
const active = resolved.groups.filter(([keys], index) =>
|
|
338
|
+
matches(keys, resolved.groupClasses[index]!, facts),
|
|
339
|
+
)
|
|
134
340
|
if (active.length === 0) return resolved.base
|
|
135
341
|
const all = [...resolved.raw, ...active.map(([, style]) => style)]
|
|
136
342
|
// A state style can carry a transform, which `compose` folds into one;
|
|
@@ -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
|
+
}
|
package/src/color-transition.ts
CHANGED
|
@@ -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,11 @@
|
|
|
1
|
+
import { hozoAuthoredStyle } from './authored-gap.ts'
|
|
2
|
+
import { composeSpreadStyles } from './spread-styles.ts'
|
|
3
|
+
|
|
4
|
+
/** Only compiler-assessed possible gap owners import the gap-aware boundary. */
|
|
5
|
+
export function hozoGapSpreadStyles(
|
|
6
|
+
styles: Readonly<Record<string, unknown>>,
|
|
7
|
+
writtenLast: readonly string[],
|
|
8
|
+
...sources: readonly unknown[]
|
|
9
|
+
): Record<string, unknown> {
|
|
10
|
+
return composeSpreadStyles(styles, writtenLast, sources, hozoAuthoredStyle)
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Native-only, like the layout boundaries: the Web backend animates with CSS
|
|
2
|
+
// and never asks for it. In the engine rather than `@hozo/primitives`
|
|
3
|
+
// because `@hozo/patterns` runs it too, for a look resolved at run time
|
|
4
|
+
// (#1450), and patterns are built on the engine, not on primitives.
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
PresenceContext,
|
|
8
|
+
type PresenceContextValue,
|
|
9
|
+
type PresenceState,
|
|
10
|
+
} from '../presence-context.ts'
|
|
11
|
+
export {
|
|
12
|
+
HozoAnimated,
|
|
13
|
+
type HozoAnimatedProps,
|
|
14
|
+
type HozoTransitionSpec,
|
|
15
|
+
} from '../runtime-transition.native.tsx'
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
// Imported by the Metro candidate module rather than by a component.
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
type ClassResolver,
|
|
4
|
+
type ClassResolverPlan,
|
|
5
|
+
createClassResolver,
|
|
6
|
+
hozoTextMetricStyles,
|
|
7
|
+
type StyleObject,
|
|
8
|
+
} from '../class-resolver.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 {
|
|
3
|
+
export {
|
|
4
|
+
type HozoSafeAreaInsets,
|
|
5
|
+
useHozoProvidedSafeArea,
|
|
6
|
+
useHozoSafeArea,
|
|
7
|
+
} from '../safe-area.native.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'
|
package/src/hooks.native.ts
CHANGED
|
@@ -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.
|
|
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
|