@blackbelt-technology/pi-dashboard-deck3d 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/.pi/skills/deck3d/SKILL.md +227 -0
- package/.pi/skills/deck3d/examples/deck.json +388 -0
- package/.pi/skills/deck3d/examples/fixture.md +18 -0
- package/.pi/skills/deck3d/examples/snapshot-after.png +0 -0
- package/.pi/skills/deck3d/examples/snapshot-before.png +0 -0
- package/.pi/skills/deck3d/reference/effects.agent.md +78 -0
- package/.pi/skills/deck3d/reference/effects.md +1217 -0
- package/.pi/skills/deck3d/reference/ir-fields.agent.md +30 -0
- package/.pi/skills/deck3d/reference/ir-fields.md +246 -0
- package/README.md +177 -2
- package/assets/LICENSE-Poppins.txt +99 -0
- package/assets/Poppins-Bold.ttf +0 -0
- package/assets/props/LICENSES.txt +4 -0
- package/assets/props/brain.glb +0 -0
- package/assets/props/cloud.glb +0 -0
- package/assets/props/cube.glb +0 -0
- package/assets/props/database.glb +0 -0
- package/assets/props/laptop.glb +0 -0
- package/assets/props/manifest.json +119 -0
- package/assets/props/robot.glb +0 -0
- package/assets/props/server.glb +0 -0
- package/assets/props/shield.glb +0 -0
- package/bin/deck3d +49 -0
- package/dist/cli.js +10228 -0
- package/dist/harvest/harness.js +185718 -0
- package/dist/runtime.js +64597 -0
- package/fixtures/business-2031/build-deck.mjs +60 -0
- package/fixtures/business-2031/build-overrides.mjs +154 -0
- package/fixtures/business-2031/deck.json +4220 -0
- package/fixtures/business-2031/deck.md +470 -0
- package/fixtures/business-2031/fx/closing-mark.js +43 -0
- package/fixtures/business-2031/fx/closing-mark.meta.json +26 -0
- package/fixtures/business-2031/overrides.json +903 -0
- package/fixtures/harvest.md +23 -0
- package/fixtures/strategy-lab.json +891 -0
- package/fixtures/strategy-lab.md +85 -0
- package/package.json +80 -4
- package/scripts/build-cli.mjs +29 -0
- package/scripts/build-harvest.ts +8 -0
- package/scripts/build-runtime.mjs +22 -0
- package/scripts/gen-effects.ts +14 -0
- package/scripts/gen-ir-fields.ts +34 -0
- package/src/check/index.ts +315 -0
- package/src/check/rules.ts +393 -0
- package/src/cli-io.ts +23 -0
- package/src/cli.ts +823 -0
- package/src/fx/accent-cycle.meta.json +26 -0
- package/src/fx/accent-cycle.ts +8 -0
- package/src/fx/agent-depth.meta.json +42 -0
- package/src/fx/agent-depth.ts +62 -0
- package/src/fx/ascii.meta.json +35 -0
- package/src/fx/ascii.ts +4 -0
- package/src/fx/aurora.meta.json +26 -0
- package/src/fx/aurora.ts +18 -0
- package/src/fx/billboards.meta.json +34 -0
- package/src/fx/billboards.ts +67 -0
- package/src/fx/bloom.meta.json +26 -0
- package/src/fx/bloom.ts +4 -0
- package/src/fx/camera-drift.meta.json +26 -0
- package/src/fx/camera-drift.ts +8 -0
- package/src/fx/capital-flows.meta.json +30 -0
- package/src/fx/capital-flows.ts +64 -0
- package/src/fx/catalogue.ts +89 -0
- package/src/fx/chromatic-aberration.meta.json +32 -0
- package/src/fx/chromatic-aberration.ts +4 -0
- package/src/fx/city-grid.meta.json +37 -0
- package/src/fx/city-grid.ts +51 -0
- package/src/fx/clipped-solids.meta.json +49 -0
- package/src/fx/clipped-solids.ts +171 -0
- package/src/fx/cohort-grid.meta.json +48 -0
- package/src/fx/cohort-grid.ts +63 -0
- package/src/fx/compose.ts +114 -0
- package/src/fx/constellation.meta.json +51 -0
- package/src/fx/constellation.ts +103 -0
- package/src/fx/curve-flow.meta.json +40 -0
- package/src/fx/curve-flow.ts +63 -0
- package/src/fx/dashed-flow.meta.json +27 -0
- package/src/fx/dashed-flow.ts +8 -0
- package/src/fx/data-columns.meta.json +30 -0
- package/src/fx/data-columns.ts +18 -0
- package/src/fx/defaults.ts +92 -0
- package/src/fx/depth-of-field.meta.json +40 -0
- package/src/fx/depth-of-field.ts +4 -0
- package/src/fx/dolly.meta.json +26 -0
- package/src/fx/dolly.ts +4 -0
- package/src/fx/dot-screen.meta.json +35 -0
- package/src/fx/dot-screen.ts +4 -0
- package/src/fx/dynamic-instances.meta.json +40 -0
- package/src/fx/dynamic-instances.ts +57 -0
- package/src/fx/emissive.meta.json +26 -0
- package/src/fx/emissive.ts +8 -0
- package/src/fx/extruded-shapes.meta.json +62 -0
- package/src/fx/extruded-shapes.ts +133 -0
- package/src/fx/fab-wafer.meta.json +42 -0
- package/src/fx/fab-wafer.ts +72 -0
- package/src/fx/fade.meta.json +26 -0
- package/src/fx/fade.ts +4 -0
- package/src/fx/film.meta.json +26 -0
- package/src/fx/film.ts +4 -0
- package/src/fx/float.meta.json +26 -0
- package/src/fx/float.ts +8 -0
- package/src/fx/flythrough.meta.json +26 -0
- package/src/fx/flythrough.ts +4 -0
- package/src/fx/fog.meta.json +26 -0
- package/src/fx/fog.ts +8 -0
- package/src/fx/geo-fragments.meta.json +48 -0
- package/src/fx/geo-fragments.ts +59 -0
- package/src/fx/glass.meta.json +26 -0
- package/src/fx/glass.ts +8 -0
- package/src/fx/globe-arcs.meta.json +36 -0
- package/src/fx/globe-arcs.ts +67 -0
- package/src/fx/glow-tube.meta.json +26 -0
- package/src/fx/glow-tube.ts +8 -0
- package/src/fx/glyph-rain.meta.json +30 -0
- package/src/fx/glyph-rain.ts +18 -0
- package/src/fx/god-rays.meta.json +40 -0
- package/src/fx/god-rays.ts +4 -0
- package/src/fx/grid-horizon.meta.json +30 -0
- package/src/fx/grid-horizon.ts +18 -0
- package/src/fx/hex-grid.meta.json +29 -0
- package/src/fx/hex-grid.ts +18 -0
- package/src/fx/holo-fresnel.meta.json +26 -0
- package/src/fx/holo-fresnel.ts +8 -0
- package/src/fx/horizon-gates.meta.json +36 -0
- package/src/fx/horizon-gates.ts +60 -0
- package/src/fx/index.ts +258 -0
- package/src/fx/iridescent.meta.json +26 -0
- package/src/fx/iridescent.ts +8 -0
- package/src/fx/iris.meta.json +26 -0
- package/src/fx/iris.ts +4 -0
- package/src/fx/lightformers.meta.json +26 -0
- package/src/fx/lightformers.ts +8 -0
- package/src/fx/local.ts +200 -0
- package/src/fx/market-tape.meta.json +53 -0
- package/src/fx/market-tape.ts +97 -0
- package/src/fx/matcap.meta.json +26 -0
- package/src/fx/matcap.ts +8 -0
- package/src/fx/meta.schema.json +49 -0
- package/src/fx/metal.meta.json +26 -0
- package/src/fx/metal.ts +8 -0
- package/src/fx/mirror-floor.meta.json +26 -0
- package/src/fx/mirror-floor.ts +8 -0
- package/src/fx/neural-mesh.meta.json +54 -0
- package/src/fx/neural-mesh.ts +110 -0
- package/src/fx/orbit-agents.meta.json +36 -0
- package/src/fx/orbit-agents.ts +63 -0
- package/src/fx/orbit.meta.json +27 -0
- package/src/fx/orbit.ts +8 -0
- package/src/fx/outline.meta.json +43 -0
- package/src/fx/outline.ts +4 -0
- package/src/fx/paper-stack.meta.json +36 -0
- package/src/fx/paper-stack.ts +61 -0
- package/src/fx/particle-stream.meta.json +27 -0
- package/src/fx/particle-stream.ts +8 -0
- package/src/fx/particles.meta.json +26 -0
- package/src/fx/particles.ts +8 -0
- package/src/fx/pixelate.meta.json +28 -0
- package/src/fx/pixelate.ts +4 -0
- package/src/fx/points-on-geometry.meta.json +61 -0
- package/src/fx/points-on-geometry.ts +71 -0
- package/src/fx/proof-gate.meta.json +30 -0
- package/src/fx/proof-gate.ts +67 -0
- package/src/fx/rings.meta.json +27 -0
- package/src/fx/rings.ts +8 -0
- package/src/fx/room-ibl.meta.json +26 -0
- package/src/fx/room-ibl.ts +8 -0
- package/src/fx/sao.meta.json +32 -0
- package/src/fx/sao.ts +4 -0
- package/src/fx/scaffold.ts +172 -0
- package/src/fx/scatter.meta.json +49 -0
- package/src/fx/scatter.ts +74 -0
- package/src/fx/selective-bloom.meta.json +36 -0
- package/src/fx/selective-bloom.ts +4 -0
- package/src/fx/server-racks.meta.json +36 -0
- package/src/fx/server-racks.ts +54 -0
- package/src/fx/shader-particles.meta.json +46 -0
- package/src/fx/shader-particles.ts +75 -0
- package/src/fx/signal-pulse.meta.json +27 -0
- package/src/fx/signal-pulse.ts +8 -0
- package/src/fx/smaa.meta.json +19 -0
- package/src/fx/smaa.ts +4 -0
- package/src/fx/sobel.meta.json +24 -0
- package/src/fx/sobel.ts +4 -0
- package/src/fx/soft-shadows.meta.json +26 -0
- package/src/fx/soft-shadows.ts +8 -0
- package/src/fx/sprites.meta.json +40 -0
- package/src/fx/sprites.ts +57 -0
- package/src/fx/stagger-reveal.meta.json +26 -0
- package/src/fx/stagger-reveal.ts +8 -0
- package/src/fx/starfield.meta.json +32 -0
- package/src/fx/starfield.ts +18 -0
- package/src/fx/swarm.meta.json +27 -0
- package/src/fx/swarm.ts +8 -0
- package/src/fx/tessellate.meta.json +39 -0
- package/src/fx/tessellate.ts +79 -0
- package/src/fx/tokens.meta.json +27 -0
- package/src/fx/tokens.ts +8 -0
- package/src/fx/trail.meta.json +27 -0
- package/src/fx/trail.ts +8 -0
- package/src/fx/trust-ledger.meta.json +30 -0
- package/src/fx/trust-ledger.ts +47 -0
- package/src/fx/types.ts +83 -0
- package/src/fx/util.ts +108 -0
- package/src/fx/vault-glyphs.meta.json +37 -0
- package/src/fx/vault-glyphs.ts +55 -0
- package/src/fx/video-screen.meta.json +57 -0
- package/src/fx/video-screen.ts +99 -0
- package/src/fx/vignette.meta.json +32 -0
- package/src/fx/vignette.ts +4 -0
- package/src/fx/volume-cloud.meta.json +58 -0
- package/src/fx/volume-cloud.ts +87 -0
- package/src/fx/volume-perlin.meta.json +46 -0
- package/src/fx/volume-perlin.ts +82 -0
- package/src/fx/volumetric-spot.meta.json +26 -0
- package/src/fx/volumetric-spot.ts +8 -0
- package/src/fx/wireframe-overlay.meta.json +27 -0
- package/src/fx/wireframe-overlay.ts +8 -0
- package/src/ir/defaults.ts +62 -0
- package/src/ir/field-reference.ts +96 -0
- package/src/ir/hash.ts +34 -0
- package/src/ir/ids.ts +65 -0
- package/src/ir/merge.ts +155 -0
- package/src/ir/schema.json +1211 -0
- package/src/ir/types.ts +333 -0
- package/src/ir/validate.ts +196 -0
- package/src/parse/derive.ts +205 -0
- package/src/parse/harvest/bundle.ts +56 -0
- package/src/parse/harvest/harness.html +22 -0
- package/src/parse/harvest/harness.ts +191 -0
- package/src/parse/harvest/index.ts +169 -0
- package/src/parse/harvest/shapes.ts +75 -0
- package/src/parse/markdown.ts +215 -0
- package/src/props/embed.ts +92 -0
- package/src/props/fetch.ts +97 -0
- package/src/props/generate.ts +152 -0
- package/src/props/key.ts +13 -0
- package/src/props/search.ts +180 -0
- package/src/render/embed-video.ts +80 -0
- package/src/render/font.ts +86 -0
- package/src/render/index.ts +149 -0
- package/src/render/template.html +87 -0
- package/src/runtime/backgrounds.ts +146 -0
- package/src/runtime/builders.ts +808 -0
- package/src/runtime/camera.ts +73 -0
- package/src/runtime/hud.ts +887 -0
- package/src/runtime/index.ts +1168 -0
- package/src/runtime/local-fx.ts +151 -0
- package/src/runtime/materials.ts +136 -0
- package/src/runtime/measure.ts +73 -0
- package/src/runtime/node-geometry.ts +26 -0
- package/src/runtime/palette.ts +111 -0
- package/src/runtime/post.ts +649 -0
- package/src/runtime/props.ts +292 -0
- package/src/runtime/quality.ts +20 -0
- package/src/runtime/rng.ts +8 -0
- package/src/runtime/scene.ts +644 -0
- package/src/runtime/text.ts +174 -0
- package/src/runtime/types.ts +118 -0
- package/src/serve/index.ts +376 -0
- package/src/util/paths.ts +35 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a `DeckIR` from parsed markdown.
|
|
3
|
+
*
|
|
4
|
+
* `defaults` and `slides[]` are regenerated every parse; only `overrides`
|
|
5
|
+
* survives (carried in from an existing deck.json, then overlaid with the
|
|
6
|
+
* markdown's inline overrides, which win and warn on a clobbered key).
|
|
7
|
+
*/
|
|
8
|
+
import { resolveDefaults } from "../ir/defaults.js";
|
|
9
|
+
import { computeDerivedHash } from "../ir/hash.js";
|
|
10
|
+
import { clone, deepMerge, findOrphanOverrides, orphanOverridePath } from "../ir/merge.js";
|
|
11
|
+
import type { BuiltDiagramKind, DeckIR, Diagram, DiagramData, Overrides } from "../ir/types.js";
|
|
12
|
+
import { type ParsedDeck, parseMarkdown } from "./markdown.js";
|
|
13
|
+
|
|
14
|
+
const YEAR = /^(19|20)\d\d$/;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* D2 built-kind table — evaluated in order, first match wins, over
|
|
18
|
+
* `title + bullets`. Word-bounded and case-insensitive so "modelling" matches
|
|
19
|
+
* `model` but "remodel" does not start a brain.
|
|
20
|
+
*/
|
|
21
|
+
const BUILT_KINDS: Array<{ kind: BuiltDiagramKind; re?: RegExp; when?: (bullets: string[], text: string) => boolean }> = [
|
|
22
|
+
{ kind: "timeline-rail", when: (_b, text) => distinctYears(text) >= 2 || /\b(timeline|road ?map)\b/i.test(text) },
|
|
23
|
+
{ kind: "bars", when: (bullets) => bullets.filter((b) => leadingMagnitude(b) !== undefined).length >= 2 },
|
|
24
|
+
{ kind: "funnel", re: /\b(funnel|pipeline|deal ?flow)\b/i },
|
|
25
|
+
{ kind: "swarm", re: /\b(agents?|swarm)\b/i },
|
|
26
|
+
{ kind: "loop", re: /\b(loop|cycle|iterat\w*)\b/i },
|
|
27
|
+
{ kind: "brain", re: /\b(LLM|model|brain|intelligence)\b/i },
|
|
28
|
+
{ kind: "globe", re: /\b(global|regions?|geo\w*|trade)\b/i },
|
|
29
|
+
{ kind: "orbit-cluster", re: /\b(ecosystem|partners?|platform)\b/i },
|
|
30
|
+
{ kind: "stack", re: /\b(compute|infra\w*|layers?)\b/i },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function distinctYears(text: string): number {
|
|
34
|
+
return new Set(text.match(/\b(?:19|20)\d\d\b/g) ?? []).size;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A bullet's leading magnitude, or `undefined` when it starts with a year or no number. */
|
|
38
|
+
function leadingMagnitude(bullet: string): number | undefined {
|
|
39
|
+
const m = /^(\d+(?:\.\d+)?)\s*%?\s*[:\u2013-]?\s*(.*)$/.exec(bullet.trim());
|
|
40
|
+
if (!m || YEAR.test(m[1])) return undefined;
|
|
41
|
+
return Number(m[1]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The caption a bullet contributes: its text with any leading magnitude stripped. */
|
|
45
|
+
function bulletLabel(bullet: string): string {
|
|
46
|
+
const trimmed = bullet.trim();
|
|
47
|
+
const m = /^(\d+(?:\.\d+)?)\s*%?\s*[:\u2013-]?\s*(.*)$/.exec(trimmed);
|
|
48
|
+
if (!m || YEAR.test(m[1]) || !m[2]) return trimmed;
|
|
49
|
+
return m[2].trim();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Built topology for a content slide with no usable mermaid block. A slide
|
|
54
|
+
* with no bullets (title, section, credits) never gets one — there is nothing
|
|
55
|
+
* to build from.
|
|
56
|
+
*/
|
|
57
|
+
export function builtKindFor(slide: { title: string; bullets: string[]; kind?: string }): BuiltDiagramKind {
|
|
58
|
+
if (slide.bullets.length === 0) return "none";
|
|
59
|
+
if (slide.kind && slide.kind !== "content") return "none";
|
|
60
|
+
const text = `${slide.title} ${slide.bullets.join(" ")}`;
|
|
61
|
+
for (const row of BUILT_KINDS) {
|
|
62
|
+
if (row.re && !row.re.test(text)) continue;
|
|
63
|
+
if (row.when && !row.when(slide.bullets, text)) continue;
|
|
64
|
+
return row.kind;
|
|
65
|
+
}
|
|
66
|
+
return "none";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Labels (always) and values (only when every bullet carries a magnitude). */
|
|
70
|
+
export function harvestData(bullets: string[]): DiagramData {
|
|
71
|
+
const labels = bullets.map(bulletLabel);
|
|
72
|
+
const values = bullets.map(leadingMagnitude);
|
|
73
|
+
return values.every((v) => v !== undefined) ? { labels, values: values as number[] } : { labels };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A mermaid harvest result: the diagram plus any warnings it produced. */
|
|
77
|
+
export interface HarvestOutcome {
|
|
78
|
+
diagram: Diagram;
|
|
79
|
+
warnings?: string[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A mermaid harvester (section 4). Injected so derive stays browser-free. */
|
|
83
|
+
export type Harvester = (mermaidSource: string, slideId: string) => Promise<HarvestOutcome>;
|
|
84
|
+
|
|
85
|
+
export interface DeriveOptions {
|
|
86
|
+
source?: string;
|
|
87
|
+
engine?: string;
|
|
88
|
+
mermaidVersion?: string;
|
|
89
|
+
/** Prior deck.json — its `overrides` are preserved unless `fresh`. */
|
|
90
|
+
previous?: DeckIR;
|
|
91
|
+
fresh?: boolean;
|
|
92
|
+
harvest?: Harvester;
|
|
93
|
+
/** Deterministic effect/scene defaults from content tags (section 7d) + topic (D3). */
|
|
94
|
+
sceneForSlide?: (slide: { id: string; title: string; bullets: string[]; diagram: Diagram }, autoStyle: boolean) => string;
|
|
95
|
+
effectsForSlide?: (
|
|
96
|
+
slide: { id: string; title: string; bullets: string[]; diagram: Diagram },
|
|
97
|
+
autoStyle: boolean,
|
|
98
|
+
) => DeckIR["slides"][number]["effects"];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface DeriveOutcome {
|
|
102
|
+
ir: DeckIR;
|
|
103
|
+
warnings: string[];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function deriveDeckIR(parsed: ParsedDeck, opts: DeriveOptions = {}): Promise<DeriveOutcome> {
|
|
107
|
+
const warnings: string[] = [];
|
|
108
|
+
const defaults = resolveDefaults(parsed.defaults);
|
|
109
|
+
const overrides = mergeOverrides(parsed, opts, warnings);
|
|
110
|
+
// `autoStyle` may be switched off in front matter or in `overrides.deck`.
|
|
111
|
+
const autoStyle = overrides.deck?.autoStyle ?? defaults.autoStyle ?? true;
|
|
112
|
+
const slides: DeckIR["slides"] = [];
|
|
113
|
+
for (const p of parsed.slides) slides.push(await buildSlide(p, defaults, opts, warnings, autoStyle));
|
|
114
|
+
|
|
115
|
+
for (const slide of slides) {
|
|
116
|
+
const ov = overrides.slides?.[slide.id]?.diagram;
|
|
117
|
+
if (!ov) continue;
|
|
118
|
+
if (slide.diagram.kind !== "flowchart" && slide.diagram.kind !== "sequence") continue;
|
|
119
|
+
for (const key of ["kind", "data"] as const) {
|
|
120
|
+
if (ov[key] === undefined) continue;
|
|
121
|
+
warnings.push(
|
|
122
|
+
`warn overrides.slides["${slide.id}"].diagram.${key} ignored while the slide has a mermaid diagram (markdown wins)`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const ir: DeckIR = {
|
|
128
|
+
meta: {
|
|
129
|
+
engine: opts.engine ?? "0.1.0",
|
|
130
|
+
mermaid: opts.mermaidVersion ?? "11.17.2",
|
|
131
|
+
...(opts.source ? { source: opts.source } : {}),
|
|
132
|
+
},
|
|
133
|
+
defaults,
|
|
134
|
+
slides,
|
|
135
|
+
overrides,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
for (const orphan of findOrphanOverrides(ir)) {
|
|
139
|
+
const suffix = orphan.kind === "slide" ? ` — pin the heading with {#${orphan.id}} to keep it` : "";
|
|
140
|
+
warnings.push(`warn orphan override ${orphanOverridePath(orphan)}${suffix}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
ir.meta.derivedHash = computeDerivedHash(ir);
|
|
144
|
+
return { ir, warnings };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function buildSlide(
|
|
148
|
+
p: ParsedDeck["slides"][number],
|
|
149
|
+
defaults: DeckIR["defaults"],
|
|
150
|
+
opts: DeriveOptions,
|
|
151
|
+
warnings: string[],
|
|
152
|
+
autoStyle: boolean,
|
|
153
|
+
): Promise<DeckIR["slides"][number]> {
|
|
154
|
+
let diagram: Diagram = { kind: "none" };
|
|
155
|
+
if (p.mermaid) {
|
|
156
|
+
if (!opts.harvest) throw new Error(`slide "${p.id}": mermaid block present but no harvester is available`);
|
|
157
|
+
const outcome = await opts.harvest(p.mermaid, p.id);
|
|
158
|
+
diagram = outcome.diagram;
|
|
159
|
+
if (outcome.warnings) warnings.push(...outcome.warnings);
|
|
160
|
+
}
|
|
161
|
+
// An unsupported fence already yielded `none` with a warning; such a slide is
|
|
162
|
+
// diagram-less here, so the built-kind table applies to it too.
|
|
163
|
+
if (autoStyle && diagram.kind === "none") {
|
|
164
|
+
const kind = builtKindFor({ title: p.title, bullets: p.bullets });
|
|
165
|
+
if (kind !== "none") diagram = { kind, data: harvestData(p.bullets) };
|
|
166
|
+
}
|
|
167
|
+
const base = { id: p.id, title: p.title, bullets: p.bullets, diagram };
|
|
168
|
+
const slide: DeckIR["slides"][number] = {
|
|
169
|
+
index: p.index,
|
|
170
|
+
id: p.id,
|
|
171
|
+
title: p.title,
|
|
172
|
+
bullets: p.bullets,
|
|
173
|
+
scene: opts.sceneForSlide ? opts.sceneForSlide(base, autoStyle) : "none",
|
|
174
|
+
diagram,
|
|
175
|
+
camera: { distance: defaults.camera?.distance },
|
|
176
|
+
labels: { size: defaults.labels?.size },
|
|
177
|
+
check: { ignore: [...(defaults.check?.ignore ?? [])] },
|
|
178
|
+
effects: opts.effectsForSlide ? opts.effectsForSlide(base, autoStyle) : [],
|
|
179
|
+
};
|
|
180
|
+
if (p.subtitle) slide.subtitle = p.subtitle;
|
|
181
|
+
return slide;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function mergeOverrides(parsed: ParsedDeck, opts: DeriveOptions, warnings: string[]): Overrides {
|
|
185
|
+
const overrides: Overrides = opts.fresh || !opts.previous ? {} : clone(opts.previous.overrides);
|
|
186
|
+
overrides.slides = { ...(overrides.slides ?? {}) };
|
|
187
|
+
for (const p of parsed.slides) {
|
|
188
|
+
if (!p.inlineOverrides) continue;
|
|
189
|
+
const existing = overrides.slides[p.id] ?? {};
|
|
190
|
+
for (const key of Object.keys(p.inlineOverrides)) {
|
|
191
|
+
if (key in existing) {
|
|
192
|
+
warnings.push(
|
|
193
|
+
`warn inline override overrides.slides["${p.id}"].${key} clobbers deck.json value (markdown wins)`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
overrides.slides[p.id] = deepMerge(existing, p.inlineOverrides) as typeof existing;
|
|
198
|
+
}
|
|
199
|
+
return overrides;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** markdown → IR in one step. */
|
|
203
|
+
export async function parseDeck(source: string, opts: DeriveOptions = {}): Promise<DeriveOutcome> {
|
|
204
|
+
return deriveDeckIR(parseMarkdown(source), opts);
|
|
205
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds and caches the browser bundle of `harness.ts` (mermaid + our harvest
|
|
3
|
+
* logic). The bundle is produced once at package build time
|
|
4
|
+
* (`scripts/build-harvest.ts` → `dist/harvest/harness.js`); in dev and tests it
|
|
5
|
+
* is rebuilt on demand when missing or stale.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { pkgRoot } from "../../util/paths.js";
|
|
10
|
+
|
|
11
|
+
/** Package root — correct both unbundled (src) and bundled (`dist/cli.js`). */
|
|
12
|
+
export const PACKAGE_ROOT = pkgRoot();
|
|
13
|
+
const HARNESS_DIR = join(PACKAGE_ROOT, "src", "parse", "harvest");
|
|
14
|
+
export const HARNESS_SRC = join(HARNESS_DIR, "harness.ts");
|
|
15
|
+
export const HARNESS_HTML = join(HARNESS_DIR, "harness.html");
|
|
16
|
+
export const BUNDLE_PATH = join(PACKAGE_ROOT, "dist", "harvest", "harness.js");
|
|
17
|
+
|
|
18
|
+
/** Bundle `harness.ts` to an IIFE string and write it to `dist/harvest/`. */
|
|
19
|
+
export async function buildHarnessBundle(): Promise<string> {
|
|
20
|
+
const esbuild = await import("esbuild");
|
|
21
|
+
const result = await esbuild.build({
|
|
22
|
+
entryPoints: [HARNESS_SRC],
|
|
23
|
+
bundle: true,
|
|
24
|
+
format: "iife",
|
|
25
|
+
platform: "browser",
|
|
26
|
+
target: "es2022",
|
|
27
|
+
write: false,
|
|
28
|
+
logLevel: "silent",
|
|
29
|
+
legalComments: "none",
|
|
30
|
+
});
|
|
31
|
+
const code = result.outputFiles[0].text;
|
|
32
|
+
mkdirSync(dirname(BUNDLE_PATH), { recursive: true });
|
|
33
|
+
writeFileSync(BUNDLE_PATH, code);
|
|
34
|
+
return code;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The cached bundle, rebuilt when missing or older than the harness source. */
|
|
38
|
+
export async function getHarnessBundle(): Promise<string> {
|
|
39
|
+
if (existsSync(BUNDLE_PATH) && statSync(BUNDLE_PATH).mtimeMs >= statSync(HARNESS_SRC).mtimeMs) {
|
|
40
|
+
return readFileSync(BUNDLE_PATH, "utf8");
|
|
41
|
+
}
|
|
42
|
+
return buildHarnessBundle();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Read the HTML shell with `__BUNDLE__`/`__FONT__`/`__STALL__` substituted. */
|
|
46
|
+
export function renderHarnessHtml(bundle: string, fontBase64: string, stall: boolean): string {
|
|
47
|
+
const template = readFileSync(HARNESS_HTML, "utf8");
|
|
48
|
+
const safeBundle = bundle.replace(/<\/script/gi, "<\\/script");
|
|
49
|
+
return template
|
|
50
|
+
.split('"__BUNDLE__"')
|
|
51
|
+
.join(safeBundle)
|
|
52
|
+
.split("__FONT__")
|
|
53
|
+
.join(fontBase64)
|
|
54
|
+
.split('"__STALL__"')
|
|
55
|
+
.join(stall ? "true" : "false");
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>deck3d mermaid harvest</title>
|
|
6
|
+
<style>
|
|
7
|
+
@font-face {
|
|
8
|
+
font-family: "Poppins";
|
|
9
|
+
font-weight: 700;
|
|
10
|
+
font-style: normal;
|
|
11
|
+
src: url(data:font/ttf;base64,__FONT__) format("truetype");
|
|
12
|
+
}
|
|
13
|
+
html, body { margin: 0; padding: 0; background: #ffffff; }
|
|
14
|
+
#mmhost { position: absolute; left: 0; top: 0; }
|
|
15
|
+
</style>
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<div id="mmhost"></div>
|
|
19
|
+
<script>window.__DECK3D_STALL = "__STALL__";</script>
|
|
20
|
+
<script>"__BUNDLE__"</script>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-side harvest harness. Bundled by esbuild into an IIFE and injected
|
|
3
|
+
* into a blank Playwright page. Semantics come from mermaid's diagram model
|
|
4
|
+
* (`db`); layout geometry comes from mermaid's own rendered SVG.
|
|
5
|
+
*
|
|
6
|
+
* This module never runs in Node — it is only ever bundled (see `bundle.ts`).
|
|
7
|
+
*/
|
|
8
|
+
import mermaid from "mermaid";
|
|
9
|
+
import { mapEdgeKind, mapMessageKind, mapNodeShape } from "./shapes.js";
|
|
10
|
+
|
|
11
|
+
/** Raw harvest payload returned to Node, before edge/message ids are assigned. */
|
|
12
|
+
export interface RawHarvest {
|
|
13
|
+
kind: "flowchart" | "sequence" | "none";
|
|
14
|
+
/** Set when `kind` is `none` because the diagram type is unsupported. */
|
|
15
|
+
unsupported?: string;
|
|
16
|
+
dir?: string;
|
|
17
|
+
nodes?: RawNode[];
|
|
18
|
+
edges?: RawEdge[];
|
|
19
|
+
groups?: Array<{ id: string; title: string; nodes: string[] }>;
|
|
20
|
+
actors?: Array<{ id: string; label: string }>;
|
|
21
|
+
messages?: Array<{ from: string; to: string; text: string; kind: "solid" | "dotted" }>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RawNode {
|
|
25
|
+
id: string;
|
|
26
|
+
label: string;
|
|
27
|
+
shape: string;
|
|
28
|
+
x: number;
|
|
29
|
+
y: number;
|
|
30
|
+
w: number;
|
|
31
|
+
h: number;
|
|
32
|
+
group?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface RawEdge {
|
|
36
|
+
from: string;
|
|
37
|
+
to: string;
|
|
38
|
+
kind: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
path: Array<[number, number]>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface RawGroup {
|
|
44
|
+
id: string;
|
|
45
|
+
title: string;
|
|
46
|
+
nodes: string[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare global {
|
|
50
|
+
interface Window {
|
|
51
|
+
__deck3dHarvest: (source: string, renderId: string) => Promise<RawHarvest>;
|
|
52
|
+
__DECK3D_STALL?: boolean;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type AnyRecord = Record<string, unknown>;
|
|
57
|
+
|
|
58
|
+
function mapVals(value: unknown): AnyRecord[] {
|
|
59
|
+
if (value instanceof Map) return [...(value as Map<unknown, AnyRecord>).values()];
|
|
60
|
+
if (value && typeof value === "object") return Object.values(value as Record<string, AnyRecord>);
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function call(db: AnyRecord, name: string): unknown {
|
|
65
|
+
const fn = db[name];
|
|
66
|
+
return typeof fn === "function" ? (fn as (...args: unknown[]) => unknown).call(db) : undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function round2(n: number): number {
|
|
70
|
+
return Math.round(n * 100) / 100;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readSequence(db: AnyRecord): RawHarvest {
|
|
74
|
+
const actors = mapVals(call(db, "getActors")).map((a) => ({
|
|
75
|
+
id: String(a.name ?? a.id ?? ""),
|
|
76
|
+
label: String(a.description ?? a.name ?? a.id ?? ""),
|
|
77
|
+
}));
|
|
78
|
+
const messages = mapVals(call(db, "getMessages"))
|
|
79
|
+
.map((m) => ({
|
|
80
|
+
from: String(m.from ?? ""),
|
|
81
|
+
to: String(m.to ?? ""),
|
|
82
|
+
text: String(m.message ?? ""),
|
|
83
|
+
kind: mapMessageKind(typeof m.type === "number" ? m.type : undefined),
|
|
84
|
+
}))
|
|
85
|
+
.filter((m): m is { from: string; to: string; text: string; kind: "solid" | "dotted" } =>
|
|
86
|
+
Boolean(m.from && m.to && m.kind),
|
|
87
|
+
);
|
|
88
|
+
return { kind: "sequence", actors, messages };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function readGroups(db: AnyRecord, groupByNode: Map<string, string>): RawGroup[] {
|
|
92
|
+
return mapVals(call(db, "getSubGraphs")).map((sg) => {
|
|
93
|
+
const nodes = Array.isArray(sg.nodes) ? (sg.nodes as unknown[]).map(String) : [];
|
|
94
|
+
const title = String(sg.title ?? sg.id ?? "");
|
|
95
|
+
for (const n of nodes) groupByNode.set(n, title);
|
|
96
|
+
return { id: String(sg.id ?? title), title, nodes };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function readNodes(db: AnyRecord, gnodes: Element[], groupByNode: Map<string, string>): RawNode[] {
|
|
101
|
+
const nodes: RawNode[] = [];
|
|
102
|
+
for (const v of mapVals(call(db, "getVertices"))) {
|
|
103
|
+
const id = String(v.id ?? "");
|
|
104
|
+
const el = gnodes.find((n) => n.id.includes(`flowchart-${id}-`));
|
|
105
|
+
if (!el) continue;
|
|
106
|
+
const m = /translate\(\s*([-\d.]+)[ ,]+([-\d.]+)/.exec(el.getAttribute("transform") ?? "");
|
|
107
|
+
const box = (el as SVGGraphicsElement).getBBox();
|
|
108
|
+
const node: RawNode = {
|
|
109
|
+
id,
|
|
110
|
+
label: String(v.text ?? id),
|
|
111
|
+
shape: mapNodeShape(typeof v.type === "string" ? v.type : undefined),
|
|
112
|
+
x: round2(m ? Number(m[1]) : 0),
|
|
113
|
+
y: round2(m ? Number(m[2]) : 0),
|
|
114
|
+
w: round2(box.width),
|
|
115
|
+
h: round2(box.height),
|
|
116
|
+
};
|
|
117
|
+
const group = groupByNode.get(id);
|
|
118
|
+
if (group) node.group = group;
|
|
119
|
+
nodes.push(node);
|
|
120
|
+
}
|
|
121
|
+
return nodes;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function samplePath(p: Element | undefined): Array<[number, number]> {
|
|
125
|
+
if (!p) return [];
|
|
126
|
+
const path = p as SVGPathElement;
|
|
127
|
+
const length = path.getTotalLength();
|
|
128
|
+
const points: Array<[number, number]> = [];
|
|
129
|
+
for (let s = 0; s <= 16; s++) {
|
|
130
|
+
const q = path.getPointAtLength((length * s) / 16);
|
|
131
|
+
points.push([round2(q.x), round2(q.y)]);
|
|
132
|
+
}
|
|
133
|
+
return points;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function readEdges(db: AnyRecord, paths: Element[]): RawEdge[] {
|
|
137
|
+
const rawEdges = mapVals(call(db, "getEdges"));
|
|
138
|
+
const seen: Record<string, number> = {};
|
|
139
|
+
return rawEdges.map((e, i) => {
|
|
140
|
+
const from = String(e.start ?? "");
|
|
141
|
+
const to = String(e.end ?? "");
|
|
142
|
+
const key = `L_${from}_${to}_`;
|
|
143
|
+
const k = (seen[key] = (seen[key] ?? -1) + 1);
|
|
144
|
+
const p = paths.find((x) => x.id.endsWith(key + k)) ?? paths[i];
|
|
145
|
+
const label = String(e.text ?? "").trim();
|
|
146
|
+
const edge: RawEdge = {
|
|
147
|
+
from,
|
|
148
|
+
to,
|
|
149
|
+
kind: mapEdgeKind(typeof e.stroke === "string" ? e.stroke : undefined),
|
|
150
|
+
path: samplePath(p),
|
|
151
|
+
};
|
|
152
|
+
if (label) edge.label = label;
|
|
153
|
+
return edge;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function harvestFlowchart(db: AnyRecord, source: string, renderId: string): Promise<RawHarvest> {
|
|
158
|
+
const { svg } = await mermaid.render(renderId, source);
|
|
159
|
+
const host = document.getElementById("mmhost") as HTMLElement;
|
|
160
|
+
host.innerHTML = svg;
|
|
161
|
+
const root = host.querySelector("svg") as SVGSVGElement;
|
|
162
|
+
const groupByNode = new Map<string, string>();
|
|
163
|
+
const groups = readGroups(db, groupByNode);
|
|
164
|
+
const nodes = readNodes(db, [...root.querySelectorAll("g.node")], groupByNode);
|
|
165
|
+
const edges = readEdges(db, [...root.querySelectorAll("path.flowchart-link")]);
|
|
166
|
+
const dir = String(call(db, "getDirection") ?? "TB");
|
|
167
|
+
return { kind: "flowchart", dir, nodes, edges, groups };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function harvest(source: string, renderId: string): Promise<RawHarvest> {
|
|
171
|
+
mermaid.initialize({
|
|
172
|
+
startOnLoad: false,
|
|
173
|
+
theme: "base",
|
|
174
|
+
securityLevel: "strict",
|
|
175
|
+
fontFamily: "Poppins, sans-serif",
|
|
176
|
+
flowchart: { htmlLabels: false, curve: "basis" },
|
|
177
|
+
});
|
|
178
|
+
const diagram = (await mermaid.mermaidAPI.getDiagramFromText(source)) as unknown as { type?: string; db: AnyRecord };
|
|
179
|
+
const db = diagram.db;
|
|
180
|
+
const type = String(diagram.type ?? "");
|
|
181
|
+
if (type === "sequence") return readSequence(db);
|
|
182
|
+
if (type !== "flowchart" && type !== "flowchart-v2" && type !== "graph") {
|
|
183
|
+
return { kind: "none", unsupported: type || "unknown" };
|
|
184
|
+
}
|
|
185
|
+
return harvestFlowchart(db, source, renderId);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
window.__deck3dHarvest = (source: string, renderId: string): Promise<RawHarvest> => {
|
|
189
|
+
if (window.__DECK3D_STALL) return new Promise<RawHarvest>(() => {});
|
|
190
|
+
return harvest(source, renderId);
|
|
191
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid harvest — parse-time only, headless chromium (design D2).
|
|
3
|
+
*
|
|
4
|
+
* Launches Playwright chromium, injects the bundled harness page, and converts
|
|
5
|
+
* a mermaid source block into the Deck IR `Diagram`. Never runs at view time.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { chromium } from "playwright";
|
|
10
|
+
import type { Diagram, DiagramEdge, DiagramMessage, EdgeKind, FlowchartDir, NodeShape } from "../../ir/types.js";
|
|
11
|
+
import { getHarnessBundle, PACKAGE_ROOT, renderHarnessHtml } from "./bundle.js";
|
|
12
|
+
import type { RawHarvest } from "./harness.js";
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_HARVEST_TIMEOUT_MS = 60_000;
|
|
15
|
+
|
|
16
|
+
/** Raised for every harvest failure; the message is the one-line CLI reason. */
|
|
17
|
+
export class HarvestError extends Error {
|
|
18
|
+
constructor(
|
|
19
|
+
message: string,
|
|
20
|
+
readonly slideId?: string,
|
|
21
|
+
) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "HarvestError";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface HarvestOptions {
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
/** Test hook: make the harness page never resolve. */
|
|
30
|
+
stall?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface HarvestOutcome {
|
|
34
|
+
diagram: Diagram;
|
|
35
|
+
warnings: string[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function envTimeout(name: string, fallback: number): number {
|
|
39
|
+
const raw = process.env[name];
|
|
40
|
+
const parsed = raw === undefined ? Number.NaN : Number(raw);
|
|
41
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function installHint(err: unknown): HarvestError {
|
|
45
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
46
|
+
return new HarvestError(
|
|
47
|
+
`chromium not available for mermaid harvest — install with: npx playwright install chromium (${message.split("\n")[0]})`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function withTimeout<T>(promise: Promise<T>, ms: number, onTimeout: () => Error): Promise<T> {
|
|
52
|
+
return new Promise<T>((resolve, reject) => {
|
|
53
|
+
const timer = setTimeout(() => reject(onTimeout()), ms);
|
|
54
|
+
promise.then(
|
|
55
|
+
(value) => {
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(value);
|
|
58
|
+
},
|
|
59
|
+
(err) => {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
reject(err);
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function fontBase64(): string {
|
|
68
|
+
return readFileSync(join(PACKAGE_ROOT, "assets", "Poppins-Bold.ttf")).toString("base64");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Convert the raw harness payload to the IR `Diagram`, assigning stable ids. */
|
|
72
|
+
export function toDiagram(raw: RawHarvest, slideId: string): HarvestOutcome {
|
|
73
|
+
if (raw.kind === "none") {
|
|
74
|
+
if (raw.unsupported) {
|
|
75
|
+
return { diagram: { kind: "none" }, warnings: [`warn unsupported diagram ${raw.unsupported} slide ${slideId}`] };
|
|
76
|
+
}
|
|
77
|
+
return { diagram: { kind: "none" }, warnings: [] };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (raw.kind === "sequence") {
|
|
81
|
+
const messages: DiagramMessage[] = (raw.messages ?? []).map((m, i) => ({
|
|
82
|
+
id: `m${i}`,
|
|
83
|
+
from: m.from,
|
|
84
|
+
to: m.to,
|
|
85
|
+
text: m.text,
|
|
86
|
+
kind: m.kind,
|
|
87
|
+
}));
|
|
88
|
+
return {
|
|
89
|
+
diagram: { kind: "sequence", actors: raw.actors ?? [], messages },
|
|
90
|
+
warnings: [],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const nodes = (raw.nodes ?? []).map((n) => ({
|
|
95
|
+
id: n.id,
|
|
96
|
+
label: n.label,
|
|
97
|
+
shape: n.shape as NodeShape,
|
|
98
|
+
x: n.x,
|
|
99
|
+
y: n.y,
|
|
100
|
+
w: n.w,
|
|
101
|
+
h: n.h,
|
|
102
|
+
...(n.group ? { group: n.group } : {}),
|
|
103
|
+
}));
|
|
104
|
+
const seen: Record<string, number> = {};
|
|
105
|
+
const edges: DiagramEdge[] = (raw.edges ?? []).map((e) => {
|
|
106
|
+
const key = `${e.from}->${e.to}`;
|
|
107
|
+
const k = (seen[key] = (seen[key] ?? -1) + 1);
|
|
108
|
+
return {
|
|
109
|
+
id: `${key}#${k}`,
|
|
110
|
+
from: e.from,
|
|
111
|
+
to: e.to,
|
|
112
|
+
kind: e.kind as EdgeKind,
|
|
113
|
+
...(e.label ? { label: e.label } : {}),
|
|
114
|
+
path: e.path,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
diagram: {
|
|
119
|
+
kind: "flowchart",
|
|
120
|
+
dir: (raw.dir as FlowchartDir) ?? "TB",
|
|
121
|
+
nodes,
|
|
122
|
+
edges,
|
|
123
|
+
groups: raw.groups ?? [],
|
|
124
|
+
},
|
|
125
|
+
warnings: [],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Harvest one mermaid block. `slideId` names the slide in error/warning lines
|
|
131
|
+
* and seeds the mermaid render id (so layout ids are stable per slide).
|
|
132
|
+
*/
|
|
133
|
+
export async function harvestDiagram(source: string, slideId: string, opts: HarvestOptions = {}): Promise<HarvestOutcome> {
|
|
134
|
+
const timeoutMs = opts.timeoutMs ?? envTimeout("DECK3D_HARVEST_TIMEOUT_MS", DEFAULT_HARVEST_TIMEOUT_MS);
|
|
135
|
+
const stall = opts.stall ?? process.env.DECK3D_HARVEST_STALL === "1";
|
|
136
|
+
const bundle = await getHarnessBundle();
|
|
137
|
+
const html = renderHarnessHtml(bundle, fontBase64(), stall);
|
|
138
|
+
|
|
139
|
+
let browser: Awaited<ReturnType<typeof chromium.launch>>;
|
|
140
|
+
try {
|
|
141
|
+
browser = await chromium.launch({ channel: "chromium" });
|
|
142
|
+
} catch (err) {
|
|
143
|
+
throw installHint(err);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const page = await browser.newPage();
|
|
148
|
+
await page.setContent(html);
|
|
149
|
+
const pending = page.evaluate(
|
|
150
|
+
({ src, id }) => window.__deck3dHarvest(src, id),
|
|
151
|
+
{ src: source, id: `mm-${slideId}` },
|
|
152
|
+
);
|
|
153
|
+
// Prevent an unhandled rejection if the timeout wins the race.
|
|
154
|
+
pending.catch(() => {});
|
|
155
|
+
let raw: RawHarvest;
|
|
156
|
+
try {
|
|
157
|
+
raw = await withTimeout(
|
|
158
|
+
pending as Promise<RawHarvest>,
|
|
159
|
+
timeoutMs,
|
|
160
|
+
() => new HarvestError(`slide "${slideId}": mermaid harvest timeout after ${timeoutMs} ms`, slideId),
|
|
161
|
+
);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
throw err instanceof HarvestError ? err : new HarvestError(`slide "${slideId}": mermaid harvest failed — ${(err as Error).message}`, slideId);
|
|
164
|
+
}
|
|
165
|
+
return toDiagram(raw, slideId);
|
|
166
|
+
} finally {
|
|
167
|
+
await browser.close();
|
|
168
|
+
}
|
|
169
|
+
}
|