@hattoriai/poney-render 0.2.0 → 0.3.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/dist/index.d.ts +1 -1
- package/dist/index.js +7 -33
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PoneyDocument } from '@hattoriai/poney-core';
|
|
2
|
-
import { Mode, ThemeName } from '@hattoriai/poney-
|
|
2
|
+
import { Mode, ThemeName } from '@hattoriai/poney-diagrams';
|
|
3
3
|
|
|
4
4
|
/** Measures text with the real font files. Call before laying out in Node. */
|
|
5
5
|
declare function useNodeTextMeasurer(): void;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
3
|
import * as fontkit from 'fontkit';
|
|
5
4
|
import { indexOf, marksOf, plainText, parseRef } from '@hattoriai/poney-core';
|
|
6
5
|
import { setTextMeasurer, layoutView, wrap } from '@hattoriai/poney-layout';
|
|
7
|
-
import {
|
|
8
|
-
import { jsx } from '
|
|
6
|
+
import { findTarget, STORY_TYPES, diagramFor, sceneLayoutOptions, sceneFrame, fit, storyState, toMarkup, resolve, RenderProvider, StoryProvider, SceneStory, THEMES, stepLetter, FONTS } from '@hattoriai/poney-diagrams';
|
|
7
|
+
import { jsx } from '@hattoriai/poney-diagrams/jsx-runtime';
|
|
9
8
|
|
|
10
9
|
// src/index.tsx
|
|
11
|
-
var STORY_TYPES = ["map", "sequence", "state"];
|
|
12
10
|
var require2 = createRequire(import.meta.url);
|
|
13
11
|
var SANS_FILES = {
|
|
14
12
|
400: "@fontsource/hanken-grotesk/files/hanken-grotesk-latin-400-normal.woff2",
|
|
@@ -47,33 +45,7 @@ function describeRef(idx, key) {
|
|
|
47
45
|
async function renderScene(doc, options = {}) {
|
|
48
46
|
useNodeTextMeasurer();
|
|
49
47
|
const idx = indexOf(doc);
|
|
50
|
-
|
|
51
|
-
let focus = [];
|
|
52
|
-
let callouts = [];
|
|
53
|
-
let notes = [];
|
|
54
|
-
let title = "";
|
|
55
|
-
let sceneData;
|
|
56
|
-
let walkthrough = options.walkthrough ? doc.walkthroughs.find((w) => w.id === options.walkthrough) : doc.walkthroughs[0];
|
|
57
|
-
if (options.view) {
|
|
58
|
-
view = idx.views.get(options.view);
|
|
59
|
-
if (!view) throw new Error(`No view "${options.view}". Views: ${doc.views.map((v) => v.id).join(", ")}`);
|
|
60
|
-
title = view.title;
|
|
61
|
-
walkthrough = options.walkthrough ? walkthrough : void 0;
|
|
62
|
-
} else {
|
|
63
|
-
const found = findScene(doc, options.walkthrough, options.scene);
|
|
64
|
-
if (!found) {
|
|
65
|
-
const w = walkthrough;
|
|
66
|
-
const ids = w ? ["overview", ...w.scenes.filter((s) => s.view).map((s) => s.id)].join(", ") : "none";
|
|
67
|
-
throw new Error(`No scene "${options.scene ?? "(default)"}" with a view. Scenes: ${ids}`);
|
|
68
|
-
}
|
|
69
|
-
walkthrough = found.walkthrough;
|
|
70
|
-
view = idx.views.get(found.viewId);
|
|
71
|
-
focus = found.focus;
|
|
72
|
-
callouts = found.callouts;
|
|
73
|
-
notes = found.notes;
|
|
74
|
-
title = found.title;
|
|
75
|
-
sceneData = found.scene;
|
|
76
|
-
}
|
|
48
|
+
const { view, walkthrough, focus, callouts, notes, title, scene: sceneData } = findTarget(doc, options);
|
|
77
49
|
const story = STORY_TYPES.includes(view.type);
|
|
78
50
|
const module = story ? void 0 : diagramFor(view);
|
|
79
51
|
if (!story && !module) throw new Error(`No renderer for "${view.id}", a ${view.type === "extension" ? view.extension : view.type} view. Register one with registerDiagram.`);
|
|
@@ -98,8 +70,10 @@ async function renderScene(doc, options = {}) {
|
|
|
98
70
|
animate: false,
|
|
99
71
|
numberSteps: true
|
|
100
72
|
});
|
|
101
|
-
const body =
|
|
102
|
-
|
|
73
|
+
const body = toMarkup(
|
|
74
|
+
resolve(
|
|
75
|
+
/* @__PURE__ */ jsx(RenderProvider, { value: { idx, still: true }, children: module ? /* @__PURE__ */ jsx(module.Renderer, { scene, view }) : /* @__PURE__ */ jsx(StoryProvider, { value: storyValue, children: /* @__PURE__ */ jsx(SceneStory, { view, scene, extra: walkthrough?.removed.entities }) }) })
|
|
76
|
+
)
|
|
103
77
|
);
|
|
104
78
|
const colors = THEMES[theme];
|
|
105
79
|
const steps = (sceneData?.trace ?? []).map((t, i) => t.caption ? plainText(t.caption) : describeRef(idx, t.ref) ?? `Step ${i + 1}`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"names":["require"],"mappings":";;;;;;;;;;AAkCA,IAAM,WAAA,GAAwB,CAAC,KAAA,EAAO,UAAA,EAAY,OAAO,CAAA;AAEzD,IAAMA,QAAAA,GAAU,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AAI7C,IAAM,UAAA,GAAqC;AAAA,EACzC,GAAA,EAAK,wEAAA;AAAA,EACL,GAAA,EAAK,wEAAA;AAAA,EACL,GAAA,EAAK,wEAAA;AAAA,EACL,GAAA,EAAK;AACP,CAAA;AACA,IAAM,SAAA,GAAY,wEAAA;AAGlB,IAAI,KAAA;AAEJ,SAAS,SAAA,GAAY;AACnB,EAAA,IAAI,OAAO,OAAO,KAAA;AAClB,EAAA,MAAM,QAAgC,EAAC;AACvC,EAAA,MAAM,OAA6B,EAAC;AACpC,EAAA,KAAA,MAAW,CAAC,CAAA,EAAG,CAAC,KAAK,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,EAAG;AAC/C,IAAA,KAAA,CAAM,CAAA,KAAA,EAAQ,CAAC,CAAA,CAAE,CAAA,GAAI,aAAaA,QAAAA,CAAQ,OAAA,CAAQ,CAAC,CAAC,CAAA;AACpD,IAAA,IAAA,CAAK,MA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C5C;AAEA,IAAM,YAAY,CAAC,CAAA,KAAc,EAAE,OAAA,CAAQ,SAAA,EAAW,CAAC,CAAA,KAAA,CAAO,EAAE,KAAK,MAAA,EAAQ,GAAA,EAAK,QAAQ,GAAA,EAAK,OAAA,EAAS,KAAK,QAAA,EAAS,EAAG,CAAC,CAAE,CAAA","file":"index.js","sourcesContent":["/** @jsxRuntime automatic @jsxImportSource react */\n/// <reference path=\"./shims.d.ts\" />\n/**\n * @hattoriai/poney-render — any view or walkthrough scene of a Poney\n * document to SVG or PNG, in Node, drawn by @hattoriai/poney-react.\n *\n * Text is measured with the same font files the PNG is drawn with, so labels\n * fit their boxes. The SVG is self-contained: colours are resolved (no CSS\n * variables), opacity is inlined, and fonts are embedded on request.\n */\nimport { readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport { renderToStaticMarkup } from 'react-dom/server'\nimport * as fontkit from 'fontkit'\nimport { indexOf, marksOf, parseRef, plainText, type PoneyDocument, type Scene, type View } from '@hattoriai/poney-core'\nimport { layoutView, setTextMeasurer, wrap, type FontFamily } from '@hattoriai/poney-layout'\nimport {\n diagramFor,\n findScene,\n fit,\n FONTS,\n RenderProvider,\n SceneStory,\n sceneFrame,\n sceneLayoutOptions,\n stepLetter,\n StoryProvider,\n storyState,\n THEMES,\n type Mode,\n type ThemeName,\n} from '@hattoriai/poney-react'\n\n/** View types drawn as walkthrough stories; the others draw with their diagram renderer. */\nconst STORY_TYPES: string[] = ['map', 'sequence', 'state']\n\nconst require = createRequire(import.meta.url)\n\n/* ─── Fonts ───────────────────────────────────────────────────────────────── */\n\nconst SANS_FILES: Record<number, string> = {\n 400: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-400-normal.woff2',\n 500: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-500-normal.woff2',\n 600: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-600-normal.woff2',\n 700: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-700-normal.woff2',\n}\nconst MONO_FILE = '@fontsource/jetbrains-mono/files/jetbrains-mono-latin-400-normal.woff2'\n\ntype Font = { layout(text: string): { advanceWidth: number }; unitsPerEm: number }\nlet fonts: { sans: Record<number, Font>; mono: Font; files: Record<string, Buffer> } | undefined\n\nfunction loadFonts() {\n if (fonts) return fonts\n const files: Record<string, Buffer> = {}\n const sans: Record<number, Font> = {}\n for (const [w, f] of Object.entries(SANS_FILES)) {\n files[`sans-${w}`] = readFileSync(require.resolve(f))\n sans[Number(w)] = fontkit.create(files[`sans-${w}`]) as unknown as Font\n }\n files.mono = readFileSync(require.resolve(MONO_FILE))\n fonts = { sans, mono: fontkit.create(files.mono) as unknown as Font, files }\n return fonts\n}\n\nconst nearest = (weight: number) => [400, 500, 600, 700].reduce((a, b) => (Math.abs(b - weight) < Math.abs(a - weight) ? b : a))\n\n/** Measures text with the real font files. Call before laying out in Node. */\nexport function useNodeTextMeasurer() {\n const f = loadFonts()\n setTextMeasurer((text: string, size: number, weight: number, family: FontFamily) => {\n const font = family === 'mono' ? f.mono : f.sans[nearest(weight)]\n return (font.layout(text).advanceWidth / font.unitsPerEm) * size\n })\n}\n\n/* ─── Rendering ───────────────────────────────────────────────────────────── */\n\nexport interface RenderSceneOptions {\n /** Walkthrough id. Default: the first. */\n walkthrough?: string\n /** Scene id, or \"overview\". Default: the overview, else the first scene with a view. */\n scene?: string\n /** Render a view directly, outside any walkthrough. */\n view?: string\n mode?: Mode\n theme?: ThemeName\n /** Width of the output in pixels. Height follows the scene. */\n width?: number\n /** Embed the fonts in the SVG, so it looks the same everywhere. */\n embedFonts?: boolean\n /** Write the numbered callout notes under the picture. Default: true. */\n legend?: boolean\n}\n\nexport interface RenderedScene {\n svg: string\n width: number\n height: number\n title: string\n}\n\nconst PAD = 40\n\n/** A plain name for a ref, for a step without a caption. */\nfunction describeRef(idx: ReturnType<typeof indexOf>, key: string): string | undefined {\n const r = parseRef(key)\n if (!r || !idx.exists(r)) return undefined\n return idx.describe(r).title\n}\n\nexport async function renderScene(doc: PoneyDocument, options: RenderSceneOptions = {}): Promise<RenderedScene> {\n useNodeTextMeasurer()\n const idx = indexOf(doc)\n let view: View | undefined\n let focus: string[] = []\n let callouts: string[] = []\n let notes: string[] = []\n let title = ''\n let sceneData: Scene | undefined\n let walkthrough = options.walkthrough ? doc.walkthroughs.find((w) => w.id === options.walkthrough) : doc.walkthroughs[0]\n if (options.view) {\n view = idx.views.get(options.view)\n if (!view) throw new Error(`No view \"${options.view}\". Views: ${doc.views.map((v) => v.id).join(', ')}`)\n title = view.title\n walkthrough = options.walkthrough ? walkthrough : undefined\n } else {\n const found = findScene(doc, options.walkthrough, options.scene)\n if (!found) {\n const w = walkthrough\n const ids = w ? ['overview', ...w.scenes.filter((s) => s.view).map((s) => s.id)].join(', ') : 'none'\n throw new Error(`No scene \"${options.scene ?? '(default)'}\" with a view. Scenes: ${ids}`)\n }\n walkthrough = found.walkthrough\n view = idx.views.get(found.viewId)!\n focus = found.focus\n callouts = found.callouts\n notes = found.notes\n title = found.title\n sceneData = found.scene\n }\n // Map, sequence and state views draw as stories (marks, focus, callouts); every other view type draws with its diagram renderer, still.\n const story = STORY_TYPES.includes(view.type)\n const module = story ? undefined : diagramFor(view)\n if (!story && !module) throw new Error(`No renderer for \"${view.id}\", a ${view.type === 'extension' ? view.extension : view.type} view. Register one with registerDiagram.`)\n const scene = await layoutView(doc, view, story ? sceneLayoutOptions(view, walkthrough, focus) : {})\n const frame = story ? sceneFrame(scene, view, focus, idx, walkthrough) : { x: 0, y: 0, w: scene.width, h: scene.height }\n const natural = { w: frame.w + PAD * 2, h: frame.h + PAD * 2 }\n const width = Math.round(options.width ?? Math.min(1600, Math.max(720, natural.w)))\n const height = Math.round((width * natural.h) / natural.w)\n const vb = fit(frame, width, height, PAD, 10)\n const theme = options.theme ?? 'light'\n const storyValue = storyState({\n marks: walkthrough ? marksOf(walkthrough) : new Map(),\n mode: options.mode ?? 'change',\n view,\n focus,\n callouts,\n idx,\n walkthrough,\n effects: sceneData?.effects,\n badges: sceneData?.badges,\n trace: sceneData?.trace,\n animate: false,\n numberSteps: true,\n })\n\n const body = renderToStaticMarkup(\n <RenderProvider value={{ idx, still: true }}>\n {module ? (\n <module.Renderer scene={scene} view={view} />\n ) : (\n <StoryProvider value={storyValue}>\n <SceneStory view={view} scene={scene} extra={walkthrough?.removed.entities} />\n </StoryProvider>\n )}\n </RenderProvider>,\n )\n\n const colors = THEMES[theme]\n // The key: each callout's number and note, under the picture.\n // The key under the picture: numbered notes (round marks), then the steps of the path (square marks).\n const steps = (sceneData?.trace ?? []).map((t, i) => (t.caption ? plainText(t.caption) : (describeRef(idx, t.ref) ?? `Step ${i + 1}`)))\n // A picture draws plain text: inline Markdown in the notes shows without its markers.\n const entries = [...notes.map((text, i) => ({ text: plainText(text), n: i + 1, step: false })), ...steps.map((text, i) => ({ text, n: i + 1, step: true }))]\n const showLegend = options.legend !== false && entries.length > 0\n const scale = vb.w / width\n const textW = width - 2 * 40 - 34\n const legendLines = showLegend ? entries.map((e) => wrap(e.text, textW, 14, 400, 4)) : []\n const legendH = showLegend ? (legendLines.reduce((s, l) => s + l.length, 0) * 20 + entries.length * 8 + 40) * scale : 0\n let ly = vb.y + vb.h + 16 * scale\n const legend = legendLines\n .map((lines, i) => {\n const y = ly\n ly += (lines.length * 20 + 8) * scale\n const x = vb.x + 40 * scale\n const e = entries[i]\n const mark = e.step ? `<rect x=\"1\" y=\"1\" width=\"20\" height=\"20\" rx=\"6\" fill=\"${colors.accent}\"/>` : `<circle cx=\"11\" cy=\"11\" r=\"11\" fill=\"${colors.ink}\"/>`\n return (\n `<g transform=\"translate(${x} ${y}) scale(${scale})\">${mark}` +\n `<text x=\"11\" y=\"15\" text-anchor=\"middle\" font-size=\"12\" font-weight=\"700\" fill=\"${colors['paper-raised']}\">${e.step ? stepLetter(e.n - 1) : e.n}</text>` +\n lines.map((l, k) => `<text x=\"34\" y=\"${15 + k * 20}\" font-size=\"14\" fill=\"${colors.ink}\">${escapeXml(l)}</text>`).join('') +\n `</g>`\n )\n })\n .join('')\n const fontFace = options.embedFonts\n ? `<style>${[400, 500, 600, 700]\n .map((w) => `@font-face{font-family:\"Hanken Grotesk\";font-weight:${w};src:url(data:font/woff2;base64,${loadFonts().files[`sans-${w}`].toString('base64')}) format(\"woff2\")}`)\n .join('')}</style>`\n : ''\n const svg =\n `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${width}\" height=\"${Math.round(height + legendH / scale)}\" viewBox=\"${vb.x} ${vb.y} ${vb.w} ${vb.h + legendH}\" font-family=\"Hanken Grotesk, Helvetica, Arial, sans-serif\" role=\"img\">` +\n `<title>${escapeXml(title)}</title>${fontFace}` +\n `<rect x=\"${vb.x}\" y=\"${vb.y}\" width=\"${vb.w}\" height=\"${vb.h + legendH}\" fill=\"${colors['paper-raised']}\"/>` +\n flatten(body, colors) +\n (showLegend ? `<line x1=\"${vb.x + 40 * scale}\" x2=\"${vb.x + vb.w - 40 * scale}\" y1=\"${vb.y + vb.h}\" y2=\"${vb.y + vb.h}\" stroke=\"${colors['story-rule']}\" stroke-width=\"${scale}\"/>` + legend : '') +\n `</svg>`\n return { svg, width, height: Math.round(height + legendH / scale), title }\n}\n\n/** Renders a scene to PNG at twice its size, with the bundled fonts. */\nexport async function renderScenePng(doc: PoneyDocument, options: RenderSceneOptions = {}): Promise<{ png: Buffer; width: number; height: number; title: string }> {\n const { svg, width, height, title } = await renderScene(doc, { ...options, embedFonts: false })\n const { Resvg } = await import('@resvg/resvg-js')\n const wawoff2 = (await import('wawoff2')).default\n const f = loadFonts()\n const buffers = await Promise.all([400, 500, 600, 700].map(async (w) => Buffer.from(await wawoff2.decompress(f.files[`sans-${w}`]))))\n const png = new Resvg(svg, {\n fitTo: { mode: 'width', value: width * 2 },\n // fontBuffers is supported at run time; the published types predate it.\n font: { fontBuffers: buffers, loadSystemFonts: false, defaultFontFamily: 'Hanken Grotesk' } as Record<string, unknown>,\n })\n .render()\n .asPng()\n return { png: Buffer.from(png), width: width * 2, height: height * 2, title }\n}\n\n/**\n * Makes the markup self-contained: CSS variables become colours, opacity\n * classes become attributes, and elements that only show on keyboard focus\n * are dropped.\n */\nfunction flatten(markup: string, colors: Record<string, string>): string {\n return markup\n .replace(/<rect[^>]*class=\"poney-focus\"[^>]*?(?:\\/>|><\\/rect>)/g, '')\n .replace(/var\\(--poney-font-(sans|mono)\\)/g, (_, f: 'sans' | 'mono') => FONTS[f].replace(/'/g, ''))\n .replace(/var\\(--poney-([a-z0-9-]+)\\)/g, (_, name: string) => colors[name] ?? '#888888')\n // Tints are CSS color-mix(); a picture gets the mixed color itself.\n .replace(/color-mix\\(in srgb,\\s*(#[0-9a-fA-F]{6})\\s+([\\d.]+)%,\\s*(#[0-9a-fA-F]{6}|transparent)\\s*\\)/g, (_, a: string, pct: string, b: string) => mix(a, Number(pct) / 100, b))\n .replace(/<(\\w+)([^>]*?) class=\"([^\"]*)\"/g, (all, tag: string, attrs: string, cls: string) => {\n const opacity = cls.includes('poney-story-hidden') ? '0' : cls.includes('poney-story-dim') ? '0.16' : cls.includes('poney-dim') ? '0.3' : undefined\n // A line that carries data flows in the Studio; a still picture draws it dashed.\n const dashed = cls.includes('poney-flowing') ? ' stroke-dasharray=\"6 4\"' : ''\n return opacity || dashed ? `<${tag}${attrs}${opacity ? ` opacity=\"${opacity}\"` : ''}${dashed}` : all\n })\n}\n\n/** `a` at `share` over `b` (or, over transparent, `a` with that alpha). */\nfunction mix(a: string, share: number, b: string): string {\n const rgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16))\n const [r, g, bl] = rgb(a)\n if (b === 'transparent') return `rgba(${r},${g},${bl},${share})`\n const [r2, g2, b2] = rgb(b)\n const c = (x: number, y: number) => Math.round(x * share + y * (1 - share)).toString(16).padStart(2, '0')\n return `#${c(r, r2)}${c(g, g2)}${c(bl, b2)}`\n}\n\nconst escapeXml = (s: string) => s.replace(/[<>&\"]/g, (c) => ({ '<': '<', '>': '>', '&': '&', '\"': '"' })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A,EAAI,EAAE,CAAA,GAAI,IAAI,CAAC,CAAA;AAC1B,EAAA,MAAM,IAAI,CAAC,CAAA,EAAW,CAAA,KAAc,IAAA,CAAK,MAAM,CAAA,GAAI,KAAA,GAAQ,CAAA,IAAK,CAAA,GAAI,MAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,GAAG,GAAG,CAAA;AACxG,EAAA,OAAO,CAAA,CAAA,EAAI,CAAA,CAAE,CAAA,EAAG,EAAE,CAAC,CAAA,EAAG,CAAA,CAAE,CAAA,EAAG,EAAE,CAAC,CAAA,EAAG,CAAA,CAAE,EAAA,EAAI,EAAE,CAAC,CAAA,CAAA;AAC5C;AAEA,IAAM,YAAY,CAAC,CAAA,KAAc,EAAE,OAAA,CAAQ,SAAA,EAAW,CAAC,CAAA,KAAA,CAAO,EAAE,KAAK,MAAA,EAAQ,GAAA,EAAK,QAAQ,GAAA,EAAK,OAAA,EAAS,KAAK,QAAA,EAAS,EAAG,CAAC,CAAE,CAAA","file":"index.js","sourcesContent":["/** @jsxRuntime automatic */\n/** @jsxImportSource @hattoriai/poney-diagrams */\n/// <reference path=\"./shims.d.ts\" />\n/**\n * @hattoriai/poney-render — any view or walkthrough scene of a Poney\n * document to SVG or PNG, in Node, drawn by @hattoriai/poney-diagrams.\n *\n * Text is measured with the same font files the PNG is drawn with, so labels\n * fit their boxes. The SVG is self-contained: colours are resolved (no CSS\n * variables), opacity is inlined, and fonts are embedded on request.\n */\nimport { readFileSync } from 'node:fs'\nimport { createRequire } from 'node:module'\nimport * as fontkit from 'fontkit'\nimport { indexOf, marksOf, parseRef, plainText, type PoneyDocument } from '@hattoriai/poney-core'\nimport { layoutView, setTextMeasurer, wrap, type FontFamily } from '@hattoriai/poney-layout'\nimport {\n diagramFor,\n findTarget,\n fit,\n FONTS,\n RenderProvider,\n resolve,\n SceneStory,\n sceneFrame,\n sceneLayoutOptions,\n stepLetter,\n StoryProvider,\n storyState,\n STORY_TYPES,\n THEMES,\n toMarkup,\n type Mode,\n type ThemeName,\n} from '@hattoriai/poney-diagrams'\n\nconst require = createRequire(import.meta.url)\n\n/* ─── Fonts ───────────────────────────────────────────────────────────────── */\n\nconst SANS_FILES: Record<number, string> = {\n 400: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-400-normal.woff2',\n 500: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-500-normal.woff2',\n 600: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-600-normal.woff2',\n 700: '@fontsource/hanken-grotesk/files/hanken-grotesk-latin-700-normal.woff2',\n}\nconst MONO_FILE = '@fontsource/jetbrains-mono/files/jetbrains-mono-latin-400-normal.woff2'\n\ntype Font = { layout(text: string): { advanceWidth: number }; unitsPerEm: number }\nlet fonts: { sans: Record<number, Font>; mono: Font; files: Record<string, Buffer> } | undefined\n\nfunction loadFonts() {\n if (fonts) return fonts\n const files: Record<string, Buffer> = {}\n const sans: Record<number, Font> = {}\n for (const [w, f] of Object.entries(SANS_FILES)) {\n files[`sans-${w}`] = readFileSync(require.resolve(f))\n sans[Number(w)] = fontkit.create(files[`sans-${w}`]) as unknown as Font\n }\n files.mono = readFileSync(require.resolve(MONO_FILE))\n fonts = { sans, mono: fontkit.create(files.mono) as unknown as Font, files }\n return fonts\n}\n\nconst nearest = (weight: number) => [400, 500, 600, 700].reduce((a, b) => (Math.abs(b - weight) < Math.abs(a - weight) ? b : a))\n\n/** Measures text with the real font files. Call before laying out in Node. */\nexport function useNodeTextMeasurer() {\n const f = loadFonts()\n setTextMeasurer((text: string, size: number, weight: number, family: FontFamily) => {\n const font = family === 'mono' ? f.mono : f.sans[nearest(weight)]\n return (font.layout(text).advanceWidth / font.unitsPerEm) * size\n })\n}\n\n/* ─── Rendering ───────────────────────────────────────────────────────────── */\n\nexport interface RenderSceneOptions {\n /** Walkthrough id. Default: the first. */\n walkthrough?: string\n /** Scene id, or \"overview\". Default: the overview, else the first scene with a view. */\n scene?: string\n /** Render a view directly, outside any walkthrough. */\n view?: string\n mode?: Mode\n theme?: ThemeName\n /** Width of the output in pixels. Height follows the scene. */\n width?: number\n /** Embed the fonts in the SVG, so it looks the same everywhere. */\n embedFonts?: boolean\n /** Write the numbered callout notes under the picture. Default: true. */\n legend?: boolean\n}\n\nexport interface RenderedScene {\n svg: string\n width: number\n height: number\n title: string\n}\n\nconst PAD = 40\n\n/** A plain name for a ref, for a step without a caption. */\nfunction describeRef(idx: ReturnType<typeof indexOf>, key: string): string | undefined {\n const r = parseRef(key)\n if (!r || !idx.exists(r)) return undefined\n return idx.describe(r).title\n}\n\nexport async function renderScene(doc: PoneyDocument, options: RenderSceneOptions = {}): Promise<RenderedScene> {\n useNodeTextMeasurer()\n const idx = indexOf(doc)\n const { view, walkthrough, focus, callouts, notes, title, scene: sceneData } = findTarget(doc, options)\n // Map, sequence and state views draw as stories (marks, focus, callouts); every other view type draws with its diagram renderer, still.\n const story = STORY_TYPES.includes(view.type)\n const module = story ? undefined : diagramFor(view)\n if (!story && !module) throw new Error(`No renderer for \"${view.id}\", a ${view.type === 'extension' ? view.extension : view.type} view. Register one with registerDiagram.`)\n const scene = await layoutView(doc, view, story ? sceneLayoutOptions(view, walkthrough, focus) : {})\n const frame = story ? sceneFrame(scene, view, focus, idx, walkthrough) : { x: 0, y: 0, w: scene.width, h: scene.height }\n const natural = { w: frame.w + PAD * 2, h: frame.h + PAD * 2 }\n const width = Math.round(options.width ?? Math.min(1600, Math.max(720, natural.w)))\n const height = Math.round((width * natural.h) / natural.w)\n const vb = fit(frame, width, height, PAD, 10)\n const theme = options.theme ?? 'light'\n const storyValue = storyState({\n marks: walkthrough ? marksOf(walkthrough) : new Map(),\n mode: options.mode ?? 'change',\n view,\n focus,\n callouts,\n idx,\n walkthrough,\n effects: sceneData?.effects,\n badges: sceneData?.badges,\n trace: sceneData?.trace,\n animate: false,\n numberSteps: true,\n })\n\n const body = toMarkup(\n resolve(\n <RenderProvider value={{ idx, still: true }}>\n {module ? (\n <module.Renderer scene={scene} view={view} />\n ) : (\n <StoryProvider value={storyValue}>\n <SceneStory view={view} scene={scene} extra={walkthrough?.removed.entities} />\n </StoryProvider>\n )}\n </RenderProvider>,\n ),\n )\n\n const colors = THEMES[theme]\n // The key: each callout's number and note, under the picture.\n // The key under the picture: numbered notes (round marks), then the steps of the path (square marks).\n const steps = (sceneData?.trace ?? []).map((t, i) => (t.caption ? plainText(t.caption) : (describeRef(idx, t.ref) ?? `Step ${i + 1}`)))\n // A picture draws plain text: inline Markdown in the notes shows without its markers.\n const entries = [...notes.map((text, i) => ({ text: plainText(text), n: i + 1, step: false })), ...steps.map((text, i) => ({ text, n: i + 1, step: true }))]\n const showLegend = options.legend !== false && entries.length > 0\n const scale = vb.w / width\n const textW = width - 2 * 40 - 34\n const legendLines = showLegend ? entries.map((e) => wrap(e.text, textW, 14, 400, 4)) : []\n const legendH = showLegend ? (legendLines.reduce((s, l) => s + l.length, 0) * 20 + entries.length * 8 + 40) * scale : 0\n let ly = vb.y + vb.h + 16 * scale\n const legend = legendLines\n .map((lines, i) => {\n const y = ly\n ly += (lines.length * 20 + 8) * scale\n const x = vb.x + 40 * scale\n const e = entries[i]\n const mark = e.step ? `<rect x=\"1\" y=\"1\" width=\"20\" height=\"20\" rx=\"6\" fill=\"${colors.accent}\"/>` : `<circle cx=\"11\" cy=\"11\" r=\"11\" fill=\"${colors.ink}\"/>`\n return (\n `<g transform=\"translate(${x} ${y}) scale(${scale})\">${mark}` +\n `<text x=\"11\" y=\"15\" text-anchor=\"middle\" font-size=\"12\" font-weight=\"700\" fill=\"${colors['paper-raised']}\">${e.step ? stepLetter(e.n - 1) : e.n}</text>` +\n lines.map((l, k) => `<text x=\"34\" y=\"${15 + k * 20}\" font-size=\"14\" fill=\"${colors.ink}\">${escapeXml(l)}</text>`).join('') +\n `</g>`\n )\n })\n .join('')\n const fontFace = options.embedFonts\n ? `<style>${[400, 500, 600, 700]\n .map((w) => `@font-face{font-family:\"Hanken Grotesk\";font-weight:${w};src:url(data:font/woff2;base64,${loadFonts().files[`sans-${w}`].toString('base64')}) format(\"woff2\")}`)\n .join('')}</style>`\n : ''\n const svg =\n `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${width}\" height=\"${Math.round(height + legendH / scale)}\" viewBox=\"${vb.x} ${vb.y} ${vb.w} ${vb.h + legendH}\" font-family=\"Hanken Grotesk, Helvetica, Arial, sans-serif\" role=\"img\">` +\n `<title>${escapeXml(title)}</title>${fontFace}` +\n `<rect x=\"${vb.x}\" y=\"${vb.y}\" width=\"${vb.w}\" height=\"${vb.h + legendH}\" fill=\"${colors['paper-raised']}\"/>` +\n flatten(body, colors) +\n (showLegend ? `<line x1=\"${vb.x + 40 * scale}\" x2=\"${vb.x + vb.w - 40 * scale}\" y1=\"${vb.y + vb.h}\" y2=\"${vb.y + vb.h}\" stroke=\"${colors['story-rule']}\" stroke-width=\"${scale}\"/>` + legend : '') +\n `</svg>`\n return { svg, width, height: Math.round(height + legendH / scale), title }\n}\n\n/** Renders a scene to PNG at twice its size, with the bundled fonts. */\nexport async function renderScenePng(doc: PoneyDocument, options: RenderSceneOptions = {}): Promise<{ png: Buffer; width: number; height: number; title: string }> {\n const { svg, width, height, title } = await renderScene(doc, { ...options, embedFonts: false })\n const { Resvg } = await import('@resvg/resvg-js')\n const wawoff2 = (await import('wawoff2')).default\n const f = loadFonts()\n const buffers = await Promise.all([400, 500, 600, 700].map(async (w) => Buffer.from(await wawoff2.decompress(f.files[`sans-${w}`]))))\n const png = new Resvg(svg, {\n fitTo: { mode: 'width', value: width * 2 },\n // fontBuffers is supported at run time; the published types predate it.\n font: { fontBuffers: buffers, loadSystemFonts: false, defaultFontFamily: 'Hanken Grotesk' } as Record<string, unknown>,\n })\n .render()\n .asPng()\n return { png: Buffer.from(png), width: width * 2, height: height * 2, title }\n}\n\n/**\n * Makes the markup self-contained: CSS variables become colours, opacity\n * classes become attributes, and elements that only show on keyboard focus\n * are dropped.\n */\nfunction flatten(markup: string, colors: Record<string, string>): string {\n return markup\n .replace(/<rect[^>]*class=\"poney-focus\"[^>]*?(?:\\/>|><\\/rect>)/g, '')\n .replace(/var\\(--poney-font-(sans|mono)\\)/g, (_, f: 'sans' | 'mono') => FONTS[f].replace(/'/g, ''))\n .replace(/var\\(--poney-([a-z0-9-]+)\\)/g, (_, name: string) => colors[name] ?? '#888888')\n // Tints are CSS color-mix(); a picture gets the mixed color itself.\n .replace(/color-mix\\(in srgb,\\s*(#[0-9a-fA-F]{6})\\s+([\\d.]+)%,\\s*(#[0-9a-fA-F]{6}|transparent)\\s*\\)/g, (_, a: string, pct: string, b: string) => mix(a, Number(pct) / 100, b))\n .replace(/<(\\w+)([^>]*?) class=\"([^\"]*)\"/g, (all, tag: string, attrs: string, cls: string) => {\n const opacity = cls.includes('poney-story-hidden') ? '0' : cls.includes('poney-story-dim') ? '0.16' : cls.includes('poney-dim') ? '0.3' : undefined\n // A line that carries data flows in the Studio; a still picture draws it dashed.\n const dashed = cls.includes('poney-flowing') ? ' stroke-dasharray=\"6 4\"' : ''\n return opacity || dashed ? `<${tag}${attrs}${opacity ? ` opacity=\"${opacity}\"` : ''}${dashed}` : all\n })\n}\n\n/** `a` at `share` over `b` (or, over transparent, `a` with that alpha). */\nfunction mix(a: string, share: number, b: string): string {\n const rgb = (h: string) => [1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16))\n const [r, g, bl] = rgb(a)\n if (b === 'transparent') return `rgba(${r},${g},${bl},${share})`\n const [r2, g2, b2] = rgb(b)\n const c = (x: number, y: number) => Math.round(x * share + y * (1 - share)).toString(16).padStart(2, '0')\n return `#${c(r, r2)}${c(g, g2)}${c(bl, b2)}`\n}\n\nconst escapeXml = (s: string) => s.replace(/[<>&\"]/g, (c) => ({ '<': '<', '>': '>', '&': '&', '\"': '"' })[c]!)\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hattoriai/poney-render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Poney documents to SVG and PNG in Node: any view or walkthrough scene, with the real fonts.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@fontsource/hanken-grotesk": "^5.3.0",
|
|
36
36
|
"@fontsource/jetbrains-mono": "^5.3.0",
|
|
37
|
-
"@hattoriai/poney-core": "0.
|
|
38
|
-
"@hattoriai/poney-
|
|
39
|
-
"@hattoriai/poney-
|
|
37
|
+
"@hattoriai/poney-core": "0.3.0",
|
|
38
|
+
"@hattoriai/poney-diagrams": "0.3.0",
|
|
39
|
+
"@hattoriai/poney-layout": "0.3.0",
|
|
40
40
|
"@resvg/resvg-js": "^2.6.2",
|
|
41
41
|
"fontkit": "^2.0.4",
|
|
42
42
|
"wawoff2": "^2.0.1"
|
|
@@ -46,8 +46,6 @@
|
|
|
46
46
|
"react-dom": "^18.3.1 || ^19.0.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"react": "^18.3.1",
|
|
50
|
-
"react-dom": "^18.3.1",
|
|
51
49
|
"tsup": "8.5.1"
|
|
52
50
|
}
|
|
53
51
|
}
|