embedded-react 0.21.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 (99) hide show
  1. package/README.md +2 -2
  2. package/aot/compile.mjs +1 -1
  3. package/aot/compiler/alerts.mjs +604 -0
  4. package/aot/compiler/check.mjs +1 -1
  5. package/aot/compiler/collect.mjs +1 -1
  6. package/aot/compiler/elements/button.mjs +3 -3
  7. package/aot/compiler/elements/image-background.mjs +1 -1
  8. package/aot/compiler/elements/props.mjs +10 -6
  9. package/aot/compiler/elements/section-list.mjs +1 -1
  10. package/aot/compiler/expressions.mjs +29 -2
  11. package/aot/compiler/handlers.mjs +73 -16
  12. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  13. package/aot/compiler/keyboard.mjs +1 -1
  14. package/aot/compiler/lower.mjs +12 -0
  15. package/aot/compiler/nodes.mjs +17 -9
  16. package/aot/compiler/out.mjs +4 -0
  17. package/aot/compiler/package/codegen.mjs +36 -2
  18. package/aot/compiler/package/format.mjs +5 -3
  19. package/aot/compiler/package/lower.mjs +53 -19
  20. package/aot/compiler/scroll-to.mjs +112 -0
  21. package/aot/compiler/style-text.mjs +2 -2
  22. package/aot/compiler/svg.mjs +6 -3
  23. package/aot/compiler/updaters.mjs +1 -0
  24. package/aot/style-map.mjs +44 -1
  25. package/assets/bake-font.mjs +187 -244
  26. package/assets/bake-image.mjs +47 -71
  27. package/assets/bake-svg.mjs +465 -533
  28. package/assets/build-builtin-font.mjs +14 -27
  29. package/assets/emit-c.mjs +124 -204
  30. package/assets/emit-container.mjs +129 -197
  31. package/assets/emit-pack.mjs +92 -136
  32. package/assets/font-config.mjs +19 -27
  33. package/assets/font-sizes.mjs +432 -507
  34. package/assets/glyph-coverage.mjs +170 -214
  35. package/assets/index.mjs +52 -97
  36. package/assets/rasterize.mjs +173 -194
  37. package/assets/svg-loader.mjs +42 -48
  38. package/build.mjs +84 -101
  39. package/cli.mjs +482 -621
  40. package/compile-bin.mjs +24 -36
  41. package/flash.mjs +297 -401
  42. package/hotreload/dev-device.mjs +229 -270
  43. package/hotreload/pack-app.mjs +118 -159
  44. package/hotreload/pack-split.mjs +144 -200
  45. package/hotreload/package-transfer.mjs +128 -131
  46. package/hotreload/protocol.mjs +118 -118
  47. package/hotreload/uploader.mjs +132 -159
  48. package/hotreload/watch-tree.mjs +56 -65
  49. package/pack-container.mjs +93 -123
  50. package/package.json +19 -16
  51. package/persist-transform.mjs +89 -105
  52. package/qjsc-wasm.mjs +47 -72
  53. package/sim/embedded-react.wasm +0 -0
  54. package/sim/index.html +1 -1
  55. package/sim-server.mjs +260 -354
  56. package/src/embedded-react/Alert.mjs +112 -0
  57. package/src/embedded-react/Animated.mjs +412 -0
  58. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  59. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  60. package/src/embedded-react/{Dimensions.js → Dimensions.mjs} +12 -17
  61. package/src/embedded-react/Easing.mjs +34 -0
  62. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  63. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  64. package/src/embedded-react/Keyboard.mjs +82 -0
  65. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  66. package/src/embedded-react/PanResponder.mjs +256 -0
  67. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  68. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  69. package/src/embedded-react/SectionList.mjs +103 -0
  70. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  71. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  72. package/src/embedded-react/background-image.mjs +321 -0
  73. package/src/embedded-react/{components.js → components.mjs} +1 -3
  74. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  75. package/src/embedded-react/index.d.ts +155 -2
  76. package/src/embedded-react/index.js +26 -19
  77. package/src/embedded-react/layout-anim-config.mjs +85 -0
  78. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  79. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  80. package/src/embedded-react/nativeModule.mjs +371 -0
  81. package/src/embedded-react/split-style.mjs +57 -0
  82. package/src/embedded-react/svg-ops.mjs +1075 -0
  83. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  84. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  85. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  86. package/src/host-config.mjs +512 -0
  87. package/src/{native-ui.js → native-ui.mjs} +1 -8
  88. package/src/props.mjs +341 -0
  89. package/src/{renderer.js → renderer.mjs} +30 -44
  90. package/src/embedded-react/Animated.js +0 -440
  91. package/src/embedded-react/Easing.js +0 -39
  92. package/src/embedded-react/PanResponder.js +0 -330
  93. package/src/embedded-react/SectionList.js +0 -146
  94. package/src/embedded-react/layout-anim-config.js +0 -101
  95. package/src/embedded-react/nativeModule.js +0 -462
  96. package/src/embedded-react/split-style.js +0 -58
  97. package/src/embedded-react/svg-ops.js +0 -1295
  98. package/src/host-config.js +0 -548
  99. package/src/props.js +0 -306
