@iconify/tools 2.0.14 → 2.0.17

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.
Files changed (309) hide show
  1. package/lib/colors/attribs.cjs +30 -0
  2. package/lib/colors/attribs.d.ts +13 -10
  3. package/lib/colors/attribs.mjs +7 -13
  4. package/lib/colors/parse.cjs +269 -0
  5. package/lib/colors/parse.d.ts +15 -11
  6. package/lib/colors/parse.mjs +27 -31
  7. package/lib/colors/validate.cjs +52 -0
  8. package/lib/colors/validate.d.ts +11 -4
  9. package/lib/colors/validate.mjs +19 -6
  10. package/lib/css/parse.cjs +26 -0
  11. package/lib/css/parse.d.ts +3 -1
  12. package/lib/css/parse.mjs +8 -6
  13. package/lib/css/parser/error.cjs +25 -0
  14. package/lib/css/parser/error.d.ts +4 -2
  15. package/lib/css/parser/error.mjs +2 -4
  16. package/lib/css/parser/export.cjs +48 -0
  17. package/lib/css/parser/export.d.ts +5 -2
  18. package/lib/css/parser/export.mjs +4 -6
  19. package/lib/css/parser/strings.cjs +77 -0
  20. package/lib/css/parser/strings.d.ts +6 -3
  21. package/lib/css/parser/strings.mjs +4 -6
  22. package/lib/css/parser/text.cjs +135 -0
  23. package/lib/css/parser/text.d.ts +8 -5
  24. package/lib/css/parser/text.mjs +3 -8
  25. package/lib/css/parser/tokens.cjs +184 -0
  26. package/lib/css/parser/tokens.d.ts +6 -3
  27. package/lib/css/parser/tokens.mjs +7 -13
  28. package/lib/css/parser/tree.cjs +42 -0
  29. package/lib/css/parser/tree.d.ts +5 -2
  30. package/lib/css/parser/tree.mjs +2 -4
  31. package/lib/css/parser/types.cjs +2 -0
  32. package/lib/css/parser/types.d.ts +13 -11
  33. package/lib/css/parser/types.mjs +1 -0
  34. package/lib/download/api/cache.cjs +86 -0
  35. package/lib/download/api/cache.d.ts +8 -5
  36. package/lib/download/api/cache.mjs +14 -19
  37. package/lib/download/api/download.cjs +28 -0
  38. package/lib/download/api/download.d.ts +5 -2
  39. package/lib/download/api/download.mjs +8 -9
  40. package/lib/download/api/index.cjs +51 -0
  41. package/lib/download/api/index.d.ts +5 -2
  42. package/lib/download/api/index.mjs +8 -6
  43. package/lib/download/api/types.cjs +2 -0
  44. package/lib/download/api/types.d.ts +4 -2
  45. package/lib/download/api/types.mjs +1 -0
  46. package/lib/download/git/branch.cjs +22 -0
  47. package/lib/download/git/branch.d.ts +5 -2
  48. package/lib/download/git/branch.mjs +5 -5
  49. package/lib/download/git/hash.cjs +15 -0
  50. package/lib/download/git/hash.d.ts +5 -2
  51. package/lib/download/git/hash.mjs +5 -5
  52. package/lib/download/git/index.cjs +76 -0
  53. package/lib/download/git/index.d.ts +10 -8
  54. package/lib/download/git/index.mjs +41 -26
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +3 -1
  57. package/lib/download/git/reset.mjs +29 -5
  58. package/lib/download/github/hash.cjs +32 -0
  59. package/lib/download/github/hash.d.ts +5 -2
  60. package/lib/download/github/hash.mjs +10 -7
  61. package/lib/download/github/index.cjs +98 -0
  62. package/lib/download/github/index.d.ts +11 -9
  63. package/lib/download/github/index.mjs +23 -17
  64. package/lib/download/github/types.cjs +2 -0
  65. package/lib/download/github/types.d.ts +3 -1
  66. package/lib/download/github/types.mjs +1 -0
  67. package/lib/download/gitlab/hash.cjs +32 -0
  68. package/lib/download/gitlab/hash.d.ts +5 -2
  69. package/lib/download/gitlab/hash.mjs +10 -6
  70. package/lib/download/gitlab/index.cjs +98 -0
  71. package/lib/download/gitlab/index.d.ts +11 -9
  72. package/lib/download/gitlab/index.mjs +24 -18
  73. package/lib/download/gitlab/types.cjs +7 -0
  74. package/lib/download/gitlab/types.d.ts +4 -2
  75. package/lib/download/gitlab/types.mjs +3 -5
  76. package/lib/download/helpers/untar.cjs +14 -0
  77. package/lib/download/helpers/untar.d.ts +3 -1
  78. package/lib/download/helpers/untar.mjs +4 -5
  79. package/lib/download/helpers/unzip.cjs +19 -0
  80. package/lib/download/helpers/unzip.d.ts +3 -1
  81. package/lib/download/helpers/unzip.mjs +6 -7
  82. package/lib/download/index.cjs +64 -0
  83. package/lib/download/index.d.ts +18 -13
  84. package/lib/download/index.mjs +46 -19
  85. package/lib/download/npm/index.cjs +82 -0
  86. package/lib/download/npm/index.d.ts +10 -8
  87. package/lib/download/npm/index.mjs +16 -13
  88. package/lib/download/npm/types.cjs +2 -0
  89. package/lib/download/npm/types.d.ts +3 -1
  90. package/lib/download/npm/types.mjs +1 -0
  91. package/lib/download/npm/version.cjs +23 -0
  92. package/lib/download/npm/version.d.ts +7 -4
  93. package/lib/download/npm/version.mjs +8 -10
  94. package/lib/download/types/modified.cjs +2 -0
  95. package/lib/download/types/modified.d.ts +3 -1
  96. package/lib/download/types/modified.mjs +1 -0
  97. package/lib/download/types/sources.cjs +2 -0
  98. package/lib/download/types/sources.d.ts +4 -2
  99. package/lib/download/types/sources.mjs +1 -0
  100. package/lib/export/directory.cjs +45 -0
  101. package/lib/export/directory.d.ts +11 -4
  102. package/lib/export/directory.mjs +8 -8
  103. package/lib/export/helpers/custom-files.cjs +28 -0
  104. package/lib/export/helpers/custom-files.d.ts +4 -2
  105. package/lib/export/helpers/custom-files.mjs +8 -9
  106. package/lib/export/helpers/prepare.cjs +36 -0
  107. package/lib/export/helpers/prepare.d.ts +5 -3
  108. package/lib/export/helpers/prepare.mjs +7 -9
  109. package/lib/export/helpers/types-version.cjs +22 -0
  110. package/lib/export/helpers/types-version.d.ts +3 -1
  111. package/lib/export/helpers/types-version.mjs +15 -37
  112. package/lib/export/icon-package.cjs +59 -0
  113. package/lib/export/icon-package.d.ts +12 -5
  114. package/lib/export/icon-package.mjs +15 -16
  115. package/lib/export/json-package.cjs +133 -0
  116. package/lib/export/json-package.d.ts +12 -5
  117. package/lib/export/json-package.mjs +20 -21
  118. package/lib/icon-set/index.cjs +588 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +40 -54
  121. package/lib/icon-set/match.cjs +58 -0
  122. package/lib/icon-set/match.d.ts +10 -3
  123. package/lib/icon-set/match.mjs +5 -6
  124. package/lib/icon-set/merge.cjs +83 -0
  125. package/lib/icon-set/merge.d.ts +9 -2
  126. package/lib/icon-set/merge.mjs +15 -10
  127. package/lib/icon-set/props.cjs +28 -0
  128. package/lib/icon-set/props.d.ts +8 -4
  129. package/lib/icon-set/props.mjs +7 -10
  130. package/lib/icon-set/types.cjs +2 -0
  131. package/lib/icon-set/types.d.ts +19 -17
  132. package/lib/icon-set/types.mjs +1 -0
  133. package/lib/import/directory.cjs +76 -0
  134. package/lib/import/directory.d.ts +11 -5
  135. package/lib/import/directory.mjs +36 -11
  136. package/lib/import/figma/index.cjs +105 -0
  137. package/lib/import/figma/index.d.ts +15 -5
  138. package/lib/import/figma/index.mjs +40 -13
  139. package/lib/import/figma/nodes.cjs +86 -0
  140. package/lib/import/figma/nodes.d.ts +13 -4
  141. package/lib/import/figma/nodes.mjs +3 -11
  142. package/lib/import/figma/query.cjs +218 -0
  143. package/lib/import/figma/query.d.ts +18 -9
  144. package/lib/import/figma/query.mjs +9 -12
  145. package/lib/import/figma/types/api.cjs +2 -0
  146. package/lib/import/figma/types/api.d.ts +8 -7
  147. package/lib/import/figma/types/api.mjs +1 -0
  148. package/lib/import/figma/types/nodes.cjs +2 -0
  149. package/lib/import/figma/types/nodes.d.ts +16 -9
  150. package/lib/import/figma/types/nodes.mjs +1 -0
  151. package/lib/import/figma/types/options.cjs +2 -0
  152. package/lib/import/figma/types/options.d.ts +17 -10
  153. package/lib/import/figma/types/options.mjs +1 -0
  154. package/lib/import/figma/types/result.cjs +2 -0
  155. package/lib/import/figma/types/result.d.ts +12 -5
  156. package/lib/import/figma/types/result.mjs +1 -0
  157. package/lib/index.cjs +138 -0
  158. package/lib/index.d.ts +66 -44
  159. package/lib/index.mjs +83 -94
  160. package/lib/misc/bump-version.cjs +17 -0
  161. package/lib/misc/bump-version.d.ts +3 -1
  162. package/lib/misc/bump-version.mjs +2 -4
  163. package/lib/misc/compare-dirs.cjs +75 -0
  164. package/lib/misc/compare-dirs.d.ts +4 -2
  165. package/lib/misc/compare-dirs.mjs +12 -12
  166. package/lib/misc/exec.cjs +25 -0
  167. package/lib/misc/exec.d.ts +6 -4
  168. package/lib/misc/exec.mjs +4 -5
  169. package/lib/misc/keyword.cjs +19 -0
  170. package/lib/misc/keyword.d.ts +3 -1
  171. package/lib/misc/keyword.mjs +2 -4
  172. package/lib/misc/scan.cjs +51 -0
  173. package/lib/misc/scan.d.ts +7 -6
  174. package/lib/misc/scan.mjs +6 -7
  175. package/lib/misc/write-json.cjs +11 -0
  176. package/lib/misc/write-json.d.ts +3 -1
  177. package/lib/misc/write-json.mjs +5 -6
  178. package/lib/optimise/flags.cjs +252 -0
  179. package/lib/optimise/flags.d.ts +7 -2
  180. package/lib/optimise/flags.mjs +18 -19
  181. package/lib/optimise/global-style.cjs +154 -0
  182. package/lib/optimise/global-style.d.ts +7 -2
  183. package/lib/optimise/global-style.mjs +18 -15
  184. package/lib/optimise/scale.cjs +26 -0
  185. package/lib/optimise/scale.d.ts +7 -2
  186. package/lib/optimise/scale.mjs +5 -5
  187. package/lib/optimise/svgo.cjs +85 -0
  188. package/lib/optimise/svgo.d.ts +18 -9
  189. package/lib/optimise/svgo.mjs +61 -61
  190. package/lib/svg/analyse/error.cjs +18 -0
  191. package/lib/svg/analyse/error.d.ts +5 -2
  192. package/lib/svg/analyse/error.mjs +2 -4
  193. package/lib/svg/analyse/types.cjs +2 -0
  194. package/lib/svg/analyse/types.d.ts +11 -11
  195. package/lib/svg/analyse/types.mjs +1 -0
  196. package/lib/svg/analyse.cjs +291 -0
  197. package/lib/svg/analyse.d.ts +8 -3
  198. package/lib/svg/analyse.mjs +15 -30
  199. package/lib/svg/cleanup/attribs.cjs +41 -0
  200. package/lib/svg/cleanup/attribs.d.ts +7 -2
  201. package/lib/svg/cleanup/attribs.mjs +6 -12
  202. package/lib/svg/cleanup/bad-tags.cjs +51 -0
  203. package/lib/svg/cleanup/bad-tags.d.ts +7 -2
  204. package/lib/svg/cleanup/bad-tags.mjs +10 -25
  205. package/lib/svg/cleanup/inline-style.cjs +64 -0
  206. package/lib/svg/cleanup/inline-style.d.ts +7 -2
  207. package/lib/svg/cleanup/inline-style.mjs +14 -19
  208. package/lib/svg/cleanup/root-svg.cjs +81 -0
  209. package/lib/svg/cleanup/root-svg.d.ts +7 -2
  210. package/lib/svg/cleanup/root-svg.mjs +7 -18
  211. package/lib/svg/cleanup/svgo-style.cjs +38 -0
  212. package/lib/svg/cleanup/svgo-style.d.ts +7 -2
  213. package/lib/svg/cleanup/svgo-style.mjs +16 -11
  214. package/lib/svg/cleanup.cjs +32 -0
  215. package/lib/svg/cleanup.d.ts +7 -2
  216. package/lib/svg/cleanup.mjs +21 -9
  217. package/lib/svg/data/attributes.cjs +355 -0
  218. package/lib/svg/data/attributes.d.ts +27 -25
  219. package/lib/svg/data/attributes.mjs +90 -115
  220. package/lib/svg/data/tags.cjs +137 -0
  221. package/lib/svg/data/tags.d.ts +25 -23
  222. package/lib/svg/data/tags.mjs +25 -49
  223. package/lib/svg/index.cjs +130 -0
  224. package/lib/svg/index.d.ts +16 -5
  225. package/lib/svg/index.mjs +48 -14
  226. package/lib/svg/parse-style.cjs +134 -0
  227. package/lib/svg/parse-style.d.ts +12 -8
  228. package/lib/svg/parse-style.mjs +11 -9
  229. package/lib/svg/parse.cjs +42 -0
  230. package/lib/svg/parse.d.ts +11 -7
  231. package/lib/svg/parse.mjs +2 -4
  232. package/package.json +99 -94
  233. package/lib/colors/attribs.js +0 -26
  234. package/lib/colors/parse.js +0 -341
  235. package/lib/colors/validate.js +0 -48
  236. package/lib/css/parse.js +0 -23
  237. package/lib/css/parser/error.js +0 -27
  238. package/lib/css/parser/export.js +0 -69
  239. package/lib/css/parser/strings.js +0 -93
  240. package/lib/css/parser/text.js +0 -171
  241. package/lib/css/parser/tokens.js +0 -200
  242. package/lib/css/parser/tree.js +0 -44
  243. package/lib/css/parser/types.js +0 -2
  244. package/lib/download/api/cache.js +0 -108
  245. package/lib/download/api/download.js +0 -27
  246. package/lib/download/api/index.js +0 -52
  247. package/lib/download/api/types.js +0 -2
  248. package/lib/download/git/branch.js +0 -22
  249. package/lib/download/git/hash.js +0 -14
  250. package/lib/download/git/index.js +0 -75
  251. package/lib/download/git/reset.js +0 -16
  252. package/lib/download/github/hash.js +0 -28
  253. package/lib/download/github/index.js +0 -116
  254. package/lib/download/github/types.js +0 -2
  255. package/lib/download/gitlab/hash.js +0 -27
  256. package/lib/download/gitlab/index.js +0 -115
  257. package/lib/download/gitlab/types.js +0 -7
  258. package/lib/download/helpers/untar.js +0 -14
  259. package/lib/download/helpers/unzip.js +0 -18
  260. package/lib/download/index.js +0 -27
  261. package/lib/download/npm/index.js +0 -91
  262. package/lib/download/npm/types.js +0 -2
  263. package/lib/download/npm/version.js +0 -27
  264. package/lib/download/types/modified.js +0 -2
  265. package/lib/download/types/sources.js +0 -2
  266. package/lib/export/directory.js +0 -52
  267. package/lib/export/helpers/custom-files.js +0 -32
  268. package/lib/export/helpers/prepare.js +0 -49
  269. package/lib/export/helpers/types-version.js +0 -12
  270. package/lib/export/icon-package.js +0 -77
  271. package/lib/export/json-package.js +0 -156
  272. package/lib/icon-set/index.js +0 -749
  273. package/lib/icon-set/match.js +0 -66
  274. package/lib/icon-set/merge.js +0 -90
  275. package/lib/icon-set/props.js +0 -34
  276. package/lib/icon-set/types.js +0 -2
  277. package/lib/import/directory.js +0 -59
  278. package/lib/import/figma/index.js +0 -90
  279. package/lib/import/figma/nodes.js +0 -106
  280. package/lib/import/figma/query.js +0 -244
  281. package/lib/import/figma/types/api.js +0 -12
  282. package/lib/import/figma/types/nodes.js +0 -2
  283. package/lib/import/figma/types/options.js +0 -2
  284. package/lib/import/figma/types/result.js +0 -2
  285. package/lib/index.js +0 -103
  286. package/lib/misc/bump-version.js +0 -19
  287. package/lib/misc/compare-dirs.js +0 -84
  288. package/lib/misc/exec.js +0 -26
  289. package/lib/misc/keyword.js +0 -31
  290. package/lib/misc/scan.js +0 -55
  291. package/lib/misc/write-json.js +0 -11
  292. package/lib/optimise/flags.js +0 -312
  293. package/lib/optimise/global-style.js +0 -185
  294. package/lib/optimise/scale.js +0 -42
  295. package/lib/optimise/svgo.js +0 -99
  296. package/lib/svg/analyse/error.js +0 -22
  297. package/lib/svg/analyse/types.js +0 -2
  298. package/lib/svg/analyse.js +0 -352
  299. package/lib/svg/cleanup/attribs.js +0 -51
  300. package/lib/svg/cleanup/bad-tags.js +0 -65
  301. package/lib/svg/cleanup/inline-style.js +0 -77
  302. package/lib/svg/cleanup/root-svg.js +0 -107
  303. package/lib/svg/cleanup/svgo-style.js +0 -35
  304. package/lib/svg/cleanup.js +0 -24
  305. package/lib/svg/data/attributes.js +0 -403
  306. package/lib/svg/data/tags.js +0 -188
  307. package/lib/svg/index.js +0 -134
  308. package/lib/svg/parse-style.js +0 -151
  309. package/lib/svg/parse.js +0 -49
