@johnoscott/isometric-engine 0.0.0-stage → 0.10.1
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.
- package/EDITOR-GUIDE.md +355 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +269 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +39 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +443 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1403 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +149 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +511 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +147 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +477 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1227 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +39 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +153 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +178 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +307 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +49 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
package/EDITOR-GUIDE.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
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
|
+
- **Optional, when you say how** (0.10.0): palette **presets** (a box, a tray, a database… each starting as itself),
|
|
37
|
+
**connecting** two objects by dragging from one to the other, and **grouping** the selection into a new container.
|
|
38
|
+
Each writes the file as your adapter says, as one undo step.
|
|
39
|
+
- **`editor.mountEditor(element, options, setup)`**, which puts it all on a page, where `setup = editor.setupFor(adapter,
|
|
40
|
+
view)`.
|
|
41
|
+
|
|
42
|
+
The other namespaces in the same import are the layers underneath: `core` (parsing, themes, the SVG kernel),
|
|
43
|
+
`objects` (object kinds, layout, routing and `compileRaw`, which turns a drawing into SVG) and `viewer` (pan and zoom,
|
|
44
|
+
overlays, CSS scoping, the 2D view and the morph).
|
|
45
|
+
|
|
46
|
+
## 2. The adapter and the view
|
|
47
|
+
|
|
48
|
+
The adapter is plain data and functions, with no DOM. Field by field:
|
|
49
|
+
|
|
50
|
+
- `id`: the format's name. `role(text)` says whether a text is a `'main'` file (or a `'base'` that others extend).
|
|
51
|
+
- `schema(role)`: a JSON Schema. The properties panel and completion are built from it, and `enum`s become choices.
|
|
52
|
+
- `read(text)`: your reader. It returns `diags`, each with a JSON-pointer `path` (the editor places it from the text),
|
|
53
|
+
and `read`, your own reading, which your view draws.
|
|
54
|
+
- `kinds`: the things a file holds, each in a map of its own (`section`), with a `template()` for a new one. Names are
|
|
55
|
+
unique across all kinds.
|
|
56
|
+
- `objectOf(pointer)` and `describe(path)`: which object a pointer is inside, and a path in words ("box a").
|
|
57
|
+
- `refs(data)` and `slotAt(pointer)`: every place whose value names another object (`in:`, `from:`, `to:`), with the
|
|
58
|
+
slot it is in. Renaming and deleting are built on them.
|
|
59
|
+
- `renameRef(ref, to)`: a reference's new text when its target is renamed.
|
|
60
|
+
- `refDeletePath(path)`: what deleting a reference removes along with its target. That's the reference itself, or
|
|
61
|
+
the entry that holds it (a link without its `to` is no link: remove `/links/3`, not `/links/3/to`).
|
|
62
|
+
- `topOrder`, `outline`, `pins`, `snippets`, `copyValue`, `entryGroups`, `keyMessage`, `noun`: the details, shown in
|
|
63
|
+
the example.
|
|
64
|
+
|
|
65
|
+
The view (`editor.DomainView`) says how a reading is drawn:
|
|
66
|
+
|
|
67
|
+
- `draw(read, data, theme)`: build the engine's drawing (`objects.compileRaw` with your catalogue) and return its
|
|
68
|
+
`scene` and `svg`. Also return `pathOf`, a map from each drawn element's `data-id` to the JSON pointer it shows (a
|
|
69
|
+
click on the canvas selects that path), and `pinId`, the element a pin moves.
|
|
70
|
+
- `catalog`: your object kinds (`objects.KindCatalog`): region kinds by shape, and node kinds that draw themselves.
|
|
71
|
+
- `icons`: your kinds' icons, as 24 × 24 SVG bodies by name. `icon(kind)` chooses one for each kind.
|
|
72
|
+
- `flat`: the 2D view. Give `load` (it returns `editor.flatCanvas`) and each link kind's style. Leave it out and the
|
|
73
|
+
canvas is 3D only. The switch morphs between the views; `motion: 'always'` morphs even under reduced motion,
|
|
74
|
+
`'never'` swaps at once (the default, `'auto'`, honours the reader's setting).
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// file: boxes.ts
|
|
78
|
+
import { core, objects, editor } from '@johnoscott/isometric-engine/editor';
|
|
79
|
+
|
|
80
|
+
type Raw = Record<string, unknown>;
|
|
81
|
+
const isMap = (v: unknown): v is Raw => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
82
|
+
|
|
83
|
+
/** a tray (a block that holds boxes), a zone (a tint on the floor that holds boxes), a box */
|
|
84
|
+
export const CATALOG: objects.KindCatalog = {
|
|
85
|
+
regions: {
|
|
86
|
+
tray: { shape: 'block', pad: 0.6, z: [0, 0.3], floor: true, role: 'server', labelStyle: 'floor' },
|
|
87
|
+
zone: { shape: 'zone', pad: 0.5, z: [0, 0.005], floor: false, role: 'grey', labelStyle: 'floor' },
|
|
88
|
+
},
|
|
89
|
+
nodes: { box: objects.boxAsset('box', 'A box', [2, 2, 1], 'lead') },
|
|
90
|
+
defaultNode: 'box',
|
|
91
|
+
};
|
|
92
|
+
const HOLDERS = ['tray', 'zone'];
|
|
93
|
+
|
|
94
|
+
export interface Box { name: string; kind: string; in?: string; label?: string; path: string }
|
|
95
|
+
export interface Boxes { data: Raw; boxes: Box[]; links: { from: string; to: string; path: string }[] }
|
|
96
|
+
|
|
97
|
+
/** read a text: the boxes, the links, and what is wrong (each at its JSON pointer) */
|
|
98
|
+
export function readBoxes(text: string): { diags: core.Diag[]; read?: Boxes } {
|
|
99
|
+
const p = core.parse(text);
|
|
100
|
+
const diags: core.Diag[] = [...p.diags];
|
|
101
|
+
const bad = (path: string, message: string) => diags.push({ severity: 'error', message, line: 0, col: 0, path });
|
|
102
|
+
if (!isMap(p.data)) return { diags };
|
|
103
|
+
const data = p.data, boxes: Box[] = [];
|
|
104
|
+
if (data.format !== 'boxes/1') bad('/format', 'format: must be boxes/1');
|
|
105
|
+
for (const [name, v] of Object.entries(isMap(data.boxes) ? data.boxes : {})) {
|
|
106
|
+
const b = isMap(v) ? v : {}, path = editor.toPointer(['boxes', name]);
|
|
107
|
+
const kind = typeof b.kind === 'string' ? b.kind : 'box';
|
|
108
|
+
if (kind !== 'box' && !HOLDERS.includes(kind)) bad(`${path}/kind`, `unknown kind "${kind}": box, tray or zone`);
|
|
109
|
+
boxes.push({ name, kind, in: typeof b.in === 'string' ? b.in : undefined, label: typeof b.label === 'string' ? b.label : undefined, path });
|
|
110
|
+
}
|
|
111
|
+
const byName = new Map(boxes.map(b => [b.name, b]));
|
|
112
|
+
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}"`);
|
|
113
|
+
const links: Boxes['links'] = [];
|
|
114
|
+
(Array.isArray(data.links) ? data.links : []).forEach((l, i) => {
|
|
115
|
+
const x = isMap(l) ? l : {}, path = editor.toPointer(['links', i]);
|
|
116
|
+
for (const k of ['from', 'to']) if (!byName.has(String(x[k]))) bad(`${path}/${k}`, `no box "${String(x[k] ?? '')}"`);
|
|
117
|
+
links.push({ from: String(x.from), to: String(x.to), path });
|
|
118
|
+
});
|
|
119
|
+
return { diags, read: { data, boxes, links } };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ---- references: every value that names another box ----
|
|
123
|
+
const SLOTS: editor.RefSlot[] = [
|
|
124
|
+
{ at: ['boxes', '*', 'in'], targets: ['boxes'], what: 'the tray or zone it is in' },
|
|
125
|
+
{ at: ['links', '#', 'from'], targets: ['boxes'], what: "a link's start" },
|
|
126
|
+
{ at: ['links', '#', 'to'], targets: ['boxes'], what: "a link's end" },
|
|
127
|
+
];
|
|
128
|
+
function refs(data: unknown): editor.Ref[] {
|
|
129
|
+
const out: editor.Ref[] = [], d = isMap(data) ? data : {};
|
|
130
|
+
for (const [name, v] of Object.entries(isMap(d.boxes) ? d.boxes : {}))
|
|
131
|
+
if (isMap(v) && typeof v.in === 'string') out.push({ path: editor.toPointer(['boxes', name, 'in']), slot: SLOTS[0], value: v.in, name: v.in });
|
|
132
|
+
(Array.isArray(d.links) ? d.links : []).forEach((l, i) => {
|
|
133
|
+
for (const [j, k] of [[1, 'from'], [2, 'to']] as const)
|
|
134
|
+
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 });
|
|
135
|
+
});
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
const slotAt = (ptr: string) => {
|
|
139
|
+
const parts = ptr.split('/').slice(1);
|
|
140
|
+
return SLOTS.find(s => s.at.length === parts.length && s.at.every((seg, i) => seg === '*' || (seg === '#' ? /^\d+$/.test(parts[i]) : seg === parts[i])));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const boxesAdapter: editor.DomainAdapter = {
|
|
144
|
+
id: 'boxes/1',
|
|
145
|
+
role: () => 'main',
|
|
146
|
+
schema: () => ({
|
|
147
|
+
type: 'object', properties: {
|
|
148
|
+
format: { const: 'boxes/1' }, title: { type: 'string', description: "The drawing's title." },
|
|
149
|
+
boxes: { type: 'object', additionalProperties: { type: 'object', properties: {
|
|
150
|
+
kind: { enum: ['box', 'tray', 'zone'], description: 'A box, or a tray or zone that holds boxes.' },
|
|
151
|
+
in: { type: 'string', description: 'The tray or zone it is in.' }, label: { type: 'string' } } } },
|
|
152
|
+
links: { type: 'array', items: { type: 'object', properties: { from: { type: 'string' }, to: { type: 'string' } } } },
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
read(text) { const r = readBoxes(text); return { diags: r.diags, read: r.read }; },
|
|
156
|
+
keyMessage: /^unknown kind/,
|
|
157
|
+
kinds: [{ kind: 'boxes', section: ['boxes'], singular: 'box', group: 'Boxes', template: () => ({ label: 'New box' }) }],
|
|
158
|
+
noun: 'box',
|
|
159
|
+
objectOf(ptr) { const m = /^\/boxes\/([^/]+)/.exec(ptr); return m ? { kind: 'boxes', name: m[1], path: `/boxes/${m[1]}` } : undefined; },
|
|
160
|
+
describe(p) { return p.length === 2 && p[0] === 'boxes' ? `box ${p[1]}` : p.join('.') || 'the file'; },
|
|
161
|
+
entryGroups: [],
|
|
162
|
+
refs, slotAt,
|
|
163
|
+
renameRef: (_ref, to) => to,
|
|
164
|
+
// a link loses its from or to: the link goes, not just the key
|
|
165
|
+
refDeletePath: p => (p[0] === 'links' ? p.slice(0, 2) : p),
|
|
166
|
+
copyValue: (_kind, v) => v,
|
|
167
|
+
topOrder: ['format', 'title', 'boxes', 'links', 'x-editor'],
|
|
168
|
+
pins: { key: 'x-editor', legacyOnly: () => false },
|
|
169
|
+
snippets: {},
|
|
170
|
+
outline: { kinds: ['boxes'], first: ['format', 'title'], groups: [{ key: 'links', label: 'Links' }], rootLabel: d => String(d.title ?? 'boxes') },
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/** the drawing: trays and zones as regions, boxes as nodes, links as routes; pins from x-editor.layout */
|
|
174
|
+
export function drawBoxes(r: Boxes, data: unknown, theme: string): editor.CanvasDrawing {
|
|
175
|
+
const pins = isMap(data) && isMap(data['x-editor']) && isMap(data['x-editor'].layout) ? data['x-editor'].layout : {};
|
|
176
|
+
const at = (name: string) => { const v = pins[name]; return isMap(v) && Array.isArray(v.at) ? { at: v.at as [number, number] } : {}; };
|
|
177
|
+
const kids = (name?: string) => r.boxes.filter(b => b.in === name);
|
|
178
|
+
const region = (b: Box): objects.RawRegion => ({ id: b.name, kind: b.kind, label: b.label ?? b.name, ...at(b.name),
|
|
179
|
+
regions: kids(b.name).filter(c => c.kind !== 'box').map(region), nodes: kids(b.name).filter(c => c.kind === 'box').map(node) });
|
|
180
|
+
const node = (b: Box): objects.RawNode => ({ id: b.name, asset: 'box', label: b.label ?? b.name, ...at(b.name) });
|
|
181
|
+
const title = String(r.data.title ?? 'boxes');
|
|
182
|
+
const doc: objects.RawDiagram = { isodiag: 1, title, scenes: [{ id: 'boxes', title,
|
|
183
|
+
regions: kids(undefined).filter(b => b.kind !== 'box').map(region), nodes: kids(undefined).filter(b => b.kind === 'box').map(node),
|
|
184
|
+
routes: r.links.map((l, i) => ({ id: `link-${i}`, from: l.from, to: l.to, kind: 'send' })) }] };
|
|
185
|
+
const compiled = objects.compileRaw(doc, theme, CATALOG), scene = compiled.scenes[0];
|
|
186
|
+
return {
|
|
187
|
+
scene, svg: scene.rendered.svg,
|
|
188
|
+
// every drawn element's data-id → the JSON pointer it shows: a click on the canvas selects that
|
|
189
|
+
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])]),
|
|
190
|
+
pinId: new Map(r.boxes.map(b => [b.name, b.name])), pinNotes: [],
|
|
191
|
+
diags: compiled.diags.filter(d => d.severity === 'error').map(d => d.message),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** the view: the drawing, the catalogue, the theme, and the 2D view */
|
|
196
|
+
export const boxesView = (theme: string): editor.DomainView<Boxes, editor.CanvasDrawing> => ({
|
|
197
|
+
draw: drawBoxes, catalog: CATALOG, theme, fileName: 'boxes.yaml', words: { brand: 'boxes' },
|
|
198
|
+
flat: { load: async () => editor.flatCanvas, title: 'boxes, flat', styles: { send: { color: 'send' } } },
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Presets, connecting and grouping (0.10.0)
|
|
203
|
+
|
|
204
|
+
Three optional pieces. Give one and the editor offers it; leave it out and nothing changes.
|
|
205
|
+
|
|
206
|
+
- **Palette presets**, on the view: `palette: [{ kind, label, icon?, value?, name? }]`. Each entry adds an object of
|
|
207
|
+
`kind` starting as a copy of `value` (default: the kind's `template()`), named from `name` (default: the kind's
|
|
208
|
+
singular). Without it, the palette has one entry per kind.
|
|
209
|
+
- **Connect**, on the adapter: `connect(from, to, data)` returns where a connection goes and what it is, `{ at, value }`
|
|
210
|
+
to add to a list (or with `name`, to a map under a fresh name), or `undefined` when those two don't connect. The
|
|
211
|
+
canvas then shows a handle on the one selected object: drag it to another (Esc cancels), or use **Connect to…** in
|
|
212
|
+
its menu and click the other.
|
|
213
|
+
- **Drop into** (0.10.1), on the adapter: `dropInto(target, value, kind, data)` returns the new thing's value inside
|
|
214
|
+
`target` (and words for it), or `undefined` when `target` doesn't hold it. A palette drop asks what is under it,
|
|
215
|
+
innermost first, and the first that holds it takes it; with none, the drop is pinned where it lands.
|
|
216
|
+
- **Group**, on the adapter: `group(members, data)` returns the new container (`at`, the base of its `name`, its
|
|
217
|
+
`value`) and `members(name)`, what changes in each member once it has a name. **Group** in the menu, or ⌘G, writes
|
|
218
|
+
it all as one step; members' pins are dropped, so the layout places them in their new container.
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
// boxes/1's: a link between two boxes (not twice), and the selection into a new zone in what they were all in
|
|
222
|
+
type Data = { boxes: Record<string, { in?: string }>; links?: { from: string; to: string }[] };
|
|
223
|
+
connect: (from, to, data) =>
|
|
224
|
+
(data as Data).links?.some(l => l.from === from.name && l.to === to.name) ? undefined
|
|
225
|
+
: { at: ['links'], value: { from: from.name, to: to.name } },
|
|
226
|
+
group: (members, data) => {
|
|
227
|
+
const ins = new Set(members.map(m => (data as Data).boxes[m.name]?.in));
|
|
228
|
+
return {
|
|
229
|
+
at: ['boxes'], name: 'group', value: { kind: 'zone', label: 'Group', ...(ins.size === 1 && [...ins][0] ? { in: [...ins][0] } : {}) },
|
|
230
|
+
members: name => members.map(m => ({ path: ['boxes', m.name, 'in'], value: name })),
|
|
231
|
+
};
|
|
232
|
+
},
|
|
233
|
+
// and on the view
|
|
234
|
+
palette: [
|
|
235
|
+
{ kind: 'boxes', label: 'Box', name: 'box', value: { size: [2, 2, 1] } },
|
|
236
|
+
{ kind: 'boxes', label: 'Tray', icon: 'layers', name: 'tray', value: { kind: 'tray', label: 'Tray' } },
|
|
237
|
+
],
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## 3. A page
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
npm i @johnoscott/isometric-engine
|
|
244
|
+
npm i -D esbuild
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
The page mounts the editor with the plain skin. Its CSS and the theme are files in the package, which a bundler loads
|
|
248
|
+
as text:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
// file: page.ts
|
|
252
|
+
import { core, objects, viewer, editor } from '@johnoscott/isometric-engine/editor';
|
|
253
|
+
import { boxesAdapter, boxesView, CATALOG } from './boxes.ts';
|
|
254
|
+
// @ts-ignore text (esbuild: loader { '.css': 'text', '.yaml': 'text' })
|
|
255
|
+
import SKIN from '@johnoscott/isometric-engine/assets/skin.css';
|
|
256
|
+
// @ts-ignore text
|
|
257
|
+
import APP from '@johnoscott/isometric-engine/assets/app.css';
|
|
258
|
+
// @ts-ignore text
|
|
259
|
+
import THEME from '@johnoscott/isometric-engine/assets/default-theme.yaml';
|
|
260
|
+
|
|
261
|
+
const theme = String(THEME), root = editor.PLAIN_WORDS.rootClass, canvas = '.iso-canvas';
|
|
262
|
+
const style = document.createElement('style');
|
|
263
|
+
style.textContent = [
|
|
264
|
+
'@layer tokens, base, components, views;',
|
|
265
|
+
editor.scopeCss(String(SKIN) + String(APP), root), // the shell
|
|
266
|
+
viewer.scope(viewer.isoVars(core.themeCss(core.loadTheme(theme))), canvas, root), // the theme's tokens
|
|
267
|
+
viewer.scope(viewer.isoVars(objects.drawingCss(CATALOG) + objects.MARKS_CSS), canvas, root), // the drawing
|
|
268
|
+
viewer.scope(viewer.isoVars(viewer.flatCss({ send: { color: 'send' } })), canvas, root), // its 2D view
|
|
269
|
+
].join('\n');
|
|
270
|
+
document.head.append(style);
|
|
271
|
+
|
|
272
|
+
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';
|
|
273
|
+
const el = document.getElementById('app')!;
|
|
274
|
+
const ed = editor.mountEditor(el, { text, onSave: async t => { localStorage.setItem('boxes', t); return { ok: true }; } },
|
|
275
|
+
editor.setupFor(boxesAdapter, boxesView(theme)));
|
|
276
|
+
(window as unknown as { editorHandle: unknown }).editorHandle = ed;
|
|
277
|
+
document.title = 'ready';
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
`assets/app.css` carries the canvas's marks too (selection, hover, the marquee, the drag's grid, problem badges), in
|
|
281
|
+
the skin's accent; a host that writes its own shell CSS takes `assets/marks.css` instead, and may set `--iso-sel` on
|
|
282
|
+
`.iso-canvas` for another colour. Without either, the marks still draw no fill and never take the pointer.
|
|
283
|
+
|
|
284
|
+
```
|
|
285
|
+
npx esbuild page.ts --bundle --format=esm --outfile=dist/page.js --loader:.css=text --loader:.yaml=text
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Its `index.html` gives the editor a sized element: `<div id="app" style="height:100vh"></div>`, then
|
|
289
|
+
`<script type="module" src="page.js"></script>`.
|
|
290
|
+
|
|
291
|
+
- **CSP.** The editor runs under `script-src 'self'` (no `unsafe-eval`). Styles go in through a `<style>` element, so
|
|
292
|
+
allow `style-src 'self' 'unsafe-inline'`.
|
|
293
|
+
- **Inline-safe.** No bundle holds `<!--`, `<script` or `</script`. Your page may inline its bundle in
|
|
294
|
+
`<script type="module">…</script>` (a page opened from disk), and a bundler printing the package again keeps it so.
|
|
295
|
+
- **Theme.** `assets/default-theme.yaml` is a theme. Your own adds roles (colours by name) and link kinds. The page
|
|
296
|
+
follows `prefers-color-scheme`, or `data-theme="light" | "dark"` on the root.
|
|
297
|
+
|
|
298
|
+
## 4. What needs what
|
|
299
|
+
|
|
300
|
+
| You want | You need |
|
|
301
|
+
|---|---|
|
|
302
|
+
| to draw or render only (`/render`, `/systems`) | the package alone: it has no dependencies |
|
|
303
|
+
| the editor (`/editor`) | the package; its code needs nothing else |
|
|
304
|
+
| to type-check against `/editor` | `yaml` and `monaco-editor` installed, for their types (or `skipLibCheck`) |
|
|
305
|
+
| 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 |
|
|
306
|
+
| the 2D view | `view.flat` with `load: async () => editor.flatCanvas`, and `viewer.flatCss(styles)` in your canvas CSS |
|
|
307
|
+
| isodiag/1 YAML drawings | `/systems`: `systems.compile(yaml, theme)` (see the README) |
|
|
308
|
+
| palette presets (0.10.0) | `view.palette` |
|
|
309
|
+
| connecting by drag, Connect to… (0.10.0) | `adapter.connect` |
|
|
310
|
+
| Group, ⌘G (0.10.0) | `adapter.group` |
|
|
311
|
+
| a palette drop that lands inside a container (0.10.1) | `adapter.dropInto` |
|
|
312
|
+
|
|
313
|
+
## 5. Testing your adapter
|
|
314
|
+
|
|
315
|
+
What we test on every adapter. Each is a few lines with the commands and the splice they make:
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
// file: boxes.test.ts
|
|
319
|
+
import { test } from 'node:test';
|
|
320
|
+
import assert from 'node:assert/strict';
|
|
321
|
+
import { editor } from '@johnoscott/isometric-engine/editor';
|
|
322
|
+
import { boxesAdapter, readBoxes } from './boxes.ts';
|
|
323
|
+
|
|
324
|
+
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';
|
|
325
|
+
const C = editor.commandsFor(boxesAdapter);
|
|
326
|
+
const run = (text: string, cmd: { build(t: string): { steps: Parameters<typeof editor.applyStep>[1][] } }) =>
|
|
327
|
+
cmd.build(text).steps.reduce((t, s) => editor.applyStep(t, s), text);
|
|
328
|
+
|
|
329
|
+
test('every reference is found', () => {
|
|
330
|
+
const r = readBoxes(TEXT).read!;
|
|
331
|
+
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']);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('a rename follows every reference, and the result reads cleanly', () => {
|
|
335
|
+
const out = run(TEXT, C.renameCmd(['boxes', 'shelf'], 'rack'));
|
|
336
|
+
assert.match(out, /a: \{ in: rack \}/);
|
|
337
|
+
assert.deepEqual(readBoxes(out).diags, []);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('a delete with its references leaves none dangling', () => {
|
|
341
|
+
const out = run(TEXT, C.deleteCmd(['boxes', 'a'], { withRefs: true }));
|
|
342
|
+
assert.doesNotMatch(out, /\ba:|from: a|to: a/);
|
|
343
|
+
assert.deepEqual(readBoxes(out).diags, []);
|
|
344
|
+
});
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
In a browser, a smoke test mounts the page and checks the following:
|
|
348
|
+
- the drawing has every object (`[data-id="a"]` in the canvas's SVG);
|
|
349
|
+
- a click on one selects it in the tree (`.trow[aria-selected="true"]`);
|
|
350
|
+
- F2 renames it with its references, and ⌘Z undoes that in one step;
|
|
351
|
+
- every icon resolves (each `<use href>` finds its `<symbol>`);
|
|
352
|
+
- there are no console errors and no CSP violations (listen for `securitypolicyviolation`).
|
|
353
|
+
|
|
354
|
+
Drive Chrome headless over the DevTools protocol. Use `--headless=new` with a throwaway `--user-data-dir`, and serve
|
|
355
|
+
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.
|
package/LICENSES/ajv.txt
ADDED
|
@@ -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
|
-
#
|
|
1
|
+
# @johnoscott/isometric-engine 0.10.1
|
|
2
2
|
|
|
3
|
-
|
|
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/`.
|