@iconify/tools 2.0.11 → 2.0.14

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 (54) hide show
  1. package/lib/colors/parse.d.ts +14 -7
  2. package/lib/colors/parse.js +101 -39
  3. package/lib/colors/parse.mjs +81 -38
  4. package/lib/download/git/index.js +12 -0
  5. package/lib/download/git/index.mjs +7 -0
  6. package/lib/download/git/reset.d.ts +4 -0
  7. package/lib/download/git/reset.js +16 -0
  8. package/lib/download/git/reset.mjs +13 -0
  9. package/lib/export/json-package.js +6 -1
  10. package/lib/export/json-package.mjs +4 -1
  11. package/lib/icon-set/index.js +7 -4
  12. package/lib/icon-set/index.mjs +7 -4
  13. package/lib/icon-set/props.d.ts +1 -1
  14. package/lib/icon-set/props.js +3 -2
  15. package/lib/icon-set/props.mjs +2 -2
  16. package/lib/import/figma/nodes.js +3 -5
  17. package/lib/import/figma/nodes.mjs +3 -5
  18. package/lib/index.d.ts +3 -0
  19. package/lib/index.js +7 -1
  20. package/lib/index.mjs +6 -0
  21. package/lib/optimise/global-style.d.ts +5 -0
  22. package/lib/optimise/global-style.js +185 -0
  23. package/lib/optimise/global-style.mjs +147 -0
  24. package/lib/svg/analyse/error.d.ts +5 -0
  25. package/lib/svg/analyse/error.js +22 -0
  26. package/lib/svg/analyse/error.mjs +16 -0
  27. package/lib/svg/analyse/types.d.ts +89 -0
  28. package/lib/svg/analyse/types.js +2 -0
  29. package/lib/svg/analyse/types.mjs +0 -0
  30. package/lib/svg/analyse.d.ts +8 -0
  31. package/lib/svg/analyse.js +352 -0
  32. package/lib/svg/analyse.mjs +302 -0
  33. package/lib/svg/cleanup/attribs.d.ts +1 -1
  34. package/lib/svg/cleanup/attribs.js +8 -0
  35. package/lib/svg/cleanup/attribs.mjs +8 -1
  36. package/lib/svg/cleanup/bad-tags.d.ts +1 -1
  37. package/lib/svg/cleanup/bad-tags.js +0 -2
  38. package/lib/svg/cleanup/bad-tags.mjs +0 -3
  39. package/lib/svg/cleanup/inline-style.d.ts +1 -1
  40. package/lib/svg/cleanup/root-svg.d.ts +1 -1
  41. package/lib/svg/cleanup/root-svg.js +3 -1
  42. package/lib/svg/cleanup/root-svg.mjs +2 -2
  43. package/lib/svg/cleanup/svgo-style.d.ts +1 -1
  44. package/lib/svg/data/attributes.js +1 -1
  45. package/lib/svg/data/attributes.mjs +1 -1
  46. package/lib/svg/data/tags.d.ts +15 -7
  47. package/lib/svg/data/tags.js +20 -9
  48. package/lib/svg/data/tags.mjs +11 -6
  49. package/lib/svg/index.js +13 -4
  50. package/lib/svg/index.mjs +5 -2
  51. package/lib/svg/parse-style.d.ts +7 -7
  52. package/lib/svg/parse-style.js +27 -7
  53. package/lib/svg/parse-style.mjs +26 -7
  54. package/package.json +21 -1
@@ -1,7 +1,7 @@
1
1
  import type { Color } from '@iconify/utils/lib/colors/types';
2
2
  import type { SVG } from '../svg';
3
- import { ParseSVGCallbackItem } from '../svg/parse';
4
3
  import { ColorAttributes } from './attribs';
4
+ import type { AnalyseSVGStructureResult, ElementsTreeItem, ExtendedTagElement, AnalyseSVGStructureOptions } from '../svg/analyse/types';
5
5
  /**
6
6
  * Result
7
7
  */
