embedded-react 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +3 -2
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +17 -47
  5. package/aot/compiler/alerts.mjs +604 -0
  6. package/aot/compiler/animations.mjs +299 -57
  7. package/aot/compiler/boot.mjs +27 -2
  8. package/aot/compiler/check.mjs +62 -10
  9. package/aot/compiler/collect.mjs +517 -137
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +276 -117
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/elements/button.mjs +182 -0
  14. package/aot/compiler/elements/image-background.mjs +76 -0
  15. package/aot/compiler/elements/image.mjs +2 -1
  16. package/aot/compiler/elements/props.mjs +47 -8
  17. package/aot/compiler/elements/rewrite.mjs +118 -0
  18. package/aot/compiler/elements/section-list.mjs +370 -0
  19. package/aot/compiler/expressions.mjs +1378 -97
  20. package/aot/compiler/handlers.mjs +1807 -354
  21. package/aot/compiler/helper-values.mjs +312 -0
  22. package/aot/compiler/ir/nodes.mjs +40 -1
  23. package/aot/compiler/ir/reads.mjs +206 -5
  24. package/aot/compiler/ir/text.mjs +5 -1
  25. package/aot/compiler/ir/types.mjs +12 -0
  26. package/aot/compiler/kept-states.mjs +177 -0
  27. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  28. package/aot/compiler/keyboard.mjs +1 -1
  29. package/aot/compiler/list-items.mjs +226 -0
  30. package/aot/compiler/list-order.mjs +586 -0
  31. package/aot/compiler/list-split.mjs +259 -0
  32. package/aot/compiler/loops.mjs +582 -0
  33. package/aot/compiler/lower.mjs +203 -53
  34. package/aot/compiler/native-files.mjs +439 -0
  35. package/aot/compiler/native-header.mjs +335 -0
  36. package/aot/compiler/native-modules.mjs +1173 -0
  37. package/aot/compiler/nodes.mjs +45 -31
  38. package/aot/compiler/options.mjs +3 -2
  39. package/aot/compiler/out.mjs +18 -1
  40. package/aot/compiler/package/animations.mjs +133 -23
  41. package/aot/compiler/package/assemble.mjs +2 -4
  42. package/aot/compiler/package/bytecode.mjs +37 -8
  43. package/aot/compiler/package/checks.mjs +4 -0
  44. package/aot/compiler/package/codegen.mjs +906 -33
  45. package/aot/compiler/package/enums.mjs +10 -0
  46. package/aot/compiler/package/format.mjs +16 -3
  47. package/aot/compiler/package/lower.mjs +707 -176
  48. package/aot/compiler/package/string-caps.mjs +515 -0
  49. package/aot/compiler/package/tables.mjs +24 -0
  50. package/aot/compiler/package/writer.mjs +22 -0
  51. package/aot/compiler/parse.mjs +3 -1
  52. package/aot/compiler/record-shapes.mjs +246 -0
  53. package/aot/compiler/records.mjs +654 -0
  54. package/aot/compiler/reducers.mjs +272 -0
  55. package/aot/compiler/scroll-to.mjs +112 -0
  56. package/aot/compiler/static-eval.mjs +315 -7
  57. package/aot/compiler/style-text.mjs +20 -5
  58. package/aot/compiler/svg.mjs +13 -7
  59. package/aot/compiler/switch-cases.mjs +198 -0
  60. package/aot/compiler/tagged-records.mjs +450 -0
  61. package/aot/compiler/typing.mjs +307 -0
  62. package/aot/compiler/updaters.mjs +321 -0
  63. package/aot/compiler/window-dimensions.mjs +94 -0
  64. package/aot/compiler/worked-values.mjs +319 -0
  65. package/aot/demo-file.mjs +30 -0
  66. package/aot/style-map.mjs +94 -3
  67. package/assets/bake-font.mjs +187 -244
  68. package/assets/bake-image.mjs +47 -71
  69. package/assets/bake-svg.mjs +465 -533
  70. package/assets/build-builtin-font.mjs +14 -27
  71. package/assets/emit-c.mjs +124 -204
  72. package/assets/emit-container.mjs +129 -197
  73. package/assets/emit-pack.mjs +92 -136
  74. package/assets/font-config.mjs +19 -27
  75. package/assets/font-sizes.mjs +432 -507
  76. package/assets/glyph-coverage.mjs +170 -214
  77. package/assets/index.mjs +52 -97
  78. package/assets/rasterize.mjs +173 -194
  79. package/assets/svg-loader.mjs +42 -48
  80. package/build.mjs +85 -94
  81. package/cli.mjs +490 -586
  82. package/compile-bin.mjs +24 -36
  83. package/flash.mjs +297 -401
  84. package/hotreload/dev-device.mjs +229 -270
  85. package/hotreload/pack-app.mjs +118 -159
  86. package/hotreload/pack-split.mjs +146 -213
  87. package/hotreload/package-transfer.mjs +128 -131
  88. package/hotreload/protocol.mjs +118 -118
  89. package/hotreload/uploader.mjs +132 -159
  90. package/hotreload/watch-tree.mjs +56 -65
  91. package/pack-container.mjs +94 -116
  92. package/package.json +19 -16
  93. package/persist-transform.mjs +89 -105
  94. package/qjsc-wasm.mjs +47 -72
  95. package/sim/embedded-react.wasm +0 -0
  96. package/sim/index.html +1 -1
  97. package/sim-server.mjs +260 -354
  98. package/src/embedded-react/Alert.mjs +112 -0
  99. package/src/embedded-react/Animated.mjs +412 -0
  100. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  101. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  102. package/src/embedded-react/Dimensions.mjs +32 -0
  103. package/src/embedded-react/Easing.mjs +34 -0
  104. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  105. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  106. package/src/embedded-react/Keyboard.mjs +82 -0
  107. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  108. package/src/embedded-react/PanResponder.mjs +256 -0
  109. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  110. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  111. package/src/embedded-react/SectionList.mjs +103 -0
  112. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  113. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  114. package/src/embedded-react/background-image.mjs +321 -0
  115. package/src/embedded-react/{components.js → components.mjs} +1 -3
  116. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  117. package/src/embedded-react/index.d.ts +238 -5
  118. package/src/embedded-react/index.js +26 -17
  119. package/src/embedded-react/layout-anim-config.mjs +85 -0
  120. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  121. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  122. package/src/embedded-react/nativeModule.mjs +371 -0
  123. package/src/embedded-react/split-style.mjs +57 -0
  124. package/src/embedded-react/svg-ops.mjs +1075 -0
  125. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  126. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  127. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  128. package/src/host-config.mjs +512 -0
  129. package/src/{native-ui.js → native-ui.mjs} +1 -8
  130. package/src/props.mjs +341 -0
  131. package/src/{renderer.js → renderer.mjs} +30 -44
  132. package/src/embedded-react/Animated.js +0 -440
  133. package/src/embedded-react/Easing.js +0 -39
  134. package/src/embedded-react/PanResponder.js +0 -330
  135. package/src/embedded-react/SectionList.js +0 -148
  136. package/src/embedded-react/layout-anim-config.js +0 -101
  137. package/src/embedded-react/split-style.js +0 -58
  138. package/src/embedded-react/svg-ops.js +0 -1295
  139. package/src/host-config.js +0 -548
  140. package/src/props.js +0 -306
