@shumoku/renderer 0.2.23 → 0.2.24

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/png.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * PNG renderer - converts SVG to PNG using resvg
3
+ */
4
+ export interface PngOptions {
5
+ /** Scale factor (default: 2) */
6
+ scale?: number;
7
+ /** Load system fonts (default: true) */
8
+ loadSystemFonts?: boolean;
9
+ }
10
+ /**
11
+ * Convert SVG string to PNG buffer
12
+ */
13
+ export declare function renderToPng(svgString: string, options?: PngOptions): Buffer;
14
+ //# sourceMappingURL=png.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"png.d.ts","sourceRoot":"","sources":["../src/png.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wCAAwC;IACxC,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,GAAG,MAAM,CAW/E"}
package/dist/png.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * PNG renderer - converts SVG to PNG using resvg
3
+ */
4
+ import { Resvg } from '@resvg/resvg-js';
5
+ /**
6
+ * Convert SVG string to PNG buffer
7
+ */
8
+ export function renderToPng(svgString, options = {}) {
9
+ const scale = options.scale ?? 2;
10
+ const loadSystemFonts = options.loadSystemFonts ?? true;
11
+ const resvg = new Resvg(svgString, {
12
+ fitTo: { mode: 'zoom', value: scale },
13
+ font: { loadSystemFonts },
14
+ });
15
+ const pngData = resvg.render();
16
+ return pngData.asPng();
17
+ }
18
+ //# sourceMappingURL=png.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"png.js","sourceRoot":"","sources":["../src/png.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AASvC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,SAAiB,EAAE,UAAsB,EAAE;IACrE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAA;IAChC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,IAAI,CAAA;IAEvD,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,SAAS,EAAE;QACjC,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;QACrC,IAAI,EAAE,EAAE,eAAe,EAAE;KAC1B,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,CAAA;IAC9B,OAAO,OAAO,CAAC,KAAK,EAAE,CAAA;AACxB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumoku/renderer",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "SVG and HTML renderers for Shumoku network diagrams",
5
5
  "license": "MIT",
6
6
  "author": "konoe-akitoshi",
@@ -39,6 +39,10 @@
39
39
  "./iife-string": {
40
40
  "types": "./dist/iife-string.d.ts",
41
41
  "import": "./dist/iife-string.js"
42
+ },
43
+ "./png": {
44
+ "types": "./dist/png.d.ts",
45
+ "import": "./dist/png.js"
42
46
  }
43
47
  },
44
48
  "files": [
package/src/png.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * PNG renderer - converts SVG to PNG using resvg
3
+ */
4
+
5
+ import { Resvg } from '@resvg/resvg-js'
6
+
7
+ export interface PngOptions {
8
+ /** Scale factor (default: 2) */
9
+ scale?: number
10
+ /** Load system fonts (default: true) */
11
+ loadSystemFonts?: boolean
12
+ }
13
+
14
+ /**
15
+ * Convert SVG string to PNG buffer
16
+ */
17
+ export function renderToPng(svgString: string, options: PngOptions = {}): Buffer {
18
+ const scale = options.scale ?? 2
19
+ const loadSystemFonts = options.loadSystemFonts ?? true
20
+
21
+ const resvg = new Resvg(svgString, {
22
+ fitTo: { mode: 'zoom', value: scale },
23
+ font: { loadSystemFonts },
24
+ })
25
+
26
+ const pngData = resvg.render()
27
+ return pngData.asPng()
28
+ }