@openartifactsai/cli 0.23.0-rc.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/SKILL.md +7 -2
  2. package/package.json +1 -1
  3. package/vendor/CHANGELOG.md +1082 -0
  4. package/vendor/artifact-types/page/SKILL.md +3 -1
  5. package/vendor/artifact-types/page/artifact-type/reference/capabilities.d.ts +0 -1
  6. package/vendor/artifact-types/page/artifact-type/reference/capabilities.md +1 -1
  7. package/vendor/frame-host/client/comments.js +20 -19
  8. package/vendor/frame-host/client/page.js +1352 -0
  9. package/vendor/frame-host/client/review.js +279 -0
  10. package/vendor/frame-host/client/runtime.js +8 -6
  11. package/vendor/frame-host/client/sample.js +1 -1
  12. package/vendor/frame-host/client/shell.css +1 -0
  13. package/vendor/frame-host/client/shell.js +206 -6
  14. package/vendor/frame-host/client/translate.js +375 -0
  15. package/vendor/frame-host/frame-host.mjs +267 -82
  16. package/vendor/home/assets/{browser-models-DWkPVHmp.js → browser-models-Ceon9UIN.js} +4 -4
  17. package/vendor/home/assets/library-RBaguEV9.js +397 -0
  18. package/vendor/home/assets/main-BKHYngAm.js +2 -0
  19. package/vendor/home/assets/main-Cw3mY0u9.css +1 -0
  20. package/vendor/home/assets/node.browser-BFrmG6rb.js +1 -0
  21. package/vendor/home/assets/node.browser-CPQVYRMD.js +1 -0
  22. package/vendor/home/assets/react-DQymU5Da.js +47 -0
  23. package/vendor/home/index.html +3 -3
  24. package/vendor/home/library/index.html +2 -2
  25. package/vendor/open-artifacts.mjs +2516 -1072
  26. package/vendor/runtime.json +1 -1
  27. package/vendor/shell/assets/{browser-models-BzwWAVuE.js → browser-models-CiXqE7b9.js} +4 -4
  28. package/vendor/shell/assets/index-BhxD6amu.js +53 -0
  29. package/vendor/shell/assets/index-Cw3mY0u9.css +1 -0
  30. package/vendor/shell/assets/{node.browser-BgqLTfql.js → node.browser-ByUkO9oN.js} +1 -1
  31. package/vendor/shell/assets/{node.browser-BvryIsl7.js → node.browser-CSEwiusG.js} +1 -1
  32. package/vendor/shell/index.html +2 -2
  33. package/vendor/type-server/cli.mjs +362 -197
  34. package/vendor/type-server/editors/data/assets/{index-CX_sn7ZZ.js → index-B0E35R1E.js} +5 -4
  35. package/vendor/type-server/editors/data/index.html +1 -1
  36. package/vendor/type-server/editors/design/assets/{index-BpNUmTVD.js → index-BOc3kd6N.js} +78 -77
  37. package/vendor/type-server/editors/design/index.html +1 -1
  38. package/vendor/type-server/editors/design-system/assets/{index-CP6AEO1P.js → index-B7MtPrtk.js} +5 -4
  39. package/vendor/type-server/editors/design-system/index.html +1 -1
  40. package/vendor/type-server/editors/docs/assets/{abnfDiagram-WEYOIA3C-Do25i7oS.js → abnfDiagram-WEYOIA3C-DcfGbMC9.js} +1 -1
  41. package/vendor/type-server/editors/docs/assets/{architectureDiagram-ZHVYKT53-BLlpboc2.js → architectureDiagram-ZHVYKT53-CfcGFZjM.js} +1 -1
  42. package/vendor/type-server/editors/docs/assets/{blockDiagram-RJAE7QA3-D0rO5p7M.js → blockDiagram-RJAE7QA3-C5s3aXD2.js} +1 -1
  43. package/vendor/type-server/editors/docs/assets/{c4Diagram-XDPPPE54-OoTiysJI.js → c4Diagram-XDPPPE54-BJgchX97.js} +1 -1
  44. package/vendor/type-server/editors/docs/assets/channel-B2TtMfsN.js +1 -0
  45. package/vendor/type-server/editors/docs/assets/{chunk-2E7WHVMD-yBl5BEaI.js → chunk-2E7WHVMD-BgQ4xapY.js} +1 -1
  46. package/vendor/type-server/editors/docs/assets/{chunk-2Q5K7J3B-DHKM5gd6.js → chunk-2Q5K7J3B-B1ktgQTo.js} +1 -1
  47. package/vendor/type-server/editors/docs/assets/{chunk-4EMNKR2T-B-f8WPM6.js → chunk-4EMNKR2T-Co-2oGfa.js} +1 -1
  48. package/vendor/type-server/editors/docs/assets/{chunk-55XCU76K-n8RDJr36.js → chunk-55XCU76K-BqpDaZgl.js} +1 -1
  49. package/vendor/type-server/editors/docs/assets/{chunk-5VM5RSS4-DzLzcqXE.js → chunk-5VM5RSS4-BJPvauTV.js} +1 -1
  50. package/vendor/type-server/editors/docs/assets/{chunk-JWPE2WC7-BLXkUVcK.js → chunk-JWPE2WC7-NCBAl-SW.js} +1 -1
  51. package/vendor/type-server/editors/docs/assets/{chunk-VQ5W62QI-DAGNVD29.js → chunk-VQ5W62QI-DPzloG3R.js} +1 -1
  52. package/vendor/type-server/editors/docs/assets/{chunk-XXDRQBXY-fgVyAbWV.js → chunk-XXDRQBXY-D08KAfXl.js} +1 -1
  53. package/vendor/type-server/editors/docs/assets/{chunk-ZCHMQSOR-D90xHR9n.js → chunk-ZCHMQSOR-CLWESu07.js} +2 -2
  54. package/vendor/type-server/editors/docs/assets/{classDiagram-v2-4MYWR3UA-uk1mPogR.js → classDiagram-v2-4MYWR3UA-BSPsabsn.js} +1 -1
  55. package/vendor/type-server/editors/docs/assets/{core-BMv5rGOd.js → core-Cqu2ilBr.js} +1 -1
  56. package/vendor/type-server/editors/docs/assets/{cose-bilkent-JH36ORCC-BJdqW8l3.js → cose-bilkent-JH36ORCC-D6at9M78.js} +1 -1
  57. package/vendor/type-server/editors/docs/assets/{cynefin-EF2NZ3EQ-BCce_ZhK.js → cynefin-EF2NZ3EQ-BTylb97F.js} +1 -1
  58. package/vendor/type-server/editors/docs/assets/{cynefinDiagram-WF24UDRP-DxD-4yjR.js → cynefinDiagram-WF24UDRP-Din3pKvL.js} +1 -1
  59. package/vendor/type-server/editors/docs/assets/{dagre-NK4GIZVX-B3VAS51Y.js → dagre-NK4GIZVX-5qfRwQnt.js} +1 -1
  60. package/vendor/type-server/editors/docs/assets/{diagram-CBK3MWTC-B0kHeUdr.js → diagram-CBK3MWTC-BnrAjIhJ.js} +1 -1
  61. package/vendor/type-server/editors/docs/assets/{diagram-I5XIIV2D-BCRvsLAu.js → diagram-I5XIIV2D-CH_xkoKv.js} +1 -1
  62. package/vendor/type-server/editors/docs/assets/{diagram-ODIL2UCW-DFOTsSuA.js → diagram-ODIL2UCW-D5dns2KC.js} +1 -1
  63. package/vendor/type-server/editors/docs/assets/{diagram-PFBEJUXE-_DT3jk0i.js → diagram-PFBEJUXE-D-3cnWXB.js} +1 -1
  64. package/vendor/type-server/editors/docs/assets/{diagram-RJA3I4VV-UFrdnTgs.js → diagram-RJA3I4VV-DImejfKM.js} +1 -1
  65. package/vendor/type-server/editors/docs/assets/{diagram-TYUNFSNR-DrbWyZOX.js → diagram-TYUNFSNR-DscxSG0M.js} +1 -1
  66. package/vendor/type-server/editors/docs/assets/{ebnfDiagram-V4P3TTPT-M-DCWgZM.js → ebnfDiagram-V4P3TTPT-C4wwb0NC.js} +1 -1
  67. package/vendor/type-server/editors/docs/assets/{elk-QONTBCTQ-l6XmbRQj.js → elk-QONTBCTQ-O05tgWzI.js} +1 -1
  68. package/vendor/type-server/editors/docs/assets/{erDiagram-KYQIGQAA-CHqbnmEE.js → erDiagram-KYQIGQAA-D171V8gY.js} +1 -1
  69. package/vendor/type-server/editors/docs/assets/{flowDiagram-IUGLLWBU-BzkFyGCL.js → flowDiagram-IUGLLWBU-DcvtJsgJ.js} +1 -1
  70. package/vendor/type-server/editors/docs/assets/{ganttDiagram-R7GPNTJY-BcNaSXNv.js → ganttDiagram-R7GPNTJY-DcuQ9a5m.js} +1 -1
  71. package/vendor/type-server/editors/docs/assets/{gitGraphDiagram-PDYL7XHY-JaNdSZbv.js → gitGraphDiagram-PDYL7XHY-iQoh6Yen.js} +1 -1
  72. package/vendor/type-server/editors/docs/assets/{index-BMNUnwXE.js → index-BNk_Jpgl.js} +49 -48
  73. package/vendor/type-server/editors/docs/assets/{infoDiagram-MVDRKAX5-Cl2Q_Ylf.js → infoDiagram-MVDRKAX5-DECkmgI6.js} +1 -1
  74. package/vendor/type-server/editors/docs/assets/{ishikawaDiagram-HPEHV2GE-umirqIpN.js → ishikawaDiagram-HPEHV2GE-CK0mATvD.js} +1 -1
  75. package/vendor/type-server/editors/docs/assets/{journeyDiagram-BOSHW7O7-HMtvkXvq.js → journeyDiagram-BOSHW7O7-Dz1u7rfA.js} +1 -1
  76. package/vendor/type-server/editors/docs/assets/{kanban-definition-FNSA4HC5-CYouTBUM.js → kanban-definition-FNSA4HC5-B1-0Mp0R.js} +1 -1
  77. package/vendor/type-server/editors/docs/assets/{mermaid.core-BEcbgpI8.js → mermaid.core-DhXbeevr.js} +4 -4
  78. package/vendor/type-server/editors/docs/assets/{mindmap-definition-6OY57UG3-BnwugHtV.js → mindmap-definition-6OY57UG3-Czy5C8sa.js} +1 -1
  79. package/vendor/type-server/editors/docs/assets/{pegDiagram-ECIUJNBX-DqT6jxo7.js → pegDiagram-ECIUJNBX-C97juwaO.js} +1 -1
  80. package/vendor/type-server/editors/docs/assets/{pieDiagram-GNMPY74T-CBKjnr1W.js → pieDiagram-GNMPY74T-rrh7flvh.js} +1 -1
  81. package/vendor/type-server/editors/docs/assets/{quadrantDiagram-D57K4MC3-CdTG11Ff.js → quadrantDiagram-D57K4MC3-D3xBy1ZX.js} +1 -1
  82. package/vendor/type-server/editors/docs/assets/{railroadDiagram-Y72NRBL7-BZgG8r2y.js → railroadDiagram-Y72NRBL7-B3r2jnFu.js} +1 -1
  83. package/vendor/type-server/editors/docs/assets/{requirementDiagram-EQYSW5RA-CutdnAmY.js → requirementDiagram-EQYSW5RA-BQ47C1Ra.js} +1 -1
  84. package/vendor/type-server/editors/docs/assets/{sankeyDiagram-SY24JHO5-DBaoPDhR.js → sankeyDiagram-SY24JHO5-CzPG7mjJ.js} +1 -1
  85. package/vendor/type-server/editors/docs/assets/{sequenceDiagram-BLEHNHQU-B6YZp-Wu.js → sequenceDiagram-BLEHNHQU-Bg7XKU4E.js} +1 -1
  86. package/vendor/type-server/editors/docs/assets/{sizeCapture-INFHLROL-xATlK6Zl.js → sizeCapture-INFHLROL-CKrHufer.js} +1 -1
  87. package/vendor/type-server/editors/docs/assets/{stateDiagram-v2-A6IESKWZ-C7BND5vv.js → stateDiagram-v2-A6IESKWZ-CW9zsuBs.js} +1 -1
  88. package/vendor/type-server/editors/docs/assets/{swimlanes-B3ENRKFQ-WYLzM6hb.js → swimlanes-B3ENRKFQ-ucM-4idg.js} +1 -1
  89. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-DuNOy5jj.js +8 -0
  90. package/vendor/type-server/editors/docs/assets/{timeline-definition-JXYKGLGB-BXC0F4xE.js → timeline-definition-JXYKGLGB-D__Vd4zC.js} +1 -1
  91. package/vendor/type-server/editors/docs/assets/{usecaseDiagram-WPOLBNNX-Cx58jkEj.js → usecaseDiagram-WPOLBNNX-MvJGETnL.js} +1 -1
  92. package/vendor/type-server/editors/docs/assets/{vennDiagram-Q3Y3IDCW-DhdwpApW.js → vennDiagram-Q3Y3IDCW-DqUtQLGR.js} +1 -1
  93. package/vendor/type-server/editors/docs/assets/{wardleyDiagram-IVAIDKWA-CBdbPWVr.js → wardleyDiagram-IVAIDKWA-usWt7-Hk.js} +1 -1
  94. package/vendor/type-server/editors/docs/assets/{xychartDiagram-4URNHDU4-Cb0tcPqs.js → xychartDiagram-4URNHDU4-D2RJz2yB.js} +1 -1
  95. package/vendor/type-server/editors/docs/index.html +1 -1
  96. package/vendor/type-server/editors/motion/assets/{gif-jobs-Bq4rwLBV.js → gif-jobs-Bn-j8izW.js} +1 -1
  97. package/vendor/type-server/editors/motion/assets/{index-BDOqtmcc.js → index-C6NXgLix.js} +7 -6
  98. package/vendor/type-server/editors/motion/assets/{src-8SKXU1IY.js → src-C0eDPv3h.js} +1 -1
  99. package/vendor/type-server/editors/motion/index.html +1 -1
  100. package/vendor/type-server/editors/sheets/assets/{index-BY38EAff.js → index-BzbNSKJF.js} +7 -6
  101. package/vendor/type-server/editors/sheets/assets/{workbook-worker-CRtLrZhP.js → workbook-worker-3zEBX9ep.js} +3 -2
  102. package/vendor/type-server/editors/sheets/index.html +1 -1
  103. package/vendor/type-server/editors/slides/assets/{index-B51oMclO.js → index-BfTA-zoQ.js} +7 -6
  104. package/vendor/type-server/editors/slides/assets/{src-CdsEFSuC.js → src-DPkvzCL6.js} +1 -1
  105. package/vendor/type-server/editors/slides/index.html +1 -1
  106. package/vendor/type-server/editors/whiteboard/assets/{drawing-look-worker-Dd2iYbXC.js → drawing-look-worker-CYqIJdVf.js} +4 -3
  107. package/vendor/type-server/editors/whiteboard/assets/{gif-jobs-DmIqT6gk.js → gif-jobs-CPyG3MAt.js} +1 -1
  108. package/vendor/type-server/editors/whiteboard/assets/{index-B3oRKavi.js → index-BBgN0Gcr.js} +2 -2
  109. package/vendor/type-server/editors/whiteboard/assets/{index-CTf9pd4S.js → index-BKFgBbwk.js} +8 -7
  110. package/vendor/type-server/editors/whiteboard/index.html +1 -1
  111. package/vendor/type-server/shell/assets/{browser-models-BzwWAVuE.js → browser-models-CiXqE7b9.js} +4 -4
  112. package/vendor/type-server/shell/assets/index-BhxD6amu.js +53 -0
  113. package/vendor/type-server/shell/assets/index-Cw3mY0u9.css +1 -0
  114. package/vendor/type-server/shell/assets/{node.browser-BgqLTfql.js → node.browser-ByUkO9oN.js} +1 -1
  115. package/vendor/type-server/shell/assets/{node.browser-BvryIsl7.js → node.browser-CSEwiusG.js} +1 -1
  116. package/vendor/type-server/shell/index.html +2 -2
  117. package/vendor/home/assets/RuntimeUpdate-BwvJ9sYp.js +0 -43
  118. package/vendor/home/assets/library-CyeaNaQo.js +0 -226
  119. package/vendor/home/assets/main-DUyobyFI.js +0 -5
  120. package/vendor/home/assets/main-DXpv3z2x.css +0 -1
  121. package/vendor/home/assets/node.browser-Cy4GM7Yl.js +0 -1
  122. package/vendor/home/assets/node.browser-nUfHL25Z.js +0 -1
  123. package/vendor/shell/assets/index-BIHLxOO6.js +0 -52
  124. package/vendor/shell/assets/index-DXpv3z2x.css +0 -1
  125. package/vendor/type-server/editors/docs/assets/channel-Cgat34ii.js +0 -1
  126. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-Bwh1tnzE.js +0 -8
  127. package/vendor/type-server/shell/assets/index-BIHLxOO6.js +0 -52
  128. package/vendor/type-server/shell/assets/index-DXpv3z2x.css +0 -1
