@johnoscott/isometric-engine 0.0.0-stage → 0.10.1
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 +355 -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 +269 -0
- package/assets/default-theme.yaml +99 -0
- package/assets/icons.svg +1 -0
- package/assets/marks.css +39 -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 +443 -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 +1403 -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 +149 -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 +511 -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 +147 -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 +477 -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 +1227 -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 +39 -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 +153 -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 +178 -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 +307 -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 +49 -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,228 @@
|
|
|
1
|
+
const APPEARS = [["scale", "Scale"], ["spin", "Spin"], ["dissolve", "Dissolve"], ["inflate", "Inflate"]];
|
|
2
|
+
const IDLES = [["none", "None"], ["jiggle", "Jiggle"], ["pirouette", "Pirouette"], ["glow", "Glow"], ["breathe", "Breathe"]];
|
|
3
|
+
function phaseOf(id) {
|
|
4
|
+
let h = 2166136261;
|
|
5
|
+
for (let i = 0; i < id.length; i++) {
|
|
6
|
+
h ^= id.charCodeAt(i);
|
|
7
|
+
h = Math.imul(h, 16777619);
|
|
8
|
+
}
|
|
9
|
+
return (h >>> 0) % 1e3 / 1e3;
|
|
10
|
+
}
|
|
11
|
+
const ease = (t) => t < 0 ? 0 : t > 1 ? 1 : 1 - Math.pow(1 - t, 3);
|
|
12
|
+
const easeIn = (t) => t < 0 ? 0 : t > 1 ? 1 : t * t * t;
|
|
13
|
+
const TAU = Math.PI * 2;
|
|
14
|
+
const T = {
|
|
15
|
+
appear: { scale: 420, spin: 760, dissolve: 520, inflate: 640 },
|
|
16
|
+
disappear: { scale: 320, spin: 600, dissolve: 420, inflate: 420 },
|
|
17
|
+
period: { jiggle: 4200, pirouette: 6400, glow: 3200, breathe: 4400 }
|
|
18
|
+
};
|
|
19
|
+
const PIR = { windup: 220, turn: 980, land: 260 };
|
|
20
|
+
function cardMotion(host, initial, { prefix, key, alt }) {
|
|
21
|
+
let s = { ...initial };
|
|
22
|
+
let speed = 1;
|
|
23
|
+
const jobs = /* @__PURE__ */ new Map();
|
|
24
|
+
const turned = /* @__PURE__ */ new WeakSet();
|
|
25
|
+
let raf = 0, frames = 0;
|
|
26
|
+
const idleAnims = /* @__PURE__ */ new WeakMap();
|
|
27
|
+
const last = /* @__PURE__ */ new WeakMap();
|
|
28
|
+
function tick(now) {
|
|
29
|
+
raf = 0;
|
|
30
|
+
for (const [card, j] of jobs) {
|
|
31
|
+
if (!card.isConnected) {
|
|
32
|
+
jobs.delete(card);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
let t;
|
|
36
|
+
if (j.repeat) {
|
|
37
|
+
const p = (now + (j.offset ?? 0)) % j.repeat;
|
|
38
|
+
t = p / j.dur;
|
|
39
|
+
if (t > 1) {
|
|
40
|
+
if (turned.has(card)) {
|
|
41
|
+
host.restore(card);
|
|
42
|
+
turned.delete(card);
|
|
43
|
+
card.style.removeProperty("transform");
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
t = (now - j.start) / j.dur;
|
|
49
|
+
if (t >= 1) {
|
|
50
|
+
finish(card, j);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const f = j.frame(Math.max(0, t));
|
|
55
|
+
host.spin(card, f.theta, f.lift);
|
|
56
|
+
turned.add(card);
|
|
57
|
+
last.set(card, f);
|
|
58
|
+
if (f.scale !== 1) card.style.transform = `scale(${f.scale.toFixed(4)})`;
|
|
59
|
+
else card.style.removeProperty("transform");
|
|
60
|
+
frames++;
|
|
61
|
+
}
|
|
62
|
+
if (jobs.size) raf = requestAnimationFrame(tick);
|
|
63
|
+
}
|
|
64
|
+
function finish(card, j) {
|
|
65
|
+
jobs.delete(card);
|
|
66
|
+
if (turned.has(card)) {
|
|
67
|
+
host.restore(card);
|
|
68
|
+
turned.delete(card);
|
|
69
|
+
}
|
|
70
|
+
card.style.removeProperty("transform");
|
|
71
|
+
j.done?.();
|
|
72
|
+
}
|
|
73
|
+
function run(j) {
|
|
74
|
+
const old = jobs.get(j.card);
|
|
75
|
+
if (old) finish(j.card, old);
|
|
76
|
+
jobs.set(j.card, j);
|
|
77
|
+
if (!raf) raf = requestAnimationFrame(tick);
|
|
78
|
+
}
|
|
79
|
+
const MAX_EFFECTS = 8;
|
|
80
|
+
let effects = 0;
|
|
81
|
+
const counted = (p) => {
|
|
82
|
+
effects++;
|
|
83
|
+
return p.finally(() => {
|
|
84
|
+
effects--;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
function appear(card) {
|
|
88
|
+
if (!s.enabled || effects >= MAX_EFFECTS) return Promise.resolve();
|
|
89
|
+
return counted(appearNow(card));
|
|
90
|
+
}
|
|
91
|
+
function disappear(card) {
|
|
92
|
+
if (!s.enabled || effects >= MAX_EFFECTS) return Promise.resolve();
|
|
93
|
+
return counted(disappearNow(card));
|
|
94
|
+
}
|
|
95
|
+
function appearNow(card) {
|
|
96
|
+
const d = T.appear[s.appear] / speed;
|
|
97
|
+
if (s.appear === "spin") {
|
|
98
|
+
return new Promise((res) => run({ card, start: performance.now(), dur: d, frame: (t) => ({ theta: (1 - ease(t)) * TAU, lift: 0, scale: Math.max(1e-3, ease(t)) }), done: res }));
|
|
99
|
+
}
|
|
100
|
+
const kf = s.appear === "scale" ? [{ transform: "scale(0)" }, { transform: "scale(1)" }] : s.appear === "dissolve" ? [{ opacity: 0, filter: "blur(4px)" }, { opacity: 1, filter: "blur(0px)" }] : [{ transform: "scale(0)", easing: "cubic-bezier(.3,0,.4,1)" }, { transform: "scale(1.16)", offset: 0.55, easing: "ease-in-out" }, { transform: "scale(.95)", offset: 0.78, easing: "ease-in-out" }, { transform: "scale(1)" }];
|
|
101
|
+
const a = card.animate(kf, { duration: d, easing: s.appear === "inflate" ? "linear" : "ease-out" });
|
|
102
|
+
return a.finished.then(() => void 0, () => void 0);
|
|
103
|
+
}
|
|
104
|
+
function disappearNow(card) {
|
|
105
|
+
const d = T.disappear[s.appear] / speed;
|
|
106
|
+
if (s.appear === "spin") {
|
|
107
|
+
return new Promise((res) => run({ card, start: performance.now(), dur: d, frame: (t) => ({ theta: easeIn(t) * TAU, lift: 0, scale: Math.max(1e-3, 1 - easeIn(t)) }), done: () => {
|
|
108
|
+
card.style.transform = "scale(0)";
|
|
109
|
+
res();
|
|
110
|
+
} }));
|
|
111
|
+
}
|
|
112
|
+
const kf = s.appear === "scale" ? [{ transform: "scale(1)" }, { transform: "scale(0)" }] : s.appear === "dissolve" ? [{ opacity: 1, filter: "blur(0px)" }, { opacity: 0, filter: "blur(4px)" }] : [{ transform: "scale(1)" }, { transform: "scale(1.08)", offset: 0.3 }, { transform: "scale(0)" }];
|
|
113
|
+
const a = card.animate(kf, { duration: d, easing: "ease-in", fill: "forwards" });
|
|
114
|
+
return a.finished.then(() => void 0, () => void 0);
|
|
115
|
+
}
|
|
116
|
+
function stopIdle(card) {
|
|
117
|
+
idleAnims.get(card)?.cancel();
|
|
118
|
+
idleAnims.delete(card);
|
|
119
|
+
const j = jobs.get(card);
|
|
120
|
+
if (j?.repeat) finish(card, j);
|
|
121
|
+
}
|
|
122
|
+
function startIdle(card, period) {
|
|
123
|
+
stopIdle(card);
|
|
124
|
+
if (!s.enabled || s.idle === "none" || card.classList.contains("still")) return;
|
|
125
|
+
const id = card.getAttribute(key) ?? card.getAttribute(alt) ?? "";
|
|
126
|
+
const P = (period ?? T.period[s.idle]) / speed, off = phaseOf(id) * P;
|
|
127
|
+
if (s.idle === "pirouette") {
|
|
128
|
+
const dur = (PIR.windup + PIR.turn + PIR.land) / speed;
|
|
129
|
+
const w = PIR.windup / (PIR.windup + PIR.turn + PIR.land), l = (PIR.windup + PIR.turn) / (PIR.windup + PIR.turn + PIR.land);
|
|
130
|
+
run({ card, start: 0, dur, repeat: P, offset: off, frame: (t) => {
|
|
131
|
+
if (t < w) return { theta: -0.35 * Math.sin(t / w * Math.PI / 2), lift: 0, scale: 1 };
|
|
132
|
+
if (t < l) {
|
|
133
|
+
const u2 = (t - w) / (l - w);
|
|
134
|
+
return { theta: -0.35 * (1 - u2) + ease(u2) * TAU, lift: 0.9 * Math.sin(u2 * Math.PI), scale: 1 };
|
|
135
|
+
}
|
|
136
|
+
const u = (t - l) / (1 - l);
|
|
137
|
+
return { theta: 0, lift: 0, scale: 1 - 0.04 * Math.sin(u * Math.PI) };
|
|
138
|
+
} });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const float = card.querySelector(`.${prefix}-float`) ?? card;
|
|
142
|
+
const amber = host.amber();
|
|
143
|
+
const kf = s.idle === "jiggle" ? [{ transform: "scale(1)", offset: 0 }, { transform: "scale(1.07)", offset: 0.04 }, { transform: "scale(.97)", offset: 0.08 }, { transform: "scale(1.02)", offset: 0.11 }, { transform: "scale(1)", offset: 0.14 }, { transform: "scale(1)", offset: 1 }] : s.idle === "glow" ? [{ filter: `drop-shadow(0 0 0px ${amber})` }, { filter: `drop-shadow(0 0 7px ${amber})` }, { filter: `drop-shadow(0 0 0px ${amber})` }] : [{ transform: "scale(1)" }, { transform: "scale(1.035)" }, { transform: "scale(1)" }];
|
|
144
|
+
const a = float.animate(kf, { duration: P, iterations: Infinity, easing: s.idle === "jiggle" ? "linear" : "ease-in-out" });
|
|
145
|
+
a.startTime = (document.timeline.currentTime ?? 0) - ((document.timeline.currentTime ?? 0) + off) % P;
|
|
146
|
+
idleAnims.set(card, a);
|
|
147
|
+
}
|
|
148
|
+
function update(prev, cur, gone, animateOut, still = false) {
|
|
149
|
+
if (still) animateOut = false;
|
|
150
|
+
for (const [from, card] of cur) {
|
|
151
|
+
if (!prev.has(from) && !still) void appear(card);
|
|
152
|
+
if (!idleAnims.has(card) && !jobs.get(card)?.repeat) startIdle(card);
|
|
153
|
+
}
|
|
154
|
+
if (!s.enabled || !animateOut) return;
|
|
155
|
+
const layer = host.leavingLayer();
|
|
156
|
+
if (!layer) return;
|
|
157
|
+
for (const [from, expired] of gone) {
|
|
158
|
+
const old = prev.get(from);
|
|
159
|
+
if (!old || cur.has(from)) continue;
|
|
160
|
+
stopIdle(old);
|
|
161
|
+
old.setAttribute("class", `${prefix}-leaving${expired ? " expired" : ""}`);
|
|
162
|
+
old.removeAttribute(alt);
|
|
163
|
+
layer.append(old);
|
|
164
|
+
void disappear(old).then(() => old.remove());
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function stopAll(root) {
|
|
168
|
+
for (const [card, j] of [...jobs]) finish(card, j);
|
|
169
|
+
if (raf) cancelAnimationFrame(raf);
|
|
170
|
+
raf = 0;
|
|
171
|
+
for (const a of document.getAnimations()) {
|
|
172
|
+
const t = a.effect?.target;
|
|
173
|
+
if (t?.closest?.(`.live-layer, .${prefix}-leaving-layer`)) a.cancel();
|
|
174
|
+
}
|
|
175
|
+
host.leavingLayer()?.replaceChildren();
|
|
176
|
+
void root;
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
get settings() {
|
|
180
|
+
return { ...s };
|
|
181
|
+
},
|
|
182
|
+
set(next, cards) {
|
|
183
|
+
const was = s;
|
|
184
|
+
s = { ...s, ...next };
|
|
185
|
+
if (!s.enabled || was.idle !== s.idle || was.enabled !== s.enabled) {
|
|
186
|
+
stopAll(void 0);
|
|
187
|
+
if (s.enabled) for (const c of cards) startIdle(c);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
update,
|
|
191
|
+
appear,
|
|
192
|
+
disappear,
|
|
193
|
+
startIdle,
|
|
194
|
+
stopIdle,
|
|
195
|
+
stopAll,
|
|
196
|
+
/** Preview: on each card, appear, then a few idle cycles, then disappear, then back as it was (still) and idling */
|
|
197
|
+
async preview(cards) {
|
|
198
|
+
if (!s.enabled) return;
|
|
199
|
+
await Promise.all(cards.map(async (c) => {
|
|
200
|
+
stopIdle(c);
|
|
201
|
+
await appear(c);
|
|
202
|
+
if (s.idle !== "none" && !c.classList.contains("still")) {
|
|
203
|
+
const P = s.idle === "pirouette" ? 1800 : 1400;
|
|
204
|
+
startIdle(c, P);
|
|
205
|
+
await new Promise((r) => setTimeout(r, P * 2.2 / speed));
|
|
206
|
+
stopIdle(c);
|
|
207
|
+
} else await new Promise((r) => setTimeout(r, 700 / speed));
|
|
208
|
+
await disappear(c);
|
|
209
|
+
for (const a of c.getAnimations()) a.cancel();
|
|
210
|
+
c.style.removeProperty("transform");
|
|
211
|
+
startIdle(c);
|
|
212
|
+
}));
|
|
213
|
+
},
|
|
214
|
+
/** for the tests */
|
|
215
|
+
get stats() {
|
|
216
|
+
return { jobs: jobs.size, raf: !!raf, frames, effects };
|
|
217
|
+
},
|
|
218
|
+
setSpeed(n) {
|
|
219
|
+
speed = n;
|
|
220
|
+
},
|
|
221
|
+
lastFrame: (card) => last.get(card)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
APPEARS,
|
|
226
|
+
IDLES,
|
|
227
|
+
cardMotion
|
|
228
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
function h(tag, attrs = null, ...kids) {
|
|
2
|
+
const el = document.createElement(tag);
|
|
3
|
+
for (const [k, v] of Object.entries(attrs ?? {})) {
|
|
4
|
+
if (v === void 0 || v === null || v === false) continue;
|
|
5
|
+
if (k === "class") el.className = String(v);
|
|
6
|
+
else if (k === "on") for (const [ev, fn] of Object.entries(v)) el.addEventListener(ev, fn);
|
|
7
|
+
else el.setAttribute(k, v === true ? "" : String(v));
|
|
8
|
+
}
|
|
9
|
+
for (const kid of kids) if (kid !== void 0 && kid !== null && kid !== false) el.append(kid instanceof Node ? kid : document.createTextNode(String(kid)));
|
|
10
|
+
return el;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
h
|
|
14
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { boardOf } from "../iso-objects/board.js";
|
|
2
|
+
import { layoutFlat } from "../iso-objects/flat.js";
|
|
3
|
+
import { flatSvg, measureIn } from "./flat-view.js";
|
|
4
|
+
import { buildLayer, clamp, ease, markConnectors } from "./morph.js";
|
|
5
|
+
let seq = 0;
|
|
6
|
+
function dualView(host, scene, opts = {}) {
|
|
7
|
+
const uid = `dv${++seq}`;
|
|
8
|
+
const root = document.createElement("div");
|
|
9
|
+
root.className = "dual-view";
|
|
10
|
+
root.style.position = "relative";
|
|
11
|
+
host.appendChild(root);
|
|
12
|
+
const wrap3 = document.createElement("div"), wrap2 = document.createElement("div");
|
|
13
|
+
wrap3.className = "dual-3d";
|
|
14
|
+
wrap2.className = "dual-2d";
|
|
15
|
+
root.append(wrap3, wrap2);
|
|
16
|
+
wrap3.innerHTML = scene.rendered.svg;
|
|
17
|
+
const svg3 = wrap3.querySelector("svg");
|
|
18
|
+
svg3.setAttribute("data-view", "3d");
|
|
19
|
+
const board = opts.board ?? boardOf(scene);
|
|
20
|
+
markConnectors(svg3, scene, board);
|
|
21
|
+
const routeIds = new Set(scene.routes.map((r) => r.id));
|
|
22
|
+
for (const g of svg3.querySelectorAll("g[data-id]")) {
|
|
23
|
+
const id = g.getAttribute("data-id");
|
|
24
|
+
if (routeIds.has(id) || g.hasAttribute("tabindex") || !g.querySelector("polygon")) continue;
|
|
25
|
+
g.setAttribute("tabindex", "0");
|
|
26
|
+
g.setAttribute("role", "button");
|
|
27
|
+
g.setAttribute("aria-label", id);
|
|
28
|
+
}
|
|
29
|
+
const measure = measureIn(wrap2);
|
|
30
|
+
const layout = layoutFlat(board, measure, opts.flat);
|
|
31
|
+
measure.dispose();
|
|
32
|
+
wrap2.innerHTML = flatSvg(layout, { id: uid, title: opts.title, styles: opts.styles });
|
|
33
|
+
const svg2 = wrap2.querySelector("svg");
|
|
34
|
+
for (const s of [svg3, svg2]) {
|
|
35
|
+
s.style.display = "block";
|
|
36
|
+
s.style.width = "100%";
|
|
37
|
+
s.style.height = "auto";
|
|
38
|
+
}
|
|
39
|
+
if (opts.title) svg3.setAttribute("aria-label", opts.title);
|
|
40
|
+
let mode = opts.mode ?? "3d", sel;
|
|
41
|
+
const wrapOf = (m) => m === "3d" ? wrap3 : wrap2;
|
|
42
|
+
const svgOf = (m) => m === "3d" ? svg3 : svg2;
|
|
43
|
+
const show = (m) => {
|
|
44
|
+
wrap3.hidden = m !== "3d";
|
|
45
|
+
wrap2.hidden = m !== "2d";
|
|
46
|
+
for (const w of [wrap3, wrap2]) w.style.cssText = "";
|
|
47
|
+
root.style.height = "";
|
|
48
|
+
root.dataset.mode = m;
|
|
49
|
+
};
|
|
50
|
+
show(mode);
|
|
51
|
+
const paint = () => {
|
|
52
|
+
for (const s of [svg3, svg2]) {
|
|
53
|
+
for (const e of s.querySelectorAll("[data-id]")) e.classList.toggle("sel", !!sel && e.getAttribute("data-id") === sel);
|
|
54
|
+
for (const e of s.querySelectorAll("[data-a]")) {
|
|
55
|
+
const on = !!sel && (e.getAttribute("data-a") === sel || e.getAttribute("data-b") === sel);
|
|
56
|
+
e.classList.toggle("hot", on);
|
|
57
|
+
e.classList.toggle("dim", !!sel && !on);
|
|
58
|
+
const lab = s.querySelector(`[data-for="${CSS.escape(e.getAttribute("data-id") ?? "")}"]`);
|
|
59
|
+
lab?.classList.toggle("dim", !!sel && !on);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const select = (id) => {
|
|
64
|
+
sel = id;
|
|
65
|
+
paint();
|
|
66
|
+
};
|
|
67
|
+
const onClick = (e) => {
|
|
68
|
+
const g = e.target.closest?.("[data-id]");
|
|
69
|
+
if (!g || !root.contains(g) || g.hasAttribute("data-a")) return;
|
|
70
|
+
const id = g.getAttribute("data-id");
|
|
71
|
+
select(id);
|
|
72
|
+
opts.onSelect?.(id);
|
|
73
|
+
};
|
|
74
|
+
const onKey = (e) => {
|
|
75
|
+
if ((e.key === "Enter" || e.key === " ") && e.target.matches?.("[data-id][tabindex]")) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
onClick(e);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
root.addEventListener("click", onClick);
|
|
81
|
+
root.addEventListener("keydown", onKey);
|
|
82
|
+
let run;
|
|
83
|
+
const finish = () => {
|
|
84
|
+
if (!run) return;
|
|
85
|
+
cancelAnimationFrame(run.frame);
|
|
86
|
+
run.layer.remove();
|
|
87
|
+
const r = run;
|
|
88
|
+
run = void 0;
|
|
89
|
+
mode = r.to;
|
|
90
|
+
show(mode);
|
|
91
|
+
paint();
|
|
92
|
+
r.done();
|
|
93
|
+
};
|
|
94
|
+
const focusSelected = (had) => {
|
|
95
|
+
if (!had || !sel) return;
|
|
96
|
+
svgOf(mode).querySelector(`[data-id="${CSS.escape(sel)}"][tabindex]`)?.focus({ preventScroll: true });
|
|
97
|
+
};
|
|
98
|
+
const morph = (to) => {
|
|
99
|
+
const hadFocus = root.contains(document.activeElement);
|
|
100
|
+
if (run) finish();
|
|
101
|
+
if (to === mode) {
|
|
102
|
+
focusSelected(hadFocus);
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
}
|
|
105
|
+
const motion = opts.motion ?? "auto";
|
|
106
|
+
const reduced = motion === "never" || motion === "auto" && typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
107
|
+
if (reduced || !(opts.duration ?? 600)) {
|
|
108
|
+
mode = to;
|
|
109
|
+
show(mode);
|
|
110
|
+
paint();
|
|
111
|
+
focusSelected(hadFocus);
|
|
112
|
+
return Promise.resolve();
|
|
113
|
+
}
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
const from = mode;
|
|
116
|
+
const h0 = root.getBoundingClientRect().height;
|
|
117
|
+
wrap3.hidden = false;
|
|
118
|
+
wrap2.hidden = false;
|
|
119
|
+
for (const w of [wrap3, wrap2]) w.style.cssText = "position:absolute;left:0;top:0;right:0;visibility:hidden";
|
|
120
|
+
const h1 = wrapOf(to).getBoundingClientRect().height;
|
|
121
|
+
root.style.height = `${h0}px`;
|
|
122
|
+
const layer = buildLayer(root, svgOf(from), svgOf(to), from);
|
|
123
|
+
root.appendChild(layer.svg);
|
|
124
|
+
const T = opts.duration ?? 600, t0 = performance.now();
|
|
125
|
+
const me = { frame: 0, layer: layer.svg, to, done: () => {
|
|
126
|
+
focusSelected(hadFocus);
|
|
127
|
+
resolve();
|
|
128
|
+
} };
|
|
129
|
+
const step = (now) => {
|
|
130
|
+
if (run !== me) return;
|
|
131
|
+
const t = Math.min(1, (now - t0) / T);
|
|
132
|
+
layer.at(t);
|
|
133
|
+
root.style.height = `${h0 + (h1 - h0) * ease(clamp((t - 0.2) / 0.6))}px`;
|
|
134
|
+
if (t < 1) me.frame = requestAnimationFrame(step);
|
|
135
|
+
else finish();
|
|
136
|
+
};
|
|
137
|
+
run = me;
|
|
138
|
+
me.frame = requestAnimationFrame(step);
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
get mode() {
|
|
143
|
+
return run ? run.to : mode;
|
|
144
|
+
},
|
|
145
|
+
layout,
|
|
146
|
+
root,
|
|
147
|
+
morph,
|
|
148
|
+
select,
|
|
149
|
+
get selected() {
|
|
150
|
+
return sel;
|
|
151
|
+
},
|
|
152
|
+
svgOf,
|
|
153
|
+
destroy() {
|
|
154
|
+
if (run) finish();
|
|
155
|
+
root.removeEventListener("click", onClick);
|
|
156
|
+
root.removeEventListener("keydown", onKey);
|
|
157
|
+
root.remove();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function storedMode(key = "iso-view") {
|
|
162
|
+
try {
|
|
163
|
+
const v = localStorage.getItem(key);
|
|
164
|
+
return v === "2d" || v === "3d" ? v : void 0;
|
|
165
|
+
} catch {
|
|
166
|
+
return void 0;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function viewToggle(host, views, opts = {}) {
|
|
170
|
+
const key = opts.storageKey ?? "iso-view", list = Array.isArray(views) ? views : [views];
|
|
171
|
+
const box = document.createElement("div");
|
|
172
|
+
box.className = "view-switch";
|
|
173
|
+
box.setAttribute("role", "group");
|
|
174
|
+
box.setAttribute("aria-label", "Drawing view");
|
|
175
|
+
const btns = ["3d", "2d"].map((m, i) => {
|
|
176
|
+
const b = document.createElement("button");
|
|
177
|
+
b.type = "button";
|
|
178
|
+
b.dataset.mode = m;
|
|
179
|
+
b.textContent = (opts.labels ?? ["3D", "2D"])[i];
|
|
180
|
+
b.addEventListener("click", () => {
|
|
181
|
+
try {
|
|
182
|
+
localStorage.setItem(key, m);
|
|
183
|
+
} catch {
|
|
184
|
+
}
|
|
185
|
+
paint(m);
|
|
186
|
+
for (const v of list) void v.morph(m);
|
|
187
|
+
});
|
|
188
|
+
box.appendChild(b);
|
|
189
|
+
return b;
|
|
190
|
+
});
|
|
191
|
+
const paint = (m) => btns.forEach((b) => b.setAttribute("aria-pressed", String(b.dataset.mode === m)));
|
|
192
|
+
paint(list[0]?.mode ?? "3d");
|
|
193
|
+
host.appendChild(box);
|
|
194
|
+
return box;
|
|
195
|
+
}
|
|
196
|
+
const DUAL_VIEW_CSS = `
|
|
197
|
+
.view-switch{display:inline-flex;border:1px solid var(--line);border-radius:8px;overflow:hidden;background:var(--surface);font:600 12px/1 system-ui,sans-serif;box-shadow:0 1px 4px rgba(0,0,0,.12)}
|
|
198
|
+
.view-switch button{font:inherit;border:0;background:none;color:var(--ink);padding:6px 10px;cursor:pointer}
|
|
199
|
+
.view-switch button+button{border-left:1px solid var(--line)}
|
|
200
|
+
.view-switch button[aria-pressed=true]{background:var(--accent,#2f6fd6);color:#fff}
|
|
201
|
+
.view-switch button:focus-visible{outline:2px solid var(--accent,#2f6fd6);outline-offset:-2px}
|
|
202
|
+
.dual-view [data-id][tabindex]:focus-visible{outline:none}
|
|
203
|
+
.dual-view .blk.sel polygon{stroke:var(--accent,#2f6fd6);stroke-width:2.4}
|
|
204
|
+
.dual-view [data-a].dim{opacity:.3}
|
|
205
|
+
.dual-view [data-a].hot path{stroke-width:3.4}
|
|
206
|
+
`;
|
|
207
|
+
export {
|
|
208
|
+
DUAL_VIEW_CSS,
|
|
209
|
+
dualView,
|
|
210
|
+
storedMode,
|
|
211
|
+
viewToggle
|
|
212
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { tag, esc } from "../iso-core/kernel.js";
|
|
2
|
+
const MARKS = {
|
|
3
|
+
arrow: { d: "M0,0 L10,5 L0,10 z", refX: 9 },
|
|
4
|
+
open: { d: "M0,0 L10,5 L0,10 L3,5 z", refX: 9 },
|
|
5
|
+
diamond: { d: "M0,5 L5,1.5 L10,5 L5,8.5 z", refX: 1 }
|
|
6
|
+
};
|
|
7
|
+
const f = (v) => (Math.round(v * 10) / 10).toString();
|
|
8
|
+
const kindOf = (k) => (k ?? "link").replace(/[^\w-]/g, "_");
|
|
9
|
+
function flatSvg(L, opts) {
|
|
10
|
+
const { id } = opts, styles = opts.styles ?? {}, o = L.options;
|
|
11
|
+
const b = L.bounds;
|
|
12
|
+
const used = /* @__PURE__ */ new Map();
|
|
13
|
+
const mark = (kind, end) => {
|
|
14
|
+
const st = styles[kind] ?? {}, shape = end === "start" ? st.start ?? "none" : st.end ?? "arrow";
|
|
15
|
+
if (shape === "none") return void 0;
|
|
16
|
+
(used.get(kind) ?? used.set(kind, /* @__PURE__ */ new Set()).get(kind)).add(shape);
|
|
17
|
+
return `url(#${id}-mk-${kind}-${shape})`;
|
|
18
|
+
};
|
|
19
|
+
let panels = "", conns = "", cards = "", labels = "";
|
|
20
|
+
for (const p of [...L.panels].sort((x, y) => x.depth - y.depth)) {
|
|
21
|
+
const r = p.rect;
|
|
22
|
+
const title = p.label ? tag("text", { class: "pl", x: p.titleAt[0], y: p.titleAt[1] }, esc(p.label) + (p.sub ? tag("tspan", { class: "pls", dx: 10 }, esc(p.sub)) : "")) : "";
|
|
23
|
+
panels += tag(
|
|
24
|
+
"g",
|
|
25
|
+
{ class: `panel k-${p.role ?? "grey"}`, "data-id": p.id },
|
|
26
|
+
tag("rect", { class: "face", x: f(r.l), y: f(r.t), width: f(r.r - r.l), height: f(r.b - r.t), rx: o.panelRx }) + title
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
for (const l of L.links) {
|
|
30
|
+
if (!l.points.length) continue;
|
|
31
|
+
const kind = kindOf(l.kind);
|
|
32
|
+
conns += tag("path", { class: `conn k-${kind}`, d: "M" + l.points.map((p) => `${f(p[0])},${f(p[1])}`).join(" L"), "data-id": l.id, "data-a": l.a, "data-b": l.b, "marker-start": mark(kind, "start"), "marker-end": mark(kind, "end") });
|
|
33
|
+
if (l.at) labels += tag("text", { class: `cl k-${kind}`, x: l.at.x, y: l.at.y, "text-anchor": l.at.anchor === "start" ? void 0 : l.at.anchor, "data-for": l.id }, esc(l.at.text));
|
|
34
|
+
}
|
|
35
|
+
for (const c of L.cards) {
|
|
36
|
+
const r = c.rect;
|
|
37
|
+
cards += tag(
|
|
38
|
+
"g",
|
|
39
|
+
{ class: `card k-${c.role ?? "grey"}${c.ghost ? " ghost" : ""}`, "data-id": c.id, tabindex: 0, role: "button", "aria-label": c.sub ? `${c.label}: ${c.sub}` : c.label },
|
|
40
|
+
tag("rect", { class: "face", x: f(r.l), y: f(r.t), width: o.W, height: o.H, rx: o.cardRx }) + tag("text", { class: "lt", x: f(r.l + 14), y: f(r.t + 24) }, esc(c.label)) + (c.sub ? tag("text", { class: "st", x: f(r.l + 14), y: f(r.t + 42) }, esc(c.sub)) : "")
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
let defs = "";
|
|
44
|
+
for (const [kind, shapes] of used) for (const s of shapes) {
|
|
45
|
+
const m = MARKS[s];
|
|
46
|
+
defs += tag(
|
|
47
|
+
"marker",
|
|
48
|
+
{ id: `${id}-mk-${kind}-${s}`, viewBox: "0 0 10 10", refX: m.refX, refY: 5, markerWidth: 5.4, markerHeight: 5.4, orient: "auto-start-reverse" },
|
|
49
|
+
tag("path", { d: m.d, class: `mk k-${kind}` })
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return tag(
|
|
53
|
+
"svg",
|
|
54
|
+
{ xmlns: "http://www.w3.org/2000/svg", class: "flat", viewBox: `${f(b.l)} ${f(b.t)} ${f(b.r - b.l)} ${f(b.b - b.t)}`, role: "img", "aria-label": opts.title ?? "drawing, flat view", "data-view": "2d" },
|
|
55
|
+
(defs ? tag("defs", {}, defs) : "") + tag("g", { class: "panels" }, panels) + tag("g", { class: "conns" }, conns) + tag("g", { class: "cards" }, cards) + tag("g", { class: "labels" }, labels)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function flatCss(styles = {}) {
|
|
59
|
+
const col = (c) => !c ? "var(--ink)" : c.startsWith("#") || c.includes("(") ? c : `var(--${c})`;
|
|
60
|
+
let css = `
|
|
61
|
+
.flat{font-family:inherit}
|
|
62
|
+
.flat .card{cursor:pointer;outline:none}
|
|
63
|
+
.flat .card .face{fill:hsl(var(--h) var(--s) var(--l-top));stroke:hsl(var(--h) var(--s) var(--l-edge) / .55);stroke-width:1}
|
|
64
|
+
.flat .card:hover .face,.flat .card:focus-visible .face{fill:hsl(var(--h) var(--s) calc(var(--l-top) + 6%))}
|
|
65
|
+
.flat .card.ghost{opacity:.4}
|
|
66
|
+
.flat .card .lt{font-size:13px;font-weight:600;fill:var(--ink)}
|
|
67
|
+
.flat .card .st{font-size:10px;fill:var(--ink);opacity:.8}
|
|
68
|
+
.flat .panel .face{fill:color-mix(in srgb,hsl(var(--h) var(--s) var(--l-top)) 22%,var(--surface));stroke:color-mix(in srgb,hsl(var(--h) var(--s) var(--l-top)) 40%,var(--line));stroke-width:1}
|
|
69
|
+
.flat .pl{font-size:12px;font-weight:700;letter-spacing:.02em;fill:var(--ink)}
|
|
70
|
+
.flat .pls{font-size:10.5px;font-weight:400;letter-spacing:0;fill:var(--muted)}
|
|
71
|
+
.flat .conn{fill:none;stroke:var(--ink);stroke-width:1.5}
|
|
72
|
+
.flat .mk{fill:var(--ink)}
|
|
73
|
+
.flat .cl{font-size:10.5px;font-weight:600;fill:var(--ink);paint-order:stroke;stroke:var(--surface);stroke-width:4px;stroke-linejoin:round}
|
|
74
|
+
.flat .card.sel .face{stroke:var(--accent,#2f6fd6);stroke-width:2.4}
|
|
75
|
+
.flat .panel.sel .face{stroke:var(--accent,#2f6fd6);stroke-width:2}
|
|
76
|
+
.flat .conn.hot{stroke-width:3}
|
|
77
|
+
.flat .conn.dim,.flat .cl.dim{opacity:.3}
|
|
78
|
+
`;
|
|
79
|
+
for (const [kind, st] of Object.entries(styles)) {
|
|
80
|
+
const k = kindOf(kind), c = col(st.color);
|
|
81
|
+
css += `.flat .conn.k-${k}{stroke:${c}${st.dash ? `;stroke-dasharray:${st.dash}` : ""}${st.width ? `;stroke-width:${st.width}` : ""}} .flat .mk.k-${k}{fill:${c}} .flat .cl.k-${k}{fill:${c}}
|
|
82
|
+
`;
|
|
83
|
+
}
|
|
84
|
+
return css;
|
|
85
|
+
}
|
|
86
|
+
const FONT_CLASS = { name: ["card", "lt"], sub: ["card", "st"], title: ["panel", "pl"], titleSub: ["panel", "pls"], label: ["", "cl"] };
|
|
87
|
+
function measureIn(host) {
|
|
88
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
89
|
+
const svg = document.createElementNS(NS, "svg");
|
|
90
|
+
svg.setAttribute("class", "flat");
|
|
91
|
+
svg.setAttribute("aria-hidden", "true");
|
|
92
|
+
svg.style.cssText = "position:absolute;left:-10000px;top:0;width:10px;height:10px;visibility:hidden";
|
|
93
|
+
host.appendChild(svg);
|
|
94
|
+
const els = {};
|
|
95
|
+
for (const [font, [g, cls]] of Object.entries(FONT_CLASS)) {
|
|
96
|
+
const wrap = document.createElementNS(NS, "g");
|
|
97
|
+
if (g) wrap.setAttribute("class", g);
|
|
98
|
+
const t = document.createElementNS(NS, "text");
|
|
99
|
+
t.setAttribute("class", cls);
|
|
100
|
+
wrap.appendChild(t);
|
|
101
|
+
svg.appendChild(wrap);
|
|
102
|
+
els[font] = t;
|
|
103
|
+
}
|
|
104
|
+
const memo = /* @__PURE__ */ new Map();
|
|
105
|
+
const m = ((text, font) => {
|
|
106
|
+
const key = font + "\0" + text;
|
|
107
|
+
let w = memo.get(key);
|
|
108
|
+
if (w === void 0) {
|
|
109
|
+
els[font].textContent = text;
|
|
110
|
+
w = els[font].getComputedTextLength();
|
|
111
|
+
memo.set(key, w);
|
|
112
|
+
}
|
|
113
|
+
return w;
|
|
114
|
+
});
|
|
115
|
+
m.dispose = () => svg.remove();
|
|
116
|
+
return m;
|
|
117
|
+
}
|
|
118
|
+
const rectOf = (L, id) => L.cards.find((c) => c.id === id)?.rect ?? L.panels.find((p) => p.id === id)?.rect;
|
|
119
|
+
export {
|
|
120
|
+
flatCss,
|
|
121
|
+
flatSvg,
|
|
122
|
+
measureIn,
|
|
123
|
+
rectOf
|
|
124
|
+
};
|