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.
Files changed (148) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +8 -3
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +180 -90
  5. package/aot/compiler/animations.mjs +568 -317
  6. package/aot/compiler/boot.mjs +97 -35
  7. package/aot/compiler/branch-merge.mjs +4 -3
  8. package/aot/compiler/check.mjs +70 -18
  9. package/aot/compiler/collect.mjs +787 -288
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +439 -268
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/diagnostics.mjs +22 -25
  14. package/aot/compiler/elements/activity-indicator.mjs +25 -24
  15. package/aot/compiler/elements/button.mjs +182 -0
  16. package/aot/compiler/elements/dial.mjs +91 -77
  17. package/aot/compiler/elements/flat-list.mjs +24 -22
  18. package/aot/compiler/elements/image-background.mjs +76 -0
  19. package/aot/compiler/elements/image.mjs +52 -50
  20. package/aot/compiler/elements/modal.mjs +31 -30
  21. package/aot/compiler/elements/props.mjs +61 -26
  22. package/aot/compiler/elements/rewrite.mjs +118 -0
  23. package/aot/compiler/elements/section-list.mjs +370 -0
  24. package/aot/compiler/elements/switch.mjs +42 -34
  25. package/aot/compiler/elements/text-input.mjs +34 -32
  26. package/aot/compiler/expressions.mjs +1685 -392
  27. package/aot/compiler/handlers.mjs +2029 -547
  28. package/aot/compiler/helper-values.mjs +312 -0
  29. package/aot/compiler/ir/functions.mjs +11 -1
  30. package/aot/compiler/ir/nodes.mjs +43 -4
  31. package/aot/compiler/ir/reads.mjs +223 -22
  32. package/aot/compiler/ir/text.mjs +5 -1
  33. package/aot/compiler/ir/types.mjs +26 -14
  34. package/aot/compiler/ir/vectors.mjs +5 -1
  35. package/aot/compiler/kept-states.mjs +177 -0
  36. package/aot/compiler/keyboard.mjs +17 -7
  37. package/aot/compiler/list-items.mjs +226 -0
  38. package/aot/compiler/list-order.mjs +586 -0
  39. package/aot/compiler/list-split.mjs +259 -0
  40. package/aot/compiler/loops.mjs +582 -0
  41. package/aot/compiler/lower.mjs +246 -111
  42. package/aot/compiler/native-files.mjs +439 -0
  43. package/aot/compiler/native-header.mjs +335 -0
  44. package/aot/compiler/native-modules.mjs +1173 -0
  45. package/aot/compiler/nodes.mjs +195 -172
  46. package/aot/compiler/options.mjs +37 -31
  47. package/aot/compiler/out.mjs +32 -23
  48. package/aot/compiler/package/animations.mjs +779 -0
  49. package/aot/compiler/package/arena.mjs +252 -0
  50. package/aot/compiler/package/assemble.mjs +175 -0
  51. package/aot/compiler/package/bytecode.mjs +315 -0
  52. package/aot/compiler/package/checks.mjs +1026 -0
  53. package/aot/compiler/package/codegen.mjs +2168 -0
  54. package/aot/compiler/package/enums.mjs +148 -0
  55. package/aot/compiler/package/format.mjs +771 -0
  56. package/aot/compiler/package/layouts.mjs +136 -0
  57. package/aot/compiler/package/lower.mjs +2103 -0
  58. package/aot/compiler/package/props.mjs +118 -0
  59. package/aot/compiler/package/string-caps.mjs +515 -0
  60. package/aot/compiler/package/tables.mjs +127 -0
  61. package/aot/compiler/package/vectors.mjs +502 -0
  62. package/aot/compiler/package/writer.mjs +686 -0
  63. package/aot/compiler/pan-responder.mjs +69 -61
  64. package/aot/compiler/parse.mjs +23 -21
  65. package/aot/compiler/record-shapes.mjs +246 -0
  66. package/aot/compiler/records.mjs +654 -0
  67. package/aot/compiler/reducers.mjs +272 -0
  68. package/aot/compiler/static-eval.mjs +340 -30
  69. package/aot/compiler/style-text.mjs +178 -174
  70. package/aot/compiler/svg.mjs +480 -251
  71. package/aot/compiler/switch-cases.mjs +198 -0
  72. package/aot/compiler/tagged-records.mjs +450 -0
  73. package/aot/compiler/typing.mjs +307 -0
  74. package/aot/compiler/updaters.mjs +320 -0
  75. package/aot/compiler/window-dimensions.mjs +94 -0
  76. package/aot/compiler/worked-values.mjs +319 -0
  77. package/aot/demo-file.mjs +30 -0
  78. package/aot/screenshot-smoke.mjs +54 -40
  79. package/aot/style-map.mjs +152 -92
  80. package/assets/bake-font.mjs +123 -77
  81. package/assets/bake-image.mjs +39 -22
  82. package/assets/bake-svg.mjs +361 -262
  83. package/assets/build-builtin-font.mjs +11 -7
  84. package/assets/emit-c.mjs +77 -58
  85. package/assets/emit-container.mjs +123 -37
  86. package/assets/emit-pack.mjs +77 -67
  87. package/assets/font-config.mjs +9 -6
  88. package/assets/font-sizes.mjs +163 -123
  89. package/assets/glyph-coverage.mjs +74 -54
  90. package/assets/index.mjs +31 -9
  91. package/assets/rasterize.mjs +126 -99
  92. package/assets/svg-loader.mjs +8 -8
  93. package/build.mjs +23 -13
  94. package/cli.mjs +402 -172
  95. package/compile-bin.mjs +3 -3
  96. package/flash.mjs +537 -0
  97. package/hotreload/dev-device.mjs +90 -33
  98. package/hotreload/pack-app.mjs +55 -43
  99. package/hotreload/pack-split.mjs +62 -64
  100. package/hotreload/package-transfer.mjs +175 -0
  101. package/hotreload/protocol.mjs +50 -37
  102. package/hotreload/uploader.mjs +38 -27
  103. package/hotreload/watch-tree.mjs +19 -19
  104. package/pack-container.mjs +37 -21
  105. package/package.json +7 -8
  106. package/persist-transform.mjs +34 -28
  107. package/qjsc-wasm.mjs +25 -14
  108. package/sim/embedded-react.cjs +1 -1
  109. package/sim/embedded-react.js +1 -1
  110. package/sim/embedded-react.wasm +0 -0
  111. package/sim/index.html +94 -85
  112. package/sim-server.mjs +113 -94
  113. package/src/embedded-react/Animated.js +24 -24
  114. package/src/embedded-react/Dimensions.js +37 -0
  115. package/src/embedded-react/Easing.js +1 -1
  116. package/src/embedded-react/FlatList.js +3 -3
  117. package/src/embedded-react/LayoutAnimation.js +8 -5
  118. package/src/embedded-react/PanResponder.js +75 -71
  119. package/src/embedded-react/Pressable.js +2 -8
  120. package/src/embedded-react/SectionList.js +7 -9
  121. package/src/embedded-react/StyleSheet.js +4 -3
  122. package/src/embedded-react/TouchableOpacity.js +13 -8
  123. package/src/embedded-react/index.d.ts +88 -8
  124. package/src/embedded-react/index.js +2 -0
  125. package/src/embedded-react/layout-anim-config.js +10 -4
  126. package/src/embedded-react/list-child.js +5 -5
  127. package/src/embedded-react/named-colors.js +1 -1
  128. package/src/embedded-react/nativeModule.js +462 -0
  129. package/src/embedded-react/split-style.js +11 -11
  130. package/src/embedded-react/svg-ops.js +760 -593
  131. package/src/embedded-react/useHostValue.js +3 -3
  132. package/src/embedded-react/usePersistentState.js +6 -6
  133. package/src/embedded-react/warn-props.js +1 -1
  134. package/src/host-config.js +60 -53
  135. package/src/props.js +49 -41
  136. package/src/renderer.js +7 -4
  137. package/aot/compiler/assemble.mjs +0 -944
  138. package/aot/compiler/c/animations.mjs +0 -436
  139. package/aot/compiler/c/boot.mjs +0 -127
  140. package/aot/compiler/c/expressions.mjs +0 -270
  141. package/aot/compiler/c/functions.mjs +0 -268
  142. package/aot/compiler/c/keyboard.mjs +0 -96
  143. package/aot/compiler/c/nodes.mjs +0 -303
  144. package/aot/compiler/c/pan-responder.mjs +0 -136
  145. package/aot/compiler/c/statements.mjs +0 -319
  146. package/aot/compiler/c/text.mjs +0 -83
  147. package/aot/compiler/c/vectors.mjs +0 -381
  148. package/aot/compiler/c-syntax.mjs +0 -127