@@ -0,0 +1,1352 @@
1
+ "use strict";
2
+ (() => {
3
+ // packages/server-sdk/src/frame/client/page.ts
4
+ (() => {
5
+ "use strict";
6
+ const w = window;
7
+ if (w.__openArtifactsPage) return;
8
+ w.__openArtifactsPage = true;
9
+ const boot = w.__OPEN_ARTIFACTS_FRAME || {};
10
+ const SHELL = boot.shellOrigin || "";
11
+ const parentWin = window.parent;
12
+ const framed = !!SHELL && !!parentWin && parentWin !== window;
13
+ const nested = (() => {
14
+ try {
15
+ return window.frameElement !== null;
16
+ } catch {
17
+ return true;
18
+ }
19
+ })();
20
+ const isRecord = (value) => value !== null && typeof value === "object";
21
+ function post(msg) {
22
+ if (!framed || nested) return;
23
+ try {
24
+ parentWin.postMessage(msg, SHELL);
25
+ } catch {
26
+ }
27
+ }
28
+ const fromShell = /* @__PURE__ */ new Map();
29
+ window.addEventListener("message", (ev) => {
30
+ if (ev.source !== parentWin || ev.origin !== SHELL || !isRecord(ev.data)) return;
31
+ for (const [key, handle] of fromShell) {
32
+ if (key in ev.data) {
33
+ try {
34
+ handle(ev.data);
35
+ } catch {
36
+ }
37
+ return;
38
+ }
39
+ }
40
+ });
41
+ const session = (() => {
42
+ try {
43
+ return window.sessionStorage;
44
+ } catch {
45
+ return null;
46
+ }
47
+ })();
48
+ function readStored(key) {
49
+ try {
50
+ const raw = session?.getItem(key);
51
+ return raw == null ? null : JSON.parse(raw);
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
56
+ function store(key, value) {
57
+ try {
58
+ session?.setItem(key, JSON.stringify(value));
59
+ } catch {
60
+ }
61
+ }
62
+ function unstore(key) {
63
+ try {
64
+ session?.removeItem(key);
65
+ } catch {
66
+ }
67
+ }
68
+ const nextFrame = typeof requestAnimationFrame === "function" ? (fn) => requestAnimationFrame(() => fn()) : (fn) => setTimeout(fn, 16);
69
+ const loaded = document.readyState === "complete" ? Promise.resolve() : new Promise((done) => addEventListener("load", () => done(), { once: true }));
70
+ const parsed = document.readyState !== "loading" ? Promise.resolve() : new Promise((done) => document.addEventListener("DOMContentLoaded", () => done(), { once: true }));
71
+ const pagePath = (() => {
72
+ const m = /^\/_f\/[^/]{1,128}\/(.*)$/.exec(location.pathname);
73
+ return (m ? m[1] : location.pathname).replace(/(^|\/)index\.html$/, "$1");
74
+ })();
75
+ const tab = (() => {
76
+ try {
77
+ const value = JSON.parse(window.name)?.tab;
78
+ return typeof value === "string" && /^[0-9a-z]{1,32}$/.test(value) ? value : null;
79
+ } catch {
80
+ return null;
81
+ }
82
+ })();
83
+ const hasFragment = () => {
84
+ try {
85
+ const hash2 = location.hash;
86
+ return hash2.length > 1 && (hash2.startsWith("#comment-") || !fragmentIsState(hash2.slice(1)));
87
+ } catch {
88
+ return true;
89
+ }
90
+ };
91
+ function fragmentIsState(fragment) {
92
+ const metas = document.querySelectorAll('meta[name="open-artifacts:fragment" i]');
93
+ if (metas[metas.length - 1]?.getAttribute("content")?.trim().toLowerCase() !== "no-jump") return false;
94
+ let id = fragment;
95
+ try {
96
+ id = decodeURIComponent(fragment);
97
+ } catch {
98
+ }
99
+ return document.getElementById(id) === null && document.getElementsByName(id).length === 0;
100
+ }
101
+ function scrollWindowTo(top) {
102
+ try {
103
+ window.scrollTo({ top, left: 0, behavior: "instant" });
104
+ } catch {
105
+ window.scrollTo(0, top);
106
+ }
107
+ }
108
+ function scrollBoxTo(box, top, left) {
109
+ try {
110
+ box.scrollTo({ top, left, behavior: "instant" });
111
+ } catch {
112
+ box.scrollTop = top;
113
+ box.scrollLeft = left;
114
+ }
115
+ }
116
+ function pathTo(el) {
117
+ const steps = [];
118
+ for (let at = el, depth = 0; at && at !== document.documentElement && depth < 32; at = at.parentElement, depth++) {
119
+ if (at.id && at.id.length <= 128) {
120
+ steps.unshift(`#${CSS.escape(at.id)}`);
121
+ return steps.join(" > ");
122
+ }
123
+ const parent = at.parentElement;
124
+ if (!parent) break;
125
+ steps.unshift(`${at.localName}:nth-child(${Array.prototype.indexOf.call(parent.children, at) + 1})`);
126
+ }
127
+ return steps.length ? `:root > ${steps.join(" > ")}` : null;
128
+ }
129
+ function find(selector) {
130
+ if (typeof selector !== "string" || !selector || selector.length > 2048) return null;
131
+ try {
132
+ return document.querySelector(selector);
133
+ } catch {
134
+ return null;
135
+ }
136
+ }
137
+ const SCROLL_KEY = tab ? `open-artifacts:scroll:${tab}` : "open-artifacts:scroll";
138
+ const SCROLL_SAVE_MS = 150;
139
+ function topAnchors() {
140
+ const out = [];
141
+ if (!innerWidth || !innerHeight) return out;
142
+ for (const x of [innerWidth / 2, innerWidth / 4, innerWidth * 3 / 4]) {
143
+ let el = document.elementFromPoint(x, 1);
144
+ while (el && el !== document.body && el !== document.documentElement && el.getBoundingClientRect().height > innerHeight * 2) el = null;
145
+ if (!el || el === document.body || el === document.documentElement) continue;
146
+ const path = pathTo(el);
147
+ if (path && !out.some(([p]) => p === path)) out.push([path, Math.round(-el.getBoundingClientRect().top)]);
148
+ }
149
+ return out;
150
+ }
151
+ function keptScroll() {
152
+ const value = readStored(SCROLL_KEY);
153
+ if (!isRecord(value) || typeof value.y !== "number" || !Number.isFinite(value.y) || value.y < 0 || typeof value.p !== "string") return null;
154
+ const anchors = Array.isArray(value.a) ? value.a.filter((a) => Array.isArray(a) && typeof a[0] === "string" && typeof a[1] === "number" && Number.isFinite(a[1])).slice(0, 3) : void 0;
155
+ return { p: value.p, y: value.y, ...anchors?.length ? { a: anchors } : {} };
156
+ }
157
+ function keptTop(kept) {
158
+ for (const [path, into] of kept.a ?? []) {
159
+ const el = find(path);
160
+ if (el) return Math.max(0, Math.round(el.getBoundingClientRect().top + scrollY + into));
161
+ }
162
+ return kept.y;
163
+ }
164
+ if (!nested) {
165
+ let saveTimer;
166
+ let ownScroll = false;
167
+ let personScrolled = false;
168
+ const save = () => {
169
+ clearTimeout(saveTimer);
170
+ saveTimer = void 0;
171
+ const y = Math.round(scrollY);
172
+ store(SCROLL_KEY, { p: pagePath, y, ...y > 0 ? { a: topAnchors() } : {} });
173
+ };
174
+ addEventListener(
175
+ "scroll",
176
+ () => {
177
+ if (ownScroll) {
178
+ ownScroll = false;
179
+ return;
180
+ }
181
+ personScrolled = true;
182
+ clearTimeout(saveTimer);
183
+ saveTimer = setTimeout(save, SCROLL_SAVE_MS);
184
+ },
185
+ { passive: true }
186
+ );
187
+ addEventListener("pagehide", () => {
188
+ if (saveTimer !== void 0) save();
189
+ });
190
+ const restore = (kept) => {
191
+ const top = keptTop(kept);
192
+ if (Math.round(scrollY) === top) return;
193
+ ownScroll = true;
194
+ scrollWindowTo(top);
195
+ };
196
+ void parsed.then(() => {
197
+ const kept = keptScroll();
198
+ if (!kept || kept.p !== pagePath) {
199
+ store(SCROLL_KEY, { p: pagePath, y: 0 });
200
+ return;
201
+ }
202
+ if (hasFragment()) return;
203
+ restore(kept);
204
+ if (Math.round(scrollY) !== keptTop(kept)) void loaded.then(() => nextFrame(() => !personScrolled && restore(kept)));
205
+ });
206
+ if (!innerHeight) {
207
+ addEventListener(
208
+ "resize",
209
+ () => {
210
+ if (document.readyState === "complete") document.querySelector(":target")?.scrollIntoView({ behavior: "instant" });
211
+ },
212
+ { once: true }
213
+ );
214
+ }
215
+ }
216
+ const RELOAD_KEY = "open-artifacts:reload";
217
+ const INPUT_KEY = "open-artifacts:reload-input";
218
+ const RELOAD_FRESH_MS = 1e4;
219
+ const MAX_BOXES = 32;
220
+ const MAX_UP = 64;
221
+ const MAX_INPUTS = 256;
222
+ const MAX_FIELD = 8192;
223
+ const RESTORE_FRAMES = 30;
224
+ const INPUT_TYPES = ["pointerdown", "pointerup", "click", "keydown", "keyup"];
225
+ const MADE_UP_ID = /(?:^|\W)(?::[rR][0-9a-zH]+:|«[rR][0-9a-zH]+»|_[rR]_[0-9a-zH]+_)(?:\W|$)/;
226
+ const TEXT_TYPES = /^(?:text|search|url|tel|)$/;
227
+ const isField = (el) => el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement;
228
+ const isTextField = (el) => el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement && TEXT_TYPES.test(el.type);
229
+ const SECRET_WORD = /^(?:pass(?:word|wd|code|phrase)?|pwd|secret|token|apikey|cv[vc]|ssn|iban|pin|(?:card|cc|account|acct|routing)(?:number|num|no))\d*$/;
230
+ const SECRET_PAIR = /^(?:api key|(?:card|cc|account|acct|routing) (?:number|num|no))\d*$/;
231
+ const SECRET_AUTOCOMPLETE = /\b(?:off|new-password|current-password|one-time-code|cc-[a-z-]+)\b/i;
232
+ function isSecret(el) {
233
+ if (!isField(el)) return false;
234
+ if (el.__artifactSecret === true) return true;
235
+ if (el instanceof HTMLInputElement && el.type === "password") return true;
236
+ for (const selector of [":autofill", ":-webkit-autofill"]) {
237
+ try {
238
+ if (el.matches(selector)) return true;
239
+ } catch {
240
+ }
241
+ }
242
+ const named = [el.name, el.id].some((text) => {
243
+ const words = text.replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/);
244
+ return words.some((word, i) => SECRET_WORD.test(word) || SECRET_PAIR.test(`${word} ${words[i + 1] ?? ""}`));
245
+ });
246
+ return named || SECRET_AUTOCOMPLETE.test(el.getAttribute("autocomplete") ?? "") || SECRET_AUTOCOMPLETE.test(el.form?.getAttribute("autocomplete") ?? "");
247
+ }
248
+ const ROLE_OF_TAG = {
249
+ a: "link",
250
+ area: "link",
251
+ aside: "complementary",
252
+ dialog: "dialog",
253
+ fieldset: "group",
254
+ form: "form",
255
+ li: "listitem",
256
+ main: "main",
257
+ nav: "navigation",
258
+ section: "region",
259
+ table: "table",
260
+ td: "cell",
261
+ th: "columnheader",
262
+ tr: "row"
263
+ };
264
+ const GROUP_ROLES = /^(?:toolbar|group|radiogroup|region|listbox|tree|treegrid|grid|table|tablist|tabpanel|menu|menubar|dialog|alertdialog|navigation|complementary|form|search|main)$/;
265
+ const ITEM_ROLES = /^(?:row|option|treeitem|gridcell|cell|tab|listitem|menuitem)$/;
266
+ const CONTENT_NAMED = /^(?:button|link|summary|checkbox|radio|switch|columnheader|rowheader|menuitemcheckbox|menuitemradio|row|option|treeitem|gridcell|cell|tab|listitem|menuitem)$/;
267
+ function roleOf(el) {
268
+ const given = el.getAttribute("role")?.trim().split(/\s+/, 1)[0]?.toLowerCase();
269
+ return (given || (el instanceof HTMLInputElement ? `input:${el.type}` : ROLE_OF_TAG[el.localName]) || el.localName).slice(0, 32);
270
+ }
271
+ const squeeze = (text) => (text ?? "").slice(0, 1e3).trim().replace(/\s+/g, " ");
272
+ function textOf(el) {
273
+ if (!el) return "";
274
+ let text = "";
275
+ const walk = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
276
+ for (let n = 0; n < 256 && text.length < 80 && walk.nextNode(); n++) {
277
+ if (!walk.currentNode.parentElement?.closest("textarea,select,script,style")) text = squeeze(`${text} ${walk.currentNode.nodeValue ?? ""}`);
278
+ }
279
+ return text.slice(0, 80);
280
+ }
281
+ function nameOf(el, fromContent) {
282
+ const labelledBy = (el.getAttribute("aria-labelledby") ?? "").split(/\s+/, 8).map((id) => id ? textOf(document.getElementById(id)) : "").join(" ");
283
+ return squeeze(el.getAttribute("aria-label")) || squeeze(labelledBy) || textOf(isField(el) ? el.labels?.[0] : null) || textOf(el.localName === "fieldset" ? el.querySelector(":scope > legend") : null) || (fromContent ? textOf(el) : "") || squeeze(el.getAttribute("title")) || squeeze(el.getAttribute("placeholder"));
284
+ }
285
+ function hash(text) {
286
+ let h = 2166136261;
287
+ for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);
288
+ return h >>> 0;
289
+ }
290
+ function markOf(el) {
291
+ const role = roleOf(el);
292
+ const within = [];
293
+ let up = el.parentElement;
294
+ for (let steps = 0; up && steps < MAX_UP && within.length < 8; up = up.parentElement, steps++) {
295
+ const upRole = roleOf(up);
296
+ const item = ITEM_ROLES.test(upRole);
297
+ const label = item || GROUP_ROLES.test(upRole) ? nameOf(up, item) : "";
298
+ if (label) within.push(hash(`${upRole} ${label}`));
299
+ }
300
+ return { role, name: hash(nameOf(el, CONTENT_NAMED.test(role))), within };
301
+ }
302
+ const sameMark = (a, b) => a.role === b.role && a.name === b.name && a.within.join() === b.within.join();
303
+ function focusTargetOf(state) {
304
+ const focus = state.focus;
305
+ const el = focus ? document.getElementById(focus.id) : null;
306
+ if (!(el instanceof HTMLElement || el instanceof SVGElement) || isSecret(el)) return null;
307
+ if (!MADE_UP_ID.test(focus.id) || !focus.control) return el;
308
+ try {
309
+ return sameMark(focus.control, markOf(el)) ? el : null;
310
+ } catch {
311
+ return null;
312
+ }
313
+ }
314
+ const scrolls = (el, top, left) => {
315
+ const style = getComputedStyle(el);
316
+ const can = /auto|scroll|overlay/;
317
+ return (top === 0 || can.test(style.overflowY)) && (left === 0 || can.test(style.overflowX));
318
+ };
319
+ const isWindowScroller = (el) => el === document.body || el === document.documentElement || el === document.scrollingElement;
320
+ function captureReload(gen, seq) {
321
+ const state = { gen, at: Date.now(), path: pagePath, seq };
322
+ const offset = (el) => [Math.round(el.scrollTop), Math.round(el.scrollLeft)];
323
+ const scrolled = [...document.querySelectorAll("[id]")].filter((el) => el.id.length <= 128 && offset(el).some(Boolean) && !isWindowScroller(el));
324
+ if (scrolled.length) state.boxes = scrolled.slice(0, MAX_BOXES).map((el) => [el.id, ...offset(el)]);
325
+ const target = hasFragment() && location.hash.length <= 129 ? document.getElementById(decodeURIComponent(location.hash.slice(1))) : null;
326
+ const above = [];
327
+ let up = target?.parentElement ?? null;
328
+ for (let steps = 1; up && steps <= MAX_UP && above.length < MAX_BOXES; up = up.parentElement, steps++) {
329
+ const top = Math.round(up.scrollTop);
330
+ const left = Math.round(up.scrollLeft);
331
+ if ((top || left) && (!up.id || up === document.body) && !isWindowScroller(up) && scrolls(up, top, left)) above.push([steps, up.localName, top, left]);
332
+ }
333
+ if (above.length) state.above = above;
334
+ const active = document.hasFocus() ? document.activeElement : null;
335
+ if (active instanceof HTMLElement && active.id && active !== document.body && !isSecret(active)) {
336
+ const focus = { id: active.id };
337
+ if (MADE_UP_ID.test(active.id)) {
338
+ try {
339
+ focus.control = markOf(active);
340
+ } catch {
341
+ }
342
+ }
343
+ if (isTextField(active) && active.value.length <= MAX_FIELD) focus.value = active.value;
344
+ try {
345
+ const field = active;
346
+ if (typeof field.selectionStart === "number" && typeof field.selectionEnd === "number") focus.sel = [field.selectionStart, field.selectionEnd];
347
+ } catch {
348
+ }
349
+ state.focus = focus;
350
+ }
351
+ return state;
352
+ }
353
+ function takeReload() {
354
+ const value = readStored(RELOAD_KEY);
355
+ unstore(RELOAD_KEY);
356
+ if (!isRecord(value) || value.path !== pagePath || typeof value.at !== "number" || Date.now() - value.at > RELOAD_FRESH_MS) {
357
+ unstore(INPUT_KEY);
358
+ return null;
359
+ }
360
+ return value;
361
+ }
362
+ function takeInputs() {
363
+ const value = readStored(INPUT_KEY);
364
+ unstore(INPUT_KEY);
365
+ return Array.isArray(value) ? value.filter((e) => isRecord(e) && typeof e.seq === "number" && typeof e.type === "string" && INPUT_TYPES.includes(e.type)).slice(0, MAX_INPUTS) : [];
366
+ }
367
+ function restoreBoxes(state, done, force) {
368
+ let all = true;
369
+ const wanted = (state.boxes ?? []).map(([id, top, left]) => [document.getElementById(id), top, left]);
370
+ const target = hasFragment() ? document.getElementById(decodeURIComponent(location.hash.slice(1))) : null;
371
+ for (const [steps, tag, top, left] of state.above ?? []) {
372
+ let up = target;
373
+ for (let i = 0; up && i < Math.min(steps, MAX_UP); i++) up = up.parentElement;
374
+ if (up && up.localName === tag && (!up.id || up === document.body) && !isWindowScroller(up) && scrolls(up, top, left)) wanted.push([up, top, left]);
375
+ }
376
+ for (const [el, top, left] of wanted) {
377
+ if (!el) {
378
+ all = false;
379
+ continue;
380
+ }
381
+ if (done.has(el)) continue;
382
+ if (el.scrollTop !== 0 || el.scrollLeft !== 0) {
383
+ done.add(el);
384
+ continue;
385
+ }
386
+ const fits = el.scrollHeight - el.clientHeight >= Math.abs(top) - 1 && el.scrollWidth - el.clientWidth >= Math.abs(left) - 1;
387
+ if (fits || force) {
388
+ scrollBoxTo(el, top, left);
389
+ if (fits || el.scrollTop !== 0 || el.scrollLeft !== 0) done.add(el);
390
+ }
391
+ all &&= fits;
392
+ }
393
+ return all;
394
+ }
395
+ function restoreFocus(state) {
396
+ const active = document.activeElement;
397
+ if (!document.hasFocus() || active && active !== document.body) return;
398
+ const el = focusTargetOf(state);
399
+ if (!el) return;
400
+ el.focus({ preventScroll: true });
401
+ const sel = state.focus?.sel;
402
+ if (sel && isTextField(el) && (state.focus?.value === void 0 || el.value === state.focus.value)) {
403
+ try {
404
+ el.setSelectionRange(sel[0], sel[1]);
405
+ } catch {
406
+ }
407
+ }
408
+ }
409
+ const CLICKABLE = "a[href],area[href],button,input[type=submit],input[type=reset],input[type=image],input[type=file]";
410
+ const replayableClick = (el) => el.closest(CLICKABLE) === null && el.closest("a")?.hasAttributeNS("http://www.w3.org/1999/xlink", "href") !== true && (isField(el) || el.closest("label") === null);
411
+ function fieldsThePageSet(state) {
412
+ const set = /* @__PURE__ */ new Set();
413
+ for (const field of document.querySelectorAll("input[id],textarea[id],select[id]")) {
414
+ if (field.id === state.focus?.id && state.focus.value !== void 0 && isTextField(field)) {
415
+ if (field.value !== state.focus.value) set.add(field.id);
416
+ } else if (!(field instanceof HTMLInputElement && field.type === "radio") && !asMarkupHasIt(field)) set.add(field.id);
417
+ }
418
+ return set;
419
+ }
420
+ function asMarkupHasIt(field) {
421
+ if (field instanceof HTMLSelectElement) {
422
+ const options = [...field.options];
423
+ let i = options.length - 1;
424
+ while (i >= 0 && !options[i].hasAttribute("selected")) i--;
425
+ return field.selectedIndex === (i >= 0 ? i : options.length && !field.multiple ? 0 : -1);
426
+ }
427
+ if (field instanceof HTMLInputElement && (field.type === "checkbox" || field.type === "radio")) return field.checked === field.defaultChecked;
428
+ if (field instanceof HTMLInputElement && (field.type === "range" || field.type === "color")) {
429
+ const twin = field.cloneNode(false);
430
+ twin.value = twin.defaultValue;
431
+ return twin.value === field.value;
432
+ }
433
+ return field.value === field.defaultValue;
434
+ }
435
+ const replayed = /* @__PURE__ */ new WeakSet();
436
+ function replay(input, pageSet, stopped) {
437
+ const target = input.id ? document.getElementById(input.id) : null;
438
+ const at = target ?? (typeof input.x === "number" && typeof input.y === "number" ? document.elementFromPoint(input.x, input.y) : null) ?? document.activeElement ?? document.body;
439
+ if (!at) return;
440
+ const toggle = input.type === "click" && typeof input.checked === "boolean" && target instanceof HTMLInputElement && (target.type === "checkbox" || target.type === "radio");
441
+ if (toggle ? target.checked === input.checked : target !== null && pageSet.has(target.id)) return;
442
+ if (input.type === "click" && (!target || !replayableClick(target))) return;
443
+ if ((input.type === "keydown" || input.type === "keyup") && input.key === "Escape") return;
444
+ const base = { bubbles: true, cancelable: true, composed: true };
445
+ const key = input.type === "keydown" || input.type === "keyup";
446
+ const event = key ? new KeyboardEvent(input.type, { ...base, key: input.key, code: input.code, shiftKey: input.shift === true }) : input.type !== "click" && typeof PointerEvent === "function" ? new PointerEvent(input.type, { ...base, clientX: input.x, clientY: input.y, button: input.button ?? 0 }) : new MouseEvent(input.type, { ...base, clientX: input.x, clientY: input.y, button: input.button ?? 0 });
447
+ replayed.add(event);
448
+ at.dispatchEvent(event);
449
+ if (input.type === "pointerdown" && isTextField(target) && target.value !== "") stopped.add(target);
450
+ if (input.type !== "keydown" || typeof input.key !== "string") return;
451
+ if (!isTextField(target) || target.readOnly || target.disabled || isSecret(target)) return;
452
+ const typed = input.key.length === 1;
453
+ if (!typed && !/^(?:Backspace|Delete|Shift|CapsLock)$/.test(input.key)) {
454
+ stopped.add(target);
455
+ return;
456
+ }
457
+ if (event.defaultPrevented || stopped.has(target) || !(typed || input.key === "Backspace" || input.key === "Delete")) return;
458
+ if (document.activeElement !== target) target.focus({ preventScroll: true });
459
+ let from = target.selectionStart ?? target.value.length;
460
+ let to = target.selectionEnd ?? target.value.length;
461
+ if (!typed && from === to) {
462
+ if (input.key === "Backspace") from = Math.max(0, from - 1);
463
+ else to = Math.min(target.value.length, to + 1);
464
+ }
465
+ target.setRangeText(typed ? input.key : "", from, to, "end");
466
+ const inputEvent = new InputEvent("input", {
467
+ bubbles: true,
468
+ data: typed ? input.key : null,
469
+ inputType: typed ? "insertText" : input.key === "Backspace" ? "deleteContentBackward" : "deleteContentForward"
470
+ });
471
+ replayed.add(inputEvent);
472
+ target.dispatchEvent(inputEvent);
473
+ }
474
+ const mac = (() => {
475
+ try {
476
+ return /^(?:Mac|iP)/.test(navigator.platform);
477
+ } catch {
478
+ return false;
479
+ }
480
+ })();
481
+ let inputSeq = 0;
482
+ let recording = false;
483
+ const recorded = [];
484
+ function standIn(k, key) {
485
+ const typedWithOption = mac && k.altKey && !k.ctrlKey && !k.metaKey;
486
+ const symbol = key.length === 1 && /[^\sA-Za-z0-9]/.test(key);
487
+ if (symbol && (typedWithOption || k.getModifierState?.("AltGraph") === true)) return null;
488
+ if (k.isComposing || key === "Process" || key === "Dead") return "Process";
489
+ for (const [held, name] of [
490
+ [k.metaKey, "Meta"],
491
+ [k.ctrlKey, "Control"],
492
+ [k.altKey, "AltGraph"]
493
+ ]) {
494
+ if (held) return name;
495
+ }
496
+ return null;
497
+ }
498
+ function record(ev) {
499
+ if (replayed.has(ev) || recorded.length >= MAX_INPUTS) return;
500
+ const k = ev;
501
+ const p = ev;
502
+ let key = typeof k.key === "string" ? k.key : void 0;
503
+ let code = typeof k.code === "string" ? k.code : void 0;
504
+ if (key !== void 0 && isSecret(ev.composedPath?.()[0] ?? ev.target)) return;
505
+ const id = ev.target instanceof Element && ev.target.id ? ev.target.id : void 0;
506
+ const stand = key === void 0 ? null : standIn(k, key);
507
+ if (stand !== null) {
508
+ const last = recorded.at(-1);
509
+ if (ev.type !== "keydown" || last && last.code === "" && last.key === stand && last.id === id) return;
510
+ key = stand;
511
+ code = "";
512
+ }
513
+ const toggle = ev.type === "click" && ev.target instanceof HTMLInputElement && /^(checkbox|radio)$/.test(ev.target.type) ? ev.target : null;
514
+ const pressed = !ev.type.startsWith("key") && typeof p.clientX === "number";
515
+ recorded.push({
516
+ seq: ++inputSeq,
517
+ type: ev.type,
518
+ ...id === void 0 ? {} : { id },
519
+ ...pressed ? { x: Math.round(p.clientX), y: Math.round(p.clientY), button: p.button } : {},
520
+ ...key === void 0 ? {} : { key, code, ...k.shiftKey && code !== "" ? { shift: true } : {} },
521
+ ...toggle ? { checked: toggle.checked } : {}
522
+ });
523
+ store(INPUT_KEY, recorded);
524
+ }
525
+ function startRecording() {
526
+ if (recording) return;
527
+ recording = true;
528
+ recorded.length = 0;
529
+ unstore(INPUT_KEY);
530
+ for (const type of INPUT_TYPES) addEventListener(type, record, { capture: true, passive: true });
531
+ addEventListener(
532
+ "pagehide",
533
+ () => {
534
+ for (const type of INPUT_TYPES) removeEventListener(type, record, true);
535
+ },
536
+ { once: true }
537
+ );
538
+ }
539
+ fromShell.set("__frame_hot_capture", (m) => {
540
+ const gen = typeof m.gen === "number" ? m.gen : 0;
541
+ if (!nested) {
542
+ try {
543
+ store(RELOAD_KEY, captureReload(gen, inputSeq));
544
+ } catch {
545
+ unstore(RELOAD_KEY);
546
+ }
547
+ startRecording();
548
+ }
549
+ post({ __frame_hot_state: true, gen });
550
+ });
551
+ if (!nested) {
552
+ const state = takeReload();
553
+ if (state) {
554
+ let personActed = false;
555
+ for (const type of ["keydown", "pointerdown"]) addEventListener(type, (ev) => personActed ||= ev.isTrusted, { capture: true, passive: true });
556
+ const done = /* @__PURE__ */ new WeakSet();
557
+ void parsed.then(() => {
558
+ let frames = 0;
559
+ const step = () => {
560
+ if (personActed) return;
561
+ if (restoreBoxes(state, done, false)) return;
562
+ if (++frames < RESTORE_FRAMES) nextFrame(step);
563
+ else void loaded.then(() => nextFrame(() => !personActed && restoreBoxes(state, done, true)));
564
+ };
565
+ step();
566
+ });
567
+ void loaded.then(
568
+ () => nextFrame(() => {
569
+ if (personActed) {
570
+ unstore(INPUT_KEY);
571
+ return;
572
+ }
573
+ restoreFocus(state);
574
+ const later = takeInputs().filter((input) => input.seq > state.seq);
575
+ if (!later.length) return;
576
+ const pageSet = fieldsThePageSet(state);
577
+ const stopped = /* @__PURE__ */ new Set();
578
+ for (const input of later) {
579
+ try {
580
+ replay(input, pageSet, stopped);
581
+ } catch {
582
+ }
583
+ }
584
+ })
585
+ );
586
+ }
587
+ }
588
+ const VERSIONED = /^\/_f\/[^/]{1,128}\//;
589
+ const pageRoot = (() => {
590
+ const m = VERSIONED.exec(location.pathname);
591
+ return m ? new URL(m[0], location.origin) : null;
592
+ })();
593
+ const isChromium = (() => {
594
+ try {
595
+ const brands = navigator.userAgentData?.brands;
596
+ return Array.isArray(brands) && brands.some((b) => b?.brand === "Chromium");
597
+ } catch {
598
+ return false;
599
+ }
600
+ })();
601
+ function linkOf(ev) {
602
+ for (const at of ev.composedPath ? ev.composedPath() : [ev.target]) {
603
+ if (at instanceof Element && hrefOf(at) !== null) return at;
604
+ }
605
+ return null;
606
+ }
607
+ function hrefOf(el) {
608
+ if (el.localName !== "a" && el.localName !== "area") return null;
609
+ const href = el.getAttribute("href");
610
+ if (href === null && el.namespaceURI === "http://www.w3.org/2000/svg") return el.getAttributeNS("http://www.w3.org/1999/xlink", "href");
611
+ return href;
612
+ }
613
+ const targetOf = (el) => (el.getAttribute("target") ?? document.querySelector("base[target]")?.getAttribute("target") ?? "").toLowerCase();
614
+ const asksNewTab = (ev) => ev.type === "auxclick" || ev.metaKey || ev.ctrlKey || ev.shiftKey;
615
+ const opensElsewhere = (ev, el) => asksNewTab(ev) || ev.altKey || !["", "_self", "_top", "_parent"].includes(targetOf(el));
616
+ const plainClick = (ev, el) => ev.button === 0 && !(ev.metaKey || ev.ctrlKey || ev.shiftKey || ev.altKey) && !(el instanceof HTMLElement && el.isContentEditable);
617
+ function hasFrameNamed(name, win = window) {
618
+ try {
619
+ for (let i = 0; i < win.length; i++) {
620
+ const child = win[i];
621
+ if (child && (child.name.toLowerCase() === name || hasFrameNamed(name, child))) return true;
622
+ }
623
+ return false;
624
+ } catch {
625
+ return true;
626
+ }
627
+ }
628
+ function opensNewTab(ev, el) {
629
+ const target = targetOf(el);
630
+ if (!plainClick(ev, el) || el.hasAttribute("download")) return false;
631
+ return target === "_blank" || !["", "_self"].includes(target) && (["_top", "_parent"].includes(target) || !hasFrameNamed(target));
632
+ }
633
+ const prevented = (ev) => Reflect.get(Event.prototype, "defaultPrevented", ev) === true;
634
+ function urlOf(href, base = document.baseURI) {
635
+ try {
636
+ return new URL(href, base);
637
+ } catch {
638
+ return null;
639
+ }
640
+ }
641
+ let lastBlocked = 0;
642
+ function blocked(kind) {
643
+ const now = Date.now();
644
+ if (now - lastBlocked < 1e3) return;
645
+ lastBlocked = now;
646
+ post({ __frame_blocked: true, kind });
647
+ }
648
+ let byKey = false;
649
+ const noteInput = (ev) => {
650
+ if (!ev.repeat) byKey = ev.type === "keydown";
651
+ };
652
+ const OUTSIDE = /^https?:$/;
653
+ const APP = /^(mailto|tel|sms):$/;
654
+ function onOutsideLink(ev) {
655
+ if (ev.type === "auxclick" && ev.button !== 1) return;
656
+ const el = linkOf(ev);
657
+ const href = el && hrefOf(el);
658
+ if (!el || !href || href.trim()[0] === "#") return;
659
+ const url = urlOf(href);
660
+ if (!url || !(OUTSIDE.test(url.protocol) || APP.test(url.protocol)) || url.origin === location.origin) return;
661
+ Event.prototype.preventDefault.call(ev);
662
+ post({ __frame_nav: true, url: url.href, rawHref: href, newTab: opensElsewhere(ev, el), ...asksNewTab(ev) ? { newTabGesture: true } : {}, ...ev.isTrusted ? { byKey } : {} });
663
+ }
664
+ function onFragmentLink(ev) {
665
+ if (prevented(ev) || ev.type === "auxclick" && ev.button !== 1) return;
666
+ const el = linkOf(ev);
667
+ const href = el && hrefOf(el);
668
+ if (!el || !href || href[0] !== "#" || href.length < 2) return;
669
+ const url = urlOf(href);
670
+ if (url && url.origin === location.origin) post({ __frame_nav: true, url: url.href, rawHref: href, newTab: asksNewTab(ev) || ev.altKey });
671
+ }
672
+ function onBasedFragment(ev) {
673
+ if (prevented(ev)) return;
674
+ const el = linkOf(ev);
675
+ if (!el || !plainClick(ev, el) || el.hasAttribute("download")) return;
676
+ const href = hrefOf(el)?.trim();
677
+ if (!href || href[0] !== "#" || !["", "_self"].includes((el.getAttribute("target") ?? "").toLowerCase())) return;
678
+ const here = urlOf(href, location.href);
679
+ const based = urlOf(href);
680
+ if (!here || !based || here.href === based.href) return;
681
+ ev.preventDefault();
682
+ location.assign(here.href);
683
+ }
684
+ function openInArtifact(url) {
685
+ if (!pageRoot) return;
686
+ const fromRoot = !url.pathname.startsWith("/_");
687
+ const to = fromRoot ? new URL(`.${url.pathname}${url.search}${url.hash}`, pageRoot) : url;
688
+ const toPath = to.pathname.replace(VERSIONED, "").replace(/(^|\/)index\.html$/, "$1");
689
+ const samePage = to.search === "" && VERSIONED.test(to.pathname) && toPath === pagePath;
690
+ if (samePage && (fromRoot || to.hash !== "")) location.assign(new URL(to.hash || "#", location.href).href);
691
+ else if (samePage || !VERSIONED.test(to.pathname)) blocked("link");
692
+ else if (/\.html?$|\/$/i.test(to.pathname)) void openIfThere(to.href);
693
+ else blocked(fromRoot ? "link" : "file");
694
+ }
695
+ async function openIfThere(href) {
696
+ try {
697
+ if ((await fetch(href, { method: "HEAD" })).ok) {
698
+ location.assign(href);
699
+ return;
700
+ }
701
+ } catch {
702
+ }
703
+ blocked("link");
704
+ }
705
+ function onArtifactLink(ev) {
706
+ if (prevented(ev) || !pageRoot || nested) return;
707
+ const el = linkOf(ev);
708
+ const href = el && hrefOf(el)?.trim();
709
+ if (!el || !href) return;
710
+ const newTab = opensNewTab(ev, el);
711
+ if (href[0] === "#") {
712
+ if (newTab) {
713
+ ev.preventDefault();
714
+ location.assign(new URL(href, location.href).href);
715
+ }
716
+ return;
717
+ }
718
+ const url = urlOf(href);
719
+ if (!url || url.host !== location.host) return;
720
+ if (newTab) {
721
+ ev.preventDefault();
722
+ openInArtifact(url);
723
+ return;
724
+ }
725
+ const sameDocument = url.hash !== "" && url.pathname === location.pathname && url.search === location.search;
726
+ const leaves = !VERSIONED.test(url.pathname) && !/^\/_(?!f(\/|$))/.test(url.pathname) && !sameDocument;
727
+ if (leaves && plainClick(ev, el) && !el.hasAttribute("download") && ["", "_self"].includes(targetOf(el))) unlessRouted(ev, url, () => openInArtifact(url));
728
+ }
729
+ const navigation = window.navigation;
730
+ const routed = /* @__PURE__ */ new WeakSet();
731
+ let watchedProto = null;
732
+ function unlessRouted(ev, url, fallback) {
733
+ const proto = window.NavigateEvent?.prototype;
734
+ if (!(navigation instanceof EventTarget) || !proto || typeof proto.intercept !== "function") {
735
+ ev.preventDefault();
736
+ fallback();
737
+ return;
738
+ }
739
+ if (watchedProto !== proto) {
740
+ watchedProto = proto;
741
+ const intercept = proto.intercept;
742
+ proto.intercept = function(...args) {
743
+ intercept.apply(this, args);
744
+ routed.add(this);
745
+ };
746
+ }
747
+ const onNavigate = (event) => {
748
+ const nav = event;
749
+ if (nav.destination.url !== url.href) return;
750
+ navigation.removeEventListener("navigate", onNavigate);
751
+ queueMicrotask(() => {
752
+ if (routed.has(nav) || prevented(nav) || prevented(ev)) return;
753
+ nav.preventDefault();
754
+ fallback();
755
+ });
756
+ };
757
+ navigation.addEventListener("navigate", onNavigate);
758
+ setTimeout(() => navigation.removeEventListener("navigate", onNavigate), 1e3);
759
+ }
760
+ function onPdfLink(ev) {
761
+ if (prevented(ev)) return;
762
+ const el = linkOf(ev);
763
+ const href = el && hrefOf(el)?.trim();
764
+ if (!el || !href || el.hasAttribute("download") || !plainClick(ev, el)) return;
765
+ const target = targetOf(el);
766
+ if (!["", "_self", "_blank"].includes(target) || target !== "_blank" && !isChromium) return;
767
+ const url = urlOf(href);
768
+ if (!url || url.origin !== location.origin || !/\.pdf$/i.test(url.pathname)) return;
769
+ ev.preventDefault();
770
+ blocked("file");
771
+ }
772
+ function watchNavigations() {
773
+ if (!(navigation instanceof EventTarget) || !("currentEntry" in navigation)) return;
774
+ const web = /^https?:$/;
775
+ const caught = /^(https?|about|data|blob):$/;
776
+ navigation.addEventListener("navigate", (event) => {
777
+ const nav = event;
778
+ if (nav.defaultPrevented || !nav.cancelable || nav.navigationType === "traverse" || nav.downloadRequest !== null) return;
779
+ const url = urlOf(nav.destination.url);
780
+ if (!url || !(isChromium || caught.test(url.protocol)) || url.protocol === location.protocol && url.host === location.host) return;
781
+ nav.preventDefault();
782
+ const source = nav.sourceElement;
783
+ const form = nav.formData !== null || (source === void 0 ? web.test(url.protocol) && url.search !== "" : source !== null && source.localName === "form");
784
+ if (!form && (web.test(url.protocol) || APP.test(url.protocol))) post({ __frame_nav: true, url: url.href, rawHref: url.href, newTab: false });
785
+ else if (navigator.userActivation?.isActive !== false) blocked(form ? "form" : "link");
786
+ });
787
+ }
788
+ if (framed && !nested) {
789
+ addEventListener("keydown", noteInput, true);
790
+ addEventListener("pointerdown", noteInput, true);
791
+ addEventListener("click", onOutsideLink, true);
792
+ addEventListener("auxclick", onOutsideLink, true);
793
+ addEventListener("click", onFragmentLink);
794
+ addEventListener("auxclick", onFragmentLink);
795
+ addEventListener("click", onBasedFragment);
796
+ addEventListener("click", onArtifactLink);
797
+ addEventListener("click", onPdfLink);
798
+ watchNavigations();
799
+ }
800
+ const HOST_KEY_FLAGS = ["meta", "ctrl", "shift", "alt", "skipInEditable"];
801
+ function readHostKey(value) {
802
+ if (!isRecord(value) || typeof value.id !== "string" || !/^[a-z0-9_]{1,48}$/.test(value.id)) return null;
803
+ if (typeof value.key !== "string" || value.key.length < 1 || value.key.length > 32) return null;
804
+ if (Object.keys(value).some((k) => k !== "id" && k !== "key" && !HOST_KEY_FLAGS.includes(k))) return null;
805
+ const out = { id: value.id, key: value.key };
806
+ for (const flag of HOST_KEY_FLAGS) {
807
+ if (value[flag] === true) out[flag] = true;
808
+ else if (value[flag] !== void 0) return null;
809
+ }
810
+ const withCommand = out.meta === true || out.ctrl === true;
811
+ const altLetter = out.alt === true && !out.shift && out.skipInEditable === true && /^Key[A-Z]$/.test(out.key);
812
+ const functionKey = !out.shift && !out.alt && /^F([1-9]|1\d|2[0-4])$/.test(out.key);
813
+ return withCommand || altLetter || functionKey ? out : null;
814
+ }
815
+ const onlyAlt = (k) => k.alt === true && !k.meta && !k.ctrl;
816
+ function letterOf(ev) {
817
+ if (/^[ -~]$/.test(ev.key)) return /^[a-z]$/i.test(ev.key) ? ev.key.toUpperCase() : null;
818
+ if (ev.keyCode >= 65 && ev.keyCode <= 90) return String.fromCharCode(ev.keyCode);
819
+ return /^Key[A-Z]$/.test(ev.code) ? ev.code.slice(3) : null;
820
+ }
821
+ const TYPING_FIELD = "input:not([type=checkbox],[type=radio],[type=range],[type=button],[type=submit],[type=reset],[type=image]),textarea,select";
822
+ function typingIn(ev) {
823
+ if (document.designMode === "on") return true;
824
+ const at = ev.composedPath()[0] ?? ev.target;
825
+ return at instanceof Element && (at.closest(TYPING_FIELD) !== null || at instanceof HTMLElement && at.isContentEditable);
826
+ }
827
+ function inWaitingField(ev) {
828
+ const at = ev.composedPath()[0] ?? ev.target;
829
+ return at instanceof HTMLInputElement && at.hasAttribute("data-frame-waiting-field") && at.value === "";
830
+ }
831
+ function hostKeyPressed(ev, keys) {
832
+ if (ev.isComposing || ev.keyCode === 229 || typeof ev.key !== "string") return null;
833
+ return keys.find((k) => {
834
+ if (ev.metaKey !== (k.meta === true) || ev.ctrlKey !== (k.ctrl === true) || ev.shiftKey !== (k.shift === true) || ev.altKey !== (k.alt === true)) return false;
835
+ if (k.alt && k.ctrl && ev.getModifierState?.("AltGraph")) return false;
836
+ const letter = /^Key([A-Z])$/.exec(k.key)?.[1];
837
+ const same = !k.alt ? ev.key.toLowerCase() === k.key.toLowerCase() : letter && !k.meta ? letterOf(ev) === letter : ev.code.toLowerCase() === k.key.toLowerCase();
838
+ return same && (!k.skipInEditable || !typingIn(ev) || onlyAlt(k) && inWaitingField(ev));
839
+ }) ?? null;
840
+ }
841
+ let hostKeys = [];
842
+ function takeHostKeys(value) {
843
+ hostKeys = Array.isArray(value) ? value.slice(0, 16).map(readHostKey).filter((k) => k !== null) : [];
844
+ }
845
+ const sendHostKey = (ev, k) => {
846
+ ev.preventDefault();
847
+ if (!ev.repeat) setTimeout(() => post({ __frame_host_key: true, id: k.id }), 0);
848
+ };
849
+ function onHostKeyFirst(ev) {
850
+ const k = hostKeyPressed(ev, hostKeys.filter(onlyAlt));
851
+ if (!k || ev.defaultPrevented || document.fullscreenElement) return;
852
+ ev.stopImmediatePropagation();
853
+ sendHostKey(ev, k);
854
+ }
855
+ function onHostKeyLast(ev) {
856
+ const k = hostKeyPressed(ev, hostKeys.filter((key) => !onlyAlt(key)));
857
+ if (k && !ev.defaultPrevented && !document.fullscreenElement) sendHostKey(ev, k);
858
+ }
859
+ fromShell.set("__frame_leave_field", () => {
860
+ heldFocus = null;
861
+ let el = document.activeElement;
862
+ while (el?.shadowRoot?.activeElement) el = el.shadowRoot.activeElement;
863
+ if (el instanceof HTMLElement && (el.closest(TYPING_FIELD) !== null || el.isContentEditable)) el.blur();
864
+ });
865
+ const FOCUSABLE = "a[href],area[href],button,input:not([type=hidden]),select,textarea,iframe,object,embed,summary,audio[controls],video[controls],[contenteditable]:not([contenteditable=false]),[tabindex]";
866
+ const TAB_STOP_DELAY_MS = 200;
867
+ const scroller = () => document.scrollingElement ?? document.documentElement;
868
+ const scrollsOwnBox = (el) => {
869
+ const style = getComputedStyle(el);
870
+ return /auto|scroll/.test(style.overflowY) && el.scrollHeight > el.clientHeight || /auto|scroll/.test(style.overflowX) && el.scrollWidth > el.clientWidth;
871
+ };
872
+ function windowScrolls() {
873
+ const root = scroller();
874
+ const style = getComputedStyle(root);
875
+ const hidden = (axis) => /hidden|clip/.test(axis);
876
+ const down = root.scrollHeight > root.clientHeight && !hidden(style.overflowY);
877
+ const across = root.scrollWidth > root.clientWidth && !hidden(style.overflowX);
878
+ return down || across || document.body !== null && scrollsOwnBox(document.body);
879
+ }
880
+ function tabReachesSomething() {
881
+ if (document.querySelector(FOCUSABLE)) return true;
882
+ for (const el of document.body?.querySelectorAll("*") ?? []) {
883
+ if (el.shadowRoot || el.localName.includes("-") || scrollsOwnBox(el)) return true;
884
+ }
885
+ return false;
886
+ }
887
+ function keepTabStop() {
888
+ if (!isChromium || matchMedia("(pointer: coarse)").matches) return;
889
+ let ours = null;
890
+ let ring = false;
891
+ let timer = null;
892
+ let done = false;
893
+ let keptScroll2 = null;
894
+ let pointing = false;
895
+ const showRing = (on) => {
896
+ if (on === ring) return;
897
+ ring = on;
898
+ post({ __frame_page_ring: on });
899
+ };
900
+ const leave = () => {
901
+ done = true;
902
+ showRing(false);
903
+ if (timer) clearTimeout(timer);
904
+ watcher.disconnect();
905
+ sizes.disconnect();
906
+ };
907
+ const check = () => {
908
+ timer = null;
909
+ const body = document.body;
910
+ if (done || !body) return;
911
+ if (body !== ours && body.hasAttribute("tabindex")) return leave();
912
+ const want = windowScrolls() && !tabReachesSomething();
913
+ if (want === (body === ours)) return;
914
+ if (want) body.setAttribute("tabindex", "0");
915
+ else {
916
+ body.removeAttribute("tabindex");
917
+ showRing(false);
918
+ }
919
+ ours = want ? body : null;
920
+ watcher.takeRecords();
921
+ };
922
+ const later = () => {
923
+ if (!done && !timer) timer = setTimeout(check, TAB_STOP_DELAY_MS);
924
+ };
925
+ const watcher = new MutationObserver((records) => {
926
+ if (records.some((r) => r.target === document.body && r.attributeName === "tabindex")) leave();
927
+ else later();
928
+ });
929
+ const sizes = new ResizeObserver(later);
930
+ watcher.observe(document, { subtree: true, childList: true, attributes: true, attributeFilter: ["tabindex", "href", "controls", "contenteditable"] });
931
+ sizes.observe(document.documentElement);
932
+ const keepScroll = () => {
933
+ if (pointing) return;
934
+ const root = scroller();
935
+ keptScroll2 = { top: root.scrollTop, left: root.scrollLeft };
936
+ setTimeout(() => keptScroll2 = null, 0);
937
+ };
938
+ addEventListener("resize", later);
939
+ addEventListener("focus", keepScroll);
940
+ addEventListener(
941
+ "keydown",
942
+ (ev) => {
943
+ if (done) return;
944
+ if (ev.key === "Tab") keepScroll();
945
+ else if (ours?.matches(":focus-visible")) showRing(true);
946
+ },
947
+ true
948
+ );
949
+ addEventListener(
950
+ "pointerdown",
951
+ () => {
952
+ pointing = true;
953
+ setTimeout(() => pointing = false, 0);
954
+ },
955
+ true
956
+ );
957
+ document.addEventListener("load", later, true);
958
+ document.addEventListener(
959
+ "focus",
960
+ (ev) => {
961
+ if (done) return;
962
+ if (keptScroll2 && ev.target === ours) scroller().scrollTo({ ...keptScroll2, behavior: "instant" });
963
+ keptScroll2 = null;
964
+ showRing(ev.target === ours && ours?.matches(":focus-visible") === true);
965
+ },
966
+ true
967
+ );
968
+ document.addEventListener("blur", () => showRing(false), true);
969
+ void document.fonts?.ready.then(later, () => {
970
+ });
971
+ later();
972
+ }
973
+ const PRINT_LOOK_MS = 250;
974
+ const PRINT_SETTLE_LIMIT_MS = 5e4;
975
+ let printUndo = [];
976
+ let printTimer;
977
+ let sentToPrint = false;
978
+ function* styleParts(sources) {
979
+ for (const source of sources) {
980
+ const own = source;
981
+ if (own.media instanceof MediaList) yield own.media;
982
+ if (own.style instanceof CSSStyleDeclaration) yield own.style;
983
+ const inner = source instanceof CSSImportRule ? source.styleSheet : source;
984
+ let rules;
985
+ try {
986
+ rules = inner?.cssRules;
987
+ } catch {
988
+ }
989
+ if (rules) yield* styleParts(Array.from(rules));
990
+ }
991
+ }
992
+ function answerAsOnPaper(media, undo) {
993
+ const written = media.mediaText;
994
+ if (!/print|screen|height|orientation|aspect/.test(written)) return;
995
+ const holds = matchMedia(written.replace(/print/g, "all").replace(/screen/g, "tty")).matches;
996
+ media.mediaText = holds ? "all" : "not all";
997
+ undo.push(() => {
998
+ media.mediaText = written;
999
+ });
1000
+ }
1001
+ function pinViewportHeights(style, undo) {
1002
+ for (const name of Array.from(style)) {
1003
+ const written = style.getPropertyValue(name);
1004
+ if (!/\d[dsl]?vh/.test(written)) continue;
1005
+ const priority = style.getPropertyPriority(name);
1006
+ style.setProperty(name, written.replace(/([\d.]+)[dsl]?vh/g, (_all, amount) => `${Number(amount) * innerHeight / 100}px`), priority);
1007
+ undo.push(() => style.setProperty(name, written, priority));
1008
+ }
1009
+ }
1010
+ function unrollScrollers(undo) {
1011
+ for (const box of document.querySelectorAll("body, body *")) {
1012
+ if (!(box instanceof HTMLElement) || box.scrollHeight <= box.clientHeight || !/auto|scroll/.test(getComputedStyle(box).overflowY)) continue;
1013
+ const { height, maxHeight } = box.style;
1014
+ box.style.height = "auto";
1015
+ box.style.maxHeight = "none";
1016
+ undo.push(() => {
1017
+ box.style.height = height;
1018
+ box.style.maxHeight = maxHeight;
1019
+ });
1020
+ }
1021
+ }
1022
+ function asOnPaper(undo) {
1023
+ const parts = [...styleParts([...document.styleSheets, ...document.adoptedStyleSheets ?? []])];
1024
+ for (const el of document.querySelectorAll("[style*=vh]")) if (el instanceof HTMLElement || el instanceof SVGElement) parts.push(el.style);
1025
+ for (const part of parts) {
1026
+ if (part instanceof MediaList) answerAsOnPaper(part, undo);
1027
+ else pinViewportHeights(part, undo);
1028
+ }
1029
+ unrollScrollers(undo);
1030
+ }
1031
+ function cutIntoSheets(undo) {
1032
+ const topOf = (el) => el.getBoundingClientRect().top + scrollY;
1033
+ const breaks = [];
1034
+ const starts = [0];
1035
+ for (const el of document.body?.querySelectorAll("*") ?? []) {
1036
+ if (!(el instanceof HTMLElement) || getComputedStyle(el).breakBefore !== "page") continue;
1037
+ const top = topOf(el);
1038
+ if (top > starts[starts.length - 1]) {
1039
+ breaks.push(el);
1040
+ starts.push(top);
1041
+ }
1042
+ }
1043
+ const end = document.documentElement.scrollHeight;
1044
+ const page = Math.ceil(Math.max(...starts.map((top, i) => (starts[i + 1] ?? end) - top)));
1045
+ breaks.forEach((el, i) => {
1046
+ const written = el.style.marginTop;
1047
+ undo.push(() => {
1048
+ el.style.marginTop = written;
1049
+ });
1050
+ el.style.marginTop = `${page}px`;
1051
+ const marginStart = topOf(el) - page;
1052
+ el.style.marginTop = `${(i + 1) * page - marginStart}px`;
1053
+ });
1054
+ return { h: (breaks.length + 1) * page, page };
1055
+ }
1056
+ function unprint() {
1057
+ clearTimeout(printTimer);
1058
+ removeEventListener("pointerdown", unprint, true);
1059
+ const steps = printUndo;
1060
+ printUndo = [];
1061
+ while (steps.length) steps.pop()();
1062
+ }
1063
+ function layOutForPrint(request) {
1064
+ unprint();
1065
+ sentToPrint = false;
1066
+ const undo = printUndo;
1067
+ undo.push(() => dispatchEvent(new CustomEvent("afterprint", { detail: sentToPrint })));
1068
+ for (const el of document.querySelectorAll("*")) {
1069
+ const { scrollTop } = el;
1070
+ if (scrollTop)
1071
+ undo.push(() => {
1072
+ el.scrollTop = scrollTop;
1073
+ });
1074
+ }
1075
+ const root = document.documentElement.style;
1076
+ for (const [name, value] of [
1077
+ ["scrollbar-width", "none"],
1078
+ ["print-color-adjust", "exact"]
1079
+ ]) {
1080
+ const written = root.getPropertyValue(name);
1081
+ const priority = root.getPropertyPriority(name);
1082
+ root.setProperty(name, value);
1083
+ undo.push(() => root.setProperty(name, written, priority));
1084
+ }
1085
+ const body = document.body;
1086
+ const wasInert = body?.inert ?? false;
1087
+ const letGo = () => {
1088
+ if (body) body.inert = wasInert;
1089
+ };
1090
+ if (body) {
1091
+ body.inert = true;
1092
+ undo.push(letGo);
1093
+ }
1094
+ asOnPaper(undo);
1095
+ dispatchEvent(new Event("beforeprint"));
1096
+ const giveUpAt = Date.now() + PRINT_SETTLE_LIMIT_MS;
1097
+ let lastHeight = -1;
1098
+ const look = () => {
1099
+ asOnPaper(undo);
1100
+ const height = document.querySelector("[aria-busy=true]") ? -1 : document.documentElement.scrollHeight;
1101
+ const still = height !== -1 && height === lastHeight;
1102
+ lastHeight = height;
1103
+ if (!still && Date.now() < giveUpAt) {
1104
+ printTimer = setTimeout(look, PRINT_LOOK_MS);
1105
+ return;
1106
+ }
1107
+ const sheets = cutIntoSheets(undo);
1108
+ printTimer = setTimeout(() => {
1109
+ letGo();
1110
+ sentToPrint = true;
1111
+ post({ __frame_print_ready: true, request, ...sheets });
1112
+ addEventListener("pointerdown", unprint, true);
1113
+ }, PRINT_LOOK_MS);
1114
+ };
1115
+ printTimer = setTimeout(look, PRINT_LOOK_MS);
1116
+ }
1117
+ fromShell.set("__frame_chrome_cmd", (m) => {
1118
+ if (m.cmd === "export" && m.format === "print" && typeof m.request === "string") layOutForPrint(m.request);
1119
+ });
1120
+ fromShell.set("__frame_print_done", (m) => {
1121
+ sentToPrint = m.printed === true;
1122
+ unprint();
1123
+ });
1124
+ let shellHidden = false;
1125
+ let heldFocus = null;
1126
+ const guardedWindows = /* @__PURE__ */ new WeakSet();
1127
+ const isElement = (value) => isRecord(value) && value.nodeType === 1;
1128
+ const takesTyping = (el) => el.matches(TYPING_FIELD) || el.isContentEditable === true;
1129
+ function holdFocus(target, method) {
1130
+ heldFocus = isElement(target) && target.isConnected && target !== target.ownerDocument.body && takesTyping(target) ? target : null;
1131
+ const field = target;
1132
+ if (method === "select" && typeof field.setSelectionRange === "function") {
1133
+ try {
1134
+ field.setSelectionRange(0, (field.value ?? "").length);
1135
+ } catch {
1136
+ }
1137
+ }
1138
+ }
1139
+ function guardFocus(win) {
1140
+ if (guardedWindows.has(win)) return;
1141
+ guardedWindows.add(win);
1142
+ const wrap = (owner, method) => {
1143
+ const original = owner ? Reflect.get(owner, method) : void 0;
1144
+ if (!owner || typeof original !== "function") return;
1145
+ Reflect.set(owner, method, function(...args) {
1146
+ if (!shellHidden || document.hasFocus() || navigator.userActivation?.isActive === true) return Reflect.apply(original, this, args);
1147
+ holdFocus(this, method);
1148
+ return void 0;
1149
+ });
1150
+ };
1151
+ if (/\{\s*\[native code\]\s*\}$/.test(String(win.focus))) wrap(win, "focus");
1152
+ for (const kind of [win.HTMLElement, win.SVGElement, win.MathMLElement]) wrap(kind?.prototype, "focus");
1153
+ wrap(win.HTMLInputElement?.prototype, "select");
1154
+ wrap(win.HTMLTextAreaElement?.prototype, "select");
1155
+ const guardFrame = (el) => {
1156
+ try {
1157
+ const inner = el.localName === "iframe" ? el.contentWindow : null;
1158
+ if (inner?.document) guardFocus(inner);
1159
+ } catch {
1160
+ }
1161
+ };
1162
+ win.document.addEventListener("load", (ev) => isElement(ev.target) && guardFrame(ev.target), true);
1163
+ for (const el of win.document.querySelectorAll("iframe")) guardFrame(el);
1164
+ }
1165
+ function keepHeldFocus() {
1166
+ document.addEventListener("focusin", () => heldFocus = null, true);
1167
+ document.addEventListener("pointerdown", () => heldFocus = null, true);
1168
+ addEventListener("focus", () => {
1169
+ const el = heldFocus;
1170
+ heldFocus = null;
1171
+ const active = document.activeElement;
1172
+ if (!el || active && active !== document.body) return;
1173
+ setTimeout(() => {
1174
+ const now = document.activeElement;
1175
+ if (!el.isConnected || now && now !== document.body) return;
1176
+ try {
1177
+ el.focus({ preventScroll: true });
1178
+ } catch {
1179
+ }
1180
+ }, 0);
1181
+ });
1182
+ }
1183
+ function takeInit(init) {
1184
+ if (!isRecord(init)) return;
1185
+ takeHostKeys(init.hostKeys);
1186
+ if (typeof init.hostVisible === "boolean") shellHidden = !init.hostVisible;
1187
+ }
1188
+ takeInit(w.__openArtifactsShellInit);
1189
+ fromShell.set("__frame_init", (m) => takeInit(m.__frame_init));
1190
+ fromShell.set("__frame_host_visible", (m) => {
1191
+ const shown = isRecord(m.__frame_host_visible) ? m.__frame_host_visible.visible : void 0;
1192
+ if (typeof shown === "boolean") shellHidden = !shown;
1193
+ });
1194
+ const TAP_RULES = "a[href],button,input,label,select,summary,textarea,[role=button],[role=checkbox],[role=link],[role=listbox],[role=menu],[role=radio],[role=switch],[role=tab]{touch-action:manipulation}";
1195
+ function pageLayers() {
1196
+ const out = [];
1197
+ const walk = (rules, parent, unsure) => {
1198
+ for (const rule of rules) {
1199
+ if (rule instanceof CSSStyleRule) continue;
1200
+ if (rule instanceof CSSLayerBlockRule && !rule.name && !rule.cssText.includes("touch-action")) continue;
1201
+ const conditional = unsure || rule instanceof CSSConditionRule || rule instanceof CSSImportRule && (rule.media.length > 0 || !!rule.supportsText);
1202
+ let names = [];
1203
+ if (rule instanceof CSSLayerStatementRule) names = [...rule.nameList];
1204
+ else if (rule instanceof CSSLayerBlockRule) names = [rule.name];
1205
+ else if (rule instanceof CSSImportRule) names = [rule.layerName];
1206
+ let inside = parent;
1207
+ for (const name of names) {
1208
+ if (typeof name !== "string") continue;
1209
+ out.push({ name: parent + name, unsure: conditional || !name });
1210
+ inside = `${parent}${name}.`;
1211
+ }
1212
+ let nested2;
1213
+ try {
1214
+ nested2 = rule instanceof CSSImportRule ? rule.styleSheet?.cssRules : rule.cssRules;
1215
+ } catch {
1216
+ }
1217
+ if (nested2) walk(Array.from(nested2), inside, conditional);
1218
+ }
1219
+ };
1220
+ for (const sheet of [...document.styleSheets, ...document.adoptedStyleSheets.filter((s) => s !== tapSheet)]) {
1221
+ const conditional = sheet.media.length > 0 || sheet.disabled;
1222
+ let rules;
1223
+ try {
1224
+ rules = sheet.cssRules;
1225
+ } catch {
1226
+ }
1227
+ if (rules) walk(Array.from(rules), "", conditional);
1228
+ }
1229
+ return out;
1230
+ }
1231
+ function tapLayerSpot(layers) {
1232
+ let spot = "";
1233
+ for (; ; ) {
1234
+ const first = layers.find((l) => !spot || l.name.startsWith(`${spot}.`));
1235
+ if (!first) return spot;
1236
+ if (first.unsure) return null;
1237
+ spot = first.name;
1238
+ }
1239
+ }
1240
+ let tapSheet = null;
1241
+ function tapsAtOnce() {
1242
+ const sheet = new CSSStyleSheet();
1243
+ tapSheet = sheet;
1244
+ let written = null;
1245
+ let queued = false;
1246
+ const update = () => {
1247
+ queued = false;
1248
+ const others = document.adoptedStyleSheets.filter((s) => s !== sheet);
1249
+ if (document.adoptedStyleSheets[others.length] !== sheet) document.adoptedStyleSheets = [...others, sheet];
1250
+ const spot = tapLayerSpot(pageLayers());
1251
+ const text = spot === null ? "" : `@layer ${spot ? `${spot}.frame-tap` : ""}{${TAP_RULES}}`;
1252
+ if (text !== written) {
1253
+ written = text;
1254
+ sheet.replaceSync(text);
1255
+ }
1256
+ };
1257
+ const later = () => {
1258
+ if (queued) return;
1259
+ queued = true;
1260
+ requestIdleCallback(update, { timeout: 500 });
1261
+ };
1262
+ for (const type of ["load", "error", "DOMContentLoaded", "pointerdown"]) document.addEventListener(type, later, true);
1263
+ later();
1264
+ }
1265
+ function tapsAtOnceOnTouch() {
1266
+ if (!matchMedia("(pointer: coarse), (hover: none)").matches || CSS.supports("-webkit-touch-callout", "default")) return;
1267
+ if (!("CSSLayerBlockRule" in window) || !("requestIdleCallback" in window)) return;
1268
+ const check = () => {
1269
+ if (innerWidth <= screen.width && !navigator.userAgent.includes("X11; Linux")) return;
1270
+ removeEventListener("resize", check);
1271
+ tapsAtOnce();
1272
+ };
1273
+ addEventListener("resize", check);
1274
+ check();
1275
+ }
1276
+ const MODULE_LOAD_MS = 15e3;
1277
+ const earlyErrors = [];
1278
+ const noteEarlyError = (error) => {
1279
+ if (earlyErrors.length < 10) earlyErrors.push(error instanceof Error ? error.message : String(error));
1280
+ };
1281
+ const onEarlyError = (ev) => noteEarlyError(ev.message);
1282
+ const onEarlyRejection = (ev) => noteEarlyError(ev.reason);
1283
+ function onDemand(slot, src, takesErrors = false) {
1284
+ let handle = null;
1285
+ let waiting = null;
1286
+ return (command) => {
1287
+ if (handle) return handle(command);
1288
+ if (waiting) {
1289
+ if (waiting.length < 32) waiting.push(command);
1290
+ return;
1291
+ }
1292
+ waiting = [command];
1293
+ let over = false;
1294
+ const done = () => {
1295
+ if (over) return;
1296
+ over = true;
1297
+ clearTimeout(timer);
1298
+ Reflect.deleteProperty(window, slot);
1299
+ if (!handle) waiting = null;
1300
+ };
1301
+ const timer = setTimeout(done, MODULE_LOAD_MS);
1302
+ Object.defineProperty(window, slot, {
1303
+ configurable: true,
1304
+ value: (start) => {
1305
+ if (handle || over) return;
1306
+ if (takesErrors) {
1307
+ removeEventListener("error", onEarlyError);
1308
+ removeEventListener("unhandledrejection", onEarlyRejection);
1309
+ }
1310
+ const started = start({ send: post, errors: takesErrors ? earlyErrors.splice(0) : [] });
1311
+ handle = started;
1312
+ const queued = waiting ?? [];
1313
+ waiting = null;
1314
+ done();
1315
+ for (const m of queued) started(m);
1316
+ }
1317
+ });
1318
+ const script = document.createElement("script");
1319
+ script.src = src;
1320
+ script.async = true;
1321
+ const gone = () => {
1322
+ script.remove();
1323
+ done();
1324
+ };
1325
+ script.addEventListener("load", gone);
1326
+ script.addEventListener("error", gone);
1327
+ (document.head || document.documentElement).append(script);
1328
+ };
1329
+ }
1330
+ const review = onDemand("__openArtifactsReview", "/_runtime/open-artifacts-review.js", true);
1331
+ fromShell.set("__fr_cmd", (m) => {
1332
+ if (isRecord(m.__fr_cmd)) review(m.__fr_cmd);
1333
+ });
1334
+ const translation = onDemand("__openArtifactsTranslate", "/_runtime/open-artifacts-translate.js");
1335
+ fromShell.set("__ft_cmd", (m) => {
1336
+ if (isRecord(m.__ft_cmd)) translation(m.__ft_cmd);
1337
+ });
1338
+ fromShell.set("__ft_xlr", (m) => {
1339
+ if (isRecord(m.__ft_xlr)) translation({ action: "reply", reply: m.__ft_xlr });
1340
+ });
1341
+ if (framed && !nested) {
1342
+ addEventListener("keydown", onHostKeyFirst, true);
1343
+ addEventListener("keydown", onHostKeyLast);
1344
+ keepTabStop();
1345
+ guardFocus(window);
1346
+ keepHeldFocus();
1347
+ tapsAtOnceOnTouch();
1348
+ addEventListener("error", onEarlyError);
1349
+ addEventListener("unhandledrejection", onEarlyRejection);
1350
+ }
1351
+ })();
1352
+ })();