embedded-react 0.1.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/LICENSE +201 -0
- package/NOTICE +58 -0
- package/README.md +224 -0
- package/aot/compile.mjs +3066 -0
- package/aot/screenshot-smoke.mjs +110 -0
- package/aot/style-map.mjs +248 -0
- package/assets/bake-font.mjs +190 -0
- package/assets/bake-image.mjs +50 -0
- package/assets/build-builtin-font.mjs +51 -0
- package/assets/emit-c.mjs +187 -0
- package/assets/emit-container.mjs +121 -0
- package/assets/emit-pack.mjs +128 -0
- package/assets/index.mjs +72 -0
- package/assets/rasterize.mjs +169 -0
- package/build.mjs +136 -0
- package/pack-container.mjs +161 -0
- package/package.json +79 -0
- package/persist-transform.mjs +106 -0
- package/src/embedded-react/Animated.js +352 -0
- package/src/embedded-react/AppRegistry.js +49 -0
- package/src/embedded-react/Easing.js +39 -0
- package/src/embedded-react/LayoutAnimation.js +45 -0
- package/src/embedded-react/Platform.js +26 -0
- package/src/embedded-react/StyleSheet.js +36 -0
- package/src/embedded-react/components.js +44 -0
- package/src/embedded-react/imperative.js +68 -0
- package/src/embedded-react/index.js +52 -0
- package/src/embedded-react/layout-anim-config.js +91 -0
- package/src/embedded-react/split-style.js +58 -0
- package/src/embedded-react/svg-ops.js +564 -0
- package/src/embedded-react/usePersistentState.js +69 -0
- package/src/host-config.js +196 -0
- package/src/native-ui.js +24 -0
- package/src/props.js +183 -0
- package/src/renderer.js +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
embedded-react
|
|
2
|
+
Copyright 2026 Cory Lamming
|
|
3
|
+
|
|
4
|
+
This product was created and is authored by Cory Lamming.
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
7
|
+
use the files in this project except in compliance with the License. You may
|
|
8
|
+
obtain a copy of the License in the accompanying LICENSE file or at:
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
14
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
15
|
+
License for the specific language governing permissions and limitations
|
|
16
|
+
under the License.
|
|
17
|
+
|
|
18
|
+
------------------------------------------------------------------------------
|
|
19
|
+
Attribution
|
|
20
|
+
------------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
All original source code in this repository -- the C99 rendering engine, the
|
|
23
|
+
hardware backends, the QuickJS bridge and NativeUI host config, the JSX-to-C
|
|
24
|
+
ahead-of-time compiler, the toolchain, the simulator, and the demos -- is the
|
|
25
|
+
original work of Cory Lamming, unless explicitly attributed otherwise.
|
|
26
|
+
|
|
27
|
+
If you redistribute this work or derivative works, you must retain this NOTICE
|
|
28
|
+
file and the attribution above, as required by Section 4 of the Apache License,
|
|
29
|
+
Version 2.0.
|
|
30
|
+
|
|
31
|
+
------------------------------------------------------------------------------
|
|
32
|
+
Third-Party Components
|
|
33
|
+
------------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
This project builds against the following third-party software. These
|
|
36
|
+
components are NOT redistributed in this repository's source tree; they are
|
|
37
|
+
fetched as build-time dependencies (via CMake FetchContent and npm) and remain
|
|
38
|
+
under their own respective licenses and copyrights:
|
|
39
|
+
|
|
40
|
+
* QuickJS / quickjs-ng -- a small embeddable JavaScript engine.
|
|
41
|
+
Copyright (c) Fabrice Bellard, Charlie Gordon, and the quickjs-ng
|
|
42
|
+
contributors. Licensed under the MIT License.
|
|
43
|
+
Used by the Flow A runtime bridge (bridges/quickjs/).
|
|
44
|
+
|
|
45
|
+
* React and react-reconciler -- the React component and reconciliation model.
|
|
46
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
47
|
+
Licensed under the MIT License.
|
|
48
|
+
Used by the Flow A bridge to drive the native engine.
|
|
49
|
+
|
|
50
|
+
The embedded-react public API (e.g. the View / Text / Pressable / Animated /
|
|
51
|
+
StyleSheet modules under bridges/quickjs/js/src/embedded-react/) is an original,
|
|
52
|
+
independent reimplementation inspired by the React Native API surface. It is not
|
|
53
|
+
derived from or copied out of React Native's source, and is the original work of
|
|
54
|
+
Cory Lamming.
|
|
55
|
+
|
|
56
|
+
Trademarks referenced in this project (including "React" and "React Native") are
|
|
57
|
+
the property of their respective owners and are used here only for descriptive
|
|
58
|
+
and interoperability purposes.
|
package/README.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
# embedded-react — QuickJS JS layer (React reconciler)
|
|
2
|
+
|
|
3
|
+
The JavaScript half of Flow A: a [`react-reconciler`](https://www.npmjs.com/package/react-reconciler)
|
|
4
|
+
host config that maps React's host API onto the `NativeUI` bridge, so **JSX components drive the
|
|
5
|
+
C engine**. Bundled to a single classic script that QuickJS runs with a plain `JS_Eval`.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
React → react-reconciler → host-config.js → NativeUI.* → er_scene.h (engine)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What an app imports
|
|
12
|
+
|
|
13
|
+
The package is the React Native analog — same idiom (hooks from `react`, everything else here):
|
|
14
|
+
|
|
15
|
+
```jsx
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
import { View, Text, Pressable, StyleSheet, AppRegistry } from 'embedded-react';
|
|
18
|
+
|
|
19
|
+
function App() { /* ... */ }
|
|
20
|
+
AppRegistry.registerComponent('demo', () => App);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`embedded-react` resolves as a Node **package self-reference** (`package.json` `name` + `exports`),
|
|
24
|
+
so esbuild and Vitest find it with no aliases.
|
|
25
|
+
|
|
26
|
+
## Layout
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
src/
|
|
30
|
+
embedded-react/ the public package surface (what apps import)
|
|
31
|
+
index.js barrel: components, StyleSheet, Platform, AppRegistry, Animated, Easing
|
|
32
|
+
components.js host component tags (View, Text, … → ERNodeType)
|
|
33
|
+
StyleSheet.js create() / flatten()
|
|
34
|
+
Platform.js { OS: 'embedded', select }
|
|
35
|
+
AppRegistry.js registerComponent(...) → mounts into a screen-sized root
|
|
36
|
+
Animated.js Value / timing / spring / decay / View|Text|Image / interpolate
|
|
37
|
+
Easing.js easing tokens (+ bezier) → engine curves
|
|
38
|
+
split-style.js pure: split style into static props + animated bindings
|
|
39
|
+
__tests__/ co-located UNIT tests for the pure surface
|
|
40
|
+
host-config.js reconciler host config → NativeUI.* (internal runtime)
|
|
41
|
+
renderer.js createRoot(props).render(...); LegacyRoot (sync) (internal)
|
|
42
|
+
props.js pure prop helpers (flattenStyle / buildProps / isEventProp)
|
|
43
|
+
native-ui.js re-exports globalThis.NativeUI (installed by the C bridge)
|
|
44
|
+
__tests__/ co-located UNIT tests (Vitest, *.unit.test.js, no engine)
|
|
45
|
+
test/runtime/ e2e tests that need the real engine host
|
|
46
|
+
*.runtime.test.jsx run inside QuickJS + engine via the headless harness
|
|
47
|
+
harness.js check()/report() — records failures for the C runner
|
|
48
|
+
run.mjs bundles each runtime test + runs er-bridge-quickjs-runtest
|
|
49
|
+
assets/ build-time asset bakers (pure JS, no native deps) — see "Assets" below
|
|
50
|
+
rasterize.mjs glyph path → coverage bitmap (supersampled, nonzero winding)
|
|
51
|
+
bake-font.mjs TTF/OTF → engine BitmapFont glyph data (opentype.js)
|
|
52
|
+
bake-image.mjs PNG → premultiplied ARGB8888 (pngjs)
|
|
53
|
+
emit-c.mjs assemble assets.generated.c + the built-in font_data.c
|
|
54
|
+
build-builtin-font.mjs regenerate the engine's default Inter font (npm run build:builtin-font)
|
|
55
|
+
build.mjs esbuild a demo's index.jsx → dist/app.bundle.js + bake its imported assets
|
|
56
|
+
pack-container.mjs bundle + bytecode-compile + bake → dist/app.erpkg config container (npm run pack)
|
|
57
|
+
assets/emit-container.mjs ERCF container writer (sections + QuickJS version stamp + CRC32)
|
|
58
|
+
vitest.config.js unit test config
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The demo apps themselves live in the top-level **`demos/`** folder (one folder per demo), *not*
|
|
62
|
+
here — this package is the library + reconciler + tests. `build.mjs` bundles a selected demo and
|
|
63
|
+
resolves its `'embedded-react'` import to `src/embedded-react/index.js` via an esbuild alias. See
|
|
64
|
+
[`demos/README.md`](../../../demos/README.md).
|
|
65
|
+
|
|
66
|
+
The host config flattens RN `style` (+ nested arrays) into the flat prop bag, routes `on*`
|
|
67
|
+
handlers to `setEvent`, and uses `shouldSetTextContent` so a flattenable `<Text>` subtree (a string,
|
|
68
|
+
interpolation like `Hi {name}`, or nested `<Text>` runs) becomes the node's `text` + inline spans.
|
|
69
|
+
`Animated`, `Easing`, and the web timer globals (`setTimeout` / `setInterval`) are all available;
|
|
70
|
+
`useEffect` flushes via the host pump (BRIDGE.md §1.2, §1.4, §2).
|
|
71
|
+
|
|
72
|
+
## Build
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
npm install
|
|
76
|
+
npm run pack # default demo → dist/app.erpkg (deployable config: bytecode + assets + CRC)
|
|
77
|
+
npm run pack -- marine-dash # pack a specific demo (demos/<name>) instead
|
|
78
|
+
npm run build # lower-level: just bundle → dist/app.bundle.js (+ bake assets.generated.c)
|
|
79
|
+
npm run create -- my-app # scaffold a new app at demos/my-app (App.jsx + scripts); then `cd` + npm run sim
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`npm run pack` is the deployable artifact the desktop demo and the ESP32 both load — see **Config
|
|
83
|
+
container** below. `npm run build` is the lower-level bundle step (used by the bytecode/asset tooling
|
|
84
|
+
and by firmware that prefers to compile assets in); both bake the demo's imported images and fonts
|
|
85
|
+
(see **Assets**).
|
|
86
|
+
|
|
87
|
+
## Assets (images and fonts)
|
|
88
|
+
|
|
89
|
+
Asset handling is **import-driven** and fully build-time — there is no runtime decoder or font
|
|
90
|
+
rasterizer on the device, and no Python toolchain. An app just imports a file and uses the name it
|
|
91
|
+
returns:
|
|
92
|
+
|
|
93
|
+
```jsx
|
|
94
|
+
import logo from './assets/logo.png'; // → the baked image NAME ("logo")
|
|
95
|
+
import Inter from './assets/Inter.ttf'; // → the baked font FAMILY ("Inter")
|
|
96
|
+
|
|
97
|
+
<Image source={logo} style={{ width: 64, height: 64 }} />
|
|
98
|
+
<Text style={{ fontFamily: Inter, fontSize: 18 }}>Hi</Text>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The baker produces the assets two ways, from the same bytes: `npm run pack` packs them **into the
|
|
102
|
+
config container** (`app.erpkg`), registered at load time — this is what the desktop demo and ESP32
|
|
103
|
+
use. `npm run build` also emits `dist/assets.generated.c` exposing **`er_register_assets()`**, for
|
|
104
|
+
firmware that prefers to **compile assets into the image** and call it once at boot (`er_image_load` /
|
|
105
|
+
`er_font_register`, both flash-resident, zero runtime RAM). Either way the asset name/family is the
|
|
106
|
+
file's basename.
|
|
107
|
+
|
|
108
|
+
- **Images:** PNG → premultiplied ARGB8888 (`bake-image.mjs`, via `pngjs`).
|
|
109
|
+
- **Fonts:** TTF/OTF → pre-rasterized `BitmapFont` glyphs (`bake-font.mjs`, via `opentype.js` + a
|
|
110
|
+
pure-JS rasterizer). The engine has no runtime rasterizer, so the baker rasterizes **exactly the
|
|
111
|
+
literal `fontSize` values the bundle uses**. Computed/dynamic sizes snap to the nearest baked size
|
|
112
|
+
at runtime — pin them in `assets.config.js` if needed.
|
|
113
|
+
|
|
114
|
+
Optional per-demo overrides live in `demos/<demo>/assets.config.js`:
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
export default {
|
|
118
|
+
fonts: {
|
|
119
|
+
Inter: { sizes: [14, 18, 24], bpp: 4, glyphs: 'common' }, // bpp 1|2|4|8 (4 default); glyphs: 'ascii'|'common'|'minimal'|'greek'|[codepoints]
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The engine's **built-in default font** (`engine/font/font_data.c`, the Inter fallback used by any
|
|
125
|
+
text without a custom `fontFamily`) is generated by the same baker — regenerate it with
|
|
126
|
+
`npm run build:builtin-font` (then re-run the engine text tests, as glyph metrics shift slightly).
|
|
127
|
+
|
|
128
|
+
## Config container
|
|
129
|
+
|
|
130
|
+
`npm run pack` wraps the app into one deployable file — **`dist/app.erpkg`** (format `ERCF`):
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
magic "ERCF" | format_version | crc32 | qjs_tag | sections[ bytecode, asset pack ]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
It bundles the demo, precompiles it to **QuickJS bytecode** (no parser/source shipped), bakes the
|
|
137
|
+
imported assets into an ERPK pack, and wraps both with a **QuickJS version stamp** and an **integrity
|
|
138
|
+
CRC32**. That one `.erpkg` is "the config": loaded by `er_runtime_load_container()` on the desktop, or
|
|
139
|
+
flashed to a device's config partition. The loader verifies CRC + version (a config built for a
|
|
140
|
+
different QuickJS is rejected, not run as garbage) and registers the assets before the app mounts. This
|
|
141
|
+
is the firmware-vs-config split: the firmware (desktop exe / ESP32 image) ships once; the `.erpkg`
|
|
142
|
+
ships and updates independently.
|
|
143
|
+
|
|
144
|
+
> Two CRCs are different things: the container's internal CRC32 is embedded-react's own integrity
|
|
145
|
+
> check (universal). A bootloader's transfer/flash CRC is a separate,
|
|
146
|
+
> project-specific step layered on the `.erpkg` by your upload toolchain.
|
|
147
|
+
|
|
148
|
+
The precompiler tool must be built once (`pack` looks for it in the usual build dirs, or set
|
|
149
|
+
`ER_COMPILE_BIN`): `cmake -S bridges/quickjs -B bridges/quickjs/build && cmake --build
|
|
150
|
+
bridges/quickjs/build --target er-bridge-quickjs-compile`.
|
|
151
|
+
|
|
152
|
+
## Run (desktop)
|
|
153
|
+
|
|
154
|
+
After `npm run pack`, **rebuild the `embedded-react-desktop` target** — its build copies
|
|
155
|
+
`dist/app.erpkg` into the "config slot" next to the executable, and the host loads it **by default**
|
|
156
|
+
(no argument), exactly as the ESP32 loads its config from flash:
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
examples/linux/build/embedded-react-desktop # runs the config in the slot
|
|
160
|
+
examples/linux/build/embedded-react-desktop other.erpkg # or an explicit container / .qbc / .js path
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The firmware ships no app and no baked assets — everything rides in the container. No config / a
|
|
164
|
+
corrupt one shows an on-screen panel (no built-in fallback). The C host injects the globals the app
|
|
165
|
+
expects: `NativeUI` (the bridge), `screen` (`{ width, height, scale }`), and `console`.
|
|
166
|
+
|
|
167
|
+
> Iteration loop: edit `src/*` (library) or `demos/<name>/*` (app) → `npm run pack` → rebuild
|
|
168
|
+
> `embedded-react-desktop` (re-copies the container into the slot) → run. Or, for an instant
|
|
169
|
+
> edit-save-see loop, use the **simulator** (`npm run sim`).
|
|
170
|
+
|
|
171
|
+
## Tests
|
|
172
|
+
|
|
173
|
+
Two tiers, by what they need:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
npm test # unit: Vitest over src/**/__tests__/*.unit.test.js (pure JS, no engine)
|
|
177
|
+
npm run test:runtime # e2e: bundles test/runtime/*.runtime.test.jsx, runs each in the headless
|
|
178
|
+
# QuickJS+engine harness (no window) and checks the result
|
|
179
|
+
npm run test:bytecode # same suite, but each bundle is precompiled to a .qbc bytecode blob and run
|
|
180
|
+
# via the bytecode path (JS_ReadObject) — proves the MCU load path
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The runtime tiers need the harness exe built once (no SDL); `test:bytecode` also needs the compiler:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
cmake --build bridges/quickjs/build --target er-bridge-quickjs-runtest er-bridge-quickjs-compile
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Pick the tier by what the code touches: pure marshalling/logic → a co-located `*.unit.test.js`;
|
|
190
|
+
anything that exercises the reconciler → engine pipeline → a `test/runtime/*.runtime.test.jsx`.
|
|
191
|
+
|
|
192
|
+
## Status & known gaps
|
|
193
|
+
|
|
194
|
+
- ✅ **Render, state, keyed-list reorder, and Animated all work end-to-end.** `<App/>` mounts, taps
|
|
195
|
+
re-render via `setState`, keyed reorder moves nodes (`insertBefore`/`appendChild`), and
|
|
196
|
+
`Animated.View` runs **native-driver** animations in the engine (no per-frame JS). Covered by
|
|
197
|
+
`test/runtime/reorder.runtime.test.jsx` and `animated.runtime.test.jsx`.
|
|
198
|
+
- ✅ **Timers, Promises, and `useEffect` work.** `setTimeout`/`setInterval`/`clearTimeout`/
|
|
199
|
+
`clearInterval` and the Promise job queue are serviced each frame by the host pump
|
|
200
|
+
(`er_bridge_pump`, off the engine clock). React passive effects (`useEffect`) flush on the pump.
|
|
201
|
+
Covered by `timers.runtime.test.js` and `effects.runtime.test.jsx`.
|
|
202
|
+
- ✅ **Animated composition + completion.** `sequence`/`parallel`/`stagger`/`delay`/`loop` and
|
|
203
|
+
`.start(({ finished }) => …)` all work — composition is pure JS over each child's start/stop, with
|
|
204
|
+
completion wired through the engine's `on_complete`. Covered by `anim-compose.runtime.test.js`.
|
|
205
|
+
- ✅ **Multi-child `<Text>` + nested spans.** Interpolation (`Hi {name}`) and nested styled
|
|
206
|
+
`<Text>` runs both work — a flattenable `<Text>` owns its subtree and renders as the node's text
|
|
207
|
+
plus, when runs differ in style, an inline span array (`NativeUI.setTextSpans`, max 4). Covered by
|
|
208
|
+
`text-spans` unit + runtime tests.
|
|
209
|
+
- ✅ **LayoutAnimation.** `LayoutAnimation.configureNext(...)` before a layout-changing state update
|
|
210
|
+
tweens every node whose computed rect moved on the next commit (in C — no per-frame JS). `Presets`
|
|
211
|
+
/ `create` / `Types` / `Properties` and the `easeInEaseOut`/`linear`/`spring` shorthands. Covered
|
|
212
|
+
by `layout-animation` unit + `layout-anim.runtime.test.jsx`.
|
|
213
|
+
- ✅ **Interpolate `extrapolate`.** `interpolate({ inputRange, outputRange, extrapolate })` supports
|
|
214
|
+
`'extend'` (default) / `'clamp'` / `'identity'`, with per-end `extrapolateLeft`/`extrapolateRight`
|
|
215
|
+
overrides. Math is engine-tested (`test_interpolate`); the bridge path by
|
|
216
|
+
`interpolate-extrapolate.runtime.test.js`.
|
|
217
|
+
- ✅ **Bytecode + assets + `useAnimatedValue`.** The build compiles the bundle to a `.qbc` bytecode
|
|
218
|
+
blob (the MCU load path) and bakes imported images/fonts to flash-resident C; `useAnimatedValue` is
|
|
219
|
+
exported. Runs end-to-end on the desktop host and on ESP32-S3 hardware.
|
|
220
|
+
- ✅ **State survives hot reload** — in the simulator, plain `useState` transparently persists across
|
|
221
|
+
saves (a sim-only build transform rewrites it to a persisting helper; press R to reset). On a device
|
|
222
|
+
it's just `useState`, so the same app code runs everywhere. `usePersistentState` is the underlying
|
|
223
|
+
helper, also exported for explicit use. See `/SIMULATOR.md`.
|
|
224
|
+
- ⏳ **`create-embedded-react` scaffold** — the project-init CLI is still to come (§4).
|