@@ -37,44 +37,53 @@
37
37
  // no alignment machinery, so whether an image's pixels landed word-aligned in flash was an accident
38
38
  // of the name strings — it varied build to build. Parsers still accept v1 packs from older tooling.
39
39
 
40
+ const INT8_MIN = -128;
41
+ const INT8_MAX = 127;
42
+ const PIXEL_ALIGNMENT = 4;
43
+ const FORMAT_ARGB8888 = 0;
44
+ const FORMAT_RGB565 = 1;
45
+
40
46
  /** Accumulates little-endian binary chunks. */
41
47
  class Writer {
42
48
  constructor() {
43
49
  this.chunks = [];
44
50
  }
45
- u8(v) {
46
- const b = Buffer.alloc(1);
47
- b.writeUInt8(v & 0xff, 0);
48
- this.chunks.push(b);
51
+ u8(value) {
52
+ const buffer = Buffer.alloc(1);
53
+ buffer.writeUInt8(value & 0xff, 0);
54
+ this.chunks.push(buffer);
49
55
  }
50
- i8(v) {
51
- const b = Buffer.alloc(1);
52
- b.writeInt8(Math.max(-128, Math.min(127, v | 0)), 0);
53
- this.chunks.push(b);
56
+ i8(value) {
57
+ const buffer = Buffer.alloc(1);
58
+ buffer.writeInt8(Math.max(INT8_MIN, Math.min(INT8_MAX, value | 0)), 0);
59
+ this.chunks.push(buffer);
54
60
  }
55
- u16(v) {
56
- const b = Buffer.alloc(2);
57
- b.writeUInt16LE(v & 0xffff, 0);
58
- this.chunks.push(b);
61
+ u16(value) {
62
+ const buffer = Buffer.alloc(2);
63
+ buffer.writeUInt16LE(value & 0xffff, 0);
64
+ this.chunks.push(buffer);
59
65
  }
60
- u32(v) {
61
- const b = Buffer.alloc(4);
62
- b.writeUInt32LE(v >>> 0, 0);
63
- this.chunks.push(b);
66
+ u32(value) {
67
+ const buffer = Buffer.alloc(4);
68
+ buffer.writeUInt32LE(value >>> 0, 0);
69
+ this.chunks.push(buffer);
64
70
  }
65
- str(s) {
66
- const b = Buffer.from(s, 'utf8');
67
- this.u16(b.length);
68
- this.chunks.push(b);
71
+ str(text) {
72
+ const buffer = Buffer.from(text, 'utf8');
73
+ this.u16(buffer.length);
74
+ this.chunks.push(buffer);
69
75
  }
70
- bytes(buf) {
71
- this.chunks.push(Buffer.from(buf));
76
+ bytes(data) {
77
+ this.chunks.push(Buffer.from(data));
72
78
  }
73
79
  /** Zero-pads so the next write lands on an n-byte boundary from the pack start. */
74
- align(n) {
75
- const len = this.chunks.reduce((a, b) => a + b.length, 0);
76
- const pad = (n - (len % n)) % n;
77
- if (pad) this.chunks.push(Buffer.alloc(pad));
80
+ align(alignment) {
81
+ const length = this.chunks.reduce(
82
+ (total, chunk) => total + chunk.length,
83
+ 0,
84
+ );
85
+ const padding = (alignment - (length % alignment)) % alignment;
86
+ if (padding) this.chunks.push(Buffer.alloc(padding));
78
87
  }
79
88
  done() {
80
89
  return Buffer.concat(this.chunks);
@@ -82,13 +91,13 @@ class Writer {
82
91
  }
83
92
 
84
93
  /** Writes one glyph record (9 bytes). */
85
- function writeGlyph(w, g) {
86
- w.u32(g.bitmapOffset);
87
- w.u8(g.width);
88
- w.u8(g.height);
89
- w.i8(g.xOffset);
90
- w.i8(g.yOffset);
91
- w.u8(g.advance);
94
+ function writeGlyph(writer, glyph) {
95
+ writer.u32(glyph.bitmapOffset);
96
+ writer.u8(glyph.width);
97
+ writer.u8(glyph.height);
98
+ writer.i8(glyph.xOffset);
99
+ writer.i8(glyph.yOffset);
100
+ writer.u8(glyph.advance);
92
101
  }
93
102
 
94
103
  /**
@@ -103,57 +112,58 @@ export function emitAssetPack({images = [], fonts = []}) {
103
112
  // Emit in a locale-independent sorted order: the discovery maps upstream are filled by esbuild
104
113
  // onLoad callbacks in whatever order the bundler visits files, which varies run to run — and an
105
114
  // unstable pack means unstable in-flash addresses and non-reproducible builds.
106
- const byName = k => (a, b) => (a[k] < b[k] ? -1 : a[k] > b[k] ? 1 : 0);
115
+ const byName = key => (left, right) =>
116
+ left[key] < right[key] ? -1 : left[key] > right[key] ? 1 : 0;
107
117
  images = [...images].sort(byName('name'));
108
118
  fonts = [...fonts].sort(byName('family'));
109
119
 
110
120
  const version = 2;
111
- const w = new Writer();
112
- w.bytes(Buffer.from('ERPK', 'ascii'));
113
- w.u32(version);
114
- w.u32(images.length);
115
- const fontSizes = fonts.reduce((n, f) => n + f.sizes.length, 0);
116
- w.u32(fontSizes);
121
+ const writer = new Writer();
122
+ writer.bytes(Buffer.from('ERPK', 'ascii'));
123
+ writer.u32(version);
124
+ writer.u32(images.length);
125
+ const fontSizes = fonts.reduce((total, font) => total + font.sizes.length, 0);
126
+ writer.u32(fontSizes);
117
127
 
118
- for (const img of images) {
119
- w.str(img.name);
120
- w.u32(img.width);
121
- w.u32(img.height);
128
+ for (const image of images) {
129
+ writer.str(image.name);
130
+ writer.u32(image.width);
131
+ writer.u32(image.height);
122
132
  if (version >= 2) {
123
- w.u8(img.format === 'rgb565' ? 1 : 0);
124
- w.align(4); // the engine reads the pixels in place; keep the pointer 4-byte aligned
133
+ writer.u8(image.format === 'rgb565' ? FORMAT_RGB565 : FORMAT_ARGB8888);
134
+ writer.align(PIXEL_ALIGNMENT); // the engine reads the pixels in place; keep the pointer 4-byte aligned
125
135
  }
126
136
  // pixels is a Uint32Array (premultiplied ARGB words) or Uint16Array (RGB565);
127
137
  // copy its LE bytes verbatim.
128
- w.bytes(
138
+ writer.bytes(
129
139
  Buffer.from(
130
- img.pixels.buffer,
131
- img.pixels.byteOffset,
132
- img.pixels.byteLength,
140
+ image.pixels.buffer,
141
+ image.pixels.byteOffset,
142
+ image.pixels.byteLength,
133
143
  ),
134
144
  );
135
145
  }
136
146
 
137
147
  for (const font of fonts) {
138
- for (const sz of font.sizes) {
139
- w.str(font.family);
140
- w.u8(sz.pixelSize);
141
- w.u8(sz.lineHeight);
142
- w.u8(sz.baseline);
143
- w.u8(sz.bpp);
144
- w.u16(sz.first);
145
- w.u16(sz.last);
146
- w.u16(sz.dense.length);
147
- w.u16(sz.extras.length);
148
- w.u32(sz.bitmap.length);
149
- for (const g of sz.dense) writeGlyph(w, g);
150
- for (const e of sz.extras) {
151
- w.u32(e.codepoint);
152
- writeGlyph(w, e.info);
148
+ for (const size of font.sizes) {
149
+ writer.str(font.family);
150
+ writer.u8(size.pixelSize);
151
+ writer.u8(size.lineHeight);
152
+ writer.u8(size.baseline);
153
+ writer.u8(size.bpp);
154
+ writer.u16(size.first);
155
+ writer.u16(size.last);
156
+ writer.u16(size.dense.length);
157
+ writer.u16(size.extras.length);
158
+ writer.u32(size.bitmap.length);
159
+ for (const glyph of size.dense) writeGlyph(writer, glyph);
160
+ for (const extra of size.extras) {
161
+ writer.u32(extra.codepoint);
162
+ writeGlyph(writer, extra.info);
153
163
  }
154
- w.bytes(Buffer.from(sz.bitmap));
164
+ writer.bytes(Buffer.from(size.bitmap));
155
165
  }
156
166
  }
157
167
 
158
- return w.done();
168
+ return writer.done();
159
169
  }
@@ -21,6 +21,9 @@
21
21
  /** Fallback pixel size when no fontSize could be discovered and the config pins none. */
22
22
  const DEFAULT_SIZE = 16;
23
23
 
24
+ /** Bits per pixel when the config pins none. */
25
+ const DEFAULT_BPP = 4;
26
+
24
27
  /**
25
28
  * Resolves discovered font imports against their per-project config.
26
29
  *
@@ -32,18 +35,18 @@ const DEFAULT_SIZE = 16;
32
35
  */
33
36
  export function resolveFontJobs(fonts, fontConfig = {}, discoveredSizes = []) {
34
37
  return [...fonts.entries()].map(([family, path]) => {
35
- const fc = fontConfig[family] || {};
38
+ const familyConfig = fontConfig[family] || {};
36
39
  return {
37
40
  path,
38
41
  family,
39
- sizes: fc.sizes?.length
40
- ? fc.sizes
42
+ sizes: familyConfig.sizes?.length
43
+ ? familyConfig.sizes
41
44
  : discoveredSizes.length
42
45
  ? discoveredSizes
43
46
  : [DEFAULT_SIZE],
44
- bpp: fc.bpp ?? 4,
45
- glyphs: fc.glyphs ?? 'ascii',
46
- extraGlyphs: fc.extraGlyphs,
47
+ bpp: familyConfig.bpp ?? DEFAULT_BPP,
48
+ glyphs: familyConfig.glyphs ?? 'ascii',
49
+ extraGlyphs: familyConfig.extraGlyphs,
47
50
  };
48
51
  });
49
52
  }