@@ -20,24 +20,31 @@ export interface FindColorsResult {
20
20
  * - 'remove' to remove shape or rule
21
21
  */
22
22
  declare type ParseColorsCallbackResult = Color | string | 'remove' | 'unset';
23
- declare type ParseColorsCallback = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string) => ParseColorsCallbackResult | Promise<ParseColorsCallbackResult>;
23
+ declare type ParseColorsCallback = (attr: ColorAttributes, colorString: string, parsedColor: Color | null, tagName?: string, item?: ExtendedTagElementWithColors) => ParseColorsCallbackResult | Promise<ParseColorsCallbackResult>;
24
+ /**
25
+ * Callback for default color
26
+ */
27
+ export declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedTagElementWithColors, treeItem: ElementsTreeItem, iconData: AnalyseSVGStructureResult) => Color;
24
28
  /**
25
29
  * Options
26
30
  */
27
- export declare type ParseColorOptionsDefaultColorCallback = (prop: string, item: ExtendedParseSVGCallbackItem) => Color;
28
- export interface ParseColorsOptions {
31
+ export interface ParseColorsOptions extends AnalyseSVGStructureOptions {
29
32
  callback?: ParseColorsCallback;
30
33
  defaultColor?: Color | string | ParseColorOptionsDefaultColorCallback;
31
34
  }
32
35
  /**
33
- * Extend properties for item
36
+ * Extend properties for element
34
37
  */
35
38
  declare type ItemColors = Partial<Record<ColorAttributes, Color | string>>;
36
- export interface ExtendedParseSVGCallbackItem extends ParseSVGCallbackItem {
37
- colors?: ItemColors;
39
+ export interface ExtendedTagElementWithColors extends ExtendedTagElement {
40
+ _colors?: ItemColors;
41
+ _removed?: boolean;
38
42
  }
39
43
  /**
40
44
  * Find colors in icon
45
+ *
46
+ * Clean up icon before running this function to convert style to attributes using
47
+ * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
41
48
  */
42
49
  export declare function parseColors(svg: SVG, options?: ParseColorsOptions): Promise<FindColorsResult>;
43
50
  /**
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEmptyColor = exports.parseColors = void 0;
4
4
  const colors_1 = require("@iconify/utils/lib/colors");
5
- const parse_1 = require("../svg/parse");
6
5
  const tags_1 = require("../svg/data/tags");
7
6
  const parse_style_1 = require("../svg/parse-style");
8
7
  const attribs_1 = require("./attribs");
9
8
  const attributes_1 = require("../svg/data/attributes");
9
+ const analyse_1 = require("../svg/analyse");
10
10
  /**
11
11
  * Properties to check
12
12
  */
@@ -14,6 +14,9 @@ const propsToCheck = Object.keys(attribs_1.defaultColorValues);
14
14
  const animatePropsToCheck = ['from', 'to', 'values'];
15
15
  /**
16
16
  * Find colors in icon
17
+ *
18
+ * Clean up icon before running this function to convert style to attributes using
19
+ * cleanupInlineStyle() or cleanupSVG(), otherwise results might be inaccurate
17
20
  */
18
21
  async function parseColors(svg, options = {}) {
19
22
  const result = {
@@ -25,6 +28,9 @@ async function parseColors(svg, options = {}) {
25
28
  const defaultColor = typeof options.defaultColor === 'string'
26
29
  ? (0, colors_1.stringToColor)(options.defaultColor)
27
30
  : options.defaultColor;
31
+ /**
32
+ * Find matching color in results
33
+ */
28
34
  function findColor(color, add = false) {
29
35
  const isString = typeof color === 'string';
30
36
  for (let i = 0; i < result.colors.length; i++) {
@@ -47,29 +53,31 @@ async function parseColors(svg, options = {}) {
47
53
  /**
48
54
  * Add color to item and to results
49
55
  */
50
- function addColorToItem(prop, color, item) {
51
- const addedColor = findColor(color, true);
56
+ function addColorToItem(prop, color, item, add = true) {
57
+ const addedColor = findColor(color, add !== false);
52
58
  if (item) {
53
- const itemColors = item.colors || {};
54
- if (!item.colors) {
55
- item.colors = itemColors;
56
- }
57
- itemColors[prop] = addedColor;
59
+ const itemColors = item._colors || (item._colors = {});
60
+ itemColors[prop] = addedColor === null ? color : addedColor;
58
61
  }
59
62
  }
60
63
  /**
61
64
  * Get element color
62
65
  */
63
- function getElementColor(prop, item) {
66
+ function getElementColor(prop, item, elements) {
64
67
  function find(prop) {
65
68
  var _a;
66
69
  let currentItem = item;
67
70
  while (currentItem) {
68
- const color = (_a = currentItem.colors) === null || _a === void 0 ? void 0 : _a[prop];
71
+ const element = elements.get(currentItem.index);
72
+ const color = (_a = element._colors) === null || _a === void 0 ? void 0 : _a[prop];
69
73
  if (color !== void 0) {
70
74
  return color;
71
75
  }
72
- currentItem = currentItem.parents[0];
76
+ currentItem = currentItem.parent;
77
+ if (currentItem === null || currentItem === void 0 ? void 0 : currentItem.usedAsMask) {
78
+ // Used as mask: color from parent item is irrelevant
79
+ return attribs_1.defaultColorValues[prop];
80
+ }
73
81
  }
74
82
  return attribs_1.defaultColorValues[prop];
75
83
  }
@@ -97,6 +105,8 @@ async function parseColors(svg, options = {}) {
97
105
  const defaultValue = parsedColor || value;
98
106
  // Ignore url()
99
107
  if ((parsedColor === null || parsedColor === void 0 ? void 0 : parsedColor.type) === 'function' && parsedColor.func === 'url') {
108
+ // Add to item, so it won't be treated as missing, but do not add to results
109
+ addColorToItem(prop, defaultValue, item, false);
100
110
  return value;
101
111
  }
102
112
  // Check if callback exists
@@ -105,7 +115,7 @@ async function parseColors(svg, options = {}) {
105
115
  return value;
106
116
  }
107
117
  // Call callback
108
- let callbackResult = options.callback(prop, value, parsedColor, item === null || item === void 0 ? void 0 : item.tagName);
118
+ let callbackResult = options.callback(prop, value, parsedColor, item === null || item === void 0 ? void 0 : item.tagName, item);
109
119
  callbackResult =
110
120
  callbackResult instanceof Promise
111
121
  ? await callbackResult
@@ -113,11 +123,7 @@ async function parseColors(svg, options = {}) {
113
123
  // Remove entry
114
124
  switch (callbackResult) {
115
125
  case 'remove': {
116
- if (item) {
117
- item.$element.remove();
118
- item.testChildren = false;
119
- }
120
- return;
126
+ return item ? callbackResult : void 0;
121
127
  }
122
128
  case 'unset':
123
129
  return;
@@ -156,19 +162,58 @@ async function parseColors(svg, options = {}) {
156
162
  result.hasGlobalStyle = true;
157
163
  }
158
164
  return newValue;
159
- }, {
160
- skipMasks: true,
161
165
  });
162
- // Parse colors in SVG
163
- await (0, parse_1.parseSVG)(svg, async (item) => {
164
- const tagName = item.tagName;
165
- if (tags_1.maskAndSymbolTags.has(tagName)) {
166
- // Ignore masks
167
- item.testChildren = false;
166
+ // Analyse SVG
167
+ const iconData = await (0, analyse_1.analyseSVGStructure)(svg, options);
168
+ const { elements, tree } = iconData;
169
+ const cheerio = svg.$svg;
170
+ const removedElements = new Set();
171
+ const parsedElements = new Set();
172
+ // Remove element
173
+ function removeElement(index, element) {
174
+ // Mark all children as removed (direct children as in DOM)
175
+ function removeChildren(element) {
176
+ element.children.forEach((item) => {
177
+ if (item.type !== 'tag') {
178
+ return;
179
+ }
180
+ const element = item;
181
+ const index = element._index;
182
+ if (index && !removedElements.has(index)) {
183
+ element._removed = true;
184
+ removedElements.add(index);
185
+ removeChildren(element);
186
+ }
187
+ });
188
+ }
189
+ // Remove element
190
+ element._removed = true;
191
+ removedElements.add(index);
192
+ removeChildren(element);
193
+ cheerio(element).remove();
194
+ }
195
+ // Parse tree item
196
+ async function parseTreeItem(item) {
197
+ const index = item.index;
198
+ if (removedElements.has(index) || parsedElements.has(index)) {
168
199
  return;
169
200
  }
170
- const $element = item.$element;
171
- const attribs = item.element.attribs;
201
+ parsedElements.add(index);
202
+ const element = elements.get(index);
203
+ if (element._removed) {
204
+ return;
205
+ }
206
+ const { tagName, attribs } = element;
207
+ // Copy colors from parent item
208
+ if (item.parent) {
209
+ const parentIndex = item.parent.index;
210
+ const parentElement = elements.get(parentIndex);
211
+ if (parentElement._colors) {
212
+ element._colors = {
213
+ ...parentElement._colors,
214
+ };
215
+ }
216
+ }
172
217
  // Check common properties
173
218
  for (let i = 0; i < propsToCheck.length; i++) {
174
219
  const prop = propsToCheck[i];
@@ -178,13 +223,24 @@ async function parseColors(svg, options = {}) {
178
223
  }
179
224
  const value = attribs[prop];
180
225
  if (value !== void 0) {
181
- const newValue = await checkColor(prop, value, item);
226
+ const newValue = await checkColor(prop, value, element);
182
227
  if (newValue !== value) {
183
228
  if (newValue === void 0) {
184
- $element.removeAttr(prop);
229
+ // Unset
230
+ cheerio(element).removeAttr(prop);
231
+ if (element._colors) {
232
+ delete element._colors[prop];
233
+ }
234
+ }
235
+ else if (newValue === 'remove') {
236
+ // Remove element
237
+ removeElement(index, element);
238
+ return;
185
239
  }
186
240
  else {
187
- $element.attr(prop, newValue);
241
+ // Change attribute
242
+ // Value in element._colors is changed in checkColor()
243
+ cheerio(element).attr(prop, newValue);
188
244
  }
189
245
  }
190
246
  }
@@ -220,7 +276,7 @@ async function parseColors(svg, options = {}) {
220
276
  }
221
277
  // Merge values back
222
278
  if (updatedValues) {
223
- $element.attr(elementProp, splitValues.join(';'));
279
+ cheerio(element).attr(elementProp, splitValues.join(';'));
224
280
  }
225
281
  }
226
282
  }
@@ -240,22 +296,19 @@ async function parseColors(svg, options = {}) {
240
296
  });
241
297
  // Check colors
242
298
  if (requiredProps) {
243
- const itemColors = item.colors || {};
244
- if (!item.colors) {
245
- item.colors = itemColors;
246
- }
299
+ const itemColors = element._colors || (element._colors = {});
247
300
  for (let i = 0; i < requiredProps.length; i++) {
248
301
  const prop = requiredProps[i];
249
- const color = getElementColor(prop, item);
302
+ const color = getElementColor(prop, item, elements);
250
303
  if (color === attribs_1.defaultBlackColor) {
251
304
  // Default black color: change it
252
305
  if (defaultColor) {
253
306
  const defaultColorValue = typeof defaultColor === 'function'
254
- ? defaultColor(prop, item)
307
+ ? defaultColor(prop, element, item, iconData)
255
308
  : defaultColor;
256
309
  // Add color to results and change attribute
257
310
  findColor(defaultColorValue, true);
258
- $element.attr(prop, (0, colors_1.colorToString)(defaultColorValue));
311
+ cheerio(element).attr(prop, (0, colors_1.colorToString)(defaultColorValue));
259
312
  itemColors[prop] = defaultColorValue;
260
313
  }
261
314
  else {
@@ -265,7 +318,16 @@ async function parseColors(svg, options = {}) {
265
318
  }
266
319
  }
267
320
  }
268
- });
321
+ // Parse child elements
322
+ for (let i = 0; i < item.children.length; i++) {
323
+ const childItem = item.children[i];
324
+ if (!childItem.usedAsMask) {
325
+ await parseTreeItem(childItem);
326
+ }
327
+ }
328
+ }
329
+ // Parse tree, starting with <svg>
330
+ await parseTreeItem(tree);
269
331
  return result;
270
332
  }
271
333
  exports.parseColors = parseColors;
@@ -4,8 +4,7 @@ import {
4
4
  stringToColor,
5
5
  colorToString
6
6
  } from "@iconify/utils/lib/colors";
7
- import { parseSVG } from "../svg/parse.mjs";
8
- import { animateTags, maskAndSymbolTags, shapeTags } from "../svg/data/tags.mjs";
7
+ import { animateTags, shapeTags } from "../svg/data/tags.mjs";
9
8
  import { parseSVGStyle } from "../svg/parse-style.mjs";
10
9
  import {
11
10
  defaultBlackColor,
@@ -14,6 +13,7 @@ import {
14
13
  specialColorAttributes
15
14
  } from "./attribs.mjs";
16
15
  import { tagSpecificPresentationalAttributes } from "../svg/data/attributes.mjs";
16
+ import { analyseSVGStructure } from "../svg/analyse.mjs";
17
17
  var propsToCheck = Object.keys(defaultColorValues);
18
18
  var animatePropsToCheck = ["from", "to", "values"];
19
19
  async function parseColors(svg, options = {}) {
@@ -40,26 +40,27 @@ async function parseColors(svg, options = {}) {
40
40
  }
41
41
  return null;
42
42
  }
43
- function addColorToItem(prop, color, item) {
44
- const addedColor = findColor(color, true);
43
+ function addColorToItem(prop, color, item, add = true) {
44
+ const addedColor = findColor(color, add !== false);
45
45
  if (item) {
46
- const itemColors = item.colors || {};
47
- if (!item.colors) {
48
- item.colors = itemColors;
49
- }
50
- itemColors[prop] = addedColor;
46
+ const itemColors = item._colors || (item._colors = {});
47
+ itemColors[prop] = addedColor === null ? color : addedColor;
51
48
  }
52
49
  }
53
- function getElementColor(prop, item) {
50
+ function getElementColor(prop, item, elements2) {
54
51
  function find(prop2) {
55
52
  var _a;
56
53
  let currentItem = item;
57
54
  while (currentItem) {
58
- const color = (_a = currentItem.colors) == null ? void 0 : _a[prop2];
55
+ const element = elements2.get(currentItem.index);
56
+ const color = (_a = element._colors) == null ? void 0 : _a[prop2];
59
57
  if (color !== void 0) {
60
58
  return color;
61
59
  }
62
- currentItem = currentItem.parents[0];
60
+ currentItem = currentItem.parent;
61
+ if (currentItem == null ? void 0 : currentItem.usedAsMask) {
62
+ return defaultColorValues[prop2];
63
+ }
63
64
  }
64
65
  return defaultColorValues[prop2];
65
66
  }
@@ -78,21 +79,18 @@ async function parseColors(svg, options = {}) {
78
79
  const parsedColor = stringToColor(value);
79
80
  const defaultValue = parsedColor || value;
80
81
  if ((parsedColor == null ? void 0 : parsedColor.type) === "function" && parsedColor.func === "url") {
82
+ addColorToItem(prop, defaultValue, item, false);
81
83
  return value;
82
84
  }
83
85
  if (!options.callback) {
84
86
  addColorToItem(prop, defaultValue, item);
85
87
  return value;
86
88
  }
87
- let callbackResult = options.callback(prop, value, parsedColor, item == null ? void 0 : item.tagName);
89
+ let callbackResult = options.callback(prop, value, parsedColor, item == null ? void 0 : item.tagName, item);
88
90
  callbackResult = callbackResult instanceof Promise ? await callbackResult : callbackResult;
89
91
  switch (callbackResult) {
90
92
  case "remove": {
91
- if (item) {
92
- item.$element.remove();
93
- item.testChildren = false;
94
- }
95
- return;
93
+ return item ? callbackResult : void 0;
96
94
  }
97
95
  case "unset":
98
96
  return;
@@ -125,17 +123,52 @@ async function parseColors(svg, options = {}) {
125
123
  result.hasGlobalStyle = true;
126
124
  }
127
125
  return newValue;
128
- }, {
129
- skipMasks: true
130
126
  });
131
- await parseSVG(svg, async (item) => {
132
- const tagName = item.tagName;
133
- if (maskAndSymbolTags.has(tagName)) {
134
- item.testChildren = false;
127
+ const iconData = await analyseSVGStructure(svg, options);
128
+ const { elements, tree } = iconData;
129
+ const cheerio = svg.$svg;
130
+ const removedElements = new Set();
131
+ const parsedElements = new Set();
132
+ function removeElement(index, element) {
133
+ function removeChildren(element2) {
134
+ element2.children.forEach((item) => {
135
+ if (item.type !== "tag") {
136
+ return;
137
+ }
138
+ const element3 = item;
139
+ const index2 = element3._index;
140
+ if (index2 && !removedElements.has(index2)) {
141
+ element3._removed = true;
142
+ removedElements.add(index2);
143
+ removeChildren(element3);
144
+ }
145
+ });
146
+ }
147
+ element._removed = true;
148
+ removedElements.add(index);
149
+ removeChildren(element);
150
+ cheerio(element).remove();
151
+ }
152
+ async function parseTreeItem(item) {
153
+ const index = item.index;
154
+ if (removedElements.has(index) || parsedElements.has(index)) {
135
155
  return;
136
156
  }
137
- const $element = item.$element;
138
- const attribs = item.element.attribs;
157
+ parsedElements.add(index);
158
+ const element = elements.get(index);
159
+ if (element._removed) {
160
+ return;
161
+ }
162
+ const { tagName, attribs } = element;
163
+ if (item.parent) {
164
+ const parentIndex = item.parent.index;
165
+ const parentElement = elements.get(parentIndex);
166
+ if (parentElement._colors) {
167
+ element._colors = {
168
+ ...parentElement._colors
169
+ };
170
+ }
171
+ }
139
172
  for (let i = 0; i < propsToCheck.length; i++) {
140
173
  const prop = propsToCheck[i];
141
174
  if (prop === "fill" && animateTags.has(tagName)) {
@@ -143,12 +176,18 @@ async function parseColors(svg, options = {}) {
143
176
  }
144
177
  const value = attribs[prop];
145
178
  if (value !== void 0) {
146
- const newValue = await checkColor(prop, value, item);
179
+ const newValue = await checkColor(prop, value, element);
147
180
  if (newValue !== value) {
148
181
  if (newValue === void 0) {
149
- $element.removeAttr(prop);
182
+ cheerio(element).removeAttr(prop);
183
+ if (element._colors) {
184
+ delete element._colors[prop];
185
+ }
186
+ } else if (newValue === "remove") {
187
+ removeElement(index, element);
188
+ return;
150
189
  } else {
151
- $element.attr(prop, newValue);
190
+ cheerio(element).attr(prop, newValue);
152
191
  }
153
192
  }
154
193
  }
@@ -175,7 +214,7 @@ async function parseColors(svg, options = {}) {
175
214
  }
176
215
  }
177
216
  if (updatedValues) {
178
- $element.attr(elementProp, splitValues.join(";"));
217
+ cheerio(element).attr(elementProp, splitValues.join(";"));
179
218
  }
180
219
  }
181
220
  }
@@ -192,18 +231,15 @@ async function parseColors(svg, options = {}) {
192
231
  }
193
232
  });
194
233
  if (requiredProps) {
195
- const itemColors = item.colors || {};
196
- if (!item.colors) {
197
- item.colors = itemColors;
198
- }
234
+ const itemColors = element._colors || (element._colors = {});
199
235
  for (let i = 0; i < requiredProps.length; i++) {
200
236
  const prop = requiredProps[i];
201
- const color = getElementColor(prop, item);
237
+ const color = getElementColor(prop, item, elements);
202
238
  if (color === defaultBlackColor) {
203
239
  if (defaultColor) {
204
- const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, item) : defaultColor;
240
+ const defaultColorValue = typeof defaultColor === "function" ? defaultColor(prop, element, item, iconData) : defaultColor;
205
241
  findColor(defaultColorValue, true);
206
- $element.attr(prop, colorToString(defaultColorValue));
242
+ cheerio(element).attr(prop, colorToString(defaultColorValue));
207
243
  itemColors[prop] = defaultColorValue;
208
244
  } else {
209
245
  result.hasUnsetColor = true;
@@ -212,7 +248,14 @@ async function parseColors(svg, options = {}) {
212
248
  }
213
249
  }
214
250
  }
215
- });
251
+ for (let i = 0; i < item.children.length; i++) {
252
+ const childItem = item.children[i];
253
+ if (!childItem.usedAsMask) {
254
+ await parseTreeItem(childItem);
255
+ }
256
+ }
257
+ }
258
+ await parseTreeItem(tree);
216
259
  return result;
217
260
  }
218
261
  function isEmptyColor(color) {
@@ -6,6 +6,7 @@ const prepare_1 = require("../../export/helpers/prepare");
6
6
  const exec_1 = require("../../misc/exec");
7
7
  const branch_1 = require("./branch");
8
8
  const hash_1 = require("./hash");
9
+ const reset_1 = require("./reset");
9
10
  async function downloadGitRepo(options) {
10
11
  const { remote, branch } = options;
11
12
  // Check for last commit
@@ -32,6 +33,8 @@ async function downloadGitRepo(options) {
32
33
  ? ifModifiedSince.hash
33
34
  : null;
34
35
  if (latestHash === expectedHash) {
36
+ // Reset contents before returning
37
+ await (0, reset_1.resetGitRepoContents)(options.target);
35
38
  return 'not_modified';
36
39
  }
37
40
  }
@@ -51,6 +54,15 @@ async function downloadGitRepo(options) {
51
54
  }
52
55
  await (0, exec_1.execAsync)(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
53
56
  }
57
+ else {
58
+ // Attempt to reset contents
59
+ try {
60
+ await (0, reset_1.resetGitRepoContents)(options.target);
61
+ }
62
+ catch (err) {
63
+ //
64
+ }
65
+ }
54
66
  // Get latest hash and make sure correct branch is available
55
67
  const hash = await (0, hash_1.getGitRepoHash)(options);
56
68
  await (0, branch_1.getGitRepoBranch)(options, branch);
@@ -6,6 +6,7 @@ import {
6
6
  import { execAsync } from "../../misc/exec.mjs";
7
7
  import { getGitRepoBranch } from "./branch.mjs";
8
8
  import { getGitRepoHash } from "./hash.mjs";
9
+ import { resetGitRepoContents } from "./reset.mjs";
9
10
  async function downloadGitRepo(options) {
10
11
  const { remote, branch } = options;
11
12
  const hasHashInTarget = options.target.indexOf("{hash}") !== -1;
@@ -22,6 +23,7 @@ async function downloadGitRepo(options) {
22
23
  if (ifModifiedSince) {
23
24
  const expectedHash = ifModifiedSince === true ? await getGitRepoHash(options) : typeof ifModifiedSince === "string" ? ifModifiedSince : ifModifiedSince.downloadType === "git" ? ifModifiedSince.hash : null;
24
25
  if (latestHash === expectedHash) {
26
+ await resetGitRepoContents(options.target);
25
27
  return "not_modified";
26
28
  }
27
29
  }
@@ -36,6 +38,11 @@ async function downloadGitRepo(options) {
36
38
  console.log(`Cloning ${remote}#${branch} to ${target}`);
37
39
  }
38
40
  await execAsync(`git clone --branch ${branch} --no-tags --depth 1 ${remote} "${target}"`);
41
+ } else {
42
+ try {
43
+ await resetGitRepoContents(options.target);
44
+ } catch (err) {
45
+ }
39
46
  }
40
47
  const hash = await getGitRepoHash(options);
41
48
  await getGitRepoBranch(options, branch);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reset Git repo contents
3
+ */
4
+ export declare function resetGitRepoContents(target: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resetGitRepoContents = void 0;
4
+ const __1 = require("../..");
5
+ /**
6
+ * Reset Git repo contents
7
+ */
8
+ async function resetGitRepoContents(target) {
9
+ await (0, __1.execAsync)('git add -A', {
10
+ cwd: target,
11
+ });
12
+ await (0, __1.execAsync)('git reset --hard --quiet', {
13
+ cwd: target,
14
+ });
15
+ }
16
+ exports.resetGitRepoContents = resetGitRepoContents;
@@ -0,0 +1,13 @@
1
+ // src/download/git/reset.ts
2
+ import { execAsync } from "../../index.mjs";
3
+ async function resetGitRepoContents(target) {
4
+ await execAsync("git add -A", {
5
+ cwd: target
6
+ });
7
+ await execAsync("git reset --hard --quiet", {
8
+ cwd: target
9
+ });
10
+ }
11
+ export {
12
+ resetGitRepoContents
13
+ };
@@ -51,7 +51,12 @@ async function exportJSONPackage(iconSet, options) {
51
51
  }
52
52
  });
53
53
  // Contents
54
- const info = exportedJSON.info;
54
+ const info = exportedJSON.info
55
+ ? {
56
+ prefix: iconSet.prefix,
57
+ ...exportedJSON.info,
58
+ }
59
+ : void 0;
55
60
  const contents = {
56
61
  icons,
57
62
  info,
@@ -41,7 +41,10 @@ async function exportJSONPackage(iconSet, options) {
41
41
  hasMetadata = true;
42
42
  }
43
43
  });
44
- const info = exportedJSON.info;
44
+ const info = exportedJSON.info ? {
45
+ prefix: iconSet.prefix,
46
+ ...exportedJSON.info
47
+ } : void 0;
45
48
  const contents = {
46
49
  icons,
47
50
  info,
@@ -42,7 +42,7 @@ class IconSet {
42
42
  load(data) {
43
43
  this.prefix = data.prefix;
44
44
  // Defaults
45
- const defaultProps = (0, props_1.filterProps)(data);
45
+ const defaultProps = (0, props_1.filterProps)(data, true);
46
46
  // Add icons
47
47
  this.entries = Object.create(null);
48
48
  const entries = this.entries;
@@ -51,7 +51,10 @@ class IconSet {
51
51
  const entry = {
52
52
  type: 'icon',
53
53
  body: item.body,
54
- props: { ...defaultProps, ...(0, props_1.filterProps)(item) },
54
+ props: (0, props_1.filterProps)({
55
+ ...defaultProps,
56
+ ...item,
57
+ }, true),
55
58
  chars: new Set(),
56
59
  categories: new Set(),
57
60
  };
@@ -62,7 +65,7 @@ class IconSet {
62
65
  for (const name in data.aliases) {
63
66
  const item = data.aliases[name];
64
67
  const parent = item.parent;
65
- const props = (0, props_1.filterProps)(item);
68
+ const props = (0, props_1.filterProps)(item, false);
66
69
  const chars = new Set();
67
70
  if (Object.keys(props).length) {
68
71
  // Variation
@@ -599,7 +602,7 @@ class IconSet {
599
602
  return this.setItem(name, {
600
603
  type: 'icon',
601
604
  body: icon.body,
602
- props: (0, props_1.filterProps)(icon),
605
+ props: (0, props_1.filterProps)(icon, true),
603
606
  chars: new Set(),
604
607
  categories: new Set(),
605
608
  });