@linxin666/dsh-remote-bridge 0.4.9 → 0.4.10

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 (40) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +28 -4
  3. package/README.zh.md +27 -4
  4. package/lib/client.js +511 -9
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +8671 -148
  7. package/lib/types/client/UiPresentRow.d.ts +13 -0
  8. package/lib/types/client/index.d.ts +4 -0
  9. package/lib/types/client/locales.d.ts +15 -2
  10. package/lib/types/client/toolview-slot.d.ts +68 -0
  11. package/lib/types/client/ui-card.d.ts +160 -0
  12. package/lib/types/core/connection.d.ts +38 -0
  13. package/lib/types/core/devices.d.ts +4 -0
  14. package/lib/types/core/extension.d.ts +13 -0
  15. package/lib/types/core/hub.d.ts +64 -0
  16. package/lib/types/core/protocol.d.ts +71 -7
  17. package/lib/types/core/push.d.ts +10 -2
  18. package/lib/types/core/turn-end-quiet.d.ts +135 -0
  19. package/lib/types/core/ui.d.ts +238 -0
  20. package/lib/types/host/ui-tools.d.ts +80 -0
  21. package/lib/types/host/watchers.d.ts +7 -0
  22. package/lib/types/index.d.ts +29 -1
  23. package/package.json +3 -2
  24. package/src/client/UiPresentRow.tsx +149 -0
  25. package/src/client/index.ts +11 -0
  26. package/src/client/locales.ts +22 -2
  27. package/src/client/toolview-slot.ts +84 -0
  28. package/src/client/ui-card.ts +368 -0
  29. package/src/client/ui-present.module.css +87 -0
  30. package/src/core/connection.ts +169 -6
  31. package/src/core/devices.ts +116 -2
  32. package/src/core/extension.ts +20 -0
  33. package/src/core/hub.ts +156 -1
  34. package/src/core/protocol.ts +78 -6
  35. package/src/core/push.ts +34 -3
  36. package/src/core/turn-end-quiet.ts +388 -0
  37. package/src/core/ui.ts +398 -0
  38. package/src/host/ui-tools.ts +233 -0
  39. package/src/host/watchers.ts +27 -3
  40. package/src/index.ts +70 -2
