@shumoku/renderer 0.2.16 → 0.2.17
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/cli.d.ts +1 -1
- package/dist/cli.js +27 -6
- package/dist/cli.js.map +1 -1
- package/package.json +2 -1
- package/src/cli.ts +27 -7
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Shumoku CLI - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
3
|
+
* Shumoku CLI - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
4
4
|
*/
|
|
5
5
|
// Import @shumoku/icons to auto-register vendor icons
|
|
6
6
|
import '@shumoku/icons';
|
|
7
7
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
8
8
|
import { dirname, extname, resolve } from 'node:path';
|
|
9
9
|
import { parseArgs } from 'node:util';
|
|
10
|
+
import { Resvg } from '@resvg/resvg-js';
|
|
10
11
|
import { buildHierarchicalSheets, HierarchicalLayout } from '@shumoku/core';
|
|
11
12
|
import { parser } from '@shumoku/parser-yaml';
|
|
12
13
|
import pkg from '../package.json' with { type: 'json' };
|
|
@@ -15,7 +16,7 @@ import { INTERACTIVE_IIFE } from './iife-string.js';
|
|
|
15
16
|
import * as svg from './svg.js';
|
|
16
17
|
const VERSION = pkg.version;
|
|
17
18
|
const HELP = `
|
|
18
|
-
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
19
|
+
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
19
20
|
|
|
20
21
|
Usage: shumoku render [options] <input>
|
|
21
22
|
|
|
@@ -24,9 +25,10 @@ Input:
|
|
|
24
25
|
Format auto-detected from extension (.yaml, .yml, .json)
|
|
25
26
|
|
|
26
27
|
Output:
|
|
27
|
-
-f, --format <type> Output format: svg|html (default: auto from extension)
|
|
28
|
+
-f, --format <type> Output format: svg|html|png (default: auto from extension)
|
|
28
29
|
-o, --output <file> Output file (default: output.svg)
|
|
29
30
|
--theme <theme> Theme: light|dark (default: light)
|
|
31
|
+
--scale <number> PNG scale factor (default: 2)
|
|
30
32
|
|
|
31
33
|
Other:
|
|
32
34
|
-h, --help Show help
|
|
@@ -35,6 +37,7 @@ Other:
|
|
|
35
37
|
Examples:
|
|
36
38
|
shumoku render network.yaml -o diagram.svg
|
|
37
39
|
shumoku render network.yaml -f html -o diagram.html
|
|
40
|
+
shumoku render network.yaml -f png -o diagram.png
|
|
38
41
|
shumoku render topology.json -o diagram.svg
|
|
39
42
|
cat network.yaml | shumoku render - -o diagram.svg
|
|
40
43
|
`;
|
|
@@ -50,6 +53,7 @@ function cli() {
|
|
|
50
53
|
format: { type: 'string', short: 'f' },
|
|
51
54
|
output: { type: 'string', short: 'o', default: 'output' },
|
|
52
55
|
theme: { type: 'string' },
|
|
56
|
+
scale: { type: 'string', default: '2' },
|
|
53
57
|
help: { type: 'boolean', short: 'h', default: false },
|
|
54
58
|
version: { type: 'boolean', short: 'v', default: false },
|
|
55
59
|
},
|
|
@@ -118,11 +122,15 @@ async function main() {
|
|
|
118
122
|
}
|
|
119
123
|
// Determine format
|
|
120
124
|
const outputBase = values.output;
|
|
121
|
-
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm)$/);
|
|
125
|
+
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm|png)$/);
|
|
122
126
|
const format = values.format ??
|
|
123
|
-
(extMatch
|
|
127
|
+
(extMatch
|
|
128
|
+
? extMatch[1] === 'htm'
|
|
129
|
+
? 'html'
|
|
130
|
+
: extMatch[1]
|
|
131
|
+
: 'svg');
|
|
124
132
|
// Build output path
|
|
125
|
-
const hasExt = /\.(svg|html|htm)$/i.test(outputBase);
|
|
133
|
+
const hasExt = /\.(svg|html|htm|png)$/i.test(outputBase);
|
|
126
134
|
const outputPath = resolve(process.cwd(), hasExt ? outputBase : `${outputBase}.${format}`);
|
|
127
135
|
// Ensure output directory exists
|
|
128
136
|
mkdirSync(dirname(outputPath), { recursive: true });
|
|
@@ -142,6 +150,19 @@ async function main() {
|
|
|
142
150
|
writeFileSync(outputPath, html.render(graph, layoutResult), 'utf-8');
|
|
143
151
|
}
|
|
144
152
|
}
|
|
153
|
+
else if (format === 'png') {
|
|
154
|
+
console.log('Rendering PNG...');
|
|
155
|
+
const svgString = svg.render(graph, layoutResult);
|
|
156
|
+
const scale = Number.parseFloat(values.scale) || 2;
|
|
157
|
+
const resvg = new Resvg(svgString, {
|
|
158
|
+
fitTo: { mode: 'zoom', value: scale },
|
|
159
|
+
font: {
|
|
160
|
+
loadSystemFonts: true,
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
const pngData = resvg.render();
|
|
164
|
+
writeFileSync(outputPath, pngData.asPng());
|
|
165
|
+
}
|
|
145
166
|
else {
|
|
146
167
|
console.log('Rendering SVG...');
|
|
147
168
|
writeFileSync(outputPath, svg.render(graph, layoutResult), 'utf-8');
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,sDAAsD;AACtD,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,sDAAsD;AACtD,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAChE,OAAO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M,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,sBAAsB,UAAU,EAAE,CAAC,CAAA;QAC/C,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACtB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAC3C,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shumoku/renderer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"description": "SVG and HTML renderers for Shumoku network diagrams",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "konoe-akitoshi",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"test": "vitest run --passWithNoTests"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
59
60
|
"@shumoku/core": "^0.2.4",
|
|
60
61
|
"@shumoku/icons": "^0.2.4",
|
|
61
62
|
"@shumoku/parser-yaml": "^0.2.15"
|
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* Shumoku CLI - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
3
|
+
* Shumoku CLI - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// Import @shumoku/icons to auto-register vendor icons
|
|
@@ -9,6 +9,7 @@ import '@shumoku/icons'
|
|
|
9
9
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
10
10
|
import { dirname, extname, resolve } from 'node:path'
|
|
11
11
|
import { parseArgs } from 'node:util'
|
|
12
|
+
import { Resvg } from '@resvg/resvg-js'
|
|
12
13
|
import type { NetworkGraph } from '@shumoku/core'
|
|
13
14
|
import { buildHierarchicalSheets, HierarchicalLayout } from '@shumoku/core'
|
|
14
15
|
import { parser } from '@shumoku/parser-yaml'
|
|
@@ -20,7 +21,7 @@ import * as svg from './svg.js'
|
|
|
20
21
|
const VERSION = pkg.version
|
|
21
22
|
|
|
22
23
|
const HELP = `
|
|
23
|
-
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
24
|
+
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
24
25
|
|
|
25
26
|
Usage: shumoku render [options] <input>
|
|
26
27
|
|
|
@@ -29,9 +30,10 @@ Input:
|
|
|
29
30
|
Format auto-detected from extension (.yaml, .yml, .json)
|
|
30
31
|
|
|
31
32
|
Output:
|
|
32
|
-
-f, --format <type> Output format: svg|html (default: auto from extension)
|
|
33
|
+
-f, --format <type> Output format: svg|html|png (default: auto from extension)
|
|
33
34
|
-o, --output <file> Output file (default: output.svg)
|
|
34
35
|
--theme <theme> Theme: light|dark (default: light)
|
|
36
|
+
--scale <number> PNG scale factor (default: 2)
|
|
35
37
|
|
|
36
38
|
Other:
|
|
37
39
|
-h, --help Show help
|
|
@@ -40,11 +42,12 @@ Other:
|
|
|
40
42
|
Examples:
|
|
41
43
|
shumoku render network.yaml -o diagram.svg
|
|
42
44
|
shumoku render network.yaml -f html -o diagram.html
|
|
45
|
+
shumoku render network.yaml -f png -o diagram.png
|
|
43
46
|
shumoku render topology.json -o diagram.svg
|
|
44
47
|
cat network.yaml | shumoku render - -o diagram.svg
|
|
45
48
|
`
|
|
46
49
|
|
|
47
|
-
type OutputFormat = 'svg' | 'html'
|
|
50
|
+
type OutputFormat = 'svg' | 'html' | 'png'
|
|
48
51
|
|
|
49
52
|
function cli() {
|
|
50
53
|
const args = process.argv.slice(2)
|
|
@@ -60,6 +63,7 @@ function cli() {
|
|
|
60
63
|
format: { type: 'string', short: 'f' },
|
|
61
64
|
output: { type: 'string', short: 'o', default: 'output' },
|
|
62
65
|
theme: { type: 'string' },
|
|
66
|
+
scale: { type: 'string', default: '2' },
|
|
63
67
|
help: { type: 'boolean', short: 'h', default: false },
|
|
64
68
|
version: { type: 'boolean', short: 'v', default: false },
|
|
65
69
|
},
|
|
@@ -138,13 +142,17 @@ async function main(): Promise<void> {
|
|
|
138
142
|
|
|
139
143
|
// Determine format
|
|
140
144
|
const outputBase = values.output!
|
|
141
|
-
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm)$/)
|
|
145
|
+
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm|png)$/)
|
|
142
146
|
const format: OutputFormat =
|
|
143
147
|
(values.format as OutputFormat) ??
|
|
144
|
-
(extMatch
|
|
148
|
+
(extMatch
|
|
149
|
+
? extMatch[1] === 'htm'
|
|
150
|
+
? 'html'
|
|
151
|
+
: (extMatch[1] as OutputFormat)
|
|
152
|
+
: 'svg')
|
|
145
153
|
|
|
146
154
|
// Build output path
|
|
147
|
-
const hasExt = /\.(svg|html|htm)$/i.test(outputBase)
|
|
155
|
+
const hasExt = /\.(svg|html|htm|png)$/i.test(outputBase)
|
|
148
156
|
const outputPath = resolve(process.cwd(), hasExt ? outputBase : `${outputBase}.${format}`)
|
|
149
157
|
|
|
150
158
|
// Ensure output directory exists
|
|
@@ -167,6 +175,18 @@ async function main(): Promise<void> {
|
|
|
167
175
|
} else {
|
|
168
176
|
writeFileSync(outputPath, html.render(graph, layoutResult), 'utf-8')
|
|
169
177
|
}
|
|
178
|
+
} else if (format === 'png') {
|
|
179
|
+
console.log('Rendering PNG...')
|
|
180
|
+
const svgString = svg.render(graph, layoutResult)
|
|
181
|
+
const scale = Number.parseFloat(values.scale!) || 2
|
|
182
|
+
const resvg = new Resvg(svgString, {
|
|
183
|
+
fitTo: { mode: 'zoom', value: scale },
|
|
184
|
+
font: {
|
|
185
|
+
loadSystemFonts: true,
|
|
186
|
+
},
|
|
187
|
+
})
|
|
188
|
+
const pngData = resvg.render()
|
|
189
|
+
writeFileSync(outputPath, pngData.asPng())
|
|
170
190
|
} else {
|
|
171
191
|
console.log('Rendering SVG...')
|
|
172
192
|
writeFileSync(outputPath, svg.render(graph, layoutResult), 'utf-8')
|