@hozo/engine 0.1.0 → 0.3.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 (67) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +34 -0
  3. package/dist/class-resolver.d.ts +28 -5
  4. package/dist/class-resolver.d.ts.map +1 -1
  5. package/dist/class-resolver.js +59 -22
  6. package/dist/class-resolver.js.map +1 -1
  7. package/dist/color-transition.d.ts.map +1 -1
  8. package/dist/color-transition.js +6 -0
  9. package/dist/color-transition.js.map +1 -1
  10. package/dist/generated/animation.d.ts +1 -0
  11. package/dist/generated/animation.d.ts.map +1 -1
  12. package/dist/generated/animation.js +1 -0
  13. package/dist/generated/animation.js.map +1 -1
  14. package/dist/generated/transform-slots.d.ts +2 -0
  15. package/dist/generated/transform-slots.d.ts.map +1 -0
  16. package/dist/generated/transform-slots.js +4 -0
  17. package/dist/generated/transform-slots.js.map +1 -0
  18. package/dist/index.d.ts +1 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.native.d.ts +1 -0
  23. package/dist/index.native.d.ts.map +1 -1
  24. package/dist/index.native.js +1 -0
  25. package/dist/index.native.js.map +1 -1
  26. package/dist/interactive.d.ts +2 -0
  27. package/dist/interactive.d.ts.map +1 -1
  28. package/dist/interactive.js +4 -0
  29. package/dist/interactive.js.map +1 -1
  30. package/dist/keyframes.native.d.ts +27 -0
  31. package/dist/keyframes.native.d.ts.map +1 -0
  32. package/dist/keyframes.native.js +167 -0
  33. package/dist/keyframes.native.js.map +1 -0
  34. package/dist/project.d.ts +8 -0
  35. package/dist/project.d.ts.map +1 -1
  36. package/dist/project.js +9 -0
  37. package/dist/project.js.map +1 -1
  38. package/dist/project.native.d.ts +1 -1
  39. package/dist/project.native.d.ts.map +1 -1
  40. package/dist/project.native.js +1 -1
  41. package/dist/project.native.js.map +1 -1
  42. package/dist/transform-slots.d.ts +22 -0
  43. package/dist/transform-slots.d.ts.map +1 -0
  44. package/dist/transform-slots.js +108 -0
  45. package/dist/transform-slots.js.map +1 -0
  46. package/dist/view-base-css.d.ts +2 -0
  47. package/dist/view-base-css.d.ts.map +1 -0
  48. package/dist/view-base-css.js +20 -0
  49. package/dist/view-base-css.js.map +1 -0
  50. package/dist/view-base.d.ts +6 -0
  51. package/dist/view-base.d.ts.map +1 -0
  52. package/dist/view-base.js +15 -0
  53. package/dist/view-base.js.map +1 -0
  54. package/package.json +6 -1
  55. package/src/class-resolver.ts +93 -26
  56. package/src/color-transition.ts +6 -0
  57. package/src/generated/animation.ts +1 -0
  58. package/src/generated/transform-slots.ts +3 -0
  59. package/src/index.native.ts +5 -0
  60. package/src/index.ts +1 -1
  61. package/src/interactive.ts +4 -0
  62. package/src/keyframes.native.ts +210 -0
  63. package/src/project.native.ts +1 -1
  64. package/src/project.ts +11 -0
  65. package/src/transform-slots.ts +119 -0
  66. package/src/view-base-css.ts +19 -0
  67. package/src/view-base.ts +20 -0
