@gramlot/gramlot 0.3.16 → 0.3.17

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 (96) hide show
  1. package/dist/components/editors/__init__.py +1 -1
  2. package/dist/components/editors/assets/collection.js +16162 -11689
  3. package/dist/components/editors/assets/index.js +1 -1
  4. package/dist/components/editors/grammar.json +3 -0
  5. package/dist/components/inputs/__init__.py +1 -1
  6. package/dist/components/inputs/assets/collection.js +134 -179
  7. package/dist/components/inputs/assets/index.js +1 -1
  8. package/dist/components/inputs/grammar.json +19 -0
  9. package/dist/components/layout/__init__.py +1 -1
  10. package/dist/components/layout/assets/collection.js +4643 -3481
  11. package/dist/components/layout/assets/index.js +1 -1
  12. package/dist/components/layout/grammar.json +509 -1
  13. package/dist/components/tree/__init__.py +1 -1
  14. package/dist/components/tree/assets/collection.js +306 -94
  15. package/dist/components/tree/assets/index.js +1 -1
  16. package/dist/components/tree/grammar.json +16 -0
  17. package/dist/components/typst/__init__.py +1 -1
  18. package/dist/components/typst/assets/collection.js +2 -2
  19. package/dist/components/typst/assets/index.js +1 -1
  20. package/dist/gramlot.js +2124 -506
  21. package/dist/gramlot.min.js +95 -40
  22. package/dist/runtime-notices.json +4 -0
  23. package/package.json +12 -8
  24. package/src/binding/device-resolver.js +27 -0
  25. package/src/binding/error-notifications.js +84 -0
  26. package/src/binding/remote-resolver.d.ts +18 -0
  27. package/src/binding/remote.js +11 -4
  28. package/src/binding/runtime.js +6 -2
  29. package/src/bootstrap.js +4 -4
  30. package/src/components/buttons.js +10 -3
  31. package/src/components/code-mirror-engine.js +14 -4
  32. package/src/components/code-mirror.js +2 -3
  33. package/src/components/container.js +1 -1
  34. package/src/components/date-calendar.js +1 -1
  35. package/src/components/formlet-labels.js +5 -4
  36. package/src/components/html-document.js +4 -2
  37. package/src/components/html-editor.js +2 -2
  38. package/src/components/jodit-engine.js +72 -11
  39. package/src/components/labelbox.js +19 -63
  40. package/src/components/layout.js +31 -19
  41. package/src/components/markdown-document.js +1 -1
  42. package/src/components/markdown-editor.js +2 -2
  43. package/src/components/menus.js +7 -6
  44. package/src/components/prose-mirror-engine.js +14 -1
  45. package/src/components/registry.js +2 -0
  46. package/src/components/selected-container.js +107 -14
  47. package/src/components/toolbar-overflow.js +9 -8
  48. package/src/components/transform-pane.js +140 -0
  49. package/src/components/tray-geometry.js +87 -0
  50. package/src/components/tray-pane.js +435 -0
  51. package/src/components/tray-settings.js +62 -0
  52. package/src/components/tree.js +115 -21
  53. package/src/components/typed-editor.js +1 -1
  54. package/src/components/typst-client.js +14 -13
  55. package/src/components/validation.js +1 -1
  56. package/src/components/window-surface.js +281 -0
  57. package/src/components/windows.js +32 -261
  58. package/src/device-frames.js +195 -0
  59. package/src/filesystem.d.ts +12 -5
  60. package/src/filesystem.js +8 -8
  61. package/src/gramlot.d.ts +3 -1
  62. package/src/gramlot.js +11 -4
  63. package/src/handlers/device-handler.d.ts +75 -0
  64. package/src/handlers/device-handler.js +1037 -0
  65. package/src/handlers/dom-handler.d.ts +2 -0
  66. package/src/handlers/dom-handler.js +9 -0
  67. package/src/handlers/rpc-handler.d.ts +2 -2
  68. package/src/http-transport.d.ts +3 -3
  69. package/src/http-transport.js +17 -11
  70. package/src/ide-documents.js +6 -4
  71. package/src/ide-runtime.d.ts +14 -3
  72. package/src/ide-runtime.js +123 -94
  73. package/src/index-page-runtime.d.ts +2 -2
  74. package/src/index-page-runtime.js +91 -43
  75. package/src/index-page-styles.js +1 -1
  76. package/src/index.d.ts +7 -2
  77. package/src/index.js +5 -1
  78. package/src/inout.d.ts +1 -1
  79. package/src/inout.js +5 -1
  80. package/src/mobile-environment.d.ts +6 -0
  81. package/src/mobile-environment.js +52 -0
  82. package/src/navigation-resolver.d.ts +14 -2
  83. package/src/renderer/attributes.js +5 -2
  84. package/src/renderer/drag-drop.js +5 -4
  85. package/src/renderer/gramlot-renderer.d.ts +13 -2
  86. package/src/renderer/gramlot-renderer.js +49 -13
  87. package/src/server/index-page.js +4 -4
  88. package/src/view/controls.js +48 -23
  89. package/src/view/html.js +85 -4
  90. package/src/view/labelbox.js +95 -0
  91. package/themes/gramlot-base/theme.css +4 -0
  92. package/themes/mela/theme.css +62 -15
  93. package/src/date-parser/civil.js +0 -61
  94. package/src/date-parser/index.d.ts +0 -18
  95. package/src/date-parser/index.js +0 -196
  96. package/src/date-parser/locales.js +0 -257
package/dist/gramlot.js CHANGED
@@ -6519,6 +6519,78 @@ var require_lib = __commonJS({
6519
6519
  }
6520
6520
  });
6521
6521
 
6522
+ // src/mobile-environment.js
6523
+ var environments = /* @__PURE__ */ new WeakMap();
6524
+ var TOUCH = `
6525
+ --gramlot-toolbar-thickness:56px; --gramlot-toolbar-control-size:44px; --gramlot-toolbar-padding:6px;
6526
+ `;
6527
+ var EDGES = `
6528
+ box-sizing:border-box; height:100dvh; min-height:0; overflow:auto;
6529
+ padding:env(safe-area-inset-top) max(12px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
6530
+ background:var(--gramlot-chrome-background,color-mix(in srgb,var(--gramlot-surface-subtle,Canvas) 88%,var(--gramlot-ink,CanvasText) 12%)); color:var(--gramlot-ink,CanvasText);
6531
+ `;
6532
+ var mobileEnvironmentStyle = `
6533
+ [data-gramlot-viewport]{--gramlot-toolbar-thickness:42px;--gramlot-toolbar-control-size:36px;--gramlot-toolbar-padding:2px 3px;}
6534
+ :root[data-gramlot-touch="on"] [data-gramlot-viewport]{${TOUCH}}
6535
+ :root[data-gramlot-touch="on"] [data-gramlot-viewport="root"]{${EDGES}}
6536
+ :root[data-gramlot-touch="on"] [data-gramlot-viewport="root"] > *{max-height:100%;}
6537
+ @media(pointer:coarse){
6538
+ :root:not([data-gramlot-touch="off"]) [data-gramlot-viewport]{${TOUCH}}
6539
+ :root:not([data-gramlot-touch="off"]) [data-gramlot-viewport="root"]{${EDGES}}
6540
+ :root:not([data-gramlot-touch="off"]) [data-gramlot-viewport="root"] > *{max-height:100%;}
6541
+ }
6542
+ `;
6543
+ var MobileEnvironment = class _MobileEnvironment {
6544
+ static install({ document, root }) {
6545
+ if (!environments.has(root)) environments.set(root, new _MobileEnvironment(document, root));
6546
+ return environments.get(root);
6547
+ }
6548
+ constructor(document, root) {
6549
+ this.document = document;
6550
+ this.root = root;
6551
+ this.releases = [];
6552
+ this.closed = false;
6553
+ root.setAttribute("data-gramlot-viewport", document.defaultView.parent === document.defaultView ? "root" : "child");
6554
+ let viewport = document.querySelector('meta[name="viewport"]');
6555
+ if (!viewport) {
6556
+ viewport = document.createElement("meta");
6557
+ viewport.name = "viewport";
6558
+ viewport.content = "width=device-width,initial-scale=1";
6559
+ document.head.append(viewport);
6560
+ }
6561
+ const parts2 = viewport.content.split(",").map((s) => s.trim()).filter((s) => !s.startsWith("viewport-fit="));
6562
+ viewport.content = [...parts2, "viewport-fit=cover"].join(",");
6563
+ this.style = document.createElement("style");
6564
+ this.style.textContent = mobileEnvironmentStyle;
6565
+ document.head.append(this.style);
6566
+ }
6567
+ subscribeAppearance(callback) {
6568
+ const window2 = this.document.defaultView, media = window2.matchMedia("(prefers-color-scheme: dark)");
6569
+ const update = () => {
6570
+ const scheme = window2.getComputedStyle(this.document.documentElement).colorScheme;
6571
+ callback({ dark: scheme === "dark" || !["light", "dark"].includes(scheme) && media.matches });
6572
+ };
6573
+ const observer = new window2.MutationObserver(update);
6574
+ observer.observe(this.document.documentElement, { attributes: true, attributeFilter: ["data-theme", "style", "class"] });
6575
+ media.addEventListener("change", update);
6576
+ update();
6577
+ const release = () => {
6578
+ observer.disconnect();
6579
+ media.removeEventListener("change", update);
6580
+ };
6581
+ this.releases.push(release);
6582
+ return release;
6583
+ }
6584
+ dispose() {
6585
+ if (this.closed) return;
6586
+ this.closed = true;
6587
+ for (const release of this.releases) release();
6588
+ this.style.remove();
6589
+ this.root.removeAttribute("data-gramlot-viewport");
6590
+ environments.delete(this.root);
6591
+ }
6592
+ };
6593
+
6522
6594
  // src/commands.js