package/lib/client.js CHANGED
@@ -1226,13 +1226,13 @@ window.__ModuleLoader__.load({
1226
1226
  const PART_PANEL = "panel";
1227
1227
  //#endregion
1228
1228
  //#region \0dsh-css:packages/dsh-remote-bridge/src/client/panel.module.css.mjs
1229
- const css = ".sd7VOG_panel,.sd7VOG_trigger,.sd7VOG_dialog{--pair-space-1:4px;--pair-space-2:8px;--pair-space-3:12px;--pair-space-4:24px;--pair-title-size:15px;--pair-title-line:24px;--pair-text-size:13px;--pair-text-line:20px;--pair-state-size:12px;--pair-state-line:18px;--pair-qr:184px;--pair-bar:4px;--pair-seat:36px;--pair-close:28px;--pair-hit:44px;--pair-width:460px;--pair-faded:.35;--pair-focus-offset:2px;--pair-status:calc(var(--pair-state-line) + var(--pair-space-1) + var(--pair-bar));--pair-address:calc(var(--pair-text-line) * 2)}.sd7VOG_trigger{width:var(--pair-seat);height:var(--pair-seat);color:var(--dsw-alias-label-secondary);cursor:pointer;transition:background-color var(--ds-transition-duration) ease, color var(--ds-transition-duration) ease;background:0 0;border:none;border-radius:50%;flex:none;order:-1;justify-content:center;align-items:center;padding:0;display:inline-flex;position:relative}.sd7VOG_trigger:after{content:\"\";inset:calc((var(--pair-hit) - var(--pair-seat)) / -2);border-radius:50%;position:absolute}.sd7VOG_trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.sd7VOG_trigger:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}.sd7VOG_trigger:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:var(--pair-focus-offset)}[class*=footerActions]:has([data-dsh-plugin=remote-bridge][data-wide=rail]){align-items:center;gap:var(--pair-space-1,4px);flex-direction:column}.sd7VOG_dialog.sd7VOG_dialog{width:min(var(--pair-width), 100%);max-height:100%;padding:var(--pair-space-4);overflow:auto}.sd7VOG_panel{gap:var(--pair-space-3);box-sizing:border-box;width:100%;max-width:100%;color:var(--dsw-alias-label-primary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);transition:opacity var(--ds-transition-duration) var(--ds-ease-in-out);flex-direction:column;display:flex}.sd7VOG_panel[data-closing]{opacity:0;animation:var(--pair-exit-name,none) var(--ds-transition-duration) var(--ds-ease-in-out) reverse both}@media (prefers-reduced-motion:reduce){.sd7VOG_panel[data-closing]{animation:none}}.sd7VOG_header{align-items:flex-start;gap:var(--pair-space-3);display:flex}.sd7VOG_heading{flex:1;min-width:0}.sd7VOG_title{font-size:var(--pair-title-size);font-weight:600;line-height:var(--pair-title-line);margin:0}.sd7VOG_subtitle{margin:var(--pair-space-1) 0 0;color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line)}.sd7VOG_close{width:var(--pair-close);color:var(--dsw-alias-label-secondary);flex:none;padding:0;position:relative}.sd7VOG_close:after{content:\"\";inset:calc((var(--pair-hit) - var(--pair-close)) / -2);border-radius:50%;position:absolute}.sd7VOG_body{gap:var(--pair-space-2);flex-direction:column;display:flex}.sd7VOG_qrCard{align-items:center;gap:var(--pair-space-2);padding:var(--pair-space-3);border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1);flex-direction:column;display:flex}.sd7VOG_qrSlot{width:var(--pair-qr);height:var(--pair-qr);justify-content:center;align-items:center;display:flex}.sd7VOG_qrSlot[data-expired]{opacity:var(--pair-faded)}.sd7VOG_skeleton{width:var(--pair-qr);height:var(--pair-qr);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-interactive-bg-hover);display:block}.sd7VOG_status{justify-content:center;align-items:center;gap:var(--pair-space-1);box-sizing:border-box;width:100%;height:var(--pair-status);flex-direction:column;display:flex}.sd7VOG_statusText{color:var(--dsw-alias-label-secondary);font-size:var(--pair-state-size);line-height:var(--pair-state-line);font-variant-numeric:tabular-nums;margin:0}.sd7VOG_bar{width:100%;height:var(--pair-bar);border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-interactive-bg-hover);display:block;overflow:hidden}.sd7VOG_barFill{border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-brand-primary);height:100%;transition:width var(--ds-transition-duration) linear;display:block}.sd7VOG_address{min-height:var(--pair-address);color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);align-items:center;margin:0;display:flex}.sd7VOG_address[data-tone=warning]{color:var(--dsw-alias-state-warn-primary)}.sd7VOG_hint{color:var(--dsw-alias-label-tertiary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);margin:0}.sd7VOG_notice{align-items:flex-start;gap:var(--pair-space-2);padding:var(--pair-space-3);border:1px solid var(--dsw-alias-state-error-primary);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1);display:flex}.sd7VOG_noticeIcon{color:var(--dsw-alias-state-error-primary);flex:none;display:inline-flex}.sd7VOG_noticeCopy{min-width:0}.sd7VOG_noticeTitle{font-size:var(--pair-text-size);font-weight:600;line-height:var(--pair-text-line);margin:0}.sd7VOG_noticeText{margin:var(--pair-space-1) 0 0;color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line)}.sd7VOG_actions{justify-content:flex-end;align-items:center;gap:var(--pair-space-2);display:flex}.sd7VOG_labels{display:grid}.sd7VOG_label{grid-area:1/1}.sd7VOG_label[data-visible=false]{visibility:hidden}.sd7VOG_announce{clip:rect(0, 0, 0, 0);clip-path:inset(0);width:0;height:0;margin:0;position:absolute;overflow:hidden}";
1230
- const tagId = "@linxin666/dsh-remote-bridge/packages/dsh-remote-bridge/src/client/panel.module.css";
1231
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
1229
+ const css$1 = ".sd7VOG_panel,.sd7VOG_trigger,.sd7VOG_dialog{--pair-space-1:4px;--pair-space-2:8px;--pair-space-3:12px;--pair-space-4:24px;--pair-title-size:15px;--pair-title-line:24px;--pair-text-size:13px;--pair-text-line:20px;--pair-state-size:12px;--pair-state-line:18px;--pair-qr:184px;--pair-bar:4px;--pair-seat:36px;--pair-close:28px;--pair-hit:44px;--pair-width:460px;--pair-faded:.35;--pair-focus-offset:2px;--pair-status:calc(var(--pair-state-line) + var(--pair-space-1) + var(--pair-bar));--pair-address:calc(var(--pair-text-line) * 2)}.sd7VOG_trigger{width:var(--pair-seat);height:var(--pair-seat);color:var(--dsw-alias-label-secondary);cursor:pointer;transition:background-color var(--ds-transition-duration) ease, color var(--ds-transition-duration) ease;background:0 0;border:none;border-radius:50%;flex:none;order:-1;justify-content:center;align-items:center;padding:0;display:inline-flex;position:relative}.sd7VOG_trigger:after{content:\"\";inset:calc((var(--pair-hit) - var(--pair-seat)) / -2);border-radius:50%;position:absolute}.sd7VOG_trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.sd7VOG_trigger:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}.sd7VOG_trigger:focus-visible{outline:var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:var(--pair-focus-offset)}[class*=footerActions]:has([data-dsh-plugin=remote-bridge][data-wide=rail]){align-items:center;gap:var(--pair-space-1,4px);flex-direction:column}.sd7VOG_dialog.sd7VOG_dialog{width:min(var(--pair-width), 100%);max-height:100%;padding:var(--pair-space-4);overflow:auto}.sd7VOG_panel{gap:var(--pair-space-3);box-sizing:border-box;width:100%;max-width:100%;color:var(--dsw-alias-label-primary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);transition:opacity var(--ds-transition-duration) var(--ds-ease-in-out);flex-direction:column;display:flex}.sd7VOG_panel[data-closing]{opacity:0;animation:var(--pair-exit-name,none) var(--ds-transition-duration) var(--ds-ease-in-out) reverse both}@media (prefers-reduced-motion:reduce){.sd7VOG_panel[data-closing]{animation:none}}.sd7VOG_header{align-items:flex-start;gap:var(--pair-space-3);display:flex}.sd7VOG_heading{flex:1;min-width:0}.sd7VOG_title{font-size:var(--pair-title-size);font-weight:600;line-height:var(--pair-title-line);margin:0}.sd7VOG_subtitle{margin:var(--pair-space-1) 0 0;color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line)}.sd7VOG_close{width:var(--pair-close);color:var(--dsw-alias-label-secondary);flex:none;padding:0;position:relative}.sd7VOG_close:after{content:\"\";inset:calc((var(--pair-hit) - var(--pair-close)) / -2);border-radius:50%;position:absolute}.sd7VOG_body{gap:var(--pair-space-2);flex-direction:column;display:flex}.sd7VOG_qrCard{align-items:center;gap:var(--pair-space-2);padding:var(--pair-space-3);border:1px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-layer-1);flex-direction:column;display:flex}.sd7VOG_qrSlot{width:var(--pair-qr);height:var(--pair-qr);justify-content:center;align-items:center;display:flex}.sd7VOG_qrSlot[data-expired]{opacity:var(--pair-faded)}.sd7VOG_skeleton{width:var(--pair-qr);height:var(--pair-qr);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-interactive-bg-hover);display:block}.sd7VOG_status{justify-content:center;align-items:center;gap:var(--pair-space-1);box-sizing:border-box;width:100%;height:var(--pair-status);flex-direction:column;display:flex}.sd7VOG_statusText{color:var(--dsw-alias-label-secondary);font-size:var(--pair-state-size);line-height:var(--pair-state-line);font-variant-numeric:tabular-nums;margin:0}.sd7VOG_bar{width:100%;height:var(--pair-bar);border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-interactive-bg-hover);display:block;overflow:hidden}.sd7VOG_barFill{border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-brand-primary);height:100%;transition:width var(--ds-transition-duration) linear;display:block}.sd7VOG_address{min-height:var(--pair-address);color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);align-items:center;margin:0;display:flex}.sd7VOG_address[data-tone=warning]{color:var(--dsw-alias-state-warn-primary)}.sd7VOG_hint{color:var(--dsw-alias-label-tertiary);font-size:var(--pair-text-size);line-height:var(--pair-text-line);margin:0}.sd7VOG_notice{align-items:flex-start;gap:var(--pair-space-2);padding:var(--pair-space-3);border:1px solid var(--dsw-alias-state-error-primary);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-layer-1);display:flex}.sd7VOG_noticeIcon{color:var(--dsw-alias-state-error-primary);flex:none;display:inline-flex}.sd7VOG_noticeCopy{min-width:0}.sd7VOG_noticeTitle{font-size:var(--pair-text-size);font-weight:600;line-height:var(--pair-text-line);margin:0}.sd7VOG_noticeText{margin:var(--pair-space-1) 0 0;color:var(--dsw-alias-label-secondary);font-size:var(--pair-text-size);line-height:var(--pair-text-line)}.sd7VOG_actions{justify-content:flex-end;align-items:center;gap:var(--pair-space-2);display:flex}.sd7VOG_labels{display:grid}.sd7VOG_label{grid-area:1/1}.sd7VOG_label[data-visible=false]{visibility:hidden}.sd7VOG_announce{clip:rect(0, 0, 0, 0);clip-path:inset(0);width:0;height:0;margin:0;position:absolute;overflow:hidden}";
1230
+ const tagId$1 = "@linxin666/dsh-remote-bridge/packages/dsh-remote-bridge/src/client/panel.module.css";
1231
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
1232
1232
  const tag = document.createElement("style");
1233
1233
  tag.dataset.plugin = "@linxin666/dsh-remote-bridge";
1234
- tag.dataset.pluginCss = tagId;
1235
- tag.textContent = css;
1234
+ tag.dataset.pluginCss = tagId$1;
1235
+ tag.textContent = css$1;
1236
1236
  document.head.appendChild(tag);
1237
1237
  }
1238
1238
  var panel_module_css_default = {
@@ -1742,15 +1742,502 @@ window.__ModuleLoader__.load({
1742
1742
  };
1743
1743
  }
1744
1744
  //#endregion
1745
+ //#region src/core/ui.ts
1746
+ /** Upper bound of one card's document, in UTF-8 bytes (§35.2). */
1747
+ const UI_HTML_MAX_BYTES = 262144;
1748
+ //#endregion
1749
+ //#region src/client/ui-card.ts
1750
+ /**
1751
+ * The transcript reading of one `ui.present` call (protocol §35.10, §35.11):
1752
+ * what the desktop row draws, decided without touching the DOM.
1753
+ *
1754
+ * A card has two sources and neither may be dropped. While the call is still
1755
+ * running the arguments are the only material on the wire, so the page comes out
1756
+ * of `args` and the header says the operator has not acted yet. Once the result
1757
+ * lands, the presentation payload `meta.ui` is the card's own record — its
1758
+ * `state`, its `title` and the very document that crossed — and the arguments
1759
+ * are only the fallback for a result that carries no payload.
1760
+ *
1761
+ * The argument view is read by shape rather than by import: a toolview receives a
1762
+ * lazy `PartialArguments` when the call arrived as argument text and a plain
1763
+ * payload when the call was dispatched as an object, and §35.10 fixes neither. A
1764
+ * field reader therefore answers from all three shapes it can meet (lazy view,
1765
+ * JSON text, parsed object) so a page is never lost to a shape this row did not
1766
+ * anticipate.
1767
+ *
1768
+ * Two rules live here rather than in the renderer. A document above 256 KiB is
1769
+ * never handed to a frame (§35.2 caps it on this side too), and a frame message is
1770
+ * read by shape alone: the sandboxed document has an opaque origin, so identity
1771
+ * comes from the frame element the row owns, never from what the message claims.
1772
+ * Nothing read here is forwarded anywhere — the desktop renders and does not
1773
+ * answer (§35.11).
1774
+ * @module dsh-remote-bridge/client/ui-card
1775
+ */
1776
+ /**
1777
+ * The theme tokens a card inherits from the GUI's own root element.
1778
+ *
1779
+ * Four roles and no more: the page needs a text colour it can trust, a quieter
1780
+ * one, a surface and a border. A token the running theme does not define is
1781
+ * simply not injected — the page then falls back to its own CSS, which is why an
1782
+ * unreadable theme is a degraded look rather than a broken card.
1783
+ */
1784
+ const CARD_THEME_TOKENS = [
1785
+ "--dsw-alias-label-primary",
1786
+ "--dsw-alias-label-secondary",
1787
+ "--dsw-alias-bg-layer-1",
1788
+ "--dsw-alias-border-l2"
1789
+ ];
1790
+ /** The one sandbox value a card frame is allowed (§35.7, §35.11). */
1791
+ const FRAME_SANDBOX = "allow-scripts";
1792
+ /**
1793
+ * The permissions a card frame is explicitly denied.
1794
+ *
1795
+ * §35.7 refuses camera, microphone, location and clipboard reads on both ends.
1796
+ * A sandboxed document already has an opaque origin, and this policy states the
1797
+ * denial where the browser enforces it rather than leaving it to the default.
1798
+ */
1799
+ const FRAME_PERMISSIONS = [
1800
+ "camera 'none'",
1801
+ "microphone 'none'",
1802
+ "geolocation 'none'",
1803
+ "clipboard-read 'none'"
1804
+ ].join("; ");
1805
+ /** The message type the injected reporter uses to publish the content height. */
1806
+ const FRAME_HEIGHT_CHANNEL = "dsh-ui-card-height";
1807
+ /**
1808
+ * Read one field as text out of every argument shape a toolview can receive.
1809
+ * @param args - the lazy view, finished JSON text, or a parsed payload.
1810
+ * @param name - the top-level field name.
1811
+ * @returns the field's decoded string, or undefined when absent or not a string.
1812
+ */
1813
+ function fieldText(args, name) {
1814
+ if (typeof args === "string") {
1815
+ const parsed = parseJson(args);
1816
+ return parsed === void 0 ? void 0 : fieldText(parsed, name);
1817
+ }
1818
+ if (typeof args !== "object" || args === null) return void 0;
1819
+ const view = args;
1820
+ if (typeof view.text === "function") {
1821
+ const read = view.text.call(args, name);
1822
+ return typeof read === "string" ? read : void 0;
1823
+ }
1824
+ const direct = view[name];
1825
+ return typeof direct === "string" ? direct : void 0;
1826
+ }
1827
+ /**
1828
+ * Read one field as any completed value out of the same three shapes.
1829
+ * @param args - the lazy view, finished JSON text, or a parsed payload.
1830
+ * @param name - the top-level field name.
1831
+ * @returns the value, or undefined when absent.
1832
+ */
1833
+ function fieldValue(args, name) {
1834
+ if (typeof args === "string") {
1835
+ const parsed = parseJson(args);
1836
+ return parsed === void 0 ? void 0 : fieldValue(parsed, name);
1837
+ }
1838
+ if (typeof args !== "object" || args === null) return void 0;
1839
+ const view = args;
1840
+ if (typeof view.value === "function") return view.value.call(args, name);
1841
+ return view[name];
1842
+ }
1843
+ /** @returns the parsed payload, or undefined when the text is not one object. */
1844
+ function parseJson(text) {
1845
+ try {
1846
+ return JSON.parse(text);
1847
+ } catch {
1848
+ return;
1849
+ }
1850
+ }
1851
+ /** @returns one suggested height as a whole number of CSS pixels, when usable. */
1852
+ function heightOf(raw) {
1853
+ if (typeof raw !== "number" || !Number.isFinite(raw) || raw <= 0) return void 0;
1854
+ return Math.ceil(raw);
1855
+ }
1856
+ /**
1857
+ * Read the presentation payload a settled call carries (§35.10).
1858
+ *
1859
+ * The payload is the card's own record, so it is read only when it is one: a
1860
+ * `html` that is not a string is no card at all, which keeps a malformed payload
1861
+ * from becoming an empty frame. `state` outside the frozen pair reads as
1862
+ * `settled` — a result-phase payload is a finished card by definition, and the
1863
+ * `open` arm exists for a presenter that answers before its first event.
1864
+ * @param meta - the result's `meta` value, carried verbatim.
1865
+ * @returns the card, or undefined when this result carries no presentation.
1866
+ */
1867
+ function readPresentation(meta) {
1868
+ if (typeof meta !== "object" || meta === null) return void 0;
1869
+ const ui = meta.ui;
1870
+ if (typeof ui !== "object" || ui === null) return void 0;
1871
+ const record = ui;
1872
+ const html = record.html;
1873
+ if (typeof html !== "string") return void 0;
1874
+ const title = record.title;
1875
+ const key = record.key;
1876
+ const height = heightOf(record.height);
1877
+ return {
1878
+ html,
1879
+ state: record.state === "open" ? "open" : "settled",
1880
+ ...typeof title === "string" ? { title } : {},
1881
+ ...height === void 0 ? {} : { height },
1882
+ ...typeof key === "string" ? { key } : {}
1883
+ };
1884
+ }
1885
+ /**
1886
+ * Build the card a running call shows from its own arguments.
1887
+ * @param block - the call material of the current stage.
1888
+ * @returns the card, or undefined when the arguments carry no page.
1889
+ */
1890
+ function argumentCard(block) {
1891
+ const html = fieldText(block.args, "html") ?? fieldText(block.argsRaw, "html");
1892
+ if (html === void 0) return void 0;
1893
+ const title = fieldText(block.args, "title") ?? fieldText(block.argsRaw, "title");
1894
+ const height = heightOf(fieldValue(block.args, "height") ?? fieldValue(block.argsRaw, "height"));
1895
+ return {
1896
+ html,
1897
+ state: "open",
1898
+ ...title === void 0 ? {} : { title },
1899
+ ...height === void 0 ? {} : { height }
1900
+ };
1901
+ }
1902
+ /** @returns whether one document is within {@link UI_HTML_MAX_BYTES}. */
1903
+ function cardHtmlFits(html) {
1904
+ return new TextEncoder().encode(html).length <= UI_HTML_MAX_BYTES;
1905
+ }
1906
+ /**
1907
+ * Decide what the row draws at one stage of the call.
1908
+ *
1909
+ * The settled stage prefers `meta.ui`, because that payload is the presentation
1910
+ * the host published and carries its ending. A result without the payload falls
1911
+ * back to the arguments — and then the card is still over, so it reads
1912
+ * `settled`: the stage decides that, not a field that is absent.
1913
+ * @param phase - the stage the Tool slot published.
1914
+ * @param block - the call material of that stage.
1915
+ * @returns a card, a refusal, or the neutral line.
1916
+ */
1917
+ function presentReadOf(phase, block) {
1918
+ if (typeof block !== "object" || block === null) return { kind: "empty" };
1919
+ const material = block;
1920
+ const card = phase === "result" ? readPresentation(material.meta) ?? settledFromArguments(material) : argumentCard(material);
1921
+ if (card === void 0) return { kind: "empty" };
1922
+ return cardHtmlFits(card.html) ? {
1923
+ kind: "card",
1924
+ card
1925
+ } : { kind: "oversize" };
1926
+ }
1927
+ /** @returns the argument page of a settled call, as a finished card. */
1928
+ function settledFromArguments(material) {
1929
+ const card = argumentCard(material);
1930
+ return card === void 0 ? void 0 : {
1931
+ ...card,
1932
+ state: "settled"
1933
+ };
1934
+ }
1935
+ /**
1936
+ * Read the theme tokens off a computed style, skipping the ones it does not carry.
1937
+ * @param style - the GUI root element's computed style.
1938
+ * @returns the tokens, in {@link CARD_THEME_TOKENS} order.
1939
+ */
1940
+ function cardThemeTokens(style) {
1941
+ const tokens = [];
1942
+ for (const name of CARD_THEME_TOKENS) {
1943
+ let value = "";
1944
+ try {
1945
+ value = style.getPropertyValue(name);
1946
+ } catch {
1947
+ value = "";
1948
+ }
1949
+ const trimmed = value.trim();
1950
+ if (trimmed !== "") tokens.push([name, trimmed]);
1951
+ }
1952
+ return tokens;
1953
+ }
1954
+ /** @returns the `<style>` handing the theme tokens to a card's document. */
1955
+ function themeStyle(tokens) {
1956
+ if (tokens.length === 0) return "";
1957
+ return `<style data-dsh-card-theme>:root{${tokens.map(([name, value]) => `${name}:${value}`).join(";")}}</style>`;
1958
+ }
1959
+ /**
1960
+ * The reporter a card's document runs to publish its own content height.
1961
+ *
1962
+ * The frame cannot be measured from the outside — the document is opaque and
1963
+ * cross-origin — so the measurement has to be pushed out. It is deliberately the
1964
+ * only code this row adds to a page: it reads a height and posts a number, and a
1965
+ * page that removes it only loses the measurement, never the card.
1966
+ * @param channel - the message type the parent listens for.
1967
+ * @returns one script element as text.
1968
+ */
1969
+ function heightReporter(channel) {
1970
+ return [
1971
+ "<script data-dsh-card-frame>(function(){",
1972
+ "function post(){try{",
1973
+ "var d=document.documentElement,b=document.body;",
1974
+ "var h=Math.max(d?d.scrollHeight:0,b?b.scrollHeight:0);",
1975
+ "if(h>0){parent.postMessage({type:" + JSON.stringify(channel) + ",height:h},\"*\")}",
1976
+ "}catch(e){}}",
1977
+ "window.addEventListener(\"load\",post);",
1978
+ "document.addEventListener(\"DOMContentLoaded\",post);",
1979
+ "try{if(typeof ResizeObserver===\"function\"){var ro=new ResizeObserver(post);",
1980
+ "if(document.documentElement)ro.observe(document.documentElement);",
1981
+ "if(document.body)ro.observe(document.body)}}catch(e){}",
1982
+ "post()})()<\/script>"
1983
+ ].join("");
1984
+ }
1985
+ /**
1986
+ * Put one snippet inside an existing element rather than before the document.
1987
+ * @param html - the card document.
1988
+ * @param closingTag - the tag to insert ahead of, lower case.
1989
+ * @param snippet - the markup to insert.
1990
+ * @returns the document with the snippet inside it.
1991
+ */
1992
+ function injectBefore(html, closingTag, snippet) {
1993
+ if (snippet === "") return html;
1994
+ const at = html.toLowerCase().lastIndexOf(closingTag);
1995
+ return at < 0 ? html + snippet : html.slice(0, at) + snippet + html.slice(at);
1996
+ }
1997
+ /**
1998
+ * Build the document handed to a card's frame.
1999
+ *
2000
+ * The agent's page stays byte for byte what crossed; this only adds the theme
2001
+ * variables its CSS may use and the height reporter. Insertion happens ahead of
2002
+ * the closing tags rather than at the start of the string, because a snippet
2003
+ * placed before `<!doctype html>` would put the document into quirks mode.
2004
+ * @param html - the card document as the presenter wrote it.
2005
+ * @param tokens - the theme tokens to hand the page.
2006
+ * @param channel - the message type the reporter publishes on.
2007
+ * @returns the frame document; the original page when it takes no injection.
2008
+ */
2009
+ function frameDocument(html, tokens, channel = FRAME_HEIGHT_CHANNEL) {
2010
+ const style = themeStyle(tokens);
2011
+ return injectBefore(style === "" ? html : injectBefore(html, "</head>", style), "</body>", heightReporter(channel));
2012
+ }
2013
+ /**
2014
+ * Read one message a card's frame posted.
2015
+ *
2016
+ * Only the shape is read. The frame's origin is opaque, so the parent identifies
2017
+ * the sender by the frame element it owns; what is left to decide here is what
2018
+ * the payload means, and a page's own `{type, payload}` action means nothing
2019
+ * beyond "the operator tried to act here".
2020
+ * @param data - the message payload.
2021
+ * @returns the event, or undefined when the message is not one this row reads.
2022
+ */
2023
+ function frameEventOf(data) {
2024
+ if (typeof data !== "object" || data === null || Array.isArray(data)) return void 0;
2025
+ const record = data;
2026
+ if (record.type === "dsh-ui-card-height") {
2027
+ const height = record.height;
2028
+ if (typeof height !== "number" || !Number.isFinite(height) || height <= 0) return void 0;
2029
+ return {
2030
+ kind: "height",
2031
+ height: Math.ceil(height)
2032
+ };
2033
+ }
2034
+ return typeof record.type === "string" && record.type !== "" ? { kind: "interaction" } : void 0;
2035
+ }
2036
+ /**
2037
+ * Hold a measured height inside the range a card may occupy.
2038
+ * @param height - the content height the frame reported, in CSS pixels.
2039
+ * @returns the height the card takes.
2040
+ */
2041
+ function clampCardHeight(height) {
2042
+ if (!Number.isFinite(height)) return 320;
2043
+ return Math.min(720, Math.max(96, Math.ceil(height)));
2044
+ }
2045
+ //#endregion
2046
+ //#region \0dsh-css:packages/dsh-remote-bridge/src/client/ui-present.module.css.mjs
2047
+ const css = ".g4_deW_card,.g4_deW_row{--card-space-1:4px;--card-space-2:8px;--card-space-3:12px;--card-title-size:13px;--card-title-line:20px;--card-state-size:12px;--card-state-line:18px;--card-radius:8px;--card-edge:1px;--card-default-height:320px}.g4_deW_card{margin:var(--card-space-1) 0;border:var(--card-edge) solid var(--dsw-alias-border-l2);border-radius:var(--card-radius);background:var(--dsw-alias-bg-layer-1);flex-direction:column;gap:0;display:flex;overflow:hidden}.g4_deW_head{align-items:center;gap:var(--card-space-2);min-height:calc(var(--card-title-line) + var(--card-space-2) * 2);padding:var(--card-space-2) var(--card-space-3);border-bottom:var(--card-edge) solid var(--dsw-alias-border-l2);display:flex}.g4_deW_title{min-width:0;color:var(--dsw-alias-label-primary);font-size:var(--card-title-size);line-height:var(--card-title-line);text-overflow:ellipsis;white-space:nowrap;flex:auto;overflow:hidden}.g4_deW_badge{color:var(--dsw-alias-label-secondary);font-size:var(--card-state-size);line-height:var(--card-state-line);flex:none;margin-inline-start:auto}.g4_deW_frame{width:100%;min-height:var(--card-default-height);background:0 0;border:0;display:block}.g4_deW_notice{padding:var(--card-space-2) var(--card-space-3);border-top:var(--card-edge) solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);font-size:var(--card-state-size);line-height:var(--card-state-line);margin:0}.g4_deW_row{margin:var(--card-space-1) 0}";
2048
+ const tagId = "@linxin666/dsh-remote-bridge/packages/dsh-remote-bridge/src/client/ui-present.module.css";
2049
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
2050
+ const tag = document.createElement("style");
2051
+ tag.dataset.plugin = "@linxin666/dsh-remote-bridge";
2052
+ tag.dataset.pluginCss = tagId;
2053
+ tag.textContent = css;
2054
+ document.head.appendChild(tag);
2055
+ }
2056
+ var ui_present_module_css_default = {
2057
+ "badge": "g4_deW_badge",
2058
+ "card": "g4_deW_card",
2059
+ "frame": "g4_deW_frame",
2060
+ "head": "g4_deW_head",
2061
+ "notice": "g4_deW_notice",
2062
+ "row": "g4_deW_row",
2063
+ "title": "g4_deW_title"
2064
+ };
2065
+ //#endregion
2066
+ //#region src/client/UiPresentRow.tsx
2067
+ /**
2068
+ * The transcript row of one `ui.present` call: the whole page an agent handed
2069
+ * into the session, drawn in a controlled frame (protocol §35.11).
2070
+ *
2071
+ * The row renders and does not answer. The frame carries `srcdoc` and the one
2072
+ * sandbox value §35.7 allows — never `allow-same-origin`, which is what turns a
2073
+ * sandboxed document back into a same-origin one and would hand an agent page the
2074
+ * GUI's own storage and cookies. There is no host request on any path here: an
2075
+ * action the page posts arrives as one visible sentence telling the operator to
2076
+ * answer on the phone, and nothing is forwarded, stored or sent.
2077
+ *
2078
+ * Height is measured from the inside because the frame is opaque from the
2079
+ * outside: the injected reporter posts the document's own content height, the
2080
+ * presenter's suggested `height` carries the first frame, and the measurement
2081
+ * replaces it as soon as one arrives. The theme is handed in as variables read
2082
+ * off the GUI root, so a card follows the running theme without importing one;
2083
+ * a theme that cannot be read costs the injected variables, never the card.
2084
+ */
2085
+ /** @returns the GUI root's theme tokens, or none when the theme cannot be read. */
2086
+ function readThemeTokens() {
2087
+ try {
2088
+ return cardThemeTokens(getComputedStyle(document.documentElement));
2089
+ } catch {
2090
+ return [];
2091
+ }
2092
+ }
2093
+ /**
2094
+ * Render one card, or the neutral line of a call that carries no page.
2095
+ * @param props - the stage, the call material and the locale seat.
2096
+ * @returns the card body placed inside the official tool row.
2097
+ */
2098
+ function UiPresentRow({ phase, block, t }) {
2099
+ const read = (0, react.useMemo)(() => presentReadOf(phase, block), [phase, block]);
2100
+ const card = read.kind === "card" ? read.card : void 0;
2101
+ const frame = (0, react.useRef)(null);
2102
+ const [tokens, setTokens] = (0, react.useState)(readThemeTokens);
2103
+ const [measured, setMeasured] = (0, react.useState)(void 0);
2104
+ const [interacted, setInteracted] = (0, react.useState)(false);
2105
+ (0, react.useEffect)(() => {
2106
+ let media;
2107
+ try {
2108
+ media = window.matchMedia("(prefers-color-scheme: dark)");
2109
+ } catch {
2110
+ return;
2111
+ }
2112
+ const sync = () => {
2113
+ setTokens(readThemeTokens());
2114
+ };
2115
+ if (typeof media.addEventListener === "function") {
2116
+ media.addEventListener("change", sync);
2117
+ return () => {
2118
+ media.removeEventListener("change", sync);
2119
+ };
2120
+ }
2121
+ media.addListener(sync);
2122
+ return () => {
2123
+ media.removeListener(sync);
2124
+ };
2125
+ }, []);
2126
+ const html = card?.html;
2127
+ (0, react.useEffect)(() => {
2128
+ setMeasured(void 0);
2129
+ setInteracted(false);
2130
+ }, [html]);
2131
+ (0, react.useEffect)(() => {
2132
+ const onMessage = (event) => {
2133
+ const element = frame.current;
2134
+ if (element === null || element.contentWindow === null || event.source !== element.contentWindow) return;
2135
+ const frameEvent = frameEventOf(event.data);
2136
+ if (frameEvent === void 0) return;
2137
+ if (frameEvent.kind === "height") {
2138
+ setMeasured(clampCardHeight(frameEvent.height));
2139
+ return;
2140
+ }
2141
+ setInteracted(true);
2142
+ };
2143
+ window.addEventListener("message", onMessage);
2144
+ return () => {
2145
+ window.removeEventListener("message", onMessage);
2146
+ };
2147
+ }, []);
2148
+ const srcdoc = (0, react.useMemo)(() => card === void 0 ? "" : frameDocument(card.html, tokens, FRAME_HEIGHT_CHANNEL), [card, tokens]);
2149
+ if (card === void 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2150
+ className: ui_present_module_css_default.row,
2151
+ "data-dsh-plugin": PLUGIN_ATTR,
2152
+ "data-tone": read.kind,
2153
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2154
+ className: ui_present_module_css_default.notice,
2155
+ role: "status",
2156
+ children: read.kind === "oversize" ? t("card.oversize") : t("card.empty")
2157
+ })
2158
+ });
2159
+ const height = measured ?? clampCardHeight(card.height ?? 320);
2160
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
2161
+ className: ui_present_module_css_default.card,
2162
+ "data-dsh-plugin": PLUGIN_ATTR,
2163
+ "data-state": card.state,
2164
+ children: [
2165
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
2166
+ className: ui_present_module_css_default.head,
2167
+ children: [card.title !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2168
+ className: ui_present_module_css_default.title,
2169
+ children: card.title
2170
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2171
+ className: ui_present_module_css_default.badge,
2172
+ children: card.state === "open" ? t("card.waiting") : t("card.settled")
2173
+ })]
2174
+ }),
2175
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", {
2176
+ ref: frame,
2177
+ className: ui_present_module_css_default.frame,
2178
+ style: { height: `${height}px` },
2179
+ title: card.title ?? t("card.frameLabel"),
2180
+ srcDoc: srcdoc,
2181
+ sandbox: FRAME_SANDBOX,
2182
+ allow: FRAME_PERMISSIONS,
2183
+ referrerPolicy: "no-referrer"
2184
+ }),
2185
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2186
+ className: ui_present_module_css_default.notice,
2187
+ role: "status",
2188
+ children: interacted ? t("card.interacted") : t("card.answerOnPhone")
2189
+ })
2190
+ ]
2191
+ });
2192
+ }
2193
+ //#endregion
2194
+ //#region src/client/toolview-slot.ts
2195
+ /** The keyed Tool view slot the official row dispatches into. */
2196
+ const TOOLVIEW_SLOT = "tool.call.toolview";
2197
+ /** The wire Tool name this package renders: the keyed cell it claims. */
2198
+ const PRESENT_TOOL = "ui.present";
2199
+ /**
2200
+ * Contribute the `ui.present` card into the Tool row.
2201
+ *
2202
+ * The contribution is declaration-aware: `inject` waits for the official slot
2203
+ * declaration, so a GUI composed without a Tool layer has no keyed cell and thus
2204
+ * no card — that is the capability being absent, not an error to report. A
2205
+ * registration refused by the registry (an occupied cell at the same priority)
2206
+ * is swallowed the same way it is for this package's other seat, so one occupied
2207
+ * slot never takes the sidebar entry down with it.
2208
+ * @param host - the client Context.
2209
+ * @param locale - the dictionary namespace this package registered.
2210
+ */
2211
+ function registerPresentToolview(host, locale) {
2212
+ const slots = host.slots;
2213
+ slots.inject(TOOLVIEW_SLOT, () => {
2214
+ try {
2215
+ return slots.register({
2216
+ name: TOOLVIEW_SLOT,
2217
+ key: PRESENT_TOOL,
2218
+ locale
2219
+ }, UiPresentRow);
2220
+ } catch {
2221
+ return () => {};
2222
+ }
2223
+ });
2224
+ }
2225
+ //#endregion
1745
2226
  //#region src/client/locales.ts
