@shumoku/renderer 0.2.15 → 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 +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +29 -6
- package/dist/cli.js.map +1 -1
- package/package.json +3 -1
- package/src/cli.ts +30 -7
package/dist/cli.d.ts
CHANGED
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG"}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA;;GAEG;AAGH,OAAO,gBAAgB,CAAA"}
|
package/dist/cli.js
CHANGED
|
@@ -1,10 +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
|
+
// Import @shumoku/icons to auto-register vendor icons
|
|
6
|
+
import '@shumoku/icons';
|
|
5
7
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
8
|
import { dirname, extname, resolve } from 'node:path';
|
|
7
9
|
import { parseArgs } from 'node:util';
|
|
10
|
+
import { Resvg } from '@resvg/resvg-js';
|
|
8
11
|
import { buildHierarchicalSheets, HierarchicalLayout } from '@shumoku/core';
|
|
9
12
|
import { parser } from '@shumoku/parser-yaml';
|
|
10
13
|
import pkg from '../package.json' with { type: 'json' };
|
|
@@ -13,7 +16,7 @@ import { INTERACTIVE_IIFE } from './iife-string.js';
|
|
|
13
16
|
import * as svg from './svg.js';
|
|
14
17
|
const VERSION = pkg.version;
|
|
15
18
|
const HELP = `
|
|
16
|
-
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
19
|
+
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
17
20
|
|
|
18
21
|
Usage: shumoku render [options] <input>
|
|
19
22
|
|
|
@@ -22,9 +25,10 @@ Input:
|
|
|
22
25
|
Format auto-detected from extension (.yaml, .yml, .json)
|
|
23
26
|
|
|
24
27
|
Output:
|
|
25
|
-
-f, --format <type> Output format: svg|html (default: auto from extension)
|
|
28
|
+
-f, --format <type> Output format: svg|html|png (default: auto from extension)
|
|
26
29
|
-o, --output <file> Output file (default: output.svg)
|
|
27
30
|
--theme <theme> Theme: light|dark (default: light)
|
|
31
|
+
--scale <number> PNG scale factor (default: 2)
|
|
28
32
|
|
|
29
33
|
Other:
|
|
30
34
|
-h, --help Show help
|
|
@@ -33,6 +37,7 @@ Other:
|
|
|
33
37
|
Examples:
|
|
34
38
|
shumoku render network.yaml -o diagram.svg
|
|
35
39
|
shumoku render network.yaml -f html -o diagram.html
|
|
40
|
+
shumoku render network.yaml -f png -o diagram.png
|
|
36
41
|
shumoku render topology.json -o diagram.svg
|
|
37
42
|
cat network.yaml | shumoku render - -o diagram.svg
|
|
38
43
|
`;
|
|
@@ -48,6 +53,7 @@ function cli() {
|
|
|
48
53
|
format: { type: 'string', short: 'f' },
|
|
49
54
|
output: { type: 'string', short: 'o', default: 'output' },
|
|
50
55
|
theme: { type: 'string' },
|
|
56
|
+
scale: { type: 'string', default: '2' },
|
|
51
57
|
help: { type: 'boolean', short: 'h', default: false },
|
|
52
58
|
version: { type: 'boolean', short: 'v', default: false },
|
|
53
59
|
},
|
|
@@ -116,11 +122,15 @@ async function main() {
|
|
|
116
122
|
}
|
|
117
123
|
// Determine format
|
|
118
124
|
const outputBase = values.output;
|
|
119
|
-
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm)$/);
|
|
125
|
+
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm|png)$/);
|
|
120
126
|
const format = values.format ??
|
|
121
|
-
(extMatch
|
|
127
|
+
(extMatch
|
|
128
|
+
? extMatch[1] === 'htm'
|
|
129
|
+
? 'html'
|
|
130
|
+
: extMatch[1]
|
|
131
|
+
: 'svg');
|
|
122
132
|
// Build output path
|
|
123
|
-
const hasExt = /\.(svg|html|htm)$/i.test(outputBase);
|
|
133
|
+
const hasExt = /\.(svg|html|htm|png)$/i.test(outputBase);
|
|
124
134
|
const outputPath = resolve(process.cwd(), hasExt ? outputBase : `${outputBase}.${format}`);
|
|
125
135
|
// Ensure output directory exists
|
|
126
136
|
mkdirSync(dirname(outputPath), { recursive: true });
|
|
@@ -140,6 +150,19 @@ async function main() {
|
|
|
140
150
|
writeFileSync(outputPath, html.render(graph, layoutResult), 'utf-8');
|
|
141
151
|
}
|
|
142
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
|
+
}
|
|
143
166
|
else {
|
|
144
167
|
console.log('Rendering SVG...');
|
|
145
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,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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AM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,CAAA;YAC9B,aAAa,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;YAC/B,aAAa,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,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,7 +56,9 @@
|
|
|
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",
|
|
61
|
+
"@shumoku/icons": "^0.2.4",
|
|
60
62
|
"@shumoku/parser-yaml": "^0.2.15"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
package/src/cli.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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
|
+
// Import @shumoku/icons to auto-register vendor icons
|
|
7
|
+
import '@shumoku/icons'
|
|
8
|
+
|
|
6
9
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
7
10
|
import { dirname, extname, resolve } from 'node:path'
|
|
8
11
|
import { parseArgs } from 'node:util'
|
|
12
|
+
import { Resvg } from '@resvg/resvg-js'
|
|
9
13
|
import type { NetworkGraph } from '@shumoku/core'
|
|
10
14
|
import { buildHierarchicalSheets, HierarchicalLayout } from '@shumoku/core'
|
|
11
15
|
import { parser } from '@shumoku/parser-yaml'
|
|
@@ -17,7 +21,7 @@ import * as svg from './svg.js'
|
|
|
17
21
|
const VERSION = pkg.version
|
|
18
22
|
|
|
19
23
|
const HELP = `
|
|
20
|
-
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML
|
|
24
|
+
shumoku v${VERSION} - Render NetworkGraph YAML/JSON to SVG/HTML/PNG
|
|
21
25
|
|
|
22
26
|
Usage: shumoku render [options] <input>
|
|
23
27
|
|
|
@@ -26,9 +30,10 @@ Input:
|
|
|
26
30
|
Format auto-detected from extension (.yaml, .yml, .json)
|
|
27
31
|
|
|
28
32
|
Output:
|
|
29
|
-
-f, --format <type> Output format: svg|html (default: auto from extension)
|
|
33
|
+
-f, --format <type> Output format: svg|html|png (default: auto from extension)
|
|
30
34
|
-o, --output <file> Output file (default: output.svg)
|
|
31
35
|
--theme <theme> Theme: light|dark (default: light)
|
|
36
|
+
--scale <number> PNG scale factor (default: 2)
|
|
32
37
|
|
|
33
38
|
Other:
|
|
34
39
|
-h, --help Show help
|
|
@@ -37,11 +42,12 @@ Other:
|
|
|
37
42
|
Examples:
|
|
38
43
|
shumoku render network.yaml -o diagram.svg
|
|
39
44
|
shumoku render network.yaml -f html -o diagram.html
|
|
45
|
+
shumoku render network.yaml -f png -o diagram.png
|
|
40
46
|
shumoku render topology.json -o diagram.svg
|
|
41
47
|
cat network.yaml | shumoku render - -o diagram.svg
|
|
42
48
|
`
|
|
43
49
|
|
|
44
|
-
type OutputFormat = 'svg' | 'html'
|
|
50
|
+
type OutputFormat = 'svg' | 'html' | 'png'
|
|
45
51
|
|
|
46
52
|
function cli() {
|
|
47
53
|
const args = process.argv.slice(2)
|
|
@@ -57,6 +63,7 @@ function cli() {
|
|
|
57
63
|
format: { type: 'string', short: 'f' },
|
|
58
64
|
output: { type: 'string', short: 'o', default: 'output' },
|
|
59
65
|
theme: { type: 'string' },
|
|
66
|
+
scale: { type: 'string', default: '2' },
|
|
60
67
|
help: { type: 'boolean', short: 'h', default: false },
|
|
61
68
|
version: { type: 'boolean', short: 'v', default: false },
|
|
62
69
|
},
|
|
@@ -135,13 +142,17 @@ async function main(): Promise<void> {
|
|
|
135
142
|
|
|
136
143
|
// Determine format
|
|
137
144
|
const outputBase = values.output!
|
|
138
|
-
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm)$/)
|
|
145
|
+
const extMatch = outputBase.toLowerCase().match(/\.(svg|html|htm|png)$/)
|
|
139
146
|
const format: OutputFormat =
|
|
140
147
|
(values.format as OutputFormat) ??
|
|
141
|
-
(extMatch
|
|
148
|
+
(extMatch
|
|
149
|
+
? extMatch[1] === 'htm'
|
|
150
|
+
? 'html'
|
|
151
|
+
: (extMatch[1] as OutputFormat)
|
|
152
|
+
: 'svg')
|
|
142
153
|
|
|
143
154
|
// Build output path
|
|
144
|
-
const hasExt = /\.(svg|html|htm)$/i.test(outputBase)
|
|
155
|
+
const hasExt = /\.(svg|html|htm|png)$/i.test(outputBase)
|
|
145
156
|
const outputPath = resolve(process.cwd(), hasExt ? outputBase : `${outputBase}.${format}`)
|
|
146
157
|
|
|
147
158
|
// Ensure output directory exists
|
|
@@ -164,6 +175,18 @@ async function main(): Promise<void> {
|
|
|
164
175
|
} else {
|
|
165
176
|
writeFileSync(outputPath, html.render(graph, layoutResult), 'utf-8')
|
|
166
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())
|
|
167
190
|
} else {
|
|
168
191
|
console.log('Rendering SVG...')
|
|
169
192
|
writeFileSync(outputPath, svg.render(graph, layoutResult), 'utf-8')
|