@iconify/tools 2.2.5 → 2.2.6

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/lib/index.cjs CHANGED
@@ -33,6 +33,7 @@ const colors_validate = require('./colors/validate.cjs');
33
33
  const colors_detect = require('./colors/detect.cjs');
34
34
  const optimise_svgo = require('./optimise/svgo.cjs');
35
35
  const optimise_flags = require('./optimise/flags.cjs');
36
+ const optimise_origin = require('./optimise/origin.cjs');
36
37
  const optimise_scale = require('./optimise/scale.cjs');
37
38
  const optimise_globalStyle = require('./optimise/global-style.cjs');
38
39
  const export_directory = require('./export/directory.cjs');
@@ -125,6 +126,7 @@ exports.validateColors = colors_validate.validateColors;
125
126
  exports.detectIconSetPalette = colors_detect.detectIconSetPalette;
126
127
  exports.runSVGO = optimise_svgo.runSVGO;
127
128
  exports.deOptimisePaths = optimise_flags.deOptimisePaths;
129
+ exports.resetSVGOrigin = optimise_origin.resetSVGOrigin;
128
130
  exports.scaleSVG = optimise_scale.scaleSVG;
129
131
  exports.cleanupGlobalStyle = optimise_globalStyle.cleanupGlobalStyle;
130
132
  exports.exportToDirectory = export_directory.exportToDirectory;
package/lib/index.d.ts CHANGED
@@ -31,6 +31,7 @@ export { validateColors } from './colors/validate.js';
31
31
  export { detectIconSetPalette } from './colors/detect.js';
32
32
  export { runSVGO } from './optimise/svgo.js';
33
33
  export { deOptimisePaths } from './optimise/flags.js';
34
+ export { resetSVGOrigin } from './optimise/origin.js';
34
35
  export { scaleSVG } from './optimise/scale.js';
35
36
  export { cleanupGlobalStyle } from './optimise/global-style.js';
36
37
  export { exportToDirectory } from './export/directory.js';
package/lib/index.mjs CHANGED
@@ -31,6 +31,7 @@ export { validateColors } from './colors/validate.mjs';
31
31
  export { detectIconSetPalette } from './colors/detect.mjs';
32
32
  export { runSVGO } from './optimise/svgo.mjs';
33
33
  export { deOptimisePaths } from './optimise/flags.mjs';
34
+ export { resetSVGOrigin } from './optimise/origin.mjs';
34
35
  export { scaleSVG } from './optimise/scale.mjs';
35
36
  export { cleanupGlobalStyle } from './optimise/global-style.mjs';
36
37
  export { exportToDirectory } from './export/directory.mjs';
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const optimise_svgo = require('./svgo.cjs');
4
+ require('svgo');
5
+ require('@iconify/utils/lib/svg/id');
6
+
7
+ function resetSVGOrigin(svg) {
8
+ const viewBox = svg.viewBox;
9
+ if (viewBox.left !== 0 || viewBox.top !== 0) {
10
+ const content = `<svg width="${viewBox.width}" height="${viewBox.height}" viewBox="0 0 ${viewBox.width} ${viewBox.height}"><g transform="translate(${0 - viewBox.left} ${0 - viewBox.top})">${svg.getBody()}</g></svg>`;
11
+ svg.load(content);
12
+ optimise_svgo.runSVGO(svg, {
13
+ plugins: [
14
+ "collapseGroups",
15
+ "convertTransform",
16
+ "convertPathData",
17
+ "sortAttrs"
18
+ ]
19
+ });
20
+ }
21
+ }
22
+
23
+ exports.resetSVGOrigin = resetSVGOrigin;
@@ -0,0 +1,10 @@
1
+ import { SVG } from '../svg/index.js';
2
+ import '@iconify/types';
3
+ import '@iconify/utils/lib/customisations/defaults';
4
+
5
+ /**
6
+ * Reset origin to 0 0
7
+ */
8
+ declare function resetSVGOrigin(svg: SVG): void;
9
+
10
+ export { resetSVGOrigin };
@@ -0,0 +1,21 @@
1
+ import { runSVGO } from './svgo.mjs';
2
+ import 'svgo';
3
+ import '@iconify/utils/lib/svg/id';
4
+
5
+ function resetSVGOrigin(svg) {
6
+ const viewBox = svg.viewBox;
7
+ if (viewBox.left !== 0 || viewBox.top !== 0) {
8
+ const content = `<svg width="${viewBox.width}" height="${viewBox.height}" viewBox="0 0 ${viewBox.width} ${viewBox.height}"><g transform="translate(${0 - viewBox.left} ${0 - viewBox.top})">${svg.getBody()}</g></svg>`;
9
+ svg.load(content);
10
+ runSVGO(svg, {
11
+ plugins: [
12
+ "collapseGroups",
13
+ "convertTransform",
14
+ "convertPathData",
15
+ "sortAttrs"
16
+ ]
17
+ });
18
+ }
19
+ }
20
+
21
+ export { resetSVGOrigin };
@@ -1,25 +1,27 @@
1
1
  'use strict';
