kist 0.1.34 → 0.1.36
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.
|
@@ -2,7 +2,7 @@ import { Action } from "../../core/pipeline/Action";
|
|
|
2
2
|
import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
3
3
|
/**
|
|
4
4
|
* SvgToPngAction converts SVG content to PNG format.
|
|
5
|
-
* Uses `
|
|
5
|
+
* Uses `resvg-js` for conversion and `jsdom` for SVG element manipulation.
|
|
6
6
|
*/
|
|
7
7
|
export declare class SvgToPngAction extends Action {
|
|
8
8
|
/**
|
|
@@ -16,17 +16,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SvgToPngAction = void 0;
|
|
19
|
+
const resvg_js_1 = require("@resvg/resvg-js");
|
|
19
20
|
const fs_1 = __importDefault(require("fs"));
|
|
20
21
|
const jsdom_1 = require("jsdom");
|
|
21
22
|
const path_1 = __importDefault(require("path"));
|
|
22
|
-
const sharp_1 = __importDefault(require("sharp"));
|
|
23
23
|
const Action_1 = require("../../core/pipeline/Action");
|
|
24
24
|
// ============================================================================
|
|
25
25
|
// Classes
|
|
26
26
|
// ============================================================================
|
|
27
27
|
/**
|
|
28
28
|
* SvgToPngAction converts SVG content to PNG format.
|
|
29
|
-
* Uses `
|
|
29
|
+
* Uses `resvg-js` for conversion and `jsdom` for SVG element manipulation.
|
|
30
30
|
*/
|
|
31
31
|
class SvgToPngAction extends Action_1.Action {
|
|
32
32
|
// Methods
|
|
@@ -68,25 +68,25 @@ class SvgToPngAction extends Action_1.Action {
|
|
|
68
68
|
if (!fs_1.default.existsSync(outputDir)) {
|
|
69
69
|
fs_1.default.mkdirSync(outputDir, { recursive: true });
|
|
70
70
|
}
|
|
71
|
-
//
|
|
71
|
+
// Parse SVG and apply width/height
|
|
72
72
|
const dom = new jsdom_1.JSDOM(svgContent);
|
|
73
73
|
const svgElement = dom.window.document.querySelector("svg");
|
|
74
74
|
if (!svgElement) {
|
|
75
75
|
throw new Error("Invalid SVG content");
|
|
76
76
|
}
|
|
77
|
-
if (width)
|
|
77
|
+
if (width)
|
|
78
78
|
svgElement.setAttribute("width", width.toString());
|
|
79
|
-
|
|
80
|
-
if (height) {
|
|
79
|
+
if (height)
|
|
81
80
|
svgElement.setAttribute("height", height.toString());
|
|
82
|
-
}
|
|
83
|
-
// Serialize the updated SVG content
|
|
84
81
|
const updatedSvgContent = svgElement.outerHTML;
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
// Render using Resvg
|
|
83
|
+
const resvg = new resvg_js_1.Resvg(updatedSvgContent, {
|
|
84
|
+
fitTo: width && height
|
|
85
|
+
? { mode: "width", value: width }
|
|
86
|
+
: undefined,
|
|
87
|
+
});
|
|
88
|
+
const pngBuffer = resvg.render().asPng();
|
|
89
|
+
fs_1.default.writeFileSync(outputPath, pngBuffer);
|
|
90
90
|
}
|
|
91
91
|
catch (error) {
|
|
92
92
|
throw new Error(`Error converting SVG to PNG: ${error.message}`);
|
|
@@ -98,7 +98,7 @@ class SvgToPngAction extends Action_1.Action {
|
|
|
98
98
|
* @returns A string description of the action.
|
|
99
99
|
*/
|
|
100
100
|
describe() {
|
|
101
|
-
return "Converts SVG content to PNG format with optional resizing.";
|
|
101
|
+
return "Converts SVG content to PNG format with optional resizing using resvg-js.";
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
exports.SvgToPngAction = SvgToPngAction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kist",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"description": "Package Pipeline Processor",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kist",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"@babel/core": "^7.23.6",
|
|
61
61
|
"@babel/preset-env": "^7.23.6",
|
|
62
62
|
"@babel/preset-typescript": "^7.23.3",
|
|
63
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
63
64
|
"@types/fs-extra": "^11.0.4",
|
|
64
65
|
"@types/glob": "^8.1.0",
|
|
65
66
|
"@types/jsdom": "^21.1.6",
|
|
@@ -88,7 +89,6 @@
|
|
|
88
89
|
"sass": "^1.69.7",
|
|
89
90
|
"sassdoc": "^2.7.4",
|
|
90
91
|
"semver": "^7.5.4",
|
|
91
|
-
"sharp": "^0.34.1",
|
|
92
92
|
"svg-sprite": "^2.0.2",
|
|
93
93
|
"svgo": "^3.1.0",
|
|
94
94
|
"terser": "^5.26.0",
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Imports
|
|
3
3
|
// ============================================================================
|
|
4
4
|
|
|
5
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
5
6
|
import fs from "fs";
|
|
6
7
|
import { JSDOM } from "jsdom";
|
|
7
8
|
import path from "path";
|
|
8
|
-
import sharp from "sharp";
|
|
9
9
|
import { Action } from "../../core/pipeline/Action";
|
|
10
10
|
import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* SvgToPngAction converts SVG content to PNG format.
|
|
18
|
-
* Uses `
|
|
18
|
+
* Uses `resvg-js` for conversion and `jsdom` for SVG element manipulation.
|
|
19
19
|
*/
|
|
20
20
|
export class SvgToPngAction extends Action {
|
|
21
21
|
// Methods
|
|
@@ -66,7 +66,7 @@ export class SvgToPngAction extends Action {
|
|
|
66
66
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
//
|
|
69
|
+
// Parse SVG and apply width/height
|
|
70
70
|
const dom = new JSDOM(svgContent);
|
|
71
71
|
const svgElement = dom.window.document.querySelector("svg");
|
|
72
72
|
|
|
@@ -74,22 +74,22 @@ export class SvgToPngAction extends Action {
|
|
|
74
74
|
throw new Error("Invalid SVG content");
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
if (width)
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (height) {
|
|
82
|
-
svgElement.setAttribute("height", height.toString());
|
|
83
|
-
}
|
|
77
|
+
if (width) svgElement.setAttribute("width", width.toString());
|
|
78
|
+
if (height) svgElement.setAttribute("height", height.toString());
|
|
84
79
|
|
|
85
|
-
// Serialize the updated SVG content
|
|
86
80
|
const updatedSvgContent = svgElement.outerHTML;
|
|
87
81
|
|
|
88
|
-
//
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
// Render using Resvg
|
|
83
|
+
const resvg = new Resvg(updatedSvgContent, {
|
|
84
|
+
fitTo:
|
|
85
|
+
width && height
|
|
86
|
+
? { mode: "width", value: width }
|
|
87
|
+
: undefined,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const pngBuffer = resvg.render().asPng();
|
|
91
|
+
|
|
92
|
+
fs.writeFileSync(outputPath, pngBuffer);
|
|
93
93
|
} catch (error) {
|
|
94
94
|
throw new Error(
|
|
95
95
|
`Error converting SVG to PNG: ${(error as Error).message}`,
|
|
@@ -102,7 +102,7 @@ export class SvgToPngAction extends Action {
|
|
|
102
102
|
* @returns A string description of the action.
|
|
103
103
|
*/
|
|
104
104
|
describe(): string {
|
|
105
|
-
return "Converts SVG content to PNG format with optional resizing.";
|
|
105
|
+
return "Converts SVG content to PNG format with optional resizing using resvg-js.";
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|