@pfdsl/preview-engine 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 takasek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @pfdsl/preview-engine
2
+
3
+ Renders [PFDSL](https://github.com/takasek/pfdsl) diagrams to SVG for preview and export.
4
+
5
+ ## Requirements
6
+
7
+ Node.js ≥ 18 (ESM only).
8
+
9
+ ## API
10
+
11
+ ```ts
12
+ import { renderGraph, renderDiff, renderDotToSvg } from "@pfdsl/preview-engine";
13
+
14
+ // Render a graph to SVG
15
+ const svg = await renderGraph(graph, frontmatter, options);
16
+
17
+ // Render a diff to SVG
18
+ const svg = await renderDiff(graph, frontmatter, options);
19
+
20
+ // Render a raw DOT string to SVG
21
+ const svg = await renderDotToSvg(dot);
22
+ ```
23
+
24
+ See [`RenderOptions`](src/index.ts) for available options (extends `ExportOptions` from `@pfdsl/graphviz-exporter`).
@@ -0,0 +1,13 @@
1
+ import { Graph, Frontmatter } from '@pfdsl/core';
2
+ import { ExportOptions } from '@pfdsl/graphviz-exporter';
3
+ export { ExportOptions, exportDiffDot } from '@pfdsl/graphviz-exporter';
4
+
5
+ type RenderFormat = "svg" | "dot";
6
+ interface RenderOptions extends ExportOptions {
7
+ format?: RenderFormat;
8
+ }
9
+ declare function renderDotToSvg(dot: string): Promise<string>;
10
+ declare function renderGraph(graph: Graph, frontmatter?: Frontmatter | null, options?: RenderOptions): Promise<string>;
11
+ declare function renderDiff(a: Graph, fmA: Frontmatter | null, b: Graph, fmB: Frontmatter | null, options?: RenderOptions): Promise<string>;
12
+
13
+ export { type RenderFormat, type RenderOptions, renderDiff, renderDotToSvg, renderGraph };
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ // src/index.ts
2
+ import { Graphviz } from "@hpcc-js/wasm";
3
+ import {
4
+ exportDiffDot,
5
+ exportDot
6
+ } from "@pfdsl/graphviz-exporter";
7
+ import { exportDiffDot as exportDiffDot2 } from "@pfdsl/graphviz-exporter";
8
+ var graphvizInstance = null;
9
+ function getGraphviz() {
10
+ if (!graphvizInstance) {
11
+ graphvizInstance = Graphviz.load();
12
+ }
13
+ return graphvizInstance;
14
+ }
15
+ async function renderDotToSvg(dot) {
16
+ const gv = await getGraphviz();
17
+ return gv.dot(dot, "svg");
18
+ }
19
+ async function renderGraph(graph, frontmatter = null, options = {}) {
20
+ const dot = exportDot(graph, frontmatter, options);
21
+ if (options.format === "dot") return dot;
22
+ return renderDotToSvg(dot);
23
+ }
24
+ async function renderDiff(a, fmA, b, fmB, options = {}) {
25
+ const dot = exportDiffDot(a, fmA, b, fmB, options);
26
+ if (options.format === "dot") return dot;
27
+ return renderDotToSvg(dot);
28
+ }
29
+ export {
30
+ exportDiffDot2 as exportDiffDot,
31
+ renderDiff,
32
+ renderDotToSvg,
33
+ renderGraph
34
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@pfdsl/preview-engine",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/index.js",
10
+ "types": "./dist/index.d.ts"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@hpcc-js/wasm": "^2.18.0",
15
+ "@pfdsl/core": "0.0.1",
16
+ "@pfdsl/graphviz-exporter": "0.0.1"
17
+ },
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^20.0.0",
29
+ "tsup": "^8.0.0",
30
+ "vitest": "^1.6.0"
31
+ },
32
+ "scripts": {
33
+ "build": "tsup src/index.ts --format esm --dts",
34
+ "test": "vitest run",
35
+ "typecheck": "tsc --noEmit"
36
+ }
37
+ }