embedded-react 0.20.0 → 0.22.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 (140) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +3 -2
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +17 -47
  5. package/aot/compiler/alerts.mjs +604 -0
  6. package/aot/compiler/animations.mjs +299 -57
  7. package/aot/compiler/boot.mjs +27 -2
  8. package/aot/compiler/check.mjs +62 -10
  9. package/aot/compiler/collect.mjs +517 -137
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +276 -117
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/elements/button.mjs +182 -0
  14. package/aot/compiler/elements/image-background.mjs +76 -0
  15. package/aot/compiler/elements/image.mjs +2 -1
  16. package/aot/compiler/elements/props.mjs +47 -8
  17. package/aot/compiler/elements/rewrite.mjs +118 -0
  18. package/aot/compiler/elements/section-list.mjs +370 -0
  19. package/aot/compiler/expressions.mjs +1378 -97
  20. package/aot/compiler/handlers.mjs +1807 -354
  21. package/aot/compiler/helper-values.mjs +312 -0
  22. package/aot/compiler/ir/nodes.mjs +40 -1
  23. package/aot/compiler/ir/reads.mjs +206 -5
  24. package/aot/compiler/ir/text.mjs +5 -1
  25. package/aot/compiler/ir/types.mjs +12 -0
  26. package/aot/compiler/kept-states.mjs +177 -0
  27. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  28. package/aot/compiler/keyboard.mjs +1 -1
  29. package/aot/compiler/list-items.mjs +226 -0
  30. package/aot/compiler/list-order.mjs +586 -0
  31. package/aot/compiler/list-split.mjs +259 -0
  32. package/aot/compiler/loops.mjs +582 -0
  33. package/aot/compiler/lower.mjs +203 -53
  34. package/aot/compiler/native-files.mjs +439 -0
  35. package/aot/compiler/native-header.mjs +335 -0
  36. package/aot/compiler/native-modules.mjs +1173 -0
  37. package/aot/compiler/nodes.mjs +45 -31
  38. package/aot/compiler/options.mjs +3 -2
  39. package/aot/compiler/out.mjs +18 -1
  40. package/aot/compiler/package/animations.mjs +133 -23
  41. package/aot/compiler/package/assemble.mjs +2 -4
  42. package/aot/compiler/package/bytecode.mjs +37 -8
  43. package/aot/compiler/package/checks.mjs +4 -0
  44. package/aot/compiler/package/codegen.mjs +906 -33
  45. package/aot/compiler/package/enums.mjs +10 -0
  46. package/aot/compiler/package/format.mjs +16 -3
  47. package/aot/compiler/package/lower.mjs +707 -176
  48. package/aot/compiler/package/string-caps.mjs +515 -0
  49. package/aot/compiler/package/tables.mjs +24 -0
  50. package/aot/compiler/package/writer.mjs +22 -0
  51. package/aot/compiler/parse.mjs +3 -1
  52. package/aot/compiler/record-shapes.mjs +246 -0
  53. package/aot/compiler/records.mjs +654 -0
  54. package/aot/compiler/reducers.mjs +272 -0
  55. package/aot/compiler/scroll-to.mjs +112 -0
  56. package/aot/compiler/static-eval.mjs +315 -7
  57. package/aot/compiler/style-text.mjs +20 -5
  58. package/aot/compiler/svg.mjs +13 -7
  59. package/aot/compiler/switch-cases.mjs +198 -0
  60. package/aot/compiler/tagged-records.mjs +450 -0
  61. package/aot/compiler/typing.mjs +307 -0
  62. package/aot/compiler/updaters.mjs +321 -0
  63. package/aot/compiler/window-dimensions.mjs +94 -0
  64. package/aot/compiler/worked-values.mjs +319 -0
  65. package/aot/demo-file.mjs +30 -0
  66. package/aot/style-map.mjs +94 -3
  67. package/assets/bake-font.mjs +187 -244
  68. package/assets/bake-image.mjs +47 -71
  69. package/assets/bake-svg.mjs +465 -533
  70. package/assets/build-builtin-font.mjs +14 -27
  71. package/assets/emit-c.mjs +124 -204
  72. package/assets/emit-container.mjs +129 -197
  73. package/assets/emit-pack.mjs +92 -136
  74. package/assets/font-config.mjs +19 -27
  75. package/assets/font-sizes.mjs +432 -507
  76. package/assets/glyph-coverage.mjs +170 -214
  77. package/assets/index.mjs +52 -97
  78. package/assets/rasterize.mjs +173 -194
  79. package/assets/svg-loader.mjs +42 -48
  80. package/build.mjs +85 -94
  81. package/cli.mjs +490 -586
  82. package/compile-bin.mjs +24 -36
  83. package/flash.mjs +297 -401
  84. package/hotreload/dev-device.mjs +229 -270
  85. package/hotreload/pack-app.mjs +118 -159
  86. package/hotreload/pack-split.mjs +146 -213
  87. package/hotreload/package-transfer.mjs +128 -131
  88. package/hotreload/protocol.mjs +118 -118
  89. package/hotreload/uploader.mjs +132 -159
  90. package/hotreload/watch-tree.mjs +56 -65
  91. package/pack-container.mjs +94 -116
  92. package/package.json +19 -16
  93. package/persist-transform.mjs +89 -105
  94. package/qjsc-wasm.mjs +47 -72
  95. package/sim/embedded-react.wasm +0 -0
  96. package/sim/index.html +1 -1
  97. package/sim-server.mjs +260 -354
  98. package/src/embedded-react/Alert.mjs +112 -0
  99. package/src/embedded-react/Animated.mjs +412 -0
  100. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  101. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  102. package/src/embedded-react/Dimensions.mjs +32 -0
  103. package/src/embedded-react/Easing.mjs +34 -0
  104. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  105. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  106. package/src/embedded-react/Keyboard.mjs +82 -0
  107. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  108. package/src/embedded-react/PanResponder.mjs +256 -0
  109. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  110. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  111. package/src/embedded-react/SectionList.mjs +103 -0
  112. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  113. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  114. package/src/embedded-react/background-image.mjs +321 -0
  115. package/src/embedded-react/{components.js → components.mjs} +1 -3
  116. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  117. package/src/embedded-react/index.d.ts +238 -5
  118. package/src/embedded-react/index.js +26 -17
  119. package/src/embedded-react/layout-anim-config.mjs +85 -0
  120. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  121. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  122. package/src/embedded-react/nativeModule.mjs +371 -0
  123. package/src/embedded-react/split-style.mjs +57 -0
  124. package/src/embedded-react/svg-ops.mjs +1075 -0
  125. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  126. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  127. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  128. package/src/host-config.mjs +512 -0
  129. package/src/{native-ui.js → native-ui.mjs} +1 -8
  130. package/src/props.mjs +341 -0
  131. package/src/{renderer.js → renderer.mjs} +30 -44
  132. package/src/embedded-react/Animated.js +0 -440
  133. package/src/embedded-react/Easing.js +0 -39
  134. package/src/embedded-react/PanResponder.js +0 -330
  135. package/src/embedded-react/SectionList.js +0 -148
  136. package/src/embedded-react/layout-anim-config.js +0 -101
  137. package/src/embedded-react/split-style.js +0 -58
  138. package/src/embedded-react/svg-ops.js +0 -1295
  139. package/src/host-config.js +0 -548
  140. package/src/props.js +0 -306
