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
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // pack-app — build a Flow A config container (.erpkg) for an app entry, in memory.
18
17
  //
19
18
  // The shared core behind both `embedded-react build` (writes dist/app.erpkg) and the on-device
@@ -21,172 +20,132 @@
21
20
  // import-driven asset discovery as the dev/build paths), precompiles to QuickJS bytecode through the
22
21
  // prebuilt sim wasm, bakes images/fonts into an ERPK pack, and serializes the ERCF container — all
23
22
  // without touching disk, so the dev loop can rebuild on every save and hand the Buffer to the uploader.
24
-
25
- import {createRequire} from 'node:module';
26
- import {pathToFileURL} from 'node:url';
27
- import {basename, resolve} from 'node:path';
28
- import {existsSync, mkdirSync, readFileSync} from 'node:fs';
29
- import {tmpdir} from 'node:os';
30
-
23
+ import { createRequire } from 'node:module';
24
+ import { pathToFileURL } from 'node:url';
25
+ import { basename, resolve } from 'node:path';
26
+ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
27
+ import { tmpdir } from 'node:os';
31
28
  const require = createRequire(import.meta.url);
32
-
33
- // QuickJS release the bytecode container targets — MUST match cli.mjs's QJS_TAG and the device loader.
29
+ // QuickJS release the bytecode container targets — MUST match cli.mts's QJS_TAG and the device loader.
34
30
  const QJS_TAG = 'v0.15.0';
35
-
36
31
  /**
37
32
  * Bundle + compile + bake an app into an ERCF container Buffer.
38
- *
39
- * @param {object} options
40
- * @param {string} options.entry App entry (index.jsx/tsx).
41
- * @param {string} options.projectRoot Project cwd (for assets.config.js + persist scoping).
42
- * @param {string} options.libSrc Path to the embedded-react library entry (aliased as 'embedded-react').
43
- * @param {string[]} options.nodePaths esbuild nodePaths (package + project node_modules).
44
- * @param {string} options.simDir Dir holding the prebuilt sim wasm (used to compile bytecode).
45
- * @param {boolean} [options.persist] Apply the useState→persist transform (dev hot reload preserves state).
46
- * @returns {Promise<{container: Buffer, bytecodeLen: number, assetsLen: number}>}
47
33
  */
