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
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
- Versions and container
|
|
24
24
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
25
|
export const FORMAT_MAJOR = 1;
|
|
26
|
-
export const FORMAT_MINOR =
|
|
26
|
+
export const FORMAT_MINOR = 16;
|
|
27
27
|
/** The engine ABI level the package is built against (er_scene.h's ER_ABI). */
|
|
28
|
-
export const ENGINE_ABI =
|
|
28
|
+
export const ENGINE_ABI = 2;
|
|
29
29
|
export const PACKAGE_TAG = 'erb';
|
|
30
30
|
export const SECTION_PROGRAM = 4;
|
|
31
31
|
export const SECTION_DEBUG = 5;
|
|
@@ -459,8 +459,9 @@ export const OPCODES = [
|
|
|
459
459
|
['AVAIL', 'abx', 1],
|
|
460
460
|
['CALLNS', 'abx', 2],
|
|
461
461
|
['FMTLOG', 'abc', 1],
|
|
462
|
+
['SCROLLAT', 'abc', 1],
|
|
462
463
|
];
|
|
463
|
-
/** The props with ids 1 to
|
|
464
|
+
/** The props with ids 1 to 151, in id order, as erb_props.c lists them, with each enum's largest value. */
|
|
464
465
|
const PROPS_IN_ORDER = [
|
|
465
466
|
['left', 'i16'],
|
|
466
467
|
['top', 'i16'],
|
|
@@ -612,6 +613,7 @@ const PROPS_IN_ORDER = [
|
|
|
612
613
|
['gradient_stops[1].position', 'float'],
|
|
613
614
|
['gradient_stops[2].position', 'float'],
|
|
614
615
|
['gradient_stops[3].position', 'float'],
|
|
616
|
+
['gradient_corner', 'enum', 4],
|
|
615
617
|
];
|
|
616
618
|
/** Span props start at this id, SPAN_STRIDE ids per span. */
|
|
617
619
|
export const SPAN_PROP_FIRST = 160;
|
|
@@ -171,26 +171,26 @@ function stringNativeCalls(value, found, seen = new Set()) {
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
|
-
* Every updateVector call a statement list makes.
|
|
174
|
+
* Every updateVector and scrollTo call a statement list makes.
|
|
175
175
|
*
|
|
176
176
|
* @param statements The statements.
|
|
177
177
|
* @param found Collects the calls.
|
|
178
178
|
*/
|
|
179
|
-
function
|
|
179
|
+
function nodeCalls(statements, found) {
|
|
180
180
|
for (const statement of statements) {
|
|
181
|
-
if (statement.kind === 'updateVector') {
|
|
181
|
+
if (statement.kind === 'updateVector' || statement.kind === 'scrollTo') {
|
|
182
182
|
found.push(statement);
|
|
183
183
|
}
|
|
184
184
|
else if (statement.kind === 'if') {
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
nodeCalls(statement.consequent, found);
|
|
186
|
+
nodeCalls(statement.alternate ?? [], found);
|
|
187
187
|
}
|
|
188
188
|
else if (statement.kind === 'block') {
|
|
189
|
-
|
|
189
|
+
nodeCalls(statement.body, found);
|
|
190
190
|
}
|
|
191
191
|
else if (statement.kind === 'loop') {
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
nodeCalls(statement.body, found);
|
|
193
|
+
nodeCalls(statement.step, found);
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
}
|
|
@@ -614,21 +614,36 @@ function planSlots(app, tables, caps) {
|
|
|
614
614
|
// A <TextInput>'s onChangeText reads the input's text, through its handle.
|
|
615
615
|
const handles = new Map();
|
|
616
616
|
const readsInput = (node) => node.wiring.some(wire => wire.kind === 'event' && wire.event === 'ER_EVENT_CHANGE_TEXT');
|
|
617
|
-
// An updateVector call draws on the node its ref holds: the last one built with
|
|
617
|
+
// An updateVector call draws on the node its ref holds, and a scrollTo call scrolls it: the last one built with
|
|
618
|
+
// the ref.
|
|
618
619
|
const calls = [];
|
|
619
620
|
for (const body of bodies(app)) {
|
|
620
|
-
|
|
621
|
+
nodeCalls(body, calls);
|
|
621
622
|
}
|
|
622
|
-
const
|
|
623
|
+
const callOf = new Map(calls.map(call => [call.node, call]));
|
|
623
624
|
const refNodes = new Map();
|
|
624
625
|
for (const node of nodes) {
|
|
625
626
|
for (const wire of node.wiring) {
|
|
626
|
-
if (wire.kind === 'ref' &&
|
|
627
|
+
if (wire.kind === 'ref' && callOf.has(wire.slot)) {
|
|
627
628
|
refNodes.set(wire.slot, node);
|
|
628
629
|
}
|
|
629
630
|
}
|
|
630
631
|
}
|
|
631
|
-
const drawnOn = new
|
|
632
|
+
const drawnOn = new Map([...refNodes].map(([ref, node]) => [
|
|
633
|
+
node,
|
|
634
|
+
callOf.get(ref).kind === 'scrollTo' ? 'scrollTo' : 'updateVector',
|
|
635
|
+
]));
|
|
636
|
+
for (const call of calls) {
|
|
637
|
+
if (call.kind !== 'scrollTo')
|
|
638
|
+
continue;
|
|
639
|
+
const node = refNodes.get(call.node);
|
|
640
|
+
if (node?.type !== 'ER_NODE_SCROLL_VIEW' &&
|
|
641
|
+
node?.type !== 'ER_NODE_FLAT_LIST') {
|
|
642
|
+
const error = aotError('AOT: scrollTo() takes a ref that is on a <ScrollView>', 'put ref={…} on the <ScrollView> to scroll, and pass its `.current`.');
|
|
643
|
+
locateError(error, node?.location ?? call.location);
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
632
647
|
const reached = (node) => isStateDriven(node) ||
|
|
633
648
|
isSetOnce(node) ||
|
|
634
649
|
readsInput(node) ||
|
|
@@ -657,7 +672,7 @@ function planSlots(app, tables, caps) {
|
|
|
657
672
|
notYetAt('onChangeText in a list row', node.location);
|
|
658
673
|
}
|
|
659
674
|
if (drawnOn.has(node)) {
|
|
660
|
-
notYetAt(
|
|
675
|
+
notYetAt(`${drawnOn.get(node)} on a node in a list row`, node.location);
|
|
661
676
|
}
|
|
662
677
|
// Every row's first node, when the first row's is an anchor, so the rows can still share a template.
|
|
663
678
|
if (reached(node) || (anchoring && place === 0)) {
|
|
@@ -674,7 +689,9 @@ function planSlots(app, tables, caps) {
|
|
|
674
689
|
}
|
|
675
690
|
for (const node of nodes) {
|
|
676
691
|
if (drawnOn.has(node) && places.has(node)) {
|
|
677
|
-
const error = aotError(
|
|
692
|
+
const error = aotError(drawnOn.get(node) === 'scrollTo'
|
|
693
|
+
? 'AOT: scrollTo scrolls a node a conditional builds and destroys'
|
|
694
|
+
: 'AOT: updateVector draws on a node a conditional builds and destroys', 'keep the node built and show it with visible={…} instead.');
|
|
678
695
|
locateError(error, node.location);
|
|
679
696
|
throw error;
|
|
680
697
|
}
|
|
@@ -781,8 +798,8 @@ function constantProps(node, lowering) {
|
|
|
781
798
|
}
|
|
782
799
|
/**
|
|
783
800
|
* The handler function an event on a node runs, made the first time. A handler bound to two events is one
|
|
784
|
-
* function per event, since a function's kind is the event it is entered with,
|
|
785
|
-
* input, since it reads its own. Each row has its own handler; rows whose handlers have the same
|
|
801
|
+
* function per event, since a function's kind is the event it is entered with, an onChangeText one per
|
|
802
|
+
* input, since it reads its own, and an onScroll one per ScrollView. Each row has its own handler; rows whose handlers have the same
|
|
786
803
|
* code share one function, so they can share a template.
|
|
787
804
|
*
|
|
788
805
|
* @param name The handler.
|
|
@@ -809,6 +826,8 @@ function handlerFunction(name, eventName, node, lowering, inRow) {
|
|
|
809
826
|
throw new Error(`AOT internal: no handler for "${name}"`);
|
|
810
827
|
}
|
|
811
828
|
const readsInput = eventName === 'ER_EVENT_CHANGE_TEXT';
|
|
829
|
+
// One per ScrollView, in a row too, so the runtime can tell whose scroll is waiting.
|
|
830
|
+
const scrolls = eventName === 'ER_EVENT_SCROLL';
|
|
812
831
|
const made = {
|
|
813
832
|
callback: then?.callback ?? { body: [], updatesState: false },
|
|
814
833
|
fade: handler.kind === 'pressFade' ? handler.fade : null,
|
|
@@ -821,8 +840,8 @@ function handlerFunction(name, eventName, node, lowering, inRow) {
|
|
|
821
840
|
};
|
|
822
841
|
// Compared by code alone, so where each handler is in the source doesn't keep two apart.
|
|
823
842
|
const key = inRow
|
|
824
|
-
? `row ${JSON.stringify({ ...handlerBody({ ...made, index: NONE }, lowering), debug: undefined })}`
|
|
825
|
-
: `${name} ${eventName}${readsInput ? ` ${node.id}` : ''}`;
|
|
843
|
+
? `row ${scrolls ? `${node.id} ` : ''}${JSON.stringify({ ...handlerBody({ ...made, index: NONE }, lowering), debug: undefined })}`
|
|
844
|
+
: `${name} ${eventName}${readsInput || scrolls ? ` ${node.id}` : ''}`;
|
|
826
845
|
const existing = lowering.handlers.get(key);
|
|
827
846
|
if (existing) {
|
|
828
847
|
return existing.index;
|
|
@@ -2040,6 +2059,21 @@ export function lowerPackage(app, options) {
|
|
|
2040
2059
|
const ends = Math.max(0, ...functions.map(programFunction => countOps(programFunction, ['ASTART', 'AVSET', 'ASTOP'])));
|
|
2041
2060
|
lowering.slots.arena.eventQueue(animations.entries + 2 * ends);
|
|
2042
2061
|
}
|
|
2062
|
+
// A scrollTo in a function fires onScroll, which waits in the queue until the function ends. The runtime keeps
|
|
2063
|
+
// one waiting event per ScrollView, and each scrollTo scrolls one, so a loop needs no more room.
|
|
2064
|
+
if (functions.some(programFunction => programFunction.kind === ENGINE_VALUES.get('ER_EVENT_SCROLL'))) {
|
|
2065
|
+
let scrolls = 0;
|
|
2066
|
+
for (const programFunction of functions) {
|
|
2067
|
+
scrolls += countOps(programFunction, ['SCROLL']);
|
|
2068
|
+
}
|
|
2069
|
+
lowering.slots.arena.eventQueue(scrolls);
|
|
2070
|
+
}
|
|
2071
|
+
// A Keyboard.dismiss() in a function fires onBlur, which waits in the queue until the function ends. One input
|
|
2072
|
+
// has the focus, so one blur waits at a time.
|
|
2073
|
+
if (functions.some(programFunction => programFunction.kind === ENGINE_VALUES.get('ER_EVENT_BLUR')) &&
|
|
2074
|
+
functions.some(programFunction => countOps(programFunction, ['BLUR']))) {
|
|
2075
|
+
lowering.slots.arena.eventQueue(1);
|
|
2076
|
+
}
|
|
2043
2077
|
const { regions, bytes } = lowering.slots.arena.regions(stackCells(functions));
|
|
2044
2078
|
// Host values, by name, for erb_input_find().
|
|
2045
2079
|
const inputs = app.state
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Cory Lamming
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file compiler/scroll-to.mts
|
|
18
|
+
* @brief Lowers `scrollTo(ref.current, {x, y})`: a scroll of the ScrollView the ref is on, and its position after.
|
|
19
|
+
*/
|
|
20
|
+
import { aotError } from './diagnostics.mjs';
|
|
21
|
+
import { lowerExpr } from './expressions.mjs';
|
|
22
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
23
|
+
- Constants
|
|
24
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
25
|
+
/** The fields of the position scrollTo returns, in the order the runtime gives them. */
|
|
26
|
+
export const SCROLL_POSITION_FIELDS = ['x', 'y', 'maxX', 'maxY'];
|
|
27
|
+
const HINT = 'call it as scrollTo(list.current, {y: 120}), where list is a useRef() on a <ScrollView>; leave an axis out ' +
|
|
28
|
+
'to keep it, or the offset out to only read the position.';
|
|
29
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
30
|
+
- Implementation
|
|
31
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
32
|
+
/**
|
|
33
|
+
* Whether an expression is a `scrollTo(…)` call.
|
|
34
|
+
*
|
|
35
|
+
* @param node The expression.
|
|
36
|
+
*
|
|
37
|
+
* @returns True when it is.
|
|
38
|
+
*/
|
|
39
|
+
export function isScrollToCall(node) {
|
|
40
|
+
return (node?.type === 'CallExpression' &&
|
|
41
|
+
node.callee.type === 'Identifier' &&
|
|
42
|
+
node.callee.name === 'scrollTo');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* One axis of the offset, or null when the offset leaves it out.
|
|
46
|
+
*
|
|
47
|
+
* @param offset The offset's object literal.
|
|
48
|
+
* @param axis The axis.
|
|
49
|
+
* @param environment The expression environment.
|
|
50
|
+
*
|
|
51
|
+
* @returns The axis's value.
|
|
52
|
+
*/
|
|
53
|
+
function axisOf(offset, axis, environment) {
|
|
54
|
+
// The last of a key written twice is the one JS keeps.
|
|
55
|
+
const property = offset.properties.findLast(candidate => candidate.type === 'ObjectProperty' &&
|
|
56
|
+
candidate.key.type === 'Identifier' &&
|
|
57
|
+
candidate.key.name === axis);
|
|
58
|
+
return property
|
|
59
|
+
? lowerExpr(property.value, environment)
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Lowers a `scrollTo(ref.current, {x, y}?)` call.
|
|
64
|
+
*
|
|
65
|
+
* @param call The call.
|
|
66
|
+
* @param environment The expression environment.
|
|
67
|
+
* @param results The locals its position is kept in, when the code reads it.
|
|
68
|
+
*
|
|
69
|
+
* @returns The statement.
|
|
70
|
+
*/
|
|
71
|
+
export function lowerScrollTo(call, environment, results) {
|
|
72
|
+
const [handle, offset, ...rest] = call.arguments;
|
|
73
|
+
const ref = handle?.type === 'MemberExpression' &&
|
|
74
|
+
!handle.computed &&
|
|
75
|
+
handle.object.type === 'Identifier' &&
|
|
76
|
+
handle.property.type === 'Identifier' &&
|
|
77
|
+
handle.property.name === 'current'
|
|
78
|
+
? environment.refs?.get(handle.object.name)
|
|
79
|
+
: null;
|
|
80
|
+
if (ref?.kind !== 'node') {
|
|
81
|
+
throw aotError('AOT: scrollTo() takes the `.current` of a node ref first', HINT);
|
|
82
|
+
}
|
|
83
|
+
ref.used = true;
|
|
84
|
+
const isOffset = offset?.type === 'ObjectExpression' &&
|
|
85
|
+
offset.properties.every(property => property.type === 'ObjectProperty' &&
|
|
86
|
+
!property.computed &&
|
|
87
|
+
property.key.type === 'Identifier' &&
|
|
88
|
+
(property.key.name === 'x' || property.key.name === 'y'));
|
|
89
|
+
if (rest.length || (offset && !isOffset)) {
|
|
90
|
+
throw aotError('AOT: scrollTo() takes its offset as an object literal of x and y', HINT);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
kind: 'scrollTo',
|
|
94
|
+
node: ref.slotName,
|
|
95
|
+
x: offset ? axisOf(offset, 'x', environment) : null,
|
|
96
|
+
y: offset ? axisOf(offset, 'y', environment) : null,
|
|
97
|
+
results,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Refuses the position scrollTo returns where it can't be kept: anywhere but a const, or a field read in one.
|
|
102
|
+
*
|
|
103
|
+
* @param node The expression.
|
|
104
|
+
*
|
|
105
|
+
* @returns The error, or null when the expression is no scrollTo call.
|
|
106
|
+
*/
|
|
107
|
+
export function unkeptScrollError(node) {
|
|
108
|
+
return isScrollToCall(node)
|
|
109
|
+
? aotError('AOT: scrollTo() returns a position, which only a const keeps', 'keep it first, then read its fields: const position = scrollTo(list.current); or ' +
|
|
110
|
+
'const {y, maxY} = scrollTo(list.current);')
|
|
111
|
+
: null;
|
|
112
|
+
}
|
|
@@ -20,7 +20,7 @@ import { attemptLowering, check } from './check.mjs';
|
|
|
20
20
|
import { shapeOf } from './typing.mjs';
|
|
21
21
|
import { BootReadError, bootEnvOf, bootSlotOf, foldBoot, isBoot, } from './boot.mjs';
|
|
22
22
|
import { lowerStyle, isStyleKey, STYLE_KEYS, DYN_FIELDS, parseColorValue, } from '../style-map.mjs';
|
|
23
|
-
import { parseColor } from '../../src/embedded-react/svg-ops.
|
|
23
|
+
import { parseColor } from '../../src/embedded-react/svg-ops.mjs';
|
|
24
24
|
import { aotError, checkEngineString } from './diagnostics.mjs';
|
|
25
25
|
import { at, checkAnimatedStyleKey, checkAttributes, checkStyleKey, inlineFragments, TEXT_SPAN, } from './elements/props.mjs';
|
|
26
26
|
import { evalStatic, foldScope, withUndefined } from './static-eval.mjs';
|
|
@@ -226,7 +226,7 @@ function lowerDynamicStyleValue(key, valueNode, environment) {
|
|
|
226
226
|
}
|
|
227
227
|
if (!dynamicField) {
|
|
228
228
|
throw aotError(`AOT: a state-driven value for style "${key}" is not supported (static only)`, `state-driven styles supported: colors, opacity, sizes/margins/padding, and the ` +
|
|
229
|
-
`layout enums (flexDirection, alignItems, alignSelf, justifyContent, position, ` +
|
|
229
|
+
`layout enums (flexDirection, flexWrap, alignItems, alignSelf, justifyContent, position, ` +
|
|
230
230
|
`display). Make "${key}" static, or drive the change another way.`);
|
|
231
231
|
}
|
|
232
232
|
// Colors and enums lower to a constant or a choice of constants.
|
package/aot/compiler/svg.mjs
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { settledOf } from './typing.mjs';
|
|
20
20
|
import { check, checkNumber } from './check.mjs';
|
|
21
21
|
import { lowerStyle, NODE_TYPES } from '../style-map.mjs';
|
|
22
|
-
import { flattenSvg, parseColor, parsePath, KAPPA, PAINT_PROPS, PAINT_STRIDE, scaleVectorArtifact, VOP_ARC, VOP_CUBIC, VOP_LINE, VOP_MOVE, VOP_QUAD, VOP_SHAPE, } from '../../src/embedded-react/svg-ops.
|
|
22
|
+
import { flattenSvg, parseColor, parsePath, KAPPA, PAINT_PROPS, PAINT_STRIDE, scaleVectorArtifact, VOP_ARC, VOP_CUBIC, VOP_LINE, VOP_MOVE, VOP_QUAD, VOP_SHAPE, } from '../../src/embedded-react/svg-ops.mjs';
|
|
23
23
|
import { aotError, currentLoc } from './diagnostics.mjs';
|
|
24
24
|
import { bootSlotOf, bootSourceText, buildValueOf, containsBoot, foldBoot, isBoot, } from './boot.mjs';
|
|
25
25
|
import { evalStatic, withUndefined } from './static-eval.mjs';
|
|
@@ -368,7 +368,7 @@ function svgAttrs(openingElement, scope, environment) {
|
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
370
|
* Lowers a `{ type, ax, ay, bx, by, r, stops: [{ color, offset }] }` gradient descriptor — the SAME shape
|
|
371
|
-
* Flow A's svg-ops.
|
|
371
|
+
* Flow A's svg-ops.mts takes. Every geometry field and every stop may be static or state-driven; `type` and the
|
|
372
372
|
* stop COUNT must be static, since they decide the emitted table's shape.
|
|
373
373
|
*
|
|
374
374
|
* Conic gradients carry the sweep's start angle in `r` (radians, clockwise from the top), so a dial whose
|
|
@@ -538,7 +538,10 @@ function lowerShapePaint(attributes, environment, scope) {
|
|
|
538
538
|
kind: 'state',
|
|
539
539
|
value: lowerColorValue(attributeValue.node, environment),
|
|
540
540
|
}
|
|
541
|
-
: {
|
|
541
|
+
: {
|
|
542
|
+
kind: 'static',
|
|
543
|
+
argb: parseColor((attributeValue ?? fallback)) >>> 0,
|
|
544
|
+
};
|
|
542
545
|
const strokeWidth = isDynamicAttr(attributes.strokeWidth)
|
|
543
546
|
? { kind: 'float', value: attributes.strokeWidth.value }
|
|
544
547
|
: checkedTapeNumber(svgNum(attributes.strokeWidth, 1));
|
package/aot/style-map.mjs
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
-
import {
|
|
19
|
+
import { BACKGROUND_MAX_STOPS, parseBackgroundImage, } from '../src/embedded-react/background-image.mjs';
|
|
20
|
+
import { NAMED_COLORS } from '../src/embedded-react/named-colors.mjs';
|
|
20
21
|
import { numberProblem } from './compiler/check.mjs';
|
|
21
22
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
22
23
|
- Constants
|
|
@@ -43,6 +44,11 @@ const FLEX_DIRECTION = {
|
|
|
43
44
|
'row-reverse': 'ER_FLEX_ROW_REVERSE',
|
|
44
45
|
'column-reverse': 'ER_FLEX_COLUMN_REVERSE',
|
|
45
46
|
};
|
|
47
|
+
const FLEX_WRAP = {
|
|
48
|
+
nowrap: 'ER_WRAP_NOWRAP',
|
|
49
|
+
wrap: 'ER_WRAP_WRAP',
|
|
50
|
+
'wrap-reverse': 'ER_WRAP_WRAP_REVERSE',
|
|
51
|
+
};
|
|
46
52
|
const POSITION = {
|
|
47
53
|
relative: 'ER_POSITION_RELATIVE',
|
|
48
54
|
absolute: 'ER_POSITION_ABSOLUTE',
|
|
@@ -102,6 +108,7 @@ const NUMBER_FIELDS = {
|
|
|
102
108
|
*/
|
|
103
109
|
const ENUM_FIELDS = {
|
|
104
110
|
flexDirection: { field: 'flex_direction', table: FLEX_DIRECTION },
|
|
111
|
+
flexWrap: { field: 'flex_wrap', table: FLEX_WRAP },
|
|
105
112
|
alignItems: { field: 'align_items', table: ALIGN },
|
|
106
113
|
alignSelf: { field: 'align_self', table: ALIGN },
|
|
107
114
|
justifyContent: { field: 'justify_content', table: JUSTIFY },
|
|
@@ -327,6 +334,9 @@ const KEYS = {
|
|
|
327
334
|
value: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
|
|
328
335
|
},
|
|
329
336
|
],
|
|
337
|
+
flexWrap: wrap => [
|
|
338
|
+
{ field: 'flex_wrap', value: enumKey(FLEX_WRAP, 'flexWrap')(wrap) },
|
|
339
|
+
],
|
|
330
340
|
alignItems: alignment => [
|
|
331
341
|
{ field: 'align_items', value: enumKey(ALIGN, 'alignItems')(alignment) },
|
|
332
342
|
],
|
|
@@ -375,6 +385,39 @@ const KEYS = {
|
|
|
375
385
|
backgroundColor: color => [
|
|
376
386
|
{ field: 'background_color', value: parseColorValue(color) },
|
|
377
387
|
],
|
|
388
|
+
// One gradient, as Flow A reads it. Every field is written, so a later backgroundImage replaces an earlier one
|
|
389
|
+
// whole.
|
|
390
|
+
backgroundImage: image => {
|
|
391
|
+
const result = parseBackgroundImage(image);
|
|
392
|
+
if (result.problem !== undefined) {
|
|
393
|
+
throw new Error(result.problem);
|
|
394
|
+
}
|
|
395
|
+
const { gradient } = result;
|
|
396
|
+
return [
|
|
397
|
+
{
|
|
398
|
+
field: 'gradient_type',
|
|
399
|
+
value: gradient.type === 'radial'
|
|
400
|
+
? 'ER_GRADIENT_RADIAL'
|
|
401
|
+
: 'ER_GRADIENT_LINEAR',
|
|
402
|
+
},
|
|
403
|
+
{ field: 'gradient_corner', value: gradient.corner },
|
|
404
|
+
{ field: 'gradient_angle', value: gradient.angle },
|
|
405
|
+
{ field: 'gradient_stop_count', value: gradient.stops.length },
|
|
406
|
+
...Array.from({ length: BACKGROUND_MAX_STOPS }, (_, index) => {
|
|
407
|
+
const stop = gradient.stops[index];
|
|
408
|
+
return [
|
|
409
|
+
{
|
|
410
|
+
field: `gradient_stops[${index}].color`,
|
|
411
|
+
value: stop ? parseColorValue(stop.color) : 0,
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
field: `gradient_stops[${index}].position`,
|
|
415
|
+
value: stop ? stop.offset : 0,
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
}).flat(),
|
|
419
|
+
];
|
|
420
|
+
},
|
|
378
421
|
borderRadius: radius => [{ field: 'border_radius', value: dimension(radius) }],
|
|
379
422
|
// Per-corner radii; the engine reads 0 in one of these as "use borderRadius" (same as Flow A).
|
|
380
423
|
borderTopLeftRadius: radius => [
|