6523
6595
  var CommandRegistry = class {
6524
6596
  #groups = /* @__PURE__ */ new Map();
@@ -6596,21 +6668,21 @@ var HttpTransport = class {
6596
6668
  return request.responseText;
6597
6669
  }
6598
6670
  /**
6599
- * Send the close message `{pageId}` without waiting for the answer: a beacon on page hide, else a
6600
- * `keepalive` POST. A failed delivery leaves the page to the server TTL; local disposal does not wait.
6671
+ * Queue `{pageId}` as a JSON beacon for every close. A refused or undelivered
6672
+ * beacon leaves cleanup to the server TTL; configuration errors remain visible.
6601
6673
  */
6602
- close(pageId, { beacon = false } = {}) {
6603
- const body = JSON.stringify({ pageId });
6604
- if (beacon) {
6605
- this.navigator.sendBeacon(this.closeUrl, new Blob([body], { type: "application/json" }));
6606
- } else {
6607
- this.fetcher(this.closeUrl, {
6608
- method: "POST",
6609
- credentials: "same-origin",
6610
- keepalive: true,
6611
- headers: { "Content-Type": "application/json" },
6612
- body
6613
- });
6674
+ close(pageId) {
6675
+ if (typeof this.closeUrl !== "string" || !this.closeUrl.trim()) {
6676
+ throw new TypeError("HttpTransport.closeUrl must be nonempty text");
6677
+ }
6678
+ if (typeof this.navigator?.sendBeacon !== "function") {
6679
+ throw new TypeError("HttpTransport requires navigator.sendBeacon");
6680
+ }
6681
+ const body = new Blob([JSON.stringify({ pageId })], { type: "application/json" });
6682
+ try {
6683
+ this.navigator.sendBeacon(this.closeUrl, body);
6684
+ } catch (error) {
6685
+ if (error.name === "TypeError") throw error;
6614
6686
  }
6615
6687
  }
6616
6688
  /** Release the transport at the dispose of the page: HTTP holds no connection, so nothing is released. The
@@ -22155,6 +22227,101 @@ var Handler = class {
22155
22227
  }
22156
22228
  };
22157
22229
 
22230
+ // src/view/labelbox.js
22231
+ var labelboxPositions = ["TL", "TC", "TR", "L", "R", "BL", "BC", "BR"];
22232
+ var labelboxStyle = `.gramlot-labelbox[hidden]{display:none!important}
22233
+ .gramlot-labelbox{box-sizing:border-box;min-width:0;min-height:0;--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control';grid-template-columns:minmax(0,1fr);grid-template-rows:max-content minmax(0,1fr)}
22234
+ .gramlot-labelbox>.label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .gramlot-labelbox>.control-box{box-sizing:border-box;grid-area:control;min-width:0;min-height:0;display:grid;grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
22235
+ .gramlot-labelbox>.control-box>*{max-width:100%;box-sizing:border-box}
22236
+ .gramlot-labelbox[data-position='L']{grid-template-areas:'label control';grid-template-rows:minmax(0,1fr)}
22237
+ .gramlot-labelbox[data-position='R']{grid-template-areas:'control label';grid-template-columns:minmax(0,1fr) max-content;grid-template-rows:minmax(0,1fr)}
22238
+ .gramlot-labelbox[data-position='L']>.label-box,.gramlot-labelbox[data-position='R']>.label-box{align-self:center}
22239
+ .gramlot-labelbox[data-position^='B']{grid-template-areas:'control' 'label';grid-template-rows:minmax(0,1fr) max-content}
22240
+ .gramlot-labelbox[data-position$='C']>.label-box{text-align:center}
22241
+ .gramlot-labelbox[data-position$='R']>.label-box{text-align:right}
22242
+ .gramlot-labelbox>.label-box[hidden]{display:none} .gramlot-labelbox>.label-box label{display:block}
22243
+ .gramlot-labelbox[data-position='L']>.label-box{text-align:right;padding-right:2px}
22244
+ .gramlot-labelbox[data-formlet-aligned]>.label-box>label{width:max-content;margin-left:auto}
22245
+ .gramlot-labelbox[data-position='L']{grid-template-columns:var(--gramlot-label-width,var(--gramlot-formlet-label-width,max-content)) minmax(0,1fr)}
22246
+ .gramlot-labelbox:has(>.label-box[hidden]){gap:0;grid-template-areas:'control';grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr)}
22247
+ .gramlot-labelbox[data-variant='card']{gap:0;border:1px solid var(--gramlot-border-control,#b9c2ce);border-radius:var(--gramlot-window-radius,9px);background:var(--gramlot-surface,#fff);box-shadow:0 3px 10px #0002}
22248
+ .gramlot-labelbox[data-variant='card']>.label-box{background:var(--gramlot-card-header-background,#303946);color:var(--gramlot-card-header-color,#fff);padding:7px 12px;border-radius:calc(var(--gramlot-window-radius,9px) - 1px) calc(var(--gramlot-window-radius,9px) - 1px) 0 0;font-weight:600}
22249
+ .gramlot-labelbox[data-variant='card']>.control-box{padding:12px}
22250
+ .gramlot-labelbox[data-movable]>.label-box{cursor:grab;touch-action:none;user-select:none}
22251
+ .gramlot-labelbox[data-selected]{outline:2px solid var(--gramlot-focus-ring,var(--gramlot-brand-blue,#3766b5));outline-offset:-2px}
22252
+ .gramlot-labelbox[data-tray-block]>.label-box{position:relative;padding-inline:32px 60px}
22253
+ .gramlot-labelbox>.label-box>.tray-settings-button{position:absolute;right:3px;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:26px;height:26px;padding:4px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:pointer}
22254
+ .gramlot-labelbox>.label-box>button[hidden]{display:none}
22255
+ .gramlot-labelbox>.label-box>.tray-settings-button[data-kind=layer]{right:31px}
22256
+ .tray-settings-button{opacity:.65}
22257
+ .tray-settings-button:hover,.tray-settings-button:focus-visible{opacity:1}
22258
+ .tray-settings-button svg{width:18px;height:18px;pointer-events:none}
22259
+ .gramlot-labelbox>.label-box>.tray-settings-button:hover{background:color-mix(in srgb,currentColor 12%,transparent)}
22260
+ .tray-settings-button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
22261
+
22262
+ .gramlot-labelbox>.label-box>.tray-rotate{position:absolute;left:3px;top:50%;transform:translateY(-50%);display:grid;place-items:center;width:26px;height:26px;padding:4px;border:0;border-radius:4px;background:transparent;color:inherit;cursor:grab;touch-action:none;opacity:.7}
22263
+ .tray-rotate svg{width:18px;height:18px;pointer-events:none}
22264
+ .gramlot-labelbox>.label-box>.tray-rotate:hover{opacity:1;background:color-mix(in srgb,currentColor 12%,transparent)}
22265
+ .tray-rotate:focus-visible{opacity:1;outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}
22266
+ .gramlot-labelbox[data-rotating]>.label-box>.tray-rotate{cursor:grabbing}
22267
+ .gramlot-labelbox[data-moving]>.label-box{cursor:grabbing}
22268
+ .gramlot-labelbox[data-resizable]>.control-box{overflow:auto}
22269
+ .gramlot-labelbox>.tray-resize{position:absolute;right:1px;bottom:1px;width:22px;height:22px;padding:2px;display:grid;place-items:end;border:0;background:transparent;color:inherit;cursor:nwse-resize;touch-action:none;border-radius:3px;opacity:.65}
22270
+ .gramlot-labelbox>.tray-resize[hidden]{display:none}
22271
+ .gramlot-labelbox>.tray-resize svg{width:16px;height:16px;pointer-events:none}
22272
+ .gramlot-labelbox>.tray-resize:hover,.gramlot-labelbox>.tray-resize:focus-visible{opacity:1}
22273
+ .gramlot-labelbox>.tray-resize:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:-2px}`;
22274
+ function createLabelbox(document, controlBox) {
22275
+ const box = document.createElement("div"), labelBox = document.createElement("div");
22276
+ const fieldLabel = document.createElement("label");
22277
+ labelBox.append(fieldLabel);
22278
+ box.append(labelBox, controlBox);
22279
+ const layout = { box, labelBox, fieldLabel, controlBox, previous: { box: {}, label: {}, labelBox: {}, controlBox: {} } };
22280
+ box.labelbox = layout;
22281
+ return layout;
22282
+ }
22283
+ function projectLabelbox(layout, attrs, adapt) {
22284
+ const { lbl, lbl_variant, lbl_position = lbl_variant === "card" ? "TC" : "TL", ...rest } = attrs;
22285
+ if (!labelboxPositions.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
22286
+ const groups = { box: {}, label: {}, labelBox: {}, controlBox: {} };
22287
+ const prefixes = [["box_l_", "labelBox"], ["box_c_", "controlBox"], ["lbl_", "label"], ["box_", "box"]];
22288
+ for (const [name, value] of Object.entries(rest)) {
22289
+ const match = prefixes.find(([prefix]) => name.startsWith(prefix));
22290
+ if (match) {
22291
+ groups[match[1]][name.slice(match[0].length)] = value;
22292
+ delete rest[name];
22293
+ }
22294
+ }
22295
+ const elements = { box: layout.box, label: layout.fieldLabel, labelBox: layout.labelBox, controlBox: layout.controlBox };
22296
+ for (const [name, element] of Object.entries(elements)) {
22297
+ const next = adapt(groups[name]), previous = layout.previous[name];
22298
+ for (const key of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)])) {
22299
+ if (next[key] == null) element.removeAttribute(key);
22300
+ else element.setAttribute(key, String(next[key]));
22301
+ }
22302
+ layout.previous[name] = next;
22303
+ }
22304
+ if (attrs.lbl_width == null) layout.box.style.removeProperty("--gramlot-label-width");
22305
+ else layout.box.style.setProperty("--gramlot-label-width", attrs.lbl_width);
22306
+ layout.box.classList.add("labelbox", "gramlot-labelbox");
22307
+ layout.labelBox.classList.add("label-box");
22308
+ layout.controlBox.classList.add("control-box");
22309
+ layout.box.dataset.position = lbl_position;
22310
+ if (lbl_variant == null) delete layout.box.dataset.variant;
22311
+ else layout.box.dataset.variant = lbl_variant;
22312
+ layout.fieldLabel.textContent = lbl ?? "";
22313
+ layout.labelBox.hidden = lbl == null || lbl === "";
22314
+ layout.box.dispatchEvent(new layout.box.ownerDocument.defaultView.Event("gramlot-label-layout", { bubbles: true }));
22315
+ return rest;
22316
+ }
22317
+ function labelboxContent(presentation) {
22318
+ return presentation?.labelbox ? presentation.labelbox.controlBox.firstElementChild : presentation;
22319
+ }
22320
+ function labelboxPresentation(content) {
22321
+ const box = content?.parentElement?.parentElement;
22322
+ return box?.labelbox && labelboxContent(box) === content ? box : content;
22323
+ }
22324
+
22158
22325
  // src/webcomponent.js
22159
22326
  var NAME2 = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
22160
22327
  var RESERVED = /* @__PURE__ */ new Set([
@@ -22213,6 +22380,7 @@ function defineComponent({ name, tag: tag2, base, mixins = [], parameters: param
22213
22380
  command,
22214
22381
  bagStore,
22215
22382
  mixins: Object.freeze([...mixins]),
22383
+ labelbox: mixins.some((mixin) => mixin.labelbox === true),
22216
22384
  parameters: freeze(structuredClone(effective)),
22217
22385
  childParameters: freeze(structuredClone(childParameters)),
22218
22386
  sourceContext,
@@ -22289,6 +22457,7 @@ var ComponentCollection = class _ComponentCollection {
22289
22457
  command: component.command,
22290
22458
  ...Object.keys(component.childParameters).length ? { childParameters: structuredClone(component.childParameters) } : {},
22291
22459
  ...component.sourceContext ? { sourceContext: true } : {},
22460
+ ...component.labelbox ? { labelbox: true } : {},
22292
22461
  ...component.dragSource ? { dragSource: true } : {},
22293
22462
  ...component.bagStore ? { bagStore: true } : {}
22294
22463
  } }
@@ -22703,6 +22872,7 @@ var BINDING_ATTRIBUTES = /* @__PURE__ */ new Set([
22703
22872
  "_onRemote",
22704
22873
  "_onCalling",
22705
22874
  "onClose",
22875
+ "onEnd",
22706
22876
  "onDrag",
22707
22877
  "onDrop",
22708
22878
  "dropTargetCb",
@@ -22724,7 +22894,7 @@ var NATIVE_ATTRIBUTES = {
22724
22894
  canvas: ["width", "height"]
22725
22895
  };
22726
22896
  var DISPLAY_ATTRIBUTES = ["format", "mask", "locale", "timeZone", "places", "dtype"];
22727
- var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "xlink:href", "xlink_href"]);
22897
+ var URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src", "data", "action", "formaction", "xlink:href", "xlink_href"]);
22728
22898
  function withoutBindingAttributes(attrs) {
22729
22899
  return Object.fromEntries(Object.entries(attrs).filter(([name, value]) => !(value && typeof value === "object" && Object.hasOwn(value, "$gramlotRef")) && !BINDING_ATTRIBUTES.has(name) && !BINDING_ATTRIBUTE_PREFIXES.some((prefix) => name.startsWith(prefix))));
22730
22900
  }
@@ -22746,6 +22916,9 @@ function requireNoScriptAttributes(node, attrs, prefixes = []) {
22746
22916
  }
22747
22917
  }
22748
22918
  }
22919
+ if (attrs.onEnd != null && (node.nodeTag.toLowerCase() !== "transformpane" || !node._getMeta("gramlot_component")?.parameters?.onEnd)) {
22920
+ throw new Error("onEnd is only supported on transformPane");
22921
+ }
22749
22922
  if (attrs.onClose != null && !node.parentNode?._getMeta("gramlot_component")?.childParameters?.onClose) {
22750
22923
  throw new Error("onClose is only supported on a tab/stack panel");
22751
22924
  }
@@ -22976,7 +23149,7 @@ var ToolbarOverflow = class {
22976
23149
  if (available <= 0) return;
22977
23150
  let active = menu.ownerDocument.activeElement;
22978
23151
  while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
22979
- const units = [...menu.children].filter((unit) => !unit.hidden && (unit.localName !== "gramlot-menu" || unit.permanent));
23152
+ const units = [...menu.children].filter((unit) => !unit.hidden && (labelboxContent(unit).localName !== "gramlot-menu" || labelboxContent(unit).permanent));
22980
23153
  for (const unit of this.#units) if (!units.includes(unit)) {
22981
23154
  this.#resize.unobserve(unit);
22982
23155
  unit.removeAttribute("slot");
@@ -22994,15 +23167,15 @@ var ToolbarOverflow = class {
22994
23167
  const gap = parseFloat(win.getComputedStyle(this.#viewport).gap) || 0;
22995
23168
  const lengths = new Map(units.map((unit) => {
22996
23169
  const css = win.getComputedStyle(unit);
22997
- const length = unit.localName === "gramlot-spacer" ? unit.parameters.size ?? 0 : unit.getBoundingClientRect()[axis];
23170
+ const length = labelboxContent(unit).localName === "gramlot-spacer" ? labelboxContent(unit).parameters.size ?? 0 : unit.getBoundingClientRect()[axis];
22998
23171
  return [unit, length + (parseFloat(css[vertical ? "marginTop" : "marginLeft"]) || 0) + (parseFloat(css[vertical ? "marginBottom" : "marginRight"]) || 0)];
22999
23172
  }));
23000
- const separator = (unit) => unit.getAttribute("role") === "separator";
23001
- const tidy = (list) => list.filter((unit, index) => !separator(unit) || list.slice(0, index).some((item) => item.localName !== "gramlot-spacer" && !separator(item)) && list.slice(index + 1).find((item) => item.localName !== "gramlot-spacer") && !separator(list.slice(index + 1).find((item) => item.localName !== "gramlot-spacer")));
23173
+ const separator = (unit) => labelboxContent(unit).getAttribute("role") === "separator";
23174
+ const tidy = (list) => list.filter((unit, index) => !separator(unit) || list.slice(0, index).some((item) => labelboxContent(item).localName !== "gramlot-spacer" && !separator(item)) && list.slice(index + 1).find((item) => labelboxContent(item).localName !== "gramlot-spacer") && !separator(list.slice(index + 1).find((item) => labelboxContent(item).localName !== "gramlot-spacer")));
23002
23175
  const required = (remaining2) => remaining2.reduce((sum2, unit) => sum2 + lengths.get(unit), 0) + Math.max(0, remaining2.length - 1) * gap;
23003
23176
  let remaining = tidy(units);
23004
23177
  if (required(remaining) > available) {
23005
- const candidates = units.map((unit, index) => ({ unit, index })).filter(({ unit }) => unit.localName === "gramlot-menu-line" && !separator(unit) && unit.parameters.overflowable).sort((a, b) => a.unit.parameters.priority - b.unit.parameters.priority || b.index - a.index);
23178
+ const candidates = units.map((unit, index) => ({ unit, index })).filter(({ unit }) => labelboxContent(unit).localName === "gramlot-menu-line" && !separator(unit) && labelboxContent(unit).parameters.overflowable).sort((a, b) => labelboxContent(a.unit).parameters.priority - labelboxContent(b.unit).parameters.priority || b.index - a.index);
23006
23179
  for (const { unit } of candidates) {
23007
23180
  if (required(remaining) <= available - 32) break;
23008
23181
  this.#overflow.add(unit);
@@ -23144,7 +23317,7 @@ function MenuContainer(HTMLElement) {
23144
23317
  return this.#overflow.contains(item);
23145
23318
  }
23146
23319
  get usableItems() {
23147
- return this.items.filter((item) => item.slot !== "suppressed" && !item.disabled && !item.hidden && !item.closest("[hidden]") && item.getAttribute("role") !== "separator");
23320
+ return this.items.filter((item) => labelboxPresentation(item).slot !== "suppressed" && !item.disabled && !item.hidden && !item.closest("[hidden]") && item.getAttribute("role") !== "separator");
23148
23321
  }
23149
23322
  get parentMenu() {
23150
23323
  return this.parentElement?.closest("gramlot-menu") ?? null;
@@ -23192,13 +23365,13 @@ function MenuContainer(HTMLElement) {
23192
23365
  return keys;
23193
23366
  }
23194
23367
  #attachOpening() {
23195
- const owner = this.parentElement;
23368
+ const owner = labelboxPresentation(this).parentElement;
23196
23369
  if (this.permanent || !owner) return;
23197
23370
  if (["gramlot-menu-line", "gramlot-drop-down-button"].includes(owner.localName)) {
23198
- this.slot = "menu";
23371
+ labelboxPresentation(this).slot = "menu";
23199
23372
  return;
23200
23373
  }
23201
- this.removeAttribute("slot");
23374
+ labelboxPresentation(this).removeAttribute("slot");
23202
23375
  if (owner.localName === "gramlot-menu") return;
23203
23376
  this.#attachment = owner;
23204
23377
  this.#attachmentEvents = new this.ownerDocument.defaultView.AbortController();
@@ -23420,7 +23593,7 @@ function menuLine(Base) {
23420
23593
  return this.parentElement?.closest("gramlot-menu") ?? null;
23421
23594
  }
23422
23595
  get submenu() {
23423
- return [...this.children].find((child) => child.localName === "gramlot-menu") ?? null;
23596
+ return [...this.children].map(labelboxContent).find((child) => child.localName === "gramlot-menu") ?? null;
23424
23597
  }
23425
23598
  get entryCaption() {
23426
23599
  return this.parameters.caption ?? this.#registry?.label ?? "";
@@ -23521,7 +23694,7 @@ function menuLine(Base) {
23521
23694
  else this.openSubmenu();
23522
23695
  return false;
23523
23696
  }
23524
- const drop = this.menuOwner?.parentElement;
23697
+ const drop = labelboxPresentation(this.menuOwner)?.parentElement;
23525
23698
  if (drop?.localName === "gramlot-drop-down-button") drop.selectCommand(this, event.shiftKey);
23526
23699
  else this.menuOwner.closeChain();
23527
23700
  return true;
@@ -23547,11 +23720,15 @@ function Command(HTMLElement) {
23547
23720
  const style = doc.createElement("style");
23548
23721
  style.textContent = `:host{vertical-align:middle} .control-box{display:flex;align-items:stretch}
23549
23722
  button{display:inline-flex;align-items:center;justify-content:center;gap:var(--gramlot-button-gap,.35em);font:inherit;
23550
- color:var(--gramlot-ink,CanvasText);background:var(--gramlot-button-background,var(--gramlot-field-background,Canvas));
23723
+ color:var(--gramlot-button-color,var(--gramlot-ink,CanvasText));background:var(--gramlot-button-background,var(--gramlot-field-background,Canvas));
23551
23724
  border:1px solid var(--gramlot-border-control,#888);border-radius:var(--gramlot-radius-sm,4px);
23552
23725
  min-height:max(var(--gramlot-field-height,28px),var(--gramlot-touch-target,0px));
23553
23726
  padding:var(--gramlot-button-padding,.25em .65em);cursor:pointer}
23554
23727
  button:hover:not(:disabled){background:var(--gramlot-button-hover,var(--gramlot-field-readonly-background,#eee))}
23728
+ :host(.button--secondary) button{background:var(--gramlot-selected,Highlight);color:var(--gramlot-action,CanvasText);border-color:transparent}
23729
+ :host(.button--secondary) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:var(--gramlot-action,CanvasText)}
23730
+ button:active:not(:disabled){filter:brightness(.9)}
23731
+ @media(prefers-contrast:more){button{border:2px solid currentColor}}
23555
23732
  :host(.button--quiet) button{background:transparent;color:var(--gramlot-action,CanvasText);border-color:transparent}
23556
23733
  :host(.button--quiet) button:hover:not(:disabled){background:var(--gramlot-selected,Highlight);color:var(--gramlot-action-hover,CanvasText);border-color:transparent}
23557
23734
  button:focus-visible{outline:2px solid var(--gramlot-focus-ring,Highlight);outline-offset:2px}
@@ -23566,7 +23743,9 @@ function Command(HTMLElement) {
23566
23743
  color:var(--gramlot-ink,CanvasText);background:var(--gramlot-field-background,Canvas);box-shadow:0 3px 12px #0003}
23567
23744
  :host(:is([role=menuitem],[role=menuitemcheckbox])){display:block} :host(:is([role=menuitem],[role=menuitemcheckbox])) button{width:100%;justify-content:start;border:0;background:transparent}
23568
23745
  :host([role=separator]){display:block;border-top:1px solid var(--gramlot-border-control,#888);margin:.25em}
23569
- :host([role=separator]) button{display:none}`;
23746
+ :host([role=separator]) button{display:none}
23747
+ @media(forced-colors:active){button,:host(.button--secondary) button,:host(.button--quiet) button{background:ButtonFace;color:ButtonText;border-color:ButtonText;filter:none}}
23748
+ `;
23570
23749
  this.shadowRoot.append(style);
23571
23750
  }
23572
23751
  get disabled() {
@@ -23763,7 +23942,7 @@ var DropDownButton = defineComponent({
23763
23942
  });
23764
23943
  }
23765
23944
  get menu() {
23766
- return [...this.children].find((child) => child.localName === "gramlot-menu");
23945
+ return [...this.children].map(labelboxContent).find((child) => child.localName === "gramlot-menu");
23767
23946
  }
23768
23947
  get menuItems() {
23769
23948
  return this.menu?.items ?? [];
@@ -25355,10 +25534,10 @@ function invokeHook(runtime, node, attribute, handler, context, inlineNames = Ob
25355
25534
 
25356
25535
  // src/view/controls.js
25357
25536
  var CONTROL_TAGS = /* @__PURE__ */ new Set(["input", "select", "textarea"]);
25358
- var REBUILD_ATTRIBUTES = ["type", "multiple", "group"];
25359
- function resolved(node, name) {
25360
- const value = node.getAttr(name);
25361
- return node.pointerType(value) ? node.getRelativeData(value) : value;
25537
+ var REBUILD_ATTRIBUTES = ["type", "multiple"];
25538
+ function resolved(control, name) {
25539
+ const node = control.node, value = node.getAttr(name);
25540
+ return node.pointerType(value) ? node.getRelativeData(value) : control.resolved[name];
25362
25541
  }
25363
25542
  var ControlAdapter = class _ControlAdapter {
25364
25543
  // Whether `live` moves the write from `change` to `input` (gate decision 3).
@@ -25396,14 +25575,15 @@ var ControlAdapter = class _ControlAdapter {
25396
25575
  return Object.hasOwn(INPUT_CONTROLS, type) ? INPUT_CONTROLS[type] : TextControl;
25397
25576
  }
25398
25577
  /**
25399
- * The resolved `type`, `multiple` and `group` of a form control element, as one comparable
25400
- * string, or null for any other element: a different shape rebuilds the element (C04.1, D7).
25578
+ * Attributes still requiring reconstruction, as one comparable string, or null for other
25579
+ * elements. Native input.type and input/select.multiple use setters; radio group changes
25580
+ * update the existing membership and never contribute to this signature.
25401
25581
  * `attrs` are the attributes of the renderer's resolved projection (`^`, `=` and `==` resolved).
25402
25582
  */
25403
25583
  static shape(element, attrs) {
25404
- if (element?.constructor.gramlotComponent?.parameters.value?.binding === "twoWay" && element.control.type === "radio") return JSON.stringify([attrs.group ?? null]);
25584
+ if (element?.constructor.gramlotComponent?.parameters.value?.binding === "twoWay" && element.control.type === "radio") return JSON.stringify([]);
25405
25585
  if (element?.namespaceURI !== XHTML_NS || !CONTROL_TAGS.has(element.localName)) return null;
25406
- return JSON.stringify(REBUILD_ATTRIBUTES.map((name) => attrs[name] ?? null));
25586
+ return JSON.stringify(REBUILD_ATTRIBUTES.filter((name) => (name !== "type" || element.localName !== "input") && (name !== "multiple" || !["input", "select"].includes(element.localName))).map((name) => attrs[name] ?? null));
25407
25587
  }
25408
25588
  constructor(binding, record2) {
25409
25589
  this.#binding = binding;
@@ -25448,7 +25628,7 @@ var ControlAdapter = class _ControlAdapter {
25448
25628
  this.#pending = true;
25449
25629
  return;
25450
25630
  }
25451
- if (this.constructor.preservesUnchangedValue && this.#hasProjectedValue && this.same(this.#projectedValue, value)) return;
25631
+ if (this.constructor.preservesUnchangedValue && this.#hasProjectedValue && this.same(this.#projectedValue, value) && (!this.#committing || this.same(this.read(), value))) return;
25452
25632
  this.#projectedValue = value;
25453
25633
  this.#hasProjectedValue = true;
25454
25634
  if (this.#committing && this.same(this.read(), value)) return;
@@ -25687,15 +25867,31 @@ var RadioControl = class extends CheckboxControl {
25687
25867
  super.detach();
25688
25868
  }
25689
25869
  /**
25690
- * Follow the semantic form owner: when a `form` or `formId` above the node was added, removed or
25691
- * moved, the button leaves its group and joins the group of the same name in its new scope, with a
25692
- * new generated `name`; the NodeBinding and the element stay (ASTRA-04). A button that is on and
25693
- * meets another button on in the new scope raises before any effect, as at the join (P11).
25870
+ * A changed group clears writable selections in both scopes without replacing the control.
25871
+ * Membership moves before Data writes so synchronous binding projections see the new group.
25872
+ * Form-owner-only moves keep their existing initial-conflict rule.
25694
25873
  */
25695
- refresh() {
25696
- if (this.#name === null) return;
25697
- const group = this.resolved.group;
25874
+ refresh(previousGroup = this.resolved.group) {
25875
+ const group = this.resolved.group ?? null;
25698
25876
  const form = formNode(this.node);
25877
+ if (!Object.is(previousGroup ?? null, group)) {
25878
+ const affected = /* @__PURE__ */ new Set([
25879
+ this,
25880
+ ...this.groups.peers(this),
25881
+ ...group === null ? [] : this.groups.peersOf(group, form)
25882
+ ]);
25883
+ this.groups.leave(this);
25884
+ this.#name = group === null ? null : this.groups.join(this, group, form);
25885
+ if (this.#name === null) this.element.removeAttribute("name");
25886
+ else this.element.setAttribute("name", this.#name);
25887
+ for (const peer of affected) {
25888
+ if (this.binding.closed || !this.binding.runtime.renderer.attached(this.node)) return;
25889
+ if (peer.binding.closed || !peer.binding.runtime.renderer.attached(peer.node)) continue;
25890
+ peer.binding.runtime.renderer.html.writeParameter(peer.node, "value", false);
25891
+ }
25892
+ return;
25893
+ }
25894
+ if (this.#name === null) return;
25699
25895
  if (this.groups.nameOf(group, form) === this.#name) return;
25700
25896
  this.#requireSingleTrue(group, form);
25701
25897
  this.groups.leave(this);
@@ -25708,7 +25904,7 @@ var RadioControl = class extends CheckboxControl {
25708
25904
  */
25709
25905
  #requireSingleTrue(group, form) {
25710
25906
  const node = this.node;
25711
- if (resolved(node, "value") && this.groups.peersOf(group, form).some((peer) => !peer.binding.closed && peer.read())) {
25907
+ if (resolved(this, "value") && this.groups.peersOf(group, form).some((peer) => !peer.binding.closed && peer.read())) {
25712
25908
  throw new Error(`${node.nodeTag} '${node.label}': several true values in radio group '${group}'`);
25713
25909
  }
25714
25910
  }
@@ -25742,7 +25938,7 @@ var RadioControl = class extends CheckboxControl {
25742
25938
  if (this.binding.closed) return;
25743
25939
  if (peer.binding.closed) continue;
25744
25940
  if (peer.element.checked) peer.element.checked = false;
25745
- if (resolved(peer.node, "value")) peer.commit(null);
25941
+ if (resolved(peer, "value")) peer.commit(null);
25746
25942
  }
25747
25943
  }
25748
25944
  };
@@ -25890,6 +26086,9 @@ function componentContext(adapter) {
25890
26086
  getDecimalLibrary,
25891
26087
  publish: (topic, payload) => node.publish(topic, payload),
25892
26088
  isActive: () => !binding.closed,
26089
+ reportError: (error, title) => {
26090
+ if (!binding.closed) binding.runtime.reportError(error, title);
26091
+ },
25893
26092
  callLogic: (name, keywords) => callLogic(binding.runtime, node, name, keywords),
25894
26093
  format: (value, options) => app.format(value, options),
25895
26094
  invoke,
@@ -25912,7 +26111,9 @@ function componentContext(adapter) {
25912
26111
  if (ok) for (const patch of result.datachanges) node.getRelativeData(".").update(patch);
25913
26112
  const attribute = ok ? "validate_onAccept" : "validate_onReject";
25914
26113
  if (rules[attribute]) {
25915
- const report = (error) => console.error("Validation notification failed:", error);
26114
+ const report = (error) => {
26115
+ if (!binding.closed) binding.runtime.reportError(error, "Validation callback failed");
26116
+ };
25916
26117
  try {
25917
26118
  const validations = Object.fromEntries(Object.entries(rules).map(([key, value]) => [key.slice(9), value]));
25918
26119
  const returned = invoke(attribute, rules[attribute], { value: result.value, result, validations, userChange: true });
@@ -25929,14 +26130,21 @@ function componentContext(adapter) {
25929
26130
  };
25930
26131
  }
25931
26132
  function commitComponent(host, outcome, commit) {
26133
+ const context = host.pageContext;
25932
26134
  const finish = (result) => {
25933
26135
  if (result.ok && result.isCurrent()) {
25934
26136
  commit(result);
25935
26137
  host.finishValidation(result);
25936
26138
  }
25937
26139
  };
25938
- if (outcome instanceof Promise) outcome.then(finish).catch((error) => console.error("Validation notification failed:", error));
25939
- else finish(outcome);
26140
+ if (outcome instanceof Promise) outcome.then(finish).catch((error) => context.reportError(error, "Field update failed"));
26141
+ else {
26142
+ try {
26143
+ finish(outcome);
26144
+ } catch (error) {
26145
+ context.reportError(error, "Field update failed");
26146
+ }
26147
+ }
25940
26148
  }
25941
26149
 
25942
26150
  // src/view/html.js
@@ -25988,9 +26196,10 @@ function domPropertyName(name) {
25988
26196
  return PROPERTY_NAMES.get(camel.toLowerCase()) ?? camel;
25989
26197
  }
25990
26198
  var HtmlElement = class {
25991
- constructor({ metadataAttributes = [], invokeScript = null, callLogic: callLogic2 = null } = {}) {
26199
+ constructor({ metadataAttributes = [], invokeScript = null, callLogic: callLogic2 = null, reportError = null } = {}) {
25992
26200
  this.invokeScript = invokeScript;
25993
26201
  this.callLogic = callLogic2;
26202
+ this.reportError = reportError;
25994
26203
  this.metadataAttributes = /* @__PURE__ */ new Set([...META_ATTRS, "_text", ...metadataAttributes]);
25995
26204
  }
25996
26205
  definition(node) {
@@ -26006,6 +26215,7 @@ var HtmlElement = class {
26006
26215
  return { meta, namespace, tag: tag2 };
26007
26216
  }
26008
26217
  validate(node, builder = node.builder) {
26218
+ this.validateLabelbox(node);
26009
26219
  const branch = node.value instanceof SourceBag;
26010
26220
  const text2 = branch ? node.getAttr("_text") : node.value;
26011
26221
  if (text2 != null && !["string", "number", "boolean"].includes(typeof text2)) {
@@ -26023,6 +26233,24 @@ var HtmlElement = class {
26023
26233
  const childTags = branch ? node.value.getNodes().map((child) => child.nodeTag).filter(Boolean) : [];
26024
26234
  builder.validateNode(node, { value: text2, attrs: declaredAttrs, childTags });
26025
26235
  }
26236
+ hasLabelbox(node) {
26237
+ const component = this.definition(node).meta.gramlot_component;
26238
+ if (component?.labelbox) return true;
26239
+ if (component?.presentationDefaults.length) return Object.hasOwn(node.attr, "lbl");
26240
+ return Object.keys(node.attr).some((name) => name === "lbl" || name.startsWith("lbl_") || name.startsWith("box_"));
26241
+ }
26242
+ validateLabelbox(node) {
26243
+ if (!this.hasLabelbox(node)) return;
26244
+ const { tag: tag2, namespace } = this.definition(node);
26245
+ if (namespace !== XHTML_NS && tag2 !== "svg" || ["html", "head", "body", "style", "script", "link", "meta", "title", "base", "tr", "td", "th", "thead", "tbody", "tfoot", "col", "colgroup", "caption", "option", "optgroup", "li", "dt", "dd", "source", "track", "param", "area"].includes(tag2))
26246
+ throw new TypeError("Labelbox requires content that can be placed in an HTML flow container");
26247
+ const parent = node.parentNode;
26248
+ if (parent?.nodeTag) {
26249
+ const definition = this.definition(parent);
26250
+ if (definition.namespace !== XHTML_NS && definition.tag !== "foreignObject" || ["table", "thead", "tbody", "tfoot", "tr", "colgroup", "select", "optgroup", "ul", "ol", "dl", "p", "button", "label"].includes(definition.tag))
26251
+ throw new TypeError("Labelbox requires an HTML flow container");
26252
+ }
26253
+ }
26026
26254
  create(node, document, tag2 = null, attrs = node.attr, visible = null) {
26027
26255
  const { tag: defaultTag, namespace, meta } = this.definition(node);
26028
26256
  tag2 ??= defaultTag;
@@ -26038,6 +26266,7 @@ var HtmlElement = class {
26038
26266
  }
26039
26267
  if (meta.gramlot_component?.sourceContext) {
26040
26268
  element.setSourceContext({
26269
+ reportError: (error, title) => this.reportError(node, error, title),
26041
26270
  publish: (topic, payload) => node.publish(topic, payload),
26042
26271
  writeParameter: (name, value) => this.writeParameter(node, name, value),
26043
26272
  callLogic: (name, keywords) => this.callLogic(node, name, keywords)
@@ -26045,7 +26274,20 @@ var HtmlElement = class {
26045
26274
  }
26046
26275
  const text2 = document.createTextNode(this.text(node));
26047
26276
  if (namespace !== XHTML_NS || !meta.void) element.append(text2);
26048
- const record2 = { element, text: text2, tag: tag2 };
26277
+ const record2 = { element, text: text2, tag: tag2, presentation: element };
26278
+ if (this.hasLabelbox(node)) {
26279
+ this.validateLabelbox(node);
26280
+ const controlBox = document.createElement("div");
26281
+ controlBox.append(element);
26282
+ record2.labelbox = createLabelbox(document, controlBox);
26283
+ record2.presentation = record2.labelbox.box;
26284
+ record2.labelId = `gramlot-label-${randomId()}`;
26285
+ record2.controlId = `gramlot-control-${randomId()}`;
26286
+ const style = document.createElement("style");
26287
+ style.textContent = labelboxStyle;
26288
+ record2.presentation.prepend(style);
26289
+ if (meta.gramlot_component?.labelbox) element.setLabelbox(record2.labelbox);
26290
+ }
26049
26291
  this.update(record2, node, attrs, DEFAULT_TEXT, visible);
26050
26292
  return record2;
26051
26293
  }
@@ -26085,6 +26327,8 @@ var HtmlElement = class {
26085
26327
  }
26086
26328
  }
26087
26329
  const { element, text: text2 } = record2;
26330
+ if (this.hasLabelbox(node) && !record2.labelbox)
26331
+ throw new TypeError("Declare lbl or box_* when creating an experimental HTML labelbox");
26088
26332
  const isHtml = element.namespaceURI === XHTML_NS;
26089
26333
  const renderAttributes = this.definition(node).meta.render_attributes ?? {};
26090
26334
  const previous = record2.attrs ?? {};
@@ -26096,31 +26340,55 @@ var HtmlElement = class {
26096
26340
  const parent = node.parentNode;
26097
26341
  if (parent?._getMeta("gramlot_component")?.childParameters) {
26098
26342
  const Parent = element.ownerDocument.defaultView.customElements.get(parent._getMeta("render_tag"));
26099
- attrs = Parent.projectChild(element, attrs, {
26343
+ attrs = Parent.projectChild(record2.presentation, attrs, {
26344
+ label: node.label,
26100
26345
  adapt,
26101
26346
  invoke: (name, code, keywords) => this.invokeScript(node, name, code, keywords),
26347
+ reportError: (error, title) => this.reportError(node, error, title),
26102
26348
  publish: (topic, payload) => node.publish(topic, payload),
26103
26349
  publishParent: (topic, payload) => parent.publish(topic, payload),
26104
26350
  writeParameter: (name, value) => this.writeParameter(node, name, value),
26105
26351
  remove: () => node.parentBag.popNode(node.label)
26106
26352
  });
26107
26353
  }
26354
+ if (record2.labelbox) {
26355
+ record2.labelbox.box.style.visibility = "";
26356
+ projectLabelbox(record2.labelbox, attrs, adapt);
26357
+ }
26108
26358
  if (this.definition(node).meta.gramlot_component) {
26109
26359
  if (this.definition(node).meta.gramlot_component.bagStore) {
26110
26360
  element.setStoreBag(node.getRelativeData(node.getAttr("storepath")));
26111
26361
  }
26112
26362
  attrs = element.projectAttributes(attrs, adapt);
26113
26363
  }
26364
+ if (record2.labelbox) {
26365
+ attrs = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== "lbl" && !name.startsWith("lbl_") && !name.startsWith("box_")));
26366
+ if (attrs.slot != null) record2.presentation.setAttribute("slot", attrs.slot);
26367
+ else if (record2.presentationSlot != null) record2.presentation.removeAttribute("slot");
26368
+ record2.presentationSlot = attrs.slot;
26369
+ delete attrs.slot;
26370
+ }
26114
26371
  attrs = Object.fromEntries(sourceAttributeItems({ ...attrs, ...renderAttributes }));
26115
26372
  const controlled = ControlAdapter.classFor(element, attrs) !== null;
26116
26373
  if (textValue2 === DEFAULT_TEXT) textValue2 = this.text(node);
26117
26374
  const nextText = textValue2 == null ? "" : String(textValue2);
26118
26375
  if (text2.data !== nextText) text2.data = nextText;
26119
26376
  const keys = [.../* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(attrs)])];
26120
- keys.sort((a, b) => (b === "sandbox") - (a === "sandbox"));
26377
+ keys.sort((a, b) => (b === "sandbox") - (a === "sandbox") || (isHtml && element.localName === "input" ? (b === "type") - (a === "type") : 0));
26121
26378
  for (const key of keys) {
26122
26379
  if (this.metadataAttributes.has(key) || ["ask", "_ask"].includes(key) || controlled && key === "value") continue;
26123
26380
  const value = attrs[key];
26381
+ if (isHtml && key === "multiple" && ["input", "select"].includes(element.localName)) {
26382
+ if (element.multiple !== Boolean(value)) element.multiple = Boolean(value);
26383
+ continue;
26384
+ }
26385
+ if (isHtml && element.localName === "input" && key === "type") {
26386
+ if (!Object.is(previous.type, value)) {
26387
+ if (value == null) element.removeAttribute("type");
26388
+ else element.type = String(value);
26389
+ }
26390
+ continue;
26391
+ }
26124
26392
  const attrName = key;
26125
26393
  const propertyName = domPropertyName(attrName);
26126
26394
  const isBoolean = isHtml && BOOLEAN_PROPERTIES.has(propertyName) && typeof element[propertyName] === "boolean";
@@ -26145,6 +26413,22 @@ var HtmlElement = class {
26145
26413
  else element.setAttribute("style", String(attrs.style));
26146
26414
  }
26147
26415
  record2.visible = visible;
26416
+ if (record2.labelbox) {
26417
+ const { fieldLabel, labelBox, box } = record2.labelbox;
26418
+ if (["input", "textarea", "select", "button", "output", "meter", "progress"].includes(record2.tag)) {
26419
+ if (!element.id) element.id = record2.controlId;
26420
+ fieldLabel.htmlFor = element.id;
26421
+ } else {
26422
+ fieldLabel.id = record2.labelId;
26423
+ if (!this.definition(node).meta.gramlot_component?.labelbox) {
26424
+ box.setAttribute("role", "group");
26425
+ if (labelBox.hidden) box.removeAttribute("aria-labelledby");
26426
+ else box.setAttribute("aria-labelledby", fieldLabel.id);
26427
+ }
26428
+ }
26429
+ box.hidden = !!attrs.hidden;
26430
+ if (visible === false) box.style.visibility = "hidden";
26431
+ }
26148
26432
  record2.attrs = attrs;
26149
26433
  }
26150
26434
  text(node) {
@@ -27764,7 +28048,7 @@ var RemoteBinding = class {
27764
28048
  }
27765
28049
  /** Start `_timing` again from its current value: called at every registration of the node's pointers. */
27766
28050
  register() {
27767
- this.#timers.startTiming(this.#control("_timing"), () => this.update());
28051
+ this.#timers.startTiming(this.#control("_timing"), () => this.trigger());
27768
28052
  }
27769
28053
  /**
27770
28054
  * A Data change of `remote` or of a `remote_<k>` parameter: `_userChanges` lets only the level `node`
@@ -27773,8 +28057,14 @@ var RemoteBinding = class {
27773
28057
  receive(change) {
27774
28058
  if (this.#control("_userChanges") && change.level !== "node") return;
27775
28059
  const delay = this.#control("_delay");
27776
- if (delay > 0) this.#timers.debounce(delay, () => this.update());
27777
- else this.update();
28060
+ if (delay > 0) this.#timers.debounce(delay, () => this.trigger());
28061
+ else this.trigger();
28062
+ }
28063
+ /** Runtime-owned triggers report failures; explicit update callers still receive rejection. */
28064
+ trigger() {
28065
+ void this.update().catch((error) => {
28066
+ if (!this.closed) this.binding.runtime.reportError(error, "Content could not be loaded");
28067
+ });
27778
28068
  }
27779
28069
  /**
27780
28070
  * Request the fragment for the current parameters. Nothing happens before the node's `start` step,
@@ -27809,7 +28099,7 @@ var RemoteBinding = class {
27809
28099
  throw new Error(`${node.nodeTag} '${node.label}': remote '${name}' failed: ${error.message}`, { cause: error });
27810
28100
  }
27811
28101
  const onRemote = node.getAttr("_onRemote");
27812
- if (!this.closed && mounted && onRemote) this.#inline("_onRemote", onRemote, onRemote, params);
28102
+ if (!this.closed && mounted && onRemote) await this.#inline("_onRemote", onRemote, onRemote, params);
27813
28103
  }
27814
28104
  /**
27815
28105
  * Record the fragment `remoteSource` mounted on the node, with its method and the TYTX of its parameters:
@@ -27975,6 +28265,101 @@ var AskDialog = class {
27975
28265
  }
27976
28266
  };
27977
28267
 
28268
+ // src/binding/error-notifications.js
28269
+ var ErrorNotifications = class {
28270
+ #runtime;
28271
+ #id = `errors_${randomId()}`;
28272
+ #group = null;
28273
+ #notices = /* @__PURE__ */ new Map();
28274
+ #dismissed = /* @__PURE__ */ new Set();
28275
+ #overflowCount = 0;
28276
+ constructor(runtime) {
28277
+ this.#runtime = runtime;
28278
+ }
28279
+ show(error, title) {
28280
+ const seen = /* @__PURE__ */ new Set(), details = [];
28281
+ for (let current = error; current !== null && typeof current === "object" && !seen.has(current); current = current.cause) {
28282
+ if (current.name === "AbortError") return;
28283
+ seen.add(current);
28284
+ details.push(current.stack ?? current.message);
28285
+ }
28286
+ const message = typeof error?.message === "string" ? error.message : String(error);
28287
+ queueMicrotask(() => {
28288
+ if (this.#runtime.disposed) return;
28289
+ this.#show(message, title, details.join("\nCaused by:\n"));
28290
+ });
28291
+ }
28292
+ #show(message, title, details) {
28293
+ const app = this.#runtime.gramlot, key = JSON.stringify([title, message]);
28294
+ if (this.#dismissed.has(key)) return;
28295
+ let panel = this.#runtime.nodeIds.get(this.#id);
28296
+ if (!panel) {
28297
+ this.#notices.clear();
28298
+ this.#overflowCount = 0;
28299
+ if (this.#group === null) {
28300
+ const notices = this;
28301
+ class Logic {
28302
+ close(node) {
28303
+ notices.#close(node.getAttr("notice"));
28304
+ }
28305
+ }
28306
+ this.#group = `errors_${randomId()}`;
28307
+ this.#runtime.logicRegistry.register(Logic, { group: this.#group, resource: "gramlot:error-notifications" });
28308
+ }
28309
+ const builder = new GramlotBuilder();
28310
+ builder.root.aside({
28311
+ nodeId: this.#id,
28312
+ class: "gramlot-error-notifications",
28313
+ popover: "manual",
28314
+ "aria-label": "Error notifications",
28315
+ style: "position:fixed;inset:auto max(12px,env(safe-area-inset-right)) max(12px,env(safe-area-inset-bottom)) auto;margin:0;width:360px;max-width:calc(100vw - 24px);max-height:50vh;overflow:auto;box-sizing:border-box;padding:0;border:1px solid var(--gramlot-border-control,#aab4c2);border-radius:8px;background:var(--gramlot-surface,#fff);color:var(--gramlot-ink,#222);font:13px/1.4 system-ui;box-shadow:0 6px 24px #0003;"
28316
+ });
28317
+ app.src.source.setItem(this.#id, app.src.prepareSource(builder.source));
28318
+ panel = this.#runtime.nodeIds.get(this.#id);
28319
+ }
28320
+ if (this.#notices.has(key)) return;
28321
+ if (this.#notices.size === 5) {
28322
+ const text2 = `${++this.#overflowCount} additional errors`;
28323
+ const counter = panel.value.getNode("overflow");
28324
+ if (counter) counter.setValue(text2);
28325
+ else app.src.builder.wrapSource(panel).p(text2, { node_label: "overflow", role: "status", style: "margin:0;padding:12px;" });
28326
+ return;
28327
+ }
28328
+ const id = `notice_${randomId()}`;
28329
+ const fragment = new GramlotBuilder();
28330
+ const notice = fragment.root.article({ role: "alert", style: "color:inherit;padding:12px;border-bottom:1px solid var(--gramlot-border,#ddd);" });
28331
+ const header = notice.div({ style: "display:flex;align-items:start;gap:12px;" });
28332
+ header.strong(`==${JSON.stringify(title)}`, { style: "flex:1;color:var(--gramlot-error,#b13d48);" });
28333
+ header.html_button("\xD7", {
28334
+ type: "button",
28335
+ notice: id,
28336
+ connect_onclick: `${this.#group}.close`,
28337
+ "aria-label": "Dismiss notification",
28338
+ title: "Dismiss notification",
28339
+ style: "border:0;background:transparent;color:inherit;font:18px/1 system-ui;width:24px;height:24px;flex:0 0 24px;padding:0;cursor:pointer;"
28340
+ });
28341
+ notice.p(`==${JSON.stringify(message)}`, { style: "margin:6px 0;overflow-wrap:anywhere;" });
28342
+ const disclosure = notice.details({ style: "border:0;padding:0;margin:8px 0 0;background:transparent;" });
28343
+ disclosure.summary("Details", { style: "cursor:pointer;" });
28344
+ disclosure.pre(`==${JSON.stringify(details)}`, { style: "font:11px/1.4 monospace;white-space:pre-wrap;overflow-wrap:anywhere;margin:6px 0 0;padding:8px;border:0;border-radius:4px;background:var(--gramlot-surface-subtle,#f2f4f6);" });
28345
+ const slot = app.src.builder.wrapSource(panel).div({ node_label: id });
28346
+ sourceTarget(slot).setValue(app.src.prepareSource(fragment.source));
28347
+ this.#notices.set(key, id);
28348
+ app.dom.getDomNode(panel).showPopover();
28349
+ }
28350
+ #close(id) {
28351
+ const panel = this.#runtime.nodeIds.get(this.#id);
28352
+ panel.value.popNode(id);
28353
+ for (const [key, value] of this.#notices) if (value === id) {
28354
+ this.#notices.delete(key);
28355
+ this.#dismissed.add(key);
28356
+ }
28357
+ if (!this.#notices.size) {
28358
+ this.#runtime.gramlot.src.source.popNode(this.#id);
28359
+ }
28360
+ }
28361
+ };
28362
+
27978
28363
  // src/binding/runtime.js
27979
28364
  var PROVIDERS = {
27980
28365
  dataFormula: FormulaProvider,
@@ -27991,6 +28376,7 @@ var BindingRuntime = class {
27991
28376
  #installer;
27992
28377
  #inlineCompiler;
27993
28378
  #askDialog;
28379
+ #errorNotifications;
27994
28380
  #subscriptions;
27995
28381
  #subscription = `gramlot-data-${randomId()}`;
27996
28382
  #disposed = false;
@@ -28001,10 +28387,14 @@ var BindingRuntime = class {
28001
28387
  this.#installer = new DataInstaller(this);
28002
28388
  this.#inlineCompiler = new InlineCompiler(this);
28003
28389
  this.#askDialog = new AskDialog(this);
28390
+ this.#errorNotifications = new ErrorNotifications(this);
28004
28391
  }
28005
28392
  get gramlot() {
28006
28393
  return this.#gramlot;
28007
28394
  }
28395
+ reportError(error, title) {
28396
+ if (!this.disposed) this.#errorNotifications.show(error, title);
28397
+ }
28008
28398
  /** The page topics and Source self-topics: the private `_subscriptions` of the Gramlot instance, given at construction. */
28009
28399
  get subscriptions() {
28010
28400
  return this.#subscriptions;
@@ -28108,7 +28498,7 @@ var BindingRuntime = class {
28108
28498
  const nodes = this.#branchNodes(node);
28109
28499
  for (const each of nodes) this.bindingFor(each)?.rebind();
28110
28500
  for (const each of nodes) this.renderer.project(each);
28111
- for (const each of nodes) this.bindingFor(each)?.remote?.update();
28501
+ for (const each of nodes) this.bindingFor(each)?.remote?.trigger();
28112
28502
  }
28113
28503
  /**
28114
28504
  * Semantic work of one Source event, called inside the renderer FIFO (§5.2).
@@ -28258,7 +28648,7 @@ var BindingRuntime = class {
28258
28648
  if (binding.hasStamp("start")) return;
28259
28649
  binding.stamp("start");
28260
28650
  this.#lifecycle(binding, "start", "_onStart");
28261
- binding.remote?.update();
28651
+ binding.remote?.trigger();
28262
28652
  }
28263
28653
  /** Invoke the providers of `binding` for the lifecycle trigger `kind` when `attribute` is on; a number delays it. */
28264
28654
  #lifecycle(binding, kind, attribute) {
@@ -28677,7 +29067,7 @@ var DragDrop = class {
28677
29067
  effectAllowed,
28678
29068
  phase: "active",
28679
29069
  tags: [declaredTags, prepared.dragValues.dragTags].filter(Boolean).join(","),
28680
- endTopic: this.#renderer.binding.gramlot._subscriptions.topicFor(record2.node, "endDrag"),
29070
+ endTopic: this.#renderer.binding.subscriptions.topicFor(record2.node, "endDrag"),
28681
29071
  source: {
28682
29072
  pageId: this.#renderer.binding.gramlot.pageId ?? null,
28683
29073
  sourcePath: record2.node.fullpath,
@@ -28778,8 +29168,9 @@ var DragDrop = class {
28778
29168
  event.preventDefault();
28779
29169
  if (this.#session.phase !== "active") return;
28780
29170
  const session = this.#session;
29171
+ let target;
28781
29172
  try {
28782
- const target = this.#target(event);
29173
+ target = this.#target(event);
28783
29174
  if (this.#session !== session) {
28784
29175
  event.dataTransfer.dropEffect = "none";
28785
29176
  return;
@@ -28798,7 +29189,7 @@ var DragDrop = class {
28798
29189
  session.phase = "rejected";
28799
29190
  this.#clearPayload();
28800
29191
  }
28801
- this.#report(error);
29192
+ if (!target || this.#renderer.records.has(target.record.node)) this.#report(error);
28802
29193
  }
28803
29194
  }
28804
29195
  #showFeedback(element, accepted) {
@@ -28837,7 +29228,7 @@ var DragDrop = class {
28837
29228
  void this.#renderer.endDrag(session.record.node, { source: { ...session.source }, dropEffect }, session.endTopic).catch((error) => this.#report(error));
28838
29229
  }
28839
29230
  #report(error) {
28840
- console.error("Gramlot drag/drop failed:", error);
29231
+ this.#renderer.binding.reportError(error, "Drag and drop failed");
28841
29232
  }
28842
29233
  dispose() {
28843
29234
  this.#clearSession();
@@ -28870,6 +29261,9 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
28870
29261
  this.destination = destination;
28871
29262
  this.html = new HtmlElement({
28872
29263
  metadataAttributes: ["__ref"],
29264
+ reportError: (node, error, title) => {
29265
+ if (this.records.has(node)) binding.reportError(error, title);
29266
+ },
28873
29267
  callLogic: (node, name, keywords) => {
28874
29268
  const { group, method } = binding.gramlot.src.logicRegistry.resolve(name, node);
28875
29269
  return method.call(group, node, keywords);
@@ -28959,7 +29353,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
28959
29353
  const declared = node.getAttr();
28960
29354
  this.#presentationDefaults.set(node, Object.fromEntries(Object.entries(attrs).filter(([name]) => Object.hasOwn(declared, name) && component.presentationDefaults.some((prefix) => name.startsWith(prefix)))));
28961
29355
  }
28962
- if (component && (component.parameters.value?.binding === "twoWay" || component.presentationDefaults.length)) {
29356
+ if (this.html.hasLabelbox(node) || component?.presentationDefaults.length) {
28963
29357
  const ancestors = [];
28964
29358
  for (let parent = node.parentNode; parent; parent = parent.parentNode) {
28965
29359
  if (this.#presentationDefaults.has(parent)) ancestors.unshift(this.#presentationDefaults.get(parent));
@@ -29051,11 +29445,13 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29051
29445
  record2.shape = ControlAdapter.shape(record2.element, resolved2);
29052
29446
  this.records.set(node, record2);
29053
29447
  this.elements.set(record2.element, record2);
29448
+ this.elements.set(record2.presentation, record2);
29054
29449
  const control = ControlAdapter.for(record2.binding, record2);
29450
+ if (control || record2.element.namespaceURI === XHTML_NS && record2.element.localName === "input")
29451
+ record2.cleanup.push(() => record2.control?.detach());
29055
29452
  if (control) {
29056
29453
  record2.control = control;
29057
29454
  control.attach();
29058
- record2.cleanup.push(() => control.detach());
29059
29455
  this.#projectControl(record2, node, attrs, null);
29060
29456
  }
29061
29457
  const button = ButtonBinding.for(record2.binding, record2);
@@ -29078,7 +29474,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29078
29474
  child.container = record2.element;
29079
29475
  record2.children.add(child.node);
29080
29476
  }
29081
- return record2.element;
29477
+ return record2.presentation;
29082
29478
  }
29083
29479
  /**
29084
29480
  * Validate a detached candidate without changing the observed Source (§5.1 step 1): grammar,
@@ -29274,7 +29670,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29274
29670
  for (let i = siblings.indexOf(node) + 1; i < siblings.length; i++) {
29275
29671
  const record2 = this.records.get(siblings[i]);
29276
29672
  if (record2) {
29277
- before = record2.element ?? record2.start;
29673
+ before = record2.presentation ?? record2.start;
29278
29674
  break;
29279
29675
  }
29280
29676
  }
@@ -29353,18 +29749,23 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29353
29749
  * adaptation as the first render, by the node's own renderer (R16). A node without an element
29354
29750
  * (not built yet, frozen before its first build, a fragment) is left alone; under freeze the
29355
29751
  * elements already built are projected. `change` is the DataChange that asked for it, or null.
29356
- * A form control whose resolved `type`, `multiple` or `group` changed is rebuilt instead, keeping
29752
+ * Native input.type and input/select.multiple use setters. Other shape changes rebuild, keeping
29357
29753
  * its NodeBinding; under freeze the rebuild waits for the thaw (C04.1, D7). The resolved projection
29358
29754
  * (runtimeValues, then `==`) is computed once and is what every consumer reads, the rebuild included.
29359
29755
  */
29360
29756
  project(node, change = null) {
29361
29757
  const record2 = this.records.get(node);
29362
- if (!record2?.element) return;
29758
+ if (!record2?.element || !this.attached(node)) return;
29363
29759
  const renderer = this.getRender(node.builder);
29364
29760
  const previousDefaults = this.#presentationDefaults.get(node);
29365
29761
  const [value, runtimeAttrs] = node.rootBuilder.runtimeValues(node);
29366
29762
  const [, resolvedAttrs] = renderer._handleMeta(node, runtimeAttrs);
29367
29763
  const resolved2 = this.#resolvedAttributes.get(node);
29764
+ const typeChanged = record2.element.namespaceURI === XHTML_NS && record2.element.localName === "input" && !Object.is(record2.resolved.type, resolved2.type);
29765
+ const multipleChanged = record2.element.namespaceURI === XHTML_NS && ["input", "select"].includes(record2.element.localName) && Boolean(record2.resolved.multiple) !== Boolean(resolved2.multiple);
29766
+ const previousGroup = record2.resolved.group;
29767
+ const groupChanged = record2.control instanceof RadioControl && !Object.is(previousGroup ?? null, resolved2.group ?? null);
29768
+ if ((typeChanged || multipleChanged || groupChanged) && this.#isFrozen(node)) return;
29368
29769
  if (record2.shape !== ControlAdapter.shape(record2.element, resolved2)) {
29369
29770
  if (this.#isFrozen(node)) return;
29370
29771
  this.#rebuildAttributes.set(node, resolved2);
@@ -29375,6 +29776,16 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29375
29776
  }
29376
29777
  return;
29377
29778
  }
29779
+ const Control = typeChanged ? ControlAdapter.classFor(record2.element, resolved2) : null;
29780
+ const replaceControl = typeChanged && (record2.control?.constructor ?? null) !== Control;
29781
+ const keepDraft = (typeChanged || multipleChanged && record2.element.localName === "input") && !replaceControl && record2.control && Object.is(record2.resolved.value, resolved2.value);
29782
+ if (replaceControl) {
29783
+ record2.control?.detach();
29784
+ record2.control = null;
29785
+ }
29786
+ if (groupChanged && !replaceControl && resolved2.group != null && node.getAttr("name") != null) {
29787
+ throw new TypeError(`${node.nodeTag} '${node.label}': name and group are two names`);
29788
+ }
29378
29789
  record2.resolved = resolved2;
29379
29790
  let attrs = node._getMeta("subbuilder") ? resolvedAttrs : renderer.adaptAttrs(resolvedAttrs);
29380
29791
  const branch = node.value instanceof SourceBag;
@@ -29389,7 +29800,16 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29389
29800
  }
29390
29801
  attrs = this.componentAttributes(node, attrs);
29391
29802
  this.html.update(record2, node, attrs, branch ? attrs._text : text2, resolved2.visible ?? null);
29392
- this.#projectControl(record2, node, attrs, change);
29803
+ if (replaceControl && Control) {
29804
+ record2.control = new Control(record2.binding, record2);
29805
+ record2.control.attach();
29806
+ }
29807
+ if (groupChanged && !replaceControl) {
29808
+ record2.control.refresh(previousGroup ?? null);
29809
+ if (this.records.get(node) === record2 && !record2.binding.closed) this.project(node);
29810
+ return;
29811
+ }
29812
+ if (!keepDraft) this.#projectControl(record2, node, attrs, change);
29393
29813
  record2.control?.refresh();
29394
29814
  record2.button?.refresh();
29395
29815
  record2.menu?.refresh();
@@ -29412,7 +29832,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29412
29832
  let inherited = changed;
29413
29833
  if (component?.presentationDefaults.length) {
29414
29834
  inherited = new Set([...changed].filter((name) => !Object.hasOwn(declared, name)));
29415
- } else if (component?.parameters.value?.binding === "twoWay" && [...changed].some((name) => !Object.hasOwn(declared, name))) {
29835
+ } else if (this.html.hasLabelbox(child) && [...changed].some((name) => !Object.hasOwn(declared, name))) {
29416
29836
  this.project(child);
29417
29837
  }
29418
29838
  if (inherited.size) this.#refreshPresentation(child, inherited);
@@ -29500,7 +29920,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29500
29920
  }
29501
29921
  #rebuild(node) {
29502
29922
  const record2 = this.records.get(node);
29503
- const before = record2.element?.nextSibling ?? record2.end?.nextSibling ?? null;
29923
+ const before = record2.presentation?.nextSibling ?? record2.end?.nextSibling ?? null;
29504
29924
  const container = record2.container;
29505
29925
  const parent = record2.parent;
29506
29926
  let removeError = null;
@@ -29551,7 +29971,8 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
29551
29971
  }
29552
29972
  this.references?.remove(node);
29553
29973
  if (record2.element) this.elements.delete(record2.element);
29554
- record2.element?.remove();
29974
+ if (record2.presentation) this.elements.delete(record2.presentation);
29975
+ record2.presentation?.remove();
29555
29976
  record2.start?.remove();
29556
29977
  record2.end?.remove();
29557
29978
  record2.parent?.children.delete(node);
@@ -30004,6 +30425,15 @@ var DomHandler = class extends Handler {
30004
30425
  if (mode === "auto") root.removeAttribute("data-gramlot-touch");
30005
30426
  else root.setAttribute("data-gramlot-touch", mode);
30006
30427
  }
30428
+ /** Navigate the current document to an explicit HTTP(S) URL selected by page policy. */
30429
+ navigate(url) {
30430
+ if (typeof url !== "string" || !url) throw new TypeError("Navigation requires an absolute HTTP(S) URL");
30431
+ const target = new URL(url);
30432
+ if (!["http:", "https:"].includes(target.protocol) || target.username || target.password) {
30433
+ throw new TypeError("Navigation requires an HTTP(S) URL without credentials");
30434
+ }
30435
+ this.gramlot.src.renderer.destination.ownerDocument.defaultView.location.assign(target.href);
30436
+ }
30007
30437
  reference(descriptor) {
30008
30438
  return this.gramlot.src.renderer.references.resolve(descriptor);
30009
30439
  }
@@ -30291,117 +30721,1244 @@ var SubscriptionsHandler = class extends Handler {
30291
30721
  }
30292
30722
  };
30293
30723
 
30294
- // src/inout.js
30295
- var MAILTO_LIMIT = 2e3;
30296
- function leafText(value) {
30297
- if (!(value instanceof Date)) return String(value ?? "");
30298
- const text2 = value.toISOString();
30299
- return text2.endsWith("T00:00:00.000Z") ? text2.slice(0, 10) : text2;
30300
- }
30301
- var InOut = class {
30302
- constructor(gramlot, document) {
30303
- this.gramlot = gramlot;
30304
- this.document = document;
30724
+ // src/binding/device-resolver.js
30725
+ var DeviceResolver = class extends BagResolver {
30726
+ constructor(handler, name, cacheTime) {
30727
+ super({ cacheTime });
30728
+ this.handler = handler;
30729
+ this.name = name;
30730
+ this.failed = false;
30731
+ this.writing = false;
30732
+ this.request = null;
30733
+ this.revision = 0;
30734
+ this.received = 0;
30305
30735
  }
30306
- /** The Bag at path in the Data. */
30307
- branch(path) {
30308
- const value = this.gramlot.data.getItem(path);
30309
- if (!(value instanceof Bag)) throw new Error(`gramlot.utl.inout: no data Bag at '${path}'`);
30310
- return value;
30736
+ resolve({ static: isStatic = false } = {}) {
30737
+ if (!isStatic && !this.handler.disposed && !this.writing && !this.request && !this.failed && !this._node.attr.watching && this.expired) this.handler.refresh(this.name);
30738
+ return this.cachedValue;
30311
30739
  }
30312
- /** One `relative.path: value` line per leaf of the branch at path. */
30313
- mailText(path) {
30314
- const lines = [];
30315
- const walk2 = (bag, prefix) => {
30316
- for (const node of bag.getNodes()) {
30317
- const label = prefix + node.label;
30318
- if (node.value instanceof Bag) walk2(node.value, `${label}.`);
30319
- else lines.push(`${label}: ${leafText(node.value)}`);
30320
- }
30321
- };
30322
- walk2(this.branch(path), "");
30323
- return lines.join("\n");
30740
+ reset() {
30741
+ super.reset();
30742
+ this.failed = false;
30743
+ this.revision++;
30324
30744
  }
30325
- /** The mailto: URL of sendMail; longer than MAILTO_LIMIT raises an Error. */
30326
- mailtoUrl(path, email) {
30327
- const url = `mailto:${encodeURIComponent(email)}?subject=${encodeURIComponent(this.document.title)}&body=${encodeURIComponent(this.mailText(path))}`;
30328
- if (url.length > MAILTO_LIMIT) {
30329
- throw new Error(`gramlot.utl.inout.sendMail: the email of '${path}' is ${url.length} characters long, over the mailto: limit of ${MAILTO_LIMIT}; send it with sendHttp or save it as a file`);
30745
+ };
30746
+
30747
+ // src/handlers/device-handler.js
30748
+ var NAMES = ["appinfo", "location"];
30749
+ var ERROR_STATUS = {
30750
+ UNAVAILABLE: "unavailable",
30751
+ PERMISSION_DENIED: "denied",
30752
+ TIMEOUT: "error",
30753
+ FAILED: "error",
30754
+ CANCELLED: "cancelled"
30755
+ };
30756
+ function failureAttributes(error) {
30757
+ const code = Object.hasOwn(ERROR_STATUS, error?.code) ? error.code : "FAILED";
30758
+ return {
30759
+ status: ERROR_STATUS[code],
30760
+ error: code === "CANCELLED" ? null : { code, message: String(error?.message ?? "Device operation failed") }
30761
+ };
30762
+ }
30763
+ var DeviceHandler = class extends Handler {
30764
+ #database = null;
30765
+ #clipboardRequest = null;
30766
+ #captureRequest = null;
30767
+ #audio = null;
30768
+ #barcodeRequest = null;
30769
+ #hapticRequest = null;
30770
+ #stateEvents = /* @__PURE__ */ new Map();
30771
+ #sensors = /* @__PURE__ */ new Map();
30772
+ #biometricsRequest = null;
30773
+ #notificationRequest = null;
30774
+ #notificationEvents = null;
30775
+ #pushRequest = null;
30776
+ #pushEvents = null;
30777
+ #shortcutEvents = null;
30778
+ #linkEvents = null;
30779
+ constructor(gramlot) {
30780
+ super(gramlot);
30781
+ this.provider = null;
30782
+ this.disposed = false;
30783
+ this.monitor = null;
30784
+ this.retiring = null;
30785
+ this.resolvers = /* @__PURE__ */ new Map();
30786
+ this.cleanup = Promise.resolve();
30787
+ }
30788
+ installData() {
30789
+ const { gramlot } = this;
30790
+ gramlot.data.setItem("gramlot.device.database", null, { status: "idle", error: null });
30791
+ gramlot.data.setItem("gramlot.device.orientation", null, { status: "idle", error: null, listening: false });
30792
+ for (const name of ["gyroscope", "accelerometer"]) {
30793
+ gramlot.data.setItem(
30794
+ `gramlot.device.${name}`,
30795
+ null,
30796
+ { enabled: false, watching: false, status: "idle", error: null }
30797
+ );
30798
+ gramlot.data.getNode(`gramlot.device.${name}`).setAttr({ error: null }, false, true, false);
30799
+ this.#sensors.set(name, {
30800
+ node: gramlot.data.getNode(`gramlot.device.${name}`),
30801
+ stream: null,
30802
+ cleanup: Promise.resolve()
30803
+ });
30330
30804
  }
30331
- return url;
30332
- }
30333
- /** Prepare an email to email in the mail program of the user, with the data at path as text lines. */
30334
- sendMail(path, email) {
30335
- this.open(this.mailtoUrl(path, email));
30805
+ for (const name of NAMES) {
30806
+ const path = `gramlot.device.${name}`;
30807
+ const attrs = { status: "idle", error: null, cacheTime: name === "appinfo" ? -1 : 5 };
30808
+ if (name === "location") Object.assign(attrs, { enabled: false, watching: false });
30809
+ gramlot.data.setItem(path, null);
30810
+ const node = gramlot.data.getNode(path);
30811
+ node.setAttr(attrs, false, true, false);
30812
+ const resolver = new DeviceResolver(this, name, attrs.cacheTime);
30813
+ node.resolver = resolver;
30814
+ this.resolvers.set(name, resolver);
30815
+ }
30816
+ gramlot.data.setItem(
30817
+ "gramlot.device.clipboard",
30818
+ null,
30819
+ { status: "idle", error: null, text: "", copy: null, paste: null, operation: null }
30820
+ );
30821
+ const clipboard = gramlot.data.getNode("gramlot.device.clipboard");
30822
+ gramlot.data.setItem("gramlot.device.camera", null, { status: "idle", error: null, capture: null, choose: null });
30823
+ const camera = gramlot.data.getNode("gramlot.device.camera");
30824
+ gramlot.data.setItem("gramlot.device.barcode", null, { status: "idle", error: null, scan: null });
30825
+ const barcode = gramlot.data.getNode("gramlot.device.barcode");
30826
+ gramlot.data.setItem("gramlot.device.biometrics", null, { status: "idle", error: null, verify: null });
30827
+ const biometrics = gramlot.data.getNode("gramlot.device.biometrics");
30828
+ const notifications = new Bag();
30829
+ notifications.setItem("request", new Bag());
30830
+ for (const name of ["scheduled", "received", "action"]) notifications.setItem(name, null);
30831
+ gramlot.data.setItem(
30832
+ "gramlot.device.notifications",
30833
+ notifications,
30834
+ { status: "idle", error: null, schedule: null, listening: false, listenerError: null }
30835
+ );
30836
+ const notificationNode = gramlot.data.getNode("gramlot.device.notifications");
30837
+ const push = new Bag();
30838
+ for (const name of ["registration", "received", "action"]) push.setItem(name, null);
30839
+ gramlot.data.setItem(
30840
+ "gramlot.device.push",
30841
+ push,
30842
+ { status: "idle", error: null, register: null, listening: false, listenerError: null }
30843
+ );
30844
+ const pushNode = gramlot.data.getNode("gramlot.device.push");
30845
+ const links = new Bag();
30846
+ links.setItem("request", null);
30847
+ gramlot.data.setItem("gramlot.device.links", links, { listening: false, listenerError: null });
30848
+ const shortcuts = new Bag();
30849
+ shortcuts.setItem("request", null);
30850
+ gramlot.data.setItem("gramlot.device.shortcuts", shortcuts, { listening: false, listenerError: null });
30851
+ gramlot.data.setItem("gramlot.device.network", null, { status: "idle", error: null, listening: false });
30852
+ const lifecycle = new Bag();
30853
+ lifecycle.setItem("active", null);
30854
+ lifecycle.setItem("event", null);
30855
+ lifecycle.setItem("sequence", 0);
30856
+ gramlot.data.setItem("gramlot.device.lifecycle", lifecycle, { status: "idle", error: null, listening: false });
30857
+ gramlot.data.setItem(
30858
+ "gramlot.device.haptics",
30859
+ null,
30860
+ { status: "idle", error: null, impact: null, style: "medium", vibrate: null, duration: 600 }
30861
+ );
30862
+ const haptics = gramlot.data.getNode("gramlot.device.haptics");
30863
+ gramlot.data.setItem(
30864
+ "gramlot.device.audio",
30865
+ null,
30866
+ {
30867
+ status: "idle",
30868
+ error: null,
30869
+ recording: false,
30870
+ start: null,
30871
+ stop: null,
30872
+ cancel: null,
30873
+ share: null,
30874
+ shareStatus: "idle",
30875
+ shareError: null,
30876
+ shareActivity: null
30877
+ }
30878
+ );
30879
+ const audio = gramlot.data.getNode("gramlot.device.audio");
30880
+ gramlot.data.subscribe("gramlot.device", { update: (event) => {
30881
+ if (this.disposed) return;
30882
+ for (const [name, sensor] of this.#sensors) {
30883
+ if (event.node === sensor.node && event.attrs_diff?.enabled) {
30884
+ if (typeof sensor.node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
30885
+ this.#reconcileSensor(name, sensor);
30886
+ }
30887
+ }
30888
+ if (event.node === clipboard && event.fired) {
30889
+ if (event.attrs_diff?.copy?.new === true) this.#clipboardCommand(clipboard, "copy");
30890
+ if (event.attrs_diff?.paste?.new === true) this.#clipboardCommand(clipboard, "paste");
30891
+ }
30892
+ if (event.node === audio && event.fired) {
30893
+ if (event.attrs_diff?.start?.new === true) this.#startAudio(audio);
30894
+ if (event.attrs_diff?.stop?.new === true) this.#stopAudio(audio);
30895
+ if (event.attrs_diff?.cancel?.new === true) this.#cancelAudio(audio);
30896
+ if (event.attrs_diff?.share?.new === true) this.#shareAudio(audio);
30897
+ }
30898
+ if (event.node === haptics && event.fired && event.attrs_diff?.impact?.new === true) {
30899
+ this.#impact(haptics);
30900
+ }
30901
+ if (event.node === haptics && event.fired && event.attrs_diff?.vibrate?.new === true) {
30902
+ this.#vibrate(haptics);
30903
+ }
30904
+ if (event.node === barcode && event.fired && event.attrs_diff?.scan?.new === true) {
30905
+ this.#scanBarcode(barcode);
30906
+ }
30907
+ if (event.node === camera && event.fired && event.attrs_diff?.choose?.new === true) {
30908
+ this.#photo(camera, "choose");
30909
+ }
30910
+ if (event.node === camera && event.fired && event.attrs_diff?.capture?.new === true) {
30911
+ this.#photo(camera, "capture");
30912
+ }
30913
+ if (event.node === biometrics && event.fired && event.attrs_diff?.verify?.new === true) {
30914
+ this.#verifyBiometrics(biometrics);
30915
+ }
30916
+ if (event.node === notificationNode && event.fired && event.attrs_diff?.schedule?.new === true) {
30917
+ this.#scheduleNotification(notificationNode);
30918
+ }
30919
+ if (event.node === pushNode && event.fired && event.attrs_diff?.register?.new === true) {
30920
+ this.#registerPush(pushNode);
30921
+ }
30922
+ for (const resolver of this.resolvers.values()) {
30923
+ if (event.node !== resolver._node) continue;
30924
+ const { cacheTime } = event.node.attr;
30925
+ if (typeof cacheTime !== "number" || !Number.isFinite(cacheTime) || cacheTime < 0 && cacheTime !== -1) {
30926
+ throw new TypeError("Device cacheTime must be -1 or a nonnegative number of seconds");
30927
+ }
30928
+ resolver.cacheTime = cacheTime;
30929
+ if (resolver.name === "location") {
30930
+ if (typeof event.node.attr.enabled !== "boolean") throw new TypeError("Device enabled must be boolean");
30931
+ this.reconcile();
30932
+ }
30933
+ }
30934
+ } });
30336
30935
  }
30337
- /** POST the data at path as a JSON object to url; resolves with the Response, rejects on a status out of 2xx. */
30338
- async sendHttp(path, url) {
30339
- const body = JSON.stringify(this.branch(path).asDict(false, false, true));
30340
- const response = await this.document.defaultView.fetch(url, {
30341
- method: "POST",
30342
- headers: { "Content-Type": "application/json" },
30343
- body
30936
+ /** Attach the explicitly selected provider once, before the page reads device values. */
30937
+ attach(provider, { dispose = null } = {}) {
30938
+ this.assertLive();
30939
+ if (this.provider) throw new Error("A device provider is already attached");
30940
+ if (!Array.isArray(provider.capabilities) || provider.capabilities.some((name) => ![...NAMES, "camera", "biometrics", "notifications", "push", "shortcuts", "barcode", "network", "lifecycle", "haptics", "audio", "clipboard", "links", "orientation", "gyroscope", "accelerometer", "database"].includes(name))) {
30941
+ throw new TypeError("Unknown device provider capability");
30942
+ }
30943
+ if (dispose !== null && typeof dispose !== "function") throw new TypeError("Device attachment dispose must be a function");
30944
+ this.releaseProvider = dispose;
30945
+ this.provider = provider;
30946
+ this.installData();
30947
+ this.reconcile();
30948
+ this.#startStateEvents("orientation", (callback, signal) => provider.startOrientationEvents(callback, signal), (node, state) => {
30949
+ if (!["portrait", "landscape"].includes(state?.type) || !["primary", "secondary"].includes(state.direction) || !Number.isFinite(state.timestamp)) throw new TypeError("Invalid screen orientation from device provider");
30950
+ const value = new Bag();
30951
+ for (const key of ["type", "direction", "timestamp"]) value.setItem(key, state[key]);
30952
+ node.setValue(value, true, { status: "success", error: null }, true, false);
30953
+ });
30954
+ this.#startStateEvents("network", (callback, signal) => provider.startNetworkEvents(callback, signal), (node, state) => {
30955
+ if (typeof state?.connected !== "boolean" || !["none", "unknown", "wifi", "cellular"].includes(state.type)) {
30956
+ throw new TypeError("Invalid network state from device provider");
30957
+ }
30958
+ const value = new Bag();
30959
+ value.setItem("connected", state.connected);
30960
+ value.setItem("type", state.type);
30961
+ node.setValue(value, true, { status: "success", error: null }, true, false);
30962
+ });
30963
+ this.#startStateEvents("lifecycle", (callback, signal) => provider.startLifecycleEvents(callback, signal), (node, event) => {
30964
+ if (event?.kind === "state" && typeof event.active === "boolean") {
30965
+ node.staticValue.setItem("active", event.active);
30966
+ } else if (event?.kind === "pause" || event?.kind === "resume") {
30967
+ node.staticValue.setItem("event", event.kind);
30968
+ node.staticValue.setItem("sequence", node.staticValue.getItem("sequence") + 1);
30969
+ } else {
30970
+ throw new TypeError("Invalid lifecycle event from device provider");
30971
+ }
30972
+ node.setAttr({ status: "success", error: null }, true, true, false);
30973
+ });
30974
+ if (provider.capabilities.includes("links")) {
30975
+ this.#startLinkEvents(this.gramlot.data.getNode("gramlot.device.links"));
30976
+ }
30977
+ if (provider.capabilities.includes("shortcuts")) {
30978
+ this.#startShortcutEvents(this.gramlot.data.getNode("gramlot.device.shortcuts"));
30979
+ }
30980
+ if (provider.capabilities.includes("push")) {
30981
+ this.#startPushEvents(this.gramlot.data.getNode("gramlot.device.push"));
30982
+ }
30983
+ if (provider.capabilities.includes("notifications")) {
30984
+ this.#startNotificationEvents(this.gramlot.data.getNode("gramlot.device.notifications"));
30985
+ }
30986
+ }
30987
+ assertLive() {
30988
+ if (this.disposed) throw new Error("DeviceHandler is disposed");
30989
+ }
30990
+ resolver(name) {
30991
+ this.assertLive();
30992
+ if (!this.resolvers.has(name)) throw new TypeError(`Unknown device value: ${name}`);
30993
+ return this.resolvers.get(name);
30994
+ }
30995
+ invalidate(name) {
30996
+ this.resolver(name).reset();
30997
+ }
30998
+ /** Command only. Success/failure is delivered through Data, never a public Promise. */
30999
+ refresh(name) {
31000
+ const resolver = this.resolver(name);
31001
+ if (resolver.request) return;
31002
+ const request = { revision: resolver.revision, received: resolver.received };
31003
+ resolver.request = request;
31004
+ this.attributes(resolver, { status: "pending", error: null });
31005
+ Promise.resolve().then(() => {
31006
+ if (this.disposed || resolver.request !== request) return;
31007
+ this.requireCapability(name);
31008
+ return name === "appinfo" ? this.provider.readAppInfo() : this.provider.readLocation();
31009
+ }).then((value) => {
31010
+ if (this.disposed || resolver.request !== request) return;
31011
+ this.accept(resolver, value);
31012
+ if (resolver.revision !== request.revision) resolver._lastUpdate = null;
31013
+ }).catch((error) => {
31014
+ if (!this.disposed && resolver.request === request && resolver.received === request.received) {
31015
+ this.failure(resolver, error);
31016
+ }
31017
+ }).finally(() => {
31018
+ if (resolver.request === request) resolver.request = null;
30344
31019
  });
30345
- if (!response.ok) throw new Error(`gramlot.utl.inout.sendHttp: ${url} answered ${response.status}`);
30346
- return response;
30347
- }
30348
- /** Save the data at path as a TYTX file, which restore reads back with its exact types. */
30349
- save(path, filename) {
30350
- this.saveText(this.branch(path).toTytx(), filename, "application/json");
30351
31020
  }
30352
- /** Read a TYTX file chosen by the user into path; resolves with the restored Bag. Needs a user gesture. */
30353
- restore(path) {
30354
- const input = this.document.createElement("input");
30355
- input.type = "file";
30356
- input.accept = ".json,application/json";
30357
- return new Promise((resolve, reject) => {
30358
- input.addEventListener("change", async () => {
31021
+ // Page-owned state streams share lifetime/error handling, never public dispatch.
31022
+ #startStateEvents(name, start, accept) {
31023
+ const node = this.gramlot.data.getNode(`gramlot.device.${name}`);
31024
+ if (!this.provider.capabilities.includes(name)) {
31025
+ node.setAttr(failureAttributes({ code: "UNAVAILABLE", message: `${name} is unavailable` }), true, true, false);
31026
+ return;
31027
+ }
31028
+ const events = { controller: new AbortController() };
31029
+ this.#stateEvents.set(name, events);
31030
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31031
+ events.start = Promise.resolve().then(() => {
31032
+ if (events.controller.signal.aborted) return async () => {
31033
+ };
31034
+ return start((value) => {
31035
+ if (events.controller.signal.aborted) return;
30359
31036
  try {
30360
- const bag = fromTytx(await input.files[0].text());
30361
- if (!(bag instanceof Bag)) throw new TypeError("the file must contain a typed Bag");
30362
- this.gramlot.data.setItem(path, bag);
30363
- resolve(bag);
31037
+ accept(node, value);
30364
31038
  } catch (error) {
30365
- reject(new Error(
30366
- `gramlot.utl.inout.restore: the file is not a saved Gramlot branch: ${error.message}`,
30367
- { cause: error }
30368
- ));
31039
+ node.setAttr(failureAttributes(error), true, true, false);
30369
31040
  }
30370
- }, { once: true });
30371
- input.click();
31041
+ }, events.controller.signal);
31042
+ }).then((stop) => {
31043
+ if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
31044
+ return stop;
31045
+ });
31046
+ events.start.catch((error) => {
31047
+ const aborted = events.controller.signal.aborted;
31048
+ events.controller.abort();
31049
+ if (!aborted) node.setAttr({ ...failureAttributes(error), listening: false }, true, true, false);
30372
31050
  });
30373
31051
  }
30374
- /** Export the data at path as 'json' (Bag.toJson) or 'xml' (Bag.toXml, inside one root element named
30375
- * after the last segment of path); types become text. */
30376
- download(path, filename, format) {
30377
- if (!["json", "xml"].includes(format)) {
30378
- throw new Error(`gramlot.utl.inout.download: format '${format}' is not 'json' or 'xml'`);
31052
+ #reconcileSensor(name, sensor) {
31053
+ const { node } = sensor;
31054
+ if (!node.attr.enabled) {
31055
+ const stream2 = sensor.stream;
31056
+ if (!stream2) return;
31057
+ sensor.stream = null;
31058
+ stream2.controller.abort();
31059
+ sensor.cleanup = stream2.start.then((stop) => stop(), () => void 0).then(() => {
31060
+ if (!this.disposed && !sensor.stream) node.setAttr({ watching: false, status: "idle", error: null }, true, true, false);
31061
+ });
31062
+ sensor.cleanup.catch((error) => {
31063
+ if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
31064
+ });
31065
+ return;
30379
31066
  }
30380
- const bag = this.branch(path);
30381
- if (format === "json") {
30382
- this.saveText(bag.toJson(false), filename, "application/json");
30383
- } else {
30384
- const root = path.split(".").at(-1);
30385
- this.saveText(
30386
- `<?xml version='1.0' encoding='UTF-8'?>
30387
- <${root}>${bag.toXml()}</${root}>`,
30388
- filename,
30389
- "application/xml"
30390
- );
31067
+ if (sensor.stream) return;
31068
+ const stream = { controller: new AbortController() };
31069
+ sensor.stream = stream;
31070
+ stream.start = sensor.cleanup.then(() => {
31071
+ if (stream.controller.signal.aborted) return async () => {
31072
+ };
31073
+ this.requireCapability(name);
31074
+ const accept = (event) => {
31075
+ if (this.disposed || stream.controller.signal.aborted) return;
31076
+ try {
31077
+ if (event?.kind === "state" && typeof event.watching === "boolean") {
31078
+ node.setAttr({ watching: event.watching, status: event.watching ? "pending" : "idle", error: null }, true, true, false);
31079
+ } else if (event?.kind === "sample") {
31080
+ for (const field of ["x", "y", "z", "timestamp"]) {
31081
+ if (!Number.isFinite(event[field])) throw new TypeError(`Invalid ${name}.${field}`);
31082
+ }
31083
+ if (!node.attr.watching) return;
31084
+ if (node.staticValue && event.timestamp < node.staticValue.getItem("timestamp")) return;
31085
+ const value = new Bag();
31086
+ for (const field of ["x", "y", "z", "timestamp"]) value.setItem(field, event[field]);
31087
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31088
+ } else if (event?.kind === "error" && event.error instanceof Error) {
31089
+ node.setAttr({ ...failureAttributes(event.error), watching: false }, true, true, false);
31090
+ } else throw new TypeError(`Invalid ${name} event`);
31091
+ } catch (error) {
31092
+ node.setAttr(failureAttributes(error), true, true, false);
31093
+ }
31094
+ };
31095
+ return name === "gyroscope" ? this.provider.startGyroscopeUpdates(accept, stream.controller.signal) : this.provider.startAccelerometerUpdates(accept, stream.controller.signal);
31096
+ });
31097
+ stream.start.catch((error) => {
31098
+ if (!this.disposed && !stream.controller.signal.aborted) {
31099
+ node.setAttr({ ...failureAttributes(error), watching: false }, true, true, false);
31100
+ }
31101
+ });
31102
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31103
+ }
31104
+ #startAudio(node) {
31105
+ const previous = this.#audio;
31106
+ if (previous) {
31107
+ if (previous.phase !== "complete") return;
31108
+ previous.phase = "replacing";
31109
+ node.setValue(null, true, {
31110
+ status: "pending",
31111
+ error: null,
31112
+ recording: false,
31113
+ shareStatus: "idle",
31114
+ shareError: null,
31115
+ shareActivity: null
31116
+ }, true, false);
31117
+ previous.close = previous.start.then((session) => session.dispose()).then(() => {
31118
+ if (this.disposed || previous.controller.signal.aborted || this.#audio !== previous) return;
31119
+ this.#audio = null;
31120
+ this.#startAudio(node);
31121
+ }).catch((error) => {
31122
+ if (!this.disposed && this.#audio === previous) {
31123
+ previous.phase = "failed";
31124
+ node.setAttr(failureAttributes(error), true, true, false);
31125
+ }
31126
+ });
31127
+ return;
30391
31128
  }
31129
+ const audio = { controller: new AbortController(), phase: "starting" };
31130
+ this.#audio = audio;
31131
+ node.setValue(null, true, {
31132
+ status: "pending",
31133
+ error: null,
31134
+ recording: false,
31135
+ shareStatus: "idle",
31136
+ shareError: null,
31137
+ shareActivity: null
31138
+ }, true, false);
31139
+ audio.start = Promise.resolve().then(async () => {
31140
+ if (audio.controller.signal.aborted) return null;
31141
+ this.requireCapability("audio");
31142
+ return this.provider.startAudioRecording((error) => {
31143
+ if (this.#audio === audio && !audio.controller.signal.aborted) this.#cancelAudio(node, error);
31144
+ }, audio.controller.signal);
31145
+ });
31146
+ audio.start.then((session) => {
31147
+ if (!session || audio.controller.signal.aborted || this.disposed) return;
31148
+ audio.phase = "recording";
31149
+ node.setAttr({ status: "recording", error: null, recording: true }, true, true, false);
31150
+ }).catch((error) => {
31151
+ if (audio.controller.signal.aborted || this.disposed) return;
31152
+ if (this.#audio === audio) this.#audio = null;
31153
+ node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
31154
+ });
30392
31155
  }
30393
- /** Hand text to the browser as a file named filename. */
30394
- saveText(text2, filename, type) {
30395
- const window2 = this.document.defaultView;
30396
- const url = window2.URL.createObjectURL(new window2.Blob([text2], { type }));
30397
- this.open(url, filename);
30398
- window2.setTimeout(() => window2.URL.revokeObjectURL(url), 1e3);
31156
+ #stopAudio(node) {
31157
+ const audio = this.#audio;
31158
+ if (!audio || audio.phase !== "recording") return;
31159
+ audio.phase = "stopping";
31160
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31161
+ audio.stop = audio.start.then((session) => session.stop()).then((result) => {
31162
+ if (audio.controller.signal.aborted || this.disposed) return;
31163
+ if (typeof result?.url !== "string" || !result.url || typeof result.mimeType !== "string" || !result.mimeType.startsWith("audio/") || !Number.isFinite(result.duration) || result.duration < 0) {
31164
+ throw new TypeError("Invalid audio result from device provider");
31165
+ }
31166
+ const value = new Bag();
31167
+ for (const key of ["url", "mimeType", "duration"]) value.setItem(key, result[key]);
31168
+ audio.phase = "complete";
31169
+ node.setValue(value, true, { status: "success", error: null, recording: false }, true, false);
31170
+ }).catch((error) => {
31171
+ if (!audio.controller.signal.aborted && !this.disposed) this.#cancelAudio(node, error);
31172
+ });
30399
31173
  }
30400
- /** Follow url through a link, as a download when filename is given. */
30401
- open(url, filename = null) {
30402
- const link = this.document.createElement("a");
30403
- link.href = url;
30404
- if (filename !== null) link.download = filename;
31174
+ #shareAudio(node) {
31175
+ const audio = this.#audio;
31176
+ if (audio?.phase === "sharing") return;
31177
+ if (!audio || audio.phase !== "complete") {
31178
+ const failure = failureAttributes(new Error("Record and stop audio before sharing"));
31179
+ node.setAttr({ shareStatus: failure.status, shareError: failure.error, shareActivity: null }, true, true, false);
31180
+ return;
31181
+ }
31182
+ audio.phase = "sharing";
31183
+ node.setAttr({ shareStatus: "pending", shareError: null, shareActivity: null }, true, true, false);
31184
+ audio.share = audio.start.then((session) => session.share(audio.controller.signal)).then((result) => {
31185
+ if (audio.controller.signal.aborted || this.disposed) return;
31186
+ if (typeof result?.activity !== "string") throw new TypeError("Invalid audio share result from device provider");
31187
+ node.setAttr({ shareStatus: "success", shareError: null, shareActivity: result.activity }, true, true, false);
31188
+ }).catch((error) => {
31189
+ if (audio.controller.signal.aborted || this.disposed) return;
31190
+ const failure = failureAttributes(error);
31191
+ node.setAttr({ shareStatus: failure.status, shareError: failure.error, shareActivity: null }, true, true, false);
31192
+ }).finally(() => {
31193
+ if (this.#audio === audio && !audio.controller.signal.aborted) audio.phase = "complete";
31194
+ });
31195
+ }
31196
+ #cancelAudio(node, error = { code: "CANCELLED", message: "Audio recording cancelled" }) {
31197
+ const audio = this.#audio;
31198
+ if (!audio || audio.phase === "closing" || audio.phase === "sharing") return;
31199
+ audio.phase = "closing";
31200
+ audio.controller.abort();
31201
+ node.setValue(null, true, {
31202
+ status: "pending",
31203
+ error: null,
31204
+ shareStatus: "idle",
31205
+ shareError: null,
31206
+ shareActivity: null
31207
+ }, true, false);
31208
+ audio.close = audio.start.then((session) => session === null ? void 0 : session.dispose(), (error2) => {
31209
+ if (error2?.code !== "CANCELLED") throw error2;
31210
+ }).then(() => {
31211
+ if (this.disposed || this.#audio !== audio) return;
31212
+ this.#audio = null;
31213
+ node.setAttr({ ...failureAttributes(error), recording: false }, true, true, false);
31214
+ }).catch((cleanupError) => {
31215
+ if (!this.disposed && this.#audio === audio) {
31216
+ audio.phase = "failed";
31217
+ node.setAttr(failureAttributes(cleanupError), true, true, false);
31218
+ }
31219
+ });
31220
+ }
31221
+ #clipboardCommand(node, operation) {
31222
+ if (this.#clipboardRequest) return;
31223
+ const request = new AbortController();
31224
+ this.#clipboardRequest = request;
31225
+ const text2 = node.attr.text;
31226
+ node.setValue(null, true, { status: "pending", error: null, operation }, true, false);
31227
+ Promise.resolve().then(async () => {
31228
+ if (request.signal.aborted) return;
31229
+ this.requireCapability("clipboard");
31230
+ let result;
31231
+ if (operation === "copy") {
31232
+ if (typeof text2 !== "string") throw new TypeError("Clipboard text must be a string");
31233
+ await this.provider.copyText(text2, request.signal);
31234
+ result = { text: text2 };
31235
+ } else {
31236
+ result = await this.provider.pasteText(request.signal);
31237
+ }
31238
+ if (request.signal.aborted) return;
31239
+ if (typeof result?.text !== "string") throw new TypeError("Invalid clipboard text from device provider");
31240
+ const value = new Bag();
31241
+ value.setItem("text", result.text);
31242
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31243
+ }).catch((error) => {
31244
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31245
+ }).finally(() => {
31246
+ if (this.#clipboardRequest === request) this.#clipboardRequest = null;
31247
+ });
31248
+ }
31249
+ #vibrate(node) {
31250
+ if (this.#hapticRequest) return;
31251
+ const request = new AbortController();
31252
+ this.#hapticRequest = request;
31253
+ const { duration } = node.attr;
31254
+ node.setValue(null, true, { status: "pending", error: null }, true, false);
31255
+ Promise.resolve().then(async () => {
31256
+ if (request.signal.aborted) return;
31257
+ this.requireCapability("haptics");
31258
+ if (!Number.isInteger(duration) || duration < 1 || duration > 5e3) {
31259
+ throw new TypeError("Vibration duration must be an integer from 1 to 5000 milliseconds");
31260
+ }
31261
+ await this.provider.vibrate(duration, request.signal);
31262
+ if (request.signal.aborted) return;
31263
+ const value = new Bag();
31264
+ value.setItem("duration", duration);
31265
+ value.setItem("acknowledged", true);
31266
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31267
+ }).catch((error) => {
31268
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31269
+ }).finally(() => {
31270
+ if (this.#hapticRequest === request) this.#hapticRequest = null;
31271
+ });
31272
+ }
31273
+ #impact(node) {
31274
+ if (this.#hapticRequest) return;
31275
+ const request = new AbortController();
31276
+ this.#hapticRequest = request;
31277
+ const { style } = node.attr;
31278
+ node.setValue(null, true, { status: "pending", error: null }, true, false);
31279
+ Promise.resolve().then(async () => {
31280
+ if (request.signal.aborted) return;
31281
+ this.requireCapability("haptics");
31282
+ if (!["light", "medium", "heavy"].includes(style)) throw new TypeError("Invalid haptic style");
31283
+ await this.provider.impact(style, request.signal);
31284
+ if (request.signal.aborted) return;
31285
+ const value = new Bag();
31286
+ value.setItem("style", style);
31287
+ value.setItem("acknowledged", true);
31288
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31289
+ }).catch((error) => {
31290
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31291
+ }).finally(() => {
31292
+ if (this.#hapticRequest === request) this.#hapticRequest = null;
31293
+ });
31294
+ }
31295
+ #scanBarcode(node) {
31296
+ if (this.#barcodeRequest) return;
31297
+ const request = new AbortController();
31298
+ this.#barcodeRequest = request;
31299
+ node.setValue(null, true, { status: "pending", error: null }, true, false);
31300
+ Promise.resolve().then(() => {
31301
+ if (request.signal.aborted) return;
31302
+ this.requireCapability("barcode");
31303
+ return this.provider.scanBarcode(request.signal);
31304
+ }).then((result) => {
31305
+ if (request.signal.aborted) return;
31306
+ if (typeof result?.text !== "string" || !result.text || typeof result.format !== "string" || !result.format) {
31307
+ throw new TypeError("Invalid barcode result from device provider");
31308
+ }
31309
+ const value = new Bag();
31310
+ value.setItem("text", result.text);
31311
+ value.setItem("format", result.format);
31312
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31313
+ }).catch((error) => {
31314
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31315
+ }).finally(() => {
31316
+ if (this.#barcodeRequest === request) this.#barcodeRequest = null;
31317
+ });
31318
+ }
31319
+ // Camera is an explicit Data event, never a resolver read with a UI side effect.
31320
+ #photo(node, operation) {
31321
+ if (this.#captureRequest) return;
31322
+ const request = new AbortController();
31323
+ this.#captureRequest = request;
31324
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31325
+ Promise.resolve().then(() => {
31326
+ if (request.signal.aborted) return;
31327
+ this.requireCapability("camera");
31328
+ return operation === "choose" ? this.provider.choosePhoto(request.signal) : this.provider.takePhoto(request.signal);
31329
+ }).then((photo) => {
31330
+ if (request.signal.aborted) return;
31331
+ if (typeof photo?.url !== "string" || !photo.url || typeof photo.format !== "string" || !photo.format) {
31332
+ throw new TypeError("Invalid camera photo from device provider");
31333
+ }
31334
+ const value = new Bag();
31335
+ value.setItem("url", photo.url);
31336
+ value.setItem("format", photo.format);
31337
+ node.setValue(value, true, { status: "success", error: null }, true, false);
31338
+ }).catch((error) => {
31339
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31340
+ }).finally(() => {
31341
+ if (this.#captureRequest === request) this.#captureRequest = null;
31342
+ });
31343
+ }
31344
+ // A fresh attempt clears the previous local verification, including on cancellation.
31345
+ #verifyBiometrics(node) {
31346
+ if (this.#biometricsRequest) return;
31347
+ const request = new AbortController();
31348
+ this.#biometricsRequest = request;
31349
+ node.setValue(null, true, { status: "pending", error: null }, true, false);
31350
+ Promise.resolve().then(() => {
31351
+ if (request.signal.aborted) return;
31352
+ this.requireCapability("biometrics");
31353
+ return this.provider.verifyBiometrics(request.signal);
31354
+ }).then(() => {
31355
+ if (request.signal.aborted) return;
31356
+ const result = new Bag();
31357
+ result.setItem("verified", true);
31358
+ node.setValue(result, true, { status: "success", error: null }, true, false);
31359
+ }).catch((error) => {
31360
+ if (!request.signal.aborted) node.setValue(null, true, failureAttributes(error), true, false);
31361
+ }).finally(() => {
31362
+ if (this.#biometricsRequest === request) this.#biometricsRequest = null;
31363
+ });
31364
+ }
31365
+ #startNotificationEvents(node) {
31366
+ if (this.#notificationEvents) return this.#notificationEvents.start;
31367
+ const events = { controller: new AbortController() };
31368
+ this.#notificationEvents = events;
31369
+ events.start = Promise.resolve().then(() => {
31370
+ if (events.controller.signal.aborted) return async () => {
31371
+ };
31372
+ return this.provider.startNotificationEvents((event) => {
31373
+ if (events.controller.signal.aborted) return;
31374
+ try {
31375
+ if (!["received", "action"].includes(event.kind) || !Number.isInteger(event.id) || typeof event.title !== "string" || typeof event.body !== "string" || event.kind === "action" && typeof event.actionId !== "string") {
31376
+ throw new TypeError("Invalid notification event from device provider");
31377
+ }
31378
+ const value = new Bag();
31379
+ for (const key of ["id", "title", "body"]) value.setItem(key, event[key]);
31380
+ if (event.kind === "action") value.setItem("actionId", event.actionId);
31381
+ node.staticValue.setItem(event.kind, value);
31382
+ } catch (error) {
31383
+ node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
31384
+ }
31385
+ }, events.controller.signal);
31386
+ }).then((stop) => {
31387
+ if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
31388
+ return stop;
31389
+ });
31390
+ events.start.catch((error) => {
31391
+ const aborted = events.controller.signal.aborted;
31392
+ events.controller.abort();
31393
+ if (this.#notificationEvents === events) this.#notificationEvents = null;
31394
+ if (!aborted) {
31395
+ node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
31396
+ }
31397
+ });
31398
+ node.setAttr({ listenerError: null }, true, true, false);
31399
+ return events.start;
31400
+ }
31401
+ #scheduleNotification(node) {
31402
+ if (this.#notificationRequest) return;
31403
+ const request = new AbortController();
31404
+ this.#notificationRequest = request;
31405
+ const value = node.staticValue.getItem("request");
31406
+ const input = value instanceof Bag ? Object.fromEntries(["id", "title", "body", "delay"].map((key) => [key, value.getItem(key)])) : null;
31407
+ node.staticValue.setItem("scheduled", null);
31408
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31409
+ Promise.resolve().then(async () => {
31410
+ if (request.signal.aborted) return;
31411
+ this.requireCapability("notifications");
31412
+ if (!input || !Number.isInteger(input.id) || input.id < 1 || input.id > 2147483647 || typeof input.title !== "string" || !input.title.trim() || typeof input.body !== "string" || !input.body.trim() || typeof input.delay !== "number" || !Number.isFinite(input.delay) || input.delay <= 0) {
31413
+ throw new TypeError("Notification requires a positive 32-bit id, title, body and positive delay in seconds");
31414
+ }
31415
+ await this.#startNotificationEvents(node);
31416
+ if (request.signal.aborted) return;
31417
+ return this.provider.scheduleNotification(input, request.signal);
31418
+ }).then((result) => {
31419
+ if (request.signal.aborted) return;
31420
+ if (result?.id !== input.id || typeof result.at !== "number" || !Number.isFinite(result.at)) {
31421
+ throw new TypeError("Invalid notification scheduling acknowledgement");
31422
+ }
31423
+ const scheduled = new Bag();
31424
+ scheduled.setItem("id", result.id);
31425
+ scheduled.setItem("at", result.at);
31426
+ node.staticValue.setItem("scheduled", scheduled);
31427
+ node.setAttr({ status: "success", error: null }, true, true, false);
31428
+ }).catch((error) => {
31429
+ if (!request.signal.aborted) node.setAttr(failureAttributes(error), true, true, false);
31430
+ }).finally(() => {
31431
+ if (this.#notificationRequest === request) this.#notificationRequest = null;
31432
+ });
31433
+ }
31434
+ #finishPushRequest() {
31435
+ const request = this.#pushRequest;
31436
+ this.#pushRequest = null;
31437
+ if (request) clearTimeout(request.timer);
31438
+ return request;
31439
+ }
31440
+ #acceptPushEvent(node, event) {
31441
+ if (event.kind === "registration") {
31442
+ if (typeof event.token !== "string" || !event.token) throw new TypeError("Invalid push registration token");
31443
+ this.#finishPushRequest();
31444
+ const value = new Bag();
31445
+ value.setItem("token", event.token);
31446
+ node.staticValue.setItem("registration", value);
31447
+ node.setAttr({ status: "success", error: null }, true, true, false);
31448
+ } else if (event.kind === "registrationError") {
31449
+ this.#finishPushRequest();
31450
+ node.staticValue.setItem("registration", null);
31451
+ node.setAttr(failureAttributes(event.error), true, true, false);
31452
+ } else {
31453
+ if (!["received", "action"].includes(event.kind)) throw new TypeError("Invalid push event kind");
31454
+ const fields = ["id", "title", "body", "messageId", "destination"];
31455
+ if (event.kind === "action") fields.push("actionId");
31456
+ const value = new Bag();
31457
+ for (const key of fields) {
31458
+ if (typeof event[key] !== "string") throw new TypeError(`Invalid push event ${key}`);
31459
+ value.setItem(key, event[key]);
31460
+ }
31461
+ node.staticValue.setItem(event.kind, value);
31462
+ }
31463
+ }
31464
+ #startPushEvents(node) {
31465
+ if (this.#pushEvents) return this.#pushEvents.start;
31466
+ const events = { controller: new AbortController() };
31467
+ this.#pushEvents = events;
31468
+ events.start = Promise.resolve().then(() => {
31469
+ if (events.controller.signal.aborted) return async () => {
31470
+ };
31471
+ return this.provider.startPushEvents((event) => {
31472
+ if (events.controller.signal.aborted) return;
31473
+ try {
31474
+ this.#acceptPushEvent(node, event);
31475
+ } catch (error) {
31476
+ node.setAttr({ listenerError: failureAttributes(error).error }, true, true, false);
31477
+ }
31478
+ }, events.controller.signal);
31479
+ }).then((stop) => {
31480
+ if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
31481
+ return stop;
31482
+ });
31483
+ events.start.catch((error) => {
31484
+ const aborted = events.controller.signal.aborted;
31485
+ events.controller.abort();
31486
+ if (this.#pushEvents === events) this.#pushEvents = null;
31487
+ if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
31488
+ });
31489
+ node.setAttr({ listenerError: null }, true, true, false);
31490
+ return events.start;
31491
+ }
31492
+ #registerPush(node) {
31493
+ if (this.#pushRequest) return;
31494
+ const request = { controller: new AbortController(), timer: null };
31495
+ this.#pushRequest = request;
31496
+ request.timer = setTimeout(() => {
31497
+ if (this.disposed || this.#pushRequest !== request) return;
31498
+ this.#finishPushRequest();
31499
+ request.controller.abort();
31500
+ node.setAttr(failureAttributes({ code: "TIMEOUT", message: "Push registration has not returned a token" }), true, true, false);
31501
+ }, 3e4);
31502
+ node.staticValue.setItem("registration", null);
31503
+ node.setAttr({ status: "pending", error: null }, true, true, false);
31504
+ Promise.resolve().then(async () => {
31505
+ if (request.controller.signal.aborted) return;
31506
+ this.requireCapability("push");
31507
+ await this.#startPushEvents(node);
31508
+ if (request.controller.signal.aborted || this.#pushRequest !== request) return;
31509
+ await this.provider.registerPush(request.controller.signal);
31510
+ }).catch((error) => {
31511
+ if (this.disposed || this.#pushRequest !== request) return;
31512
+ this.#finishPushRequest();
31513
+ request.controller.abort();
31514
+ node.setAttr(failureAttributes(error), true, true, false);
31515
+ });
31516
+ }
31517
+ #startShortcutEvents(node) {
31518
+ const events = { controller: new AbortController() };
31519
+ this.#shortcutEvents = events;
31520
+ events.start = Promise.resolve().then(() => {
31521
+ if (events.controller.signal.aborted) return async () => {
31522
+ };
31523
+ return this.provider.startShortcutEvents((request, error = null) => {
31524
+ if (events.controller.signal.aborted) return;
31525
+ try {
31526
+ if (error) throw error;
31527
+ for (const key of ["id", "destination"]) {
31528
+ if (typeof request?.[key] !== "string" || !request[key]) {
31529
+ throw new TypeError(`Invalid shortcut request ${key}`);
31530
+ }
31531
+ }
31532
+ if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
31533
+ const value = new Bag();
31534
+ value.setItem("id", request.id);
31535
+ value.setItem("destination", request.destination);
31536
+ node.setAttr({ listenerError: null }, true, true, false);
31537
+ node.staticValue.setItem("request", value);
31538
+ } catch (error2) {
31539
+ node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
31540
+ }
31541
+ }, events.controller.signal);
31542
+ }).then((stop) => {
31543
+ if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
31544
+ return stop;
31545
+ });
31546
+ events.start.catch((error) => {
31547
+ const aborted = events.controller.signal.aborted;
31548
+ events.controller.abort();
31549
+ if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
31550
+ });
31551
+ }
31552
+ #startLinkEvents(node) {
31553
+ const events = { controller: new AbortController() };
31554
+ this.#linkEvents = events;
31555
+ events.start = Promise.resolve().then(() => {
31556
+ if (events.controller.signal.aborted) return async () => {
31557
+ };
31558
+ return this.provider.startLinkEvents((request, error = null) => {
31559
+ if (events.controller.signal.aborted) return;
31560
+ try {
31561
+ if (error) throw error;
31562
+ for (const key of ["id", "url"]) {
31563
+ if (typeof request?.[key] !== "string" || !request[key]) {
31564
+ throw new TypeError(`Invalid link request ${key}`);
31565
+ }
31566
+ }
31567
+ if (node.staticValue.getItem("request")?.getItem("id") === request.id) return;
31568
+ const value = new Bag();
31569
+ value.setItem("id", request.id);
31570
+ value.setItem("url", request.url);
31571
+ node.setAttr({ listenerError: null }, true, true, false);
31572
+ node.staticValue.setItem("request", value);
31573
+ } catch (error2) {
31574
+ node.setAttr({ listenerError: failureAttributes(error2).error }, true, true, false);
31575
+ }
31576
+ }, events.controller.signal);
31577
+ }).then((stop) => {
31578
+ if (!events.controller.signal.aborted) node.setAttr({ listening: true }, true, true, false);
31579
+ return stop;
31580
+ });
31581
+ events.start.catch((error) => {
31582
+ const aborted = events.controller.signal.aborted;
31583
+ events.controller.abort();
31584
+ if (!aborted) node.setAttr({ listening: false, listenerError: failureAttributes(error).error }, true, true, false);
31585
+ });
31586
+ }
31587
+ requireCapability(name) {
31588
+ if (!this.provider || !this.provider.capabilities.includes(name)) {
31589
+ throw Object.assign(new Error(`${name} is unavailable in this environment`), { code: "UNAVAILABLE" });
31590
+ }
31591
+ }
31592
+ attributes(resolver, attrs) {
31593
+ const writing = resolver.writing;
31594
+ resolver.writing = true;
31595
+ try {
31596
+ resolver._node.setAttr(attrs, true, true, false);
31597
+ } finally {
31598
+ resolver.writing = writing;
31599
+ }
31600
+ }
31601
+ accept(resolver, value) {
31602
+ const fields = resolver.name === "appinfo" ? ["id", "name", "version", "build"] : ["latitude", "longitude", "accuracy", "timestamp"];
31603
+ const type = resolver.name === "appinfo" ? "string" : "number";
31604
+ for (const key of fields) {
31605
+ if (typeof value[key] !== type || type === "number" && !Number.isFinite(value[key])) {
31606
+ throw new TypeError(`Invalid ${resolver.name}.${key} from device provider`);
31607
+ }
31608
+ }
31609
+ const current = resolver.cachedValue;
31610
+ if (resolver.name === "location" && current && value.timestamp < current.getItem("timestamp")) {
31611
+ this.attributes(resolver, { status: "success", error: null });
31612
+ return;
31613
+ }
31614
+ const bag = new Bag();
31615
+ for (const key of fields) bag.setItem(key, value[key]);
31616
+ resolver._lastUpdate = Date.now();
31617
+ resolver.failed = false;
31618
+ resolver.received++;
31619
+ const writing = resolver.writing;
31620
+ resolver.writing = true;
31621
+ try {
31622
+ resolver._node.setValue(bag, true, { status: "success", error: null }, true, false);
31623
+ } finally {
31624
+ resolver.writing = writing;
31625
+ }
31626
+ }
31627
+ failure(resolver, error) {
31628
+ resolver.failed = true;
31629
+ this.attributes(resolver, failureAttributes(error));
31630
+ }
31631
+ reconcile() {
31632
+ const resolver = this.resolvers.get("location");
31633
+ if (resolver._node.attr.enabled) {
31634
+ if (this.monitor) return;
31635
+ const monitor = { stop: null, controller: new AbortController() };
31636
+ this.monitor = monitor;
31637
+ monitor.start = Promise.resolve(this.cleanup).then(() => {
31638
+ if (this.disposed || this.monitor !== monitor) return null;
31639
+ this.requireCapability("location");
31640
+ return this.provider.startLocationUpdates((value, error) => {
31641
+ if (this.disposed || this.monitor !== monitor) return;
31642
+ if (error) this.failure(resolver, error);
31643
+ else {
31644
+ try {
31645
+ this.accept(resolver, value);
31646
+ } catch (failure) {
31647
+ this.failure(resolver, failure);
31648
+ }
31649
+ }
31650
+ }, monitor.controller.signal);
31651
+ });
31652
+ monitor.start.then((stop) => {
31653
+ if (stop === null || this.disposed || this.monitor !== monitor) return;
31654
+ monitor.stop = stop;
31655
+ this.attributes(resolver, { watching: true });
31656
+ }).catch((error) => {
31657
+ if (!this.disposed && this.monitor === monitor) {
31658
+ this.attributes(resolver, { watching: false });
31659
+ this.failure(resolver, error);
31660
+ }
31661
+ });
31662
+ this.attributes(resolver, { status: "pending", error: null });
31663
+ } else if (this.monitor) {
31664
+ const monitor = this.monitor;
31665
+ this.monitor = null;
31666
+ monitor.controller.abort();
31667
+ this.retiring = monitor;
31668
+ this.cleanup = monitor.start.then((stop) => stop === null ? void 0 : stop(), () => void 0).then(() => {
31669
+ if (this.retiring === monitor) this.retiring = null;
31670
+ if (!this.disposed) {
31671
+ const attrs = { watching: false };
31672
+ if (!this.monitor && !resolver.request && resolver._node.attr.status === "pending") {
31673
+ Object.assign(attrs, { status: "cancelled", error: null });
31674
+ }
31675
+ this.attributes(resolver, attrs);
31676
+ }
31677
+ });
31678
+ this.cleanup.catch((error) => {
31679
+ if (!this.disposed) this.failure(resolver, error);
31680
+ });
31681
+ }
31682
+ }
31683
+ /** A page-owned database connection; database technology remains provider-owned. */
31684
+ async openDatabase(name) {
31685
+ this.assertLive();
31686
+ if (!/^[A-Za-z][A-Za-z0-9_]{0,63}$/.test(name) || typeof name !== "string") throw new TypeError("Invalid database name");
31687
+ if (this.#database) throw new Error("This page already owns a database connection");
31688
+ const node = this.gramlot.data.getNode("gramlot.device.database");
31689
+ const state = (status, error = null) => {
31690
+ if (!this.disposed) node.setAttr({ status, error }, true, true, false);
31691
+ };
31692
+ if (!this.provider.capabilities.includes("database")) {
31693
+ const error = Object.assign(new Error("Native database unavailable"), { code: "UNAVAILABLE" });
31694
+ state("unavailable", { code: error.code, message: error.message });
31695
+ throw error;
31696
+ }
31697
+ const slot = { controller: new AbortController(), close: null, start: null };
31698
+ this.#database = slot;
31699
+ state("pending");
31700
+ slot.start = this.provider.openDatabase(name, slot.controller.signal);
31701
+ try {
31702
+ const connection = await slot.start;
31703
+ let closed = false, closing = null;
31704
+ const close = () => {
31705
+ if (closing) return closing;
31706
+ closed = true;
31707
+ closing = connection.close().then(() => {
31708
+ state("closed");
31709
+ }, (error) => {
31710
+ state("error", { code: "FAILED", message: error.message });
31711
+ throw error;
31712
+ }).finally(() => {
31713
+ if (this.#database === slot) this.#database = null;
31714
+ });
31715
+ return closing;
31716
+ };
31717
+ slot.close = close;
31718
+ if (this.disposed || slot.controller.signal.aborted) {
31719
+ await close();
31720
+ throw Object.assign(new Error("Page closed"), { code: "CANCELLED" });
31721
+ }
31722
+ const invoke = async (method, sql, params) => {
31723
+ this.assertLive();
31724
+ if (closed) throw new Error("Database connection is closed");
31725
+ state("pending");
31726
+ try {
31727
+ const result = await connection[method](sql, params);
31728
+ state("success");
31729
+ return result;
31730
+ } catch (error) {
31731
+ state("error", { code: "FAILED", message: error.message });
31732
+ throw error;
31733
+ }
31734
+ };
31735
+ state("success");
31736
+ return {
31737
+ query: (sql, params = []) => invoke("query", sql, params),
31738
+ execute: (sql, params = []) => invoke("execute", sql, params),
31739
+ close
31740
+ };
31741
+ } catch (error) {
31742
+ if (this.#database === slot) this.#database = null;
31743
+ if (!this.disposed) node.setAttr(failureAttributes(error), true, true, false);
31744
+ throw error;
31745
+ }
31746
+ }
31747
+ dispose() {
31748
+ if (this.disposed) return;
31749
+ this.disposed = true;
31750
+ const database = this.#database;
31751
+ database?.controller.abort();
31752
+ if (database) this.cleanup = Promise.all([
31753
+ this.cleanup,
31754
+ database.start.then(() => database.close?.(), () => void 0)
31755
+ ]).then(() => void 0);
31756
+ const sensorCleanup = [...this.#sensors.values()].map((sensor) => {
31757
+ const stream = sensor.stream;
31758
+ sensor.stream = null;
31759
+ stream?.controller.abort();
31760
+ return stream ? stream.start.then((stop) => stop(), () => void 0) : sensor.cleanup;
31761
+ });
31762
+ this.#clipboardRequest?.abort();
31763
+ this.#clipboardRequest = null;
31764
+ const audio = this.#audio;
31765
+ this.#audio = null;
31766
+ audio?.controller.abort();
31767
+ this.#hapticRequest?.abort();
31768
+ this.#hapticRequest = null;
31769
+ const stateEvents = [...this.#stateEvents.values()];
31770
+ this.#stateEvents.clear();
31771
+ for (const events of stateEvents) events.controller.abort();
31772
+ const linkEvents = this.#linkEvents;
31773
+ this.#linkEvents = null;
31774
+ linkEvents?.controller.abort();
31775
+ const shortcutEvents = this.#shortcutEvents;
31776
+ this.#shortcutEvents = null;
31777
+ shortcutEvents?.controller.abort();
31778
+ this.#finishPushRequest()?.controller.abort();
31779
+ const pushEvents = this.#pushEvents;
31780
+ this.#pushEvents = null;
31781
+ pushEvents?.controller.abort();
31782
+ this.#barcodeRequest?.abort();
31783
+ this.#barcodeRequest = null;
31784
+ this.#captureRequest?.abort();
31785
+ this.#captureRequest = null;
31786
+ this.#biometricsRequest?.abort();
31787
+ this.#biometricsRequest = null;
31788
+ this.#notificationRequest?.abort();
31789
+ this.#notificationRequest = null;
31790
+ const notificationEvents = this.#notificationEvents;
31791
+ this.#notificationEvents = null;
31792
+ notificationEvents?.controller.abort();
31793
+ this.gramlot.data.unsubscribe("gramlot.device", { any: true });
31794
+ const monitor = this.monitor;
31795
+ this.monitor = null;
31796
+ monitor?.controller.abort();
31797
+ if (monitor) {
31798
+ this.cleanup = monitor.start.then((stop) => stop === null ? void 0 : stop(), () => void 0);
31799
+ } else if (this.retiring?.stop) {
31800
+ const retiring = this.retiring;
31801
+ this.cleanup = this.cleanup.catch(() => retiring.stop());
31802
+ }
31803
+ if (notificationEvents) {
31804
+ this.cleanup = Promise.all([
31805
+ this.cleanup,
31806
+ notificationEvents.start.then((stop) => stop(), () => void 0)
31807
+ ]).then(() => void 0);
31808
+ }
31809
+ if (pushEvents) {
31810
+ this.cleanup = Promise.all([
31811
+ this.cleanup,
31812
+ pushEvents.start.then((stop) => stop(), () => void 0)
31813
+ ]).then(() => void 0);
31814
+ }
31815
+ if (linkEvents) {
31816
+ this.cleanup = Promise.all([
31817
+ this.cleanup,
31818
+ linkEvents.start.then((stop) => stop(), () => void 0)
31819
+ ]).then(() => void 0);
31820
+ }
31821
+ if (shortcutEvents) {
31822
+ this.cleanup = Promise.all([
31823
+ this.cleanup,
31824
+ shortcutEvents.start.then((stop) => stop(), () => void 0)
31825
+ ]).then(() => void 0);
31826
+ }
31827
+ this.cleanup = Promise.all([this.cleanup, ...sensorCleanup, ...stateEvents.map((events) => events.start.then((stop) => stop(), () => void 0))]).then(() => void 0);
31828
+ if (audio) {
31829
+ this.cleanup = Promise.all([
31830
+ this.cleanup,
31831
+ audio.start.then((session) => session === null ? void 0 : session.dispose(), (error) => {
31832
+ if (error?.code !== "CANCELLED") throw error;
31833
+ })
31834
+ ]).then(() => void 0);
31835
+ }
31836
+ this.cleanup = this.cleanup.finally(() => this.releaseProvider?.());
31837
+ this.cleanup.catch((error) => {
31838
+ this.cleanupError = error;
31839
+ });
31840
+ for (const resolver of this.resolvers.values()) resolver.request = null;
31841
+ }
31842
+ };
31843
+
31844
+ // src/inout.js
31845
+ var MAILTO_LIMIT = 2e3;
31846
+ function leafText(value) {
31847
+ if (!(value instanceof Date)) return String(value ?? "");
31848
+ const text2 = value.toISOString();
31849
+ return text2.endsWith("T00:00:00.000Z") ? text2.slice(0, 10) : text2;
31850
+ }
31851
+ var InOut = class {
31852
+ constructor(gramlot, document) {
31853
+ this.gramlot = gramlot;
31854
+ this.document = document;
31855
+ }
31856
+ /** The Bag at path in the Data. */
31857
+ branch(path) {
31858
+ const value = this.gramlot.data.getItem(path);
31859
+ if (!(value instanceof Bag)) throw new Error(`gramlot.utl.inout: no data Bag at '${path}'`);
31860
+ return value;
31861
+ }
31862
+ /** One `relative.path: value` line per leaf of the branch at path. */
31863
+ mailText(path) {
31864
+ const lines = [];
31865
+ const walk2 = (bag, prefix) => {
31866
+ for (const node of bag.getNodes()) {
31867
+ const label = prefix + node.label;
31868
+ if (node.value instanceof Bag) walk2(node.value, `${label}.`);
31869
+ else lines.push(`${label}: ${leafText(node.value)}`);
31870
+ }
31871
+ };
31872
+ walk2(this.branch(path), "");
31873
+ return lines.join("\n");
31874
+ }
31875
+ /** The mailto: URL of sendMail; longer than MAILTO_LIMIT raises an Error. */
31876
+ mailtoUrl(path, email) {
31877
+ const url = `mailto:${encodeURIComponent(email)}?subject=${encodeURIComponent(this.document.title)}&body=${encodeURIComponent(this.mailText(path))}`;
31878
+ if (url.length > MAILTO_LIMIT) {
31879
+ throw new Error(`gramlot.utl.inout.sendMail: the email of '${path}' is ${url.length} characters long, over the mailto: limit of ${MAILTO_LIMIT}; send it with sendHttp or save it as a file`);
31880
+ }
31881
+ return url;
31882
+ }
31883
+ /** Prepare an email to email in the mail program of the user, with the data at path as text lines. */
31884
+ sendMail(path, email) {
31885
+ this.open(this.mailtoUrl(path, email));
31886
+ }
31887
+ /** POST the data at path as a JSON object to url; resolves with the Response, rejects on a status out of 2xx. */
31888
+ async sendHttp(path, url) {
31889
+ const body = JSON.stringify(this.branch(path).asDict(false, false, true));
31890
+ const response = await this.document.defaultView.fetch(url, {
31891
+ method: "POST",
31892
+ headers: { "Content-Type": "application/json" },
31893
+ body
31894
+ });
31895
+ if (!response.ok) throw new Error(`gramlot.utl.inout.sendHttp: ${url} answered ${response.status}`);
31896
+ return response;
31897
+ }
31898
+ /** Save the data at path as a TYTX file, which restore reads back with its exact types. */
31899
+ save(path, filename) {
31900
+ this.saveText(this.branch(path).toTytx(), filename, "application/json");
31901
+ }
31902
+ /** Read a TYTX file into path; resolves with the Bag, rejects with AbortError on cancel. Needs a user gesture. */
31903
+ restore(path) {
31904
+ const input = this.document.createElement("input");
31905
+ input.type = "file";
31906
+ input.accept = ".json,application/json";
31907
+ return new Promise((resolve, reject) => {
31908
+ const cancel = () => reject(new this.document.defaultView.DOMException("File selection cancelled", "AbortError"));
31909
+ input.addEventListener("cancel", cancel, { once: true });
31910
+ input.addEventListener("change", async () => {
31911
+ input.removeEventListener("cancel", cancel);
31912
+ if (!input.files.length) {
31913
+ cancel();
31914
+ return;
31915
+ }
31916
+ try {
31917
+ const bag = fromTytx(await input.files[0].text());
31918
+ if (!(bag instanceof Bag)) throw new TypeError("the file must contain a typed Bag");
31919
+ this.gramlot.data.setItem(path, bag);
31920
+ resolve(bag);
31921
+ } catch (error) {
31922
+ reject(new Error(
31923
+ `gramlot.utl.inout.restore: the file is not a saved Gramlot branch: ${error.message}`,
31924
+ { cause: error }
31925
+ ));
31926
+ }
31927
+ }, { once: true });
31928
+ input.click();
31929
+ });
31930
+ }
31931
+ /** Export the data at path as 'json' (Bag.toJson) or 'xml' (Bag.toXml, inside one root element named
31932
+ * after the last segment of path); types become text. */
31933
+ download(path, filename, format) {
31934
+ if (!["json", "xml"].includes(format)) {
31935
+ throw new Error(`gramlot.utl.inout.download: format '${format}' is not 'json' or 'xml'`);
31936
+ }
31937
+ const bag = this.branch(path);
31938
+ if (format === "json") {
31939
+ this.saveText(bag.toJson(false), filename, "application/json");
31940
+ } else {
31941
+ const root = path.split(".").at(-1);
31942
+ this.saveText(
31943
+ `<?xml version='1.0' encoding='UTF-8'?>
31944
+ <${root}>${bag.toXml()}</${root}>`,
31945
+ filename,
31946
+ "application/xml"
31947
+ );
31948
+ }
31949
+ }
31950
+ /** Hand text to the browser as a file named filename. */
31951
+ saveText(text2, filename, type) {
31952
+ const window2 = this.document.defaultView;
31953
+ const url = window2.URL.createObjectURL(new window2.Blob([text2], { type }));
31954
+ this.open(url, filename);
31955
+ window2.setTimeout(() => window2.URL.revokeObjectURL(url), 1e3);
31956
+ }
31957
+ /** Follow url through a link, as a download when filename is given. */
31958
+ open(url, filename = null) {
31959
+ const link = this.document.createElement("a");
31960
+ link.href = url;
31961
+ if (filename !== null) link.download = filename;
30405
31962
  link.click();
30406
31963
  }
30407
31964
  };
@@ -30416,6 +31973,7 @@ var UtilitiesHandler = class extends Handler {
30416
31973
 
30417
31974
  // src/gramlot.js
30418
31975
  var Gramlot = class {
31976
+ #mobileEnvironment;
30419
31977
  constructor({
30420
31978
  pageId,
30421
31979
  rpcUrl = "/gramlot/rpc",
@@ -30451,7 +32009,9 @@ var Gramlot = class {
30451
32009
  subscriptions: this._subscriptions,
30452
32010
  nameSyntax: nameSyntax === null ? NAME_SYNTAX : NameSyntax.fromJSON(nameSyntax)
30453
32011
  });
32012
+ this.#mobileEnvironment = MobileEnvironment.install({ document, root: this.src.renderer.destination });
30454
32013
  this.data = this.src.builder.data;
32014
+ this.dvc = new DeviceHandler(this);
30455
32015
  this.rpc = new RpcHandler(this, { rpcUrl, closeUrl, document, transport });
30456
32016
  this.dom = new DomHandler(this);
30457
32017
  this.utl = new UtilitiesHandler(this, document);
@@ -30460,7 +32020,7 @@ var Gramlot = class {
30460
32020
  this.abort = new AbortController();
30461
32021
  if (this.rpc.transport) {
30462
32022
  this.pagehide = (event) => {
30463
- if (!event.persisted) this.dispose({ beacon: true });
32023
+ if (!event.persisted) this.dispose();
30464
32024
  };
30465
32025
  document.defaultView.addEventListener("pagehide", this.pagehide);
30466
32026
  this.window = document.defaultView;
@@ -30506,9 +32066,11 @@ var Gramlot = class {
30506
32066
  throw error;
30507
32067
  }
30508
32068
  }
30509
- dispose({ beacon = false } = {}) {
32069
+ dispose() {
30510
32070
  if (this.state === "disposed") return;
30511
32071
  this.state = "disposed";
32072
+ this.dvc.dispose();
32073
+ this.#mobileEnvironment.dispose();
30512
32074
  this._subscriptions.dispose();
30513
32075
  if (this.pagehide) this.window.removeEventListener("pagehide", this.pagehide);
30514
32076
  this.abort.abort();
@@ -30520,8 +32082,11 @@ var Gramlot = class {
30520
32082
  }
30521
32083
  } finally {
30522
32084
  if (this.rpc.transport) {
30523
- this.rpc.transport.close(this.pageId, { beacon });
30524
- this.rpc.transport.dispose();
32085
+ try {
32086
+ this.rpc.transport.close(this.pageId);
32087
+ } finally {
32088
+ this.rpc.transport.dispose();
32089
+ }
30525
32090
  }
30526
32091
  }
30527
32092
  }
@@ -30554,8 +32119,11 @@ var PageBootstrap = class {
30554
32119
  const pagehide = (event) => {
30555
32120
  if (event.persisted || closed) return;
30556
32121
  closed = true;
30557
- this.closePage();
30558
- resolveClosed(null);
32122
+ try {
32123
+ this.closePage();
32124
+ } finally {
32125
+ resolveClosed(null);
32126
+ }
30559
32127
  };
30560
32128
  window2.addEventListener("pagehide", pagehide);
30561
32129
  try {
@@ -30654,8 +32222,11 @@ var PageBootstrap = class {
30654
32222
  * with a beacon, as `Gramlot` sends on pagehide. */
30655
32223
  closePage() {
30656
32224
  const transport = this.serverAdapter.createTransport({ ...this.config, document: this.document });
30657
- transport.close(this.config.pageId, { beacon: true });
30658
- transport.dispose();
32225
+ try {
32226
+ transport.close(this.config.pageId);
32227
+ } finally {
32228
+ transport.dispose();
32229
+ }
30659
32230
  }
30660
32231
  };
30661
32232
 
@@ -30777,17 +32348,17 @@ var IndexPage = class extends FramePage {
30777
32348
  pane.setAttr({ width: "240px", splitter: true, drawer: true, drawer_label: "Navigation" });
30778
32349
  pane.tree({
30779
32350
  node_label: "tree",
30780
- storepath: `${this.constructor.datapath}.navigation`,
32351
+ storepath: ".navigation",
30781
32352
  labelAttribute: "title",
30782
32353
  hideValues: true,
30783
- selectedPath: `^${this.constructor.datapath}.navigationSelection`
32354
+ selectedPath: "^.navigationSelection"
30784
32355
  });
30785
32356
  }
30786
32357
  center(pane) {
30787
- pane.tabContainer({ node_label: "tabs", height: "100%", selectedPage: `^${this.constructor.datapath}.active` });
32358
+ pane.tabContainer({ node_label: "tabs", height: "100%", selectedPage: "^.active" });
30788
32359
  }
30789
32360
  behavior(shell) {
30790
- shell.dataController({ func: "indexMount", _onStart: true, shell_id: this.constructor.shellId });
32361
+ shell.dataController({ func: "indexMount", _onStart: true });
30791
32362
  }
30792
32363
  index_panel(pane, { selection }) {
30793
32364
  this.panel(pane, selection.getNode("#0"));
@@ -30808,7 +32379,7 @@ IndexPage.registerSource("index_panel");
30808
32379
  function mountIndexPage(renderer, root, onSelection = () => {
30809
32380
  }, prepareEntry = () => {
30810
32381
  }, {
30811
- state = root.builder.data.getItem(root.getAttr("datapath")),
32382
+ state = root.getRelativeData("."),
30812
32383
  createEntry = null,
30813
32384
  onLoad = () => {
30814
32385
  }
@@ -30818,7 +32389,8 @@ function mountIndexPage(renderer, root, onSelection = () => {
30818
32389
  const tabs = root.value.getNode("frame.center.tabs");
30819
32390
  const builder = root.builder;
30820
32391
  const entries2 = /* @__PURE__ */ new Map();
30821
- let disposed = false, selecting = false, sequence = 0, requested = null;
32392
+ const context = { entries: entries2, disposed: false, selecting: false, sequence: 0, requested: null };
32393
+ Object.defineProperty(root, "indexContext", { value: context, configurable: true });
30822
32394
  const opened = state.getItem("opened");
30823
32395
  for (const record2 of opened.getNodes()) {
30824
32396
  const { url, path, title } = record2.attr;
@@ -30826,45 +32398,65 @@ function mountIndexPage(renderer, root, onSelection = () => {
30826
32398
  const entry = { url, path, title, pane, node: navigation.getNode(path), loading: false };
30827
32399
  prepareEntry(entry);
30828
32400
  entries2.set(url, entry);
30829
- sequence++;
32401
+ context.sequence++;
30830
32402
  }
32403
+ const notifyLoad = (entry, status, error) => {
32404
+ try {
32405
+ onLoad(entry.url, status, error);
32406
+ } catch (callbackError) {
32407
+ renderer.binding.reportError(callbackError, "Page load callback failed");
32408
+ }
32409
+ };
32410
+ const finishLoad = (entry, status, error) => {
32411
+ if (!entry.loading) return;
32412
+ entry.loading = false;
32413
+ notifyLoad(entry, status, error);
32414
+ };
30831
32415
  const activate = (entry) => {
30832
- if (disposed) return;
30833
- selecting = true;
32416
+ if (context.disposed) return;
32417
+ context.selecting = true;
30834
32418
  try {
30835
32419
  state.setItem("active", entry.url);
30836
32420
  state.setItem("navigationSelection", entry.path);
30837
32421
  onSelection(entries2, entry.url);
30838
32422
  } finally {
30839
- selecting = false;
32423
+ context.selecting = false;
30840
32424
  }
30841
32425
  };
32426
+ function requestSelection(path) {
32427
+ void select(path).catch((error) => {
32428
+ if (!context.disposed) renderer.binding.reportError(error, "Page could not be opened");
32429
+ });
32430
+ }
30842
32431
  async function select(path) {
30843
32432
  const node = navigation.getNode(path);
30844
32433
  if (!node) throw new Error(`Unknown index navigation path: ${path}`);
30845
32434
  const url = node.attr.url;
30846
32435
  if (url == null) return;
30847
32436
  if (typeof url !== "string" || !url) throw new TypeError("IndexPage URL must be nonempty text");
30848
- requested = url;
32437
+ context.requested = url;
30849
32438
  let entry = entries2.get(url);
30850
32439
  if (entry) {
30851
32440
  entry.path = path;
30852
32441
  activate(entry);
30853
32442
  return;
30854
32443
  }
30855
- while (tabs.value !== null && tabs.value.getNode(`page${sequence}`)) sequence++;
32444
+ while (tabs.value !== null && tabs.value.getNode(`page${context.sequence}`)) context.sequence++;
30856
32445
  const pane = sourceTarget(builder.wrapSource(tabs).contentPane({
30857
- node_label: `page${sequence++}`,
32446
+ node_label: `page${context.sequence++}`,
30858
32447
  title: node.attr.title ?? node.label,
30859
32448
  pageName: url,
30860
- height: "100%"
32449
+ height: "100%",
32450
+ closable: true
30861
32451
  }));
30862
32452
  const previous = state.getItem("active");
30863
32453
  entry = { url, path, node, pane, title: node.attr.title ?? node.label, loading: true };
30864
32454
  entries2.set(url, entry);
30865
32455
  try {
32456
+ notifyLoad(entry, "loading");
32457
+ if (context.disposed || entries2.get(url) !== entry) return;
30866
32458
  activate(entry);
30867
- onLoad(url, "loading");
32459
+ if (context.disposed || entries2.get(url) !== entry) return;
30868
32460
  if (createEntry) await createEntry(entry);
30869
32461
  else {
30870
32462
  const selection = new Bag();
@@ -30872,69 +32464,105 @@ function mountIndexPage(renderer, root, onSelection = () => {
30872
32464
  const mounted = await renderer.binding.gramlot.src.remoteSource(pane, "index_panel", { selection });
30873
32465
  if (!mounted) throw new Error("Panel loading was cancelled");
30874
32466
  }
30875
- if (disposed) return;
30876
- entry.loading = false;
32467
+ if (context.disposed || entries2.get(url) !== entry) return;
30877
32468
  opened.setItem(pane.label, null, { url, path: entry.path, title: entry.title });
30878
32469
  prepareEntry(entry);
30879
- if (requested === url) {
30880
- onLoad(url, "ready");
30881
- activate(entry);
30882
- }
30883
32470
  } catch (error) {
30884
- entries2.delete(url);
30885
- if (opened.getNode(pane.label)) opened.popNode(pane.label);
30886
- if (pane.parentBag) pane.parentBag.popNode(pane.label);
30887
- if (!disposed && requested === url) {
30888
- onLoad(url, "error", error);
30889
- const restored = entries2.get(previous);
30890
- requested = restored?.url ?? null;
30891
- if (restored) activate(restored);
32471
+ if (context.disposed || entries2.get(url) !== entry) return;
32472
+ try {
32473
+ renderer.binding.reportError(error, "Page could not be opened");
32474
+ entries2.delete(url);
32475
+ if (opened.getNode(pane.label)) opened.popNode(pane.label);
32476
+ if (pane.parentBag) pane.parentBag.popNode(pane.label);
32477
+ if (!context.disposed && context.requested === url) {
32478
+ const restored = entries2.get(previous);
32479
+ context.requested = restored?.url ?? null;
32480
+ if (restored) activate(restored);
32481
+ else {
32482
+ context.selecting = true;
32483
+ try {
32484
+ state.setItem("active", null);
32485
+ state.setItem("navigationSelection", null);
32486
+ onSelection(entries2, null);
32487
+ } finally {
32488
+ context.selecting = false;
32489
+ }
32490
+ }
32491
+ }
32492
+ } finally {
32493
+ finishLoad(entry, "error", error);
32494
+ }
32495
+ return;
32496
+ }
32497
+ if (context.disposed || entries2.get(url) !== entry) return;
32498
+ finishLoad(entry, "ready");
32499
+ if (!context.disposed && entries2.get(url) === entry && context.requested === url) activate(entry);
32500
+ }
32501
+ const sourceSubscription = `${root.getAttr("id")}-page-close`;
32502
+ root.value.subscribe(sourceSubscription, { any: (event) => {
32503
+ if (event.evt !== "del") return;
32504
+ const entry = [...entries2.values()].find((candidate) => candidate.pane === event.node);
32505
+ if (!entry) return;
32506
+ const { url, pane } = entry;
32507
+ if (context.disposed || renderer.disposed || entries2.get(url) !== entry) return;
32508
+ entries2.delete(url);
32509
+ if (opened.getNode(pane.label)) opened.popNode(pane.label);
32510
+ try {
32511
+ if (state.getItem("active") === url) {
32512
+ const next = [...entries2.values()].at(-1);
32513
+ context.requested = next?.url ?? null;
32514
+ if (next) activate(next);
30892
32515
  else {
30893
- selecting = true;
32516
+ context.selecting = true;
30894
32517
  try {
30895
32518
  state.setItem("active", null);
30896
32519
  state.setItem("navigationSelection", null);
30897
32520
  onSelection(entries2, null);
30898
32521
  } finally {
30899
- selecting = false;
32522
+ context.selecting = false;
30900
32523
  }
30901
32524
  }
30902
- }
32525
+ } else onSelection(entries2, state.getItem("active"));
32526
+ } finally {
32527
+ finishLoad(entry, "cancelled");
30903
32528
  }
30904
- }
32529
+ } });
30905
32530
  const subscription = `${root.getAttr("id")}-selection`;
30906
32531
  state.subscribe(subscription, { any: (event) => {
30907
- if (selecting || disposed) return;
32532
+ if (context.selecting || context.disposed) return;
30908
32533
  if (event.node === state.getNode("navigationSelection")) {
30909
32534
  const path = state.getItem("navigationSelection");
30910
- if (path !== null) void select(path);
32535
+ if (path !== null) requestSelection(path);
30911
32536
  } else if (event.node === state.getNode("active")) {
30912
32537
  const entry = entries2.get(state.getItem("active"));
30913
32538
  if (entry) {
30914
- requested = entry.url;
32539
+ context.requested = entry.url;
30915
32540
  activate(entry);
30916
32541
  }
30917
32542
  }
30918
32543
  } });
30919
32544
  const dispose = () => {
30920
- if (disposed) return;
30921
- disposed = true;
32545
+ if (context.disposed) return;
32546
+ context.disposed = true;
30922
32547
  state.unsubscribe(subscription, { any: true });
30923
- for (const entry of entries2.values()) if (entry.loading && entry.pane.parentBag) {
30924
- entry.pane.parentBag.popNode(entry.pane.label);
32548
+ root.value.unsubscribe(sourceSubscription, { any: true });
32549
+ for (const entry of entries2.values()) if (entry.loading) {
32550
+ if (entry.pane.parentBag) entry.pane.parentBag.popNode(entry.pane.label);
32551
+ finishLoad(entry, "cancelled");
30925
32552
  }
32553
+ entries2.clear();
32554
+ if (root.indexContext === context) delete root.indexContext;
30926
32555
  };
32556
+ context.dispose = dispose;
30927
32557
  renderer.onDispose(root, dispose);
30928
32558
  const active = entries2.get(state.getItem("active"));
30929
32559
  if (active) activate(active);
30930
- else if (state.getItem("navigationSelection") !== null) void select(state.getItem("navigationSelection"));
30931
- return { entries: entries2, dispose };
32560
+ else if (state.getItem("navigationSelection") !== null) requestSelection(state.getItem("navigationSelection"));
32561
+ return context;
30932
32562
  }
30933
32563
  var IndexLogic = class {
30934
- indexMount(node, { shell_id }) {
30935
- const renderer = this.page.src.renderer;
30936
- const element = renderer.destination.ownerDocument.getElementById(shell_id);
30937
- this.index = mountIndexPage(renderer, renderer.elements.get(element).node);
32564
+ indexMount(node) {
32565
+ mountIndexPage(this.page.src.renderer, node.parentNode);
30938
32566
  }
30939
32567
  };
30940
32568
 
@@ -31054,13 +32682,16 @@ var DirectoryResolver = class _DirectoryResolver extends RemoteResolver {
31054
32682
  }
31055
32683
  };
31056
32684
  var FileSystemController = class {
31057
- constructor(gramlot, state) {
32685
+ constructor(gramlot, source) {
31058
32686
  this.gramlot = gramlot;
31059
- this.state = state;
32687
+ this.source = source;
31060
32688
  this.request = null;
31061
32689
  this.resolver = null;
31062
32690
  this.disposed = false;
31063
32691
  }
32692
+ get state() {
32693
+ return this.source.getRelativeData(".");
32694
+ }
31064
32695
  async open(root) {
31065
32696
  this.request?.abort();
31066
32697
  const request = this.request = new AbortController();
@@ -31097,14 +32728,13 @@ var FileSystemController = class {
31097
32728
  };
31098
32729
  var FileSystemLogic = class {
31099
32730
  fileSystemMount(node) {
31100
- this.fileSystems ??= /* @__PURE__ */ new WeakMap();
31101
- const scope = node.parentNode, state = scope.getRelativeData(".");
31102
- const controller = new FileSystemController(this.page, state);
31103
- this.fileSystems.set(state, controller);
32731
+ const scope = node.parentNode;
32732
+ const controller = new FileSystemController(this.page, scope);
32733
+ Object.defineProperty(scope, "fileSystemController", { value: controller, configurable: true });
31104
32734
  this.page.src.renderer.onDispose(scope, () => controller.dispose());
31105
32735
  }
31106
32736
  fileSystemOpen(node, { root }) {
31107
- if (root) return this.fileSystems.get(node.getRelativeData(".")).open(root);
32737
+ if (root) return node.parentNode.fileSystemController.open(root);
31108
32738
  }
31109
32739
  };
31110
32740
  function fileSystemTree(parent, { datapath, ...attributes }) {
@@ -31130,12 +32760,15 @@ function fileSystemTree(parent, { datapath, ...attributes }) {
31130
32760
  // src/ide-documents.js
31131
32761
  var documentKey = (root, path) => "d_" + [...new TextEncoder().encode(JSON.stringify([root, path]))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
31132
32762
  var IdeDocuments = class {
31133
- constructor(gramlot, state) {
32763
+ constructor(gramlot, source) {
31134
32764
  this.gramlot = gramlot;
31135
- this.state = state;
32765
+ this.source = source;
31136
32766
  this.pending = /* @__PURE__ */ new Map();
31137
32767
  this.disposed = false;
31138
32768
  }
32769
+ get state() {
32770
+ return this.source.getRelativeData(".");
32771
+ }
31139
32772
  get documents() {
31140
32773
  return this.state.getItem("documents");
31141
32774
  }
@@ -31156,7 +32789,7 @@ var IdeDocuments = class {
31156
32789
  return promise;
31157
32790
  }
31158
32791
  newDocument(language, extension, root = "") {
31159
- const key = `new_${crypto.randomUUID().replaceAll("-", "")}`;
32792
+ const key = `new_${randomId()}`;
31160
32793
  const doc = new Bag();
31161
32794
  for (const [name, value] of Object.entries({
31162
32795
  language,
@@ -31315,6 +32948,13 @@ var RecentWorkspaces = class {
31315
32948
  };
31316
32949
 
31317
32950
  // src/ide-runtime.js
32951
+ function ideContext(node) {
32952
+ for (let scope = node; scope; scope = scope.parentNode) {
32953
+ const context = scope.ideContext;
32954
+ if (context) return context;
32955
+ }
32956
+ throw new Error("IDE operation requires a node inside a mounted IDE");
32957
+ }
31318
32958
  var IdeLogic = class {
31319
32959
  fileSystemMount(node) {
31320
32960
  return FileSystemLogic.prototype.fileSystemMount.call(this, node);
@@ -31323,77 +32963,89 @@ var IdeLogic = class {
31323
32963
  return FileSystemLogic.prototype.fileSystemOpen.call(this, node, args);
31324
32964
  }
31325
32965
  ideMount(node) {
31326
- this.ideRoot = node.parentNode;
31327
- this.ideState = node.getRelativeData(".");
31328
- this.ideDocuments = new IdeDocuments(this.page, this.ideState);
31329
- this.idePanels = /* @__PURE__ */ new Map();
31330
- this.ideDisposed = false;
31331
- this.ideRequested = 0;
31332
- this.ideRecent = new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage);
31333
- const roots = this.ideRecent.read();
31334
- this.ideState.setItem("recent", this.ideRecent.choices(roots));
31335
- this.ideState.setItem("workspace", roots[0] ?? "");
31336
- const browser = this.ideState.getItem("browser");
32966
+ const scope = node.parentNode;
32967
+ const context = {
32968
+ scope,
32969
+ documents: new IdeDocuments(this.page, scope),
32970
+ requested: 0,
32971
+ editorPrefix: `ide_${randomId()}`,
32972
+ recent: new RecentWorkspaces(this.page.src.renderer.destination.ownerDocument.defaultView.sessionStorage)
32973
+ };
32974
+ Object.defineProperty(scope, "ideContext", { value: context, configurable: true });
32975
+ const { documents, recent } = context;
32976
+ const state = scope.getRelativeData(".");
32977
+ const roots = recent.read();
32978
+ state.setItem("recent", recent.choices(roots));
32979
+ state.setItem("workspace", roots[0] ?? "");
32980
+ const browser = state.getItem("browser");
31337
32981
  browser.subscribe("ide-browser", { any: (event) => {
31338
32982
  if (event.node === browser.getNode("root")) {
31339
32983
  const root = browser.getItem("root");
31340
- this.ideState.setItem("workspace", root);
31341
- this.ideState.setItem("recent", this.ideRecent.choices(this.ideRecent.remember(root)));
31342
- this.ideState.setItem("status", `Workspace: ${root}`);
32984
+ state.setItem("workspace", root);
32985
+ state.setItem("recent", recent.choices(recent.remember(root)));
32986
+ state.setItem("status", `Workspace: ${root}`);
31343
32987
  } else if (event.node === browser.getNode("selectedPath")) {
31344
32988
  const path = browser.getItem("selectedPath");
31345
32989
  const item = path === null ? null : browser.getItem("store").getNode(path);
31346
- if (item && !item.attr.is_directory) void this.ideOpenDocument(browser.getItem("root"), item.attr.path);
32990
+ if (item && !item.attr.is_directory) void this.ideOpenDocument(scope, browser.getItem("root"), item.attr.path);
31347
32991
  }
31348
32992
  } });
31349
- this.ideDocuments.documents.subscribe("ide-documents", { any: (event) => {
32993
+ const documentBag = documents.documents;
32994
+ documentBag.subscribe("ide-documents", { any: (event) => {
31350
32995
  if (!["content", "saved", "busy", "writable", "view", "isNew", "path", "root"].includes(event.node.label)) return;
31351
- for (const [key, pane] of this.idePanels) {
31352
- const doc = this.ideDocuments.documents.getItem(key);
32996
+ for (const pane of scope.value.getNode("frame.center.tabs").value?.getNodes() ?? []) {
32997
+ const key = pane.getAttr("documentKey");
32998
+ const doc = documents.documents.getItem(key);
31353
32999
  if (doc) {
31354
- if (event.node === doc.getNode("content")) this.ideDocuments.invalidateRecipe(key);
31355
- this.ideDocumentState(key);
31356
- pane.setAttr({ title: `${this.ideDocuments.dirty(key) ? "\u25CF " : ""}${doc.getItem("path")}` });
33000
+ if (event.node === doc.getNode("content")) documents.invalidateRecipe(key);
33001
+ this.ideDocumentState(scope, key);
33002
+ pane.setAttr({ title: `${documents.dirty(key) ? "\u25CF " : ""}${doc.getItem("path")}` });
31357
33003
  }
31358
33004
  }
31359
33005
  } });
31360
- this.page.src.renderer.onDispose(this.ideRoot, () => {
31361
- this.ideDisposed = true;
33006
+ this.page.src.renderer.onDispose(context.scope, () => {
31362
33007
  browser.unsubscribe("ide-browser", { any: true });
31363
- this.ideDocuments.documents.unsubscribe("ide-documents", { any: true });
31364
- this.ideDocuments.dispose();
33008
+ documentBag.unsubscribe("ide-documents", { any: true });
33009
+ documents.dispose();
31365
33010
  });
31366
33011
  }
31367
- ideOpenWorkspace() {
31368
- const root = this.ideState.getItem("workspace");
31369
- if (root && root !== this.ideState.getItem("browser.root")) this.ideState.setItem("browser.requestedRoot", root);
33012
+ ideOpenWorkspace(node) {
33013
+ const context = ideContext(node);
33014
+ const state = context.scope.getRelativeData(".");
33015
+ const root = state.getItem("workspace");
33016
+ if (root && root !== state.getItem("browser.root")) state.setItem("browser.requestedRoot", root);
31370
33017
  }
31371
- ideDocumentState(key) {
31372
- const doc = this.ideDocuments.documents.getItem(key);
31373
- const disabled = !this.ideDocuments.dirty(key) && !doc.getItem("isNew") || doc.getItem("busy");
33018
+ ideDocumentState(node, key) {
33019
+ const context = ideContext(node), { documents } = context;
33020
+ const doc = documents.documents.getItem(key);
33021
+ const disabled = !documents.dirty(key) && !doc.getItem("isNew") || doc.getItem("busy");
31374
33022
  doc.setItem("saveDisabled", Boolean(disabled || !doc.getItem("writable")));
31375
- doc.setItem("revertDisabled", Boolean(!this.ideDocuments.dirty(key) || doc.getItem("busy")));
33023
+ doc.setItem("revertDisabled", Boolean(!documents.dirty(key) || doc.getItem("busy")));
31376
33024
  doc.setItem("displayPath", doc.getItem("isNew") ? doc.getItem("path") : `${doc.getItem("root")}/${doc.getItem("path")}`);
31377
33025
  doc.setItem("pdfFilename", doc.getItem("path").split("/").at(-1).replace(/\.typ(?:\.py)?$/i, ".pdf"));
31378
33026
  doc.setItem("renderDisabled", Boolean(doc.getItem("busy") || !doc.getItem("writable")));
31379
33027
  this.ideHistoryState(doc);
31380
33028
  }
31381
- async ideOpenDocument(root, path) {
31382
- const requested = ++this.ideRequested;
33029
+ async ideOpenDocument(node, root, path) {
33030
+ const context = ideContext(node), { documents } = context;
33031
+ const state = context.scope.getRelativeData(".");
33032
+ const requested = ++context.requested;
31383
33033
  try {
31384
- const key = await this.ideDocuments.open(root, path);
31385
- if (key === null || this.ideDisposed) return;
31386
- this.ideShowDocument(key);
31387
- if (requested === this.ideRequested) {
31388
- this.ideState.setItem("active", key);
31389
- this.ideState.setItem("status", `${path}${this.ideDocuments.documents.getItem(key).getItem("writable") ? "" : " (draft only \u2014 Remote Edit is disabled)"}`);
33034
+ const key = await documents.open(root, path);
33035
+ if (key === null || documents.disposed) return;
33036
+ this.ideShowDocument(node, key);
33037
+ if (requested === context.requested) {
33038
+ state.setItem("active", key);
33039
+ state.setItem("status", `${path}${documents.documents.getItem(key).getItem("writable") ? "" : " (draft only \u2014 Remote Edit is disabled)"}`);
31390
33040
  }
31391
33041
  } catch (error) {
31392
- if (!this.ideDisposed) this.ideState.setItem("status", error.message);
33042
+ if (!documents.disposed) state.setItem("status", error.message);
31393
33043
  }
31394
33044
  }
31395
- ideNew() {
31396
- const type = this.ideState.getItem("newType");
33045
+ ideNew(node) {
33046
+ const context = ideContext(node), { documents } = context;
33047
+ const state = context.scope.getRelativeData(".");
33048
+ const type = state.getItem("newType");
31397
33049
  const language = type === "typstRecipe" ? "python" : type;
31398
33050
  const extensions = {
31399
33051
  typstRecipe: ".typ.py",
@@ -31409,27 +33061,28 @@ var IdeLogic = class {
31409
33061
  xml: ".xml",
31410
33062
  text: ".txt"
31411
33063
  };
31412
- const key = this.ideDocuments.newDocument(language, extensions[type], this.ideState.getItem("workspace"));
31413
- this.ideDocuments.documents.getItem(key).setItem("writable", this.ideState.getItem("browser.writable") === true);
31414
- ++this.ideRequested;
31415
- this.ideShowDocument(key);
31416
- this.ideState.setItem("active", key);
31417
- this.ideState.setItem("status", "New document. Choose directory and name when saving.");
31418
- }
31419
- ideShowDocument(key) {
31420
- const document = this.ideDocuments.documents.getItem(key);
33064
+ const key = documents.newDocument(language, extensions[type], state.getItem("workspace"));
33065
+ documents.documents.getItem(key).setItem("writable", state.getItem("browser.writable") === true);
33066
+ ++context.requested;
33067
+ this.ideShowDocument(node, key);
33068
+ state.setItem("active", key);
33069
+ state.setItem("status", "New document. Choose directory and name when saving.");
33070
+ }
33071
+ ideShowDocument(node, key) {
33072
+ const context = ideContext(node), { documents } = context;
33073
+ const document = documents.documents.getItem(key);
31421
33074
  const path = document.getItem("path");
31422
- if (!this.idePanels.has(key)) {
31423
- const doc = this.ideDocuments.documents.getItem(key);
33075
+ const tabs = context.scope.value.getNode("frame.center.tabs");
33076
+ if (!tabs.value?.getNode(key)) {
33077
+ const doc = documents.documents.getItem(key);
31424
33078
  const recipe = path.endsWith(".typ.py");
31425
- if (recipe) this.ideDocuments.invalidateRecipe(key);
33079
+ if (recipe) documents.invalidateRecipe(key);
31426
33080
  doc.setItem("readonly", false);
31427
- this.ideDocumentState(key);
33081
+ this.ideDocumentState(node, key);
31428
33082
  doc.setItem("view", "code");
31429
33083
  doc.setItem("createHidden", true);
31430
33084
  doc.setItem("undoDisabled", true);
31431
33085
  doc.setItem("redoDisabled", true);
31432
- const tabs = this.ideRoot.value.getNode("frame.center.tabs");
31433
33086
  const pane = sourceTarget(tabs.builder.wrapSource(tabs).contentPane({
31434
33087
  node_label: key,
31435
33088
  title: path,
@@ -31439,7 +33092,6 @@ var IdeLogic = class {
31439
33092
  onClose: "ideClose",
31440
33093
  height: "100%"
31441
33094
  }));
31442
- this.idePanels.set(key, pane);
31443
33095
  const target = pane.builder.wrapSource(pane).div({ display: "flex", flex_direction: "column", height: "100%" });
31444
33096
  const toolbar = target.div({
31445
33097
  datapath: `.documents.${key}`,
@@ -31515,11 +33167,11 @@ var IdeLogic = class {
31515
33167
  language: doc.getItem("language"),
31516
33168
  height: "100%",
31517
33169
  readonly: "^.readonly",
31518
- nodeId: `editor_${key}`,
33170
+ nodeId: `${context.editorPrefix}_editor_${key}`,
31519
33171
  editorView: "code",
31520
33172
  selfsubscribe_historyChanged: "ideHistoryChanged"
31521
33173
  });
31522
- target.dataController({ func: "ideSave", documentKey: key, [`subscribe_editor_${key}_save`]: true });
33174
+ target.dataController({ func: "ideSave", documentKey: key, [`subscribe_${context.editorPrefix}_editor_${key}_save`]: true });
31523
33175
  if (typst) views.contentPane({ title: "Preview", pageName: "preview", height: "100%" }).typstPreview({ value: `^.documents.${key}.content`, filename: `^.documents.${key}.pdfFilename`, height: "100%" });
31524
33176
  if (recipe) {
31525
33177
  const output = views.contentPane({ title: "Preview", pageName: "preview", height: "100%", display: "flex", flex_direction: "column" });
@@ -31550,53 +33202,61 @@ var IdeLogic = class {
31550
33202
  value: "^.content",
31551
33203
  readonly: "^.readonly",
31552
33204
  height: "100%",
31553
- nodeId: `rich_editor_${key}`,
33205
+ nodeId: `${context.editorPrefix}_rich_editor_${key}`,
31554
33206
  editorView: "rich",
31555
33207
  selfsubscribe_historyChanged: "ideHistoryChanged"
31556
33208
  });
31557
- target.dataController({ func: "ideSave", documentKey: key, [`subscribe_rich_editor_${key}_save`]: true });
33209
+ target.dataController({ func: "ideSave", documentKey: key, [`subscribe_${context.editorPrefix}_rich_editor_${key}_save`]: true });
31558
33210
  }
31559
33211
  }
31560
33212
  }
31561
33213
  async ideRenderRecipe(node, { documentKey: documentKey2 }) {
31562
- const doc = this.ideDocuments.documents.getItem(documentKey2);
33214
+ const context = ideContext(node), { documents } = context;
33215
+ const doc = documents.documents.getItem(documentKey2);
31563
33216
  doc.setItem("view", "preview");
31564
- await this.ideDocuments.renderRecipe(documentKey2);
33217
+ await documents.renderRecipe(documentKey2);
31565
33218
  }
31566
33219
  ideCancelCreate(node, { documentKey: documentKey2 }) {
31567
- this.ideDocuments.documents.getItem(documentKey2).setItem("createHidden", true);
33220
+ const context = ideContext(node), { documents } = context;
33221
+ documents.documents.getItem(documentKey2).setItem("createHidden", true);
31568
33222
  }
31569
33223
  async ideCreate(node, { documentKey: documentKey2 }) {
31570
- this.ideState.setItem("status", "Creating file\u2026");
33224
+ const context = ideContext(node), { documents } = context;
33225
+ const state = context.scope.getRelativeData(".");
33226
+ state.setItem("status", "Creating file\u2026");
31571
33227
  try {
31572
- const saved = await this.ideDocuments.create(documentKey2);
31573
- if (!this.ideDisposed && saved) {
31574
- this.ideState.setItem("status", "File created.");
31575
- const browser = this.ideState.getItem("browser");
31576
- if (browser.getItem("root")) await this.fileSystems.get(browser).open(browser.getItem("root"));
33228
+ const saved = await documents.create(documentKey2);
33229
+ if (!documents.disposed && saved) {
33230
+ state.setItem("status", "File created.");
33231
+ const browser = state.getItem("browser");
33232
+ if (browser.getItem("root")) await context.scope.value.getNode("frame.left.browser").fileSystemController.open(browser.getItem("root"));
31577
33233
  }
31578
33234
  } catch (error) {
31579
- if (!this.ideDisposed) this.ideState.setItem("status", error.message);
33235
+ if (!documents.disposed) state.setItem("status", error.message);
31580
33236
  }
31581
33237
  }
31582
33238
  async ideSave(node, { documentKey: documentKey2 = null } = {}) {
31583
- const key = documentKey2 ?? this.ideState.getItem("active");
31584
- if (!key || this.ideDocuments.documents.getItem(key).getItem("saveDisabled")) return;
31585
- const doc = this.ideDocuments.documents.getItem(key);
33239
+ const context = ideContext(node), { documents } = context;
33240
+ const state = context.scope.getRelativeData(".");
33241
+ const key = documentKey2 ?? state.getItem("active");
33242
+ if (!key || documents.documents.getItem(key).getItem("saveDisabled")) return;
33243
+ const doc = documents.documents.getItem(key);
31586
33244
  if (doc.getItem("isNew")) {
31587
33245
  doc.setItem("createHidden", false);
31588
33246
  return;
31589
33247
  }
31590
- this.ideState.setItem("status", "Saving\u2026");
33248
+ state.setItem("status", "Saving\u2026");
31591
33249
  try {
31592
- const saved = await this.ideDocuments.save(key);
31593
- if (!this.ideDisposed) this.ideState.setItem("status", saved ? "Saved." : "Document is read only or a request is pending.");
33250
+ const saved = await documents.save(key);
33251
+ if (!documents.disposed) state.setItem("status", saved ? "Saved." : "Document is read only or a request is pending.");
31594
33252
  } catch (error) {
31595
- if (!this.ideDisposed) this.ideState.setItem("status", error.message);
33253
+ if (!documents.disposed) state.setItem("status", error.message);
31596
33254
  }
31597
33255
  }
31598
33256
  ideRevert(node, { documentKey: documentKey2 }) {
31599
- if (this.ideDocuments.revert(documentKey2)) this.ideState.setItem("status", "Restored the last saved version.");
33257
+ const context = ideContext(node), { documents } = context;
33258
+ const state = context.scope.getRelativeData(".");
33259
+ if (documents.revert(documentKey2)) state.setItem("status", "Restored the last saved version.");
31600
33260
  }
31601
33261
  ideHistoryChanged(node, { canUndo, canRedo }) {
31602
33262
  const doc = node.getRelativeData(".");
@@ -31610,37 +33270,41 @@ var IdeLogic = class {
31610
33270
  doc.setItem("undoDisabled", !doc.getItem(`${view}CanUndo`));
31611
33271
  doc.setItem("redoDisabled", !doc.getItem(`${view}CanRedo`));
31612
33272
  }
31613
- ideEditor(documentKey2) {
31614
- const rich = this.ideDocuments.documents.getItem(documentKey2).getItem("view") === "rich";
31615
- const node = this.page.src.binding.nodeIds.get(`${rich ? "rich_" : ""}editor_${documentKey2}`);
31616
- return this.page.src.renderer.records.get(node).element;
33273
+ ideEditor(node, documentKey2) {
33274
+ const context = ideContext(node), { documents } = context;
33275
+ const rich = documents.documents.getItem(documentKey2).getItem("view") === "rich";
33276
+ const editor = this.page.src.binding.nodeIds.get(`${context.editorPrefix}_${rich ? "rich_" : ""}editor_${documentKey2}`);
33277
+ return this.page.src.renderer.records.get(editor).element;
31617
33278
  }
31618
33279
  ideUndo(node, { documentKey: documentKey2 }) {
31619
- this.ideEditor(documentKey2).undo();
33280
+ this.ideEditor(node, documentKey2).undo();
31620
33281
  }
31621
33282
  ideRedo(node, { documentKey: documentKey2 }) {
31622
- this.ideEditor(documentKey2).redo();
33283
+ this.ideEditor(node, documentKey2).redo();
31623
33284
  }
31624
33285
  ideClose(node) {
33286
+ const context = ideContext(node), { documents } = context;
33287
+ const state = context.scope.getRelativeData(".");
31625
33288
  const key = node.getAttr("documentKey");
31626
- if (!this.ideDocuments.canClose(key)) {
31627
- this.ideState.setItem("status", "Save or revert your changes before closing. Pending operations must finish first.");
33289
+ if (!documents.canClose(key)) {
33290
+ state.setItem("status", "Save or revert your changes before closing. Pending operations must finish first.");
31628
33291
  return false;
31629
33292
  }
31630
33293
  return true;
31631
33294
  }
31632
33295
  ideClosed(node, { pageName }) {
31633
- this.ideForgetDocument(pageName);
33296
+ this.ideForgetDocument(node, pageName);
31634
33297
  }
31635
- ideForgetDocument(key, discard = false) {
31636
- const document = this.ideDocuments.documents.getItem(key);
31637
- const browser = this.ideState.getItem("browser"), selectedPath = browser.getItem("selectedPath");
33298
+ ideForgetDocument(node, key, discard = false) {
33299
+ const context = ideContext(node), { documents } = context;
33300
+ const state = context.scope.getRelativeData(".");
33301
+ const document = documents.documents.getItem(key);
33302
+ const browser = state.getItem("browser"), selectedPath = browser.getItem("selectedPath");
31638
33303
  const selected = selectedPath === null ? null : browser.getItem("store").getNode(selectedPath);
31639
33304
  if (document && browser.getItem("root") === document.getItem("root") && selected?.attr.path === document.getItem("path")) {
31640
33305
  browser.setItem("selectedPath", null);
31641
33306
  }
31642
- this.idePanels.delete(key);
31643
- this.ideDocuments.close(key, discard);
33307
+ documents.close(key, discard);
31644
33308
  }
31645
33309
  };
31646
33310
 
@@ -31707,7 +33371,7 @@ var NavigationResolver = class _NavigationResolver extends RemoteResolver {
31707
33371
  }
31708
33372
  };
31709
33373
 
31710
- // src/date-parser/civil.js
33374
+ // node_modules/@genrojs/toolbox/js/src/dates/civil.js
31711
33375
  function daysInMonth(year, month) {
31712
33376
  if (month === 2) return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28;
31713
33377
  return [4, 6, 9, 11].includes(month) ? 30 : 31;
@@ -31759,8 +33423,121 @@ function monthPeriod(year, month, offset = 0, count = 1) {
31759
33423
  return { start: civil(y, m, 1), end: civil(ey, em, daysInMonth(ey, em)) };
31760
33424
  }
31761
33425
 
31762
- // src/date-parser/locales.js
33426
+ // node_modules/@genrojs/toolbox/js/src/dates/locales.js
31763
33427
  var locales = {
33428
+ "en": {
33429
+ "months": {
33430
+ "january": 1,
33431
+ "february": 2,
33432
+ "march": 3,
33433
+ "april": 4,
33434
+ "may": 5,
33435
+ "june": 6,
33436
+ "july": 7,
33437
+ "august": 8,
33438
+ "september": 9,
33439
+ "october": 10,
33440
+ "november": 11,
33441
+ "december": 12,
33442
+ "jan": 1,
33443
+ "feb": 2,
33444
+ "mar": 3,
33445
+ "apr": 4,
33446
+ "jun": 6,
33447
+ "jul": 7,
33448
+ "aug": 8,
33449
+ "sep": 9,
33450
+ "oct": 10,
33451
+ "nov": 11,
33452
+ "dec": 12
33453
+ },
33454
+ "weekdays": {
33455
+ "monday": 0,
33456
+ "tuesday": 1,
33457
+ "wednesday": 2,
33458
+ "thursday": 3,
33459
+ "friday": 4,
33460
+ "saturday": 5,
33461
+ "sunday": 6,
33462
+ "mon": 0,
33463
+ "tue": 1,
33464
+ "wed": 2,
33465
+ "thu": 3,
33466
+ "fri": 4,
33467
+ "sat": 5,
33468
+ "sun": 6
33469
+ },
33470
+ "quarters": {
33471
+ "1st quarter": 1,
33472
+ "2nd quarter": 2,
33473
+ "3rd quarter": 3,
33474
+ "4th quarter": 4,
33475
+ "q1": 1,
33476
+ "q2": 2,
33477
+ "q3": 3,
33478
+ "q4": 4
33479
+ },
33480
+ "keywords": {
33481
+ "today": [
33482
+ "today"
33483
+ ],
33484
+ "yesterday": [
33485
+ "yesterday"
33486
+ ],
33487
+ "tomorrow": [
33488
+ "tomorrow"
33489
+ ],
33490
+ "this_week": [
33491
+ "this week",
33492
+ "week"
33493
+ ],
33494
+ "last_week": [
33495
+ "last week"
33496
+ ],
33497
+ "next_week": [
33498
+ "next week"
33499
+ ],
33500
+ "this_month": [
33501
+ "this month",
33502
+ "month"
33503
+ ],
33504
+ "last_month": [
33505
+ "last month"
33506
+ ],
33507
+ "next_month": [
33508
+ "next month"
33509
+ ],
33510
+ "last": [
33511
+ "last"
33512
+ ],
33513
+ "next": [
33514
+ "next"
33515
+ ],
33516
+ "articles": [
33517
+ "the"
33518
+ ],
33519
+ "from": [
33520
+ "from",
33521
+ "between"
33522
+ ],
33523
+ "to": [
33524
+ "to",
33525
+ "and"
33526
+ ],
33527
+ "no_period": [
33528
+ "no period",
33529
+ "always"
33530
+ ]
33531
+ },
33532
+ "date_order": {
33533
+ "default": "MDY",
33534
+ "GB": "DMY",
33535
+ "AU": "DMY",
33536
+ "IE": "DMY",
33537
+ "NZ": "DMY",
33538
+ "IN": "DMY"
33539
+ }
33540
+ },
31764
33541
  "it": {
31765
33542
  "months": {
31766
33543
  "gennaio": 1,
@@ -31887,121 +33664,10 @@ var locales = {
31887
33664
  "date_order": {
31888
33665
  "default": "DMY"
31889
33666
  }
31890
- },
31891
- "en": {
31892
- "months": {
31893
- "january": 1,
31894
- "february": 2,
31895
- "march": 3,
31896
- "april": 4,
31897
- "may": 5,
31898
- "june": 6,
31899
- "july": 7,
31900
- "august": 8,
31901
- "september": 9,
31902
- "october": 10,
31903
- "november": 11,
31904
- "december": 12,
31905
- "jan": 1,
31906
- "feb": 2,
31907
- "mar": 3,
31908
- "apr": 4,
31909
- "jun": 6,
31910
- "jul": 7,
31911
- "aug": 8,
31912
- "sep": 9,
31913
- "oct": 10,
31914
- "nov": 11,
31915
- "dec": 12
31916
- },
31917
- "weekdays": {
31918
- "monday": 0,
31919
- "tuesday": 1,
31920
- "wednesday": 2,
31921
- "thursday": 3,
31922
- "friday": 4,
31923
- "saturday": 5,
31924
- "sunday": 6,
31925
- "mon": 0,
31926
- "tue": 1,
31927
- "wed": 2,
31928
- "thu": 3,
31929
- "fri": 4,
31930
- "sat": 5,
31931
- "sun": 6
31932
- },
31933
- "quarters": {
31934
- "1st quarter": 1,
31935
- "2nd quarter": 2,
31936
- "3rd quarter": 3,
31937
- "4th quarter": 4,
31938
- "q1": 1,
31939
- "q2": 2,
31940
- "q3": 3,
31941
- "q4": 4
31942
- },
31943
- "keywords": {
31944
- "today": [
31945
- "today"
31946
- ],
31947
- "yesterday": [
31948
- "yesterday"
31949
- ],
31950
- "tomorrow": [
31951
- "tomorrow"
31952
- ],
31953
- "this_week": [
31954
- "this week",
31955
- "week"
31956
- ],
31957
- "last_week": [
31958
- "last week"
31959
- ],
31960
- "next_week": [
31961
- "next week"
31962
- ],
31963
- "this_month": [
31964
- "this month",
31965
- "month"
31966
- ],
31967
- "last_month": [
31968
- "last month"
31969
- ],
31970
- "next_month": [
31971
- "next month"
31972
- ],
31973
- "last": [
31974
- "last"
31975
- ],
31976
- "next": [
31977
- "next"
31978
- ],
31979
- "articles": [
31980
- "the"
31981
- ],
31982
- "from": [
31983
- "from",
31984
- "between"
31985
- ],
31986
- "to": [
31987
- "to",
31988
- "and"
31989
- ],
31990
- "no_period": [
31991
- "no period",
31992
- "always"
31993
- ]
31994
- },
31995
- "date_order": {
31996
- "default": "MDY",
31997
- "GB": "DMY",
31998
- "AU": "DMY",
31999
- "IE": "DMY",
32000
- "NZ": "DMY",
32001
- "IN": "DMY"
32002
- }
32003
33667
  }
32004
33668
  };
33669
+
33670
+ // node_modules/@genrojs/toolbox/js/src/dates/locale-context.js
32005
33671
  function localeContext(locale) {
32006
33672
  if (typeof locale !== "string") throw new RangeError("A supported locale is required.");
32007
33673
  const tag2 = locale.replaceAll("-", "_");
@@ -32014,7 +33680,7 @@ function localeContext(locale) {
32014
33680
  return { dictionary, phrases, order: dictionary.date_order[region] ?? dictionary.date_order.default };
32015
33681
  }
32016
33682
 
32017
- // src/date-parser/index.js
33683
+ // node_modules/@genrojs/toolbox/js/src/dates/index.js
32018
33684
  var yearPattern = /^(?:\d{4}|\d{2})$/;
32019
33685
  var dayPattern = /^\d{1,2}$/;
32020
33686
  var fail2 = (code, message) => ({ ok: false, error: { code, message } });
@@ -32207,80 +33873,30 @@ function parseDateExpression(text2, options = {}) {
32207
33873
  }
32208
33874
 
32209
33875
  // src/components/labelbox.js
32210
- var POSITIONS = ["TL", "TC", "TR", "L", "R", "BL", "BC", "BR"];
32211
- function project2(element, attrs, adapt, previous) {
32212
- const next = adapt(attrs);
32213
- for (const key of /* @__PURE__ */ new Set([...Object.keys(previous), ...Object.keys(next)])) {
32214
- if (next[key] == null) element.removeAttribute(key);
32215
- else element.setAttribute(key, String(next[key]));
32216
- }
32217
- return next;
32218
- }
32219
33876
  function Labelbox(Base) {
32220
33877
  return class extends Base {
32221
- #previous = { box: {}, label: {}, labelBox: {}, controlBox: {} };
32222
- constructor() {
32223
- super();
32224
- this.box = this.ownerDocument.createElement("div");
32225
- this.box.className = "labelbox";
32226
- this.labelBox = this.ownerDocument.createElement("div");
32227
- this.labelBox.className = "label-box";
32228
- this.fieldLabel = this.ownerDocument.createElement("label");
32229
- this.fieldLabel.id = "field-label";
32230
- this.fieldLabel.htmlFor = "control";
32231
- this.labelBox.append(this.fieldLabel);
32232
- this.box.append(this.labelBox, this.controlBox);
32233
- const style = this.ownerDocument.createElement("style");
32234
- style.textContent = `.labelbox{--gramlot-label-width:initial;--gramlot-formlet-label-width:initial;display:grid;gap:var(--gramlot-label-gap,.25em);grid-template-areas:'label' 'control'}
32235
- .label-box{grid-area:label;color:var(--gramlot-label-color,var(--gramlot-text-secondary,inherit));font-size:var(--gramlot-label-size,1em)} .control-box{grid-area:control}
32236
- .labelbox[data-position='L']{grid-template-areas:'label control';align-items:center}
32237
- .labelbox[data-position='R']{grid-template-areas:'control label';align-items:center}
32238
- .labelbox[data-position^='B']{grid-template-areas:'control' 'label'}
32239
- .labelbox[data-position$='C']>.label-box{text-align:center}
32240
- .labelbox[data-position$='R']>.label-box{text-align:right}
32241
- .label-box[hidden]{display:none} .label-box label{display:block}
32242
- .labelbox[data-position='L']>.label-box{text-align:right;padding-right:2px}
32243
- .labelbox[data-formlet-aligned]>.label-box>label{width:max-content;margin-left:auto}
32244
- .labelbox[data-position='L']{grid-template-columns:var(--gramlot-label-width,var(--gramlot-formlet-label-width,max-content)) minmax(0,1fr)}`;
32245
- this.shadowRoot.append(style, this.box);
33878
+ setLabelbox(layout) {
33879
+ const { box, labelBox, fieldLabel } = layout;
33880
+ Object.assign(this, { box, labelBox, fieldLabel });
33881
+ fieldLabel.addEventListener("click", () => {
33882
+ this.control.focus();
33883
+ if (this.control.localName === "input" && ["checkbox", "radio"].includes(this.control.type))
33884
+ this.control.click();
33885
+ });
32246
33886
  }
32247
33887
  projectAttributes(attrs, adapt) {
32248
33888
  const rest = super.projectAttributes(attrs, adapt);
32249
- const { lbl, lbl_position = "TL" } = this.parameters;
32250
- if (!POSITIONS.includes(lbl_position)) throw new TypeError(`Invalid lbl_position: ${lbl_position}`);
32251
- const groups = { box: {}, label: {}, labelBox: {}, controlBox: {} };
32252
- const prefixes = [["box_l_", "labelBox"], ["box_c_", "controlBox"], ["lbl_", "label"], ["box_", "box"]];
32253
- for (const [name, value] of Object.entries(rest)) {
32254
- const match = prefixes.find(([prefix]) => name.startsWith(prefix));
32255
- if (match) {
32256
- groups[match[1]][name.slice(match[0].length)] = value;
32257
- delete rest[name];
32258
- }
32259
- }
32260
- const elements = { box: this.box, label: this.fieldLabel, labelBox: this.labelBox, controlBox: this.controlBox };
32261
- for (const [name, element] of Object.entries(elements)) {
32262
- this.#previous[name] = project2(element, groups[name], adapt, this.#previous[name]);
32263
- }
32264
- if (attrs.lbl_width == null) this.box.style.removeProperty("--gramlot-label-width");
32265
- else this.box.style.setProperty("--gramlot-label-width", attrs.lbl_width);
32266
- this.box.classList.add("labelbox");
32267
- this.labelBox.classList.add("label-box");
32268
- this.controlBox.classList.add("control-box");
32269
- this.box.dataset.position = lbl_position;
32270
- this.fieldLabel.textContent = lbl ?? "";
32271
- this.labelBox.hidden = lbl == null || lbl === "";
32272
- if (this.control.localName !== "input") {
32273
- if (this.labelBox.hidden) this.control.removeAttribute("aria-labelledby");
32274
- else this.control.setAttribute("aria-labelledby", "field-label");
32275
- }
32276
- this.dispatchEvent(new this.ownerDocument.defaultView.Event("gramlot-label-layout", { bubbles: true }));
33889
+ const label = this.parameters.lbl ?? "";
33890
+ if (label) this.control.setAttribute("aria-label", label);
33891
+ else this.control.removeAttribute("aria-label");
32277
33892
  return rest;
32278
33893
  }
32279
33894
  };
32280
33895
  }
33896
+ Labelbox.labelbox = true;
32281
33897
  Labelbox.parameters = {
32282
33898
  lbl: { dtype: "T", qualification: "intl_str", nullable: true, binding: "read" },
32283
- lbl_position: { dtype: "T", default: "TL", binding: "read", enum: POSITIONS }
33899
+ lbl_position: { dtype: "T", default: "TL", binding: "read", enum: labelboxPositions }
32284
33900
  };
32285
33901
 
32286
33902
  // src/components/validation.js
@@ -32696,6 +34312,7 @@ export {
32696
34312
  ChoiceGroup,
32697
34313
  CommandRegistry,
32698
34314
  ComponentCollection,
34315
+ DeviceHandler,
32699
34316
  DirectoryResolver,
32700
34317
  DomHandler,
32701
34318
  Exposed,
@@ -32715,6 +34332,7 @@ export {
32715
34332
  IndexLogic,
32716
34333
  IndexPage,
32717
34334
  Labelbox,
34335
+ MobileEnvironment,
32718
34336
  NativeControl,
32719
34337
  NavigationResolver,
32720
34338
  Page,