48
- export async function packAppContainer({
49
- entry,
50
- projectRoot,
51
- libSrc,
52
- nodePaths,
53
- simDir,
54
- persist = false,
55
- strip = false,
56
- }) {
57
- const esbuild = require('esbuild');
58
- const {bakeImage} = await import('../assets/bake-image.mjs');
59
- const {bakeFont} = await import('../assets/bake-font.mjs');
60
- const {resolveFontJobs} = await import('../assets/font-config.mjs');
61
- const {analyzeFontSizes, warnFontSizes} =
62
- await import('../assets/font-sizes.mjs');
63
- const {warnMissingGlyphs} = await import('../assets/glyph-coverage.mjs');
64
- const {emitAssetPack} = await import('../assets/emit-pack.mjs');
65
- const {emitContainer} = await import('../assets/emit-container.mjs');
66
- const {registerSvgVectorLoader} = await import('../assets/svg-loader.mjs');
67
- const {compileToBytecode} = await import('../qjsc-wasm.mjs');
68
-
69
- const assetName = filePath => basename(filePath).replace(/\.[^.]+$/, '');
70
- const images = new Map();
71
- const fonts = new Map();
72
-
73
- // Optionally apply the persist transform to the app's own source (not deps) so plain useState survives
74
- // a live reload on-device, matching the simulator. The device must have install_persist=true.
75
- let persistHooks = null;
76
- if (persist) {
77
- const {transformPersist, shouldPersist} =
78
- await import('../persist-transform.mjs');
79
- const {relative} = await import('node:path');
80
- const normalizedProjectRoot = projectRoot.replace(/\\/g, '/');
81
- persistHooks = {
82
- transformPersist,
83
- shouldPersist,
84
- relative,
85
- normalizedProjectRoot,
86
- };
87
- }
88
-
89
- const assetPlugin = {
90
- name: 'embedded-react-assets',
91
- setup(build) {
92
- if (persistHooks) {
93
- build.onLoad({filter: /\.(jsx?|tsx?)$/}, args => {
94
- const {
34
+ export async function packAppContainer({ entry, projectRoot, libSrc, nodePaths, simDir, persist = false, strip = false, }) {
35
+ const esbuild = require('esbuild');
36
+ const { bakeImage } = await import('../assets/bake-image.mjs');
37
+ const { bakeFont } = await import('../assets/bake-font.mjs');
38
+ const { resolveFontJobs } = await import('../assets/font-config.mjs');
39
+ const { analyzeFontSizes, warnFontSizes } = await import('../assets/font-sizes.mjs');
40
+ const { warnMissingGlyphs } = await import('../assets/glyph-coverage.mjs');
41
+ const { emitAssetPack } = await import('../assets/emit-pack.mjs');
42
+ const { emitContainer } = await import('../assets/emit-container.mjs');
43
+ const { registerSvgVectorLoader } = await import('../assets/svg-loader.mjs');
44
+ const { compileToBytecode } = await import('../qjsc-wasm.mjs');
45
+ const assetName = (filePath) => basename(filePath).replace(/\.[^.]+$/, '');
46
+ const images = new Map();
47
+ const fonts = new Map();
48
+ // Optionally apply the persist transform to the app's own source (not deps) so plain useState survives
49
+ // a live reload on-device, matching the simulator. The device must have install_persist=true.
50
+ let persistHooks = null;
51
+ if (persist) {
52
+ const { transformPersist, shouldPersist } = await import('../persist-transform.mjs');
53
+ const { relative } = await import('node:path');
54
+ const normalizedProjectRoot = projectRoot.replace(/\\/g, '/');
55
+ persistHooks = {
95
56
  transformPersist,
96
57
  shouldPersist,
97
58
  relative,
98
59
  normalizedProjectRoot,
99
- } = persistHooks;
100
- if (!shouldPersist(args.path, normalizedProjectRoot))
101
- return undefined;
102
- try {
103
- const loader = args.path.endsWith('.tsx')
104
- ? 'tsx'
105
- : args.path.endsWith('.ts')
106
- ? 'ts'
107
- : 'jsx';
108
- return {
109
- contents: transformPersist(
110
- readFileSync(args.path, 'utf8'),
111
- relative(projectRoot, args.path).replace(/\\/g, '/'),
112
- ),
113
- loader,
114
- };
115
- } catch (error) {
116
- return {errors: [{text: `persist transform: ${error.message}`}]};
117
- }
118
- });
119
- }
120
- build.onLoad({filter: /\.(png|jpe?g|webp|gif|bmp)$/i}, args => {
121
- const name = assetName(args.path);
122
- images.set(name, args.path);
123
- return {
124
- contents: `module.exports = ${JSON.stringify(name)};`,
125
- loader: 'js',
126
- };
127
- });
128
- build.onLoad({filter: /\.(ttf|otf)$/i}, args => {
129
- const family = assetName(args.path);
130
- fonts.set(family, args.path);
131
- return {
132
- contents: `module.exports = ${JSON.stringify(family)};`,
133
- loader: 'js',
134
60
  };
135
- });
136
- registerSvgVectorLoader(build, (name, pngPath) =>
137
- images.set(name, pngPath),
138
- );
139
- },
140
- };
141
-
142
- const buildDirectory = resolve(tmpdir(), 'embedded-react-build');
143
- mkdirSync(buildDirectory, {recursive: true});
144
- const bundlePath = resolve(buildDirectory, 'app.bundle.js');
145
- await esbuild.build({
146
- entryPoints: [entry],
147
- bundle: true,
148
- format: 'iife',
149
- outfile: bundlePath,
150
- platform: 'neutral',
151
- target: 'es2020',
152
- jsx: 'automatic',
153
- alias: {'embedded-react': libSrc},
154
- nodePaths,
155
- plugins: [assetPlugin],
156
- define: {'process.env.NODE_ENV': '"production"'},
157
- legalComments: 'none',
158
- logLevel: 'silent',
159
- });
160
- const bundleSource = readFileSync(bundlePath, 'utf8');
161
-
162
- const bytecode = await compileToBytecode(bundleSource, simDir, {strip});
163
-
164
- const usedSizes = analyzeFontSizes(bundleSource);
165
- let config = {};
166
- const configPath = resolve(projectRoot, 'assets.config.js');
167
- if (existsSync(configPath))
168
- config = (await import(pathToFileURL(configPath).href)).default || {};
169
- const fontConfig = config.fonts || {};
170
- const imageConfig = config.images || {};
171
- const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
172
- const imageJobs = [...images.entries()].map(([name, path]) => ({
173
- path,
174
- name,
175
- format: imageConfig[name]?.format,
176
- }));
177
- const bakedImages = imageJobs.map(bakeImage);
178
- const bakedFonts = fontJobs.map(bakeFont);
179
- warnMissingGlyphs({source: bundleSource, fonts: bakedFonts});
180
- warnFontSizes({used: usedSizes, fonts: bakedFonts});
181
- const assetPack =
182
- bakedImages.length || bakedFonts.length
183
- ? emitAssetPack({images: bakedImages, fonts: bakedFonts})
184
- : null;
185
-
186
- const container = emitContainer({bytecode, assetPack, qjsTag: QJS_TAG});
187
- return {
188
- container,
189
- bytecodeLen: bytecode.length,
190
- assetsLen: assetPack ? assetPack.length : 0,
191
- };
61
+ }
62
+ const assetPlugin = {
63
+ name: 'embedded-react-assets',
64
+ setup(build) {
65
+ if (persistHooks) {
66
+ build.onLoad({ filter: /\.(jsx?|tsx?)$/ }, args => {
67
+ const { transformPersist, shouldPersist, relative, normalizedProjectRoot, } = persistHooks;
68
+ if (!shouldPersist(args.path, normalizedProjectRoot))
69
+ return undefined;
70
+ try {
71
+ const loader = args.path.endsWith('.tsx')
72
+ ? 'tsx'
73
+ : args.path.endsWith('.ts')
74
+ ? 'ts'
75
+ : 'jsx';
76
+ return {
77
+ contents: transformPersist(readFileSync(args.path, 'utf8'), relative(projectRoot, args.path).replace(/\\/g, '/')),
78
+ loader,
79
+ };
80
+ }
81
+ catch (error) {
82
+ return { errors: [{ text: `persist transform: ${error.message}` }] };
83
+ }
84
+ });
85
+ }
86
+ build.onLoad({ filter: /\.(png|jpe?g|webp|gif|bmp)$/i }, args => {
87
+ const name = assetName(args.path);
88
+ images.set(name, args.path);
89
+ return {
90
+ contents: `module.exports = ${JSON.stringify(name)};`,
91
+ loader: 'js',
92
+ };
93
+ });
94
+ build.onLoad({ filter: /\.(ttf|otf)$/i }, args => {
95
+ const family = assetName(args.path);
96
+ fonts.set(family, args.path);
97
+ return {
98
+ contents: `module.exports = ${JSON.stringify(family)};`,
99
+ loader: 'js',
100
+ };
101
+ });
102
+ registerSvgVectorLoader(build, (name, pngPath) => images.set(name, pngPath));
103
+ },
104
+ };
105
+ const buildDirectory = resolve(tmpdir(), 'embedded-react-build');
106
+ mkdirSync(buildDirectory, { recursive: true });
107
+ const bundlePath = resolve(buildDirectory, 'app.bundle.js');
108
+ await esbuild.build({
109
+ entryPoints: [entry],
110
+ bundle: true,
111
+ format: 'iife',
112
+ outfile: bundlePath,
113
+ platform: 'neutral',
114
+ target: 'es2020',
115
+ jsx: 'automatic',
116
+ alias: { 'embedded-react': libSrc },
117
+ nodePaths,
118
+ plugins: [assetPlugin],
119
+ define: { 'process.env.NODE_ENV': '"production"' },
120
+ legalComments: 'none',
121
+ logLevel: 'silent',
122
+ });
123
+ const bundleSource = readFileSync(bundlePath, 'utf8');
124
+ const bytecode = await compileToBytecode(bundleSource, simDir, { strip });
125
+ const usedSizes = analyzeFontSizes(bundleSource);
126
+ let config = {};
127
+ const configPath = resolve(projectRoot, 'assets.config.js');
128
+ if (existsSync(configPath))
129
+ config = (await import(pathToFileURL(configPath).href)).default || {};
130
+ const fontConfig = config.fonts || {};
131
+ const imageConfig = config.images || {};
132
+ const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
133
+ const imageJobs = [...images.entries()].map(([name, path]) => ({
134
+ path,
135
+ name,
136
+ format: imageConfig[name]?.format,
137
+ }));
138
+ const bakedImages = imageJobs.map(bakeImage);
139
+ const bakedFonts = fontJobs.map(bakeFont);
140
+ warnMissingGlyphs({ source: bundleSource, fonts: bakedFonts });
141
+ warnFontSizes({ used: usedSizes, fonts: bakedFonts });
142
+ const assetPack = bakedImages.length || bakedFonts.length
143
+ ? emitAssetPack({ images: bakedImages, fonts: bakedFonts })
144
+ : null;
145
+ const container = emitContainer({ bytecode, assetPack, qjsTag: QJS_TAG });
146
+ return {
147
+ container,
148
+ bytecodeLen: bytecode.length,
149
+ assetsLen: assetPack ? assetPack.length : 0,
150
+ };
192
151
  }