@open-pencil/cli 0.5.1 → 0.7.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/package.json +5 -7
- package/src/commands/export.ts +20 -4
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-pencil/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"openpencil": "./src/index.ts"
|
|
8
8
|
},
|
|
9
|
-
"files": [
|
|
10
|
-
"src"
|
|
11
|
-
],
|
|
9
|
+
"files": ["src"],
|
|
12
10
|
"repository": {
|
|
13
11
|
"type": "git",
|
|
14
12
|
"url": "git+https://github.com/open-pencil/open-pencil.git",
|
|
@@ -19,12 +17,12 @@
|
|
|
19
17
|
"provenance": true
|
|
20
18
|
},
|
|
21
19
|
"dependencies": {
|
|
20
|
+
"@open-pencil/core": "workspace:*",
|
|
22
21
|
"agentfmt": "^0.1.3",
|
|
23
22
|
"canvaskit-wasm": "^0.40.0",
|
|
24
|
-
"citty": "^0.1.6"
|
|
25
|
-
"@open-pencil/core": "0.5.1"
|
|
23
|
+
"citty": "^0.1.6"
|
|
26
24
|
},
|
|
27
25
|
"devDependencies": {
|
|
28
26
|
"@types/bun": "^1.2.9"
|
|
29
27
|
}
|
|
30
|
-
}
|
|
28
|
+
}
|
package/src/commands/export.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { defineCommand } from 'citty'
|
|
2
2
|
import { basename, extname, resolve } from 'node:path'
|
|
3
3
|
|
|
4
|
+
import { renderNodesToSVG } from '@open-pencil/core'
|
|
5
|
+
|
|
4
6
|
import { loadDocument, loadFonts, exportNodes, exportThumbnail } from '../headless'
|
|
5
7
|
import { ok, printError } from '../format'
|
|
6
8
|
import type { ExportFormat } from '@open-pencil/core'
|
|
7
9
|
|
|
10
|
+
const RASTER_FORMATS = ['PNG', 'JPG', 'WEBP']
|
|
11
|
+
|
|
8
12
|
export default defineCommand({
|
|
9
|
-
meta: { description: 'Export a .fig file to PNG, JPG, or
|
|
13
|
+
meta: { description: 'Export a .fig file to PNG, JPG, WEBP, or SVG' },
|
|
10
14
|
args: {
|
|
11
15
|
file: { type: 'positional', description: '.fig file path', required: true },
|
|
12
16
|
output: { type: 'string', alias: 'o', description: 'Output file path (default: <name>.<format>)' },
|
|
13
|
-
format: { type: 'string', alias: 'f', description: 'Export format: png, jpg, webp (default: png)', default: 'png' },
|
|
17
|
+
format: { type: 'string', alias: 'f', description: 'Export format: png, jpg, webp, svg (default: png)', default: 'png' },
|
|
14
18
|
scale: { type: 'string', alias: 's', description: 'Export scale (default: 1)', default: '1' },
|
|
15
19
|
quality: { type: 'string', alias: 'q', description: 'Quality 0-100 for JPG/WEBP (default: 90)' },
|
|
16
20
|
page: { type: 'string', description: 'Page name (default: first page)' },
|
|
@@ -21,8 +25,8 @@ export default defineCommand({
|
|
|
21
25
|
},
|
|
22
26
|
async run({ args }) {
|
|
23
27
|
const format = args.format.toUpperCase() as ExportFormat
|
|
24
|
-
if (![
|
|
25
|
-
printError(`Invalid format "${args.format}". Use png, jpg, or
|
|
28
|
+
if (![...RASTER_FORMATS, 'SVG'].includes(format)) {
|
|
29
|
+
printError(`Invalid format "${args.format}". Use png, jpg, webp, or svg.`)
|
|
26
30
|
process.exit(1)
|
|
27
31
|
}
|
|
28
32
|
|
|
@@ -43,6 +47,18 @@ export default defineCommand({
|
|
|
43
47
|
const defaultName = basename(args.file, extname(args.file))
|
|
44
48
|
const output = resolve(args.output ?? `${defaultName}.${ext}`)
|
|
45
49
|
|
|
50
|
+
if (format === 'SVG') {
|
|
51
|
+
const nodeIds = args.node ? [args.node] : page.childIds
|
|
52
|
+
const svgStr = renderNodesToSVG(graph, page.id, nodeIds)
|
|
53
|
+
if (!svgStr) {
|
|
54
|
+
printError('Nothing to export (empty page or no visible nodes).')
|
|
55
|
+
process.exit(1)
|
|
56
|
+
}
|
|
57
|
+
await Bun.write(output, svgStr)
|
|
58
|
+
console.log(ok(`Exported ${output} (${(svgStr.length / 1024).toFixed(1)} KB)`))
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
let data: Uint8Array | null
|
|
47
63
|
|
|
48
64
|
if (args.thumbnail) {
|