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.
- package/NOTICE +5 -0
- package/README.md +3 -2
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +17 -47
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +62 -10
- package/aot/compiler/collect.mjs +517 -137
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +47 -8
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1378 -97
- package/aot/compiler/handlers.mjs +1807 -354
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +203 -53
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +45 -31
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +18 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +906 -33
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +16 -3
- package/aot/compiler/package/lower.mjs +707 -176
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +20 -5
- package/aot/compiler/svg.mjs +13 -7
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +321 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/style-map.mjs +94 -3
- 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 +85 -94
- package/cli.mjs +490 -586
- 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 +146 -213
- 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 +94 -116
- 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.mjs +32 -0
- 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 +238 -5
- package/src/embedded-react/index.js +26 -17
- 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 -148
- package/src/embedded-react/layout-anim-config.js +0 -101
- 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/build.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
|
// Bundles a demo (React app + reconciler + host config) into a single classic (IIFE) script that
|
|
18
17
|
// QuickJS can run with a plain JS_Eval, and bakes the images/fonts the demo imports into a generated
|
|
19
18
|
// C translation unit (dist/assets.generated.c) exposing er_register_assets(). Globals the bundle
|
|
@@ -26,38 +25,36 @@
|
|
|
26
25
|
// npm run build -- marine-dash # a specific demo by folder name
|
|
27
26
|
// Outputs are always dist/app.bundle.js + dist/assets.generated.{c,h} — the single "active" app the
|
|
28
27
|
// example hosts pick up.
|
|
29
|
-
import {build} from 'esbuild';
|
|
30
|
-
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
31
|
-
import {dirname, resolve, basename} from 'node:path';
|
|
32
|
-
import {existsSync, readdirSync, readFileSync} from 'node:fs';
|
|
33
|
-
import {bakeAssets} from './assets/index.mjs';
|
|
34
|
-
import {resolveFontJobs} from './assets/font-config.mjs';
|
|
35
|
-
import {analyzeFontSizes} from './assets/font-sizes.mjs';
|
|
36
|
-
import {registerSvgVectorLoader} from './assets/svg-loader.mjs';
|
|
37
|
-
|
|
28
|
+
import { build } from 'esbuild';
|
|
29
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
30
|
+
import { dirname, resolve, basename } from 'node:path';
|
|
31
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
32
|
+
import { bakeAssets } from './assets/index.mjs';
|
|
33
|
+
import { resolveFontJobs } from './assets/font-config.mjs';
|
|
34
|
+
import { analyzeFontSizes } from './assets/font-sizes.mjs';
|
|
35
|
+
import { registerSvgVectorLoader } from './assets/svg-loader.mjs';
|
|
36
|
+
import { loadAppFile, loadDependencyFile } from './aot/app-file-loader.mjs';
|
|
37
|
+
import { demoFile } from './aot/demo-file.mjs';
|
|
38
38
|
const here = dirname(fileURLToPath(import.meta.url)); // packages/embedded-react
|
|
39
39
|
const repoRoot = resolve(here, '../..');
|
|
40
40
|
const demosDir = resolve(repoRoot, 'demos');
|
|
41
41
|
const libEntry = resolve(here, 'src/embedded-react/index.js');
|
|
42
42
|
const nodeModules = resolve(here, 'node_modules');
|
|
43
43
|
const distDir = resolve(here, 'dist');
|
|
44
|
-
|
|
45
44
|
const DEFAULT_DEMO = 'thermostat';
|
|
46
45
|
const demo = process.argv[2] || process.env.DEMO || DEFAULT_DEMO;
|
|
47
46
|
const demoDir = resolve(demosDir, demo);
|
|
48
|
-
const entry =
|
|
49
|
-
|
|
47
|
+
const entry = demoFile(demoDir, 'index');
|
|
50
48
|
if (!existsSync(entry)) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
const available = existsSync(demosDir)
|
|
50
|
+
? readdirSync(demosDir, { withFileTypes: true })
|
|
51
|
+
.filter(entry => entry.isDirectory())
|
|
52
|
+
.map(entry => entry.name)
|
|
53
|
+
: [];
|
|
54
|
+
console.error(`Demo "${demo}" not found (expected ${entry}).`);
|
|
55
|
+
console.error(`Available demos: ${available.join(', ') || '(none)'}`);
|
|
56
|
+
process.exit(1);
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
// Asset discovery is import-driven: an `import x from './x.png'` (image) or `import F from './F.ttf'`
|
|
62
59
|
// (font) is intercepted here. The import resolves to the asset's NAME (its file basename) — the
|
|
63
60
|
// string an <Image source>/imageName looks up, or the family a fontFamily uses — and the path is
|
|
@@ -65,101 +62,95 @@ if (!existsSync(entry)) {
|
|
|
65
62
|
const images = new Map(); // name -> path
|
|
66
63
|
const fonts = new Map(); // family -> path
|
|
67
64
|
const assetPlugin = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
name: 'embedded-react-assets',
|
|
66
|
+
setup(pluginBuild) {
|
|
67
|
+
// The demo's own files give its native modules their signatures, and so do a package's.
|
|
68
|
+
pluginBuild.onLoad({ filter: /\.(jsx?|tsx?)$/ }, args => args.path.startsWith(demoDir)
|
|
69
|
+
? loadAppFile(args.path)
|
|
70
|
+
: loadDependencyFile(args.path));
|
|
71
|
+
pluginBuild.onLoad({ filter: /\.(png|jpe?g|webp|gif|bmp)$/i }, args => {
|
|
72
|
+
const name = basename(args.path).replace(/\.[^.]+$/, '');
|
|
73
|
+
images.set(name, args.path);
|
|
74
|
+
return {
|
|
75
|
+
contents: `module.exports = ${JSON.stringify(name)};`,
|
|
76
|
+
loader: 'js',
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
pluginBuild.onLoad({ filter: /\.(ttf|otf)$/i }, args => {
|
|
80
|
+
const family = basename(args.path).replace(/\.[^.]+$/, '');
|
|
81
|
+
fonts.set(family, args.path);
|
|
82
|
+
return {
|
|
83
|
+
contents: `module.exports = ${JSON.stringify(family)};`,
|
|
84
|
+
loader: 'js',
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
registerSvgVectorLoader(pluginBuild, (name, svgPath) => images.set(name, svgPath));
|
|
88
|
+
},
|
|
90
89
|
};
|
|
91
|
-
|
|
92
90
|
const bundlePath = resolve(distDir, 'app.bundle.js');
|
|
93
91
|
await build({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
92
|
+
entryPoints: [entry],
|
|
93
|
+
bundle: true,
|
|
94
|
+
format: 'iife',
|
|
95
|
+
outfile: bundlePath,
|
|
96
|
+
platform: 'neutral',
|
|
97
|
+
target: 'es2020',
|
|
98
|
+
jsx: 'automatic',
|
|
99
|
+
// Demos live outside the embedded-react package, so the package self-reference doesn't resolve for
|
|
100
|
+
// them: map the bare `embedded-react` import to the library source and let the demo's bare deps
|
|
101
|
+
// (react, react-reconciler) resolve from this package's node_modules. (The library's own internal
|
|
102
|
+
// imports still resolve relatively / from node_modules as before.)
|
|
103
|
+
// Pin React to THIS package's copy: a demo/consumer project may carry its own node_modules
|
|
104
|
+
// (e.g., after `npm install` for device-dev deps), and esbuild resolving `react` from there while
|
|
105
|
+
// the library resolves its copy from here yields two React instances — the hook dispatcher is
|
|
106
|
+
// null and every component throws. One copy, always.
|
|
107
|
+
alias: {
|
|
108
|
+
'embedded-react': libEntry,
|
|
109
|
+
react: resolve(nodeModules, 'react'),
|
|
110
|
+
'react-reconciler': resolve(nodeModules, 'react-reconciler'),
|
|
111
|
+
scheduler: resolve(nodeModules, 'scheduler'),
|
|
112
|
+
},
|
|
113
|
+
nodePaths: [nodeModules],
|
|
114
|
+
plugins: [assetPlugin],
|
|
115
|
+
// Production React: smaller and avoids dev-only warning machinery that needs more shims.
|
|
116
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
117
|
+
legalComments: 'none',
|
|
118
|
+
logLevel: 'info',
|
|
121
119
|
});
|
|
122
|
-
|
|
123
120
|
console.log(`Bundled demo "${demo}" -> dist/app.bundle.js`);
|
|
124
|
-
|
|
125
121
|
// --- Bake imported assets ---------------------------------------------------------------------
|
|
126
122
|
// Fonts are pre-rasterized at fixed sizes (the engine has no runtime rasterizer), so bake exactly the
|
|
127
123
|
// fontSize values the bundle uses — constants and token scales folded, not just literals. A size that
|
|
128
124
|
// only exists at runtime can't be discovered; the bake reports those rather than snapping silently.
|
|
129
125
|
const bundleSource = readFileSync(bundlePath, 'utf8');
|
|
130
126
|
const usedSizes = analyzeFontSizes(bundleSource);
|
|
131
|
-
|
|
132
127
|
// Optional per-demo overrides: demos/<demo>/assets.config.js
|
|
133
128
|
// export default { fonts: { 'Family': { sizes: [..], bpp: 4, glyphs: 'ascii'|'common'|[cps],
|
|
134
129
|
// extraGlyphs: '°±' } } }
|
|
135
130
|
let config = {};
|
|
136
131
|
const configPath = resolve(demoDir, 'assets.config.js');
|
|
137
132
|
if (existsSync(configPath)) {
|
|
138
|
-
|
|
133
|
+
config = (await import(pathToFileURL(configPath).href)).default || {};
|
|
139
134
|
}
|
|
140
135
|
const fontConfig = config.fonts || {};
|
|
141
136
|
const imageConfig = config.images || {};
|
|
142
|
-
|
|
143
137
|
const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
|
|
144
138
|
const imageJobs = [...images.entries()].map(([name, path]) => ({
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
139
|
+
path,
|
|
140
|
+
name,
|
|
141
|
+
format: imageConfig[name]?.format,
|
|
148
142
|
}));
|
|
149
|
-
|
|
150
143
|
const summary = bakeAssets({
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
144
|
+
images: imageJobs,
|
|
145
|
+
fonts: fontJobs,
|
|
146
|
+
outDir: distDir,
|
|
147
|
+
source: bundleSource,
|
|
148
|
+
usedSizes,
|
|
156
149
|
});
|
|
157
150
|
const fontDescription = fontJobs.length
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
console.log(
|
|
163
|
-
|
|
164
|
-
` fonts: ${fontDescription}`,
|
|
165
|
-
);
|
|
151
|
+
? fontJobs
|
|
152
|
+
.map(font => `${font.family}@[${font.sizes.join(',')}]x${font.bpp}bpp`)
|
|
153
|
+
.join(', ')
|
|
154
|
+
: 'none';
|
|
155
|
+
console.log(`Baked ${summary.images} image(s), ${summary.fonts} font size(s) -> dist/assets.generated.c\n` +
|
|
156
|
+
` fonts: ${fontDescription}`);
|