@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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Problems for the editor: the domain's reader (schema + rules), turned into ranges in this file. A problem in another
|
|
2
|
+
// file (a base file the chain inherits) is shown at this file's extends:, naming the file and line. Pure; the caller
|
|
3
|
+
// supplies the base files (a server resolves extends: under its root).
|
|
4
|
+
|
|
5
|
+
import { EditorDoc } from './doc.ts';
|
|
6
|
+
import { fromPointer } from './path.ts';
|
|
7
|
+
import type { Diag } from '../iso-core/errors.ts';
|
|
8
|
+
import type { PlaceAdapter, ReadAdapter } from './adapter.ts';
|
|
9
|
+
|
|
10
|
+
export interface Problem {
|
|
11
|
+
severity: 'error' | 'warning';
|
|
12
|
+
message: string;
|
|
13
|
+
hint?: string;
|
|
14
|
+
path: string;
|
|
15
|
+
/** 1-based, end exclusive */
|
|
16
|
+
startLine: number; startCol: number; endLine: number; endCol: number;
|
|
17
|
+
/** the other file it is in, when it isn't this one */
|
|
18
|
+
file?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ValidateOpts {
|
|
22
|
+
fileName?: string;
|
|
23
|
+
defaults?: { name: string; text: string }[];
|
|
24
|
+
/** problems resolving extends: (loops, missing files), from the server */
|
|
25
|
+
extendsDiags?: Diag[];
|
|
26
|
+
profiles?: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The problems, and what the reader resolved: each object's tag (with the base files merged), and its own reading. */
|
|
30
|
+
export function analyse(a: ReadAdapter, text: string, opts: ValidateOpts & { fileName: string }): { problems: Problem[]; tags: Map<string, string>; read?: unknown } {
|
|
31
|
+
const d = new EditorDoc(text);
|
|
32
|
+
const r = a.read(text, { fileName: opts.fileName, defaults: opts.defaults, profiles: opts.profiles, role: a.role(text) });
|
|
33
|
+
const all = [...(opts.extendsDiags ?? []), ...r.diags];
|
|
34
|
+
return { problems: all.map(x => place(a, d, x, opts.fileName)), tags: r.tags ?? new Map(), read: r.read };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A diagnostic as a range in the text (a host's plan problem too: its pointer and line, made a Diag). */
|
|
38
|
+
export function place(a: PlaceAdapter, d: EditorDoc, x: Diag, fileName: string): Problem {
|
|
39
|
+
const base = { severity: x.severity, message: x.message, hint: x.hint, path: x.path };
|
|
40
|
+
if (x.file && x.file !== fileName) {
|
|
41
|
+
// in another file: at this file's extends:
|
|
42
|
+
const r = d.rangeOf(['extends']) ?? [0, 0];
|
|
43
|
+
const a = d.pos(r[0]), b = d.pos(r[1]);
|
|
44
|
+
return { ...base, message: `${x.file}:${x.line}: ${x.message}`, file: x.file, startLine: a.line, startCol: a.col, endLine: b.line, endCol: b.col };
|
|
45
|
+
}
|
|
46
|
+
const path = fromPointer(x.path);
|
|
47
|
+
// a message about a whole object is placed on its name
|
|
48
|
+
const whole = a.objectOf(x.path)?.path === x.path;
|
|
49
|
+
const r = path.length ? d.rangeOf(path, whole || a.keyMessage.test(x.message) ? 'key' : 'value') : undefined;
|
|
50
|
+
if (r && r[1] > r[0]) {
|
|
51
|
+
// a block value spans lines: mark its first line only
|
|
52
|
+
const nl = d.text.indexOf('\n', r[0]);
|
|
53
|
+
const end = nl >= 0 && nl < r[1] ? nl : r[1];
|
|
54
|
+
const a = d.pos(r[0]), b = d.pos(Math.max(end, r[0] + 1));
|
|
55
|
+
return { ...base, startLine: a.line, startCol: a.col, endLine: b.line, endCol: b.col };
|
|
56
|
+
}
|
|
57
|
+
// the word at the reported place
|
|
58
|
+
const line = Math.max(1, x.line), col = Math.max(1, x.col);
|
|
59
|
+
const off = d.offset(line, col);
|
|
60
|
+
const m = /^[^\s,:{}[\]]+/.exec(d.text.slice(off));
|
|
61
|
+
return { ...base, startLine: line, startCol: col, endLine: line, endCol: col + Math.max(1, m ? m[0].length : 1) };
|
|
62
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// A feature window's protocol (version 1), as any domain's editor speaks it: a host page runs the editor in a window
|
|
2
|
+
// of its own (or an <iframe>), and the two talk over postMessage. Every message is { v: 1, type, … }; a request carries
|
|
3
|
+
// an id and its answer re: that id; each side checks the other's origin, and ignores a type it doesn't know (never an
|
|
4
|
+
// error). These are the messages every editor has (hello, save, dirty, close; init, text, read-only, theme, saved);
|
|
5
|
+
// a domain adds its own (types only here: the domain's client and page script are its own, and stay small).
|
|
6
|
+
|
|
7
|
+
import type { Theme, SaveResult } from '../ui/mount.ts';
|
|
8
|
+
|
|
9
|
+
export const PROTOCOL = 1;
|
|
10
|
+
export type Refused = { refused: string };
|
|
11
|
+
|
|
12
|
+
/** what a window can do: a newer window tells an older host what it lacks, and the reverse */
|
|
13
|
+
export interface Capabilities { protocol: number; features: string[]; messages: string[] }
|
|
14
|
+
|
|
15
|
+
/** the window's messages every editor sends */
|
|
16
|
+
export type BaseToHost =
|
|
17
|
+
| { v: 1; type: 'hello'; capabilities: Capabilities }
|
|
18
|
+
| { v: 1; type: 'save'; id: number; text: string }
|
|
19
|
+
| { v: 1; type: 'dirty'; dirty: boolean }
|
|
20
|
+
| { v: 1; type: 'close' };
|
|
21
|
+
|
|
22
|
+
/** the host's messages every editor takes (I: the domain's own fields in init) */
|
|
23
|
+
export type BaseToWindow<I extends object = object> =
|
|
24
|
+
| ({ v: 1; type: 'init'; text: string; fileName?: string; readOnly?: boolean; theme?: Theme; features?: string[] } & I)
|
|
25
|
+
| { v: 1; type: 'text'; text: string }
|
|
26
|
+
| { v: 1; type: 'read-only'; readOnly: boolean }
|
|
27
|
+
| { v: 1; type: 'theme'; theme: Theme }
|
|
28
|
+
| { v: 1; type: 'saved'; re: number; result: SaveResult | Refused };
|
|
29
|
+
|
|
30
|
+
/** a message of this protocol, of a type the receiver knows (anything else is ignored, never an error) */
|
|
31
|
+
export function isMessage<T extends { type: string }>(d: unknown, types: readonly string[]): d is T {
|
|
32
|
+
return !!d && typeof d === 'object' && (d as { v?: unknown }).v === PROTOCOL && types.includes((d as { type?: unknown }).type as string);
|
|
33
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Assemble mode: the timeline of an intro in which each region and node flies in from just outside the canvas,
|
|
2
|
+
// from the canvas edge nearest to where it ends up, then routes draw in and labels fade in. Computed at build time,
|
|
3
|
+
// so it can be tested without a browser; the player only plays it.
|
|
4
|
+
|
|
5
|
+
import type { Routed } from './route.ts';
|
|
6
|
+
import type { Layout } from './place.ts';
|
|
7
|
+
import type { Placed } from './types.ts';
|
|
8
|
+
import { polyBounds, silhouette, type Rect } from './labels.ts';
|
|
9
|
+
|
|
10
|
+
export type Edge = 'left' | 'right' | 'top' | 'bottom';
|
|
11
|
+
export interface Piece { id: string; kind: 'region' | 'node'; edge: Edge; dx: number; dy: number; delay: number; dur: number; bbox: Rect }
|
|
12
|
+
export interface Assembly {
|
|
13
|
+
pieces: Piece[];
|
|
14
|
+
routes: { id: string; delay: number; dur: number }[];
|
|
15
|
+
labels: { delay: number; dur: number };
|
|
16
|
+
/** ms until everything is in place */
|
|
17
|
+
total: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MARGIN = 24;
|
|
21
|
+
|
|
22
|
+
/** The edge of the canvas nearest a box, and the offset that puts the box fully outside the canvas beyond it. */
|
|
23
|
+
export function offscreen(b: Rect, vb: [number, number, number, number]): { edge: Edge; dx: number; dy: number } {
|
|
24
|
+
const [vx, vy, vw, vh] = vb, cx = b.x + b.w / 2, cy = b.y + b.h / 2;
|
|
25
|
+
const d: [Edge, number][] = [['left', cx - vx], ['right', vx + vw - cx], ['top', cy - vy], ['bottom', vy + vh - cy]];
|
|
26
|
+
d.sort((p, q) => p[1] - q[1]);
|
|
27
|
+
const edge = d[0][0];
|
|
28
|
+
if (edge === 'left') return { edge, dx: -(b.x + b.w - vx) - MARGIN, dy: 0 };
|
|
29
|
+
if (edge === 'right') return { edge, dx: vx + vw - b.x + MARGIN, dy: 0 };
|
|
30
|
+
if (edge === 'top') return { edge, dx: 0, dy: -(b.y + b.h - vy) - MARGIN };
|
|
31
|
+
return { edge, dx: 0, dy: vy + vh - b.y + MARGIN };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function assembly(layout: Layout, routes: Routed[], vb: [number, number, number, number]): Assembly {
|
|
35
|
+
const depth = (p: Placed) => { let d = 0; for (let a = p.parent; a; a = a.parent) d++; return d; };
|
|
36
|
+
const key = (p: Placed) => p.box.x0 + p.box.y0 + p.box.z0 * 0.01;
|
|
37
|
+
// base slabs, then the regions inside them; then nodes back to front
|
|
38
|
+
const regions = layout.items.filter(p => p.type === 'region').sort((a, b) => depth(a) - depth(b) || key(a) - key(b));
|
|
39
|
+
const nodes = layout.items.filter(p => p.type === 'node').sort((a, b) => key(a) - key(b) || a.box.z0 - b.box.z0);
|
|
40
|
+
const pieces: Piece[] = [];
|
|
41
|
+
const rStep = Math.min(90, 400 / Math.max(1, regions.length)), rDur = 650;
|
|
42
|
+
regions.forEach((p, i) => {
|
|
43
|
+
const bbox = polyBounds(silhouette(p.box));
|
|
44
|
+
pieces.push({ id: p.id, kind: 'region', ...offscreen(bbox, vb), delay: Math.round(i * rStep), dur: rDur, bbox });
|
|
45
|
+
});
|
|
46
|
+
const nStart = 250 + Math.round(rStep * regions.length), nStep = Math.min(70, 700 / Math.max(1, nodes.length)), nDur = 600;
|
|
47
|
+
nodes.forEach((p, i) => {
|
|
48
|
+
const bbox = polyBounds(silhouette(p.box));
|
|
49
|
+
pieces.push({ id: p.id, kind: 'node', ...offscreen(bbox, vb), delay: Math.round(nStart + i * nStep), dur: nDur, bbox });
|
|
50
|
+
});
|
|
51
|
+
const lastNode = nodes.length ? nStart + (nodes.length - 1) * nStep : nStart;
|
|
52
|
+
const rtStart = Math.round(lastNode + 300), rtStep = Math.min(30, 300 / Math.max(1, routes.length)), rtDur = 400;
|
|
53
|
+
const rts = routes.filter(r => r.points.length >= 2).map((r, i) => ({ id: r.id, delay: Math.round(rtStart + i * rtStep), dur: rtDur }));
|
|
54
|
+
const labels = { delay: rtStart + 200, dur: 400 };
|
|
55
|
+
const total = Math.max(...pieces.map(p => p.delay + p.dur), ...rts.map(r => r.delay + r.dur), labels.delay + labels.dur);
|
|
56
|
+
return { pieces, routes: rts, labels, total };
|
|
57
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Node kinds as data, and the factories a kind pack builds them with (docs/editor/LAYERS.md §2): what a node kind says
|
|
2
|
+
// (its default size and colour role, how it draws itself in a box, where its label and pulse go), the plain box with
|
|
3
|
+
// decorations, the plate figures stand on, and the cloud. The kinds themselves are a pack's (src/iso-systems/nodes.ts).
|
|
4
|
+
|
|
5
|
+
import { type Box, type Kernel, type Mat, type P3, iso, tag, S, C, center } from '../iso-core/kernel.ts';
|
|
6
|
+
import * as D from '../iso-core/glyphs.ts';
|
|
7
|
+
import type { RawDeco, RawNode } from './types.ts';
|
|
8
|
+
|
|
9
|
+
export interface LabelSpot {
|
|
10
|
+
/** screen pixels: where the label's first line's baseline sits */
|
|
11
|
+
x: number; y: number;
|
|
12
|
+
anchor: 'start' | 'middle' | 'end';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NodeAsset {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
/** default w (x), d (y), h (z) in grid units */
|
|
19
|
+
size: [number, number, number];
|
|
20
|
+
role: string;
|
|
21
|
+
deco?: RawDeco[];
|
|
22
|
+
/** SVG for the inside of the node's <g class="blk k-ROLE">; b is the node's box */
|
|
23
|
+
draw(k: Kernel, b: Box, n: RawNode): string;
|
|
24
|
+
/** where the label goes; default: centred above the top */
|
|
25
|
+
label?(b: Box, n: RawNode, hasSub: boolean): LabelSpot;
|
|
26
|
+
/** [x, y, z, r]: centre and radius (px) of the step pulse ring; default from the footprint */
|
|
27
|
+
pulse?(b: Box): [number, number, number, number];
|
|
28
|
+
/** extra classes for the node group */
|
|
29
|
+
cls?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** an icon a node can wear (deco: icon: NAME), painted on its box */
|
|
33
|
+
export type IconPainter = (k: Kernel, b: Box) => string;
|
|
34
|
+
|
|
35
|
+
/** The icons and screen faces a drawing may name beyond the engine's own (terminal, chat, desktop, tiles): a host
|
|
36
|
+
* registers its marks once, before it draws (registerMarks). A name nothing has registered draws a neutral
|
|
37
|
+
* placeholder, and the compile warns (unknownMarks). */
|
|
38
|
+
const ICONS: Record<string, IconPainter> = Object.create(null);
|
|
39
|
+
|
|
40
|
+
const CSS: string[] = [];
|
|
41
|
+
|
|
42
|
+
/** `css`: the marks' styles; drawingCss() includes them from then on */
|
|
43
|
+
export function registerMarks(marks: { icons?: Record<string, IconPainter>; faces?: Record<string, D.FacePainter>; css?: string }): void {
|
|
44
|
+
Object.assign(ICONS, marks.icons ?? {});
|
|
45
|
+
Object.assign(D.screenFaces, marks.faces ?? {});
|
|
46
|
+
if (marks.css && !CSS.includes(marks.css)) CSS.push(marks.css);
|
|
47
|
+
}
|
|
48
|
+
/** the registered marks' styles */
|
|
49
|
+
export const markCss = (): string => CSS.join('');
|
|
50
|
+
export const iconPainter = (name: string): IconPainter | undefined => (Object.hasOwn(ICONS, name) ? ICONS[name] : undefined);
|
|
51
|
+
export const facePainter = (name: string): D.FacePainter | undefined => (Object.hasOwn(D.screenFaces, name) ? D.screenFaces[name] : undefined);
|
|
52
|
+
|
|
53
|
+
/** an icon the drawing names but nothing has registered: a dashed square with a question mark on the top face */
|
|
54
|
+
export function placeholderIcon(k: Kernel, b: Box): string {
|
|
55
|
+
const cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2, z = b.z1 + 0.005, r = Math.min(0.6, (b.x1 - b.x0) * 0.24, (b.y1 - b.y0) * 0.24);
|
|
56
|
+
const q: P3[] = [[cx - r, cy - r, z], [cx + r, cy - r, z], [cx + r, cy + r, z], [cx - r, cy + r, z]];
|
|
57
|
+
return k.poly(q, 'ico-unknown') + k.line3([cx - r * 0.3, cy - r * 0.35, z], [cx + r * 0.3, cy - r * 0.35, z], 'ico-unknown-q')
|
|
58
|
+
+ k.line3([cx + r * 0.3, cy - r * 0.35, z], [cx, cy + r * 0.1, z], 'ico-unknown-q') + k.line3([cx, cy + r * 0.45, z], [cx, cy + r * 0.5, z], 'ico-unknown-q');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function drawDecos(k: Kernel, b: Box, decos: RawDeco[] | undefined): string {
|
|
62
|
+
let s = '';
|
|
63
|
+
for (const d of decos ?? []) {
|
|
64
|
+
if (d === 'terminal') s += D.termLines(k, b, 3);
|
|
65
|
+
else if (d === 'envelope') s += D.envelope(k, b);
|
|
66
|
+
else if (d === 'bubble') s += D.bubble(k, b);
|
|
67
|
+
else if (d === 'file-lines') s += D.fileLines(k, b);
|
|
68
|
+
else if (typeof d === 'object') {
|
|
69
|
+
if (d.terminal) s += D.termLines(k, b, d.terminal);
|
|
70
|
+
if (d.icon) s += (iconPainter(d.icon) ?? placeholderIcon)(k, b);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return s;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const decosOf = (n: RawNode, a: NodeAsset) => (n.deco ?? a.deco ?? []).filter(d => d !== 'ghost');
|
|
77
|
+
|
|
78
|
+
/** A plain box, with decorations: the workhorse. */
|
|
79
|
+
export function boxAsset(name: string, description: string, size: [number, number, number], role: string, deco?: RawDeco[], extra?: (k: Kernel, b: Box) => string): NodeAsset {
|
|
80
|
+
const a: NodeAsset = {
|
|
81
|
+
name, description, size, role, deco,
|
|
82
|
+
draw: (k, b, n) => k.blockFaces(b) + drawDecos(k, b, decosOf(n, a)) + (extra ? extra(k, b) : ''),
|
|
83
|
+
};
|
|
84
|
+
return a;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The plate figures stand on: 1.5 × 1.5, 0.18 high, centred in the box. */
|
|
88
|
+
export function plate(b: Box): Box {
|
|
89
|
+
const [cx, cy] = center(b);
|
|
90
|
+
return { x0: cx - 0.75, y0: cy - 0.75, x1: cx + 0.75, y1: cy + 0.75, z0: b.z0, z1: b.z0 + 0.18 };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A puffy cloud outline in a face's 2D plane (w × h px), drawn clockwise with outward bumps. */
|
|
94
|
+
export function cloudPath(w: number, h: number): string {
|
|
95
|
+
const r = Math.max(8, Math.min(w, h) * 0.18), ins = r * 0.55;
|
|
96
|
+
const x0 = ins, y0 = ins, x1 = w - ins, y1 = h - ins;
|
|
97
|
+
const edge = (ax: number, ay: number, bx: number, by: number) => {
|
|
98
|
+
const len = Math.hypot(bx - ax, by - ay), n = Math.max(1, Math.round(len / (r * 1.7)));
|
|
99
|
+
let d = '';
|
|
100
|
+
for (let i = 1; i <= n; i++) {
|
|
101
|
+
const x = ax + (bx - ax) * i / n, y = ay + (by - ay) * i / n, rr = (len / n) / 2 * 1.08;
|
|
102
|
+
d += ` A${rr.toFixed(1)},${rr.toFixed(1)} 0 0 1 ${x.toFixed(1)},${y.toFixed(1)}`;
|
|
103
|
+
}
|
|
104
|
+
return d;
|
|
105
|
+
};
|
|
106
|
+
return `M${x0.toFixed(1)},${y0.toFixed(1)}` + edge(x0, y0, x1, y0) + edge(x1, y0, x1, y1) + edge(x1, y1, x0, y1) + edge(x0, y1, x0, y0) + 'Z';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A cloud lying on the floor with a little thickness: the side is the outline dropped by the height. */
|
|
110
|
+
export function drawCloud(k: Kernel, b: Box): string {
|
|
111
|
+
const top = { ...b, z0: b.z1 };
|
|
112
|
+
const f = (z: number) => { const [X, Y] = iso(b.x0, b.y0, z); return [C, 0.5, -C, 0.5, X, Y] as Mat; };
|
|
113
|
+
const w = (b.x1 - b.x0) * S, h = (b.y1 - b.y0) * S, d = cloudPath(w, h);
|
|
114
|
+
void top;
|
|
115
|
+
return k.onMatrix(f(b.z0), w, h, () => tag('path', { d, class: 'lft cloud-side' }))
|
|
116
|
+
+ k.onMatrix(f(b.z1), w, h, () => tag('path', { d, class: 'top cloud-top' }));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function defaultLabel(b: Box, hasSub: boolean): LabelSpot {
|
|
120
|
+
const [X, Y] = iso((b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.z1 + 0.75);
|
|
121
|
+
return { x: X, y: Y - 18 + (hasSub ? 0 : 6), anchor: 'middle' };
|
|
122
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// A board both ways (0.6.0): boardOf reads one from any drawing the engine has laid out (so a drawing in any format
|
|
2
|
+
// has a 2D view), and boardDiagram draws a board in 3D through the engine (a neutral card kind and a panel kind).
|
|
3
|
+
//
|
|
4
|
+
// boardOf: the 2D view is derived from the 3D placement, never authored on its own. A card's row is one below every
|
|
5
|
+
// card above it, and its column one right of every card left of it, asked of the two things that part them (so each
|
|
6
|
+
// container's rows and columns are its own, and near-aligned boxes share them); a card in no region keeps its place
|
|
7
|
+
// across. Two cards in one cell get a column each. A region (or a node
|
|
8
|
+
// holding nodes) is a panel over the cells of what it holds; one holding nothing has no cell and isn't shown. Routes
|
|
9
|
+
// are links, their ends' sides dropped. What 2D leaves out: sizes (every card is the same size), heights, a route's
|
|
10
|
+
// sides and via points, a region's label style.
|
|
11
|
+
|
|
12
|
+
import { type Box, type Kernel, FONTS } from '../iso-core/kernel.ts';
|
|
13
|
+
import type { NodeAsset } from './assets.ts';
|
|
14
|
+
import type { KindCatalog } from './kinds.ts';
|
|
15
|
+
import { nodeKindOr, regionKind } from './kinds.ts';
|
|
16
|
+
import type { CompiledScene } from './compile.ts';
|
|
17
|
+
import type { Placed, RawDiagram, RawNode, RawRegion, RawKind, RawRole } from './types.ts';
|
|
18
|
+
import { parseEnd, type RawRoute } from './route.ts';
|
|
19
|
+
import { placeBoard, type Board, type BoardCard, type BoardLink, type BoardPanel } from './flat.ts';
|
|
20
|
+
|
|
21
|
+
/** the board of a laid-out scene; `visible`: only what it says is shown (e.g. a step's visible set) */
|
|
22
|
+
export function boardOf(scene: CompiledScene, visible: (id: string) => boolean = () => true): Required<Board> {
|
|
23
|
+
const items = scene.layout.items.filter(p => visible(p.id));
|
|
24
|
+
const cat = scene.layout.catalog;
|
|
25
|
+
const isCard = (p: Placed) => p.type === 'node' && !p.children.some(c => c.type === 'node' && visible(c.id));
|
|
26
|
+
const cardsP = items.filter(isCard);
|
|
27
|
+
// rows and columns: a card is a row below every card above it, and a column right of every card left of it, asked of
|
|
28
|
+
// the two things that part them (the children of their nearest common container holding each: their regions, or the
|
|
29
|
+
// cards themselves): one wholly behind (left of) the other and overlapping it across (down). So a region's rows and
|
|
30
|
+
// columns are its own: a tall or wide neighbour opens none inside it.
|
|
31
|
+
const line = (p: Placed) => { const a: Placed[] = []; for (let q: Placed | undefined = p; q; q = q.parent) a.unshift(q); return a; };
|
|
32
|
+
const lines = new Map(cardsP.map(p => [p.id, line(p)]));
|
|
33
|
+
const parted = (q: Placed, p: Placed) => {
|
|
34
|
+
const A = lines.get(q.id)!, B = lines.get(p.id)!;
|
|
35
|
+
let i = 0;
|
|
36
|
+
while (i < A.length && i < B.length && A[i] === B[i]) i++;
|
|
37
|
+
return [A[i].box, B[i].box] as const;
|
|
38
|
+
};
|
|
39
|
+
const e = 1e-6;
|
|
40
|
+
const above = (q: Placed, p: Placed) => { const [a, b] = parted(q, p); return a.y1 <= b.y0 + e && a.x0 < b.x1 - e && b.x0 < a.x1 - e; };
|
|
41
|
+
const leftOf = (q: Placed, p: Placed) => { const [a, b] = parted(q, p); return a.x1 <= b.x0 + e && a.y0 < b.y1 - e && b.y0 < a.y1 - e; };
|
|
42
|
+
const longest = (rel: (q: Placed, p: Placed) => boolean, key: (p: Placed) => number) => {
|
|
43
|
+
const out = new Map<string, number>(), done: Placed[] = [];
|
|
44
|
+
for (const p of [...cardsP].sort((a, b) => key(a) - key(b))) {
|
|
45
|
+
let r = 0;
|
|
46
|
+
for (const q of done) if (out.get(q.id)! + 1 > r && rel(q, p)) r = out.get(q.id)! + 1;
|
|
47
|
+
out.set(p.id, r); done.push(p);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
};
|
|
51
|
+
const rowOf = longest(above, p => p.box.y0), colOf = longest(leftOf, p => p.box.x0);
|
|
52
|
+
// a card in no region (one floating over the drawing) keeps its place across: no further left than any card that
|
|
53
|
+
// starts left of it
|
|
54
|
+
const tolX = Math.min(...cardsP.map(p => p.box.x1 - p.box.x0)) / 2;
|
|
55
|
+
for (const p of cardsP) if (!p.parent) for (const q of cardsP) if (q.parent && q.box.x0 <= p.box.x0 + tolX) colOf.set(p.id, Math.max(colOf.get(p.id)!, colOf.get(q.id)!));
|
|
56
|
+
const cell = new Map<string, [number, number]>();
|
|
57
|
+
for (const p of cardsP) cell.set(p.id, [colOf.get(p.id)!, rowOf.get(p.id)!]);
|
|
58
|
+
// two in one cell: the later one gets a new column just right of it (everything right of it moves along)
|
|
59
|
+
const taken = new Map<string, string>();
|
|
60
|
+
for (const p of cardsP) {
|
|
61
|
+
const c = cell.get(p.id)!;
|
|
62
|
+
const was = taken.get(String(c));
|
|
63
|
+
if (was !== undefined && was !== p.id) {
|
|
64
|
+
for (const [, k] of cell) if (k[0] > c[0] && k !== c) k[0]++;
|
|
65
|
+
c[0]++;
|
|
66
|
+
taken.clear();
|
|
67
|
+
for (const q of cardsP) taken.set(String(cell.get(q.id)), q.id);
|
|
68
|
+
} else taken.set(String(c), p.id);
|
|
69
|
+
}
|
|
70
|
+
const cards: BoardCard[] = cardsP.map(p => {
|
|
71
|
+
const n = p.node!, a = nodeKindOr(cat, n.asset);
|
|
72
|
+
return { id: p.id, label: n.label ?? p.id, sub: n.sub, role: n.role ?? a.role, ghost: n.ghost || undefined, cell: cell.get(p.id)! };
|
|
73
|
+
});
|
|
74
|
+
const panels: BoardPanel[] = [];
|
|
75
|
+
for (const p of items) {
|
|
76
|
+
if (isCard(p)) continue;
|
|
77
|
+
const inner: [number, number][] = [];
|
|
78
|
+
const walk = (q: Placed) => { for (const c of q.children) { const k = cell.get(c.id); if (k) inner.push(k); walk(c); } };
|
|
79
|
+
walk(p);
|
|
80
|
+
if (!inner.length) continue;
|
|
81
|
+
const xs = inner.map(k => k[0]), ys = inner.map(k => k[1]);
|
|
82
|
+
const label = p.type === 'region' ? p.region!.label : (p.node!.label ?? p.id);
|
|
83
|
+
const role = p.type === 'region' ? (p.region!.role ?? regionKind(cat, p.region!.kind)?.role) : (p.node!.role ?? nodeKindOr(cat, p.node!.asset).role);
|
|
84
|
+
panels.push({ id: p.id, label, sub: p.type === 'node' ? p.node!.sub : undefined, role, cells: [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)] });
|
|
85
|
+
}
|
|
86
|
+
const ends = new Set([...cards.map(c => c.id), ...panels.map(p => p.id)]);
|
|
87
|
+
const links: BoardLink[] = [];
|
|
88
|
+
for (const r of scene.routes) {
|
|
89
|
+
if (!visible(r.id)) continue;
|
|
90
|
+
const a = parseEnd(r.raw.from).id, b = parseEnd(r.raw.to).id;
|
|
91
|
+
if (!ends.has(a) || !ends.has(b)) continue;
|
|
92
|
+
const label = typeof r.raw.label === 'string' ? r.raw.label : r.raw.label?.text;
|
|
93
|
+
links.push({ id: r.id, a, b, kind: r.kind, label });
|
|
94
|
+
}
|
|
95
|
+
return { cards, panels, links };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---- a board in 3D ----
|
|
99
|
+
|
|
100
|
+
/** the 3D board's sizes, in grid units: a card's footprint and height, the gaps, a panel's margin, the channel */
|
|
101
|
+
export const BOARD_3D = { W: 4, D: 2, H: 0.9, GX: 2, GY: 2.4, PAD: 0.6, CH: 2.2, PANEL_H: 0.3 };
|
|
102
|
+
|
|
103
|
+
/** the text on a 3D card's front face */
|
|
104
|
+
export const BOARD_CSS = `
|
|
105
|
+
.blk .card-name{font-size:13px;font-weight:600;fill:var(--ink)}
|
|
106
|
+
.blk .card-sub{font-size:10px;fill:var(--ink);opacity:.75}
|
|
107
|
+
.blk.ghost .card-name,.blk.ghost .card-sub{fill:var(--muted)}
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
/** a card: a slab with its name (and sub) on its front face. The text is the board's (`text`), not the node's label:
|
|
111
|
+
* a node with a label gets the scene's upright label above it as well */
|
|
112
|
+
export function cardAsset(text: (id: string) => { label: string; sub?: string } | undefined): NodeAsset {
|
|
113
|
+
return {
|
|
114
|
+
name: 'card', description: 'A card: a slab with its name on its front face', size: [BOARD_3D.W, BOARD_3D.D, BOARD_3D.H], role: 'grey',
|
|
115
|
+
draw(k: Kernel, b: Box, n: RawNode) {
|
|
116
|
+
const t = text(n.id);
|
|
117
|
+
let s = k.blockFaces(b);
|
|
118
|
+
if (!t) return s;
|
|
119
|
+
const h = b.z1 - b.z0;
|
|
120
|
+
s += k.faceText(b.x0 + 0.2, b.y1, b.z0 + (t.sub ? h * 0.52 : h * 0.34), t.label, 'card-name', FONTS.lbl, 'left', 'start');
|
|
121
|
+
if (t.sub) s += k.faceText(b.x0 + 0.2, b.y1, b.z0 + h * 0.14, t.sub, 'card-sub', FONTS.sub, 'left', 'start');
|
|
122
|
+
return s;
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** the catalogue a board is drawn with in 3D: a panel (a thin slab, its name on its floor) and a card showing the
|
|
128
|
+
* board's text */
|
|
129
|
+
export function boardCatalog(board: Board): KindCatalog {
|
|
130
|
+
const text = new Map(board.cards.map(c => [c.id, { label: c.label, sub: c.sub }]));
|
|
131
|
+
return {
|
|
132
|
+
regions: { panel: { shape: 'slab', pad: BOARD_3D.PAD, z: [BOARD_3D.PANEL_H, 0], floor: true, role: 'grey', labelStyle: 'floor' } },
|
|
133
|
+
nodes: { card: cardAsset(id => text.get(id)) },
|
|
134
|
+
defaultNode: 'card',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** a board as an engine drawing (one scene): panels as regions, nested as they hold each other, cards as nodes, links
|
|
139
|
+
* as routes (kinds and roles: the drawing's own, as a document's `kinds:` and `roles:`) */
|
|
140
|
+
export function boardDiagram(board: Board, opts: { title?: string; kinds?: Record<string, RawKind>; roles?: Record<string, RawRole> } = {}): RawDiagram {
|
|
141
|
+
const g = BOARD_3D;
|
|
142
|
+
const { prect, parentIx, cardAt } = placeBoard(board, { W: g.W, H: g.D, GX: g.GX, GY: g.GY, PAD: g.PAD, TITLE: 0, CH: g.CH });
|
|
143
|
+
const PL = board.panels ?? [];
|
|
144
|
+
const r1 = (v: number) => Math.round(v * 1000) / 1000;
|
|
145
|
+
// each card in its innermost panel: the smallest holding its cell (of equal ones, the later: the earlier holds it)
|
|
146
|
+
const area = (p: BoardPanel) => (p.cells[2] - p.cells[0] + 1) * (p.cells[3] - p.cells[1] + 1);
|
|
147
|
+
const holder = (c: BoardCard) => {
|
|
148
|
+
let best = -1;
|
|
149
|
+
PL.forEach((p, n) => {
|
|
150
|
+
const k = p.cells;
|
|
151
|
+
if (c.cell[0] >= k[0] && c.cell[0] <= k[2] && c.cell[1] >= k[1] && c.cell[1] <= k[3] && (best < 0 || area(p) <= area(PL[best]))) best = n;
|
|
152
|
+
});
|
|
153
|
+
return best;
|
|
154
|
+
};
|
|
155
|
+
const regions: RawRegion[] = PL.map((p, n) => {
|
|
156
|
+
const r = prect[n], par = parentIx[n] >= 0 ? prect[parentIx[n]] : { l: 0, t: 0 };
|
|
157
|
+
return { id: p.id, kind: 'panel', label: p.label, role: p.role, at: [r1(r.l - par.l), r1(r.t - par.t)], size: [r1(r.r - r.l), r1(r.b - r.t)], regions: [], nodes: [] };
|
|
158
|
+
});
|
|
159
|
+
const top: RawRegion[] = [], topNodes: RawNode[] = [];
|
|
160
|
+
regions.forEach((r, n) => (parentIx[n] >= 0 ? regions[parentIx[n]].regions!.push(r) : top.push(r)));
|
|
161
|
+
for (const c of board.cards) {
|
|
162
|
+
const [x, y] = cardAt(board.cards.indexOf(c)), h = holder(c), par = h >= 0 ? prect[h] : { l: 0, t: 0 };
|
|
163
|
+
const node: RawNode = { id: c.id, asset: 'card', role: c.role, ghost: c.ghost || undefined, at: [r1(x - par.l), r1(y - par.t)], size: [g.W, g.D, g.H] };
|
|
164
|
+
(h >= 0 ? regions[h].nodes! : topNodes).push(node);
|
|
165
|
+
}
|
|
166
|
+
for (const r of regions) { if (!r.regions!.length) delete r.regions; if (!r.nodes!.length) delete r.nodes; }
|
|
167
|
+
const routes: RawRoute[] = (board.links ?? []).map((l, i) => ({ id: l.id ?? `link-${i}`, from: l.aOn ?? l.a, to: l.bOn ?? l.b, kind: l.kind, label: l.label }));
|
|
168
|
+
return { isodiag: 1, title: opts.title, kinds: opts.kinds, roles: opts.roles, scenes: [{ id: 'board', title: opts.title ?? 'board', regions: top, nodes: topNodes, routes }] };
|
|
169
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// A drawing document (already a RawDiagram, valid by construction) → laid-out, rendered scenes: compile()'s second half,
|
|
2
|
+
// without parsing YAML or checking the drawing schema. The editor's canvas uses it on the document it generates.
|
|
3
|
+
|
|
4
|
+
import type { Parsed } from '../iso-core/parse.ts';
|
|
5
|
+
import type { Diag } from '../iso-core/errors.ts';
|
|
6
|
+
import { place, type Layout } from './place.ts';
|
|
7
|
+
import { renderScene, type RenderedScene } from './scene.ts';
|
|
8
|
+
import { routeAll, type Routed } from './route.ts';
|
|
9
|
+
import { resolveSteps, type Steps } from './steps.ts';
|
|
10
|
+
import { extendTheme, loadTheme } from '../iso-core/theme.ts';
|
|
11
|
+
import { type KindCatalog, nodeKindOr } from './kinds.ts';
|
|
12
|
+
import type { GridDef, RawDiagram, RawNode, RawRegion, RawScene, Theme } from './types.ts';
|
|
13
|
+
import { facePainter, iconPainter } from './assets.ts';
|
|
14
|
+
|
|
15
|
+
export interface CompiledScene { id: string; raw: RawDiagram['scenes'][number]; layout: Layout; routes: Routed[]; steps: Steps; rendered: RenderedScene; grid: GridDef; assemble: boolean }
|
|
16
|
+
export interface Compiled {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
/** the parsed source: positions and spans of every value, for the proof sheet */
|
|
19
|
+
parsed?: Parsed;
|
|
20
|
+
source?: string;
|
|
21
|
+
diags: Diag[];
|
|
22
|
+
doc?: RawDiagram;
|
|
23
|
+
theme?: Theme;
|
|
24
|
+
/** the kinds it was drawn with (a page's legend and stylesheet ask them) */
|
|
25
|
+
catalog: KindCatalog;
|
|
26
|
+
scenes: CompiledScene[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Places for a document that has no source text: every place is unknown (line 0). */
|
|
30
|
+
export const noSource = (data: unknown): Parsed => ({ data, locate: () => ({ line: 0, col: 0 }), span: () => undefined, diags: [] });
|
|
31
|
+
|
|
32
|
+
export function compileRaw(doc: RawDiagram, themeText: string, catalog: KindCatalog, parsed: Parsed = noSource(doc), source?: string, opts: { snap?: number } = {}, diags: Diag[] = []): Compiled {
|
|
33
|
+
const theme = extendTheme(loadTheme(themeText), doc.roles, doc.kinds);
|
|
34
|
+
const scenes: CompiledScene[] = [];
|
|
35
|
+
const sceneIds = new Map<string, number>();
|
|
36
|
+
doc.scenes.forEach((raw, i) => {
|
|
37
|
+
const path = `/scenes/${i}`;
|
|
38
|
+
if (sceneIds.has(raw.id)) {
|
|
39
|
+
const p = parsed.locate(path + '/id');
|
|
40
|
+
diags.push({ severity: 'error', message: `duplicate scene id "${raw.id}"`, line: p.line, col: p.col, path: path + '/id' });
|
|
41
|
+
}
|
|
42
|
+
sceneIds.set(raw.id, i);
|
|
43
|
+
const grid = { ...doc.grid, ...raw.grid, ...(opts.snap ? { snap: opts.snap } : {}) };
|
|
44
|
+
const layout = place(raw, path, parsed, theme, catalog, doc.roles, grid.snap);
|
|
45
|
+
diags.push(...layout.diags);
|
|
46
|
+
const routed = routeAll(raw, path, layout, parsed, new Set(Object.keys(theme.kinds)), grid.snap);
|
|
47
|
+
diags.push(...routed.diags);
|
|
48
|
+
const steps = resolveSteps(raw, path, layout, routed.routes, parsed, theme);
|
|
49
|
+
diags.push(...steps.diags);
|
|
50
|
+
diags.push(...unknownMarks(raw, path, catalog, parsed));
|
|
51
|
+
const rendered = renderScene({ scene: raw, layout, routes: routed.routes, steps, theme, id: raw.id, gridStep: grid.step ?? grid.snap ?? 1 });
|
|
52
|
+
for (const w of rendered.warnings) { const p = parsed.locate(w.path); diags.push({ severity: 'warning', message: w.message, line: p.line, col: p.col, path: w.path }); }
|
|
53
|
+
scenes.push({ id: raw.id, raw, layout, routes: routed.routes, steps, rendered, grid, assemble: raw.assemble ?? doc.assemble ?? false });
|
|
54
|
+
});
|
|
55
|
+
diags.sort((a, b) => a.line - b.line || a.col - b.col);
|
|
56
|
+
return { ok: !diags.some(d => d.severity === 'error'), diags, doc, theme, catalog, scenes, parsed, source };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** icons and screen faces the scene names that nothing has registered (registerMarks): drawn as a placeholder, and warned */
|
|
60
|
+
function unknownMarks(scene: RawScene, path: string, catalog: KindCatalog, parsed: Parsed): Diag[] {
|
|
61
|
+
const out: Diag[] = [];
|
|
62
|
+
const warn = (at: string, message: string) => { const p = parsed.locate(at); out.push({ severity: 'warning', message, line: p.line, col: p.col, path: at }); };
|
|
63
|
+
const walk = (holder: { nodes?: RawNode[]; regions?: RawRegion[] }, at: string) => {
|
|
64
|
+
holder.nodes?.forEach((n, j) => {
|
|
65
|
+
const np = `${at}/nodes/${j}`;
|
|
66
|
+
(n.deco ?? nodeKindOr(catalog, n.asset).deco ?? []).forEach((d, i) => {
|
|
67
|
+
if (typeof d === 'object' && d.icon && !iconPainter(d.icon)) warn(n.deco ? `${np}/deco/${i}/icon` : np, `node "${n.id}": no icon "${d.icon}" is registered here, so it is drawn as a placeholder`);
|
|
68
|
+
});
|
|
69
|
+
if (n.face !== undefined && !facePainter(n.face)) warn(`${np}/face`, `node "${n.id}": no screen face "${n.face}" is registered here, so it is drawn as a placeholder`);
|
|
70
|
+
});
|
|
71
|
+
holder.regions?.forEach((r, i) => walk(r, `${at}/regions/${i}`));
|
|
72
|
+
};
|
|
73
|
+
walk(scene, path);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|