@johnoscott/isometric-engine 0.0.0-stage → 0.9.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/EDITOR-GUIDE.md +317 -0
- package/LICENSE +21 -0
- package/LICENSES/ajv.txt +22 -0
- package/LICENSES/lucide-static.txt +43 -0
- package/LICENSES/yaml.txt +13 -0
- package/README.md +62 -2
- package/assets/app.css +265 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +35 -0
- package/assets/skin.css +181 -0
- package/iso-editor.d.ts +4 -0
- package/iso-editor.js +550 -0
- package/iso-render.d.ts +3 -0
- package/iso-render.js +388 -0
- package/iso-systems.d.ts +4 -0
- package/iso-systems.js +389 -0
- package/js/iso-core/compile-schema.js +22 -0
- package/js/iso-core/depth.js +55 -0
- package/js/iso-core/errors.js +65 -0
- package/js/iso-core/glyphs.js +100 -0
- package/js/iso-core/index.js +55 -0
- package/js/iso-core/kernel.js +158 -0
- package/js/iso-core/metrics.json +1 -0
- package/js/iso-core/package.json +6 -0
- package/js/iso-core/parse.js +79 -0
- package/js/iso-core/schema-errors.js +170 -0
- package/js/iso-core/shims/crypto.js +125 -0
- package/js/iso-core/shims/path.js +49 -0
- package/js/iso-core/svg-dom.js +144 -0
- package/js/iso-core/theme.js +48 -0
- package/js/iso-core/vdom.js +48 -0
- package/js/iso-editor/adapter.js +0 -0
- package/js/iso-editor/clipboard.js +152 -0
- package/js/iso-editor/commands.js +173 -0
- package/js/iso-editor/complete.js +55 -0
- package/js/iso-editor/doc.js +182 -0
- package/js/iso-editor/index.js +105 -0
- package/js/iso-editor/model.js +210 -0
- package/js/iso-editor/outline.js +111 -0
- package/js/iso-editor/package.json +6 -0
- package/js/iso-editor/path.js +19 -0
- package/js/iso-editor/providers.js +96 -0
- package/js/iso-editor/schema-nav.js +117 -0
- package/js/iso-editor/splice.js +441 -0
- package/js/iso-editor/storage-keys.js +6 -0
- package/js/iso-editor/ui/actions.js +116 -0
- package/js/iso-editor/ui/canvas-layer.js +0 -0
- package/js/iso-editor/ui/canvas.js +1205 -0
- package/js/iso-editor/ui/clip.js +133 -0
- package/js/iso-editor/ui/dialog.js +26 -0
- package/js/iso-editor/ui/flat-canvas.js +54 -0
- package/js/iso-editor/ui/icons.js +15 -0
- package/js/iso-editor/ui/keys.js +26 -0
- package/js/iso-editor/ui/later.js +28 -0
- package/js/iso-editor/ui/layer.js +11 -0
- package/js/iso-editor/ui/menu.js +105 -0
- package/js/iso-editor/ui/monaco-entry.js +2 -0
- package/js/iso-editor/ui/mount-kit.js +0 -0
- package/js/iso-editor/ui/mount.js +767 -0
- package/js/iso-editor/ui/pane.js +0 -0
- package/js/iso-editor/ui/part.js +0 -0
- package/js/iso-editor/ui/plain-icons.js +34 -0
- package/js/iso-editor/ui/props.js +314 -0
- package/js/iso-editor/ui/scope-css.js +81 -0
- package/js/iso-editor/ui/setup.js +145 -0
- package/js/iso-editor/ui/text.js +323 -0
- package/js/iso-editor/ui/tree.js +728 -0
- package/js/iso-editor/validate.js +33 -0
- package/js/iso-editor/window/protocol.js +8 -0
- package/js/iso-objects/assemble.js +43 -0
- package/js/iso-objects/assets.js +88 -0
- package/js/iso-objects/board.js +162 -0
- package/js/iso-objects/compile.js +60 -0
- package/js/iso-objects/css.js +154 -0
- package/js/iso-objects/flat.js +696 -0
- package/js/iso-objects/focus.js +16 -0
- package/js/iso-objects/geometry.js +76 -0
- package/js/iso-objects/index.js +93 -0
- package/js/iso-objects/kinds.js +12 -0
- package/js/iso-objects/labels.js +325 -0
- package/js/iso-objects/package.json +6 -0
- package/js/iso-objects/place.js +347 -0
- package/js/iso-objects/route.js +461 -0
- package/js/iso-objects/scene.js +350 -0
- package/js/iso-objects/steps.js +246 -0
- package/js/iso-objects/types.js +0 -0
- package/js/iso-systems/catalog.js +42 -0
- package/js/iso-systems/compile.js +34 -0
- package/js/iso-systems/css.js +8 -0
- package/js/iso-systems/index.js +16 -0
- package/js/iso-systems/nodes.js +124 -0
- package/js/iso-systems/package.json +6 -0
- package/js/iso-systems/schema.json +311 -0
- package/js/iso-systems/validate.js +35 -0
- package/js/iso-viewer/bundle.js +20 -0
- package/js/iso-viewer/card-motion.js +228 -0
- package/js/iso-viewer/dom.js +14 -0
- package/js/iso-viewer/dual-view.js +212 -0
- package/js/iso-viewer/flat-view.js +124 -0
- package/js/iso-viewer/history.js +990 -0
- package/js/iso-viewer/index.js +98 -0
- package/js/iso-viewer/morph.js +192 -0
- package/js/iso-viewer/overlay.js +199 -0
- package/js/iso-viewer/package.json +6 -0
- package/js/iso-viewer/page.js +138 -0
- package/js/iso-viewer/player.js +409 -0
- package/js/iso-viewer/still.js +81 -0
- package/js/iso-viewer/timeline-contract.js +14 -0
- package/js/iso-viewer/timeline-engine.js +475 -0
- package/js/iso-viewer/timeline-export.js +36 -0
- package/js/iso-viewer/timeline-scale.js +116 -0
- package/js/iso-viewer/timeline-scope.js +58 -0
- package/js/iso-viewer/timeline-search.js +216 -0
- package/js/iso-viewer/timeline-time.js +55 -0
- package/js/iso-viewer/view-css.js +68 -0
- package/js/iso-viewer/viewport.js +177 -0
- package/package.json +502 -4
- package/src/iso-core/compile-schema.ts +23 -0
- package/src/iso-core/depth.ts +56 -0
- package/src/iso-core/errors.ts +73 -0
- package/src/iso-core/glyphs.ts +108 -0
- package/src/iso-core/index.ts +27 -0
- package/src/iso-core/kernel.ts +163 -0
- package/src/iso-core/metrics.json +1 -0
- package/src/iso-core/package.json +6 -0
- package/src/iso-core/parse.ts +91 -0
- package/src/iso-core/schema-errors.ts +163 -0
- package/src/iso-core/shims/crypto.ts +37 -0
- package/src/iso-core/shims/path.ts +24 -0
- package/src/iso-core/svg-dom.ts +103 -0
- package/src/iso-core/theme.ts +64 -0
- package/src/iso-core/vdom.ts +41 -0
- package/src/iso-editor/adapter.ts +128 -0
- package/src/iso-editor/clipboard.ts +163 -0
- package/src/iso-editor/commands.ts +191 -0
- package/src/iso-editor/complete.ts +73 -0
- package/src/iso-editor/doc.ts +207 -0
- package/src/iso-editor/index.ts +67 -0
- package/src/iso-editor/model.ts +234 -0
- package/src/iso-editor/outline.ts +126 -0
- package/src/iso-editor/package.json +6 -0
- package/src/iso-editor/path.ts +18 -0
- package/src/iso-editor/providers.ts +113 -0
- package/src/iso-editor/schema-nav.ts +129 -0
- package/src/iso-editor/splice.ts +472 -0
- package/src/iso-editor/storage-keys.ts +6 -0
- package/src/iso-editor/ui/actions.ts +119 -0
- package/src/iso-editor/ui/app.css +230 -0
- package/src/iso-editor/ui/canvas-layer.ts +56 -0
- package/src/iso-editor/ui/canvas.ts +1071 -0
- package/src/iso-editor/ui/clip.ts +97 -0
- package/src/iso-editor/ui/dialog.ts +25 -0
- package/src/iso-editor/ui/flat-canvas.ts +51 -0
- package/src/iso-editor/ui/icons.ts +21 -0
- package/src/iso-editor/ui/keys.ts +30 -0
- package/src/iso-editor/ui/later.ts +22 -0
- package/src/iso-editor/ui/layer.ts +7 -0
- package/src/iso-editor/ui/marks.css +35 -0
- package/src/iso-editor/ui/menu.ts +67 -0
- package/src/iso-editor/ui/monaco-entry.ts +6 -0
- package/src/iso-editor/ui/mount-kit.ts +35 -0
- package/src/iso-editor/ui/mount.ts +684 -0
- package/src/iso-editor/ui/pane.ts +45 -0
- package/src/iso-editor/ui/part.ts +45 -0
- package/src/iso-editor/ui/plain-icons.ts +83 -0
- package/src/iso-editor/ui/props.ts +347 -0
- package/src/iso-editor/ui/scope-css.ts +65 -0
- package/src/iso-editor/ui/setup.ts +144 -0
- package/src/iso-editor/ui/skin.css +181 -0
- package/src/iso-editor/ui/text.ts +262 -0
- package/src/iso-editor/ui/tree.ts +657 -0
- package/src/iso-editor/validate.ts +62 -0
- package/src/iso-editor/window/protocol.ts +33 -0
- package/src/iso-objects/assemble.ts +57 -0
- package/src/iso-objects/assets.ts +122 -0
- package/src/iso-objects/board.ts +169 -0
- package/src/iso-objects/compile.ts +76 -0
- package/src/iso-objects/css.ts +163 -0
- package/src/iso-objects/flat.ts +653 -0
- package/src/iso-objects/focus.ts +14 -0
- package/src/iso-objects/geometry.ts +86 -0
- package/src/iso-objects/index.ts +33 -0
- package/src/iso-objects/kinds.ts +56 -0
- package/src/iso-objects/labels.ts +310 -0
- package/src/iso-objects/package.json +6 -0
- package/src/iso-objects/place.ts +318 -0
- package/src/iso-objects/route.ts +444 -0
- package/src/iso-objects/scene.ts +376 -0
- package/src/iso-objects/steps.ts +234 -0
- package/src/iso-objects/types.ts +68 -0
- package/src/iso-systems/catalog.ts +31 -0
- package/src/iso-systems/compile.ts +39 -0
- package/src/iso-systems/css.ts +9 -0
- package/src/iso-systems/index.ts +12 -0
- package/src/iso-systems/nodes.ts +126 -0
- package/src/iso-systems/package.json +6 -0
- package/src/iso-systems/schema.json +311 -0
- package/src/iso-systems/validate.ts +34 -0
- package/src/iso-viewer/bundle.ts +15 -0
- package/src/iso-viewer/card-motion.ts +237 -0
- package/src/iso-viewer/dom.ts +13 -0
- package/src/iso-viewer/dual-view.ts +212 -0
- package/src/iso-viewer/flat-view.ts +127 -0
- package/src/iso-viewer/history.ts +781 -0
- package/src/iso-viewer/index.ts +40 -0
- package/src/iso-viewer/morph.ts +191 -0
- package/src/iso-viewer/overlay.ts +212 -0
- package/src/iso-viewer/package.json +6 -0
- package/src/iso-viewer/page.ts +150 -0
- package/src/iso-viewer/player.ts +321 -0
- package/src/iso-viewer/still.ts +74 -0
- package/src/iso-viewer/timeline-contract.ts +342 -0
- package/src/iso-viewer/timeline-engine.ts +420 -0
- package/src/iso-viewer/timeline-export.ts +31 -0
- package/src/iso-viewer/timeline-scale.ts +129 -0
- package/src/iso-viewer/timeline-scope.ts +56 -0
- package/src/iso-viewer/timeline-search.ts +198 -0
- package/src/iso-viewer/timeline-time.ts +54 -0
- package/src/iso-viewer/view-css.ts +59 -0
- package/src/iso-viewer/viewport.ts +142 -0
- package/types/iso-core/compile-schema.d.ts +11 -0
- package/types/iso-core/depth.d.ts +6 -0
- package/types/iso-core/errors.d.ts +24 -0
- package/types/iso-core/glyphs.d.ts +19 -0
- package/types/iso-core/index.d.ts +17 -0
- package/types/iso-core/kernel.d.ts +130 -0
- package/types/iso-core/metrics.json +1 -0
- package/types/iso-core/parse.d.ts +18 -0
- package/types/iso-core/schema-errors.d.ts +14 -0
- package/types/iso-core/shims/crypto.d.ts +9 -0
- package/types/iso-core/svg-dom.d.ts +15 -0
- package/types/iso-core/theme.d.ts +38 -0
- package/types/iso-core/vdom.d.ts +26 -0
- package/types/iso-editor/adapter.d.ts +145 -0
- package/types/iso-editor/clipboard.d.ts +23 -0
- package/types/iso-editor/commands.d.ts +32 -0
- package/types/iso-editor/complete.d.ts +25 -0
- package/types/iso-editor/doc.d.ts +50 -0
- package/types/iso-editor/index.d.ts +57 -0
- package/types/iso-editor/model.d.ts +96 -0
- package/types/iso-editor/outline.d.ts +28 -0
- package/types/iso-editor/path.d.ts +7 -0
- package/types/iso-editor/providers.d.ts +43 -0
- package/types/iso-editor/schema-nav.d.ts +34 -0
- package/types/iso-editor/splice.d.ts +53 -0
- package/types/iso-editor/storage-keys.d.ts +5 -0
- package/types/iso-editor/ui/actions.d.ts +23 -0
- package/types/iso-editor/ui/canvas-layer.d.ts +65 -0
- package/types/iso-editor/ui/canvas.d.ts +279 -0
- package/types/iso-editor/ui/clip.d.ts +14 -0
- package/types/iso-editor/ui/dialog.d.ts +7 -0
- package/types/iso-editor/ui/flat-canvas.d.ts +2 -0
- package/types/iso-editor/ui/icons.d.ts +5 -0
- package/types/iso-editor/ui/keys.d.ts +7 -0
- package/types/iso-editor/ui/later.d.ts +12 -0
- package/types/iso-editor/ui/layer.d.ts +2 -0
- package/types/iso-editor/ui/menu.d.ts +21 -0
- package/types/iso-editor/ui/mount-kit.d.ts +31 -0
- package/types/iso-editor/ui/mount.d.ts +146 -0
- package/types/iso-editor/ui/pane.d.ts +60 -0
- package/types/iso-editor/ui/part.d.ts +40 -0
- package/types/iso-editor/ui/plain-icons.d.ts +10 -0
- package/types/iso-editor/ui/props.d.ts +57 -0
- package/types/iso-editor/ui/scope-css.d.ts +5 -0
- package/types/iso-editor/ui/setup.d.ts +40 -0
- package/types/iso-editor/ui/text.d.ts +19 -0
- package/types/iso-editor/ui/tree.d.ts +100 -0
- package/types/iso-editor/validate.d.ts +36 -0
- package/types/iso-editor/window/protocol.d.ts +60 -0
- package/types/iso-objects/assemble.d.ts +35 -0
- package/types/iso-objects/assets.d.ts +49 -0
- package/types/iso-objects/board.d.ts +36 -0
- package/types/iso-objects/compile.d.ts +35 -0
- package/types/iso-objects/css.d.ts +16 -0
- package/types/iso-objects/flat.d.ts +130 -0
- package/types/iso-objects/focus.d.ts +1 -0
- package/types/iso-objects/geometry.d.ts +59 -0
- package/types/iso-objects/index.d.ts +26 -0
- package/types/iso-objects/kinds.d.ts +53 -0
- package/types/iso-objects/labels.d.ts +92 -0
- package/types/iso-objects/place.d.ts +25 -0
- package/types/iso-objects/route.d.ts +67 -0
- package/types/iso-objects/scene.d.ts +63 -0
- package/types/iso-objects/steps.d.ts +90 -0
- package/types/iso-objects/types.d.ts +140 -0
- package/types/iso-systems/catalog.d.ts +4 -0
- package/types/iso-systems/compile.d.ts +6 -0
- package/types/iso-systems/css.d.ts +3 -0
- package/types/iso-systems/index.d.ts +5 -0
- package/types/iso-systems/nodes.d.ts +3 -0
- package/types/iso-viewer/card-motion.d.ts +56 -0
- package/types/iso-viewer/dom.d.ts +1 -0
- package/types/iso-viewer/dual-view.d.ts +44 -0
- package/types/iso-viewer/flat-view.d.ts +25 -0
- package/types/iso-viewer/history.d.ts +91 -0
- package/types/iso-viewer/index.d.ts +31 -0
- package/types/iso-viewer/morph.d.ts +28 -0
- package/types/iso-viewer/overlay.d.ts +135 -0
- package/types/iso-viewer/page.d.ts +13 -0
- package/types/iso-viewer/still.d.ts +26 -0
- package/types/iso-viewer/timeline-contract.d.ts +345 -0
- package/types/iso-viewer/timeline-engine.d.ts +20 -0
- package/types/iso-viewer/timeline-export.d.ts +5 -0
- package/types/iso-viewer/timeline-scale.d.ts +44 -0
- package/types/iso-viewer/timeline-scope.d.ts +33 -0
- package/types/iso-viewer/timeline-search.d.ts +52 -0
- package/types/iso-viewer/timeline-time.d.ts +8 -0
- package/types/iso-viewer/view-css.d.ts +7 -0
- package/types/iso-viewer/viewport.d.ts +50 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// The player: runs each scene's steps in the browser. No dependencies; bundled to one small script and inlined.
|
|
2
|
+
// It reads the scene data from <script type="application/json" id="diagram-steps"> and the rendered SVG.
|
|
3
|
+
//
|
|
4
|
+
// Hash flags (for screenshots and links): #theme=light|dark, #still (no motion: tokens frozen mid-route),
|
|
5
|
+
// #scene=ID&step=N (open a scene at a step), #t=0.6 (where frozen tokens sit, 0..1), #motion (ignore reduced motion),
|
|
6
|
+
// #grid (show the floor grid), #assemble (play the assemble intro) and #assemble&at=MS (freeze it at that moment).
|
|
7
|
+
|
|
8
|
+
import { focusView } from '../iso-objects/focus.ts';
|
|
9
|
+
|
|
10
|
+
interface Token { route: string; kind: string; color: string }
|
|
11
|
+
interface Step {
|
|
12
|
+
n: number; num: number; kind: string; color: string; heading: string; caption: string; command: string;
|
|
13
|
+
phases: Token[][]; pulses: [number, number, number, number][]; lit: string[]; duration: number;
|
|
14
|
+
focus?: [number, number, number, number];
|
|
15
|
+
}
|
|
16
|
+
interface Piece { id: string; kind: 'region' | 'node'; dx: number; dy: number; delay: number; dur: number }
|
|
17
|
+
interface Assembly { pieces: Piece[]; routes: { id: string; delay: number; dur: number }[]; labels: { delay: number; dur: number }; total: number }
|
|
18
|
+
interface SceneData {
|
|
19
|
+
id: string; loop: boolean; dim: 'flows' | 'all'; steps: Step[]; vis: Record<string, boolean[]>;
|
|
20
|
+
assemble: boolean; grid: boolean; assembly: Assembly;
|
|
21
|
+
}
|
|
22
|
+
interface Data { scenes: SceneData[] }
|
|
23
|
+
|
|
24
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
25
|
+
const TRAVEL = 1150;
|
|
26
|
+
const EASE_IN = 'cubic-bezier(.16,.84,.3,1)';
|
|
27
|
+
|
|
28
|
+
function svgEl(tag: string, attrs: Record<string, string | number>, parent: Element): SVGElement {
|
|
29
|
+
const e = document.createElementNS(NS, tag);
|
|
30
|
+
for (const k in attrs) e.setAttribute(k, String(attrs[k]));
|
|
31
|
+
parent.appendChild(e);
|
|
32
|
+
return e;
|
|
33
|
+
}
|
|
34
|
+
const ease = (f: number) => (f < 0.5 ? 2 * f * f : 1 - Math.pow(-2 * f + 2, 2) / 2);
|
|
35
|
+
|
|
36
|
+
function init() {
|
|
37
|
+
const dataEl = document.getElementById('diagram-steps');
|
|
38
|
+
if (!dataEl) return;
|
|
39
|
+
const data = JSON.parse(dataEl.textContent || '{}') as Data;
|
|
40
|
+
const hash = location.hash;
|
|
41
|
+
const still = /still/.test(hash);
|
|
42
|
+
const reduceMedia = matchMedia('(prefers-reduced-motion: reduce)').matches && !/motion/.test(hash);
|
|
43
|
+
const reduce = still || reduceMedia;
|
|
44
|
+
const frozenT = Math.max(0, Math.min(1, Number((/[#&]t=([\d.]+)/.exec(hash) || [])[1] ?? 0.6)));
|
|
45
|
+
const wantScene = (/[#&]scene=([\w-]+)/.exec(hash) || [])[1];
|
|
46
|
+
const wantStep = Number((/[#&]step=?(\d+)/.exec(hash) || [])[1] || 0);
|
|
47
|
+
const wantGrid = /[#&]grid\b/.test(hash);
|
|
48
|
+
const wantAssemble = /[#&]assemble\b/.test(hash);
|
|
49
|
+
const assembleAt = (/[#&]at=(\d+)/.exec(hash) || [])[1];
|
|
50
|
+
if (still) document.documentElement.classList.add('still');
|
|
51
|
+
|
|
52
|
+
// #scene=ID opens the page at that scene (screenshots use #still, which keeps the page at the top)
|
|
53
|
+
if (wantScene && !still) document.getElementById('scene-' + wantScene)?.scrollIntoView({ block: 'start' });
|
|
54
|
+
|
|
55
|
+
const runners: { fig: Element; setActive(on: boolean): void }[] = [];
|
|
56
|
+
for (const sd of data.scenes) {
|
|
57
|
+
const sec = document.getElementById('scene-' + sd.id);
|
|
58
|
+
if (sec) runners.push(makeRunner(sec, sd));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function makeRunner(sec: HTMLElement, sd: SceneData) {
|
|
62
|
+
const STEPS = sd.steps, N = STEPS.length;
|
|
63
|
+
const svg = sec.querySelector('svg')!, fig = sec.querySelector('.figure')!;
|
|
64
|
+
const anim = svg.querySelector('.g-anim')!;
|
|
65
|
+
const q = <T extends Element>(s: string) => sec.querySelector(s) as T | null;
|
|
66
|
+
const num = q<HTMLElement>('.cap-h .num'), hEl = q<HTMLElement>('.cap-h .h'), cnt = q<HTMLElement>('.cap-h .cnt');
|
|
67
|
+
const capT = q<HTMLElement>('.cap-t'), capC = q<HTMLElement>('.cap-c'), prog = q<HTMLElement>('.prog i'), dots = q<HTMLElement>('.dots');
|
|
68
|
+
const capBox = q<HTMLElement>('.cap'), playBtn = q<HTMLButtonElement>('[data-a=play]');
|
|
69
|
+
const gridBtn = q<HTMLButtonElement>('[data-a=grid]'), asmBtn = q<HTMLButtonElement>('[data-a=assemble]');
|
|
70
|
+
const hlEls = [...svg.querySelectorAll<SVGElement>('[data-hl]')];
|
|
71
|
+
const stepEls = [...svg.querySelectorAll<SVGElement>('[data-step]')];
|
|
72
|
+
const idEls = [...svg.querySelectorAll<SVGElement>('[data-id]')];
|
|
73
|
+
const visEls = new Map<string, SVGElement[]>();
|
|
74
|
+
for (const e of idEls) if (sd.vis[e.dataset.id!]) { const l = visEls.get(e.dataset.id!) ?? []; l.push(e); visEls.set(e.dataset.id!, l); }
|
|
75
|
+
for (const e of hlEls) { const id = e.dataset.hl!; if (sd.vis[id] && !e.dataset.id) { const l = visEls.get(id) ?? []; l.push(e); visEls.set(id, l); } }
|
|
76
|
+
const flowPath = (id: string) => svg.querySelector<SVGPathElement>(`[data-hl="${CSS.escape(id)}"] path.flow`);
|
|
77
|
+
if (sd.dim === 'all') svg.classList.add('dim-all');
|
|
78
|
+
|
|
79
|
+
let cur = 0, playing = false, userPaused = false, active = false, timer = 0, raf = 0, groups = 0, t0 = 0;
|
|
80
|
+
let assembling = false, assembled = false, animations: Animation[] = [];
|
|
81
|
+
let tokens: { path: SVGPathElement; len: number; gi: number; stop: boolean; c: SVGElement }[] = [];
|
|
82
|
+
|
|
83
|
+
// ---- grid ----
|
|
84
|
+
const setGrid = (on: boolean) => { svg.classList.toggle('show-grid', on); gridBtn?.setAttribute('aria-pressed', String(on)); };
|
|
85
|
+
setGrid(sd.grid || wantGrid);
|
|
86
|
+
gridBtn?.addEventListener('click', () => setGrid(!svg.classList.contains('show-grid')));
|
|
87
|
+
|
|
88
|
+
STEPS.forEach((s, i) => {
|
|
89
|
+
const b = document.createElement('button');
|
|
90
|
+
b.className = 'dot'; b.type = 'button'; b.setAttribute('aria-label', `Step ${s.num}: ${s.heading}`);
|
|
91
|
+
b.addEventListener('click', () => { userPause(); finishAssemble(); show(i); });
|
|
92
|
+
dots?.appendChild(b);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function clearAnim() { anim.textContent = ''; tokens = []; if (raf) cancelAnimationFrame(raf); raf = 0; }
|
|
96
|
+
function tick(now: number) {
|
|
97
|
+
const per = TRAVEL * groups + 700, tt = (now - t0) % per;
|
|
98
|
+
for (const tk of tokens) {
|
|
99
|
+
// frozen: every phase's token sits at the same point, so one picture shows them all
|
|
100
|
+
const f = reduce ? frozenT : Math.max(0, Math.min(1, (tt - tk.gi * TRAVEL) / TRAVEL));
|
|
101
|
+
let e = ease(f);
|
|
102
|
+
if (tk.stop) e = f < 0.7 ? f / 0.7 : 1 - ((f - 0.7) / 0.3) * 0.25; // a blocked token stalls and falls back
|
|
103
|
+
const p = tk.path.getPointAtLength(Math.max(0, Math.min(1, e)) * tk.len);
|
|
104
|
+
tk.c.setAttribute('cx', String(p.x)); tk.c.setAttribute('cy', String(p.y));
|
|
105
|
+
tk.c.style.opacity = reduce ? '1' : f <= 0 || f >= 1 ? '0' : '1';
|
|
106
|
+
}
|
|
107
|
+
if (!reduce && active) raf = requestAnimationFrame(tick);
|
|
108
|
+
}
|
|
109
|
+
// ---- focus: ease the viewBox to a step's focus box (keeping the drawing's proportions), and back ----
|
|
110
|
+
const FULL = svg.getAttribute('viewBox')!.split(/\s+/).map(Number);
|
|
111
|
+
let view = FULL.slice(), zoomTimer = 0;
|
|
112
|
+
const viewFor = (s: Step) => focusView(FULL, s.focus);
|
|
113
|
+
function zoomTo(target: number[]) {
|
|
114
|
+
clearTimeout(zoomTimer);
|
|
115
|
+
if (target.every((v, k) => Math.abs(v - view[k]) < 0.5)) return;
|
|
116
|
+
const from = view.slice(), t0z = performance.now(), D = reduce ? 0 : 900;
|
|
117
|
+
// a timer, not a frame callback, so it also finishes where no frames are drawn
|
|
118
|
+
const step = () => {
|
|
119
|
+
const f = D ? Math.min(1, (performance.now() - t0z) / D) : 1, e = ease(f);
|
|
120
|
+
view = from.map((v, k) => v + (target[k] - v) * e);
|
|
121
|
+
svg.setAttribute('viewBox', view.map(v => v.toFixed(1)).join(' '));
|
|
122
|
+
if (f < 1) zoomTimer = window.setTimeout(step, 16);
|
|
123
|
+
};
|
|
124
|
+
step();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function show(i: number) {
|
|
128
|
+
if (!N) return;
|
|
129
|
+
clearAnim();
|
|
130
|
+
cur = i;
|
|
131
|
+
const s = STEPS[i], n = s.n;
|
|
132
|
+
zoomTo(svg.classList.contains("all") ? FULL : viewFor(s));
|
|
133
|
+
const lit = new Set(s.lit);
|
|
134
|
+
svg.classList.add('focus');
|
|
135
|
+
for (const e of hlEls) e.classList.toggle('hl', e.dataset.hl!.split(' ').some(x => lit.has(x)));
|
|
136
|
+
if (sd.dim === 'all') for (const e of idEls) if (e.hasAttribute('data-dim')) e.classList.toggle('hl', lit.has(e.dataset.id!));
|
|
137
|
+
for (const e of stepEls) e.classList.toggle('on', e.dataset.step === String(n));
|
|
138
|
+
svg.querySelectorAll<SVGElement>('[data-badge]').forEach(b => b.classList.toggle('on', b.dataset.badge === String(n)));
|
|
139
|
+
for (const [id, els] of visEls) { const v = sd.vis[id][i]; for (const e of els) e.classList.toggle('pre', !v); }
|
|
140
|
+
for (const [x, y, rx, ry] of s.pulses) svgEl('ellipse', { cx: x, cy: y, rx, ry, class: 'pulse', style: `stroke:${s.color}` }, anim);
|
|
141
|
+
groups = s.phases.length;
|
|
142
|
+
s.phases.forEach((ph, gi) => ph.forEach(tk => {
|
|
143
|
+
const path = flowPath(tk.route);
|
|
144
|
+
if (!path) return;
|
|
145
|
+
tokens.push({ path, len: path.getTotalLength(), gi, stop: tk.kind === 'blocked', c: svgEl('circle', { r: 7, class: 'tok', style: `fill:${tk.color}` }, anim) });
|
|
146
|
+
}));
|
|
147
|
+
t0 = performance.now(); tick(t0);
|
|
148
|
+
if (!reduce && active && !raf) raf = requestAnimationFrame(tick);
|
|
149
|
+
num!.textContent = String(s.num); num!.style.background = s.color;
|
|
150
|
+
hEl!.textContent = s.heading; cnt!.textContent = `${i + 1} / ${N}`;
|
|
151
|
+
capT!.innerHTML = s.caption; capC!.textContent = s.command;
|
|
152
|
+
prog!.style.setProperty('--c', s.color);
|
|
153
|
+
[...dots!.children].forEach((d, j) => { d.classList.toggle('on', j === i); d.classList.toggle('done', j < i); });
|
|
154
|
+
restartProg();
|
|
155
|
+
}
|
|
156
|
+
function restartProg() {
|
|
157
|
+
if (!prog) return;
|
|
158
|
+
prog.style.transition = 'none';
|
|
159
|
+
prog.style.width = playing ? '0%' : ((cur + 1) / N * 100) + '%';
|
|
160
|
+
if (playing) { void prog.offsetWidth; prog.style.transition = `width ${STEPS[cur].duration}ms linear`; prog.style.width = '100%'; }
|
|
161
|
+
}
|
|
162
|
+
function schedule() {
|
|
163
|
+
clearTimeout(timer);
|
|
164
|
+
if (!playing) return;
|
|
165
|
+
timer = window.setTimeout(() => {
|
|
166
|
+
if (cur === N - 1 && !sd.loop) { stop(); return; }
|
|
167
|
+
show((cur + 1) % N); schedule();
|
|
168
|
+
}, STEPS[cur].duration);
|
|
169
|
+
}
|
|
170
|
+
function setBtn() {
|
|
171
|
+
if (!playBtn) return;
|
|
172
|
+
playBtn.textContent = playing ? '❚❚ Pause' : '▶ Play';
|
|
173
|
+
playBtn.setAttribute('aria-label', playing ? 'Pause' : 'Play');
|
|
174
|
+
capBox?.setAttribute('aria-live', playing ? 'off' : 'polite');
|
|
175
|
+
}
|
|
176
|
+
function play() { if (reduce || !N || assembling) return; playing = true; setBtn(); restartProg(); schedule(); }
|
|
177
|
+
function stop() { playing = false; clearTimeout(timer); setBtn(); restartProg(); }
|
|
178
|
+
function userPause() { userPaused = true; stop(); }
|
|
179
|
+
|
|
180
|
+
// ---- assemble: regions and nodes fly in from the nearest edge, routes draw in, labels fade in ----
|
|
181
|
+
const A = sd.assembly;
|
|
182
|
+
const layer = (name: string) => svg.querySelector(`.g-${name}`);
|
|
183
|
+
function finishAssemble() {
|
|
184
|
+
if (!assembling) return;
|
|
185
|
+
for (const a of animations) a.finish();
|
|
186
|
+
}
|
|
187
|
+
function assemble(freezeAt?: number) {
|
|
188
|
+
for (const a of animations) a.cancel();
|
|
189
|
+
animations = [];
|
|
190
|
+
stop();
|
|
191
|
+
if (N) show(cur); // set what is visible at this step; focus comes back at the end
|
|
192
|
+
clearAnim();
|
|
193
|
+
svg.classList.remove('focus', 'pre-assemble', 'all');
|
|
194
|
+
assembling = true;
|
|
195
|
+
const run = (el: Element, frames: Keyframe[], delay: number, dur: number, easing = EASE_IN) =>
|
|
196
|
+
animations.push(el.animate(frames, { delay, duration: dur, easing, fill: 'backwards' }));
|
|
197
|
+
const solid = ['base', 'blocks', 'air'].map(layer).filter(Boolean) as Element[];
|
|
198
|
+
for (const p of A.pieces) {
|
|
199
|
+
const from = `translate(${p.dx}px, ${p.dy}px)`;
|
|
200
|
+
for (const L of solid) L.querySelectorAll(`[data-id="${CSS.escape(p.id)}"]`).forEach(el =>
|
|
201
|
+
run(el, [{ transform: from }, { transform: 'translate(0px, 0px)' }], p.delay, p.dur));
|
|
202
|
+
}
|
|
203
|
+
for (const r of A.routes) {
|
|
204
|
+
const g = layer('flows')?.querySelector(`[data-hl="${CSS.escape(r.id)}"]`);
|
|
205
|
+
const path = g?.querySelector<SVGPathElement>('path.flow');
|
|
206
|
+
if (!g || !path) continue;
|
|
207
|
+
const len = path.getTotalLength();
|
|
208
|
+
run(g, [{ opacity: 0 }, { opacity: 1 }], r.delay, 80, 'linear');
|
|
209
|
+
run(path, [{ strokeDasharray: `${len} ${len}`, strokeDashoffset: len }, { strokeDasharray: `${len} ${len}`, strokeDashoffset: 0 }], r.delay, r.dur, 'ease-out');
|
|
210
|
+
}
|
|
211
|
+
for (const name of ['floor', 'labels', 'badges']) {
|
|
212
|
+
const L = layer(name);
|
|
213
|
+
if (L) run(L, [{ opacity: 0 }, { opacity: 1 }], A.labels.delay, A.labels.dur, 'ease-out');
|
|
214
|
+
}
|
|
215
|
+
if (freezeAt !== undefined) {
|
|
216
|
+
for (const a of animations) { a.pause(); a.currentTime = freezeAt; }
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
Promise.all(animations.map(a => a.finished)).then(() => {
|
|
220
|
+
assembling = false; assembled = true; animations = [];
|
|
221
|
+
if (N) show(cur);
|
|
222
|
+
if (active && !userPaused) play();
|
|
223
|
+
}, () => { /* replaced by a newer run */ });
|
|
224
|
+
}
|
|
225
|
+
asmBtn?.addEventListener('click', () => { userPaused = false; assemble(); });
|
|
226
|
+
|
|
227
|
+
function setActive(on: boolean) {
|
|
228
|
+
if (on === active) return;
|
|
229
|
+
active = on;
|
|
230
|
+
if (on) {
|
|
231
|
+
if (!reduce) { t0 = performance.now(); raf = requestAnimationFrame(tick); }
|
|
232
|
+
if (!userPaused) play();
|
|
233
|
+
} else { stop(); if (raf) cancelAnimationFrame(raf); raf = 0; }
|
|
234
|
+
}
|
|
235
|
+
playBtn?.addEventListener('click', () => {
|
|
236
|
+
if (playing) userPause();
|
|
237
|
+
else { userPaused = false; finishAssemble(); if (cur === N - 1) show(0); play(); }
|
|
238
|
+
});
|
|
239
|
+
q('[data-a=next]')?.addEventListener('click', () => { userPause(); finishAssemble(); show(Math.min(N - 1, cur + 1)); });
|
|
240
|
+
q('[data-a=prev]')?.addEventListener('click', () => { userPause(); finishAssemble(); show(Math.max(0, cur - 1)); });
|
|
241
|
+
fig.addEventListener('keydown', e => {
|
|
242
|
+
const k = (e as KeyboardEvent).key;
|
|
243
|
+
if (!N) return;
|
|
244
|
+
if (k === 'ArrowRight') { e.preventDefault(); userPause(); finishAssemble(); show(Math.min(N - 1, cur + 1)); }
|
|
245
|
+
if (k === 'ArrowLeft') { e.preventDefault(); userPause(); finishAssemble(); show(Math.max(0, cur - 1)); }
|
|
246
|
+
});
|
|
247
|
+
svg.querySelectorAll<SVGElement>('.badge').forEach(b => {
|
|
248
|
+
const go = () => { userPause(); finishAssemble(); show(Number(b.dataset.go) - 1); };
|
|
249
|
+
b.addEventListener('click', go);
|
|
250
|
+
b.addEventListener('keydown', e => { const k = (e as KeyboardEvent).key; if (k === 'Enter' || k === ' ') { e.preventDefault(); go(); } });
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const forced = wantStep && (!wantScene || wantScene === sd.id) ? Math.min(N, wantStep) - 1 : -1;
|
|
254
|
+
const frozenAssemble = wantAssemble && assembleAt !== undefined && (!wantScene || wantScene === sd.id);
|
|
255
|
+
if (reduce && forced < 0 && !still && !frozenAssemble) {
|
|
256
|
+
// reduced motion: the whole diagram, everything lit, the step list open, no assembly
|
|
257
|
+
if (N) { svg.classList.add('all'); show(N - 1); }
|
|
258
|
+
if (playBtn) { playBtn.disabled = true; playBtn.textContent = 'Motion off'; }
|
|
259
|
+
if (asmBtn) asmBtn.disabled = true;
|
|
260
|
+
sec.querySelector('details.steps')?.setAttribute('open', '');
|
|
261
|
+
} else {
|
|
262
|
+
if (N) show(forced >= 0 ? forced : 0);
|
|
263
|
+
if (reduce && playBtn) { playBtn.disabled = true; playBtn.textContent = 'Motion off'; }
|
|
264
|
+
}
|
|
265
|
+
if (frozenAssemble) assemble(Number(assembleAt));
|
|
266
|
+
else if ((sd.assemble || wantAssemble) && !reduce && !(window as unknown as { __diagramNoIntro?: boolean }).__diagramNoIntro) {
|
|
267
|
+
// hidden until it comes into view, then drawn piece by piece. The trigger is its own, so a figure taller
|
|
268
|
+
// than the window still starts once as much of it shows as can.
|
|
269
|
+
svg.classList.add('pre-assemble');
|
|
270
|
+
let io: IntersectionObserver | undefined;
|
|
271
|
+
const start = () => { io?.disconnect(); removeEventListener('scroll', check); if (!assembled && !assembling) assemble(); };
|
|
272
|
+
const enough = (r: DOMRect) => {
|
|
273
|
+
const seen = Math.max(0, Math.min(r.bottom, innerHeight) - Math.max(r.top, 0)) / Math.max(1, r.height);
|
|
274
|
+
return seen > 0 && seen >= Math.min(0.3, (innerHeight / Math.max(1, r.height)) * 0.8);
|
|
275
|
+
};
|
|
276
|
+
// An observer for scrolling into view, and a plain check as well: some browsers and webviews are slow to
|
|
277
|
+
// deliver the observer's first callback, and the figure must not stay hidden.
|
|
278
|
+
function check() { if (enough(fig.getBoundingClientRect())) start(); }
|
|
279
|
+
if ('IntersectionObserver' in window) {
|
|
280
|
+
io = new IntersectionObserver(es => { for (const e of es) if (e.isIntersecting && enough(e.boundingClientRect)) start(); },
|
|
281
|
+
{ threshold: [0, 0.05, 0.1, 0.2, 0.3, 0.5] });
|
|
282
|
+
io.observe(fig);
|
|
283
|
+
}
|
|
284
|
+
addEventListener('scroll', check, { passive: true });
|
|
285
|
+
setTimeout(check, 60);
|
|
286
|
+
}
|
|
287
|
+
return { fig, setActive };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// only the most visible scene animates
|
|
291
|
+
if (!reduce) {
|
|
292
|
+
const ratio = new Map<Element, number>();
|
|
293
|
+
const pick = () => {
|
|
294
|
+
let best: typeof runners[number] | undefined, br = 0;
|
|
295
|
+
for (const r of runners) { const v = ratio.get(r.fig) || 0; if (v > br) { br = v; best = r; } }
|
|
296
|
+
for (const r of runners) r.setActive(r === best && br >= 0.35);
|
|
297
|
+
};
|
|
298
|
+
// the observer, plus a plain measurement on load and on scroll, for browsers slow to deliver the observer
|
|
299
|
+
const measure = () => {
|
|
300
|
+
for (const r of runners) {
|
|
301
|
+
const b = r.fig.getBoundingClientRect();
|
|
302
|
+
ratio.set(r.fig, Math.max(0, Math.min(b.bottom, innerHeight) - Math.max(b.top, 0)) / Math.max(1, b.height));
|
|
303
|
+
}
|
|
304
|
+
pick();
|
|
305
|
+
};
|
|
306
|
+
if ('IntersectionObserver' in window) {
|
|
307
|
+
const io = new IntersectionObserver(entries => {
|
|
308
|
+
for (const e of entries) ratio.set(e.target, e.isIntersecting ? e.intersectionRatio : 0);
|
|
309
|
+
pick();
|
|
310
|
+
}, { threshold: [0, 0.2, 0.35, 0.5, 0.7, 0.9, 1] });
|
|
311
|
+
for (const r of runners) io.observe(r.fig);
|
|
312
|
+
}
|
|
313
|
+
let pending = 0;
|
|
314
|
+
addEventListener('scroll', () => { if (!pending) pending = window.setTimeout(() => { pending = 0; measure(); }, 120); }, { passive: true });
|
|
315
|
+
setTimeout(measure, 80);
|
|
316
|
+
} else {
|
|
317
|
+
for (const r of runners) r.setActive(true);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// A still render's machinery (docs/editor/LAYERS.md §2): a drawing (the renderer's SVG, parsed) and its overlay,
|
|
2
|
+
// fitted to a size and written as one SVG with every id prefixed, so many can share a page. No DOM: the overlay is
|
|
3
|
+
// drawn into the virtual document (src/iso-core/vdom.ts) and measured from what it drew. The domain's entry reads its
|
|
4
|
+
// file, says what the overlay draws, and assembles the SVG with its own classes and stylesheet.
|
|
5
|
+
|
|
6
|
+
import type { SvgNode } from '../iso-core/svg-dom.ts';
|
|
7
|
+
import type { VNode } from '../iso-core/vdom.ts';
|
|
8
|
+
|
|
9
|
+
import type { Box } from './overlay.ts';
|
|
10
|
+
export type { Box };
|
|
11
|
+
|
|
12
|
+
export const n = (v: number) => String(Math.round(v * 100) / 100);
|
|
13
|
+
export const node = (name: string, attrs: Record<string, string | number> = {}, ...children: (VNode | string)[]): VNode =>
|
|
14
|
+
({ name, attrs: Object.entries(attrs).map(([k, v]) => [k, typeof v === 'number' ? n(v) : v]), children });
|
|
15
|
+
|
|
16
|
+
/** "var(--x)" → "var(--iso-x)" (the drawing's tokens, as the stylesheet names them); "#id" → the prefixed id */
|
|
17
|
+
export function rewrite(t: SvgNode | VNode | string, pfx: string): VNode | string {
|
|
18
|
+
if (typeof t === 'string') return t;
|
|
19
|
+
const attrs = t.attrs.map(([k, v]) => {
|
|
20
|
+
if (k === 'id') return [k, pfx + v] as [string, string];
|
|
21
|
+
let w = v.replace(/var\(--([a-zA-Z][\w-]*)/g, 'var(--iso-$1').replace(/url\(\s*(['"]?)#/g, (_m, q: string) => `url(${q}#${pfx}`);
|
|
22
|
+
if ((k === 'href' || k === 'xlink:href') && w.startsWith('#') && !w.startsWith(`#${pfx}`)) w = `#${pfx}${w.slice(1)}`;
|
|
23
|
+
return [k, w] as [string, string];
|
|
24
|
+
});
|
|
25
|
+
return { name: t.name, attrs, children: t.children.map(c => rewrite(c, pfx)) };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** keep a node? (for thumbs: no text, no titles, no small things, no badges) */
|
|
29
|
+
export function prune(t: VNode | string, drop: (n: VNode) => boolean): VNode | string | undefined {
|
|
30
|
+
if (typeof t === 'string') return t;
|
|
31
|
+
if (drop(t)) return undefined;
|
|
32
|
+
return { ...t, children: t.children.map(c => prune(c, drop)).filter((c): c is VNode | string => c !== undefined) };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const cls = (t: VNode) => (t.attrs.find(a => a[0] === 'class')?.[1] ?? '').split(/\s+/);
|
|
36
|
+
export const attr = (t: VNode, k: string) => t.attrs.find(a => a[0] === k)?.[1];
|
|
37
|
+
|
|
38
|
+
/** every point a tree draws (polygon points, rects, circles), for the overlay's extent */
|
|
39
|
+
export function extent(ts: (VNode | string)[]): Box | undefined {
|
|
40
|
+
const xs: number[] = [], ys: number[] = [];
|
|
41
|
+
const walk = (t: VNode | string) => {
|
|
42
|
+
if (typeof t === 'string') return;
|
|
43
|
+
const tr = attr(t, 'transform');
|
|
44
|
+
if (tr && /matrix/.test(tr)) return; // a card's face text: inside its card
|
|
45
|
+
const pts = attr(t, 'points');
|
|
46
|
+
if (pts) for (const p of pts.trim().split(/\s+/)) { const [x, y] = p.split(',').map(Number); if (Number.isFinite(x) && Number.isFinite(y)) { xs.push(x); ys.push(y); } }
|
|
47
|
+
if (t.name === 'rect') { const x = Number(attr(t, 'x')), y = Number(attr(t, 'y')), w = Number(attr(t, 'width')), h = Number(attr(t, 'height')); if ([x, y, w, h].every(Number.isFinite)) { xs.push(x, x + w); ys.push(y, y + h); } }
|
|
48
|
+
if (t.name === 'circle') { const x = Number(attr(t, 'cx')), y = Number(attr(t, 'cy')), r = Number(attr(t, 'r')); if ([x, y, r].every(Number.isFinite)) { xs.push(x - r, x + r); ys.push(y - r, y + r); } }
|
|
49
|
+
t.children.forEach(walk);
|
|
50
|
+
};
|
|
51
|
+
ts.forEach(walk);
|
|
52
|
+
if (!xs.length) return undefined;
|
|
53
|
+
const x0 = Math.min(...xs), y0 = Math.min(...ys);
|
|
54
|
+
return { x: x0, y: y0, w: Math.max(...xs) - x0, h: Math.max(...ys) - y0 };
|
|
55
|
+
}
|
|
56
|
+
export const unite = (a: Box, b?: Box): Box => {
|
|
57
|
+
if (!b) return a;
|
|
58
|
+
const x0 = Math.min(a.x, b.x), y0 = Math.min(a.y, b.y);
|
|
59
|
+
return { x: x0, y: y0, w: Math.max(a.x + a.w, b.x + b.w) - x0, h: Math.max(a.y + a.h, b.y + b.h) - y0 };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** The scale that fits the drawing and its overlay. The overlay's badges keep their size in px, so it is drawn at a
|
|
63
|
+
* scale, measured, and drawn again at the scale that holds both (twice: the scale it ends at is the one it is drawn at). */
|
|
64
|
+
export function fitWithOverlay(drawn: Box, size: { width: number; height: number; pad: number }, paint: (k: number) => (VNode | string)[]) {
|
|
65
|
+
const fitK = (b: Box) => Math.min((size.width - size.pad * 2) / b.w, (size.height - size.pad * 2) / b.h);
|
|
66
|
+
let k = fitK(drawn);
|
|
67
|
+
let live = paint(k);
|
|
68
|
+
let box = unite(drawn, extent(live));
|
|
69
|
+
k = fitK(box);
|
|
70
|
+
live = paint(k);
|
|
71
|
+
box = unite(drawn, extent(live));
|
|
72
|
+
k = fitK(box);
|
|
73
|
+
return { k, box, live };
|
|
74
|
+
}
|