@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
package/js/iso-core/index.js
CHANGED
|
@@ -7,12 +7,14 @@ import { parse } from "./parse.js";
|
|
|
7
7
|
import { allowed, parseSvg, buildSvg } from "./svg-dom.js";
|
|
8
8
|
import { VEl, vdoc, serialize } from "./vdom.js";
|
|
9
9
|
import { createHash, sha256Hex } from "./shims/crypto.js";
|
|
10
|
+
import { MONO, greyOf, contrast, monoOf } from "./mono.js";
|
|
10
11
|
export {
|
|
11
12
|
Bounds,
|
|
12
13
|
C,
|
|
13
14
|
DiagError,
|
|
14
15
|
FONTS,
|
|
15
16
|
Kernel,
|
|
17
|
+
MONO,
|
|
16
18
|
S,
|
|
17
19
|
VEl,
|
|
18
20
|
allowed,
|
|
@@ -21,6 +23,7 @@ export {
|
|
|
21
23
|
buildSvg,
|
|
22
24
|
center,
|
|
23
25
|
colorRef,
|
|
26
|
+
contrast,
|
|
24
27
|
createHash,
|
|
25
28
|
depthSort,
|
|
26
29
|
didYouMean,
|
|
@@ -32,10 +35,12 @@ export {
|
|
|
32
35
|
fileLines,
|
|
33
36
|
formatDiag,
|
|
34
37
|
formatDiags,
|
|
38
|
+
greyOf,
|
|
35
39
|
iso,
|
|
36
40
|
keyGlyph,
|
|
37
41
|
loadTheme,
|
|
38
42
|
matStr,
|
|
43
|
+
monoOf,
|
|
39
44
|
n1,
|
|
40
45
|
parse,
|
|
41
46
|
parseSvg,
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
const deepFreeze = (v) => {
|
|
2
|
+
if (v && typeof v === "object") {
|
|
3
|
+
Object.freeze(v);
|
|
4
|
+
for (const child of Object.values(v)) deepFreeze(child);
|
|
5
|
+
}
|
|
6
|
+
return v;
|
|
7
|
+
};
|
|
8
|
+
const STEP_THRESHOLDS = [86, 81, 76];
|
|
9
|
+
const KIND_ORDER = ["send", "reply", "token", "blocked", "user", "event", "control", "planned"];
|
|
10
|
+
const MONO = deepFreeze({
|
|
11
|
+
light: {
|
|
12
|
+
paper: "#ffffff",
|
|
13
|
+
ink: "#141414",
|
|
14
|
+
steps: [
|
|
15
|
+
{ top: "#f4f4f4", left: "#dcdcdc", right: "#c4c4c4", edge: "#3a3a3a" },
|
|
16
|
+
{ top: "#dedede", left: "#bfbfbf", right: "#a2a2a2", edge: "#2e2e2e" },
|
|
17
|
+
{ top: "#bcbcbc", left: "#9a9a9a", right: "#7e7e7e", edge: "#222222" },
|
|
18
|
+
{ top: "#8f8f8f", left: "#707070", right: "#565656", edge: "#141414" }
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
dark: {
|
|
22
|
+
paper: "#161616",
|
|
23
|
+
ink: "#f2f2f2",
|
|
24
|
+
steps: [
|
|
25
|
+
{ top: "#2a2a2a", left: "#222222", right: "#1b1b1b", edge: "#b8b8b8" },
|
|
26
|
+
{ top: "#454545", left: "#383838", right: "#2c2c2c", edge: "#c8c8c8" },
|
|
27
|
+
{ top: "#6a6a6a", left: "#565656", right: "#444444", edge: "#dadada" },
|
|
28
|
+
{ top: "#9c9c9c", left: "#808080", right: "#686868", edge: "#141414" }
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
patterns: ["none", "hatch", "hatch-wide", "dots"],
|
|
32
|
+
rhythms: [
|
|
33
|
+
{ dash: [], width: 2.6 },
|
|
34
|
+
{ dash: [9, 4], width: 2.4 },
|
|
35
|
+
{ dash: [7, 6], width: 2.4 },
|
|
36
|
+
{ dash: [3, 6], width: 2.4 },
|
|
37
|
+
{ dash: [1.5, 3.5], width: 2.6 },
|
|
38
|
+
{ dash: [10, 3, 2, 3], width: 2.4 },
|
|
39
|
+
{ dash: [], width: 1.4 },
|
|
40
|
+
{ dash: [7, 6], width: 1.4 },
|
|
41
|
+
{ dash: [3, 3], width: 1.6 },
|
|
42
|
+
{ dash: [14, 4], width: 1.8 }
|
|
43
|
+
],
|
|
44
|
+
kindOrder: KIND_ORDER,
|
|
45
|
+
thresholds: STEP_THRESHOLDS,
|
|
46
|
+
darkWidthAdd: 0.4
|
|
47
|
+
});
|
|
48
|
+
const HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
49
|
+
const HSL_RE = /^hsl\(\s*([+-]?(?:\d+\.?\d*|\.\d+))\s+([+-]?(?:\d+\.?\d*|\.\d+))%\s+([+-]?(?:\d+\.?\d*|\.\d+))%\s*\)$/i;
|
|
50
|
+
function parseColor(color) {
|
|
51
|
+
if (typeof color !== "string") throw new Error(`mono: invalid colour "${String(color)}"`);
|
|
52
|
+
const s = color.trim();
|
|
53
|
+
const hex = HEX_RE.exec(s);
|
|
54
|
+
if (hex) {
|
|
55
|
+
const h = hex[1];
|
|
56
|
+
if (h.length === 3) {
|
|
57
|
+
return [
|
|
58
|
+
parseInt(h[0] + h[0], 16) / 255,
|
|
59
|
+
parseInt(h[1] + h[1], 16) / 255,
|
|
60
|
+
parseInt(h[2] + h[2], 16) / 255
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
return [
|
|
64
|
+
parseInt(h.slice(0, 2), 16) / 255,
|
|
65
|
+
parseInt(h.slice(2, 4), 16) / 255,
|
|
66
|
+
parseInt(h.slice(4, 6), 16) / 255
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
const hsl = HSL_RE.exec(s);
|
|
70
|
+
if (hsl) {
|
|
71
|
+
const h = Number(hsl[1]);
|
|
72
|
+
const sat = Number(hsl[2]);
|
|
73
|
+
const lig = Number(hsl[3]);
|
|
74
|
+
if (!Number.isFinite(h) || sat < 0 || sat > 100 || lig < 0 || lig > 100) {
|
|
75
|
+
throw new Error(`mono: invalid colour "${color}"`);
|
|
76
|
+
}
|
|
77
|
+
const hue = (h % 360 + 360) % 360;
|
|
78
|
+
const S = sat / 100;
|
|
79
|
+
const L = lig / 100;
|
|
80
|
+
const a = S * Math.min(L, 1 - L);
|
|
81
|
+
const f = (n) => {
|
|
82
|
+
const k = (n + hue / 30) % 12;
|
|
83
|
+
return L - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
|
|
84
|
+
};
|
|
85
|
+
return [f(0), f(8), f(4)];
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`mono: invalid colour "${color}"`);
|
|
88
|
+
}
|
|
89
|
+
function luminance(color) {
|
|
90
|
+
const [r, g, b] = parseColor(color);
|
|
91
|
+
const lin = (c) => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
92
|
+
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);
|
|
93
|
+
}
|
|
94
|
+
function greyOf(color) {
|
|
95
|
+
const y = luminance(color);
|
|
96
|
+
return y > 216 / 24389 ? 116 * Math.cbrt(y) - 16 : 24389 / 27 * y;
|
|
97
|
+
}
|
|
98
|
+
function contrast(a, b) {
|
|
99
|
+
const la = luminance(a);
|
|
100
|
+
const lb = luminance(b);
|
|
101
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
|
|
102
|
+
}
|
|
103
|
+
const VALID_PATTERNS = new Set(MONO.patterns);
|
|
104
|
+
const FIXED_KIND_INDEX = new Map(MONO.kindOrder.map((k, i) => [k, i]));
|
|
105
|
+
const cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
106
|
+
const uniqueSorted = (names) => [...new Set(names)].sort(cmp);
|
|
107
|
+
const round2 = (n) => Math.round(n * 100) / 100;
|
|
108
|
+
function stepFromLightness(lStar) {
|
|
109
|
+
if (lStar >= STEP_THRESHOLDS[0]) return 0;
|
|
110
|
+
if (lStar >= STEP_THRESHOLDS[1]) return 1;
|
|
111
|
+
if (lStar >= STEP_THRESHOLDS[2]) return 2;
|
|
112
|
+
return 3;
|
|
113
|
+
}
|
|
114
|
+
function validateOwn(own) {
|
|
115
|
+
if (own.roles) {
|
|
116
|
+
for (const [name, ov] of Object.entries(own.roles)) {
|
|
117
|
+
if (ov.step !== void 0) {
|
|
118
|
+
if (typeof ov.step !== "number" || !Number.isInteger(ov.step) || ov.step < 0 || ov.step > 3) {
|
|
119
|
+
throw new Error(`mono: invalid step "${String(ov.step)}" for role "${name}"`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (ov.pattern !== void 0) {
|
|
123
|
+
if (typeof ov.pattern !== "string" || !VALID_PATTERNS.has(ov.pattern)) {
|
|
124
|
+
throw new Error(`mono: invalid pattern "${String(ov.pattern)}" for role "${name}"`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (own.kinds) {
|
|
130
|
+
for (const [name, ov] of Object.entries(own.kinds)) {
|
|
131
|
+
if (ov.dash !== void 0) {
|
|
132
|
+
if (!Array.isArray(ov.dash) || !ov.dash.every((n) => typeof n === "number" && Number.isFinite(n) && n >= 0)) {
|
|
133
|
+
throw new Error(`mono: invalid dash "${String(ov.dash)}" for kind "${name}"`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (ov.width !== void 0) {
|
|
137
|
+
if (typeof ov.width !== "number" || !Number.isFinite(ov.width) || ov.width <= 0) {
|
|
138
|
+
throw new Error(`mono: invalid width "${String(ov.width)}" for kind "${name}"`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function monoOf(theme, mode, use, own) {
|
|
145
|
+
if (mode !== "light" && mode !== "dark") throw new Error(`mono: invalid mode "${String(mode)}"`);
|
|
146
|
+
if (own) validateOwn(own);
|
|
147
|
+
const palette = MONO[mode];
|
|
148
|
+
const warnings = [];
|
|
149
|
+
const lTop = theme.light["l-top"];
|
|
150
|
+
const roleNames = uniqueSorted(use?.roles ?? Object.keys(theme.roles));
|
|
151
|
+
const stepByRole = /* @__PURE__ */ new Map();
|
|
152
|
+
const byStep = [[], [], [], []];
|
|
153
|
+
for (const name of roleNames) {
|
|
154
|
+
const ovStep = own?.roles?.[name]?.step;
|
|
155
|
+
let step;
|
|
156
|
+
if (ovStep !== void 0) {
|
|
157
|
+
step = ovStep;
|
|
158
|
+
} else {
|
|
159
|
+
const def = theme.roles[name];
|
|
160
|
+
if (!def) throw new Error(`mono: unknown role "${name}"`);
|
|
161
|
+
if (typeof lTop !== "string") throw new Error('mono: theme.light is missing "l-top"');
|
|
162
|
+
step = stepFromLightness(greyOf(`hsl(${def.h} ${def.s}% ${lTop})`));
|
|
163
|
+
}
|
|
164
|
+
stepByRole.set(name, step);
|
|
165
|
+
byStep[step].push(name);
|
|
166
|
+
}
|
|
167
|
+
const patternByRole = /* @__PURE__ */ new Map();
|
|
168
|
+
for (let step = 0; step < byStep.length; step++) {
|
|
169
|
+
const group = byStep[step];
|
|
170
|
+
for (let i = 0; i < group.length; i++) {
|
|
171
|
+
const name = group[i];
|
|
172
|
+
const ovPattern = own?.roles?.[name]?.pattern;
|
|
173
|
+
if (ovPattern !== void 0) {
|
|
174
|
+
patternByRole.set(name, ovPattern);
|
|
175
|
+
} else {
|
|
176
|
+
const idx = i % MONO.patterns.length;
|
|
177
|
+
const pattern = MONO.patterns[idx];
|
|
178
|
+
patternByRole.set(name, pattern);
|
|
179
|
+
if (i >= MONO.patterns.length) {
|
|
180
|
+
const alike = group.slice(0, i).find((r) => patternByRole.get(r) === pattern);
|
|
181
|
+
if (alike !== void 0) {
|
|
182
|
+
warnings.push(`role "${name}" wraps on step ${step} to pattern "${pattern}", matching "${alike}"`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const roles = {};
|
|
189
|
+
for (const name of roleNames) {
|
|
190
|
+
const step = stepByRole.get(name);
|
|
191
|
+
const pattern = patternByRole.get(name);
|
|
192
|
+
const face = palette.steps[step];
|
|
193
|
+
roles[name] = {
|
|
194
|
+
step,
|
|
195
|
+
pattern,
|
|
196
|
+
top: face.top,
|
|
197
|
+
left: face.left,
|
|
198
|
+
right: face.right,
|
|
199
|
+
edge: face.edge
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const kindNames = uniqueSorted(use?.kinds ?? Object.keys(theme.kinds));
|
|
203
|
+
const widthBump = mode === "dark" ? MONO.darkWidthAdd : 0;
|
|
204
|
+
const kinds = {};
|
|
205
|
+
let extraIndex = 0;
|
|
206
|
+
for (const name of kindNames) {
|
|
207
|
+
const ov = own?.kinds?.[name];
|
|
208
|
+
const fixedIdx = FIXED_KIND_INDEX.get(name);
|
|
209
|
+
let rhythmIdx;
|
|
210
|
+
if (fixedIdx !== void 0) {
|
|
211
|
+
rhythmIdx = fixedIdx;
|
|
212
|
+
} else {
|
|
213
|
+
rhythmIdx = MONO.kindOrder.length + extraIndex;
|
|
214
|
+
extraIndex++;
|
|
215
|
+
if (rhythmIdx >= MONO.rhythms.length) {
|
|
216
|
+
const wrapped = rhythmIdx % MONO.rhythms.length;
|
|
217
|
+
if (!ov || ov.dash === void 0 || ov.width === void 0) {
|
|
218
|
+
warnings.push(`kind "${name}" exceeds the ${MONO.rhythms.length} line rhythms; reusing rhythm ${wrapped}`);
|
|
219
|
+
}
|
|
220
|
+
rhythmIdx = wrapped;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const base = MONO.rhythms[rhythmIdx];
|
|
224
|
+
const dash = ov?.dash !== void 0 ? [...ov.dash] : [...base.dash];
|
|
225
|
+
const width = ov?.width !== void 0 ? ov.width : round2(base.width + widthBump);
|
|
226
|
+
kinds[name] = { dash, width };
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
mode,
|
|
230
|
+
paper: palette.paper,
|
|
231
|
+
ink: palette.ink,
|
|
232
|
+
roles,
|
|
233
|
+
kinds,
|
|
234
|
+
warnings
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
export {
|
|
238
|
+
MONO,
|
|
239
|
+
contrast,
|
|
240
|
+
greyOf,
|
|
241
|
+
monoOf
|
|
242
|
+
};
|
|
@@ -241,6 +241,10 @@ function canvasView(host, doc, opts) {
|
|
|
241
241
|
empty.hidden = true;
|
|
242
242
|
layer?.drawn?.();
|
|
243
243
|
if (pendingReveal && reveal(pendingReveal)) pendingReveal = void 0;
|
|
244
|
+
if (pendingNudge) {
|
|
245
|
+
if (!drag) nudge(pendingNudge);
|
|
246
|
+
pendingNudge = void 0;
|
|
247
|
+
}
|
|
244
248
|
paintNav();
|
|
245
249
|
paintOverlay();
|
|
246
250
|
if (from && from.svg !== s) {
|
|
@@ -1200,7 +1204,10 @@ function canvasView(host, doc, opts) {
|
|
|
1200
1204
|
await draw(g.origCd);
|
|
1201
1205
|
return;
|
|
1202
1206
|
}
|
|
1203
|
-
if (g.invalid)
|
|
1207
|
+
if (g.invalid) {
|
|
1208
|
+
opts.note(`${f.name} added; that spot is taken, so the layout placed it`);
|
|
1209
|
+
pendingNudge = f.path;
|
|
1210
|
+
}
|
|
1204
1211
|
doc.select([f.path], "canvas");
|
|
1205
1212
|
rename(f.path, { joins: doc.undoId, at: lastPin });
|
|
1206
1213
|
}
|
|
@@ -1836,6 +1843,21 @@ function canvasView(host, doc, opts) {
|
|
|
1836
1843
|
return true;
|
|
1837
1844
|
}
|
|
1838
1845
|
let pendingReveal;
|
|
1846
|
+
function nudge(p) {
|
|
1847
|
+
const b = boxFor(p), v = V.view;
|
|
1848
|
+
if (!v || !b) return;
|
|
1849
|
+
if (b.w > v.w || b.h > v.h) {
|
|
1850
|
+
reveal([p]);
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
const m = 12 / scale(), by = (a, n, va, vn) => a < va ? a - va - m : a + n > va + vn ? a + n - va - vn + m : 0;
|
|
1854
|
+
const dx = by(b.x, b.w, v.x, v.w), dy = by(b.y, b.h, v.y, v.h);
|
|
1855
|
+
if (dx || dy) {
|
|
1856
|
+
V.view = { ...v, x: v.x + dx, y: v.y + dy };
|
|
1857
|
+
applyView();
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
let pendingNudge;
|
|
1839
1861
|
ifEvents();
|
|
1840
1862
|
doc.onSelect((c) => {
|
|
1841
1863
|
paintOverlay();
|
package/js/iso-objects/ants.js
CHANGED
|
@@ -6,7 +6,7 @@ const ANTS_CSS = `
|
|
|
6
6
|
@keyframes iso-ants{to{stroke-dashoffset:var(--ant-to)}}
|
|
7
7
|
`;
|
|
8
8
|
function antDash(kind, o = {}) {
|
|
9
|
-
return (o.still ?? ANT_STILL).includes(kind) ? void 0 : o.dash ?? ANT_DASH[o.kinds?.[kind]?.dash ?? "solid"];
|
|
9
|
+
return (o.still ?? ANT_STILL).includes(kind) ? void 0 : o.dash ?? o.kinds?.[kind]?.ants ?? ANT_DASH[o.kinds?.[kind]?.dash ?? "solid"];
|
|
10
10
|
}
|
|
11
11
|
function antsOf(raw) {
|
|
12
12
|
const a = raw?.ants;
|
package/js/iso-objects/index.js
CHANGED
|
@@ -8,9 +8,11 @@ import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS, MOTION_EASINGS, mot
|
|
|
8
8
|
import { drawLooks } from "./looks.js";
|
|
9
9
|
import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
|
|
10
10
|
import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
|
|
11
|
-
import { bindMotion, motionOfSteps } from "./timeline.js";
|
|
12
|
-
import { MOTION_SCHEMA
|
|
11
|
+
import { bindMotion, motionOfSteps, motionSource } from "./timeline.js";
|
|
12
|
+
import { MOTION_SCHEMA } from "./motion-schema.js";
|
|
13
|
+
import { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
|
|
13
14
|
import { resolveSvg, FONT_STACKS } from "./resolve.js";
|
|
15
|
+
import { monoOfDrawing, monoTheme, monoCss, paintMono, usedIn } from "./mono-paint.js";
|
|
14
16
|
import { durationFor, resolveSteps, midpoint } from "./steps.js";
|
|
15
17
|
import { focusView } from "./focus.js";
|
|
16
18
|
import { regionRole, renderScene, wallsOf, LABEL_BUDGET } from "./scene.js";
|
|
@@ -94,10 +96,14 @@ export {
|
|
|
94
96
|
markCss,
|
|
95
97
|
metricsMeasure,
|
|
96
98
|
midpoint,
|
|
99
|
+
monoCss,
|
|
100
|
+
monoOfDrawing,
|
|
101
|
+
monoTheme,
|
|
97
102
|
motion,
|
|
98
103
|
motionModel,
|
|
99
104
|
motionOfSteps,
|
|
100
105
|
motionOrder,
|
|
106
|
+
motionSource,
|
|
101
107
|
msOf,
|
|
102
108
|
noSource,
|
|
103
109
|
nodeKind,
|
|
@@ -108,6 +114,7 @@ export {
|
|
|
108
114
|
overlaps,
|
|
109
115
|
paddingOf,
|
|
110
116
|
paint,
|
|
117
|
+
paintMono,
|
|
111
118
|
parseEnd,
|
|
112
119
|
place,
|
|
113
120
|
placeBoard,
|
|
@@ -133,6 +140,7 @@ export {
|
|
|
133
140
|
snapMove,
|
|
134
141
|
springAt,
|
|
135
142
|
svgAt,
|
|
143
|
+
usedIn,
|
|
136
144
|
wallHeight,
|
|
137
145
|
wallsOf,
|
|
138
146
|
withAnts
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { extendTheme } from "../iso-core/theme.js";
|
|
2
|
+
import { contrast, greyOf, MONO, monoOf } from "../iso-core/mono.js";
|
|
3
|
+
const pct = (grey) => `${Math.round(parseInt(grey.slice(1, 3), 16) / 255 * 1e4) / 100}%`;
|
|
4
|
+
const between = (a, b, f) => {
|
|
5
|
+
const [x, y] = [a, b].map((c) => parseInt(c.slice(1, 3), 16)), v = Math.round(x + (y - x) * f).toString(16).padStart(2, "0");
|
|
6
|
+
return `#${v}${v}${v}`;
|
|
7
|
+
};
|
|
8
|
+
function usedIn(svg, theme, kinds) {
|
|
9
|
+
const seen = new Set([...svg.matchAll(/\sclass="([^"]*)"/g)].flatMap((m) => m[1].split(/\s+/)).filter((c) => c.startsWith("k-")).map((c) => c.slice(2)));
|
|
10
|
+
return { roles: Object.keys(theme.roles).filter((r) => seen.has(r)), kinds: [...new Set(kinds)].filter((k) => k in theme.kinds) };
|
|
11
|
+
}
|
|
12
|
+
function monoTheme(theme, look) {
|
|
13
|
+
const steps = MONO[look.mode].steps, face = (role, step) => look.roles[role] ?? steps[step];
|
|
14
|
+
const tokens = {};
|
|
15
|
+
for (const [k, v] of Object.entries(theme.light)) tokens[k] = /%$/.test(v) ? v : look.ink;
|
|
16
|
+
const slab = face("slab", 0), pad = face("pad", 0);
|
|
17
|
+
Object.assign(tokens, {
|
|
18
|
+
bg: look.paper,
|
|
19
|
+
surface: look.paper,
|
|
20
|
+
on: look.paper,
|
|
21
|
+
ink: look.ink,
|
|
22
|
+
muted: between(look.paper, look.ink, 0.72),
|
|
23
|
+
line: between(look.paper, look.ink, 0.3),
|
|
24
|
+
"code-bg": between(look.paper, look.ink, 0.06),
|
|
25
|
+
"slab-top": slab.top,
|
|
26
|
+
"slab-l": slab.left,
|
|
27
|
+
"slab-r": slab.right,
|
|
28
|
+
"pad-top": pad.top
|
|
29
|
+
});
|
|
30
|
+
const roles = Object.fromEntries(Object.entries(theme.roles).map(([k]) => [k, { h: 0, s: 0 }]));
|
|
31
|
+
const kinds = Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => [k, { ...v, color: look.ink }]));
|
|
32
|
+
return extendTheme({ ...theme, light: tokens, dark: tokens, roles, kinds });
|
|
33
|
+
}
|
|
34
|
+
function monoCss(look) {
|
|
35
|
+
let css = "";
|
|
36
|
+
for (const [name, r] of Object.entries(look.roles)) css += `.k-${name}{--s:0%;--l-top:${pct(r.top)};--l-left:${pct(r.left)};--l-right:${pct(r.right)};--l-edge:${pct(r.edge)}}
|
|
37
|
+
`;
|
|
38
|
+
for (const [name, k] of Object.entries(look.kinds)) css += `.flow.f-${name}{stroke-width:${k.width}${k.dash.length ? `;stroke-dasharray:${k.dash.join(" ")}` : ";stroke-dasharray:none"}}
|
|
39
|
+
`;
|
|
40
|
+
return css;
|
|
41
|
+
}
|
|
42
|
+
const TILE = {
|
|
43
|
+
hatch: { size: 6, draw: (c, w) => `<path d="M0,6L6,0M-1.5,1.5L1.5,-1.5M4.5,7.5L7.5,4.5" stroke="${c}" stroke-width="${w}" fill="none"/>` },
|
|
44
|
+
"hatch-wide": { size: 12, draw: (c, w) => `<path d="M0,0L12,12M-3,9L3,15M9,-3L15,3" stroke="${c}" stroke-width="${w}" fill="none"/>` },
|
|
45
|
+
dots: { size: 8, draw: (c, w) => `<circle cx="2" cy="2" r="${w + 0.2}" fill="${c}"/><circle cx="6" cy="6" r="${w + 0.2}" fill="${c}"/>` }
|
|
46
|
+
};
|
|
47
|
+
const round = (v) => Math.round(v * 100) / 100;
|
|
48
|
+
const patternInk = (face, look) => contrast(face, look.ink) >= contrast(face, look.paper) ? look.ink : look.paper;
|
|
49
|
+
function paintMono(svg, look, id) {
|
|
50
|
+
const need = /* @__PURE__ */ new Map();
|
|
51
|
+
const use = (pattern, ink) => {
|
|
52
|
+
const key = `${id}-mono-${pattern}-${ink.slice(1)}`, t = TILE[pattern], w = look.mode === "dark" ? 1.2 : 0.9;
|
|
53
|
+
if (!need.has(key)) need.set(key, `<pattern id="${key}" width="${t.size}" height="${t.size}" patternUnits="userSpaceOnUse">${t.draw(ink, round(w))}</pattern>`);
|
|
54
|
+
return key;
|
|
55
|
+
};
|
|
56
|
+
const depth = [];
|
|
57
|
+
let out = "", layer = "";
|
|
58
|
+
for (const m of svg.matchAll(/<\/[a-zA-Z][\w:-]*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|[^<]+/g)) {
|
|
59
|
+
out += m[0];
|
|
60
|
+
if (m[0].startsWith("</")) {
|
|
61
|
+
depth.pop();
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (m[1] === void 0) continue;
|
|
65
|
+
const cls = (/\sclass="([^"]*)"/.exec(m[2])?.[1] ?? "").split(/\s+/);
|
|
66
|
+
if (depth.length === 1) layer = cls.find((c) => c.startsWith("g-")) ?? "";
|
|
67
|
+
const role = cls.find((c) => c.startsWith("k-"))?.slice(2) ?? depth.at(-1);
|
|
68
|
+
if (!m[3]) depth.push(cls.includes("ghost") ? "" : role);
|
|
69
|
+
if (!m[3] || m[1] !== "polygon" && m[1] !== "path" || !role || !cls.some((c) => c === "top" || c === "lft" || c === "rgt")) continue;
|
|
70
|
+
if (layer === "g-base" && !cls.includes("rgt")) continue;
|
|
71
|
+
const p = Object.hasOwn(look.roles, role) ? look.roles[role].pattern : "none";
|
|
72
|
+
const fill = /\sfill="(#[0-9a-f]{6})"/.exec(m[2])?.[1], shape = /\s(points|d)="[^"]*"/.exec(m[2])?.[0];
|
|
73
|
+
if (p === "none" || !fill || !shape) continue;
|
|
74
|
+
const opacity = /\sfill-opacity="[^"]*"/.exec(m[2])?.[0] ?? "";
|
|
75
|
+
out += `<${m[1]}${shape} class="mono-pattern" fill="url(#${use(p, patternInk(fill, look))})" stroke="none"${opacity}/>`;
|
|
76
|
+
}
|
|
77
|
+
out = out.replace(/#([0-9a-f]{6})\b/g, (h, x) => x.slice(0, 2) === x.slice(2, 4) && x.slice(2, 4) === x.slice(4, 6) ? h : greyHex(h));
|
|
78
|
+
if (need.size) out = out.replace(/<defs\/>|<defs>/, (d) => d === "<defs/>" ? `<defs>${[...need.values()].join("")}</defs>` : d + [...need.values()].join(""));
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
function greyHex(c) {
|
|
82
|
+
const l = greyOf(c), y = l > 8 ? ((l + 16) / 116) ** 3 : l / (24389 / 27), s = y <= 31308e-7 ? y * 12.92 : 1.055 * y ** (1 / 2.4) - 0.055;
|
|
83
|
+
const v = Math.max(0, Math.min(255, Math.round(s * 255))).toString(16).padStart(2, "0");
|
|
84
|
+
return `#${v}${v}${v}`;
|
|
85
|
+
}
|
|
86
|
+
function monoOfDrawing(svg, theme, mode, kinds, own) {
|
|
87
|
+
const look = monoOf(theme, mode, usedIn(svg, theme, kinds), own);
|
|
88
|
+
return { look, theme: monoTheme(theme, look), css: monoCss(look) };
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
monoCss,
|
|
92
|
+
monoOfDrawing,
|
|
93
|
+
monoTheme,
|
|
94
|
+
paintMono,
|
|
95
|
+
usedIn
|
|
96
|
+
};
|
|
@@ -86,84 +86,6 @@ function curveAt(c, t, fps) {
|
|
|
86
86
|
const g = f < 0 || f > 1 ? f : easeOf(c.easing, span, "linear")(f);
|
|
87
87
|
return vs[i] + (vs[i + 1] - vs[i]) * g;
|
|
88
88
|
}
|
|
89
|
-
const TIME = { anyOf: [{ type: "number" }, { type: "string", pattern: "^-?\\d+(\\.\\d+)?(ms|s|f)?$" }] };
|
|
90
|
-
const IDS = { type: "array", items: { type: "string" } };
|
|
91
|
-
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" } } }] };
|
|
92
|
-
const timing = { from: { $ref: "#/$defs/time" }, duration: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } };
|
|
93
|
-
const node = (key, value, more = {}, withTiming = true) => ({ type: "object", required: [key], additionalProperties: false, properties: { [key]: value, ...withTiming ? timing : {}, ...more } });
|
|
94
|
-
const MOTION_SCHEMA = {
|
|
95
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
96
|
-
title: "isomotion/1",
|
|
97
|
-
type: "object",
|
|
98
|
-
required: ["isomotion"],
|
|
99
|
-
additionalProperties: false,
|
|
100
|
-
properties: {
|
|
101
|
-
isomotion: { const: 1 },
|
|
102
|
-
fps: { type: "number", exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' },
|
|
103
|
-
seed: { type: "integer" },
|
|
104
|
-
ambient: { enum: ["on", "off"], description: "Off: the ants and the looping tokens and pulses stand still, each at its start." },
|
|
105
|
-
series: { $ref: "#/$defs/series" },
|
|
106
|
-
layers: { $ref: "#/$defs/nodes" },
|
|
107
|
-
markers: { type: "object", additionalProperties: { anyOf: [{ type: "number" }, { type: "string" }] } }
|
|
108
|
-
},
|
|
109
|
-
$defs: {
|
|
110
|
-
time: TIME,
|
|
111
|
-
ids: IDS,
|
|
112
|
-
ease: EASE,
|
|
113
|
-
spring: { type: "object", additionalProperties: false, properties: { mass: { type: "number", exclusiveMinimum: 0 }, damping: { type: "number", exclusiveMinimum: 0 }, stiffness: { type: "number", exclusiveMinimum: 0 }, overshootClamping: { type: "boolean" } } },
|
|
114
|
-
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 } } },
|
|
115
|
-
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 } } } },
|
|
116
|
-
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" } } },
|
|
117
|
-
sequence: {
|
|
118
|
-
type: "object",
|
|
119
|
-
additionalProperties: false,
|
|
120
|
-
properties: {
|
|
121
|
-
name: { type: "string", pattern: "^[A-Za-z][\\w-]*$" },
|
|
122
|
-
from: { $ref: "#/$defs/time" },
|
|
123
|
-
offset: { $ref: "#/$defs/time" },
|
|
124
|
-
trimBefore: { $ref: "#/$defs/time" },
|
|
125
|
-
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" } } }] } } }] },
|
|
126
|
-
loop: { anyOf: [{ type: "boolean" }, { type: "integer", minimum: 1 }] },
|
|
127
|
-
playbackRate: { type: "number", exclusiveMinimum: 0 },
|
|
128
|
-
say: { $ref: "#/$defs/say" },
|
|
129
|
-
show: { $ref: "#/$defs/ids" },
|
|
130
|
-
hide: { $ref: "#/$defs/ids" },
|
|
131
|
-
focus: { $ref: "#/$defs/focus" },
|
|
132
|
-
highlight: { $ref: "#/$defs/ids" },
|
|
133
|
-
levels: { type: "object", additionalProperties: { type: "number", minimum: 0, maximum: 1 } },
|
|
134
|
-
variants: { type: "object", additionalProperties: { type: "string" } },
|
|
135
|
-
enter: { type: "object", required: ["fade"], additionalProperties: false, properties: { fade: { $ref: "#/$defs/time" }, easing: { $ref: "#/$defs/ease" } } },
|
|
136
|
-
ants: { anyOf: [{ type: "boolean" }, { $ref: "#/$defs/ids" }] },
|
|
137
|
-
children: { $ref: "#/$defs/nodes" },
|
|
138
|
-
layers: { $ref: "#/$defs/nodes" },
|
|
139
|
-
series: { $ref: "#/$defs/series" }
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
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)] } },
|
|
143
|
-
seq: node("sequence", { $ref: "#/$defs/sequence" }, {}, false),
|
|
144
|
-
plan: { type: "object" },
|
|
145
|
-
nodes: {
|
|
146
|
-
type: "array",
|
|
147
|
-
items: { anyOf: [
|
|
148
|
-
{ $ref: "#/$defs/seq" },
|
|
149
|
-
node("series", { $ref: "#/$defs/series" }, {}, false),
|
|
150
|
-
node("layers", { $ref: "#/$defs/nodes" }, {}, false),
|
|
151
|
-
node("assemble", { type: "object", properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
152
|
-
node("disassemble", { type: "object", properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
153
|
-
node("travel", { type: "array", items: { anyOf: [{ type: "string" }, { $ref: "#/$defs/ids" }] }, minItems: 1 }, { each: { $ref: "#/$defs/time" }, hold: { $ref: "#/$defs/time" }, loop: { type: "boolean" } }),
|
|
154
|
-
node("pulse", { $ref: "#/$defs/ids" }, { loop: { type: "boolean" } }),
|
|
155
|
-
node("ants", { anyOf: [{ const: true }, { $ref: "#/$defs/ids" }] }, { speed: { type: "number" }, dash: { type: "array", items: { type: "number", exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
|
|
156
|
-
node("draw", { $ref: "#/$defs/ids" }, { by: { enum: ["stroke", "grow"] }, stagger: { $ref: "#/$defs/time" } }),
|
|
157
|
-
node("type", { $ref: "#/$defs/ids" }),
|
|
158
|
-
{ 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" } } },
|
|
159
|
-
{ 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 } },
|
|
160
|
-
node("focus", { $ref: "#/$defs/focus" }, { fade: { $ref: "#/$defs/time" } }),
|
|
161
|
-
node("highlight", { $ref: "#/$defs/ids" }, { fade: { $ref: "#/$defs/time" } }),
|
|
162
|
-
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" } } }] })
|
|
163
|
-
] }
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
89
|
const KINDS = ["sequence", "series", "layers", "assemble", "disassemble", "travel", "pulse", "ants", "draw", "type", "move", "lift", "focus", "highlight", "camera"];
|
|
168
90
|
const LATER = { morph: "the 2D morph is a later version's", diff: "diffs are a later version's", switch: "a look is a beat's: its variants" };
|
|
169
91
|
const TIMING = ["from", "duration", "easing"];
|
|
@@ -489,7 +411,6 @@ function checkMotion(doc) {
|
|
|
489
411
|
export {
|
|
490
412
|
EASING_NAMES,
|
|
491
413
|
EXTRAPOLATE,
|
|
492
|
-
MOTION_SCHEMA,
|
|
493
414
|
bezier,
|
|
494
415
|
checkMotion,
|
|
495
416
|
curveAt,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from "./motion.js";
|
|
2
|
-
import { bindMotion, motionOfSteps } from "./timeline.js";
|
|
2
|
+
import { bindMotion, motionOfSteps, motionSource } from "./timeline.js";
|
|
3
3
|
import { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from "./motion-builder.js";
|
|
4
|
-
import { MOTION_SCHEMA
|
|
4
|
+
import { MOTION_SCHEMA } from "./motion-schema.js";
|
|
5
|
+
import { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from "./motion-doc.js";
|
|
5
6
|
import { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from "./ants.js";
|
|
6
7
|
import { drawLooks } from "./looks.js";
|
|
7
8
|
export {
|
|
@@ -25,6 +26,7 @@ export {
|
|
|
25
26
|
easeOf,
|
|
26
27
|
motion,
|
|
27
28
|
motionOfSteps,
|
|
29
|
+
motionSource,
|
|
28
30
|
msOf,
|
|
29
31
|
readMs,
|
|
30
32
|
springAt,
|