@gramlot/gramlot 0.3.35 → 0.3.37

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 (117) hide show
  1. package/dist/components/charts/__init__.py +1 -1
  2. package/dist/components/charts/assets/collection.js +9 -9
  3. package/dist/components/charts/assets/index.js +1 -1
  4. package/dist/components/charts/grammar.json +0 -30
  5. package/dist/components/drawing/__init__.py +1 -1
  6. package/dist/components/drawing/assets/collection.js +3 -3
  7. package/dist/components/drawing/assets/index.js +1 -1
  8. package/dist/components/editors/__init__.py +2 -2
  9. package/dist/components/editors/assets/collection.js +4 -2
  10. package/dist/components/editors/assets/index.js +1 -1
  11. package/dist/components/editors/assets/modules/addon-fit-L6JK4OJX.js +12 -0
  12. package/dist/components/editors/assets/modules/xterm-BF3OSWRI.js +286 -0
  13. package/dist/components/editors/assets/modules/xterm-UBEXZEYY.js +47 -0
  14. package/dist/components/editors/grammar.json +207 -0
  15. package/dist/components/grid/__init__.py +1 -1
  16. package/dist/components/grid/assets/collection.js +6 -6
  17. package/dist/components/grid/assets/index.js +1 -1
  18. package/dist/components/grid/grammar.json +0 -2
  19. package/dist/components/inputs/__init__.py +1 -1
  20. package/dist/components/inputs/assets/collection.js +8 -8
  21. package/dist/components/inputs/assets/index.js +1 -1
  22. package/dist/components/inputs/grammar.json +2 -1
  23. package/dist/components/layout/__init__.py +1 -1
  24. package/dist/components/layout/assets/collection.js +9 -9
  25. package/dist/components/layout/assets/index.js +1 -1
  26. package/dist/components/layout/grammar.json +2 -2
  27. package/dist/components/selection_trial/__init__.py +1 -1
  28. package/dist/components/selection_trial/assets/collection.js +3 -3
  29. package/dist/components/selection_trial/assets/index.js +1 -1
  30. package/dist/components/tree/__init__.py +1 -1
  31. package/dist/components/tree/assets/collection.js +6 -6
  32. package/dist/components/tree/assets/index.js +1 -1
  33. package/dist/components/tree/grammar.json +0 -1
  34. package/dist/components/uploads/__init__.py +1 -1
  35. package/dist/components/uploads/assets/collection.js +3 -3
  36. package/dist/components/uploads/assets/index.js +1 -1
  37. package/dist/components/uploads/grammar.json +0 -3
  38. package/dist/gramlot.js +1238 -627
  39. package/dist/gramlot.min.js +45 -45
  40. package/dist/libraries.json +27 -0
  41. package/dist/standard-collections.js +1 -1
  42. package/package.json +4 -3
  43. package/src/binding/data-binder.js +11 -3
  44. package/src/binding/grid-struct.js +7 -4
  45. package/src/binding/runtime.js +203 -46
  46. package/src/builder/binding.json +23 -1
  47. package/src/builder/gramlot-builder.d.ts +1 -4
  48. package/src/builder/source.js +185 -29
  49. package/src/chat.js +26 -20
  50. package/src/components/attachment-manager.js +38 -34
  51. package/src/components/chart-data-view.js +4 -7
  52. package/src/components/chart-fields.js +18 -6
  53. package/src/components/chart-renderer.js +10 -3
  54. package/src/components/chart-timeline.js +7 -5
  55. package/src/components/charts.js +74 -67
  56. package/src/components/check-box-text-editor.js +3 -3
  57. package/src/components/check-box-text.js +7 -22
  58. package/src/components/check-box-tree.js +20 -16
  59. package/src/components/choice-editor.js +1 -1
  60. package/src/components/drawing.js +47 -34
  61. package/src/components/editors.js +3 -1
  62. package/src/components/grid-cell-editor.js +72 -29
  63. package/src/components/grid-column-filters.js +47 -40
  64. package/src/components/grid-formulas.js +22 -17
  65. package/src/components/grid-header-interaction.js +9 -11
  66. package/src/components/grid-row-interaction.js +25 -24
  67. package/src/components/grid-row-layout.js +28 -29
  68. package/src/components/grid-search-box.js +3 -3
  69. package/src/components/grid-search.js +3 -8
  70. package/src/components/grid-selection.js +33 -29
  71. package/src/components/grid-structure.js +48 -10
  72. package/src/components/grid-tools.js +14 -14
  73. package/src/components/grid.js +83 -79
  74. package/src/components/image-crop-dialog.js +2 -2
  75. package/src/components/image-crop.js +16 -9
  76. package/src/components/image-uploader.js +21 -28
  77. package/src/components/inputs.js +19 -1
  78. package/src/components/registry.js +3 -5
  79. package/src/components/terminal.js +158 -0
  80. package/src/components/tray-pane.js +85 -61
  81. package/src/components/tree.js +332 -239
  82. package/src/components/upload-engine.js +10 -2
  83. package/src/components/uploader.js +31 -27
  84. package/src/editing-session.d.ts +4 -1
  85. package/src/editing-session.js +120 -83
  86. package/src/experiments/window-selection.js +4 -6
  87. package/src/filesystem.js +2 -2
  88. package/src/gramlot.js +1 -0
  89. package/src/handlers/device-handler.js +219 -213
  90. package/src/handlers/rpc-handler.d.ts +17 -0
  91. package/src/handlers/rpc-handler.js +22 -0
  92. package/src/ide-documents.js +29 -11
  93. package/src/ide-runtime.js +33 -31
  94. package/src/index-page-runtime.d.ts +2 -2
  95. package/src/index-page-runtime.js +67 -48
  96. package/src/libraries.js +9 -0
  97. package/src/message-port-connection.js +100 -0
  98. package/src/message-port-store.js +158 -0
  99. package/src/page-store-connection.js +14 -1
  100. package/src/renderer/gramlot-renderer.js +21 -2
  101. package/src/source-picker.d.ts +2 -2
  102. package/src/source-picker.js +15 -6
  103. package/src/stores/bag-collection-store.js +25 -7
  104. package/src/stores/bag-collection-view.js +23 -22
  105. package/src/view/controls.js +1 -1
  106. package/src/view/html.js +45 -20
  107. package/src/visual-editor-canvas.js +1 -1
  108. package/src/visual-editor.js +18 -19
  109. package/tools/gramlot-tools-inspector.js +400 -374
  110. package/tools/inspector-agent.js +223 -49
  111. package/dist/components/vizabi/__init__.py +0 -13
  112. package/dist/components/vizabi/assets/collection.js +0 -4
  113. package/dist/components/vizabi/assets/index.js +0 -3
  114. package/dist/components/vizabi/commands.json +0 -7
  115. package/dist/components/vizabi/grammar.json +0 -128
  116. package/src/components/vizabi-session.js +0 -66
  117. package/src/components/vizabi.js +0 -66
@@ -4,6 +4,7 @@ import {Handler} from './handler.js';
4
4
  import {DeviceResolver} from '../binding/device-resolver.js';
5
5
 
6
6
  const NAMES = ['appinfo', 'location'];
7
+ const DEVICE = '_gramlot.device';
7
8
  const ERROR_STATUS = {UNAVAILABLE: 'unavailable', PERMISSION_DENIED: 'denied',
8
9
  TIMEOUT: 'error', FAILED: 'error', CANCELLED: 'cancelled'};
9
10
 
