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/style-map.mjs
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
- Imports
|
|
18
18
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
19
|
import { NAMED_COLORS } from '../src/embedded-react/named-colors.js';
|
|
20
|
+
import { numberProblem } from './compiler/check.mjs';
|
|
20
21
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
21
22
|
- Constants
|
|
22
23
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -37,14 +38,14 @@ const JUSTIFY = {
|
|
|
37
38
|
'space-evenly': 'ER_JUSTIFY_SPACE_EVENLY',
|
|
38
39
|
};
|
|
39
40
|
const FLEX_DIRECTION = {
|
|
40
|
-
column: '
|
|
41
|
+
column: 'ER_FLEX_COLUMN',
|
|
41
42
|
row: 'ER_FLEX_ROW',
|
|
42
43
|
'row-reverse': 'ER_FLEX_ROW_REVERSE',
|
|
43
|
-
'column-reverse': '
|
|
44
|
+
'column-reverse': 'ER_FLEX_COLUMN_REVERSE',
|
|
44
45
|
};
|
|
45
46
|
const POSITION = {
|
|
46
|
-
relative: '
|
|
47
|
-
absolute: '
|
|
47
|
+
relative: 'ER_POSITION_RELATIVE',
|
|
48
|
+
absolute: 'ER_POSITION_ABSOLUTE',
|
|
48
49
|
};
|
|
49
50
|
const DISPLAY = { flex: 'ER_DISPLAY_FLEX', none: 'ER_DISPLAY_NONE' };
|
|
50
51
|
/** Maps a JSX host tag to its ERNodeType enum, for the components the generic node emitter handles. */
|
|
@@ -57,7 +58,7 @@ export const NODE_TYPES = {
|
|
|
57
58
|
ScrollView: 'ER_NODE_SCROLL_VIEW',
|
|
58
59
|
};
|
|
59
60
|
/** Numeric style keys that can be state-driven and the ERProps field each one writes. */
|
|
60
|
-
const
|
|
61
|
+
const NUMBER_FIELDS = {
|
|
61
62
|
width: 'width',
|
|
62
63
|
height: 'height',
|
|
63
64
|
minWidth: 'min_width',
|
|
@@ -93,10 +94,11 @@ const NUM_FIELDS = {
|
|
|
93
94
|
fontSize: 'font_size',
|
|
94
95
|
lineHeight: 'line_height',
|
|
95
96
|
letterSpacing: 'letter_spacing',
|
|
97
|
+
shadowOpacity: 'shadow_opacity',
|
|
96
98
|
};
|
|
97
99
|
/**
|
|
98
100
|
* Enum style keys that can be state-driven: the value (a string literal or a ternary of them) lowers to the
|
|
99
|
-
* matching ER_* constant via its table. Changing one in
|
|
101
|
+
* matching ER_* constant via its table. Changing one in an update re-runs layout (props_hash covers it).
|
|
100
102
|
*/
|
|
101
103
|
const ENUM_FIELDS = {
|
|
102
104
|
flexDirection: { field: 'flex_direction', table: FLEX_DIRECTION },
|
|
@@ -107,12 +109,12 @@ const ENUM_FIELDS = {
|
|
|
107
109
|
display: { field: 'display', table: DISPLAY },
|
|
108
110
|
};
|
|
109
111
|
/**
|
|
110
|
-
* Every style key whose value can be state-driven, with its ERProps field and how
|
|
111
|
-
* DynamicStyleField). Keys absent here (such as the `flex` shorthand, `flexBasis`, the four insets
|
|
112
|
-
* `fontWeight`) can only be static.
|
|
112
|
+
* Every style key whose value can be state-driven, with its ERProps field and how an update lowers it (see
|
|
113
|
+
* DynamicStyleField). Keys absent here (such as the `flex` shorthand, `flexBasis`, the four insets,
|
|
114
|
+
* `fontWeight` and `shadowOffset`) can only be static.
|
|
113
115
|
*/
|
|
114
116
|
export const DYN_FIELDS = {
|
|
115
|
-
...Object.fromEntries(Object.entries(
|
|
117
|
+
...Object.fromEntries(Object.entries(NUMBER_FIELDS).map(([styleKey, field]) => [
|
|
116
118
|
styleKey,
|
|
117
119
|
{ field, kind: 'num' },
|
|
118
120
|
])),
|
|
@@ -123,8 +125,19 @@ export const DYN_FIELDS = {
|
|
|
123
125
|
backgroundColor: { field: 'background_color', kind: 'color' },
|
|
124
126
|
color: { field: 'color', kind: 'color' },
|
|
125
127
|
borderColor: { field: 'border_color', kind: 'color' },
|
|
128
|
+
shadowColor: { field: 'shadow_color', kind: 'color' },
|
|
129
|
+
shadowRadius: { field: 'shadow_radius', kind: 'byte' },
|
|
130
|
+
elevation: { field: 'elevation', kind: 'byte' },
|
|
126
131
|
opacity: { field: 'opacity', kind: 'opacity' },
|
|
127
132
|
};
|
|
133
|
+
/** The engine's opacity for fully opaque, which a 0–1 opacity scales to. */
|
|
134
|
+
export const OPACITY_OPAQUE = 255;
|
|
135
|
+
/** The alpha of a color written without one. */
|
|
136
|
+
const ALPHA_OPAQUE = 0xff;
|
|
137
|
+
/** The largest value a byte field holds. */
|
|
138
|
+
const BYTE_MAX = 255;
|
|
139
|
+
/** The lightest numeric fontWeight drawn bold. */
|
|
140
|
+
const BOLD_WEIGHT = 600;
|
|
128
141
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
129
142
|
- Implementation
|
|
130
143
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -159,7 +172,7 @@ export function parseColorValue(color) {
|
|
|
159
172
|
// Split out the channels; a 6-digit color is opaque.
|
|
160
173
|
let red, green, blue, alpha;
|
|
161
174
|
if (hex.length === 6) {
|
|
162
|
-
alpha =
|
|
175
|
+
alpha = ALPHA_OPAQUE;
|
|
163
176
|
red = parseInt(hex.slice(0, 2), 16);
|
|
164
177
|
green = parseInt(hex.slice(2, 4), 16);
|
|
165
178
|
blue = parseInt(hex.slice(4, 6), 16);
|
|
@@ -174,14 +187,19 @@ export function parseColorValue(color) {
|
|
|
174
187
|
return ((alpha << 24) | (red << 16) | (green << 8) | blue) >>> 0;
|
|
175
188
|
}
|
|
176
189
|
/**
|
|
177
|
-
*
|
|
190
|
+
* A number for a float field, checked.
|
|
178
191
|
*
|
|
179
|
-
* @param
|
|
192
|
+
* @param rawValue The value; anything `Number()` converts to a finite float.
|
|
180
193
|
*
|
|
181
|
-
* @returns
|
|
194
|
+
* @returns The number.
|
|
182
195
|
*/
|
|
183
|
-
export function
|
|
184
|
-
|
|
196
|
+
export function floatConstant(rawValue) {
|
|
197
|
+
// The check pass refuses what a float cannot hold; a value that reaches here unchecked fails the same way.
|
|
198
|
+
const problem = numberProblem(rawValue);
|
|
199
|
+
if (problem) {
|
|
200
|
+
throw problem;
|
|
201
|
+
}
|
|
202
|
+
return Number(rawValue);
|
|
185
203
|
}
|
|
186
204
|
/**
|
|
187
205
|
* Looks an enum style value up in its table.
|
|
@@ -201,7 +219,7 @@ const enumKey = (table, name) => (value) => {
|
|
|
201
219
|
return constant;
|
|
202
220
|
};
|
|
203
221
|
/**
|
|
204
|
-
* A pixel dimension as
|
|
222
|
+
* A pixel dimension as a constant.
|
|
205
223
|
*
|
|
206
224
|
* @param value The style value; must be a finite number.
|
|
207
225
|
*
|
|
@@ -211,19 +229,42 @@ const dimension = (value) => {
|
|
|
211
229
|
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
212
230
|
throw new Error(`expected a numeric dimension, got ${JSON.stringify(value)}`);
|
|
213
231
|
}
|
|
214
|
-
|
|
232
|
+
// Adding 0 turns -0 into 0, whose bits a float field keeps.
|
|
233
|
+
return Math.round(value) + 0;
|
|
215
234
|
};
|
|
216
235
|
/**
|
|
217
|
-
* A
|
|
236
|
+
* A whole number for a byte field.
|
|
237
|
+
*
|
|
238
|
+
* @param value The style value; must be a finite number.
|
|
239
|
+
*
|
|
240
|
+
* @returns It with its fraction dropped, clamped to 0–255, as Flow A reads one.
|
|
241
|
+
*/
|
|
242
|
+
const byteValue = (value) => {
|
|
243
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
244
|
+
throw new Error(`expected a number, got ${JSON.stringify(value)}`);
|
|
245
|
+
}
|
|
246
|
+
// Adding 0 turns -0 into 0.
|
|
247
|
+
return Math.min(BYTE_MAX, Math.max(0, Math.trunc(value))) + 0;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* One side of a `shadowOffset`.
|
|
251
|
+
*
|
|
252
|
+
* @param offset `width` or `height`; left out, it is 0.
|
|
253
|
+
*
|
|
254
|
+
* @returns The offset in pixels.
|
|
255
|
+
*/
|
|
256
|
+
const shadowOffsetSide = (offset) => offset === undefined || offset === null ? 0 : floatConstant(offset);
|
|
257
|
+
/**
|
|
258
|
+
* A dimension that may be a percentage. `'50%'` → the engine's float `*_percent` field (% of the parent);
|
|
218
259
|
* a number → the pixel field. Used for width / height / flexBasis and the four insets, all of which the
|
|
219
260
|
* engine resolves at layout.
|
|
220
261
|
*
|
|
221
|
-
* @param
|
|
222
|
-
* @param
|
|
262
|
+
* @param pixelField ERProps pixel field (e.g. 'width').
|
|
263
|
+
* @param percentField ERProps percentage field (e.g. 'width_percent').
|
|
223
264
|
*
|
|
224
265
|
* @returns The lowering for that key.
|
|
225
266
|
*/
|
|
226
|
-
const
|
|
267
|
+
const percentOrPixels = (pixelField, percentField) => value => {
|
|
227
268
|
if (typeof value === 'string' && value.trim().endsWith('%')) {
|
|
228
269
|
const percent = parseFloat(value);
|
|
229
270
|
if (!Number.isFinite(percent)) {
|
|
@@ -231,148 +272,168 @@ const pctOrPx = (pxField, pctField) => value => {
|
|
|
231
272
|
}
|
|
232
273
|
// The engine reads a 0.0 percentage as "not set", so lower 0% to the pixel field, where 0 means the same.
|
|
233
274
|
if (percent === 0)
|
|
234
|
-
return [{ field:
|
|
235
|
-
|
|
236
|
-
const floatLiteral = Number.isInteger(percent)
|
|
237
|
-
? `${percent}.0f`
|
|
238
|
-
: `${percent}f`;
|
|
239
|
-
return [{ field: pctField, expr: floatLiteral }];
|
|
275
|
+
return [{ field: pixelField, value: 0 }];
|
|
276
|
+
return [{ field: percentField, value: percent }];
|
|
240
277
|
}
|
|
241
|
-
return [{ field:
|
|
278
|
+
return [{ field: pixelField, value: dimension(value) }];
|
|
242
279
|
};
|
|
243
280
|
/**
|
|
244
|
-
* Per-style-key lowering. Each entry maps a style value to one or more { field,
|
|
245
|
-
* (field = ERProps
|
|
281
|
+
* Per-style-key lowering. Each entry maps a style value to one or more { field, value } ERProps writes
|
|
282
|
+
* (field = ERProps member, value = the constant). `flex` expands to several fields.
|
|
246
283
|
*/
|
|
247
284
|
const KEYS = {
|
|
248
285
|
// Layout
|
|
249
|
-
width:
|
|
250
|
-
height:
|
|
251
|
-
flexBasis:
|
|
252
|
-
minWidth: width => [{ field: 'min_width',
|
|
253
|
-
maxWidth: width => [{ field: 'max_width',
|
|
254
|
-
minHeight: height => [{ field: 'min_height',
|
|
255
|
-
maxHeight: height => [{ field: 'max_height',
|
|
256
|
-
padding: padding => [{ field: 'padding',
|
|
286
|
+
width: percentOrPixels('width', 'width_percent'),
|
|
287
|
+
height: percentOrPixels('height', 'height_percent'),
|
|
288
|
+
flexBasis: percentOrPixels('flex_basis', 'flex_basis_percent'),
|
|
289
|
+
minWidth: width => [{ field: 'min_width', value: dimension(width) }],
|
|
290
|
+
maxWidth: width => [{ field: 'max_width', value: dimension(width) }],
|
|
291
|
+
minHeight: height => [{ field: 'min_height', value: dimension(height) }],
|
|
292
|
+
maxHeight: height => [{ field: 'max_height', value: dimension(height) }],
|
|
293
|
+
padding: padding => [{ field: 'padding', value: dimension(padding) }],
|
|
257
294
|
paddingHorizontal: padding => [
|
|
258
|
-
{ field: 'padding_horizontal',
|
|
295
|
+
{ field: 'padding_horizontal', value: dimension(padding) },
|
|
259
296
|
],
|
|
260
297
|
paddingVertical: padding => [
|
|
261
|
-
{ field: 'padding_vertical',
|
|
298
|
+
{ field: 'padding_vertical', value: dimension(padding) },
|
|
299
|
+
],
|
|
300
|
+
paddingLeft: padding => [{ field: 'padding_left', value: dimension(padding) }],
|
|
301
|
+
paddingTop: padding => [{ field: 'padding_top', value: dimension(padding) }],
|
|
302
|
+
paddingRight: padding => [
|
|
303
|
+
{ field: 'padding_right', value: dimension(padding) },
|
|
262
304
|
],
|
|
263
|
-
paddingLeft: padding => [{ field: 'padding_left', expr: dimension(padding) }],
|
|
264
|
-
paddingTop: padding => [{ field: 'padding_top', expr: dimension(padding) }],
|
|
265
|
-
paddingRight: padding => [{ field: 'padding_right', expr: dimension(padding) }],
|
|
266
305
|
paddingBottom: padding => [
|
|
267
|
-
{ field: 'padding_bottom',
|
|
306
|
+
{ field: 'padding_bottom', value: dimension(padding) },
|
|
268
307
|
],
|
|
269
|
-
margin: margin => [{ field: 'margin',
|
|
308
|
+
margin: margin => [{ field: 'margin', value: dimension(margin) }],
|
|
270
309
|
marginHorizontal: margin => [
|
|
271
|
-
{ field: 'margin_horizontal',
|
|
310
|
+
{ field: 'margin_horizontal', value: dimension(margin) },
|
|
272
311
|
],
|
|
273
312
|
marginVertical: margin => [
|
|
274
|
-
{ field: 'margin_vertical',
|
|
313
|
+
{ field: 'margin_vertical', value: dimension(margin) },
|
|
275
314
|
],
|
|
276
|
-
marginLeft: margin => [{ field: 'margin_left',
|
|
277
|
-
marginTop: margin => [{ field: 'margin_top',
|
|
278
|
-
marginRight: margin => [{ field: 'margin_right',
|
|
279
|
-
marginBottom: margin => [{ field: 'margin_bottom',
|
|
280
|
-
gap: gap => [{ field: 'gap',
|
|
281
|
-
rowGap: gap => [{ field: 'row_gap',
|
|
282
|
-
columnGap: gap => [{ field: 'column_gap',
|
|
283
|
-
flexGrow: grow => [{ field: 'flex_grow',
|
|
284
|
-
flexShrink: shrink => [{ field: 'flex_shrink',
|
|
315
|
+
marginLeft: margin => [{ field: 'margin_left', value: dimension(margin) }],
|
|
316
|
+
marginTop: margin => [{ field: 'margin_top', value: dimension(margin) }],
|
|
317
|
+
marginRight: margin => [{ field: 'margin_right', value: dimension(margin) }],
|
|
318
|
+
marginBottom: margin => [{ field: 'margin_bottom', value: dimension(margin) }],
|
|
319
|
+
gap: gap => [{ field: 'gap', value: dimension(gap) }],
|
|
320
|
+
rowGap: gap => [{ field: 'row_gap', value: dimension(gap) }],
|
|
321
|
+
columnGap: gap => [{ field: 'column_gap', value: dimension(gap) }],
|
|
322
|
+
flexGrow: grow => [{ field: 'flex_grow', value: dimension(grow) }],
|
|
323
|
+
flexShrink: shrink => [{ field: 'flex_shrink', value: dimension(shrink) }],
|
|
285
324
|
flexDirection: direction => [
|
|
286
325
|
{
|
|
287
326
|
field: 'flex_direction',
|
|
288
|
-
|
|
327
|
+
value: enumKey(FLEX_DIRECTION, 'flexDirection')(direction),
|
|
289
328
|
},
|
|
290
329
|
],
|
|
291
330
|
alignItems: alignment => [
|
|
292
|
-
{ field: 'align_items',
|
|
331
|
+
{ field: 'align_items', value: enumKey(ALIGN, 'alignItems')(alignment) },
|
|
293
332
|
],
|
|
294
333
|
alignSelf: alignment => [
|
|
295
|
-
{ field: 'align_self',
|
|
334
|
+
{ field: 'align_self', value: enumKey(ALIGN, 'alignSelf')(alignment) },
|
|
296
335
|
],
|
|
297
336
|
justifyContent: justification => [
|
|
298
337
|
{
|
|
299
338
|
field: 'justify_content',
|
|
300
|
-
|
|
339
|
+
value: enumKey(JUSTIFY, 'justifyContent')(justification),
|
|
301
340
|
},
|
|
302
341
|
],
|
|
303
342
|
// Positioning: `position: 'absolute'` takes a node out of flow; left/top/right/bottom are its anchors.
|
|
304
343
|
position: position => [
|
|
305
|
-
{ field: 'position',
|
|
344
|
+
{ field: 'position', value: enumKey(POSITION, 'position')(position) },
|
|
306
345
|
],
|
|
307
346
|
display: display => [
|
|
308
|
-
{ field: 'display',
|
|
347
|
+
{ field: 'display', value: enumKey(DISPLAY, 'display')(display) },
|
|
309
348
|
],
|
|
310
|
-
left:
|
|
311
|
-
top:
|
|
312
|
-
right:
|
|
313
|
-
bottom:
|
|
349
|
+
left: percentOrPixels('left', 'left_percent'),
|
|
350
|
+
top: percentOrPixels('top', 'top_percent'),
|
|
351
|
+
right: percentOrPixels('right', 'right_percent'),
|
|
352
|
+
bottom: percentOrPixels('bottom', 'bottom_percent'),
|
|
314
353
|
// `flex: n` → grow=n, shrink=1, basis=0 (RN semantics; matches native_ui_bridge apply_flex).
|
|
315
354
|
flex: flexValue => {
|
|
316
355
|
const factor = Number(flexValue);
|
|
317
356
|
if (factor > 0) {
|
|
318
357
|
return [
|
|
319
|
-
{ field: 'flex_grow',
|
|
320
|
-
{ field: 'flex_shrink',
|
|
321
|
-
{ field: 'flex_basis',
|
|
358
|
+
{ field: 'flex_grow', value: dimension(factor) },
|
|
359
|
+
{ field: 'flex_shrink', value: 1 },
|
|
360
|
+
{ field: 'flex_basis', value: 0 },
|
|
322
361
|
];
|
|
323
362
|
}
|
|
324
363
|
if (factor === 0) {
|
|
325
364
|
return [
|
|
326
|
-
{ field: 'flex_grow',
|
|
327
|
-
{ field: 'flex_shrink',
|
|
365
|
+
{ field: 'flex_grow', value: 0 },
|
|
366
|
+
{ field: 'flex_shrink', value: 0 },
|
|
328
367
|
];
|
|
329
368
|
}
|
|
330
369
|
return [
|
|
331
|
-
{ field: 'flex_grow',
|
|
332
|
-
{ field: 'flex_shrink',
|
|
370
|
+
{ field: 'flex_grow', value: 0 },
|
|
371
|
+
{ field: 'flex_shrink', value: 1 },
|
|
333
372
|
];
|
|
334
373
|
},
|
|
335
374
|
// View visual
|
|
336
375
|
backgroundColor: color => [
|
|
337
|
-
{ field: 'background_color',
|
|
376
|
+
{ field: 'background_color', value: parseColorValue(color) },
|
|
338
377
|
],
|
|
339
|
-
borderRadius: radius => [{ field: 'border_radius',
|
|
378
|
+
borderRadius: radius => [{ field: 'border_radius', value: dimension(radius) }],
|
|
340
379
|
// Per-corner radii; the engine reads 0 in one of these as "use borderRadius" (same as Flow A).
|
|
341
380
|
borderTopLeftRadius: radius => [
|
|
342
|
-
{ field: 'border_top_left_radius',
|
|
381
|
+
{ field: 'border_top_left_radius', value: dimension(radius) },
|
|
343
382
|
],
|
|
344
383
|
borderTopRightRadius: radius => [
|
|
345
|
-
{ field: 'border_top_right_radius',
|
|
384
|
+
{ field: 'border_top_right_radius', value: dimension(radius) },
|
|
346
385
|
],
|
|
347
386
|
borderBottomRightRadius: radius => [
|
|
348
|
-
{ field: 'border_bottom_right_radius',
|
|
387
|
+
{ field: 'border_bottom_right_radius', value: dimension(radius) },
|
|
349
388
|
],
|
|
350
389
|
borderBottomLeftRadius: radius => [
|
|
351
|
-
{ field: 'border_bottom_left_radius',
|
|
390
|
+
{ field: 'border_bottom_left_radius', value: dimension(radius) },
|
|
391
|
+
],
|
|
392
|
+
borderWidth: width => [{ field: 'border_width', value: dimension(width) }],
|
|
393
|
+
borderColor: color => [
|
|
394
|
+
{ field: 'border_color', value: parseColorValue(color) },
|
|
352
395
|
],
|
|
353
|
-
borderWidth: width => [{ field: 'border_width', expr: dimension(width) }],
|
|
354
|
-
borderColor: color => [{ field: 'border_color', expr: colorLiteral(color) }],
|
|
355
396
|
opacity: opacity => [
|
|
356
397
|
{
|
|
357
398
|
field: 'opacity',
|
|
358
|
-
|
|
399
|
+
value: Math.round(Math.max(0, Math.min(1, Number(opacity))) * OPACITY_OPAQUE),
|
|
359
400
|
},
|
|
360
401
|
],
|
|
361
|
-
zIndex: zIndex => [{ field: 'z_index',
|
|
402
|
+
zIndex: zIndex => [{ field: 'z_index', value: dimension(zIndex) }],
|
|
403
|
+
// Shadow, drawn only by a firmware built with ERUI_SHADOWS (same as Flow A).
|
|
404
|
+
shadowColor: color => [
|
|
405
|
+
{ field: 'shadow_color', value: parseColorValue(color) },
|
|
406
|
+
],
|
|
407
|
+
// Both sides are written, so a later shadowOffset replaces an earlier one whole, as in RN.
|
|
408
|
+
shadowOffset: offset => {
|
|
409
|
+
if (typeof offset !== 'object' || Array.isArray(offset)) {
|
|
410
|
+
throw new Error(`expected {width, height}, got ${JSON.stringify(offset)}`);
|
|
411
|
+
}
|
|
412
|
+
const { width, height } = offset;
|
|
413
|
+
return [
|
|
414
|
+
{ field: 'shadow_offset_x', value: shadowOffsetSide(width) },
|
|
415
|
+
{ field: 'shadow_offset_y', value: shadowOffsetSide(height) },
|
|
416
|
+
];
|
|
417
|
+
},
|
|
418
|
+
shadowOpacity: opacity => [
|
|
419
|
+
{ field: 'shadow_opacity', value: floatConstant(opacity) },
|
|
420
|
+
],
|
|
421
|
+
shadowRadius: radius => [{ field: 'shadow_radius', value: byteValue(radius) }],
|
|
422
|
+
elevation: elevation => [{ field: 'elevation', value: byteValue(elevation) }],
|
|
362
423
|
// Text
|
|
363
|
-
color: color => [{ field: 'color',
|
|
364
|
-
fontSize: size => [{ field: 'font_size',
|
|
424
|
+
color: color => [{ field: 'color', value: parseColorValue(color) }],
|
|
425
|
+
fontSize: size => [{ field: 'font_size', value: dimension(size) }],
|
|
365
426
|
fontWeight: weight => [
|
|
366
427
|
{
|
|
367
428
|
field: 'font_weight',
|
|
368
|
-
|
|
429
|
+
value: weight === 'bold' || Number(weight) >= BOLD_WEIGHT ? 1 : 0,
|
|
369
430
|
},
|
|
370
431
|
],
|
|
371
432
|
lineHeight: lineHeight => [
|
|
372
|
-
{ field: 'line_height',
|
|
433
|
+
{ field: 'line_height', value: dimension(lineHeight) },
|
|
373
434
|
],
|
|
374
435
|
letterSpacing: spacing => [
|
|
375
|
-
{ field: 'letter_spacing',
|
|
436
|
+
{ field: 'letter_spacing', value: dimension(spacing) },
|
|
376
437
|
],
|
|
377
438
|
};
|
|
378
439
|
/**
|
|
@@ -387,9 +448,8 @@ export const isStyleKey = (key) => Object.hasOwn(KEYS, key);
|
|
|
387
448
|
export const STYLE_KEYS = Object.keys(KEYS);
|
|
388
449
|
/**
|
|
389
450
|
* Lowers one flattened style object to a list of ERProps field assignments. This is the build-time mirror
|
|
390
|
-
* of what native_ui_bridge.c does at runtime in Flow A: the
|
|
391
|
-
*
|
|
392
|
-
* (er_props_default), so both render the same pixels. An unsupported key throws, so the compiler fails
|
|
451
|
+
* of what native_ui_bridge.c does at runtime in Flow A: the package builds the same prop bags as Flow A,
|
|
452
|
+
* from the same defaults (er_props_default), so both render the same pixels. An unsupported key throws, so the compiler fails
|
|
393
453
|
* loudly instead of silently dropping a style.
|
|
394
454
|
*
|
|
395
455
|
* @param style Flattened style (plain key→value; values already statically resolved).
|