@johnoscott/isometric-engine 0.15.0 → 0.17.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.
Files changed (78) hide show
  1. package/README.md +3 -1
  2. package/iso-editor.js +230 -193
  3. package/iso-remotion.js +353 -0
  4. package/iso-render.js +184 -147
  5. package/iso-systems.js +183 -146
  6. package/isometric-diagram.js +389 -0
  7. package/js/iso-core/arimo.js +5 -0
  8. package/js/iso-core/arimo.json +1 -0
  9. package/js/iso-core/index.js +8 -2
  10. package/js/iso-core/kernel.js +13 -2
  11. package/js/iso-core/mono.js +242 -0
  12. package/js/iso-editor/ui/canvas.js +23 -1
  13. package/js/iso-objects/ants.js +1 -1
  14. package/js/iso-objects/index.js +10 -2
  15. package/js/iso-objects/mono-paint.js +96 -0
  16. package/js/iso-objects/motion-doc.js +0 -79
  17. package/js/iso-objects/motion-entry.js +4 -2
  18. package/js/iso-objects/motion-schema.js +83 -0
  19. package/js/iso-objects/motion.js +9 -4
  20. package/js/iso-objects/timeline.js +60 -16
  21. package/js/iso-systems/compile.js +34 -3
  22. package/js/iso-systems/render.js +1 -1
  23. package/js/iso-systems/schema.json +1 -0
  24. package/js/iso-viewer/index.js +6 -0
  25. package/js/iso-viewer/page.js +40 -17
  26. package/js/iso-viewer/play.js +340 -0
  27. package/js/iso-viewer/player.js +147 -162
  28. package/js/iso-viewer/transport.js +289 -0
  29. package/package.json +61 -2
  30. package/src/iso-core/arimo.json +1 -0
  31. package/src/iso-core/arimo.ts +6 -0
  32. package/src/iso-core/index.ts +2 -1
  33. package/src/iso-core/kernel.ts +11 -1
  34. package/src/iso-core/mono.ts +306 -0
  35. package/src/iso-core/theme.ts +2 -1
  36. package/src/iso-editor/ui/canvas.ts +14 -1
  37. package/src/iso-objects/ants.ts +2 -2
  38. package/src/iso-objects/index.ts +5 -3
  39. package/src/iso-objects/mono-paint.ts +97 -0
  40. package/src/iso-objects/motion-doc.ts +0 -52
  41. package/src/iso-objects/motion-entry.ts +4 -3
  42. package/src/iso-objects/motion-schema.ts +55 -0
  43. package/src/iso-objects/motion.ts +6 -5
  44. package/src/iso-objects/scene.ts +3 -0
  45. package/src/iso-objects/timeline.ts +71 -15
  46. package/src/iso-objects/types.ts +2 -0
  47. package/src/iso-systems/compile.ts +37 -4
  48. package/src/iso-systems/render.ts +5 -1
  49. package/src/iso-systems/schema.json +1 -0
  50. package/src/iso-viewer/index.ts +4 -0
  51. package/src/iso-viewer/page.ts +28 -12
  52. package/src/iso-viewer/play.ts +280 -0
  53. package/src/iso-viewer/player.ts +133 -134
  54. package/src/iso-viewer/transport.ts +272 -0
  55. package/types/iso-core/arimo.d.ts +2 -0
  56. package/types/iso-core/index.d.ts +2 -1
  57. package/types/iso-core/kernel.d.ts +9 -0
  58. package/types/iso-core/mono.d.ts +61 -0
  59. package/types/iso-core/theme.d.ts +2 -0
  60. package/types/iso-objects/ants.d.ts +1 -0
  61. package/types/iso-objects/index.d.ts +5 -3
  62. package/types/iso-objects/mono-paint.d.ts +20 -0
  63. package/types/iso-objects/motion-doc.d.ts +0 -594
  64. package/types/iso-objects/motion-entry.d.ts +4 -3
  65. package/types/iso-objects/motion-schema.d.ts +594 -0
  66. package/types/iso-objects/motion.d.ts +4 -2
  67. package/types/iso-objects/scene.d.ts +3 -0
  68. package/types/iso-objects/timeline.d.ts +26 -3
  69. package/types/iso-objects/types.d.ts +2 -0
  70. package/types/iso-systems/compile.d.ts +8 -0
  71. package/types/iso-systems/render.d.ts +4 -0
  72. package/types/iso-viewer/index.d.ts +4 -0
  73. package/types/iso-viewer/play.d.ts +37 -0
  74. package/types/iso-viewer/transport.d.ts +73 -0
  75. package/types/player/isometric-diagram.d.ts +24 -0
  76. package/types/remotion/entry.d.ts +2 -0
  77. package/types/remotion/frames.d.ts +70 -0
  78. package/types/remotion/index.d.ts +39 -0