@@ -13,20 +13,17 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
-
17
16
  // Build-time image baker: PNG → premultiplied ARGB8888 (the default) or RGB565, the two formats
18
17
  // the engine's image registry references by pointer (er_image_load / er_image_load_rgb565).
19
18
  // Pure JS (pngjs) — no native deps, no Python. The engine scales at render time, so bake at
20
19
  // whatever source resolution you want to ship.
21
20
  import fs from 'node:fs';
22
- import {PNG} from 'pngjs';
23
-
21
+ import { PNG } from 'pngjs';
24
22
  const RGBA_BYTES = 4;
25
23
  const CHANNEL_MAX = 255;
26
24
  const CHANNEL_ROUND = 127;
27
25
  const RGB565_RED_BLUE_MAX = 31;
28
26
  const RGB565_GREEN_MAX = 63;
29
-
30
27
  /**
31
28
  * Decodes an image and returns its baked pixels.
32
29
  *
@@ -34,74 +31,53 @@ const RGB565_GREEN_MAX = 63;
34
31
  * 16-bit RGB565 instead — half the flash and half the source-read bandwidth on every repaint,
35
32
  * meant for opaque full-screen backgrounds. RGB565 has no alpha channel, so a source image with
36
33
  * any non-opaque pixel is rejected with an error rather than silently dropping its transparency.
37
- *
38
- * @param {object} opts
39
- * @param {string} opts.path Path to the source image.
40
- * @param {string} opts.name Asset name an <Image source>/imageName looks up.
41
- * @param {string} [opts.format] 'argb8888' (default) or 'rgb565'.
42
- * @returns {{name:string, width:number, height:number, format:'argb8888'|'rgb565',
43
- * pixels:Uint32Array|Uint16Array}}
44
34
  */