2
2
 
3
+ const optimise_origin = require('./origin.cjs');
3
4
  const optimise_svgo = require('./svgo.cjs');
4
5
  require('svgo');
5
6
  require('@iconify/utils/lib/svg/id');
6
7
 
7
8
  function scaleSVG(svg, scale) {
8
- const viewBox = svg.viewBox;
9
- const width = viewBox.width * scale;
10
- const height = viewBox.height * scale;
11
- const left = viewBox.left * scale;
12
- const top = viewBox.top * scale;
13
- const content = `<svg width="${width}" height="${height}" viewBox="${left} ${top} ${width} ${height}"><g transform="scale(${scale})">${svg.getBody()}</g></svg>`;
14
- svg.load(content);
15
- optimise_svgo.runSVGO(svg, {
16
- plugins: [
17
- "collapseGroups",
18
- "convertTransform",
19
- "convertPathData",
20
- "sortAttrs"
21
- ]
22
- });
9
+ optimise_origin.resetSVGOrigin(svg);
10
+ if (scale !== 1) {
11
+ const viewBox = svg.viewBox;
12
+ const width = viewBox.width * scale;
13
+ const height = viewBox.height * scale;
14
+ const content = `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"><g transform="scale(${scale})">${svg.getBody()}</g></svg>`;
15
+ svg.load(content);
16
+ optimise_svgo.runSVGO(svg, {
17
+ plugins: [
18
+ "collapseGroups",
19
+ "convertTransform",
20
+ "convertPathData",
21
+ "sortAttrs"
22
+ ]
23
+ });
24
+ }
23
25
  }
24
26
 
25
27
  exports.scaleSVG = scaleSVG;
@@ -1,23 +1,25 @@
1
+ import { resetSVGOrigin } from './origin.mjs';
1
2
  import { runSVGO } from './svgo.mjs';
2
3
  import 'svgo';
3
4
  import '@iconify/utils/lib/svg/id';
4
5
 
5
6
  function scaleSVG(svg, scale) {
6
- const viewBox = svg.viewBox;
7
- const width = viewBox.width * scale;
8
- const height = viewBox.height * scale;
9
- const left = viewBox.left * scale;
10
- const top = viewBox.top * scale;
11
- const content = `<svg width="${width}" height="${height}" viewBox="${left} ${top} ${width} ${height}"><g transform="scale(${scale})">${svg.getBody()}</g></svg>`;
12
- svg.load(content);
13
- runSVGO(svg, {
14
- plugins: [
15
- "collapseGroups",
16
- "convertTransform",
17
- "convertPathData",
18
- "sortAttrs"
19
- ]
20
- });
7
+ resetSVGOrigin(svg);
8
+ if (scale !== 1) {
9
+ const viewBox = svg.viewBox;
10
+ const width = viewBox.width * scale;
11
+ const height = viewBox.height * scale;
12
+ const content = `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"><g transform="scale(${scale})">${svg.getBody()}</g></svg>`;
13
+ svg.load(content);
14
+ runSVGO(svg, {
15
+ plugins: [
16
+ "collapseGroups",
17
+ "convertTransform",
18
+ "convertPathData",
19
+ "sortAttrs"
20
+ ]
21
+ });
22
+ }
21
23
  }
