embedded-react 0.18.0 → 0.20.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 +1 -1
- package/README.md +8 -4
- package/aot/compile.mjs +178 -58
- package/aot/compiler/animations.mjs +290 -281
- package/aot/compiler/boot.mjs +70 -33
- package/aot/compiler/branch-merge.mjs +4 -3
- package/aot/compiler/check.mjs +9 -9
- package/aot/compiler/collect.mjs +324 -205
- package/aot/compiler/control-flow.mjs +209 -197
- package/aot/compiler/diagnostics.mjs +22 -25
- package/aot/compiler/elements/activity-indicator.mjs +25 -24
- package/aot/compiler/elements/dial.mjs +91 -77
- package/aot/compiler/elements/flat-list.mjs +24 -22
- package/aot/compiler/elements/image.mjs +51 -50
- package/aot/compiler/elements/modal.mjs +31 -30
- package/aot/compiler/elements/props.mjs +23 -23
- package/aot/compiler/elements/switch.mjs +42 -34
- package/aot/compiler/elements/text-input.mjs +34 -32
- package/aot/compiler/expressions.mjs +372 -333
- package/aot/compiler/handlers.mjs +473 -387
- package/aot/compiler/ir/functions.mjs +11 -1
- package/aot/compiler/ir/nodes.mjs +4 -4
- package/aot/compiler/ir/reads.mjs +19 -19
- package/aot/compiler/ir/types.mjs +14 -14
- package/aot/compiler/ir/vectors.mjs +5 -1
- package/aot/compiler/keyboard.mjs +17 -7
- package/aot/compiler/lower.mjs +77 -80
- package/aot/compiler/nodes.mjs +169 -152
- package/aot/compiler/options.mjs +35 -30
- package/aot/compiler/out.mjs +18 -22
- package/aot/compiler/package/animations.mjs +669 -0
- package/aot/compiler/package/arena.mjs +252 -0
- package/aot/compiler/package/assemble.mjs +177 -0
- package/aot/compiler/package/bytecode.mjs +286 -0
- package/aot/compiler/package/checks.mjs +1022 -0
- package/aot/compiler/package/codegen.mjs +1329 -0
- package/aot/compiler/package/enums.mjs +138 -0
- package/aot/compiler/package/format.mjs +760 -0
- package/aot/compiler/package/layouts.mjs +136 -0
- package/aot/compiler/package/lower.mjs +1606 -0
- package/aot/compiler/package/props.mjs +118 -0
- package/aot/compiler/package/tables.mjs +103 -0
- package/aot/compiler/package/vectors.mjs +502 -0
- package/aot/compiler/package/writer.mjs +664 -0
- package/aot/compiler/pan-responder.mjs +69 -61
- package/aot/compiler/parse.mjs +21 -21
- package/aot/compiler/static-eval.mjs +25 -23
- package/aot/compiler/style-text.mjs +161 -172
- package/aot/compiler/svg.mjs +477 -251
- package/aot/screenshot-smoke.mjs +55 -41
- package/aot/style-map.mjs +102 -90
- 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 +14 -10
- package/assets/emit-c.mjs +83 -62
- package/assets/emit-container.mjs +124 -38
- 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 +16 -14
- package/cli.mjs +359 -172
- package/compile-bin.mjs +5 -5
- package/flash.mjs +537 -0
- package/hotreload/dev-device.mjs +90 -33
- package/hotreload/pack-app.mjs +55 -43
- package/hotreload/pack-split.mjs +46 -37
- package/hotreload/package-transfer.mjs +175 -0
- package/hotreload/protocol.mjs +51 -38
- package/hotreload/uploader.mjs +38 -27
- package/hotreload/watch-tree.mjs +19 -19
- package/pack-container.mjs +31 -23
- package/package.json +11 -12
- 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 +101 -82
- package/src/embedded-react/Animated.js +24 -24
- package/src/embedded-react/Easing.js +1 -1
- package/src/embedded-react/FlatList.js +4 -4
- 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 +6 -6
- package/src/embedded-react/StyleSheet.js +4 -3
- package/src/embedded-react/TouchableOpacity.js +13 -8
- package/src/embedded-react/index.d.ts +5 -5
- 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/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
|
@@ -18,15 +18,13 @@
|
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { attemptLowering, check } from './check.mjs';
|
|
20
20
|
import { BootReadError, bootEnvOf, bootSlotOf, foldBoot, isBoot, } from './boot.mjs';
|
|
21
|
-
import { lowerStyle, isStyleKey, STYLE_KEYS, DYN_FIELDS,
|
|
21
|
+
import { lowerStyle, isStyleKey, STYLE_KEYS, DYN_FIELDS, parseColorValue, } from '../style-map.mjs';
|
|
22
22
|
import { parseColor } from '../../src/embedded-react/svg-ops.js';
|
|
23
23
|
import { aotError, checkEngineString } from './diagnostics.mjs';
|
|
24
24
|
import { at, checkAnimatedStyleKey, checkAttributes, checkStyleKey, inlineFragments, TEXT_SPAN, } from './elements/props.mjs';
|
|
25
25
|
import { evalStatic, foldScope, withUndefined } from './static-eval.mjs';
|
|
26
|
-
import { cstr } from './c-syntax.mjs';
|
|
27
26
|
import { jsxChildText, lowerExpr, lowerText } from './expressions.mjs';
|
|
28
|
-
import {
|
|
29
|
-
import { ANIM_COLOR_KEYS, ANIM_STYLE_PROPS, ANIM_TRANSFORM_PROPS, parseInterp, } from './animations.mjs';
|
|
27
|
+
import { ANIMATED_COLOR_KEYS, ANIMATED_STYLE_PROPS, ANIMATED_TRANSFORM_PROPS, parseInterp, } from './animations.mjs';
|
|
30
28
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
31
29
|
- Constants
|
|
32
30
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -38,6 +36,8 @@ const BOOT_PIXEL_FIELDS = {
|
|
|
38
36
|
bottom: 'bottom',
|
|
39
37
|
flexBasis: 'flex_basis',
|
|
40
38
|
};
|
|
39
|
+
/** A span's weight, style or decoration that takes its parent's. */
|
|
40
|
+
const SPAN_INHERIT = 0xff;
|
|
41
41
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
42
42
|
- Implementation
|
|
43
43
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -45,48 +45,41 @@ const BOOT_PIXEL_FIELDS = {
|
|
|
45
45
|
* A JSX attribute's value as an expression: a bare `name` is `true`, `name="x"` the string, `name={expr}` the
|
|
46
46
|
* expression.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
48
|
+
* @param attribute The attribute.
|
|
49
49
|
*
|
|
50
50
|
* @returns Its value.
|
|
51
51
|
*/
|
|
52
|
-
export function attrExpr(
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
52
|
+
export function attrExpr(attribute) {
|
|
53
|
+
const attributeValue = attribute.value;
|
|
54
|
+
if (!attributeValue)
|
|
55
55
|
return { type: 'BooleanLiteral', value: true };
|
|
56
|
-
if (
|
|
57
|
-
return
|
|
58
|
-
if (
|
|
59
|
-
return
|
|
60
|
-
return
|
|
56
|
+
if (attributeValue.type === 'StringLiteral')
|
|
57
|
+
return attributeValue;
|
|
58
|
+
if (attributeValue.type === 'JSXExpressionContainer')
|
|
59
|
+
return attributeValue.expression;
|
|
60
|
+
return attributeValue;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* A static ARGB8888
|
|
63
|
+
* A static ARGB8888 value from a CSS color string or number.
|
|
64
64
|
*
|
|
65
65
|
* @param value The color.
|
|
66
66
|
*
|
|
67
|
-
* @returns Its
|
|
67
|
+
* @returns Its value.
|
|
68
68
|
*/
|
|
69
|
-
export
|
|
70
|
-
return ('0x' +
|
|
71
|
-
(parseColor(String(value)) >>> 0)
|
|
72
|
-
.toString(16)
|
|
73
|
-
.padStart(8, '0')
|
|
74
|
-
.toUpperCase() +
|
|
75
|
-
'u');
|
|
76
|
-
}
|
|
69
|
+
export const argbValue = (value) => parseColor(String(value)) >>> 0;
|
|
77
70
|
/**
|
|
78
71
|
* Refuses an animated binding whose values do not fit the key: a color key takes only an interpolation onto
|
|
79
72
|
* colors, and every other key only numbers.
|
|
80
73
|
*
|
|
81
74
|
* @param key The style or transform key.
|
|
82
|
-
* @param
|
|
75
|
+
* @param interpolation The binding's interpolation, or undefined for the value itself.
|
|
83
76
|
* @param node The node to pin an error to.
|
|
84
77
|
*/
|
|
85
|
-
function checkAnimatedColor(key,
|
|
86
|
-
if (
|
|
78
|
+
function checkAnimatedColor(key, interpolation, node) {
|
|
79
|
+
if (ANIMATED_COLOR_KEYS.has(key) && !interpolation?.colors) {
|
|
87
80
|
throw at(aotError(`AOT: an animated "${key}" needs colors`, "bind value.interpolate({inputRange: [0, 1], outputRange: ['#000', '#fff']}) rather than a number."), node);
|
|
88
81
|
}
|
|
89
|
-
if (!
|
|
82
|
+
if (!ANIMATED_COLOR_KEYS.has(key) && interpolation?.colors) {
|
|
90
83
|
throw at(aotError(`AOT: an animated "${key}" takes numbers, not colors`, 'an outputRange of colors drives backgroundColor or color.'), node);
|
|
91
84
|
}
|
|
92
85
|
}
|
|
@@ -94,34 +87,34 @@ function checkAnimatedColor(key, interp, node) {
|
|
|
94
87
|
* Lowers a dynamic (state-referencing) color expression to an ARGB value: a color, or a ternary of them.
|
|
95
88
|
*
|
|
96
89
|
* @param node The color expression.
|
|
97
|
-
* @param
|
|
90
|
+
* @param environment The expression environment.
|
|
98
91
|
*
|
|
99
92
|
* @returns The value.
|
|
100
93
|
*/
|
|
101
|
-
export function lowerColorValue(node,
|
|
94
|
+
export function lowerColorValue(node, environment) {
|
|
102
95
|
if (node.type === 'StringLiteral') {
|
|
103
|
-
return { kind: 'constant',
|
|
96
|
+
return { kind: 'constant', value: parseColorValue(node.value) };
|
|
104
97
|
}
|
|
105
98
|
if (node.type === 'ConditionalExpression') {
|
|
106
99
|
return {
|
|
107
100
|
kind: 'select',
|
|
108
|
-
test: lowerExpr(node.test,
|
|
109
|
-
whenTrue: lowerColorValue(node.consequent,
|
|
110
|
-
whenFalse: lowerColorValue(node.alternate,
|
|
101
|
+
test: lowerExpr(node.test, environment),
|
|
102
|
+
whenTrue: lowerColorValue(node.consequent, environment),
|
|
103
|
+
whenFalse: lowerColorValue(node.alternate, environment),
|
|
111
104
|
};
|
|
112
105
|
}
|
|
113
106
|
// A const worked out at boot picks its color at boot, from its own expression.
|
|
114
|
-
const bootAlias = bootAliasOf(node,
|
|
107
|
+
const bootAlias = bootAliasOf(node, environment);
|
|
115
108
|
if (bootAlias) {
|
|
116
|
-
const picked = tryLowering(() => lowerColorValue(bootAlias.node, bootAlias.
|
|
109
|
+
const picked = tryLowering(() => lowerColorValue(bootAlias.node, bootAlias.environment));
|
|
117
110
|
if (picked)
|
|
118
111
|
return picked;
|
|
119
112
|
}
|
|
120
113
|
// A statically resolvable color (a const string, or a theme token like `theme.card`) folds to a literal.
|
|
121
114
|
try {
|
|
122
|
-
const color = evalStatic(node, foldScope(
|
|
115
|
+
const color = evalStatic(node, foldScope(environment, environment.constants ?? {}));
|
|
123
116
|
if (typeof color === 'string') {
|
|
124
|
-
return { kind: 'constant',
|
|
117
|
+
return { kind: 'constant', value: parseColorValue(color) };
|
|
125
118
|
}
|
|
126
119
|
}
|
|
127
120
|
catch {
|
|
@@ -129,26 +122,17 @@ export function lowerColorValue(node, env) {
|
|
|
129
122
|
}
|
|
130
123
|
throw new Error('AOT: a dynamic color must be a color string literal or a ternary of them');
|
|
131
124
|
}
|
|
132
|
-
/**
|
|
133
|
-
* A dynamic color expression as C for its ARGB value (see lowerColorValue).
|
|
134
|
-
*
|
|
135
|
-
* @param node The color expression.
|
|
136
|
-
* @param env The expression environment.
|
|
137
|
-
*
|
|
138
|
-
* @returns The C.
|
|
139
|
-
*/
|
|
140
|
-
export const emitColorExpr = (node, env) => printPropValue(lowerColorValue(node, env));
|
|
141
125
|
/**
|
|
142
126
|
* Lowers a dynamic enum-style expression (e.g. `flexDirection: row ? 'row' : 'column'`) to its ER_* constant
|
|
143
127
|
* (or a ternary of them), looking values up in the style key's enum `table`.
|
|
144
128
|
*
|
|
145
129
|
* @param node The enum expression.
|
|
146
130
|
* @param table The RN value → ER_* constant table.
|
|
147
|
-
* @param
|
|
131
|
+
* @param environment The expression environment.
|
|
148
132
|
*
|
|
149
133
|
* @returns The value.
|
|
150
134
|
*/
|
|
151
|
-
export function lowerEnumValue(node, table,
|
|
135
|
+
export function lowerEnumValue(node, table, environment) {
|
|
152
136
|
if (node.type === 'StringLiteral') {
|
|
153
137
|
const enumConstant = Object.hasOwn(table, node.value)
|
|
154
138
|
? table[node.value]
|
|
@@ -156,28 +140,28 @@ export function lowerEnumValue(node, table, env) {
|
|
|
156
140
|
if (!enumConstant) {
|
|
157
141
|
throw aotError(`AOT: unsupported enum value "${node.value}"`, `one of: ${Object.keys(table).join(', ')}`);
|
|
158
142
|
}
|
|
159
|
-
return { kind: 'constant',
|
|
143
|
+
return { kind: 'constant', value: enumConstant };
|
|
160
144
|
}
|
|
161
145
|
if (node.type === 'ConditionalExpression') {
|
|
162
146
|
return {
|
|
163
147
|
kind: 'select',
|
|
164
|
-
test: lowerExpr(node.test,
|
|
165
|
-
whenTrue: lowerEnumValue(node.consequent, table,
|
|
166
|
-
whenFalse: lowerEnumValue(node.alternate, table,
|
|
148
|
+
test: lowerExpr(node.test, environment),
|
|
149
|
+
whenTrue: lowerEnumValue(node.consequent, table, environment),
|
|
150
|
+
whenFalse: lowerEnumValue(node.alternate, table, environment),
|
|
167
151
|
};
|
|
168
152
|
}
|
|
169
153
|
// A const worked out at boot picks its value at boot, from its own expression.
|
|
170
|
-
const bootAlias = bootAliasOf(node,
|
|
154
|
+
const bootAlias = bootAliasOf(node, environment);
|
|
171
155
|
if (bootAlias) {
|
|
172
|
-
const picked = tryLowering(() => lowerEnumValue(bootAlias.node, table, bootAlias.
|
|
156
|
+
const picked = tryLowering(() => lowerEnumValue(bootAlias.node, table, bootAlias.environment));
|
|
173
157
|
if (picked)
|
|
174
158
|
return picked;
|
|
175
159
|
}
|
|
176
160
|
// A statically resolvable enum (a const string) folds to its constant.
|
|
177
161
|
try {
|
|
178
|
-
const enumValue = evalStatic(node, foldScope(
|
|
162
|
+
const enumValue = evalStatic(node, foldScope(environment, environment.constants ?? {}));
|
|
179
163
|
if (typeof enumValue === 'string' && Object.hasOwn(table, enumValue)) {
|
|
180
|
-
return { kind: 'constant',
|
|
164
|
+
return { kind: 'constant', value: table[enumValue] };
|
|
181
165
|
}
|
|
182
166
|
}
|
|
183
167
|
catch {
|
|
@@ -185,16 +169,6 @@ export function lowerEnumValue(node, table, env) {
|
|
|
185
169
|
}
|
|
186
170
|
throw aotError('AOT: a state-driven enum style must be a string literal or a ternary of them', "e.g. flexDirection: wide ? 'row' : 'column'");
|
|
187
171
|
}
|
|
188
|
-
/**
|
|
189
|
-
* A dynamic enum-style expression as C for its ER_* value (see lowerEnumValue).
|
|
190
|
-
*
|
|
191
|
-
* @param node The enum expression.
|
|
192
|
-
* @param table The RN value → ER_* constant table.
|
|
193
|
-
* @param env The expression environment.
|
|
194
|
-
*
|
|
195
|
-
* @returns The C.
|
|
196
|
-
*/
|
|
197
|
-
export const emitEnumExpr = (node, table, env) => printPropValue(lowerEnumValue(node, table, env));
|
|
198
172
|
/**
|
|
199
173
|
* The diagnostic for a style key the AOT has no lowering for, static or dynamic.
|
|
200
174
|
*
|
|
@@ -236,11 +210,11 @@ function lowerStyleChecked(key, value) {
|
|
|
236
210
|
*
|
|
237
211
|
* @param key The style key.
|
|
238
212
|
* @param valueNode Its state-driven value.
|
|
239
|
-
* @param
|
|
213
|
+
* @param environment The expression environment.
|
|
240
214
|
*
|
|
241
215
|
* @returns The ERProps writes.
|
|
242
216
|
*/
|
|
243
|
-
function lowerDynamicStyleValue(key, valueNode,
|
|
217
|
+
function lowerDynamicStyleValue(key, valueNode, environment) {
|
|
244
218
|
// Own properties only, so a key like `toString` cannot resolve to Object.prototype and emit `p.undefined`.
|
|
245
219
|
const dynamicField = Object.hasOwn(DYN_FIELDS, key)
|
|
246
220
|
? DYN_FIELDS[key]
|
|
@@ -254,24 +228,27 @@ function lowerDynamicStyleValue(key, valueNode, env) {
|
|
|
254
228
|
`layout enums (flexDirection, alignItems, alignSelf, justifyContent, position, ` +
|
|
255
229
|
`display). Make "${key}" static, or drive the change another way.`);
|
|
256
230
|
}
|
|
257
|
-
// Colors and enums lower to a constant or a
|
|
231
|
+
// Colors and enums lower to a constant or a choice of constants.
|
|
258
232
|
if (dynamicField.kind === 'color') {
|
|
259
233
|
return [
|
|
260
|
-
{
|
|
234
|
+
{
|
|
235
|
+
field: dynamicField.field,
|
|
236
|
+
value: lowerColorValue(valueNode, environment),
|
|
237
|
+
},
|
|
261
238
|
];
|
|
262
239
|
}
|
|
263
240
|
if (dynamicField.kind === 'enum') {
|
|
264
241
|
return [
|
|
265
242
|
{
|
|
266
243
|
field: dynamicField.field,
|
|
267
|
-
value: lowerEnumValue(valueNode, dynamicField.table,
|
|
244
|
+
value: lowerEnumValue(valueNode, dynamicField.table, environment),
|
|
268
245
|
},
|
|
269
246
|
];
|
|
270
247
|
}
|
|
271
|
-
// Opacity and every size are numbers
|
|
272
|
-
const
|
|
273
|
-
if (
|
|
274
|
-
const error = aotError(`AOT: style "${key}" needs a number, but the value is a string`, "JS would coerce the string;
|
|
248
|
+
// Opacity and every size are numbers.
|
|
249
|
+
const valueExpression = lowerExpr(valueNode, environment);
|
|
250
|
+
if (valueExpression.type.kind === 'string') {
|
|
251
|
+
const error = aotError(`AOT: style "${key}" needs a number, but the value is a string`, "JS would coerce the string; the AOT doesn't. Keep the state numeric — useState(10), not useState('10').");
|
|
275
252
|
if (valueNode.loc) {
|
|
276
253
|
error.aotLoc = valueNode.loc.start;
|
|
277
254
|
}
|
|
@@ -279,11 +256,17 @@ function lowerDynamicStyleValue(key, valueNode, env) {
|
|
|
279
256
|
}
|
|
280
257
|
if (dynamicField.kind === 'opacity') {
|
|
281
258
|
return [
|
|
282
|
-
{
|
|
259
|
+
{
|
|
260
|
+
field: dynamicField.field,
|
|
261
|
+
value: { kind: 'opacity', value: valueExpression },
|
|
262
|
+
},
|
|
283
263
|
];
|
|
284
264
|
}
|
|
285
265
|
return [
|
|
286
|
-
{
|
|
266
|
+
{
|
|
267
|
+
field: dynamicField.field,
|
|
268
|
+
value: { kind: 'dimension', value: valueExpression },
|
|
269
|
+
},
|
|
287
270
|
];
|
|
288
271
|
}
|
|
289
272
|
/**
|
|
@@ -291,22 +274,22 @@ function lowerDynamicStyleValue(key, valueNode, env) {
|
|
|
291
274
|
* entry of one), for a lowering that picks between literals.
|
|
292
275
|
*
|
|
293
276
|
* @param node The expression.
|
|
294
|
-
* @param
|
|
277
|
+
* @param environment The expression environment.
|
|
295
278
|
*
|
|
296
279
|
* @returns The value's own expression and the environment it lowers in, or null.
|
|
297
280
|
*/
|
|
298
|
-
function bootAliasOf(node,
|
|
281
|
+
function bootAliasOf(node, environment) {
|
|
299
282
|
let value;
|
|
300
283
|
try {
|
|
301
|
-
value = evalStatic(node, foldScope(
|
|
284
|
+
value = evalStatic(node, foldScope(environment, environment.constants ?? {}), 'boot');
|
|
302
285
|
}
|
|
303
286
|
catch {
|
|
304
287
|
return null;
|
|
305
288
|
}
|
|
306
289
|
if (!isBoot(value) || !value.node || value.node === node)
|
|
307
290
|
return null;
|
|
308
|
-
const
|
|
309
|
-
return
|
|
291
|
+
const bootEnvironment = bootEnvOf(value);
|
|
292
|
+
return bootEnvironment && { node: value.node, environment: bootEnvironment };
|
|
310
293
|
}
|
|
311
294
|
/**
|
|
312
295
|
* A style entry worked out at boot, as the runtime write of its field: a size or an opacity. Null for a value
|
|
@@ -317,7 +300,7 @@ function bootAliasOf(node, env) {
|
|
|
317
300
|
*
|
|
318
301
|
* @returns The write, or null.
|
|
319
302
|
*/
|
|
320
|
-
function bootStyleAssign(key, value) {
|
|
303
|
+
export function bootStyleAssign(key, value) {
|
|
321
304
|
const dynamicField = Object.hasOwn(DYN_FIELDS, key)
|
|
322
305
|
? DYN_FIELDS[key]
|
|
323
306
|
: undefined;
|
|
@@ -326,13 +309,13 @@ function bootStyleAssign(key, value) {
|
|
|
326
309
|
: undefined;
|
|
327
310
|
// A color or an enum lowers its own expression (a ternary of literals) against the names it reads.
|
|
328
311
|
if (dynamicField?.kind === 'color' || dynamicField?.kind === 'enum') {
|
|
329
|
-
const
|
|
312
|
+
const environment = bootEnvOf(value);
|
|
330
313
|
const valueNode = value.node;
|
|
331
|
-
if (!
|
|
314
|
+
if (!environment || !valueNode)
|
|
332
315
|
return null;
|
|
333
316
|
const propValue = tryLowering(() => dynamicField.kind === 'enum'
|
|
334
|
-
? lowerEnumValue(valueNode, dynamicField.table,
|
|
335
|
-
: lowerColorValue(valueNode,
|
|
317
|
+
? lowerEnumValue(valueNode, dynamicField.table, environment)
|
|
318
|
+
: lowerColorValue(valueNode, environment));
|
|
336
319
|
return propValue && { field: dynamicField.field, value: propValue };
|
|
337
320
|
}
|
|
338
321
|
const isNumeric = pixelField ||
|
|
@@ -359,15 +342,15 @@ function bootStyleAssign(key, value) {
|
|
|
359
342
|
*
|
|
360
343
|
* @param key The style key.
|
|
361
344
|
* @param valueNode The value expression.
|
|
362
|
-
* @param
|
|
345
|
+
* @param environment The expression environment.
|
|
363
346
|
*
|
|
364
347
|
* @returns The runtime writes.
|
|
365
348
|
*/
|
|
366
|
-
function lowerBootStyleValue(key, valueNode,
|
|
349
|
+
function lowerBootStyleValue(key, valueNode, environment) {
|
|
367
350
|
if (!Object.hasOwn(BOOT_PIXEL_FIELDS, key)) {
|
|
368
|
-
return lowerDynamicStyleValue(key, valueNode,
|
|
351
|
+
return lowerDynamicStyleValue(key, valueNode, environment);
|
|
369
352
|
}
|
|
370
|
-
const value = lowerExpr(valueNode,
|
|
353
|
+
const value = lowerExpr(valueNode, environment);
|
|
371
354
|
if (value.type.kind !== 'int' && value.type.kind !== 'float') {
|
|
372
355
|
throw new Error(`AOT: style "${key}" needs a number`);
|
|
373
356
|
}
|
|
@@ -390,18 +373,18 @@ function tryLowering(attempt) {
|
|
|
390
373
|
}
|
|
391
374
|
/**
|
|
392
375
|
* Whether a style already writes `field`, counting its percentage twin: `width: '50%'` lowers to
|
|
393
|
-
* `
|
|
376
|
+
* `width_percent`, and the author has still set the width. Used by the components that fall back to a
|
|
394
377
|
* built-in size or inset when the style leaves one out — without the twin they inject a pixel default
|
|
395
378
|
* ALONGSIDE the percentage, and the engine prefers the pixel value for a size.
|
|
396
379
|
*
|
|
397
380
|
* @param staticAssigns Static field writes from collectStyleAssigns().
|
|
398
|
-
* @param
|
|
381
|
+
* @param dynamicAssigns State-driven field writes from collectStyleAssigns().
|
|
399
382
|
* @param field ERProps field to look for.
|
|
400
383
|
*
|
|
401
|
-
* @returns Whether either list writes the field or its `
|
|
384
|
+
* @returns Whether either list writes the field or its `_percent` twin.
|
|
402
385
|
*/
|
|
403
|
-
export const styleWrites = (staticAssigns,
|
|
404
|
-
|
|
386
|
+
export const styleWrites = (staticAssigns, dynamicAssigns, field) => [field, `${field}_percent`].some(fieldName => staticAssigns.some(assign => assign.field === fieldName) ||
|
|
387
|
+
dynamicAssigns.some(assign => assign.field === fieldName));
|
|
405
388
|
/**
|
|
406
389
|
* Collects an element's merged style into static field assigns and dynamic (state-driven) field assigns.
|
|
407
390
|
* Inline object values are tried statically first; a value that references state becomes a dynAssign.
|
|
@@ -410,36 +393,38 @@ export const styleWrites = (staticAssigns, dynAssigns, field) => [field, `${fiel
|
|
|
410
393
|
*
|
|
411
394
|
* @param openingElement The element's opening tag.
|
|
412
395
|
* @param scope Compile-time constants in reach.
|
|
413
|
-
* @param
|
|
396
|
+
* @param environment The expression environment.
|
|
414
397
|
* @param spec The element, for the style keys it takes.
|
|
415
398
|
* @param bootValues How a value worked out at boot is set: once at build, or taken at the build's panel.
|
|
416
399
|
*
|
|
417
400
|
* @returns The style's constant writes, state-driven writes, and animated-value binds.
|
|
418
401
|
*/
|
|
419
|
-
export function collectStyleAssigns(openingElement, scope,
|
|
420
|
-
// ERProps field → its last write: a constant
|
|
402
|
+
export function collectStyleAssigns(openingElement, scope, environment, spec, bootValues = 'boot') {
|
|
403
|
+
// ERProps field → its last write: a constant, or a state-driven value.
|
|
421
404
|
const fields = new Map();
|
|
422
405
|
const binds = []; // animated values bound to node properties (native driver)
|
|
423
406
|
// A size in pixels and its percentage twin are one style key, so a later write of either replaces both.
|
|
424
407
|
const setField = (field, write) => {
|
|
425
|
-
fields.delete(field.endsWith('
|
|
408
|
+
fields.delete(field.endsWith('_percent')
|
|
409
|
+
? field.slice(0, -'_percent'.length)
|
|
410
|
+
: `${field}_percent`);
|
|
426
411
|
fields.set(field, write);
|
|
427
412
|
};
|
|
428
|
-
// The
|
|
429
|
-
const animRef = (node) => node?.type === 'Identifier' &&
|
|
430
|
-
?
|
|
413
|
+
// The handle of an animated value used directly as a style value, or null.
|
|
414
|
+
const animRef = (node) => node?.type === 'Identifier' && environment.animations?.has(node.name)
|
|
415
|
+
? environment.animations.get(node.name).slotName
|
|
431
416
|
: null;
|
|
432
|
-
// `<animValue>.interpolate({ inputRange, outputRange, extrapolate })` → {
|
|
417
|
+
// `<animValue>.interpolate({ inputRange, outputRange, extrapolate })` → { slotName, interp } for a mapped bind.
|
|
433
418
|
const animInterpRef = (node) => {
|
|
434
419
|
if (node?.type === 'CallExpression' &&
|
|
435
420
|
node.callee.type === 'MemberExpression' &&
|
|
436
421
|
!node.callee.computed &&
|
|
437
422
|
node.callee.property.name === 'interpolate' &&
|
|
438
423
|
node.callee.object.type === 'Identifier' &&
|
|
439
|
-
|
|
424
|
+
environment.animations?.has(node.callee.object.name)) {
|
|
440
425
|
return {
|
|
441
|
-
|
|
442
|
-
|
|
426
|
+
slotName: environment.animations.get(node.callee.object.name).slotName,
|
|
427
|
+
interpolation: parseInterp(node.arguments[0], environment),
|
|
443
428
|
};
|
|
444
429
|
}
|
|
445
430
|
return null;
|
|
@@ -468,14 +453,18 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
468
453
|
continue;
|
|
469
454
|
}
|
|
470
455
|
// An animated entry the engine has no property for is refused, not skipped.
|
|
471
|
-
if (!Object.hasOwn(
|
|
472
|
-
throw at(aotError(`AOT: transform "${transformKey}" cannot be animated in Flow B`, `animated transforms: ${Object.keys(
|
|
456
|
+
if (!Object.hasOwn(ANIMATED_TRANSFORM_PROPS, transformKey)) {
|
|
457
|
+
throw at(aotError(`AOT: transform "${transformKey}" cannot be animated in Flow B`, `animated transforms: ${Object.keys(ANIMATED_TRANSFORM_PROPS).join(', ')}.`), transformProp);
|
|
473
458
|
}
|
|
474
|
-
checkAnimatedColor(transformKey, mapped?.
|
|
475
|
-
for (const
|
|
459
|
+
checkAnimatedColor(transformKey, mapped?.interpolation, transformProp);
|
|
460
|
+
for (const animationProp of ANIMATED_TRANSFORM_PROPS[transformKey]) {
|
|
476
461
|
transformBinds.push(mapped
|
|
477
|
-
? {
|
|
478
|
-
|
|
462
|
+
? {
|
|
463
|
+
slotName: mapped.slotName,
|
|
464
|
+
prop: animationProp,
|
|
465
|
+
interpolation: mapped.interpolation,
|
|
466
|
+
}
|
|
467
|
+
: { slotName: direct, prop: animationProp });
|
|
479
468
|
}
|
|
480
469
|
}
|
|
481
470
|
}
|
|
@@ -488,22 +477,22 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
488
477
|
return transformBinds;
|
|
489
478
|
};
|
|
490
479
|
// Lowers one style source (an array, an inline object, or a static reference) into `fields` and `binds`.
|
|
491
|
-
const applyStyle = (
|
|
480
|
+
const applyStyle = (expression) => {
|
|
492
481
|
// RN ignores an undefined style or style-array entry; so does Flow A's flattenStyle.
|
|
493
|
-
if (
|
|
482
|
+
if (expression.type === 'Identifier' && expression.name === 'undefined')
|
|
494
483
|
return;
|
|
495
484
|
// A style array applies its entries in order, so later entries win.
|
|
496
|
-
if (
|
|
497
|
-
for (const styleEntry of
|
|
485
|
+
if (expression.type === 'ArrayExpression') {
|
|
486
|
+
for (const styleEntry of expression.elements) {
|
|
498
487
|
if (styleEntry) {
|
|
499
488
|
applyStyle(styleEntry);
|
|
500
489
|
}
|
|
501
490
|
}
|
|
502
491
|
return;
|
|
503
492
|
}
|
|
504
|
-
// Inline object: bind animated values natively; fold other keys statically or re-apply them in
|
|
505
|
-
if (
|
|
506
|
-
for (const prop of
|
|
493
|
+
// Inline object: bind animated values natively; fold other keys statically or re-apply them in the update.
|
|
494
|
+
if (expression.type === 'ObjectExpression') {
|
|
495
|
+
for (const prop of expression.properties) {
|
|
507
496
|
if (prop.type !== 'ObjectProperty') {
|
|
508
497
|
throw new Error('AOT: spread/method in an inline style object not supported');
|
|
509
498
|
}
|
|
@@ -517,24 +506,24 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
517
506
|
continue;
|
|
518
507
|
}
|
|
519
508
|
// Bind an animated value to its prop (opacity / backgroundColor / color), directly or via .interpolate().
|
|
520
|
-
const
|
|
521
|
-
if (
|
|
509
|
+
const animationValue = animRef(prop.value);
|
|
510
|
+
if (animationValue && ANIMATED_STYLE_PROPS[key]) {
|
|
522
511
|
checkAnimatedStyleKey(spec, key, prop);
|
|
523
512
|
checkAnimatedColor(key, undefined, prop);
|
|
524
|
-
for (const
|
|
525
|
-
binds.push({
|
|
513
|
+
for (const animationProp of ANIMATED_STYLE_PROPS[key]) {
|
|
514
|
+
binds.push({ slotName: animationValue, prop: animationProp });
|
|
526
515
|
}
|
|
527
516
|
continue;
|
|
528
517
|
}
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
518
|
+
const animationInterpolation = animInterpRef(prop.value);
|
|
519
|
+
if (animationInterpolation && ANIMATED_STYLE_PROPS[key]) {
|
|
531
520
|
checkAnimatedStyleKey(spec, key, prop);
|
|
532
|
-
checkAnimatedColor(key,
|
|
533
|
-
for (const
|
|
521
|
+
checkAnimatedColor(key, animationInterpolation.interpolation, prop);
|
|
522
|
+
for (const animationProp of ANIMATED_STYLE_PROPS[key]) {
|
|
534
523
|
binds.push({
|
|
535
|
-
|
|
536
|
-
prop:
|
|
537
|
-
|
|
524
|
+
slotName: animationInterpolation.slotName,
|
|
525
|
+
prop: animationProp,
|
|
526
|
+
interpolation: animationInterpolation.interpolation,
|
|
538
527
|
});
|
|
539
528
|
}
|
|
540
529
|
continue;
|
|
@@ -553,7 +542,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
553
542
|
let readsBoot = false;
|
|
554
543
|
try {
|
|
555
544
|
staticValue = {
|
|
556
|
-
|
|
545
|
+
value: evalStatic(prop.value, withUndefined(scope), bootValues === 'fold' ? 'fold' : 'strict'),
|
|
557
546
|
};
|
|
558
547
|
}
|
|
559
548
|
catch (error) {
|
|
@@ -562,7 +551,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
562
551
|
}
|
|
563
552
|
// A value worked out at boot is set once at build; a key that takes no runtime value folds it instead.
|
|
564
553
|
if (readsBoot) {
|
|
565
|
-
const bootAssigns = tryLowering(() => lowerBootStyleValue(key, prop.value,
|
|
554
|
+
const bootAssigns = tryLowering(() => lowerBootStyleValue(key, prop.value, environment));
|
|
566
555
|
if (bootAssigns) {
|
|
567
556
|
checkStyleKey(spec, key, prop);
|
|
568
557
|
for (const assign of bootAssigns) {
|
|
@@ -570,19 +559,19 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
570
559
|
}
|
|
571
560
|
continue;
|
|
572
561
|
}
|
|
573
|
-
staticValue = {
|
|
562
|
+
staticValue = { value: evalStatic(prop.value, withUndefined(scope)) };
|
|
574
563
|
}
|
|
575
564
|
if (staticValue) {
|
|
576
|
-
if (staticValue.
|
|
565
|
+
if (staticValue.value != null) {
|
|
577
566
|
checkStyleKey(spec, key, prop);
|
|
578
567
|
}
|
|
579
|
-
for (const assign of lowerStyleChecked(key, staticValue.
|
|
580
|
-
setField(assign.field, {
|
|
568
|
+
for (const assign of lowerStyleChecked(key, staticValue.value)) {
|
|
569
|
+
setField(assign.field, { constant: assign.value });
|
|
581
570
|
}
|
|
582
571
|
}
|
|
583
572
|
else {
|
|
584
573
|
checkStyleKey(spec, key, prop);
|
|
585
|
-
for (const assign of lowerDynamicStyleValue(key, prop.value,
|
|
574
|
+
for (const assign of lowerDynamicStyleValue(key, prop.value, environment)) {
|
|
586
575
|
setField(assign.field, { value: assign.value });
|
|
587
576
|
}
|
|
588
577
|
}
|
|
@@ -590,7 +579,7 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
590
579
|
return;
|
|
591
580
|
}
|
|
592
581
|
// A static style reference; null, undefined or false (`cond && s`) means no style, as in RN.
|
|
593
|
-
let resolved = evalStatic(
|
|
582
|
+
let resolved = evalStatic(expression, withUndefined(scope), 'boot');
|
|
594
583
|
if (isBoot(resolved)) {
|
|
595
584
|
resolved = foldBoot(resolved);
|
|
596
585
|
}
|
|
@@ -603,39 +592,39 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
603
592
|
? bootStyleAssign(styleKey, entry)
|
|
604
593
|
: null;
|
|
605
594
|
if (bootAssign) {
|
|
606
|
-
checkStyleKey(spec, styleKey,
|
|
595
|
+
checkStyleKey(spec, styleKey, expression);
|
|
607
596
|
setField(bootAssign.field, { value: bootAssign.value });
|
|
608
597
|
continue;
|
|
609
598
|
}
|
|
610
599
|
const styleValue = foldBoot(entry);
|
|
611
600
|
if (styleValue === undefined || styleValue === null)
|
|
612
601
|
continue;
|
|
613
|
-
checkStyleKey(spec, styleKey,
|
|
602
|
+
checkStyleKey(spec, styleKey, expression);
|
|
614
603
|
for (const assign of lowerStyleChecked(styleKey, styleValue)) {
|
|
615
|
-
setField(assign.field, {
|
|
604
|
+
setField(assign.field, { constant: assign.value });
|
|
616
605
|
}
|
|
617
606
|
}
|
|
618
607
|
};
|
|
619
608
|
// Apply every style attribute in source order.
|
|
620
|
-
for (const
|
|
621
|
-
if (
|
|
622
|
-
|
|
609
|
+
for (const attribute of openingElement.attributes) {
|
|
610
|
+
if (attribute.type !== 'JSXAttribute' ||
|
|
611
|
+
attribute.name.name !== 'style') {
|
|
623
612
|
continue;
|
|
624
613
|
}
|
|
625
|
-
applyStyle(attrExpr(
|
|
614
|
+
applyStyle(attrExpr(attribute));
|
|
626
615
|
}
|
|
627
616
|
// Split the merged fields into constant writes and state-driven writes.
|
|
628
617
|
const staticAssigns = [];
|
|
629
|
-
const
|
|
618
|
+
const dynamicAssigns = [];
|
|
630
619
|
for (const [field, fieldWrite] of fields) {
|
|
631
620
|
if ('value' in fieldWrite) {
|
|
632
|
-
|
|
621
|
+
dynamicAssigns.push({ field, value: fieldWrite.value });
|
|
633
622
|
}
|
|
634
623
|
else {
|
|
635
|
-
staticAssigns.push({ field,
|
|
624
|
+
staticAssigns.push({ field, value: fieldWrite.constant });
|
|
636
625
|
}
|
|
637
626
|
}
|
|
638
|
-
return { staticAssigns,
|
|
627
|
+
return { staticAssigns, dynamicAssigns, binds };
|
|
639
628
|
}
|
|
640
629
|
/**
|
|
641
630
|
* Lowers a Text node's body. Static interpolations fold into literal text; any that reference state are values
|
|
@@ -643,11 +632,11 @@ export function collectStyleAssigns(openingElement, scope, env, spec, bootValues
|
|
|
643
632
|
*
|
|
644
633
|
* @param children The <Text>'s children.
|
|
645
634
|
* @param scope Compile-time constants in reach.
|
|
646
|
-
* @param
|
|
635
|
+
* @param environment The expression environment.
|
|
647
636
|
*
|
|
648
637
|
* @returns The body.
|
|
649
638
|
*/
|
|
650
|
-
export function lowerNodeText(children, scope,
|
|
639
|
+
export function lowerNodeText(children, scope, environment) {
|
|
651
640
|
const parts = [];
|
|
652
641
|
for (const child of inlineFragments(children)) {
|
|
653
642
|
if (child.type === 'JSXText') {
|
|
@@ -657,7 +646,7 @@ export function lowerNodeText(children, scope, env) {
|
|
|
657
646
|
if (child.expression.type === 'JSXEmptyExpression')
|
|
658
647
|
continue;
|
|
659
648
|
// Constants fold into literal text; anything referencing state is a runtime value.
|
|
660
|
-
parts.push(...lowerText(child.expression,
|
|
649
|
+
parts.push(...lowerText(child.expression, environment, scope).parts);
|
|
661
650
|
}
|
|
662
651
|
else if (child.type === 'JSXElement') {
|
|
663
652
|
throw new Error('AOT: nested <Text> / element children inside <Text> not yet supported (spans)');
|
|
@@ -739,17 +728,17 @@ function staticTextContent(children, scope) {
|
|
|
739
728
|
}
|
|
740
729
|
/**
|
|
741
730
|
* If a <Text>'s children include a nested <Text>, returns inline SPANS [{text, color, font_size,
|
|
742
|
-
* font_weight, font_style, text_decoration, letter_spacing}] (
|
|
731
|
+
* font_weight, font_style, text_decoration, letter_spacing}] (constants; inherit sentinels for unset).
|
|
743
732
|
* Returns null when there's no nested <Text> (caller uses the single-string buildText path). Static only —
|
|
744
733
|
* a dynamic {…} segment or a state-driven span style throws.
|
|
745
734
|
*
|
|
746
735
|
* @param children The <Text>'s children.
|
|
747
736
|
* @param scope Compile-time constants in reach.
|
|
748
|
-
* @param
|
|
737
|
+
* @param environment The expression environment.
|
|
749
738
|
*
|
|
750
739
|
* @returns The spans, or null when the <Text> has no nested <Text>.
|
|
751
740
|
*/
|
|
752
|
-
export function collectTextSpans(children, scope,
|
|
741
|
+
export function collectTextSpans(children, scope, environment) {
|
|
753
742
|
// Without a nested <Text>, the caller uses the single-string buildText path.
|
|
754
743
|
children = inlineFragments(children);
|
|
755
744
|
if (!children.some(child => child.type === 'JSXElement' &&
|
|
@@ -759,17 +748,17 @@ export function collectTextSpans(children, scope, env) {
|
|
|
759
748
|
// Inherit sentinels (see ERTextSpan doc): color 0, font_size 0, weight/style/decoration 0xFF, spacing AUTO.
|
|
760
749
|
const inheritSpan = (text) => ({
|
|
761
750
|
text,
|
|
762
|
-
color:
|
|
763
|
-
font_size:
|
|
764
|
-
font_weight:
|
|
765
|
-
font_style:
|
|
766
|
-
text_decoration:
|
|
751
|
+
color: 0,
|
|
752
|
+
font_size: 0,
|
|
753
|
+
font_weight: SPAN_INHERIT,
|
|
754
|
+
font_style: SPAN_INHERIT,
|
|
755
|
+
text_decoration: SPAN_INHERIT,
|
|
767
756
|
letter_spacing: 'ER_LAYOUT_AUTO',
|
|
768
757
|
});
|
|
769
|
-
// A span's text
|
|
758
|
+
// A span's text goes in a fixed engine buffer.
|
|
770
759
|
const spanText = (text) => {
|
|
771
760
|
checkEngineString(text, 'ER_SPAN_TEXT_MAX', 'a <Text> span');
|
|
772
|
-
return
|
|
761
|
+
return text;
|
|
773
762
|
};
|
|
774
763
|
// One span per child: text and static {…} values inherit the parent's style; a nested <Text> carries its own.
|
|
775
764
|
const spans = [];
|
|
@@ -799,20 +788,20 @@ export function collectTextSpans(children, scope, env) {
|
|
|
799
788
|
child.openingElement.name.name === 'Text') {
|
|
800
789
|
checkAttributes(TEXT_SPAN, child.openingElement);
|
|
801
790
|
// A span is a static table, so a value worked out at boot is taken at the build's panel instead.
|
|
802
|
-
const { staticAssigns,
|
|
803
|
-
if (
|
|
791
|
+
const { staticAssigns, dynamicAssigns } = collectStyleAssigns(child.openingElement, scope, environment, TEXT_SPAN, 'fold');
|
|
792
|
+
if (dynamicAssigns.length) {
|
|
804
793
|
throw aotError('AOT: a state-driven style on a nested <Text> span is not supported', 'give the span <Text> a static style.');
|
|
805
794
|
}
|
|
806
795
|
// Each span field is the nested <Text>'s own static style value, or the inherit sentinel.
|
|
807
|
-
const spanStyle = (fieldName, fallback) => staticAssigns.find(assign => assign.field === fieldName)?.
|
|
796
|
+
const spanStyle = (fieldName, fallback) => staticAssigns.find(assign => assign.field === fieldName)?.value ??
|
|
808
797
|
fallback;
|
|
809
798
|
spans.push({
|
|
810
799
|
text: spanText(staticTextContent(child.children, scope)),
|
|
811
|
-
color: spanStyle('color',
|
|
812
|
-
font_size: spanStyle('font_size',
|
|
813
|
-
font_weight: spanStyle('font_weight',
|
|
814
|
-
font_style: spanStyle('font_style',
|
|
815
|
-
text_decoration: spanStyle('text_decoration',
|
|
800
|
+
color: spanStyle('color', 0),
|
|
801
|
+
font_size: spanStyle('font_size', 0),
|
|
802
|
+
font_weight: spanStyle('font_weight', SPAN_INHERIT),
|
|
803
|
+
font_style: spanStyle('font_style', SPAN_INHERIT),
|
|
804
|
+
text_decoration: spanStyle('text_decoration', SPAN_INHERIT),
|
|
816
805
|
letter_spacing: spanStyle('letter_spacing', 'ER_LAYOUT_AUTO'),
|
|
817
806
|
});
|
|
818
807
|
}
|
|
@@ -824,7 +813,7 @@ export function collectTextSpans(children, scope, env) {
|
|
|
824
813
|
check({
|
|
825
814
|
kind: 'textSpans',
|
|
826
815
|
count: spans.length,
|
|
827
|
-
max:
|
|
816
|
+
max: environment.caps.maxTextSpans,
|
|
828
817
|
});
|
|
829
818
|
return spans;
|
|
830
819
|
}
|