@@ -0,0 +1,167 @@
1
+ // A project's own `@keyframes`, on React Native (decision 007, slice 3).
2
+ //
3
+ // `useHozoAnimation` runs Tailwind's four loops, whose frames are known in
4
+ // advance and written out by hand. This runs frames the compiler read from
5
+ // the project: a StyleX `stylex.keyframes(...)`, or a Tailwind theme's
6
+ // `--animate-*` and its `@keyframes`. The compiler hands over the frames as
7
+ // React Native style objects and the timing as CSS said it; this turns
8
+ // them into one progress value, interpolated per property.
9
+ //
10
+ // What it can move is what `HozoAnimated` can: opacity, the colours, and
11
+ // transforms. The compiler leaves out anything else and says so, because a
12
+ // width that jumped from frame to frame would be a different animation
13
+ // from the one on the Web.
14
+ import { useEffect, useMemo, useRef, useState } from 'react';
15
+ import { Animated, Easing } from 'react-native';
16
+ const COLOR_KEYS = ['backgroundColor', 'borderColor', 'color'];
17
+ /** What a transform key is when no frame sets it. */
18
+ function identity(key) {
19
+ if (key.startsWith('scale'))
20
+ return 1;
21
+ if (key.startsWith('rotate') || key.startsWith('skew'))
22
+ return '0deg';
23
+ return 0;
24
+ }
25
+ function easingFor(easing) {
26
+ if (Array.isArray(easing))
27
+ return Easing.bezier(...easing);
28
+ switch (easing) {
29
+ case 'linear':
30
+ return Easing.linear;
31
+ case 'ease-in':
32
+ return Easing.bezier(0.42, 0, 1, 1);
33
+ case 'ease-out':
34
+ return Easing.bezier(0, 0, 0.58, 1);
35
+ case 'ease-in-out':
36
+ return Easing.bezier(0.42, 0, 0.58, 1);
37
+ default:
38
+ // CSS's initial value, and what `animation` means with none written.
39
+ return Easing.bezier(0.25, 0.1, 0.25, 1);
40
+ }
41
+ }
42
+ /**
43
+ * One property's track: the frames that set it, in order, with the ends
44
+ * filled in where no frame does. CSS fills them from the element's own
45
+ * value; this fills them with the identity, which is the element's own
46
+ * value unless it has an opacity or a transform of its own.
47
+ */
48
+ function track(points, fill) {
49
+ const sorted = [...points].sort((a, b) => a.at - b.at);
50
+ if (fill !== undefined) {
51
+ if (sorted[0]?.at !== 0)
52
+ sorted.unshift({ at: 0, value: fill });
53
+ if (sorted[sorted.length - 1]?.at !== 1)
54
+ sorted.push({ at: 1, value: fill });
55
+ }
56
+ // `interpolate` needs a strictly increasing input range. Two frames at the
57
+ // same point are the later one winning, as in CSS.
58
+ const deduped = [];
59
+ for (const point of sorted) {
60
+ if (deduped.length > 0 && deduped[deduped.length - 1]?.at === point.at)
61
+ deduped.pop();
62
+ deduped.push(point);
63
+ }
64
+ return deduped;
65
+ }
66
+ export function useHozoKeyframes(spec) {
67
+ const progress = useRef(new Animated.Value(0)).current;
68
+ const [phase, setPhase] = useState(spec.delay ? 'waiting' : 'running');
69
+ const signature = JSON.stringify(spec);
70
+ // biome-ignore lint/correctness/useExhaustiveDependencies: `signature` is the spec, compared by value
71
+ useEffect(() => {
72
+ const iterations = spec.iterations ?? 1;
73
+ const direction = spec.direction ?? 'normal';
74
+ const reversed = direction === 'reverse' || direction === 'alternate-reverse';
75
+ const alternates = direction === 'alternate' || direction === 'alternate-reverse';
76
+ const colours = spec.frames.some((frame) => COLOR_KEYS.some((key) => frame.style[key] !== undefined));
77
+ const leg = (toValue) => Animated.timing(progress, {
78
+ toValue,
79
+ duration: spec.duration,
80
+ easing: easingFor(spec.easing),
81
+ // React Native cannot interpolate a colour on the native driver.
82
+ useNativeDriver: !colours,
83
+ });
84
+ let animation;
85
+ if (alternates) {
86
+ const forth = leg(reversed ? 0 : 1);
87
+ const back = leg(reversed ? 1 : 0);
88
+ animation =
89
+ iterations < 0
90
+ ? Animated.loop(Animated.sequence([forth, back]))
91
+ : Animated.sequence(Array.from({ length: iterations }, (_, i) => leg((i % 2 === 0) !== reversed ? 1 : 0)));
92
+ }
93
+ else {
94
+ animation = Animated.loop(leg(reversed ? 0 : 1), {
95
+ iterations: iterations < 0 ? -1 : iterations,
96
+ });
97
+ }
98
+ progress.setValue(reversed ? 1 : 0);
99
+ let timer;
100
+ const start = () => {
101
+ setPhase('running');
102
+ animation.start(({ finished }) => {
103
+ if (finished)
104
+ setPhase('done');
105
+ });
106
+ };
107
+ if (spec.delay) {
108
+ setPhase('waiting');
109
+ timer = setTimeout(start, spec.delay);
110
+ }
111
+ else {
112
+ start();
113
+ }
114
+ return () => {
115
+ clearTimeout(timer);
116
+ animation.stop();
117
+ };
118
+ }, [progress, signature]);
119
+ // biome-ignore lint/correctness/useExhaustiveDependencies: as above
120
+ const animated = useMemo(() => {
121
+ const style = {};
122
+ const range = (points) => ({
123
+ inputRange: points.map((point) => point.at),
124
+ // Numbers or unit strings, never mixed: the compiler writes one track in
125
+ // one unit. The cast is to the overload; the runtime takes either.
126
+ outputRange: points.map((point) => point.value),
127
+ });
128
+ const opacity = spec.frames.flatMap((frame) => frame.style.opacity === undefined ? [] : [{ at: frame.at, value: frame.style.opacity }]);
129
+ if (opacity.length > 0) {
130
+ style.opacity = progress.interpolate(range(track(opacity, 1)));
131
+ }
132
+ for (const key of COLOR_KEYS) {
133
+ const points = spec.frames.flatMap((frame) => frame.style[key] === undefined ? [] : [{ at: frame.at, value: frame.style[key] }]);
134
+ // No identity for a colour: the ends hold the nearest frame.
135
+ if (points.length > 0)
136
+ style[key] = progress.interpolate(range(track(points, undefined)));
137
+ }
138
+ const keys = [];
139
+ for (const frame of spec.frames) {
140
+ for (const entry of frame.style.transform ?? []) {
141
+ for (const key of Object.keys(entry))
142
+ if (!keys.includes(key))
143
+ keys.push(key);
144
+ }
145
+ }
146
+ if (keys.length > 0) {
147
+ style.transform = keys.map((key) => {
148
+ const points = spec.frames.flatMap((frame) => {
149
+ const entry = frame.style.transform?.find((candidate) => key in candidate);
150
+ return entry ? [{ at: frame.at, value: entry[key] }] : [];
151
+ });
152
+ return { [key]: progress.interpolate(range(track(points, identity(key)))) };
153
+ });
154
+ }
155
+ return style;
156
+ }, [progress, signature]);
157
+ // Outside the animation's run, CSS shows the element's own style unless
158
+ // the fill mode says otherwise: `backwards` holds the first frame through
159
+ // the delay, `forwards` the last after the end.
160
+ const fill = spec.fillMode ?? 'none';
161
+ if (phase === 'waiting' && fill !== 'backwards' && fill !== 'both')
162
+ return null;
163
+ if (phase === 'done' && fill !== 'forwards' && fill !== 'both')
164
+ return null;
165
+ return animated;
166
+ }
167
+ //# sourceMappingURL=keyframes.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyframes.native.js","sourceRoot":"","sources":["../src/keyframes.native.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,2EAA2E;AAC3E,2EAA2E;AAC3E,uEAAuE;AACvE,4EAA4E;AAC5E,uEAAuE;AACvE,2DAA2D;AAC3D,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,uEAAuE;AACvE,2BAA2B;AAE3B,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAuB,MAAM,cAAc,CAAA;AAmCpE,MAAM,UAAU,GAAG,CAA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CAAC;QACD,OAAO,KAAK,CAAA;IACd,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAA;IAEzB,wEAAwE;IACxE,0EAA0E;IAC1E,gDAAgD;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAA;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IAC/E,IAAI,KAAK,KAAK,MAAM,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAA;IAC3E,OAAO,QAAQ,CAAA;AACjB,CAAC"}
package/dist/project.d.ts CHANGED
@@ -7,4 +7,12 @@
7
7
  * reset is the common case and was the fallback before this entry existed.
