embedded-react 0.19.0 → 0.21.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 +8 -3
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +180 -90
- package/aot/compiler/animations.mjs +568 -317
- package/aot/compiler/boot.mjs +97 -35
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +70 -18
- package/aot/compiler/collect.mjs +787 -288
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +439 -268
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +52 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +61 -26
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +1685 -392
- package/aot/compiler/handlers.mjs +2029 -547
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +43 -4
- package/aot/compiler/ir/reads.mjs +223 -22
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +26 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard.mjs +17 -7
- 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 +246 -111
- 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 +195 -172
- package/aot/compiler/options.mjs +37 -31
- package/aot/compiler/out.mjs +32 -23
- package/aot/compiler/package/animations.mjs +779 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +175 -0
- package/aot/compiler/package/bytecode.mjs +315 -0
- package/aot/compiler/package/checks.mjs +1026 -0
- package/aot/compiler/package/codegen.mjs +2168 -0
- package/aot/compiler/package/enums.mjs +148 -0
- package/aot/compiler/package/format.mjs +771 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +2103 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +127 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +686 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +23 -21
- 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/static-eval.mjs +340 -30
- package/aot/compiler/style-text.mjs +178 -174
- package/aot/compiler/svg.mjs +480 -251
- 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 +320 -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/screenshot-smoke.mjs +54 -40
- package/aot/style-map.mjs +152 -92
- package/assets/bake-font.mjs +123 -77
- package/assets/bake-image.mjs +39 -22
- package/assets/bake-svg.mjs +361 -262
- package/assets/build-builtin-font.mjs +11 -7
- package/assets/emit-c.mjs +77 -58
- package/assets/emit-container.mjs +123 -37
- package/assets/emit-pack.mjs +77 -67
- package/assets/font-config.mjs +9 -6
- package/assets/font-sizes.mjs +163 -123
- package/assets/glyph-coverage.mjs +74 -54
- package/assets/index.mjs +31 -9
- package/assets/rasterize.mjs +126 -99
- package/assets/svg-loader.mjs +8 -8
- package/build.mjs +23 -13
- package/cli.mjs +402 -172
- package/compile-bin.mjs +3 -3
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +62 -64
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +50 -37
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +37 -21
- package/package.json +7 -8
- package/persist-transform.mjs +34 -28
- package/qjsc-wasm.mjs +25 -14
- package/sim/embedded-react.cjs +1 -1
- package/sim/embedded-react.js +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +94 -85
- package/sim-server.mjs +113 -94
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Dimensions.js +37 -0
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +3 -3
- package/src/embedded-react/LayoutAnimation.js +8 -5
- package/src/embedded-react/PanResponder.js +75 -71
- package/src/embedded-react/Pressable.js +2 -8
- package/src/embedded-react/SectionList.js +7 -9
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +88 -8
- package/src/embedded-react/index.js +2 -0
- package/src/embedded-react/layout-anim-config.js +10 -4
- package/src/embedded-react/list-child.js +5 -5
- package/src/embedded-react/named-colors.js +1 -1
- package/src/embedded-react/nativeModule.js +462 -0
- package/src/embedded-react/split-style.js +11 -11
- package/src/embedded-react/svg-ops.js +760 -593
- package/src/embedded-react/useHostValue.js +3 -3
- package/src/embedded-react/usePersistentState.js +6 -6
- package/src/embedded-react/warn-props.js +1 -1
- package/src/host-config.js +60 -53
- package/src/props.js +49 -41
- package/src/renderer.js +7 -4
- package/aot/compiler/assemble.mjs +0 -944
- package/aot/compiler/c/animations.mjs +0 -436
- package/aot/compiler/c/boot.mjs +0 -127
- package/aot/compiler/c/expressions.mjs +0 -270
- package/aot/compiler/c/functions.mjs +0 -268
- package/aot/compiler/c/keyboard.mjs +0 -96
- package/aot/compiler/c/nodes.mjs +0 -303
- package/aot/compiler/c/pan-responder.mjs +0 -136
- package/aot/compiler/c/statements.mjs +0 -319
- package/aot/compiler/c/text.mjs +0 -83
- package/aot/compiler/c/vectors.mjs +0 -381
- package/aot/compiler/c-syntax.mjs +0 -127
package/aot/compiler/options.mjs
CHANGED
|
@@ -17,20 +17,26 @@
|
|
|
17
17
|
- Constants
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
/**
|
|
20
|
-
* The largest value each size or cap takes; the smallest is 1. Screen dimensions end up in int16_t props, a
|
|
21
|
-
*
|
|
22
|
-
* engine's uint8_t `span_count`.
|
|
20
|
+
* The largest value each size or cap takes; the smallest is 1. Screen dimensions end up in int16_t props, and a
|
|
21
|
+
* nested <Text>'s segment count in the engine's uint8_t `span_count`.
|
|
23
22
|
*/
|
|
24
23
|
const MAX_SCREEN = 32767;
|
|
25
|
-
const
|
|
26
|
-
const
|
|
24
|
+
export const MAX_LIST_CAPACITY = 32767;
|
|
25
|
+
const MAX_LIST_STRING_CAPACITY = 32767;
|
|
27
26
|
const MAX_TEXT_SPANS = 255;
|
|
27
|
+
const MAX_TIMERS = 4096;
|
|
28
|
+
// What each size or cap is when neither the options nor a variable set it.
|
|
29
|
+
const DEFAULT_SCREEN_WIDTH = 800;
|
|
30
|
+
const DEFAULT_SCREEN_HEIGHT = 480;
|
|
31
|
+
const DEFAULT_LIST_CAPACITY = 16;
|
|
32
|
+
const DEFAULT_LIST_STRING_CAPACITY = 48;
|
|
33
|
+
const DEFAULT_TEXT_SPANS = 4;
|
|
34
|
+
const DEFAULT_TIMERS = 8;
|
|
28
35
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
29
36
|
- Implementation
|
|
30
37
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
31
38
|
/**
|
|
32
|
-
* Checks that a size or cap is a whole number from 1 to `max`, since it
|
|
33
|
-
* `#define` or an array size.
|
|
39
|
+
* Checks that a size or cap is a whole number from 1 to `max`, since it sizes what the package holds.
|
|
34
40
|
*
|
|
35
41
|
* @param value The value, as the option or the parsed variable gave it.
|
|
36
42
|
* @param name The option or variable, as the error names it.
|
|
@@ -49,26 +55,30 @@ function wholeInRange(value, name, max, shown = String(value)) {
|
|
|
49
55
|
return value;
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
52
|
-
*
|
|
58
|
+
* compilePackage's options with the screen and the fixed-buffer caps filled in. Each one the caller
|
|
53
59
|
* leaves out falls back to its environment variable, then to a default. The environment is read on every
|
|
54
60
|
* call, not at import, so one process can compile for several boards.
|
|
55
61
|
*
|
|
56
|
-
* screen ER_AOT_SCREEN_W / _H 800×480
|
|
57
|
-
*
|
|
62
|
+
* screen ER_AOT_SCREEN_W / _H 800×480 A panel to keep a layout for. A package finds its layouts
|
|
63
|
+
* unless told a size, with both variables or the option.
|
|
58
64
|
* listCap ER_AOT_LIST_CAP 16 Rows a list state holds. Each pooled row costs engine
|
|
59
65
|
* nodes, so lower it on a tight-RAM MCU.
|
|
60
|
-
* listStrCap ER_AOT_LIST_STR_CAP 48
|
|
66
|
+
* listStrCap ER_AOT_LIST_STR_CAP 48 Bytes for a string built from itself (`log + '.'`), with
|
|
67
|
+
* its terminator. Every other string is sized from its values.
|
|
61
68
|
* maxTextSpans ER_AOT_MAX_TEXT_SPANS 4 Inline segments in a nested <Text>. Must match the
|
|
62
69
|
* engine's ER_TEXT_MAX_SPANS.
|
|
70
|
+
* maxTimers ER_AOT_MAX_TIMERS 8 Timers that run at once. Sizes the package's timer
|
|
71
|
+
* table.
|
|
63
72
|
*
|
|
64
73
|
* Each value must be a whole number from 1 up: to 32767 for the screen and the list caps, to 255 for
|
|
65
|
-
* maxTextSpans. One that isn't, from the options or a variable, is an `AOT:` error
|
|
74
|
+
* maxTextSpans, to 4096 for maxTimers. One that isn't, from the options or a variable, is an `AOT:` error
|
|
75
|
+
* that names it.
|
|
66
76
|
*
|
|
67
|
-
* @param
|
|
77
|
+
* @param options The options the caller passed.
|
|
68
78
|
*
|
|
69
79
|
* @returns The same options with every value filled in.
|
|
70
80
|
*/
|
|
71
|
-
export function resolveOptions(
|
|
81
|
+
export function resolveOptions(options) {
|
|
72
82
|
// An unset or blank variable falls back to the default; any other value must parse to one in range.
|
|
73
83
|
const isSet = (name) => (process.env[name] ?? '').trim() !== '';
|
|
74
84
|
const fromEnv = (name, fallback, max) => {
|
|
@@ -77,30 +87,26 @@ export function resolveOptions(opts) {
|
|
|
77
87
|
const raw = process.env[name];
|
|
78
88
|
return wholeInRange(Number(raw), name, max, JSON.stringify(raw));
|
|
79
89
|
};
|
|
80
|
-
const fromOption = (value, name,
|
|
90
|
+
const fromOption = (value, name, environmentName, fallback, max) => value != null
|
|
81
91
|
? wholeInRange(value, name, max)
|
|
82
|
-
: fromEnv(
|
|
92
|
+
: fromEnv(environmentName, fallback, max);
|
|
83
93
|
return {
|
|
84
|
-
...
|
|
85
|
-
screen:
|
|
94
|
+
...options,
|
|
95
|
+
screen: options.screen
|
|
86
96
|
? {
|
|
87
|
-
width: wholeInRange(
|
|
88
|
-
height: wholeInRange(
|
|
97
|
+
width: wholeInRange(options.screen.width, 'screen.width', MAX_SCREEN),
|
|
98
|
+
height: wholeInRange(options.screen.height, 'screen.height', MAX_SCREEN),
|
|
89
99
|
}
|
|
90
100
|
: {
|
|
91
|
-
width: fromEnv('ER_AOT_SCREEN_W',
|
|
92
|
-
height: fromEnv('ER_AOT_SCREEN_H',
|
|
101
|
+
width: fromEnv('ER_AOT_SCREEN_W', DEFAULT_SCREEN_WIDTH, MAX_SCREEN),
|
|
102
|
+
height: fromEnv('ER_AOT_SCREEN_H', DEFAULT_SCREEN_HEIGHT, MAX_SCREEN),
|
|
93
103
|
},
|
|
94
|
-
|
|
95
|
-
screenFrom: opts.screen
|
|
96
|
-
? 'option'
|
|
97
|
-
: isSet('ER_AOT_SCREEN_W') && isSet('ER_AOT_SCREEN_H')
|
|
98
|
-
? 'env'
|
|
99
|
-
: 'default',
|
|
104
|
+
screenFrom: 'option',
|
|
100
105
|
caps: {
|
|
101
|
-
listCap: fromOption(
|
|
102
|
-
listStrCap: fromOption(
|
|
103
|
-
maxTextSpans: fromOption(
|
|
106
|
+
listCap: fromOption(options.listCap, 'listCap', 'ER_AOT_LIST_CAP', DEFAULT_LIST_CAPACITY, MAX_LIST_CAPACITY),
|
|
107
|
+
listStrCap: fromOption(options.listStrCap, 'listStrCap', 'ER_AOT_LIST_STR_CAP', DEFAULT_LIST_STRING_CAPACITY, MAX_LIST_STRING_CAPACITY),
|
|
108
|
+
maxTextSpans: fromOption(options.maxTextSpans, 'maxTextSpans', 'ER_AOT_MAX_TEXT_SPANS', DEFAULT_TEXT_SPANS, MAX_TEXT_SPANS),
|
|
109
|
+
maxTimers: fromOption(options.maxTimers, 'maxTimers', 'ER_AOT_MAX_TIMERS', DEFAULT_TIMERS, MAX_TIMERS),
|
|
104
110
|
},
|
|
105
111
|
};
|
|
106
112
|
}
|
package/aot/compiler/out.mjs
CHANGED
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
/**
|
|
20
20
|
* Everything the passes lower for one app besides its element tree: the functions, drawings, responders and
|
|
21
|
-
* effects, and the counters that name them. Each pass appends to it as the JSX tree is walked
|
|
22
|
-
* writes it out as app.gen.c.
|
|
21
|
+
* effects, and the counters that name them. Each pass appends to it as the JSX tree is walked.
|
|
23
22
|
*
|
|
24
23
|
* @class Out
|
|
25
24
|
*/
|
|
@@ -28,43 +27,53 @@ export class Out {
|
|
|
28
27
|
nodes = 0;
|
|
29
28
|
/** Event handlers, one function each. */
|
|
30
29
|
handlers = [];
|
|
31
|
-
/** A useCallback's
|
|
32
|
-
|
|
30
|
+
/** A useCallback's handler, by component prefix and name, so each is emitted once. */
|
|
31
|
+
emittedCallbacks = new Map();
|
|
33
32
|
/** File-scope vector op-tapes and paint tables, and the builders of state-driven drawings. */
|
|
34
33
|
vectors = [];
|
|
35
|
-
/** Numbers the next <Svg> (its tapes
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
/** Numbers the next <Svg> (which names its tapes). */
|
|
35
|
+
svgCount = 0;
|
|
36
|
+
timerFunctions = [];
|
|
37
|
+
/** A release build, which leaves the console calls out. */
|
|
38
|
+
release = false;
|
|
39
|
+
/** The states a handler, effect or timer keeps a copy of, to read after setting them. */
|
|
40
|
+
keptStates = new Set();
|
|
41
|
+
/** useNativeEvent handlers, in the order they lower. */
|
|
42
|
+
nativeEventHandlers = [];
|
|
43
|
+
/** The optional native modules, by index, each with every method and event the package lists. */
|
|
44
|
+
optionalModules = [];
|
|
45
|
+
/** What the build runs last: mount-once effects, and the first run of each dep-driven one. */
|
|
42
46
|
mountEffects = [];
|
|
43
47
|
/** Animations' on_complete callbacks: completions, completion waits, and chains. */
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
|
|
48
|
+
animationCallbacks = [];
|
|
49
|
+
/**
|
|
50
|
+
* The owner number of each composition that completion waits belong to, by composition; `isStarted` once a
|
|
51
|
+
* start keeps a run under it, and `hasWaits` once one runs waits of their own.
|
|
52
|
+
*/
|
|
53
|
+
animationWaits = new Map();
|
|
54
|
+
/** Running-animation entries the groups of several animations take: each group's own, and all it runs. */
|
|
55
|
+
animationGroupEntries = 0;
|
|
47
56
|
/** Numbers the next animation sequence. */
|
|
48
|
-
|
|
57
|
+
sequenceCount = 0;
|
|
49
58
|
/** Image assets the app reaches: asset name → source-relative import path. */
|
|
50
59
|
images = new Map();
|
|
51
60
|
/** A dynamic image source was reached, so every imported image has to be baked. */
|
|
52
61
|
bakeAllImages = false;
|
|
53
62
|
/** Numbers the next inlined component instance (its storage prefix is `c<n>_`). */
|
|
54
|
-
|
|
63
|
+
instanceCount = 0;
|
|
55
64
|
/** State, refs, and animated values that belong to inlined component instances. */
|
|
56
65
|
childStateRecords = [];
|
|
57
66
|
childRefs = [];
|
|
58
67
|
childAnimations = [];
|
|
59
68
|
/** Numbers the next effect. */
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
effectCount = 0;
|
|
70
|
+
effectFunctions = [];
|
|
62
71
|
/** File-scope variables the effects and animation loops need. */
|
|
63
|
-
|
|
64
|
-
/** Dep-driven effects, which
|
|
65
|
-
|
|
72
|
+
effectDeclarations = [];
|
|
73
|
+
/** Dep-driven effects, which the update re-runs when one of their deps changed. */
|
|
74
|
+
dependencyEffects = [];
|
|
66
75
|
/** Numbers the next PanResponder. */
|
|
67
|
-
|
|
76
|
+
panCount = 0;
|
|
68
77
|
/** Every PanResponder a node spreads, lowered once each. */
|
|
69
78
|
panResponders = [];
|
|
70
79
|
/** The module's function components, by name, for inlining. */
|
|
@@ -86,7 +95,7 @@ export class Out {
|
|
|
86
95
|
/**
|
|
87
96
|
* Reserves the next engine node.
|
|
88
97
|
*
|
|
89
|
-
* @returns Its number: the node is
|
|
98
|
+
* @returns Its number: the node is known as `n<number>`.
|
|
90
99
|
*/
|
|
91
100
|
allocateNodeId() {
|
|
92
101
|
return this.nodes++;
|