@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,317 @@
1
+ # Write your own editor on @johnoscott/isometric-engine
2
+
3
+ This guide is for someone who has only the published package. You describe your file format to the engine (an
4
+ **adapter**) and how a file is drawn (a **view**). The editor around them comes from the package: the tree, the
5
+ properties panel, the canvas in 3D and 2D, the palette, menus, keys, problems, undo and save.
6
+
7
+ The running example is **boxes/1**, a small format of boxes, trays and links. A larger case on the same contract is a
8
+ cloud architecture editor: two kinds (groups and resources), 31 resource types, nested groups, and connections with
9
+ labels. Everything below scales to it unchanged.
10
+
11
+ ```yaml
12
+ format: boxes/1
13
+ title: Two trays
14
+ boxes:
15
+ shelf: { kind: tray, label: Shelf } # a tray or a zone holds boxes
16
+ a: { in: shelf, label: A }
17
+ b: { in: shelf, label: B }
18
+ floor: { kind: zone, label: Floor }
19
+ c: { in: floor, label: C }
20
+ links:
21
+ - { from: a, to: b }
22
+ - { from: b, to: c }
23
+ ```
24
+
25
+ ## 1. What the editor gives you
26
+
27
+ All of this comes from `@johnoscott/isometric-engine/editor`, namespace `editor`:
28
+
29
+ - **The document model and undo.** The text is the truth. Every edit, from the tree, the canvas, the properties or
30
+ a command, is a splice of the text, so comments and formatting survive and undo is one step per action.
31
+ - **Commands** (`editor.commandsFor(adapter)`): set, insert, rename (every reference follows), delete (optionally with
32
+ every reference), duplicate, paste, and pins.
33
+ - **The canvas**: your drawing in 3D, with selection, a marquee, pan and zoom, and pins (a dragged object is pinned in
34
+ the file). It also has a **2D view** that you opt into: the same drawing laid out flat, with a 3D | 2D switch.
35
+ - **The outline (tree)**, **properties** (from your JSON Schema), **problems**, **palette**, **menus** and **keys**.
36
+ - **`editor.mountEditor(element, options, setup)`**, which puts it all on a page, where `setup = editor.setupFor(adapter,
37
+ view)`.
38
+
39
+ The other namespaces in the same import are the layers underneath: `core` (parsing, themes, the SVG kernel),
40
+ `objects` (object kinds, layout, routing and `compileRaw`, which turns a drawing into SVG) and `viewer` (pan and zoom,
41
+ overlays, CSS scoping, the 2D view and the morph).
42
+
43
+ ## 2. The adapter and the view
44
+
45
+ The adapter is plain data and functions, with no DOM. Field by field:
46
+
47
+ - `id`: the format's name. `role(text)` says whether a text is a `'main'` file (or a `'base'` that others extend).
48
+ - `schema(role)`: a JSON Schema. The properties panel and completion are built from it, and `enum`s become choices.
49
+ - `read(text)`: your reader. It returns `diags`, each with a JSON-pointer `path` (the editor places it from the text),
50
+ and `read`, your own reading, which your view draws.
51
+ - `kinds`: the things a file holds, each in a map of its own (`section`), with a `template()` for a new one. Names are
52
+ unique across all kinds.
53
+ - `objectOf(pointer)` and `describe(path)`: which object a pointer is inside, and a path in words ("box a").
54
+ - `refs(data)` and `slotAt(pointer)`: every place whose value names another object (`in:`, `from:`, `to:`), with the
55
+ slot it is in. Renaming and deleting are built on them.
56
+ - `renameRef(ref, to)`: a reference's new text when its target is renamed.
57
+ - `refDeletePath(path)`: what deleting a reference removes along with its target. That's the reference itself, or
58
+ the entry that holds it (a link without its `to` is no link: remove `/links/3`, not `/links/3/to`).
59
+ - `topOrder`, `outline`, `pins`, `snippets`, `copyValue`, `entryGroups`, `keyMessage`, `noun`: the details, shown in
60
+ the example.
61
+
62
+ The view (`editor.DomainView`) says how a reading is drawn:
63
+
64
+ - `draw(read, data, theme)`: build the engine's drawing (`objects.compileRaw` with your catalogue) and return its
65
+ `scene` and `svg`. Also return `pathOf`, a map from each drawn element's `data-id` to the JSON pointer it shows (a
66
+ click on the canvas selects that path), and `pinId`, the element a pin moves.
67
+ - `catalog`: your object kinds (`objects.KindCatalog`): region kinds by shape, and node kinds that draw themselves.
68
+ - `icons`: your kinds' icons, as 24 × 24 SVG bodies by name. `icon(kind)` chooses one for each kind.
69
+ - `flat`: the 2D view. Give `load` (it returns `editor.flatCanvas`) and each link kind's style. Leave it out and the
70
+ canvas is 3D only. The switch morphs between the views; `motion: 'always'` morphs even under reduced motion,
71
+ `'never'` swaps at once (the default, `'auto'`, honours the reader's setting).
72
+
73
+ ```ts
74
+ // file: boxes.ts
75
+ import { core, objects, editor } from '@johnoscott/isometric-engine/editor';
76
+
77
+ type Raw = Record<string, unknown>;
78
+ const isMap = (v: unknown): v is Raw => !!v && typeof v === 'object' && !Array.isArray(v);
79
+
80
+ /** a tray (a block that holds boxes), a zone (a tint on the floor that holds boxes), a box */
81
+ export const CATALOG: objects.KindCatalog = {
82
+ regions: {
83
+ tray: { shape: 'block', pad: 0.6, z: [0, 0.3], floor: true, role: 'server', labelStyle: 'floor' },
84
+ zone: { shape: 'zone', pad: 0.5, z: [0, 0.005], floor: false, role: 'grey', labelStyle: 'floor' },
85
+ },
86
+ nodes: { box: objects.boxAsset('box', 'A box', [2, 2, 1], 'lead') },
87
+ defaultNode: 'box',
88
+ };
89
+ const HOLDERS = ['tray', 'zone'];
90
+
91
+ export interface Box { name: string; kind: string; in?: string; label?: string; path: string }
92
+ export interface Boxes { data: Raw; boxes: Box[]; links: { from: string; to: string; path: string }[] }
93
+
94
+ /** read a text: the boxes, the links, and what is wrong (each at its JSON pointer) */
95
+ export function readBoxes(text: string): { diags: core.Diag[]; read?: Boxes } {
96
+ const p = core.parse(text);
97
+ const diags: core.Diag[] = [...p.diags];
98
+ const bad = (path: string, message: string) => diags.push({ severity: 'error', message, line: 0, col: 0, path });
99
+ if (!isMap(p.data)) return { diags };
100
+ const data = p.data, boxes: Box[] = [];
101
+ if (data.format !== 'boxes/1') bad('/format', 'format: must be boxes/1');
102
+ for (const [name, v] of Object.entries(isMap(data.boxes) ? data.boxes : {})) {
103
+ const b = isMap(v) ? v : {}, path = editor.toPointer(['boxes', name]);
104
+ const kind = typeof b.kind === 'string' ? b.kind : 'box';
105
+ if (kind !== 'box' && !HOLDERS.includes(kind)) bad(`${path}/kind`, `unknown kind "${kind}": box, tray or zone`);
106
+ boxes.push({ name, kind, in: typeof b.in === 'string' ? b.in : undefined, label: typeof b.label === 'string' ? b.label : undefined, path });
107
+ }
108
+ const byName = new Map(boxes.map(b => [b.name, b]));
109
+ for (const b of boxes) if (b.in !== undefined && !HOLDERS.includes(byName.get(b.in)?.kind ?? '')) bad(`${b.path}/in`, `no tray or zone "${b.in}"`);
110
+ const links: Boxes['links'] = [];
111
+ (Array.isArray(data.links) ? data.links : []).forEach((l, i) => {
112
+ const x = isMap(l) ? l : {}, path = editor.toPointer(['links', i]);
113
+ for (const k of ['from', 'to']) if (!byName.has(String(x[k]))) bad(`${path}/${k}`, `no box "${String(x[k] ?? '')}"`);
114
+ links.push({ from: String(x.from), to: String(x.to), path });
115
+ });
116
+ return { diags, read: { data, boxes, links } };
117
+ }
118
+
119
+ // ---- references: every value that names another box ----
120
+ const SLOTS: editor.RefSlot[] = [
121
+ { at: ['boxes', '*', 'in'], targets: ['boxes'], what: 'the tray or zone it is in' },
122
+ { at: ['links', '#', 'from'], targets: ['boxes'], what: "a link's start" },
123
+ { at: ['links', '#', 'to'], targets: ['boxes'], what: "a link's end" },
124
+ ];
125
+ function refs(data: unknown): editor.Ref[] {
126
+ const out: editor.Ref[] = [], d = isMap(data) ? data : {};
127
+ for (const [name, v] of Object.entries(isMap(d.boxes) ? d.boxes : {}))
128
+ if (isMap(v) && typeof v.in === 'string') out.push({ path: editor.toPointer(['boxes', name, 'in']), slot: SLOTS[0], value: v.in, name: v.in });
129
+ (Array.isArray(d.links) ? d.links : []).forEach((l, i) => {
130
+ for (const [j, k] of [[1, 'from'], [2, 'to']] as const)
131
+ if (isMap(l) && typeof l[k] === 'string') out.push({ path: editor.toPointer(['links', i, k]), slot: SLOTS[j], value: l[k] as string, name: l[k] as string });
132
+ });
133
+ return out;
134
+ }
135
+ const slotAt = (ptr: string) => {
136
+ const parts = ptr.split('/').slice(1);
137
+ return SLOTS.find(s => s.at.length === parts.length && s.at.every((seg, i) => seg === '*' || (seg === '#' ? /^\d+$/.test(parts[i]) : seg === parts[i])));
138
+ };
139
+
140
+ export const boxesAdapter: editor.DomainAdapter = {
141
+ id: 'boxes/1',
142
+ role: () => 'main',
143
+ schema: () => ({
144
+ type: 'object', properties: {
145
+ format: { const: 'boxes/1' }, title: { type: 'string', description: "The drawing's title." },
146
+ boxes: { type: 'object', additionalProperties: { type: 'object', properties: {
147
+ kind: { enum: ['box', 'tray', 'zone'], description: 'A box, or a tray or zone that holds boxes.' },
148
+ in: { type: 'string', description: 'The tray or zone it is in.' }, label: { type: 'string' } } } },
149
+ links: { type: 'array', items: { type: 'object', properties: { from: { type: 'string' }, to: { type: 'string' } } } },
150
+ },
151
+ }),
152
+ read(text) { const r = readBoxes(text); return { diags: r.diags, read: r.read }; },
153
+ keyMessage: /^unknown kind/,
154
+ kinds: [{ kind: 'boxes', section: ['boxes'], singular: 'box', group: 'Boxes', template: () => ({ label: 'New box' }) }],
155
+ noun: 'box',
156
+ objectOf(ptr) { const m = /^\/boxes\/([^/]+)/.exec(ptr); return m ? { kind: 'boxes', name: m[1], path: `/boxes/${m[1]}` } : undefined; },
157
+ describe(p) { return p.length === 2 && p[0] === 'boxes' ? `box ${p[1]}` : p.join('.') || 'the file'; },
158
+ entryGroups: [],
159
+ refs, slotAt,
160
+ renameRef: (_ref, to) => to,
161
+ // a link loses its from or to: the link goes, not just the key
162
+ refDeletePath: p => (p[0] === 'links' ? p.slice(0, 2) : p),
163
+ copyValue: (_kind, v) => v,
164
+ topOrder: ['format', 'title', 'boxes', 'links', 'x-editor'],
165
+ pins: { key: 'x-editor', legacyOnly: () => false },
166
+ snippets: {},
167
+ outline: { kinds: ['boxes'], first: ['format', 'title'], groups: [{ key: 'links', label: 'Links' }], rootLabel: d => String(d.title ?? 'boxes') },
168
+ };
169
+
170
+ /** the drawing: trays and zones as regions, boxes as nodes, links as routes; pins from x-editor.layout */
171
+ export function drawBoxes(r: Boxes, data: unknown, theme: string): editor.CanvasDrawing {
172
+ const pins = isMap(data) && isMap(data['x-editor']) && isMap(data['x-editor'].layout) ? data['x-editor'].layout : {};
173
+ const at = (name: string) => { const v = pins[name]; return isMap(v) && Array.isArray(v.at) ? { at: v.at as [number, number] } : {}; };
174
+ const kids = (name?: string) => r.boxes.filter(b => b.in === name);
175
+ const region = (b: Box): objects.RawRegion => ({ id: b.name, kind: b.kind, label: b.label ?? b.name, ...at(b.name),
176
+ regions: kids(b.name).filter(c => c.kind !== 'box').map(region), nodes: kids(b.name).filter(c => c.kind === 'box').map(node) });
177
+ const node = (b: Box): objects.RawNode => ({ id: b.name, asset: 'box', label: b.label ?? b.name, ...at(b.name) });
178
+ const title = String(r.data.title ?? 'boxes');
179
+ const doc: objects.RawDiagram = { isodiag: 1, title, scenes: [{ id: 'boxes', title,
180
+ regions: kids(undefined).filter(b => b.kind !== 'box').map(region), nodes: kids(undefined).filter(b => b.kind === 'box').map(node),
181
+ routes: r.links.map((l, i) => ({ id: `link-${i}`, from: l.from, to: l.to, kind: 'send' })) }] };
182
+ const compiled = objects.compileRaw(doc, theme, CATALOG), scene = compiled.scenes[0];
183
+ return {
184
+ scene, svg: scene.rendered.svg,
185
+ // every drawn element's data-id → the JSON pointer it shows: a click on the canvas selects that
186
+ pathOf: new Map([...r.boxes.map(b => [b.name, b.path] as [string, string]), ...r.links.map((l, i) => [`link-${i}`, l.path] as [string, string])]),
187
+ pinId: new Map(r.boxes.map(b => [b.name, b.name])), pinNotes: [],
188
+ diags: compiled.diags.filter(d => d.severity === 'error').map(d => d.message),
189
+ };
190
+ }
191
+
192
+ /** the view: the drawing, the catalogue, the theme, and the 2D view */
193
+ export const boxesView = (theme: string): editor.DomainView<Boxes, editor.CanvasDrawing> => ({
194
+ draw: drawBoxes, catalog: CATALOG, theme, fileName: 'boxes.yaml', words: { brand: 'boxes' },
195
+ flat: { load: async () => editor.flatCanvas, title: 'boxes, flat', styles: { send: { color: 'send' } } },
196
+ });
197
+ ```
198
+
199
+ ## 3. A page
200
+
201
+ The package is private, on GitHub Packages. In your project's `.npmrc`, with a token that may read packages in your
202
+ user `~/.npmrc` (never in a repo):
203
+
204
+ ```
205
+ @johnoscott:registry=https://npm.pkg.github.com
206
+ ```
207
+
208
+ ```
209
+ npm i @johnoscott/isometric-engine
210
+ npm i -D esbuild
211
+ ```
212
+
213
+ The page mounts the editor with the plain skin. Its CSS and the theme are files in the package, which a bundler loads
214
+ as text:
215
+
216
+ ```ts
217
+ // file: page.ts
218
+ import { core, objects, viewer, editor } from '@johnoscott/isometric-engine/editor';
219
+ import { boxesAdapter, boxesView, CATALOG } from './boxes.ts';
220
+ // @ts-ignore text (esbuild: loader { '.css': 'text', '.yaml': 'text' })
221
+ import SKIN from '@johnoscott/isometric-engine/assets/skin.css';
222
+ // @ts-ignore text
223
+ import APP from '@johnoscott/isometric-engine/assets/app.css';
224
+ // @ts-ignore text
225
+ import THEME from '@johnoscott/isometric-engine/assets/default-theme.yaml';
226
+
227
+ const theme = String(THEME), root = editor.PLAIN_WORDS.rootClass, canvas = '.iso-canvas';
228
+ const style = document.createElement('style');
229
+ style.textContent = [
230
+ '@layer tokens, base, components, views;',
231
+ editor.scopeCss(String(SKIN) + String(APP), root), // the shell
232
+ viewer.scope(viewer.isoVars(core.themeCss(core.loadTheme(theme))), canvas, root), // the theme's tokens
233
+ viewer.scope(viewer.isoVars(objects.drawingCss(CATALOG) + objects.MARKS_CSS), canvas, root), // the drawing
234
+ viewer.scope(viewer.isoVars(viewer.flatCss({ send: { color: 'send' } })), canvas, root), // its 2D view
235
+ ].join('\n');
236
+ document.head.append(style);
237
+
238
+ const text = 'format: boxes/1\ntitle: Two trays\nboxes:\n shelf: { kind: tray }\n a: { in: shelf }\n b: { in: shelf }\nlinks:\n - { from: a, to: b }\n';
239
+ const el = document.getElementById('app')!;
240
+ const ed = editor.mountEditor(el, { text, onSave: async t => { localStorage.setItem('boxes', t); return { ok: true }; } },
241
+ editor.setupFor(boxesAdapter, boxesView(theme)));
242
+ (window as unknown as { editorHandle: unknown }).editorHandle = ed;
243
+ document.title = 'ready';
244
+ ```
245
+
246
+ `assets/app.css` carries the canvas's marks too (selection, hover, the marquee, the drag's grid, problem badges), in
247
+ the skin's accent; a host that writes its own shell CSS takes `assets/marks.css` instead, and may set `--iso-sel` on
248
+ `.iso-canvas` for another colour. Without either, the marks still draw no fill and never take the pointer.
249
+
250
+ ```
251
+ npx esbuild page.ts --bundle --format=esm --outfile=dist/page.js --loader:.css=text --loader:.yaml=text
252
+ ```
253
+
254
+ Its `index.html` gives the editor a sized element: `<div id="app" style="height:100vh"></div>`, then
255
+ `<script type="module" src="page.js"></script>`.
256
+
257
+ - **CSP.** The editor runs under `script-src 'self'` (no `unsafe-eval`). Styles go in through a `<style>` element, so
258
+ allow `style-src 'self' 'unsafe-inline'`.
259
+ - **Inline-safe.** No bundle holds `<!--`, `<script` or `</script`. Your page may inline its bundle in
260
+ `<script type="module">…</script>` (a page opened from disk), and a bundler printing the package again keeps it so.
261
+ - **Theme.** `assets/default-theme.yaml` is a theme. Your own adds roles (colours by name) and link kinds. The page
262
+ follows `prefers-color-scheme`, or `data-theme="light" | "dark"` on the root.
263
+
264
+ ## 4. What needs what
265
+
266
+ | You want | You need |
267
+ |---|---|
268
+ | to draw or render only (`/render`, `/systems`) | the package alone: it has no dependencies |
269
+ | the editor (`/editor`) | the package; its code needs nothing else |
270
+ | to type-check against `/editor` | `yaml` and `monaco-editor` installed, for their types (or `skipLibCheck`) |
271
+ | a text pane beside the tree and canvas | your own pane on the `TextPane` interface (`editor.PaneOpts`), given as `setupFor`'s third argument, and Monaco in your bundle. The package ships none (Monaco is large); without one, the tree, canvas and properties make a complete editor |
272
+ | the 2D view | `view.flat` with `load: async () => editor.flatCanvas`, and `viewer.flatCss(styles)` in your canvas CSS |
273
+ | isodiag/1 YAML drawings | `/systems`: `systems.compile(yaml, theme)` (see the README) |
274
+
275
+ ## 5. Testing your adapter
276
+
277
+ What we test on every adapter. Each is a few lines with the commands and the splice they make:
278
+
279
+ ```ts
280
+ // file: boxes.test.ts
281
+ import { test } from 'node:test';
282
+ import assert from 'node:assert/strict';
283
+ import { editor } from '@johnoscott/isometric-engine/editor';
284
+ import { boxesAdapter, readBoxes } from './boxes.ts';
285
+
286
+ const TEXT = 'format: boxes/1\nboxes:\n shelf: { kind: tray }\n a: { in: shelf }\n b: { in: shelf }\nlinks:\n - { from: a, to: b }\n - { from: b, to: a }\n';
287
+ const C = editor.commandsFor(boxesAdapter);
288
+ const run = (text: string, cmd: { build(t: string): { steps: Parameters<typeof editor.applyStep>[1][] } }) =>
289
+ cmd.build(text).steps.reduce((t, s) => editor.applyStep(t, s), text);
290
+
291
+ test('every reference is found', () => {
292
+ const r = readBoxes(TEXT).read!;
293
+ assert.deepEqual(boxesAdapter.refs(r.data).map(x => x.path), ['/boxes/a/in', '/boxes/b/in', '/links/0/from', '/links/0/to', '/links/1/from', '/links/1/to']);
294
+ });
295
+
296
+ test('a rename follows every reference, and the result reads cleanly', () => {
297
+ const out = run(TEXT, C.renameCmd(['boxes', 'shelf'], 'rack'));
298
+ assert.match(out, /a: \{ in: rack \}/);
299
+ assert.deepEqual(readBoxes(out).diags, []);
300
+ });
301
+
302
+ test('a delete with its references leaves none dangling', () => {
303
+ const out = run(TEXT, C.deleteCmd(['boxes', 'a'], { withRefs: true }));
304
+ assert.doesNotMatch(out, /\ba:|from: a|to: a/);
305
+ assert.deepEqual(readBoxes(out).diags, []);
306
+ });
307
+ ```
308
+
309
+ In a browser, a smoke test mounts the page and checks the following:
310
+ - the drawing has every object (`[data-id="a"]` in the canvas's SVG);
311
+ - a click on one selects it in the tree (`.trow[aria-selected="true"]`);
312
+ - F2 renames it with its references, and ⌘Z undoes that in one step;
313
+ - every icon resolves (each `<use href>` finds its `<symbol>`);
314
+ - there are no console errors and no CSP violations (listen for `securitypolicyviolation`).
315
+
316
+ Drive Chrome headless over the DevTools protocol. Use `--headless=new` with a throwaway `--user-data-dir`, and serve
317
+ the page from a free port or through `Fetch.fulfillRequest`, so test runs never collide.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Johno Scott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2021 Evgeny Poberezkin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,43 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Lucide Icons and Contributors
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+
17
+ ---
18
+
19
+ The following Lucide icons are derived from the Feather project:
20
+
21
+ airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out
22
+
23
+ The MIT License (MIT) (for the icons listed above)
24
+
25
+ Copyright (c) 2013-present Cole Bemis
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ Copyright Eemeli Aro <eemeli@gmail.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # @johnoscott/isometric-engine 0.9.0
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A generic isometric diagram engine: `@johnoscott/isometric-engine/render` (L0 core, L1 objects, L2 viewer)
4
+ and `@johnoscott/isometric-engine/editor` (the same, and L3 editor). Each exports one namespace per layer:
5
+ `{ core, objects, viewer, editor }`. It has no product-specific content; hosts register their own marks with
6
+ `objects.registerMarks`. MIT (`LICENSE`); the code it bundles keeps its own licences (`LICENSES/`).
7
+
8
+ **Writing an editor of your own?** Start with `EDITOR-GUIDE.md` in this package: the adapter and view for a small
9
+ format, a page that mounts the editor, and how to test it, all worked from one example.
10
+
11
+ Install:
12
+
13
+ npm i @johnoscott/isometric-engine
14
+
15
+ Use:
16
+
17
+ import { core, objects, viewer, editor } from '@johnoscott/isometric-engine/editor';
18
+ import SKIN from '@johnoscott/isometric-engine/assets/skin.css'; // L3's plain skin (as text, with your bundler's loader)
19
+ import APP from '@johnoscott/isometric-engine/assets/app.css'; // the editor shell's layout
20
+ import THEME from '@johnoscott/isometric-engine/assets/default-theme.yaml'; // a theme to draw with
21
+
22
+ - Mount with `editor.mountEditor(el, options, editor.setupFor(adapter, view))`, `adapter` being your own `DomainAdapter`.
23
+ - Scope the CSS to the shell: `editor.scopeCss(SKIN + APP, editor.PLAIN_WORDS.rootClass)`.
24
+ - Icons: `setupFor` gives the editor L3's own (Lucide, ISC; the names are `editor.PLAIN_ICONS`). Add your kinds' icons
25
+ with the view's `icons` (24 × 24 SVG bodies by name). `assets/icons.svg` is the same sprite as a file.
26
+ - No dependencies: the bundles carry what they run. `/editor`'s declarations name `yaml`'s types and, for the optional
27
+ Monaco text pane, `monaco-editor`'s: a host type-checking against `/editor` installs those itself (needed for /editor
28
+ only), or uses `skipLibCheck`. `/render` and `/systems` need nothing else installed.
29
+ - Inline-safe: no bundle holds `<!--`, `<script` or `</script`, so a page may inline one (or its own bundle of them)
30
+ in `<script type="module">…</script>`, as a page opened from disk does.
31
+ - Schemas: `core` compiles JSON Schemas with ajv at run time, which needs a CSP that allows it (or precompile them).
32
+
33
+ ## Per module
34
+
35
+ `@johnoscott/isometric-engine/modules/<layer>/<module>` (e.g. `…/modules/iso-editor/ui/canvas`) is a layer's public module
36
+ as TypeScript source, for a host that bundles per module: with code splitting, each chunk then holds only what it
37
+ uses, where a namespace pulls in everything its layer's barrel reaches. It needs a bundler that reads TypeScript
38
+ (esbuild does), and the packages those modules import (`yaml`, and `ajv`, `monaco-editor` or `esbuild` for the
39
+ modules that use them). The subpaths are exactly the public modules: what each layer's index re-exports from, and its
40
+ declared entries (`iso-editor/ui/text`, the Monaco text pane; `iso-editor/ui/monaco-entry`; `iso-core/schema-errors`).
41
+
42
+ ## Rendering isodiag/1 YAML
43
+
44
+ `@johnoscott/isometric-engine/systems` is the drawing format isodiag/1 (its reader, compile, kind catalogue and
45
+ stylesheets: `systems`) with the layers it draws with (`core`, `objects`, `viewer`). Its schema is compiled to code at
46
+ build time, so a page under a strict CSP (`script-src 'self'`) renders YAML drawings. A page showing one in 3D and 2D:
47
+
48
+ import { core, viewer, systems } from '@johnoscott/isometric-engine/systems';
49
+ import THEME from '@johnoscott/isometric-engine/assets/default-theme.yaml'; // text
50
+ import SRC from './drawing.yaml'; // text
51
+
52
+ const d = systems.compile(SRC, THEME); // d.diags: problems, each with its line
53
+ const styles = { send: { color: 'send' }, reply: { color: 'reply' } }; // a link kind's 2D style
54
+ const css = [core.themeCss(d.theme), systems.DRAWING_CSS, viewer.flatCss(styles), viewer.DUAL_VIEW_CSS].join('\n');
55
+ const view = viewer.dualView(figure, d.scenes[0], { mode: viewer.storedMode() ?? '3d', styles, title: 'A drawing' });
56
+ viewer.viewToggle(document.body, [view]); // the 3D | 2D switch; view.morph('2d' | '3d') animates
57
+
58
+ The engine draws only its own marks. Icons (`deco: [{ icon: NAME }]`) and screen faces (`face: NAME`) beyond
59
+ terminal, chat, desktop and tiles are the host's: register them once with `objects.registerMarks({ icons, faces, css })`
60
+ before drawing. A name nothing registered draws a neutral placeholder, and the compile warns.
61
+
62
+ Bundle the YAML files as text (esbuild: `loader: { '.yaml': 'text' }`). `layoutFlat`'s options (`flat: { wrap: { aspect } }`)
63
+ and the board API are in `objects`, declared in `types/`.