@open-pencil/cli 0.6.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-pencil/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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 WEBP' },
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 (!['PNG', 'JPG', 'WEBP'].includes(format)) {
25
- printError(`Invalid format "${args.format}". Use png, jpg, or webp.`)
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) {