8
8
  */
9
9
  export declare const hozoPreflight = true;
10
+ /**
11
+ * The project's class resolver, for code the compiler does not lower --
12
+ * `@hozo/patterns`' Native components resolve their class props through it
13
+ * (#886). Redirected to the generated candidate module like `hozoPreflight`;
14
+ * unconfigured, there is no candidate map, so it resolves nothing, which is
15
+ * what those props did before.
16
+ */
17
+ export declare const hozoClasses: import("./class-resolver.ts").ClassResolver;
10
18
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,OAAO,CAAA"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,OAAO,CAAA;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,6CAA0B,CAAA"}
package/dist/project.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { createClassResolver } from './class-resolver.js';
1
2
  /**
2
3
  * Project-wide Native defaults when no bundler integration supplies them.
3
4
  *
@@ -7,4 +8,12 @@
7
8
  * reset is the common case and was the fallback before this entry existed.
8
9
  */
9
10
  export const hozoPreflight = true;
11
+ /**
12
+ * The project's class resolver, for code the compiler does not lower --
13
+ * `@hozo/patterns`' Native components resolve their class props through it
14
+ * (#886). Redirected to the generated candidate module like `hozoPreflight`;
15
+ * unconfigured, there is no candidate map, so it resolves nothing, which is
16
+ * what those props did before.
17
+ */
18
+ export const hozoClasses = createClassResolver({});
10
19
  //# sourceMappingURL=project.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA"}
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAEzD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAEjC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAA"}
@@ -1,2 +1,2 @@
1
- export { hozoPreflight } from './project.ts';
1
+ export { hozoClasses, hozoPreflight } from './project.ts';
2
2
  //# sourceMappingURL=project.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.native.d.ts","sourceRoot":"","sources":["../src/project.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"project.native.d.ts","sourceRoot":"","sources":["../src/project.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
