svg-toolbox 1.0.4 → 1.1.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/README.md CHANGED
@@ -20,4 +20,12 @@ const { diffSvg } = require('svg-toolbox')
20
20
  ...
21
21
  diffSvg(svgPath1, svgPath2, diffResultSavePath)
22
22
  ...
23
+ ```
24
+
25
+ ```js
26
+ const { removeEmptyCoordinates } = require('svg-toolbox')
27
+
28
+ ...
29
+ const mData = removeEmptyCoordinates(svgContent)
30
+ ...
23
31
  ```
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Compares two SVG files and generates a diff image.
3
+ * @param {string} pathA - The path of the first SVG file.
4
+ * @param {string} pathB - The path of the second SVG file.
5
+ * @param {string} diffFilePath - The path to save the diff image.
6
+ * @returns - The diff image buffer and the number of different pixels.
7
+ */
8
+ export default function (pathA: string, pathB: string, diffFilePath: string): Promise<{
9
+ diffPngBuffer: ArrayBuffer;
10
+ numDiffPixels: number;
11
+ } | void>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @file applyDiffSvg.js
3
+ * @description This module provides a function to compare two PNG images and generate a diff image using the sharp and pixelmatch libraries.
4
+ * @module applyDiffSvg
5
+ * @requires sharp - Image processing library
6
+ * @requires pixelmatch - Image comparison library
7
+ * @requires fs - File system module
8
+ * @requires path - Path module
9
+ * @author pipi
10
+ */
11
+ // @ts-ignore
12
+ import fs from 'fs';
13
+ import sharp from 'sharp';
14
+ // @ts-ignore
15
+ import pngjs from 'pngjs';
16
+ // @ts-ignore
17
+ import path from 'path';
18
+ // @ts-ignore
19
+ import pixelmatch from 'pixelmatch';
20
+ const PNG = pngjs.PNG;
21
+ /**
22
+ * Checks if the filename has a valid suffix.
23
+ * @param {string} filename - The name of the file.
24
+ * @returns {boolean} - True if the filename has a suffix, false otherwise.
25
+ */
26
+ function validSuffix(filename) {
27
+ return path.extname(filename) !== '';
28
+ }
29
+ /**
30
+ * Compares two SVG files and generates a diff image.
31
+ * @param {string} pathA - The path of the first SVG file.
32
+ * @param {string} pathB - The path of the second SVG file.
33
+ * @param {string} diffFilePath - The path to save the diff image.
34
+ * @returns - The diff image buffer and the number of different pixels.
35
+ */
36
+ export default async function (pathA, pathB, diffFilePath) {
37
+ // Import pixelmatch library
38
+ // @ts-ignore
39
+ // const pixelmatch = (await import('pixelmatch')).default;
40
+ // Read the PNG files as buffers
41
+ const pngA = await sharp(pathA).toBuffer();
42
+ const pngB = await sharp(pathB).toBuffer();
43
+ // Decode the PNG buffers
44
+ const img1 = PNG.sync.read(pngA);
45
+ const img2 = PNG.sync.read(pngB);
46
+ const { width, height } = img1;
47
+ // Create a new PNG object for the diff image
48
+ const diff = new PNG({ width, height });
49
+ // Compare the images and get the number of different pixels
50
+ const numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 });
51
+ // Write the diff image to a buffer
52
+ const diffPngBuffer = PNG.sync.write(diff);
53
+ // If a diff file path is provided, save the diff image
54
+ if (diffFilePath) {
55
+ const diffFileName = path.basename(diffFilePath);
56
+ if (!validSuffix(diffFileName)) {
57
+ console.error(`Error converting ${diffFileName} to PNG: No suffix found.`);
58
+ return;
59
+ }
60
+ fs.writeFileSync(diffFilePath, diffPngBuffer);
61
+ // Log the result
62
+ if (numDiffPixels === 0) {
63
+ console.log(`\x1b[32mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
64
+ }
65
+ else {
66
+ console.log(`\x1b[33mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
67
+ }
68
+ }
69
+ return { diffPngBuffer, numDiffPixels };
70
+ }
71
+ //# sourceMappingURL=applyDiffSvg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyDiffSvg.js","sourceRoot":"","sources":["../src/applyDiffSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,aAAa;AACb,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,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AC,IAAI,CAAC,CAAC;IAE3C,uDAAuD;IACvD,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACjD,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,oBAAoB,YAAY,2BAA2B,CAAC,CAAC;YAC3E,OAAO;QACT,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QAE9C,iBAAiB;QACjB,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,sBAAsB,YAAY,gCAAgC,aAAa,SAAS,CAAC,CAAC;QACxG,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,sBAAsB,YAAY,gCAAgC,aAAa,SAAS,CAAC,CAAC;QACxG,CAAC;IACH,CAAC;IAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @file applyRemoveNanCoordinates.js
3
+ * @description This module provides a function to parse and normalize the 'd' attribute of all path elements in an SVG content.
4
+ * @requires jsdom - JavaScript DOM library
5
+ * @module applyRemoveNanCoordinates
6
+ * @author pipi
7
+ */
8
+ /**
9
+ * Parses and normalizes the 'd' attribute of all path elements in an SVG content.
10
+ * @param {*} svgContent
11
+ * @returns
12
+ */
13
+ export default function (svgContent: string): string;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @file applyRemoveNanCoordinates.js
3
+ * @description This module provides a function to parse and normalize the 'd' attribute of all path elements in an SVG content.
4
+ * @requires jsdom - JavaScript DOM library
5
+ * @module applyRemoveNanCoordinates
6
+ * @author pipi
7
+ */
8
+ // @ts-ignore
9
+ import { JSDOM } from 'jsdom';
10
+ /**
11
+ * Parses and normalizes the 'd' attribute of all path elements in an SVG content.
12
+ * @param {*} svgContent
13
+ * @returns
14
+ */
15
+ export default function (svgContent) {
16
+ // Create a DOM from the SVG content
17
+ const dom = new JSDOM(svgContent, {
18
+ contentType: 'image/svg+xml' // Set content type to SVG
19
+ });
20
+ const document = dom.window.document;
21
+ const svgElement = document.querySelector('svg');
22
+ const paths = svgElement.querySelectorAll('path');
23
+ // Iterate over each path element
24
+ Array.from(paths).forEach((path) => {
25
+ const d = path.getAttribute('d'); // Get the 'd' attribute
26
+ const commands = d.split(/(?=[MLHVCSQTAZ])/).map((command) => {
27
+ const type = command[0]; // Command type (e.g., M, L, H, etc.)
28
+ const params = command.slice(1).trim().split(/[\s,]+/).filter(Number); // Command parameters
29
+ return { type, params };
30
+ }).filter((command) => (command.type === 'Z' || command.params.length > 0)); // Filter out invalid commands
31
+ // Reconstruct the 'd' attribute
32
+ const modifiedD = commands.map((command) => {
33
+ return command.type + command.params.join(' ');
34
+ }).join('');
35
+ path.setAttribute('d', modifiedD); // Set the modified 'd' attribute
36
+ });
37
+ // Get the new SVG content
38
+ const newSvgContent = svgElement.outerHTML.trim();
39
+ return newSvgContent;
40
+ }
41
+ //# sourceMappingURL=applyRemoveNanCoordinates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyRemoveNanCoordinates.js","sourceRoot":"","sources":["../src/applyRemoveNanCoordinates.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,aAAa;AACb,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,UAAkB;IACzC,oCAAoC;IACpC,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE;QAChC,WAAW,EAAE,eAAe,CAAC,0BAA0B;KACxD,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;IACrC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACjD,MAAM,KAAK,GAAG,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AC;AACvB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file applySvg2Png.js
3
+ * @description This module provides a function to convert SVG files to PNG format using the sharp library.
4
+ * @module applySvg2Png
5
+ * @requires sharp - Image processing library
6
+ * @requires fs - File system module
7
+ * @author pipi
8
+ */
9
+ /**
10
+ * Converts an SVG file to PNG format.
11
+ * @param {string} svgPath - The path to read the SVG file.
12
+ * @param {string} pngPath - The path to save the PNG file.
13
+ * @param {number} x - The scaling factor for the PNG image.
14
+ * @returns
15
+ */
16
+ export default function (svgPath: string, pngPath: string, x?: number): void;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @file applySvg2Png.js
3
+ * @description This module provides a function to convert SVG files to PNG format using the sharp library.
4
+ * @module applySvg2Png
5
+ * @requires sharp - Image processing library
6
+ * @requires fs - File system module
7
+ * @author pipi
8
+ */
9
+ import sharp from 'sharp';
10
+ // @ts-ignore
11
+ import fs from 'fs';
12
+ /**
13
+ * Converts an SVG file to PNG format.
14
+ * @param {string} svgPath - The path to read the SVG file.
15
+ * @param {string} pngPath - The path to save the PNG file.
16
+ * @param {number} x - The scaling factor for the PNG image.
17
+ * @returns
18
+ */
19
+ export default function (svgPath, pngPath, x = 2) {
20
+ // Read the SVG file
21
+ const file = svgPath.split('/').pop();
22
+ const svgContent = fs.readFileSync(svgPath, 'utf8');
23
+ // Extract the viewBox from the SVG content
24
+ const viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
25
+ const viewBoxMatch = viewBoxRegex.exec(svgContent);
26
+ if (!viewBoxMatch) {
27
+ console.error(`Error converting ${file} to PNG: No viewBox found.`);
28
+ return;
29
+ }
30
+ // Extract the width and height from the viewBox
31
+ const [, , , baseWidth, baseHeight] = viewBoxMatch.map(Number);
32
+ // Resize the SVG to the desired dimensions and convert it to PNG
33
+ sharp(svgPath)
34
+ .resize(x * baseWidth, x * baseHeight)
35
+ .png()
36
+ .toFile(pngPath)
37
+ .then(() => {
38
+ console.log(`\x1b[32mConverted ${file} to PNG successfully.\x1b[0m`);
39
+ })
40
+ .catch(error => {
41
+ console.error(`Error converting ${file} to PNG:`, error);
42
+ });
43
+ }
44
+ //# sourceMappingURL=applySvg2Png.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../src/applySvg2Png.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,aAAa;AACb,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,WAAW,OAAe,EAAE,OAAe,EAAE,IAAY,CAAC;IACtE,oBAAoB;IACpB,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACtC,MAAM,UAAU,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAEpD,2CAA2C;IAC3C,MAAM,YAAY,GAAG,mCAAmC,CAAC;IACzD,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAEnD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,oBAAoB,IAAI,4BAA4B,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,gDAAgD;IAChD,MAAM,CAAC,EAAE,AAAD,EAAG,AAAD,EAAG,SAAS,EAAE,UAAU,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE/D,iEAAiE;IACjE,KAAK,CAAC,OAAO,CAAC;SACX,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;SACrC,GAAG,EAAE;SACL,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,GAAG,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,8BAA8B,CAAC,CAAC;IACvE,CAAC,CAAC;SACD,KAAK,CAAC,KAAK,CAAC,EAAE;QACb,OAAO,CAAC,KAAK,CAAC,oBAAoB,IAAI,UAAU,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC"}
package/es/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import svg2Png from './applySvg2Png';
2
+ import diffSvg from './applyDiffSvg';
3
+ import removeEmptyCoordinates from './applyRemoveNanCoordinates';
4
+ export { svg2Png, diffSvg, removeEmptyCoordinates, };
package/es/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import svg2Png from './applySvg2Png';
2
+ import diffSvg from './applyDiffSvg';
3
+ import removeEmptyCoordinates from './applyRemoveNanCoordinates';
4
+ export { svg2Png, diffSvg, removeEmptyCoordinates, };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,sBAAsB,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EACL,OAAO,EACP,OAAO,EACP,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Compares two SVG files and generates a diff image.
3
+ * @param {string} pathA - The path of the first SVG file.
4
+ * @param {string} pathB - The path of the second SVG file.
5
+ * @param {string} diffFilePath - The path to save the diff image.
6
+ * @returns - The diff image buffer and the number of different pixels.
7
+ */
8
+ export default function (pathA: string, pathB: string, diffFilePath: string): Promise<{
9
+ diffPngBuffer: ArrayBuffer;
10
+ numDiffPixels: number;
11
+ } | void>;
@@ -1,3 +1,45 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.default = default_1;
1
43
  /**
2
44
  * @file applyDiffSvg.js
3
45
  * @description This module provides a function to compare two PNG images and generate a diff image using the sharp and pixelmatch libraries.
@@ -8,21 +50,24 @@
8
50
  * @requires path - Path module
9
51
  * @author pipi
10
52
  */
11
-
12
- const fs = require('fs');
13
- const sharp = require('sharp');
14
- const PNG = require('pngjs').PNG;
15
- const path = require('path');
16
-
53
+ // @ts-ignore
54
+ var fs_1 = __importDefault(require("fs"));
55
+ var sharp_1 = __importDefault(require("sharp"));
56
+ // @ts-ignore
57
+ var pngjs_1 = __importDefault(require("pngjs"));
58
+ // @ts-ignore
59
+ var path_1 = __importDefault(require("path"));
60
+ // @ts-ignore
61
+ var pixelmatch_1 = __importDefault(require("pixelmatch"));
62
+ var PNG = pngjs_1.default.PNG;
17
63
  /**
18
64
  * Checks if the filename has a valid suffix.
19
65
  * @param {string} filename - The name of the file.
20
66
  * @returns {boolean} - True if the filename has a suffix, false otherwise.
21
67
  */
22
68
  function validSuffix(filename) {
23
- return path.extname(filename) !== '';
69
+ return path_1.default.extname(filename) !== '';
24
70
  }
25
-
26
71
  /**
27
72
  * Compares two SVG files and generates a diff image.
28
73
  * @param {string} pathA - The path of the first SVG file.
@@ -30,44 +75,42 @@ function validSuffix(filename) {
30
75
  * @param {string} diffFilePath - The path to save the diff image.
31
76
  * @returns - The diff image buffer and the number of different pixels.
32
77
  */
33
- module.exports = async function (pathA, pathB, diffFilePath) {
34
- // Read the PNG files as buffers
35
- const pngA = await sharp(pathA).toBuffer();
36
- const pngB = await sharp(pathB).toBuffer();
37
-
38
- // Import pixelmatch library
39
- const pixelmatch = (await import('pixelmatch')).default;
40
-
41
- // Decode the PNG buffers
42
- const img1 = PNG.sync.read(pngA);
43
- const img2 = PNG.sync.read(pngB);
44
- const { width, height } = img1;
45
-
46
- // Create a new PNG object for the diff image
47
- const diff = new PNG({ width, height });
48
-
49
- // Compare the images and get the number of different pixels
50
- const numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 });
51
-
52
- // Write the diff image to a buffer
53
- const diffPngBuffer = PNG.sync.write(diff);
54
-
55
- // If a diff file path is provided, save the diff image
56
- if (diffFilePath) {
57
- const diffFileName = path.basename(diffFilePath);
58
- if (!validSuffix(diffFileName)) {
59
- console.error(`Error converting ${diffFileName} to PNG: No suffix found.`);
60
- return;
61
- }
62
- fs.writeFileSync(diffFilePath, diffPngBuffer);
63
-
64
- // Log the result
65
- if (numDiffPixels === 0) {
66
- console.log(`\x1b[32mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
67
- } else {
68
- console.log(`\x1b[33mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
69
- }
70
- }
71
-
72
- return { diffPngBuffer, numDiffPixels };
73
- }
78
+ function default_1(pathA, pathB, diffFilePath) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ var pngA, pngB, img1, img2, width, height, diff, numDiffPixels, diffPngBuffer, diffFileName;
81
+ return __generator(this, function (_a) {
82
+ switch (_a.label) {
83
+ case 0: return [4 /*yield*/, (0, sharp_1.default)(pathA).toBuffer()];
84
+ case 1:
85
+ pngA = _a.sent();
86
+ return [4 /*yield*/, (0, sharp_1.default)(pathB).toBuffer()];
87
+ case 2:
88
+ pngB = _a.sent();
89
+ img1 = PNG.sync.read(pngA);
90
+ img2 = PNG.sync.read(pngB);
91
+ width = img1.width, height = img1.height;
92
+ diff = new PNG({ width: width, height: height });
93
+ numDiffPixels = (0, pixelmatch_1.default)(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 });
94
+ diffPngBuffer = PNG.sync.write(diff);
95
+ // If a diff file path is provided, save the diff image
96
+ if (diffFilePath) {
97
+ diffFileName = path_1.default.basename(diffFilePath);
98
+ if (!validSuffix(diffFileName)) {
99
+ console.error("Error converting ".concat(diffFileName, " to PNG: No suffix found."));
100
+ return [2 /*return*/];
101
+ }
102
+ fs_1.default.writeFileSync(diffFilePath, diffPngBuffer);
103
+ // Log the result
104
+ if (numDiffPixels === 0) {
105
+ console.log("\u001B[32mFile name: ".concat(diffFileName, " Number of different pixels: ").concat(numDiffPixels, "\u001B[0m"));
106
+ }
107
+ else {
108
+ console.log("\u001B[33mFile name: ".concat(diffFileName, " Number of different pixels: ").concat(numDiffPixels, "\u001B[0m"));
109
+ }
110
+ }
111
+ return [2 /*return*/, { diffPngBuffer: diffPngBuffer, numDiffPixels: numDiffPixels }];
112
+ }
113
+ });
114
+ });
115
+ }
116
+ //# sourceMappingURL=applyDiffSvg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyDiffSvg.js","sourceRoot":"","sources":["../src/applyDiffSvg.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,4BAwCC;AA9ED;;;;;;;;;GASG;AACH,aAAa;AACb,0CAAoB;AACpB,gDAA0B;AAC1B,aAAa;AACb,gDAA0B;AAC1B,aAAa;AACb,8CAAwB;AACxB,cAAc;AACd,0DAAoC;AAEpC,IAAM,GAAG,GAAG,eAAK,CAAC,GAAG,CAAC;AAEtB;;;;GAIG;AACH,SAAS,WAAW,CAAC,QAAgB;IACnC,OAAO,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;AACvC,CAAC;AAED;;;;;;GAMG;AACH,mBAA+B,KAAa,EAAE,KAAa,EAAE,YAAoB;;;;;wBAKlE,qBAAM,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAA;;oBAApC,IAAI,GAAG,SAA6B;oBAC7B,qBAAM,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAA;;oBAApC,IAAI,GAAG,S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 -0,0 +1,13 @@
1
+ /**
2
+ * @file applyRemoveNanCoordinates.js
3
+ * @description This module provides a function to parse and normalize the 'd' attribute of all path elements in an SVG content.
4
+ * @requires jsdom - JavaScript DOM library
5
+ * @module applyRemoveNanCoordinates
6
+ * @author pipi
7
+ */
8
+ /**
9
+ * Parses and normalizes the 'd' attribute of all path elements in an SVG content.
10
+ * @param {*} svgContent
11
+ * @returns
12
+ */
13
+ export default function (svgContent: string): string;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * @file applyRemoveNanCoordinates.js
3
4
  * @description This module provides a function to parse and normalize the 'd' attribute of all path elements in an SVG content.
@@ -5,41 +6,39 @@
5
6
  * @module applyRemoveNanCoordinates
6
7
  * @author pipi
7
8
  */
8
-
9
- const { JSDOM } = require('jsdom');
10
-
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.default = default_1;
11
+ // @ts-ignore
12
+ var jsdom_1 = require("jsdom");
11
13
  /**
12
14
  * Parses and normalizes the 'd' attribute of all path elements in an SVG content.
13
- * @param {*} svgContent
14
- * @returns
15
+ * @param {*} svgContent
16
+ * @returns
15
17
  */
16
- module.exports = function (svgContent) {
17
- // Create a DOM from the SVG content
18
- const dom = new JSDOM(svgContent, {
19
- contentType: 'image/svg+xml' // Set content type to SVG
20
- });
21
- const document = dom.window.document;
22
- const svgElement = document.querySelector('svg');
23
- const paths = svgElement.querySelectorAll('path');
24
-
25
- // Iterate over each path element
26
- Array.from(paths).forEach(path => {
27
- const d = path.getAttribute('d'); // Get the 'd' attribute
28
- const commands = d.split(/(?=[MLHVCSQTAZ])/).map(command => {
29
- const type = command[0]; // Command type (e.g., M, L, H, etc.)
30
- const params = command.slice(1).trim().split(/[\s,]+/).filter(Number); // Command parameters
31
- return { type, params };
32
- }).filter(command => (command.type === 'Z' || command.params.length > 0)); // Filter out invalid commands
33
-
34
- // Reconstruct the 'd' attribute
35
- const modifiedD = commands.map(command => {
36
- return command.type + command.params.join(' ');
37
- }).join('');
38
- path.setAttribute('d', modifiedD); // Set the modified 'd' attribute
39
- });
40
-
41
- // Get the new SVG content
42
- const newSvgContent = svgElement.outerHTML.trim();
43
-
44
- return newSvgContent;
45
- }
18
+ function default_1(svgContent) {
19
+ // Create a DOM from the SVG content
20
+ var dom = new jsdom_1.JSDOM(svgContent, {
21
+ contentType: 'image/svg+xml' // Set content type to SVG
22
+ });
23
+ var document = dom.window.document;
24
+ var svgElement = document.querySelector('svg');
25
+ var paths = svgElement.querySelectorAll('path');
26
+ // Iterate over each path element
27
+ Array.from(paths).forEach(function (path) {
28
+ var d = path.getAttribute('d'); // Get the 'd' attribute
29
+ var commands = d.split(/(?=[MLHVCSQTAZ])/).map(function (command) {
30
+ var type = command[0]; // Command type (e.g., M, L, H, etc.)
31
+ var params = command.slice(1).trim().split(/[\s,]+/).filter(Number); // Command parameters
32
+ return { type: type, params: params };
33
+ }).filter(function (command) { return (command.type === 'Z' || command.params.length > 0); }); // Filter out invalid commands
34
+ // Reconstruct the 'd' attribute
35
+ var modifiedD = commands.map(function (command) {
36
+ return command.type + command.params.join(' ');
37
+ }).join('');
38
+ path.setAttribute('d', modifiedD); // Set the modified 'd' attribute
39
+ });
40
+ // Get the new SVG content
41
+ var newSvgContent = svgElement.outerHTML.trim();
42
+ return newSvgContent;
43
+ }
44
+ //# sourceMappingURL=applyRemoveNanCoordinates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyRemoveNanCoordinates.js","sourceRoot":"","sources":["../src/applyRemoveNanCoordinates.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAUH,4BA6BC;AArCD,aAAa;AACb,+BAA8B;AAE9B;;;;GAIG;AACH,mBAAyB,UAAkB;IACzC,oCAAoC;IACpC,IAAM,GAAG,GAAG,IAAI,aAAK,CAAC,UAAU,EAAE;QAChC,WAAW,EAAE,eAAe,CAAC,0BAA0B;KACxD,CAAC,CAAC;IACH,IAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QA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AC1B,IAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAElD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @file applySvg2Png.js
3
+ * @description This module provides a function to convert SVG files to PNG format using the sharp library.
4
+ * @module applySvg2Png
5
+ * @requires sharp - Image processing library
6
+ * @requires fs - File system module
7
+ * @author pipi
8
+ */
9
+ /**
10
+ * Converts an SVG file to PNG format.
11
+ * @param {string} svgPath - The path to read the SVG file.
12
+ * @param {string} pngPath - The path to save the PNG file.
13
+ * @param {number} x - The scaling factor for the PNG image.
14
+ * @returns
15
+ */
16
+ export default function (svgPath: string, pngPath: string, x?: number): void;
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * @file applySvg2Png.js
3
4
  * @description This module provides a function to convert SVG files to PNG format using the sharp library.
@@ -6,43 +7,45 @@
6
7
  * @requires fs - File system module
7
8
  * @author pipi
8
9
  */
9
-
10
- const sharp = require('sharp');
11
- const fs = require('fs');
12
-
10
+ var __importDefault = (this && this.__importDefault) || function (mod) {
11
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.default = default_1;
15
+ var sharp_1 = __importDefault(require("sharp"));
16
+ // @ts-ignore
17
+ var fs_1 = __importDefault(require("fs"));
13
18
  /**
14
19
  * Converts an SVG file to PNG format.
15
- * @param {string} svgPath - The path to read the SVG file.
20
+ * @param {string} svgPath - The path to read the SVG file.
16
21
  * @param {string} pngPath - The path to save the PNG file.
17
22
  * @param {number} x - The scaling factor for the PNG image.
18
23
  * @returns
19
24
  */
20
- module.exports = function (svgPath, pngPath, x = 2) {
21
- // Read the SVG file
22
- const file = svgPath.split('/').pop();
23
- const svgContent = fs.readFileSync(svgPath, 'utf8');
24
-
25
- // Extract the viewBox from the SVG content
26
- const viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
27
- const viewBoxMatch = viewBoxRegex.exec(svgContent);
28
-
29
- if (!viewBoxMatch) {
30
- console.error(`Error converting ${file} to PNG: No viewBox found.`);
31
- return;
32
- }
33
-
34
- // Extract the width and height from the viewBox
35
- const [, , , baseWidth, baseHeight] = viewBoxMatch.map(Number);
36
-
37
- // Resize the SVG to the desired dimensions and convert it to PNG
38
- sharp(svgPath)
39
- .resize(x * baseWidth, x * baseHeight)
40
- .png()
41
- .toFile(pngPath)
42
- .then(() => {
43
- console.log(`\x1b[32mConverted ${file} to PNG successfully.\x1b[0m`);
25
+ function default_1(svgPath, pngPath, x) {
26
+ if (x === void 0) { x = 2; }
27
+ // Read the SVG file
28
+ var file = svgPath.split('/').pop();
29
+ var svgContent = fs_1.default.readFileSync(svgPath, 'utf8');
30
+ // Extract the viewBox from the SVG content
31
+ var viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
32
+ var viewBoxMatch = viewBoxRegex.exec(svgContent);
33
+ if (!viewBoxMatch) {
34
+ console.error("Error converting ".concat(file, " to PNG: No viewBox found."));
35
+ return;
36
+ }
37
+ // Extract the width and height from the viewBox
38
+ var _a = viewBoxMatch.map(Number), baseWidth = _a[3], baseHeight = _a[4];
39
+ // Resize the SVG to the desired dimensions and convert it to PNG
40
+ (0, sharp_1.default)(svgPath)
41
+ .resize(x * baseWidth, x * baseHeight)
42
+ .png()
43
+ .toFile(pngPath)
44
+ .then(function () {
45
+ console.log("\u001B[32mConverted ".concat(file, " to PNG successfully.\u001B[0m"));
44
46
  })
45
- .catch(error => {
46
- console.error(`Error converting ${file} to PNG:`, error);
47
+ .catch(function (error) {
48
+ console.error("Error converting ".concat(file, " to PNG:"), error);
47
49
  });
48
- }
50
+ }
51
+ //# sourceMappingURL=applySvg2Png.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../src/applySvg2Png.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AAaH,4BA4BC;AAvCD,gDAA0B;AAC1B,aAAa;AACb,0CAAoB;AAEpB;;;;;;GAMG;AACH,mBAAyB,OAAe,EAAE,OAAe,EAAE,CAAa;IAAb,kBAAA,EAAA,KAAa;IACtE,oBAAoB;IACpB,IAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;IACtC,IAAM,UAAU,GAAG,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAEpD,2CAA2C;IAC3C,IAAM,YAAY,GAAG,mCAAmC,CAAC;IACzD,IAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAEnD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,2BAAoB,IAAI,+BAA4B,CAAC,CAAC;QACpE,OAAO;IACT,CAAC;IAED,gDAAgD;IAC1C,IAAA,KAAgC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAjD,SAAS,QAAA,EAAE,UAAU,QAA4B,CAAC;IAE/D,iEAAiE;IACjE,IAAA,eAAK,EAAC,OAAO,CAAC;SACX,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;SACrC,GAAG,EAAE;SACL,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC;QACJ,OAAO,CAAC,GAAG,CAAC,8BAAqB,IAAI,mCAA8B,CAAC,CAAC;IACvE,CAAC,CAAC;SACD,KAAK,CAAC,UAAA,KAAK;QACV,OAAO,CAAC,KAAK,CAAC,2BAAoB,IAAI,aAAU,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACP,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import svg2Png from './applySvg2Png';
2
+ import diffSvg from './applyDiffSvg';
3
+ import removeEmptyCoordinates from './applyRemoveNanCoordinates';
4
+ export { svg2Png, diffSvg, removeEmptyCoordinates, };
package/lib/index.js CHANGED
@@ -1,9 +1,13 @@
1
- const svg2Png = require('./applySvg2Png');
2
- const diffSvg = require('./applyDiffSvg');
3
- const removeEmptyCoordinates = require('./applyRemoveNanCoordinates');
4
-
5
- module.exports = {
6
- svg2Png,
7
- diffSvg,
8
- removeEmptyCoordinates,
9
- };
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.removeEmptyCoordinates = exports.diffSvg = exports.svg2Png = void 0;
7
+ var applySvg2Png_1 = __importDefault(require("./applySvg2Png"));
8
+ exports.svg2Png = applySvg2Png_1.default;
9
+ var applyDiffSvg_1 = __importDefault(require("./applyDiffSvg"));
10
+ exports.diffSvg = applyDiffSvg_1.default;
11
+ var applyRemoveNanCoordinates_1 = __importDefault(require("./applyRemoveNanCoordinates"));
12
+ exports.removeEmptyCoordinates = applyRemoveNanCoordinates_1.default;
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAKnC,kBALK,sBAAO,CAKL;AAJT,gEAAqC;AAKnC,kBALK,sBAAO,CAKL;AAJT,0FAAiE;AAK/D,iCALK,mCAAsB,CAKL"}
package/package.json CHANGED
@@ -1,11 +1,21 @@
1
1
  {
2
2
  "name": "svg-toolbox",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "This library provides some SVG-related tools",
5
5
  "main": "lib/index.js",
6
+ "module": "es/index.js",
7
+ "types": "es/index.d.ts",
8
+ "files": [
9
+ "lib",
10
+ "es",
11
+ "LICENSE",
12
+ "README.md"
13
+ ],
6
14
  "repository": "https://github.com/SteamedBread2333/svg-toolbox",
7
15
  "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
16
+ "build:es": "tsc -p tsconfig.json",
17
+ "build:cjs": "tsc -p tsconfig.cjs.json",
18
+ "build": "npm run build:es && npm run build:cjs"
9
19
  },
10
20
  "keywords": [
11
21
  "svg"
@@ -13,8 +23,12 @@
13
23
  "author": "pipi",
14
24
  "license": "MIT",
15
25
  "dependencies": {
16
- "pixelmatch": "^6.0.0",
26
+ "jsdom": "^26.0.0",
27
+ "pixelmatch": "5.3.0",
17
28
  "pngjs": "^7.0.0",
18
29
  "sharp": "^0.33.5"
30
+ },
31
+ "devDependencies": {
32
+ "typescript": "^5.7.3"
19
33
  }
20
34
  }