@@ -20,8 +20,8 @@ import { check, checkNumber } from './check.mjs';
20
20
  import { aotError } from './diagnostics.mjs';
21
21
  import { evalStaticOrThrow, evalStatic, foldScope, evalStaticOr, } from './static-eval.mjs';
22
22
  import { INT_MAX, lowerExpr } from './expressions.mjs';
23
- import { NO_WIDE, isFn, wideInitial } from './collect.mjs';
24
- import { lowerStmts } from './handlers.mjs';
23
+ import { isFn, wideInitial } from './collect.mjs';
24
+ import { lowerBody } from './handlers.mjs';
25
25
  import { isPanCreate } from './pan-responder.mjs';
26
26
  import { parseColorValue } from '../style-map.mjs';
27
27
  /*----------------------------------------------------------------------------------------------------------------------
@@ -62,6 +62,8 @@ const DEFAULT_SPRING_DAMPING = 18;
62
62
  const DEFAULT_DECAY_DECELERATION = 0.998;
63
63
  /** The numbers Easing.bezier takes: x1, y1, x2, y2. */
64
64
  const BEZIER_CONTROL_POINTS = 4;
65
+ /** Most descriptors one started tree may have (the runtime's ERB_MAX_ANIM_TREE): a group, its animations, its wait. */
66
+ const MAX_GROUP_ENTRIES = 32;
65
67
  /*----------------------------------------------------------------------------------------------------------------------
66
68
  - Implementation
67
69
  ---------------------------------------------------------------------------------------------------------------------*/