@@ -1,2 +1,2 @@
1
- export { hozoPreflight } from './project.js';
1
+ export { hozoClasses, hozoPreflight } from './project.js';
2
2
  //# sourceMappingURL=project.native.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.native.js","sourceRoot":"","sources":["../src/project.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"project.native.js","sourceRoot":"","sources":["../src/project.native.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,22 @@
1
+ export type TransformEntry = Record<string, number | string | readonly number[]>;
2
+ type Mode = 'slots' | 'authored' | 'none';
3
+ export interface TransformSlots {
4
+ translate?: Mode;
5
+ translateSlots?: TransformEntry[];
6
+ translateAuthored?: TransformEntry[];
7
+ rotate?: TransformEntry[];
8
+ scale?: Mode;
9
+ scaleSlots?: TransformEntry[];
10
+ scale3d?: boolean;
11
+ scaleAuthored?: TransformEntry[];
12
+ functions?: Mode;
13
+ functionsSlots?: TransformEntry[];
14
+ functionsAuthored?: TransformEntry[];
15
+ }
16
+ type Style = Record<string, unknown>;
17
+ export type TransformSpec = readonly [Style, TransformSlots];
18
+ export type TransformStyle = Style | false | null | undefined | readonly TransformStyle[];
19
+ /** Only generated reset-bearing boundaries need this; plain styles bypass it. */
20
+ export declare function hozoTransformStyles(styles: readonly TransformStyle[], specs: readonly TransformSpec[] | ReadonlyMap<Style, TransformSlots>): Style[];
21
+ export {};
22
+ //# sourceMappingURL=transform-slots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-slots.d.ts","sourceRoot":"","sources":["../src/transform-slots.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAA;AAChF,KAAK,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,MAAM,CAAA;AACzC,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,cAAc,EAAE,CAAA;IACpC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAA;IACzB,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,aAAa,CAAC,EAAE,cAAc,EAAE,CAAA;IAChC,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,cAAc,CAAC,EAAE,cAAc,EAAE,CAAA;IACjC,iBAAiB,CAAC,EAAE,cAAc,EAAE,CAAA;CACrC;AACD,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACpC,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;AAC5D,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,cAAc,EAAE,CAAA;AAEzF,iFAAiF;AACjF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,WAAW,CAAC,KAAK,EAAE,cAAc,CAAC,GACnE,KAAK,EAAE,CA6FT"}
@@ -0,0 +1,108 @@
1
+ /** Only generated reset-bearing boundaries need this; plain styles bypass it. */
2
+ export function hozoTransformStyles(styles, specs) {
3
+ // Candidate maps can contain thousands of entries. They pre-index once;
4
+ // resolving one class string must never walk the entire project map.
5
+ const metadata = Array.isArray(specs)
6
+ ? new Map(specs)
7
+ : specs;
8
+ const result = [];
9
+ const families = {
10
+ translate: {
11
+ slots: new Map(),
12
+ authored: [],
13
+ mode: 'slots',
14
+ },
15
+ scale: {
16
+ slots: new Map(),
17
+ authored: [],
18
+ mode: 'slots',
19
+ },
20
+ functions: {
21
+ slots: new Map(),
22
+ authored: [],
23
+ mode: 'slots',
24
+ },
25
+ };
26
+ let rotate = [];
27
+ let scale3d = false;
28
+ let touched = false;
29
+ function visit(style) {
30
+ if (!style)
31
+ return;
32
+ if (Array.isArray(style)) {
33
+ for (const part of style)
34
+ visit(part);
35
+ return;
36
+ }
37
+ const object = style;
38
+ const slots = metadata.get(object);
39
+ if (!slots) {
40
+ result.push(object);
41
+ // An authored RN transform is a whole-array override, not CSS slots.
42
+ if ('transform' in object) {
43
+ for (const family of Object.values(families)) {
44
+ family.slots.clear();
45
+ family.authored = [];
46
+ family.mode = 'none';
47
+ }
48
+ rotate = [];
49
+ scale3d = false;
50
+ touched = false;
51
+ }
52
+ return;
53
+ }
54
+ const { transform: _transform, ...rest } = object;
55
+ if (Object.keys(rest).length)
56
+ result.push(rest);
57
+ touched = true;
58
+ if (slots.rotate)
59
+ rotate = slots.rotate;
60
+ if (slots.scale3d !== undefined)
61
+ scale3d = slots.scale3d;
62
+ for (const name of ['translate', 'scale', 'functions']) {
63
+ const family = families[name];
64
+ for (const entry of slots[`${name}Slots`] ?? []) {
65
+ // A uniform 2D scale writes both registers. Keep Z's matrix separate.
66
+ if (name === 'scale' && 'scale' in entry) {
67
+ family.slots.set('scaleX', { scaleX: entry.scale });
68
+ family.slots.set('scaleY', { scaleY: entry.scale });
69
+ }
70
+ else {
71
+ const key = Object.keys(entry)[0];
72
+ if (key)
73
+ family.slots.set(key, entry);
74
+ }
75
+ }
76
+ const authored = slots[`${name}Authored`];
77
+ if (authored)
78
+ family.authored = authored;
79
+ if (slots[name])
80
+ family.mode = slots[name];
81
+ }
82
+ }
83
+ for (const style of styles)
84
+ visit(style);
85
+ if (touched) {
86
+ const output = (name, keys) => {
87
+ const family = families[name];
88
+ if (family.mode === 'none')
89
+ return [];
90
+ if (family.mode === 'authored')
91
+ return family.authored;
92
+ return keys.flatMap((key) => {
93
+ const entry = family.slots.get(key);
94
+ return entry ? [entry] : [];
95
+ });
96
+ };
97
+ result.push({
98
+ transform: [
99
+ ...output('translate', ['translateX', 'translateY', 'matrix']),
100
+ ...rotate,
101
+ ...output('scale', scale3d ? ['scaleX', 'scaleY', 'matrix'] : ['scaleX', 'scaleY']),
102
+ ...output('functions', ['rotateX', 'rotateY', 'rotateZ', 'skewX', 'skewY']),
103
+ ],
104
+ });
105
+ }
106
+ return result;
107
+ }
108
+ //# sourceMappingURL=transform-slots.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform-slots.js","sourceRoot":"","sources":["../src/transform-slots.ts"],"names":[],"mappings":"AAqBA,iFAAiF;AACjF,MAAM,UAAU,mBAAmB,CACjC,MAAiC,EACjC,KAAoE;IAEpE,wEAAwE;IACxE,qEAAqE;IACrE,MAAM,QAAQ,GAAuC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QACvE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC;QAChB,CAAC,CAAE,KAA4C,CAAA;IACjD,MAAM,MAAM,GAAY,EAAE,CAAA;IAC1B,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE;YACT,KAAK,EAAE,IAAI,GAAG,EAA0B;YACxC,QAAQ,EAAE,EAAsB;YAChC,IAAI,EAAE,OAAe;SACtB;QACD,KAAK,EAAE;YACL,KAAK,EAAE,IAAI,GAAG,EAA0B;YACxC,QAAQ,EAAE,EAAsB;YAChC,IAAI,EAAE,OAAe;SACtB;QACD,SAAS,EAAE;YACT,KAAK,EAAE,IAAI,GAAG,EAA0B;YACxC,QAAQ,EAAE,EAAsB;YAChC,IAAI,EAAE,OAAe;SACtB;KACF,CAAA;IACD,IAAI,MAAM,GAAqB,EAAE,CAAA;IACjC,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,IAAI,OAAO,GAAG,KAAK,CAAA;IACnB,SAAS,KAAK,CAAC,KAAqB;QAClC,IAAI,CAAC,KAAK;YAAE,OAAM;QAClB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,CAAA;YACrC,OAAM;QACR,CAAC;QACD,MAAM,MAAM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GAAG,CAAC,CAAA;gBACnC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;YAC7B,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA;QACD,MAAM,CAAC,IAAI,CAAC;YACV,SAAS,EAAE;gBACT,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;gBAC9D,GAAG,MAAM;gBACT,GAAG,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBACnF,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;aAC5E;SACF,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const HOZO_VIEW_BASE_CSS = "@layer base {\n :where(.hozo-view) {\n display: flex;\n flex-direction: column;\n flex-shrink: 0;\n position: relative;\n min-width: 0;\n box-sizing: border-box;\n margin: 0;\n padding: 0;\n border: 0 solid;\n }\n\n :where([data-hozo-pressable]:not(:disabled, [data-hozo-disabled], [aria-disabled=\"true\"])) {\n cursor: pointer;\n }\n}\n";
2
+ //# sourceMappingURL=view-base-css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-base-css.d.ts","sourceRoot":"","sources":["../src/view-base-css.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,yXAiB9B,CAAA"}
@@ -0,0 +1,20 @@
1
+ // Generated by scripts/view-base.mjs from the Web backend's shared CSS.
2
+ export const HOZO_VIEW_BASE_CSS = `@layer base {
3
+ :where(.hozo-view) {
4
+ display: flex;
5
+ flex-direction: column;
6
+ flex-shrink: 0;
7
+ position: relative;
8
+ min-width: 0;
9
+ box-sizing: border-box;
10
+ margin: 0;
11
+ padding: 0;
12
+ border: 0 solid;
13
+ }
14
+
15
+ :where([data-hozo-pressable]:not(:disabled, [data-hozo-disabled], [aria-disabled="true"])) {
16
+ cursor: pointer;
17
+ }
18
+ }
19
+ `;
20
+ //# sourceMappingURL=view-base-css.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-base-css.js","sourceRoot":"","sources":["../src/view-base-css.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;CAiBjC,CAAA"}
@@ -0,0 +1,6 @@
1
+ export declare function hozoViewBase(): import("react").ReactElement<{
2
+ href: string;
3
+ precedence: string;
4
+ }, string | import("react").JSXElementConstructor<any>>;
5
+ export declare function hozoViewClassName(className?: string): string;
6
+ //# sourceMappingURL=view-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-base.d.ts","sourceRoot":"","sources":["../src/view-base.ts"],"names":[],"mappings":"AAYA,wBAAgB,YAAY;;;wDAE3B;AAED,wBAAgB,iBAAiB,CAAC,SAAS,CAAC,EAAE,MAAM,UAGnD"}
@@ -0,0 +1,15 @@
1
+ import { createElement } from 'react';
2
+ import { HOZO_VIEW_BASE_CSS } from './view-base-css.js';
3
+ // A React 19 stylesheet resource, not an effect or a DOM mutation. React
4
+ // hoists and deduplicates it in SSR and on the client, even if every box asks
5
+ // for it. Defaults belong in CSS, not inline styles that defeat utilities.
6
+ const resource = createElement('style', { href: 'hozo-view-base', precedence: 'hozo-base' }, HOZO_VIEW_BASE_CSS);
7
+ export function hozoViewBase() {
8
+ return resource;
9
+ }
10
+ export function hozoViewClassName(className) {
11
+ if (!className)
12
+ return 'hozo-view';
13
+ return className.split(/\s+/).includes('hozo-view') ? className : `hozo-view ${className}`;
14
+ }
15
+ //# sourceMappingURL=view-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view-base.js","sourceRoot":"","sources":["../src/view-base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,yEAAyE;AACzE,8EAA8E;AAC9E,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,aAAa,CAC5B,OAAO,EACP,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,EACnD,kBAAkB,CACnB,CAAA;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAkB;IAClD,IAAI,CAAC,SAAS;QAAE,OAAO,WAAW,CAAA;IAClC,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,aAAa,SAAS,EAAE,CAAA;AAC5F,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hozo/engine",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Runtime fallback for genuinely dynamic styles, interactive behavior, and accessibility behavior.",
5
5
  "keywords": [
6
6
  "react-native",
@@ -85,9 +85,14 @@
85
85
  "types": "./dist/generated/scrollable.d.ts",
86
86
  "default": "./dist/generated/scrollable.js"
87
87
  },
