@johnoscott/isometric-engine 0.0.0-stage → 0.9.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 (310) hide show
  1. package/EDITOR-GUIDE.md +317 -0
  2. package/LICENSE +21 -0
  3. package/LICENSES/ajv.txt +22 -0
  4. package/LICENSES/lucide-static.txt +43 -0
  5. package/LICENSES/yaml.txt +13 -0
  6. package/README.md +62 -2
  7. package/assets/app.css +265 -0
  8. package/assets/default-theme.yaml +99 -0
  9. package/assets/icons.svg +1 -0
  10. package/assets/marks.css +35 -0
  11. package/assets/skin.css +181 -0
  12. package/iso-editor.d.ts +4 -0
  13. package/iso-editor.js +550 -0
  14. package/iso-render.d.ts +3 -0
  15. package/iso-render.js +388 -0
  16. package/iso-systems.d.ts +4 -0
  17. package/iso-systems.js +389 -0
  18. package/js/iso-core/compile-schema.js +22 -0
  19. package/js/iso-core/depth.js +55 -0
  20. package/js/iso-core/errors.js +65 -0
  21. package/js/iso-core/glyphs.js +100 -0
  22. package/js/iso-core/index.js +55 -0
  23. package/js/iso-core/kernel.js +158 -0
  24. package/js/iso-core/metrics.json +1 -0
  25. package/js/iso-core/package.json +6 -0
  26. package/js/iso-core/parse.js +79 -0
  27. package/js/iso-core/schema-errors.js +170 -0
  28. package/js/iso-core/shims/crypto.js +125 -0
  29. package/js/iso-core/shims/path.js +49 -0
  30. package/js/iso-core/svg-dom.js +144 -0
  31. package/js/iso-core/theme.js +48 -0
  32. package/js/iso-core/vdom.js +48 -0
  33. package/js/iso-editor/adapter.js +0 -0
  34. package/js/iso-editor/clipboard.js +152 -0
  35. package/js/iso-editor/commands.js +173 -0
  36. package/js/iso-editor/complete.js +55 -0
  37. package/js/iso-editor/doc.js +182 -0
  38. package/js/iso-editor/index.js +105 -0
  39. package/js/iso-editor/model.js +210 -0
  40. package/js/iso-editor/outline.js +111 -0
  41. package/js/iso-editor/package.json +6 -0
  42. package/js/iso-editor/path.js +19 -0
  43. package/js/iso-editor/providers.js +96 -0
  44. package/js/iso-editor/schema-nav.js +117 -0
  45. package/js/iso-editor/splice.js +441 -0
  46. package/js/iso-editor/storage-keys.js +6 -0
  47. package/js/iso-editor/ui/actions.js +116 -0
  48. package/js/iso-editor/ui/canvas-layer.js +0 -0
  49. package/js/iso-editor/ui/canvas.js +1205 -0
  50. package/js/iso-editor/ui/clip.js +133 -0
  51. package/js/iso-editor/ui/dialog.js +26 -0
  52. package/js/iso-editor/ui/flat-canvas.js +54 -0
  53. package/js/iso-editor/ui/icons.js +15 -0
  54. package/js/iso-editor/ui/keys.js +26 -0
  55. package/js/iso-editor/ui/later.js +28 -0
  56. package/js/iso-editor/ui/layer.js +11 -0
  57. package/js/iso-editor/ui/menu.js +105 -0
  58. package/js/iso-editor/ui/monaco-entry.js +2 -0
  59. package/js/iso-editor/ui/mount-kit.js +0 -0
  60. package/js/iso-editor/ui/mount.js +767 -0
  61. package/js/iso-editor/ui/pane.js +0 -0
  62. package/js/iso-editor/ui/part.js +0 -0
  63. package/js/iso-editor/ui/plain-icons.js +34 -0
  64. package/js/iso-editor/ui/props.js +314 -0
  65. package/js/iso-editor/ui/scope-css.js +81 -0
  66. package/js/iso-editor/ui/setup.js +145 -0
  67. package/js/iso-editor/ui/text.js +323 -0
  68. package/js/iso-editor/ui/tree.js +728 -0
  69. package/js/iso-editor/validate.js +33 -0
  70. package/js/iso-editor/window/protocol.js +8 -0
  71. package/js/iso-objects/assemble.js +43 -0
  72. package/js/iso-objects/assets.js +88 -0
  73. package/js/iso-objects/board.js +162 -0
  74. package/js/iso-objects/compile.js +60 -0
  75. package/js/iso-objects/css.js +154 -0
  76. package/js/iso-objects/flat.js +696 -0
  77. package/js/iso-objects/focus.js +16 -0
  78. package/js/iso-objects/geometry.js +76 -0
  79. package/js/iso-objects/index.js +93 -0
  80. package/js/iso-objects/kinds.js +12 -0
  81. package/js/iso-objects/labels.js +325 -0
  82. package/js/iso-objects/package.json +6 -0
  83. package/js/iso-objects/place.js +347 -0
  84. package/js/iso-objects/route.js +461 -0
  85. package/js/iso-objects/scene.js +350 -0
  86. package/js/iso-objects/steps.js +246 -0
  87. package/js/iso-objects/types.js +0 -0
  88. package/js/iso-systems/catalog.js +42 -0
  89. package/js/iso-systems/compile.js +34 -0
  90. package/js/iso-systems/css.js +8 -0
  91. package/js/iso-systems/index.js +16 -0
  92. package/js/iso-systems/nodes.js +124 -0
  93. package/js/iso-systems/package.json +6 -0
  94. package/js/iso-systems/schema.json +311 -0
  95. package/js/iso-systems/validate.js +35 -0
  96. package/js/iso-viewer/bundle.js +20 -0
  97. package/js/iso-viewer/card-motion.js +228 -0
  98. package/js/iso-viewer/dom.js +14 -0
  99. package/js/iso-viewer/dual-view.js +212 -0
  100. package/js/iso-viewer/flat-view.js +124 -0
  101. package/js/iso-viewer/history.js +990 -0
  102. package/js/iso-viewer/index.js +98 -0
  103. package/js/iso-viewer/morph.js +192 -0
  104. package/js/iso-viewer/overlay.js +199 -0
  105. package/js/iso-viewer/package.json +6 -0
  106. package/js/iso-viewer/page.js +138 -0
  107. package/js/iso-viewer/player.js +409 -0
  108. package/js/iso-viewer/still.js +81 -0
  109. package/js/iso-viewer/timeline-contract.js +14 -0
  110. package/js/iso-viewer/timeline-engine.js +475 -0
  111. package/js/iso-viewer/timeline-export.js +36 -0
  112. package/js/iso-viewer/timeline-scale.js +116 -0
  113. package/js/iso-viewer/timeline-scope.js +58 -0
  114. package/js/iso-viewer/timeline-search.js +216 -0
  115. package/js/iso-viewer/timeline-time.js +55 -0
  116. package/js/iso-viewer/view-css.js +68 -0
  117. package/js/iso-viewer/viewport.js +177 -0
  118. package/package.json +502 -4
  119. package/src/iso-core/compile-schema.ts +23 -0
  120. package/src/iso-core/depth.ts +56 -0
  121. package/src/iso-core/errors.ts +73 -0
  122. package/src/iso-core/glyphs.ts +108 -0
  123. package/src/iso-core/index.ts +27 -0
  124. package/src/iso-core/kernel.ts +163 -0
  125. package/src/iso-core/metrics.json +1 -0
  126. package/src/iso-core/package.json +6 -0
  127. package/src/iso-core/parse.ts +91 -0
  128. package/src/iso-core/schema-errors.ts +163 -0
  129. package/src/iso-core/shims/crypto.ts +37 -0
  130. package/src/iso-core/shims/path.ts +24 -0
  131. package/src/iso-core/svg-dom.ts +103 -0
  132. package/src/iso-core/theme.ts +64 -0
  133. package/src/iso-core/vdom.ts +41 -0
  134. package/src/iso-editor/adapter.ts +128 -0
  135. package/src/iso-editor/clipboard.ts +163 -0
  136. package/src/iso-editor/commands.ts +191 -0
  137. package/src/iso-editor/complete.ts +73 -0
  138. package/src/iso-editor/doc.ts +207 -0
  139. package/src/iso-editor/index.ts +67 -0
  140. package/src/iso-editor/model.ts +234 -0
  141. package/src/iso-editor/outline.ts +126 -0
  142. package/src/iso-editor/package.json +6 -0
  143. package/src/iso-editor/path.ts +18 -0
  144. package/src/iso-editor/providers.ts +113 -0
  145. package/src/iso-editor/schema-nav.ts +129 -0
  146. package/src/iso-editor/splice.ts +472 -0
  147. package/src/iso-editor/storage-keys.ts +6 -0
  148. package/src/iso-editor/ui/actions.ts +119 -0
  149. package/src/iso-editor/ui/app.css +230 -0
  150. package/src/iso-editor/ui/canvas-layer.ts +56 -0
  151. package/src/iso-editor/ui/canvas.ts +1071 -0
  152. package/src/iso-editor/ui/clip.ts +97 -0
  153. package/src/iso-editor/ui/dialog.ts +25 -0
  154. package/src/iso-editor/ui/flat-canvas.ts +51 -0
  155. package/src/iso-editor/ui/icons.ts +21 -0
  156. package/src/iso-editor/ui/keys.ts +30 -0
  157. package/src/iso-editor/ui/later.ts +22 -0
  158. package/src/iso-editor/ui/layer.ts +7 -0
  159. package/src/iso-editor/ui/marks.css +35 -0
  160. package/src/iso-editor/ui/menu.ts +67 -0
  161. package/src/iso-editor/ui/monaco-entry.ts +6 -0
  162. package/src/iso-editor/ui/mount-kit.ts +35 -0
  163. package/src/iso-editor/ui/mount.ts +684 -0
  164. package/src/iso-editor/ui/pane.ts +45 -0
  165. package/src/iso-editor/ui/part.ts +45 -0
  166. package/src/iso-editor/ui/plain-icons.ts +83 -0
  167. package/src/iso-editor/ui/props.ts +347 -0
  168. package/src/iso-editor/ui/scope-css.ts +65 -0
  169. package/src/iso-editor/ui/setup.ts +144 -0
  170. package/src/iso-editor/ui/skin.css +181 -0
  171. package/src/iso-editor/ui/text.ts +262 -0
  172. package/src/iso-editor/ui/tree.ts +657 -0
  173. package/src/iso-editor/validate.ts +62 -0
  174. package/src/iso-editor/window/protocol.ts +33 -0
  175. package/src/iso-objects/assemble.ts +57 -0
  176. package/src/iso-objects/assets.ts +122 -0
  177. package/src/iso-objects/board.ts +169 -0
  178. package/src/iso-objects/compile.ts +76 -0
  179. package/src/iso-objects/css.ts +163 -0
  180. package/src/iso-objects/flat.ts +653 -0
  181. package/src/iso-objects/focus.ts +14 -0
  182. package/src/iso-objects/geometry.ts +86 -0
  183. package/src/iso-objects/index.ts +33 -0
  184. package/src/iso-objects/kinds.ts +56 -0
  185. package/src/iso-objects/labels.ts +310 -0
  186. package/src/iso-objects/package.json +6 -0
  187. package/src/iso-objects/place.ts +318 -0
  188. package/src/iso-objects/route.ts +444 -0
  189. package/src/iso-objects/scene.ts +376 -0
  190. package/src/iso-objects/steps.ts +234 -0
  191. package/src/iso-objects/types.ts +68 -0
  192. package/src/iso-systems/catalog.ts +31 -0
  193. package/src/iso-systems/compile.ts +39 -0
  194. package/src/iso-systems/css.ts +9 -0
  195. package/src/iso-systems/index.ts +12 -0
  196. package/src/iso-systems/nodes.ts +126 -0
  197. package/src/iso-systems/package.json +6 -0
  198. package/src/iso-systems/schema.json +311 -0
  199. package/src/iso-systems/validate.ts +34 -0
  200. package/src/iso-viewer/bundle.ts +15 -0
  201. package/src/iso-viewer/card-motion.ts +237 -0
  202. package/src/iso-viewer/dom.ts +13 -0
  203. package/src/iso-viewer/dual-view.ts +212 -0
  204. package/src/iso-viewer/flat-view.ts +127 -0
  205. package/src/iso-viewer/history.ts +781 -0
  206. package/src/iso-viewer/index.ts +40 -0
  207. package/src/iso-viewer/morph.ts +191 -0
  208. package/src/iso-viewer/overlay.ts +212 -0
  209. package/src/iso-viewer/package.json +6 -0
  210. package/src/iso-viewer/page.ts +150 -0
  211. package/src/iso-viewer/player.ts +321 -0
  212. package/src/iso-viewer/still.ts +74 -0
  213. package/src/iso-viewer/timeline-contract.ts +342 -0
  214. package/src/iso-viewer/timeline-engine.ts +420 -0
  215. package/src/iso-viewer/timeline-export.ts +31 -0
  216. package/src/iso-viewer/timeline-scale.ts +129 -0
  217. package/src/iso-viewer/timeline-scope.ts +56 -0
  218. package/src/iso-viewer/timeline-search.ts +198 -0
  219. package/src/iso-viewer/timeline-time.ts +54 -0
  220. package/src/iso-viewer/view-css.ts +59 -0
  221. package/src/iso-viewer/viewport.ts +142 -0
  222. package/types/iso-core/compile-schema.d.ts +11 -0
  223. package/types/iso-core/depth.d.ts +6 -0
  224. package/types/iso-core/errors.d.ts +24 -0
  225. package/types/iso-core/glyphs.d.ts +19 -0
  226. package/types/iso-core/index.d.ts +17 -0
  227. package/types/iso-core/kernel.d.ts +130 -0
  228. package/types/iso-core/metrics.json +1 -0
  229. package/types/iso-core/parse.d.ts +18 -0
  230. package/types/iso-core/schema-errors.d.ts +14 -0
  231. package/types/iso-core/shims/crypto.d.ts +9 -0
  232. package/types/iso-core/svg-dom.d.ts +15 -0
  233. package/types/iso-core/theme.d.ts +38 -0
  234. package/types/iso-core/vdom.d.ts +26 -0
  235. package/types/iso-editor/adapter.d.ts +145 -0
  236. package/types/iso-editor/clipboard.d.ts +23 -0
  237. package/types/iso-editor/commands.d.ts +32 -0
  238. package/types/iso-editor/complete.d.ts +25 -0
  239. package/types/iso-editor/doc.d.ts +50 -0
  240. package/types/iso-editor/index.d.ts +57 -0
  241. package/types/iso-editor/model.d.ts +96 -0
  242. package/types/iso-editor/outline.d.ts +28 -0
  243. package/types/iso-editor/path.d.ts +7 -0
  244. package/types/iso-editor/providers.d.ts +43 -0
  245. package/types/iso-editor/schema-nav.d.ts +34 -0
  246. package/types/iso-editor/splice.d.ts +53 -0
  247. package/types/iso-editor/storage-keys.d.ts +5 -0
  248. package/types/iso-editor/ui/actions.d.ts +23 -0
  249. package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
  250. package/types/iso-editor/ui/canvas.d.ts +279 -0
  251. package/types/iso-editor/ui/clip.d.ts +14 -0
  252. package/types/iso-editor/ui/dialog.d.ts +7 -0
  253. package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
  254. package/types/iso-editor/ui/icons.d.ts +5 -0
  255. package/types/iso-editor/ui/keys.d.ts +7 -0
  256. package/types/iso-editor/ui/later.d.ts +12 -0
  257. package/types/iso-editor/ui/layer.d.ts +2 -0
  258. package/types/iso-editor/ui/menu.d.ts +21 -0
  259. package/types/iso-editor/ui/mount-kit.d.ts +31 -0
  260. package/types/iso-editor/ui/mount.d.ts +146 -0
  261. package/types/iso-editor/ui/pane.d.ts +60 -0
  262. package/types/iso-editor/ui/part.d.ts +40 -0
  263. package/types/iso-editor/ui/plain-icons.d.ts +10 -0
  264. package/types/iso-editor/ui/props.d.ts +57 -0
  265. package/types/iso-editor/ui/scope-css.d.ts +5 -0
  266. package/types/iso-editor/ui/setup.d.ts +40 -0
  267. package/types/iso-editor/ui/text.d.ts +19 -0
  268. package/types/iso-editor/ui/tree.d.ts +100 -0
  269. package/types/iso-editor/validate.d.ts +36 -0
  270. package/types/iso-editor/window/protocol.d.ts +60 -0
  271. package/types/iso-objects/assemble.d.ts +35 -0
  272. package/types/iso-objects/assets.d.ts +49 -0
  273. package/types/iso-objects/board.d.ts +36 -0
  274. package/types/iso-objects/compile.d.ts +35 -0
  275. package/types/iso-objects/css.d.ts +16 -0
  276. package/types/iso-objects/flat.d.ts +130 -0
  277. package/types/iso-objects/focus.d.ts +1 -0
  278. package/types/iso-objects/geometry.d.ts +59 -0
  279. package/types/iso-objects/index.d.ts +26 -0
  280. package/types/iso-objects/kinds.d.ts +53 -0
  281. package/types/iso-objects/labels.d.ts +92 -0
  282. package/types/iso-objects/place.d.ts +25 -0
  283. package/types/iso-objects/route.d.ts +67 -0
  284. package/types/iso-objects/scene.d.ts +63 -0
  285. package/types/iso-objects/steps.d.ts +90 -0
  286. package/types/iso-objects/types.d.ts +140 -0
  287. package/types/iso-systems/catalog.d.ts +4 -0
  288. package/types/iso-systems/compile.d.ts +6 -0
  289. package/types/iso-systems/css.d.ts +3 -0
  290. package/types/iso-systems/index.d.ts +5 -0
  291. package/types/iso-systems/nodes.d.ts +3 -0
  292. package/types/iso-viewer/card-motion.d.ts +56 -0
  293. package/types/iso-viewer/dom.d.ts +1 -0
  294. package/types/iso-viewer/dual-view.d.ts +44 -0
  295. package/types/iso-viewer/flat-view.d.ts +25 -0
  296. package/types/iso-viewer/history.d.ts +91 -0
  297. package/types/iso-viewer/index.d.ts +31 -0
  298. package/types/iso-viewer/morph.d.ts +28 -0
  299. package/types/iso-viewer/overlay.d.ts +135 -0
  300. package/types/iso-viewer/page.d.ts +13 -0
  301. package/types/iso-viewer/still.d.ts +26 -0
  302. package/types/iso-viewer/timeline-contract.d.ts +345 -0
  303. package/types/iso-viewer/timeline-engine.d.ts +20 -0
  304. package/types/iso-viewer/timeline-export.d.ts +5 -0
  305. package/types/iso-viewer/timeline-scale.d.ts +44 -0
  306. package/types/iso-viewer/timeline-scope.d.ts +33 -0
  307. package/types/iso-viewer/timeline-search.d.ts +52 -0
  308. package/types/iso-viewer/timeline-time.d.ts +8 -0
  309. package/types/iso-viewer/view-css.d.ts +7 -0
  310. package/types/iso-viewer/viewport.d.ts +50 -0
