@iconify/tools 2.0.12 → 2.0.15

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 (308) 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 +42 -20
  55. package/lib/download/git/reset.cjs +41 -0
  56. package/lib/download/git/reset.d.ts +6 -0
  57. package/lib/download/git/reset.mjs +37 -0
  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 +24 -22
  118. package/lib/icon-set/index.cjs +589 -0
  119. package/lib/icon-set/index.d.ts +9 -6
  120. package/lib/icon-set/index.mjs +47 -57
  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 +9 -12
  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 +6 -16
  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 +137 -0
  158. package/lib/index.d.ts +65 -43
  159. package/lib/index.mjs +83 -92
  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 +68 -47
  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 +83 -0
  188. package/lib/optimise/svgo.d.ts +10 -6
  189. package/lib/optimise/svgo.mjs +6 -9
  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 -11
  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 +102 -93
  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 -63
  251. package/lib/download/github/hash.js +0 -28
  252. package/lib/download/github/index.js +0 -116
  253. package/lib/download/github/types.js +0 -2
  254. package/lib/download/gitlab/hash.js +0 -27
  255. package/lib/download/gitlab/index.js +0 -115
  256. package/lib/download/gitlab/types.js +0 -7
  257. package/lib/download/helpers/untar.js +0 -14
  258. package/lib/download/helpers/unzip.js +0 -18
  259. package/lib/download/index.js +0 -27
  260. package/lib/download/npm/index.js +0 -91
  261. package/lib/download/npm/types.js +0 -2
  262. package/lib/download/npm/version.js +0 -27
  263. package/lib/download/types/modified.js +0 -2
  264. package/lib/download/types/sources.js +0 -2
  265. package/lib/export/directory.js +0 -52
  266. package/lib/export/helpers/custom-files.js +0 -32
  267. package/lib/export/helpers/prepare.js +0 -49
  268. package/lib/export/helpers/types-version.js +0 -12
  269. package/lib/export/icon-package.js +0 -77
  270. package/lib/export/json-package.js +0 -151
  271. package/lib/icon-set/index.js +0 -746
  272. package/lib/icon-set/match.js +0 -66
  273. package/lib/icon-set/merge.js +0 -90
  274. package/lib/icon-set/props.js +0 -33
  275. package/lib/icon-set/types.js +0 -2
  276. package/lib/import/directory.js +0 -59
  277. package/lib/import/figma/index.js +0 -90
  278. package/lib/import/figma/nodes.js +0 -108
  279. package/lib/import/figma/query.js +0 -244
  280. package/lib/import/figma/types/api.js +0 -12
  281. package/lib/import/figma/types/nodes.js +0 -2
  282. package/lib/import/figma/types/options.js +0 -2
  283. package/lib/import/figma/types/result.js +0 -2
  284. package/lib/index.js +0 -101
  285. package/lib/misc/bump-version.js +0 -19
  286. package/lib/misc/compare-dirs.js +0 -84
  287. package/lib/misc/exec.js +0 -26
  288. package/lib/misc/keyword.js +0 -31
  289. package/lib/misc/scan.js +0 -55
  290. package/lib/misc/write-json.js +0 -11
  291. package/lib/optimise/flags.js +0 -312
  292. package/lib/optimise/global-style.js +0 -158
  293. package/lib/optimise/scale.js +0 -42
  294. package/lib/optimise/svgo.js +0 -99
  295. package/lib/svg/analyse/error.js +0 -22
  296. package/lib/svg/analyse/types.js +0 -2
  297. package/lib/svg/analyse.js +0 -352
  298. package/lib/svg/cleanup/attribs.js +0 -51
  299. package/lib/svg/cleanup/bad-tags.js +0 -65
  300. package/lib/svg/cleanup/inline-style.js +0 -77
  301. package/lib/svg/cleanup/root-svg.js +0 -107
  302. package/lib/svg/cleanup/svgo-style.js +0 -35
  303. package/lib/svg/cleanup.js +0 -24
  304. package/lib/svg/data/attributes.js +0 -403
  305. package/lib/svg/data/tags.js +0 -188
  306. package/lib/svg/index.js +0 -125
  307. package/lib/svg/parse-style.js +0 -151
  308. package/lib/svg/parse.js +0 -49