@@ -125,11 +127,10 @@ export function collectAnims(functionBody, scope, prefix = '') {
125
127
  * @param functionBody The component's body.
126
128
  * @param scope Compile-time constants the initial values fold against.
127
129
  * @param prefix The name prefix: none for the App, `c<n>_` for an inlined instance.
128
- * @param wide Slots to declare 64-bit (see compileWidened).
129
130
  *
130
131
  * @returns The refs, by name.
131
132
  */
132
- export function collectRefs(functionBody, scope, prefix = '', wide = NO_WIDE) {
133
+ export function collectRefs(functionBody, scope, prefix = '') {
133
134
  // Collect ref records by their JS binding name.
134
135
  const refs = new Map();
135
136
  // Only block-bodied functions can contain ref declarations to collect.
@@ -170,11 +171,10 @@ export function collectRefs(functionBody, scope, prefix = '', wide = NO_WIDE) {
170
171
  }
171
172
  throw error;
172
173
  }
173
- // A ref a timestamp or a number past the int range is written to hold 64 bits (see compileWidened).
174
+ // A ref that starts past the int range holds 64 bits; one a timestamp is written to is widened later.
174
175
  const initialWidth = wideInitial(value);
175
- const widened = Number.isInteger(value) && initialWidth !== 'float'
176
- ? (wide.get(slotName) ??
177
- (initialWidth === 'number' ? 'number' : undefined))
176
+ const widened = Number.isInteger(value) && initialWidth === 'number'
177
+ ? 'number'
178
178
  : undefined;
179
179
  const slotKind = !Number.isInteger(value) || initialWidth === 'float'
180
180
  ? 'float'
@@ -458,12 +458,200 @@ function lowerAnimation(entry, environment) {
458
458
  isLooping: loop,
459
459
  };
460
460
  }
461
+ /**
462
+ * The latest a composition's delays end, when that may be after its animations do: what a group waits on.
463
+ *
464
+ * @param flat The flattened composition.
465
+ * @param environment The expression environment.
466
+ *
467
+ * @returns The wait from the composition's start, or null when an animation is known to end last.
468
+ */
469
+ function outlastingDelay(flat, environment) {
470
+ const lastKnownEnd = Math.max(0, ...flat.entries.map(animationEntry => animationEntry.delayMs +
471
+ (animationEntry.kind === 'timing'
472
+ ? timingDuration(animationEntry.get, environment)
473
+ : 0)));
474
+ return flat.duration != null && flat.duration > lastKnownEnd
475
+ ? flat.duration
476
+ : null;
477
+ }
478
+ /**
479
+ * The handle of every value a sequence drives.
480
+ *
481
+ * @param sequence The sequence.
482
+ * @param accumulator Collects the handles.
483
+ *
484
+ * @returns `accumulator`.
485
+ */
486
+ function sequenceValues(sequence, accumulator = new Set()) {
487
+ for (const step of sequence.steps) {
488
+ if (step.kind === 'animation') {
489
+ accumulator.add(step.entry.slotName);
490
+ }
491
+ else if (step.kind === 'group') {
492
+ for (const animationEntry of step.flat.entries) {
493
+ accumulator.add(animationEntry.slotName);
494
+ }
495
+ for (const nested of step.flat.sequences) {
496
+ sequenceValues(nested, accumulator);
497
+ }
498
+ }
499
+ }
500
+ return accumulator;
501
+ }
502
+ /**
503
+ * Running-animation entries a sequence takes: its own, and one for each step, delay and animation in it.
504
+ *
505
+ * @param sequence The sequence.
506
+ * @param environment The expression environment.
507
+ *
508
+ * @returns The entries.
509
+ */
510
+ function sequenceEntries(sequence, environment) {
511
+ let count = 1;
512
+ for (const step of sequence.steps) {
513
+ if (step.kind !== 'group') {
514
+ count++;
515
+ continue;
516
+ }
517
+ count +=
518
+ 1 +
519
+ (outlastingDelay(step.flat, environment) == null ? 0 : 1) +
520
+ step.flat.entries.length;
521
+ for (const nested of step.flat.sequences) {
522
+ count += sequenceEntries(nested, environment);
523
+ }
524
+ }
525
+ return count;
526
+ }
527
+ /**
528
+ * Lowers a sequence that runs inside a parallel or stagger.
529
+ *
530
+ * @param sequence The sequence.
531
+ * @param environment The expression environment.
532
+ *
533
+ * @returns The sequence.
534
+ */
535
+ function lowerSequence(sequence, environment) {
536
+ return {
537
+ steps: sequence.steps.map(step => {
538
+ if (step.kind === 'animation') {
539
+ return {
540
+ kind: 'animation',
541
+ animation: lowerAnimation(step.entry, environment),
542
+ };
543
+ }
544
+ if (step.kind === 'delay') {
545
+ return { kind: 'delay', delayMs: totalMs(step.delayMs) };
546
+ }
547
+ const waitMs = outlastingDelay(step.flat, environment);
548
+ return {
549
+ kind: 'group',
550
+ stopsTogether: step.stopsTogether,
551
+ animations: step.flat.entries.map(animationEntry => lowerAnimation(animationEntry, environment)),
552
+ sequences: step.flat.sequences.map(nested => lowerSequence(nested, environment)),
553
+ waitMs: waitMs == null ? null : totalMs(waitMs),
554
+ };
555
+ }),
556
+ };
557
+ }
558
+ /**
559
+ * Flattens a sequence inside another composition. One with a single animation is that animation, delayed. Any
560
+ * other runs step by step, each step started when the one before it finishes, so a step that is interrupted ends
561
+ * the sequence, the same value can take several steps, and a step needs no fixed length. A sequence inside it is
562
+ * part of it.
563
+ *
564
+ * @param sequenceNode The sequence call.
565
+ * @param environment The expression environment.
566
+ * @param baseDelay When the sequence starts, in ms.
567
+ * @param loop The sequence repeats forever (inside an Animated.loop).
568
+ *
569
+ * @returns Its entries, or the sequence, and its run length.
570
+ */
571
+ function flattenSequence(sequenceNode, environment, baseDelay, loop) {
572
+ const steps = [];
573
+ // The delays not yet given to a step: a step's own delay takes them, and a group has a delay step before it.
574
+ let pendingDelay = baseDelay;
575
+ const collect = (node) => {
576
+ const list = node.arguments[0];
577
+ if (list?.type !== 'ArrayExpression') {
578
+ throw aotError('AOT: Animated.sequence(...) needs an array of animations');
579
+ }
580
+ for (const element of list.elements) {
581
+ if (!element)
582
+ continue;
583
+ const child = resolveAnim(element, environment);
584
+ if (!isAnimatedCall(child)) {
585
+ throw aotError('AOT: an animation must be Animated.timing/spring/decay/sequence/parallel/stagger/delay/loop(...)');
586
+ }
587
+ const kind = child.callee.property.name;
588
+ if (kind === 'sequence') {
589
+ collect(child);
590
+ }
591
+ else if (kind === 'loop') {
592
+ throw aotError('AOT: an Animated.loop inside an Animated.sequence is not supported', 'a loop around a sequence works when the loop is the animation you start: Animated.loop(Animated.sequence([...])).start().');
593
+ }
594
+ else if (kind === 'parallel' || kind === 'stagger') {
595
+ const flat = flattenAnim(child, environment, 0, loop);
596
+ if (!flat.entries.length && !flat.sequences.length) {
597
+ pendingDelay += flat.duration ?? 0;
598
+ continue;
599
+ }
600
+ if (pendingDelay > 0) {
601
+ steps.push({ kind: 'delay', delayMs: pendingDelay });
602
+ pendingDelay = 0;
603
+ }
604
+ steps.push({
605
+ kind: 'group',
606
+ stopsTogether: stopsTogether(child, environment),
607
+ flat,
608
+ });
609
+ }
610
+ else {
611
+ const flat = flattenAnim(child, environment, pendingDelay, loop);
612
+ if (flat.entries.length) {
613
+ steps.push({ kind: 'animation', entry: flat.entries[0] });
614
+ pendingDelay = 0;
615
+ }
616
+ else {
617
+ pendingDelay += flat.duration ?? 0;
618
+ }
619
+ }
620
+ }
621
+ };
622
+ collect(sequenceNode);
623
+ // Delays alone start nothing.
624
+ if (!steps.length) {
625
+ return { entries: [], sequences: [], duration: pendingDelay - baseDelay };
626
+ }
627
+ // One animation needs no sequence, unless a delay follows an animation with no fixed length.
628
+ const [only] = steps;
629
+ if (steps.length === 1 &&
630
+ only.kind === 'animation' &&
631
+ (only.entry.kind === 'timing' || pendingDelay === 0)) {
632
+ const { entry } = only;
633
+ return {
634
+ entries: [entry],
635
+ sequences: [],
636
+ duration: entry.kind === 'timing'
637
+ ? entry.delayMs -
638
+ baseDelay +
639
+ timingDuration(entry.get, environment) +
640
+ pendingDelay
641
+ : null,
642
+ };
643
+ }
644
+ if (pendingDelay > 0) {
645
+ steps.push({ kind: 'delay', delayMs: pendingDelay });
646
+ }
647
+ return { entries: [], sequences: [{ steps }], duration: null };
648
+ }
461
649
  /**
462
650
  * Flattens an Animated composition (timing/spring/decay/sequence/parallel/stagger/delay/loop) into a flat
463
- * list of atomic entries, each with an ABSOLUTE start delay (ms) — composition is realized purely through
464
- * per-entry delay_ms (no engine grouping needed for standalone values). Returns { entries, duration } where
465
- * `duration` is this node's own run length in ms, used to offset later siblings in a sequence/stagger;
466
- * null = unknown (spring/decay/loop), which is illegal to sequence anything after.
651
+ * list of atomic entries, each with an ABSOLUTE start delay (ms) — a parallel or stagger is realized purely
652
+ * through per-entry delay_ms. A sequence of several steps inside one is kept whole instead (flattenSequence).
653
+ * Returns { entries, sequences, duration } where `duration` is this node's own run length in ms, used to offset
654
+ * later siblings in a stagger and to know what a completion waits on; null = unknown (spring/decay/loop).
467
655
  *
468
656
  * @param node The composition.
469
657
  * @param environment The expression environment.
@@ -493,6 +681,7 @@ function flattenAnim(node, environment, baseDelay, loop) {
493
681
  const duration = kind === 'timing' ? ownDelay + timingDuration(get, environment) : null;
494
682
  return {
495
683
  entries: [{ slotName, kind, get, delayMs: baseDelay + ownDelay, loop }],
684
+ sequences: [],
496
685
  duration,
497
686
  };
498
687
  }
@@ -500,11 +689,15 @@ function flattenAnim(node, environment, baseDelay, loop) {
500
689
  if (kind === 'delay') {
501
690
  return {
502
691
  entries: [],
692
+ sequences: [],
503
693
  duration: configMs(callArguments[0], environment, 0, "Animated.delay's time"),
504
694
  };
505
695
  }
506
- // Composition nodes flatten into atomic animations with absolute delay_ms offsets.
507
- if (kind === 'sequence' || kind === 'parallel' || kind === 'stagger') {
696
+ if (kind === 'sequence') {
697
+ return flattenSequence(node, environment, baseDelay, loop);
698
+ }
699
+ // A parallel or stagger flattens into atomic animations with absolute delay_ms offsets.
700
+ if (kind === 'parallel' || kind === 'stagger') {
508
701
  const list = kind === 'stagger' ? callArguments[1] : callArguments[0];
509
702
  const staggerMs = kind === 'stagger'
510
703
  ? configMs(callArguments[0], environment, 0, "Animated.stagger's interval")
@@ -512,53 +705,46 @@ function flattenAnim(node, environment, baseDelay, loop) {
512
705
  if (list?.type !== 'ArrayExpression') {
513
706
  throw aotError(`AOT: Animated.${kind}(...) needs an array of animations`);
514
707
  }
515
- // Sequence advances its running offset; parallel/stagger start children from the same base with offsets.
708
+ // Every child starts from the same base, a stagger's each an interval after the one before. A value can be
709
+ // driven by one child only: er_animation_value_animate cancels the running anim on a value, so two that run
710
+ // at once would cancel each other.
516
711
  const entries = [];
517
- let offset = baseDelay; // running offset (sequence)
518
- let groupDuration = 0; // max end-time relative to baseDelay (parallel/stagger)
712
+ const sequences = [];
713
+ const driven = new Set();
714
+ let groupDuration = 0; // max end-time relative to baseDelay
519
715
  let index = 0;
520
716
  for (const child of list.elements) {
521
717
  if (!child)
522
718
  continue;
523
- const start = kind === 'sequence' ? offset : baseDelay + index * staggerMs;
719
+ const start = baseDelay + index * staggerMs;
524
720
  const flatAnimation = flattenAnim(child, environment, start, loop);
525
721
  entries.push(...flatAnimation.entries);
526
- if (kind === 'sequence') {
527
- if (flatAnimation.duration == null) {
528
- throw aotError('AOT: an Animated.sequence entry needs a known duration — use Animated.timing / Animated.delay (a spring/decay/loop inside a sequence is not supported; it has no fixed length to offset the next entry by)');
529
- }
530
- offset += flatAnimation.duration;
722
+ sequences.push(...flatAnimation.sequences);
723
+ const end = start - baseDelay + (flatAnimation.duration ?? 0);
724
+ if (end > groupDuration) {
725
+ groupDuration = end;
531
726
  }
532
- else {
533
- const end = start - baseDelay + (flatAnimation.duration ?? 0);
534
- if (end > groupDuration) {
535
- groupDuration = end;
727
+ const values = new Set(flatAnimation.entries.map(animationEntry => animationEntry.slotName));
728
+ for (const sequence of flatAnimation.sequences) {
729
+ sequenceValues(sequence, values);
730
+ }
731
+ for (const value of values) {
732
+ if (driven.has(value)) {
733
+ throw aotError('AOT: the same animated value is driven more than once in this composition — animations that run at once on one value cancel each other. Use an Animated.sequence(...) for multi-step animation of one value.');
536
734
  }
735
+ driven.add(value);
537
736
  }
538
737
  index++;
539
738
  }
540
- // The same value can't appear twice in a flat (delay_ms) composition: er_animation_value_animate cancels the
541
- // running anim on a value, so concurrent/flat-sequenced same-value steps cancel each other. (A
542
- // top-level Animated.sequence is handled separately via on_complete chaining, which does support this.)
543
- const seen = new Set();
544
- for (const entry of entries) {
545
- if (seen.has(entry.slotName)) {
546
- throw aotError('AOT: the same animated value is driven more than once in this composition — concurrent/flat same-value steps cancel each other. Use a top-level Animated.sequence(...) for multi-step animation of one value.');
547
- }
548
- seen.add(entry.slotName);
549
- }
550
- return {
551
- entries,
552
- duration: kind === 'sequence' ? offset - baseDelay : groupDuration,
553
- };
739
+ return { entries, sequences, duration: groupDuration };
554
740
  }
555
741
  // A nested loop can flatten only when it wraps a single atomic animation; complex loops need start-time chaining.
556
742
  if (kind === 'loop') {
557
743
  const flatAnimation = flattenAnim(callArguments[0], environment, baseDelay, true);
558
- if (flatAnimation.entries.length !== 1) {
744
+ if (flatAnimation.entries.length !== 1 || flatAnimation.sequences.length) {
559
745
  throw aotError('AOT: an Animated.loop inside another composition can only wrap a single Animated.timing/spring/decay', 'a loop around a sequence works when the loop is the animation you start: Animated.loop(Animated.sequence([...])).start().');
560
746
  }
561
- return { entries: flatAnimation.entries, duration: null };
747
+ return { entries: flatAnimation.entries, sequences: [], duration: null };
562
748
  }
563
749
  throw aotError(`AOT: Animated.${kind}(...) is not a supported animation`);
564
750
  }
@@ -754,9 +940,10 @@ function lowerChain(steps, environment, context, completion, loop = null, traili
754
940
  const emptyStart = (context, completion) => ({
755
941
  kind: 'startAnimations',
756
942
  animations: [],
943
+ sequences: [],
757
944
  completion,
758
945
  completionWait: null,
759
- completionJoin: null,
946
+ group: null,
760
947
  });
761
948
  /** Numbers each composition node once, so a key names the place it is written. */
762
949
  const compositionIds = new WeakMap();
@@ -786,18 +973,26 @@ function compositionKey(node, environment) {
786
973
  * @param context The statement compiler's context.
787
974
  * @param key The composition's key.
788
975
  * @param isStart A start is asking, so the waits are real (a stop alone leaves nothing to end).
976
+ * @param hasWaits The start runs waits of their own, beside any group it runs.
789
977
  *
790
978
  * @returns The owner.
791
979
  */
792
- function waitOwner(context, key, isStart) {
980
+ function waitOwner(context, key, isStart, hasWaits = isStart) {
793
981
  let record = context.output.animationWaits.get(key);
794
982
  if (!record) {
795
- record = { owner: context.output.animationWaits.size, isStarted: false };
983
+ record = {
984
+ owner: context.output.animationWaits.size,
985
+ isStarted: false,
986
+ hasWaits: false,
987
+ };
796
988
  context.output.animationWaits.set(key, record);
797
989
  }
798
990
  if (isStart) {
799
991
  record.isStarted = true;
800
992
  }
993
+ if (hasWaits) {
994
+ record.hasWaits = true;
995
+ }
801
996
  return record.owner;
802
997
  }
803
998
  /**
@@ -997,16 +1192,32 @@ function lowerCompletion(functionNode, environment, state, context) {
997
1192
  stateChanged: false,
998
1193
  output: context.output,
999
1194
  };
1000
- const body = lowerStmts(list, { ...environment, locals }, state, completionContext);
1195
+ const body = lowerBody(list, { ...environment, locals }, state, completionContext);
1001
1196
  const completion = { name, body, updatesState: completionContext.stateChanged };
1002
1197
  context.output.animationCallbacks.push({ kind: 'completion', completion });
1003
1198
  return completion;
1004
1199
  }
1200
+ /**
1201
+ * Whether one interrupted animation of a composition stops the rest: a parallel's do unless it is given
1202
+ * `stopTogether: false`, and a stagger's run on.
1203
+ *
1204
+ * @param node The parallel or stagger.
1205
+ * @param environment The expression environment.
1206
+ *
1207
+ * @returns Whether they stop together.
1208
+ */
1209
+ function stopsTogether(node, environment) {
1210
+ if (node.callee.property.name !== 'parallel')
1211
+ return false;
1212
+ const stopTogether = animConfigGetter(node.arguments[1])('stopTogether');
1213
+ return evalStaticOr(stopTogether, environment, true) !== false;
1214
+ }
1005
1215
  /**
1006
1216
  * Lowers `<animation>.start()` — a single Animated.timing/spring/decay or a composition
1007
1217
  * (sequence/parallel/stagger/delay/loop). A sequence, and a loop the engine cannot repeat on its own, become
1008
1218
  * an on_complete chain (lowerChain); everything else flattens to one animation per atomic entry, composition
1009
- * expressed through per-entry delay_ms. Native-driven; sets no React state.
1219
+ * expressed through per-entry delay_ms, run as a group when a completion waits on several or a parallel stops
1220
+ * them together. Native-driven; sets no React state.
1010
1221
  *
1011
1222
  * @param expression The `.start(…)` call.
1012
1223
  * @param environment The expression environment.
@@ -1037,19 +1248,46 @@ export function lowerAnimateStart(expression, environment, state, context) {
1037
1248
  if (start)
1038
1249
  return start;
1039
1250
  }
1040
- // The flat path has no "after all entries finish" join point, so completion callbacks are limited to one entry.
1041
- const { entries, duration } = flattenAnim(receiver, environment, 0, false);
1042
- if (!entries.length) {
1251
+ const flat = flattenAnim(receiver, environment, 0, false);
1252
+ const { entries, sequences, duration } = flat;
1253
+ if (!entries.length && !sequences.length) {
1043
1254
  return startNothing(context, completion, duration ?? 0, key);
1044
1255
  }
1045
- if (completion && entries.length > 1) {
1046
- 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.');
1047
- }
1048
1256
  // Each entry starts on its own, numbered after the configs already in this body.
1049
1257
  const start = emptyStart(context, completion);
1050
1258
  for (const animationEntry of entries) {
1051
1259
  start.animations.push(lowerAnimation(animationEntry, environment));
1052
1260
  }
1261
+ // Several animations run as a group when a completion waits on them all, one stopping stops the rest, or a
1262
+ // sequence runs among them.
1263
+ const runners = entries.length + sequences.length;
1264
+ const stopTogether = runners > 1 && stopsTogether(receiver, environment);
1265
+ if (sequences.length || (runners > 1 && (completion || stopTogether))) {
1266
+ const waitMs = completion ? outlastingDelay(flat, environment) : null;
1267
+ const groupEntries = 1 +
1268
+ (waitMs == null ? 0 : 1) +
1269
+ entries.length +
1270
+ sequences.reduce((count, sequence) => count + sequenceEntries(sequence, environment), 0);
1271
+ if (groupEntries > MAX_GROUP_ENTRIES) {
1272
+ const mostAnimations = MAX_GROUP_ENTRIES - 1 - (waitMs == null ? 0 : 1);
1273
+ throw aotError(sequences.length
1274
+ ? `AOT: this parallel/stagger takes ${groupEntries} entries to run as one group, of at most ${MAX_GROUP_ENTRIES} (one for itself, and one for each animation, sequence and delay in it)`
1275
+ : `AOT: this parallel/stagger can run at most ${mostAnimations} animations as one group`, 'split the composition into smaller ones.');
1276
+ }
1277
+ context.output.animationGroupEntries += groupEntries;
1278
+ start.sequences = sequences.map(sequence => lowerSequence(sequence, environment));
1279
+ start.group = {
1280
+ stopsTogether: stopTogether,
1281
+ wait: waitMs == null
1282
+ ? null
1283
+ : { delayMs: totalMs(waitMs), owner: waitOwner(context, key, true) },
1284
+ // A group with sequences is kept, so starting it again stops the run before.
1285
+ owner: sequences.length
1286
+ ? waitOwner(context, key, true, waitMs != null)
1287
+ : null,
1288
+ };
1289
+ return start;
1290
+ }
1053
1291
  // A spring or decay has no fixed end, so a delay beside it that runs past its start is joined at run time.
1054
1292
  const [only] = entries;
1055
1293
  if (completion &&
@@ -1057,9 +1295,13 @@ export function lowerAnimateStart(expression, environment, state, context) {
1057
1295
  !only.loop &&
1058
1296
  duration != null &&
1059
1297
  duration > only.delayMs) {
1060
- start.completionJoin = {
1061
- delayMs: totalMs(duration),
1062
- owner: waitOwner(context, key, true),
1298
+ start.group = {
1299
+ stopsTogether: true,
1300
+ wait: {
1301
+ delayMs: totalMs(duration),
1302
+ owner: waitOwner(context, key, true),
1303
+ },
1304
+ owner: null,
1063
1305
  };
1064
1306
  }
1065
1307
  // A delay beside the one timing that outlasts it holds the completion back until the composition ends.
@@ -17,12 +17,14 @@
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
19
  import { attemptLowering } from './check.mjs';
20
- import { INT } from './ir/types.mjs';
20
+ import { BOOL, INT } from './ir/types.mjs';
21
21
  /*----------------------------------------------------------------------------------------------------------------------
22
22
  - Constants
23
23
  ---------------------------------------------------------------------------------------------------------------------*/
24
24
  /** The kinds of value a boot slot holds. */
25
25
  const SLOT_KINDS = new Set(['bool', 'int', 'float', 'string']);
26
+ /** The name the panel's size is read by once `useWindowDimensions()` is rewritten, which no name in the app can take. */
27
+ export const PANEL_KEY = '<panel>';
26
28
  /** The current compile's boot values, or null outside a compile. */
27
29
  let context = null;
28
30
  /** The longest source text an error quotes, and what ends a longer one. */
@@ -176,6 +178,29 @@ export const screenBinding = (screen) => ({
176
178
  width: new BootValue(null, {}, screen.width, true, null, 'width'),
177
179
  height: new BootValue(null, {}, screen.height, true, null, 'height'),
178
180
  });
181
+ /**
182
+ * The slot boot reads whether an optional native module is there into, added on first use.
183
+ *
184
+ * @param module The module's index among the optional modules.
185
+ * @param name Its name, which the slot is named after.
186
+ *
187
+ * @returns The slot.
188
+ */
189
+ export function nativeAvailableSlot(module, name) {
190
+ if (!context) {
191
+ throw new Error('AOT: a native module is read outside a compile');
192
+ }
193
+ const found = context.slots.find(slot => slot.initializer.kind === 'native' && slot.initializer.module === module);
194
+ if (found)
195
+ return found;
196
+ const slot = {
197
+ field: slotField(`${name}_available`),
198
+ type: BOOL,
199
+ initializer: { kind: 'native', module },
200
+ };
201
+ context.slots.push(slot);
202
+ return slot;
203
+ }
179
204
  /**
180
205
  * Starts recording a compile's boot values.
181
206
  *
@@ -352,7 +377,7 @@ const bootEnv = (environment, scope) => ({
352
377
  event: null,
353
378
  gesture: null,
354
379
  pan: null,
355
- math64: false,
380
+ math64: undefined,
356
381
  animationLocals: undefined,
357
382
  });
358
383
  /**
@@ -16,7 +16,7 @@
16
16
  /*----------------------------------------------------------------------------------------------------------------------
17
17
  - Imports
18
18
  ---------------------------------------------------------------------------------------------------------------------*/
19
- import { GRAD_MAX_STOPS } from '../../src/embedded-react/svg-ops.js';
19
+ import { GRAD_MAX_STOPS } from '../../src/embedded-react/svg-ops.mjs';
20
20
  import { aotError, currentLoc, locateError } from './diagnostics.mjs';
21
21
  /*----------------------------------------------------------------------------------------------------------------------
22
22
  - Constants
@@ -27,7 +27,10 @@ const MAX_INTERPOLATION_POINTS = 8;
27
27
  const MAX_MILLISECONDS = 2 ** 31 - 1;
28
28
  /** The most stops a <Dial indicatorGradient> holds (the engine's ER_GRADIENT_MAX_STOPS). */
29
29
  export const DIAL_MAX_GRADIENT_STOPS = 4;
30
- /** Where lowering records its checks while a compile runs, or null outside one, when a check runs at once. */
30
+ /**
31
+ * Where lowering records its checks and typing steps while a compile runs, in order, or null outside one, when
32
+ * each runs at once.
33
+ */
31
34
  let recording = null;
32
35
  /** How many fallback attempts are running: a check inside one runs at once, so its failure picks the fallback. */
33
36
  let attempts = 0;
@@ -111,6 +114,8 @@ export function checkProblem(subject) {
111
114
  return subject.count > DIAL_MAX_GRADIENT_STOPS
112
115
  ? aotError(`AOT: <Dial indicatorGradient> takes at most ${DIAL_MAX_GRADIENT_STOPS} stops (got ${subject.count})`, "the engine's arc holds 4 (ER_GRADIENT_MAX_STOPS); merge stops that sit close together.")
113
116
  : null;
117
+ case 'typing':
118
+ return subject.problem;
114
119
  }
115
120
  }
116
121
  /**
@@ -131,6 +136,25 @@ export function check(subject, location) {
131
136
  throw problem;
132
137
  }
133
138
  }
139
+ /**
140
+ * Whether lowering is leaving types to the typing pass: during a compile, outside a fallback attempt.
141
+ *
142
+ * @returns True when a typing step is recorded rather than run.
143
+ */
144
+ export const defersTyping = () => recording !== null && !attempts;
145
+ /**
146
+ * Runs what depends on a type. During a compile it is recorded for the typing pass, which runs it once the
147
+ * slot widths are known; otherwise, or inside a fallback attempt, it runs at once.
148
+ *
149
+ * @param run The step.
150
+ */
151
+ export function whenTyped(run) {
152
+ if (recording && !attempts) {
153
+ recording.push({ kind: 'typingStep', run, location: currentLoc() });
154
+ return;
155
+ }
156
+ run();
157
+ }
134
158
  /**
135
159
  * Checks a number the app stores as a float (see check).
136
160
  *
@@ -170,25 +194,53 @@ export function runChecks(checks) {
170
194
  }
171
195
  }
172
196
  /**
173
- * Lowers with its checks recorded rather than run. When lowering fails, the checks recorded before the
174
- * failure run first, so the first problem in the app is the one reported, as when every check ran at once.
197
+ * Lowers with its checks and typing steps recorded rather than run, then runs the typing pass: each step, in
198
+ * the order lowering recorded it, until one fails. That one becomes a check, so the check pass reports the first
199
+ * problem in the app. When lowering fails, both passes run over what was recorded before the failure, so the
200
+ * first problem is still the one reported.
175
201
  *
176
202
  * @param lower The lowering.
203
+ * @param beforeTyping Runs once lowering is over, before the typing pass.
177
204
  *
178
205
  * @returns What lowering returns, and its checks, in order.
179
206
  */
180
- export function lowerWithChecks(lower) {
181
- const checks = [];
207
+ export function lowerWithChecks(lower, beforeTyping = () => { }) {
208
+ const steps = [];
182
209
  const outer = recording;
183
- recording = checks;
210
+ recording = steps;
211
+ let lowered;
184
212
  try {
185
- return { result: lower(), checks };
213
+ lowered = { result: lower() };
186
214
  }
187
215
  catch (error) {
188
- runChecks(checks);
189
- throw error;
216
+ lowered = { error };
190
217
  }
191
218
  finally {
192
219
  recording = outer;
193
220
  }
221
+ beforeTyping();
222
+ const checks = [];
223
+ for (const step of steps) {
224
+ if (step.kind !== 'typingStep') {
225
+ checks.push(step);
226
+ continue;
227
+ }
228
+ try {
229
+ step.run();
230
+ }
231
+ catch (error) {
232
+ locateError(error, step.location);
233
+ checks.push({
234
+ kind: 'typing',
235
+ problem: error,
236
+ location: error.aotLoc,
237
+ });
238
+ break;
239
+ }
240
+ }
241
+ if ('error' in lowered) {
242
+ runChecks(checks);
243
+ throw lowered.error;
244
+ }
245
+ return { result: lowered.result, checks };
194
246
  }