@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,98 @@
|
|
|
1
|
+
import { MIN_ZOOM, viewport, MAX_ZOOM } from "./viewport.js";
|
|
2
|
+
import { CARD, P3, pts, overlayPaint } from "./overlay.js";
|
|
3
|
+
import { APPEARS, IDLES, cardMotion } from "./card-motion.js";
|
|
4
|
+
import { n, node, rewrite, prune, cls, attr, extent, unite, fitWithOverlay } from "./still.js";
|
|
5
|
+
import { isoVars, scopeSelector, scope } from "./view-css.js";
|
|
6
|
+
import { md, stepData, legend, renderPage } from "./page.js";
|
|
7
|
+
import { playerScript } from "./bundle.js";
|
|
8
|
+
import { h } from "./dom.js";
|
|
9
|
+
import { TIMELINE_VERSION, SEGMENT_NAME, SEVERITIES, BINS, BIN_MS, scopePattern } from "./timeline-contract.js";
|
|
10
|
+
import { scopeRules, escapeName, formatScope, join, levelOf, prefixAt, parentOf, within, hasSegment, kindOf, nameOf, crumbs } from "./timeline-scope.js";
|
|
11
|
+
import { BASE_FIELDS, readTime, searchFor, rangeOf, highlights, severities } from "./timeline-search.js";
|
|
12
|
+
import { offsetAt, isZone, binStart, binNext } from "./timeline-time.js";
|
|
13
|
+
import { findGaps, gapLabel, gapKey, timeScale, ticks } from "./timeline-scale.js";
|
|
14
|
+
import { toJSON, toCSV } from "./timeline-export.js";
|
|
15
|
+
import { memorySource } from "./timeline-engine.js";
|
|
16
|
+
import { modeFor, activityOf, mountTimeline } from "./history.js";
|
|
17
|
+
import { flatSvg, flatCss, measureIn, rectOf } from "./flat-view.js";
|
|
18
|
+
import { dualView, storedMode, viewToggle, DUAL_VIEW_CSS } from "./dual-view.js";
|
|
19
|
+
import { morphSvgs, markConnectors } from "./morph.js";
|
|
20
|
+
export {
|
|
21
|
+
APPEARS,
|
|
22
|
+
BASE_FIELDS,
|
|
23
|
+
BINS,
|
|
24
|
+
BIN_MS,
|
|
25
|
+
CARD,
|
|
26
|
+
DUAL_VIEW_CSS,
|
|
27
|
+
IDLES,
|
|
28
|
+
MAX_ZOOM,
|
|
29
|
+
MIN_ZOOM,
|
|
30
|
+
P3,
|
|
31
|
+
SEGMENT_NAME,
|
|
32
|
+
SEVERITIES,
|
|
33
|
+
TIMELINE_VERSION,
|
|
34
|
+
activityOf,
|
|
35
|
+
attr,
|
|
36
|
+
binNext,
|
|
37
|
+
binStart,
|
|
38
|
+
cardMotion,
|
|
39
|
+
cls,
|
|
40
|
+
crumbs,
|
|
41
|
+
dualView,
|
|
42
|
+
escapeName,
|
|
43
|
+
extent,
|
|
44
|
+
findGaps,
|
|
45
|
+
fitWithOverlay,
|
|
46
|
+
flatCss,
|
|
47
|
+
flatSvg,
|
|
48
|
+
formatScope,
|
|
49
|
+
gapKey,
|
|
50
|
+
gapLabel,
|
|
51
|
+
h,
|
|
52
|
+
hasSegment,
|
|
53
|
+
highlights,
|
|
54
|
+
isZone,
|
|
55
|
+
isoVars,
|
|
56
|
+
join,
|
|
57
|
+
kindOf,
|
|
58
|
+
legend,
|
|
59
|
+
levelOf,
|
|
60
|
+
markConnectors,
|
|
61
|
+
md,
|
|
62
|
+
measureIn,
|
|
63
|
+
memorySource,
|
|
64
|
+
modeFor,
|
|
65
|
+
morphSvgs,
|
|
66
|
+
mountTimeline,
|
|
67
|
+
n,
|
|
68
|
+
nameOf,
|
|
69
|
+
node,
|
|
70
|
+
offsetAt,
|
|
71
|
+
overlayPaint,
|
|
72
|
+
parentOf,
|
|
73
|
+
playerScript,
|
|
74
|
+
prefixAt,
|
|
75
|
+
prune,
|
|
76
|
+
pts,
|
|
77
|
+
rangeOf,
|
|
78
|
+
readTime,
|
|
79
|
+
rectOf,
|
|
80
|
+
renderPage,
|
|
81
|
+
rewrite,
|
|
82
|
+
scope,
|
|
83
|
+
scopePattern,
|
|
84
|
+
scopeRules,
|
|
85
|
+
scopeSelector,
|
|
86
|
+
searchFor,
|
|
87
|
+
severities,
|
|
88
|
+
stepData,
|
|
89
|
+
storedMode,
|
|
90
|
+
ticks,
|
|
91
|
+
timeScale,
|
|
92
|
+
toCSV,
|
|
93
|
+
toJSON,
|
|
94
|
+
unite,
|
|
95
|
+
viewToggle,
|
|
96
|
+
viewport,
|
|
97
|
+
within
|
|
98
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { parseEnd } from "../iso-objects/route.js";
|
|
2
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
3
|
+
function markConnectors(svg3, scene, board) {
|
|
4
|
+
const links = new Map((board?.links ?? []).map((l, i) => [l.id ?? `link-${i}`, l]));
|
|
5
|
+
for (const r of scene.routes) {
|
|
6
|
+
const l = links.get(r.id), a = l?.a ?? parseEnd(r.raw.from).id, b = l?.b ?? parseEnd(r.raw.to).id;
|
|
7
|
+
for (const g of svg3.querySelectorAll(`[data-id="${CSS.escape(r.id)}"]`)) {
|
|
8
|
+
g.setAttribute("data-a", a);
|
|
9
|
+
g.setAttribute("data-b", b);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const morphs = (motion = "auto") => motion === "always" || motion === "auto" && !(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
14
|
+
function morphSvgs(root, fromSvg, toSvg, from, o = {}) {
|
|
15
|
+
const T = o.duration ?? 600;
|
|
16
|
+
if (!T || !morphs(o.motion)) return void 0;
|
|
17
|
+
const layer = buildLayer(root, fromSvg, toSvg, from);
|
|
18
|
+
root.appendChild(layer.svg);
|
|
19
|
+
layer.at(0);
|
|
20
|
+
let frame = 0, over = false, resolve;
|
|
21
|
+
const done = new Promise((r) => resolve = r);
|
|
22
|
+
const finish = () => {
|
|
23
|
+
if (over) return;
|
|
24
|
+
over = true;
|
|
25
|
+
cancelAnimationFrame(frame);
|
|
26
|
+
layer.svg.remove();
|
|
27
|
+
resolve();
|
|
28
|
+
};
|
|
29
|
+
const t0 = performance.now();
|
|
30
|
+
const step = (now) => {
|
|
31
|
+
if (over) return;
|
|
32
|
+
const t = Math.min(1, (now - t0) / T);
|
|
33
|
+
layer.at(t);
|
|
34
|
+
if (t < 1) frame = requestAnimationFrame(step);
|
|
35
|
+
else finish();
|
|
36
|
+
};
|
|
37
|
+
frame = requestAnimationFrame(step);
|
|
38
|
+
return { done, finish };
|
|
39
|
+
}
|
|
40
|
+
const clamp = (v) => Math.max(0, Math.min(1, v));
|
|
41
|
+
const ease = (t) => t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
|
|
42
|
+
function paintedClone(el) {
|
|
43
|
+
const c = el.cloneNode(true);
|
|
44
|
+
const src = [el, ...el.querySelectorAll("*")], dst = [c, ...c.querySelectorAll("*")];
|
|
45
|
+
src.forEach((s, i) => {
|
|
46
|
+
const cs = getComputedStyle(s), d = dst[i];
|
|
47
|
+
d.removeAttribute("class");
|
|
48
|
+
d.removeAttribute("tabindex");
|
|
49
|
+
for (const p of ["fill", "fill-opacity", "stroke", "stroke-width", "stroke-dasharray", "stroke-opacity", "opacity", "font-size", "font-weight", "font-family", "letter-spacing", "paint-order", "stroke-linejoin", "text-anchor"]) d.style.setProperty(p, cs.getPropertyValue(p));
|
|
50
|
+
});
|
|
51
|
+
return c;
|
|
52
|
+
}
|
|
53
|
+
const rectIn = (el, origin) => {
|
|
54
|
+
const r = el.getBoundingClientRect();
|
|
55
|
+
return { x: r.left - origin.left, y: r.top - origin.top, w: r.width, h: r.height };
|
|
56
|
+
};
|
|
57
|
+
const union = (rs) => {
|
|
58
|
+
const x0 = Math.min(...rs.map((r) => r.x)), y0 = Math.min(...rs.map((r) => r.y)), x1 = Math.max(...rs.map((r) => r.x + r.w)), y1 = Math.max(...rs.map((r) => r.y + r.h));
|
|
59
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
|
|
60
|
+
};
|
|
61
|
+
const ctmIn = (svg, origin) => {
|
|
62
|
+
const m = svg.getScreenCTM();
|
|
63
|
+
return `matrix(${m.a} ${m.b} ${m.c} ${m.d} ${m.e - origin.left} ${m.f - origin.top})`;
|
|
64
|
+
};
|
|
65
|
+
const toward = (a, b, t) => {
|
|
66
|
+
const sx = 1 + (b.w / Math.max(a.w, 1e-6) - 1) * t, sy = 1 + (b.h / Math.max(a.h, 1e-6) - 1) * t;
|
|
67
|
+
const tx = (b.x - a.x * (b.w / Math.max(a.w, 1e-6))) * t, ty = (b.y - a.y * (b.h / Math.max(a.h, 1e-6))) * t;
|
|
68
|
+
return `matrix(${sx} 0 0 ${sy} ${tx} ${ty})`;
|
|
69
|
+
};
|
|
70
|
+
function topFace(g, origin) {
|
|
71
|
+
const poly = g.querySelector("polygon.top");
|
|
72
|
+
if (!poly) return void 0;
|
|
73
|
+
const m = poly.getScreenCTM(), pts = [];
|
|
74
|
+
for (let i = 0; i < poly.points.numberOfItems; i++) {
|
|
75
|
+
const p = poly.points.getItem(i);
|
|
76
|
+
pts.push([m.a * p.x + m.c * p.y + m.e - origin.left, m.b * p.x + m.d * p.y + m.f - origin.top]);
|
|
77
|
+
}
|
|
78
|
+
return pts.length === 4 ? { pts, fill: getComputedStyle(poly).fill } : void 0;
|
|
79
|
+
}
|
|
80
|
+
function buildLayer(root, fromSvg, toSvg, from) {
|
|
81
|
+
const origin = root.getBoundingClientRect();
|
|
82
|
+
const layer = document.createElementNS(NS, "svg");
|
|
83
|
+
layer.setAttribute("class", "dual-morph");
|
|
84
|
+
layer.setAttribute("aria-hidden", "true");
|
|
85
|
+
layer.style.cssText = `position:absolute;left:0;top:0;width:${origin.width}px;height:${Math.max(origin.height, fromSvg.getBoundingClientRect().height, toSvg.getBoundingClientRect().height)}px;overflow:visible;pointer-events:none`;
|
|
86
|
+
const inUser = (svg) => {
|
|
87
|
+
const g = document.createElementNS(NS, "g");
|
|
88
|
+
g.setAttribute("transform", ctmIn(svg, origin));
|
|
89
|
+
return g;
|
|
90
|
+
};
|
|
91
|
+
const isConn = (e) => e.hasAttribute("data-a") || e.hasAttribute("data-for");
|
|
92
|
+
const things = (svg) => {
|
|
93
|
+
const m = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const e of svg.querySelectorAll("[data-id]")) {
|
|
95
|
+
if (isConn(e) || e.parentElement?.closest("[data-id]") || e.closest(".overlay")) continue;
|
|
96
|
+
const id = e.getAttribute("data-id");
|
|
97
|
+
(m.get(id) ?? m.set(id, []).get(id)).push(e);
|
|
98
|
+
}
|
|
99
|
+
return m;
|
|
100
|
+
};
|
|
101
|
+
const A = things(fromSvg), B = things(toSvg);
|
|
102
|
+
const connsOut = document.createElementNS(NS, "g"), connsIn = document.createElementNS(NS, "g");
|
|
103
|
+
const cOut = inUser(fromSvg), cIn = inUser(toSvg);
|
|
104
|
+
for (const e of fromSvg.querySelectorAll("[data-a],[data-for]")) if (!e.closest(".overlay")) cOut.appendChild(paintedClone(e));
|
|
105
|
+
for (const e of toSvg.querySelectorAll("[data-a],[data-for]")) if (!e.closest(".overlay")) cIn.appendChild(paintedClone(e));
|
|
106
|
+
connsOut.appendChild(cOut);
|
|
107
|
+
connsIn.appendChild(cIn);
|
|
108
|
+
const drawIn = [...cIn.querySelectorAll("path")].map((p) => {
|
|
109
|
+
const len = p.getTotalLength?.() ?? 0;
|
|
110
|
+
return { p, len };
|
|
111
|
+
});
|
|
112
|
+
const inLabels = [...cIn.children].filter((e) => e.tagName.toLowerCase() === "text");
|
|
113
|
+
const order = [...(from === "2d" ? A : B).keys()];
|
|
114
|
+
const items = [];
|
|
115
|
+
const shapes = document.createElementNS(NS, "g");
|
|
116
|
+
for (const id of /* @__PURE__ */ new Set([...order, ...A.keys(), ...B.keys()])) {
|
|
117
|
+
const ea = A.get(id), eb = B.get(id);
|
|
118
|
+
const it = {};
|
|
119
|
+
if (ea) {
|
|
120
|
+
it.a = union(ea.map((e) => rectIn(e, origin)));
|
|
121
|
+
const g = document.createElementNS(NS, "g"), u = inUser(fromSvg);
|
|
122
|
+
for (const e of ea) u.appendChild(paintedClone(e));
|
|
123
|
+
g.appendChild(u);
|
|
124
|
+
it.src = g;
|
|
125
|
+
}
|
|
126
|
+
if (eb) {
|
|
127
|
+
it.b = union(eb.map((e) => rectIn(e, origin)));
|
|
128
|
+
const g = document.createElementNS(NS, "g"), u = inUser(toSvg);
|
|
129
|
+
for (const e of eb) u.appendChild(paintedClone(e));
|
|
130
|
+
g.appendChild(u);
|
|
131
|
+
it.dst = g;
|
|
132
|
+
}
|
|
133
|
+
const g3 = from === "3d" ? ea?.[0] : eb?.[0], g2 = from === "3d" ? eb?.[0] : ea?.[0];
|
|
134
|
+
const top = g3 ? topFace(g3, origin) : void 0, face2 = g2?.querySelector("rect.face");
|
|
135
|
+
if (top && face2) {
|
|
136
|
+
const r = rectIn(face2, origin);
|
|
137
|
+
const flat = [[r.x, r.y], [r.x + r.w, r.y], [r.x + r.w, r.y + r.h], [r.x, r.y + r.h]];
|
|
138
|
+
const k = top.pts.reduce((m, p, i) => p[0] < top.pts[m][0] ? i : m, 0);
|
|
139
|
+
const rot = [...top.pts.slice(k), ...top.pts.slice(0, k)];
|
|
140
|
+
const ordered = [rot[0], rot[1], rot[2], rot[3]];
|
|
141
|
+
const f2 = getComputedStyle(face2).fill;
|
|
142
|
+
const poly = document.createElementNS(NS, "polygon");
|
|
143
|
+
it.face = poly;
|
|
144
|
+
it.faceFrom = from === "3d" ? ordered : flat;
|
|
145
|
+
it.faceTo = from === "3d" ? flat : ordered;
|
|
146
|
+
it.faceFill = from === "3d" ? [top.fill, f2] : [f2, top.fill];
|
|
147
|
+
}
|
|
148
|
+
if (it.src) shapes.appendChild(it.src);
|
|
149
|
+
if (it.face) shapes.appendChild(it.face);
|
|
150
|
+
if (it.dst) shapes.appendChild(it.dst);
|
|
151
|
+
items.push(it);
|
|
152
|
+
}
|
|
153
|
+
layer.append(connsOut, shapes, connsIn);
|
|
154
|
+
const mix = (a, b, t) => `color-mix(in srgb, ${a} ${Math.round((1 - t) * 100)}%, ${b})`;
|
|
155
|
+
return {
|
|
156
|
+
svg: layer,
|
|
157
|
+
at(t) {
|
|
158
|
+
const out = clamp(t / 0.2), mid = ease(clamp((t - 0.2) / 0.6)), inn = clamp((t - 0.8) / 0.2);
|
|
159
|
+
connsOut.setAttribute("opacity", String(1 - out));
|
|
160
|
+
for (const { p, len } of drawIn) {
|
|
161
|
+
p.style.strokeDasharray = `${len} ${len}`;
|
|
162
|
+
p.style.strokeDashoffset = String(len * (1 - inn));
|
|
163
|
+
}
|
|
164
|
+
connsIn.setAttribute("opacity", String(inn > 0 ? 1 : 0));
|
|
165
|
+
for (const l of inLabels) l.style.opacity = String(inn);
|
|
166
|
+
for (const it of items) {
|
|
167
|
+
if (it.src) {
|
|
168
|
+
it.src.setAttribute("transform", it.a && it.b ? toward(it.a, it.b, mid) : "");
|
|
169
|
+
it.src.setAttribute("opacity", String(it.b ? 1 - clamp(mid / (it.face ? 0.35 : 0.6)) : 1 - mid));
|
|
170
|
+
}
|
|
171
|
+
if (it.dst) {
|
|
172
|
+
it.dst.setAttribute("transform", it.a && it.b ? toward(it.b, it.a, 1 - mid) : "");
|
|
173
|
+
it.dst.setAttribute("opacity", String(it.a ? clamp((mid - (it.face ? 0.65 : 0.4)) / (it.face ? 0.35 : 0.6)) : mid));
|
|
174
|
+
}
|
|
175
|
+
if (it.face) {
|
|
176
|
+
const pts = it.faceFrom.map((p, i) => [p[0] + (it.faceTo[i][0] - p[0]) * mid, p[1] + (it.faceTo[i][1] - p[1]) * mid]);
|
|
177
|
+
it.face.setAttribute("points", pts.map((p) => p.join(",")).join(" "));
|
|
178
|
+
it.face.style.fill = mix(it.faceFill[0], it.faceFill[1], mid);
|
|
179
|
+
it.face.setAttribute("opacity", String(mid < 0.08 ? mid / 0.08 : mid > 0.92 ? (1 - mid) / 0.08 : 1));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export {
|
|
186
|
+
buildLayer,
|
|
187
|
+
clamp,
|
|
188
|
+
ease,
|
|
189
|
+
markConnectors,
|
|
190
|
+
morphSvgs,
|
|
191
|
+
morphs
|
|
192
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { C, S } from "../iso-core/kernel.js";
|
|
2
|
+
import { overlaps } from "../iso-objects/geometry.js";
|
|
3
|
+
const SVGNS = "http://www.w3.org/2000/svg";
|
|
4
|
+
const CARD = { half: 2.4, h: 3.2, t: 0.25, above: 1.4, lift: 3.8, fan: 0.32, gap: 0.3 };
|
|
5
|
+
const P3 = (x, y, z) => [(x - y) * C * S, (x + y) * 0.5 * S - z * S];
|
|
6
|
+
const pts = (ps) => ps.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(" ");
|
|
7
|
+
function overlayPaint(ctx, cards) {
|
|
8
|
+
function paintMarks(d, put, marks) {
|
|
9
|
+
const k = ctx.k();
|
|
10
|
+
const glyph = (x, y, spec, title, extra = "") => {
|
|
11
|
+
const g = d.createElementNS(SVGNS, "g");
|
|
12
|
+
g.setAttribute("class", `live-badge ${spec.cls} ${extra}`.trim());
|
|
13
|
+
const rr = 8 / k;
|
|
14
|
+
const c = d.createElementNS(SVGNS, "circle");
|
|
15
|
+
c.setAttribute("cx", String(x));
|
|
16
|
+
c.setAttribute("cy", String(y));
|
|
17
|
+
c.setAttribute("r", String(rr));
|
|
18
|
+
g.append(c);
|
|
19
|
+
if ("g" in spec) {
|
|
20
|
+
const t = d.createElementNS(SVGNS, "text");
|
|
21
|
+
t.setAttribute("x", String(x));
|
|
22
|
+
t.setAttribute("y", String(y));
|
|
23
|
+
t.style.fontSize = `${(10 / k).toFixed(2)}px`;
|
|
24
|
+
t.textContent = spec.g;
|
|
25
|
+
g.append(t);
|
|
26
|
+
} else {
|
|
27
|
+
const u = d.createElementNS(SVGNS, "use");
|
|
28
|
+
u.setAttribute("href", ctx.iconHref(spec.icon));
|
|
29
|
+
const s = 11 / k;
|
|
30
|
+
u.setAttribute("x", String(x - s / 2));
|
|
31
|
+
u.setAttribute("y", String(y - s / 2));
|
|
32
|
+
u.setAttribute("width", String(s));
|
|
33
|
+
u.setAttribute("height", String(s));
|
|
34
|
+
g.append(u);
|
|
35
|
+
}
|
|
36
|
+
const tt = d.createElementNS(SVGNS, "title");
|
|
37
|
+
tt.textContent = title;
|
|
38
|
+
g.append(tt);
|
|
39
|
+
put(g);
|
|
40
|
+
};
|
|
41
|
+
const outline = (at, cls) => {
|
|
42
|
+
for (const sh of ctx.outlinesFor(at)) {
|
|
43
|
+
if (sh.kind !== "poly") continue;
|
|
44
|
+
const p = d.createElementNS(SVGNS, "polygon");
|
|
45
|
+
p.setAttribute("class", cls);
|
|
46
|
+
p.setAttribute("points", sh.points.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(" "));
|
|
47
|
+
put(p);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (const m of marks) {
|
|
51
|
+
const b = ctx.boxOf(m.at);
|
|
52
|
+
if (!b) continue;
|
|
53
|
+
if (m.outline) outline(m.at, m.outline);
|
|
54
|
+
if (m.badge) glyph(b.x, b.y, m.badge, m.title);
|
|
55
|
+
else if (m.hit) {
|
|
56
|
+
const t = d.createElementNS(SVGNS, "title");
|
|
57
|
+
t.textContent = m.title;
|
|
58
|
+
const hit = d.createElementNS(SVGNS, "rect");
|
|
59
|
+
hit.setAttribute("class", "live-hit");
|
|
60
|
+
hit.setAttribute("x", String(b.x));
|
|
61
|
+
hit.setAttribute("y", String(b.y));
|
|
62
|
+
hit.setAttribute("width", String(b.w));
|
|
63
|
+
hit.setAttribute("height", String(b.h));
|
|
64
|
+
hit.append(t);
|
|
65
|
+
put(hit);
|
|
66
|
+
}
|
|
67
|
+
(m.beside ?? []).forEach((x, i) => glyph(b.x + 18 * (i + 1) / k, b.y, x.glyph, x.title));
|
|
68
|
+
if (m.dot) glyph(b.x, b.y + b.h, m.dot.glyph, m.dot.title);
|
|
69
|
+
if (m.tag) {
|
|
70
|
+
const t = d.createElementNS(SVGNS, "text");
|
|
71
|
+
t.setAttribute("class", `live-life ${m.tag.cls}`);
|
|
72
|
+
t.setAttribute("x", String(b.x + b.w));
|
|
73
|
+
t.setAttribute("y", String(b.y + b.h));
|
|
74
|
+
t.style.fontSize = `${(9 / k).toFixed(2)}px`;
|
|
75
|
+
t.textContent = m.tag.text;
|
|
76
|
+
put(t);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function paintGhosts(d, put, ghosts) {
|
|
81
|
+
for (const gh of ghosts) {
|
|
82
|
+
const g = d.createElementNS(SVGNS, "g");
|
|
83
|
+
g.setAttribute("class", `live-extra${gh.cls}`);
|
|
84
|
+
for (const [a, v] of gh.data) g.setAttribute(a, v);
|
|
85
|
+
const { x, y, w, hgt, k } = gh.rect;
|
|
86
|
+
const r = d.createElementNS(SVGNS, "rect");
|
|
87
|
+
r.setAttribute("x", String(x));
|
|
88
|
+
r.setAttribute("y", String(y));
|
|
89
|
+
r.setAttribute("width", String(w));
|
|
90
|
+
r.setAttribute("height", String(hgt));
|
|
91
|
+
r.setAttribute("rx", String(6 / k));
|
|
92
|
+
const t1 = d.createElementNS(SVGNS, "text");
|
|
93
|
+
t1.setAttribute("x", String(x + 8 / k));
|
|
94
|
+
t1.setAttribute("y", String(y + 13 / k));
|
|
95
|
+
t1.style.fontSize = `${(11 / k).toFixed(2)}px`;
|
|
96
|
+
t1.textContent = gh.line1;
|
|
97
|
+
const t2 = d.createElementNS(SVGNS, "text");
|
|
98
|
+
t2.setAttribute("class", "sub");
|
|
99
|
+
t2.setAttribute("x", String(x + 8 / k));
|
|
100
|
+
t2.setAttribute("y", String(y + 27 / k));
|
|
101
|
+
t2.style.fontSize = `${(9 / k).toFixed(2)}px`;
|
|
102
|
+
t2.textContent = gh.line2;
|
|
103
|
+
const tt = d.createElementNS(SVGNS, "title");
|
|
104
|
+
tt.textContent = gh.title;
|
|
105
|
+
g.append(r, t1, t2, tt);
|
|
106
|
+
put(g);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function paintCards(d, put, list) {
|
|
110
|
+
const placed = [];
|
|
111
|
+
for (const cd of list) {
|
|
112
|
+
const b = cd.over, cx = (b.x0 + b.x1) / 2, cy = (b.y0 + b.y1) / 2;
|
|
113
|
+
let lift = 0, bbox = { x0: 0, y0: 0, x1: 0, y1: 0 };
|
|
114
|
+
for (let tries = 0; tries < 6; tries++) {
|
|
115
|
+
const z02 = b.z1 + CARD.above + lift, z12 = z02 + CARD.h;
|
|
116
|
+
const corners = [P3(cx - CARD.half, cy + CARD.t, z02), P3(cx + CARD.half, cy + CARD.t, z02), P3(cx + CARD.half, cy - CARD.t, z12), P3(cx - CARD.half, cy + CARD.t, z12)];
|
|
117
|
+
bbox = { x0: Math.min(...corners.map((p) => p[0])), y0: Math.min(...corners.map((p) => p[1])), x1: Math.max(...corners.map((p) => p[0])), y1: Math.max(...corners.map((p) => p[1])) };
|
|
118
|
+
if (!overlaps(bbox, placed)) break;
|
|
119
|
+
lift += CARD.lift;
|
|
120
|
+
}
|
|
121
|
+
placed.push(bbox);
|
|
122
|
+
const z0 = b.z1 + CARD.above + lift, z1 = z0 + CARD.h, x0 = cx - CARD.half, x1 = cx + CARD.half, yf = cy + CARD.t, yb = cy - CARD.t;
|
|
123
|
+
const g = d.createElementNS(SVGNS, "g");
|
|
124
|
+
g.setAttribute("class", `${cards}-card${cd.cls}`);
|
|
125
|
+
for (const [a, v] of cd.data) g.setAttribute(a, v);
|
|
126
|
+
const [tipX, tipY] = P3(cx, cy, b.z1 + 0.15);
|
|
127
|
+
const origin = `${tipX.toFixed(1)}px ${tipY.toFixed(1)}px`;
|
|
128
|
+
g.style.transformOrigin = origin;
|
|
129
|
+
const float = d.createElementNS(SVGNS, "g");
|
|
130
|
+
float.setAttribute("class", `${cards}-float`);
|
|
131
|
+
float.style.transformOrigin = origin;
|
|
132
|
+
const panes = [];
|
|
133
|
+
for (let i = Math.min(cd.count - 1, 3); i >= 1; i--) {
|
|
134
|
+
const o = i * CARD.fan, pf = yb - (i - 1) * (2 * CARD.t + CARD.gap) - CARD.gap, pb = pf - 2 * CARD.t;
|
|
135
|
+
const a0 = x0 + o, a1 = x1 + o, h0 = z0 + o, h1 = z1 + o;
|
|
136
|
+
const pane = (cls, ps) => {
|
|
137
|
+
const f = d.createElementNS(SVGNS, "polygon");
|
|
138
|
+
f.setAttribute("class", `${cards}-face stacked ${cls}`);
|
|
139
|
+
f.setAttribute("points", pts(ps));
|
|
140
|
+
float.append(f);
|
|
141
|
+
};
|
|
142
|
+
pane("s-top", [P3(a0, pb, h1), P3(a1, pb, h1), P3(a1, pf, h1), P3(a0, pf, h1)]);
|
|
143
|
+
pane("s-side", [P3(a1, pb, h0), P3(a1, pf, h0), P3(a1, pf, h1), P3(a1, pb, h1)]);
|
|
144
|
+
pane("s-front", [P3(a0, pf, h0), P3(a1, pf, h0), P3(a1, pf, h1), P3(a0, pf, h1)]);
|
|
145
|
+
panes.push({ x0: a0, x1: a1, y0: pb, y1: pf, z0: h0, z1: h1 });
|
|
146
|
+
}
|
|
147
|
+
const tail = d.createElementNS(SVGNS, "polygon");
|
|
148
|
+
tail.setAttribute("class", `${cards}-tail`);
|
|
149
|
+
tail.setAttribute("points", pts([P3(cx - 0.5, yf, z0 + 0.05), P3(cx + 0.5, yf, z0 + 0.05), P3(cx, cy, b.z1 + 0.15)]));
|
|
150
|
+
const face = (cls, ps) => {
|
|
151
|
+
const f = d.createElementNS(SVGNS, "polygon");
|
|
152
|
+
f.setAttribute("class", cls);
|
|
153
|
+
f.setAttribute("points", pts(ps));
|
|
154
|
+
return f;
|
|
155
|
+
};
|
|
156
|
+
const front = face(`${cards}-face front`, [P3(x0, yf, z0), P3(x1, yf, z0), P3(x1, yf, z1), P3(x0, yf, z1)]);
|
|
157
|
+
float.append(
|
|
158
|
+
tail,
|
|
159
|
+
face(`${cards}-face top`, [P3(x0, yb, z1), P3(x1, yb, z1), P3(x1, yf, z1), P3(x0, yf, z1)]),
|
|
160
|
+
face(`${cards}-face side`, [P3(x1, yb, z0), P3(x1, yf, z0), P3(x1, yf, z1), P3(x1, yb, z1)]),
|
|
161
|
+
front
|
|
162
|
+
);
|
|
163
|
+
const [ox, oy] = P3(x0, yf, z1), U = 40;
|
|
164
|
+
const txt = d.createElementNS(SVGNS, "g");
|
|
165
|
+
txt.setAttribute("transform", `matrix(${(C * S / U).toFixed(4)} ${(0.5 * S / U).toFixed(4)} 0 ${(S / U).toFixed(4)} ${ox.toFixed(1)} ${oy.toFixed(1)})`);
|
|
166
|
+
const t = (cls, x, y, text) => {
|
|
167
|
+
const e = d.createElementNS(SVGNS, "text");
|
|
168
|
+
e.setAttribute("class", cls);
|
|
169
|
+
e.setAttribute("x", String(x));
|
|
170
|
+
e.setAttribute("y", String(y));
|
|
171
|
+
e.textContent = text;
|
|
172
|
+
return e;
|
|
173
|
+
};
|
|
174
|
+
txt.append(t(`${cards}-mark`, 34, 98, cd.mark), t(`${cards}-who`, 70, 52, cd.who), t(`${cards}-age`, 70, 82, cd.age));
|
|
175
|
+
if (cd.line !== void 0) txt.append(t(`${cards}-q`, 12, 118, cd.line));
|
|
176
|
+
if (cd.count > 1) {
|
|
177
|
+
const c = d.createElementNS(SVGNS, "circle");
|
|
178
|
+
c.setAttribute("class", `${cards}-count-bg`);
|
|
179
|
+
c.setAttribute("cx", "178");
|
|
180
|
+
c.setAttribute("cy", "14");
|
|
181
|
+
c.setAttribute("r", "15");
|
|
182
|
+
txt.append(c, t(`${cards}-count`, 178, 14, String(cd.count)));
|
|
183
|
+
}
|
|
184
|
+
float.append(txt);
|
|
185
|
+
const title = d.createElementNS(SVGNS, "title");
|
|
186
|
+
title.textContent = cd.title;
|
|
187
|
+
g.append(float, title);
|
|
188
|
+
ctx.onCard?.(g, { cx, cy, tipZ: b.z1 + 0.15, card: { x0, x1, y0: yb, y1: yf, z0, z1 }, panes: panes.reverse() });
|
|
189
|
+
put(g);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return { paintMarks, paintGhosts, paintCards };
|
|
193
|
+
}
|
|
194
|
+
export {
|
|
195
|
+
CARD,
|
|
196
|
+
P3,
|
|
197
|
+
overlayPaint,
|
|
198
|
+
pts
|
|
199
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { esc } from "../iso-core/kernel.js";
|
|
2
|
+
import { themeCss } from "../iso-core/theme.js";
|
|
3
|
+
import { baseCss, PLAYER_CSS } from "../iso-objects/css.js";
|
|
4
|
+
import { regionKind } from "../iso-objects/kinds.js";
|
|
5
|
+
import { colorRef } from "../iso-core/theme.js";
|
|
6
|
+
const SCRIPT = ["<", "script"].join("");
|
|
7
|
+
function md(s) {
|
|
8
|
+
if (!s) return "";
|
|
9
|
+
return esc(s).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>").replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_m, t, u) => /^(https?:|#|\.{0,2}\/)/.test(u.replace(/&/g, "&")) ? `<a href="${u}">${t}</a>` : t);
|
|
10
|
+
}
|
|
11
|
+
const paras = (s) => (s ?? "").split(/\n\s*\n/).filter(Boolean).map((p) => `<p class="sec-sub">${md(p.trim())}</p>`).join("");
|
|
12
|
+
function stepData(c) {
|
|
13
|
+
return JSON.stringify({
|
|
14
|
+
scenes: c.scenes.map((s) => ({
|
|
15
|
+
id: s.id,
|
|
16
|
+
loop: s.raw.loop ?? true,
|
|
17
|
+
dim: s.raw.dim ?? "flows",
|
|
18
|
+
vis: s.steps.vis,
|
|
19
|
+
steps: s.steps.steps.map((st) => ({ ...st, caption: md(st.caption) })),
|
|
20
|
+
assemble: s.assemble,
|
|
21
|
+
grid: !!s.grid.show,
|
|
22
|
+
assembly: s.rendered.assembly
|
|
23
|
+
}))
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function legend(c, s) {
|
|
27
|
+
const t = c.theme, spec = s.raw.legend;
|
|
28
|
+
if (spec === false) return "";
|
|
29
|
+
const kinds = Array.isArray(spec) ? spec : s.steps.kindsUsed.filter((k) => s.routes.some((r) => r.kind === k) || s.steps.steps.some((st) => st.phases.some((p) => p.some((tk) => tk.kind === k))));
|
|
30
|
+
const row = (l) => `<span><i${l.box ? ' class="box"' : ""} style="${l.swatch}"></i>${l.label}</span>`;
|
|
31
|
+
const items = kinds.map((k) => {
|
|
32
|
+
const rl = regionKind(c.catalog, k)?.legend;
|
|
33
|
+
if (rl) return row(rl);
|
|
34
|
+
const d = t.kinds[k];
|
|
35
|
+
if (!d) return "";
|
|
36
|
+
const style = `border-color:${colorRef(t, d.color)}${d.dash === "dashed" ? ";border-top-style:dashed" : d.dash === "dotted" ? ";border-top-style:dotted" : ""}`;
|
|
37
|
+
return `<span><i style="${style}"></i>${md(d.legend)}</span>`;
|
|
38
|
+
});
|
|
39
|
+
if (!Array.isArray(spec)) {
|
|
40
|
+
const kindsOf = new Set(s.layout.items.map((p) => p.region?.kind));
|
|
41
|
+
for (const [name, rk] of Object.entries(c.catalog.regions)) if (rk.legend?.auto && kindsOf.has(name)) items.push(row(rk.legend));
|
|
42
|
+
}
|
|
43
|
+
return items.join("");
|
|
44
|
+
}
|
|
45
|
+
function player(s) {
|
|
46
|
+
const st = s.steps.steps;
|
|
47
|
+
const tools = `<div class="tools">
|
|
48
|
+
<button class="pbtn small" type="button" data-a="grid" aria-pressed="${s.grid.show ? "true" : "false"}" title="Show the floor grid">Grid</button>
|
|
49
|
+
<button class="pbtn small" type="button" data-a="assemble" title="Draw the diagram again, piece by piece">Assemble</button>
|
|
50
|
+
</div>`;
|
|
51
|
+
if (!st.length) return `<div class="player">${tools}</div>`;
|
|
52
|
+
const f = st[0];
|
|
53
|
+
return `<div class="player">
|
|
54
|
+
<div class="ctrls">
|
|
55
|
+
<button class="pbtn icon" type="button" data-a="prev" aria-label="Previous step">\u2039</button>
|
|
56
|
+
<button class="pbtn primary" type="button" data-a="play" aria-label="Play">\u25B6 Play</button>
|
|
57
|
+
<button class="pbtn icon" type="button" data-a="next" aria-label="Next step">\u203A</button>
|
|
58
|
+
</div>
|
|
59
|
+
${tools}
|
|
60
|
+
<div class="cap" aria-live="polite">
|
|
61
|
+
<div class="cap-h"><span class="num" style="background:${f.color}">${f.num}</span><span class="h">${esc(f.heading)}</span><span class="cnt">1 / ${st.length}</span></div>
|
|
62
|
+
<p class="cap-t">${md(f.caption)}</p>
|
|
63
|
+
<pre class="cap-c">${esc(f.command)}</pre>
|
|
64
|
+
<div class="prog"><i></i></div>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="dots"></div>
|
|
67
|
+
</div>`;
|
|
68
|
+
}
|
|
69
|
+
function stepList(s) {
|
|
70
|
+
const st = s.steps.steps;
|
|
71
|
+
if (!st.length) return "";
|
|
72
|
+
return `<details class="steps"><summary>All ${st.length} steps as text</summary><ol>${st.map((x) => `<li value="${x.num}"><b>${esc(x.heading)}.</b> ${md(x.caption)}${x.command ? `<br><code>${esc(x.command)}</code>` : ""}</li>`).join("")}</ol></details>`;
|
|
73
|
+
}
|
|
74
|
+
function renderPage(c, opts = {}) {
|
|
75
|
+
const doc = c.doc, title = doc.title ?? doc.scenes[0]?.title ?? "Diagram";
|
|
76
|
+
const pills = (doc.pills ?? []).map((p) => `<span class="pill">${md(p)}</span>`).join("");
|
|
77
|
+
const sections = c.scenes.map((s) => `
|
|
78
|
+
<section class="scene" id="scene-${esc(s.id)}">
|
|
79
|
+
<h2>${esc(s.raw.title)}</h2>
|
|
80
|
+
${paras(s.raw.caption)}
|
|
81
|
+
<div class="figure" tabindex="-1">
|
|
82
|
+
<div class="scroller">${s.grid.show ? s.rendered.svg.replace("<svg ", '<svg class="show-grid" ') : s.rendered.svg}</div>
|
|
83
|
+
${player(s)}
|
|
84
|
+
<div class="legend">${legend(c, s)}</div>
|
|
85
|
+
</div>
|
|
86
|
+
${stepList(s)}
|
|
87
|
+
${s.raw.after ? `<div class="after">${paras(s.raw.after)}</div>` : ""}
|
|
88
|
+
</section>`).join("\n");
|
|
89
|
+
return `<!doctype html>
|
|
90
|
+
<html lang="en">
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="utf-8">
|
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
94
|
+
<title>${esc(title)}</title>
|
|
95
|
+
${doc.lede ? `<meta name="description" content="${esc(doc.lede)}">` : ""}
|
|
96
|
+
<style>
|
|
97
|
+
${themeCss(c.theme)}${baseCss(c.catalog)}${PLAYER_CSS}
|
|
98
|
+
</style>
|
|
99
|
+
${opts.extraHead ?? ""}
|
|
100
|
+
</head>
|
|
101
|
+
<body>
|
|
102
|
+
<div class="wrap">
|
|
103
|
+
<header class="page">
|
|
104
|
+
<div>
|
|
105
|
+
<h1>${esc(title)}</h1>
|
|
106
|
+
${doc.lede ? `<p class="lede">${md(doc.lede)}</p>` : ""}
|
|
107
|
+
</div>
|
|
108
|
+
<div class="pills">${pills}<button class="theme" id="themeBtn" type="button">Theme</button></div>
|
|
109
|
+
</header>
|
|
110
|
+
${sections}
|
|
111
|
+
${doc.after ? paras(doc.after) : ""}
|
|
112
|
+
${doc.footer ? `<footer>${md(doc.footer)}</footer>` : ""}
|
|
113
|
+
</div>
|
|
114
|
+
${SCRIPT} type="application/json" id="diagram-steps">${stepData(c).replace(/</g, "\\u003c")}<\/script>
|
|
115
|
+
${SCRIPT}>
|
|
116
|
+
(function(){
|
|
117
|
+
var root=document.documentElement, m=/theme=(light|dark)/.exec(location.hash);
|
|
118
|
+
try{var t=localStorage.getItem('diagram-theme'); if(t) root.dataset.theme=t;}catch(e){}
|
|
119
|
+
if(m) root.dataset.theme=m[1];
|
|
120
|
+
document.getElementById('themeBtn').addEventListener('click',function(){
|
|
121
|
+
var dark=root.dataset.theme?root.dataset.theme==='dark':matchMedia('(prefers-color-scheme: dark)').matches;
|
|
122
|
+
root.dataset.theme=dark?'light':'dark';
|
|
123
|
+
try{localStorage.setItem('diagram-theme',root.dataset.theme);}catch(e){}
|
|
124
|
+
});
|
|
125
|
+
})();
|
|
126
|
+
<\/script>
|
|
127
|
+
${opts.runtime ? `${SCRIPT}>${opts.runtime}<\/script>` : ""}
|
|
128
|
+
${opts.extraBody ?? ""}
|
|
129
|
+
</body>
|
|
130
|
+
</html>
|
|
131
|
+
`;
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
legend,
|
|
135
|
+
md,
|
|
136
|
+
renderPage,
|
|
137
|
+
stepData
|
|
138
|
+
};
|