@@ -1,5 +1,10 @@
1
- import type { SVG } from '../svg';
1
+ import { SVG } from '../svg/index.js';
2
+ import '@iconify/types';
3
+ import '@iconify/utils/lib/customisations';
4
+
2
5
  /**
3
6
  * Scale icon
4
7
  */
5
- export declare function scaleSVG(svg: SVG, scale: number): Promise<void>;
8
+ declare function scaleSVG(svg: SVG, scale: number): Promise<void>;
9
+
10
+ export { scaleSVG };
@@ -1,5 +1,6 @@
1
- // src/optimise/scale.ts
2
- import { runSVGO } from "./svgo.mjs";
1
+ import { runSVGO } from './svgo.mjs';
2
+ import 'svgo';
3
+
3
4
  async function scaleSVG(svg, scale) {
4
5
  const viewBox = svg.viewBox;
5
6
  const width = viewBox.width * scale;
@@ -17,6 +18,5 @@ async function scaleSVG(svg, scale) {
17
18
  ]
18
19
  });
19
20
  }
20
- export {
21
- scaleSVG
22
- };
21
+
22
+ export { scaleSVG };
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const svgo = require('svgo');
6
+
7
+ function getSVGOPlugins(options) {
8
+ return [
9
+ "cleanupAttrs",
10
+ "mergeStyles",
11
+ "inlineStyles",
12
+ "removeComments",
13
+ "removeUselessDefs",
14
+ "removeEditorsNSData",
15
+ "removeEmptyAttrs",
16
+ "removeEmptyContainers",
17
+ "convertStyleToAttrs",
18
+ "convertColors",
19
+ "convertTransform",
20
+ "removeUnknownsAndDefaults",
21
+ "removeNonInheritableGroupAttrs",
22
+ "removeUnusedNS",
23
+ "cleanupNumericValues",
24
+ "cleanupListOfValues",
25
+ "moveElemsAttrsToGroup",
26
+ "moveGroupAttrsToElems",
27
+ "collapseGroups",
28
+ "sortDefsChildren",
29
+ "sortAttrs",
30
+ ...options.animated ? [] : ["removeUselessStrokeAndFill"],
31
+ ...options.animated || options.keepShapes ? [] : [
32
+ "removeHiddenElems",
33
+ "convertShapeToPath",
34
+ "convertEllipseToCircle",
35
+ {
36
+ name: "convertPathData",
37
+ params: {
38
+ noSpaceAfterFlags: true
39
+ }
40
+ },
41
+ {
42
+ name: "mergePaths",
43
+ params: {
44
+ noSpaceAfterFlags: true
45
+ }
46
+ },
47
+ "reusePaths"
48
+ ],
49
+ ...options.cleanupIDs !== false ? [
50
+ {
51
+ name: "cleanupIDs",
52
+ params: {
53
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
54
+ }
55
+ }
56
+ ] : []
57
+ ];
58
+ }
59
+ async function runSVGO(svg, options = {}) {
60
+ const code = svg.toString();
61
+ const multipass = options.multipass !== false;
62
+ let plugins;
63
+ if (options.plugins) {
64
+ plugins = options.plugins;
65
+ } else {
66
+ const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
67
+ plugins = getSVGOPlugins({
68
+ ...options,
69
+ animated
70
+ });
71
+ }
72
+ const pluginOptions = {
73
+ plugins,
74
+ multipass
75
+ };
76
+ const result = svgo.optimize(code, pluginOptions);
77
+ if (typeof result.error === "string") {
78
+ throw new Error(result.error);
79
+ }
80
+ const content = result.data.replace(/<defs\/>/g, "");
81
+ svg.load(content);
82
+ }
83
+
84
+ exports.getSVGOPlugins = getSVGOPlugins;
85
+ exports.runSVGO = runSVGO;
@@ -1,10 +1,19 @@
1
- import type { Plugin } from 'svgo';
2
- import type { SVG } from '../svg';
3
- export declare const defaultSVGOPlugins: Plugin[];
1
+ import { Plugin } from 'svgo';
2
+ import { SVG } from '../svg/index.js';
3
+ import '@iconify/types';
4
+ import '@iconify/utils/lib/customisations';
5
+
6
+ interface CleanupIDsOption {
7
+ cleanupIDs?: string | false;
8
+ }
9
+ interface GetSVGOPluingOptions extends CleanupIDsOption {
10
+ animated?: boolean;
11
+ keepShapes?: boolean;
12
+ }
4
13
  /**
5
- * Plugins that modify shapes. Added to plugins list, unless 'keepShapes' option is enabled
14
+ * Get list of plugins
6
15
  */