@@ -0,0 +1,97 @@
1
+ // The clipboard in the page: ⌘C, ⌘X and ⌘V in the tree and on the canvas go through the system clipboard as plain
2
+ // text, so a copy pastes into the text pane, another file or another program, and back. The menus' Copy, Cut and
3
+ // Paste use the async clipboard API, with the last copy kept here as a fallback where reading is refused. In the text
4
+ // pane (and any field) the browser's own clipboard applies. The YAML and the commands are src/iso-editor/clipboard.ts.
5
+
6
+ import type { Clipboard } from '../clipboard.ts';
7
+ import type { EditorModel } from '../model.ts';
8
+ import type { MenuItem } from './menu.ts';
9
+
10
+ export interface Clip {
11
+ /** the menu items for what is selected */
12
+ items(): MenuItem[];
13
+ /** handle the clipboard events of a document (the page, or the canvas's frame) */
14
+ attach(d: EventTarget, owns: (target: EventTarget | null) => boolean): () => void;
15
+ copy(): Promise<boolean>;
16
+ cut(): Promise<boolean>;
17
+ paste(text?: string): Promise<boolean>;
18
+ }
19
+
20
+ /** the page's clipboard over the domain's (its copyText, cutCmd and pasteCmd: src/iso-editor/clipboard.ts) */
21
+ export function clipboard(doc: EditorModel, note: (t: string, tone?: 'info' | 'warn' | 'bad') => void, services: Clipboard): Clip {
22
+ const { copyText, cutCmd, pasteCmd } = services;
23
+ let last = '';
24
+ const ro = () => !doc.doc.ok;
25
+ const editable = (t: EventTarget | null) => !!(t as HTMLElement | null)?.closest?.('input, textarea, select, .monaco-editor, [contenteditable]');
26
+
27
+ const doCopy = (): string | undefined => {
28
+ const c = copyText(doc.text, doc.selection);
29
+ if (!c) { note('Select something to copy'); return undefined; }
30
+ last = c.text;
31
+ note(`Copied ${c.what}`);
32
+ return c.text;
33
+ };
34
+ const doCut = (): string | undefined => {
35
+ if (ro()) { note('Fix the YAML first', 'warn'); return undefined; }
36
+ const c = cutCmd(doc.text, doc.selection);
37
+ if (!c) { note('Select something to cut'); return undefined; }
38
+ last = c.text;
39
+ doc.apply(c.cmd, 'menu');
40
+ doc.select([], 'menu');
41
+ return c.text;
42
+ };
43
+ const doPaste = (text: string): boolean => {
44
+ if (ro()) { note('Fix the YAML first', 'warn'); return false; }
45
+ const p = pasteCmd(doc.text, text, doc.selection);
46
+ if (!p.cmd) { note(`Can't paste: ${p.error}`, 'warn'); return false; }
47
+ try {
48
+ if (!doc.apply(p.cmd, 'menu')) return false;
49
+ } catch (e) { note(`Can't paste: ${(e as Error).message}`, 'bad'); return false; }
50
+ if (p.cmd.select) doc.select(p.cmd.select, 'menu');
51
+ const renamed = p.names ? [...p.names].filter(([a, b]) => a !== b) : [];
52
+ note(renamed.length ? `${p.what}: ${renamed.map(([a, b]) => `${a} → ${b}`).join(', ')}` : p.what);
53
+ return true;
54
+ };
55
+
56
+ return {
57
+ items() {
58
+ const has = doc.selection.length > 0;
59
+ return [
60
+ { label: 'Cut', icon: 'clipboard', keys: '⌘X', disabled: !has || ro(), why: has ? 'Fix the YAML first' : 'Nothing selected', onSelect: () => void this.cut() },
61
+ { label: 'Copy', icon: 'copy', keys: '⌘C', disabled: !has, why: 'Nothing selected', onSelect: () => void this.copy() },
62
+ { label: 'Paste', icon: 'clipboard-paste', keys: '⌘V', disabled: ro(), why: 'Fix the YAML first', onSelect: () => void this.paste() },
63
+ ];
64
+ },
65
+ attach(d, owns) {
66
+ const copy = (ev: Event) => {
67
+ const e = ev as ClipboardEvent;
68
+ if (editable(e.target) || !owns(e.target)) return;
69
+ const t = doCopy();
70
+ if (t !== undefined) { e.clipboardData?.setData('text/plain', t); e.preventDefault(); }
71
+ };
72
+ const cut = (ev: Event) => {
73
+ const e = ev as ClipboardEvent;
74
+ if (editable(e.target) || !owns(e.target)) return;
75
+ const t = doCut();
76
+ if (t !== undefined) { e.clipboardData?.setData('text/plain', t); e.preventDefault(); }
77
+ };
78
+ const paste = (ev: Event) => {
79
+ const e = ev as ClipboardEvent;
80
+ if (editable(e.target) || !owns(e.target)) return;
81
+ const t = e.clipboardData?.getData('text/plain') ?? '';
82
+ e.preventDefault();
83
+ doPaste(t || last);
84
+ };
85
+ d.addEventListener('copy', copy); d.addEventListener('cut', cut); d.addEventListener('paste', paste);
86
+ return () => { d.removeEventListener('copy', copy); d.removeEventListener('cut', cut); d.removeEventListener('paste', paste); };
87
+ },
88
+ async copy() { const t = doCopy(); if (t === undefined) return false; try { await navigator.clipboard.writeText(t); } catch { /* kept here */ } return true; },
89
+ async cut() { const t = doCut(); if (t === undefined) return false; try { await navigator.clipboard.writeText(t); } catch { /* kept here */ } return true; },
90
+ async paste(text?: string) {
91
+ let t = text;
92
+ if (t === undefined) { try { t = await navigator.clipboard.readText(); } catch { t = last; } }
93
+ if (!t) { note('The clipboard is empty'); return false; }
94
+ return doPaste(t);
95
+ },
96
+ };
97
+ }
@@ -0,0 +1,25 @@
1
+ // A modal dialog (the <dialog class="dlg"> structure: head, body and foot; provenance: docs/editor/INTEGRATION.md, its table of what is copied), as
2
+ // a promise: it resolves with the chosen button's value, or null when cancelled.
3
+
4
+ import { h } from './icons.ts';
5
+ import { layer } from './layer.ts';
6
+
7
+ export interface DialogButton { label: string; value: string; primary?: boolean; danger?: boolean }
8
+
9
+ export function ask(title: string, body: (Node | string)[], buttons: DialogButton[]): Promise<string | null> {
10
+ return new Promise(resolve => {
11
+ const d = h('dialog', { class: 'dlg', 'aria-label': title });
12
+ const form = h('form', { method: 'dialog' });
13
+ const foot = h('div', { class: 'dlg-foot' });
14
+ for (const b of buttons) {
15
+ const btn = h('button', { type: 'submit', value: b.value, class: `btn${b.primary ? ' primary' : ''}${b.danger ? ' danger' : ''}` }, b.label);
16
+ foot.append(btn);
17
+ }
18
+ form.append(h('div', { class: 'dlg-head' }, h('h2', { class: 'h-title' }, title)), h('div', { class: 'dlg-body' }, ...body), foot);
19
+ d.append(form);
20
+ layer().append(d);
21
+ d.addEventListener('close', () => { const v = d.returnValue; d.remove(); resolve(v && v !== 'cancel' ? v : null); });
22
+ d.showModal();
23
+ (foot.querySelector('.primary') as HTMLElement | null)?.focus();
24
+ });
25
+ }
@@ -0,0 +1,51 @@
1
+ // The canvas's 2D view (0.6.4): what the canvas asks of it, done with the flat layout. The canvas never imports this
2
+ // module: a host that wants the 2D view hands it over (DomainView.flat.load, e.g. `() => import(…).then(m => m.flatCanvas)`),
3
+ // so a host that gives no 2D view bundles none of it.
4
+
5
+ import { boardOf } from '../../iso-objects/board.ts';
6
+ import { layoutFlat } from '../../iso-objects/flat.ts';
7
+ import { flatSvg, measureIn } from '../../iso-viewer/flat-view.ts';
8
+ import { markConnectors, morphSvgs } from '../../iso-viewer/morph.ts';
9
+ import type { FlatCanvas, FlatDrawn } from './canvas.ts';
10
+
11
+ export const flatCanvas: FlatCanvas = {
12
+ draw(scene, stage, o) {
13
+ // laid out with the stage's own text measured (the host's canvas CSS has the 2D view's stylesheet)
14
+ const m = measureIn(stage);
15
+ let L;
16
+ try { L = layoutFlat(boardOf(scene), m, o.options); } finally { m.dispose(); }
17
+ const b = L.bounds;
18
+ const rectOf = (id: string) => L.cards.find(c => c.id === id)?.rect ?? L.panels.find(p => p.id === id)?.rect;
19
+ const drawn: FlatDrawn = {
20
+ svg: flatSvg(L, { id: 'canvas-2d', title: o.title, styles: o.styles }),
21
+ full: [b.l, b.t, b.r - b.l, b.b - b.t],
22
+ layout: L,
23
+ outlines(ids, svg) {
24
+ const out: ReturnType<FlatDrawn['outlines']> = [];
25
+ for (const id of ids) {
26
+ const r = rectOf(id);
27
+ if (r) { out.push({ kind: 'poly', id, points: [[r.l, r.t], [r.r, r.t], [r.r, r.b], [r.l, r.b]] }); continue; }
28
+ const d = svg.querySelector(`path.conn[data-id="${CSS.escape(id)}"]`)?.getAttribute('d');
29
+ if (d) out.push({ kind: 'route', d });
30
+ }
31
+ return out;
32
+ },
33
+ hits(g, touch) {
34
+ return [...L.cards, ...L.panels].filter(it => {
35
+ const r = it.rect;
36
+ return touch ? r.l < g.r && r.r > g.l && r.t < g.b && r.b > g.t : r.l >= g.l && r.t >= g.t && r.r <= g.r && r.b <= g.b;
37
+ }).map(it => it.id);
38
+ },
39
+ panelsAt(x, y) {
40
+ return [...L.panels].sort((p, q) => q.depth - p.depth).filter(p => x >= p.rect.l && x <= p.rect.r && y >= p.rect.t && y <= p.rect.b).map(p => p.id);
41
+ },
42
+ };
43
+ return drawn;
44
+ },
45
+ // 0.7.5: the switch's morph, dualView's: the 3D drawing's connectors marked with their ends first, as the 2D ones are
46
+ morph(root, scene, from, to, o) {
47
+ const svg3 = from.mode === '3d' ? from.svg : to;
48
+ markConnectors(svg3, scene, boardOf(scene));
49
+ return morphSvgs(root, from.svg, to, from.mode, o);
50
+ },
51
+ };
@@ -0,0 +1,21 @@
1
+ // Icons, by name, from a sprite of <symbol id="se-i-NAME"> the host's build puts in the editor's root at mount (the
2
+ // names it holds are the domain's list): an icon is <svg class="icon"><use href="#se-i-NAME"></svg>, hidden from
3
+ // assistive tech (every button keeps its text or aria-label). Provenance: docs/editor/INTEGRATION.md, its table of what is copied.
4
+
5
+ /** an icon's name in the sprite */
6
+ export type IconName = string;
7
+
8
+
9
+ const NS = 'http://www.w3.org/2000/svg';
10
+ export function icon(name: IconName, cls = ''): SVGSVGElement {
11
+ const svg = document.createElementNS(NS, 'svg');
12
+ svg.setAttribute('class', `icon${cls ? ' ' + cls : ''}`);
13
+ svg.setAttribute('aria-hidden', 'true');
14
+ const use = document.createElementNS(NS, 'use');
15
+ use.setAttribute('href', `#se-i-${name}`);
16
+ svg.append(use);
17
+ return svg;
18
+ }
19
+
20
+ /** h(): the DOM, built as text only (never HTML), from the viewer (src/iso-viewer/dom.ts) */
21
+ export { h } from '../../iso-viewer/dom.ts';
@@ -0,0 +1,30 @@
1
+ // The keyboard sheet: every key the editor answers, by where it applies (the domain's map), opened with ? (outside a
2
+ // text field) or the title bar's Keys button.
3
+
4
+ import { h } from './icons.ts';
5
+ import { layer } from './layer.ts';
6
+
7
+ export type KeyGroup = { where: string; keys: [string, string][] };
8
+
9
+ /** The map with a host's own keys added to the first group (the standalone page: ⇧⌘S Save as, ⌘O Open). */
10
+ export function keymapWith(map: KeyGroup[], extra: [string, string][]): KeyGroup[] {
11
+ return map.map((g, i) => (i === 0 ? { ...g, keys: [...g.keys.slice(0, 1), ...extra, ...g.keys.slice(1)] } : g));
12
+ }
13
+
14
+ export function keySheet(map: KeyGroup[]): HTMLDialogElement {
15
+ const d = h('dialog', { class: 'dlg keys-dlg', 'aria-label': 'Keyboard' });
16
+ const form = h('form', { method: 'dialog' });
17
+ const body = h('div', { class: 'dlg-body keys' });
18
+ for (const g of map) {
19
+ body.append(h('h3', { class: 'keys-h' }, g.where));
20
+ const dl = h('dl', { class: 'keys-list' });
21
+ for (const [k, what] of g.keys) dl.append(h('dt', null, ...k.split(/(\s+or\s+|,\s*)/).map(p => (/^\s+or\s+$|^,\s*$/.test(p) ? p : h('kbd', null, p)))), h('dd', null, what));
22
+ body.append(dl);
23
+ }
24
+ form.append(h('div', { class: 'dlg-head' }, h('h2', { class: 'h-title' }, 'Keyboard')), body, h('div', { class: 'dlg-foot' }, h('button', { type: 'submit', class: 'btn primary', value: 'close' }, 'Close')));
25
+ d.append(form);
26
+ d.addEventListener('close', () => d.remove());
27
+ layer().append(d);
28
+ d.showModal();
29
+ return d;
30
+ }
@@ -0,0 +1,22 @@
1
+ // Work that waits for a pause in typing. Typing in a text pane is synchronous to the model and the other pane (the
2
+ // text never lags); the structural views (the tree, the properties, the path at the caret, the problems and canvas)
3
+ // repaint once typing pauses, so a keystroke never waits on a parse of the whole file.
4
+
5
+ import type { Change } from '../model.ts';
6
+
7
+ export const TYPING_PAUSE_MS = 150;
8
+
9
+ /** Is this change typing (from a text pane)? Then the structural views can wait. */
10
+ export const isTyping = (c: Change) => c.kind === 'do' && c.origin === 'text';
11
+
12
+ /** A function that runs `fn` once, `ms` after the last call; `now()` runs it at once (and cancels the wait); `cancel()`
13
+ * drops a pending run (when the editor is disposed). */
14
+ export function later(fn: () => void, ms = TYPING_PAUSE_MS): { (): void; now(): void; pending(): boolean; cancel(): void } {
15
+ let t = 0;
16
+ const run = () => { t = 0; fn(); };
17
+ const f = () => { clearTimeout(t); t = window.setTimeout(run, ms); };
18
+ f.now = () => { clearTimeout(t); run(); };
19
+ f.pending = () => t !== 0;
20
+ f.cancel = () => { clearTimeout(t); t = 0; };
21
+ return f;
22
+ }
@@ -0,0 +1,7 @@
1
+ // Where the editor puts what floats over it (menus, dialogs, the keyboard sheet): inside its own root, so its styles
2
+ // apply and disposing the editor removes them. The root of the editor last used (mount.ts sets it on focus and at
3
+ // mount); document.body only when no editor is mounted (the Node tests).
4
+
5
+ let current: HTMLElement | null = null;
6
+ export function setLayer(el: HTMLElement | null) { current = el; }
7
+ export function layer(): HTMLElement { return current && current.isConnected ? current : document.body; }
@@ -0,0 +1,35 @@
1
+ /* The canvas's own marks over the drawing (0.7.4), for the plain words (setup.ts: the root .iso-canvas, the pan key's
2
+ class .pan-key): selection, hover, marquee, the drag's grid, drop target and edges,
3
+ problem badges, and the canvas's cursors. On the skin's tokens: --iso-sel* default to --accent, --iso-bad and
4
+ --iso-warn to --bad and --warn; a host may set any of them on .iso-canvas. The package's assets/app.css carries
5
+ this file after the layout, and it ships alone as assets/marks.css. (A domain with its own words styles its own.)
6
+ Without any of it the marks are still harmless: the overlay's own attributes give no fill and take no pointer. */
7
+ @layer views {
8
+ .iso-canvas { --iso-sel: var(--accent); --iso-sel-fill: color-mix(in srgb, var(--iso-sel) 12%, transparent);
9
+ --iso-sel-faint: color-mix(in srgb, var(--iso-sel) 6%, transparent); --iso-bad: var(--bad); --iso-warn: var(--warn); }
10
+ .iso-canvas svg.scene [data-id] { cursor: pointer; }
11
+ .iso-canvas svg.scene.mode-pan { cursor: grab; }
12
+ .iso-canvas svg.scene.mode-select { cursor: crosshair; }
13
+ .iso-canvas svg.scene.pan-key, .iso-canvas svg.scene.pan-key [data-id] { cursor: grab; }
14
+ .iso-canvas svg.scene.panning, .iso-canvas svg.scene.panning [data-id] { cursor: grabbing; }
15
+ .iso-canvas svg.scene.drag-bad, .iso-canvas svg.scene.drag-bad * { cursor: not-allowed !important; }
16
+ .iso-canvas svg.scene.dragging, .iso-canvas svg.scene.dragging * { cursor: grabbing; }
17
+ .iso-canvas .overlay, .iso-canvas .overlay * { pointer-events: none; }
18
+ .iso-canvas .overlay .ring { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
19
+ .iso-canvas .overlay .hover { fill: var(--iso-sel-faint); stroke: var(--iso-sel); stroke-width: 1; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: .55; }
20
+ .iso-canvas .overlay .route-ring { fill: none; stroke: var(--iso-sel); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; opacity: .35; vector-effect: non-scaling-stroke; }
21
+ .iso-canvas .overlay .route-hover { fill: none; stroke: var(--iso-sel); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: .18; vector-effect: non-scaling-stroke; }
22
+ .iso-canvas .overlay .marquee { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 1.2; stroke-dasharray: 5 4; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
23
+ .iso-canvas .overlay .dgrid { fill: none; stroke: var(--iso-sel); stroke-width: 1; opacity: .42; vector-effect: non-scaling-stroke; }
24
+ .iso-canvas .overlay .dgrid.sub { opacity: .24; stroke-dasharray: 2 3; }
25
+ .iso-canvas .overlay .gridwrap.fresh { animation: iso-gridin .18s ease-out; }
26
+ .iso-canvas .overlay .out { opacity: 0; transition: opacity .15s ease-in; }
27
+ .iso-canvas .overlay .drop { fill: var(--iso-sel-fill); stroke: var(--iso-sel); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
28
+ .iso-canvas .overlay .drop.bad { fill: color-mix(in srgb, var(--iso-bad) 18%, transparent); stroke: var(--iso-bad); }
29
+ .iso-canvas .overlay .edge { fill: none; stroke: var(--iso-sel); stroke-width: 4; stroke-linecap: round; vector-effect: non-scaling-stroke; }
30
+ .iso-canvas .overlay .badge circle { fill: var(--iso-bad); stroke: none; }
31
+ .iso-canvas .overlay .badge.warn circle { fill: var(--iso-warn); }
32
+ .iso-canvas .overlay .badge text { fill: #fff; stroke: none; font-family: system-ui, sans-serif; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
33
+ @media (prefers-reduced-motion: reduce) { .iso-canvas .overlay .gridwrap.fresh { animation: none; } .iso-canvas .overlay .out { transition: none; } }
34
+ }
35
+ @keyframes iso-gridin { from { opacity: 0; } to { opacity: 1; } }
@@ -0,0 +1,67 @@
1
+ // A menu opened at the pointer (the right-click menu) or under a button (provenance: docs/editor/INTEGRATION.md, its table of what is copied; its DOM
2
+ // and classes, rewritten for a position rather than a trigger). Arrow keys, Home and End move;
3
+ // Enter or the Space key chooses; Escape or Tab closes and gives the focus back; a click outside closes. A disabled item stays
4
+ // visible and says why.
5
+
6
+ import { h, icon, type IconName } from './icons.ts';
7
+ import { layer } from './layer.ts';
8
+
9
+ export type MenuItem =
10
+ | { label: string; icon?: IconName; desc?: string; keys?: string; danger?: boolean; disabled?: boolean; why?: string; onSelect(): void }
11
+ | { sep: true } | { heading: string };
12
+
13
+ let open: { el: HTMLElement; close(focusBack: boolean): void } | undefined;
14
+ export const menuOpen = () => !!open;
15
+
16
+ export function openMenu(items: MenuItem[], at: { x: number; y: number } | HTMLElement, label = 'Actions'): HTMLElement {
17
+ open?.close(false);
18
+ const back = document.activeElement as HTMLElement | null;
19
+ const el = h('div', { class: 'menu', role: 'menu', 'aria-label': label, tabindex: '-1' });
20
+ const buttons: HTMLButtonElement[] = [];
21
+ for (const it of items) {
22
+ if ('sep' in it) { el.append(h('div', { class: 'menu-sep', role: 'separator' })); continue; }
23
+ if ('heading' in it) { el.append(h('div', { class: 'menu-label' }, it.heading)); continue; }
24
+ const desc = (it.disabled ? it.why : undefined) ?? it.desc;
25
+ const b = h('button', { type: 'button', role: 'menuitem', tabindex: '-1', class: 'menu-item' + (it.danger ? ' danger' : ''), 'data-desc': desc, 'aria-description': desc },
26
+ it.icon ? icon(it.icon) : h('span'), h('span', { class: 'mi-label' }, it.label), it.keys ? h('span', { class: 'menu-trail' }, it.keys) : null);
27
+ if (it.disabled) b.disabled = true;
28
+ b.addEventListener('click', e => { e.stopPropagation(); if (b.disabled) return; close(true); it.onSelect(); });
29
+ buttons.push(b);
30
+ el.append(b);
31
+ }
32
+ layer().append(el);
33
+ // placed at the point (or under the element), kept on screen
34
+ const r = el.getBoundingClientRect();
35
+ let x: number, y: number;
36
+ if (at instanceof HTMLElement) { const a = at.getBoundingClientRect(); x = a.left; y = a.bottom + 4; if (y + r.height > innerHeight - 8) y = a.top - r.height - 4; }
37
+ else { x = at.x; y = at.y; if (y + r.height > innerHeight - 8) y = Math.max(8, at.y - r.height); }
38
+ el.style.left = `${Math.max(8, Math.min(x, innerWidth - r.width - 8))}px`;
39
+ el.style.top = `${Math.max(8, y)}px`;
40
+ const live = () => buttons.filter(b => !b.disabled);
41
+ const focus = (i: number) => { const l = live(); if (l.length) l[(i + l.length) % l.length].focus(); };
42
+ focus(0);
43
+ el.addEventListener('keydown', e => {
44
+ const l = live();
45
+ const i = l.indexOf(document.activeElement as HTMLButtonElement);
46
+ if (e.key === 'ArrowDown') { focus(i + 1); e.preventDefault(); }
47
+ else if (e.key === 'ArrowUp') { focus(i - 1); e.preventDefault(); }
48
+ else if (e.key === 'Home') { focus(0); e.preventDefault(); }
49
+ else if (e.key === 'End') { focus(-1); e.preventDefault(); }
50
+ else if (e.key === 'Escape' || e.key === 'Tab') { close(true); e.preventDefault(); }
51
+ e.stopPropagation();
52
+ });
53
+ const outside = (e: Event) => { if (!el.contains(e.target as Node)) close(false); };
54
+ setTimeout(() => { addEventListener('pointerdown', outside, true); addEventListener('blur', blur); }, 0);
55
+ const blur = () => close(false);
56
+ function close(focusBack: boolean) {
57
+ if (!el.isConnected) return;
58
+ el.remove();
59
+ removeEventListener('pointerdown', outside, true);
60
+ removeEventListener('blur', blur);
61
+ open = undefined;
62
+ if (focusBack) back?.focus();
63
+ }
64
+ open = { el, close };
65
+ return el;
66
+ }
67
+ export function closeMenu() { open?.close(false); }
@@ -0,0 +1,6 @@
1
+ // The portable build's Monaco: one ES module (monaco/monaco.js), the editor trimmed to what the text pane uses (the
2
+ // build's lean-monaco) with the YAML grammar. The editor's bundle imports it from beside it.
3
+ // @ts-ignore no d.ts for this path
4
+ export * from 'monaco-editor/editor/editor.main.js';
5
+ // @ts-ignore registers the YAML grammar
6
+ import 'monaco-editor/languages/definitions/yaml/register.js';
@@ -0,0 +1,35 @@
1
+ // What the mounted editor is given of its domain (beside the views' own kits): how a text is checked (the reader's
2
+ // problems, or a host's deeper check, and what the canvas draws), what role a file has and what its kind is called,
3
+ // the schema's navigation, where an object is by its name, the words of the host's check beside Problems, and the
4
+ // keys. (The drawing's theme is the canvas feature's: an editor without a canvas carries none.) Types only: the domain's module gives the values.
5
+
6
+ import type { Problem } from '../validate.ts';
7
+ import type { SchemaNav } from '../schema-nav.ts';
8
+ import type { FileRole } from '../adapter.ts';
9
+ import type { KeyGroup } from './keys.ts';
10
+
11
+ /** a text, checked (R: the domain's reading; X: a host's deeper check, shown beside Problems) */
12
+ export interface Checked<R, X> {
13
+ problems: Problem[];
14
+ read: R | undefined;
15
+ /** each object's tag (the tree's pills) */
16
+ tags: Map<string, string>;
17
+ /** what the canvas draws (undefined: nothing), and the data it is drawn from */
18
+ model: unknown;
19
+ data: unknown;
20
+ extra: X | undefined;
21
+ }
22
+
23
+ export interface MountKit<R, X> {
24
+ /** check a text (prev: the last check's extra); a failure of the host's check is a note, not a throw */
25
+ check(text: string, prev: X | undefined, note: (t: string, tone?: 'info' | 'warn' | 'bad') => void): Promise<Checked<R, X>>;
26
+ role(text: string): FileRole;
27
+ /** the status bar's word for the file's kind */
28
+ kindLabel(text: string): string;
29
+ nav(text: string): SchemaNav;
30
+ /** an object's pointer, by its name, in the reading */
31
+ objectPath(name: string, read: R | undefined): string | undefined;
32
+ /** the host's check beside Problems, in a word (none: '' and '') */
33
+ extraLabel(extra: X | undefined): { text: string; cls: string };
34
+ keymap: KeyGroup[];
35
+ }