@@ -20,7 +20,7 @@
20
20
  //
21
21
  // What is declared here is what the RUNTIME honors. The sources of truth are the bridge's prop and event
22
22
  // tables (`k_prop_names` / `event_type_from_name` in bridges/quickjs/native_ui_bridge.c), the top-level
23
- // prop list (`PASSTHROUGH` in src/props.js), and the SVG compiler (src/embedded-react/svg-ops.js). A prop
23
+ // prop list (`PASSTHROUGH` in src/props.mts), and the SVG compiler (src/embedded-react/svg-ops.mts). A prop
24
24
  // the engine ignores is deliberately absent, so a name that typechecks is a name that reaches the engine.
25
25
  // `npm test` runs a parity test over those tables to keep it that way.
26
26
  //
@@ -75,10 +75,36 @@ export type StyleValue =
75
75
  | number
76
76
  | AnimatedNode
77
77
  | TransformStyle[]
78
+ | BackgroundImageValue[]
78
79
  | ShadowOffset
79
80
  | TransformOrigin
80
81
  | undefined;
81
82
 
83
+ /** A color stop of a gradient. Each position is a percentage such as `'40%'`; two paint the color across a band. */
84
+ export interface GradientColorStop {
85
+ color: string;
86
+ positions?: string[];
87
+ }
88
+
89
+ /**
90
+ * A gradient in React Native's object form. `direction` is an angle (`'45deg'`) or `to` a side or corner
91
+ * (`'to bottom right'`), and defaults to `'to bottom'`. A radial gradient is a circle from the center to the
92
+ * farthest corner.
93
+ */
94
+ export type BackgroundImageValue =
95
+ | {
96
+ type: 'linear-gradient';
97
+ direction?: string;
98
+ colorStops: GradientColorStop[];
99
+ }
100
+ | {
101
+ type: 'radial-gradient';
102
+ shape: 'circle';
103
+ size?: 'farthest-corner';
104
+ position?: 'center';
105
+ colorStops: GradientColorStop[];
106
+ };
107
+
82
108
  /** A single style object. Properties mirror the React Native subset the engine supports. */
