embedded-react 0.17.0 → 0.18.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/aot/compiler/animations.mjs +102 -34
- package/aot/compiler/assemble.mjs +27 -5
- package/aot/compiler/branch-merge.mjs +5 -9
- package/aot/compiler/c/animations.mjs +90 -16
- package/aot/compiler/c/nodes.mjs +20 -11
- package/aot/compiler/c/statements.mjs +59 -11
- package/aot/compiler/check.mjs +32 -3
- package/aot/compiler/collect.mjs +46 -2
- package/aot/compiler/control-flow.mjs +26 -14
- package/aot/compiler/diagnostics.mjs +33 -0
- package/aot/compiler/elements/dial.mjs +1 -3
- package/aot/compiler/elements/props.mjs +19 -9
- package/aot/compiler/elements/text-input.mjs +7 -2
- package/aot/compiler/expressions.mjs +29 -7
- package/aot/compiler/handlers.mjs +62 -24
- package/aot/compiler/keyboard.mjs +35 -21
- package/aot/compiler/lower.mjs +3 -3
- package/aot/compiler/nodes.mjs +16 -8
- package/aot/compiler/options.mjs +63 -12
- package/aot/compiler/static-eval.mjs +36 -4
- package/aot/compiler/style-text.mjs +35 -12
- package/aot/compiler/svg.mjs +7 -3
- package/aot/style-map.mjs +9 -11
- package/assets/bake-svg.mjs +3 -2
- package/package.json +1 -1
- package/sim/embedded-react.wasm +0 -0
- package/src/embedded-react/Animated.js +41 -0
- package/src/embedded-react/Button.js +3 -4
- package/src/embedded-react/Pressable.js +59 -0
- package/src/embedded-react/TouchableOpacity.js +6 -9
- package/src/embedded-react/index.d.ts +118 -30
- package/src/embedded-react/index.js +1 -1
- package/src/embedded-react/named-colors.js +37 -0
- package/src/embedded-react/svg-ops.js +13 -16
- package/src/host-config.js +50 -8
|
@@ -23,9 +23,12 @@ import { INT_MAX, lowerExpr } from './expressions.mjs';
|
|
|
23
23
|
import { NO_WIDE, isFn, wideInitial } from './collect.mjs';
|
|
24
24
|
import { lowerStmts } from './handlers.mjs';
|
|
25
25
|
import { isPanCreate } from './pan-responder.mjs';
|
|
26
|
+
import { parseColorValue } from '../style-map.mjs';
|
|
26
27
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
27
28
|
- Constants
|
|
28
29
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
30
|
+
/** The style keys an animated value drives only through an interpolation onto colors. */
|
|
31
|
+
export const ANIM_COLOR_KEYS = new Set(['backgroundColor', 'color']);
|
|
29
32
|
/** Style key → the ERAnimProp(s) an animated value binds to. */
|
|
30
33
|
export const ANIM_STYLE_PROPS = {
|
|
31
34
|
opacity: ['ER_PROP_OPACITY'],
|
|
@@ -275,17 +278,33 @@ export function parseInterp(cfgNode, env) {
|
|
|
275
278
|
// Read a named property from the interpolation config, accepting both identifier and string-literal keys.
|
|
276
279
|
const get = (key) => cfgNode.properties.find(property => (property.key.name ??
|
|
277
280
|
property.key.value) === key)?.value;
|
|
278
|
-
// Fold an interpolation range into
|
|
281
|
+
// Fold an interpolation range into its breakpoints; ranges must be array literals for AOT emission.
|
|
279
282
|
const arr = (node, name) => {
|
|
280
283
|
if (node?.type !== 'ArrayExpression') {
|
|
281
284
|
throw aotError(`AOT: .interpolate() ${name} must be an array literal`);
|
|
282
285
|
}
|
|
283
|
-
return node.elements.map(e =>
|
|
286
|
+
return node.elements.map(e => evalStatic(e, env.consts ?? {}));
|
|
284
287
|
};
|
|
285
|
-
// inputRange and outputRange define the piecewise mapping and must line up point-for-point.
|
|
286
|
-
|
|
287
|
-
const
|
|
288
|
-
|
|
288
|
+
// inputRange and outputRange define the piecewise mapping and must line up point-for-point. An
|
|
289
|
+
// outputRange of strings maps onto colors.
|
|
290
|
+
const input = arr(get('inputRange'), 'inputRange').map(Number);
|
|
291
|
+
const outputValues = arr(get('outputRange'), 'outputRange');
|
|
292
|
+
// Colors parse as strictly as a static style color, so a typo is an error rather than black.
|
|
293
|
+
const colors = outputValues.every(v => typeof v === 'string')
|
|
294
|
+
? outputValues.map(v => {
|
|
295
|
+
try {
|
|
296
|
+
return parseColorValue(v);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
throw aotError(`AOT: .interpolate() outputRange has an ${error.message}`);
|
|
300
|
+
}
|
|
301
|
+
})
|
|
302
|
+
: undefined;
|
|
303
|
+
if (!colors && outputValues.some(v => typeof v !== 'number')) {
|
|
304
|
+
throw aotError('AOT: .interpolate() outputRange must be all numbers or all colors');
|
|
305
|
+
}
|
|
306
|
+
const output = colors ? [] : outputValues;
|
|
307
|
+
if (input.length < 2 || input.length !== outputValues.length) {
|
|
289
308
|
throw aotError('AOT: .interpolate() inputRange and outputRange must be the same length (>= 2)');
|
|
290
309
|
}
|
|
291
310
|
check({ kind: 'interpolationPoints', count: input.length });
|
|
@@ -305,6 +324,7 @@ export function parseInterp(cfgNode, env) {
|
|
|
305
324
|
return {
|
|
306
325
|
input,
|
|
307
326
|
output,
|
|
327
|
+
...(colors && { colors }),
|
|
308
328
|
exLeft: ex(get('extrapolateLeft') ?? both),
|
|
309
329
|
exRight: ex(get('extrapolateRight') ?? both),
|
|
310
330
|
};
|
|
@@ -332,6 +352,51 @@ function configFloat(rawValue) {
|
|
|
332
352
|
checkNumber(rawValue);
|
|
333
353
|
return Number(rawValue);
|
|
334
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* A folded config time in whole milliseconds, checked so a time C cannot hold is reported at the field.
|
|
357
|
+
*
|
|
358
|
+
* @param node The field's value, if the app wrote one.
|
|
359
|
+
* @param env The expression environment.
|
|
360
|
+
* @param defaultValue The time when the field is left out or not known at build time.
|
|
361
|
+
* @param field What the time is, for the error.
|
|
362
|
+
*
|
|
363
|
+
* @returns The time.
|
|
364
|
+
*/
|
|
365
|
+
function configMs(node, env, defaultValue, field) {
|
|
366
|
+
const rawValue = evalStaticOr(node, env, defaultValue);
|
|
367
|
+
check({ kind: 'milliseconds', field, value: rawValue }, node?.loc?.start);
|
|
368
|
+
return Math.round(Number(rawValue));
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* A timing's folded duration (250 ms when it is left out, as in React Native).
|
|
372
|
+
*
|
|
373
|
+
* @param get The timing's config.
|
|
374
|
+
* @param env The expression environment.
|
|
375
|
+
*
|
|
376
|
+
* @returns The duration.
|
|
377
|
+
*/
|
|
378
|
+
const timingDuration = (get, env) => configMs(get('duration'), env, 250, `Animated.timing's "duration"`);
|
|
379
|
+
/**
|
|
380
|
+
* An animation's own delay (0 when it is left out).
|
|
381
|
+
*
|
|
382
|
+
* @param kind timing, spring or decay.
|
|
383
|
+
* @param get The animation's config.
|
|
384
|
+
* @param env The expression environment.
|
|
385
|
+
*
|
|
386
|
+
* @returns The delay.
|
|
387
|
+
*/
|
|
388
|
+
const ownDelayMs = (kind, get, env) => configMs(get('delay'), env, 0, `Animated.${kind}'s "delay"`);
|
|
389
|
+
/**
|
|
390
|
+
* A time added up from a composition's times, checked like them: each fits an int, but a sum of them need not.
|
|
391
|
+
*
|
|
392
|
+
* @param value The sum.
|
|
393
|
+
*
|
|
394
|
+
* @returns The sum.
|
|
395
|
+
*/
|
|
396
|
+
function totalMs(value) {
|
|
397
|
+
check({ kind: 'milliseconds', field: "this animation's total time", value });
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
335
400
|
/**
|
|
336
401
|
* Lowers one atomic animation (timing/spring/decay). `delayMs` is the absolute start delay (how composition
|
|
337
402
|
* offsets are realized) and `loop` repeats a timing on the engine's own loop.
|
|
@@ -361,7 +426,7 @@ function lowerAnimation(entry, env) {
|
|
|
361
426
|
};
|
|
362
427
|
}
|
|
363
428
|
else {
|
|
364
|
-
const durationMs =
|
|
429
|
+
const durationMs = timingDuration(get, env);
|
|
365
430
|
const { ease, bezier } = easingInfo(get('easing'), env);
|
|
366
431
|
curve = {
|
|
367
432
|
kind: 'timing',
|
|
@@ -379,7 +444,7 @@ function lowerAnimation(entry, env) {
|
|
|
379
444
|
handle: cVar,
|
|
380
445
|
curve,
|
|
381
446
|
to: toNode ? lowerExpr(toNode, env) : null,
|
|
382
|
-
delayMs,
|
|
447
|
+
delayMs: totalMs(delayMs),
|
|
383
448
|
isLooping: loop,
|
|
384
449
|
};
|
|
385
450
|
}
|
|
@@ -413,10 +478,8 @@ function flattenAnim(node, env, baseDelay, loop) {
|
|
|
413
478
|
}
|
|
414
479
|
const cVar = env.animations.get(valRef.name).cVar;
|
|
415
480
|
const get = animConfigGetter(args[1]);
|
|
416
|
-
const ownDelay =
|
|
417
|
-
const duration = kind === 'timing'
|
|
418
|
-
? ownDelay + Math.round(Number(evalStaticOr(get('duration'), env, 250)))
|
|
419
|
-
: null;
|
|
481
|
+
const ownDelay = ownDelayMs(kind, get, env);
|
|
482
|
+
const duration = kind === 'timing' ? ownDelay + timingDuration(get, env) : null;
|
|
420
483
|
return {
|
|
421
484
|
entries: [{ cVar, kind, get, delayMs: baseDelay + ownDelay, loop }],
|
|
422
485
|
duration,
|
|
@@ -426,14 +489,14 @@ function flattenAnim(node, env, baseDelay, loop) {
|
|
|
426
489
|
if (kind === 'delay') {
|
|
427
490
|
return {
|
|
428
491
|
entries: [],
|
|
429
|
-
duration:
|
|
492
|
+
duration: configMs(args[0], env, 0, "Animated.delay's time"),
|
|
430
493
|
};
|
|
431
494
|
}
|
|
432
495
|
// Composition nodes flatten into atomic animations with absolute delay_ms offsets.
|
|
433
496
|
if (kind === 'sequence' || kind === 'parallel' || kind === 'stagger') {
|
|
434
497
|
const list = kind === 'stagger' ? args[1] : args[0];
|
|
435
498
|
const staggerMs = kind === 'stagger'
|
|
436
|
-
?
|
|
499
|
+
? configMs(args[0], env, 0, "Animated.stagger's interval")
|
|
437
500
|
: 0;
|
|
438
501
|
if (list?.type !== 'ArrayExpression') {
|
|
439
502
|
throw aotError(`AOT: Animated.${kind}(...) needs an array of animations`);
|
|
@@ -528,7 +591,7 @@ function animStep(node, env, extraDelay) {
|
|
|
528
591
|
}
|
|
529
592
|
// Fold this step's own delay and add any delay inherited from an enclosing sequence/delay.
|
|
530
593
|
const get = animConfigGetter(node.arguments[1]);
|
|
531
|
-
const ownDelay =
|
|
594
|
+
const ownDelay = ownDelayMs(kind, get, env);
|
|
532
595
|
return {
|
|
533
596
|
cVar: env.animations.get(valRef.name).cVar,
|
|
534
597
|
kind,
|
|
@@ -601,7 +664,7 @@ function sequenceSteps(seqNode, env) {
|
|
|
601
664
|
// Fold delay-only entries into the following animation step.
|
|
602
665
|
const kind = child.callee.property.name;
|
|
603
666
|
if (kind === 'delay') {
|
|
604
|
-
pendingDelay +=
|
|
667
|
+
pendingDelay += configMs(child.arguments[0], env, 0, "Animated.delay's time");
|
|
605
668
|
continue;
|
|
606
669
|
}
|
|
607
670
|
// Keep sequence chains flat: delay plus timing/spring/decay only.
|
|
@@ -653,7 +716,7 @@ function lowerChain(steps, env, ctx, completion, loop = null, trailing = null) {
|
|
|
653
716
|
restart: lowerAnimation({ ...steps[0], delayMs: steps[0].delayMs + loop.trailingDelay }, env),
|
|
654
717
|
finalWait: loop.iterations >= 0 && completion && loop.trailingDelay > 0
|
|
655
718
|
? {
|
|
656
|
-
delayMs: loop.trailingDelay,
|
|
719
|
+
delayMs: totalMs(loop.trailingDelay),
|
|
657
720
|
owner: waitOwner(ctx, loop.key, true),
|
|
658
721
|
}
|
|
659
722
|
: null,
|
|
@@ -682,6 +745,7 @@ const emptyStart = (ctx, completion) => ({
|
|
|
682
745
|
firstConfig: ctx.animIdx,
|
|
683
746
|
completion,
|
|
684
747
|
completionWait: null,
|
|
748
|
+
completionJoin: null,
|
|
685
749
|
});
|
|
686
750
|
/** Numbers each composition node once, so a key names the place it is written. */
|
|
687
751
|
const compositionIds = new WeakMap();
|
|
@@ -776,7 +840,11 @@ export function stopWaitOwner(node, env, ctx) {
|
|
|
776
840
|
*
|
|
777
841
|
* @returns The wait.
|
|
778
842
|
*/
|
|
779
|
-
const completionWait = (ctx, key, delayMs, callback) => ({
|
|
843
|
+
const completionWait = (ctx, key, delayMs, callback) => ({
|
|
844
|
+
delayMs: totalMs(delayMs),
|
|
845
|
+
callback,
|
|
846
|
+
owner: waitOwner(ctx, key, true),
|
|
847
|
+
});
|
|
780
848
|
/**
|
|
781
849
|
* A start that drives no value. As in JS, its completion still runs as finished once the composition's delays
|
|
782
850
|
* have passed, counted down in a completion wait of its own.
|
|
@@ -795,7 +863,7 @@ function startNothing(ctx, completion, delayMs, key) {
|
|
|
795
863
|
const start = {
|
|
796
864
|
kind: 'completeAfter',
|
|
797
865
|
completion,
|
|
798
|
-
delayMs,
|
|
866
|
+
delayMs: totalMs(delayMs),
|
|
799
867
|
owner: null,
|
|
800
868
|
};
|
|
801
869
|
if (delayMs > 0) {
|
|
@@ -863,13 +931,13 @@ function lowerLoopStart(loopNode, env, ctx, completion, key) {
|
|
|
863
931
|
if (!steps.length) {
|
|
864
932
|
return iterations < 0
|
|
865
933
|
? emptyStart(ctx, completion)
|
|
866
|
-
: startNothing(ctx, completion,
|
|
934
|
+
: startNothing(ctx, completion, iterations * trailingDelay, key);
|
|
867
935
|
}
|
|
868
936
|
// A timing with no duration and no delay completes inside er_anim_value_animate, so a loop made only of
|
|
869
937
|
// those would restart itself forever without returning.
|
|
870
938
|
const instant = (animEntry) => animEntry.kind === 'timing' &&
|
|
871
939
|
animEntry.delayMs === 0 &&
|
|
872
|
-
|
|
940
|
+
timingDuration(animEntry.get, env) === 0;
|
|
873
941
|
if (trailingDelay === 0 && steps.every(instant)) {
|
|
874
942
|
throw aotError('AOT: every step of this Animated.loop finishes instantly, so it would never stop repeating', 'give a step a duration or a delay.');
|
|
875
943
|
}
|
|
@@ -967,27 +1035,27 @@ export function lowerAnimateStart(expr, env, state, ctx) {
|
|
|
967
1035
|
if (completion && entries.length > 1) {
|
|
968
1036
|
throw aotError('AOT: a .start(onComplete) callback on a parallel/stagger animation is not yet supported', 'attach the completion callback to a single animation or an Animated.sequence(...). For "after all parallel anims", restructure as a sequence.');
|
|
969
1037
|
}
|
|
970
|
-
//
|
|
1038
|
+
// Each entry starts on its own, numbered after the configs already in this body.
|
|
1039
|
+
const start = emptyStart(ctx, completion);
|
|
1040
|
+
for (const animEntry of entries) {
|
|
1041
|
+
start.animations.push(lowerAnimation(animEntry, env));
|
|
1042
|
+
ctx.animIdx++;
|
|
1043
|
+
}
|
|
1044
|
+
// A spring or decay has no fixed end, so a delay beside it that runs past its start is joined at run time.
|
|
971
1045
|
const [only] = entries;
|
|
972
1046
|
if (completion &&
|
|
973
|
-
only &&
|
|
974
1047
|
only.kind !== 'timing' &&
|
|
975
1048
|
!only.loop &&
|
|
976
1049
|
duration != null &&
|
|
977
1050
|
duration > only.delayMs) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
const start = emptyStart(ctx, completion);
|
|
983
|
-
for (const animEntry of entries) {
|
|
984
|
-
start.animations.push(lowerAnimation(animEntry, env));
|
|
985
|
-
ctx.animIdx++;
|
|
1051
|
+
start.completionJoin = {
|
|
1052
|
+
delayMs: totalMs(duration),
|
|
1053
|
+
owner: waitOwner(ctx, key, true),
|
|
1054
|
+
};
|
|
986
1055
|
}
|
|
987
1056
|
// A delay beside the one timing that outlasts it holds the completion back until the composition ends.
|
|
988
|
-
if (completion && only
|
|
989
|
-
const end = only.delayMs +
|
|
990
|
-
Math.round(Number(evalStaticOr(only.get('duration'), env, 250)));
|
|
1057
|
+
if (completion && only.kind === 'timing' && !only.loop && duration != null) {
|
|
1058
|
+
const end = only.delayMs + timingDuration(only.get, env);
|
|
991
1059
|
if (duration > end) {
|
|
992
1060
|
start.completionWait = completionWait(ctx, key, duration - end, `er_waitcb_${ctx.out.seqN++}`);
|
|
993
1061
|
ctx.out.animCbs.push({
|
|
@@ -25,7 +25,7 @@ import { printAnimationCallback, printDepEffectCheck, printEffectFunction, print
|
|
|
25
25
|
import { printKeyboard } from './c/keyboard.mjs';
|
|
26
26
|
import { printElementTree, printNode, printNodeUpdate } from './c/nodes.mjs';
|
|
27
27
|
import { printPanDecls, printPanQuery } from './c/pan-responder.mjs';
|
|
28
|
-
import { CHANGED_FLAGS, printChangedFlag } from './c/statements.mjs';
|
|
28
|
+
import { APP_LIMIT_DEFINITION, CHANGED_FLAGS, printChangedFlag, } from './c/statements.mjs';
|
|
29
29
|
import { printVectorBlocks, printVectorRebuild } from './c/vectors.mjs';
|
|
30
30
|
import { isStateDriven, nodesOf, stateDrivenVectorOf, updatedVectorOf, } from './ir/nodes.mjs';
|
|
31
31
|
import { nodeReads, vectorReads } from './ir/reads.mjs';
|
|
@@ -291,7 +291,8 @@ static int er_timer_add(int ms, bool repeat, void (*fn)(void))
|
|
|
291
291
|
return (s_timers[i].gen * ER_AOT_MAX_TIMERS) + i;
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
|
|
294
|
+
APP_LIMIT("timer table full, raise ER_AOT_MAX_TIMERS");
|
|
295
|
+
return -1;
|
|
295
296
|
}`
|
|
296
297
|
: '';
|
|
297
298
|
const timerFnDefs = timerFns
|
|
@@ -749,6 +750,25 @@ static int16_t app_round_dim(double v)
|
|
|
749
750
|
'#ifndef M_PI\n#define M_PI 3.14159265358979323846\n#endif\n'
|
|
750
751
|
: '';
|
|
751
752
|
const limitsInclude = usesLimits ? '#include <limits.h>\n' : '';
|
|
753
|
+
// The root and every node in the tree, all created by er_app_build().
|
|
754
|
+
const totalNodes = out.nodeCount + 1;
|
|
755
|
+
const limitBlock = `/* er_app_build() creates every node the app has, so a pool too small for the tree fails here, not on the
|
|
756
|
+
device. ERUI_MAX_NODES comes from er_scene.h, as the engine was configured or its default. */
|
|
757
|
+
_Static_assert(ERUI_MAX_NODES >= ${totalNodes}, "this app builds ${totalNodes} nodes: raise ERUI_MAX_NODES to at least ${totalNodes}");
|
|
758
|
+
|
|
759
|
+
${APP_LIMIT_DEFINITION}
|
|
760
|
+
/* er_node_create, reporting a full pool: the engine skips a NULL node, so the app would run with part of
|
|
761
|
+
its tree missing. */
|
|
762
|
+
static ERNode* app_node_create(ERNodeType type)
|
|
763
|
+
{
|
|
764
|
+
ERNode* node = er_node_create(type);
|
|
765
|
+
if (!node)
|
|
766
|
+
{
|
|
767
|
+
APP_LIMIT("node pool full, raise ERUI_MAX_NODES");
|
|
768
|
+
}
|
|
769
|
+
return node;
|
|
770
|
+
}
|
|
771
|
+
`;
|
|
752
772
|
// A blank line sets off each non-empty block before and after.
|
|
753
773
|
const spaced = (block) => (block ? '\n' + block + '\n' : '');
|
|
754
774
|
const keyboard = app.keyboard ? printKeyboard(app.keyboard) : null;
|
|
@@ -819,7 +839,8 @@ static int16_t app_round_dim(double v)
|
|
|
819
839
|
#include <string.h>
|
|
820
840
|
|
|
821
841
|
/* Every string this file writes goes into a FIXED-SIZE slot (a state buffer, ERProps.text), so an
|
|
822
|
-
over-long value is truncated by design — the app cannot grow the buffer the way JS grows a string
|
|
842
|
+
over-long value is truncated by design — the app cannot grow the buffer the way JS grows a string, and
|
|
843
|
+
a cut app string is reported through APP_LIMIT.
|
|
823
844
|
GCC's -Wformat-truncation reports exactly that intent for any format combining %s with anything else,
|
|
824
845
|
and ESP-IDF compiles with -Werror, so leaving it on would fail the build for ordinary text like
|
|
825
846
|
{'n=' + name}. Clang does not implement the warning; the guard keeps its "unknown warning group"
|
|
@@ -833,7 +854,8 @@ static int16_t app_round_dim(double v)
|
|
|
833
854
|
A mismatch fails HERE at compile time (not on-device). Regenerate the app (npm run aot) or align versions. */
|
|
834
855
|
_Static_assert(ER_VERSION_MAJOR == ${PKG_MAJOR} && ER_VERSION_MINOR == ${PKG_MINOR},
|
|
835
856
|
"${versionMismatch}");
|
|
836
|
-
${mathInclude}${limitsInclude}
|
|
857
|
+
${mathInclude}${limitsInclude}
|
|
858
|
+
${limitBlock}${dimRoundBlock}\n${clockBlock}\n${stateBlock ? '\n' + stateBlock : ''}${declarations}
|
|
837
859
|
${appTickFn}
|
|
838
860
|
|
|
839
861
|
void er_app_set_wall_clock(int64_t epoch_ms)
|
|
@@ -849,7 +871,7 @@ bool er_app_build(int screen_w, int screen_h)
|
|
|
849
871
|
ERNode* ${nodeDecls.join(';\n ERNode* ')};
|
|
850
872
|
${bootCall}
|
|
851
873
|
/* A screen-sized root the app tree fills (mirrors AppRegistry mounting into a screen-sized host). */
|
|
852
|
-
ERNode* root =
|
|
874
|
+
ERNode* root = app_node_create(ER_NODE_VIEW);
|
|
853
875
|
er_props_default(&p);
|
|
854
876
|
p.width = (int16_t)screen_w;
|
|
855
877
|
p.height = (int16_t)screen_h;
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
|
+
- Imports
|
|
18
|
+
---------------------------------------------------------------------------------------------------------------------*/
|
|
19
|
+
import { cleanJsxText } from './style-text.mjs';
|
|
16
20
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
17
21
|
- Constants
|
|
18
22
|
---------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -242,14 +246,6 @@ function mergeAttributes(test, whenTrue, whenFalse) {
|
|
|
242
246
|
*/
|
|
243
247
|
const childrenOf = (element) => element.children.filter(child => !(child.type === 'JSXExpressionContainer' &&
|
|
244
248
|
child.expression.type === 'JSXEmptyExpression'));
|
|
245
|
-
/**
|
|
246
|
-
* JSX text as it renders: text spanning lines collapses its whitespace, as Babel does.
|
|
247
|
-
*
|
|
248
|
-
* @param text The text.
|
|
249
|
-
*
|
|
250
|
-
* @returns The rendered text.
|
|
251
|
-
*/
|
|
252
|
-
const renderedText = (text) => /\n/.test(text.value) ? text.value.replace(/\s+/g, ' ').trim() : text.value;
|
|
253
249
|
/**
|
|
254
250
|
* Two branches of a test that depends on the panel, as one element whose differing values each pick at boot,
|
|
255
251
|
* or null when the branches differ in shape: their elements, attributes, children, handlers or text. A branch
|
|
@@ -289,7 +285,7 @@ export function mergeBranchElements(test, whenTrue, whenFalse) {
|
|
|
289
285
|
if (sameCode(child, other) ||
|
|
290
286
|
(child.type === 'JSXText' &&
|
|
291
287
|
other.type === 'JSXText' &&
|
|
292
|
-
|
|
288
|
+
cleanJsxText(child.value) === cleanJsxText(other.value))) {
|
|
293
289
|
children.push(child);
|
|
294
290
|
}
|
|
295
291
|
else if (child.type === 'JSXElement' && other.type === 'JSXElement') {
|
|
@@ -28,10 +28,11 @@ import { printExpr } from './expressions.mjs';
|
|
|
28
28
|
* @param animation The animation.
|
|
29
29
|
* @param configName The config's name, unique within the function.
|
|
30
30
|
* @param onComplete The C function to run when it completes, or null.
|
|
31
|
+
* @param userData What the engine passes that function as user_data, or null.
|
|
31
32
|
*
|
|
32
33
|
* @returns The C block.
|
|
33
34
|
*/
|
|
34
|
-
export function printAnimation(animation, configName, onComplete) {
|
|
35
|
+
export function printAnimation(animation, configName, onComplete, userData = null) {
|
|
35
36
|
const set = (field, value) => ` ${configName}.${field} = ${value};`;
|
|
36
37
|
const lines = [
|
|
37
38
|
' {',
|
|
@@ -63,6 +64,9 @@ export function printAnimation(animation, configName, onComplete) {
|
|
|
63
64
|
if (onComplete) {
|
|
64
65
|
lines.push(set('on_complete', onComplete));
|
|
65
66
|
}
|
|
67
|
+
if (userData) {
|
|
68
|
+
lines.push(set('on_complete_user_data', userData));
|
|
69
|
+
}
|
|
66
70
|
// Decay with no target is given the value it holds now.
|
|
67
71
|
const to = animation.to
|
|
68
72
|
? printExpr(animation.to)
|
|
@@ -104,25 +108,28 @@ export function printWaitDeclarations(callers) {
|
|
|
104
108
|
#endif
|
|
105
109
|
|
|
106
110
|
/* The wait between a run's last animation and its completion: the composition it belongs to (which a stop
|
|
107
|
-
names), the time left and the completion it runs. */
|
|
111
|
+
names), the time left, the animations of a joined run still running, and the completion it runs. */
|
|
108
112
|
typedef struct
|
|
109
113
|
{
|
|
110
114
|
int remaining_ms;
|
|
111
115
|
int owner;
|
|
112
116
|
ERAnimCompleteFn done;
|
|
113
117
|
uint8_t state;
|
|
118
|
+
uint8_t parts;
|
|
114
119
|
} ErAnimWait;
|
|
115
120
|
enum
|
|
116
121
|
{
|
|
117
122
|
APP_WAIT_FREE,
|
|
118
123
|
APP_WAIT_PENDING,
|
|
119
124
|
APP_WAIT_DUE,
|
|
120
|
-
APP_WAIT_STOPPING
|
|
125
|
+
APP_WAIT_STOPPING,
|
|
126
|
+
/* A joined run that has completed, kept until its animations still running have reported. */
|
|
127
|
+
APP_WAIT_DRAINING
|
|
121
128
|
};
|
|
122
129
|
static ErAnimWait s_waits[ER_AOT_MAX_WAITS];
|
|
123
130
|
|
|
124
|
-
/*
|
|
125
|
-
static
|
|
131
|
+
/* Takes a free wait for one run; runs never share one. */
|
|
132
|
+
static int app_wait_claim(int owner, int ms, int parts, ERAnimCompleteFn done)
|
|
126
133
|
{
|
|
127
134
|
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
128
135
|
{
|
|
@@ -131,13 +138,15 @@ static void app_wait_start(int owner, int ms, ERAnimCompleteFn done)
|
|
|
131
138
|
s_waits[i].remaining_ms = ms;
|
|
132
139
|
s_waits[i].owner = owner;
|
|
133
140
|
s_waits[i].done = done;
|
|
141
|
+
s_waits[i].parts = (uint8_t)parts;
|
|
134
142
|
s_waits[i].state = APP_WAIT_PENDING;
|
|
135
|
-
return;
|
|
143
|
+
return i;
|
|
136
144
|
}
|
|
137
145
|
}
|
|
138
146
|
|
|
139
|
-
/* The table is full
|
|
140
|
-
|
|
147
|
+
/* The table is full: the run cannot wait, so it ends now, as not finished. A run that completion starts
|
|
148
|
+
while the table is still full is dropped instead of recursing. */
|
|
149
|
+
APP_LIMIT("wait table full, raise ER_AOT_MAX_WAITS");
|
|
141
150
|
static bool s_reporting_full;
|
|
142
151
|
if (!s_reporting_full)
|
|
143
152
|
{
|
|
@@ -145,21 +154,22 @@ static void app_wait_start(int owner, int ms, ERAnimCompleteFn done)
|
|
|
145
154
|
done(false, NULL);
|
|
146
155
|
s_reporting_full = false;
|
|
147
156
|
}
|
|
157
|
+
return -1;
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
/* Counts down every wait, then completes the ones that ran out. A
|
|
151
|
-
full time. */
|
|
160
|
+
/* Counts down every wait, then completes the ones that ran out. A joined run that runs out first holds until
|
|
161
|
+
its animations finish. A wait a completion starts here waits its full time. */
|
|
152
162
|
static void app_wait_tick(int dt_ms)
|
|
153
163
|
{
|
|
154
164
|
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
155
165
|
{
|
|
156
|
-
if (s_waits[i].state == APP_WAIT_PENDING)
|
|
166
|
+
if (s_waits[i].state == APP_WAIT_PENDING && s_waits[i].remaining_ms > 0)
|
|
157
167
|
{
|
|
158
168
|
s_waits[i].remaining_ms -= dt_ms;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
169
|
+
}
|
|
170
|
+
if (s_waits[i].state == APP_WAIT_PENDING && s_waits[i].remaining_ms <= 0 && s_waits[i].parts == 0)
|
|
171
|
+
{
|
|
172
|
+
s_waits[i].state = APP_WAIT_DUE;
|
|
163
173
|
}
|
|
164
174
|
}
|
|
165
175
|
for (int i = 0; i < ER_AOT_MAX_WAITS; i++)
|
|
@@ -172,6 +182,60 @@ static void app_wait_tick(int dt_ms)
|
|
|
172
182
|
}
|
|
173
183
|
}`,
|
|
174
184
|
];
|
|
185
|
+
if (callers.includes('app_wait_start(')) {
|
|
186
|
+
blocks.push(`/* Starts the wait between a run's last animation and its completion. */
|
|
187
|
+
static void app_wait_start(int owner, int ms, ERAnimCompleteFn done)
|
|
188
|
+
{
|
|
189
|
+
(void)app_wait_claim(owner, ms, 0, done);
|
|
190
|
+
}`);
|
|
191
|
+
}
|
|
192
|
+
if (callers.includes('app_wait_join(')) {
|
|
193
|
+
blocks.push(`/* Starts a run that waits for its animations as well as its delay: it completes as finished once ms have passed
|
|
194
|
+
and all of its parts (animations) have finished, and as not finished as soon as one is interrupted. Each
|
|
195
|
+
animation runs app_wait_part when it ends, with what this returns as its user_data (NULL: the table was full,
|
|
196
|
+
so the run has already ended). */
|
|
197
|
+
static void* app_wait_join(int owner, int ms, int parts, ERAnimCompleteFn done)
|
|
198
|
+
{
|
|
199
|
+
const int i = app_wait_claim(owner, ms, parts, done);
|
|
200
|
+
return i < 0 ? NULL : (void*)(intptr_t)(i + 1);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* An animation of a joined run has ended. */
|
|
204
|
+
static void app_wait_part(bool finished, void* user_data)
|
|
205
|
+
{
|
|
206
|
+
if (!user_data)
|
|
207
|
+
{
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
ErAnimWait* wait = &s_waits[(intptr_t)user_data - 1];
|
|
212
|
+
wait->parts--;
|
|
213
|
+
if (wait->state == APP_WAIT_DRAINING)
|
|
214
|
+
{
|
|
215
|
+
if (wait->parts == 0)
|
|
216
|
+
{
|
|
217
|
+
wait->state = APP_WAIT_FREE;
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/* A stop in progress reports the run itself (see app_wait_report). */
|
|
223
|
+
if (wait->state != APP_WAIT_PENDING)
|
|
224
|
+
{
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (!finished)
|
|
228
|
+
{
|
|
229
|
+
wait->state = wait->parts ? APP_WAIT_DRAINING : APP_WAIT_FREE;
|
|
230
|
+
wait->done(false, NULL);
|
|
231
|
+
}
|
|
232
|
+
else if (wait->parts == 0 && wait->remaining_ms <= 0)
|
|
233
|
+
{
|
|
234
|
+
wait->state = APP_WAIT_FREE;
|
|
235
|
+
wait->done(true, NULL);
|
|
236
|
+
}
|
|
237
|
+
}`);
|
|
238
|
+
}
|
|
175
239
|
if (callers.includes('app_wait_detach(')) {
|
|
176
240
|
blocks.push(`/* A stop's two halves: detach the composition's waits, then report them as not finished. Anything a
|
|
177
241
|
completion in between starts is a new run, which the stop leaves alone. */
|
|
@@ -193,7 +257,7 @@ static void app_wait_report(int owner)
|
|
|
193
257
|
{
|
|
194
258
|
if (s_waits[i].owner == owner && s_waits[i].state == APP_WAIT_STOPPING)
|
|
195
259
|
{
|
|
196
|
-
s_waits[i].state = APP_WAIT_FREE;
|
|
260
|
+
s_waits[i].state = s_waits[i].parts ? APP_WAIT_DRAINING : APP_WAIT_FREE;
|
|
197
261
|
s_waits[i].done(false, NULL);
|
|
198
262
|
}
|
|
199
263
|
}
|
|
@@ -335,6 +399,16 @@ export function printAnimationStart(start) {
|
|
|
335
399
|
if (!start.animations.length) {
|
|
336
400
|
return start.completion ? [` (void)${start.completion.name};`] : [];
|
|
337
401
|
}
|
|
402
|
+
// A joined run takes its wait first, and every animation reports to it.
|
|
403
|
+
const join = start.completionJoin;
|
|
404
|
+
if (join && start.completion) {
|
|
405
|
+
return [
|
|
406
|
+
' {',
|
|
407
|
+
` void* join = app_wait_join(${join.owner}, ${join.delayMs}, ${start.animations.length}, ${start.completion.name});`,
|
|
408
|
+
...start.animations.flatMap((animation, index) => printAnimation(animation, `cfg${start.firstConfig + index}`, 'app_wait_part', 'join').map(line => ` ${line}`)),
|
|
409
|
+
' }',
|
|
410
|
+
];
|
|
411
|
+
}
|
|
338
412
|
// The completion (or its wait) goes on the last animation, the only one when there is a completion.
|
|
339
413
|
const last = start.animations.length - 1;
|
|
340
414
|
const onComplete = start.completionWait?.callback ?? start.completion?.name ?? null;
|
package/aot/compiler/c/nodes.mjs
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
import { cstr, floatLit } from '../c-syntax.mjs';
|
|
20
20
|
import { printCondition, printExpr } from './expressions.mjs';
|
|
21
21
|
import { panEventName, panQueryName } from './pan-responder.mjs';
|
|
22
|
-
import {
|
|
22
|
+
import { printStringWrite } from './statements.mjs';
|
|
23
|
+
import { formatArgs, printText } from './text.mjs';
|
|
23
24
|
import { printStateDrivenVectorWiring, printVectorOps } from './vectors.mjs';
|
|
24
25
|
import { branchElements, hasRuntimeProps, isStateDriven } from '../ir/nodes.mjs';
|
|
25
26
|
/*----------------------------------------------------------------------------------------------------------------------
|
|
@@ -93,6 +94,18 @@ function printBind(node, bind, index) {
|
|
|
93
94
|
const interp = bind.interp;
|
|
94
95
|
const name = `interp_${node.id}_${index}`;
|
|
95
96
|
const input = interp.input.map(floatLit).join(', ');
|
|
97
|
+
if (interp.colors) {
|
|
98
|
+
const colors = interp.colors
|
|
99
|
+
.map(c => `0x${c.toString(16).padStart(8, '0').toUpperCase()}u`)
|
|
100
|
+
.join(', ');
|
|
101
|
+
return [
|
|
102
|
+
` {`,
|
|
103
|
+
` static const ERColorInterpolation ${name} = { { ${input} }, { ${colors} }, ` +
|
|
104
|
+
`${interp.input.length}, ${interp.exLeft}, ${interp.exRight} };`,
|
|
105
|
+
` er_anim_value_bind_color(${bind.cVar}, ${node.id}, ${bind.prop}, &${name});`,
|
|
106
|
+
` }`,
|
|
107
|
+
];
|
|
108
|
+
}
|
|
96
109
|
const output = interp.output.map(floatLit).join(', ');
|
|
97
110
|
const table = node.type === 'ER_NODE_ARC'
|
|
98
111
|
? [
|
|
@@ -142,10 +155,10 @@ export function printNode(node) {
|
|
|
142
155
|
const text = node.text ? printText(node.text) : null;
|
|
143
156
|
const imageName = node.image?.kind === 'value'
|
|
144
157
|
? printExpr(node.image.value)
|
|
145
|
-
: node.image
|
|
158
|
+
: node.image
|
|
146
159
|
? cstr(node.image.name)
|
|
147
160
|
: null;
|
|
148
|
-
const build = [` ${id} =
|
|
161
|
+
const build = [` ${id} = app_node_create(${node.type});`];
|
|
149
162
|
let update = null;
|
|
150
163
|
if (isStateDriven(node)) {
|
|
151
164
|
build.push(` s_${id} = ${id};`);
|
|
@@ -165,7 +178,7 @@ export function printNode(node) {
|
|
|
165
178
|
styleAssigns: node.constantProps,
|
|
166
179
|
text,
|
|
167
180
|
dynAssigns: node.stateProps,
|
|
168
|
-
imageName
|
|
181
|
+
imageName,
|
|
169
182
|
placeholder: node.placeholder,
|
|
170
183
|
}, id));
|
|
171
184
|
}
|
|
@@ -278,16 +291,12 @@ export function printNodeUpdate(update, target = `s_${update.nodeId}`) {
|
|
|
278
291
|
if (update.placeholder != null) {
|
|
279
292
|
lines.push(` snprintf(p.placeholder, sizeof(p.placeholder), "%s", ${cstr(update.placeholder)});`);
|
|
280
293
|
}
|
|
294
|
+
// A static image name was checked at compile time; one from state is checked here.
|
|
281
295
|
if (update.imageName != null) {
|
|
282
|
-
lines.push(
|
|
296
|
+
lines.push(...printStringWrite('p.image_name', `"%s", ${update.imageName}`, update.imageName.startsWith('"'), 'image name cut short at ER_IMAGE_NAME_MAX', ' '));
|
|
283
297
|
}
|
|
284
298
|
if (update.text) {
|
|
285
|
-
|
|
286
|
-
lines.push(` snprintf(p.text, sizeof(p.text), ${cstr(update.text.format)}, ${update.text.args.join(', ')});`);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
lines.push(` snprintf(p.text, sizeof(p.text), "%s", ${cstr(update.text.format.replace(/%%/g, '%'))});`);
|
|
290
|
-
}
|
|
299
|
+
lines.push(...printStringWrite('p.text', formatArgs(update.text), !update.text.args.length, 'text cut short at ER_TEXT_MAX', ' '));
|
|
291
300
|
}
|
|
292
301
|
lines.push(` er_node_set_props(${target}, &p);`);
|
|
293
302
|
return lines;
|