@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/src/iso-core/theme.ts
CHANGED
|
@@ -12,7 +12,8 @@ export interface Theme {
|
|
|
12
12
|
name: string;
|
|
13
13
|
light: Record<string, string>;
|
|
14
14
|
dark: Record<string, string>;
|
|
15
|
-
|
|
15
|
+
/** ants: the dash its connectors march with, where it isn't its dash's own */
|
|
16
|
+
kinds: Record<string, { color: string; dash: 'solid' | 'dashed' | 'dotted'; legend: string; ants?: [number, number] }>;
|
|
16
17
|
roles: Record<string, RawRole>;
|
|
17
18
|
}
|
|
18
19
|
|
|
@@ -328,6 +328,8 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
328
328
|
empty.hidden = true;
|
|
329
329
|
layer?.drawn?.();
|
|
330
330
|
if (pendingReveal && reveal(pendingReveal)) pendingReveal = undefined;
|
|
331
|
+
// once, on the first drawing after its own drop; another drag forgets it (its drawings are trials, and the pointer is on them)
|
|
332
|
+
if (pendingNudge) { if (!drag) nudge(pendingNudge); pendingNudge = undefined; }
|
|
331
333
|
paintNav();
|
|
332
334
|
paintOverlay();
|
|
333
335
|
if (from && from.svg !== s) {
|
|
@@ -1162,7 +1164,8 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1162
1164
|
const cmd = pins.length ? seqCmd(`${f.plan.label} at [${m.at.join(', ')}]${wayWords(g, keep)}`, [f.plan.add, pinsCmd(pins, '')]) : f.plan.add;
|
|
1163
1165
|
if (g.invalid) unshift(g);
|
|
1164
1166
|
if (!run(doc, { ...cmd, select: [f.path] }, 'canvas', opts.note)) { lastKey = ''; unshift(g); await draw(g.origCd!); return; }
|
|
1165
|
-
|
|
1167
|
+
// the layout may have placed it out of view: shown, once it is drawn there, so that its name is asked above it
|
|
1168
|
+
if (g.invalid) { opts.note(`${f.name} added; that spot is taken, so the layout placed it`); pendingNudge = f.path; }
|
|
1166
1169
|
doc.select([f.path], 'canvas');
|
|
1167
1170
|
// its name, in the inline field above it; the drop and the name are one undo step
|
|
1168
1171
|
rename(f.path, { joins: doc.undoId, at: lastPin });
|
|
@@ -1609,6 +1612,16 @@ export function canvasView<M, D extends CanvasDrawing, A extends object = object
|
|
|
1609
1612
|
return true;
|
|
1610
1613
|
}
|
|
1611
1614
|
let pendingReveal: Path[] | undefined;
|
|
1615
|
+
/** what is cut off by the canvas's edge, just into view: as far as it takes, and nothing when none of it is cut off */
|
|
1616
|
+
function nudge(p: Path) {
|
|
1617
|
+
const b = boxFor(p), v = V.view;
|
|
1618
|
+
if (!v || !b) return;
|
|
1619
|
+
if (b.w > v.w || b.h > v.h) { reveal([p]); return; }
|
|
1620
|
+
const m = 12 / scale(), by = (a: number, n: number, va: number, vn: number) => (a < va ? a - va - m : a + n > va + vn ? a + n - va - vn + m : 0);
|
|
1621
|
+
const dx = by(b.x, b.w, v.x, v.w), dy = by(b.y, b.h, v.y, v.h);
|
|
1622
|
+
if (dx || dy) { V.view = { ...v, x: v.x + dx, y: v.y + dy }; applyView(); }
|
|
1623
|
+
}
|
|
1624
|
+
let pendingNudge: Path | undefined;
|
|
1612
1625
|
ifEvents();
|
|
1613
1626
|
doc.onSelect(c => {
|
|
1614
1627
|
paintOverlay();
|
package/src/iso-objects/ants.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface AntsOptions {
|
|
|
17
17
|
speed?: number;
|
|
18
18
|
dash?: [number, number];
|
|
19
19
|
/** the connectors' dashes, by kind: the theme's `kinds` (a dashed kind marches with its own dash) */
|
|
20
|
-
kinds?: Record<string, { dash?: 'solid' | 'dashed' | 'dotted' }>;
|
|
20
|
+
kinds?: Record<string, { dash?: 'solid' | 'dashed' | 'dotted'; ants?: [number, number] }>;
|
|
21
21
|
/** kinds whose connectors stand still (default: blocked, planned) */
|
|
22
22
|
still?: string[];
|
|
23
23
|
}
|
|
@@ -28,7 +28,7 @@ export const ANTS_CSS = `
|
|
|
28
28
|
`;
|
|
29
29
|
/** the dash a connector marches with, or undefined when it stands still */
|
|
30
30
|
export function antDash(kind: string, o: Pick<AntsOptions, 'dash' | 'kinds' | 'still'> = {}): [number, number] | undefined {
|
|
31
|
-
return (o.still ?? ANT_STILL).includes(kind) ? undefined : o.dash ?? ANT_DASH[o.kinds?.[kind]?.dash ?? 'solid'];
|
|
31
|
+
return (o.still ?? ANT_STILL).includes(kind) ? undefined : o.dash ?? o.kinds?.[kind]?.ants ?? ANT_DASH[o.kinds?.[kind]?.dash ?? 'solid'];
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** what a scene's `ants:` in the file asks for, as options; undefined: none */
|
package/src/iso-objects/index.ts
CHANGED
|
@@ -25,11 +25,13 @@ export { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } f
|
|
|
25
25
|
export type { AntsOptions } from './ants.ts';
|
|
26
26
|
export { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from './motion-builder.ts';
|
|
27
27
|
export type { SequenceOptions, Timing, CameraVerbs, Ids as MotionIds } from './motion-builder.ts';
|
|
28
|
-
export { bindMotion, motionOfSteps } from './timeline.ts';
|
|
29
|
-
export type { Timeline, BindOptions, BeatInfo, Cue } from './timeline.ts';
|
|
30
|
-
export { MOTION_SCHEMA
|
|
28
|
+
export { bindMotion, motionOfSteps, motionSource } from './timeline.ts';
|
|
29
|
+
export type { Timeline, BindOptions, BeatInfo, Cue, MotionSource } from './timeline.ts';
|
|
30
|
+
export { MOTION_SCHEMA } from './motion-schema.ts';
|
|
31
|
+
export { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from './motion-doc.ts';
|
|
31
32
|
export type { MotionDoc, MotionNode, MotionTime, MotionEase, EasingName, Extrapolate, SpringConfig, Curve, Say as MotionSay, Focus, ReadTime, Sequence, SeriesItem, Transition, MotionDiag } from './motion-doc.ts';
|
|
32
33
|
export { resolveSvg, FONT_STACKS } from './resolve.ts';
|
|
34
|
+
export { monoOfDrawing, monoTheme, monoCss, paintMono, usedIn } from './mono-paint.ts';
|
|
33
35
|
export type { ResolveOptions, ThemeMode } from './resolve.ts';
|
|
34
36
|
export { durationFor, resolveSteps, midpoint } from './steps.ts';
|
|
35
37
|
export type { RawStep, Token, StepData, Say, Mark, Badge, Steps } from './steps.ts';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The black and white treatment of a self-contained drawing (docs/design/MOTION.md, 5b): a paint, not a drawing. The tables
|
|
2
|
+
// (iso-core/mono.ts) become a theme and rules the resolver works out as it does any theme's; patterns go over a thing's faces, inside
|
|
3
|
+
// its own wrapper, so that motion moves them with it. Geometry, ids and wrappers are the styled drawing's. What has a hue after all of
|
|
4
|
+
// that (a screen's own colours, a brand mark's) becomes the grey of its lightness: nothing has a hue.
|
|
5
|
+
|
|
6
|
+
import { extendTheme, type Theme } from '../iso-core/theme.ts';
|
|
7
|
+
import { contrast, greyOf, MONO, monoOf, type MonoLook, type MonoPattern, type MonoTable } from '../iso-core/mono.ts';
|
|
8
|
+
import type { ThemeMode } from './resolve.ts';
|
|
9
|
+
|
|
10
|
+
const pct = (grey: string) => `${Math.round((parseInt(grey.slice(1, 3), 16) / 255) * 10000) / 100}%`;
|
|
11
|
+
/** a grey between two, by its share of the second */
|
|
12
|
+
const between = (a: string, b: string, f: number) => { 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'); return `#${v}${v}${v}`; };
|
|
13
|
+
|
|
14
|
+
/** the roles and connector kinds a drawing uses */
|
|
15
|
+
export function usedIn(svg: string, theme: Theme, kinds: string[]): { roles: string[]; kinds: string[] } {
|
|
16
|
+
const seen = new Set([...svg.matchAll(/\sclass="([^"]*)"/g)].flatMap(m => m[1].split(/\s+/)).filter(c => c.startsWith('k-')).map(c => c.slice(2)));
|
|
17
|
+
return { roles: Object.keys(theme.roles).filter(r => seen.has(r)), kinds: [...new Set(kinds)].filter(k => k in theme.kinds) };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** the theme in greys, its tokens by the same names, so that everything that names one is grey too */
|
|
21
|
+
export function monoTheme(theme: Theme, look: MonoLook): Theme {
|
|
22
|
+
const steps = MONO[look.mode].steps, face = (role: string, step: 0 | 1) => look.roles[role] ?? steps[step];
|
|
23
|
+
const tokens: Record<string, string> = {};
|
|
24
|
+
// a token is ink, unless it is one of a surface's
|
|
25
|
+
for (const [k, v] of Object.entries(theme.light)) tokens[k] = /%$/.test(v) ? v : look.ink;
|
|
26
|
+
const slab = face('slab', 0), pad = face('pad', 0);
|
|
27
|
+
Object.assign(tokens, {
|
|
28
|
+
bg: look.paper, surface: look.paper, on: look.paper, ink: look.ink, muted: between(look.paper, look.ink, 0.72), line: between(look.paper, look.ink, 0.3), 'code-bg': between(look.paper, look.ink, 0.06),
|
|
29
|
+
'slab-top': slab.top, 'slab-l': slab.left, 'slab-r': slab.right, 'pad-top': pad.top,
|
|
30
|
+
});
|
|
31
|
+
const roles = Object.fromEntries(Object.entries(theme.roles).map(([k]) => [k, { h: 0, s: 0 }]));
|
|
32
|
+
const kinds = Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => [k, { ...v, color: look.ink }]));
|
|
33
|
+
return extendTheme({ ...theme, light: tokens, dark: tokens, roles, kinds });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** what is each role's and each kind's own: the faces' lightnesses, the connectors' rhythms */
|
|
37
|
+
export function monoCss(look: MonoLook): string {
|
|
38
|
+
let css = '';
|
|
39
|
+
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)}}\n`;
|
|
40
|
+
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'}}\n`;
|
|
41
|
+
return css;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const TILE: Record<Exclude<MonoPattern, 'none'>, { size: number; draw: (ink: string, w: number) => string }> = {
|
|
45
|
+
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"/>` },
|
|
46
|
+
'hatch-wide': { size: 12, draw: (c, w) => `<path d="M0,0L12,12M-3,9L3,15M9,-3L15,3" stroke="${c}" stroke-width="${w}" fill="none"/>` },
|
|
47
|
+
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}"/>` },
|
|
48
|
+
};
|
|
49
|
+
const round = (v: number) => Math.round(v * 100) / 100;
|
|
50
|
+
/** a pattern's ink on a face: the mode's own ink or paper, whichever stands out */
|
|
51
|
+
const patternInk = (face: string, look: MonoLook) => (contrast(face, look.ink) >= contrast(face, look.paper) ? look.ink : look.paper);
|
|
52
|
+
|
|
53
|
+
/** The resolved drawing with its patterns, and no hue in it. `id`: the drawing's own (its patterns' ids begin with it). */
|
|
54
|
+
export function paintMono(svg: string, look: MonoLook, id: string): string {
|
|
55
|
+
const need = new Map<string, string>();
|
|
56
|
+
const use = (pattern: Exclude<MonoPattern, 'none'>, ink: string) => {
|
|
57
|
+
const key = `${id}-mono-${pattern}-${ink.slice(1)}`, t = TILE[pattern], w = look.mode === 'dark' ? 1.2 : 0.9;
|
|
58
|
+
if (!need.has(key)) need.set(key, `<pattern id="${key}" width="${t.size}" height="${t.size}" patternUnits="userSpaceOnUse">${t.draw(ink, round(w))}</pattern>`);
|
|
59
|
+
return key;
|
|
60
|
+
};
|
|
61
|
+
// each face of a patterned role's solids, again, in its pattern, straight after it
|
|
62
|
+
const depth: (string | undefined)[] = [];
|
|
63
|
+
let out = '', layer = '';
|
|
64
|
+
for (const m of svg.matchAll(/<\/[a-zA-Z][\w:-]*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+="[^"]*")*)\s*(\/?)>|[^<]+/g)) {
|
|
65
|
+
out += m[0];
|
|
66
|
+
if (m[0].startsWith('</')) { depth.pop(); continue; }
|
|
67
|
+
if (m[1] === undefined) continue;
|
|
68
|
+
const cls = (/\sclass="([^"]*)"/.exec(m[2])?.[1] ?? '').split(/\s+/);
|
|
69
|
+
if (depth.length === 1) layer = cls.find(c => c.startsWith('g-')) ?? '';
|
|
70
|
+
const role = cls.find(c => c.startsWith('k-'))?.slice(2) ?? depth.at(-1);
|
|
71
|
+
if (!m[3]) depth.push(cls.includes('ghost') ? '' : role);
|
|
72
|
+
if (!m[3] || (m[1] !== 'polygon' && m[1] !== 'path') || !role || !cls.some(c => c === 'top' || c === 'lft' || c === 'rgt')) continue;
|
|
73
|
+
// a ground is drawn on (its top) and has its name on its front: they stay plain, and its other side tells it
|
|
74
|
+
if (layer === 'g-base' && !cls.includes('rgt')) continue;
|
|
75
|
+
const p = Object.hasOwn(look.roles, role) ? look.roles[role].pattern : 'none';
|
|
76
|
+
const fill = /\sfill="(#[0-9a-f]{6})"/.exec(m[2])?.[1], shape = /\s(points|d)="[^"]*"/.exec(m[2])?.[0];
|
|
77
|
+
if (p === 'none' || !fill || !shape) continue;
|
|
78
|
+
const opacity = /\sfill-opacity="[^"]*"/.exec(m[2])?.[0] ?? '';
|
|
79
|
+
out += `<${m[1]}${shape} class="mono-pattern" fill="url(#${use(p, patternInk(fill, look))})" stroke="none"${opacity}/>`;
|
|
80
|
+
}
|
|
81
|
+
// whatever still has a hue, in the grey of its own lightness
|
|
82
|
+
out = out.replace(/#([0-9a-f]{6})\b/g, (h, x: string) => (x.slice(0, 2) === x.slice(2, 4) && x.slice(2, 4) === x.slice(4, 6) ? h : greyHex(h)));
|
|
83
|
+
if (need.size) out = out.replace(/<defs\/>|<defs>/, d => (d === '<defs/>' ? `<defs>${[...need.values()].join('')}</defs>` : d + [...need.values()].join('')));
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** the grey of a colour's own lightness (L*) */
|
|
87
|
+
function greyHex(c: string): string {
|
|
88
|
+
const l = greyOf(c), y = l > 8 ? ((l + 16) / 116) ** 3 : l / (24389 / 27), s = y <= 0.0031308 ? y * 12.92 : 1.055 * y ** (1 / 2.4) - 0.055;
|
|
89
|
+
const v = Math.max(0, Math.min(255, Math.round(s * 255))).toString(16).padStart(2, '0');
|
|
90
|
+
return `#${v}${v}${v}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Everything a compile needs for the treatment: the look, its theme and its rules. */
|
|
94
|
+
export function monoOfDrawing(svg: string, theme: Theme, mode: ThemeMode, kinds: string[], own?: MonoTable): { look: MonoLook; theme: Theme; css: string } {
|
|
95
|
+
const look = monoOf(theme, mode, usedIn(svg, theme, kinds), own);
|
|
96
|
+
return { look, theme: monoTheme(theme, look), css: monoCss(look) };
|
|
97
|
+
}
|
|
@@ -150,58 +150,6 @@ export function curveAt(c: Curve, t: number, fps?: number): number {
|
|
|
150
150
|
return vs[i] + (vs[i + 1] - vs[i]) * g;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
// ---------- the JSON Schema: for editors (completion, hover) and for tools; checkMotion says the same, with places ----------
|
|
154
|
-
|
|
155
|
-
const TIME = { anyOf: [{ type: 'number' }, { type: 'string', pattern: '^-?\\d+(\\.\\d+)?(ms|s|f)?$' }] } as const;
|
|
156
|
-
const IDS = { type: 'array', items: { type: 'string' } } as const;
|
|
157
|
-
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' } } }] } as const;
|
|
158
|
-
const timing = { from: { $ref: '#/$defs/time' }, duration: { $ref: '#/$defs/time' }, easing: { $ref: '#/$defs/ease' } };
|
|
159
|
-
const node = (key: string, value: object, more: object = {}, withTiming = true) => ({ type: 'object', required: [key], additionalProperties: false, properties: { [key]: value, ...(withTiming ? timing : {}), ...more } });
|
|
160
|
-
export const MOTION_SCHEMA = {
|
|
161
|
-
$schema: 'https://json-schema.org/draft/2020-12/schema', title: 'isomotion/1',
|
|
162
|
-
type: 'object', required: ['isomotion'], additionalProperties: false,
|
|
163
|
-
properties: {
|
|
164
|
-
isomotion: { const: 1 }, fps: { type: 'number', exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' }, seed: { type: 'integer' },
|
|
165
|
-
ambient: { enum: ['on', 'off'], description: 'Off: the ants and the looping tokens and pulses stand still, each at its start.' },
|
|
166
|
-
series: { $ref: '#/$defs/series' }, layers: { $ref: '#/$defs/nodes' },
|
|
167
|
-
markers: { type: 'object', additionalProperties: { anyOf: [{ type: 'number' }, { type: 'string' }] } },
|
|
168
|
-
},
|
|
169
|
-
$defs: {
|
|
170
|
-
time: TIME, ids: IDS, ease: EASE,
|
|
171
|
-
spring: { type: 'object', additionalProperties: false, properties: { mass: { type: 'number', exclusiveMinimum: 0 }, damping: { type: 'number', exclusiveMinimum: 0 }, stiffness: { type: 'number', exclusiveMinimum: 0 }, overshootClamping: { type: 'boolean' } } },
|
|
172
|
-
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 } } },
|
|
173
|
-
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 } } } },
|
|
174
|
-
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' } } },
|
|
175
|
-
sequence: {
|
|
176
|
-
type: 'object', additionalProperties: false, properties: {
|
|
177
|
-
name: { type: 'string', pattern: '^[A-Za-z][\\w-]*$' }, from: { $ref: '#/$defs/time' }, offset: { $ref: '#/$defs/time' }, trimBefore: { $ref: '#/$defs/time' },
|
|
178
|
-
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' } } }] } } }] },
|
|
179
|
-
loop: { anyOf: [{ type: 'boolean' }, { type: 'integer', minimum: 1 }] }, playbackRate: { type: 'number', exclusiveMinimum: 0 },
|
|
180
|
-
say: { $ref: '#/$defs/say' }, show: { $ref: '#/$defs/ids' }, hide: { $ref: '#/$defs/ids' }, focus: { $ref: '#/$defs/focus' }, highlight: { $ref: '#/$defs/ids' }, levels: { type: 'object', additionalProperties: { type: 'number', minimum: 0, maximum: 1 } }, variants: { type: 'object', additionalProperties: { type: 'string' } },
|
|
181
|
-
enter: { type: 'object', required: ['fade'], additionalProperties: false, properties: { fade: { $ref: '#/$defs/time' }, easing: { $ref: '#/$defs/ease' } } },
|
|
182
|
-
ants: { anyOf: [{ type: 'boolean' }, { $ref: '#/$defs/ids' }] }, children: { $ref: '#/$defs/nodes' }, layers: { $ref: '#/$defs/nodes' }, series: { $ref: '#/$defs/series' },
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
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)] } },
|
|
186
|
-
seq: node('sequence', { $ref: '#/$defs/sequence' }, {}, false),
|
|
187
|
-
plan: { type: 'object' },
|
|
188
|
-
nodes: {
|
|
189
|
-
type: 'array', items: { anyOf: [
|
|
190
|
-
{ $ref: '#/$defs/seq' }, node('series', { $ref: '#/$defs/series' }, {}, false), node('layers', { $ref: '#/$defs/nodes' }, {}, false),
|
|
191
|
-
node('assemble', { type: 'object', properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }), node('disassemble', { type: 'object', properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
192
|
-
node('travel', { type: 'array', items: { anyOf: [{ type: 'string' }, { $ref: '#/$defs/ids' }] }, minItems: 1 }, { each: { $ref: '#/$defs/time' }, hold: { $ref: '#/$defs/time' }, loop: { type: 'boolean' } }),
|
|
193
|
-
node('pulse', { $ref: '#/$defs/ids' }, { loop: { type: 'boolean' } }),
|
|
194
|
-
node('ants', { anyOf: [{ const: true }, { $ref: '#/$defs/ids' }] }, { speed: { type: 'number' }, dash: { type: 'array', items: { type: 'number', exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
|
|
195
|
-
node('draw', { $ref: '#/$defs/ids' }, { by: { enum: ['stroke', 'grow'] }, stagger: { $ref: '#/$defs/time' } }), node('type', { $ref: '#/$defs/ids' }),
|
|
196
|
-
{ 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' } } },
|
|
197
|
-
{ 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 } },
|
|
198
|
-
node('focus', { $ref: '#/$defs/focus' }, { fade: { $ref: '#/$defs/time' } }), node('highlight', { $ref: '#/$defs/ids' }, { fade: { $ref: '#/$defs/time' } }),
|
|
199
|
-
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' } } }] }),
|
|
200
|
-
] },
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
} as const;
|
|
204
|
-
|
|
205
153
|
// ---------- the checks ----------
|
|
206
154
|
|
|
207
155
|
const KINDS = ['sequence', 'series', 'layers', 'assemble', 'disassemble', 'travel', 'pulse', 'ants', 'draw', 'type', 'move', 'lift', 'focus', 'highlight', 'camera'] as const;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// The package's /motion: plans, the motion document and its Timeline, the builder, looks and ants. All pure, no DOM but paint().
|
|
2
2
|
|
|
3
3
|
export * from './motion.ts';
|
|
4
|
-
export { bindMotion, motionOfSteps } from './timeline.ts';
|
|
5
|
-
export type { Timeline, BindOptions, BeatInfo, Cue } from './timeline.ts';
|
|
4
|
+
export { bindMotion, motionOfSteps, motionSource } from './timeline.ts';
|
|
5
|
+
export type { Timeline, BindOptions, BeatInfo, Cue, MotionSource } from './timeline.ts';
|
|
6
6
|
export { motion, MotionBuilder, SeriesBuilder, NodesBuilder } from './motion-builder.ts';
|
|
7
7
|
export type { SequenceOptions, Timing, CameraVerbs, Ids as MotionIds } from './motion-builder.ts';
|
|
8
|
-
export { MOTION_SCHEMA
|
|
8
|
+
export { MOTION_SCHEMA } from './motion-schema.ts';
|
|
9
|
+
export { EASING_NAMES, EXTRAPOLATE, checkMotion, msOf, readMs, easeOf, curveAt, springAt, bezier } from './motion-doc.ts';
|
|
9
10
|
export type { MotionDoc, MotionNode, MotionTime, MotionEase, EasingName, Extrapolate, SpringConfig, Curve, Say as MotionSay, Focus, ReadTime, Sequence, SeriesItem, Transition, MotionDiag } from './motion-doc.ts';
|
|
10
11
|
export { withAnts, antsOf, antDash, ANTS_CSS, ANT_SPEED, ANT_DASH, ANT_STILL } from './ants.ts';
|
|
11
12
|
export type { AntsOptions } from './ants.ts';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// The motion document's JSON Schema, for editors (completion, hover) and for tools; checkMotion (motion-doc.ts) says the same, with
|
|
2
|
+
// places. A module of its own: a page that plays a document doesn't carry it.
|
|
3
|
+
|
|
4
|
+
import { ASSEMBLE_STYLES, DISASSEMBLE_STYLES, MOTION_ORDERS } from './motion.ts';
|
|
5
|
+
import { EASING_NAMES, EXTRAPOLATE } from './motion-doc.ts';
|
|
6
|
+
|
|
7
|
+
const TIME = { anyOf: [{ type: 'number' }, { type: 'string', pattern: '^-?\\d+(\\.\\d+)?(ms|s|f)?$' }] } as const;
|
|
8
|
+
const IDS = { type: 'array', items: { type: 'string' } } as const;
|
|
9
|
+
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' } } }] } as const;
|
|
10
|
+
const timing = { from: { $ref: '#/$defs/time' }, duration: { $ref: '#/$defs/time' }, easing: { $ref: '#/$defs/ease' } };
|
|
11
|
+
const node = (key: string, value: object, more: object = {}, withTiming = true) => ({ type: 'object', required: [key], additionalProperties: false, properties: { [key]: value, ...(withTiming ? timing : {}), ...more } });
|
|
12
|
+
export const MOTION_SCHEMA = {
|
|
13
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema', title: 'isomotion/1',
|
|
14
|
+
type: 'object', required: ['isomotion'], additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
isomotion: { const: 1 }, fps: { type: 'number', exclusiveMinimum: 0, description: 'Frames a second, for lengths written "30f".' }, seed: { type: 'integer' },
|
|
17
|
+
ambient: { enum: ['on', 'off'], description: 'Off: the ants and the looping tokens and pulses stand still, each at its start.' },
|
|
18
|
+
series: { $ref: '#/$defs/series' }, layers: { $ref: '#/$defs/nodes' },
|
|
19
|
+
markers: { type: 'object', additionalProperties: { anyOf: [{ type: 'number' }, { type: 'string' }] } },
|
|
20
|
+
},
|
|
21
|
+
$defs: {
|
|
22
|
+
time: TIME, ids: IDS, ease: EASE,
|
|
23
|
+
spring: { type: 'object', additionalProperties: false, properties: { mass: { type: 'number', exclusiveMinimum: 0 }, damping: { type: 'number', exclusiveMinimum: 0 }, stiffness: { type: 'number', exclusiveMinimum: 0 }, overshootClamping: { type: 'boolean' } } },
|
|
24
|
+
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 } } },
|
|
25
|
+
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 } } } },
|
|
26
|
+
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' } } },
|
|
27
|
+
sequence: {
|
|
28
|
+
type: 'object', additionalProperties: false, properties: {
|
|
29
|
+
name: { type: 'string', pattern: '^[A-Za-z][\\w-]*$' }, from: { $ref: '#/$defs/time' }, offset: { $ref: '#/$defs/time' }, trimBefore: { $ref: '#/$defs/time' },
|
|
30
|
+
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' } } }] } } }] },
|
|
31
|
+
loop: { anyOf: [{ type: 'boolean' }, { type: 'integer', minimum: 1 }] }, playbackRate: { type: 'number', exclusiveMinimum: 0 },
|
|
32
|
+
say: { $ref: '#/$defs/say' }, show: { $ref: '#/$defs/ids' }, hide: { $ref: '#/$defs/ids' }, focus: { $ref: '#/$defs/focus' }, highlight: { $ref: '#/$defs/ids' }, levels: { type: 'object', additionalProperties: { type: 'number', minimum: 0, maximum: 1 } }, variants: { type: 'object', additionalProperties: { type: 'string' } },
|
|
33
|
+
enter: { type: 'object', required: ['fade'], additionalProperties: false, properties: { fade: { $ref: '#/$defs/time' }, easing: { $ref: '#/$defs/ease' } } },
|
|
34
|
+
ants: { anyOf: [{ type: 'boolean' }, { $ref: '#/$defs/ids' }] }, children: { $ref: '#/$defs/nodes' }, layers: { $ref: '#/$defs/nodes' }, series: { $ref: '#/$defs/series' },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
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)] } },
|
|
38
|
+
seq: node('sequence', { $ref: '#/$defs/sequence' }, {}, false),
|
|
39
|
+
plan: { type: 'object' },
|
|
40
|
+
nodes: {
|
|
41
|
+
type: 'array', items: { anyOf: [
|
|
42
|
+
{ $ref: '#/$defs/seq' }, node('series', { $ref: '#/$defs/series' }, {}, false), node('layers', { $ref: '#/$defs/nodes' }, {}, false),
|
|
43
|
+
node('assemble', { type: 'object', properties: { style: { enum: ASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }), node('disassemble', { type: 'object', properties: { style: { enum: DISASSEMBLE_STYLES }, order: { enum: MOTION_ORDERS } } }),
|
|
44
|
+
node('travel', { type: 'array', items: { anyOf: [{ type: 'string' }, { $ref: '#/$defs/ids' }] }, minItems: 1 }, { each: { $ref: '#/$defs/time' }, hold: { $ref: '#/$defs/time' }, loop: { type: 'boolean' } }),
|
|
45
|
+
node('pulse', { $ref: '#/$defs/ids' }, { loop: { type: 'boolean' } }),
|
|
46
|
+
node('ants', { anyOf: [{ const: true }, { $ref: '#/$defs/ids' }] }, { speed: { type: 'number' }, dash: { type: 'array', items: { type: 'number', exclusiveMinimum: 0 }, minItems: 2, maxItems: 2 } }),
|
|
47
|
+
node('draw', { $ref: '#/$defs/ids' }, { by: { enum: ['stroke', 'grow'] }, stagger: { $ref: '#/$defs/time' } }), node('type', { $ref: '#/$defs/ids' }),
|
|
48
|
+
{ 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' } } },
|
|
49
|
+
{ 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 } },
|
|
50
|
+
node('focus', { $ref: '#/$defs/focus' }, { fade: { $ref: '#/$defs/time' } }), node('highlight', { $ref: '#/$defs/ids' }, { fade: { $ref: '#/$defs/time' } }),
|
|
51
|
+
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' } } }] }),
|
|
52
|
+
] },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
} as const;
|
|
@@ -469,7 +469,7 @@ function insides(svg: string): Map<string, [number, number]> {
|
|
|
469
469
|
}
|
|
470
470
|
return out;
|
|
471
471
|
}
|
|
472
|
-
type Looks = Pick<CompiledScene['rendered'], 'svg' | 'variants' | 'looks'>;
|
|
472
|
+
type Looks = Pick<CompiledScene['rendered'], 'svg' | 'variants' | 'looks' | 'inks'>;
|
|
473
473
|
const lookCache = new WeakMap<object, Map<string, Map<string, string>>>();
|
|
474
474
|
/** a look's parts of a thing: id and part → what is inside, where it isn't as in the still */
|
|
475
475
|
function lookParts(r: Looks, name: string): Map<string, string> {
|
|
@@ -543,7 +543,7 @@ type Kept = { attrs: Map<Element, Map<string, string | null>>; texts: Map<Text,
|
|
|
543
543
|
const keptOf = new WeakMap<Element, Kept>();
|
|
544
544
|
/** The same on a live drawing (a scene's own <svg>). Idempotent, in any order: what the last state changed is put back
|
|
545
545
|
* first, so the same state gives the same DOM; an empty state gives the still back. */
|
|
546
|
-
export function paint(svg: SVGSVGElement, S: SceneState, rendered?: Looks): void {
|
|
546
|
+
export function paint(svg: SVGSVGElement, S: SceneState, rendered?: Looks, o: { styles?: 'attribute' | 'cssom' } = {}): void {
|
|
547
547
|
const was = keptOf.get(svg);
|
|
548
548
|
if (was) {
|
|
549
549
|
for (const [el, kids] of was.mixed) el.replaceChildren(...kids);
|
|
@@ -558,7 +558,8 @@ export function paint(svg: SVGSVGElement, S: SceneState, rendered?: Looks): void
|
|
|
558
558
|
keptOf.set(svg, kept);
|
|
559
559
|
const set = (el: Element, k: string, v: string | null) => {
|
|
560
560
|
const m = kept.attrs.get(el) ?? new Map<string, string | null>();
|
|
561
|
-
|
|
561
|
+
// (a style Chrome has just taken away reads as '': there is none)
|
|
562
|
+
if (!m.has(k)) m.set(k, k === 'style' ? el.getAttribute(k) || null : el.getAttribute(k));
|
|
562
563
|
kept.attrs.set(el, m);
|
|
563
564
|
if (v === null) el.removeAttribute(k); else el.setAttribute(k, v);
|
|
564
565
|
};
|
|
@@ -598,10 +599,10 @@ export function paint(svg: SVGSVGElement, S: SceneState, rendered?: Looks): void
|
|
|
598
599
|
}
|
|
599
600
|
}
|
|
600
601
|
const path = w.path && el.querySelector('path.flow');
|
|
601
|
-
if (path && w.path) { if (w.path.d !== undefined) set(path, 'd', w.path.d); if (w.path.style !== undefined) set(path, 'style', w.path.style); if (!w.path.head) set(path, 'marker-end', null); }
|
|
602
|
+
if (path && w.path) { if (w.path.d !== undefined) set(path, 'd', w.path.d); if (w.path.style !== undefined) { if (o.styles === 'cssom') { set(path, 'style', null); (path as SVGPathElement).style.cssText = w.path.style; } else set(path, 'style', w.path.style); } if (!w.path.head) set(path, 'marker-end', null); }
|
|
602
603
|
}
|
|
603
604
|
const anim = layer('anim');
|
|
604
|
-
if (anim) for (const [n, at] of overlay(S, pathOf)) make(n, at, anim);
|
|
605
|
+
if (anim) for (const [n, at] of overlay(S, pathOf, rendered?.inks)) make(n, at, anim);
|
|
605
606
|
}
|
|
606
607
|
|
|
607
608
|
// ---------- a compiled scene's plans ----------
|
package/src/iso-objects/scene.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// One scene → one SVG string. Pure: no DOM, so it runs the same in Node and in the browser.
|
|
2
2
|
|
|
3
|
+
import type { MonoLook } from '../iso-core/mono.ts';
|
|
3
4
|
import { type Attrs, type Box, type P2, Kernel, FONTS, S, tag, iso, pt, n1, esc, textWidth } from '../iso-core/kernel.ts';
|
|
4
5
|
import { drawCloud } from './assets.ts';
|
|
5
6
|
import { type KindCatalog, regionKind, nodeKindOr } from './kinds.ts';
|
|
@@ -27,6 +28,8 @@ export interface RenderedScene {
|
|
|
27
28
|
warnings: RenderWarning[];
|
|
28
29
|
/** (0.15.0) a self-contained drawing's own colours, for what a state adds to it (a token's rim and fill) */
|
|
29
30
|
inks?: { surface: string; control: string; kinds?: Record<string, string> };
|
|
31
|
+
/** (0.16.0) its black and white table, when it is in that treatment */
|
|
32
|
+
mono?: MonoLook;
|
|
30
33
|
/** the drawing with every thing that has a look of this name in it, as SVG text (what a switch takes the thing's parts from);
|
|
31
34
|
* none when nothing declares one */
|
|
32
35
|
variants?: Record<string, string>;
|
|
@@ -7,7 +7,8 @@ import { didYouMean } from '../iso-core/errors.ts';
|
|
|
7
7
|
import type { CompiledScene } from './compile.ts';
|
|
8
8
|
import { ANT_SPEED, antDash, antsOf } from './ants.ts';
|
|
9
9
|
import { silhouette, type Rect } from './labels.ts';
|
|
10
|
-
import { motionModel, planOf, type ItemState, type LabelState, type MotionPlan, type RouteState, type SceneState } from './motion.ts';
|
|
10
|
+
import { motionModel, planOf, type ItemState, type MotionModel, type LabelState, type MotionPlan, type RouteState, type SceneState } from './motion.ts';
|
|
11
|
+
import { focusView } from './focus.ts';
|
|
11
12
|
import { checkMotion, curveAt, easeOf, msOf, readMs, springAt, type Focus, type MotionDiag, type MotionDoc, type MotionNode, type Say, type Sequence, type SeriesItem, type Transition } from './motion-doc.ts';
|
|
12
13
|
|
|
13
14
|
export interface BeatInfo { name: string; index: number; start: number; end: number; say?: Say }
|
|
@@ -18,6 +19,10 @@ export interface Timeline {
|
|
|
18
19
|
readonly duration: number;
|
|
19
20
|
readonly beats: BeatInfo[];
|
|
20
21
|
readonly markers: Record<string, number>;
|
|
22
|
+
/** the document's own `ambient`: what at(ms) does with none given */
|
|
23
|
+
readonly ambient: 'on' | 'off';
|
|
24
|
+
/** whether anything in it runs on the ambient clock (ants, looping tokens and pulses): a host with none needs no frames while paused */
|
|
25
|
+
readonly loops: boolean;
|
|
21
26
|
/** what the drawing looks like at ms. `ambient`: the ambient clock's time (default: the same; a host that stopped it passes the time it
|
|
22
27
|
* stopped at, and what loops stands where it was), or 'off': it never ran, and each loop stands at its start */
|
|
23
28
|
at(ms: number, o?: { ambient?: number | 'off' }): SceneState;
|
|
@@ -27,7 +32,7 @@ export interface Timeline {
|
|
|
27
32
|
}
|
|
28
33
|
export interface BindOptions {
|
|
29
34
|
/** the connectors' dashes, by kind: the theme's `kinds` (a dashed kind marches with its own dash) */
|
|
30
|
-
kinds?: Record<string, { dash?: 'solid' | 'dashed' | 'dotted' }>;
|
|
35
|
+
kinds?: Record<string, { dash?: 'solid' | 'dashed' | 'dotted'; ants?: [number, number] }>;
|
|
31
36
|
/** kinds whose connectors stand still (default: blocked, planned) */
|
|
32
37
|
still?: string[];
|
|
33
38
|
}
|
|
@@ -84,16 +89,40 @@ class Sum {
|
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
/** What binding needs to know of a drawing, as plain JSON: for a page that has the drawing and no compiler. */
|
|
93
|
+
export interface MotionSource {
|
|
94
|
+
model: MotionModel;
|
|
95
|
+
/** each connector's kind */
|
|
96
|
+
kinds: Record<string, string>;
|
|
97
|
+
/** each thing's outline */
|
|
98
|
+
outlines: Record<string, [number, number][]>;
|
|
99
|
+
/** the looks each thing declares */
|
|
100
|
+
looks?: Record<string, string[]>;
|
|
101
|
+
ants?: ReturnType<typeof antsOf>;
|
|
102
|
+
/** the notes on nothing (JSON keeps no undefined) */
|
|
103
|
+
free?: string[];
|
|
104
|
+
}
|
|
105
|
+
export function motionSource(scene: CompiledScene): MotionSource {
|
|
106
|
+
const ants = antsOf(scene.raw), looks = scene.rendered.looks, model = motionModel(scene), free = Object.keys(model.notes).filter(n => model.notes[n] === undefined);
|
|
107
|
+
return {
|
|
108
|
+
model, kinds: Object.fromEntries(scene.routes.map(r => [r.id, r.kind])),
|
|
109
|
+
outlines: Object.fromEntries(scene.layout.items.map(p => [p.id, silhouette(p.box).map(q => [r2(q[0]), r2(q[1])] as [number, number])])),
|
|
110
|
+
...(looks && Object.keys(looks).length ? { looks } : {}), ...(ants ? { ants } : {}), ...(free.length ? { free } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function bindMotion(drawing: CompiledScene | MotionSource, doc: MotionDoc, opts: BindOptions = {}): Timeline {
|
|
115
|
+
const src = 'model' in drawing ? drawing : motionSource(drawing);
|
|
116
|
+
const m: MotionModel = src.free ? { ...src.model, notes: { ...src.model.notes, ...Object.fromEntries(src.free.map(n => [n, undefined])) } } : src.model;
|
|
117
|
+
const diags = checkMotion(doc), fps = doc.fps, fileAnts = src.ants;
|
|
118
|
+
const none = (): Timeline => ({ ok: false, diags, duration: 0, beats: [], markers: {}, ambient: 'on', loops: false, at: () => ({}), cues: () => undefined, beatAt: () => undefined, startOf: () => undefined });
|
|
90
119
|
if (diags.length) return none();
|
|
91
120
|
const err = (path: string, message: string, hint?: string) => { diags.push({ severity: 'error', path, message, ...(hint ? { hint } : {}) }); };
|
|
92
121
|
const ms = (t: unknown, otherwise: number) => (t === undefined ? otherwise : msOf(t, fps)!);
|
|
93
122
|
|
|
94
123
|
// ---------- what is in the drawing ----------
|
|
95
124
|
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));
|
|
96
|
-
const kindOf = new Map(
|
|
125
|
+
const kindOf = new Map(Object.entries(src.kinds));
|
|
97
126
|
const all = [...pieces.keys(), ...routes, ...notes];
|
|
98
127
|
const known = new Set(all);
|
|
99
128
|
/** what moves and fades with a thing or a connector: its own label, and the notes on it */
|
|
@@ -103,7 +132,7 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
|
|
|
103
132
|
const words = { any: 'thing, connector or note', thing: 'thing', route: 'connector' };
|
|
104
133
|
const need = (id: string, path: string, kind: keyof typeof what = 'any') => { if (!what[kind].has(id)) { const d = didYouMean(id, what[kind]); err(path, `no ${words[kind]} "${id}" in this drawing`, d ? `did you mean "${d}"?` : undefined); } };
|
|
105
134
|
const needAll = (v: string[] | undefined, path: string, kind: keyof typeof what = 'any') => v?.forEach((id, i) => need(id, `${path}/${i}`, kind));
|
|
106
|
-
const outline = new Map(
|
|
135
|
+
const outline = new Map(Object.entries(src.outlines));
|
|
107
136
|
|
|
108
137
|
// ---------- how long things are ----------
|
|
109
138
|
const plans = new Map<object, MotionPlan>();
|
|
@@ -222,7 +251,7 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
|
|
|
222
251
|
for (const id of Object.keys(s.levels ?? {})) if (id !== '*') need(id, `${path}/levels/${id}`);
|
|
223
252
|
for (const [id, name] of Object.entries(s.variants ?? {})) {
|
|
224
253
|
need(id, `${path}/variants/${id}`, 'thing');
|
|
225
|
-
const have =
|
|
254
|
+
const have = src.looks?.[id] ?? [];
|
|
226
255
|
if (pieces.has(id) && name !== '' && !have.includes(name)) { const d = didYouMean(name, have); 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}"?` : undefined); }
|
|
227
256
|
}
|
|
228
257
|
if (Array.isArray(s.ants)) needAll(s.ants, `${path}/ants`, 'route');
|
|
@@ -329,10 +358,12 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
|
|
|
329
358
|
const one = ms(n.each, 1150), hold = ms(n.hold, n.loop ? 700 : 0), period = n.travel.length * one + hold;
|
|
330
359
|
const q = n.loop ? turned(a - from, period, c) : lt, i = Math.floor(q / one);
|
|
331
360
|
if (i >= n.travel.length) return;
|
|
332
|
-
const f = easeOf(n.easing, one, 'ease-in-out')(
|
|
333
|
-
for (const x of Array.isArray(group) ? group : [group]) { const [id, kind] = x.split(':'); if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4(f), ...(kind ? { kind } : {}) }); }
|
|
361
|
+
const part = (q - i * one) / one, f = easeOf(n.easing, one, 'ease-in-out')(part), group = n.travel[i];
|
|
362
|
+
for (const x of Array.isArray(group) ? group : [group]) { const [id, kind] = x.split(':'); if (c.shown(id)) c.sum.tokens.push({ route: id, at: r4((kind ?? kindOf.get(id)) === 'blocked' ? stalled(part) : f), ...(kind ? { kind } : {}) }); }
|
|
334
363
|
}
|
|
335
364
|
}
|
|
365
|
+
/** a blocked token gets most of the way, stalls and falls back a little, as the page's steps have it */
|
|
366
|
+
const stalled = (f: number) => (f < 0.7 ? f / 0.7 : 1 - ((f - 0.7) / 0.3) * 0.25);
|
|
336
367
|
/** where in its turn a loop is: with the ambient off, at its start */
|
|
337
368
|
const turned = (x: number, period: number, c: Ctx) => (c.off ? 0 : ((x % period) + period) % period);
|
|
338
369
|
const ring = (id: string, amount: number, sum: Sum) => { if (r4(amount) > 0 && outline.has(id)) sum.outlines.push({ id, points: outline.get(id)!, ...(r4(amount) < 1 ? { opacity: r4(amount) } : {}) }); };
|
|
@@ -404,9 +435,19 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
|
|
|
404
435
|
return sum.state(cam && cam.some((v, i) => Math.abs(v - fit[i]) > 0.005) ? cam : undefined);
|
|
405
436
|
}
|
|
406
437
|
|
|
438
|
+
// whether anything anywhere is the ambient clock's
|
|
439
|
+
const moving = (n: unknown): boolean => {
|
|
440
|
+
if (!n || typeof n !== 'object') return false;
|
|
441
|
+
if (Array.isArray(n)) return n.some(moving);
|
|
442
|
+
const o = n as Record<string, unknown>;
|
|
443
|
+
if (o.ants !== undefined && o.ants !== false) return true;
|
|
444
|
+
if (o.loop === true && ('travel' in o || 'pulse' in o)) return true;
|
|
445
|
+
return Object.values(o).some(moving);
|
|
446
|
+
};
|
|
447
|
+
const loops = fileAnts !== undefined || moving(doc.series) || moving(doc.layers);
|
|
407
448
|
const beatAt = (t: number) => { const k = beatIndex(Math.max(0, Math.min(duration, t))); return k < 0 ? undefined : beats[k]; };
|
|
408
449
|
return {
|
|
409
|
-
ok: true, diags, duration, beats, markers, at, beatAt,
|
|
450
|
+
ok: true, diags, duration, beats, markers, ambient: doc.ambient ?? 'on', loops, at, beatAt,
|
|
410
451
|
startOf: n => starts.get(n) ?? beats.find(b => b.name === n)?.start,
|
|
411
452
|
cues(t) {
|
|
412
453
|
const b = beatAt(t);
|
|
@@ -424,18 +465,27 @@ function settleMs(c: { mass?: number; damping?: number; stiffness?: number }): n
|
|
|
424
465
|
|
|
425
466
|
/** A drawing's own steps as a motion document, so that every drawing with steps has a timeline. */
|
|
426
467
|
export function motionOfSteps(scene: CompiledScene): MotionDoc {
|
|
427
|
-
const { steps, vis } = scene.steps;
|
|
468
|
+
const { steps, vis } = scene.steps, full = scene.rendered.viewBox;
|
|
469
|
+
let zoomed = false;
|
|
470
|
+
const m = motionModel(scene), ids = new Set([...m.pieces.map(p => p.id), ...m.routes.map(r => r.id), ...Object.keys(m.notes)]), has = (id: string) => ids.has(id);
|
|
471
|
+
// (a note on nothing is no connector's)
|
|
472
|
+
const free = Object.keys(m.notes).filter(n => m.notes[n] === undefined);
|
|
428
473
|
const series: SeriesItem[] = steps.map((st, i) => {
|
|
429
474
|
const show: string[] = [], hide: string[] = [];
|
|
430
475
|
// (an id first shown is hidden until then, and one first hidden is there until then: so only the changes are said)
|
|
431
476
|
for (const [id, v] of Object.entries(vis)) { if (i === 0 ? !v.includes(true) : v[i - 1] && !v[i]) hide.push(id); else if (i > 0 ? v[i] && !v[i - 1] : false) show.push(id); }
|
|
432
477
|
const children: MotionNode[] = [];
|
|
433
|
-
|
|
478
|
+
const token = (t: { route: string; kind: string }) => `${t.route}:${t.kind}`;
|
|
479
|
+
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 });
|
|
434
480
|
const pulse = ((scene.raw.steps ?? [])[i] as { pulse?: string[] } | undefined)?.pulse?.filter(id => scene.layout.byId.has(id)) ?? [];
|
|
435
481
|
if (pulse.length) children.push({ pulse, loop: true });
|
|
482
|
+
// a step's focus is where the camera goes, and back out with the first step that has none
|
|
483
|
+
if (st.focus) { const [x, y, w, h] = focusView(full, st.focus).map(r2); children.push({ camera: { focus: [x, y, w, h] }, duration: 900, easing: 'ease-in-out' }); zoomed = true; } else if (zoomed) { children.push({ camera: 'fit', duration: 900, easing: 'ease-in-out' }); zoomed = false; }
|
|
436
484
|
const s: Sequence = { name: `step-${st.n}`, duration: st.duration, say: { title: st.heading, ...(st.caption ? { text: st.caption } : {}), ...(st.command ? { code: st.command } : {}) } };
|
|
437
485
|
if (show.length) s.show = show;
|
|
438
486
|
if (hide.length) s.hide = hide;
|
|
487
|
+
// what a step doesn't touch dims, as on its page: the connectors and notes, or everything (the scene's `dim`)
|
|
488
|
+
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 } : {}) };
|
|
439
489
|
if (children.length) s.children = children;
|
|
440
490
|
return { sequence: s };
|
|
441
491
|
});
|
package/src/iso-objects/types.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface RawDiagram {
|
|
|
60
60
|
isodiag: 1; title?: string; lede?: string; pills?: string[]; theme?: string;
|
|
61
61
|
roles?: Record<string, RawRole>; kinds?: Record<string, RawKind>; after?: string; footer?: string;
|
|
62
62
|
grid?: GridDef; assemble?: boolean;
|
|
63
|
+
/** how a self-contained drawing of it is painted, where the host doesn't say */
|
|
64
|
+
treatment?: 'mono';
|
|
63
65
|
scenes: RawScene[];
|
|
64
66
|
}
|
|
65
67
|
|