83
109
  export interface ViewStyle {
84
110
  [key: string]: StyleValue;
@@ -158,6 +184,12 @@ export interface ViewStyle {
158
184
 
159
185
  // Paint.
160
186
  backgroundColor?: string | AnimatedNode;
187
+ /**
188
+ * One gradient of two to four stops behind a View, ScrollView or Pressable: a CSS `linear-gradient()` or
189
+ * `radial-gradient(circle, ...)` string, or an array of one gradient object. Firmware built without
190
+ * `ERUI_GRADIENT` paints `backgroundColor` instead.
191
+ */
192
+ backgroundImage?: string | BackgroundImageValue[];
161
193
  opacity?: number | AnimatedNode;
162
194
 
163
195
  // Border.
@@ -182,7 +214,7 @@ export interface ViewStyle {
182
214
  transform?: TransformStyle[];
183
215
  transformOrigin?: TransformOrigin;
184
216
 
185
- // Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS) and `shadowOpacity` above 0.
217
+ // Shadow. Rendered only in a build with shadows enabled (ERUI_SHADOWS), by `shadowOpacity` above 0 or an `elevation`.
186
218
  shadowColor?: string;
187
219
  shadowOffset?: ShadowOffset;
188
220
  shadowOpacity?: number;
@@ -434,8 +466,8 @@ export interface FlatListProps<T = unknown> {
434
466
  /**
435
467
  * `<SectionList>` is a thin `<ScrollView>` alias like `<FlatList>` — no virtualization, no sticky
436
468
  * headers, and every header, row and footer mounts as a real engine node and stays mounted. Header,
437
- * rows and footer are flat siblings, exactly as in RN. Flow A / simulator only for now: the AOT has no
438
- * `<SectionList>` lowering yet.
469
+ * rows and footer are flat siblings, exactly as in RN. Flow B unrolls the sections at build time, so
470
+ * write them out in place or use a constant array.
439
471
  */
440
472
  export interface SectionListProps<ItemT = unknown, SectionT = DefaultSectionT> {
441
473
  sections?: ReadonlyArray<SectionListData<ItemT, SectionT>>;
@@ -788,6 +820,89 @@ export const Platform: {
788
820
  select<T>(specifics: Record<string, T>): T | undefined;
789
821
  };
790
822
 
823
+ // --- Dimensions ------------------------------------------------------------
824
+ /** The panel's size in pixels. `scale` and `fontScale` are always 1. */
825
+ export interface ScaledSize {
826
+ width: number;
827
+ height: number;
828
+ scale: number;
829
+ fontScale: number;
830
+ }
831
+
832
+ export const Dimensions: {
833
+ /** The panel's size. 'window' and 'screen' are the same on a panel. */
834
+ get(dimension: 'window' | 'screen'): ScaledSize;
835
+ };
836
+
837
+ /** The panel's size. It is fixed while the app runs. */
838
+ export function useWindowDimensions(): ScaledSize;
839
+
840
+ // --- Alert -----------------------------------------------------------------
841
+ export interface AlertButton {
842
+ text?: string;
843
+ onPress?: () => void;
844
+ /** 'destructive' draws the label in red; 'cancel' looks like 'default'. */
845
+ style?: 'default' | 'cancel' | 'destructive';
846
+ }
847
+
848
+ export interface AlertOptions {
849
+ /** Lets a tap outside the dialog close it. Off by default. */
850
+ cancelable?: boolean;
851
+ /** Called when a tap outside closes a cancelable alert. */
852
+ onDismiss?: () => void;
853
+ }
854
+
855
+ export const Alert: {
856
+ /**
857
+ * Shows a stock dialog over the app. With no buttons it gets a single "OK". A second alert waits
858
+ * until the first is closed; in Flow B it replaces the first.
859
+ */
860
+ alert(
861
+ title: string,
862
+ message?: string,
863
+ buttons?: AlertButton[],
864
+ options?: AlertOptions,
865
+ ): void;
866
+ };
867
+
868
+ // --- Keyboard --------------------------------------------------------------
869
+ export type KeyboardEventName =
870
+ | 'keyboardWillShow'
871
+ | 'keyboardDidShow'
872
+ | 'keyboardWillHide'
873
+ | 'keyboardDidHide';
874
+
875
+ /** The strip of the screen the on-screen keyboard covers, in pixels. */
876
+ export interface KeyboardMetrics {
877
+ screenX: number;
878
+ screenY: number;
879
+ width: number;
880
+ height: number;
881
+ }
882
+
883
+ export interface KeyboardEvent {
884
+ /** Where the keyboard ends up: its strip when it shows, the same strip just below the screen when it hides. */
885
+ endCoordinates: KeyboardMetrics;
886
+ }
887
+
888
+ /**
889
+ * The on-screen keyboard, which shows while a `<TextInput>` has the focus. A build without it
890
+ * (ERUI_ONSCREEN_KEYBOARD=0) fires no events and is never visible; `dismiss()` still takes the focus away.
891
+ */
892
+ export const Keyboard: {
893
+ /** Nothing animates, so each "will" event fires just before its "did". */
894
+ addListener(
895
+ eventName: KeyboardEventName,
896
+ listener: (event: KeyboardEvent) => void,
897
+ ): {remove(): void};
898
+ removeAllListeners(eventName: KeyboardEventName): void;
899
+ /** Takes the focus from the focused `<TextInput>`, which hides the keyboard. */
900
+ dismiss(): void;
901
+ isVisible(): boolean;
902
+ /** The keyboard's strip, or undefined while it is hidden. */
903
+ metrics(): KeyboardMetrics | undefined;
904
+ };
905
+
791
906
  // --- AppRegistry -----------------------------------------------------------
792
907
  export const AppRegistry: {
793
908
  registerComponent(
@@ -929,10 +1044,110 @@ export function usePersistentState<S>(
929
1044
  ): [S, (value: S | ((prev: S) => S)) => void];
930
1045
 
931
1046
  export function useHostValue(initial: number): number;
1047
+
1048
+ /** A whole number. A native method's `Int` is an int in C, where a `number` is a float. */
1049
+ export type Int = number;
1050
+
1051
+ /**
1052
+ * A whole number that may be past an Int's range: a native method's `Int64` is an int64_t in C. In JS it is a number,
1053
+ * so it is exact up to 2^53.
1054
+ */
1055
+ export type Int64 = number;
1056
+
1057
+ /** An optional native module, as nativeModule.optional returns it. */
1058
+ export type OptionalNativeModule<T> = T & {
1059
+ /** Whether the firmware has every method and event of the module. Set at load, and it never changes. */
1060
+ readonly available: boolean;
1061
+ };
1062
+
1063
+ /**
1064
+ * A module the firmware provides in C, declared at module level by an interface of its methods, which take and
1065
+ * return Int, Int64, number, boolean, string and records of them:
1066
+ * `const Sensors = nativeModule<Sensors>('sensors', 1)`. Its events are the interface's `events`:
1067
+ * `events: {reading(celsius: number): void}`.
1068
+ */
1069
+ export const nativeModule: {
1070
+ <T>(name: string, version: number): T;
1071
+ /**
1072
+ * A module only some boards have: `const Wifi = nativeModule.optional<Wifi>('wifi', 1)`. A package that uses it
1073
+ * loads without it, and `Wifi.available` says whether it is there. Calling a method of a module that isn't stops
1074
+ * the app; its events never arrive.
1075
+ */
1076
+ optional<T>(name: string, version: number): OptionalNativeModule<T>;
1077
+ };
1078
+
1079
+ /** The events a native module's interface declares. */
1080
+ export type NativeEvents<T> = T extends {events: infer E} ? E : {};
1081
+
1082
+ /** The values an event is posted with. */
1083
+ export type NativeEventValues<
1084
+ T,
1085
+ K extends keyof NativeEvents<T>,
1086
+ > = NativeEvents<T>[K] extends (...values: infer V) => void ? V : never;
1087
+
1088
+ /**
1089
+ * Runs `handler` with an event's values each time the firmware posts it, while the component is mounted:
1090
+ * `useNativeEvent(Sensors, 'reading', celsius => setTemperature(celsius))`.
1091
+ */
1092
+ export function useNativeEvent<T, K extends keyof NativeEvents<T> & string>(
1093
+ module: T,
1094
+ event: K,
1095
+ handler: (...values: NativeEventValues<T, K>) => void,
1096
+ ): void;
1097
+
1098
+ /** Posts one of a mocked module's events, as the firmware would. false while one of the mock's methods runs. */
1099
+ export type NativeEmit<T> = <K extends keyof NativeEvents<T> & string>(
1100
+ event: K,
1101
+ ...values: NativeEventValues<T, K>
1102
+ ) => boolean;
1103
+
1104
+ /**
1105
+ * A native module's mock for the simulators, the default export of `<name>.mock.ts`: its methods, or a function
1106
+ * that is given `emit` and returns them.
1107
+ */
1108
+ export type NativeMock<T> =
1109
+ Omit<T, 'events'> | ((emit: NativeEmit<T>) => Omit<T, 'events'>);
932
1110
  export const Easing: {readonly [K in EasingName]: K} & {
933
1111
  bezier(x1: number, y1: number, x2: number, y2: number): BezierEasing;
934
1112
  };
935
- export const LayoutAnimation: Record<string, unknown>;
1113
+
1114
+ // --- LayoutAnimation -------------------------------------------------------
1115
+
1116
+ /** One phase of a layout animation. */
1117
+ export interface LayoutAnimationPhase {
1118
+ type?: string;
1119
+ property?: string;
1120
+ springDamping?: number;
1121
+ }
1122
+
1123
+ /** A layout animation, in React Native's shape. The engine tweens position; `update.type` picks the curve. */
1124
+ export interface LayoutAnimationConfig {
1125
+ /** Default 300. */
1126
+ duration?: number;
1127
+ type?: string;
1128
+ create?: LayoutAnimationPhase;
1129
+ update?: LayoutAnimationPhase;
1130
+ delete?: LayoutAnimationPhase;
1131
+ }
1132
+
1133
+ export const LayoutAnimation: {
1134
+ /** Animates the layout changes of the next commit. Call it right before the state update that moves things. */
1135
+ configureNext(config?: LayoutAnimationConfig | null, done?: () => void): void;
1136
+ create(
1137
+ duration: number,
1138
+ type?: string,
1139
+ creationProp?: string,
1140
+ ): LayoutAnimationConfig;
1141
+ Types: Record<
1142
+ 'spring' | 'linear' | 'easeInEaseOut' | 'easeIn' | 'easeOut' | 'keyboard',
1143
+ string
1144
+ >;
1145
+ Properties: Record<'opacity' | 'scaleX' | 'scaleY' | 'scaleXY', string>;
1146
+ Presets: Record<'easeInEaseOut' | 'linear' | 'spring', LayoutAnimationConfig>;
1147
+ easeInEaseOut(done?: () => void): void;
1148
+ linear(done?: () => void): void;
1149
+ spring(done?: () => void): void;
1150
+ };
936
1151
 
937
1152
  // --- PanResponder ----------------------------------------------------------
938
1153
 
@@ -1079,6 +1294,24 @@ export function updateText(
1079
1294
  text: string | number,
1080
1295
  ): void;
1081
1296
 
1297
+ /** Where a `<ScrollView>` is scrolled to, and the largest offset it accepts on each axis. */
1298
+ export interface ScrollPosition {
1299
+ x: number;
1300
+ y: number;
1301
+ maxX: number;
1302
+ maxY: number;
1303
+ }
1304
+
1305
+ /**
1306
+ * Scrolls a `<ScrollView>` and returns where it landed, or `undefined` when the handle is not a
1307
+ * ScrollView. The offset is clamped to the scroll range, and an axis left out stays where it is, so
1308
+ * `scrollTo(handle)` only reads the position. The range is as of the last render.
1309
+ */
1310
+ export function scrollTo(
1311
+ handle: NodeHandle | null | undefined,
1312
+ offset?: {x?: number; y?: number},
1313
+ ): ScrollPosition | undefined;
1314
+
1082
1315
  /** One key in a `setKeyboardConfig` layer. `char` types it; `layer` switches layer; `backspace`/`done` act. */
1083
1316
  export interface KeyboardKey {
1084
1317
  char?: string;
@@ -39,20 +39,29 @@ export {
39
39
  Line,
40
40
  G,
41
41
  Arc,
42
- } from './components.js';
43
- export {Pressable} from './Pressable.js';
44
- export {Button} from './Button.js';
45
- export {TouchableOpacity} from './TouchableOpacity.js';
46
- export {FlatList} from './FlatList.js';
47
- export {ImageBackground} from './ImageBackground.js';
48
- export {SectionList} from './SectionList.js';
49
- export {updateVector, updateText, setKeyboardConfig} from './imperative.js';
50
- export {StyleSheet} from './StyleSheet.js';
51
- export {Platform} from './Platform.js';
52
- export {AppRegistry} from './AppRegistry.js';
53
- export {Animated, useAnimatedValue} from './Animated.js';
54
- export {PanResponder} from './PanResponder.js';
55
- export {usePersistentState} from './usePersistentState.js';
56
- export {useHostValue} from './useHostValue.js';
57
- export {Easing} from './Easing.js';
58
- export {LayoutAnimation} from './LayoutAnimation.js';
42
+ } from './components.mjs';
43
+ export {Pressable} from './Pressable.mjs';
44
+ export {Button} from './Button.mjs';
45
+ export {TouchableOpacity} from './TouchableOpacity.mjs';
46
+ export {FlatList} from './FlatList.mjs';
47
+ export {ImageBackground} from './ImageBackground.mjs';
48
+ export {SectionList} from './SectionList.mjs';
49
+ export {
50
+ updateVector,
51
+ updateText,
52
+ scrollTo,
53
+ setKeyboardConfig,
54
+ } from './imperative.mjs';
55
+ export {StyleSheet} from './StyleSheet.mjs';
56
+ export {Platform} from './Platform.mjs';
57
+ export {Dimensions, useWindowDimensions} from './Dimensions.mjs';
58
+ export {AppRegistry} from './AppRegistry.mjs';
59
+ export {Alert} from './Alert.mjs';
60
+ export {Keyboard} from './Keyboard.mjs';
61
+ export {Animated, useAnimatedValue} from './Animated.mjs';
62
+ export {PanResponder} from './PanResponder.mjs';
63
+ export {usePersistentState} from './usePersistentState.mjs';
64
+ export {useHostValue} from './useHostValue.mjs';
65
+ export {nativeModule, useNativeEvent} from './nativeModule.mjs';
66
+ export {Easing} from './Easing.mjs';
67
+ export {LayoutAnimation} from './LayoutAnimation.mjs';
@@ -0,0 +1,85 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /** Duration when a config gives none, as in RN. */
17
+ export const DEFAULT_DURATION_MS = 300;
18
+ /** RN-compatible animation type tokens. */
19
+ export const Types = {
20
+ spring: 'spring',
21
+ linear: 'linear',
22
+ easeInEaseOut: 'easeInEaseOut',
23
+ easeIn: 'easeIn',
24
+ easeOut: 'easeOut',
25
+ keyboard: 'keyboard',
26
+ };
27
+ /** RN-compatible animated-property tokens (accepted for API parity; the engine tweens position). */
28
+ export const Properties = {
29
+ opacity: 'opacity',
30
+ scaleX: 'scaleX',
31
+ scaleY: 'scaleY',
32
+ scaleXY: 'scaleXY',
33
+ };
34
+ /** Maps an RN animation-type token to an engine easing token. */
35
+ function easingForType(type) {
36
+ switch (type) {
37
+ case Types.linear:
38
+ return 'linear';
39
+ case Types.easeIn:
40
+ return 'easeIn';
41
+ case Types.easeOut:
42
+ return 'easeOut';
43
+ case Types.easeInEaseOut:
44
+ case Types.keyboard:
45
+ default:
46
+ return 'easeInOut';
47
+ }
48
+ }
49
+ /**
50
+ * Reduces an RN LayoutAnimation config ({ duration, create, update, delete }) to the engine's flat
51
+ * config. The engine tweens the *position transition*, which is RN's `update`; create/delete opacity
52
+ * are accepted for parity but not separately animated.
53
+ */
54
+ export function toEngineConfig(config) {
55
+ const options = config || {};
56
+ const duration = typeof options.duration === 'number'
57
+ ? options.duration
58
+ : DEFAULT_DURATION_MS;
59
+ const update = options.update || {};
60
+ const type = update.type || options.type || Types.easeInEaseOut;
61
+ if (type === Types.spring) {
62
+ return { type: 'spring', duration };
63
+ }
64
+ return { type: 'timing', duration, easing: easingForType(type) };
65
+ }
66
+ /** Builds an RN-shaped config (duration + create/update/delete) from a type + creation property. */
67
+ export function create(duration, type = Types.easeInEaseOut, creationProp = Properties.opacity) {
68
+ return {
69
+ duration,
70
+ create: { type, property: creationProp },
71
+ update: { type },
72
+ delete: { type, property: creationProp },
73
+ };
74
+ }
75
+ /** RN-compatible preset configs. */
76
+ export const Presets = {
77
+ easeInEaseOut: create(300, Types.easeInEaseOut, Properties.opacity),
78
+ linear: create(500, Types.linear, Properties.opacity),
79
+ spring: {
80
+ duration: 700,
81
+ create: { type: Types.linear, property: Properties.opacity },
82
+ update: { type: Types.spring, springDamping: 0.4 },
83
+ delete: { type: Types.linear, property: Properties.opacity },
84
+ },
85
+ };
@@ -13,20 +13,14 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // Shared row handling for the list wrappers (<FlatList>, <SectionList>). Both turn a render callback's
18
17
  // result into a keyed child of one <ScrollView>, and the awkward cases are the same for both: a row
19
18
  // that renders to nothing, and a row that isn't an element at all.
20
- import {cloneElement} from 'react';
21
-
19
+ import { cloneElement } from 'react';
22
20
  /** True for a render result that puts nothing on screen — the `{cond && <Row/>}` of a row callback. */
23
- export const rendersNothing = node =>
24
- node === null || node === undefined || node === false;
25
-
21
+ export const rendersNothing = (node) => node === null || node === undefined || node === false;
26
22
  /** True for something cloneElement can key — a React element, as opposed to a string/number row. */
27
- export const isElement = node =>
28
- node !== null && typeof node === 'object' && node.$$typeof !== undefined;
29
-
23
+ export const isElement = (node) => node !== null && typeof node === 'object' && node.$$typeof !== undefined;
30
24
  /**
31
25
  * Appends one rendered row to `children`, keyed, or drops it if it rendered nothing.
32
26
  *
@@ -38,17 +32,14 @@ export const isElement = node =>
38
32
  * can actually carry one. `keyExtractor` is the app's code — running it for a row that rendered
39
33
  * nothing, or for a raw string that cannot be cloned, is both wasted work on the commit path and a
40
34
  * side effect the app never asked for. Passing the key by value invites exactly that, and did.
41
- *
42
- * @param {Array} children The child list being built.
43
- * @param {*} node Whatever the render callback returned.
44
- * @param {(element: object) => string} keyFor Builds the React key, given the keyable element.
45
35
  */
46
36
  export function pushKeyedChild(children, node, keyFor) {
47
- if (rendersNothing(node)) return;
48
- if (!isElement(node)) {
49
- children.push(node);
50
- return;
51
- }
52
- const key = keyFor(node);
53
- children.push(node.key === key ? node : cloneElement(node, {key}));
37
+ if (rendersNothing(node))
38
+ return;
39
+ if (!isElement(node)) {
40
+ children.push(node);
41
+ return;
42
+ }
43
+ const key = keyFor(node);
44
+ children.push(node.key === key ? node : cloneElement(node, { key }));
54
45
  }
@@ -13,14 +13,11 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // The named colors every path accepts, as ARGB8888 with their CSS values. Keys are lowercase; callers
18
17
  // lowercase the name first. The bridge's k_named_colors table (native_ui_bridge.c) must list the same entries.
19
18
  // No prototype, so `name in NAMED_COLORS` never finds `toString` and friends.
20
-
21
19
  /** @type {Readonly<Record<string, number>>} */
22
- export const NAMED_COLORS = Object.freeze(
23
- Object.assign(Object.create(null), {
20
+ export const NAMED_COLORS = Object.freeze(Object.assign(Object.create(null), {
24
21
  transparent: 0x00000000,
25
22
  black: 0xff000000,
26
23
  white: 0xffffffff,
@@ -33,5 +30,4 @@ export const NAMED_COLORS = Object.freeze(
33
30
  cyan: 0xff00ffff,
34
31
  magenta: 0xffff00ff,
35
32
  orange: 0xffffa500,
36
- }),
37
- );
33
+ }));