22
24
 
23
25
  export { scaleSVG };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "description": "Collection of functions for cleaning up and parsing SVG for Iconify project",
5
5
  "author": "Vjacheslav Trushkin",
6
- "version": "2.2.5",
6
+ "version": "2.2.6",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/iconify/tools/issues",
9
9
  "homepage": "https://github.com/iconify/tools",
@@ -16,35 +16,35 @@
16
16
  "types": "./lib/index.d.ts",
17
17
  "dependencies": {
18
18
  "@iconify/types": "^2.0.0",
19
- "@iconify/utils": "^2.1.0",
19
+ "@iconify/utils": "^2.1.4",
20
20
  "@types/cheerio": "^0.22.31",
21
21
  "@types/node-fetch": "^2.6.2",
22
- "@types/tar": "^6.1.3",
22
+ "@types/tar": "^6.1.4",
23
23
  "cheerio": "^1.0.0-rc.12",
24
24
  "extract-zip": "^2.0.1",
25
- "local-pkg": "^0.4.2",
26
- "node-fetch": "^2.6.8",
27
- "pathe": "^1.0.0",
25
+ "local-pkg": "^0.4.3",
26
+ "node-fetch": "^2.6.9",
27
+ "pathe": "^1.1.0",
28
28
  "svgo": "^3.0.2",
29
29
  "tar": "^6.1.13"
30
30
  },
31
31
  "devDependencies": {
32
- "@types/jest": "^29.2.5",
33
- "@types/node": "^18.11.18",
34
- "@typescript-eslint/eslint-plugin": "^5.48.1",
35
- "@typescript-eslint/parser": "^5.48.1",
32
+ "@types/jest": "^29.4.0",
33
+ "@types/node": "^18.14.0",
34
+ "@typescript-eslint/eslint-plugin": "^5.52.0",
35
+ "@typescript-eslint/parser": "^5.52.0",
36
36
  "cross-env": "^7.0.3",
37
- "eslint": "^8.32.0",
37
+ "eslint": "^8.34.0",
38
38
  "eslint-config-prettier": "^8.6.0",
39
39
  "eslint-plugin-jasmine": "^4.1.3",
40
40
  "eslint-plugin-prettier": "^4.2.1",
41
41
  "jasmine": "^4.5.0",
42
- "jest": "^29.3.1",
43
- "prettier": "^2.8.3",
42
+ "jest": "^29.4.3",
43
+ "prettier": "^2.8.4",
44
44
  "rimraf": "^3.0.2",
45
45
  "ts-jest": "^29.0.5",
46
- "typescript": "^4.9.4",
47
- "unbuild": "^1.1.1"
46
+ "typescript": "^4.9.5",
47
+ "unbuild": "^1.1.2"
48
48
  },
49
49
  "exports": {
50
50
  "./*": "./*",
@@ -423,6 +423,11 @@
423
423
  "import": "./lib/optimise/global-style.mjs",
424
424
  "types": "./lib/optimise/global-style.d.ts"
425
425
  },
426
+ "./lib/optimise/origin": {
427
+ "require": "./lib/optimise/origin.cjs",
428
+ "import": "./lib/optimise/origin.mjs",
429
+ "types": "./lib/optimise/origin.d.ts"
430
+ },
426
431
  "./lib/optimise/scale": {
427
432
  "require": "./lib/optimise/scale.cjs",
428
433
  "import": "./lib/optimise/scale.mjs",