@@ -30,6 +31,7 @@ export class DeviceHandler extends Handler {
30
31
  #pushEvents = null;
31
32
  #shortcutEvents = null;
32
33
  #linkEvents = null;
34
+ #registration = null;
33
35
 
34
36
  constructor(gramlot) {
35
37
  super(gramlot);
@@ -37,7 +39,6 @@ export class DeviceHandler extends Handler {
37
39
  this.disposed = false;
38
40
  this.monitor = null;
39
41
  this.retiring = null;
40
- this.resolvers = new Map();
41
42
  this.cleanup = Promise.resolve();
42
43
  }
43
44
 
@@ -49,8 +50,7 @@ export class DeviceHandler extends Handler {
49
50
  gramlot.data.setItem(`_gramlot.device.${name}`, null,
50
51
  {enabled: false, watching: false, status: 'idle', error: null});
51
52
  gramlot.data.getNode(`_gramlot.device.${name}`).setAttr({error: null}, false, true, false);
52
- this.#sensors.set(name, {node: gramlot.data.getNode(`_gramlot.device.${name}`),
53
- stream: null, cleanup: Promise.resolve()});
53
+ this.#sensors.set(name, {stream: null, cleanup: Promise.resolve()});
54
54
  }
55
55
  for (const name of NAMES) {
56
56
  const path = `_gramlot.device.${name}`;
@@ -59,30 +59,22 @@ export class DeviceHandler extends Handler {
59
59
  gramlot.data.setItem(path, null);
60
60
  const node = gramlot.data.getNode(path);
61
61
  node.setAttr(attrs, false, true, false);
62
- const resolver = new DeviceResolver(this, name, attrs.cacheTime);
63
- node.resolver = resolver;
64
- this.resolvers.set(name, resolver);
62
+ node.resolver = new DeviceResolver(this, name, attrs.cacheTime);
65
63
  }
66
64
  gramlot.data.setItem('_gramlot.device.clipboard', null,
67
65
  {status: 'idle', error: null, text: '', copy: null, paste: null, operation: null});
68
- const clipboard = gramlot.data.getNode('_gramlot.device.clipboard');
69
66
  gramlot.data.setItem('_gramlot.device.camera', null, {status: 'idle', error: null, capture: null, choose: null});
70
- const camera = gramlot.data.getNode('_gramlot.device.camera');
71
67
  gramlot.data.setItem('_gramlot.device.barcode', null, {status: 'idle', error: null, scan: null});
72
- const barcode = gramlot.data.getNode('_gramlot.device.barcode');
73
68
  gramlot.data.setItem('_gramlot.device.biometrics', null, {status: 'idle', error: null, verify: null});
74
- const biometrics = gramlot.data.getNode('_gramlot.device.biometrics');
75
69
  const notifications = new Bag();
76
70
  notifications.setItem('request', new Bag());
77
71
  for (const name of ['scheduled', 'received', 'action']) notifications.setItem(name, null);
78
72
  gramlot.data.setItem('_gramlot.device.notifications', notifications,
79
73
  {status: 'idle', error: null, schedule: null, listening: false, listenerError: null});
80
- const notificationNode = gramlot.data.getNode('_gramlot.device.notifications');
81
74
  const push = new Bag();
82
75
  for (const name of ['registration', 'received', 'action']) push.setItem(name, null);
83
76
  gramlot.data.setItem('_gramlot.device.push', push,
84
77
  {status: 'idle', error: null, register: null, listening: false, listenerError: null});
85
- const pushNode = gramlot.data.getNode('_gramlot.device.push');
86
78
  const links = new Bag();
87
79
  links.setItem('request', null);
88
80
  gramlot.data.setItem('_gramlot.device.links', links, {listening: false, listenerError: null});
@@ -97,66 +89,57 @@ export class DeviceHandler extends Handler {
97
89
  gramlot.data.setItem('_gramlot.device.lifecycle', lifecycle, {status: 'idle', error: null, listening: false});
98
90
  gramlot.data.setItem('_gramlot.device.haptics', null,
99
91
  {status: 'idle', error: null, impact: null, style: 'medium', vibrate: null, duration: 600});
100
- const haptics = gramlot.data.getNode('_gramlot.device.haptics');
101
92
  gramlot.data.setItem('_gramlot.device.audio', null,
102
93
  {status: 'idle', error: null, recording: false, start: null, stop: null, cancel: null,
103
94
  share: null, shareStatus: 'idle', shareError: null, shareActivity: null});
104
- const audio = gramlot.data.getNode('_gramlot.device.audio');
105
- gramlot.data.subscribe('gramlot.device', {update: event => {
106
- if (this.disposed) return;
107
- for (const [name, sensor] of this.#sensors) {
108
- if (event.node === sensor.node && event.attrs_diff?.enabled) {
109
- if (typeof sensor.node.attr.enabled !== 'boolean') throw new TypeError('Device enabled must be boolean');
110
- this.#reconcileSensor(name, sensor);
111
- }
112
- }
113
- if (event.node === clipboard && event.fired) {
114
- if (event.attrs_diff?.copy?.new === true) this.#clipboardCommand(clipboard, 'copy');
115
- if (event.attrs_diff?.paste?.new === true) this.#clipboardCommand(clipboard, 'paste');
116
- }
117
- if (event.node === audio && event.fired) {
118
- if (event.attrs_diff?.start?.new === true) this.#startAudio(audio);
119
- if (event.attrs_diff?.stop?.new === true) this.#stopAudio(audio);
120
- if (event.attrs_diff?.cancel?.new === true) this.#cancelAudio(audio);
121
- if (event.attrs_diff?.share?.new === true) this.#shareAudio(audio);
122
- }
123
- if (event.node === haptics && event.fired && event.attrs_diff?.impact?.new === true) {
124
- this.#impact(haptics);
125
- }
126
- if (event.node === haptics && event.fired && event.attrs_diff?.vibrate?.new === true) {
127
- this.#vibrate(haptics);
128
- }
129
- if (event.node === barcode && event.fired && event.attrs_diff?.scan?.new === true) {
130
- this.#scanBarcode(barcode);
131
- }
132
- if (event.node === camera && event.fired && event.attrs_diff?.choose?.new === true) {
133
- this.#photo(camera, 'choose');
134
- }
135
- if (event.node === camera && event.fired && event.attrs_diff?.capture?.new === true) {
136
- this.#photo(camera, 'capture');
137
- }
138
- if (event.node === biometrics && event.fired && event.attrs_diff?.verify?.new === true) {
139
- this.#verifyBiometrics(biometrics);
140
- }
141
- if (event.node === notificationNode && event.fired && event.attrs_diff?.schedule?.new === true) {
142
- this.#scheduleNotification(notificationNode);
143
- }
144
- if (event.node === pushNode && event.fired && event.attrs_diff?.register?.new === true) {
145
- this.#registerPush(pushNode);
95
+ // Commands and settings arrive as Data events at their device path; no device node is retained.
96
+ this.#registration = gramlot.src.binding.router.register({path: DEVICE, subtree: true,
97
+ recipient: {receive: change => this.#receive(change)}});
98
+ }
99
+
100
+ /** The device node at `_gramlot.device.<name>`, read at each use. */
101
+ #deviceNode(name) { return this.gramlot.data.getNode(`${DEVICE}.${name}`); }
102
+
103
+ #receive(change) {
104
+ if (this.disposed || !change.evt.startsWith('upd')) return;
105
+ const segments = change.path.split('.');
106
+ if (segments.length !== 3) return;
107
+ const name = segments[2], diff = change.attrsDiff ?? {};
108
+ const command = attribute => change.fired && diff[attribute]?.new === true;
109
+ const node = change.node;
110
+ if (this.#sensors.has(name) && diff.enabled) {
111
+ if (typeof node.attr.enabled !== 'boolean') throw new TypeError('Device enabled must be boolean');
112
+ this.#reconcileSensor(name);
113
+ }
114
+ if (name === 'clipboard') {
115
+ if (command('copy')) this.#clipboardCommand('copy');
116
+ if (command('paste')) this.#clipboardCommand('paste');
117
+ }
118
+ if (name === 'audio') {
119
+ if (command('start')) this.#startAudio();
120
+ if (command('stop')) this.#stopAudio();
121
+ if (command('cancel')) this.#cancelAudio();
122
+ if (command('share')) this.#shareAudio();
123
+ }
124
+ if (name === 'haptics' && command('impact')) this.#impact();
125
+ if (name === 'haptics' && command('vibrate')) this.#vibrate();
126
+ if (name === 'barcode' && command('scan')) this.#scanBarcode();
127
+ if (name === 'camera' && command('choose')) this.#photo('choose');
128
+ if (name === 'camera' && command('capture')) this.#photo('capture');
129
+ if (name === 'biometrics' && command('verify')) this.#verifyBiometrics();
130
+ if (name === 'notifications' && command('schedule')) this.#scheduleNotification();
131
+ if (name === 'push' && command('register')) this.#registerPush();
132
+ if (NAMES.includes(name)) {
133
+ const {cacheTime} = node.attr;
134
+ if (typeof cacheTime !== 'number' || !Number.isFinite(cacheTime) || (cacheTime < 0 && cacheTime !== -1)) {
135
+ throw new TypeError('Device cacheTime must be -1 or a nonnegative number of seconds');
146
136
  }
147
- for (const resolver of this.resolvers.values()) {
148
- if (event.node !== resolver._node) continue;
149
- const {cacheTime} = event.node.attr;
150
- if (typeof cacheTime !== 'number' || !Number.isFinite(cacheTime) || (cacheTime < 0 && cacheTime !== -1)) {
151
- throw new TypeError('Device cacheTime must be -1 or a nonnegative number of seconds');
152
- }
153
- resolver.cacheTime = cacheTime;
154
- if (resolver.name === 'location') {
155
- if (typeof event.node.attr.enabled !== 'boolean') throw new TypeError('Device enabled must be boolean');
156
- this.reconcile();
157
- }
137
+ this.resolver(name).cacheTime = cacheTime;
138
+ if (name === 'location') {
139
+ if (typeof node.attr.enabled !== 'boolean') throw new TypeError('Device enabled must be boolean');
140
+ this.reconcile();
158
141
  }
159
- }});
142
+ }
160
143
  }
161
144
 
162
145
  /** Attach the explicitly selected provider once, before the page reads device values. */
@@ -199,16 +182,16 @@ export class DeviceHandler extends Handler {
199
182
  node.setAttr({status: 'success', error: null}, true, true, false);
200
183
  });
201
184
  if (provider.capabilities.includes('links')) {
202
- this.#startLinkEvents(this.gramlot.data.getNode('_gramlot.device.links'));
185
+ this.#startLinkEvents();
203
186
  }
204
187
  if (provider.capabilities.includes('shortcuts')) {
205
- this.#startShortcutEvents(this.gramlot.data.getNode('_gramlot.device.shortcuts'));
188
+ this.#startShortcutEvents();
206
189
  }
207
190
  if (provider.capabilities.includes('push')) {
208
- this.#startPushEvents(this.gramlot.data.getNode('_gramlot.device.push'));
191
+ this.#startPushEvents();
209
192
  }
210
193
  if (provider.capabilities.includes('notifications')) {
211
- this.#startNotificationEvents(this.gramlot.data.getNode('_gramlot.device.notifications'));
194
+ this.#startNotificationEvents();
212
195
  }
213
196
  }
214
197
 
@@ -218,8 +201,9 @@ export class DeviceHandler extends Handler {
218
201
 
219
202
  resolver(name) {
220
203
  this.assertLive();
221
- if (!this.resolvers.has(name)) throw new TypeError(`Unknown device value: ${name}`);
222
- return this.resolvers.get(name);
204
+ const node = NAMES.includes(name) ? this.#deviceNode(name) : null;
205
+ if (!node) throw new TypeError(`Unknown device value: ${name}`);
206
+ return node.resolver;
223
207
  }
224
208
 
225
209
  invalidate(name) { this.resolver(name).reset(); }
@@ -231,64 +215,67 @@ export class DeviceHandler extends Handler {
231
215
  const request = {revision: resolver.revision, received: resolver.received};
232
216
  resolver.request = request;
233
217
  this.attributes(resolver, {status: 'pending', error: null});
218
+ // The continuations read the resolver at its path again; a disposed handler is never read.
219
+ const current = () => this.resolver(name);
234
220
  Promise.resolve().then(() => {
235
- if (this.disposed || resolver.request !== request) return;
221
+ if (this.disposed || current().request !== request) return;
236
222
  this.requireCapability(name);
237
223
  return name === 'appinfo' ? this.provider.readAppInfo() : this.provider.readLocation();
238
224
  }).then(value => {
239
- if (this.disposed || resolver.request !== request) return;
240
- this.accept(resolver, value);
225
+ if (this.disposed || current().request !== request) return;
226
+ this.accept(current(), value);
241
227
  // Invalidation while pending retains the arriving result, but leaves it stale.
242
- if (resolver.revision !== request.revision) resolver._lastUpdate = null;
228
+ if (current().revision !== request.revision) current()._lastUpdate = null;
243
229
  }).catch(error => {
244
- if (!this.disposed && resolver.request === request && resolver.received === request.received) {
245
- this.failure(resolver, error);
230
+ if (!this.disposed && current().request === request && current().received === request.received) {
231
+ this.failure(current(), error);
246
232
  }
247
233
  }).finally(() => {
248
- if (resolver.request === request) resolver.request = null;
234
+ if (!this.disposed && current().request === request) current().request = null;
249
235
  });
250
236
  }
251
237
 
252
238
  // Page-owned state streams share lifetime/error handling, never public dispatch.
253
239
  #startStateEvents(name, start, accept) {
254
- const node = this.gramlot.data.getNode(`_gramlot.device.${name}`);
240
+ const node = () => this.#deviceNode(name);
255
241
  if (!this.provider.capabilities.includes(name)) {
256
- node.setAttr(failureAttributes({code: 'UNAVAILABLE', message: `${name} is unavailable`}), true, true, false);
242
+ node().setAttr(failureAttributes({code: 'UNAVAILABLE', message: `${name} is unavailable`}), true, true, false);
257
243
  return;
258
244
  }
259
245
  const events = {controller: new AbortController()};
260
246
  this.#stateEvents.set(name, events);
261
- node.setAttr({status: 'pending', error: null}, true, true, false);
247
+ node().setAttr({status: 'pending', error: null}, true, true, false);
262
248
  events.start = Promise.resolve().then(() => {
263
249
  if (events.controller.signal.aborted) return async () => {};
264
250
  return start(value => {
265
251
  if (events.controller.signal.aborted) return;
266
- try { accept(node, value); }
267
- catch (error) { node.setAttr(failureAttributes(error), true, true, false); }
252
+ try { accept(node(), value); }
253
+ catch (error) { node().setAttr(failureAttributes(error), true, true, false); }
268
254
  }, events.controller.signal);
269
255
  }).then(stop => {
270
- if (!events.controller.signal.aborted) node.setAttr({listening: true}, true, true, false);
256
+ if (!events.controller.signal.aborted) node().setAttr({listening: true}, true, true, false);
271
257
  return stop;
272
258
  });
273
259
  events.start.catch(error => {
274
260
  const aborted = events.controller.signal.aborted;
275
261
  events.controller.abort();
276
- if (!aborted) node.setAttr({...failureAttributes(error), listening: false}, true, true, false);
262
+ if (!aborted) node().setAttr({...failureAttributes(error), listening: false}, true, true, false);
277
263
  });
278
264
  }
279
265
 
280
- #reconcileSensor(name, sensor) {
281
- const {node} = sensor;
282
- if (!node.attr.enabled) {
266
+ #reconcileSensor(name) {
267
+ const sensor = this.#sensors.get(name);
268
+ const node = () => this.#deviceNode(name);
269
+ if (!node().attr.enabled) {
283
270
  const stream = sensor.stream;
284
271
  if (!stream) return;
285
272
  sensor.stream = null;
286
273
  stream.controller.abort();
287
274
  sensor.cleanup = stream.start.then(stop => stop(), () => undefined).then(() => {
288
- if (!this.disposed && !sensor.stream) node.setAttr({watching: false, status: 'idle', error: null}, true, true, false);
275
+ if (!this.disposed && !sensor.stream) node().setAttr({watching: false, status: 'idle', error: null}, true, true, false);
289
276
  });
290
277
  sensor.cleanup.catch(error => {
291
- if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
278
+ if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
292
279
  });
293
280
  return;
294
281
  }
@@ -302,78 +289,80 @@ export class DeviceHandler extends Handler {
302
289
  if (this.disposed || stream.controller.signal.aborted) return;
303
290
  try {
304
291
  if (event?.kind === 'state' && typeof event.watching === 'boolean') {
305
- node.setAttr({watching: event.watching, status: event.watching ? 'pending' : 'idle', error: null}, true, true, false);
292
+ node().setAttr({watching: event.watching, status: event.watching ? 'pending' : 'idle', error: null}, true, true, false);
306
293
  } else if (event?.kind === 'sample') {
307
294
  for (const field of ['x', 'y', 'z', 'timestamp']) {
308
295
  if (!Number.isFinite(event[field])) throw new TypeError(`Invalid ${name}.${field}`);
309
296
  }
310
- if (!node.attr.watching) return;
311
- if (node.staticValue && event.timestamp < node.staticValue.getItem('timestamp')) return;
297
+ if (!node().attr.watching) return;
298
+ if (node().staticValue && event.timestamp < node().staticValue.getItem('timestamp')) return;
312
299
  const value = new Bag();
313
300
  for (const field of ['x', 'y', 'z', 'timestamp']) value.setItem(field, event[field]);
314
- node.setValue(value, true, {status: 'success', error: null}, true, false);
301
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
315
302
  } else if (event?.kind === 'error' && event.error instanceof Error) {
316
- node.setAttr({...failureAttributes(event.error), watching: false}, true, true, false);
303
+ node().setAttr({...failureAttributes(event.error), watching: false}, true, true, false);
317
304
  } else throw new TypeError(`Invalid ${name} event`);
318
- } catch (error) { node.setAttr(failureAttributes(error), true, true, false); }
305
+ } catch (error) { node().setAttr(failureAttributes(error), true, true, false); }
319
306
  };
320
307
  return name === 'gyroscope' ? this.provider.startGyroscopeUpdates(accept, stream.controller.signal)
321
308
  : this.provider.startAccelerometerUpdates(accept, stream.controller.signal);
322
309
  });