@@ -1,158 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanupGlobalStyle = void 0;
4
- require("../svg/data/attributes");
5
- const tags_1 = require("../svg/data/tags");
6
- const parse_1 = require("../svg/parse");
7
- const parse_style_1 = require("../svg/parse-style");
8
- function getClassList(value) {
9
- return value === null || value === void 0 ? void 0 : value.split(/\s+/);
10
- }
11
- const tempDataAttrbiute = 'data-gstyle-temp';
12
- /**
13
- * Expand global style
14
- */
15
- async function cleanupGlobalStyle(svg) {
16
- const backup = svg.toString();
17
- let containsTempAttr = false;
18
- // Find all animated classes
19
- const animatedClasses = new Set();
20
- await (0, parse_1.parseSVG)(svg, (item) => {
21
- if (!tags_1.animateTags.has(item.tagName)) {
22
- return;
23
- }
24
- const $element = item.$element;
25
- if ($element.attr('attributeName') !== 'class') {
26
- return;
27
- }
28
- ['from', 'to', 'values'].forEach((attr) => {
29
- const value = $element.attr(attr);
30
- if (typeof value !== 'string') {
31
- return;
32
- }
33
- value.split(';').forEach((item) => {
34
- getClassList(item).forEach((className) => {
35
- animatedClasses.add(className);
36
- });
37
- });
38
- });
39
- });
40
- // Parse style
41
- try {
42
- await (0, parse_style_1.parseSVGStyle)(svg, async (styleItem) => {
43
- var _a;
44
- const returnValue = styleItem.value;
45
- if (styleItem.type !== 'global') {
46
- return returnValue;
47
- }
48
- // Handle only simple selectors
49
- if (styleItem.selectors.length !== 1 ||
50
- styleItem.selectorTokens.length !== 1) {
51
- return returnValue;
52
- }
53
- // Do not handle media queries
54
- const selectorToken = styleItem.selectorTokens[0];
55
- if (selectorToken.type !== 'selector') {
56
- return returnValue;
57
- }
58
- // Simple selector and simple rule
59
- const selector = styleItem.selectors[0];
60
- const firstChar = selector.charAt(0);
61
- let matchType;
62
- if (firstChar === '.') {
63
- matchType = 'class';
64
- }
65
- else if (firstChar === '#') {
66
- matchType = 'id';
67
- }
68
- else if (tags_1.allValidTags.has(selector)) {
69
- matchType = 'tag';
70
- }
71
- else {
72
- return returnValue;
73
- }
74
- const valueMatch = matchType === 'tag' ? selector : selector.slice(1);
75
- if (matchType === 'class' && animatedClasses.has(valueMatch)) {
76
- // Class name is used in animations
77
- return returnValue;
78
- }
79
- // Check if element is a match
80
- const isMatch = (tagName, $element) => {
81
- switch (matchType) {
82
- case 'id':
83
- return $element.attr('id') === valueMatch;
84
- case 'tag':
85
- return tagName === valueMatch;
86
- case 'class': {
87
- const className = $element.attr('class');
88
- if (!className ||
89
- getClassList(className).indexOf(valueMatch) === -1) {
90
- return false;
91
- }
92
- }
93
- }
94
- return true;
95
- };
96
- // Parse all elements
97
- await (0, parse_1.parseSVG)(svg, (svgItem) => {
98
- var _a;
99
- const tagName = svgItem.tagName;
100
- const $element = svgItem.$element;
101
- if (!isMatch(tagName, $element)) {
102
- return;
103
- }
104
- // Transfer attribute
105
- const addedAttributes = new Set((_a = $element.attr(tempDataAttrbiute)) === null || _a === void 0 ? void 0 : _a.split(/\s+/));
106
- const prop = styleItem.prop;
107
- if ($element.attr(prop) !== void 0) {
108
- // Previously added attribute?
109
- if (addedAttributes.has(prop)) {
110
- // Two CSS rules are applied to same element: abort parsing and restore content from backup.
111
- // This parse is very basic, it does not account for specificity.
112
- throw new Error('Duplicate attribute');
113
- }
114
- }
115
- $element.attr(prop, styleItem.value);
116
- addedAttributes.add(prop);
117
- $element.attr(tempDataAttrbiute, Array.from(addedAttributes).join(' '));
118
- containsTempAttr = true;
119
- });
120
- // Remove class attribute
121
- if (matchType === 'class' &&
122
- ((_a = styleItem.nextTokens[0]) === null || _a === void 0 ? void 0 : _a.type) === 'close') {
123
- // Can remove class
124
- await (0, parse_1.parseSVG)(svg, (svgItem) => {
125
- const $element = svgItem.$element;
126
- if (!isMatch('', $element)) {
127
- return;
128
- }
129
- // Remove class
130
- const classList = getClassList($element.attr('class'));
131
- if (!classList) {
132
- return;
133
- }
134
- const filtered = classList.filter((item) => item !== valueMatch);
135
- if (!filtered.length) {
136
- $element.removeAttr('class');
137
- }
138
- else {
139
- $element.attr('class', filtered.join(' '));
140
- }
141
- });
142
- }
143
- // Remove rule
144
- return;
145
- });
146
- // Remove temporary attributes
147
- if (containsTempAttr) {
148
- await (0, parse_1.parseSVG)(svg, (item) => {
149
- item.$element.removeAttr(tempDataAttrbiute);
150
- });
151
- }
152
- }
153
- catch (err) {
154
- // Failed: restore from backup
155
- svg.load(backup);
156
- }
157
- }
158
- exports.cleanupGlobalStyle = cleanupGlobalStyle;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.scaleSVG = void 0;
4
- const svgo_1 = require("./svgo");
5
- /**
6
- * Scale icon
7
- */
8
- async function scaleSVG(svg, scale) {
9
- const viewBox = svg.viewBox;
10
- const width = viewBox.width * scale;
11
- const height = viewBox.height * scale;
12
- const left = viewBox.left * scale;
13
- const top = viewBox.top * scale;
14
- const content = '<svg width="' +
15
- width +
16
- '" height="' +
17
- height +
18
- '" viewBox="' +
19
- left +
20
- ' ' +
21
- top +
22
- ' ' +
23
- width +
24
- ' ' +
25
- height +
26
- '">' +
27
- '<g transform="scale(' +
28
- scale +
29
- ')">' +
30
- svg.getBody() +
31
- '</g></svg>';
32
- svg.load(content);
33
- await (0, svgo_1.runSVGO)(svg, {
34
- plugins: [
35
- 'collapseGroups',
36
- 'convertTransform',
37
- 'convertPathData',
38
- 'sortAttrs',
39
- ],
40
- });
41
- }
42
- exports.scaleSVG = scaleSVG;
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runSVGO = exports.shapeModifiyingSVGOPlugins = exports.defaultSVGOPlugins = void 0;
4
- const svgo_1 = require("svgo");
5
- exports.defaultSVGOPlugins = [
6
- 'cleanupAttrs',
7
- 'mergeStyles',
8
- 'inlineStyles',
9
- 'removeComments',
10
- 'removeUselessDefs',
11
- 'removeEditorsNSData',
12
- 'removeEmptyAttrs',
13
- 'removeEmptyContainers',
14
- 'convertStyleToAttrs',
15
- 'convertColors',
16
- 'convertTransform',
17
- 'removeUnknownsAndDefaults',
18
- 'removeNonInheritableGroupAttrs',
19
- 'removeUselessStrokeAndFill',
20
- 'removeUnusedNS',
21
- 'cleanupNumericValues',
22
- 'cleanupListOfValues',
23
- 'moveElemsAttrsToGroup',
24
- 'moveGroupAttrsToElems',
25
- 'collapseGroups',
26
- 'sortDefsChildren',
27
- 'sortAttrs',
28
- ];
29
- /**
30
- * Plugins that modify shapes. Added to plugins list, unless 'keepShapes' option is enabled
31
- */
32
- exports.shapeModifiyingSVGOPlugins = [
33
- 'removeHiddenElems',
34
- 'convertShapeToPath',
35
- 'convertEllipseToCircle',
36
- {
37
- name: 'convertPathData',
38
- params: {
39
- noSpaceAfterFlags: true,
40
- },
41
- },
42
- {
43
- name: 'mergePaths',
44
- params: {
45
- noSpaceAfterFlags: true,
46
- },
47
- },
48
- // 'removeOffCanvasPaths', // bugged for some icons
49
- 'reusePaths',
50
- ];
51
- /**
52
- * Run SVGO on icon
53
- */
54
- async function runSVGO(svg, options = {}) {
55
- // Code
56
- const code = svg.toString();
57
- // Options
58
- const multipass = options.multipass !== false;
59
- // Plugins list
60
- let plugins;
61
- if (options.plugins) {
62
- plugins = options.plugins;
63
- }
64
- else {
65
- // Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
66
- let keepShapes = options.keepShapes;
67
- if (keepShapes === void 0 &&
68
- (code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1)) {
69
- // Do not check animations: just assume they might break
70
- keepShapes = true;
71
- }
72
- plugins = exports.defaultSVGOPlugins.concat(keepShapes ? [] : exports.shapeModifiyingSVGOPlugins, options.cleanupIDs !== false
73
- ? [
74
- {
75
- name: 'cleanupIDs',
76
- params: {
77
- prefix: typeof options.cleanupIDs === 'string'
78
- ? options.cleanupIDs
79
- : 'svgID',
80
- },
81
- },
82
- ]
83
- : []);
84
- }
85
- // Run SVGO
86
- const pluginOptions = {
87
- plugins,
88
- multipass,
89
- };
90
- // Load data (changing type because SVGO types do not include error ?????)
91
- const result = (0, svgo_1.optimize)(code, pluginOptions);
92
- if (typeof result.error === 'string') {
93
- throw new Error(result.error);
94
- }
95
- // Sometimes empty definitions are not removed: remove them
96
- const content = result.data.replace(/<defs\/>/g, '');
97
- svg.load(content);
98
- }
99
- exports.runSVGO = runSVGO;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyseTagError = void 0;
4
- /**
5
- * Get tag for error message
6
- */
7
- function analyseTagError(element) {
8
- let result = '<' + element.tagName;
9
- if (element._id) {
10
- result += ' id="' + element._id + '"';
11
- }
12
- const attribs = element.attribs;
13
- if (attribs['d']) {
14
- const value = attribs['d'];
15
- result +=
16
- ' d="' +
17
- (value.length > 16 ? value.slice(0, 12) + '...' : value) +
18
- '"';
19
- }
20
- return result + '>';
21
- }
22
- exports.analyseTagError = analyseTagError;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,352 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyseSVGStructure = void 0;
4
- const parse_1 = require("./parse");
5
- const attributes_1 = require("./data/attributes");
6
- const tags_1 = require("./data/tags");
7
- const error_1 = require("./analyse/error");
8
- /**
9
- * Find all IDs, links, which elements use palette, which items aren't used
10
- *
11
- * Before running this function run cleanup functions to change inline style to attributes and fix attributes
12
- */
13
- async function analyseSVGStructure(svg, options = {}) {
14
- // Options
15
- const fixErrors = options.fixErrors;
16
- // Root element
17
- let root = svg.$svg(':root').get(0);
18
- if (root._parsed) {
19
- // Reload to reset custom properties
20
- svg.load(svg.toString());
21
- root = svg.$svg(':root').get(0);
22
- }
23
- root._parsed = true;
24
- const cheerio = svg.$svg;
25
- // List of all elements
26
- const elements = new Map();
27
- // List of IDs
28
- const ids = Object.create(null);
29
- // Links
30
- let links = [];
31
- /**
32
- * Found element with id
33
- */
34
- function addID(element, id) {
35
- if (ids[id]) {
36
- throw new Error(`Duplicate id "${id}"`);
37
- }
38
- element._id = id;
39
- ids[id] = element._index;
40
- return true;
41
- }
42
- /**
43
- * Add _belongsTo
44
- */
45
- function gotElementWithID(element, id, isMask) {
46
- addID(element, id);
47
- if (!element._belongsTo) {
48
- element._belongsTo = [];
49
- }
50
- element._belongsTo.push({
51
- id,
52
- isMask,
53
- indexes: new Set([element._index]),
54
- });
55
- return;
56
- }
57
- /**
58
- * Mark element as reusable, set properties
59
- */
60
- function gotReusableElement(item, isMask) {
61
- const element = item.element;
62
- const attribs = element.attribs;
63
- const index = element._index;
64
- const id = attribs['id'];
65
- if (typeof id !== 'string') {
66
- const message = `Definition element ${(0, error_1.analyseTagError)(element)} does not have id`;
67
- if (fixErrors) {
68
- item.removeNode = true;
69
- item.testChildren = false;
70
- console.warn(message);
71
- return false;
72
- }
73
- throw new Error(message);
74
- }
75
- if (ids[id] && fixErrors) {
76
- console.warn(`Duplicate id "${id}"`);
77
- item.removeNode = true;
78
- item.testChildren = false;
79
- return false;
80
- }
81
- element._reusableElement = {
82
- id,
83
- isMask,
84
- index,
85
- };
86
- gotElementWithID(element, id, isMask);
87
- return true;
88
- }
89
- /**
90
- * Found element that uses another element
91
- */
92
- function gotElementReference(item, id, usedAsMask) {
93
- const element = item.element;
94
- const usedByIndex = element._index;
95
- const link = {
96
- id,
97
- usedByIndex,
98
- usedAsMask,
99
- };
100
- // Add to global list
101
- links.push(link);
102
- // Add to element and parent elements
103
- if (!element._linksTo) {
104
- element._linksTo = [];
105
- }
106
- element._linksTo.push(link);
107
- }
108
- // Find all reusable elements and all usages
109
- let index = 0;
110
- await (0, parse_1.parseSVG)(svg, (item) => {
111
- var _a;
112
- const { tagName, parents } = item;
113
- if (tags_1.styleTag.has(tagName)) {
114
- item.testChildren = false;
115
- return;
116
- }
117
- const element = item.element;
118
- const attribs = element.attribs;
119
- // Set index
120
- index++;
121
- element._index = index;
122
- elements.set(index, element);
123
- if (!parents.length) {
124
- // root <svg>
125
- element._usedAsMask = false;
126
- element._usedAsPaint = true;
127
- return;
128
- }
129
- element._usedAsMask = false;
130
- element._usedAsPaint = false;
131
- // Get parent element
132
- const parentItem = parents[0];
133
- const parentElement = parentItem.element;
134
- // Check for mask or clip path
135
- if (tags_1.maskTags.has(tagName)) {
136
- // Element can only be used as mask or clip path
137
- if (!gotReusableElement(item, true)) {
138
- return;
139
- }
140
- }
141
- else if (tags_1.reusableElementsWithPalette.has(tagName)) {
142
- // Reusable element that uses palette
143
- if (!gotReusableElement(item, false)) {
144
- return;
145
- }
146
- }
147
- else if (tags_1.defsTag.has(parentItem.tagName)) {
148
- // Symbol without <symbol> tag
149
- if (!gotReusableElement(item, false)) {
150
- return;
151
- }
152
- }
153
- else if (!tags_1.defsTag.has(tagName)) {
154
- // Not reusable element, not <defs>. Copy parent stuff
155
- element._usedAsMask = parentElement._usedAsMask;
156
- element._usedAsPaint = parentElement._usedAsPaint;
157
- element._parentElement = parentElement._index;
158
- if (!parentElement._childElements) {
159
- parentElement._childElements = [];
160
- }
161
- parentElement._childElements.push(index);
162
- // Copy id of reusable element from parent
163
- const parentReusableElement = parentElement._reusableElement;
164
- if (parentReusableElement) {
165
- if (element._reusableElement) {
166
- // Reusable element inside reusable element: should not happen!
167
- throw new Error(`Reusable element ${(0, error_1.analyseTagError)(element)} is inside another reusable element id="${parentReusableElement.id}"`);
168
- }
169
- element._reusableElement = parentReusableElement;
170
- }
171
- // Copy all parent ids
172
- const parentBelongsTo = parentElement._belongsTo;
173
- if (parentBelongsTo) {
174
- const list = element._belongsTo || (element._belongsTo = []);
175
- parentBelongsTo.forEach((item) => {
176
- item.indexes.add(index);
177
- list.push(item);
178
- });
179
- }
180
- // Check if element has its own id
181
- if (element._id === void 0) {
182
- const id = attribs['id'];
183
- if (typeof id === 'string') {
184
- if (ids[id] && fixErrors) {
185
- console.warn(`Duplicate id "${id}"`);
186
- cheerio(element).removeAttr('id');
187
- }
188
- else {
189
- gotElementWithID(element, id, false);
190
- }
191
- }
192
- }
193
- }
194
- // Check if element uses any ID
195
- if ((_a = attributes_1.tagSpecificNonPresentationalAttributes[tagName]) === null || _a === void 0 ? void 0 : _a.has('href')) {
196
- const href = attribs['href'] || attribs['xlink:href'];
197
- if (typeof href === 'string') {
198
- if (href.slice(0, 1) !== '#') {
199
- throw new Error(`Invalid link in ${(0, error_1.analyseTagError)(element)}`);
200
- }
201
- const id = href.slice(1);
202
- gotElementReference(item, id, false);
203
- }
204
- }
205
- // Check colors
206
- Object.keys(attribs).forEach((attr) => {
207
- // Get id
208
- let value = attribs[attr];
209
- if (value.slice(0, 5).toLowerCase() !== 'url(#') {
210
- return;
211
- }
212
- value = value.slice(5);
213
- if (value.slice(-1) !== ')') {
214
- return;
215
- }
216
- const id = value.slice(0, value.length - 1).trim();
217
- if (attributes_1.urlPresentationalAttributes.has(attr)) {
218
- // Used as mask, clip path or filter
219
- gotElementReference(item, id, attr !== 'filter');
220
- return;
221
- }
222
- if (attributes_1.commonColorPresentationalAttributes.has(attr) ||
223
- attributes_1.markerAttributes.has(attr)) {
224
- // Used as paint
225
- gotElementReference(item, id, false);
226
- return;
227
- }
228
- });
229
- });
230
- // Make sure all required IDs exist
231
- links = links.filter((item) => {
232
- const id = item.id;
233
- if (ids[id]) {
234
- return true;
235
- }
236
- // Attempt to fix error
237
- function fix() {
238
- const index = item.usedByIndex;
239
- const element = elements.get(index);
240
- const tagName = element.tagName;
241
- function remove() {
242
- var _a;
243
- const $element = cheerio(element);
244
- const parent = element.parent;
245
- if (parent) {
246
- if (parent._childElements) {
247
- parent._childElements = parent._childElements.filter((num) => num !== index);
248
- }
249
- (_a = parent._belongsTo) === null || _a === void 0 ? void 0 : _a.forEach((list) => {
250
- list.indexes.delete(index);
251
- });
252
- }
253
- $element.remove();
254
- }
255
- // Remove links
256
- if (element._linksTo) {
257
- element._linksTo = element._linksTo.filter((item) => item.id !== id);
258
- }
259
- // Remove <use /> without children
260
- if (!element.children.length) {
261
- if (tags_1.useTag.has(tagName)) {
262
- remove();
263
- return;
264
- }
265
- }
266
- // Remove attributes that use id
267
- const matches = new Set(['#' + id, 'url(#' + id + ')']);
268
- const attribs = element.attribs;
269
- for (const attr in attribs) {
270
- if (matches.has(attribs[attr])) {
271
- cheerio(element).removeAttr(attr);
272
- }
273
- }
274
- }
275
- const message = `Missing element with id="${id}"`;
276
- if (fixErrors) {
277
- fix();
278
- console.warn(message);
279
- }
280
- else {
281
- throw new Error(message);
282
- }
283
- return false;
284
- });
285
- // Check if tree item already has child item
286
- function hasChildItem(tree, child, canThrow) {
287
- const item = tree.children.find((item) => item.index === child.index &&
288
- item.usedAsMask === child.usedAsMask);
289
- if (item && canThrow) {
290
- throw new Error('Recursion');
291
- }
292
- return !!item;
293
- }
294
- // Generate tree
295
- const tree = {
296
- index: 1,
297
- usedAsMask: false,
298
- children: [],
299
- };
300
- function parseTreeItem(tree, usedItems, inMask) {
301
- var _a, _b;
302
- const element = elements.get(tree.index);
303
- // Add usage
304
- if (tree.usedAsMask || inMask) {
305
- element._usedAsMask = true;
306
- inMask = true;
307
- }
308
- else {
309
- element._usedAsPaint = true;
310
- }
311
- usedItems = usedItems.slice(0);
312
- usedItems.push(element._index);
313
- // Add all child elements
314
- (_a = element._childElements) === null || _a === void 0 ? void 0 : _a.forEach((childIndex) => {
315
- if (usedItems.indexOf(childIndex) !== -1) {
316
- throw new Error('Recursion');
317
- }
318
- const childItem = {
319
- index: childIndex,
320
- usedAsMask: false,
321
- children: [],
322
- parent: tree,
323
- };
324
- tree.children.push(childItem);
325
- parseTreeItem(childItem, usedItems, inMask);
326
- });
327
- // Add all links
328
- (_b = element._linksTo) === null || _b === void 0 ? void 0 : _b.forEach((link) => {
329
- const linkIndex = ids[link.id];
330
- const usedAsMask = link.usedAsMask;
331
- const childItem = {
332
- index: linkIndex,
333
- usedAsMask,
334
- children: [],
335
- parent: tree,
336
- };
337
- if (hasChildItem(tree, childItem, false)) {
338
- return;
339
- }
340
- tree.children.push(childItem);
341
- parseTreeItem(childItem, usedItems, inMask || usedAsMask);
342
- });
343
- }
344
- parseTreeItem(tree, [0], false);
345
- return {
346
- elements,
347
- ids,
348
- links,
349
- tree,
350
- };
351
- }
352
- exports.analyseSVGStructure = analyseSVGStructure;