@geastack/geatsc-plugin-gea 0.1.23 → 0.1.24

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.
@@ -6,6 +6,9 @@ import path from 'node:path';
6
6
  // escape their declaration/import/indexed-read paths.
7
7
  export function sourceLiteralResolver(files, initiallyOpaque) {
8
8
  const sources = new Map([...files].filter(([file]) => !/\.css$/i.test(file)).map(([file, text]) => [file, ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS)]));
9
+ // Ownership by identity: the program hands back these very SourceFiles, but
10
+ // with fileName normalized to forward slashes, which no Windows key matches.
11
+ const owned = new Set(sources.values());
9
12
  const variables = new Map();
10
13
  const properties = new Map();
11
14
  const arrays = new Set(), escapedArrays = new Set();
@@ -92,7 +95,7 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
92
95
  symbol = typeChecker().getAliasedSymbol(symbol);
93
96
  const declaration = symbol?.valueDeclaration;
94
97
  return declaration && ts.isVariableDeclaration(declaration) && ts.isIdentifier(declaration.name) &&
95
- sources.has(declaration.getSourceFile().fileName) && ts.isVariableDeclarationList(declaration.parent) &&
98
+ owned.has(declaration.getSourceFile()) && ts.isVariableDeclarationList(declaration.parent) &&
96
99
  (declaration.parent.flags & ts.NodeFlags.Const) ? declaration : undefined;
97
100
  };
98
101
  const localReceiver = (node, seen = new Set()) => {
@@ -116,14 +119,14 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
116
119
  symbol = typeChecker().getAliasedSymbol(symbol);
117
120
  const exported = symbol?.valueDeclaration;
118
121
  return !!exported && ts.isExportAssignment(exported) &&
119
- sources.has(exported.getSourceFile().fileName) && localReceiver(exported.expression, seen);
122
+ owned.has(exported.getSourceFile()) && localReceiver(exported.expression, seen);
120
123
  }
