@johnoscott/isometric-engine 0.14.1 → 0.15.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 +199 -190
- package/iso-render.js +157 -148
- package/iso-systems.js +170 -159
- package/js/iso-objects/ants.js +36 -0
- package/js/iso-objects/index.js +47 -1
- package/js/iso-objects/looks.js +25 -0
- package/js/iso-objects/motion-builder.js +130 -0
- package/js/iso-objects/motion-doc.js +500 -0
- package/js/iso-objects/motion-entry.js +32 -0
- package/js/iso-objects/motion.js +635 -0
- package/js/iso-objects/resolve.js +238 -0
- package/js/iso-objects/scene.js +15 -13
- package/js/iso-objects/timeline.js +553 -0
- package/js/iso-systems/compile.js +59 -1
- package/js/iso-systems/index.js +4 -1
- package/js/iso-systems/render.js +20 -0
- package/js/iso-systems/schema.json +39 -0
- package/js/iso-viewer/page.js +2 -1
- package/js/iso-viewer/player.js +23 -34
- package/package.json +46 -1
- package/src/iso-objects/ants.ts +53 -0
- package/src/iso-objects/compile.ts +4 -1
- package/src/iso-objects/index.ts +14 -1
- package/src/iso-objects/looks.ts +21 -0
- package/src/iso-objects/motion-builder.ts +79 -0
- package/src/iso-objects/motion-doc.ts +361 -0
- package/src/iso-objects/motion-entry.ts +12 -0
- package/src/iso-objects/motion.ts +616 -0
- package/src/iso-objects/resolve.ts +196 -0
- package/src/iso-objects/scene.ts +29 -13
- package/src/iso-objects/timeline.ts +443 -0
- package/src/iso-objects/types.ts +20 -2
- package/src/iso-systems/compile.ts +58 -3
- package/src/iso-systems/index.ts +4 -1
- package/src/iso-systems/render.ts +41 -0
- package/src/iso-systems/schema.json +39 -0
- package/src/iso-viewer/page.ts +2 -1
- package/src/iso-viewer/player.ts +24 -41
- package/types/iso-objects/ants.d.ts +33 -0
- package/types/iso-objects/compile.d.ts +3 -0
- package/types/iso-objects/index.d.ts +14 -1
- package/types/iso-objects/looks.d.ts +4 -0
- package/types/iso-objects/motion-builder.d.ts +105 -0
- package/types/iso-objects/motion-doc.d.ts +787 -0
- package/types/iso-objects/motion-entry.d.ts +10 -0
- package/types/iso-objects/motion.d.ts +200 -0
- package/types/iso-objects/resolve.d.ts +20 -0
- package/types/iso-objects/scene.d.ts +11 -0
- package/types/iso-objects/timeline.d.ts +46 -0
- package/types/iso-objects/types.d.ts +32 -0
- package/types/iso-systems/compile.d.ts +20 -3
- package/types/iso-systems/index.d.ts +4 -1
- package/types/iso-systems/render.d.ts +21 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ANT_SPEED = 32 / 1.1;
|
|
2
|
+
const ANT_DASH = { solid: [9, 7], dashed: [7, 6], dotted: [3, 6] };
|
|
3
|
+
const ANT_STILL = ["blocked", "planned"];
|
|
4
|
+
const ANTS_CSS = `
|
|
5
|
+
.flow.iso-ants{stroke-dasharray:var(--ant-on) var(--ant-off);animation:iso-ants var(--ant-turn) linear infinite;animation-play-state:var(--ants,running)}
|
|
6
|
+
@keyframes iso-ants{to{stroke-dashoffset:var(--ant-to)}}
|
|
7
|
+
`;
|
|
8
|
+
function antDash(kind, o = {}) {
|
|
9
|
+
return (o.still ?? ANT_STILL).includes(kind) ? void 0 : o.dash ?? ANT_DASH[o.kinds?.[kind]?.dash ?? "solid"];
|
|
10
|
+
}
|
|
11
|
+
function antsOf(raw) {
|
|
12
|
+
const a = raw?.ants;
|
|
13
|
+
return !a ? void 0 : a === true ? {} : Array.isArray(a) ? { ids: a } : a;
|
|
14
|
+
}
|
|
15
|
+
function withAnts(scene, o = {}) {
|
|
16
|
+
const kindOf = new Map(scene.routes.map((r) => [r.id, r.kind])), wanted = o.ids && new Set(o.ids), speed = o.speed ?? ANT_SPEED;
|
|
17
|
+
const n = (v) => String(Number(v.toFixed(3)));
|
|
18
|
+
return scene.rendered.svg.replace(/(<g data-route="([^"]*)" data-part="line">(?:<g[^>]*>)*)<path ([^>]*?)\s*\/>/g, (m, before, id, attrs) => {
|
|
19
|
+
const route = id.replace(/"/g, '"').replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
20
|
+
const dash = wanted && !wanted.has(route) ? void 0 : antDash(kindOf.get(route) ?? "", o);
|
|
21
|
+
if (!dash || !/class="flow\b/.test(attrs)) return m;
|
|
22
|
+
const period = dash[0] + dash[1], turn = n(period / Math.max(1e-6, Math.abs(speed))), to = n(speed < 0 ? period : -period);
|
|
23
|
+
if (o.by === "css") return `${before}<path ${attrs.replace(/class="flow\b/, 'class="flow iso-ants')} style="--ant-on:${n(dash[0])};--ant-off:${n(dash[1])};--ant-to:${to};--ant-turn:${turn}s"/>`;
|
|
24
|
+
if (o.by === "none") return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, "")} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"/>`;
|
|
25
|
+
return `${before}<path ${attrs.replace(/ ?stroke-dasharray="[^"]*"/, "")} style="stroke-dasharray:${n(dash[0])} ${n(dash[1])}"><animate attributeName="stroke-dashoffset" from="0" to="${to}" dur="${turn}s" repeatCount="indefinite"/></path>`;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
ANTS_CSS,
|
|
30
|
+
ANT_DASH,
|
|
31
|
+
ANT_SPEED,
|
|
32
|
+
ANT_STILL,
|
|
33
|
+
antDash,
|
|
34
|
+
antsOf,
|
|
35
|
+
withAnts
|
|
36
|
+
};
|
package/js/iso-objects/index.js
CHANGED
|
@@ -4,6 +4,13 @@ import { WALL_T, place, gateBox, overlap2 } from "./place.js";
|
|
|
4
4
|
import { parseEnd, floorAt, ROUTE_BUDGET, routeAll, openList, simplify } from "./route.js";
|
|
5
5
|
import { silhouette, polyBounds, polyRectArea, rectArea, lineRectArea, Obstacles, labelRect, placeNodeLabel, calloutRect, placeCallout, inConvex, convexOverlap } from "./labels.js";
|
|
6
6
|
import { offscreen, assembly } from "./assemble.js";
|
|
7
|
+
import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS, MOTION_EASINGS, motionModel, motionOrder, planOf, assemble, disassemble, alongPath, svgAt, paint, introSvg } from "./motion.js";
|
|
8
|
+
import { drawLooks } from "./looks.js";
|
|
9
|
+
import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
|
|
10
|
+
import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
|
|
11
|
+
import { bindMotion, motionOfSteps } from "./timeline.js";
|
|
12
|
+
import { MOTION_SCHEMA, EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
|
|
13
|
+
import { resolveSvg, FONT_STACKS } from "./resolve.js";
|
|
7
14
|
import { durationFor, resolveSteps, midpoint } from "./steps.js";
|
|
8
15
|
import { focusView } from "./focus.js";
|
|
9
16
|
import { regionRole, renderScene, wallsOf, LABEL_BUDGET } from "./scene.js";
|
|
@@ -13,21 +20,42 @@ import { screenToGrid, localAt, boxSilhouette, floorOf, paddingOf, snapMove, ove
|
|
|
13
20
|
import { FLAT_DEFAULTS, FLAT_FONTS, metricsMeasure, boardErrors, placeBoard, layoutFlat, flatHit } from "./flat.js";
|
|
14
21
|
import { boardOf, BOARD_3D, BOARD_CSS, cardAsset, boardCatalog, boardDiagram } from "./board.js";
|
|
15
22
|
export {
|
|
23
|
+
ANTS_CSS,
|
|
24
|
+
ANT_DASH,
|
|
25
|
+
ANT_SPEED,
|
|
26
|
+
ANT_STILL,
|
|
27
|
+
ASSEMBLE_STYLES,
|
|
16
28
|
BOARD_3D,
|
|
17
29
|
BOARD_CSS,
|
|
30
|
+
DISASSEMBLE_STYLES,
|
|
31
|
+
EASING_NAMES,
|
|
32
|
+
EXTRAPOLATE,
|
|
18
33
|
FLAT_DEFAULTS,
|
|
19
34
|
FLAT_FONTS,
|
|
35
|
+
FONT_STACKS,
|
|
20
36
|
GRID_CSS,
|
|
21
37
|
LABEL_BUDGET,
|
|
22
38
|
MARKS_CSS,
|
|
39
|
+
MOTION_EASINGS,
|
|
40
|
+
MOTION_ORDERS,
|
|
41
|
+
MOTION_SCHEMA,
|
|
42
|
+
MotionBuilder,
|
|
43
|
+
NodesBuilder,
|
|
23
44
|
Obstacles,
|
|
24
45
|
PAGE_CSS,
|
|
25
46
|
PLAYER_CSS,
|
|
26
47
|
PLAYER_UI_CSS,
|
|
27
48
|
ROUTE_BUDGET,
|
|
49
|
+
SeriesBuilder,
|
|
28
50
|
WALL_T,
|
|
51
|
+
alongPath,
|
|
52
|
+
antDash,
|
|
53
|
+
antsOf,
|
|
54
|
+
assemble,
|
|
29
55
|
assembly,
|
|
30
56
|
baseCss,
|
|
57
|
+
bezier,
|
|
58
|
+
bindMotion,
|
|
31
59
|
boardCatalog,
|
|
32
60
|
boardDiagram,
|
|
33
61
|
boardErrors,
|
|
@@ -36,14 +64,19 @@ export {
|
|
|
36
64
|
boxSilhouette,
|
|
37
65
|
calloutRect,
|
|
38
66
|
cardAsset,
|
|
67
|
+
checkMotion,
|
|
39
68
|
cloudPath,
|
|
40
69
|
compileRaw,
|
|
41
70
|
convexOverlap,
|
|
71
|
+
curveAt,
|
|
42
72
|
defaultLabel,
|
|
73
|
+
disassemble,
|
|
43
74
|
drawCloud,
|
|
44
75
|
drawDecos,
|
|
76
|
+
drawLooks,
|
|
45
77
|
drawingCss,
|
|
46
78
|
durationFor,
|
|
79
|
+
easeOf,
|
|
47
80
|
facePainter,
|
|
48
81
|
flatHit,
|
|
49
82
|
floorAt,
|
|
@@ -52,6 +85,7 @@ export {
|
|
|
52
85
|
gateBox,
|
|
53
86
|
iconPainter,
|
|
54
87
|
inConvex,
|
|
88
|
+
introSvg,
|
|
55
89
|
kindsCss,
|
|
56
90
|
labelRect,
|
|
57
91
|
layoutFlat,
|
|
@@ -60,6 +94,11 @@ export {
|
|
|
60
94
|
markCss,
|
|
61
95
|
metricsMeasure,
|
|
62
96
|
midpoint,
|
|
97
|
+
motion,
|
|
98
|
+
motionModel,
|
|
99
|
+
motionOfSteps,
|
|
100
|
+
motionOrder,
|
|
101
|
+
msOf,
|
|
63
102
|
noSource,
|
|
64
103
|
nodeKind,
|
|
65
104
|
nodeKindOr,
|
|
@@ -68,26 +107,33 @@ export {
|
|
|
68
107
|
overlap2,
|
|
69
108
|
overlaps,
|
|
70
109
|
paddingOf,
|
|
110
|
+
paint,
|
|
71
111
|
parseEnd,
|
|
72
112
|
place,
|
|
73
113
|
placeBoard,
|
|
74
114
|
placeCallout,
|
|
75
115
|
placeNodeLabel,
|
|
76
116
|
placeholderIcon,
|
|
117
|
+
planOf,
|
|
77
118
|
plate,
|
|
78
119
|
polyBounds,
|
|
79
120
|
polyRectArea,
|
|
121
|
+
readMs,
|
|
80
122
|
rectArea,
|
|
81
123
|
regionKind,
|
|
82
124
|
regionRole,
|
|
83
125
|
registerMarks,
|
|
84
126
|
renderScene,
|
|
85
127
|
resolveSteps,
|
|
128
|
+
resolveSvg,
|
|
86
129
|
routeAll,
|
|
87
130
|
screenToGrid,
|
|
88
131
|
silhouette,
|
|
89
132
|
simplify,
|
|
90
133
|
snapMove,
|
|
134
|
+
springAt,
|
|
135
|
+
svgAt,
|
|
91
136
|
wallHeight,
|
|
92
|
-
wallsOf
|
|
137
|
+
wallsOf,
|
|
138
|
+
withAnts
|
|
93
139
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { renderScene } from "./scene.js";
|
|
2
|
+
function drawLooks(s, theme) {
|
|
3
|
+
const looks = {};
|
|
4
|
+
for (const p of s.layout.items) {
|
|
5
|
+
const v = (p.region ?? p.node)?.variants;
|
|
6
|
+
if (v) looks[p.id] = Object.keys(v);
|
|
7
|
+
}
|
|
8
|
+
if (!Object.keys(looks).length) return;
|
|
9
|
+
s.rendered.looks = looks;
|
|
10
|
+
s.rendered.variants = Object.fromEntries([...new Set(Object.values(looks).flat())].map((name) => [name, renderScene({
|
|
11
|
+
scene: s.raw,
|
|
12
|
+
routes: s.routes,
|
|
13
|
+
steps: s.steps,
|
|
14
|
+
theme,
|
|
15
|
+
id: s.raw.id,
|
|
16
|
+
gridStep: s.grid.step ?? s.grid.snap ?? 1,
|
|
17
|
+
layout: { ...s.layout, items: s.layout.items.map((p) => {
|
|
18
|
+
const v = (p.region ?? p.node)?.variants?.[name];
|
|
19
|
+
return !v ? p : p.region ? { ...p, region: { ...p.region, ...v, deco: void 0 } } : { ...p, node: { ...p.node, ...v } };
|
|
20
|
+
}) }
|
|
21
|
+
}).svg]));
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
drawLooks
|
|
25
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
const list = (v) => typeof v === "string" ? [v] : [...v];
|
|
2
|
+
const plain = (v) => JSON.parse(JSON.stringify(v));
|
|
3
|
+
const timing = (o = {}) => ({ ...o.from === void 0 ? {} : { from: o.from }, ...o.over === void 0 ? {} : { duration: o.over }, ...o.easing === void 0 ? {} : { easing: o.easing } });
|
|
4
|
+
class NodesBuilder {
|
|
5
|
+
/** @internal */
|
|
6
|
+
nodes = [];
|
|
7
|
+
add(n) {
|
|
8
|
+
this.nodes.push(plain(n));
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
assemble(o = {}, t = {}) {
|
|
12
|
+
return this.add({ assemble: o, ...timing(t) });
|
|
13
|
+
}
|
|
14
|
+
disassemble(o = {}, t = {}) {
|
|
15
|
+
return this.add({ disassemble: o, ...timing(t) });
|
|
16
|
+
}
|
|
17
|
+
/** tokens along connectors, one after another; a nested list at once; "id:kind" */
|
|
18
|
+
travel(routes, o = {}) {
|
|
19
|
+
const { each, hold, loop } = o;
|
|
20
|
+
return this.add({ travel: routes, ...timing(o), each, hold, loop });
|
|
21
|
+
}
|
|
22
|
+
pulse(ids, o = {}) {
|
|
23
|
+
return this.add({ pulse: list(ids), ...timing(o), loop: o.loop });
|
|
24
|
+
}
|
|
25
|
+
ants(ids = true, o = {}) {
|
|
26
|
+
return this.add({ ants: ids === true ? true : list(ids), ...timing(o), speed: o.speed, dash: o.dash });
|
|
27
|
+
}
|
|
28
|
+
draw(routes, o = {}) {
|
|
29
|
+
return this.add({ draw: list(routes), ...timing(o), by: o.by, stagger: o.stagger });
|
|
30
|
+
}
|
|
31
|
+
type(ids, o = {}) {
|
|
32
|
+
return this.add({ type: list(ids), ...timing(o) });
|
|
33
|
+
}
|
|
34
|
+
move(id, o) {
|
|
35
|
+
return this.add({ move: id, ...o });
|
|
36
|
+
}
|
|
37
|
+
lift(ids, by, o = {}) {
|
|
38
|
+
return this.add({ lift: list(ids), by, ...timing(o), stagger: o.stagger, to: o.to, opacity: o.opacity });
|
|
39
|
+
}
|
|
40
|
+
focus(lit, o = {}) {
|
|
41
|
+
const { scope, level, always } = o;
|
|
42
|
+
return this.add({ focus: { lit: list(lit), scope, level, always }, ...timing(o), fade: o.fade });
|
|
43
|
+
}
|
|
44
|
+
highlight(ids, o = {}) {
|
|
45
|
+
return this.add({ highlight: list(ids), ...timing(o), fade: o.fade });
|
|
46
|
+
}
|
|
47
|
+
/** the view: on a thing, some things or a box; or the whole drawing again */
|
|
48
|
+
get camera() {
|
|
49
|
+
return {
|
|
50
|
+
focus: (on, o = {}) => this.add({ camera: { focus: on, zoom: o.zoom, margin: o.margin }, ...timing(o) }),
|
|
51
|
+
fit: (o = {}) => this.add({ camera: "fit", ...timing(o) })
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** a sequence in this one: a clock of its own, from `from` */
|
|
55
|
+
sequence(name, o = {}, fill) {
|
|
56
|
+
return this.add({ sequence: sequenceOf(name, o, fill) });
|
|
57
|
+
}
|
|
58
|
+
/** sequences one after another */
|
|
59
|
+
series(fill) {
|
|
60
|
+
const s = new SeriesBuilder();
|
|
61
|
+
fill(s);
|
|
62
|
+
return this.add({ series: s.items });
|
|
63
|
+
}
|
|
64
|
+
/** nodes over one another */
|
|
65
|
+
layers(fill) {
|
|
66
|
+
const b = new NodesBuilder();
|
|
67
|
+
fill(b);
|
|
68
|
+
return this.add({ layers: b.nodes });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function sequenceOf(name, o, fill) {
|
|
72
|
+
const { read, duration, ...rest } = o, b = new NodesBuilder();
|
|
73
|
+
fill?.(b);
|
|
74
|
+
return plain({ ...name === void 0 ? {} : { name }, ...rest, ...read !== void 0 ? { duration: { read } } : duration !== void 0 ? { duration } : {}, ...b.nodes.length ? { children: b.nodes } : {} });
|
|
75
|
+
}
|
|
76
|
+
class SeriesBuilder {
|
|
77
|
+
/** @internal */
|
|
78
|
+
items = [];
|
|
79
|
+
sequence(name, o = {}, fill) {
|
|
80
|
+
this.items.push({ sequence: sequenceOf(name, o, fill) });
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
transition(t) {
|
|
84
|
+
this.items.push({ transition: plain(t) });
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class MotionBuilder extends SeriesBuilder {
|
|
89
|
+
over = [];
|
|
90
|
+
marks = {};
|
|
91
|
+
head;
|
|
92
|
+
constructor(head = {}) {
|
|
93
|
+
super();
|
|
94
|
+
this.head = head;
|
|
95
|
+
}
|
|
96
|
+
/** a beat: a sequence with commentary */
|
|
97
|
+
beat(name, say, o = {}, fill) {
|
|
98
|
+
return this.sequence(name, { ...o, say }, fill);
|
|
99
|
+
}
|
|
100
|
+
/** the whole drawing arrives (a sequence as long as that takes) */
|
|
101
|
+
assemble(o = {}, t = {}) {
|
|
102
|
+
return this.sequence(void 0, {}, (b) => b.assemble(o, t));
|
|
103
|
+
}
|
|
104
|
+
/** the whole drawing leaves */
|
|
105
|
+
disassemble(o = {}, t = {}) {
|
|
106
|
+
return this.sequence(void 0, {}, (b) => b.disassemble(o, t));
|
|
107
|
+
}
|
|
108
|
+
/** a name for a moment: ms, or "beat+1200" */
|
|
109
|
+
mark(name, at) {
|
|
110
|
+
this.marks[name] = at;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
/** nodes over the whole document, on its own clock */
|
|
114
|
+
layers(fill) {
|
|
115
|
+
const b = new NodesBuilder();
|
|
116
|
+
fill(b);
|
|
117
|
+
this.over.push(...b.nodes);
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
toJSON() {
|
|
121
|
+
return plain({ isomotion: 1, ...this.head, ...this.items.length ? { series: this.items } : {}, ...this.over.length ? { layers: this.over } : {}, ...Object.keys(this.marks).length ? { markers: this.marks } : {} });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const motion = (head = {}) => new MotionBuilder(head);
|
|
125
|
+
export {
|
|
126
|
+
MotionBuilder,
|
|
127
|
+
NodesBuilder,
|
|
128
|
+
SeriesBuilder,
|
|
129
|
+
motion
|
|
130
|
+
};
|