svg-toolbox 1.1.9 → 1.1.10
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 +24 -20
- package/es/{applyDiffSvg.d.ts → extra-apply/applyDiffSvg.d.ts} +2 -2
- package/es/{applyDiffSvg.js → extra-apply/applyDiffSvg.js} +21 -27
- package/es/extra-apply/applyDiffSvg.js.map +1 -0
- package/es/extra-apply/applyRemoveNanCoordinates.js.map +1 -0
- package/es/{applySvg2Png.d.ts → extra-apply/applySvg2Png.d.ts} +3 -3
- package/es/extra-apply/applySvg2Png.js +64 -0
- package/es/extra-apply/applySvg2Png.js.map +1 -0
- package/es/index.d.ts +5 -4
- package/es/index.js +5 -4
- package/es/index.js.map +1 -1
- package/es/utils/pixelLevelDiffPng.d.ts +4 -0
- package/es/utils/pixelLevelDiffPng.js +29 -0
- package/es/utils/pixelLevelDiffPng.js.map +1 -0
- package/lib/{applyDiffSvg.d.ts → extra-apply/applyDiffSvg.d.ts} +2 -2
- package/lib/{applyDiffSvg.js → extra-apply/applyDiffSvg.js} +27 -28
- package/lib/extra-apply/applyDiffSvg.js.map +1 -0
- package/lib/extra-apply/applyRemoveNanCoordinates.js.map +1 -0
- package/lib/{applySvg2Png.d.ts → extra-apply/applySvg2Png.d.ts} +3 -3
- package/lib/extra-apply/applySvg2Png.js +111 -0
- package/lib/extra-apply/applySvg2Png.js.map +1 -0
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -4
- package/lib/index.js.map +1 -1
- package/lib/utils/pixelLevelDiffPng.d.ts +4 -0
- package/lib/utils/pixelLevelDiffPng.js +36 -0
- package/lib/utils/pixelLevelDiffPng.js.map +1 -0
- package/package.json +1 -1
- package/es/applyDiffSvg.js.map +0 -1
- package/es/applyRemoveNanCoordinates.js.map +0 -1
- package/es/applySvg2Png.js +0 -43
- package/es/applySvg2Png.js.map +0 -1
- package/lib/applyDiffSvg.js.map +0 -1
- package/lib/applyRemoveNanCoordinates.js.map +0 -1
- package/lib/applySvg2Png.js +0 -50
- package/lib/applySvg2Png.js.map +0 -1
- /package/es/{applyRemoveNanCoordinates.d.ts → extra-apply/applyRemoveNanCoordinates.d.ts} +0 -0
- /package/es/{applyRemoveNanCoordinates.js → extra-apply/applyRemoveNanCoordinates.js} +0 -0
- /package/lib/{applyRemoveNanCoordinates.d.ts → extra-apply/applyRemoveNanCoordinates.d.ts} +0 -0
- /package/lib/{applyRemoveNanCoordinates.js → extra-apply/applyRemoveNanCoordinates.js} +0 -0
package/README.md
CHANGED
|
@@ -28,8 +28,8 @@ npm install svg-toolbox
|
|
|
28
28
|
- [convertSVGToBase64](#convertsvgtobase64)
|
|
29
29
|
- [convertBase64ToSVG](#convertbase64tosvg)
|
|
30
30
|
- [diffSvg](#diffsvg)
|
|
31
|
-
- [removeNanCoordinates](#removenancoordinates)
|
|
32
31
|
- [svg2png](#svg2png)
|
|
32
|
+
- [removeNanCoordinates](#removenancoordinates)
|
|
33
33
|
- [License](#license)
|
|
34
34
|
|
|
35
35
|
## Usage
|
|
@@ -133,31 +133,18 @@ const pathA = 'path/to/first/image.png';
|
|
|
133
133
|
const pathB = 'path/to/second/image.png';
|
|
134
134
|
const diffFilePath = 'path/to/save/diff/image.png';
|
|
135
135
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.error('Error generating diff image:', error);
|
|
142
|
-
});
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
### removeNanCoordinates
|
|
146
|
-
Parses and normalizes the d attribute of all path elements in an SVG content.
|
|
147
|
-
|
|
148
|
-
```typescript
|
|
149
|
-
import { removeNanCoordinates } from 'svg-toolbox';
|
|
150
|
-
|
|
151
|
-
const svgContent = `<svg><path d="M 10,20 nan L 30,40 -nan Z" /></svg>`;
|
|
152
|
-
const normalizedSvgContent = removeNanCoordinates(svgContent);
|
|
153
|
-
console.log(normalizedSvgContent);
|
|
154
|
-
|
|
136
|
+
// diffPngBuffer is a Buffer object containing the diff image in PNG format.
|
|
137
|
+
// numDiffPixels is the number of different pixels between the two images.
|
|
138
|
+
const { diffPngBuffer, numDiffPixels } = await diffSvg(pathA, pathB, diffFilePath)
|
|
139
|
+
const diffPngBase64 = `data:image/png;base64,${diffPngBuffer.toString('base64')}`;
|
|
140
|
+
console.log(`Number of different pixels: ${numDiffPixels}`);
|
|
155
141
|
```
|
|
156
142
|
|
|
157
143
|
### svg2png
|
|
158
144
|
Converts an SVG file to PNG format.
|
|
159
145
|
|
|
160
146
|
```typescript
|
|
147
|
+
// Callback/Promise
|
|
161
148
|
import { svg2Png } from 'svg-toolbox';
|
|
162
149
|
|
|
163
150
|
const svgPath = 'path/to/input/image.svg';
|
|
@@ -165,6 +152,23 @@ const pngPath = 'path/to/output/image.png';
|
|
|
165
152
|
const scale = 2; // Scaling factor
|
|
166
153
|
|
|
167
154
|
svg2Png(svgPath, pngPath, scale);
|
|
155
|
+
|
|
156
|
+
// Async/await
|
|
157
|
+
const pngBuffer = await svg2Png(svgPath, scale);
|
|
158
|
+
const pngBase64 = `data:image/png;base64,${pngBuffer.toString('base64')}`;
|
|
159
|
+
console.log(pngBase64);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### removeNanCoordinates
|
|
163
|
+
Parses and normalizes the d attribute of all path elements in an SVG content.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import { removeNanCoordinates } from 'svg-toolbox';
|
|
167
|
+
|
|
168
|
+
const svgContent = `<svg><path d="M 10,20 nan L 30,40 -nan Z" /></svg>`;
|
|
169
|
+
const normalizedSvgContent = removeNanCoordinates(svgContent);
|
|
170
|
+
console.log(normalizedSvgContent);
|
|
171
|
+
|
|
168
172
|
```
|
|
169
173
|
|
|
170
174
|
## License
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compares two SVG files and generates a diff image.
|
|
3
|
-
* @param {string} pathA - The path
|
|
4
|
-
* @param {string} pathB - The path
|
|
3
|
+
* @param {string} pathA - The path to the first SVG file.
|
|
4
|
+
* @param {string} pathB - The path to the second SVG file.
|
|
5
5
|
* @param {string} diffFilePath - The path to save the diff image.
|
|
6
6
|
* @returns - The diff image buffer and the number of different pixels.
|
|
7
7
|
*/
|
|
@@ -10,10 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import fs from 'fs';
|
|
12
12
|
import sharp from 'sharp';
|
|
13
|
-
import pngjs from 'pngjs';
|
|
14
13
|
import path from 'path';
|
|
15
|
-
import
|
|
16
|
-
const PNG = pngjs.PNG;
|
|
14
|
+
import pixelLevelDiffSvg from '../utils/pixelLevelDiffPng';
|
|
17
15
|
/**
|
|
18
16
|
* Checks if the filename has a valid suffix.
|
|
19
17
|
* @param {string} filename - The name of the file.
|
|
@@ -24,40 +22,36 @@ function validSuffix(filename) {
|
|
|
24
22
|
}
|
|
25
23
|
/**
|
|
26
24
|
* Compares two SVG files and generates a diff image.
|
|
27
|
-
* @param {string} pathA - The path
|
|
28
|
-
* @param {string} pathB - The path
|
|
25
|
+
* @param {string} pathA - The path to the first SVG file.
|
|
26
|
+
* @param {string} pathB - The path to the second SVG file.
|
|
29
27
|
* @param {string} diffFilePath - The path to save the diff image.
|
|
30
28
|
* @returns - The diff image buffer and the number of different pixels.
|
|
31
29
|
*/
|
|
32
30
|
export default async function (pathA, pathB, diffFilePath) {
|
|
33
|
-
|
|
34
|
-
const pngA = await sharp(pathA).toBuffer();
|
|
35
|
-
const pngB = await sharp(pathB).toBuffer();
|
|
36
|
-
// Decode the PNG buffers
|
|
37
|
-
const img1 = PNG.sync.read(pngA);
|
|
38
|
-
const img2 = PNG.sync.read(pngB);
|
|
39
|
-
const { width, height } = img1;
|
|
40
|
-
// Create a new PNG object for the diff image
|
|
41
|
-
const diff = new PNG({ width, height });
|
|
42
|
-
// Compare the images and get the number of different pixels
|
|
43
|
-
const numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 });
|
|
44
|
-
// Write the diff image to a buffer
|
|
45
|
-
const diffPngBuffer = PNG.sync.write(diff);
|
|
31
|
+
let diffFileName = '';
|
|
46
32
|
// If a diff file path is provided, save the diff image
|
|
47
33
|
if (diffFilePath) {
|
|
48
|
-
|
|
34
|
+
diffFileName = path.basename(diffFilePath);
|
|
49
35
|
if (!validSuffix(diffFileName)) {
|
|
50
36
|
console.error(`Error converting ${diffFileName} to PNG: No suffix found.`);
|
|
51
37
|
return;
|
|
52
38
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.error('Error converting to PNG: No diff file path provided.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
// Read the PNG files as buffers
|
|
45
|
+
const pngA = await sharp(pathA).toBuffer();
|
|
46
|
+
const pngB = await sharp(pathB).toBuffer();
|
|
47
|
+
const { diffPngBuffer, numDiffPixels } = pixelLevelDiffSvg(pngA, pngB, 0.1);
|
|
48
|
+
fs.writeFileSync(diffFilePath, diffPngBuffer);
|
|
49
|
+
// Log the result
|
|
50
|
+
if (numDiffPixels === 0) {
|
|
51
|
+
console.log(`\x1b[32mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
console.log(`\x1b[33mFile name: ${diffFileName} Number of different pixels: ${numDiffPixels}\x1b[0m`);
|
|
61
55
|
}
|
|
62
56
|
return {
|
|
63
57
|
// The diff image buffer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyDiffSvg.js","sourceRoot":"","sources":["../../src/extra-apply/applyDiffSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM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C;IAED,OAAO;QACL,wBAAwB;QACxB,aAAa;QACb,iCAAiC;QACjC,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyRemoveNanCoordinates.js","sourceRoot":"","sources":["../../src/extra-apply/applyRemoveNanCoordinates.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,gEAAgE;AAChE,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAE/B;;;;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,mCAAmC;IACnC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC;IACrC,sBAAsB;IACtB,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAEjD,oCAAoC;IACpC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,iCAAiC;IACjC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACjC,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB;QAC1D,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QACD,uDAAuD;QACvD,MAAM,QAAQ,GAAG,CAAC;YAChB,iCAAiC;aAChC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;YAC1B,wG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CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,iCAAiC;IACtE,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,MAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Converts an SVG file to PNG format.
|
|
11
11
|
* @param {string} svgPath - The path to read the SVG file.
|
|
12
|
-
* @param {string} pngPath - The path to save the PNG file.
|
|
12
|
+
* @param {string} pngPath - The path to save the PNG file. if not provided, return the buffer.
|
|
13
13
|
* @param {number} x - The scaling factor for the PNG image.
|
|
14
|
-
* @returns
|
|
14
|
+
* @returns {Promise<void | Buffer<ArrayBufferLike>>} - The PNG image buffer.
|
|
15
15
|
*/
|
|
16
|
-
export default function (svgPath: string, pngPath
|
|
16
|
+
export default function (svgPath: string, pngPath?: string, x?: number): Promise<void | Buffer<ArrayBufferLike>>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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 fs from 'fs';
|
|
10
|
+
import sharp from 'sharp';
|
|
11
|
+
/**
|
|
12
|
+
* Converts an SVG file to PNG format.
|
|
13
|
+
* @param {string} svgPath - The path to read the SVG file.
|
|
14
|
+
* @param {string} pngPath - The path to save the PNG file. if not provided, return the buffer.
|
|
15
|
+
* @param {number} x - The scaling factor for the PNG image.
|
|
16
|
+
* @returns {Promise<void | Buffer<ArrayBufferLike>>} - The PNG image buffer.
|
|
17
|
+
*/
|
|
18
|
+
export default async function (svgPath, pngPath, x) {
|
|
19
|
+
if (!svgPath) {
|
|
20
|
+
console.error('Error converting to PNG: No svg file path provided.');
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (!pngPath) {
|
|
24
|
+
console.log(`\x1b[33mNo png file path provided, return the buffer.\x1b[0m`);
|
|
25
|
+
}
|
|
26
|
+
if (!x) {
|
|
27
|
+
x = 2;
|
|
28
|
+
console.log(`\x1b[33mNo scaling factor provided, use the default value 2.\x1b[0m`);
|
|
29
|
+
}
|
|
30
|
+
// Read the SVG file
|
|
31
|
+
const file = svgPath.split('/').pop();
|
|
32
|
+
const svgContent = fs.readFileSync(svgPath, 'utf8');
|
|
33
|
+
// Extract the viewBox from the SVG content
|
|
34
|
+
const viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
|
|
35
|
+
const viewBoxMatch = viewBoxRegex.exec(svgContent);
|
|
36
|
+
if (!viewBoxMatch) {
|
|
37
|
+
console.error(`Error converting ${file} to PNG: No viewBox found.`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Extract the width and height from the viewBox
|
|
41
|
+
const [, , , baseWidth, baseHeight] = viewBoxMatch.map(Number);
|
|
42
|
+
if (pngPath) {
|
|
43
|
+
// Resize the SVG to the desired dimensions and convert it to PNG
|
|
44
|
+
sharp(svgPath)
|
|
45
|
+
.resize(x * baseWidth, x * baseHeight)
|
|
46
|
+
.png()
|
|
47
|
+
.toFile(pngPath)
|
|
48
|
+
.then(() => {
|
|
49
|
+
console.log(`\x1b[32mConverted ${file} to PNG successfully.\x1b[0m`);
|
|
50
|
+
})
|
|
51
|
+
.catch(error => {
|
|
52
|
+
console.error(`Error converting ${file} to PNG:`, error);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Resize the SVG to the desired dimensions and convert it to PNG
|
|
57
|
+
const buffer = await sharp(svgPath)
|
|
58
|
+
.resize(x * baseWidth, x * baseHeight)
|
|
59
|
+
.png()
|
|
60
|
+
.toBuffer();
|
|
61
|
+
return buffer;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=applySvg2Png.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../../src/extra-apply/applySvg2Png.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,WAAW,OAAe,EAAE,OAAgB,EAAE,CAAU;IAC1E,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QACrE,OAAO;IACT,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,8DAA8D,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,CAAC,CAAC,EAAE,CAAC;QACP,CAAC,GAAG,CAAC,CAAA;QACL,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAC;IACrF,CAAC;IACD,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,IAAI,OAAO,EAAE,CAAC;QACZ,iEAAiE;QACjE,KAAK,CAAC,OAAO,CAAC;aACX,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;aACrC,GAAG,EAAE;aACL,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,EAAE;YACT,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,8BAA8B,CAAC,CAAC;QACvE,CAAC,CAAC;aACD,KAAK,CAAC,KAAK,CAAC,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,oBAAoB,IAAI,UAAU,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACN,iEAAiE;QACjE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC;aAChC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;aACrC,GAAG,EAAE;aACL,QAAQ,EAAE,CAAA;QACb,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC"}
|
package/es/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import svg2Png from './applySvg2Png';
|
|
2
|
-
import diffSvg from './applyDiffSvg';
|
|
3
|
-
import removeNanCoordinates from './applyRemoveNanCoordinates';
|
|
1
|
+
import svg2Png from './extra-apply/applySvg2Png';
|
|
2
|
+
import diffSvg from './extra-apply/applyDiffSvg';
|
|
3
|
+
import removeNanCoordinates from './extra-apply/applyRemoveNanCoordinates';
|
|
4
4
|
import { createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG } from './common';
|
|
5
|
+
import pixelLevelDiffPng from './utils/pixelLevelDiffPng';
|
|
5
6
|
declare const removeEmptyCoordinates: typeof removeNanCoordinates;
|
|
6
7
|
export { svg2Png, diffSvg,
|
|
7
8
|
/**
|
|
8
9
|
* @deprecated
|
|
9
10
|
* @see removeNanCoordinates
|
|
10
11
|
*/
|
|
11
|
-
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG };
|
|
12
|
+
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG, pixelLevelDiffPng };
|
package/es/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import svg2Png from './applySvg2Png';
|
|
2
|
-
import diffSvg from './applyDiffSvg';
|
|
3
|
-
import removeNanCoordinates from './applyRemoveNanCoordinates';
|
|
1
|
+
import svg2Png from './extra-apply/applySvg2Png';
|
|
2
|
+
import diffSvg from './extra-apply/applyDiffSvg';
|
|
3
|
+
import removeNanCoordinates from './extra-apply/applyRemoveNanCoordinates';
|
|
4
4
|
import { createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG } from './common';
|
|
5
|
+
import pixelLevelDiffPng from './utils/pixelLevelDiffPng';
|
|
5
6
|
const removeEmptyCoordinates = removeNanCoordinates;
|
|
6
7
|
export { svg2Png, diffSvg,
|
|
7
8
|
/**
|
|
8
9
|
* @deprecated
|
|
9
10
|
* @see removeNanCoordinates
|
|
10
11
|
*/
|
|
11
|
-
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG };
|
|
12
|
+
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG, pixelLevelDiffPng };
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,oBAAoB,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AACtH,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAE1D,MAAM,sBAAsB,GAAG,oBAAoB,CAAA;AAEnD,OAAO,EACL,OAAO,EACP,OAAO;AACP;;;GAGG;AACH,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAC3F,iBAAiB,EAClB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file pixelLevelDiffSvg.ts
|
|
3
|
+
* @description This module provides a function to compare two SVG files and generate a diff image.
|
|
4
|
+
* @module applyDiffSvg
|
|
5
|
+
* @requires pixelmatch - Image comparison library
|
|
6
|
+
* @requires pngjs - PNG image processing library
|
|
7
|
+
* @author pipi
|
|
8
|
+
*/
|
|
9
|
+
import { PNG } from "pngjs";
|
|
10
|
+
import pixelmatch from 'pixelmatch';
|
|
11
|
+
export default function (pngA, pngB, threshold = 0.1) {
|
|
12
|
+
// Decode the PNG buffers
|
|
13
|
+
const img1 = PNG.sync.read(pngA);
|
|
14
|
+
const img2 = PNG.sync.read(pngB);
|
|
15
|
+
const { width, height } = img1;
|
|
16
|
+
// Create a new PNG object for the diff image
|
|
17
|
+
const diff = new PNG({ width, height });
|
|
18
|
+
// Compare the images and get the number of different pixels
|
|
19
|
+
const numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, width, height, { threshold });
|
|
20
|
+
// Write the diff image to a buffer
|
|
21
|
+
const diffPngBuffer = PNG.sync.write(diff);
|
|
22
|
+
return {
|
|
23
|
+
// The diff image buffer
|
|
24
|
+
diffPngBuffer,
|
|
25
|
+
// The number of different pixels
|
|
26
|
+
numDiffPixels
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pixelLevelDiffPng.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixelLevelDiffPng.js","sourceRoot":"","sources":["../../src/utils/pixelLevelDiffPng.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,OAAO,WAAW,IAA6B,EAAE,IAA6B,EAAE,YAAoB,GAAG;IAC5G,yBAAyB;IACzB,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAE/B,6CAA6C;IAC7C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IAExC,4DAA4D;IAC5D,MAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAEhG,mCAAmC;IACnC,MAAM,aAAa,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE3C,OAAO;QACL,wBAAwB;QACxB,aAAa;QACb,iCAAiC;QACjC,aAAa;KACd,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Compares two SVG files and generates a diff image.
|
|
3
|
-
* @param {string} pathA - The path
|
|
4
|
-
* @param {string} pathB - The path
|
|
3
|
+
* @param {string} pathA - The path to the first SVG file.
|
|
4
|
+
* @param {string} pathB - The path to the second SVG file.
|
|
5
5
|
* @param {string} diffFilePath - The path to save the diff image.
|
|
6
6
|
* @returns - The diff image buffer and the number of different pixels.
|
|
7
7
|
*/
|
|
@@ -52,10 +52,8 @@ exports.default = default_1;
|
|
|
52
52
|
*/
|
|
53
53
|
var fs_1 = __importDefault(require("fs"));
|
|
54
54
|
var sharp_1 = __importDefault(require("sharp"));
|
|
55
|
-
var pngjs_1 = __importDefault(require("pngjs"));
|
|
56
55
|
var path_1 = __importDefault(require("path"));
|
|
57
|
-
var
|
|
58
|
-
var PNG = pngjs_1.default.PNG;
|
|
56
|
+
var pixelLevelDiffPng_1 = __importDefault(require("../utils/pixelLevelDiffPng"));
|
|
59
57
|
/**
|
|
60
58
|
* Checks if the filename has a valid suffix.
|
|
61
59
|
* @param {string} filename - The name of the file.
|
|
@@ -66,28 +64,18 @@ function validSuffix(filename) {
|
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
66
|
* Compares two SVG files and generates a diff image.
|
|
69
|
-
* @param {string} pathA - The path
|
|
70
|
-
* @param {string} pathB - The path
|
|
67
|
+
* @param {string} pathA - The path to the first SVG file.
|
|
68
|
+
* @param {string} pathB - The path to the second SVG file.
|
|
71
69
|
* @param {string} diffFilePath - The path to save the diff image.
|
|
72
70
|
* @returns - The diff image buffer and the number of different pixels.
|
|
73
71
|
*/
|
|
74
72
|
function default_1(pathA, pathB, diffFilePath) {
|
|
75
73
|
return __awaiter(this, void 0, void 0, function () {
|
|
76
|
-
var pngA, pngB,
|
|
77
|
-
return __generator(this, function (
|
|
78
|
-
switch (
|
|
79
|
-
case 0:
|
|
80
|
-
|
|
81
|
-
pngA = _a.sent();
|
|
82
|
-
return [4 /*yield*/, (0, sharp_1.default)(pathB).toBuffer()];
|
|
83
|
-
case 2:
|
|
84
|
-
pngB = _a.sent();
|
|
85
|
-
img1 = PNG.sync.read(pngA);
|
|
86
|
-
img2 = PNG.sync.read(pngB);
|
|
87
|
-
width = img1.width, height = img1.height;
|
|
88
|
-
diff = new PNG({ width: width, height: height });
|
|
89
|
-
numDiffPixels = (0, pixelmatch_1.default)(img1.data, img2.data, diff.data, width, height, { threshold: 0.1 });
|
|
90
|
-
diffPngBuffer = PNG.sync.write(diff);
|
|
74
|
+
var diffFileName, pngA, pngB, _a, diffPngBuffer, numDiffPixels;
|
|
75
|
+
return __generator(this, function (_b) {
|
|
76
|
+
switch (_b.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
diffFileName = '';
|
|
91
79
|
// If a diff file path is provided, save the diff image
|
|
92
80
|
if (diffFilePath) {
|
|
93
81
|
diffFileName = path_1.default.basename(diffFilePath);
|
|
@@ -95,14 +83,25 @@ function default_1(pathA, pathB, diffFilePath) {
|
|
|
95
83
|
console.error("Error converting ".concat(diffFileName, " to PNG: No suffix found."));
|
|
96
84
|
return [2 /*return*/];
|
|
97
85
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
console.error('Error converting to PNG: No diff file path provided.');
|
|
89
|
+
return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
return [4 /*yield*/, (0, sharp_1.default)(pathA).toBuffer()];
|
|
92
|
+
case 1:
|
|
93
|
+
pngA = _b.sent();
|
|
94
|
+
return [4 /*yield*/, (0, sharp_1.default)(pathB).toBuffer()];
|
|
95
|
+
case 2:
|
|
96
|
+
pngB = _b.sent();
|
|
97
|
+
_a = (0, pixelLevelDiffPng_1.default)(pngA, pngB, 0.1), diffPngBuffer = _a.diffPngBuffer, numDiffPixels = _a.numDiffPixels;
|
|
98
|
+
fs_1.default.writeFileSync(diffFilePath, diffPngBuffer);
|
|
99
|
+
// Log the result
|
|
100
|
+
if (numDiffPixels === 0) {
|
|
101
|
+
console.log("\u001B[32mFile name: ".concat(diffFileName, " Number of different pixels: ").concat(numDiffPixels, "\u001B[0m"));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.log("\u001B[33mFile name: ".concat(diffFileName, " Number of different pixels: ").concat(numDiffPixels, "\u001B[0m"));
|
|
106
105
|
}
|
|
107
106
|
return [2 /*return*/, {
|
|
108
107
|
// The diff image buffer
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyDiffSvg.js","sourceRoot":"","sources":["../../src/extra-apply/applyDiffSvg.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,4BAgCC;AA/DD;;;;;;;;;GASG;AACH,0CAAoB;AACpB,gDAA0B;AAC1B,8CAAwB;AACxB,iFAA2D;AAE3D;;;;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;;;;;;oBAC3E,YAAY,GAAG,EAAE,CAAC;oBACtB,uDAAuD;oBACvD,IAAI,YAAY,EAAE,CAAC;wBACjB,YAAY,GAAG,cAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;wBAC3C,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;4BAC/B,OAAO,CAAC,KAAK,CAAC,2BAAoB,YAAY,8BAA2B,CAAC,CAAC;4BAC3E,sBAAO;wBACT,CAAC;oBACH,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;wBACtE,sBAAO;oBACT,CAAC;oBAEY,qBAAM,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAA;;oBAApC,IAAI,GAAG,SAA6B;oBAC7B,qBAAM,IAAA,eAAK,EAA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A,IAAI,KAAK,KAAK,CAAC,EAAf,CAAe,CAAC;YAClC,wGAAwG;YACxG,4EAA4E;aAC3E,MAAM,CAAC,UAAC,OAAO,IAAK,OAAA,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAjE,CAAiE,CAAC,CAAC;QAC1F,gCAAgC;QAChC,IAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAC,OAAO;YACrC,OAAO,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,iCAAiC;IACtE,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,IAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
/**
|
|
10
10
|
* Converts an SVG file to PNG format.
|
|
11
11
|
* @param {string} svgPath - The path to read the SVG file.
|
|
12
|
-
* @param {string} pngPath - The path to save the PNG file.
|
|
12
|
+
* @param {string} pngPath - The path to save the PNG file. if not provided, return the buffer.
|
|
13
13
|
* @param {number} x - The scaling factor for the PNG image.
|
|
14
|
-
* @returns
|
|
14
|
+
* @returns {Promise<void | Buffer<ArrayBufferLike>>} - The PNG image buffer.
|
|
15
15
|
*/
|
|
16
|
-
export default function (svgPath: string, pngPath
|
|
16
|
+
export default function (svgPath: string, pngPath?: string, x?: number): Promise<void | Buffer<ArrayBufferLike>>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file applySvg2Png.js
|
|
4
|
+
* @description This module provides a function to convert SVG files to PNG format using the sharp library.
|
|
5
|
+
* @module applySvg2Png
|
|
6
|
+
* @requires sharp - Image processing library
|
|
7
|
+
* @requires fs - File system module
|
|
8
|
+
* @author pipi
|
|
9
|
+
*/
|
|
10
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
20
|
+
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);
|
|
21
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
22
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
23
|
+
function step(op) {
|
|
24
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
25
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
26
|
+
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;
|
|
27
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
28
|
+
switch (op[0]) {
|
|
29
|
+
case 0: case 1: t = op; break;
|
|
30
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
31
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
32
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
33
|
+
default:
|
|
34
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
35
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
36
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
37
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
38
|
+
if (t[2]) _.ops.pop();
|
|
39
|
+
_.trys.pop(); continue;
|
|
40
|
+
}
|
|
41
|
+
op = body.call(thisArg, _);
|
|
42
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
43
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
47
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.default = default_1;
|
|
51
|
+
var fs_1 = __importDefault(require("fs"));
|
|
52
|
+
var sharp_1 = __importDefault(require("sharp"));
|
|
53
|
+
/**
|
|
54
|
+
* Converts an SVG file to PNG format.
|
|
55
|
+
* @param {string} svgPath - The path to read the SVG file.
|
|
56
|
+
* @param {string} pngPath - The path to save the PNG file. if not provided, return the buffer.
|
|
57
|
+
* @param {number} x - The scaling factor for the PNG image.
|
|
58
|
+
* @returns {Promise<void | Buffer<ArrayBufferLike>>} - The PNG image buffer.
|
|
59
|
+
*/
|
|
60
|
+
function default_1(svgPath, pngPath, x) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var file, svgContent, viewBoxRegex, viewBoxMatch, _a, baseWidth, baseHeight, buffer;
|
|
63
|
+
return __generator(this, function (_b) {
|
|
64
|
+
switch (_b.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!svgPath) {
|
|
67
|
+
console.error('Error converting to PNG: No svg file path provided.');
|
|
68
|
+
return [2 /*return*/];
|
|
69
|
+
}
|
|
70
|
+
if (!pngPath) {
|
|
71
|
+
console.log("\u001B[33mNo png file path provided, return the buffer.\u001B[0m");
|
|
72
|
+
}
|
|
73
|
+
if (!x) {
|
|
74
|
+
x = 2;
|
|
75
|
+
console.log("\u001B[33mNo scaling factor provided, use the default value 2.\u001B[0m");
|
|
76
|
+
}
|
|
77
|
+
file = svgPath.split('/').pop();
|
|
78
|
+
svgContent = fs_1.default.readFileSync(svgPath, 'utf8');
|
|
79
|
+
viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
|
|
80
|
+
viewBoxMatch = viewBoxRegex.exec(svgContent);
|
|
81
|
+
if (!viewBoxMatch) {
|
|
82
|
+
console.error("Error converting ".concat(file, " to PNG: No viewBox found."));
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
_a = viewBoxMatch.map(Number), baseWidth = _a[3], baseHeight = _a[4];
|
|
86
|
+
if (!pngPath) return [3 /*break*/, 1];
|
|
87
|
+
// Resize the SVG to the desired dimensions and convert it to PNG
|
|
88
|
+
(0, sharp_1.default)(svgPath)
|
|
89
|
+
.resize(x * baseWidth, x * baseHeight)
|
|
90
|
+
.png()
|
|
91
|
+
.toFile(pngPath)
|
|
92
|
+
.then(function () {
|
|
93
|
+
console.log("\u001B[32mConverted ".concat(file, " to PNG successfully.\u001B[0m"));
|
|
94
|
+
})
|
|
95
|
+
.catch(function (error) {
|
|
96
|
+
console.error("Error converting ".concat(file, " to PNG:"), error);
|
|
97
|
+
});
|
|
98
|
+
return [3 /*break*/, 3];
|
|
99
|
+
case 1: return [4 /*yield*/, (0, sharp_1.default)(svgPath)
|
|
100
|
+
.resize(x * baseWidth, x * baseHeight)
|
|
101
|
+
.png()
|
|
102
|
+
.toBuffer()];
|
|
103
|
+
case 2:
|
|
104
|
+
buffer = _b.sent();
|
|
105
|
+
return [2 /*return*/, buffer];
|
|
106
|
+
case 3: return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=applySvg2Png.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../../src/extra-apply/applySvg2Png.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYH,4BAgDC;AA1DD,0CAAoB;AACpB,gDAA0B;AAE1B;;;;;;GAMG;AACH,mBAA+B,OAAe,EAAE,OAAgB,EAAE,CAAU;;;;;;oBAC1E,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;wBACrE,sBAAO;oBACT,CAAC;oBACD,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,CAAC,GAAG,CAAC,kEAA8D,CAAC,CAAC;oBAC9E,CAAC;oBACD,IAAI,CAAC,CAAC,EAAE,CAAC;wBACP,CAAC,GAAG,CAAC,CAAA;wBACL,OAAO,CAAC,GAAG,CAAC,yEAAqE,CAAC,CAAC;oBACrF,CAAC;oBAEK,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;oBAChC,UAAU,GAAG,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAG9C,YAAY,GAAG,mCAAmC,CAAC;oBACnD,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAEnD,IAAI,CAAC,YAAY,EAAE,CAAC;wBAClB,OAAO,CAAC,KAAK,CAAC,2BAAoB,IAAI,+BAA4B,CAAC,CAAC;wBACpE,sBAAO;oBACT,CAAC;oBAGK,KAAgC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAjD,SAAS,QAAA,EAAE,UAAU,QAAA,CAA6B;yBAE3D,OAAO,EAAP,wBAAO;oBACT,iEAAiE;oBACjE,IAAA,eAAK,EAAC,OAAO,CAAC;yBACX,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;yBACrC,GAAG,EAAE;yBACL,MAAM,CAAC,OAAO,CAAC;yBACf,IAAI,CAAC;wBACJ,OAAO,CAAC,GAAG,CAAC,8BAAqB,IAAI,mCAA8B,CAAC,CAAC;oBACvE,CAAC,CAAC;yBACD,KAAK,CAAC,UAAA,KAAK;wBACV,OAAO,CAAC,KAAK,CAAC,2BAAoB,IAAI,aAAU,EAAE,KAAK,CAAC,CAAC;oBAC3D,CAAC,CAAC,CAAC;;wBAGU,qBAAM,IAAA,eAAK,EAAC,OAAO,CAAC;yBAChC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,GAAG,UAAU,CAAC;yBACrC,GAAG,EAAE;yBACL,QAAQ,EAAE,EAAA;;oBAHP,MAAM,GAAG,SAGF;oBACb,sBAAO,MAAM,EAAC;;;;;CAEjB"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import svg2Png from './applySvg2Png';
|
|
2
|
-
import diffSvg from './applyDiffSvg';
|
|
3
|
-
import removeNanCoordinates from './applyRemoveNanCoordinates';
|
|
1
|
+
import svg2Png from './extra-apply/applySvg2Png';
|
|
2
|
+
import diffSvg from './extra-apply/applyDiffSvg';
|
|
3
|
+
import removeNanCoordinates from './extra-apply/applyRemoveNanCoordinates';
|
|
4
4
|
import { createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG } from './common';
|
|
5
|
+
import pixelLevelDiffPng from './utils/pixelLevelDiffPng';
|
|
5
6
|
declare const removeEmptyCoordinates: typeof removeNanCoordinates;
|
|
6
7
|
export { svg2Png, diffSvg,
|
|
7
8
|
/**
|
|
8
9
|
* @deprecated
|
|
9
10
|
* @see removeNanCoordinates
|
|
10
11
|
*/
|
|
11
|
-
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG };
|
|
12
|
+
removeEmptyCoordinates, removeNanCoordinates, createSVGElement, cloneSVGElement, mergeSVGElements, convertSVGToBase64, convertBase64ToSVG, pixelLevelDiffPng };
|
package/lib/index.js
CHANGED
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.convertBase64ToSVG = exports.convertSVGToBase64 = exports.mergeSVGElements = exports.cloneSVGElement = exports.createSVGElement = exports.removeNanCoordinates = exports.removeEmptyCoordinates = exports.diffSvg = exports.svg2Png = void 0;
|
|
7
|
-
var applySvg2Png_1 = __importDefault(require("./applySvg2Png"));
|
|
6
|
+
exports.pixelLevelDiffPng = exports.convertBase64ToSVG = exports.convertSVGToBase64 = exports.mergeSVGElements = exports.cloneSVGElement = exports.createSVGElement = exports.removeNanCoordinates = exports.removeEmptyCoordinates = exports.diffSvg = exports.svg2Png = void 0;
|
|
7
|
+
var applySvg2Png_1 = __importDefault(require("./extra-apply/applySvg2Png"));
|
|
8
8
|
exports.svg2Png = applySvg2Png_1.default;
|
|
9
|
-
var applyDiffSvg_1 = __importDefault(require("./applyDiffSvg"));
|
|
9
|
+
var applyDiffSvg_1 = __importDefault(require("./extra-apply/applyDiffSvg"));
|
|
10
10
|
exports.diffSvg = applyDiffSvg_1.default;
|
|
11
|
-
var applyRemoveNanCoordinates_1 = __importDefault(require("./applyRemoveNanCoordinates"));
|
|
11
|
+
var applyRemoveNanCoordinates_1 = __importDefault(require("./extra-apply/applyRemoveNanCoordinates"));
|
|
12
12
|
exports.removeNanCoordinates = applyRemoveNanCoordinates_1.default;
|
|
13
13
|
var common_1 = require("./common");
|
|
14
14
|
Object.defineProperty(exports, "createSVGElement", { enumerable: true, get: function () { return common_1.createSVGElement; } });
|
|
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "cloneSVGElement", { enumerable: true, get: funct
|
|
|
16
16
|
Object.defineProperty(exports, "mergeSVGElements", { enumerable: true, get: function () { return common_1.mergeSVGElements; } });
|
|
17
17
|
Object.defineProperty(exports, "convertSVGToBase64", { enumerable: true, get: function () { return common_1.convertSVGToBase64; } });
|
|
18
18
|
Object.defineProperty(exports, "convertBase64ToSVG", { enumerable: true, get: function () { return common_1.convertBase64ToSVG; } });
|
|
19
|
+
var pixelLevelDiffPng_1 = __importDefault(require("./utils/pixelLevelDiffPng"));
|
|
20
|
+
exports.pixelLevelDiffPng = pixelLevelDiffPng_1.default;
|
|
19
21
|
var removeEmptyCoordinates = applyRemoveNanCoordinates_1.default;
|
|
20
22
|
exports.removeEmptyCoordinates = removeEmptyCoordinates;
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,4EAAiD;AAS/C,kBATK,sBAAO,CASL;AART,4EAAiD;AAS/C,kBATK,sBAAO,CASL;AART,sGAA2E;AAczE,+BAdK,mCAAoB,CAcL;AAbtB,mCAAsH;AAcpH,iGAdO,yBAAgB,OAcP;AAAE,gGAdO,wBAAe,OAcP;AAAE,iGAdO,yBAAgB,OAcP;AAAE,mGAdO,2BAAkB,OAcP;AAAE,mGAdO,2BAAkB,OAcP;AAb7F,gFAA0D;AAcxD,4BAdK,2BAAiB,CAcL;AAZnB,IAAM,sBAAsB,GAAG,mCAAoB,CAAA;AASjD,wDAAsB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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.default = default_1;
|
|
7
|
+
/**
|
|
8
|
+
* @file pixelLevelDiffSvg.ts
|
|
9
|
+
* @description This module provides a function to compare two SVG files and generate a diff image.
|
|
10
|
+
* @module applyDiffSvg
|
|
11
|
+
* @requires pixelmatch - Image comparison library
|
|
12
|
+
* @requires pngjs - PNG image processing library
|
|
13
|
+
* @author pipi
|
|
14
|
+
*/
|
|
15
|
+
var pngjs_1 = require("pngjs");
|
|
16
|
+
var pixelmatch_1 = __importDefault(require("pixelmatch"));
|
|
17
|
+
function default_1(pngA, pngB, threshold) {
|
|
18
|
+
if (threshold === void 0) { threshold = 0.1; }
|
|
19
|
+
// Decode the PNG buffers
|
|
20
|
+
var img1 = pngjs_1.PNG.sync.read(pngA);
|
|
21
|
+
var img2 = pngjs_1.PNG.sync.read(pngB);
|
|
22
|
+
var width = img1.width, height = img1.height;
|
|
23
|
+
// Create a new PNG object for the diff image
|
|
24
|
+
var diff = new pngjs_1.PNG({ width: width, height: height });
|
|
25
|
+
// Compare the images and get the number of different pixels
|
|
26
|
+
var numDiffPixels = (0, pixelmatch_1.default)(img1.data, img2.data, diff.data, width, height, { threshold: threshold });
|
|
27
|
+
// Write the diff image to a buffer
|
|
28
|
+
var diffPngBuffer = pngjs_1.PNG.sync.write(diff);
|
|
29
|
+
return {
|
|
30
|
+
// The diff image buffer
|
|
31
|
+
diffPngBuffer: diffPngBuffer,
|
|
32
|
+
// The number of different pixels
|
|
33
|
+
numDiffPixels: numDiffPixels
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=pixelLevelDiffPng.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pixelLevelDiffPng.js","sourceRoot":"","sources":["../../src/utils/pixelLevelDiffPng.ts"],"names":[],"mappings":";;;;;AAWA,4BAqBC;AAhCD;;;;;;;GAOG;AACH,+BAA4B;AAC5B,0DAAoC;AAEpC,mBAAyB,IAA6B,EAAE,IAA6B,EAAE,SAAuB;IAAvB,0BAAA,EAAA,eAAuB;IAC5G,yBAAyB;IACzB,IAAM,IAAI,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAM,IAAI,GAAG,WAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,IAAA,KAAK,GAAa,IAAI,MAAjB,EAAE,MAAM,GAAK,IAAI,OAAT,CAAU;IAE/B,6CAA6C;IAC7C,IAAM,IAAI,GAAG,IAAI,WAAG,CAAC,EAAE,KAAK,OAAA,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IAExC,4DAA4D;IAC5D,IAAM,aAAa,GAAG,IAAA,oBAAU,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,WAAA,EAAE,CAAC,CAAC;IAEhG,mCAAmC;IACnC,IAAM,aAAa,GAAG,WAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAE3C,OAAO;QACL,wBAAwB;QACxB,aAAa,eAAA;QACb,iCAAiC;QACjC,aAAa,eAAA;KACd,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
package/es/applyDiffSvg.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applyDiffSvg.js","sourceRoot":"","sources":["../src/applyDiffSvg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,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AAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;YAClC,wGAAwG;YACxG,4EAA4E;aAC3E,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1F,gCAAgC;QAChC,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YACzC,OAAO,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,iCAAiC;IACtE,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,MAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/es/applySvg2Png.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
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 fs from 'fs';
|
|
10
|
-
import sharp from 'sharp';
|
|
11
|
-
/**
|
|
12
|
-
* Converts an SVG file to PNG format.
|
|
13
|
-
* @param {string} svgPath - The path to read the SVG file.
|
|
14
|
-
* @param {string} pngPath - The path to save the PNG file.
|
|
15
|
-
* @param {number} x - The scaling factor for the PNG image.
|
|
16
|
-
* @returns
|
|
17
|
-
*/
|
|
18
|
-
export default function (svgPath, pngPath, x = 2) {
|
|
19
|
-
// Read the SVG file
|
|
20
|
-
const file = svgPath.split('/').pop();
|
|
21
|
-
const svgContent = fs.readFileSync(svgPath, 'utf8');
|
|
22
|
-
// Extract the viewBox from the SVG content
|
|
23
|
-
const viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
|
|
24
|
-
const viewBoxMatch = viewBoxRegex.exec(svgContent);
|
|
25
|
-
if (!viewBoxMatch) {
|
|
26
|
-
console.error(`Error converting ${file} to PNG: No viewBox found.`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
// Extract the width and height from the viewBox
|
|
30
|
-
const [, , , baseWidth, baseHeight] = viewBoxMatch.map(Number);
|
|
31
|
-
// Resize the SVG to the desired dimensions and convert it to PNG
|
|
32
|
-
sharp(svgPath)
|
|
33
|
-
.resize(x * baseWidth, x * baseHeight)
|
|
34
|
-
.png()
|
|
35
|
-
.toFile(pngPath)
|
|
36
|
-
.then(() => {
|
|
37
|
-
console.log(`\x1b[32mConverted ${file} to PNG successfully.\x1b[0m`);
|
|
38
|
-
})
|
|
39
|
-
.catch(error => {
|
|
40
|
-
console.error(`Error converting ${file} to PNG:`, error);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=applySvg2Png.js.map
|
package/es/applySvg2Png.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../src/applySvg2Png.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;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,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E,CAAiE,CAAC,CAAC;QAC1F,gCAAgC;QAChC,IAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,UAAC,OAAO;YACrC,OAAO,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACZ,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,iCAAiC;IACtE,CAAC,CAAC,CAAC;IAEH,0BAA0B;IAC1B,IAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
package/lib/applySvg2Png.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @file applySvg2Png.js
|
|
4
|
-
* @description This module provides a function to convert SVG files to PNG format using the sharp library.
|
|
5
|
-
* @module applySvg2Png
|
|
6
|
-
* @requires sharp - Image processing library
|
|
7
|
-
* @requires fs - File system module
|
|
8
|
-
* @author pipi
|
|
9
|
-
*/
|
|
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 fs_1 = __importDefault(require("fs"));
|
|
16
|
-
var sharp_1 = __importDefault(require("sharp"));
|
|
17
|
-
/**
|
|
18
|
-
* Converts an SVG file to PNG format.
|
|
19
|
-
* @param {string} svgPath - The path to read the SVG file.
|
|
20
|
-
* @param {string} pngPath - The path to save the PNG file.
|
|
21
|
-
* @param {number} x - The scaling factor for the PNG image.
|
|
22
|
-
* @returns
|
|
23
|
-
*/
|
|
24
|
-
function default_1(svgPath, pngPath, x) {
|
|
25
|
-
if (x === void 0) { x = 2; }
|
|
26
|
-
// Read the SVG file
|
|
27
|
-
var file = svgPath.split('/').pop();
|
|
28
|
-
var svgContent = fs_1.default.readFileSync(svgPath, 'utf8');
|
|
29
|
-
// Extract the viewBox from the SVG content
|
|
30
|
-
var viewBoxRegex = /viewBox="(\d+) (\d+) (\d+) (\d+)"/;
|
|
31
|
-
var viewBoxMatch = viewBoxRegex.exec(svgContent);
|
|
32
|
-
if (!viewBoxMatch) {
|
|
33
|
-
console.error("Error converting ".concat(file, " to PNG: No viewBox found."));
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// Extract the width and height from the viewBox
|
|
37
|
-
var _a = viewBoxMatch.map(Number), baseWidth = _a[3], baseHeight = _a[4];
|
|
38
|
-
// Resize the SVG to the desired dimensions and convert it to PNG
|
|
39
|
-
(0, sharp_1.default)(svgPath)
|
|
40
|
-
.resize(x * baseWidth, x * baseHeight)
|
|
41
|
-
.png()
|
|
42
|
-
.toFile(pngPath)
|
|
43
|
-
.then(function () {
|
|
44
|
-
console.log("\u001B[32mConverted ".concat(file, " to PNG successfully.\u001B[0m"));
|
|
45
|
-
})
|
|
46
|
-
.catch(function (error) {
|
|
47
|
-
console.error("Error converting ".concat(file, " to PNG:"), error);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=applySvg2Png.js.map
|
package/lib/applySvg2Png.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"applySvg2Png.js","sourceRoot":"","sources":["../src/applySvg2Png.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;AAYH,4BA4BC;AAtCD,0CAAoB;AACpB,gDAA0B;AAE1B;;;;;;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"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|