7
- export declare const shapeModifiyingSVGOPlugins: Plugin[];
16
+ declare function getSVGOPlugins(options: GetSVGOPluingOptions): Plugin[];
8
17
  /**
9
18
  * Options
10
19
  */
@@ -14,14 +23,14 @@ interface SVGOCommonOptions {
14
23
  interface SVGOOptionsWithPlugin extends SVGOCommonOptions {
15
24
  plugins: Plugin[];
16
25
  }
17
- interface SVGOptionsWithoutPlugin extends SVGOCommonOptions {
26
+ interface SVGOptionsWithoutPlugin extends SVGOCommonOptions, CleanupIDsOption {
18
27
  plugins?: undefined;
19
28
  keepShapes?: boolean;
20
- cleanupIDs?: string | false;
21
29
  }
22
30
  declare type SVGOOptions = SVGOOptionsWithPlugin | SVGOptionsWithoutPlugin;
23
31
  /**
24
32
  * Run SVGO on icon
25
33
  */
26
- export declare function runSVGO(svg: SVG, options?: SVGOOptions): Promise<void>;
27
- export {};
34
+ declare function runSVGO(svg: SVG, options?: SVGOOptions): Promise<void>;
35
+
36
+ export { getSVGOPlugins, runSVGO };
@@ -1,47 +1,57 @@
1
- // src/optimise/svgo.ts
2
- import { optimize } from "svgo";
3
- var defaultSVGOPlugins = [
4
- "cleanupAttrs",
5
- "mergeStyles",
6
- "inlineStyles",
7
- "removeComments",
8
- "removeUselessDefs",
9
- "removeEditorsNSData",
10
- "removeEmptyAttrs",
11
- "removeEmptyContainers",
12
- "convertStyleToAttrs",
13
- "convertColors",
14
- "convertTransform",
15
- "removeUnknownsAndDefaults",
16
- "removeNonInheritableGroupAttrs",
17
- "removeUselessStrokeAndFill",
18
- "removeUnusedNS",
19
- "cleanupNumericValues",
20
- "cleanupListOfValues",
21
- "moveElemsAttrsToGroup",
22
- "moveGroupAttrsToElems",
23
- "collapseGroups",
24
- "sortDefsChildren",
25
- "sortAttrs"
26
- ];
27
- var shapeModifiyingSVGOPlugins = [
28
- "removeHiddenElems",
29
- "convertShapeToPath",
30
- "convertEllipseToCircle",
31
- {
32
- name: "convertPathData",
33
- params: {
34
- noSpaceAfterFlags: true
35
- }
36
- },
37
- {
38
- name: "mergePaths",
39
- params: {
40
- noSpaceAfterFlags: true
41
- }
42
- },
43
- "reusePaths"
44
- ];
1
+ import { optimize } from 'svgo';
2
+
3
+ function getSVGOPlugins(options) {
4
+ return [
5
+ "cleanupAttrs",
6
+ "mergeStyles",
7
+ "inlineStyles",
8
+ "removeComments",
9
+ "removeUselessDefs",
10
+ "removeEditorsNSData",
11
+ "removeEmptyAttrs",
12
+ "removeEmptyContainers",
13
+ "convertStyleToAttrs",
14
+ "convertColors",
15
+ "convertTransform",
16
+ "removeUnknownsAndDefaults",
17
+ "removeNonInheritableGroupAttrs",
18
+ "removeUnusedNS",
19
+ "cleanupNumericValues",
20
+ "cleanupListOfValues",
21
+ "moveElemsAttrsToGroup",
22
+ "moveGroupAttrsToElems",
23
+ "collapseGroups",
24
+ "sortDefsChildren",
25
+ "sortAttrs",
26
+ ...options.animated ? [] : ["removeUselessStrokeAndFill"],
27
+ ...options.animated || options.keepShapes ? [] : [
28
+ "removeHiddenElems",
29
+ "convertShapeToPath",
30
+ "convertEllipseToCircle",
31
+ {
32
+ name: "convertPathData",
33
+ params: {
34
+ noSpaceAfterFlags: true
35
+ }
36
+ },
37
+ {
38
+ name: "mergePaths",
39
+ params: {
40
+ noSpaceAfterFlags: true
41
+ }
42
+ },
43
+ "reusePaths"
44
+ ],
45
+ ...options.cleanupIDs !== false ? [
46
+ {
47
+ name: "cleanupIDs",
48
+ params: {
49
+ prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
50
+ }
51
+ }
52
+ ] : []
53
+ ];
54
+ }
45
55
  async function runSVGO(svg, options = {}) {
46
56
  const code = svg.toString();
47
57
  const multipass = options.multipass !== false;
@@ -49,18 +59,11 @@ async function runSVGO(svg, options = {}) {
49
59
  if (options.plugins) {
50
60
  plugins = options.plugins;
51
61
  } else {
52
- let keepShapes = options.keepShapes;
53
- if (keepShapes === void 0 && (code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1)) {
54
- keepShapes = true;
55
- }
56
- plugins = defaultSVGOPlugins.concat(keepShapes ? [] : shapeModifiyingSVGOPlugins, options.cleanupIDs !== false ? [
57
- {
58
- name: "cleanupIDs",
59
- params: {
60
- prefix: typeof options.cleanupIDs === "string" ? options.cleanupIDs : "svgID"
61
- }
62
- }
63
- ] : []);
62
+ const animated = code.indexOf("<animate") !== -1 || code.indexOf("<set") !== -1;
63
+ plugins = getSVGOPlugins({
64
+ ...options,
65
+ animated
66
+ });
64
67
  }
65
68
  const pluginOptions = {
66
69
  plugins,
@@ -73,8 +76,5 @@ async function runSVGO(svg, options = {}) {
73
76
  const content = result.data.replace(/<defs\/>/g, "");
74
77
  svg.load(content);
75
78
  }
76
- export {
77
- defaultSVGOPlugins,
78
- runSVGO,
79
- shapeModifiyingSVGOPlugins
80
- };
79
+
80
+ export { getSVGOPlugins, runSVGO };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function analyseTagError(element) {
6
+ let result = "<" + element.tagName;
7
+ if (element._id) {
8
+ result += ' id="' + element._id + '"';
9
+ }
10
+ const attribs = element.attribs;
11
+ if (attribs["d"]) {
12
+ const value = attribs["d"];
13
+ result += ' d="' + (value.length > 16 ? value.slice(0, 12) + "..." : value) + '"';
14
+ }
15
+ return result + ">";
16
+ }
17
+
18
+ exports.analyseTagError = analyseTagError;
@@ -1,5 +1,8 @@
1
- import type { ExtendedTagElement } from './types';
1
+ import { ExtendedTagElement } from './types.js';
2
+
2
3
  /**
3
4
  * Get tag for error message
4
5
  */
5
- export declare function analyseTagError(element: ExtendedTagElement): string;
6
+ declare function analyseTagError(element: ExtendedTagElement): string;
7
+
8
+ export { analyseTagError };
@@ -1,4 +1,3 @@
1
- // src/svg/analyse/error.ts
2
1
  function analyseTagError(element) {
3
2
  let result = "<" + element.tagName;
4
3
  if (element._id) {
@@ -11,6 +10,5 @@ function analyseTagError(element) {
11
10
  }
12
11
  return result + ">";
13
12
  }
14
- export {
15
- analyseTagError
16
- };
13
+
14
+ export { analyseTagError };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,8 +1,7 @@
1
- /// <reference types="cheerio" />
2
1
  /**
3
2
  * Options
4
3
  */
5
- export interface AnalyseSVGStructureOptions {
4
+ interface AnalyseSVGStructureOptions {
6
5
  fixErrors?: boolean;
7
6
  }
8
7
  /**
@@ -11,7 +10,7 @@ export interface AnalyseSVGStructureOptions {
11
10
  /**
12
11
  * Link to element
13
12
  */
14
- export interface LinkToElementWithID {
13
+ interface LinkToElementWithID {
15
14
  id: string;
16
15
  usedAsMask: boolean;
17
16
  usedByIndex: number;
@@ -19,7 +18,7 @@ export interface LinkToElementWithID {
19
18
  /**
20
19
  * How element is used by parent elements
21
20
  */
22
- export interface ExtendedTagElementUses {
21
+ interface ExtendedTagElementUses {
23
22
  _usedAsMask: boolean;
24
23
  _usedAsPaint: boolean;
25
24
  }
@@ -36,7 +35,7 @@ interface ReusableElement {
36
35
  *
37
36
  * Similar to ReusableElement, but not necessary a definition - any element with id. Also contains list of child elements
38
37
  */
39
- export interface ElementWithID {
38
+ interface ElementWithID {
40
39
  id: string;
41
40
  isMask: boolean;
42
41
  indexes: Set<number>;
@@ -51,7 +50,7 @@ interface ExtendedTagElementRelations {
51
50
  /**
52
51
  * Extended tag
53
52
  */
54
- export interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagElementUses, ExtendedTagElementRelations {
53
+ interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagElementUses, ExtendedTagElementRelations {
55
54
  _index: number;
56
55
  _id?: string;
57
56
  _belongsTo?: ElementWithID[];
@@ -61,13 +60,13 @@ export interface ExtendedTagElement extends cheerio.TagElement, ExtendedTagEleme
61
60
  /**
62
61
  * Additional stuff for <svg>
63
62
  */
64
- export interface ExtendedRootTagElement extends ExtendedTagElement {
63
+ interface ExtendedRootTagElement extends ExtendedTagElement {
65
64
  _parsed?: boolean;
66
65
  }
67
66
  /**
68
67
  * Tree
69
68
  */
70
- export interface ElementsTreeItem {
69
+ interface ElementsTreeItem {
71
70
  index: number;
72
71
  usedAsMask: boolean;
73
72
  parent?: ElementsTreeItem;
@@ -76,14 +75,15 @@ export interface ElementsTreeItem {
76
75
  /**
77
76
  * Elements map
78
77
  */
79
- export declare type ElementsMap = Map<number, ExtendedTagElement>;
78
+ declare type ElementsMap = Map<number, ExtendedTagElement>;
80
79
  /**
81
80
  * Result
82
81
  */
83
- export interface AnalyseSVGStructureResult {
82
+ interface AnalyseSVGStructureResult {
84
83
  elements: ElementsMap;
85
84
  ids: Record<string, number>;
86
85
  links: LinkToElementWithID[];
87
86
  tree: ElementsTreeItem;
88
87
  }
89
- export {};
88
+
89
+ export { AnalyseSVGStructureOptions, AnalyseSVGStructureResult, ElementWithID, ElementsMap, ElementsTreeItem, ExtendedRootTagElement, ExtendedTagElement, ExtendedTagElementUses, LinkToElementWithID };
@@ -0,0 +1 @@
1
+