@johnoscott/isometric-engine 0.15.0 → 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 +230 -193
- package/iso-render.js +184 -147
- package/iso-systems.js +183 -146
- 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 +1 -1
- package/js/iso-objects/index.js +10 -2
- package/js/iso-objects/mono-paint.js +96 -0
- package/js/iso-objects/motion-doc.js +0 -79
- package/js/iso-objects/motion-entry.js +4 -2
- package/js/iso-objects/motion-schema.js +83 -0
- package/js/iso-objects/motion.js +9 -4
- package/js/iso-objects/timeline.js +51 -11
- package/js/iso-systems/compile.js +25 -1
- package/js/iso-systems/render.js +1 -1
- package/js/iso-systems/schema.json +1 -0
- package/js/iso-viewer/index.js +6 -0
- package/js/iso-viewer/page.js +40 -17
- package/js/iso-viewer/play.js +340 -0
- package/js/iso-viewer/player.js +147 -162
- package/js/iso-viewer/transport.js +289 -0
- package/package.json +39 -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 +2 -2
- package/src/iso-objects/index.ts +5 -3
- package/src/iso-objects/mono-paint.ts +97 -0
- package/src/iso-objects/motion-doc.ts +0 -52
- package/src/iso-objects/motion-entry.ts +4 -3
- package/src/iso-objects/motion-schema.ts +55 -0
- package/src/iso-objects/motion.ts +6 -5
- package/src/iso-objects/scene.ts +3 -0
- package/src/iso-objects/timeline.ts +63 -13
- package/src/iso-objects/types.ts +2 -0
- package/src/iso-systems/compile.ts +29 -2
- package/src/iso-systems/render.ts +5 -1
- package/src/iso-systems/schema.json +1 -0
- package/src/iso-viewer/index.ts +4 -0
- package/src/iso-viewer/page.ts +28 -12
- package/src/iso-viewer/play.ts +280 -0
- package/src/iso-viewer/player.ts +133 -134
- 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 +1 -0
- package/types/iso-objects/index.d.ts +5 -3
- package/types/iso-objects/mono-paint.d.ts +20 -0
- package/types/iso-objects/motion-doc.d.ts +0 -594
- package/types/iso-objects/motion-entry.d.ts +4 -3
- package/types/iso-objects/motion-schema.d.ts +594 -0
- package/types/iso-objects/motion.d.ts +4 -2
- package/types/iso-objects/scene.d.ts +3 -0
- package/types/iso-objects/timeline.d.ts +22 -2
- package/types/iso-objects/types.d.ts +2 -0
- package/types/iso-systems/compile.d.ts +5 -0
- package/types/iso-systems/render.d.ts +4 -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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS } from "./motion.js";
|
|
2
|
+
import { EASING_NAMES, EXTRAPOLATE } from "./motion-doc.js";
|
|
3
|
+
const TIME = { anyOf: [{ type: "number" }, { type: "string", pattern: "^-?\\d+(\\.\\d+)?(ms|s|f)?$" }] };
|
|
4
|
+
const IDS = { type: "array", items: { type: "string" } };
|
|
5
|
+
const EASE = { anyOf: [{ enum: EASING_NAMES }, { type: "object", required: ["bezier"], additionalProperties: false, properties: { bezier: { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { $ref: "#/$defs/spring" } } }] };
|
|
6
|
+
const timing = { from: { $ref: "#/$defs/time" }, duration: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } };
|
|
7
|
+
const node = (key, value, more = {}, withTiming = true) => ({ type: "object", required: [key], additionalProperties: false, properties: { [key]: value, ...withTiming ? timing : {}, ...more } });
|
|
8
|
+
const MOTION_SCHEMA = {
|
|
9
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
10
|
+
title: "isomotion/1",
|
|
11
|
+
type: "object",
|
|
12
|
+
required: ["isomotion"],
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
isomotion: { const: 1 },
|
|
16
|
+
fps: { type: "number", exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' },
|
|
17
|
+
seed: { type: "integer" },
|
|
18
|
+
ambient: { enum: ["on", "off"], description: "Off: the ants and the looping tokens and pulses stand still, each at its start." },
|
|
19
|
+
series: { $ref: "#/$defs/series" },
|
|
20
|
+
layers: { $ref: "#/$defs/nodes" },
|
|
21
|
+
markers: { type: "object", additionalProperties: { anyOf: [{ type: "number" }, { type: "string" }] } }
|
|
22
|
+
},
|
|
23
|
+
$defs: {
|
|
24
|
+
time: TIME,
|
|
25
|
+
ids: IDS,
|
|
26
|
+
ease: EASE,
|
|
27
|
+
spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" } } },
|
|
28
|
+
curve: { type: "object", required: ["times", "values"], additionalProperties: false, properties: { times: { type: "array", items: { $ref: "#/$defs/time" }, minItems: 1 }, values: { type: "array", items: { type: "number" }, minItems: 1 }, easing: { $ref: "#/$defs/ease" }, extrapolateLeft: { enum: EXTRAPOLATE }, extrapolateRight: { enum: EXTRAPOLATE } } },
|
|
29
|
+
say: { type: "object", additionalProperties: false, properties: { chapter: { type: "string" }, title: { type: "string" }, text: { type: "string" }, code: { type: "string" }, color: { type: "string" }, facts: { type: "array", items: { type: "array", items: { type: "string" }, minItems: 2, maxItems: 2 } } } },
|
|
30
|
+
focus: { type: "object", required: ["lit"], additionalProperties: false, properties: { lit: { $ref: "#/$defs/ids" }, scope: { enum: ["all", "links"] }, level: { type: "number", minimum: 0, maximum: 1 }, always: { $ref: "#/$defs/ids" } } },
|
|
31
|
+
sequence: {
|
|
32
|
+
type: "object",
|
|
33
|
+
additionalProperties: false,
|
|
34
|
+
properties: {
|
|
35
|
+
name: { type: "string", pattern: "^[A-Za-z][\\w-]*$" },
|
|
36
|
+
from: { $ref: "#/$defs/time" },
|
|
37
|
+
offset: { $ref: "#/$defs/time" },
|
|
38
|
+
trimBefore: { $ref: "#/$defs/time" },
|
|
39
|
+
duration: { anyOf: [{ $ref: "#/$defs/time" }, { type: "object", required: ["read"], additionalProperties: false, properties: { read: { anyOf: [{ const: true }, { type: "object", additionalProperties: false, properties: { base: { type: "number" }, perChar: { type: "number" }, min: { type: "number" }, max: { type: "number" } } }] } } }] },
|
|
40
|
+
loop: { anyOf: [{ type: "boolean" }, { type: "integer", minimum: 1 }] },
|
|
41
|
+
playbackRate: { type: "number", exclusiveMinimum: 0 },
|
|
42
|
+
say: { $ref: "#/$defs/say" },
|
|
43
|
+
show: { $ref: "#/$defs/ids" },
|
|
44
|
+
hide: { $ref: "#/$defs/ids" },
|
|
45
|
+
focus: { $ref: "#/$defs/focus" },
|
|
46
|
+
highlight: { $ref: "#/$defs/ids" },
|
|
47
|
+
levels: { type: "object", additionalProperties: { type: "number", minimum: 0, maximum: 1 } },
|
|
48
|
+
variants: { type: "object", additionalProperties: { type: "string" } },
|
|
49
|
+
enter: { type: "object", required: ["fade"], additionalProperties: false, properties: { fade: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } } },
|
|
50
|
+
ants: { anyOf: [{ type: "boolean" }, { $ref: "#/$defs/ids" }] },
|
|
51
|
+
children: { $ref: "#/$defs/nodes" },
|
|
52
|
+
layers: { $ref: "#/$defs/nodes" },
|
|
53
|
+
series: { $ref: "#/$defs/series" }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
series: { type: "array", items: { anyOf: [{ $ref: "#/$defs/seq" }, node("transition", { type: "object", required: ["presentation", "timing"], additionalProperties: false, properties: { presentation: { enum: ["fade", "none"] }, timing: { anyOf: [{ type: "object", required: ["linear"], additionalProperties: false, properties: { linear: { $ref: "#/$defs/time" } } }, { type: "object", required: ["spring"], additionalProperties: false, properties: { spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" }, duration: { $ref: "#/$defs/time" } } } } }] } } }, {}, false)] } },
|
|
57
|
+
seq: node("sequence", { $ref: "#/$defs/sequence" }, {}, false),
|
|
58
|
+
plan: { type: "object" },
|
|
59
|
+
nodes: {
|
|
60
|
+
type: "array",
|
|
61
|
+
items: { anyOf: [
|
|
62
|
+
{ $ref: "#/$defs/seq" },
|
|
63
|
+
node("series", { $ref: "#/$defs/series" }, {}, false),
|
|
64
|
+
node("layers", { $ref: "#/$defs/nodes" }, {}, false),
|
|
65
|
+
node("assemble", { type: "object", properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
66
|
+
node("disassemble", { type: "object", properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
67
|
+
node("travel", { type: "array", items: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }] }, minItems: 1 }, { each: { $ref: "#/$defs/time" }, hold: { $ref: "#/$defs/time" }, loop: { type: "boolean" } }),
|
|
68
|
+
node("pulse", { $ref: "#/$defs/ids" }, { loop: { type: "boolean" } }),
|
|
69
|
+
node("ants", { anyOf: [{ const: true }, { $ref: "#/$defs/ids" }] }, { speed: { type: "number" }, dash: { type: "array", items: { type: "number", exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
|
|
70
|
+
node("draw", { $ref: "#/$defs/ids" }, { by: { enum: ["stroke", "grow"] }, stagger: { $ref: "#/$defs/time" } }),
|
|
71
|
+
node("type", { $ref: "#/$defs/ids" }),
|
|
72
|
+
{ type: "object", required: ["move"], additionalProperties: false, properties: { move: { type: "string" }, from: { $ref: "#/$defs/time" }, x: { $ref: "#/$defs/curve" }, y: { $ref: "#/$defs/curve" }, scale: { $ref: "#/$defs/curve" }, opacity: { $ref: "#/$defs/curve" } } },
|
|
73
|
+
{ type: "object", required: ["lift", "by"], additionalProperties: false, properties: { lift: { $ref: "#/$defs/ids" }, by: { type: "number" }, stagger: { $ref: "#/$defs/time" }, to: { enum: ["up", "down"] }, opacity: { $ref: "#/$defs/curve" }, ...timing } },
|
|
74
|
+
node("focus", { $ref: "#/$defs/focus" }, { fade: { $ref: "#/$defs/time" } }),
|
|
75
|
+
node("highlight", { $ref: "#/$defs/ids" }, { fade: { $ref: "#/$defs/time" } }),
|
|
76
|
+
node("camera", { anyOf: [{ const: "fit" }, { type: "object", required: ["focus"], additionalProperties: false, properties: { focus: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }, { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4 }] }, zoom: { type: "number", exclusiveMinimum: 0 }, margin: { type: "number" } } }] })
|
|
77
|
+
] }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
export {
|
|
82
|
+
MOTION_SCHEMA
|
|
83
|
+
};
|
package/js/iso-objects/motion.js
CHANGED
|
@@ -519,7 +519,7 @@ function svgAt(scene, S) {
|
|
|
519
519
|
}
|
|
520
520
|
const unescape = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"').replace(/&/g, "&");
|
|
521
521
|
const keptOf = /* @__PURE__ */ new WeakMap();
|
|
522
|
-
function paint(svg, S, rendered) {
|
|
522
|
+
function paint(svg, S, rendered, o = {}) {
|
|
523
523
|
const was = keptOf.get(svg);
|
|
524
524
|
if (was) {
|
|
525
525
|
for (const [el, kids] of was.mixed) el.replaceChildren(...kids);
|
|
@@ -537,7 +537,7 @@ function paint(svg, S, rendered) {
|
|
|
537
537
|
keptOf.set(svg, kept);
|
|
538
538
|
const set = (el, k, v) => {
|
|
539
539
|
const m = kept.attrs.get(el) ?? /* @__PURE__ */ new Map();
|
|
540
|
-
if (!m.has(k)) m.set(k, el.getAttribute(k));
|
|
540
|
+
if (!m.has(k)) m.set(k, k === "style" ? el.getAttribute(k) || null : el.getAttribute(k));
|
|
541
541
|
kept.attrs.set(el, m);
|
|
542
542
|
if (v === null) el.removeAttribute(k);
|
|
543
543
|
else el.setAttribute(k, v);
|
|
@@ -606,12 +606,17 @@ function paint(svg, S, rendered) {
|
|
|
606
606
|
const path = w.path && el.querySelector("path.flow");
|
|
607
607
|
if (path && w.path) {
|
|
608
608
|
if (w.path.d !== void 0) set(path, "d", w.path.d);
|
|
609
|
-
if (w.path.style !== void 0)
|
|
609
|
+
if (w.path.style !== void 0) {
|
|
610
|
+
if (o.styles === "cssom") {
|
|
611
|
+
set(path, "style", null);
|
|
612
|
+
path.style.cssText = w.path.style;
|
|
613
|
+
} else set(path, "style", w.path.style);
|
|
614
|
+
}
|
|
610
615
|
if (!w.path.head) set(path, "marker-end", null);
|
|
611
616
|
}
|
|
612
617
|
}
|
|
613
618
|
const anim = layer("anim");
|
|
614
|
-
if (anim) for (const [n, at] of overlay(S, pathOf)) make(n, at, anim);
|
|
619
|
+
if (anim) for (const [n, at] of overlay(S, pathOf, rendered?.inks)) make(n, at, anim);
|
|
615
620
|
}
|
|
616
621
|
const ofScene = (s, p) => ({ ...p, frame: (t) => svgAt(s, p.at(t)) });
|
|
617
622
|
const assemble = (s, o = {}) => ofScene(s, planOf(motionModel(s), "assemble", o));
|
|
@@ -2,6 +2,7 @@ import { didYouMean } from "../iso-core/errors.js";
|
|
|
2
2
|
import { ANT_SPEED, antDash, antsOf } from "./ants.js";
|
|
3
3
|
import { silhouette } from "./labels.js";
|
|
4
4
|
import { motionModel, planOf } from "./motion.js";
|
|
5
|
+
import { focusView } from "./focus.js";
|
|
5
6
|
import { checkMotion, curveAt, easeOf, msOf, readMs, springAt } from "./motion-doc.js";
|
|
6
7
|
const r2 = (v) => Math.round(v * 100) / 100 || 0;
|
|
7
8
|
const r4 = (v) => Math.round(v * 1e4) / 1e4 || 0;
|
|
@@ -88,16 +89,29 @@ class Sum {
|
|
|
88
89
|
return out;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
function
|
|
92
|
-
const
|
|
93
|
-
|
|
92
|
+
function motionSource(scene) {
|
|
93
|
+
const ants = antsOf(scene.raw), looks = scene.rendered.looks, model = motionModel(scene), free = Object.keys(model.notes).filter((n) => model.notes[n] === void 0);
|
|
94
|
+
return {
|
|
95
|
+
model,
|
|
96
|
+
kinds: Object.fromEntries(scene.routes.map((r) => [r.id, r.kind])),
|
|
97
|
+
outlines: Object.fromEntries(scene.layout.items.map((p) => [p.id, silhouette(p.box).map((q) => [r2(q[0]), r2(q[1])])])),
|
|
98
|
+
...looks && Object.keys(looks).length ? { looks } : {},
|
|
99
|
+
...ants ? { ants } : {},
|
|
100
|
+
...free.length ? { free } : {}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function bindMotion(drawing, doc, opts = {}) {
|
|
104
|
+
const src = "model" in drawing ? drawing : motionSource(drawing);
|
|
105
|
+
const m = src.free ? { ...src.model, notes: { ...src.model.notes, ...Object.fromEntries(src.free.map((n) => [n, void 0])) } } : src.model;
|
|
106
|
+
const diags = checkMotion(doc), fps = doc.fps, fileAnts = src.ants;
|
|
107
|
+
const none = () => ({ ok: false, diags, duration: 0, beats: [], markers: {}, ambient: "on", loops: false, at: () => ({}), cues: () => void 0, beatAt: () => void 0, startOf: () => void 0 });
|
|
94
108
|
if (diags.length) return none();
|
|
95
109
|
const err = (path, message, hint) => {
|
|
96
110
|
diags.push({ severity: "error", path, message, ...hint ? { hint } : {} });
|
|
97
111
|
};
|
|
98
112
|
const ms = (t, otherwise) => t === void 0 ? otherwise : msOf(t, fps);
|
|
99
113
|
const pieces = new Map(m.pieces.map((p) => [p.id, p])), routes = new Set(m.routes.map((r) => r.id)), notes = new Set(Object.keys(m.notes));
|
|
100
|
-
const kindOf = new Map(
|
|
114
|
+
const kindOf = new Map(Object.entries(src.kinds));
|
|
101
115
|
const all = [...pieces.keys(), ...routes, ...notes];
|
|
102
116
|
const known = new Set(all);
|
|
103
117
|
const notesOn = /* @__PURE__ */ new Map();
|
|
@@ -111,7 +125,7 @@ function bindMotion(scene, doc, opts = {}) {
|
|
|
111
125
|
}
|
|
112
126
|
};
|
|
113
127
|
const needAll = (v, path, kind = "any") => v?.forEach((id, i) => need(id, `${path}/${i}`, kind));
|
|
114
|
-
const outline = new Map(
|
|
128
|
+
const outline = new Map(Object.entries(src.outlines));
|
|
115
129
|
const plans = /* @__PURE__ */ new Map();
|
|
116
130
|
function nodeEnd(n, path) {
|
|
117
131
|
const from = "from" in n ? ms(n.from, 0) : 0, dur = "duration" in n ? ms(n.duration, NaN) : NaN, given = Number.isFinite(dur);
|
|
@@ -250,7 +264,7 @@ function bindMotion(scene, doc, opts = {}) {
|
|
|
250
264
|
for (const id of Object.keys(s.levels ?? {})) if (id !== "*") need(id, `${path}/levels/${id}`);
|
|
251
265
|
for (const [id, name] of Object.entries(s.variants ?? {})) {
|
|
252
266
|
need(id, `${path}/variants/${id}`, "thing");
|
|
253
|
-
const have =
|
|
267
|
+
const have = src.looks?.[id] ?? [];
|
|
254
268
|
if (pieces.has(id) && name !== "" && !have.includes(name)) {
|
|
255
269
|
const d = didYouMean(name, have);
|
|
256
270
|
err(`${path}/variants/${id}`, have.length ? `${id} has no look "${name}" (it has ${have.join(", ")})` : `${id} declares no looks (variants: in the diagram)`, d ? `did you mean "${d}"?` : void 0);
|
|
@@ -414,13 +428,14 @@ function bindMotion(scene, doc, opts = {}) {
|
|
|
414
428
|
const one = ms(n.each, 1150), hold = ms(n.hold, n.loop ? 700 : 0), period = n.travel.length * one + hold;
|
|
415
429
|
const q = n.loop ? turned(a - from, period, c) : lt, i = Math.floor(q / one);
|
|
416
430
|
if (i >= n.travel.length) return;
|
|
417
|
-
const f = easeOf(n.easing, one, "ease-in-out")(
|
|
431
|
+
const part = (q - i * one) / one, f = easeOf(n.easing, one, "ease-in-out")(part), group = n.travel[i];
|
|
418
432
|
for (const x of Array.isArray(group) ? group : [group]) {
|
|
419
433
|
const [id, kind] = x.split(":");
|
|
420
|
-
if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4(f), ...kind ? { kind } : {} });
|
|
434
|
+
if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4((kind ?? kindOf.get(id)) === "blocked" ? stalled(part) : f), ...kind ? { kind } : {} });
|
|
421
435
|
}
|
|
422
436
|
}
|
|
423
437
|
}
|
|
438
|
+
const stalled = (f) => f < 0.7 ? f / 0.7 : 1 - (f - 0.7) / 0.3 * 0.25;
|
|
424
439
|
const turned = (x, period, c) => c.off ? 0 : (x % period + period) % period;
|
|
425
440
|
const ring = (id, amount, sum) => {
|
|
426
441
|
if (r4(amount) > 0 && outline.has(id)) sum.outlines.push({ id, points: outline.get(id), ...r4(amount) < 1 ? { opacity: r4(amount) } : {} });
|
|
@@ -502,6 +517,15 @@ function bindMotion(scene, doc, opts = {}) {
|
|
|
502
517
|
const cam = view?.map(r2);
|
|
503
518
|
return sum.state(cam && cam.some((v, i) => Math.abs(v - fit[i]) > 5e-3) ? cam : void 0);
|
|
504
519
|
}
|
|
520
|
+
const moving = (n) => {
|
|
521
|
+
if (!n || typeof n !== "object") return false;
|
|
522
|
+
if (Array.isArray(n)) return n.some(moving);
|
|
523
|
+
const o = n;
|
|
524
|
+
if (o.ants !== void 0 && o.ants !== false) return true;
|
|
525
|
+
if (o.loop === true && ("travel" in o || "pulse" in o)) return true;
|
|
526
|
+
return Object.values(o).some(moving);
|
|
527
|
+
};
|
|
528
|
+
const loops = fileAnts !== void 0 || moving(doc.series) || moving(doc.layers);
|
|
505
529
|
const beatAt = (t) => {
|
|
506
530
|
const k = beatIndex(Math.max(0, Math.min(duration, t)));
|
|
507
531
|
return k < 0 ? void 0 : beats[k];
|
|
@@ -512,6 +536,8 @@ function bindMotion(scene, doc, opts = {}) {
|
|
|
512
536
|
duration,
|
|
513
537
|
beats,
|
|
514
538
|
markers,
|
|
539
|
+
ambient: doc.ambient ?? "on",
|
|
540
|
+
loops,
|
|
515
541
|
at,
|
|
516
542
|
beatAt,
|
|
517
543
|
startOf: (n) => starts.get(n) ?? beats.find((b) => b.name === n)?.start,
|
|
@@ -528,7 +554,10 @@ function settleMs(c) {
|
|
|
528
554
|
return Math.ceil(Math.log(200) / (z * w0) * 1e3 * (z >= 1 ? 1.6 : 1));
|
|
529
555
|
}
|
|
530
556
|
function motionOfSteps(scene) {
|
|
531
|
-
const { steps, vis } = scene.steps;
|
|
557
|
+
const { steps, vis } = scene.steps, full = scene.rendered.viewBox;
|
|
558
|
+
let zoomed = false;
|
|
559
|
+
const m = motionModel(scene), ids = /* @__PURE__ */ new Set([...m.pieces.map((p) => p.id), ...m.routes.map((r) => r.id), ...Object.keys(m.notes)]), has = (id) => ids.has(id);
|
|
560
|
+
const free = Object.keys(m.notes).filter((n) => m.notes[n] === void 0);
|
|
532
561
|
const series = steps.map((st, i) => {
|
|
533
562
|
const show = [], hide = [];
|
|
534
563
|
for (const [id, v] of Object.entries(vis)) {
|
|
@@ -536,12 +565,22 @@ function motionOfSteps(scene) {
|
|
|
536
565
|
else if (i > 0 ? v[i] && !v[i - 1] : false) show.push(id);
|
|
537
566
|
}
|
|
538
567
|
const children = [];
|
|
539
|
-
|
|
568
|
+
const token = (t) => `${t.route}:${t.kind}`;
|
|
569
|
+
if (st.phases.length) children.push({ travel: st.phases.map((g) => g.length === 1 ? token(g[0]) : g.map(token)), each: 1150, hold: 700, loop: true });
|
|
540
570
|
const pulse = (scene.raw.steps ?? [])[i]?.pulse?.filter((id) => scene.layout.byId.has(id)) ?? [];
|
|
541
571
|
if (pulse.length) children.push({ pulse, loop: true });
|
|
572
|
+
if (st.focus) {
|
|
573
|
+
const [x, y, w, h] = focusView(full, st.focus).map(r2);
|
|
574
|
+
children.push({ camera: { focus: [x, y, w, h] }, duration: 900, easing: "ease-in-out" });
|
|
575
|
+
zoomed = true;
|
|
576
|
+
} else if (zoomed) {
|
|
577
|
+
children.push({ camera: "fit", duration: 900, easing: "ease-in-out" });
|
|
578
|
+
zoomed = false;
|
|
579
|
+
}
|
|
542
580
|
const s = { name: `step-${st.n}`, duration: st.duration, say: { title: st.heading, ...st.caption ? { text: st.caption } : {}, ...st.command ? { code: st.command } : {} } };
|
|
543
581
|
if (show.length) s.show = show;
|
|
544
582
|
if (hide.length) s.hide = hide;
|
|
583
|
+
s.focus = scene.raw.dim === "all" ? { lit: st.lit.filter(has), scope: "all", level: 0.14 } : { lit: st.lit.filter(has), scope: "links", level: 0.12, ...free.length ? { always: free } : {} };
|
|
545
584
|
if (children.length) s.children = children;
|
|
546
585
|
return { sequence: s };
|
|
547
586
|
});
|
|
@@ -549,5 +588,6 @@ function motionOfSteps(scene) {
|
|
|
549
588
|
}
|
|
550
589
|
export {
|
|
551
590
|
bindMotion,
|
|
552
|
-
motionOfSteps
|
|
591
|
+
motionOfSteps,
|
|
592
|
+
motionSource
|
|
553
593
|
};
|
|
@@ -4,6 +4,7 @@ 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
6
|
import { resolveSvg } from "../iso-objects/resolve.js";
|
|
7
|
+
import { monoOfDrawing, paintMono } from "../iso-objects/mono-paint.js";
|
|
7
8
|
import { bindMotion } from "../iso-objects/timeline.js";
|
|
8
9
|
import { antsOf } from "../iso-objects/ants.js";
|
|
9
10
|
import { drawLooks } from "../iso-objects/looks.js";
|
|
@@ -22,8 +23,17 @@ function compile(source, themeText, opts = {}) {
|
|
|
22
23
|
if (!c.ok && opts.strict === "throw") throw new CompileError(c.diags);
|
|
23
24
|
if (!c.ok && opts.strict) c.scenes = [];
|
|
24
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;
|
|
25
30
|
if (opts.resolveVars) for (const s of c.scenes) {
|
|
26
|
-
const
|
|
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 };
|
|
27
37
|
s.rendered.svg = resolveSvg(s.rendered.svg, o);
|
|
28
38
|
if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
|
|
29
39
|
s.rendered.inks = {
|
|
@@ -32,8 +42,22 @@ function compile(source, themeText, opts = {}) {
|
|
|
32
42
|
kinds: Object.fromEntries(Object.entries(c.theme.kinds).map(([k, v]) => [k, c.theme[o.mode][v.color] ?? v.color]))
|
|
33
43
|
};
|
|
34
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
|
+
})) };
|
|
35
49
|
return c;
|
|
36
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
|
+
}
|
|
37
61
|
function compileAll(source, themeText, opts) {
|
|
38
62
|
const parsed = parse(source);
|
|
39
63
|
const diags = [...parsed.diags];
|
package/js/iso-systems/render.js
CHANGED
|
@@ -3,7 +3,7 @@ import { svgAt } from "../iso-objects/motion.js";
|
|
|
3
3
|
import { bindMotion } from "../iso-objects/timeline.js";
|
|
4
4
|
import { compile } from "./compile.js";
|
|
5
5
|
function renderSvg(source, o) {
|
|
6
|
-
const c = compile(source, o.theme, { mode: o.mode ?? "light", resolveVars: true, strict: "throw" }), kinds = c.theme.kinds;
|
|
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
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
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
9
|
const ants = o.ants === void 0 ? antsOf(s.raw) : o.ants === true ? antsOf(s.raw) ?? {} : o.ants || void 0;
|
|
@@ -26,6 +26,7 @@
|
|
|
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": {
|
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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bindMotion, motionOfSteps, motionSource } from "../iso-objects/timeline.js";
|
|
2
2
|
import { esc } from "../iso-core/kernel.js";
|
|
3
3
|
import { themeCss } from "../iso-core/theme.js";
|
|
4
4
|
import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
|
|
@@ -10,18 +10,41 @@ function md(s) {
|
|
|
10
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);
|
|
11
11
|
}
|
|
12
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
|
+
}
|
|
13
30
|
function stepData(c) {
|
|
14
31
|
return JSON.stringify({
|
|
15
|
-
scenes: c.scenes.map((s) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
+
})
|
|
25
48
|
});
|
|
26
49
|
}
|
|
27
50
|
function legend(c, s) {
|
|
@@ -43,8 +66,8 @@ function legend(c, s) {
|
|
|
43
66
|
}
|
|
44
67
|
return items.join("");
|
|
45
68
|
}
|
|
46
|
-
function player(s) {
|
|
47
|
-
const st = s
|
|
69
|
+
function player(c, s) {
|
|
70
|
+
const st = stepsOf(c, s);
|
|
48
71
|
const tools = `<div class="tools">
|
|
49
72
|
<button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? "true" : "false"}" title="Show the floor grid">Grid</button>
|
|
50
73
|
<button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
|
|
@@ -67,8 +90,8 @@ function player(s) {
|
|
|
67
90
|
<div class="dots"></div>
|
|
68
91
|
</div>`;
|
|
69
92
|
}
|
|
70
|
-
function stepList(s) {
|
|
71
|
-
const st = s
|
|
93
|
+
function stepList(c, s) {
|
|
94
|
+
const st = stepsOf(c, s);
|
|
72
95
|
if (!st.length) return "";
|
|
73
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>`;
|
|
74
97
|
}
|
|
@@ -81,10 +104,10 @@ function renderPage(c, opts = {}) {
|
|
|
81
104
|
${paras(s.raw.caption)}
|
|
82
105
|
<div class="figure" tabindex="-1">
|
|
83
106
|
<div class="scroller">${s.grid.show ? s.rendered.svg.replace("<svg ", '<svg class="show-grid" ') : s.rendered.svg}</div>
|
|
84
|
-
${player(s)}
|
|
107
|
+
${player(c, s)}
|
|
85
108
|
<div class="legend">${legend(c, s)}</div>
|
|
86
109
|
</div>
|
|
87
|
-
${stepList(s)}
|
|
110
|
+
${stepList(c, s)}
|
|
88
111
|
${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ""}
|
|
89
112
|
</section>`).join("\n");
|
|
90
113
|
return `<!doctype html>
|