@@ -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
- if (!m.has(k)) m.set(k, el.getAttribute(k));
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 ----------
@@ -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
- export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptions = {}): Timeline {
88
- const diags = checkMotion(doc), m = motionModel(scene), fps = doc.fps, fileAnts = antsOf(scene.raw);
89
- const none = (): Timeline => ({ ok: false, diags, duration: 0, beats: [], markers: {}, at: () => ({}), cues: () => undefined, beatAt: () => undefined, startOf: () => undefined });
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(scene.routes.map(r => [r.id, r.kind]));
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(scene.layout.items.map(p => [p.id, silhouette(p.box).map(q => [r2(q[0]), r2(q[1])] as [number, number])]));
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>();
@@ -155,7 +184,7 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
155
184
  items.forEach((it, i) => {
156
185
  if ('transition' in it) {
157
186
  const t = it.transition, g = t.timing;
158
- const length = t.presentation === 'none' ? 0 : 'linear' in g ? ms(g.linear, 0) : ms(g.spring.duration, settleMs(g.spring));
187
+ const length = t.presentation === 'none' ? 0 : transitionMs(g, fps);
159
188
  into = { t, length };
160
189
  return;
161
190
  }
@@ -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 = scene.rendered.looks?.[id] ?? [];
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');
@@ -272,7 +301,7 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
272
301
  /** how much of beat k has come in at T (1: all of it) */
273
302
  const entered = (k: number, T: number) => {
274
303
  const p = top.list[k], lt = T - p.start;
275
- if (p.into && p.into.length > 0) { const g = p.into.t.timing; return 'spring' in g ? (lt >= p.into.length ? 1 : clamp(springAt(lt, { ...g.spring, overshootClamping: true }) / springAt(p.into.length, { ...g.spring, overshootClamping: true }))) : clamp(lt / p.into.length); }
304
+ if (p.into && p.into.length > 0) return transitionAt(p.into.t.timing, lt, p.into.length);
276
305
  const e = p.s.enter; if (!e) return 1;
277
306
  const over = ms(e.fade, 0);
278
307
  return over <= 0 ? 1 : easeOf(e.easing, over, 'ease')(clamp(lt / over));
@@ -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')((q - i * one) / one), group = n.travel[i];
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);
@@ -416,6 +457,12 @@ export function bindMotion(scene: CompiledScene, doc: MotionDoc, opts: BindOptio
416
457
  },
417
458
  };
418
459
  }
460
+ /** how long a transition is, ms, and how far it is in at t of them */
461
+ export const transitionMs = (g: Transition['timing'], fps?: number): number => ('linear' in g ? msOf(g.linear, fps) ?? 0 : msOf(g.spring.duration, fps) ?? settleMs(g.spring));
462
+ export function transitionAt(g: Transition['timing'], t: number, length: number): number {
463
+ if (length <= 0 || t >= length) return 1;
464
+ return 'spring' in g ? clamp(springAt(t, { ...g.spring, overshootClamping: true }) / springAt(length, { ...g.spring, overshootClamping: true })) : clamp(t / length);
465
+ }
419
466
  /** how long a spring takes to come to rest, ms: its envelope under half a percent */
420
467
  function settleMs(c: { mass?: number; damping?: number; stiffness?: number }): number {
421
468
  const m = c.mass ?? 1, k = c.stiffness ?? 100, d = c.damping ?? 10, w0 = Math.sqrt(k / m), z = Math.min(1, d / (2 * Math.sqrt(k * m)));
@@ -424,18 +471,27 @@ function settleMs(c: { mass?: number; damping?: number; stiffness?: number }): n
424
471
 
425
472
  /** A drawing's own steps as a motion document, so that every drawing with steps has a timeline. */
426
473
  export function motionOfSteps(scene: CompiledScene): MotionDoc {
427
- const { steps, vis } = scene.steps;
474
+ const { steps, vis } = scene.steps, full = scene.rendered.viewBox;
475
+ let zoomed = false;
476
+ 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);
477
+ // (a note on nothing is no connector's)
478
+ const free = Object.keys(m.notes).filter(n => m.notes[n] === undefined);
428
479
  const series: SeriesItem[] = steps.map((st, i) => {
429
480
  const show: string[] = [], hide: string[] = [];
430
481
  // (an id first shown is hidden until then, and one first hidden is there until then: so only the changes are said)
431
482
  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
483
  const children: MotionNode[] = [];
433
- if (st.phases.length) children.push({ travel: st.phases.map(g => (g.length === 1 ? g[0].route : g.map(t => t.route))), each: 1150, hold: 700, loop: true });
484
+ const token = (t: { route: string; kind: string }) => `${t.route}:${t.kind}`;
485
+ 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
486
  const pulse = ((scene.raw.steps ?? [])[i] as { pulse?: string[] } | undefined)?.pulse?.filter(id => scene.layout.byId.has(id)) ?? [];
435
487
  if (pulse.length) children.push({ pulse, loop: true });
488
+ // a step's focus is where the camera goes, and back out with the first step that has none
489
+ 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
490
  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
491
  if (show.length) s.show = show;
438
492
  if (hide.length) s.hide = hide;
493
+ // what a step doesn't touch dims, as on its page: the connectors and notes, or everything (the scene's `dim`)
494
+ 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
495
  if (children.length) s.children = children;
440
496
  return { sequence: s };
441
497
  });
@@ -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
 
@@ -4,10 +4,14 @@ import { parse, type Parsed } from '../iso-core/parse.ts';
4
4
  import { validateSchema } from './validate.ts';
5
5
  import type { Diag } from '../iso-core/errors.ts';
6
6
  import { place } from '../iso-objects/place.ts';
7
- import { extendTheme, loadTheme } from '../iso-core/theme.ts';
7
+ import { extendTheme, loadTheme, type Theme } from '../iso-core/theme.ts';
8
8
  import type { RawDiagram } from '../iso-objects/types.ts';
9
9
  import { compileRaw, type Compiled } from '../iso-objects/compile.ts';
10
- import { resolveSvg, type ThemeMode } from '../iso-objects/resolve.ts';
10
+ import { FONT_STACKS, resolveSvg, type ThemeMode } from '../iso-objects/resolve.ts';
11
+ import { monoOfDrawing, paintMono } from '../iso-objects/mono-paint.ts';
12
+ import type { MonoTable } from '../iso-core/mono.ts';
13
+ import type { CompiledScene } from '../iso-objects/compile.ts';
14
+ import { withFont, type FontTable } from '../iso-core/kernel.ts';
11
15
  import { bindMotion } from '../iso-objects/timeline.ts';
12
16
  import type { MotionDoc } from '../iso-objects/motion-doc.ts';
13
17
  import { antsOf } from '../iso-objects/ants.ts';
@@ -24,6 +28,12 @@ export interface CompileOptions {
24
28
  /** (0.15.0) self-contained drawings: each scene's SVG has its colours and text styles on its elements, in `mode`: no
25
29
  * stylesheet, no custom properties, no hsl() or color-mix() (svgAt's frames too) */
26
30
  resolveVars?: boolean;
31
+ /** (0.16.0) a self-contained drawing in black and white, in either mode: greys, patterns and line rhythms, and no hue */
32
+ treatment?: 'mono' | 'none';
33
+ /** a host's own table, over the treatment's */
34
+ mono?: MonoTable;
35
+ /** (0.17.0) a self-contained drawing laid out with another font's widths (Arimo's: modules/iso-core/arimo), and asking for it. The host loads the font */
36
+ font?: FontTable;
27
37
  /** a file with an error draws nothing: `scenes` is empty (true), or it throws ('throw'). Default: what could be laid
28
38
  * out is in `scenes` all the same, with `ok` false */
29
39
  strict?: boolean | 'throw';
@@ -36,20 +46,43 @@ export class CompileError extends Error {
36
46
  }
37
47
 
38
48
  export function compile(source: string, themeText: string, opts: CompileOptions = {}): Compiled {
39
- const c = compileAll(source, themeText, opts);
49
+ if (opts.font && !opts.resolveVars) throw new Error('font: a self-contained drawing\'s (resolveVars)');
50
+ const c = withFont(opts.font, () => compileAll(source, themeText, opts)), fonts = opts.font && { sans: opts.font.sans, mono: opts.font.mono ?? FONT_STACKS.mono };
40
51
  if (!c.ok && opts.strict === 'throw') throw new CompileError(c.diags);
41
52
  if (!c.ok && opts.strict) c.scenes = [];
42
53
  if (opts.stepMs !== undefined) for (const s of c.scenes) for (const st of s.steps.steps) st.duration = opts.stepMs;
54
+ if (opts.treatment !== undefined && opts.treatment !== 'mono' && opts.treatment !== 'none') throw new Error(`treatment: there is "mono" (and "none"), and no ${JSON.stringify(opts.treatment)}`);
55
+ const treatment = (opts.treatment ?? c.doc?.treatment) === 'mono';
56
+ if (opts.treatment === 'mono' && !opts.resolveVars) throw new Error('treatment: a self-contained drawing\'s (resolveVars)');
57
+ const theme = c.theme;
43
58
  if (opts.resolveVars) for (const s of c.scenes) {
44
- const o = { mode: opts.mode ?? 'light', theme: c.theme!, css: drawingCss(systems) + MARKS_CSS + GRID_CSS } as const;
59
+ const mode = opts.mode ?? 'light', css = drawingCss(systems) + MARKS_CSS + GRID_CSS;
60
+ if (treatment) { toMono(s, theme!, mode, css, opts.mono, fonts); continue; }
61
+ const o = { mode, theme: c.theme!, css, fonts } as const;
45
62
  s.rendered.svg = resolveSvg(s.rendered.svg, o);
46
63
  if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, resolveSvg(v, o)]));
47
64
  s.rendered.inks = { surface: c.theme![o.mode].surface ?? c.theme!.light.surface, control: c.theme![o.mode].control ?? c.theme!.light.control,
48
65
  kinds: Object.fromEntries(Object.entries(c.theme!.kinds).map(([k, v]) => [k, c.theme![o.mode][v.color] ?? v.color])) };
49
66
  }
67
+ // it says which font it was laid out with (nothing: the default)
68
+ if (opts.font) for (const s of c.scenes) { const name = opts.font.name, mark = (svg: string) => svg.replace('<svg ', `<svg data-font="${name.replace(/[^\w-]/g, '')}" `); s.rendered.svg = mark(s.rendered.svg); if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, mark(v)])); }
69
+ // its connectors march in their own rhythms
70
+ if (opts.resolveVars && treatment && theme) c.theme = { ...theme, kinds: Object.fromEntries(Object.entries(theme.kinds).map(([k, v]) => { const d = c.scenes.map(s => s.rendered.mono?.kinds[k]?.dash).find(x => x && x.length > 1); return [k, d ? { ...v, ants: [d[0], d[1]] as [number, number] } : v]; })) };
50
71
  return c;
