embedded-react 0.21.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 (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. 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
  }