1746
2227
  /**
1747
- * `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy.
2228
+ * `remote-bridge` namespace dictionaries: the protocol v1 pairing panel copy and
2229
+ * the header of an interactive card (§35.11).
1748
2230
  *
1749
2231
  * The panel has one job — put the live one-shot code in front of the operator as
1750
- * a QR symbol — so the copy carries exactly four things: what to do with the
2232
+ * a QR symbol — so its copy carries exactly four things: what to do with the
1751
2233
  * symbol, how long it lives, which address the phone will actually dial, and why
1752
2234
  * the code is single-use. No key states how the host finds its public address:
1753
2235
  * that is an implementation fact the reader cannot act on.
2236
+ *
2237
+ * The card's keys say only what the transcript row can act on: whether the page
2238
+ * is still waiting for the operator, that it is over, that this desktop renders
2239
+ * without answering, and that a page carrying nothing or too much draws a
2240
+ * sentence instead of a frame.
1754
2241
  */
1755
2242
  /** Simplified Chinese dictionary (the key-set source of truth). */
1756
2243
  const zh = {
@@ -1775,7 +2262,14 @@ window.__ModuleLoader__.load({
1775
2262
  "action.copy": "复制配对码",
1776
2263
  "action.copied": "已复制",
1777
2264
  "action.copyFailed": "复制失败",
1778
- "action.retry": "重试"
2265
+ "action.retry": "重试",
2266
+ "card.waiting": "等你操作",
2267
+ "card.settled": "已结算",
2268
+ "card.answerOnPhone": "在手机上作答",
2269
+ "card.interacted": "已收到页面上的操作,但桌面端不作答:在手机上作答",
2270
+ "card.frameLabel": "整页卡片",
2271
+ "card.empty": "这次调用没有可渲染的页面",
2272
+ "card.oversize": "页面超出大小上限,未渲染"
1779
2273
  };
1780
2274
  /** English dictionary, key-for-key with the zh source. */
1781
2275
  const en = {
@@ -1800,7 +2294,14 @@ window.__ModuleLoader__.load({
1800
2294
  "action.copy": "Copy pairing code",
1801
2295
  "action.copied": "Copied",
1802
2296
  "action.copyFailed": "Copy failed",
1803
- "action.retry": "Retry"
2297
+ "action.retry": "Retry",
2298
+ "card.waiting": "Waiting for you",
2299
+ "card.settled": "Settled",
2300
+ "card.answerOnPhone": "Answer on the phone",
2301
+ "card.interacted": "The page sent an action, but this desktop does not answer: answer on the phone",
2302
+ "card.frameLabel": "Page card",
2303
+ "card.empty": "This call carried no page to render",
2304
+ "card.oversize": "The page is over the size limit and was not rendered"
1804
2305
  };
1805
2306
  //#endregion
1806
2307
  //#region src/client/index.ts
@@ -1840,6 +2341,7 @@ window.__ModuleLoader__.load({
1840
2341
  return () => {};
1841
2342
  }
1842
2343
  });
2344
+ registerPresentToolview(ctx, NS);
1843
2345
  }
1844
2346
  //#endregion
1845
2347
  exports.apply = apply;