51
72
  }
52
73
 
74
+ /** a scene in black and white: its drawing and its looks alike, by one table */
75
+ function toMono(s: CompiledScene, theme: Theme, mode: ThemeMode, css: string, own?: MonoTable, fonts?: { sans: string; mono: string }) {
76
+ const all = [s.rendered.svg, ...Object.values(s.rendered.variants ?? {})];
77
+ const m = monoOfDrawing(all.join(''), theme, mode, [...s.routes.map(r => r.kind), ...s.steps.kindsUsed], own);
78
+ const draw = (svg: string) => paintMono(resolveSvg(svg, { mode, theme: m.theme, css: css + m.css, fonts }), m.look, s.id);
79
+ s.rendered.svg = draw(s.rendered.svg);
80
+ if (s.rendered.variants) s.rendered.variants = Object.fromEntries(Object.entries(s.rendered.variants).map(([k, v]) => [k, draw(v)]));
81
+ s.rendered.inks = { surface: m.look.paper, control: m.look.ink, kinds: Object.fromEntries(Object.keys(theme.kinds).map(k => [k, m.look.ink])) };
82
+ s.rendered.mono = m.look;
83
+ for (const w of m.look.warnings) s.rendered.warnings.push({ path: '', message: `black and white: ${w}` });
84
+ }
85
+
53
86
  function compileAll(source: string, themeText: string, opts: { snap?: number }): Compiled {
54
87
  const parsed = parse(source);
55
88
  const diags: Diag[] = [...parsed.diags];
@@ -6,12 +6,16 @@ import { svgAt } from '../iso-objects/motion.ts';
6
6
  import { bindMotion } from '../iso-objects/timeline.ts';
7
7
  import type { MotionDoc } from '../iso-objects/motion-doc.ts';
8
8
  import { compile } from './compile.ts';
9
+ import type { MonoTable } from '../iso-core/mono.ts';
9
10
  import type { ThemeMode } from '../iso-objects/resolve.ts';
10
11
 
11
12
  export interface RenderSvgOptions {
12
13
  /** the theme's text */
13
14
  theme: string;
14
15
  mode?: ThemeMode;
16
+ /** black and white, in either mode, and a host's own table for it */
17
+ treatment?: 'mono' | 'none';
18
+ mono?: MonoTable;
15
19
  /** which scene: its id or its place (default: the first) */
16
20
  scene?: string | number;
17
21
  /** a moment of its motion, ms: the still without it */
@@ -27,7 +31,7 @@ export interface RenderSvgOptions {
27
31
 
28
32
  /** Throws, with every fault and its line, when the file or its motion has one. */
29
33
  export function renderSvg(source: string, o: RenderSvgOptions): string {
30
- const c = compile(source, o.theme, { mode: o.mode ?? 'light', resolveVars: true, strict: 'throw' }), kinds = c.theme!.kinds;
34
+ const c = compile(source, o.theme, { mode: o.mode ?? 'light', resolveVars: true, strict: 'throw', treatment: o.treatment, mono: o.mono }), kinds = c.theme!.kinds;
31
35
  const s = o.scene === undefined ? c.scenes[0] : typeof o.scene === 'number' ? c.scenes[o.scene] : c.scenes.find(x => x.id === o.scene);
32
36
  if (!s) throw new Error(`no scene ${JSON.stringify(o.scene)} (there ${c.scenes.length === 1 ? 'is' : 'are'} ${c.scenes.map(x => x.id).join(', ')})`);
33
37
  const ants = o.ants === undefined ? antsOf(s.raw) : o.ants === true ? antsOf(s.raw) ?? {} : o.ants || undefined;
@@ -26,6 +26,7 @@
26
26
  "grid": { "$ref": "#/$defs/grid" },
27
27
  "assemble": { "type": "boolean", "description": "draw each scene by flying its parts in from the nearest edge, then play" },
28
28
  "footer": { "type": "string" },
29
+ "treatment": { "enum": ["mono"], "description": "How a self-contained drawing (renderSvg, <isometric-diagram>) is painted: mono, black and white. A host may say otherwise. The page isodiag build writes is in colour." },
29
30
  "scenes": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/scene" } }
30
31
  },
31
32
  "$defs": {
@@ -17,6 +17,10 @@ export { isoVars, scopeSelector, scope } from './view-css.ts';
17
17
  export { md, stepData, legend, renderPage } from './page.ts';
18
18
  export type { PageOpts } from './page.ts';
19
19
  export { playerScript } from './bundle.ts';
20
+ export { transport, pageClock } from './transport.ts';
21
+ export type { Transport, TransportClock, TransportEvents, TransportOptions } from './transport.ts';
22
+ export { mountPlayer, PLAY_CSS } from './play.ts';
23
+ export type { Player, PlayerOptions } from './play.ts';
20
24
  export { h } from './dom.ts';
21
25
  export { TIMELINE_VERSION, SEGMENT_NAME, SEVERITIES, BINS, BIN_MS, scopePattern } from './timeline-contract.ts';
22
26
  export type { TimelineTypes, AnyTimeline, Scope, Severity, AttrValue, TimelineEvent, Bin, MetricPoint, MetricRollup, EventBin, Match, AstTerm, SearchAst, Days, Retention, SeriesInfo, KindInfo, SourceInfo, EffectiveRetention, ScopeName, Catalog, Filters, Query, Row, Result, Batch, View as TimelineView, Recording, TimelineSource, TimelineCatalog } from './timeline-contract.ts';
@@ -1,6 +1,7 @@
1
1
  // The HTML page around the scenes: header, one section per scene, theme toggle. One file, no network.
2
2
 
3
- import { motionModel } from '../iso-objects/motion.ts';
3
+ import { bindMotion, motionOfSteps, motionSource } from '../iso-objects/timeline.ts';
4
+ import type { StepData } from '../iso-objects/steps.ts';
4
5
  import { esc } from '../iso-core/kernel.ts';
5
6
  import type { Compiled } from '../iso-objects/compile.ts';
6
7
  import { themeCss } from '../iso-core/theme.ts';
@@ -26,14 +27,29 @@ const paras = (s: string | undefined) => (s ?? '').split(/\n\s*\n/).filter(Boole
26
27
 
27
28
  export interface PageOpts { runtime?: string; extraHead?: string; extraBody?: string }
28
29
 
30
+ /** a scene's own motion, where it has any that binds: what its page plays, in place of its steps */
31
+ const ownMotion = (c: Compiled, s: CompiledScene) => !!s.motion && bindMotion(s, s.motion, { kinds: c.theme!.kinds }).ok;
32
+ /** what the page steps through: the scene's steps, or the beats of its own motion */
33
+ function stepsOf(c: Compiled, s: CompiledScene): StepData[] {
34
+ if (!ownMotion(c, s)) return s.steps.steps;
35
+ return bindMotion(s, s.motion!, { kinds: c.theme!.kinds }).beats.map(b => ({
36
+ n: b.index + 1, num: b.index + 1, kind: 'control', color: b.say?.color ?? colorRef(c.theme!, c.theme!.kinds.control?.color ?? 'control'),
37
+ heading: b.say?.title ?? b.name, caption: b.say?.text ?? '', command: b.say?.code ?? '', phases: [], pulses: [], lit: [], duration: b.end - b.start,
38
+ }));
39
+ }
40
+
29
41
  /** The data the player runs on, for every scene with steps. */
30
42
  export function stepData(c: Compiled): string {
31
43
  return JSON.stringify({
32
- scenes: c.scenes.map(s => ({
33
- id: s.id, loop: s.raw.loop ?? true, dim: s.raw.dim ?? 'flows', vis: s.steps.vis,
34
- steps: s.steps.steps.map(st => ({ ...st, caption: md(st.caption) })),
35
- assemble: s.assemble, grid: !!s.grid.show, motion: motionModel(s),
36
- })),
44
+ scenes: c.scenes.map(s => {
45
+ const own = ownMotion(c, s), steps = stepsOf(c, s), doc = own ? s.motion : s.steps.steps.length ? motionOfSteps(s) : undefined;
46
+ return {
47
+ id: s.id, loop: s.raw.loop ?? true, dim: s.raw.dim ?? 'flows', vis: s.steps.vis,
48
+ // (where a step's view goes is its document's camera)
49
+ steps: steps.map(({ focus: _, ...st }) => ({ ...st, caption: md(st.caption) })),
50
+ assemble: s.assemble, grid: !!s.grid.show, source: motionSource(s), ...(doc ? { doc } : {}), ...(own ? { own } : {}),
51
+ };
52
+ }),
37
53
  });
38
54
  }
39
55
 
@@ -58,8 +74,8 @@ export function legend(c: Compiled, s: CompiledScene): string {
58
74
  return items.join('');
59
75
  }
60
76
 
61
- function player(s: CompiledScene): string {
62
- const st = s.steps.steps;
77
+ function player(c: Compiled, s: CompiledScene): string {
78
+ const st = stepsOf(c, s);
63
79
  const tools = `<div class="tools">
64
80
  <button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? 'true' : 'false'}" title="Show the floor grid">Grid</button>
65
81
  <button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
@@ -83,8 +99,8 @@ function player(s: CompiledScene): string {
83
99
  </div>`;
84
100
  }
85
101
 
86
- function stepList(s: CompiledScene): string {
87
- const st = s.steps.steps;
102
+ function stepList(c: Compiled, s: CompiledScene): string {
103
+ const st = stepsOf(c, s);
88
104
  if (!st.length) return '';
89
105
  return `<details class="steps"><summary>All ${st.length} steps as text</summary><ol>${st.map(x =>
90
106
  `<li value="${x.num}"><b>${esc(x.heading)}.</b> ${md(x.caption)}${x.command ? `<br><code>${esc(x.command)}</code>` : ''}</li>`).join('')}</ol></details>`;
@@ -99,10 +115,10 @@ export function renderPage(c: Compiled, opts: PageOpts = {}): string {
99
115
  ${paras(s.raw.caption)}
100
116
  <div class="figure" tabindex="-1">
101
117
  <div class="scroller">${s.grid.show ? s.rendered.svg.replace('<svg ', '<svg class="show-grid" ') : s.rendered.svg}</div>
102
- ${player(s)}
118
+ ${player(c, s)}
103
119
  <div class="legend">${legend(c, s)}</div>
104
120
  </div>
105
- ${stepList(s)}
121
+ ${stepList(c, s)}
106
122
  ${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ''}
107
123
  </section>`).join('\n');
108
124
  return `<!doctype html>