@johnoscott/isometric-engine 0.14.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/iso-editor.js +249 -203
- package/iso-render.js +200 -154
- package/iso-systems.js +210 -162
- package/isometric-diagram.js +389 -0
- package/js/iso-core/index.js +5 -0
- package/js/iso-core/mono.js +242 -0
- package/js/iso-editor/ui/canvas.js +23 -1
- package/js/iso-objects/ants.js +36 -0
- package/js/iso-objects/index.js +55 -1
- package/js/iso-objects/looks.js +25 -0
- package/js/iso-objects/mono-paint.js +96 -0
- package/js/iso-objects/motion-builder.js +130 -0
- package/js/iso-objects/motion-doc.js +421 -0
- package/js/iso-objects/motion-entry.js +34 -0
- package/js/iso-objects/motion-schema.js +83 -0
- package/js/iso-objects/motion.js +640 -0
- package/js/iso-objects/resolve.js +238 -0
- package/js/iso-objects/scene.js +15 -13
- package/js/iso-objects/timeline.js +593 -0
- package/js/iso-systems/compile.js +83 -1
- package/js/iso-systems/index.js +4 -1
- package/js/iso-systems/render.js +20 -0
- package/js/iso-systems/schema.json +40 -0
- package/js/iso-viewer/index.js +6 -0
- package/js/iso-viewer/page.js +40 -16
- package/js/iso-viewer/play.js +340 -0
- package/js/iso-viewer/player.js +149 -175
- package/js/iso-viewer/transport.js +289 -0
- package/package.json +84 -2
- package/src/iso-core/index.ts +1 -0
- package/src/iso-core/mono.ts +306 -0
- package/src/iso-core/theme.ts +2 -1
- package/src/iso-editor/ui/canvas.ts +14 -1
- package/src/iso-objects/ants.ts +53 -0
- package/src/iso-objects/compile.ts +4 -1
- package/src/iso-objects/index.ts +16 -1
- package/src/iso-objects/looks.ts +21 -0
- package/src/iso-objects/mono-paint.ts +97 -0
- package/src/iso-objects/motion-builder.ts +79 -0
- package/src/iso-objects/motion-doc.ts +309 -0
- package/src/iso-objects/motion-entry.ts +13 -0
- package/src/iso-objects/motion-schema.ts +55 -0
- package/src/iso-objects/motion.ts +617 -0
- package/src/iso-objects/resolve.ts +196 -0
- package/src/iso-objects/scene.ts +32 -13
- package/src/iso-objects/timeline.ts +493 -0
- package/src/iso-objects/types.ts +22 -2
- package/src/iso-systems/compile.ts +86 -4
- package/src/iso-systems/index.ts +4 -1
- package/src/iso-systems/render.ts +45 -0
- package/src/iso-systems/schema.json +40 -0
- package/src/iso-viewer/index.ts +4 -0
- package/src/iso-viewer/page.ts +28 -11
- package/src/iso-viewer/play.ts +280 -0
- package/src/iso-viewer/player.ts +132 -150
- package/src/iso-viewer/transport.ts +272 -0
- package/types/iso-core/index.d.ts +1 -0
- package/types/iso-core/mono.d.ts +61 -0
- package/types/iso-core/theme.d.ts +2 -0
- package/types/iso-objects/ants.d.ts +34 -0
- package/types/iso-objects/compile.d.ts +3 -0
- package/types/iso-objects/index.d.ts +16 -1
- package/types/iso-objects/looks.d.ts +4 -0
- package/types/iso-objects/mono-paint.d.ts +20 -0
- package/types/iso-objects/motion-builder.d.ts +105 -0
- package/types/iso-objects/motion-doc.d.ts +193 -0
- package/types/iso-objects/motion-entry.d.ts +11 -0
- package/types/iso-objects/motion-schema.d.ts +594 -0
- package/types/iso-objects/motion.d.ts +202 -0
- package/types/iso-objects/resolve.d.ts +20 -0
- package/types/iso-objects/scene.d.ts +14 -0
- package/types/iso-objects/timeline.d.ts +66 -0
- package/types/iso-objects/types.d.ts +34 -0
- package/types/iso-systems/compile.d.ts +25 -3
- package/types/iso-systems/index.d.ts +4 -1
- package/types/iso-systems/render.d.ts +25 -0
- package/types/iso-viewer/index.d.ts +4 -0
- package/types/iso-viewer/play.d.ts +37 -0
- package/types/iso-viewer/transport.d.ts +73 -0
- package/types/player/isometric-diagram.d.ts +24 -0
|
@@ -3,8 +3,62 @@ import { validateSchema } from "./validate.js";
|
|
|
3
3
|
import { place } from "../iso-objects/place.js";
|
|
4
4
|
import { extendTheme, loadTheme } from "../iso-core/theme.js";
|
|
5
5
|
import { compileRaw } from "../iso-objects/compile.js";
|
|
6
|
+
import { resolveSvg } from "../iso-objects/resolve.js";
|
|
7
|
+
import { monoOfDrawing, paintMono } from "../iso-objects/mono-paint.js";
|
|
8
|
+
import { bindMotion } from "../iso-objects/timeline.js";
|
|
9
|
+
import { antsOf } from "../iso-objects/ants.js";
|
|
10
|
+
import { drawLooks } from "../iso-objects/looks.js";
|
|
11
|
+
import { drawingCss, GRID_CSS, MARKS_CSS } from "../iso-objects/css.js";
|
|
6
12
|
import { systems } from "./catalog.js";
|
|
13
|
+
class CompileError extends Error {
|
|
14
|
+
diags;
|
|
15
|
+
constructor(diags) {
|
|
16
|
+
super(diags.filter((d) => d.severity === "error").map((d) => `line ${d.line}: ${d.message}`).join("\n"));
|
|
17
|
+
this.name = "CompileError";
|
|
18
|
+
this.diags = diags;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
function compile(source, themeText, opts = {}) {
|
|
22
|
+
const c = compileAll(source, themeText, opts);
|
|
23
|
+
if (!c.ok && opts.strict === "throw") throw new CompileError(c.diags);
|
|
24
|
+
if (!c.ok && opts.strict) c.scenes = [];
|
|
25
|
+
if (opts.stepMs !== void 0) for (const s of c.scenes) for (const st of s.steps.steps) st.duration = opts.stepMs;
|
|
26
|
+
if (opts.treatment !== void 0 && opts.treatment !== "mono" && opts.treatment !== "none") throw new Error(`treatment: there is "mono" (and "none"), and no ${JSON.stringify(opts.treatment)}`);
|
|
27
|
+
const treatment = (opts.treatment ?? c.doc?.treatment) === "mono";
|
|
28
|
+
if (opts.treatment === "mono" && !opts.resolveVars) throw new Error("treatment: a self-contained drawing's (resolveVars)");
|
|
29
|
+
const theme = c.theme;
|
|
30
|
+
if (opts.resolveVars) for (const s of c.scenes) {
|
|
31
|
+
const mode = opts.mode ?? "light", css = drawingCss(systems) + MARKS_CSS + GRID_CSS;
|
|
32
|
+
if (treatment) {
|
|
33
|
+
toMono(s, theme, mode, css, opts.mono);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const o = { mode, theme: c.theme, css };
|
|
37
|
+
s.rendered.svg = resolveSvg(s.rendered.svg, o);
|
|
38
|
+
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
|
|
39
|
+
s.rendered.inks = {
|
|
40
|
+
surface: c.theme[o.mode].surface ?? c.theme.light.surface,
|
|
41
|
+
control: c.theme[o.mode].control ?? c.theme.light.control,
|
|
42
|
+
kinds: Object.fromEntries(Object.entries(c.theme.kinds).map(([k, v]) => [k, c.theme[o.mode][v.color] ?? v.color]))
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (opts.resolveVars && treatment && theme) c.theme = { ...theme, kinds: Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => {
|
|
46
|
+
const d = c.scenes.map((s) => s.rendered.mono?.kinds[k]?.dash).find((x) => x && x.length > 1);
|
|
47
|
+
return [k, d ? { ...v, ants: [d[0], d[1]] } : v];
|
|
48
|
+
})) };
|
|
49
|
+
return c;
|
|
50
|
+
}
|
|
51
|
+
function toMono(s, theme, mode, css, own) {
|
|
52
|
+
const all = [s.rendered.svg, ...Object.values(s.rendered.variants ?? {})];
|
|
53
|
+
const m = monoOfDrawing(all.join(""), theme, mode, [...s.routes.map((r) => r.kind), ...s.steps.kindsUsed], own);
|
|
54
|
+
const draw = (svg) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css }), m.look, s.id);
|
|
55
|
+
s.rendered.svg = draw(s.rendered.svg);
|
|
56
|
+
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, draw(v)]));
|
|
57
|
+
s.rendered.inks = { surface: m.look.paper, control: m.look.ink, kinds: Object.fromEntries(Object.keys(theme.kinds).map((k) => [k, m.look.ink])) };
|
|
58
|
+
s.rendered.mono = m.look;
|
|
59
|
+
for (const w of m.look.warnings) s.rendered.warnings.push({ path: "", message: `black and white: ${w}` });
|
|
60
|
+
}
|
|
61
|
+
function compileAll(source, themeText, opts) {
|
|
8
62
|
const parsed = parse(source);
|
|
9
63
|
const diags = [...parsed.diags];
|
|
10
64
|
if (diags.some((d) => d.severity === "error")) return { ok: false, diags, catalog: systems, scenes: [] };
|
|
@@ -27,8 +81,36 @@ function compile(source, themeText, opts = {}) {
|
|
|
27
81
|
diags.sort((a, b) => a.line - b.line || a.col - b.col);
|
|
28
82
|
return { ok: false, diags, catalog: systems, scenes: [] };
|
|
29
83
|
}
|
|
30
|
-
|
|
84
|
+
const c = compileRaw(doc, themeText, systems, parsed, source, { snap: opts.snap }, diags);
|
|
85
|
+
let faults = 0;
|
|
86
|
+
const say = (path, message, hint) => {
|
|
87
|
+
const at = parsed.locate(path);
|
|
88
|
+
c.diags.push({ severity: "error", message, line: at.line, col: at.col, path, ...hint ? { hint } : {} });
|
|
89
|
+
faults++;
|
|
90
|
+
};
|
|
91
|
+
c.scenes.forEach((s, i) => {
|
|
92
|
+
drawLooks(s, c.theme);
|
|
93
|
+
const ants = s.raw.ants, ids = antsOf(s.raw)?.ids, known = s.routes.map((r) => r.id);
|
|
94
|
+
(ids ?? []).forEach((id, k) => {
|
|
95
|
+
if (!known.includes(id)) say(`/scenes/${i}/ants${Array.isArray(ants) ? "" : "/ids"}/${k}`, `no connector "${id}" in this scene`, known.length ? `its connectors: ${known.slice(0, 8).join(", ")}${known.length > 8 ? ", \u2026" : ""}` : void 0);
|
|
96
|
+
});
|
|
97
|
+
if (!s.raw.motion) return;
|
|
98
|
+
const motion = { isomotion: 1, ...s.raw.motion }, path = `/scenes/${i}/motion`;
|
|
99
|
+
const said = bindMotion(s, motion, { kinds: c.theme.kinds }).diags;
|
|
100
|
+
for (const d of said) {
|
|
101
|
+
const at = parsed.locate(path + d.path);
|
|
102
|
+
c.diags.push({ severity: d.severity, message: d.message, line: at.line, col: at.col, path: path + d.path, ...d.hint ? { hint: d.hint } : {} });
|
|
103
|
+
}
|
|
104
|
+
faults += said.length;
|
|
105
|
+
if (!said.length) s.motion = motion;
|
|
106
|
+
});
|
|
107
|
+
if (faults) {
|
|
108
|
+
c.ok = false;
|
|
109
|
+
c.diags.sort((a, b) => a.line - b.line || a.col - b.col);
|
|
110
|
+
}
|
|
111
|
+
return c;
|
|
31
112
|
}
|
|
32
113
|
export {
|
|
114
|
+
CompileError,
|
|
33
115
|
compile
|
|
34
116
|
};
|
package/js/iso-systems/index.js
CHANGED
|
@@ -2,14 +2,17 @@ import { NODE_ASSETS, getAsset } from "./nodes.js";
|
|
|
2
2
|
import { REGION_KINDS, systems } from "./catalog.js";
|
|
3
3
|
import { DRAWING_CSS, BASE_CSS } from "./css.js";
|
|
4
4
|
import { validateSchema, schemaValidator } from "./validate.js";
|
|
5
|
-
import { compile } from "./compile.js";
|
|
5
|
+
import { compile, CompileError } from "./compile.js";
|
|
6
|
+
import { renderSvg } from "./render.js";
|
|
6
7
|
export {
|
|
7
8
|
BASE_CSS,
|
|
9
|
+
CompileError,
|
|
8
10
|
DRAWING_CSS,
|
|
9
11
|
NODE_ASSETS,
|
|
10
12
|
REGION_KINDS,
|
|
11
13
|
compile,
|
|
12
14
|
getAsset,
|
|
15
|
+
renderSvg,
|
|
13
16
|
schemaValidator,
|
|
14
17
|
systems,
|
|
15
18
|
validateSchema
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { antsOf, withAnts } from "../iso-objects/ants.js";
|
|
2
|
+
import { svgAt } from "../iso-objects/motion.js";
|
|
3
|
+
import { bindMotion } from "../iso-objects/timeline.js";
|
|
4
|
+
import { compile } from "./compile.js";
|
|
5
|
+
function renderSvg(source, o) {
|
|
6
|
+
const c = compile(source, o.theme, { mode: o.mode ?? "light", resolveVars: true, strict: "throw", treatment: o.treatment, mono: o.mono }), kinds = c.theme.kinds;
|
|
7
|
+
const s = o.scene === void 0 ? c.scenes[0] : typeof o.scene === "number" ? c.scenes[o.scene] : c.scenes.find((x) => x.id === o.scene);
|
|
8
|
+
if (!s) throw new Error(`no scene ${JSON.stringify(o.scene)} (there ${c.scenes.length === 1 ? "is" : "are"} ${c.scenes.map((x) => x.id).join(", ")})`);
|
|
9
|
+
const ants = o.ants === void 0 ? antsOf(s.raw) : o.ants === true ? antsOf(s.raw) ?? {} : o.ants || void 0;
|
|
10
|
+
if (o.t === void 0) return ants ? withAnts(s, { ...ants, by: o.ambient === "off" ? "none" : "smil", kinds }) : s.rendered.svg;
|
|
11
|
+
if (o.ants) throw new Error("ants: at a moment they are its motion document's");
|
|
12
|
+
const doc = o.motion ?? s.motion;
|
|
13
|
+
if (!doc) throw new Error("t: this scene has no motion");
|
|
14
|
+
const tl = bindMotion(s, doc, { kinds });
|
|
15
|
+
if (!tl.ok) throw new Error(tl.diags.map((d) => `${d.path}: ${d.message}${d.hint ? ` (${d.hint})` : ""}`).join("\n"));
|
|
16
|
+
return svgAt(s, tl.at(o.t, o.ambient === void 0 ? {} : { ambient: o.ambient }));
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
renderSvg
|
|
20
|
+
};
|
|
@@ -26,9 +26,33 @@
|
|
|
26
26
|
"grid": { "$ref": "#/$defs/grid" },
|
|
27
27
|
"assemble": { "type": "boolean", "description": "draw each scene by flying its parts in from the nearest edge, then play" },
|
|
28
28
|
"footer": { "type": "string" },
|
|
29
|
+
"treatment": { "enum": ["mono"], "description": "How a self-contained drawing (renderSvg, <isometric-diagram>) is painted: mono, black and white. A host may say otherwise. The page isodiag build writes is in colour." },
|
|
29
30
|
"scenes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/scene" } }
|
|
30
31
|
},
|
|
31
32
|
"$defs": {
|
|
33
|
+
"motion": {
|
|
34
|
+
"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
35
|
+
"description": "how this piece (a region: its contents too) moves when the drawing assembles or disassembles",
|
|
36
|
+
"properties": {
|
|
37
|
+
"style": { "enum": ["edge", "drop", "rise", "fly", "pop", "scatter", "build", "fade"], "description": "how it arrives" },
|
|
38
|
+
"out": { "enum": ["explode", "lift-off", "sink", "scatter", "fly-out", "collapse", "fade", "reverse"], "description": "how it leaves" },
|
|
39
|
+
"easing": { "enum": ["linear", "ease", "ease-in", "ease-out", "settle", "spring", "bounce"] },
|
|
40
|
+
"from": { "enum": ["left", "right", "top", "bottom"], "description": "fly: the side it comes from" },
|
|
41
|
+
"delay": { "type": "number", "minimum": 0, "description": "ms after its turn" },
|
|
42
|
+
"duration": { "type": "number", "exclusiveMinimum": 0, "description": "ms its own move takes" }
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"variants": {
|
|
46
|
+
"type": "object", "minProperties": 1, "propertyNames": { "$ref": "#/$defs/id" },
|
|
47
|
+
"description": "other looks of it, by name, for a motion to switch to (its box stays as it is)",
|
|
48
|
+
"additionalProperties": {
|
|
49
|
+
"type": "object", "additionalProperties": false, "minProperties": 1,
|
|
50
|
+
"properties": {
|
|
51
|
+
"role": { "type": "string" }, "ghost": { "type": "boolean" }, "label": { "type": "string" }, "sub": { "type": "string" },
|
|
52
|
+
"face": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" }, "deco": { "type": "array", "items": { "$ref": "#/$defs/deco" } }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
32
56
|
"id": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]*$" },
|
|
33
57
|
"grid": {
|
|
34
58
|
"type": "object",
|
|
@@ -88,6 +112,18 @@
|
|
|
88
112
|
"properties": {
|
|
89
113
|
"id": { "$ref": "#/$defs/id" },
|
|
90
114
|
"title": { "type": "string" },
|
|
115
|
+
"ants": {
|
|
116
|
+
"description": "its connectors march, showing which way they flow: all that may, these, or with a speed (units a second) and a dash",
|
|
117
|
+
"anyOf": [
|
|
118
|
+
{ "type": "boolean" },
|
|
119
|
+
{ "type": "array", "items": { "type": "string" } },
|
|
120
|
+
{ "type": "object", "additionalProperties": false, "properties": {
|
|
121
|
+
"ids": { "type": "array", "items": { "type": "string" } },
|
|
122
|
+
"speed": { "type": "number" },
|
|
123
|
+
"dash": { "type": "array", "items": { "type": "number", "exclusiveMinimum": 0 }, "minItems": 2, "maxItems": 2 } } }
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"motion": { "type": "object", "description": "the scene's motion document (isomotion/1; its `isomotion: 1` may be left out)" },
|
|
91
127
|
"caption": { "type": "string" },
|
|
92
128
|
"aria": { "type": "string" },
|
|
93
129
|
"gap": { "type": "number", "exclusiveMinimum": 0 },
|
|
@@ -143,6 +179,8 @@
|
|
|
143
179
|
},
|
|
144
180
|
"around": { "type": "array", "items": { "$ref": "#/$defs/id" }, "description": "tunnel: routes it wraps" },
|
|
145
181
|
"regions": { "type": "array", "items": { "$ref": "#/$defs/region" } },
|
|
182
|
+
"motion": { "$ref": "#/$defs/motion" },
|
|
183
|
+
"variants": { "$ref": "#/$defs/variants" },
|
|
146
184
|
"nodes": { "type": "array", "items": { "$ref": "#/$defs/node" } }
|
|
147
185
|
}
|
|
148
186
|
},
|
|
@@ -188,6 +226,8 @@
|
|
|
188
226
|
"dy": { "type": "number" }
|
|
189
227
|
}
|
|
190
228
|
},
|
|
229
|
+
"motion": { "$ref": "#/$defs/motion" },
|
|
230
|
+
"variants": { "$ref": "#/$defs/variants" },
|
|
191
231
|
"nodes": { "type": "array", "items": { "$ref": "#/$defs/node" }, "description": "nodes standing on top of this one" }
|
|
192
232
|
}
|
|
193
233
|
},
|
package/js/iso-viewer/index.js
CHANGED
|
@@ -5,6 +5,8 @@ import { n, node, rewrite, prune, cls, attr, extent, unite, fitWithOverlay } fro
|
|
|
5
5
|
import { isoVars, scopeSelector, scope } from "./view-css.js";
|
|
6
6
|
import { md, stepData, legend, renderPage } from "./page.js";
|
|
7
7
|
import { playerScript } from "./bundle.js";
|
|
8
|
+
import { transport, pageClock } from "./transport.js";
|
|
9
|
+
import { mountPlayer, PLAY_CSS } from "./play.js";
|
|
8
10
|
import { h } from "./dom.js";
|
|
9
11
|
import { TIMELINE_VERSION, SEGMENT_NAME, SEVERITIES, BINS, BIN_MS, scopePattern } from "./timeline-contract.js";
|
|
10
12
|
import { scopeRules, escapeName, formatScope, join, levelOf, prefixAt, parentOf, within, hasSegment, kindOf, nameOf, crumbs } from "./timeline-scope.js";
|
|
@@ -28,6 +30,7 @@ export {
|
|
|
28
30
|
MAX_ZOOM,
|
|
29
31
|
MIN_ZOOM,
|
|
30
32
|
P3,
|
|
33
|
+
PLAY_CSS,
|
|
31
34
|
SEGMENT_NAME,
|
|
32
35
|
SEVERITIES,
|
|
33
36
|
TIMELINE_VERSION,
|
|
@@ -66,12 +69,14 @@ export {
|
|
|
66
69
|
memorySource,
|
|
67
70
|
modeFor,
|
|
68
71
|
morphSvgs,
|
|
72
|
+
mountPlayer,
|
|
69
73
|
mountTimeline,
|
|
70
74
|
n,
|
|
71
75
|
nameOf,
|
|
72
76
|
node,
|
|
73
77
|
offsetAt,
|
|
74
78
|
overlayPaint,
|
|
79
|
+
pageClock,
|
|
75
80
|
parentOf,
|
|
76
81
|
playerScript,
|
|
77
82
|
prefixAt,
|
|
@@ -94,6 +99,7 @@ export {
|
|
|
94
99
|
timeScale,
|
|
95
100
|
toCSV,
|
|
96
101
|
toJSON,
|
|
102
|
+
transport,
|
|
97
103
|
unite,
|
|
98
104
|
viewToggle,
|
|
99
105
|
viewport,
|
package/js/iso-viewer/page.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bindMotion, motionOfSteps, motionSource } from "../iso-objects/timeline.js";
|
|
1
2
|
import { esc } from "../iso-core/kernel.js";
|
|
2
3
|
import { themeCss } from "../iso-core/theme.js";
|
|
3
4
|
import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
|
|
@@ -9,18 +10,41 @@ function md(s) {
|
|
|
9
10
|
return esc(s).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, t, u) => /^(https?:|#|\.{0,2}\/)/.test(u.replace(/&/g, "&")) ? `<a href="${u}">${t}</a>` : t);
|
|
10
11
|
}
|
|
11
12
|
const paras = (s) => (s ?? "").split(/\n\s*\n/).filter(Boolean).map((p) => `<p class="sec-sub">${md(p.trim())}</p>`).join("");
|
|
13
|
+
const ownMotion = (c, s) => !!s.motion && bindMotion(s, s.motion, { kinds: c.theme.kinds }).ok;
|
|
14
|
+
function stepsOf(c, s) {
|
|
15
|
+
if (!ownMotion(c, s)) return s.steps.steps;
|
|
16
|
+
return bindMotion(s, s.motion, { kinds: c.theme.kinds }).beats.map((b) => ({
|
|
17
|
+
n: b.index + 1,
|
|
18
|
+
num: b.index + 1,
|
|
19
|
+
kind: "control",
|
|
20
|
+
color: b.say?.color ?? colorRef(c.theme, c.theme.kinds.control?.color ?? "control"),
|
|
21
|
+
heading: b.say?.title ?? b.name,
|
|
22
|
+
caption: b.say?.text ?? "",
|
|
23
|
+
command: b.say?.code ?? "",
|
|
24
|
+
phases: [],
|
|
25
|
+
pulses: [],
|
|
26
|
+
lit: [],
|
|
27
|
+
duration: b.end - b.start
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
12
30
|
function stepData(c) {
|
|
13
31
|
return JSON.stringify({
|
|
14
|
-
scenes: c.scenes.map((s) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
scenes: c.scenes.map((s) => {
|
|
33
|
+
const own = ownMotion(c, s), steps = stepsOf(c, s), doc = own ? s.motion : s.steps.steps.length ? motionOfSteps(s) : void 0;
|
|
34
|
+
return {
|
|
35
|
+
id: s.id,
|
|
36
|
+
loop: s.raw.loop ?? true,
|
|
37
|
+
dim: s.raw.dim ?? "flows",
|
|
38
|
+
vis: s.steps.vis,
|
|
39
|
+
// (where a step's view goes is its document's camera)
|
|
40
|
+
steps: steps.map(({ focus: _, ...st }) => ({ ...st, caption: md(st.caption) })),
|
|
41
|
+
assemble: s.assemble,
|
|
42
|
+
grid: !!s.grid.show,
|
|
43
|
+
source: motionSource(s),
|
|
44
|
+
...doc ? { doc } : {},
|
|
45
|
+
...own ? { own } : {}
|
|
46
|
+
};
|
|
47
|
+
})
|
|
24
48
|
});
|
|
25
49
|
}
|
|
26
50
|
function legend(c, s) {
|
|
@@ -42,8 +66,8 @@ function legend(c, s) {
|
|
|
42
66
|
}
|
|
43
67
|
return items.join("");
|
|
44
68
|
}
|
|
45
|
-
function player(s) {
|
|
46
|
-
const st = s
|
|
69
|
+
function player(c, s) {
|
|
70
|
+
const st = stepsOf(c, s);
|
|
47
71
|
const tools = `<div class="tools">
|
|
48
72
|
<button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? "true" : "false"}" title="Show the floor grid">Grid</button>
|
|
49
73
|
<button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
|
|
@@ -66,8 +90,8 @@ function player(s) {
|
|
|
66
90
|
<div class="dots"></div>
|
|
67
91
|
</div>`;
|
|
68
92
|
}
|
|
69
|
-
function stepList(s) {
|
|
70
|
-
const st = s
|
|
93
|
+
function stepList(c, s) {
|
|
94
|
+
const st = stepsOf(c, s);
|
|
71
95
|
if (!st.length) return "";
|
|
72
96
|
return `<details class="steps"><summary>All ${st.length} steps as text</summary><ol>${st.map((x) => `<li value="${x.num}"><b>${esc(x.heading)}.</b> ${md(x.caption)}${x.command ? `<br><code>${esc(x.command)}</code>` : ""}</li>`).join("")}</ol></details>`;
|
|
73
97
|
}
|
|
@@ -80,10 +104,10 @@ function renderPage(c, opts = {}) {
|
|
|
80
104
|
${paras(s.raw.caption)}
|
|
81
105
|
<div class="figure" tabindex="-1">
|
|
82
106
|
<div class="scroller">${s.grid.show ? s.rendered.svg.replace("<svg ", '<svg class="show-grid" ') : s.rendered.svg}</div>
|
|
83
|
-
${player(s)}
|
|
107
|
+
${player(c, s)}
|
|
84
108
|
<div class="legend">${legend(c, s)}</div>
|
|
85
109
|
</div>
|
|
86
|
-
${stepList(s)}
|
|
110
|
+
${stepList(c, s)}
|
|
87
111
|
${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ""}
|
|
88
112
|
</section>`).join("\n");
|
|
89
113
|
return `<!doctype html>
|