embedded-react 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +7 -3
  2. package/aot/compile.mjs +178 -58
  3. package/aot/compiler/animations.mjs +290 -281
  4. package/aot/compiler/boot.mjs +70 -33
  5. package/aot/compiler/branch-merge.mjs +4 -3
  6. package/aot/compiler/check.mjs +9 -9
  7. package/aot/compiler/collect.mjs +324 -205
  8. package/aot/compiler/control-flow.mjs +209 -197
  9. package/aot/compiler/diagnostics.mjs +22 -25
  10. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  11. package/aot/compiler/elements/dial.mjs +91 -77
  12. package/aot/compiler/elements/flat-list.mjs +24 -22
  13. package/aot/compiler/elements/image.mjs +51 -50
  14. package/aot/compiler/elements/modal.mjs +31 -30
  15. package/aot/compiler/elements/props.mjs +23 -23
  16. package/aot/compiler/elements/switch.mjs +42 -34
  17. package/aot/compiler/elements/text-input.mjs +34 -32
  18. package/aot/compiler/expressions.mjs +372 -333
  19. package/aot/compiler/handlers.mjs +473 -387
  20. package/aot/compiler/ir/functions.mjs +11 -1
  21. package/aot/compiler/ir/nodes.mjs +4 -4
  22. package/aot/compiler/ir/reads.mjs +19 -19
  23. package/aot/compiler/ir/types.mjs +14 -14
  24. package/aot/compiler/ir/vectors.mjs +5 -1
  25. package/aot/compiler/keyboard.mjs +17 -7
  26. package/aot/compiler/lower.mjs +77 -80
  27. package/aot/compiler/nodes.mjs +169 -152
  28. package/aot/compiler/options.mjs +35 -30
  29. package/aot/compiler/out.mjs +18 -22
  30. package/aot/compiler/package/animations.mjs +669 -0
  31. package/aot/compiler/package/arena.mjs +252 -0
  32. package/aot/compiler/package/assemble.mjs +177 -0
  33. package/aot/compiler/package/bytecode.mjs +286 -0
  34. package/aot/compiler/package/checks.mjs +1022 -0
  35. package/aot/compiler/package/codegen.mjs +1329 -0
  36. package/aot/compiler/package/enums.mjs +138 -0
  37. package/aot/compiler/package/format.mjs +760 -0
  38. package/aot/compiler/package/layouts.mjs +136 -0
  39. package/aot/compiler/package/lower.mjs +1606 -0
  40. package/aot/compiler/package/props.mjs +118 -0
  41. package/aot/compiler/package/tables.mjs +103 -0
  42. package/aot/compiler/package/vectors.mjs +502 -0
  43. package/aot/compiler/package/writer.mjs +664 -0
  44. package/aot/compiler/pan-responder.mjs +69 -61
  45. package/aot/compiler/parse.mjs +21 -21
  46. package/aot/compiler/static-eval.mjs +25 -23
  47. package/aot/compiler/style-text.mjs +161 -172
  48. package/aot/compiler/svg.mjs +477 -251
  49. package/aot/screenshot-smoke.mjs +54 -40
  50. package/aot/style-map.mjs +102 -90
  51. package/assets/bake-font.mjs +123 -77
  52. package/assets/bake-image.mjs +39 -22
  53. package/assets/bake-svg.mjs +361 -262
  54. package/assets/build-builtin-font.mjs +11 -7
  55. package/assets/emit-c.mjs +77 -58
  56. package/assets/emit-container.mjs +123 -37
  57. package/assets/emit-pack.mjs +77 -67
  58. package/assets/font-config.mjs +9 -6
  59. package/assets/font-sizes.mjs +163 -123
  60. package/assets/glyph-coverage.mjs +74 -54
  61. package/assets/index.mjs +31 -9
  62. package/assets/rasterize.mjs +126 -99
  63. package/assets/svg-loader.mjs +8 -8
  64. package/build.mjs +14 -12
  65. package/cli.mjs +359 -172
  66. package/compile-bin.mjs +3 -3
  67. package/flash.mjs +537 -0
  68. package/hotreload/dev-device.mjs +90 -33
  69. package/hotreload/pack-app.mjs +55 -43
  70. package/hotreload/pack-split.mjs +46 -37
  71. package/hotreload/package-transfer.mjs +175 -0
  72. package/hotreload/protocol.mjs +50 -37
  73. package/hotreload/uploader.mjs +38 -27
  74. package/hotreload/watch-tree.mjs +19 -19
  75. package/pack-container.mjs +28 -20
  76. package/package.json +7 -8
  77. package/persist-transform.mjs +34 -28
  78. package/qjsc-wasm.mjs +25 -14
  79. package/sim/embedded-react.cjs +1 -1
  80. package/sim/embedded-react.js +1 -1
  81. package/sim/embedded-react.wasm +0 -0
  82. package/sim/index.html +94 -85
  83. package/sim-server.mjs +101 -82
  84. package/src/embedded-react/Animated.js +24 -24
  85. package/src/embedded-react/Easing.js +1 -1
  86. package/src/embedded-react/FlatList.js +3 -3
  87. package/src/embedded-react/LayoutAnimation.js +8 -5
  88. package/src/embedded-react/PanResponder.js +75 -71
  89. package/src/embedded-react/Pressable.js +2 -8
  90. package/src/embedded-react/SectionList.js +6 -6
  91. package/src/embedded-react/StyleSheet.js +4 -3
  92. package/src/embedded-react/TouchableOpacity.js +13 -8
  93. package/src/embedded-react/index.d.ts +5 -5
  94. package/src/embedded-react/layout-anim-config.js +10 -4
  95. package/src/embedded-react/list-child.js +5 -5
  96. package/src/embedded-react/named-colors.js +1 -1
  97. package/src/embedded-react/split-style.js +11 -11
  98. package/src/embedded-react/svg-ops.js +760 -593
  99. package/src/embedded-react/useHostValue.js +3 -3
  100. package/src/embedded-react/usePersistentState.js +6 -6
  101. package/src/embedded-react/warn-props.js +1 -1
  102. package/src/host-config.js +60 -53
  103. package/src/props.js +49 -41
  104. package/src/renderer.js +7 -4
  105. package/aot/compiler/assemble.mjs +0 -944
  106. package/aot/compiler/c/animations.mjs +0 -436
  107. package/aot/compiler/c/boot.mjs +0 -127
  108. package/aot/compiler/c/expressions.mjs +0 -270
  109. package/aot/compiler/c/functions.mjs +0 -268
  110. package/aot/compiler/c/keyboard.mjs +0 -96
  111. package/aot/compiler/c/nodes.mjs +0 -303
  112. package/aot/compiler/c/pan-responder.mjs +0 -136
  113. package/aot/compiler/c/statements.mjs +0 -319
  114. package/aot/compiler/c/text.mjs +0 -83
  115. package/aot/compiler/c/vectors.mjs +0 -381
  116. package/aot/compiler/c-syntax.mjs +0 -127
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Copyright 2026 Cory Lamming
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /*
17
+ * Finds the layouts of an app that names no sizes: compile one, ask which size its check rejects, compile again, until
18
+ * every size has a layout. The search is over ranges of sizes, which is what makes "every size" a proof instead of a
19
+ * sample: a range is settled once one check passes for all of it, and a range every check fails for holds a size with
20
+ * no layout. Anything else is split in two.
21
+ */
22
+ /*----------------------------------------------------------------------------------------------------------------------
23
+ - Imports
24
+ ---------------------------------------------------------------------------------------------------------------------*/
25
+ import { checkOverSizes, runCheck } from './checks.mjs';
26
+ /*----------------------------------------------------------------------------------------------------------------------
27
+ - Constants
28
+ ---------------------------------------------------------------------------------------------------------------------*/
29
+ /** The largest panel side the search covers, as options.mts allows. */
30
+ export const MAX_PANEL_SIDE = 32767;
31
+ /** The most ranges one search looks at before it gives up: a few seconds at worst. */
32
+ const MAX_RANGES = 8000000;
33
+ /** A range holding several sizes starts its answer here: a small panel, which is what most compile best for. */
34
+ const PREFERRED = { width: 320, height: 240 };
35
+ /** Panels tried first, so a layout is compiled at, and named by, a size someone has. */
36
+ const COMMON_PANELS = [
37
+ { width: 240, height: 320 },
38
+ { width: 320, height: 240 },
39
+ { width: 240, height: 240 },
40
+ { width: 240, height: 280 },
41
+ { width: 320, height: 480 },
42
+ { width: 480, height: 320 },
43
+ { width: 480, height: 272 },
44
+ { width: 480, height: 800 },
45
+ { width: 800, height: 480 },
46
+ { width: 1024, height: 600 },
47
+ { width: 1280, height: 720 },
48
+ ];
49
+ /*----------------------------------------------------------------------------------------------------------------------
50
+ - Implementation
51
+ ---------------------------------------------------------------------------------------------------------------------*/
52
+ /**
53
+ * Finds sizes that have no layout yet, as the layouts grow.
54
+ *
55
+ * @class SizeSearch
56
+ */
57
+ export class SizeSearch {
58
+ /** The ranges not settled yet. Ranges already settled stay settled, whatever layouts come later. */
59
+ open = [
60
+ {
61
+ minWidth: 1,
62
+ maxWidth: MAX_PANEL_SIDE,
63
+ minHeight: 1,
64
+ maxHeight: MAX_PANEL_SIDE,
65
+ },
66
+ ];
67
+ looked = 0;
68
+ /**
69
+ * The next size none of the checks takes.
70
+ *
71
+ * @param checks The checks of the layouts so far.
72
+ *
73
+ * @returns The size, null when every size has a layout, or 'gave-up' when the checks are too intricate to tell.
74
+ */
75
+ next(checks) {
76
+ const common = COMMON_PANELS.find(({ width, height }) => !checks.some(check => runCheck(check, width, height)));
77
+ if (common)
78
+ return common;
79
+ for (;;) {
80
+ const sizes = this.open.pop();
81
+ if (!sizes)
82
+ return null;
83
+ if (++this.looked > MAX_RANGES)
84
+ return 'gave-up';
85
+ const verdicts = checks.map(check => checkOverSizes(check, sizes));
86
+ if (verdicts.includes('pass'))
87
+ continue;
88
+ if (verdicts.every(verdict => verdict === 'fail')) {
89
+ // The rest of this range may be left for later layouts to settle.
90
+ const size = {
91
+ width: Math.min(sizes.maxWidth, Math.max(sizes.minWidth, PREFERRED.width)),
92
+ height: Math.min(sizes.maxHeight, Math.max(sizes.minHeight, PREFERRED.height)),
93
+ };
94
+ this.open.push(sizes);
95
+ return size;
96
+ }
97
+ this.split(sizes, checks.filter((_, index) => verdicts[index] === 'unsure'));
98
+ }
99
+ }
100
+ /**
101
+ * Splits a range across the side that decides it: the one whose pinning settles the most checks. Otherwise a
102
+ * breakpoint on the width alone would split the height all along its edge too.
103
+ *
104
+ * @param sizes The range.
105
+ * @param unsure The checks that can't tell yet.
106
+ */
107
+ split(sizes, unsure) {
108
+ const midWidth = Math.floor((sizes.minWidth + sizes.maxWidth) / 2);
109
+ const midHeight = Math.floor((sizes.minHeight + sizes.maxHeight) / 2);
110
+ const wide = sizes.maxWidth > sizes.minWidth;
111
+ const tall = sizes.maxHeight > sizes.minHeight;
112
+ const stillUnsure = (range) => unsure.filter(check => checkOverSizes(check, range) === 'unsure').length;
113
+ const pinnedWidth = stillUnsure({
114
+ ...sizes,
115
+ minWidth: midWidth,
116
+ maxWidth: midWidth,
117
+ });
118
+ const pinnedHeight = stillUnsure({
119
+ ...sizes,
120
+ minHeight: midHeight,
121
+ maxHeight: midHeight,
122
+ });
123
+ const byWidth = wide &&
124
+ (!tall ||
125
+ pinnedWidth < pinnedHeight ||
126
+ (pinnedWidth === pinnedHeight &&
127
+ sizes.maxWidth - sizes.minWidth >=
128
+ sizes.maxHeight - sizes.minHeight));
129
+ if (byWidth) {
130
+ this.open.push({ ...sizes, minWidth: midWidth + 1 }, { ...sizes, maxWidth: midWidth });
131
+ }
132
+ else {
133
+ this.open.push({ ...sizes, minHeight: midHeight + 1 }, { ...sizes, maxHeight: midHeight });
134
+ }
135
+ }
136
+ }