121
124
  if (ts.isNewExpression(node)) {
122
125
  let symbol = typeChecker().getSymbolAtLocation(node.expression);
123
126
  if (symbol && (symbol.flags & ts.SymbolFlags.Alias))
124
127
  symbol = typeChecker().getAliasedSymbol(symbol);
125
128
  const declaration = symbol?.valueDeclaration;
126
- if (!declaration || !ts.isClassDeclaration(declaration) || !sources.has(declaration.getSourceFile().fileName))
129
+ if (!declaration || !ts.isClassDeclaration(declaration) || !owned.has(declaration.getSourceFile()))
127
130
  return false;
128
131
  // A constructor returning another object breaks the local-instance proof.
129
132
  let returnsObject = false;
@@ -160,7 +163,7 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
160
163
  if (ts.isCallExpression(node) && (ts.isPropertyAccessExpression(node.expression) || ts.isElementAccessExpression(node.expression)) && localReceiver(node.expression.expression)) {
161
164
  const declaration = typeChecker().getResolvedSignature(node)?.declaration;
162
165
  // An opaque method receives the object implicitly through `this`.
163
- if (!declaration || !sources.has(declaration.getSourceFile().fileName) ||
166
+ if (!declaration || !owned.has(declaration.getSourceFile()) ||
164
167
  !(ts.isMethodDeclaration(declaration) || ts.isFunctionDeclaration(declaration) || ts.isFunctionExpression(declaration) || ts.isArrowFunction(declaration)))
165
168
  opaque = true;
166
169
  }
@@ -266,7 +269,7 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
266
269
  return undefined;
267
270
  const at = ts.isPropertyAccessExpression(node) ? node.name : ts.isElementAccessExpression(node) ? node.argumentExpression : node;
268
271
  const symbol = at && typeChecker().getSymbolAtLocation(at);
269
- if (!symbol?.declarations?.some(declaration => sources.has(declaration.getSourceFile().fileName) &&
272
+ if (!symbol?.declarations?.some(declaration => owned.has(declaration.getSourceFile()) &&
270
273
  (ts.isPropertyDeclaration(declaration) || ts.isGetAccessorDeclaration(declaration) || ts.isPropertyAssignment(declaration))))
271
274
  return undefined;
272
275
  const key = 'property:' + name;
@@ -332,7 +335,7 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
332
335
  if (symbol && (symbol.flags & ts.SymbolFlags.Alias))
333
336
  symbol = typeChecker().getAliasedSymbol(symbol);
334
337
  const declarations = symbol?.declarations;
335
- if (declarations?.length && declarations.every(declaration => sources.has(declaration.getSourceFile().fileName) && ts.isFunctionDeclaration(declaration) && !!declaration.body)) {
338
+ if (declarations?.length && declarations.every(declaration => owned.has(declaration.getSourceFile()) && ts.isFunctionDeclaration(declaration) && !!declaration.body)) {
336
339
  let reassigned = false;
337
340
  const checkWrites = (child) => {
338
341
  if (ts.isBinaryExpression(child) && child.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
@@ -360,7 +363,7 @@ export function sourceLiteralResolver(files, initiallyOpaque) {
360
363
  return false;
361
364
  const name = ts.isPropertyAccessExpression(access) ? access.name : access.argumentExpression;
362
365
  const declarations = name && typeChecker().getSymbolAtLocation(name)?.declarations;
363
- return !!declarations?.length && declarations.every(declaration => sources.has(declaration.getSourceFile().fileName) && ts.isMethodDeclaration(declaration) && !!declaration.body);
366
+ return !!declarations?.length && declarations.every(declaration => owned.has(declaration.getSourceFile()) && ts.isMethodDeclaration(declaration) && !!declaration.body);
364
367
  },
365
368
  });
366
369
  }
@@ -47,7 +47,7 @@ export function addNodeAuxFeatures(file, text, features, isNumeric) {
47
47
  const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/i.test(file) ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
48
48
  const unknown = () => addUnknownNodeAux(features);
49
49
  const token = (name) => {
50
- if (/^(?:addEventListener|removeEventListener|setEventListener|dispatchEvent|on[A-Z].*|on(?:click|pointer.*|touch.*|input|keydown|keyup|scroll)|click|touchstart|touchmove|touchend|pointerdown|pointermove|pointerup|input|keydown|keyup|scroll)$/.test(name))
50
+ if (/^(?:addEventListener|removeEventListener|setEventListener|dispatchEvent|on[A-Z].*|on(?:click|pointer.*|touch.*|input|keydown|keyup|scroll)|click|touchstart|touchmove|touchend|pointerdown|pointermove|pointerup|input|change|keydown|keyup|scroll)$/.test(name))
51
51
  features.add('node-listeners');
52
52
  if (/^(?:id|dataset|attributes|getElementById|querySelector|querySelectorAll|ensureAppRoot|setAttribute|getAttribute|removeAttribute|hasAttribute|toggleAttribute|setPressId|setPressValue|pressId|pressValue|data-press-id|data-press-value)$/.test(name))
53
53
  features.add('node-attributes');
@@ -1,3 +1,4 @@
1
+ import path from 'node:path';
1
2
  import ts from 'typescript';
2
3
  // This proof is intentionally narrower than "no JSX". The canvas frame/boot
3
4
  // path omits document refresh and service callbacks, so every executable import
@@ -20,26 +21,32 @@ const canvasModule = /^(?:gea-embedded|@geastack\/core)$/;
20
21
  export function inferCanvasOnly(sources, unknown) {
21
22
  if (unknown || !sources.size)
22
23
  return false;
24
+ // Keyed by resolved path: TypeScript asks the host for `C:/app/index.tsx`
25
+ // where discovery recorded `C:\app\index.tsx`, and a missed lookup left the
26
+ // checker binding no file at all on Windows.
27
+ const key = (file) => path.resolve(file);
23
28
  const files = new Map();
29
+ const texts = new Map();
24
30
  for (const [file, text] of sources) {
25
31
  if (!/\.[cm]?[jt]sx?$/.test(file))
26
32
  return false;
27
33
  const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, /\.[jt]sx$/.test(file) ? ts.ScriptKind.TSX : /\.[cm]?js$/.test(file) ? ts.ScriptKind.JS : ts.ScriptKind.TS);
28
34
  if (source.parseDiagnostics?.length)
29
35
  return false;
30
- files.set(file, source);
36
+ files.set(key(file), source);
37
+ texts.set(key(file), text);
31
38
  }
32
39
  // Binding local names avoids both a host-global blacklist (which misses new
33
40
  // APIs) and false positives for ordinary app methods named fetch/document.
34
41
  // No library or filesystem resolution: discovery already owns the graph.
35
42
  const options = { noLib: true, noResolve: true, types: [], allowJs: true, target: ts.ScriptTarget.Latest };
36
43
  const host = ts.createCompilerHost(options);
37
- host.getSourceFile = file => files.get(file);
44
+ host.getSourceFile = file => files.get(key(file));
38
45
  host.resolveModuleNames = names => names.map(() => undefined);
39
46
  host.directoryExists = () => false;
40
47
  host.getDirectories = () => [];
41
- host.fileExists = file => files.has(file);
42
- host.readFile = file => sources.get(file);
48
+ host.fileExists = file => files.has(key(file));
49
+ host.readFile = file => texts.get(key(file));
43
50
  const checker = ts.createProgram([...files.keys()], options, host).getTypeChecker();
44
51
  let safe = true;
45
52
  let display = false;
package/dist/analyze.js CHANGED
@@ -70,6 +70,7 @@ export function analyzeSourceHostBindings(entry) {
70
70
  addBindingsForGeaEmbeddedImports(text, bindings);
71
71
  addBindingsForEmbeddedHostNames(text, bindings);
72
72
  addBindingsForHostGlobals(text, bindings);
73
+ addMediaCapabilities(file, text, bindings, features);
73
74
  addFeaturesForUrlSchemes(text, features);
74
75
  if (analyzeWorkerModules(file, text).realms)
75
76
  features.add('worker-realms');
@@ -113,6 +114,7 @@ const importBindingNames = new Map([
113
114
  // WiFi/network bring-up binding so the TCP/IP stack is initialized.
114
115
  ['http', 'wifi'],
115
116
  ['Accelerometer', 'imu'],
117
+ ['Magnetometer', 'imu'],
116
118
  ['Audio', 'audio'],
117
119
  ['Display', 'display'],
118
120
  ['Memory', 'memory'],
@@ -124,6 +126,7 @@ const importBindingNames = new Map([
124
126
  ]);
125
127
  const embeddedHostNamePrefixes = [
126
128
  ['__gea_Accelerometer', 'imu'],
129
+ ['__gea_Magnetometer', 'imu'],
127
130
  ['__gea_audioContext', 'audio'],
128
131
  ['__gea_Audio', 'audio'],
129
132
  ['__gea_Display', 'display'],
@@ -184,6 +187,32 @@ function addBindingsForHostGlobals(text, bindings) {
184
187
  bindings.add(binding);
185
188
  }
186
189
  }
190
+ function addMediaCapabilities(file, text, bindings, features) {
191
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
192
+ const visit = (node) => {
193
+ if (ts.isCallExpression(node) && node.expression.getText(source) === 'navigator.mediaDevices.getUserMedia') {
194
+ const constraints = node.arguments[0];
195
+ for (const kind of ['audio', 'video']) {
196
+ const property = constraints && ts.isObjectLiteralExpression(constraints)
197
+ ? constraints.properties.find(member => member.name && member.name.getText(source).replace(/['"]/g, '') === kind)
198
+ : undefined;
199
+ const requested = !constraints || !ts.isObjectLiteralExpression(constraints) ||
200
+ (property && (!ts.isPropertyAssignment(property) || property.initializer.kind !== ts.SyntaxKind.FalseKeyword));
201
+ if (requested) {
202
+ if (kind === 'video')
203
+ bindings.add('camera');
204
+ else
205
+ features.add('audio-capture');
206
+ }
207
+ }
208
+ }
209
+ if (ts.isNewExpression(node) && /^(?:(?:window|globalThis)\.)?(?:AudioContext|PcmAudioStream|Audio)$/.test(node.expression.getText(source))) {
210
+ features.add('audio-playback');
211
+ }
212
+ ts.forEachChild(node, visit);
213
+ };
214
+ visit(source);
215
+ }
187
216
  // Only a quoted `https://` counts: a bare one is almost always a comment
188
217
  // citing a source, and linking mbedtls for a comment would cost every app
189
218
  // that documents itself ~100 KB of flash and the TLS heap at first use.
package/dist/cpp-ir.js CHANGED
@@ -1915,9 +1915,7 @@ function canvasInteropSource(usesCanvas, directCanvas) {
1915
1915
  " for (int i = 0;; i++) {",
1916
1916
  " auto c = node.childAt(i);",
1917
1917
  " if (!c.valid()) break;",
1918
- " const auto &__gea_child_node = __gea_tree.node(c.id());",
1919
- " const std::string __gea_child_tag = gea::embedded::ui::tagFromId(__gea_child_node.tag_id);",
1920
- ' if (__gea_child_node.type == gea::embedded::ui::NodeType::Text || __gea_child_tag == "#comment" || __gea_child_tag == "#fragment" || __gea_child_tag == "#document-frag" || __gea_child_tag == "#document-fragment") continue;',
1918
+ " if (static_cast<int>(c.nodeType) != 1) continue;",
1921
1919
  " kids.push_back(nodeValue(c));",
1922
1920
  " }",
1923
1921
  " return gea_cpp_value(kids);",
@@ -1940,6 +1938,7 @@ function canvasInteropSource(usesCanvas, directCanvas) {
1940
1938
  " },",
1941
1939
  " [node](const std::string &key, gea_cpp_value assigned_value) {",
1942
1940
  " const std::string value = nodeStringArg(assigned_value);",
1941
+ ' if (key == "disabled") { node.setDisabled(gea::runtime::coerce::to_boolean(gea_cpp_key(assigned_value))); return; }',
1943
1942
  ' if (key == "className") {',
1944
1943
  " node.classList().set(value);",
1945
1944
  " return;",
@@ -1966,13 +1965,7 @@ function canvasInteropSource(usesCanvas, directCanvas) {
1966
1965
  "// node representations resolve these properties identically.",
1967
1966
  "inline double domNodeType(gea::embedded::ui::NodeHandle node) {",
1968
1967
  " if (!node) return 0.0;",
1969
- " const auto &__gea_tree = gea::embedded::ui::Tree::instance();",
1970
- " const auto &__gea_n = __gea_tree.node(node.id());",
1971
- ' if (std::string(gea::embedded::ui::tagFromId(__gea_n.tag_id)) == "#comment") return 8.0;',
1972
- " if (__gea_n.type == gea::embedded::ui::NodeType::Text) return 3.0;",
1973
- " const std::string __gea_tag = gea::embedded::ui::tagFromId(__gea_n.tag_id);",
1974
- ' if (__gea_tag == "#fragment" || __gea_tag == "#document-frag" || __gea_tag == "#document-fragment") return 11.0;',
1975
- " return 1.0;",
1968
+ " return static_cast<double>(static_cast<int>(node.nodeType));",
1976
1969
  "}",
1977
1970
  "",
1978
1971
  "inline gea_cpp_value domParentNode(gea::embedded::ui::NodeHandle node) {",
@@ -2044,13 +2037,13 @@ function canvasInteropSource(usesCanvas, directCanvas) {
2044
2037
  " return gea_cpp_key(gea::runtime::host::document());",
2045
2038
  "}",
2046
2039
  "",
2047
- "inline gea_cpp_value domFirstChild(gea::embedded::ui::NodeHandle node) {",
2048
- " gea::embedded::ui::NodeHandle child = node.firstChildHandle();",
2049
- " return child.valid() ? nodeValue(child) : gea_cpp_value::null_v();",
2040
+ "inline gea::embedded::ui::NodeHandle domFirstChild(gea::embedded::ui::NodeHandle node) {",
2041
+ " return node.firstChildHandle();",
2050
2042
  "}",
2051
2043
  "",
2052
2044
  "inline gea_cpp_value domFirstChild(const gea_cpp_value &node) {",
2053
- " return domFirstChild(gea::embedded::ui::NodeHandle(nodeIdFromValue(node)));",
2045
+ " const auto child = domFirstChild(gea::embedded::ui::NodeHandle(nodeIdFromValue(node)));",
2046
+ " return child.valid() ? nodeValue(child) : gea_cpp_value::null_v();",
2054
2047
  "}",
2055
2048
  "",
2056
2049
  "// `node.nextSibling`: typed NodeHandle (not boxed) so the compiled-component",
@@ -61,8 +61,10 @@ const geaGeolocationHostMethods = [
61
61
  'clearWatch',
62
62
  ];
63
63
  const geaInputHostMethods = ['consumeBackButton'];
64
- const geaUartHostMethods = ['open', 'isOpen', 'close', 'read', 'write', 'available', 'writable'];
65
64
  const geaGpioHostMethods = ['configureOutput', 'configureInput', 'write', 'read'];
65
+ const geaMagnetometerHostMethods = ['open', 'close', 'count', 'read'];
66
+ const geaEspNowHostMethods = ['open', 'isOpen', 'canSend', 'setMaxTxPower', 'getMaxTxPower', 'close', 'addPeer', 'send', 'receive'];
67
+ const geaUartHostMethods = ['open', 'isOpen', 'close', 'read', 'write', 'available', 'writable'];
66
68
  const geaLedHostMethods = ['set', 'off', 'attach', 'setPixel', 'show', 'detach'];
67
69
  const geaClockHostMethods = ['epochMs', 'setEpochMs'];
68
70
  const geaProfilerHostMethods = ['nowUs', 'nowCycles'];
@@ -132,6 +134,10 @@ const rawGeaHostExternDeclarations = Object.fromEntries([
132
134
  ['gea::host::Storage', geaHostDeclarations],
133
135
  ['gea::host::window.innerWidth', geaHostDeclarations],
134
136
  ['gea::host::window.innerHeight', geaHostDeclarations],
137
+ ['gea::host::window.addEventListener', geaHostDeclarations],
138
+ ['gea::host::window.removeEventListener', geaHostDeclarations],
139
+ ['gea::embedded::ui::Document::instance().addEventListener({args})', geaHostDeclarations],
140
+ ['gea::embedded::ui::Document::instance().removeEventListener({args})', geaHostDeclarations],
135
141
  ['gea::host::navigator.userAgent', geaHostDeclarations],
136
142
  ['gea::host::navigator.language', geaHostDeclarations],
137
143
  ['gea::host::navigator.platform', geaHostDeclarations],
@@ -140,8 +146,10 @@ const rawGeaHostExternDeclarations = Object.fromEntries([
140
146
  ...geaTouchHostMethods.map((method) => [`gea::host::touch.${method}`, geaHostDeclarations]),
141
147
  ...geaMemoryHostMethods.map((method) => [`gea::host::Memory.${method}`, geaHostDeclarations]),
142
148
  ...geaInputHostMethods.map((method) => [`gea::host::Input.${method}`, geaHostDeclarations]),
143
- ...geaUartHostMethods.map((method) => [`gea::host::Uart.${method}`, geaHostDeclarations]),
144
149
  ...geaGpioHostMethods.map((method) => [`gea::host::Gpio.${method}`, geaHostDeclarations]),
150
+ ...geaMagnetometerHostMethods.map((method) => [`gea::host::Magnetometer.${method}`, geaHostDeclarations]),
151
+ ...geaEspNowHostMethods.map((method) => [`gea::host::EspNow.${method}`, geaHostDeclarations]),
152
+ ...geaUartHostMethods.map((method) => [`gea::host::Uart.${method}`, geaHostDeclarations]),
145
153
  ...geaLedHostMethods.map((method) => [`gea::host::Led.${method}`, geaHostDeclarations]),
146
154
  ...geaClockHostMethods.map((method) => [`gea::host::Clock.${method}`, geaHostDeclarations]),
147
155
  ...geaProfilerHostMethods.map((method) => [`gea::host::Profiler.${method}`, geaHostDeclarations]),
@@ -24,6 +24,8 @@ const NODE_HANDLE_RECEIVER_TYPES = [
24
24
  "GeaCanvasElement",
25
25
  "GeaCameraElement",
26
26
  "VirtualListElement",
27
+ "ButtonElement",
28
+ "InputElement",
27
29
  ];
28
30
  // Receiver type names for the event a listener is handed. One native struct
29
31
  // backs every gea event (`gea::framework::events::PointerEvent`), so the
@@ -271,6 +273,12 @@ export function createGeaHostShims() {
271
273
  // gea runtime is written against all lower to that one concrete handle, so
272
274
  // component templates flow as `NodeHandle` end-to-end with no `gea_cpp_value`
273
275
  // record bridge.
276
+ nativeReferenceIdentities: [
277
+ "gea::embedded::ui::NodeHandle",
278
+ "gea::embedded::ui::ChildNodeList",
279
+ "gea::framework::events::EventTarget",
280
+ "gea::framework::events::PointerEvent",
281
+ ],
274
282
  nativeTypes: {
275
283
  // The ambient DOM global `document` (lib.dom.d.ts's `Document`) — a
276
284
  // singleton, not a tree node, so it gets its own storage rather than
@@ -289,6 +297,7 @@ export function createGeaHostShims() {
289
297
  // property-access callee resolve SOME carrier.
290
298
  Document: "gea::embedded::ui::Document",
291
299
  Node: "gea::embedded::ui::NodeHandle",
300
+ NodeList: "gea::embedded::ui::ChildNodeList",
292
301
  ChildNode: "gea::embedded::ui::NodeHandle",
293
302
  ParentNode: "gea::embedded::ui::NodeHandle",
294
303
  Element: "gea::embedded::ui::NodeHandle",
@@ -349,6 +358,7 @@ export function createGeaHostShims() {
349
358
  // attribute). v1 emitted exactly this:
350
359
  // `event.currentTarget.getAttribute("value")`.
351
360
  InputEventTarget: "gea::framework::events::EventTarget",
361
+ GeaWindow: "gea::host::WindowFacade",
352
362
  PressEventTarget: "gea::framework::events::EventTarget",
353
363
  // gea-embedded's own element interfaces (index.d.ts) — without these a
354
364
  // `Component<GeaCanvasElement>`'s `this.el` lowers to a record-alias struct
@@ -364,6 +374,8 @@ export function createGeaHostShims() {
364
374
  // `VirtualListElement | null` field is not a node at all, and its
365
375
  // `rowHeight`/`scrollTop` reads fall to the dynamic path.
366
376
  VirtualListElement: "gea::embedded::ui::NodeHandle",
377
+ ButtonElement: "gea::embedded::ui::NodeHandle",
378
+ InputElement: "gea::embedded::ui::NodeHandle",
367
379
  // The result of `fetch(...)` flows as the concrete C++ struct (which carries
368
380
  // `ok`/`status`/`body` data members plus `text()`/`bytes()`/`arrayBuffer()`
369
381
  // methods), not a `gea_cpp_value` record — so `await fetch(url).arrayBuffer()`
@@ -515,10 +527,7 @@ export function createGeaHostShims() {
515
527
  },
516
528
  hostNamespaces: {
517
529
  navigator: "gea::host::navigator",
518
- // The viewport globals. `gea::host::window` is a real facade object
519
- // (packages/host/include/host/window.h) whose `innerWidth`/`innerHeight`
520
- // are METHODS, which is why they are listed as accessors below --
521
- // `navigator`'s siblings are plain fields and are not.
530
+ // Fixed singleton member paths are native host calls, alongside its value carrier.
522
531
  window: "gea::host::window",
523
532
  image: "image",
524
533
  // Async tile/image loader (second-core worker: SD read -> HTTP fetch ->
@@ -560,8 +569,10 @@ export function createGeaHostShims() {
560
569
  __gea_Display: "gea::host::Display",
561
570
  __gea_Memory: "gea::host::Memory",
562
571
  __gea_Input: "gea::host::Input",
563
- __gea_Uart: "gea::host::Uart",
564
572
  __gea_Gpio: "gea::host::Gpio",
573
+ __gea_EspNow: "gea::host::EspNow",
574
+ __gea_Magnetometer: "gea::host::Magnetometer",
575
+ __gea_Uart: "gea::host::Uart",
565
576
  __gea_Led: "gea::host::Led",
566
577
  __gea_Clock: "gea::host::Clock",
567
578
  __gea_Haptics: "gea::host::Haptics",
@@ -584,6 +595,10 @@ export function createGeaHostShims() {
584
595
  Display: { moduleSpecifier: "/", exportName: "Display" },
585
596
  },
586
597
  hostNamespaceMethods: {
598
+ window: {
599
+ addEventListener: "gea::host::window.addEventListener",
600
+ removeEventListener: "gea::host::window.removeEventListener",
601
+ },
587
602
  // Free functions in `gea::host::console` (geatsc's `gea_runtime.h`
588
603
  // declares them unconditionally, outside any `GEA_HOST_DECLARED` guard,
589
604
  // so they are reachable from a gea build too). `warn`/`info`/`debug` are
@@ -1298,6 +1313,29 @@ export function createGeaHostShims() {
1298
1313
  write: "gea::host::Gpio.write",
1299
1314
  read: "gea::host::Gpio.read",
1300
1315
  },
1316
+ __gea_Gpio: {
1317
+ configureOutput: "gea::host::Gpio.configureOutput",
1318
+ configureInput: "gea::host::Gpio.configureInput",
1319
+ write: "gea::host::Gpio.write",
1320
+ read: "gea::host::Gpio.read",
1321
+ },
1322
+ __gea_Magnetometer: {
1323
+ open: "gea::host::Magnetometer.open",
1324
+ close: "gea::host::Magnetometer.close",
1325
+ count: "gea::host::Magnetometer.count",
1326
+ read: "gea::host::Magnetometer.read",
1327
+ },
1328
+ __gea_EspNow: {
1329
+ open: "gea::host::EspNow.open",
1330
+ isOpen: "gea::host::EspNow.isOpen",
1331
+ canSend: "gea::host::EspNow.canSend",
1332
+ setMaxTxPower: "gea::host::EspNow.setMaxTxPower",
1333
+ getMaxTxPower: "gea::host::EspNow.getMaxTxPower",
1334
+ close: "gea::host::EspNow.close",
1335
+ addPeer: "gea::host::EspNow.addPeer",
1336
+ send: "gea::host::EspNow.send",
1337
+ receive: "gea::host::EspNow.receive",
1338
+ },
1301
1339
  __gea_Uart: {
1302
1340
  open: "gea::host::Uart.open",
1303
1341
  isOpen: "gea::host::Uart.isOpen",
@@ -1307,12 +1345,6 @@ export function createGeaHostShims() {
1307
1345
  available: "gea::host::Uart.available",
1308
1346
  writable: "gea::host::Uart.writable",
1309
1347
  },
1310
- __gea_Gpio: {
1311
- configureOutput: "gea::host::Gpio.configureOutput",
1312
- configureInput: "gea::host::Gpio.configureInput",
1313
- write: "gea::host::Gpio.write",
1314
- read: "gea::host::Gpio.read",
1315
- },
1316
1348
  Led: {
1317
1349
  set: "gea::host::Led.set",
1318
1350
  off: "gea::host::Led.off",
@@ -1392,8 +1424,10 @@ export function createGeaHostShims() {
1392
1424
  Input: ["consumeBackButton"],
1393
1425
  __gea_Input: ["consumeBackButton"],
1394
1426
  Gpio: ["configureOutput", "configureInput", "write", "read"],
1395
- __gea_Uart: ["open", "isOpen", "close", "available", "writable"],
1396
1427
  __gea_Gpio: ["configureOutput", "configureInput", "write", "read"],
1428
+ __gea_EspNow: ["open", "isOpen", "canSend", "setMaxTxPower", "getMaxTxPower", "close"],
1429
+ __gea_Magnetometer: ["open", "close", "count"],
1430
+ __gea_Uart: ["open", "isOpen", "close", "available", "writable"],
1397
1431
  Led: ["set", "off", "attach", "setPixel", "show", "detach"],
1398
1432
  __gea_Led: ["set", "off", "attach", "setPixel", "show", "detach"],
1399
1433
  Clock: ["epochMs"],
@@ -1626,15 +1660,10 @@ export function createGeaHostShims() {
1626
1660
  emit: "gea::embedded::ui::Document::instance().createDocumentFragment()",
1627
1661
  returnType: "gea::embedded::ui::NodeHandle",
1628
1662
  },
1629
- // The embedded UI has no comment node, and does not need one: every use of
1630
- // `createComment` in the framework is a SENTINEL — a non-rendering node
1631
- // parked in the tree so a later `insertBefore` has a stable anchor
1632
- // (`conditional-truthy.ts`'s `sentinel`, the keyed-list row anchors). An
1633
- // empty text node is exactly that on this target: it occupies a position,
1634
- // renders nothing, and is a real `NodeHandle`. Without a binding here the
1635
- // call had no plan at all and took its whole function out of the program.
1663
+ // Structural comments retain their data and insertion identity without
1664
+ // becoming text, layout boxes, paint commands or pointer targets.
1636
1665
  createComment: {
1637
- emit: "gea::embedded::ui::Document::instance().createText(({arg0}))",
1666
+ emit: "gea::embedded::ui::Document::instance().createComment(({arg0}))",
1638
1667
  returnType: "gea::embedded::ui::NodeHandle",
1639
1668
  },
1640
1669
  },
@@ -1655,6 +1684,11 @@ export function createGeaHostShims() {
1655
1684
  // `document.body.appendChild(node)` refused at emission ("Document.body
1656
1685
  // is claimed by no host member table"), which is the fail-closed guard
1657
1686
  // correctly naming the missing statement.
1687
+ activeElement: [{
1688
+ emit: "gea::embedded::ui::Document::instance().activeElement()",
1689
+ returnType: "gea::embedded::ui::NodeHandle",
1690
+ receiverTypes: ["gea::embedded::ui::Document", "Document"],
1691
+ }],
1658
1692
  body: [
1659
1693
  {
1660
1694
  emit: "gea::embedded::ui::Document::instance().body()",
@@ -1683,6 +1717,8 @@ export function createGeaHostShims() {
1683
1717
  receiverTypes: EVENT_RECEIVER_TYPES,
1684
1718
  },
1685
1719
  ],
1720
+ button: [{ emit: "static_cast<double>(({receiver}).button)", returnType: "double", receiverTypes: EVENT_RECEIVER_TYPES }],
1721
+ buttons: [{ emit: "static_cast<double>(({receiver}).buttons)", returnType: "double", receiverTypes: EVENT_RECEIVER_TYPES }],
1686
1722
  pointerId: [
1687
1723
  {
1688
1724
  emit: "static_cast<double>(({receiver}).pointerId)",
@@ -1721,6 +1757,71 @@ export function createGeaHostShims() {
1721
1757
  receiverTypes: EVENT_RECEIVER_TYPES,
1722
1758
  },
1723
1759
  ],
1760
+ defaultPrevented: [
1761
+ {
1762
+ emit: "static_cast<bool>(({receiver}).defaultPrevented)",
1763
+ returnType: "bool",
1764
+ receiverTypes: EVENT_RECEIVER_TYPES,
1765
+ },
1766
+ ],
1767
+ // Typed native keyboard carrier fields, populated by the host. No
1768
+ // reconstructed browser records or permissive synthetic defaults.
1769
+ key: [
1770
+ {
1771
+ emit: "(({receiver}).key)",
1772
+ returnType: "std::string",
1773
+ receiverTypes: EVENT_RECEIVER_TYPES,
1774
+ },
1775
+ ],
1776
+ code: [
1777
+ {
1778
+ emit: "(({receiver}).code)",
1779
+ returnType: "std::string",
1780
+ receiverTypes: EVENT_RECEIVER_TYPES,
1781
+ },
1782
+ ],
1783
+ altKey: [
1784
+ {
1785
+ emit: "(({receiver}).altKey)",
1786
+ returnType: "bool",
1787
+ receiverTypes: EVENT_RECEIVER_TYPES,
1788
+ },
1789
+ ],
1790
+ ctrlKey: [
1791
+ {
1792
+ emit: "(({receiver}).ctrlKey)",
1793
+ returnType: "bool",
1794
+ receiverTypes: EVENT_RECEIVER_TYPES,
1795
+ },
1796
+ ],
1797
+ metaKey: [
1798
+ {
1799
+ emit: "(({receiver}).metaKey)",
1800
+ returnType: "bool",
1801
+ receiverTypes: EVENT_RECEIVER_TYPES,
1802
+ },
1803
+ ],
1804
+ shiftKey: [
1805
+ {
1806
+ emit: "(({receiver}).shiftKey)",
1807
+ returnType: "bool",
1808
+ receiverTypes: EVENT_RECEIVER_TYPES,
1809
+ },
1810
+ ],
1811
+ repeat: [
1812
+ {
1813
+ emit: "(({receiver}).repeat)",
1814
+ returnType: "bool",
1815
+ receiverTypes: EVENT_RECEIVER_TYPES,
1816
+ },
1817
+ ],
1818
+ isComposing: [
1819
+ {
1820
+ emit: "(({receiver}).isComposing)",
1821
+ returnType: "bool",
1822
+ receiverTypes: EVENT_RECEIVER_TYPES,
1823
+ },
1824
+ ],
1724
1825
  // The node an event names. Both are real members of the engine's event
1725
1826
  // struct, so the getter is the member read itself -- but it must be
1726
1827
  // STATED, because without a row here the emitter has no spelling for
@@ -1950,17 +2051,37 @@ export function createGeaHostShims() {
1950
2051
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
1951
2052
  },
1952
2053
  ],
2054
+ disabled: [{ emit: "gea::embedded::ui::NodeHandle({receiver}).disabled()", returnType: "bool", receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES] }],
2055
+ isConnected: [
2056
+ {
2057
+ emit: "gea::embedded::ui::NodeHandle({receiver}).isConnected()",
2058
+ returnType: "bool",
2059
+ receiverTypes: EVENT_TARGET_RECEIVER_TYPES,
2060
+ },
2061
+ {
2062
+ emit: "({receiver}).isConnected()",
2063
+ returnType: "bool",
2064
+ receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2065
+ },
2066
+ ],
1953
2067
  nodeType: [
1954
2068
  {
1955
- emit: "gea_ir::domNodeType({receiver})",
2069
+ emit: "static_cast<double>(static_cast<int>(({receiver}).nodeType))",
1956
2070
  returnType: "double",
1957
2071
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
1958
2072
  },
1959
2073
  ],
1960
2074
  parentNode: [
1961
2075
  {
1962
- emit: "gea_ir::domParentNode({receiver})",
1963
- returnType: "gea_cpp_value",
2076
+ emit: "({receiver}).parentHandle()",
2077
+ returnType: "gea::embedded::ui::NodeHandle",
2078
+ receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2079
+ },
2080
+ ],
2081
+ lastElementChild: [
2082
+ {
2083
+ emit: "({receiver}).lastElementChildHandle()",
2084
+ returnType: "gea::embedded::ui::NodeHandle",
1964
2085
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
1965
2086
  },
1966
2087
  ],
@@ -1992,8 +2113,8 @@ export function createGeaHostShims() {
1992
2113
  ],
1993
2114
  firstChild: [
1994
2115
  {
1995
- emit: "gea_ir::domFirstChild({receiver})",
1996
- returnType: "gea_cpp_value",
2116
+ emit: "({receiver}).firstChildHandle()",
2117
+ returnType: "gea::embedded::ui::NodeHandle",
1997
2118
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
1998
2119
  },
1999
2120
  ],
@@ -2010,14 +2131,14 @@ export function createGeaHostShims() {
2010
2131
  ],
2011
2132
  childNodes: [
2012
2133
  {
2013
- emit: "gea_ir::domChildNodes({receiver})",
2014
- returnType: "gea_cpp_value",
2134
+ emit: "({receiver}).childNodesHandle()",
2135
+ returnType: "gea::embedded::ui::ChildNodeList",
2015
2136
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2016
2137
  },
2017
2138
  ],
2018
2139
  children: [
2019
2140
  {
2020
- emit: "gea_ir::domChildren({receiver})",
2141
+ emit: "({receiver}).elementChildren()",
2021
2142
  returnType: "std::vector<gea::embedded::ui::NodeHandle>",
2022
2143
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2023
2144
  },
@@ -2188,6 +2309,7 @@ export function createGeaHostShims() {
2188
2309
  },
2189
2310
  ],
2190
2311
  length: [
2312
+ { emit: "static_cast<double>(({receiver}).length())", returnType: "double", receiverTypes: ["gea::embedded::ui::ChildNodeList", "NodeList"] },
2191
2313
  {
2192
2314
  emit: "({receiver}).getLength()",
2193
2315
  returnType: "double",
@@ -2289,6 +2411,7 @@ export function createGeaHostShims() {
2289
2411
  // The write half of the two scroll offsets above. `setScrollTop` narrows
2290
2412
  // to the engine's `int`, exactly as the dynamic path already does before
2291
2413
  // calling the same setter.
2414
+ disabled: [{ emit: "gea::embedded::ui::NodeHandle({receiver}).setDisabled({value})", returnType: "void", receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES] }],
2292
2415
  scrollTop: [
2293
2416
  {
2294
2417
  emit: "gea::embedded::ui::Tree::instance().setScrollTop(({receiver}).id(), static_cast<int>({value}))",
@@ -2363,6 +2486,13 @@ export function createGeaHostShims() {
2363
2486
  emit: "({receiver}).value = {value}",
2364
2487
  receiverTypes: ["gea::host::AudioParam", "AudioParam"],
2365
2488
  },
2489
+ // ButtonElement.value reflects the actual node attribute; it is not
2490
+ // a label mutation or an event. NodeHandle guards allocation lifetime.
2491
+ {
2492
+ emit: 'gea::embedded::ui::NodeHandle({receiver}).setAttribute(std::string("value"), {value})',
2493
+ receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2494
+ returnType: "void",
2495
+ },
2366
2496
  ],
2367
2497
  // The recorder's two callbacks. `MediaRecorder.ondataavailable` and
2368
2498
  // `.onstop` are DECLARED settable (`core/index.d.ts`: `ondataavailable:
@@ -2550,6 +2680,8 @@ export function createGeaHostShims() {
2550
2680
  // setTimeout"). Naming the spelling makes the call
2551
2681
  // `gea::host::setTimeout(cb, ms)`, which is the function the engine
2552
2682
  // actually exports.
2683
+ // Promise jobs and author microtasks share one FIFO, not a zero-delay timer.
2684
+ queueMicrotask: "gea::detail::queuePromiseJob",
2553
2685
  setTimeout: "gea::host::setTimeout",
2554
2686
  clearTimeout: "gea::host::clearTimeout",
2555
2687
  setInterval: "gea::host::setInterval",
@@ -2818,6 +2950,11 @@ export function createGeaHostShims() {
2818
2950
  // returnType-only bindings (no `emit`) keep the normal direct method-call
2819
2951
  // emit; receiverTypes bound the match to FetchResponse.
2820
2952
  nativeMemberMethods: {
2953
+ item: [{ emit: "({receiver}).item({arg0})", returnType: "gea::embedded::ui::NodeHandle", receiverTypes: ["gea::embedded::ui::ChildNodeList", "NodeList"] }],
2954
+ matches: [{ receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES], emit: "gea::embedded::ui::NodeHandle({receiver}).matches({arg0})", returnType: "bool" }],
2955
+ closest: [{ receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES], emit: "gea::embedded::ui::NodeHandle({receiver}).closest({arg0})", returnType: "gea::embedded::ui::NodeHandle" }],
2956
+ querySelector: [{ receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES], emit: "gea::embedded::ui::NodeHandle({receiver}).querySelector({arg0})", returnType: "gea::embedded::ui::NodeHandle" }],
2957
+ querySelectorAll: [{ receiverTypes: [...NODE_HANDLE_RECEIVER_TYPES, ...EVENT_TARGET_RECEIVER_TYPES], emit: "gea::embedded::ui::NodeHandle({receiver}).querySelectorAll({arg0})", returnType: "std::vector<gea::embedded::ui::NodeHandle>" }],
2821
2958
  // `Event.preventDefault()` / `.stopPropagation()` (index.d.ts:269-270),
2822
2959
  // which every event interface inherits. Both are real methods on the
2823
2960
  // engine's own event struct -- `PointerEvent::preventDefault` /
@@ -2876,31 +3013,7 @@ export function createGeaHostShims() {
2876
3013
  // `document` identifier. The receiver carrier and operation role are
2877
3014
  // authenticated by host-runtime-v1 before this physical symbol is used.
2878
3015
  addEventListener: [
2879
- {
2880
- receiverTypes: ["gea::embedded::ui::Document"],
2881
- emit: "gea::runtime::host::geaDocumentAddEventListener({receiver}, {arg0}, {arg1})",
2882
- returnType: "gea_cpp_value",
2883
- dynamicRecordSchemas: [
2884
- {
2885
- protocolId: "gea.pointer-event-record-v1",
2886
- fields: [{ key: "target", value: "checker-carrier" }],
2887
- },
2888
- ],
2889
- argumentRoles: [
2890
- "dynamic-value",
2891
- {
2892
- kind: "callback",
2893
- parameters: [
2894
- {
2895
- kind: "dynamic-record",
2896
- protocolId: "gea.pointer-event-record-v1",
2897
- },
2898
- ],
2899
- result: "void",
2900
- lifetime: "retained",
2901
- },
2902
- ],
2903
- },
3016
+ { receiverTypes: ["gea::embedded::ui::Document"], emit: "gea::embedded::ui::Document::instance().addEventListener({args})", returnType: "void" },
2904
3017
  // The same member on a NODE, which is a different receiver carrier and
2905
3018
  // therefore a different physical symbol -- `el.addEventListener('touchstart',
2906
3019
  // handler)` written imperatively on a `Component<GeaCanvasElement>`'s `this.el`,
@@ -2933,38 +3046,32 @@ export function createGeaHostShims() {
2933
3046
  returnType: "void",
2934
3047
  },
2935
3048
  ],
3049
+ // Options are ordinary configuration properties; callback and event carriers stay typed.
3050
+ removeEventListener: [
3051
+ { receiverTypes: ["gea::embedded::ui::Document"], emit: "gea::embedded::ui::Document::instance().removeEventListener({args})", returnType: "void" },
3052
+ ],
2936
3053
  appendChild: [
2937
3054
  {
2938
3055
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2939
3056
  emit: "gea_ir::domAppendChild({receiver}, {arg0})",
2940
3057
  },
2941
3058
  ],
2942
- // `Node.insertBefore(newNode, referenceNode)` — argument order maps
2943
- // straight onto `domInsertBefore(parent, child, reference)`
2944
- // (`compiler/packages/geatsc/src/targets/cpp/runtime/host_document_gea.cpp`,
2945
- // namespace `gea::runtime::host`, fully typed `NodeHandle` params, `void`
2946
- // result — a perfect fit for a receiver-carrying flat symbol call). This
2947
- // is geatsc's OWN runtime, not a `gea_ir`-generated overload: there is no
2948
- // `gea_ir::domInsertBefore` (the doc comment at `cpp-ir.ts:1826-1827`
2949
- // documents only `domNextSibling`'s role in feeding `container.
2950
- // insertBefore(ref, ...)`'s reference argument, not a codegen'd
2951
- // `insertBefore` binding itself), so this entry is qualified with the
2952
- // runtime's real namespace instead of the plugin-generated one.
3059
+ // The actual native facade preserves allocation identity, validates the
3060
+ // reference and returns the inserted node (including an emptied Fragment).
2953
3061
  insertBefore: [
2954
3062
  {
2955
3063
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2956
- emit: "gea::runtime::host::domInsertBefore({receiver}, {arg0}, {arg1})",
2957
- returnType: "void",
3064
+ emit: "({receiver}).insertBefore({arg0}, {arg1})",
3065
+ returnType: "gea::embedded::ui::NodeHandle",
2958
3066
  },
2959
3067
  ],
2960
- // `parent.removeChild(child)`. The engine models removal on the CHILD
2961
- // (`NodeHandle::remove()`), so the runtime helper validates the parent and
2962
- // detaches the child; void, matching appendChild/insertBefore above.
3068
+ // The actual facade validates both allocation owners/direct parent,
3069
+ // detaches without retiring, and returns the same native child handle.
2963
3070
  removeChild: [
2964
3071
  {
2965
3072
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
2966
- emit: "gea::runtime::host::domRemoveChild({receiver}, {arg0})",
2967
- returnType: "void",
3073
+ emit: "({receiver}).removeChild({arg0})",
3074
+ returnType: "gea::embedded::ui::NodeHandle",
2968
3075
  },
2969
3076
  ],
2970
3077
  // `parent.replaceChild(replacement, child)`. Keep both operands on the
@@ -3051,7 +3158,7 @@ export function createGeaHostShims() {
3051
3158
  focus: [
3052
3159
  {
3053
3160
  receiverTypes: NODE_HANDLE_RECEIVER_TYPES,
3054
- emit: "({receiver}).focus()",
3161
+ emit: "({receiver}).focus({args})",
3055
3162
  returnType: "void",
3056
3163
  },
3057
3164
  ],
package/dist/types.d.ts CHANGED
@@ -19,6 +19,7 @@ export interface HostShimDefinitions {
19
19
  declarationFileName: string;
20
20
  }>;
21
21
  nativeTypes?: Record<string, string>;
22
+ nativeReferenceIdentities?: string[];
22
23
  /** Identity-preserving views: destination carrier -> source carrier -> {value} template. */
23
24
  nativeViews?: Record<string, Record<string, string>>;
24
25
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/geatsc-plugin-gea",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "Gea IR backend plugin for geatsc.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -53,7 +53,8 @@
53
53
  "typescript": "^5.9.3"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/node": "^22.15.3"
56
+ "@types/node": "^22.15.3",
57
+ "livekit-client": "2.22.3"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "@geastack/compiler": ">=1.0.22"