@dudko.dev/agent-web-ui 0.0.0 → 0.0.2

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 (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-7O64ZI6Z.js +125 -0
  10. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  11. package/dist/chunk-EL2YCROY.js +127 -0
  12. package/dist/chunk-EL2YCROY.js.map +1 -0
  13. package/dist/chunk-GB7RZJMG.js +98 -0
  14. package/dist/chunk-GB7RZJMG.js.map +1 -0
  15. package/dist/chunk-KZQB35LS.js +22 -0
  16. package/dist/chunk-KZQB35LS.js.map +1 -0
  17. package/dist/chunk-SVYHDLAZ.js +348 -0
  18. package/dist/chunk-SVYHDLAZ.js.map +1 -0
  19. package/dist/chunk-VCR7LU7J.js +348 -0
  20. package/dist/chunk-VCR7LU7J.js.map +1 -0
  21. package/dist/chunk-WFM6B7CL.js +406 -0
  22. package/dist/chunk-WFM6B7CL.js.map +1 -0
  23. package/dist/chunk-WZ7K7JIP.js +348 -0
  24. package/dist/chunk-WZ7K7JIP.js.map +1 -0
  25. package/dist/chunk-ZBHESK6V.js +1440 -0
  26. package/dist/chunk-ZBHESK6V.js.map +1 -0
  27. package/dist/controller.cjs +1891 -0
  28. package/dist/controller.cjs.map +1 -0
  29. package/dist/controller.d.cts +253 -0
  30. package/dist/controller.d.ts +253 -0
  31. package/dist/controller.js +482 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/en-Dg2MtzcJ.d.cts +348 -0
  34. package/dist/en-Dg2MtzcJ.d.ts +348 -0
  35. package/dist/index.cjs +4276 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +997 -0
  38. package/dist/index.d.ts +997 -0
  39. package/dist/index.js +2494 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/labels-B5xpIGf_.d.cts +25 -0
  42. package/dist/labels-B5xpIGf_.d.ts +25 -0
  43. package/dist/labels-CmiTBLWD.d.cts +1176 -0
  44. package/dist/labels-DH1ESUtm.d.ts +1176 -0
  45. package/dist/locales/be.cjs +806 -0
  46. package/dist/locales/be.cjs.map +1 -0
  47. package/dist/locales/be.d.cts +16 -0
  48. package/dist/locales/be.d.ts +16 -0
  49. package/dist/locales/be.js +380 -0
  50. package/dist/locales/be.js.map +1 -0
  51. package/dist/locales/bg.cjs +759 -0
  52. package/dist/locales/bg.cjs.map +1 -0
  53. package/dist/locales/bg.d.cts +16 -0
  54. package/dist/locales/bg.d.ts +16 -0
  55. package/dist/locales/bg.js +333 -0
  56. package/dist/locales/bg.js.map +1 -0
  57. package/dist/locales/ca.cjs +785 -0
  58. package/dist/locales/ca.cjs.map +1 -0
  59. package/dist/locales/ca.d.cts +16 -0
  60. package/dist/locales/ca.d.ts +16 -0
  61. package/dist/locales/ca.js +359 -0
  62. package/dist/locales/ca.js.map +1 -0
  63. package/dist/locales/cs.cjs +806 -0
  64. package/dist/locales/cs.cjs.map +1 -0
  65. package/dist/locales/cs.d.cts +16 -0
  66. package/dist/locales/cs.d.ts +16 -0
  67. package/dist/locales/cs.js +380 -0
  68. package/dist/locales/cs.js.map +1 -0
  69. package/dist/locales/da.cjs +759 -0
  70. package/dist/locales/da.cjs.map +1 -0
  71. package/dist/locales/da.d.cts +16 -0
  72. package/dist/locales/da.d.ts +16 -0
  73. package/dist/locales/da.js +333 -0
  74. package/dist/locales/da.js.map +1 -0
  75. package/dist/locales/de.cjs +768 -0
  76. package/dist/locales/de.cjs.map +1 -0
  77. package/dist/locales/de.d.cts +16 -0
  78. package/dist/locales/de.d.ts +16 -0
  79. package/dist/locales/de.js +342 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/el.cjs +768 -0
  82. package/dist/locales/el.cjs.map +1 -0
  83. package/dist/locales/el.d.cts +16 -0
  84. package/dist/locales/el.d.ts +16 -0
  85. package/dist/locales/el.js +342 -0
  86. package/dist/locales/el.js.map +1 -0
  87. package/dist/locales/en.cjs +765 -0
  88. package/dist/locales/en.cjs.map +1 -0
  89. package/dist/locales/en.d.cts +12 -0
  90. package/dist/locales/en.d.ts +12 -0
  91. package/dist/locales/en.js +339 -0
  92. package/dist/locales/en.js.map +1 -0
  93. package/dist/locales/es-419.cjs +793 -0
  94. package/dist/locales/es-419.cjs.map +1 -0
  95. package/dist/locales/es-419.d.cts +18 -0
  96. package/dist/locales/es-419.d.ts +18 -0
  97. package/dist/locales/es-419.js +26 -0
  98. package/dist/locales/es-419.js.map +1 -0
  99. package/dist/locales/es.cjs +781 -0
  100. package/dist/locales/es.cjs.map +1 -0
  101. package/dist/locales/es.d.cts +16 -0
  102. package/dist/locales/es.d.ts +16 -0
  103. package/dist/locales/es.js +14 -0
  104. package/dist/locales/es.js.map +1 -0
  105. package/dist/locales/fi.cjs +765 -0
  106. package/dist/locales/fi.cjs.map +1 -0
  107. package/dist/locales/fi.d.cts +16 -0
  108. package/dist/locales/fi.d.ts +16 -0
  109. package/dist/locales/fi.js +339 -0
  110. package/dist/locales/fi.js.map +1 -0
  111. package/dist/locales/fr-CA.cjs +789 -0
  112. package/dist/locales/fr-CA.cjs.map +1 -0
  113. package/dist/locales/fr-CA.d.cts +19 -0
  114. package/dist/locales/fr-CA.d.ts +19 -0
  115. package/dist/locales/fr-CA.js +22 -0
  116. package/dist/locales/fr-CA.js.map +1 -0
  117. package/dist/locales/fr.cjs +781 -0
  118. package/dist/locales/fr.cjs.map +1 -0
  119. package/dist/locales/fr.d.cts +16 -0
  120. package/dist/locales/fr.d.ts +16 -0
  121. package/dist/locales/fr.js +14 -0
  122. package/dist/locales/fr.js.map +1 -0
  123. package/dist/locales/gn.cjs +762 -0
  124. package/dist/locales/gn.cjs.map +1 -0
  125. package/dist/locales/gn.d.cts +18 -0
  126. package/dist/locales/gn.d.ts +18 -0
  127. package/dist/locales/gn.js +336 -0
  128. package/dist/locales/gn.js.map +1 -0
  129. package/dist/locales/hr.cjs +781 -0
  130. package/dist/locales/hr.cjs.map +1 -0
  131. package/dist/locales/hr.d.cts +16 -0
  132. package/dist/locales/hr.d.ts +16 -0
  133. package/dist/locales/hr.js +355 -0
  134. package/dist/locales/hr.js.map +1 -0
  135. package/dist/locales/ht.cjs +762 -0
  136. package/dist/locales/ht.cjs.map +1 -0
  137. package/dist/locales/ht.d.cts +18 -0
  138. package/dist/locales/ht.d.ts +18 -0
  139. package/dist/locales/ht.js +336 -0
  140. package/dist/locales/ht.js.map +1 -0
  141. package/dist/locales/hu.cjs +765 -0
  142. package/dist/locales/hu.cjs.map +1 -0
  143. package/dist/locales/hu.d.cts +16 -0
  144. package/dist/locales/hu.d.ts +16 -0
  145. package/dist/locales/hu.js +339 -0
  146. package/dist/locales/hu.js.map +1 -0
  147. package/dist/locales/index.cjs +543 -0
  148. package/dist/locales/index.cjs.map +1 -0
  149. package/dist/locales/index.d.cts +40 -0
  150. package/dist/locales/index.d.ts +40 -0
  151. package/dist/locales/index.js +105 -0
  152. package/dist/locales/index.js.map +1 -0
  153. package/dist/locales/it.cjs +789 -0
  154. package/dist/locales/it.cjs.map +1 -0
  155. package/dist/locales/it.d.cts +16 -0
  156. package/dist/locales/it.d.ts +16 -0
  157. package/dist/locales/it.js +363 -0
  158. package/dist/locales/it.js.map +1 -0
  159. package/dist/locales/nb.cjs +759 -0
  160. package/dist/locales/nb.cjs.map +1 -0
  161. package/dist/locales/nb.d.cts +16 -0
  162. package/dist/locales/nb.d.ts +16 -0
  163. package/dist/locales/nb.js +333 -0
  164. package/dist/locales/nb.js.map +1 -0
  165. package/dist/locales/nl.cjs +765 -0
  166. package/dist/locales/nl.cjs.map +1 -0
  167. package/dist/locales/nl.d.cts +16 -0
  168. package/dist/locales/nl.d.ts +16 -0
  169. package/dist/locales/nl.js +339 -0
  170. package/dist/locales/nl.js.map +1 -0
  171. package/dist/locales/pl.cjs +806 -0
  172. package/dist/locales/pl.cjs.map +1 -0
  173. package/dist/locales/pl.d.cts +16 -0
  174. package/dist/locales/pl.d.ts +16 -0
  175. package/dist/locales/pl.js +380 -0
  176. package/dist/locales/pl.js.map +1 -0
  177. package/dist/locales/pt-BR.cjs +785 -0
  178. package/dist/locales/pt-BR.cjs.map +1 -0
  179. package/dist/locales/pt-BR.d.cts +16 -0
  180. package/dist/locales/pt-BR.d.ts +16 -0
  181. package/dist/locales/pt-BR.js +359 -0
  182. package/dist/locales/pt-BR.js.map +1 -0
  183. package/dist/locales/pt.cjs +789 -0
  184. package/dist/locales/pt.cjs.map +1 -0
  185. package/dist/locales/pt.d.cts +16 -0
  186. package/dist/locales/pt.d.ts +16 -0
  187. package/dist/locales/pt.js +363 -0
  188. package/dist/locales/pt.js.map +1 -0
  189. package/dist/locales/qu.cjs +768 -0
  190. package/dist/locales/qu.cjs.map +1 -0
  191. package/dist/locales/qu.d.cts +18 -0
  192. package/dist/locales/qu.d.ts +18 -0
  193. package/dist/locales/qu.js +342 -0
  194. package/dist/locales/qu.js.map +1 -0
  195. package/dist/locales/ro.cjs +781 -0
  196. package/dist/locales/ro.cjs.map +1 -0
  197. package/dist/locales/ro.d.cts +16 -0
  198. package/dist/locales/ro.d.ts +16 -0
  199. package/dist/locales/ro.js +355 -0
  200. package/dist/locales/ro.js.map +1 -0
  201. package/dist/locales/ru.cjs +801 -0
  202. package/dist/locales/ru.cjs.map +1 -0
  203. package/dist/locales/ru.d.cts +16 -0
  204. package/dist/locales/ru.d.ts +16 -0
  205. package/dist/locales/ru.js +375 -0
  206. package/dist/locales/ru.js.map +1 -0
  207. package/dist/locales/sk.cjs +806 -0
  208. package/dist/locales/sk.cjs.map +1 -0
  209. package/dist/locales/sk.d.cts +16 -0
  210. package/dist/locales/sk.d.ts +16 -0
  211. package/dist/locales/sk.js +380 -0
  212. package/dist/locales/sk.js.map +1 -0
  213. package/dist/locales/sq.cjs +765 -0
  214. package/dist/locales/sq.cjs.map +1 -0
  215. package/dist/locales/sq.d.cts +16 -0
  216. package/dist/locales/sq.d.ts +16 -0
  217. package/dist/locales/sq.js +339 -0
  218. package/dist/locales/sq.js.map +1 -0
  219. package/dist/locales/sr-Latn.cjs +853 -0
  220. package/dist/locales/sr-Latn.cjs.map +1 -0
  221. package/dist/locales/sr-Latn.d.cts +19 -0
  222. package/dist/locales/sr-Latn.d.ts +19 -0
  223. package/dist/locales/sr-Latn.js +86 -0
  224. package/dist/locales/sr-Latn.js.map +1 -0
  225. package/dist/locales/sr.cjs +781 -0
  226. package/dist/locales/sr.cjs.map +1 -0
  227. package/dist/locales/sr.d.cts +16 -0
  228. package/dist/locales/sr.d.ts +16 -0
  229. package/dist/locales/sr.js +14 -0
  230. package/dist/locales/sr.js.map +1 -0
  231. package/dist/locales/sv.cjs +765 -0
  232. package/dist/locales/sv.cjs.map +1 -0
  233. package/dist/locales/sv.d.cts +16 -0
  234. package/dist/locales/sv.d.ts +16 -0
  235. package/dist/locales/sv.js +339 -0
  236. package/dist/locales/sv.js.map +1 -0
  237. package/dist/locales/tr.cjs +762 -0
  238. package/dist/locales/tr.cjs.map +1 -0
  239. package/dist/locales/tr.d.cts +16 -0
  240. package/dist/locales/tr.d.ts +16 -0
  241. package/dist/locales/tr.js +336 -0
  242. package/dist/locales/tr.js.map +1 -0
  243. package/dist/locales/uk.cjs +806 -0
  244. package/dist/locales/uk.cjs.map +1 -0
  245. package/dist/locales/uk.d.cts +16 -0
  246. package/dist/locales/uk.d.ts +16 -0
  247. package/dist/locales/uk.js +380 -0
  248. package/dist/locales/uk.js.map +1 -0
  249. package/dist/markdown.cjs +620 -0
  250. package/dist/markdown.cjs.map +1 -0
  251. package/dist/markdown.d.cts +153 -0
  252. package/dist/markdown.d.ts +153 -0
  253. package/dist/markdown.js +573 -0
  254. package/dist/markdown.js.map +1 -0
  255. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  256. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  257. package/dist/mcp-app-sandbox.cjs +323 -0
  258. package/dist/mcp-app-sandbox.cjs.map +1 -0
  259. package/dist/mcp-app-sandbox.d.cts +70 -0
  260. package/dist/mcp-app-sandbox.d.ts +70 -0
  261. package/dist/mcp-app-sandbox.js +209 -0
  262. package/dist/mcp-app-sandbox.js.map +1 -0
  263. package/dist/mcp-app.cjs +980 -0
  264. package/dist/mcp-app.cjs.map +1 -0
  265. package/dist/mcp-app.d.cts +491 -0
  266. package/dist/mcp-app.d.ts +491 -0
  267. package/dist/mcp-app.js +816 -0
  268. package/dist/mcp-app.js.map +1 -0
  269. package/dist/pipeline.cjs +845 -0
  270. package/dist/pipeline.cjs.map +1 -0
  271. package/dist/pipeline.css +1407 -0
  272. package/dist/pipeline.d.cts +348 -0
  273. package/dist/pipeline.d.ts +348 -0
  274. package/dist/pipeline.js +778 -0
  275. package/dist/pipeline.js.map +1 -0
  276. package/dist/questions-Dw--IEjT.d.cts +100 -0
  277. package/dist/questions-Dw--IEjT.d.ts +100 -0
  278. package/dist/styles.css +4109 -0
  279. package/dist/types-CQquuZpl.d.cts +19 -0
  280. package/dist/types-CXZfZVP5.d.ts +19 -0
  281. package/dist/types-DnBCok3z.d.cts +994 -0
  282. package/dist/types-DnBCok3z.d.ts +994 -0
  283. package/package.json +165 -8
@@ -0,0 +1,127 @@
1
+ // src/html-preview.ts
2
+ var sandboxedCsp = (scripts = false) => [
3
+ "default-src 'none'",
4
+ scripts ? "script-src 'unsafe-inline'" : "script-src 'none'",
5
+ "style-src 'unsafe-inline'",
6
+ "img-src data: blob:",
7
+ "font-src data:",
8
+ "media-src data: blob:",
9
+ "connect-src 'none'",
10
+ "frame-src 'none'",
11
+ "child-src 'none'",
12
+ "object-src 'none'",
13
+ "form-action 'none'",
14
+ "base-uri 'none'",
15
+ "webrtc 'block'"
16
+ ].join("; ");
17
+ var sandboxTokens = (scripts = false) => scripts ? "allow-scripts" : "";
18
+ var escapeAttribute = (value) => value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
19
+ var cspMetaTag = (policy) => `<meta http-equiv="Content-Security-Policy" content="${escapeAttribute(policy)}">`;
20
+ var cspMeta = (scripts) => cspMetaTag(sandboxedCsp(scripts));
21
+ var DOCTYPE = /^[\t\n\f\r ]*<!doctype[^>]*>/i;
22
+ var withCspFirst = (html, scripts = false) => withPolicyFirst(html, sandboxedCsp(scripts));
23
+ var withPolicyFirst = (html, policy) => {
24
+ const doctype = DOCTYPE.exec(html)?.[0] ?? "";
25
+ return `${doctype}${cspMetaTag(policy)}${html.slice(doctype.length)}`;
26
+ };
27
+ var buildSandboxedDocument = (html, { scripts = false } = {}) => "<!doctype html><html><head>" + cspMeta(scripts) + `<style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}iframe{display:block;border:0;width:100%;height:100%}</style></head><body><iframe sandbox="${sandboxTokens(scripts)}" referrerpolicy="no-referrer" srcdoc="${escapeAttribute(withCspFirst(html, scripts))}"></iframe></body></html>`;
28
+ var HTML_PREVIEW_MAX_CHARS = 1e6;
29
+ var ASSET_ATTR = /\b(?:src|href)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/gi;
30
+ var linkedFilesOf = (html, max = 4) => {
31
+ const found = [];
32
+ for (const m of html.matchAll(ASSET_ATTR)) {
33
+ const ref = (m[1] ?? m[2] ?? m[3] ?? "").trim();
34
+ if (!ref || /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i.test(ref)) continue;
35
+ if (!found.includes(ref)) found.push(ref);
36
+ if (found.length >= max) break;
37
+ }
38
+ return found;
39
+ };
40
+ var RAW_TEXT = /^<(script|style|textarea|title)\b/i;
41
+ var tokenizeHtml = (source) => {
42
+ const out = [];
43
+ const push = (kind, text) => {
44
+ if (!text) return;
45
+ const last = out[out.length - 1];
46
+ if (last && last.kind === kind) last.text += text;
47
+ else out.push({ kind, text });
48
+ };
49
+ let i = 0;
50
+ const n = source.length;
51
+ while (i < n) {
52
+ const lt = source.indexOf("<", i);
53
+ if (lt < 0) {
54
+ push("text", source.slice(i));
55
+ break;
56
+ }
57
+ push("text", source.slice(i, lt));
58
+ i = lt;
59
+ if (source.startsWith("<!--", i)) {
60
+ const end = source.indexOf("-->", i + 4);
61
+ const stop = end < 0 ? n : end + 3;
62
+ push("comment", source.slice(i, stop));
63
+ i = stop;
64
+ continue;
65
+ }
66
+ const open = /^<[!/?]?[a-zA-Z][^\s/>]*/.exec(source.slice(i, i + 80));
67
+ if (!open) {
68
+ push("text", "<");
69
+ i += 1;
70
+ continue;
71
+ }
72
+ push("tag", open[0]);
73
+ const raw = RAW_TEXT.exec(open[0])?.[1].toLowerCase();
74
+ i += open[0].length;
75
+ while (i < n && source[i] !== ">") {
76
+ const c = source[i];
77
+ if (c === '"' || c === "'") {
78
+ const end = source.indexOf(c, i + 1);
79
+ const stop = end < 0 ? n : end + 1;
80
+ push("string", source.slice(i, stop));
81
+ i = stop;
82
+ } else if (/[^\s=/>"']/.test(c)) {
83
+ const name = /^[^\s=/>"']+/.exec(source.slice(i, i + 200))?.[0] ?? c;
84
+ const before = out[out.length - 1];
85
+ push(before?.kind === "text" && before.text.endsWith("=") ? "string" : "attr", name);
86
+ i += name.length;
87
+ } else {
88
+ push(c === "/" ? "tag" : "text", c);
89
+ i += 1;
90
+ }
91
+ }
92
+ if (i < n) {
93
+ push("tag", ">");
94
+ i += 1;
95
+ }
96
+ if (raw) {
97
+ const close = source.toLowerCase().indexOf(`</${raw}`, i);
98
+ const stop = close < 0 ? n : close;
99
+ push("text", source.slice(i, stop));
100
+ i = stop;
101
+ }
102
+ }
103
+ return out;
104
+ };
105
+ var FRAME_MIN_HEIGHT = 120;
106
+ var FRAME_MAX_HEIGHT = 800;
107
+ var clampFrameHeight = (height) => Math.min(
108
+ FRAME_MAX_HEIGHT,
109
+ Math.max(FRAME_MIN_HEIGHT, Math.round(Number.isFinite(height) ? height : 300))
110
+ );
111
+
112
+ export {
113
+ sandboxedCsp,
114
+ sandboxTokens,
115
+ escapeAttribute,
116
+ cspMetaTag,
117
+ withCspFirst,
118
+ withPolicyFirst,
119
+ buildSandboxedDocument,
120
+ HTML_PREVIEW_MAX_CHARS,
121
+ linkedFilesOf,
122
+ tokenizeHtml,
123
+ FRAME_MIN_HEIGHT,
124
+ FRAME_MAX_HEIGHT,
125
+ clampFrameHeight
126
+ };
127
+ //# sourceMappingURL=chunk-EL2YCROY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/html-preview.ts"],"sourcesContent":["/**\n * The sandboxed frame's security core: what untrusted HTML (a file the agent wrote, later an\n * MCP App) is wrapped in before it reaches an `<iframe>`. Pure strings - no React, no DOM - so\n * every guard is unit-tested here and proved in a real browser by `e2e/files.spec.ts`.\n *\n * The boundary, in three layers:\n * 1. `sandbox` WITHOUT `allow-same-origin`: the document gets an opaque origin - no access to\n * the page's DOM, storage, IndexedDB (the key vault), cookies. No `allow-top-navigation`,\n * `allow-popups`, `allow-forms`, `allow-modals`, `allow-downloads` either.\n * 2. A Content-Security-Policy with no network source at all, given twice: as the first element\n * of the document itself, and by inheritance from the shell (3) - a `srcdoc` document takes\n * its parent's policy, which nothing inside the document can pre-empt.\n * 3. A shell document of ours between the page and the untrusted one. A frame may always\n * navigate ITSELF (`location = …`, a link, `<meta http-equiv=refresh>`): neither the sandbox\n * nor a document's own CSP stops that, and a navigation is a network request. The only thing\n * that does is the `frame-src` of the document that EMBEDS the frame - so we embed it in one\n * we wrote, whose policy says `frame-src 'none'`.\n */\n\nexport interface SandboxedDocumentOptions {\n /** Let the document's own inline scripts run (default false). */\n scripts?: boolean\n}\n\n/**\n * The policy of the framed document: nothing is fetched from anywhere. Inline styles, and\n * images / fonts / media the document carries inside itself (`data:`, `blob:`), are all it gets;\n * inline scripts only when asked for. `frame-src 'none'` is what stops the frame from navigating.\n */\nexport const sandboxedCsp = (scripts = false): string =>\n [\n \"default-src 'none'\",\n scripts ? \"script-src 'unsafe-inline'\" : \"script-src 'none'\",\n \"style-src 'unsafe-inline'\",\n 'img-src data: blob:',\n 'font-src data:',\n 'media-src data: blob:',\n \"connect-src 'none'\",\n \"frame-src 'none'\",\n \"child-src 'none'\",\n \"object-src 'none'\",\n \"form-action 'none'\",\n \"base-uri 'none'\",\n \"webrtc 'block'\",\n ].join('; ')\n\n/**\n * The `sandbox` attribute: empty (everything off) or `allow-scripts`. Never\n * `allow-same-origin`, never a navigation, popup, form, modal or download token.\n */\nexport const sandboxTokens = (scripts = false): string => (scripts ? 'allow-scripts' : '')\n\n/** A string as the value of a double-quoted HTML attribute. */\nexport const escapeAttribute = (value: string): string =>\n value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n\n/** A `<meta>` that carries a Content-Security-Policy. */\nexport const cspMetaTag = (policy: string): string =>\n `<meta http-equiv=\"Content-Security-Policy\" content=\"${escapeAttribute(policy)}\">`\n\nconst cspMeta = (scripts: boolean): string => cspMetaTag(sandboxedCsp(scripts))\n\n// A DOCTYPE token ends at the first \">\" whatever is inside it (the tokenizer's rule), so this is\n// exactly where the parser leaves it.\nconst DOCTYPE = /^[\\t\\n\\f\\r ]*<!doctype[^>]*>/i\n\n/**\n * The document with our policy as its FIRST element: right after a leading DOCTYPE (so the\n * page stays in standards mode), otherwise before everything. Nothing the document says can\n * come earlier - not its own `<meta>`, not a `<base>`, not a script before `<html>` - and a\n * later policy of its own can only narrow ours.\n */\nexport const withCspFirst = (html: string, scripts = false): string =>\n withPolicyFirst(html, sandboxedCsp(scripts))\n\n/** `withCspFirst` with a policy of the caller's (an MCP App's, built by `mcpAppCsp`). */\nexport const withPolicyFirst = (html: string, policy: string): string => {\n const doctype = DOCTYPE.exec(html)?.[0] ?? ''\n return `${doctype}${cspMetaTag(policy)}${html.slice(doctype.length)}`\n}\n\n/**\n * What goes into the outer frame's `srcdoc`: the shell (ours: the policy, and one inner frame\n * that fills it) carrying the untrusted document, escaped, as the inner frame's `srcdoc`.\n * Give the OUTER `<iframe>` the same `sandboxTokens(scripts)`.\n */\nexport const buildSandboxedDocument = (\n html: string,\n { scripts = false }: SandboxedDocumentOptions = {},\n): string =>\n '<!doctype html><html><head>' +\n cspMeta(scripts) +\n '<style>html,body{margin:0;height:100%;overflow:hidden;background:transparent}' +\n 'iframe{display:block;border:0;width:100%;height:100%}</style></head><body>' +\n `<iframe sandbox=\"${sandboxTokens(scripts)}\" referrerpolicy=\"no-referrer\" ` +\n `srcdoc=\"${escapeAttribute(withCspFirst(html, scripts))}\"></iframe></body></html>`\n\n/** HTML above this many characters is not framed at all - it is shown as source. */\nexport const HTML_PREVIEW_MAX_CHARS = 1_000_000\n\nconst ASSET_ATTR = /\\b(?:src|href)\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>]+))/gi\n\n/**\n * The files a document links to by a relative path (`style.css`, `./app.js`, `img/a.png`): the\n * preview does not load them, and says so. A hint for the user, not a guard - the policy is\n * what keeps them from loading.\n */\nexport const linkedFilesOf = (html: string, max = 4): string[] => {\n const found: string[] = []\n for (const m of html.matchAll(ASSET_ATTR)) {\n const ref = (m[1] ?? m[2] ?? m[3] ?? '').trim()\n if (!ref || /^(?:[a-z][a-z0-9+.-]*:|\\/\\/|#)/i.test(ref)) continue\n if (!found.includes(ref)) found.push(ref)\n if (found.length >= max) break\n }\n return found\n}\n\n/** A piece of HTML source, by what it is (for colouring the Source view). */\nexport interface SourceToken {\n kind: 'text' | 'tag' | 'attr' | 'string' | 'comment'\n text: string\n}\n\nconst RAW_TEXT = /^<(script|style|textarea|title)\\b/i\n\n/**\n * Split HTML source into coloured pieces. Lossless: the pieces joined are the input. It only\n * decides colours - the result is rendered as text nodes, never as markup.\n */\nexport const tokenizeHtml = (source: string): SourceToken[] => {\n const out: SourceToken[] = []\n const push = (kind: SourceToken['kind'], text: string) => {\n if (!text) return\n const last = out[out.length - 1]\n if (last && last.kind === kind) last.text += text\n else out.push({ kind, text })\n }\n let i = 0\n const n = source.length\n while (i < n) {\n const lt = source.indexOf('<', i)\n if (lt < 0) {\n push('text', source.slice(i))\n break\n }\n push('text', source.slice(i, lt))\n i = lt\n if (source.startsWith('<!--', i)) {\n const end = source.indexOf('-->', i + 4)\n const stop = end < 0 ? n : end + 3\n push('comment', source.slice(i, stop))\n i = stop\n continue\n }\n const open = /^<[!/?]?[a-zA-Z][^\\s/>]*/.exec(source.slice(i, i + 80))\n if (!open) {\n push('text', '<')\n i += 1\n continue\n }\n push('tag', open[0])\n const raw = RAW_TEXT.exec(open[0])?.[1].toLowerCase()\n i += open[0].length\n // Inside the tag, up to its \">\".\n while (i < n && source[i] !== '>') {\n const c = source[i]\n if (c === '\"' || c === \"'\") {\n const end = source.indexOf(c, i + 1)\n const stop = end < 0 ? n : end + 1\n push('string', source.slice(i, stop))\n i = stop\n } else if (/[^\\s=/>\"']/.test(c)) {\n const name = /^[^\\s=/>\"']+/.exec(source.slice(i, i + 200))?.[0] ?? c\n // After \"=\" it is an unquoted value; otherwise a name.\n const before = out[out.length - 1]\n push(before?.kind === 'text' && before.text.endsWith('=') ? 'string' : 'attr', name)\n i += name.length\n } else {\n push(c === '/' ? 'tag' : 'text', c)\n i += 1\n }\n }\n if (i < n) {\n push('tag', '>')\n i += 1\n }\n if (raw) {\n // The content of <script> / <style> is not markup: plain, up to its closing tag.\n const close = source.toLowerCase().indexOf(`</${raw}`, i)\n const stop = close < 0 ? n : close\n push('text', source.slice(i, stop))\n i = stop\n }\n }\n return out\n}\n\n/** The frame's height is the host's: a number of pixels between these, never the content's wish. */\nexport const FRAME_MIN_HEIGHT = 120\nexport const FRAME_MAX_HEIGHT = 800\n\nexport const clampFrameHeight = (height: number): number =>\n Math.min(\n FRAME_MAX_HEIGHT,\n Math.max(FRAME_MIN_HEIGHT, Math.round(Number.isFinite(height) ? height : 300)),\n )\n"],"mappings":";AA6BO,IAAM,eAAe,CAAC,UAAU,UACr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;AAClB,UAAI,MAAM,OAAO,MAAM,KAAK;AAC1B,cAAM,MAAM,OAAO,QAAQ,GAAG,IAAI,CAAC;AACnC,cAAM,OAAO,MAAM,IAAI,IAAI,MAAM;AACjC,aAAK,UAAU,OAAO,MAAM,GAAG,IAAI,CAAC;AACpC,YAAI;AAAA,MACN,WAAW,aAAa,KAAK,CAAC,GAAG;AAC/B,cAAM,OAAO,eAAe,KAAK,OAAO,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK;AAEnE,cAAM,SAAS,IAAI,IAAI,SAAS,CAAC;AACjC,aAAK,QAAQ,SAAS,UAAU,OAAO,KAAK,SAAS,GAAG,IAAI,WAAW,QAAQ,IAAI;AACnF,aAAK,KAAK;AAAA,MACZ,OAAO;AACL,aAAK,MAAM,MAAM,QAAQ,QAAQ,CAAC;AAClC,aAAK;AAAA,MACP;AAAA,IACF;AACA,QAAI,IAAI,GAAG;AACT,WAAK,OAAO,GAAG;AACf,WAAK;AAAA,IACP;AACA,QAAI,KAAK;AAEP,YAAM,QAAQ,OAAO,YAAY,EAAE,QAAQ,KAAK,GAAG,IAAI,CAAC;AACxD,YAAM,OAAO,QAAQ,IAAI,IAAI;AAC7B,WAAK,QAAQ,OAAO,MAAM,GAAG,IAAI,CAAC;AAClC,UAAI;AAAA,IACN;AAAA,EACF;AACA,SAAO;AACT;AAGO,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAEzB,IAAM,mBAAmB,CAAC,WAC/B,KAAK;AAAA,EACH;AAAA,EACA,KAAK,IAAI,kBAAkB,KAAK,MAAM,OAAO,SAAS,MAAM,IAAI,SAAS,GAAG,CAAC;AAC/E;","names":[]}
@@ -0,0 +1,98 @@
1
+ // src/mcp-app-policy.ts
2
+ var MCP_APP_SANDBOX_PROXY_READY = "ui/notifications/sandbox-proxy-ready";
3
+ var MCP_APP_SANDBOX_RESOURCE_READY = "ui/notifications/sandbox-resource-ready";
4
+ var isMcpAppSandboxMessage = (data) => typeof data === "object" && data !== null && typeof data.method === "string" && data.method.startsWith("ui/notifications/sandbox-");
5
+ var MCP_APP_SCHEME_PARAM = "scheme";
6
+ var mcpAppColorScheme = (value) => value === "light" || value === "dark" ? value : void 0;
7
+ var mcpAppPolicy = ({ connect, resources }) => {
8
+ const from = resources.length > 0 ? ` ${resources.join(" ")}` : "";
9
+ return [
10
+ "default-src 'none'",
11
+ `script-src 'unsafe-inline' 'wasm-unsafe-eval'${from}`,
12
+ `style-src 'unsafe-inline'${from}`,
13
+ `img-src data: blob:${from}`,
14
+ `font-src data:${from}`,
15
+ `media-src data: blob:${from}`,
16
+ connect.length > 0 ? `connect-src ${connect.join(" ")}` : "connect-src 'none'",
17
+ "frame-src 'none'",
18
+ "child-src 'none'",
19
+ "worker-src 'none'",
20
+ "object-src 'none'",
21
+ "form-action 'none'",
22
+ "base-uri 'none'",
23
+ "webrtc 'block'"
24
+ ].join("; ");
25
+ };
26
+ var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
27
+ var HOST = `(?:\\*\\.)?${LABEL}(?:\\.${LABEL})*`;
28
+ var PORT = "(?::\\d{1,5})?";
29
+ var SECURE_ORIGIN = new RegExp(`^(?:https|wss)://${HOST}${PORT}$`);
30
+ var LOOPBACK_ORIGIN = new RegExp(`^(?:http|ws)://(?:localhost|127\\.0\\.0\\.1|\\[::1\\])${PORT}$`);
31
+ var mcpAppPolicyOrigin = (entry) => {
32
+ if (typeof entry !== "string" || entry.length > 300) return void 0;
33
+ const value = entry.trim().toLowerCase().replace(/\/$/, "");
34
+ if (SECURE_ORIGIN.test(value)) {
35
+ const host = value.replace(/^[a-z]+:\/\//, "").replace(/:\d+$/, "");
36
+ if (host.startsWith("*.") && !host.slice(2).includes(".")) return void 0;
37
+ return value;
38
+ }
39
+ return LOOPBACK_ORIGIN.test(value) ? value : void 0;
40
+ };
41
+ var MCP_APP_POLICY_MAX_ORIGINS = 32;
42
+ var MCP_APP_POLICY_TOKEN_MAX_CHARS = 4096;
43
+ var B64URL = /^[A-Za-z0-9_-]+$/;
44
+ var mcpAppPolicyToken = ({
45
+ connect,
46
+ resources
47
+ }) => {
48
+ const json = JSON.stringify({ c: connect, r: resources });
49
+ if (/[^\x20-\x7e]/.test(json)) return void 0;
50
+ const token = btoa(json).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
51
+ return token.length <= MCP_APP_POLICY_TOKEN_MAX_CHARS ? token : void 0;
52
+ };
53
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
54
+ var originList = (value) => {
55
+ if (!Array.isArray(value) || value.length > MCP_APP_POLICY_MAX_ORIGINS) return void 0;
56
+ const out = [];
57
+ for (const entry of value) {
58
+ if (typeof entry !== "string" || mcpAppPolicyOrigin(entry) !== entry || out.includes(entry)) {
59
+ return void 0;
60
+ }
61
+ out.push(entry);
62
+ }
63
+ return out;
64
+ };
65
+ var mcpAppPolicyOfToken = (token) => {
66
+ if (typeof token !== "string" || token.length === 0 || token.length > MCP_APP_POLICY_TOKEN_MAX_CHARS || !B64URL.test(token)) {
67
+ return void 0;
68
+ }
69
+ let parsed;
70
+ try {
71
+ parsed = JSON.parse(atob(token.replace(/-/g, "+").replace(/_/g, "/")));
72
+ } catch {
73
+ return void 0;
74
+ }
75
+ if (!isObject(parsed)) return void 0;
76
+ const keys = Object.keys(parsed);
77
+ if (keys.length !== 2 || !keys.includes("c") || !keys.includes("r")) return void 0;
78
+ const connect = originList(parsed.c);
79
+ const resources = originList(parsed.r);
80
+ if (!connect || !resources) return void 0;
81
+ const policy = { connect, resources };
82
+ return mcpAppPolicyToken(policy) === token ? policy : void 0;
83
+ };
84
+
85
+ export {
86
+ MCP_APP_SANDBOX_PROXY_READY,
87
+ MCP_APP_SANDBOX_RESOURCE_READY,
88
+ isMcpAppSandboxMessage,
89
+ MCP_APP_SCHEME_PARAM,
90
+ mcpAppColorScheme,
91
+ mcpAppPolicy,
92
+ mcpAppPolicyOrigin,
93
+ MCP_APP_POLICY_MAX_ORIGINS,
94
+ MCP_APP_POLICY_TOKEN_MAX_CHARS,
95
+ mcpAppPolicyToken,
96
+ mcpAppPolicyOfToken
97
+ };
98
+ //# sourceMappingURL=chunk-GB7RZJMG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp-app-policy.ts"],"sourcesContent":["/**\n * MCP Apps: what the host (the page, `mcp-app.ts`) and the sandbox proxy (a page on ANOTHER\n * origin, `mcp-app-sandbox.ts`) must agree on - the app's Content-Security-Policy, the policy as a\n * path segment of the proxy's URL, and the names of the sandbox messages. Pure code with NO\n * imports at all: the proxy's server bundles it without React or the core (a Worker), so the\n * origin rule below is a copy of the core's `mcpAppOrigin`, and `tests/apps-sandbox.test.ts`\n * holds the two to the same answers.\n */\n\n/** The proxy tells the host it can take the app (Sandbox → Host; content-free). */\nexport const MCP_APP_SANDBOX_PROXY_READY = 'ui/notifications/sandbox-proxy-ready'\n/** The host hands the proxy the app's HTML (Host → Sandbox), once. */\nexport const MCP_APP_SANDBOX_RESOURCE_READY = 'ui/notifications/sandbox-resource-ready'\n\n/** The specification reserves these between a host and its proxy: never relayed to or from an app. */\nexport const isMcpAppSandboxMessage = (data: unknown): boolean =>\n typeof data === 'object' &&\n data !== null &&\n typeof (data as { method?: unknown }).method === 'string' &&\n (data as { method: string }).method.startsWith('ui/notifications/sandbox-')\n\n/**\n * The colour scheme of an app's frame: the theme the app is told when its frame is drawn. Every\n * document between the page and the app declares it (the frame element, the shell, the sandbox\n * page and its frame), because a browser paints an OPAQUE canvas - the canvas colour of the\n * embedded document's own scheme - behind a document whose scheme differs from its frame\n * element's: an app that is dark with a transparent body was drawn on white.\n */\nexport type McpAppColorScheme = 'light' | 'dark'\n\n/** The query parameter of the sandbox page that carries the scheme (`?scheme=dark`). */\nexport const MCP_APP_SCHEME_PARAM = 'scheme'\n\n/** `light` or `dark` exactly; anything else is no scheme (nothing is declared). */\nexport const mcpAppColorScheme = (value: unknown): McpAppColorScheme | undefined =>\n value === 'light' || value === 'dark' ? value : undefined\n\n/** The origins an app's policy grants, each already an origin (`mcpAppPolicyOrigin`). */\nexport interface McpAppPolicyOrigins {\n /** `fetch` / XHR / WebSocket (`connect-src`). */\n connect: string[]\n /** Scripts, styles, images, fonts, media. */\n resources: string[]\n}\n\n/**\n * The policy of an app's document: scripts and styles inline, `data:` / `blob:` media, and the\n * network ONLY where the resource declared it. Nested frames, workers, plugins, forms and `<base>`\n * are refused whatever was declared (a frame the app may embed would also be a place it may\n * navigate itself to). The lists must already be checked origins: nothing here re-checks them.\n *\n * `'wasm-unsafe-eval'` lets the app compile WebAssembly (a tracer, a codec, a parser), which the\n * specification's default policy leaves out and a server cannot ask for (it declares origins, not\n * keywords). It adds no reach: a module only calls what the app's own script hands it, and the\n * network stays `connect-src`. `eval`, `new Function` and string timers stay refused - that is\n * `'unsafe-eval'`, which is never granted.\n */\nexport const mcpAppPolicy = ({ connect, resources }: McpAppPolicyOrigins): string => {\n const from = resources.length > 0 ? ` ${resources.join(' ')}` : ''\n return [\n \"default-src 'none'\",\n `script-src 'unsafe-inline' 'wasm-unsafe-eval'${from}`,\n `style-src 'unsafe-inline'${from}`,\n `img-src data: blob:${from}`,\n `font-src data:${from}`,\n `media-src data: blob:${from}`,\n connect.length > 0 ? `connect-src ${connect.join(' ')}` : \"connect-src 'none'\",\n \"frame-src 'none'\",\n \"child-src 'none'\",\n \"worker-src 'none'\",\n \"object-src 'none'\",\n \"form-action 'none'\",\n \"base-uri 'none'\",\n \"webrtc 'block'\",\n ].join('; ')\n}\n\n// ── The origin rule: a COPY of the core's `mcpAppOrigin` (src/mcp/apps.ts) ──────────────────\n\nconst LABEL = '[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?'\nconst HOST = `(?:\\\\*\\\\.)?${LABEL}(?:\\\\.${LABEL})*`\nconst PORT = '(?::\\\\d{1,5})?'\nconst SECURE_ORIGIN = new RegExp(`^(?:https|wss)://${HOST}${PORT}$`)\nconst LOOPBACK_ORIGIN = new RegExp(`^(?:http|ws)://(?:localhost|127\\\\.0\\\\.0\\\\.1|\\\\[::1\\\\])${PORT}$`)\n\n/**\n * One declared CSP entry as a source expression a policy may carry, or `undefined`: only an\n * origin (`https://` / `wss://`, a `*.` wildcard over at least two labels, or `http://` /\n * `ws://` on loopback). The same answers as the core's `mcpAppOrigin`, for the proxy's server.\n */\nexport const mcpAppPolicyOrigin = (entry: unknown): string | undefined => {\n if (typeof entry !== 'string' || entry.length > 300) return undefined\n const value = entry.trim().toLowerCase().replace(/\\/$/, '')\n if (SECURE_ORIGIN.test(value)) {\n const host = value.replace(/^[a-z]+:\\/\\//, '').replace(/:\\d+$/, '')\n if (host.startsWith('*.') && !host.slice(2).includes('.')) return undefined\n return value\n }\n return LOOPBACK_ORIGIN.test(value) ? value : undefined\n}\n\n// ── The policy in the proxy's URL ────────────────────────────────────────────────────────────\n\n/** At most this many origins per list (the core's `MCP_APP_MAX_DOMAINS`). */\nexport const MCP_APP_POLICY_MAX_ORIGINS = 32\n/** A policy token longer than this is not put in a URL: the app runs without its own origin. */\nexport const MCP_APP_POLICY_TOKEN_MAX_CHARS = 4096\n\nconst B64URL = /^[A-Za-z0-9_-]+$/\n\n/**\n * The policy as one path segment (base64url of `{\"c\":[…],\"r\":[…]}`), or `undefined` when it does\n * not fit. It is in the PATH, not the query, because a `frame-src` source expression matches a\n * path exactly and ignores the query: the host pins the proxy's frame to this one URL, so nothing\n * inside the frame can load the proxy page with a policy of its choosing.\n */\nexport const mcpAppPolicyToken = ({\n connect,\n resources,\n}: McpAppPolicyOrigins): string | undefined => {\n const json = JSON.stringify({ c: connect, r: resources })\n // Origins are ASCII; anything else is not a list of checked origins.\n if (/[^\\x20-\\x7e]/.test(json)) return undefined\n const token = btoa(json).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n return token.length <= MCP_APP_POLICY_TOKEN_MAX_CHARS ? token : undefined\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\nconst originList = (value: unknown): string[] | undefined => {\n if (!Array.isArray(value) || value.length > MCP_APP_POLICY_MAX_ORIGINS) return undefined\n const out: string[] = []\n for (const entry of value) {\n // Exactly an origin as the host writes it: checked, canonical, once.\n if (typeof entry !== 'string' || mcpAppPolicyOrigin(entry) !== entry || out.includes(entry)) {\n return undefined\n }\n out.push(entry)\n }\n return out\n}\n\n/**\n * The policy a token stands for, or `undefined` for anything that is not exactly what\n * `mcpAppPolicyToken` writes: base64url of an object with the two lists and nothing else, every\n * entry an origin by the rule above, no more than `MCP_APP_POLICY_MAX_ORIGINS` each, the\n * canonical encoding (one URL per policy).\n */\nexport const mcpAppPolicyOfToken = (token: unknown): McpAppPolicyOrigins | undefined => {\n if (\n typeof token !== 'string' ||\n token.length === 0 ||\n token.length > MCP_APP_POLICY_TOKEN_MAX_CHARS ||\n !B64URL.test(token)\n ) {\n return undefined\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(atob(token.replace(/-/g, '+').replace(/_/g, '/')))\n } catch {\n return undefined\n }\n if (!isObject(parsed)) return undefined\n const keys = Object.keys(parsed)\n if (keys.length !== 2 || !keys.includes('c') || !keys.includes('r')) return undefined\n const connect = originList(parsed.c)\n const resources = originList(parsed.r)\n if (!connect || !resources) return undefined\n const policy = { connect, resources }\n return mcpAppPolicyToken(policy) === token ? policy : undefined\n}\n"],"mappings":";AAUO,IAAM,8BAA8B;AAEpC,IAAM,iCAAiC;AAGvC,IAAM,yBAAyB,CAAC,SACrC,OAAO,SAAS,YAChB,SAAS,QACT,OAAQ,KAA8B,WAAW,YAChD,KAA4B,OAAO,WAAW,2BAA2B;AAYrE,IAAM,uBAAuB;AAG7B,IAAM,oBAAoB,CAAC,UAChC,UAAU,WAAW,UAAU,SAAS,QAAQ;AAsB3C,IAAM,eAAe,CAAC,EAAE,SAAS,UAAU,MAAmC;AACnF,QAAM,OAAO,UAAU,SAAS,IAAI,IAAI,UAAU,KAAK,GAAG,CAAC,KAAK;AAChE,SAA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els.ts
2
+ var defaultCanvasLabels = {
3
+ canvas: "Canvas",
4
+ help: "Tab moves between nodes and their connections. Arrow keys move the selected node, Enter opens it, Delete removes it, C starts a connection, Escape clears the selection. On the canvas itself the arrow keys pan, plus and minus zoom, 0 fits everything.",
5
+ node: "node",
6
+ edge: (from, to, description) => `Connection from ${from} to ${to}${description ? `: ${description}` : ""}`,
7
+ port: (node, port) => `Connect ${node}${port ? ` (${port})` : ""} to another node`,
8
+ connectsTo: (names) => `Connects to: ${names}.`,
9
+ receivesFrom: (names) => `Receives from: ${names}.`,
10
+ zoomIn: "Zoom in",
11
+ zoomOut: "Zoom out",
12
+ fit: "Fit to view",
13
+ zoomLevel: (percent) => `${percent}%`,
14
+ connectHint: (from) => `Pick the node to connect ${from} to`,
15
+ cancel: "Cancel",
16
+ connected: (from, to) => `Connected ${from} to ${to}`
17
+ };
18
+
19
+ export {
20
+ defaultCanvasLabels
21
+ };
22
+ //# sourceMappingURL=chunk-KZQB35LS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/canvas/labels.ts"],"sourcesContent":["// The canvas's strings: what it shows and says to a screen reader. Generic - nothing of agents.\n\n/** Every string the canvas shows or says. */\nexport interface CanvasLabels {\n /** The canvas's own name for a screen reader. */\n canvas: string\n /** How to use it with a keyboard; read once, when the canvas is focused. */\n help: string\n /** `aria-roledescription` of a node. */\n node: string\n edge: (from: string, to: string, description?: string) => string\n port: (node: string, port?: string) => string\n connectsTo: (names: string) => string\n receivesFrom: (names: string) => string\n zoomIn: string\n zoomOut: string\n fit: string\n zoomLevel: (percent: number) => string\n /** Shown (and announced) while a connection is being made without dragging. */\n connectHint: (from: string) => string\n cancel: string\n connected: (from: string, to: string) => string\n}\n\nexport const defaultCanvasLabels: CanvasLabels = {\n canvas: 'Canvas',\n help: 'Tab moves between nodes and their connections. Arrow keys move the selected node, Enter opens it, Delete removes it, C starts a connection, Escape clears the selection. On the canvas itself the arrow keys pan, plus and minus zoom, 0 fits everything.',\n node: 'node',\n edge: (from, to, description) =>\n `Connection from ${from} to ${to}${description ? `: ${description}` : ''}`,\n port: (node, port) => `Connect ${node}${port ? ` (${port})` : ''} to another node`,\n connectsTo: (names) => `Connects to: ${names}.`,\n receivesFrom: (names) => `Receives from: ${names}.`,\n zoomIn: 'Zoom in',\n zoomOut: 'Zoom out',\n fit: 'Fit to view',\n zoomLevel: (percent) => `${percent}%`,\n connectHint: (from) => `Pick the node to connect ${from} to`,\n cancel: 'Cancel',\n connected: (from, to) => `Connected ${from} to ${to}`,\n}\n"],"mappings":";AAwBO,IAAM,sBAAoC;AAAA,EAC/C,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM,CAAC,MAAM,IAAI,gBACf,mBAAmB,IAAI,OAAO,EAAE,GAAG,cAAc,KAAK,WAAW,KAAK,EAAE;AAAA,EAC1E,MAAM,CAAC,MAAM,SAAS,WAAW,IAAI,GAAG,OAAO,KAAK,IAAI,MAAM,EAAE;AAAA,EAChE,YAAY,CAAC,UAAU,gBAAgB,KAAK;AAAA,EAC5C,cAAc,CAAC,UAAU,kBAAkB,KAAK;AAAA,EAChD,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,KAAK;AAAA,EACL,WAAW,CAAC,YAAY,GAAG,OAAO;AAAA,EAClC,aAAa,CAAC,SAAS,4BAA4B,IAAI;AAAA,EACvD,QAAQ;AAAA,EACR,WAAW,CAAC,MAAM,OAAO,aAAa,IAAI,OAAO,EAAE;AACrD;","names":[]}