88
+ "./generated/transform-slots": {
89
+ "types": "./dist/generated/transform-slots.d.ts",
90
+ "default": "./dist/generated/transform-slots.js"
91
+ },
88
92
  "./package.json": "./package.json"
89
93
  },
90
94
  "files": [
95
+ "CHANGELOG.md",
91
96
  "dist",
92
97
  "src",
93
98
  "!src/**/*.test.ts",
@@ -1,74 +1,141 @@
1
1
  /** A React Native style object, as the compiler emits it. */
2
2
  export type StyleObject = Record<string, unknown>
3
3
 
4
+ /**
5
+ * The state an element is in when its runtime classes are resolved: what
6
+ * its pressable reports (`pressed`, `hovered`, `focused`, `focusVisible`)
7
+ * and what its props say: `disabled`, and `aria-checked`, `aria-selected` and
8
+ * the rest under their attribute names, so `aria-pressed` cannot be read as
9
+ * the pointer's `pressed`.
10
+ */
11
+ export type ClassState = Readonly<Record<string, unknown>>
12
+
13
+ /**
14
+ * A class that applies only in a state: the state keys that all have to
15
+ * hold, and the style it applies then. `active:opacity-80` is
16
+ * `[['pressed'], { opacity: 0.8 }]`.
17
+ */
18
+ export type StateGroup = readonly [readonly string[], StyleObject]
19
+
4
20
  /**
5
21
  * Resolves whitespace-separated class names to React Native style objects.
6
22
  *
7
23
  * Returns an array, which is a valid `style` value on its own and also
8
24
  * nests inside one -- RN flattens arbitrarily nested style arrays, so
9
25
  * callers never have to spread it.
26
+ *
27
+ * `state` is what the element is in. Without it, a class that applies only
28
+ * in a state is reported as it always was; with it, that class applies
29
+ * when its state holds, after the unconditional ones.
10
30
  */
11
- export type ClassResolver = (value: unknown) => StyleObject[]
31
+ export type ClassResolver = (value: unknown, state?: ClassState) => StyleObject[]
32
+
33
+ interface Resolved {
34
+ /** The unconditional styles, composed: what a string with no state classes returns. */
35
+ base: StyleObject[]
36
+ /** The same, before `compose`, for composing again with state styles. */
37
+ raw: StyleObject[]
38
+ groups: StateGroup[]
39
+ /** State classes in this string, named if it is resolved without a state. */
40
+ stateClasses: string[]
41
+ }
12
42
 
13
43
  /**
14
44
  * Builds a resolver over one project's candidate map.
15
45
  *
16
46
  * Called by the generated candidate module rather than by application
17
- * code: `styles` and `unsupported` are build output, and binding them here
18
- * keeps the generated file to data plus one call.
47
+ * code: `styles`, `unsupported` and `states` are build output, and binding
48
+ * them here keeps the generated file to data plus one call.
19
49
  *
20
50
  * `unsupported` maps a class the compiler *recognized but can't express*
21
- * as a plain style object -- a conditional utility (`hover:`, `md:`), or
51
+ * as a plain style object -- a utility under a breakpoint or `dark:`, or
22
52
  * one that's Web-only -- to the reason. Those are reported when they're
23
53
  * actually used rather than at build time, because a class appearing in
24
54
  * the project's candidate scan doesn't mean any dynamic expression ever
25
55
  * produces it.
56
+ *
57
+ * `states` holds the classes whose only condition is the element's own
58
+ * state (#886). Those need no tracking here: the pressable that renders
59
+ * the element already tracks it and hands it in, so this stays a function
60
+ * of the class string and that state.
26
61
  */
27
62
  export function createClassResolver(
28
63
  styles: Record<string, StyleObject>,
29
64
  unsupported: Record<string, string> = {},
65
+ compose?: (styles: StyleObject[]) => StyleObject[],
66
+ states: Record<string, readonly StateGroup[]> = {},
30
67
  ): ClassResolver {
31
68
  // Class strings repeat constantly across renders and list items, and the
32
69
  // result is immutable, so each distinct string is resolved once.
33
- const cache = new Map<string, StyleObject[]>()
70
+ const cache = new Map<string, Resolved>()
34
71
  // Warn once per class, not once per render -- a warning inside a list's
35
72
  // render path would otherwise repeat for every row, every frame.
36
73
  const warned = new Set<string>()
74
+ const warn = (name: string, reason: string) => {
75
+ if (warned.has(name)) return
76
+ warned.add(name)
77
+ // eslint-disable-next-line no-console
78
+ console.warn(`[hozo] ${reason}`)
79
+ }
37
80
 
38
- return function hozoClasses(value: unknown): StyleObject[] {
39
- // Falsy is the normal case, not an error: `cond && 'p-4'` yields
40
- // `false` whenever the condition is off.
41
- if (typeof value !== 'string' || value === '') {
42
- return []
43
- }
44
-
45
- const cached = cache.get(value)
46
- if (cached) {
47
- return cached
48
- }
49
-
50
- const resolved: StyleObject[] = []
81
+ function resolve(value: string): Resolved {
82
+ const base: StyleObject[] = []
83
+ const groups: StateGroup[] = []
84
+ const stateClasses: string[] = []
51
85
  for (const name of value.split(/\s+/)) {
52
86
  if (name === '') {
53
87
  continue
54
88
  }
55
89
  const style = styles[name]
56
90
  if (style) {
57
- resolved.push(style)
91
+ base.push(style)
92
+ continue
93
+ }
94
+ const conditional = states[name]
95
+ if (conditional) {
96
+ groups.push(...conditional)
97
+ stateClasses.push(name)
58
98
  continue
59
99
  }
60
100
  // An unknown class isn't necessarily a Hozo problem -- it may be an
61
101
  // app's own non-Tailwind class, or a testID-ish marker -- so only the
62
102
  // ones the compiler recognized and refused are reported.
63
103
  const reason = unsupported[name]
64
- if (reason && !warned.has(name)) {
65
- warned.add(name)
66
- // eslint-disable-next-line no-console
67
- console.warn(`[hozo] ${reason}`)
68
- }
104
+ if (reason) warn(name, reason)
105
+ }
106
+ return { base: compose ? compose(base) : base, raw: base, groups, stateClasses }
107
+ }
108
+
109
+ return function hozoClasses(value: unknown, state?: ClassState): StyleObject[] {
110
+ // Falsy is the normal case, not an error: `cond && 'p-4'` yields
111
+ // `false` whenever the condition is off.
112
+ if (typeof value !== 'string' || value === '') {
113
+ return []
69
114
  }
70
115
 
71
- cache.set(value, resolved)
72
- return resolved
116
+ let resolved = cache.get(value)
117
+ if (!resolved) {
118
+ resolved = resolve(value)
119
+ cache.set(value, resolved)
120
+ }
121
+ if (resolved.groups.length === 0) return resolved.base
122
+ if (state === undefined) {
123
+ for (const name of resolved.stateClasses) {
124
+ warn(
125
+ name,
126
+ `\`${name}\` applies in a state, and this element hands its classes no state to ` +
127
+ 'resolve it against. Put it on a Pressable, Button or Link, or write it as a static ' +
128
+ 'className so it compiles to a real style variant.',
129
+ )
130
+ }
131
+ return resolved.base
132
+ }
133
+ const active = resolved.groups.filter(([keys]) => keys.every((key) => Boolean(state[key])))
134
+ if (active.length === 0) return resolved.base
135
+ const all = [...resolved.raw, ...active.map(([, style]) => style)]
136
+ // A state style can carry a transform, which `compose` folds into one;
137
+ // so it runs over the whole list, and the result is per render rather
138
+ // than cached -- it changes with the state.
139
+ return compose ? compose(all) : all
73
140
  }
74
141
  }