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.
- package/README.md +2 -2
- package/aot/compile.mjs +1 -1
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/check.mjs +1 -1
- package/aot/compiler/collect.mjs +1 -1
- package/aot/compiler/elements/button.mjs +3 -3
- package/aot/compiler/elements/image-background.mjs +1 -1
- package/aot/compiler/elements/props.mjs +10 -6
- package/aot/compiler/elements/section-list.mjs +1 -1
- package/aot/compiler/expressions.mjs +29 -2
- package/aot/compiler/handlers.mjs +73 -16
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/lower.mjs +12 -0
- package/aot/compiler/nodes.mjs +17 -9
- package/aot/compiler/out.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +36 -2
- package/aot/compiler/package/format.mjs +5 -3
- package/aot/compiler/package/lower.mjs +53 -19
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/style-text.mjs +2 -2
- package/aot/compiler/svg.mjs +6 -3
- package/aot/compiler/updaters.mjs +1 -0
- package/aot/style-map.mjs +44 -1
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +84 -101
- package/cli.mjs +482 -621
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +144 -200
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +93 -123
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +155 -2
- package/src/embedded-react/index.js +26 -19
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -146
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/nativeModule.js +0 -462
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
package/hotreload/pack-app.mjs
CHANGED
|
@@ -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 {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
}
|