45
- export function bakeImage({path, name, format = 'argb8888'}) {
46
- if (!/\.png$/i.test(path)) {
47
- throw new Error(
48
- `image "${path}": only PNG is supported by the baker (convert to PNG, or extend bake-image.mjs)`,
49
- );
50
- }
51
- if (format !== 'argb8888' && format !== 'rgb565') {
52
- throw new Error(
53
- `image "${name}": unknown format "${format}" (expected "argb8888" or "rgb565")`,
54
- );
55
- }
56
- const png = PNG.sync.read(fs.readFileSync(path));
57
- const {width, height, data} = png; // data = RGBA, 8-bit, row-major
58
-
59
- if (format === 'rgb565') {
60
- const pixels = new Uint16Array(width * height);
35
+ export function bakeImage({ path, name, format = 'argb8888', }) {
36
+ if (!/\.png$/i.test(path)) {
37
+ throw new Error(`image "${path}": only PNG is supported by the baker (convert to PNG, or extend bake-image.mts)`);
38
+ }
39
+ if (format !== 'argb8888' && format !== 'rgb565') {
40
+ throw new Error(`image "${name}": unknown format "${format}" (expected "argb8888" or "rgb565")`);
41
+ }
42
+ const png = PNG.sync.read(fs.readFileSync(path));
43
+ const { width, height, data } = png; // data = RGBA, 8-bit, row-major
44
+ if (format === 'rgb565') {
45
+ const pixels = new Uint16Array(width * height);
46
+ for (let pixel = 0; pixel < width * height; pixel++) {
47
+ const red = data[pixel * RGBA_BYTES];
48
+ const green = data[pixel * RGBA_BYTES + 1];
49
+ const blue = data[pixel * RGBA_BYTES + 2];
50
+ const alpha = data[pixel * RGBA_BYTES + 3];
51
+ if (alpha !== CHANNEL_MAX) {
52
+ const x = pixel % width;
53
+ const y = (pixel - x) / width;
54
+ throw new Error(`image "${name}": rgb565 requires a fully opaque source, but pixel (${x},${y}) has alpha ${alpha} — ` +
55
+ `flatten the art onto its background, or keep the default argb8888 format`);
56
+ }
57
+ // Round-to-nearest 8→5/6/5 bit reduction (the engine bit-replicates back on expand).
58
+ const red5 = Math.round((red * RGB565_RED_BLUE_MAX) / CHANNEL_MAX);
59
+ const green6 = Math.round((green * RGB565_GREEN_MAX) / CHANNEL_MAX);
60
+ const blue5 = Math.round((blue * RGB565_RED_BLUE_MAX) / CHANNEL_MAX);
61
+ pixels[pixel] = ((red5 << 11) | (green6 << 5) | blue5) & 0xffff;
62
+ }
63
+ return { name, width, height, format, pixels };
64
+ }
65
+ const pixels = new Uint32Array(width * height);
61
66
  for (let pixel = 0; pixel < width * height; pixel++) {
62
- const red = data[pixel * RGBA_BYTES];
63
- const green = data[pixel * RGBA_BYTES + 1];
64
- const blue = data[pixel * RGBA_BYTES + 2];
65
- const alpha = data[pixel * RGBA_BYTES + 3];
66
- if (alpha !== CHANNEL_MAX) {
67
- const x = pixel % width;
68
- const y = (pixel - x) / width;
69
- throw new Error(
70
- `image "${name}": rgb565 requires a fully opaque source, but pixel (${x},${y}) has alpha ${alpha} — ` +
71
- `flatten the art onto its background, or keep the default argb8888 format`,
72
- );
73
- }
74
- // Round-to-nearest 8→5/6/5 bit reduction (the engine bit-replicates back on expand).
75
- const red5 = Math.round((red * RGB565_RED_BLUE_MAX) / CHANNEL_MAX);
76
- const green6 = Math.round((green * RGB565_GREEN_MAX) / CHANNEL_MAX);
77
- const blue5 = Math.round((blue * RGB565_RED_BLUE_MAX) / CHANNEL_MAX);
78
- pixels[pixel] = ((red5 << 11) | (green6 << 5) | blue5) & 0xffff;
67
+ const red = data[pixel * RGBA_BYTES];
68
+ const green = data[pixel * RGBA_BYTES + 1];
69
+ const blue = data[pixel * RGBA_BYTES + 2];
70
+ const alpha = data[pixel * RGBA_BYTES + 3];
71
+ // Premultiply the color channels by alpha (round-to-nearest) — the engine's image format.
72
+ const premultipliedRed = Math.floor((red * alpha + CHANNEL_ROUND) / CHANNEL_MAX);
73
+ const premultipliedGreen = Math.floor((green * alpha + CHANNEL_ROUND) / CHANNEL_MAX);
74
+ const premultipliedBlue = Math.floor((blue * alpha + CHANNEL_ROUND) / CHANNEL_MAX);
75
+ pixels[pixel] =
76
+ ((alpha << 24) |
77
+ (premultipliedRed << 16) |
78
+ (premultipliedGreen << 8) |
79
+ premultipliedBlue) >>>
80
+ 0;
79
81
  }
80
- return {name, width, height, format, pixels};
81
- }
82
-
83
- const pixels = new Uint32Array(width * height);
84
- for (let pixel = 0; pixel < width * height; pixel++) {
85
- const red = data[pixel * RGBA_BYTES];
86
- const green = data[pixel * RGBA_BYTES + 1];
87
- const blue = data[pixel * RGBA_BYTES + 2];
88
- const alpha = data[pixel * RGBA_BYTES + 3];
89
- // Premultiply the color channels by alpha (round-to-nearest) — the engine's image format.
90
- const premultipliedRed = Math.floor(
91
- (red * alpha + CHANNEL_ROUND) / CHANNEL_MAX,
92
- );
93
- const premultipliedGreen = Math.floor(
94
- (green * alpha + CHANNEL_ROUND) / CHANNEL_MAX,
95
- );
96
- const premultipliedBlue = Math.floor(
97
- (blue * alpha + CHANNEL_ROUND) / CHANNEL_MAX,
98
- );
99
- pixels[pixel] =
100
- ((alpha << 24) |
101
- (premultipliedRed << 16) |
102
- (premultipliedGreen << 8) |
103
- premultipliedBlue) >>>
104
- 0;
105
- }
106
- return {name, width, height, format, pixels};
82
+ return { name, width, height, format, pixels };
107
83
  }