323
310
  stream.start.catch(error => {
324
311
  if (!this.disposed && !stream.controller.signal.aborted) {
325
- node.setAttr({...failureAttributes(error), watching: false}, true, true, false);
312
+ node().setAttr({...failureAttributes(error), watching: false}, true, true, false);
326
313
  }
327
314
  });
328
- node.setAttr({status: 'pending', error: null}, true, true, false);
315
+ node().setAttr({status: 'pending', error: null}, true, true, false);
329
316
  }
330
317
 
331
- #startAudio(node) {
318
+ #startAudio() {
319
+ const node = () => this.#deviceNode('audio');
332
320
  const previous = this.#audio;
333
321
  if (previous) {
334
322
  if (previous.phase !== 'complete') return;
335
323
  previous.phase = 'replacing';
336
- node.setValue(null, true, {status: 'pending', error: null, recording: false,
324
+ node().setValue(null, true, {status: 'pending', error: null, recording: false,
337
325
  shareStatus: 'idle', shareError: null, shareActivity: null}, true, false);
338
326
  previous.close = previous.start.then(session => session.dispose()).then(() => {
339
327
  if (this.disposed || previous.controller.signal.aborted || this.#audio !== previous) return;
340
328
  this.#audio = null;
341
- this.#startAudio(node);
329
+ this.#startAudio();
342
330
  }).catch(error => {
343
331
  if (!this.disposed && this.#audio === previous) {
344
332
  previous.phase = 'failed';
345
- node.setAttr(failureAttributes(error), true, true, false);
333
+ node().setAttr(failureAttributes(error), true, true, false);
346
334
  }
347
335
  });
348
336
  return;
349
337
  }
350
338
  const audio = {controller: new AbortController(), phase: 'starting'};
351
339
  this.#audio = audio;
352
- node.setValue(null, true, {status: 'pending', error: null, recording: false,
340
+ node().setValue(null, true, {status: 'pending', error: null, recording: false,
353
341
  shareStatus: 'idle', shareError: null, shareActivity: null}, true, false);
354
342
  audio.start = Promise.resolve().then(async () => {
355
343
  if (audio.controller.signal.aborted) return null;
356
344
  this.requireCapability('audio');
357
345
  return this.provider.startAudioRecording(error => {
358
- if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(node, error);
346
+ if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(error);
359
347
  }, audio.controller.signal);
360
348
  });
361
349
  audio.start.then(session => {
362
350
  if (!session || audio.controller.signal.aborted || this.disposed) return;
363
351
  audio.phase = 'recording';
364
- node.setAttr({status: 'recording', error: null, recording: true}, true, true, false);
352
+ node().setAttr({status: 'recording', error: null, recording: true}, true, true, false);
365
353
  }).catch(error => {
366
354
  if (audio.controller.signal.aborted || this.disposed) return;
367
355
  if (this.#audio === audio) this.#audio = null;
368
- node.setAttr({...failureAttributes(error), recording: false}, true, true, false);
356
+ node().setAttr({...failureAttributes(error), recording: false}, true, true, false);
369
357
  });
370
358
  }
371
359
 
372
- #stopAudio(node) {
360
+ #stopAudio() {
361
+ const node = () => this.#deviceNode('audio');
373
362
  const audio = this.#audio;
374
363
  if (!audio || audio.phase !== 'recording') return;
375
364
  audio.phase = 'stopping';
376
- node.setAttr({status: 'pending', error: null}, true, true, false);
365
+ node().setAttr({status: 'pending', error: null}, true, true, false);
377
366
  audio.stop = audio.start.then(session => session.stop()).then(result => {
378
367
  if (audio.controller.signal.aborted || this.disposed) return;
379
368
  if (typeof result?.url !== 'string' || !result.url || typeof result.mimeType !== 'string' ||
@@ -383,61 +372,64 @@ export class DeviceHandler extends Handler {
383
372
  const value = new Bag();
384
373
  for (const key of ['url', 'mimeType', 'duration']) value.setItem(key, result[key]);
385
374
  audio.phase = 'complete';
386
- node.setValue(value, true, {status: 'success', error: null, recording: false}, true, false);
375
+ node().setValue(value, true, {status: 'success', error: null, recording: false}, true, false);
387
376
  }).catch(error => {
388
- if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(node, error);
377
+ if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(error);
389
378
  });
390
379
  }
391
380
 
392
- #shareAudio(node) {
381
+ #shareAudio() {
382
+ const node = () => this.#deviceNode('audio');
393
383
  const audio = this.#audio;
394
384
  if (audio?.phase === 'sharing') return;
395
385
  if (!audio || audio.phase !== 'complete') {
396
386
  const failure = failureAttributes(new Error('Record and stop audio before sharing'));
397
- node.setAttr({shareStatus: failure.status, shareError: failure.error, shareActivity: null}, true, true, false);
387
+ node().setAttr({shareStatus: failure.status, shareError: failure.error, shareActivity: null}, true, true, false);
398
388
  return;
399
389
  }
400
390
  audio.phase = 'sharing';
401
- node.setAttr({shareStatus: 'pending', shareError: null, shareActivity: null}, true, true, false);
391
+ node().setAttr({shareStatus: 'pending', shareError: null, shareActivity: null}, true, true, false);
402
392
  audio.share = audio.start.then(session => session.share(audio.controller.signal)).then(result => {
403
393
  if (audio.controller.signal.aborted || this.disposed) return;
404
394
  if (typeof result?.activity !== 'string') throw new TypeError('Invalid audio share result from device provider');
405
- node.setAttr({shareStatus: 'success', shareError: null, shareActivity: result.activity}, true, true, false);
395
+ node().setAttr({shareStatus: 'success', shareError: null, shareActivity: result.activity}, true, true, false);
406
396
  }).catch(error => {
407
397
  if (audio.controller.signal.aborted || this.disposed) return;
408
398
  const failure = failureAttributes(error);
409
- node.setAttr({shareStatus: failure.status, shareError: failure.error, shareActivity: null}, true, true, false);
399
+ node().setAttr({shareStatus: failure.status, shareError: failure.error, shareActivity: null}, true, true, false);
410
400
  }).finally(() => {
411
401
  if (this.#audio === audio && !audio.controller.signal.aborted) audio.phase = 'complete';
412
402
  });
413
403
  }
414
404
 
415
- #cancelAudio(node, error = {code: 'CANCELLED', message: 'Audio recording cancelled'}) {
405
+ #cancelAudio(error = {code: 'CANCELLED', message: 'Audio recording cancelled'}) {
406
+ const node = () => this.#deviceNode('audio');
416
407
  const audio = this.#audio;
417
408
  if (!audio || audio.phase === 'closing' || audio.phase === 'sharing') return;
418
409
  audio.phase = 'closing';
419
410
  audio.controller.abort();
420
- node.setValue(null, true, {status: 'pending', error: null,
411
+ node().setValue(null, true, {status: 'pending', error: null,
421
412
  shareStatus: 'idle', shareError: null, shareActivity: null}, true, false);
422
413
  audio.close = audio.start.then(session => session === null ? undefined : session.dispose(), error => { if (error?.code !== 'CANCELLED') throw error; }).then(() => {
423
414
  if (this.disposed || this.#audio !== audio) return;
424
415
  this.#audio = null;
425
- node.setAttr({...failureAttributes(error), recording: false}, true, true, false);
416
+ node().setAttr({...failureAttributes(error), recording: false}, true, true, false);
426
417
  }).catch(cleanupError => {
427
418
  if (!this.disposed && this.#audio === audio) {
428
419
  // Keep ownership when cleanup failed; the page may retry cancellation.
429
420
  audio.phase = 'failed';
430
- node.setAttr(failureAttributes(cleanupError), true, true, false);
421
+ node().setAttr(failureAttributes(cleanupError), true, true, false);
431
422
  }
432
423
  });
433
424
  }
434
425
 
435
- #clipboardCommand(node, operation) {
426
+ #clipboardCommand(operation) {
427
+ const node = () => this.#deviceNode('clipboard');
436
428
  if (this.#clipboardRequest) return;
437
429
  const request = new AbortController();
438
430
  this.#clipboardRequest = request;
439
- const text = node.attr.text;
440
- node.setValue(null, true, {status: 'pending', error: null, operation}, true, false);
431
+ const text = node().attr.text;
432
+ node().setValue(null, true, {status: 'pending', error: null, operation}, true, false);
441
433
  Promise.resolve().then(async () => {
442
434
  if (request.signal.aborted) return;
443
435
  this.requireCapability('clipboard');
@@ -453,20 +445,21 @@ export class DeviceHandler extends Handler {
453
445
  if (typeof result?.text !== 'string') throw new TypeError('Invalid clipboard text from device provider');
454
446
  const value = new Bag();
455
447
  value.setItem('text', result.text);
456
- node.setValue(value, true, {status: 'success', error: null}, true, false);
448
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
457
449
  }).catch(error => {
458
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
450
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
459
451
  }).finally(() => {
460
452
  if (this.#clipboardRequest === request) this.#clipboardRequest = null;
461
453
  });
462
454
  }
463
455
 
464
- #vibrate(node) {
456
+ #vibrate() {
457
+ const node = () => this.#deviceNode('haptics');
465
458
  if (this.#hapticRequest) return;
466
459
  const request = new AbortController();
467
460
  this.#hapticRequest = request;
468
- const {duration} = node.attr;
469
- node.setValue(null, true, {status: 'pending', error: null}, true, false);
461
+ const {duration} = node().attr;
462
+ node().setValue(null, true, {status: 'pending', error: null}, true, false);
470
463
  Promise.resolve().then(async () => {
471
464
  if (request.signal.aborted) return;
472
465
  this.requireCapability('haptics');
@@ -478,20 +471,21 @@ export class DeviceHandler extends Handler {
478
471
  const value = new Bag();
479
472
  value.setItem('duration', duration);
480
473
  value.setItem('acknowledged', true);
481
- node.setValue(value, true, {status: 'success', error: null}, true, false);
474
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
482
475
  }).catch(error => {
483
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
476
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
484
477
  }).finally(() => {
485
478
  if (this.#hapticRequest === request) this.#hapticRequest = null;
486
479
  });
487
480
  }
488
481
 
489
- #impact(node) {
482
+ #impact() {
483
+ const node = () => this.#deviceNode('haptics');
490
484
  if (this.#hapticRequest) return;
491
485
  const request = new AbortController();
492
486
  this.#hapticRequest = request;
493
- const {style} = node.attr;
494
- node.setValue(null, true, {status: 'pending', error: null}, true, false);
487
+ const {style} = node().attr;
488
+ node().setValue(null, true, {status: 'pending', error: null}, true, false);
495
489
  Promise.resolve().then(async () => {
496
490
  if (request.signal.aborted) return;
497
491
  this.requireCapability('haptics');
@@ -501,19 +495,20 @@ export class DeviceHandler extends Handler {
501
495
  const value = new Bag();
502
496
  value.setItem('style', style);
503
497
  value.setItem('acknowledged', true);
504
- node.setValue(value, true, {status: 'success', error: null}, true, false);
498
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
505
499
  }).catch(error => {
506
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
500
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
507
501
  }).finally(() => {
508
502
  if (this.#hapticRequest === request) this.#hapticRequest = null;
509
503
  });
510
504
  }
511
505
 
512
- #scanBarcode(node) {
506
+ #scanBarcode() {
507
+ const node = () => this.#deviceNode('barcode');
513
508
  if (this.#barcodeRequest) return;
514
509
  const request = new AbortController();
515
510
  this.#barcodeRequest = request;
516
- node.setValue(null, true, {status: 'pending', error: null}, true, false);
511
+ node().setValue(null, true, {status: 'pending', error: null}, true, false);
517
512
  Promise.resolve().then(() => {
518
513
  if (request.signal.aborted) return;
519
514
  this.requireCapability('barcode');
@@ -526,20 +521,21 @@ export class DeviceHandler extends Handler {
526
521
  const value = new Bag();
527
522
  value.setItem('text', result.text);
528
523
  value.setItem('format', result.format);
529
- node.setValue(value, true, {status: 'success', error: null}, true, false);
524
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
530
525
  }).catch(error => {
531
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
526
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
532
527
  }).finally(() => {
533
528
  if (this.#barcodeRequest === request) this.#barcodeRequest = null;
534
529
  });
535
530
  }
536
531
 
537
532
  // Camera is an explicit Data event, never a resolver read with a UI side effect.
538
- #photo(node, operation) {
533
+ #photo(operation) {
534
+ const node = () => this.#deviceNode('camera');
539
535
  if (this.#captureRequest) return;
540
536
  const request = new AbortController();
541
537
  this.#captureRequest = request;
542
- node.setAttr({status: 'pending', error: null}, true, true, false);
538
+ node().setAttr({status: 'pending', error: null}, true, true, false);
543
539
  Promise.resolve().then(() => {
544
540
  if (request.signal.aborted) return;
545
541
  this.requireCapability('camera');
@@ -554,20 +550,21 @@ export class DeviceHandler extends Handler {
554
550
  const value = new Bag();
555
551
  value.setItem('url', photo.url);
556
552
  value.setItem('format', photo.format);
557
- node.setValue(value, true, {status: 'success', error: null}, true, false);
553
+ node().setValue(value, true, {status: 'success', error: null}, true, false);
558
554
  }).catch(error => {
559
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
555
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
560
556
  }).finally(() => {
561
557
  if (this.#captureRequest === request) this.#captureRequest = null;
562
558
  });
563
559
  }
564
560
 
565
561
  // A fresh attempt clears the previous local verification, including on cancellation.
566
- #verifyBiometrics(node) {
562
+ #verifyBiometrics() {
563
+ const node = () => this.#deviceNode('biometrics');
567
564
  if (this.#biometricsRequest) return;
568
565
  const request = new AbortController();
569
566
  this.#biometricsRequest = request;
570
- node.setValue(null, true, {status: 'pending', error: null}, true, false);
567
+ node().setValue(null, true, {status: 'pending', error: null}, true, false);
571
568
  Promise.resolve().then(() => {
572
569
  if (request.signal.aborted) return;
573
570
  this.requireCapability('biometrics');
@@ -576,15 +573,16 @@ export class DeviceHandler extends Handler {
576
573
  if (request.signal.aborted) return;
577
574
  const result = new Bag();
578
575
  result.setItem('verified', true);
579
- node.setValue(result, true, {status: 'success', error: null}, true, false);
576
+ node().setValue(result, true, {status: 'success', error: null}, true, false);
580
577
  }).catch(error => {
581
- if (!request.signal.aborted) node.setValue(null, true, failureAttributes(error), true, false);
578
+ if (!request.signal.aborted) node().setValue(null, true, failureAttributes(error), true, false);
582
579
  }).finally(() => {
583
580
  if (this.#biometricsRequest === request) this.#biometricsRequest = null;
584
581
  });
585
582
  }
586
583
 
587
- #startNotificationEvents(node) {
584
+ #startNotificationEvents() {
585
+ const node = () => this.#deviceNode('notifications');
588
586
  if (this.#notificationEvents) return this.#notificationEvents.start;
589
587
  const events = {controller: new AbortController()};
590
588
  this.#notificationEvents = events;
@@ -601,13 +599,13 @@ export class DeviceHandler extends Handler {
601
599
  const value = new Bag();
602
600
  for (const key of ['id', 'title', 'body']) value.setItem(key, event[key]);
603
601
  if (event.kind === 'action') value.setItem('actionId', event.actionId);
604
- node.staticValue.setItem(event.kind, value);
602
+ node().staticValue.setItem(event.kind, value);
605
603
  } catch (error) {
606
- node.setAttr({listenerError: failureAttributes(error).error}, true, true, false);
604
+ node().setAttr({listenerError: failureAttributes(error).error}, true, true, false);
607
605
  }
608
606
  }, events.controller.signal);
609
607
  }).then(stop => {
610
- if (!events.controller.signal.aborted) node.setAttr({listening: true}, true, true, false);
608
+ if (!events.controller.signal.aborted) node().setAttr({listening: true}, true, true, false);
611
609
  return stop;
612
610
  });
613
611
  events.start.catch(error => {
@@ -615,22 +613,23 @@ export class DeviceHandler extends Handler {
615
613
  events.controller.abort();
616
614
  if (this.#notificationEvents === events) this.#notificationEvents = null;
617
615
  if (!aborted) {
618
- node.setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
616
+ node().setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
619
617
  }
620
618
  });
621
- node.setAttr({listenerError: null}, true, true, false);
619
+ node().setAttr({listenerError: null}, true, true, false);
622
620
  return events.start;
623
621
  }
624
622
 
625
- #scheduleNotification(node) {
623
+ #scheduleNotification() {
624
+ const node = () => this.#deviceNode('notifications');
626
625
  if (this.#notificationRequest) return;
627
626
  const request = new AbortController();
628
627
  this.#notificationRequest = request;
629
- const value = node.staticValue.getItem('request');
628
+ const value = node().staticValue.getItem('request');
630
629
  const input = value instanceof Bag
631
630
  ? Object.fromEntries(['id', 'title', 'body', 'delay'].map(key => [key, value.getItem(key)])) : null;
632
- node.staticValue.setItem('scheduled', null);
633
- node.setAttr({status: 'pending', error: null}, true, true, false);
631
+ node().staticValue.setItem('scheduled', null);
632
+ node().setAttr({status: 'pending', error: null}, true, true, false);
634
633
  Promise.resolve().then(async () => {
635
634
  if (request.signal.aborted) return;
636
635
  this.requireCapability('notifications');
@@ -640,7 +639,7 @@ export class DeviceHandler extends Handler {
640
639
  || typeof input.delay !== 'number' || !Number.isFinite(input.delay) || input.delay <= 0) {
641
640
  throw new TypeError('Notification requires a positive 32-bit id, title, body and positive delay in seconds');
642
641
  }
643
- await this.#startNotificationEvents(node);
642
+ await this.#startNotificationEvents();
644
643
  if (request.signal.aborted) return;
645
644
  return this.provider.scheduleNotification(input, request.signal);
646
645
  }).then(result => {
@@ -651,10 +650,10 @@ export class DeviceHandler extends Handler {
651
650
  const scheduled = new Bag();
652
651
  scheduled.setItem('id', result.id);
653
652
  scheduled.setItem('at', result.at);
654
- node.staticValue.setItem('scheduled', scheduled);
655
- node.setAttr({status: 'success', error: null}, true, true, false);
653
+ node().staticValue.setItem('scheduled', scheduled);
654
+ node().setAttr({status: 'success', error: null}, true, true, false);
656
655
  }).catch(error => {
657
- if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
656
+ if (!request.signal.aborted) node().setAttr(failureAttributes(error), true, true, false);
658
657
  }).finally(() => {
659
658
  if (this.#notificationRequest === request) this.#notificationRequest = null;
660
659
  });
@@ -667,18 +666,19 @@ export class DeviceHandler extends Handler {
667
666
  return request;
668
667
  }
669
668
 
670
- #acceptPushEvent(node, event) {
669
+ #acceptPushEvent(event) {
670
+ const node = () => this.#deviceNode('push');
671
671
  if (event.kind === 'registration') {
672
672
  if (typeof event.token !== 'string' || !event.token) throw new TypeError('Invalid push registration token');
673
673
  this.#finishPushRequest();
674
674
  const value = new Bag();
675
675
  value.setItem('token', event.token);
676
- node.staticValue.setItem('registration', value);
677
- node.setAttr({status: 'success', error: null}, true, true, false);
676
+ node().staticValue.setItem('registration', value);
677
+ node().setAttr({status: 'success', error: null}, true, true, false);
678
678
  } else if (event.kind === 'registrationError') {
679
679
  this.#finishPushRequest();
680
- node.staticValue.setItem('registration', null);
681
- node.setAttr(failureAttributes(event.error), true, true, false);
680
+ node().staticValue.setItem('registration', null);
681
+ node().setAttr(failureAttributes(event.error), true, true, false);
682
682
  } else {
683
683
  if (!['received', 'action'].includes(event.kind)) throw new TypeError('Invalid push event kind');
684
684
  const fields = ['id', 'title', 'body', 'messageId', 'destination'];
@@ -688,11 +688,12 @@ export class DeviceHandler extends Handler {
688
688
  if (typeof event[key] !== 'string') throw new TypeError(`Invalid push event ${key}`);
689
689
  value.setItem(key, event[key]);
690
690
  }
691
- node.staticValue.setItem(event.kind, value);
691
+ node().staticValue.setItem(event.kind, value);
692
692
  }
693
693
  }
694
694
 
695
- #startPushEvents(node) {
695
+ #startPushEvents() {
696
+ const node = () => this.#deviceNode('push');
696
697
  if (this.#pushEvents) return this.#pushEvents.start;
697
698
  const events = {controller: new AbortController()};
698
699
  this.#pushEvents = events;
@@ -700,24 +701,25 @@ export class DeviceHandler extends Handler {
700
701
  if (events.controller.signal.aborted) return async () => {};
701
702
  return this.provider.startPushEvents(event => {
702
703
  if (events.controller.signal.aborted) return;
703
- try { this.#acceptPushEvent(node, event); }
704
- catch (error) { node.setAttr({listenerError: failureAttributes(error).error}, true, true, false); }
704
+ try { this.#acceptPushEvent(event); }
705
+ catch (error) { node().setAttr({listenerError: failureAttributes(error).error}, true, true, false); }
705
706
  }, events.controller.signal);
706
707
  }).then(stop => {
707
- if (!events.controller.signal.aborted) node.setAttr({listening: true}, true, true, false);
708
+ if (!events.controller.signal.aborted) node().setAttr({listening: true}, true, true, false);
708
709
  return stop;
709
710
  });
710
711
  events.start.catch(error => {
711
712
  const aborted = events.controller.signal.aborted;
712
713
  events.controller.abort();
713
714
  if (this.#pushEvents === events) this.#pushEvents = null;
714
- if (!aborted) node.setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
715
+ if (!aborted) node().setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
715
716
  });
716
- node.setAttr({listenerError: null}, true, true, false);
717
+ node().setAttr({listenerError: null}, true, true, false);
717
718
  return events.start;
718
719
  }
719
720
 
720
- #registerPush(node) {
721
+ #registerPush() {
722
+ const node = () => this.#deviceNode('push');
721
723
  if (this.#pushRequest) return;
722
724
  const request = {controller: new AbortController(), timer: null};
723
725
  this.#pushRequest = request;
@@ -725,14 +727,14 @@ export class DeviceHandler extends Handler {
725
727
  if (this.disposed || this.#pushRequest !== request) return;
726
728
  this.#finishPushRequest();
727
729
  request.controller.abort();
728
- node.setAttr(failureAttributes({code: 'TIMEOUT', message: 'Push registration has not returned a token'}), true, true, false);
730
+ node().setAttr(failureAttributes({code: 'TIMEOUT', message: 'Push registration has not returned a token'}), true, true, false);
729
731
  }, 30000);
730
- node.staticValue.setItem('registration', null);
731
- node.setAttr({status: 'pending', error: null}, true, true, false);
732
+ node().staticValue.setItem('registration', null);
733
+ node().setAttr({status: 'pending', error: null}, true, true, false);
732
734
  Promise.resolve().then(async () => {
733
735
  if (request.controller.signal.aborted) return;
734
736
  this.requireCapability('push');
735
- await this.#startPushEvents(node);
737
+ await this.#startPushEvents();
736
738
  if (request.controller.signal.aborted || this.#pushRequest !== request) return;
737
739
  await this.provider.registerPush(request.controller.signal);
738
740
  // SDK register() only initiates registration. The token event completes it.
@@ -740,11 +742,12 @@ export class DeviceHandler extends Handler {
740
742
  if (this.disposed || this.#pushRequest !== request) return;
741
743
  this.#finishPushRequest();
742
744
  request.controller.abort();
743
- node.setAttr(failureAttributes(error), true, true, false);
745
+ node().setAttr(failureAttributes(error), true, true, false);
744
746
  });
745
747
  }
746
748
 
747
- #startShortcutEvents(node) {
749
+ #startShortcutEvents() {
750
+ const node = () => this.#deviceNode('shortcuts');
748
751
  const events = {controller: new AbortController()};
749
752
  this.#shortcutEvents = events;
750
753
  events.start = Promise.resolve().then(() => {
@@ -758,28 +761,29 @@ export class DeviceHandler extends Handler {
758
761
  throw new TypeError(`Invalid shortcut request ${key}`);
759
762
  }
760
763
  }
761
- if (node.staticValue.getItem('request')?.getItem('id') === request.id) return;
764
+ if (node().staticValue.getItem('request')?.getItem('id') === request.id) return;
762
765
  const value = new Bag();
763
766
  value.setItem('id', request.id);
764
767
  value.setItem('destination', request.destination);
765
- node.setAttr({listenerError: null}, true, true, false);
766
- node.staticValue.setItem('request', value);
768
+ node().setAttr({listenerError: null}, true, true, false);
769
+ node().staticValue.setItem('request', value);
767
770
  } catch (error) {
768
- node.setAttr({listenerError: failureAttributes(error).error}, true, true, false);
771
+ node().setAttr({listenerError: failureAttributes(error).error}, true, true, false);
769
772
  }
770
773
  }, events.controller.signal);
771
774
  }).then(stop => {
772
- if (!events.controller.signal.aborted) node.setAttr({listening: true}, true, true, false);
775
+ if (!events.controller.signal.aborted) node().setAttr({listening: true}, true, true, false);
773
776
  return stop;
774
777
  });
775
778
  events.start.catch(error => {
776
779
  const aborted = events.controller.signal.aborted;
777
780
  events.controller.abort();
778
- if (!aborted) node.setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
781
+ if (!aborted) node().setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
779
782
  });
780
783
  }
781
784
 
782
- #startLinkEvents(node) {
785
+ #startLinkEvents() {
786
+ const node = () => this.#deviceNode('links');
783
787
  const events = {controller: new AbortController()};
784
788
  this.#linkEvents = events;
785
789
  events.start = Promise.resolve().then(() => {
@@ -793,24 +797,24 @@ export class DeviceHandler extends Handler {
793
797
  throw new TypeError(`Invalid link request ${key}`);
794
798
  }
795
799
  }
796
- if (node.staticValue.getItem('request')?.getItem('id') === request.id) return;
800
+ if (node().staticValue.getItem('request')?.getItem('id') === request.id) return;
797
801
  const value = new Bag();
798
802
  value.setItem('id', request.id);
799
803
  value.setItem('url', request.url);
800
- node.setAttr({listenerError: null}, true, true, false);
801
- node.staticValue.setItem('request', value);
804
+ node().setAttr({listenerError: null}, true, true, false);
805
+ node().staticValue.setItem('request', value);
802
806
  } catch (error) {
803
- node.setAttr({listenerError: failureAttributes(error).error}, true, true, false);
807
+ node().setAttr({listenerError: failureAttributes(error).error}, true, true, false);
804
808
  }
805
809
  }, events.controller.signal);
806
810
  }).then(stop => {
807
- if (!events.controller.signal.aborted) node.setAttr({listening: true}, true, true, false);
811
+ if (!events.controller.signal.aborted) node().setAttr({listening: true}, true, true, false);
808
812
  return stop;
809
813
  });
810
814
  events.start.catch(error => {
811
815
  const aborted = events.controller.signal.aborted;
812
816
  events.controller.abort();
813
- if (!aborted) node.setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
817
+ if (!aborted) node().setAttr({listening: false, listenerError: failureAttributes(error).error}, true, true, false);
814
818
  });
815
819
  }
816
820
 
@@ -823,7 +827,7 @@ export class DeviceHandler extends Handler {
823
827
  attributes(resolver, attrs) {
824
828
  const writing = resolver.writing;
825
829
  resolver.writing = true;
826
- try { resolver._node.setAttr(attrs, true, true, false); }
830
+ try { this.#deviceNode(resolver.name).setAttr(attrs, true, true, false); }
827
831
  finally { resolver.writing = writing; }
828
832
  }
829
833
 
@@ -849,7 +853,7 @@ export class DeviceHandler extends Handler {
849
853
  resolver.received++;
850
854
  const writing = resolver.writing;
851
855
  resolver.writing = true;
852
- try { resolver._node.setValue(bag, true, {status: 'success', error: null}, true, false); }
856
+ try { this.#deviceNode(resolver.name).setValue(bag, true, {status: 'success', error: null}, true, false); }
853
857
  finally { resolver.writing = writing; }
854
858
  }
855
859
 
@@ -859,8 +863,9 @@ export class DeviceHandler extends Handler {
859
863
  }
860
864
 
861
865
  reconcile() {
862
- const resolver = this.resolvers.get('location');
863
- if (resolver._node.attr.enabled) {
866
+ // Callbacks read the location resolver at its path when they run.
867
+ const resolver = () => this.resolver('location');
868
+ if (this.#deviceNode('location').attr.enabled) {
864
869
  if (this.monitor) return;
865
870
  const monitor = {stop: null, controller: new AbortController()};
866
871
  this.monitor = monitor;
@@ -869,25 +874,25 @@ export class DeviceHandler extends Handler {
869
874
  this.requireCapability('location');
870
875
  return this.provider.startLocationUpdates((value, error) => {
871
876
  if (this.disposed || this.monitor !== monitor) return;
872
- if (error) this.failure(resolver, error);
877
+ if (error) this.failure(resolver(), error);
873
878
  else {
874
- try { this.accept(resolver, value); }
875
- catch (failure) { this.failure(resolver, failure); }
879
+ try { this.accept(resolver(), value); }
880
+ catch (failure) { this.failure(resolver(), failure); }
876
881
  }
877
882
  }, monitor.controller.signal);
878
883
  });
879
884
  monitor.start.then(stop => {
880
885
  if (stop === null || this.disposed || this.monitor !== monitor) return;
881
886
  monitor.stop = stop;
882
- this.attributes(resolver, {watching: true});
887
+ this.attributes(resolver(), {watching: true});
883
888
  }).catch(error => {
884
889
  if (!this.disposed && this.monitor === monitor) {
885
890
  // Keep the failed intent until enabled changes; Data notifications cannot retry it.
886
- this.attributes(resolver, {watching: false});
887
- this.failure(resolver, error);
891
+ this.attributes(resolver(), {watching: false});
892
+ this.failure(resolver(), error);
888
893
  }
889
894
  });
890
- this.attributes(resolver, {status: 'pending', error: null});
895
+ this.attributes(resolver(), {status: 'pending', error: null});
891
896
  } else if (this.monitor) {
892
897
  const monitor = this.monitor;
893
898
  this.monitor = null;
@@ -898,13 +903,13 @@ export class DeviceHandler extends Handler {
898
903
  if (this.retiring === monitor) this.retiring = null;
899
904
  if (!this.disposed) {
900
905
  const attrs = {watching: false};
901
- if (!this.monitor && !resolver.request && resolver._node.attr.status === 'pending') {
906
+ if (!this.monitor && !resolver().request && this.#deviceNode('location').attr.status === 'pending') {
902
907
  Object.assign(attrs, {status: 'cancelled', error: null});
903
908
  }
904
- this.attributes(resolver, attrs);
909
+ this.attributes(resolver(), attrs);
905
910
  }
906
911
  });
907
- this.cleanup.catch(error => { if (!this.disposed) this.failure(resolver, error); });
912
+ this.cleanup.catch(error => { if (!this.disposed) this.failure(resolver(), error); });
908
913
  }
909
914
  }
910
915
 
@@ -913,9 +918,9 @@ export class DeviceHandler extends Handler {
913
918
  this.assertLive();
914
919
  if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== 'string') throw new TypeError('Invalid database name');
915
920
  if (this.#database) throw new Error('This page already owns a database connection');
916
- const node = this.gramlot.data.getNode('_gramlot.device.database');
921
+ const node = () => this.#deviceNode('database');
917
922
  const state = (status, error = null) => {
918
- if (!this.disposed) node.setAttr({status, error}, true, true, false);
923
+ if (!this.disposed) node().setAttr({status, error}, true, true, false);
919
924
  };
920
925
  if (!this.provider.capabilities.includes('database')) {
921
926
  const error = Object.assign(new Error('Native database unavailable'), {code: 'UNAVAILABLE'});
@@ -948,7 +953,7 @@ export class DeviceHandler extends Handler {
948
953
  execute:(sql, params = []) => invoke('execute', sql, params), close};
949
954
  } catch (error) {
950
955
  if (this.#database === slot) this.#database = null;
951
- if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
956
+ if (!this.disposed) node().setAttr(failureAttributes(error), true, true, false);
952
957
  throw error;
953
958
  }
954
959
  }
@@ -997,7 +1002,8 @@ export class DeviceHandler extends Handler {
997
1002
  const notificationEvents = this.#notificationEvents;
998
1003
  this.#notificationEvents = null;
999
1004
  notificationEvents?.controller.abort();
1000
- this.gramlot.data.unsubscribe('gramlot.device', {any: true});
1005
+ this.#registration?.close();
1006
+ this.#registration = null;
1001
1007
  const monitor = this.monitor;
1002
1008
  this.monitor = null;
1003
1009
  monitor?.controller.abort();
@@ -1032,6 +1038,6 @@ export class DeviceHandler extends Handler {
1032
1038
  // Cleanup rejection is observed; disposed pages must not receive late Data writes.
1033
1039
  this.cleanup = this.cleanup.finally(() => this.releaseProvider?.());
1034
1040
  this.cleanup.catch(error => { this.cleanupError = error; });
1035
- for (const resolver of this.resolvers.values()) resolver.request = null;
1041
+ if (this.provider) for (const name of NAMES) this.#deviceNode(name).resolver.request = null;
1036
1042
  }
1037
1043
  }