@iconify/tools 3.0.6 → 4.0.0-beta.1
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/colors/detect.cjs +1 -1
- package/lib/colors/detect.d.ts +1 -0
- package/lib/colors/detect.mjs +2 -2
- package/lib/colors/parse.cjs +131 -275
- package/lib/colors/parse.d.ts +8 -15
- package/lib/colors/parse.mjs +135 -278
- package/lib/colors/validate.cjs +2 -11
- package/lib/colors/validate.d.ts +5 -11
- package/lib/colors/validate.mjs +4 -12
- package/lib/export/directory.d.ts +1 -0
- package/lib/export/icon-package.d.ts +4 -1
- package/lib/export/json-package.cjs +1 -0
- package/lib/export/json-package.d.ts +2 -0
- package/lib/export/json-package.mjs +1 -0
- package/lib/icon-set/index.d.ts +1 -0
- package/lib/icon-set/match.d.ts +1 -0
- package/lib/icon-set/merge.d.ts +1 -0
- package/lib/icon-set/modified.d.ts +1 -0
- package/lib/icon-set/tags.d.ts +1 -0
- package/lib/import/directory.d.ts +1 -0
- package/lib/import/figma/index.d.ts +1 -0
- package/lib/import/figma/nodes.d.ts +1 -0
- package/lib/import/figma/query.d.ts +1 -0
- package/lib/import/figma/types/nodes.d.ts +1 -0
- package/lib/import/figma/types/options.d.ts +1 -0
- package/lib/import/figma/types/result.d.ts +1 -0
- package/lib/index.cjs +0 -6
- package/lib/index.d.ts +5 -5
- package/lib/index.mjs +4 -5
- package/lib/misc/cheerio.d.ts +4 -2
- package/lib/optimise/figma.d.ts +1 -0
- package/lib/optimise/flags.cjs +2 -2
- package/lib/optimise/flags.d.ts +2 -1
- package/lib/optimise/flags.mjs +2 -2
- package/lib/optimise/global-style.cjs +6 -6
- package/lib/optimise/global-style.d.ts +2 -1
- package/lib/optimise/global-style.mjs +6 -6
- package/lib/optimise/mask.cjs +10 -10
- package/lib/optimise/mask.d.ts +1 -0
- package/lib/optimise/mask.mjs +11 -11
- package/lib/optimise/origin.d.ts +1 -0
- package/lib/optimise/scale.d.ts +1 -0
- package/lib/optimise/svgo.d.ts +1 -0
- package/lib/svg/analyse/error.d.ts +2 -0
- package/lib/svg/analyse/types.d.ts +4 -1
- package/lib/svg/analyse.cjs +1 -1
- package/lib/svg/analyse.d.ts +2 -0
- package/lib/svg/analyse.mjs +3 -3
- package/lib/svg/cleanup/attribs.cjs +1 -1
- package/lib/svg/cleanup/attribs.d.ts +1 -0
- package/lib/svg/cleanup/attribs.mjs +2 -2
- package/lib/svg/cleanup/bad-tags.cjs +1 -1
- package/lib/svg/cleanup/bad-tags.d.ts +1 -0
- package/lib/svg/cleanup/bad-tags.mjs +2 -2
- package/lib/svg/cleanup/inline-style.cjs +1 -1
- package/lib/svg/cleanup/inline-style.d.ts +1 -0
- package/lib/svg/cleanup/inline-style.mjs +2 -2
- package/lib/svg/cleanup/root-style.cjs +1 -1
- package/lib/svg/cleanup/root-style.d.ts +1 -0
- package/lib/svg/cleanup/root-style.mjs +2 -2
- package/lib/svg/cleanup/root-svg.d.ts +1 -0
- package/lib/svg/cleanup/svgo-style.cjs +1 -1
- package/lib/svg/cleanup/svgo-style.d.ts +1 -0
- package/lib/svg/cleanup/svgo-style.mjs +2 -2
- package/lib/svg/cleanup.d.ts +1 -0
- package/lib/svg/index.cjs +13 -3
- package/lib/svg/index.d.ts +2 -1
- package/lib/svg/index.mjs +1 -1
- package/lib/svg/parse-style.cjs +178 -235
- package/lib/svg/parse-style.d.ts +4 -9
- package/lib/svg/parse-style.mjs +180 -236
- package/lib/svg/parse.cjs +26 -58
- package/lib/svg/parse.d.ts +4 -10
- package/lib/svg/parse.mjs +27 -58
- package/package.json +12 -10
package/lib/colors/parse.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { stringToColor,
|
|
1
|
+
import { stringToColor, colorToString, compareColors } from '@iconify/utils/lib/colors';
|
|
2
2
|
import { animateTags, shapeTags } from '../svg/data/tags.mjs';
|
|
3
|
-
import { parseSVGStyle
|
|
4
|
-
import {
|
|
3
|
+
import { parseSVGStyle } from '../svg/parse-style.mjs';
|
|
4
|
+
import { specialColorAttributes, defaultBlackColor, defaultColorValues, shapeColorAttributes, allowDefaultColorValue } from './attribs.mjs';
|
|
5
5
|
import { tagSpecificPresentationalAttributes } from '../svg/data/attributes.mjs';
|
|
6
6
|
import { analyseSVGStructure } from '../svg/analyse.mjs';
|
|
7
7
|
import '../css/parse.mjs';
|
|
@@ -16,7 +16,7 @@ import '../svg/analyse/error.mjs';
|
|
|
16
16
|
|
|
17
17
|
const propsToCheck = Object.keys(defaultColorValues);
|
|
18
18
|
const animatePropsToCheck = ["from", "to", "values"];
|
|
19
|
-
function
|
|
19
|
+
function parseColors(svg, options = {}) {
|
|
20
20
|
const result = {
|
|
21
21
|
colors: [],
|
|
22
22
|
hasUnsetColor: false,
|
|
@@ -47,12 +47,12 @@ function createContext(options, callback) {
|
|
|
47
47
|
itemColors[prop] = addedColor === null ? color : addedColor;
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
function getElementColor(prop, item,
|
|
50
|
+
function getElementColor(prop, item, elements2) {
|
|
51
51
|
function find(prop2) {
|
|
52
52
|
let currentItem = item;
|
|
53
53
|
const allowDefaultColor = allowDefaultColorValue[prop2];
|
|
54
54
|
while (currentItem) {
|
|
55
|
-
const element =
|
|
55
|
+
const element = elements2.get(
|
|
56
56
|
currentItem.index
|
|
57
57
|
);
|
|
58
58
|
const color = element._colors?.[prop2];
|
|
@@ -77,81 +77,69 @@ function createContext(options, callback) {
|
|
|
77
77
|
}
|
|
78
78
|
return propColor;
|
|
79
79
|
}
|
|
80
|
-
function checkColor(
|
|
80
|
+
function checkColor(prop, value, item) {
|
|
81
81
|
switch (value.trim().toLowerCase()) {
|
|
82
82
|
case "":
|
|
83
83
|
case "inherit":
|
|
84
|
-
return
|
|
84
|
+
return;
|
|
85
85
|
}
|
|
86
86
|
const parsedColor = stringToColor(value);
|
|
87
87
|
const defaultValue = parsedColor || value;
|
|
88
88
|
if (parsedColor?.type === "function" && parsedColor.func === "url") {
|
|
89
89
|
addColorToItem(prop, defaultValue, item, false);
|
|
90
|
-
return
|
|
90
|
+
return value;
|
|
91
91
|
}
|
|
92
|
-
if (!callback) {
|
|
92
|
+
if (!options.callback) {
|
|
93
93
|
addColorToItem(prop, defaultValue, item);
|
|
94
|
-
return
|
|
94
|
+
return value;
|
|
95
95
|
}
|
|
96
|
-
callback(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
case "unset":
|
|
104
|
-
return done();
|
|
105
|
-
}
|
|
106
|
-
if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
|
|
107
|
-
addColorToItem(prop, defaultValue, item);
|
|
108
|
-
return done(value);
|
|
109
|
-
}
|
|
110
|
-
if (typeof callbackResult === "string") {
|
|
111
|
-
const newColor = stringToColor(callbackResult);
|
|
112
|
-
addColorToItem(prop, newColor || callbackResult, item);
|
|
113
|
-
return done(callbackResult);
|
|
114
|
-
}
|
|
115
|
-
const newValue = colorToString(callbackResult);
|
|
116
|
-
addColorToItem(prop, callbackResult, item);
|
|
117
|
-
return done(newValue);
|
|
118
|
-
}
|
|
96
|
+
const callbackResult = options.callback(
|
|
97
|
+
prop,
|
|
98
|
+
value,
|
|
99
|
+
parsedColor,
|
|
100
|
+
item?.tagName,
|
|
101
|
+
item
|
|
119
102
|
);
|
|
103
|
+
if (callbackResult instanceof Promise) {
|
|
104
|
+
throw new Error("parseColors does not support async callbacks");
|
|
105
|
+
}
|
|
106
|
+
switch (callbackResult) {
|
|
107
|
+
case "remove": {
|
|
108
|
+
return item ? callbackResult : void 0;
|
|
109
|
+
}
|
|
110
|
+
case "unset":
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (callbackResult === value || parsedColor && callbackResult === parsedColor) {
|
|
114
|
+
addColorToItem(prop, defaultValue, item);
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
if (typeof callbackResult === "string") {
|
|
118
|
+
const newColor = stringToColor(callbackResult);
|
|
119
|
+
addColorToItem(prop, newColor || callbackResult, item);
|
|
120
|
+
return callbackResult;
|
|
121
|
+
}
|
|
122
|
+
const newValue = colorToString(callbackResult);
|
|
123
|
+
addColorToItem(prop, callbackResult, item);
|
|
124
|
+
return newValue;
|
|
120
125
|
}
|
|
121
|
-
|
|
126
|
+
parseSVGStyle(svg, (item) => {
|
|
122
127
|
const prop = item.prop;
|
|
123
128
|
const value = item.value;
|
|
124
129
|
if (propsToCheck.indexOf(prop) === -1) {
|
|
125
|
-
return
|
|
130
|
+
return value;
|
|
126
131
|
}
|
|
127
132
|
const attr = prop;
|
|
128
|
-
checkColor(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
attr,
|
|
139
|
-
value
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
return {
|
|
143
|
-
result,
|
|
144
|
-
defaultColor,
|
|
145
|
-
rawOptions: options,
|
|
146
|
-
findColor,
|
|
147
|
-
addColorToItem,
|
|
148
|
-
getElementColor,
|
|
149
|
-
checkColor,
|
|
150
|
-
parseStyleItem
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function analyseSVG(svg, context, done) {
|
|
154
|
-
const iconData = analyseSVGStructure(svg, context.rawOptions);
|
|
133
|
+
const newValue = checkColor(attr, value);
|
|
134
|
+
if (newValue === void 0) {
|
|
135
|
+
return newValue;
|
|
136
|
+
}
|
|
137
|
+
if (item.type === "global") {
|
|
138
|
+
result.hasGlobalStyle = true;
|
|
139
|
+
}
|
|
140
|
+
return newValue;
|
|
141
|
+
});
|
|
142
|
+
const iconData = analyseSVGStructure(svg, options);
|
|
155
143
|
const { elements, tree } = iconData;
|
|
156
144
|
const cheerio = svg.$svg;
|
|
157
145
|
const removedElements = /* @__PURE__ */ new Set();
|
|
@@ -176,15 +164,15 @@ function analyseSVG(svg, context, done) {
|
|
|
176
164
|
removeChildren(element);
|
|
177
165
|
cheerio(element).remove();
|
|
178
166
|
}
|
|
179
|
-
function parseTreeItem(item
|
|
167
|
+
function parseTreeItem(item) {
|
|
180
168
|
const index = item.index;
|
|
181
169
|
if (removedElements.has(index) || parsedElements.has(index)) {
|
|
182
|
-
return
|
|
170
|
+
return;
|
|
183
171
|
}
|
|
184
172
|
parsedElements.add(index);
|
|
185
173
|
const element = elements.get(index);
|
|
186
174
|
if (element._removed) {
|
|
187
|
-
return
|
|
175
|
+
return;
|
|
188
176
|
}
|
|
189
177
|
const { tagName, attribs } = element;
|
|
190
178
|
if (item.parent) {
|
|
@@ -198,243 +186,112 @@ function analyseSVG(svg, context, done) {
|
|
|
198
186
|
};
|
|
199
187
|
}
|
|
200
188
|
}
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (prop === "fill" && animateTags.has(tagName)) {
|
|
206
|
-
continue;
|
|
207
|
-
}
|
|
208
|
-
const value = attribs[prop];
|
|
209
|
-
if (value !== void 0) {
|
|
210
|
-
propsQueue.push([prop, value]);
|
|
211
|
-
}
|
|
189
|
+
for (let i = 0; i < propsToCheck.length; i++) {
|
|
190
|
+
const prop = propsToCheck[i];
|
|
191
|
+
if (prop === "fill" && animateTags.has(tagName)) {
|
|
192
|
+
continue;
|
|
212
193
|
}
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (newValue !== value) {
|
|
222
|
-
if (newValue === void 0) {
|
|
223
|
-
cheerio(element).removeAttr(prop);
|
|
224
|
-
if (element._colors) {
|
|
225
|
-
delete element._colors[prop];
|
|
226
|
-
}
|
|
227
|
-
} else if (newValue === "remove") {
|
|
228
|
-
removeElement(index, element);
|
|
229
|
-
} else {
|
|
230
|
-
cheerio(element).attr(prop, newValue);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return parsePropsQueue();
|
|
234
|
-
},
|
|
235
|
-
prop,
|
|
236
|
-
value,
|
|
237
|
-
element
|
|
238
|
-
);
|
|
239
|
-
};
|
|
240
|
-
parsePropsQueue();
|
|
241
|
-
}
|
|
242
|
-
function checkAnimations(done3) {
|
|
243
|
-
const propsQueue = [];
|
|
244
|
-
if (animateTags.has(tagName)) {
|
|
245
|
-
const attr = attribs.attributeName;
|
|
246
|
-
if (propsToCheck.indexOf(attr) !== -1) {
|
|
247
|
-
for (let i = 0; i < animatePropsToCheck.length; i++) {
|
|
248
|
-
const elementProp = animatePropsToCheck[i];
|
|
249
|
-
const fullValue = attribs[elementProp];
|
|
250
|
-
if (typeof fullValue !== "string") {
|
|
251
|
-
continue;
|
|
194
|
+
const value = attribs[prop];
|
|
195
|
+
if (value !== void 0) {
|
|
196
|
+
const newValue = checkColor(prop, value, element);
|
|
197
|
+
if (newValue !== value) {
|
|
198
|
+
if (newValue === void 0) {
|
|
199
|
+
cheerio(element).removeAttr(prop);
|
|
200
|
+
if (element._colors) {
|
|
201
|
+
delete element._colors[prop];
|
|
252
202
|
}
|
|
253
|
-
|
|
203
|
+
} else if (newValue === "remove") {
|
|
204
|
+
removeElement(index, element);
|
|
205
|
+
return;
|
|
206
|
+
} else {
|
|
207
|
+
cheerio(element).attr(prop, newValue);
|
|
254
208
|
}
|
|
255
209
|
}
|
|
256
210
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
211
|
+
}
|
|
212
|
+
if (animateTags.has(tagName)) {
|
|
213
|
+
const attr = attribs.attributeName;
|
|
214
|
+
if (propsToCheck.indexOf(attr) !== -1) {
|
|
215
|
+
for (let i = 0; i < animatePropsToCheck.length; i++) {
|
|
216
|
+
const elementProp = animatePropsToCheck[i];
|
|
217
|
+
const fullValue = attribs[elementProp];
|
|
218
|
+
if (typeof fullValue !== "string") {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const splitValues = fullValue.split(";");
|
|
222
|
+
let updatedValues = false;
|
|
223
|
+
for (let j = 0; j < splitValues.length; j++) {
|
|
224
|
+
const value = splitValues[j];
|
|
225
|
+
if (value !== void 0) {
|
|
226
|
+
const newValue = checkColor(
|
|
227
|
+
elementProp,
|
|
228
|
+
value
|
|
229
|
+
// Do not pass third parameter
|
|
230
|
+
);
|
|
231
|
+
if (newValue !== value) {
|
|
232
|
+
updatedValues = true;
|
|
233
|
+
splitValues[j] = typeof newValue === "string" ? newValue : "";
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
266
237
|
if (updatedValues) {
|
|
267
238
|
cheerio(element).attr(
|
|
268
239
|
elementProp,
|
|
269
240
|
splitValues.join(";")
|
|
270
241
|
);
|
|
271
242
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const parseItem = (index2) => {
|
|
275
|
-
if (index2 >= splitValues.length) {
|
|
276
|
-
return parsedAllItems();
|
|
277
|
-
}
|
|
278
|
-
const value = splitValues[index2];
|
|
279
|
-
if (value === void 0) {
|
|
280
|
-
return parseItem(index2 + 1);
|
|
281
|
-
}
|
|
282
|
-
context.checkColor(
|
|
283
|
-
(newValue) => {
|
|
284
|
-
if (newValue !== value) {
|
|
285
|
-
updatedValues = true;
|
|
286
|
-
splitValues[index2] = typeof newValue === "string" ? newValue : "";
|
|
287
|
-
}
|
|
288
|
-
parseItem(index2 + 1);
|
|
289
|
-
},
|
|
290
|
-
elementProp,
|
|
291
|
-
value
|
|
292
|
-
// Do not pass third parameter
|
|
293
|
-
);
|
|
294
|
-
};
|
|
295
|
-
parseItem(0);
|
|
296
|
-
};
|
|
297
|
-
parsePropsQueue();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
298
245
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
const color = context.getElementColor(
|
|
246
|
+
if (!result.hasGlobalStyle) {
|
|
247
|
+
let requiredProps;
|
|
248
|
+
if (shapeTags.has(tagName)) {
|
|
249
|
+
requiredProps = shapeColorAttributes;
|
|
250
|
+
}
|
|
251
|
+
specialColorAttributes.forEach((attr) => {
|
|
252
|
+
if (tagSpecificPresentationalAttributes[tagName]?.has(attr)) {
|
|
253
|
+
requiredProps = [attr];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
if (requiredProps) {
|
|
257
|
+
const itemColors = element._colors || (element._colors = {});
|
|
258
|
+
for (let i = 0; i < requiredProps.length; i++) {
|
|
259
|
+
const prop = requiredProps[i];
|
|
260
|
+
const color = getElementColor(prop, item, elements);
|
|
261
|
+
if (color === defaultBlackColor) {
|
|
262
|
+
if (defaultColor) {
|
|
263
|
+
const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
|
|
318
264
|
prop,
|
|
265
|
+
element,
|
|
319
266
|
item,
|
|
320
|
-
|
|
267
|
+
iconData
|
|
268
|
+
) : defaultColor;
|
|
269
|
+
findColor(defaultColorValue, true);
|
|
270
|
+
cheerio(element).attr(
|
|
271
|
+
prop,
|
|
272
|
+
colorToString(defaultColorValue)
|
|
321
273
|
);
|
|
322
|
-
|
|
323
|
-
const defaultColor = context.defaultColor;
|
|
324
|
-
if (defaultColor) {
|
|
325
|
-
const defaultColorValue = typeof defaultColor === "function" ? defaultColor(
|
|
326
|
-
prop,
|
|
327
|
-
element,
|
|
328
|
-
item,
|
|
329
|
-
iconData
|
|
330
|
-
) : defaultColor;
|
|
331
|
-
context.findColor(defaultColorValue, true);
|
|
332
|
-
cheerio(element).attr(
|
|
333
|
-
prop,
|
|
334
|
-
colorToString(defaultColorValue)
|
|
335
|
-
);
|
|
336
|
-
itemColors[prop] = defaultColorValue;
|
|
337
|
-
} else {
|
|
338
|
-
context.result.hasUnsetColor = true;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
let index2 = 0;
|
|
345
|
-
const parseChildItem = () => {
|
|
346
|
-
if (index2 >= item.children.length) {
|
|
347
|
-
return done2();
|
|
348
|
-
}
|
|
349
|
-
const childItem = item.children[index2];
|
|
350
|
-
index2++;
|
|
351
|
-
if (!childItem.usedAsMask) {
|
|
352
|
-
parseTreeItem(childItem, parseChildItem);
|
|
353
|
-
} else {
|
|
354
|
-
parseChildItem();
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
parseChildItem();
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
parseTreeItem(tree, done);
|
|
362
|
-
}
|
|
363
|
-
function parseColors(svg, options = {}) {
|
|
364
|
-
const callback = options.callback;
|
|
365
|
-
return new Promise((fulfill, reject) => {
|
|
366
|
-
let context;
|
|
367
|
-
try {
|
|
368
|
-
context = createContext(
|
|
369
|
-
options,
|
|
370
|
-
callback ? (params, done) => {
|
|
371
|
-
try {
|
|
372
|
-
const result = callback(...params);
|
|
373
|
-
if (result instanceof Promise) {
|
|
374
|
-
result.then(done).catch(reject);
|
|
274
|
+
itemColors[prop] = defaultColorValue;
|
|
375
275
|
} else {
|
|
376
|
-
|
|
276
|
+
result.hasUnsetColor = true;
|
|
377
277
|
}
|
|
378
|
-
} catch (err) {
|
|
379
|
-
reject(err);
|
|
380
278
|
}
|
|
381
|
-
} : void 0
|
|
382
|
-
);
|
|
383
|
-
} catch (err) {
|
|
384
|
-
reject(err);
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
parseSVGStyle(svg, (item) => {
|
|
388
|
-
return new Promise((fulfill2, reject2) => {
|
|
389
|
-
try {
|
|
390
|
-
context.parseStyleItem(item, fulfill2);
|
|
391
|
-
} catch (err) {
|
|
392
|
-
reject2(err);
|
|
393
279
|
}
|
|
394
|
-
});
|
|
395
|
-
}).then(() => {
|
|
396
|
-
try {
|
|
397
|
-
analyseSVG(svg, context, () => {
|
|
398
|
-
fulfill(context.result);
|
|
399
|
-
});
|
|
400
|
-
} catch (err) {
|
|
401
|
-
reject(err);
|
|
402
280
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const context = createContext(
|
|
409
|
-
options,
|
|
410
|
-
callback ? (params, done) => {
|
|
411
|
-
done(callback(...params));
|
|
412
|
-
} : void 0
|
|
413
|
-
);
|
|
414
|
-
parseSVGStyleSync(svg, (item) => {
|
|
415
|
-
let isSync2 = true;
|
|
416
|
-
let result;
|
|
417
|
-
context.parseStyleItem(item, (value) => {
|
|
418
|
-
if (!isSync2) {
|
|
419
|
-
throw new Error("parseStyleItem callback supposed to be sync");
|
|
281
|
+
}
|
|
282
|
+
for (let i = 0; i < item.children.length; i++) {
|
|
283
|
+
const childItem = item.children[i];
|
|
284
|
+
if (!childItem.usedAsMask) {
|
|
285
|
+
parseTreeItem(childItem);
|
|
420
286
|
}
|
|
421
|
-
result = value;
|
|
422
|
-
});
|
|
423
|
-
isSync2 = false;
|
|
424
|
-
return result;
|
|
425
|
-
});
|
|
426
|
-
let isSync = true;
|
|
427
|
-
analyseSVG(svg, context, () => {
|
|
428
|
-
if (!isSync) {
|
|
429
|
-
throw new Error("analyseSVG callback supposed to be sync");
|
|
430
287
|
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return
|
|
288
|
+
}
|
|
289
|
+
parseTreeItem(tree);
|
|
290
|
+
return result;
|
|
434
291
|
}
|
|
435
292
|
function isEmptyColor(color) {
|
|
436
293
|
const type = color.type;
|
|
437
294
|
return type === "none" || type === "transparent";
|
|
438
295
|
}
|
|
439
296
|
|
|
440
|
-
export { isEmptyColor, parseColors
|
|
297
|
+
export { isEmptyColor, parseColors };
|
package/lib/colors/validate.cjs
CHANGED
|
@@ -17,7 +17,8 @@ require('../svg/data/attributes.cjs');
|
|
|
17
17
|
require('../svg/analyse.cjs');
|
|
18
18
|
require('../svg/analyse/error.cjs');
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function validateColors(svg, expectMonotone, options) {
|
|
21
|
+
const palette = colors_parse.parseColors(svg, options);
|
|
21
22
|
palette.colors.forEach((color) => {
|
|
22
23
|
if (typeof color === "string") {
|
|
23
24
|
throw new Error("Unexpected color: " + color);
|
|
@@ -49,17 +50,7 @@ function checkPalette(palette, expectMonotone) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
});
|
|
52
|
-
}
|
|
53
|
-
async function validateColors(svg, expectMonotone, options) {
|
|
54
|
-
const palette = await colors_parse.parseColors(svg, options);
|
|
55
|
-
checkPalette(palette, expectMonotone);
|
|
56
|
-
return palette;
|
|
57
|
-
}
|
|
58
|
-
function validateColorsSync(svg, expectMonotone, options) {
|
|
59
|
-
const palette = colors_parse.parseColorsSync(svg, options);
|
|
60
|
-
checkPalette(palette, expectMonotone);
|
|
61
53
|
return palette;
|
|
62
54
|
}
|
|
63
55
|
|
|
64
56
|
exports.validateColors = validateColors;
|
|
65
|
-
exports.validateColorsSync = validateColorsSync;
|
package/lib/colors/validate.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SVG } from '../svg/index.js';
|
|
2
|
-
import { ParseColorsOptions, FindColorsResult
|
|
2
|
+
import { ParseColorsOptions, FindColorsResult } from './parse.js';
|
|
3
|
+
import 'cheerio';
|
|
3
4
|
import '@iconify/types';
|
|
4
5
|
import '@iconify/utils/lib/customisations/defaults';
|
|
5
6
|
import '@iconify/utils/lib/colors/types';
|
|
6
7
|
import './attribs.js';
|
|
7
8
|
import '../svg/analyse/types.js';
|
|
9
|
+
import '../misc/cheerio.js';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Validate colors in icon
|
|
@@ -13,14 +15,6 @@ import '../svg/analyse/types.js';
|
|
|
13
15
|
*
|
|
14
16
|
* Throws exception on error
|
|
15
17
|
*/
|
|
16
|
-
declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions):
|
|
17
|
-
/**
|
|
18
|
-
* Validate colors in icon, synchronous version
|
|
19
|
-
*
|
|
20
|
-
* If icon is monotone,
|
|
21
|
-
*
|
|
22
|
-
* Throws exception on error
|
|
23
|
-
*/
|
|
24
|
-
declare function validateColorsSync(svg: SVG, expectMonotone: boolean, options?: ParseColorsSyncOptions): FindColorsResult;
|
|
18
|
+
declare function validateColors(svg: SVG, expectMonotone: boolean, options?: ParseColorsOptions): FindColorsResult;
|
|
25
19
|
|
|
26
|
-
export { validateColors
|
|
20
|
+
export { validateColors };
|
package/lib/colors/validate.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { colorToString } from '@iconify/utils/lib/colors';
|
|
2
|
-
import { parseColors
|
|
2
|
+
import { parseColors } from './parse.mjs';
|
|
3
3
|
import '../svg/data/tags.mjs';
|
|
4
4
|
import '../svg/parse-style.mjs';
|
|
5
5
|
import '../css/parse.mjs';
|
|
@@ -15,7 +15,8 @@ import '../svg/data/attributes.mjs';
|
|
|
15
15
|
import '../svg/analyse.mjs';
|
|
16
16
|
import '../svg/analyse/error.mjs';
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function validateColors(svg, expectMonotone, options) {
|
|
19
|
+
const palette = parseColors(svg, options);
|
|
19
20
|
palette.colors.forEach((color) => {
|
|
20
21
|
if (typeof color === "string") {
|
|
21
22
|
throw new Error("Unexpected color: " + color);
|
|
@@ -47,16 +48,7 @@ function checkPalette(palette, expectMonotone) {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
|
-
}
|
|
51
|
-
async function validateColors(svg, expectMonotone, options) {
|
|
52
|
-
const palette = await parseColors(svg, options);
|
|
53
|
-
checkPalette(palette, expectMonotone);
|
|
54
|
-
return palette;
|
|
55
|
-
}
|
|
56
|
-
function validateColorsSync(svg, expectMonotone, options) {
|
|
57
|
-
const palette = parseColorsSync(svg, options);
|
|
58
|
-
checkPalette(palette, expectMonotone);
|
|
59
51
|
return palette;
|
|
60
52
|
}
|
|
61
53
|
|
|
62
|
-
export { validateColors
|
|
54
|
+
export { validateColors };
|
|
@@ -5,6 +5,7 @@ import '@iconify/types';
|
|
|
5
5
|
import '@iconify/utils/lib/customisations/defaults';
|
|
6
6
|
import '../icon-set/types.js';
|
|
7
7
|
import '../svg/index.js';
|
|
8
|
+
import 'cheerio';
|
|
8
9
|
import '@iconify/utils/lib/icon-set/tree';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -18,7 +19,9 @@ interface ExportIconPackageOptions extends ExportTargetOptions, ExportOptionsWit
|
|
|
18
19
|
/**
|
|
19
20
|
* Export icon set as single icon packages
|
|
20
21
|
*
|
|
21
|
-
*
|
|
22
|
+
* Was used for exporting `@iconify-icons/{prefix}` packages
|
|
23
|
+
*
|
|
24
|
+
* @deprecated Packages with single icons are no longer maintained.
|
|
22
25
|
*/
|
|
23
26
|
declare function exportIconPackage(iconSet: IconSet, options: ExportIconPackageOptions): Promise<string[]>;
|
|
24
27
|
|
|
@@ -135,6 +135,7 @@ async function exportJSONPackage(iconSet, options) {
|
|
|
135
135
|
);
|
|
136
136
|
files.add("index.d.ts");
|
|
137
137
|
await export_helpers_customFiles.exportCustomFiles(dir, options, files);
|
|
138
|
+
options.customisePackage?.(packageJSON);
|
|
138
139
|
await misc_writeJson.writeJSONFile(dir + "/package.json", packageJSON);
|
|
139
140
|
files.add("package.json");
|
|
140
141
|
return Array.from(files);
|
|
@@ -5,6 +5,7 @@ import '@iconify/types';
|
|
|
5
5
|
import '@iconify/utils/lib/customisations/defaults';
|
|
6
6
|
import '../icon-set/types.js';
|
|
7
7
|
import '../svg/index.js';
|
|
8
|
+
import 'cheerio';
|
|
8
9
|
import '@iconify/utils/lib/icon-set/tree';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -12,6 +13,7 @@ import '@iconify/utils/lib/icon-set/tree';
|
|
|
12
13
|
*/
|
|
13
14
|
interface ExportJSONPackageOptions extends ExportTargetOptions, ExportOptionsWithCustomFiles {
|
|
14
15
|
package?: Record<string, unknown>;
|
|
16
|
+
customisePackage?: (contents: Record<string, unknown>) => void;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Export icon set as JSON package
|
|
@@ -133,6 +133,7 @@ async function exportJSONPackage(iconSet, options) {
|
|
|
133
133
|
);
|
|
134
134
|
files.add("index.d.ts");
|
|
135
135
|
await exportCustomFiles(dir, options, files);
|
|
136
|
+
options.customisePackage?.(packageJSON);
|
|
136
137
|
await writeJSONFile(dir + "/package.json", packageJSON);
|
|
137
138
|
files.add("package.json");
|
|
138
139
|
return Array.from(files);
|
package/lib/icon-set/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IconifyIconCustomisations } from '@iconify/utils/lib/customisations/def
|
|
|
3
3
|
import { IconSetIconEntry, IconCategory, IconSetIconType, IconSetAsyncForEachCallback, IconSetSyncForEachCallback, ResolvedIconifyIcon, CommonIconProps, CheckThemeResult } from './types.js';
|
|
4
4
|
import { SVG } from '../svg/index.js';
|
|
5
5
|
import { ParentIconsTree } from '@iconify/utils/lib/icon-set/tree';
|
|
6
|
+
import 'cheerio';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Sort theme keys: long keys first
|