@diagrampilot/render-svg 0.1.5
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 +21 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DiagramPilot contributors
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DiagramSpec, type SvgArtifactProvenance } from "@diagrampilot/core";
|
|
2
|
+
export declare const RENDER_SVG_PACKAGE_NAME = "@diagrampilot/render-svg";
|
|
3
|
+
export declare const SVG_RENDERER_NAME = "@terrastruct/d2";
|
|
4
|
+
export declare const SVG_RENDERER_VERSION = "0.1.33";
|
|
5
|
+
export type SvgRendererProvenance = SvgArtifactProvenance;
|
|
6
|
+
export interface CreateSvgRendererProvenanceOptions {
|
|
7
|
+
sourcePath: string;
|
|
8
|
+
sourceContent: string | Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
export interface RenderDiagramSpecToSvgOptions {
|
|
11
|
+
provenance?: SvgRendererProvenance;
|
|
12
|
+
}
|
|
13
|
+
export declare function createSvgRendererProvenance(options: CreateSvgRendererProvenanceOptions): SvgRendererProvenance;
|
|
14
|
+
export declare function addSvgProvenanceMetadata(svg: string, provenance: SvgRendererProvenance): string;
|
|
15
|
+
export declare function renderDiagramSpecToSvg(spec: DiagramSpec, options?: RenderDiagramSpecToSvgOptions): Promise<string>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,qBAAqB,EAC3B,MAAM,oBAAoB,CAAC;AAI5B,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAClE,eAAO,MAAM,iBAAiB,oBAAoB,CAAC;AACnD,eAAO,MAAM,oBAAoB,WAAW,CAAC;AAE7C,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE1D,MAAM,WAAW,kCAAkC;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,GAAG,UAAU,CAAC;CACpC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACpC;AAkBD,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kCAAkC,GAC1C,qBAAqB,CASvB;AAED,wBAAgB,wBAAwB,CACtC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,qBAAqB,GAChC,MAAM,CAeR;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,6BAAkC,GAC1C,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createSvgArtifactProvenance, } from "@diagrampilot/core";
|
|
2
|
+
import { exportDiagramSpecToD2 } from "@diagrampilot/export-d2";
|
|
3
|
+
import { D2 } from "@terrastruct/d2";
|
|
4
|
+
export const RENDER_SVG_PACKAGE_NAME = "@diagrampilot/render-svg";
|
|
5
|
+
export const SVG_RENDERER_NAME = "@terrastruct/d2";
|
|
6
|
+
export const SVG_RENDERER_VERSION = "0.1.33";
|
|
7
|
+
async function terminateD2Worker(d2) {
|
|
8
|
+
const worker = d2.worker;
|
|
9
|
+
if (worker === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
await worker.terminate();
|
|
13
|
+
}
|
|
14
|
+
export function createSvgRendererProvenance(options) {
|
|
15
|
+
return createSvgArtifactProvenance({
|
|
16
|
+
sourcePath: options.sourcePath,
|
|
17
|
+
sourceContent: options.sourceContent,
|
|
18
|
+
renderer: {
|
|
19
|
+
name: SVG_RENDERER_NAME,
|
|
20
|
+
version: SVG_RENDERER_VERSION,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function addSvgProvenanceMetadata(svg, provenance) {
|
|
25
|
+
const openingSvgTag = /<svg\b[^>]*>/i.exec(svg);
|
|
26
|
+
if (openingSvgTag === null) {
|
|
27
|
+
return svg;
|
|
28
|
+
}
|
|
29
|
+
const insertionIndex = openingSvgTag.index + openingSvgTag[0].length;
|
|
30
|
+
const metadata = `<metadata id="diagrampilot-provenance">${JSON.stringify(provenance)}</metadata>`;
|
|
31
|
+
return `${svg.slice(0, insertionIndex)}${metadata}${svg.slice(insertionIndex)}`;
|
|
32
|
+
}
|
|
33
|
+
export async function renderDiagramSpecToSvg(spec, options = {}) {
|
|
34
|
+
const d2 = new D2();
|
|
35
|
+
try {
|
|
36
|
+
const d2Text = exportDiagramSpecToD2(spec);
|
|
37
|
+
const result = await d2.compile(d2Text);
|
|
38
|
+
const renderedSvg = await d2.render(result.diagram, result.renderOptions);
|
|
39
|
+
if (options.provenance === undefined) {
|
|
40
|
+
return renderedSvg;
|
|
41
|
+
}
|
|
42
|
+
return addSvgProvenanceMetadata(renderedSvg, options.provenance);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
await terminateD2Worker(d2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,GAG5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAErC,MAAM,CAAC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC;AAClE,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAmB7C,KAAK,UAAU,iBAAiB,CAAC,EAAM;IACrC,MAAM,MAAM,GAAI,EAAoB,CAAC,MAAM,CAAC;IAE5C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,OAA2C;IAE3C,OAAO,2BAA2B,CAAC;QACjC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;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AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diagrampilot/render-svg",
|
|
3
|
+
"version": "0.1.5",
|
|
4
|
+
"description": "SVG rendering adapter for DiagramPilot.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/StiensWout/DiagramPilot.git",
|
|
10
|
+
"directory": "packages/render-svg"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://diagrampilot.com",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/StiensWout/DiagramPilot/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"diagrampilot",
|
|
18
|
+
"diagramspec",
|
|
19
|
+
"diagram",
|
|
20
|
+
"architecture",
|
|
21
|
+
"svg"
|
|
22
|
+
],
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist/**/*.d.ts",
|
|
33
|
+
"dist/**/*.d.ts.map",
|
|
34
|
+
"dist/**/*.js",
|
|
35
|
+
"dist/**/*.js.map",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -b"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@diagrampilot/core": "0.1.5",
|
|
46
|
+
"@diagrampilot/export-d2": "0.1.5",
|
|
47
|
+
"@terrastruct/d2": "0.1.33"
|
|
48
|
+
}
|
|
49
|
+
}
|