@histoire/vendors 0.8.0

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.
@@ -0,0 +1,2070 @@
1
+ import { x as h, d as defineComponent } from './vue.runtime.esm-bundler.js';
2
+
3
+ const matchName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
4
+ const iconDefaults = Object.freeze({
5
+ left: 0,
6
+ top: 0,
7
+ width: 16,
8
+ height: 16,
9
+ rotate: 0,
10
+ vFlip: false,
11
+ hFlip: false
12
+ });
13
+ function fullIcon(data) {
14
+ return { ...iconDefaults, ...data };
15
+ }
16
+
17
+ const stringToIcon = (value, validate, allowSimpleName, provider = "") => {
18
+ const colonSeparated = value.split(":");
19
+ if (value.slice(0, 1) === "@") {
20
+ if (colonSeparated.length < 2 || colonSeparated.length > 3) {
21
+ return null;
22
+ }
23
+ provider = colonSeparated.shift().slice(1);
24
+ }
25
+ if (colonSeparated.length > 3 || !colonSeparated.length) {
26
+ return null;
27
+ }
28
+ if (colonSeparated.length > 1) {
29
+ const name2 = colonSeparated.pop();
30
+ const prefix = colonSeparated.pop();
31
+ const result = {
32
+ provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
33
+ prefix,
34
+ name: name2
35
+ };
36
+ return validate && !validateIcon(result) ? null : result;
37
+ }
38
+ const name = colonSeparated[0];
39
+ const dashSeparated = name.split("-");
40
+ if (dashSeparated.length > 1) {
41
+ const result = {
42
+ provider,
43
+ prefix: dashSeparated.shift(),
44
+ name: dashSeparated.join("-")
45
+ };
46
+ return validate && !validateIcon(result) ? null : result;
47
+ }
48
+ if (allowSimpleName && provider === "") {
49
+ const result = {
50
+ provider,
51
+ prefix: "",
52
+ name
53
+ };
54
+ return validate && !validateIcon(result, allowSimpleName) ? null : result;
55
+ }
56
+ return null;
57
+ };
58
+ const validateIcon = (icon, allowSimpleName) => {
59
+ if (!icon) {
60
+ return false;
61
+ }
62
+ return !!((icon.provider === "" || icon.provider.match(matchName)) && (allowSimpleName && icon.prefix === "" || icon.prefix.match(matchName)) && icon.name.match(matchName));
63
+ };
64
+
65
+ function mergeIconData(icon, alias) {
66
+ const result = { ...icon };
67
+ for (const key in iconDefaults) {
68
+ const prop = key;
69
+ if (alias[prop] !== void 0) {
70
+ const value = alias[prop];
71
+ if (result[prop] === void 0) {
72
+ result[prop] = value;
73
+ continue;
74
+ }
75
+ switch (prop) {
76
+ case "rotate":
77
+ result[prop] = (result[prop] + value) % 4;
78
+ break;
79
+ case "hFlip":
80
+ case "vFlip":
81
+ result[prop] = value !== result[prop];
82
+ break;
83
+ default:
84
+ result[prop] = value;
85
+ }
86
+ }
87
+ }
88
+ return result;
89
+ }
90
+
91
+ function getIconData$1(data, name, full = false) {
92
+ function getIcon(name2, iteration) {
93
+ if (data.icons[name2] !== void 0) {
94
+ return Object.assign({}, data.icons[name2]);
95
+ }
96
+ if (iteration > 5) {
97
+ return null;
98
+ }
99
+ const aliases = data.aliases;
100
+ if (aliases && aliases[name2] !== void 0) {
101
+ const item = aliases[name2];
102
+ const result2 = getIcon(item.parent, iteration + 1);
103
+ if (result2) {
104
+ return mergeIconData(result2, item);
105
+ }
106
+ return result2;
107
+ }
108
+ const chars = data.chars;
109
+ if (!iteration && chars && chars[name2] !== void 0) {
110
+ return getIcon(chars[name2], iteration + 1);
111
+ }
112
+ return null;
113
+ }
114
+ const result = getIcon(name, 0);
115
+ if (result) {
116
+ for (const key in iconDefaults) {
117
+ if (result[key] === void 0 && data[key] !== void 0) {
118
+ result[key] = data[key];
119
+ }
120
+ }
121
+ }
122
+ return result && full ? fullIcon(result) : result;
123
+ }
124
+
125
+ function isVariation(item) {
126
+ for (const key in iconDefaults) {
127
+ if (item[key] !== void 0) {
128
+ return true;
129
+ }
130
+ }
131
+ return false;
132
+ }
133
+ function parseIconSet(data, callback, options) {
134
+ options = options || {};
135
+ const names = [];
136
+ if (typeof data !== "object" || typeof data.icons !== "object") {
137
+ return names;
138
+ }
139
+ if (data.not_found instanceof Array) {
140
+ data.not_found.forEach((name) => {
141
+ callback(name, null);
142
+ names.push(name);
143
+ });
144
+ }
145
+ const icons = data.icons;
146
+ Object.keys(icons).forEach((name) => {
147
+ const iconData = getIconData$1(data, name, true);
148
+ if (iconData) {
149
+ callback(name, iconData);
150
+ names.push(name);
151
+ }
152
+ });
153
+ const parseAliases = options.aliases || "all";
154
+ if (parseAliases !== "none" && typeof data.aliases === "object") {
155
+ const aliases = data.aliases;
156
+ Object.keys(aliases).forEach((name) => {
157
+ if (parseAliases === "variations" && isVariation(aliases[name])) {
158
+ return;
159
+ }
160
+ const iconData = getIconData$1(data, name, true);
161
+ if (iconData) {
162
+ callback(name, iconData);
163
+ names.push(name);
164
+ }
165
+ });
166
+ }
167
+ return names;
168
+ }
169
+
170
+ const optionalProperties = {
171
+ provider: "string",
172
+ aliases: "object",
173
+ not_found: "object"
174
+ };
175
+ for (const prop in iconDefaults) {
176
+ optionalProperties[prop] = typeof iconDefaults[prop];
177
+ }
178
+ function quicklyValidateIconSet(obj) {
179
+ if (typeof obj !== "object" || obj === null) {
180
+ return null;
181
+ }
182
+ const data = obj;
183
+ if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
184
+ return null;
185
+ }
186
+ for (const prop in optionalProperties) {
187
+ if (obj[prop] !== void 0 && typeof obj[prop] !== optionalProperties[prop]) {
188
+ return null;
189
+ }
190
+ }
191
+ const icons = data.icons;
192
+ for (const name in icons) {
193
+ const icon = icons[name];
194
+ if (!name.match(matchName) || typeof icon.body !== "string") {
195
+ return null;
196
+ }
197
+ for (const prop in iconDefaults) {
198
+ if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) {
199
+ return null;
200
+ }
201
+ }
202
+ }
203
+ const aliases = data.aliases;
204
+ if (aliases) {
205
+ for (const name in aliases) {
206
+ const icon = aliases[name];
207
+ const parent = icon.parent;
208
+ if (!name.match(matchName) || typeof parent !== "string" || !icons[parent] && !aliases[parent]) {
209
+ return null;
210
+ }
211
+ for (const prop in iconDefaults) {
212
+ if (icon[prop] !== void 0 && typeof icon[prop] !== typeof iconDefaults[prop]) {
213
+ return null;
214
+ }
215
+ }
216
+ }
217
+ }
218
+ return data;
219
+ }
220
+
221
+ const storageVersion = 1;
222
+ let storage$1 = /* @__PURE__ */ Object.create(null);
223
+ try {
224
+ const w = window || self;
225
+ if (w && w._iconifyStorage.version === storageVersion) {
226
+ storage$1 = w._iconifyStorage.storage;
227
+ }
228
+ } catch (err) {
229
+ }
230
+ function shareStorage() {
231
+ try {
232
+ const w = window || self;
233
+ if (w && !w._iconifyStorage) {
234
+ w._iconifyStorage = {
235
+ version: storageVersion,
236
+ storage: storage$1
237
+ };
238
+ }
239
+ } catch (err) {
240
+ }
241
+ }
242
+ function newStorage(provider, prefix) {
243
+ return {
244
+ provider,
245
+ prefix,
246
+ icons: /* @__PURE__ */ Object.create(null),
247
+ missing: /* @__PURE__ */ Object.create(null)
248
+ };
249
+ }
250
+ function getStorage(provider, prefix) {
251
+ if (storage$1[provider] === void 0) {
252
+ storage$1[provider] = /* @__PURE__ */ Object.create(null);
253
+ }
254
+ const providerStorage = storage$1[provider];
255
+ if (providerStorage[prefix] === void 0) {
256
+ providerStorage[prefix] = newStorage(provider, prefix);
257
+ }
258
+ return providerStorage[prefix];
259
+ }
260
+ function addIconSet(storage2, data) {
261
+ if (!quicklyValidateIconSet(data)) {
262
+ return [];
263
+ }
264
+ const t = Date.now();
265
+ return parseIconSet(data, (name, icon) => {
266
+ if (icon) {
267
+ storage2.icons[name] = icon;
268
+ } else {
269
+ storage2.missing[name] = t;
270
+ }
271
+ });
272
+ }
273
+ function addIconToStorage(storage2, name, icon) {
274
+ try {
275
+ if (typeof icon.body === "string") {
276
+ storage2.icons[name] = Object.freeze(fullIcon(icon));
277
+ return true;
278
+ }
279
+ } catch (err) {
280
+ }
281
+ return false;
282
+ }
283
+ function getIconFromStorage(storage2, name) {
284
+ const value = storage2.icons[name];
285
+ return value === void 0 ? null : value;
286
+ }
287
+ function listIcons(provider, prefix) {
288
+ let allIcons = [];
289
+ let providers;
290
+ if (typeof provider === "string") {
291
+ providers = [provider];
292
+ } else {
293
+ providers = Object.keys(storage$1);
294
+ }
295
+ providers.forEach((provider2) => {
296
+ let prefixes;
297
+ if (typeof provider2 === "string" && typeof prefix === "string") {
298
+ prefixes = [prefix];
299
+ } else {
300
+ prefixes = storage$1[provider2] === void 0 ? [] : Object.keys(storage$1[provider2]);
301
+ }
302
+ prefixes.forEach((prefix2) => {
303
+ const storage2 = getStorage(provider2, prefix2);
304
+ const icons = Object.keys(storage2.icons).map((name) => (provider2 !== "" ? "@" + provider2 + ":" : "") + prefix2 + ":" + name);
305
+ allIcons = allIcons.concat(icons);
306
+ });
307
+ });
308
+ return allIcons;
309
+ }
310
+
311
+ let simpleNames = false;
312
+ function allowSimpleNames(allow) {
313
+ if (typeof allow === "boolean") {
314
+ simpleNames = allow;
315
+ }
316
+ return simpleNames;
317
+ }
318
+ function getIconData(name) {
319
+ const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name;
320
+ return icon ? getIconFromStorage(getStorage(icon.provider, icon.prefix), icon.name) : null;
321
+ }
322
+ function addIcon(name, data) {
323
+ const icon = stringToIcon(name, true, simpleNames);
324
+ if (!icon) {
325
+ return false;
326
+ }
327
+ const storage = getStorage(icon.provider, icon.prefix);
328
+ return addIconToStorage(storage, icon.name, data);
329
+ }
330
+ function addCollection(data, provider) {
331
+ if (typeof data !== "object") {
332
+ return false;
333
+ }
334
+ if (typeof provider !== "string") {
335
+ provider = typeof data.provider === "string" ? data.provider : "";
336
+ }
337
+ if (simpleNames && provider === "" && (typeof data.prefix !== "string" || data.prefix === "")) {
338
+ let added = false;
339
+ if (quicklyValidateIconSet(data)) {
340
+ data.prefix = "";
341
+ parseIconSet(data, (name, icon) => {
342
+ if (icon && addIcon(name, icon)) {
343
+ added = true;
344
+ }
345
+ });
346
+ }
347
+ return added;
348
+ }
349
+ if (typeof data.prefix !== "string" || !validateIcon({
350
+ provider,
351
+ prefix: data.prefix,
352
+ name: "a"
353
+ })) {
354
+ return false;
355
+ }
356
+ const storage = getStorage(provider, data.prefix);
357
+ return !!addIconSet(storage, data);
358
+ }
359
+ function iconExists(name) {
360
+ return getIconData(name) !== null;
361
+ }
362
+ function getIcon(name) {
363
+ const result = getIconData(name);
364
+ return result ? { ...result } : null;
365
+ }
366
+
367
+ const defaults = Object.freeze({
368
+ inline: false,
369
+ width: null,
370
+ height: null,
371
+ hAlign: "center",
372
+ vAlign: "middle",
373
+ slice: false,
374
+ hFlip: false,
375
+ vFlip: false,
376
+ rotate: 0
377
+ });
378
+ function mergeCustomisations(defaults2, item) {
379
+ const result = {};
380
+ for (const key in defaults2) {
381
+ const attr = key;
382
+ result[attr] = defaults2[attr];
383
+ if (item[attr] === void 0) {
384
+ continue;
385
+ }
386
+ const value = item[attr];
387
+ switch (attr) {
388
+ case "inline":
389
+ case "slice":
390
+ if (typeof value === "boolean") {
391
+ result[attr] = value;
392
+ }
393
+ break;
394
+ case "hFlip":
395
+ case "vFlip":
396
+ if (value === true) {
397
+ result[attr] = !result[attr];
398
+ }
399
+ break;
400
+ case "hAlign":
401
+ case "vAlign":
402
+ if (typeof value === "string" && value !== "") {
403
+ result[attr] = value;
404
+ }
405
+ break;
406
+ case "width":
407
+ case "height":
408
+ if (typeof value === "string" && value !== "" || typeof value === "number" && value || value === null) {
409
+ result[attr] = value;
410
+ }
411
+ break;
412
+ case "rotate":
413
+ if (typeof value === "number") {
414
+ result[attr] += value;
415
+ }
416
+ break;
417
+ }
418
+ }
419
+ return result;
420
+ }
421
+
422
+ const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
423
+ const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
424
+ function calculateSize(size, ratio, precision) {
425
+ if (ratio === 1) {
426
+ return size;
427
+ }
428
+ precision = precision === void 0 ? 100 : precision;
429
+ if (typeof size === "number") {
430
+ return Math.ceil(size * ratio * precision) / precision;
431
+ }
432
+ if (typeof size !== "string") {
433
+ return size;
434
+ }
435
+ const oldParts = size.split(unitsSplit);
436
+ if (oldParts === null || !oldParts.length) {
437
+ return size;
438
+ }
439
+ const newParts = [];
440
+ let code = oldParts.shift();
441
+ let isNumber = unitsTest.test(code);
442
+ while (true) {
443
+ if (isNumber) {
444
+ const num = parseFloat(code);
445
+ if (isNaN(num)) {
446
+ newParts.push(code);
447
+ } else {
448
+ newParts.push(Math.ceil(num * ratio * precision) / precision);
449
+ }
450
+ } else {
451
+ newParts.push(code);
452
+ }
453
+ code = oldParts.shift();
454
+ if (code === void 0) {
455
+ return newParts.join("");
456
+ }
457
+ isNumber = !isNumber;
458
+ }
459
+ }
460
+
461
+ function preserveAspectRatio(props) {
462
+ let result = "";
463
+ switch (props.hAlign) {
464
+ case "left":
465
+ result += "xMin";
466
+ break;
467
+ case "right":
468
+ result += "xMax";
469
+ break;
470
+ default:
471
+ result += "xMid";
472
+ }
473
+ switch (props.vAlign) {
474
+ case "top":
475
+ result += "YMin";
476
+ break;
477
+ case "bottom":
478
+ result += "YMax";
479
+ break;
480
+ default:
481
+ result += "YMid";
482
+ }
483
+ result += props.slice ? " slice" : " meet";
484
+ return result;
485
+ }
486
+ function iconToSVG(icon, customisations) {
487
+ const box = {
488
+ left: icon.left,
489
+ top: icon.top,
490
+ width: icon.width,
491
+ height: icon.height
492
+ };
493
+ let body = icon.body;
494
+ [icon, customisations].forEach((props) => {
495
+ const transformations = [];
496
+ const hFlip = props.hFlip;
497
+ const vFlip = props.vFlip;
498
+ let rotation = props.rotate;
499
+ if (hFlip) {
500
+ if (vFlip) {
501
+ rotation += 2;
502
+ } else {
503
+ transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")");
504
+ transformations.push("scale(-1 1)");
505
+ box.top = box.left = 0;
506
+ }
507
+ } else if (vFlip) {
508
+ transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")");
509
+ transformations.push("scale(1 -1)");
510
+ box.top = box.left = 0;
511
+ }
512
+ let tempValue;
513
+ if (rotation < 0) {
514
+ rotation -= Math.floor(rotation / 4) * 4;
515
+ }
516
+ rotation = rotation % 4;
517
+ switch (rotation) {
518
+ case 1:
519
+ tempValue = box.height / 2 + box.top;
520
+ transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")");
521
+ break;
522
+ case 2:
523
+ transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")");
524
+ break;
525
+ case 3:
526
+ tempValue = box.width / 2 + box.left;
527
+ transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")");
528
+ break;
529
+ }
530
+ if (rotation % 2 === 1) {
531
+ if (box.left !== 0 || box.top !== 0) {
532
+ tempValue = box.left;
533
+ box.left = box.top;
534
+ box.top = tempValue;
535
+ }
536
+ if (box.width !== box.height) {
537
+ tempValue = box.width;
538
+ box.width = box.height;
539
+ box.height = tempValue;
540
+ }
541
+ }
542
+ if (transformations.length) {
543
+ body = '<g transform="' + transformations.join(" ") + '">' + body + "</g>";
544
+ }
545
+ });
546
+ let width, height;
547
+ if (customisations.width === null && customisations.height === null) {
548
+ height = "1em";
549
+ width = calculateSize(height, box.width / box.height);
550
+ } else if (customisations.width !== null && customisations.height !== null) {
551
+ width = customisations.width;
552
+ height = customisations.height;
553
+ } else if (customisations.height !== null) {
554
+ height = customisations.height;
555
+ width = calculateSize(height, box.width / box.height);
556
+ } else {
557
+ width = customisations.width;
558
+ height = calculateSize(width, box.height / box.width);
559
+ }
560
+ if (width === "auto") {
561
+ width = box.width;
562
+ }
563
+ if (height === "auto") {
564
+ height = box.height;
565
+ }
566
+ width = typeof width === "string" ? width : width.toString() + "";
567
+ height = typeof height === "string" ? height : height.toString() + "";
568
+ const result = {
569
+ attributes: {
570
+ width,
571
+ height,
572
+ preserveAspectRatio: preserveAspectRatio(customisations),
573
+ viewBox: box.left.toString() + " " + box.top.toString() + " " + box.width.toString() + " " + box.height.toString()
574
+ },
575
+ body
576
+ };
577
+ if (customisations.inline) {
578
+ result.inline = true;
579
+ }
580
+ return result;
581
+ }
582
+
583
+ function buildIcon(icon, customisations) {
584
+ return iconToSVG(fullIcon(icon), customisations ? mergeCustomisations(defaults, customisations) : defaults);
585
+ }
586
+
587
+ const regex = /\sid="(\S+)"/g;
588
+ const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
589
+ let counter = 0;
590
+ function replaceIDs(body, prefix = randomPrefix) {
591
+ const ids = [];
592
+ let match;
593
+ while (match = regex.exec(body)) {
594
+ ids.push(match[1]);
595
+ }
596
+ if (!ids.length) {
597
+ return body;
598
+ }
599
+ ids.forEach((id) => {
600
+ const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
601
+ const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
602
+ body = body.replace(new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"), "$1" + newID + "$3");
603
+ });
604
+ return body;
605
+ }
606
+
607
+ const storage = /* @__PURE__ */ Object.create(null);
608
+ function setAPIModule(provider, item) {
609
+ storage[provider] = item;
610
+ }
611
+ function getAPIModule(provider) {
612
+ return storage[provider] || storage[""];
613
+ }
614
+
615
+ function createAPIConfig(source) {
616
+ let resources;
617
+ if (typeof source.resources === "string") {
618
+ resources = [source.resources];
619
+ } else {
620
+ resources = source.resources;
621
+ if (!(resources instanceof Array) || !resources.length) {
622
+ return null;
623
+ }
624
+ }
625
+ const result = {
626
+ resources,
627
+ path: source.path === void 0 ? "/" : source.path,
628
+ maxURL: source.maxURL ? source.maxURL : 500,
629
+ rotate: source.rotate ? source.rotate : 750,
630
+ timeout: source.timeout ? source.timeout : 5e3,
631
+ random: source.random === true,
632
+ index: source.index ? source.index : 0,
633
+ dataAfterTimeout: source.dataAfterTimeout !== false
634
+ };
635
+ return result;
636
+ }
637
+ const configStorage = /* @__PURE__ */ Object.create(null);
638
+ const fallBackAPISources = [
639
+ "https://api.simplesvg.com",
640
+ "https://api.unisvg.com"
641
+ ];
642
+ const fallBackAPI = [];
643
+ while (fallBackAPISources.length > 0) {
644
+ if (fallBackAPISources.length === 1) {
645
+ fallBackAPI.push(fallBackAPISources.shift());
646
+ } else {
647
+ if (Math.random() > 0.5) {
648
+ fallBackAPI.push(fallBackAPISources.shift());
649
+ } else {
650
+ fallBackAPI.push(fallBackAPISources.pop());
651
+ }
652
+ }
653
+ }
654
+ configStorage[""] = createAPIConfig({
655
+ resources: ["https://api.iconify.design"].concat(fallBackAPI)
656
+ });
657
+ function addAPIProvider(provider, customConfig) {
658
+ const config = createAPIConfig(customConfig);
659
+ if (config === null) {
660
+ return false;
661
+ }
662
+ configStorage[provider] = config;
663
+ return true;
664
+ }
665
+ function getAPIConfig(provider) {
666
+ return configStorage[provider];
667
+ }
668
+ function listAPIProviders() {
669
+ return Object.keys(configStorage);
670
+ }
671
+
672
+ const mergeParams = (base, params) => {
673
+ let result = base, hasParams = result.indexOf("?") !== -1;
674
+ function paramToString(value) {
675
+ switch (typeof value) {
676
+ case "boolean":
677
+ return value ? "true" : "false";
678
+ case "number":
679
+ return encodeURIComponent(value);
680
+ case "string":
681
+ return encodeURIComponent(value);
682
+ default:
683
+ throw new Error("Invalid parameter");
684
+ }
685
+ }
686
+ Object.keys(params).forEach((key) => {
687
+ let value;
688
+ try {
689
+ value = paramToString(params[key]);
690
+ } catch (err) {
691
+ return;
692
+ }
693
+ result += (hasParams ? "&" : "?") + encodeURIComponent(key) + "=" + value;
694
+ hasParams = true;
695
+ });
696
+ return result;
697
+ };
698
+
699
+ const maxLengthCache = {};
700
+ const pathCache = {};
701
+ const detectFetch = () => {
702
+ let callback;
703
+ try {
704
+ callback = fetch;
705
+ if (typeof callback === "function") {
706
+ return callback;
707
+ }
708
+ } catch (err) {
709
+ }
710
+ return null;
711
+ };
712
+ let fetchModule = detectFetch();
713
+ function setFetch(fetch2) {
714
+ fetchModule = fetch2;
715
+ }
716
+ function getFetch() {
717
+ return fetchModule;
718
+ }
719
+ function calculateMaxLength(provider, prefix) {
720
+ const config = getAPIConfig(provider);
721
+ if (!config) {
722
+ return 0;
723
+ }
724
+ let result;
725
+ if (!config.maxURL) {
726
+ result = 0;
727
+ } else {
728
+ let maxHostLength = 0;
729
+ config.resources.forEach((item) => {
730
+ const host = item;
731
+ maxHostLength = Math.max(maxHostLength, host.length);
732
+ });
733
+ const url = mergeParams(prefix + ".json", {
734
+ icons: ""
735
+ });
736
+ result = config.maxURL - maxHostLength - config.path.length - url.length;
737
+ }
738
+ const cacheKey = provider + ":" + prefix;
739
+ pathCache[provider] = config.path;
740
+ maxLengthCache[cacheKey] = result;
741
+ return result;
742
+ }
743
+ function shouldAbort(status) {
744
+ return status === 404;
745
+ }
746
+ const prepare = (provider, prefix, icons) => {
747
+ const results = [];
748
+ let maxLength = maxLengthCache[prefix];
749
+ if (maxLength === void 0) {
750
+ maxLength = calculateMaxLength(provider, prefix);
751
+ }
752
+ const type = "icons";
753
+ let item = {
754
+ type,
755
+ provider,
756
+ prefix,
757
+ icons: []
758
+ };
759
+ let length = 0;
760
+ icons.forEach((name, index) => {
761
+ length += name.length + 1;
762
+ if (length >= maxLength && index > 0) {
763
+ results.push(item);
764
+ item = {
765
+ type,
766
+ provider,
767
+ prefix,
768
+ icons: []
769
+ };
770
+ length = name.length;
771
+ }
772
+ item.icons.push(name);
773
+ });
774
+ results.push(item);
775
+ return results;
776
+ };
777
+ function getPath(provider) {
778
+ if (typeof provider === "string") {
779
+ if (pathCache[provider] === void 0) {
780
+ const config = getAPIConfig(provider);
781
+ if (!config) {
782
+ return "/";
783
+ }
784
+ pathCache[provider] = config.path;
785
+ }
786
+ return pathCache[provider];
787
+ }
788
+ return "/";
789
+ }
790
+ const send = (host, params, callback) => {
791
+ if (!fetchModule) {
792
+ callback("abort", 424);
793
+ return;
794
+ }
795
+ let path = getPath(params.provider);
796
+ switch (params.type) {
797
+ case "icons": {
798
+ const prefix = params.prefix;
799
+ const icons = params.icons;
800
+ const iconsList = icons.join(",");
801
+ path += mergeParams(prefix + ".json", {
802
+ icons: iconsList
803
+ });
804
+ break;
805
+ }
806
+ case "custom": {
807
+ const uri = params.uri;
808
+ path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri;
809
+ break;
810
+ }
811
+ default:
812
+ callback("abort", 400);
813
+ return;
814
+ }
815
+ let defaultError = 503;
816
+ fetchModule(host + path).then((response) => {
817
+ const status = response.status;
818
+ if (status !== 200) {
819
+ setTimeout(() => {
820
+ callback(shouldAbort(status) ? "abort" : "next", status);
821
+ });
822
+ return;
823
+ }
824
+ defaultError = 501;
825
+ return response.json();
826
+ }).then((data) => {
827
+ if (typeof data !== "object" || data === null) {
828
+ setTimeout(() => {
829
+ callback("next", defaultError);
830
+ });
831
+ return;
832
+ }
833
+ setTimeout(() => {
834
+ callback("success", data);
835
+ });
836
+ }).catch(() => {
837
+ callback("next", defaultError);
838
+ });
839
+ };
840
+ const fetchAPIModule = {
841
+ prepare,
842
+ send
843
+ };
844
+
845
+ function sortIcons(icons) {
846
+ const result = {
847
+ loaded: [],
848
+ missing: [],
849
+ pending: []
850
+ };
851
+ const storage = /* @__PURE__ */ Object.create(null);
852
+ icons.sort((a, b) => {
853
+ if (a.provider !== b.provider) {
854
+ return a.provider.localeCompare(b.provider);
855
+ }
856
+ if (a.prefix !== b.prefix) {
857
+ return a.prefix.localeCompare(b.prefix);
858
+ }
859
+ return a.name.localeCompare(b.name);
860
+ });
861
+ let lastIcon = {
862
+ provider: "",
863
+ prefix: "",
864
+ name: ""
865
+ };
866
+ icons.forEach((icon) => {
867
+ if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) {
868
+ return;
869
+ }
870
+ lastIcon = icon;
871
+ const provider = icon.provider;
872
+ const prefix = icon.prefix;
873
+ const name = icon.name;
874
+ if (storage[provider] === void 0) {
875
+ storage[provider] = /* @__PURE__ */ Object.create(null);
876
+ }
877
+ const providerStorage = storage[provider];
878
+ if (providerStorage[prefix] === void 0) {
879
+ providerStorage[prefix] = getStorage(provider, prefix);
880
+ }
881
+ const localStorage = providerStorage[prefix];
882
+ let list;
883
+ if (localStorage.icons[name] !== void 0) {
884
+ list = result.loaded;
885
+ } else if (prefix === "" || localStorage.missing[name] !== void 0) {
886
+ list = result.missing;
887
+ } else {
888
+ list = result.pending;
889
+ }
890
+ const item = {
891
+ provider,
892
+ prefix,
893
+ name
894
+ };
895
+ list.push(item);
896
+ });
897
+ return result;
898
+ }
899
+
900
+ const callbacks = /* @__PURE__ */ Object.create(null);
901
+ const pendingUpdates = /* @__PURE__ */ Object.create(null);
902
+ function removeCallback(sources, id) {
903
+ sources.forEach((source) => {
904
+ const provider = source.provider;
905
+ if (callbacks[provider] === void 0) {
906
+ return;
907
+ }
908
+ const providerCallbacks = callbacks[provider];
909
+ const prefix = source.prefix;
910
+ const items = providerCallbacks[prefix];
911
+ if (items) {
912
+ providerCallbacks[prefix] = items.filter((row) => row.id !== id);
913
+ }
914
+ });
915
+ }
916
+ function updateCallbacks(provider, prefix) {
917
+ if (pendingUpdates[provider] === void 0) {
918
+ pendingUpdates[provider] = /* @__PURE__ */ Object.create(null);
919
+ }
920
+ const providerPendingUpdates = pendingUpdates[provider];
921
+ if (!providerPendingUpdates[prefix]) {
922
+ providerPendingUpdates[prefix] = true;
923
+ setTimeout(() => {
924
+ providerPendingUpdates[prefix] = false;
925
+ if (callbacks[provider] === void 0 || callbacks[provider][prefix] === void 0) {
926
+ return;
927
+ }
928
+ const items = callbacks[provider][prefix].slice(0);
929
+ if (!items.length) {
930
+ return;
931
+ }
932
+ const storage = getStorage(provider, prefix);
933
+ let hasPending = false;
934
+ items.forEach((item) => {
935
+ const icons = item.icons;
936
+ const oldLength = icons.pending.length;
937
+ icons.pending = icons.pending.filter((icon) => {
938
+ if (icon.prefix !== prefix) {
939
+ return true;
940
+ }
941
+ const name = icon.name;
942
+ if (storage.icons[name] !== void 0) {
943
+ icons.loaded.push({
944
+ provider,
945
+ prefix,
946
+ name
947
+ });
948
+ } else if (storage.missing[name] !== void 0) {
949
+ icons.missing.push({
950
+ provider,
951
+ prefix,
952
+ name
953
+ });
954
+ } else {
955
+ hasPending = true;
956
+ return true;
957
+ }
958
+ return false;
959
+ });
960
+ if (icons.pending.length !== oldLength) {
961
+ if (!hasPending) {
962
+ removeCallback([
963
+ {
964
+ provider,
965
+ prefix
966
+ }
967
+ ], item.id);
968
+ }
969
+ item.callback(icons.loaded.slice(0), icons.missing.slice(0), icons.pending.slice(0), item.abort);
970
+ }
971
+ });
972
+ });
973
+ }
974
+ }
975
+ let idCounter = 0;
976
+ function storeCallback(callback, icons, pendingSources) {
977
+ const id = idCounter++;
978
+ const abort = removeCallback.bind(null, pendingSources, id);
979
+ if (!icons.pending.length) {
980
+ return abort;
981
+ }
982
+ const item = {
983
+ id,
984
+ icons,
985
+ callback,
986
+ abort
987
+ };
988
+ pendingSources.forEach((source) => {
989
+ const provider = source.provider;
990
+ const prefix = source.prefix;
991
+ if (callbacks[provider] === void 0) {
992
+ callbacks[provider] = /* @__PURE__ */ Object.create(null);
993
+ }
994
+ const providerCallbacks = callbacks[provider];
995
+ if (providerCallbacks[prefix] === void 0) {
996
+ providerCallbacks[prefix] = [];
997
+ }
998
+ providerCallbacks[prefix].push(item);
999
+ });
1000
+ return abort;
1001
+ }
1002
+
1003
+ function listToIcons(list, validate = true, simpleNames = false) {
1004
+ const result = [];
1005
+ list.forEach((item) => {
1006
+ const icon = typeof item === "string" ? stringToIcon(item, false, simpleNames) : item;
1007
+ if (!validate || validateIcon(icon, simpleNames)) {
1008
+ result.push({
1009
+ provider: icon.provider,
1010
+ prefix: icon.prefix,
1011
+ name: icon.name
1012
+ });
1013
+ }
1014
+ });
1015
+ return result;
1016
+ }
1017
+
1018
+ // src/config.ts
1019
+ var defaultConfig = {
1020
+ resources: [],
1021
+ index: 0,
1022
+ timeout: 2e3,
1023
+ rotate: 750,
1024
+ random: false,
1025
+ dataAfterTimeout: false
1026
+ };
1027
+
1028
+ // src/query.ts
1029
+ function sendQuery(config, payload, query, done) {
1030
+ const resourcesCount = config.resources.length;
1031
+ const startIndex = config.random ? Math.floor(Math.random() * resourcesCount) : config.index;
1032
+ let resources;
1033
+ if (config.random) {
1034
+ let list = config.resources.slice(0);
1035
+ resources = [];
1036
+ while (list.length > 1) {
1037
+ const nextIndex = Math.floor(Math.random() * list.length);
1038
+ resources.push(list[nextIndex]);
1039
+ list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1));
1040
+ }
1041
+ resources = resources.concat(list);
1042
+ } else {
1043
+ resources = config.resources.slice(startIndex).concat(config.resources.slice(0, startIndex));
1044
+ }
1045
+ const startTime = Date.now();
1046
+ let status = "pending";
1047
+ let queriesSent = 0;
1048
+ let lastError;
1049
+ let timer = null;
1050
+ let queue = [];
1051
+ let doneCallbacks = [];
1052
+ if (typeof done === "function") {
1053
+ doneCallbacks.push(done);
1054
+ }
1055
+ function resetTimer() {
1056
+ if (timer) {
1057
+ clearTimeout(timer);
1058
+ timer = null;
1059
+ }
1060
+ }
1061
+ function abort() {
1062
+ if (status === "pending") {
1063
+ status = "aborted";
1064
+ }
1065
+ resetTimer();
1066
+ queue.forEach((item) => {
1067
+ if (item.status === "pending") {
1068
+ item.status = "aborted";
1069
+ }
1070
+ });
1071
+ queue = [];
1072
+ }
1073
+ function subscribe(callback, overwrite) {
1074
+ if (overwrite) {
1075
+ doneCallbacks = [];
1076
+ }
1077
+ if (typeof callback === "function") {
1078
+ doneCallbacks.push(callback);
1079
+ }
1080
+ }
1081
+ function getQueryStatus() {
1082
+ return {
1083
+ startTime,
1084
+ payload,
1085
+ status,
1086
+ queriesSent,
1087
+ queriesPending: queue.length,
1088
+ subscribe,
1089
+ abort
1090
+ };
1091
+ }
1092
+ function failQuery() {
1093
+ status = "failed";
1094
+ doneCallbacks.forEach((callback) => {
1095
+ callback(void 0, lastError);
1096
+ });
1097
+ }
1098
+ function clearQueue() {
1099
+ queue.forEach((item) => {
1100
+ if (item.status === "pending") {
1101
+ item.status = "aborted";
1102
+ }
1103
+ });
1104
+ queue = [];
1105
+ }
1106
+ function moduleResponse(item, response, data) {
1107
+ const isError = response !== "success";
1108
+ queue = queue.filter((queued) => queued !== item);
1109
+ switch (status) {
1110
+ case "pending":
1111
+ break;
1112
+ case "failed":
1113
+ if (isError || !config.dataAfterTimeout) {
1114
+ return;
1115
+ }
1116
+ break;
1117
+ default:
1118
+ return;
1119
+ }
1120
+ if (response === "abort") {
1121
+ lastError = data;
1122
+ failQuery();
1123
+ return;
1124
+ }
1125
+ if (isError) {
1126
+ lastError = data;
1127
+ if (!queue.length) {
1128
+ if (!resources.length) {
1129
+ failQuery();
1130
+ } else {
1131
+ execNext();
1132
+ }
1133
+ }
1134
+ return;
1135
+ }
1136
+ resetTimer();
1137
+ clearQueue();
1138
+ if (!config.random) {
1139
+ const index = config.resources.indexOf(item.resource);
1140
+ if (index !== -1 && index !== config.index) {
1141
+ config.index = index;
1142
+ }
1143
+ }
1144
+ status = "completed";
1145
+ doneCallbacks.forEach((callback) => {
1146
+ callback(data);
1147
+ });
1148
+ }
1149
+ function execNext() {
1150
+ if (status !== "pending") {
1151
+ return;
1152
+ }
1153
+ resetTimer();
1154
+ const resource = resources.shift();
1155
+ if (resource === void 0) {
1156
+ if (queue.length) {
1157
+ timer = setTimeout(() => {
1158
+ resetTimer();
1159
+ if (status === "pending") {
1160
+ clearQueue();
1161
+ failQuery();
1162
+ }
1163
+ }, config.timeout);
1164
+ return;
1165
+ }
1166
+ failQuery();
1167
+ return;
1168
+ }
1169
+ const item = {
1170
+ status: "pending",
1171
+ resource,
1172
+ callback: (status2, data) => {
1173
+ moduleResponse(item, status2, data);
1174
+ }
1175
+ };
1176
+ queue.push(item);
1177
+ queriesSent++;
1178
+ timer = setTimeout(execNext, config.rotate);
1179
+ query(resource, payload, item.callback);
1180
+ }
1181
+ setTimeout(execNext);
1182
+ return getQueryStatus;
1183
+ }
1184
+
1185
+ // src/index.ts
1186
+ function setConfig(config) {
1187
+ if (typeof config !== "object" || typeof config.resources !== "object" || !(config.resources instanceof Array) || !config.resources.length) {
1188
+ throw new Error("Invalid Reduncancy configuration");
1189
+ }
1190
+ const newConfig = /* @__PURE__ */ Object.create(null);
1191
+ let key;
1192
+ for (key in defaultConfig) {
1193
+ if (config[key] !== void 0) {
1194
+ newConfig[key] = config[key];
1195
+ } else {
1196
+ newConfig[key] = defaultConfig[key];
1197
+ }
1198
+ }
1199
+ return newConfig;
1200
+ }
1201
+ function initRedundancy(cfg) {
1202
+ const config = setConfig(cfg);
1203
+ let queries = [];
1204
+ function cleanup() {
1205
+ queries = queries.filter((item) => item().status === "pending");
1206
+ }
1207
+ function query(payload, queryCallback, doneCallback) {
1208
+ const query2 = sendQuery(config, payload, queryCallback, (data, error) => {
1209
+ cleanup();
1210
+ if (doneCallback) {
1211
+ doneCallback(data, error);
1212
+ }
1213
+ });
1214
+ queries.push(query2);
1215
+ return query2;
1216
+ }
1217
+ function find(callback) {
1218
+ const result = queries.find((value) => {
1219
+ return callback(value);
1220
+ });
1221
+ return result !== void 0 ? result : null;
1222
+ }
1223
+ const instance = {
1224
+ query,
1225
+ find,
1226
+ setIndex: (index) => {
1227
+ config.index = index;
1228
+ },
1229
+ getIndex: () => config.index,
1230
+ cleanup
1231
+ };
1232
+ return instance;
1233
+ }
1234
+
1235
+ function emptyCallback$1() {
1236
+ }
1237
+ const redundancyCache = /* @__PURE__ */ Object.create(null);
1238
+ function getRedundancyCache(provider) {
1239
+ if (redundancyCache[provider] === void 0) {
1240
+ const config = getAPIConfig(provider);
1241
+ if (!config) {
1242
+ return;
1243
+ }
1244
+ const redundancy = initRedundancy(config);
1245
+ const cachedReundancy = {
1246
+ config,
1247
+ redundancy
1248
+ };
1249
+ redundancyCache[provider] = cachedReundancy;
1250
+ }
1251
+ return redundancyCache[provider];
1252
+ }
1253
+ function sendAPIQuery(target, query, callback) {
1254
+ let redundancy;
1255
+ let send;
1256
+ if (typeof target === "string") {
1257
+ const api = getAPIModule(target);
1258
+ if (!api) {
1259
+ callback(void 0, 424);
1260
+ return emptyCallback$1;
1261
+ }
1262
+ send = api.send;
1263
+ const cached = getRedundancyCache(target);
1264
+ if (cached) {
1265
+ redundancy = cached.redundancy;
1266
+ }
1267
+ } else {
1268
+ const config = createAPIConfig(target);
1269
+ if (config) {
1270
+ redundancy = initRedundancy(config);
1271
+ const moduleKey = target.resources ? target.resources[0] : "";
1272
+ const api = getAPIModule(moduleKey);
1273
+ if (api) {
1274
+ send = api.send;
1275
+ }
1276
+ }
1277
+ }
1278
+ if (!redundancy || !send) {
1279
+ callback(void 0, 424);
1280
+ return emptyCallback$1;
1281
+ }
1282
+ return redundancy.query(query, send, callback)().abort;
1283
+ }
1284
+
1285
+ const cache = {};
1286
+
1287
+ function emptyCallback() {
1288
+ }
1289
+ const pendingIcons = /* @__PURE__ */ Object.create(null);
1290
+ const iconsToLoad = /* @__PURE__ */ Object.create(null);
1291
+ const loaderFlags = /* @__PURE__ */ Object.create(null);
1292
+ const queueFlags = /* @__PURE__ */ Object.create(null);
1293
+ function loadedNewIcons(provider, prefix) {
1294
+ if (loaderFlags[provider] === void 0) {
1295
+ loaderFlags[provider] = /* @__PURE__ */ Object.create(null);
1296
+ }
1297
+ const providerLoaderFlags = loaderFlags[provider];
1298
+ if (!providerLoaderFlags[prefix]) {
1299
+ providerLoaderFlags[prefix] = true;
1300
+ setTimeout(() => {
1301
+ providerLoaderFlags[prefix] = false;
1302
+ updateCallbacks(provider, prefix);
1303
+ });
1304
+ }
1305
+ }
1306
+ const errorsCache = /* @__PURE__ */ Object.create(null);
1307
+ function loadNewIcons(provider, prefix, icons) {
1308
+ function err() {
1309
+ const key = (provider === "" ? "" : "@" + provider + ":") + prefix;
1310
+ const time = Math.floor(Date.now() / 6e4);
1311
+ if (errorsCache[key] < time) {
1312
+ errorsCache[key] = time;
1313
+ console.error('Unable to retrieve icons for "' + key + '" because API is not configured properly.');
1314
+ }
1315
+ }
1316
+ if (iconsToLoad[provider] === void 0) {
1317
+ iconsToLoad[provider] = /* @__PURE__ */ Object.create(null);
1318
+ }
1319
+ const providerIconsToLoad = iconsToLoad[provider];
1320
+ if (queueFlags[provider] === void 0) {
1321
+ queueFlags[provider] = /* @__PURE__ */ Object.create(null);
1322
+ }
1323
+ const providerQueueFlags = queueFlags[provider];
1324
+ if (pendingIcons[provider] === void 0) {
1325
+ pendingIcons[provider] = /* @__PURE__ */ Object.create(null);
1326
+ }
1327
+ const providerPendingIcons = pendingIcons[provider];
1328
+ if (providerIconsToLoad[prefix] === void 0) {
1329
+ providerIconsToLoad[prefix] = icons;
1330
+ } else {
1331
+ providerIconsToLoad[prefix] = providerIconsToLoad[prefix].concat(icons).sort();
1332
+ }
1333
+ if (!providerQueueFlags[prefix]) {
1334
+ providerQueueFlags[prefix] = true;
1335
+ setTimeout(() => {
1336
+ providerQueueFlags[prefix] = false;
1337
+ const icons2 = providerIconsToLoad[prefix];
1338
+ delete providerIconsToLoad[prefix];
1339
+ const api = getAPIModule(provider);
1340
+ if (!api) {
1341
+ err();
1342
+ return;
1343
+ }
1344
+ const params = api.prepare(provider, prefix, icons2);
1345
+ params.forEach((item) => {
1346
+ sendAPIQuery(provider, item, (data, error) => {
1347
+ const storage = getStorage(provider, prefix);
1348
+ if (typeof data !== "object") {
1349
+ if (error !== 404) {
1350
+ return;
1351
+ }
1352
+ const t = Date.now();
1353
+ item.icons.forEach((name) => {
1354
+ storage.missing[name] = t;
1355
+ });
1356
+ } else {
1357
+ try {
1358
+ const parsed = addIconSet(storage, data);
1359
+ if (!parsed.length) {
1360
+ return;
1361
+ }
1362
+ const pending = providerPendingIcons[prefix];
1363
+ parsed.forEach((name) => {
1364
+ delete pending[name];
1365
+ });
1366
+ if (cache.store) {
1367
+ cache.store(provider, data);
1368
+ }
1369
+ } catch (err2) {
1370
+ console.error(err2);
1371
+ }
1372
+ }
1373
+ loadedNewIcons(provider, prefix);
1374
+ });
1375
+ });
1376
+ });
1377
+ }
1378
+ }
1379
+ const loadIcons = (icons, callback) => {
1380
+ const cleanedIcons = listToIcons(icons, true, allowSimpleNames());
1381
+ const sortedIcons = sortIcons(cleanedIcons);
1382
+ if (!sortedIcons.pending.length) {
1383
+ let callCallback = true;
1384
+ if (callback) {
1385
+ setTimeout(() => {
1386
+ if (callCallback) {
1387
+ callback(sortedIcons.loaded, sortedIcons.missing, sortedIcons.pending, emptyCallback);
1388
+ }
1389
+ });
1390
+ }
1391
+ return () => {
1392
+ callCallback = false;
1393
+ };
1394
+ }
1395
+ const newIcons = /* @__PURE__ */ Object.create(null);
1396
+ const sources = [];
1397
+ let lastProvider, lastPrefix;
1398
+ sortedIcons.pending.forEach((icon) => {
1399
+ const provider = icon.provider;
1400
+ const prefix = icon.prefix;
1401
+ if (prefix === lastPrefix && provider === lastProvider) {
1402
+ return;
1403
+ }
1404
+ lastProvider = provider;
1405
+ lastPrefix = prefix;
1406
+ sources.push({
1407
+ provider,
1408
+ prefix
1409
+ });
1410
+ if (pendingIcons[provider] === void 0) {
1411
+ pendingIcons[provider] = /* @__PURE__ */ Object.create(null);
1412
+ }
1413
+ const providerPendingIcons = pendingIcons[provider];
1414
+ if (providerPendingIcons[prefix] === void 0) {
1415
+ providerPendingIcons[prefix] = /* @__PURE__ */ Object.create(null);
1416
+ }
1417
+ if (newIcons[provider] === void 0) {
1418
+ newIcons[provider] = /* @__PURE__ */ Object.create(null);
1419
+ }
1420
+ const providerNewIcons = newIcons[provider];
1421
+ if (providerNewIcons[prefix] === void 0) {
1422
+ providerNewIcons[prefix] = [];
1423
+ }
1424
+ });
1425
+ const time = Date.now();
1426
+ sortedIcons.pending.forEach((icon) => {
1427
+ const provider = icon.provider;
1428
+ const prefix = icon.prefix;
1429
+ const name = icon.name;
1430
+ const pendingQueue = pendingIcons[provider][prefix];
1431
+ if (pendingQueue[name] === void 0) {
1432
+ pendingQueue[name] = time;
1433
+ newIcons[provider][prefix].push(name);
1434
+ }
1435
+ });
1436
+ sources.forEach((source) => {
1437
+ const provider = source.provider;
1438
+ const prefix = source.prefix;
1439
+ if (newIcons[provider][prefix].length) {
1440
+ loadNewIcons(provider, prefix, newIcons[provider][prefix]);
1441
+ }
1442
+ });
1443
+ return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
1444
+ };
1445
+ const loadIcon = (icon) => {
1446
+ return new Promise((fulfill, reject) => {
1447
+ const iconObj = typeof icon === "string" ? stringToIcon(icon) : icon;
1448
+ loadIcons([iconObj || icon], (loaded) => {
1449
+ if (loaded.length && iconObj) {
1450
+ const storage = getStorage(iconObj.provider, iconObj.prefix);
1451
+ const data = getIconFromStorage(storage, iconObj.name);
1452
+ if (data) {
1453
+ fulfill(data);
1454
+ return;
1455
+ }
1456
+ }
1457
+ reject(icon);
1458
+ });
1459
+ });
1460
+ };
1461
+
1462
+ const cacheVersion = "iconify2";
1463
+ const cachePrefix = "iconify";
1464
+ const countKey = cachePrefix + "-count";
1465
+ const versionKey = cachePrefix + "-version";
1466
+ const hour = 36e5;
1467
+ const cacheExpiration = 168;
1468
+ const config = {
1469
+ local: true,
1470
+ session: true
1471
+ };
1472
+ let loaded = false;
1473
+ const count = {
1474
+ local: 0,
1475
+ session: 0
1476
+ };
1477
+ const emptyList = {
1478
+ local: [],
1479
+ session: []
1480
+ };
1481
+ let _window = typeof window === "undefined" ? {} : window;
1482
+ function getGlobal(key) {
1483
+ const attr = key + "Storage";
1484
+ try {
1485
+ if (_window && _window[attr] && typeof _window[attr].length === "number") {
1486
+ return _window[attr];
1487
+ }
1488
+ } catch (err) {
1489
+ }
1490
+ config[key] = false;
1491
+ return null;
1492
+ }
1493
+ function setCount(storage, key, value) {
1494
+ try {
1495
+ storage.setItem(countKey, value.toString());
1496
+ count[key] = value;
1497
+ return true;
1498
+ } catch (err) {
1499
+ return false;
1500
+ }
1501
+ }
1502
+ function getCount(storage) {
1503
+ const count2 = storage.getItem(countKey);
1504
+ if (count2) {
1505
+ const total = parseInt(count2);
1506
+ return total ? total : 0;
1507
+ }
1508
+ return 0;
1509
+ }
1510
+ function initCache(storage, key) {
1511
+ try {
1512
+ storage.setItem(versionKey, cacheVersion);
1513
+ } catch (err) {
1514
+ }
1515
+ setCount(storage, key, 0);
1516
+ }
1517
+ function destroyCache(storage) {
1518
+ try {
1519
+ const total = getCount(storage);
1520
+ for (let i = 0; i < total; i++) {
1521
+ storage.removeItem(cachePrefix + i.toString());
1522
+ }
1523
+ } catch (err) {
1524
+ }
1525
+ }
1526
+ const loadCache = () => {
1527
+ if (loaded) {
1528
+ return;
1529
+ }
1530
+ loaded = true;
1531
+ const minTime = Math.floor(Date.now() / hour) - cacheExpiration;
1532
+ function load(key) {
1533
+ const func = getGlobal(key);
1534
+ if (!func) {
1535
+ return;
1536
+ }
1537
+ const getItem = (index) => {
1538
+ const name = cachePrefix + index.toString();
1539
+ const item = func.getItem(name);
1540
+ if (typeof item !== "string") {
1541
+ return false;
1542
+ }
1543
+ let valid = true;
1544
+ try {
1545
+ const data = JSON.parse(item);
1546
+ if (typeof data !== "object" || typeof data.cached !== "number" || data.cached < minTime || typeof data.provider !== "string" || typeof data.data !== "object" || typeof data.data.prefix !== "string") {
1547
+ valid = false;
1548
+ } else {
1549
+ const provider = data.provider;
1550
+ const prefix = data.data.prefix;
1551
+ const storage = getStorage(provider, prefix);
1552
+ valid = addIconSet(storage, data.data).length > 0;
1553
+ }
1554
+ } catch (err) {
1555
+ valid = false;
1556
+ }
1557
+ if (!valid) {
1558
+ func.removeItem(name);
1559
+ }
1560
+ return valid;
1561
+ };
1562
+ try {
1563
+ const version = func.getItem(versionKey);
1564
+ if (version !== cacheVersion) {
1565
+ if (version) {
1566
+ destroyCache(func);
1567
+ }
1568
+ initCache(func, key);
1569
+ return;
1570
+ }
1571
+ let total = getCount(func);
1572
+ for (let i = total - 1; i >= 0; i--) {
1573
+ if (!getItem(i)) {
1574
+ if (i === total - 1) {
1575
+ total--;
1576
+ } else {
1577
+ emptyList[key].push(i);
1578
+ }
1579
+ }
1580
+ }
1581
+ setCount(func, key, total);
1582
+ } catch (err) {
1583
+ }
1584
+ }
1585
+ for (const key in config) {
1586
+ load(key);
1587
+ }
1588
+ };
1589
+ const storeCache = (provider, data) => {
1590
+ if (!loaded) {
1591
+ loadCache();
1592
+ }
1593
+ function store(key) {
1594
+ if (!config[key]) {
1595
+ return false;
1596
+ }
1597
+ const func = getGlobal(key);
1598
+ if (!func) {
1599
+ return false;
1600
+ }
1601
+ let index = emptyList[key].shift();
1602
+ if (index === void 0) {
1603
+ index = count[key];
1604
+ if (!setCount(func, key, index + 1)) {
1605
+ return false;
1606
+ }
1607
+ }
1608
+ try {
1609
+ const item = {
1610
+ cached: Math.floor(Date.now() / hour),
1611
+ provider,
1612
+ data
1613
+ };
1614
+ func.setItem(cachePrefix + index.toString(), JSON.stringify(item));
1615
+ } catch (err) {
1616
+ return false;
1617
+ }
1618
+ return true;
1619
+ }
1620
+ if (!Object.keys(data.icons).length) {
1621
+ return;
1622
+ }
1623
+ if (data.not_found) {
1624
+ data = Object.assign({}, data);
1625
+ delete data.not_found;
1626
+ }
1627
+ if (!store("local")) {
1628
+ store("session");
1629
+ }
1630
+ };
1631
+
1632
+ function toggleBrowserCache(storage, value) {
1633
+ switch (storage) {
1634
+ case "local":
1635
+ case "session":
1636
+ config[storage] = value;
1637
+ break;
1638
+ case "all":
1639
+ for (const key in config) {
1640
+ config[key] = value;
1641
+ }
1642
+ break;
1643
+ }
1644
+ }
1645
+
1646
+ const separator = /[\s,]+/;
1647
+ function flipFromString(custom, flip) {
1648
+ flip.split(separator).forEach((str) => {
1649
+ const value = str.trim();
1650
+ switch (value) {
1651
+ case "horizontal":
1652
+ custom.hFlip = true;
1653
+ break;
1654
+ case "vertical":
1655
+ custom.vFlip = true;
1656
+ break;
1657
+ }
1658
+ });
1659
+ }
1660
+ function alignmentFromString(custom, align) {
1661
+ align.split(separator).forEach((str) => {
1662
+ const value = str.trim();
1663
+ switch (value) {
1664
+ case "left":
1665
+ case "center":
1666
+ case "right":
1667
+ custom.hAlign = value;
1668
+ break;
1669
+ case "top":
1670
+ case "middle":
1671
+ case "bottom":
1672
+ custom.vAlign = value;
1673
+ break;
1674
+ case "slice":
1675
+ case "crop":
1676
+ custom.slice = true;
1677
+ break;
1678
+ case "meet":
1679
+ custom.slice = false;
1680
+ }
1681
+ });
1682
+ }
1683
+
1684
+ function rotateFromString(value, defaultValue = 0) {
1685
+ const units = value.replace(/^-?[0-9.]*/, "");
1686
+ function cleanup(value2) {
1687
+ while (value2 < 0) {
1688
+ value2 += 4;
1689
+ }
1690
+ return value2 % 4;
1691
+ }
1692
+ if (units === "") {
1693
+ const num = parseInt(value);
1694
+ return isNaN(num) ? 0 : cleanup(num);
1695
+ } else if (units !== value) {
1696
+ let split = 0;
1697
+ switch (units) {
1698
+ case "%":
1699
+ split = 25;
1700
+ break;
1701
+ case "deg":
1702
+ split = 90;
1703
+ }
1704
+ if (split) {
1705
+ let num = parseFloat(value.slice(0, value.length - units.length));
1706
+ if (isNaN(num)) {
1707
+ return 0;
1708
+ }
1709
+ num = num / split;
1710
+ return num % 1 === 0 ? cleanup(num) : 0;
1711
+ }
1712
+ }
1713
+ return defaultValue;
1714
+ }
1715
+
1716
+ /**
1717
+ * Default SVG attributes
1718
+ */
1719
+ const svgDefaults = {
1720
+ 'xmlns': 'http://www.w3.org/2000/svg',
1721
+ 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
1722
+ 'aria-hidden': true,
1723
+ 'role': 'img',
1724
+ };
1725
+ /**
1726
+ * Aliases for customisations.
1727
+ * In Vue 'v-' properties are reserved, so v-align and v-flip must be renamed
1728
+ */
1729
+ let customisationAliases = {};
1730
+ ['horizontal', 'vertical'].forEach((prefix) => {
1731
+ ['Align', 'Flip'].forEach((suffix) => {
1732
+ const attr = prefix.slice(0, 1) + suffix;
1733
+ const value = {
1734
+ attr,
1735
+ boolean: suffix === 'Flip',
1736
+ };
1737
+ // vertical-align
1738
+ customisationAliases[prefix + '-' + suffix.toLowerCase()] = value;
1739
+ // v-align
1740
+ customisationAliases[prefix.slice(0, 1) + '-' + suffix.toLowerCase()] =
1741
+ value;
1742
+ // verticalAlign
1743
+ customisationAliases[prefix + suffix] = value;
1744
+ });
1745
+ });
1746
+ /**
1747
+ * Render icon
1748
+ */
1749
+ const render = (
1750
+ // Icon must be validated before calling this function
1751
+ icon,
1752
+ // Partial properties
1753
+ props) => {
1754
+ // Split properties
1755
+ const customisations = mergeCustomisations(defaults, props);
1756
+ const componentProps = { ...svgDefaults };
1757
+ // Copy style
1758
+ let style = typeof props.style === 'object' && !(props.style instanceof Array)
1759
+ ? { ...props.style }
1760
+ : {};
1761
+ // Get element properties
1762
+ for (let key in props) {
1763
+ const value = props[key];
1764
+ if (value === void 0) {
1765
+ continue;
1766
+ }
1767
+ switch (key) {
1768
+ // Properties to ignore
1769
+ case 'icon':
1770
+ case 'style':
1771
+ case 'onLoad':
1772
+ break;
1773
+ // Boolean attributes
1774
+ case 'inline':
1775
+ case 'hFlip':
1776
+ case 'vFlip':
1777
+ customisations[key] =
1778
+ value === true || value === 'true' || value === 1;
1779
+ break;
1780
+ // Flip as string: 'horizontal,vertical'
1781
+ case 'flip':
1782
+ if (typeof value === 'string') {
1783
+ flipFromString(customisations, value);
1784
+ }
1785
+ break;
1786
+ // Alignment as string
1787
+ case 'align':
1788
+ if (typeof value === 'string') {
1789
+ alignmentFromString(customisations, value);
1790
+ }
1791
+ break;
1792
+ // Color: override style
1793
+ case 'color':
1794
+ style.color = value;
1795
+ break;
1796
+ // Rotation as string
1797
+ case 'rotate':
1798
+ if (typeof value === 'string') {
1799
+ customisations[key] = rotateFromString(value);
1800
+ }
1801
+ else if (typeof value === 'number') {
1802
+ customisations[key] = value;
1803
+ }
1804
+ break;
1805
+ // Remove aria-hidden
1806
+ case 'ariaHidden':
1807
+ case 'aria-hidden':
1808
+ // Vue transforms 'aria-hidden' property to 'ariaHidden'
1809
+ if (value !== true && value !== 'true') {
1810
+ delete componentProps['aria-hidden'];
1811
+ }
1812
+ break;
1813
+ default:
1814
+ if (customisationAliases[key] !== void 0) {
1815
+ // Aliases for customisations
1816
+ if (customisationAliases[key].boolean &&
1817
+ (value === true || value === 'true' || value === 1)) {
1818
+ // Check for boolean
1819
+ customisations[customisationAliases[key].attr] = true;
1820
+ }
1821
+ else if (!customisationAliases[key].boolean &&
1822
+ typeof value === 'string' &&
1823
+ value !== '') {
1824
+ // String
1825
+ customisations[customisationAliases[key].attr] = value;
1826
+ }
1827
+ }
1828
+ else if (defaults[key] === void 0) {
1829
+ // Copy missing property if it does not exist in customisations
1830
+ componentProps[key] = value;
1831
+ }
1832
+ }
1833
+ }
1834
+ // Generate icon
1835
+ const item = iconToSVG(icon, customisations);
1836
+ // Add icon stuff
1837
+ for (let key in item.attributes) {
1838
+ componentProps[key] = item.attributes[key];
1839
+ }
1840
+ if (item.inline &&
1841
+ style.verticalAlign === void 0 &&
1842
+ style['vertical-align'] === void 0) {
1843
+ style.verticalAlign = '-0.125em';
1844
+ }
1845
+ // Counter for ids based on "id" property to render icons consistently on server and client
1846
+ let localCounter = 0;
1847
+ let id = props.id;
1848
+ if (typeof id === 'string') {
1849
+ // Convert '-' to '_' to avoid errors in animations
1850
+ id = id.replace(/-/g, '_');
1851
+ }
1852
+ // Add innerHTML and style to props
1853
+ componentProps['innerHTML'] = replaceIDs(item.body, id ? () => id + 'ID' + localCounter++ : 'iconifyVue');
1854
+ if (Object.keys(style).length > 0) {
1855
+ componentProps['style'] = style;
1856
+ }
1857
+ // Render icon
1858
+ return h('svg', componentProps);
1859
+ };
1860
+
1861
+ /**
1862
+ * Enable cache
1863
+ */
1864
+ function enableCache(storage) {
1865
+ toggleBrowserCache(storage, true);
1866
+ }
1867
+ /**
1868
+ * Disable cache
1869
+ */
1870
+ function disableCache(storage) {
1871
+ toggleBrowserCache(storage, false);
1872
+ }
1873
+ /**
1874
+ * Initialise stuff
1875
+ */
1876
+ // Enable short names
1877
+ allowSimpleNames(true);
1878
+ // Set API module
1879
+ setAPIModule('', fetchAPIModule);
1880
+ /**
1881
+ * Browser stuff
1882
+ */
1883
+ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
1884
+ // Set cache and load existing cache
1885
+ cache.store = storeCache;
1886
+ loadCache();
1887
+ const _window = window;
1888
+ // Load icons from global "IconifyPreload"
1889
+ if (_window.IconifyPreload !== void 0) {
1890
+ const preload = _window.IconifyPreload;
1891
+ const err = 'Invalid IconifyPreload syntax.';
1892
+ if (typeof preload === 'object' && preload !== null) {
1893
+ (preload instanceof Array ? preload : [preload]).forEach((item) => {
1894
+ try {
1895
+ if (
1896
+ // Check if item is an object and not null/array
1897
+ typeof item !== 'object' ||
1898
+ item === null ||
1899
+ item instanceof Array ||
1900
+ // Check for 'icons' and 'prefix'
1901
+ typeof item.icons !== 'object' ||
1902
+ typeof item.prefix !== 'string' ||
1903
+ // Add icon set
1904
+ !addCollection(item)) {
1905
+ console.error(err);
1906
+ }
1907
+ }
1908
+ catch (e) {
1909
+ console.error(err);
1910
+ }
1911
+ });
1912
+ }
1913
+ }
1914
+ // Set API from global "IconifyProviders"
1915
+ if (_window.IconifyProviders !== void 0) {
1916
+ const providers = _window.IconifyProviders;
1917
+ if (typeof providers === 'object' && providers !== null) {
1918
+ for (let key in providers) {
1919
+ const err = 'IconifyProviders[' + key + '] is invalid.';
1920
+ try {
1921
+ const value = providers[key];
1922
+ if (typeof value !== 'object' ||
1923
+ !value ||
1924
+ value.resources === void 0) {
1925
+ continue;
1926
+ }
1927
+ if (!addAPIProvider(key, value)) {
1928
+ console.error(err);
1929
+ }
1930
+ }
1931
+ catch (e) {
1932
+ console.error(err);
1933
+ }
1934
+ }
1935
+ }
1936
+ }
1937
+ }
1938
+ /**
1939
+ * Empty icon data, rendered when icon is not available
1940
+ */
1941
+ const emptyIcon = fullIcon({
1942
+ body: '',
1943
+ });
1944
+ const Icon = defineComponent({
1945
+ // Do not inherit other attributes: it is handled by render()
1946
+ inheritAttrs: false,
1947
+ // Set initial data
1948
+ data() {
1949
+ return {
1950
+ // Mounted status
1951
+ iconMounted: false,
1952
+ // Callback counter to trigger re-render
1953
+ counter: 0,
1954
+ };
1955
+ },
1956
+ mounted() {
1957
+ // Current icon name
1958
+ this._name = '';
1959
+ // Loading
1960
+ this._loadingIcon = null;
1961
+ // Mark as mounted
1962
+ this.iconMounted = true;
1963
+ },
1964
+ unmounted() {
1965
+ this.abortLoading();
1966
+ },
1967
+ methods: {
1968
+ abortLoading() {
1969
+ if (this._loadingIcon) {
1970
+ this._loadingIcon.abort();
1971
+ this._loadingIcon = null;
1972
+ }
1973
+ },
1974
+ // Get data for icon to render or null
1975
+ getIcon(icon, onload) {
1976
+ // Icon is an object
1977
+ if (typeof icon === 'object' &&
1978
+ icon !== null &&
1979
+ typeof icon.body === 'string') {
1980
+ // Stop loading
1981
+ this._name = '';
1982
+ this.abortLoading();
1983
+ return {
1984
+ data: fullIcon(icon),
1985
+ };
1986
+ }
1987
+ // Invalid icon?
1988
+ let iconName;
1989
+ if (typeof icon !== 'string' ||
1990
+ (iconName = stringToIcon(icon, false, true)) === null) {
1991
+ this.abortLoading();
1992
+ return null;
1993
+ }
1994
+ // Load icon
1995
+ const data = getIconData(iconName);
1996
+ if (data === null) {
1997
+ // Icon needs to be loaded
1998
+ if (!this._loadingIcon || this._loadingIcon.name !== icon) {
1999
+ // New icon to load
2000
+ this.abortLoading();
2001
+ this._name = '';
2002
+ this._loadingIcon = {
2003
+ name: icon,
2004
+ abort: loadIcons([iconName], () => {
2005
+ this.counter++;
2006
+ }),
2007
+ };
2008
+ }
2009
+ return null;
2010
+ }
2011
+ // Icon data is available
2012
+ this.abortLoading();
2013
+ if (this._name !== icon) {
2014
+ this._name = icon;
2015
+ if (onload) {
2016
+ onload(icon);
2017
+ }
2018
+ }
2019
+ // Add classes
2020
+ const classes = ['iconify'];
2021
+ if (iconName.prefix !== '') {
2022
+ classes.push('iconify--' + iconName.prefix);
2023
+ }
2024
+ if (iconName.provider !== '') {
2025
+ classes.push('iconify--' + iconName.provider);
2026
+ }
2027
+ return { data, classes };
2028
+ },
2029
+ },
2030
+ // Render icon
2031
+ render() {
2032
+ // Re-render when counter changes
2033
+ this.counter;
2034
+ const props = this.$attrs;
2035
+ // Get icon data
2036
+ const icon = this.iconMounted
2037
+ ? this.getIcon(props.icon, props.onLoad)
2038
+ : null;
2039
+ // Validate icon object
2040
+ if (!icon) {
2041
+ return render(emptyIcon, props);
2042
+ }
2043
+ // Add classes
2044
+ let newProps = props;
2045
+ if (icon.classes) {
2046
+ newProps = {
2047
+ ...props,
2048
+ class: (typeof props['class'] === 'string'
2049
+ ? props['class'] + ' '
2050
+ : '') + icon.classes.join(' '),
2051
+ };
2052
+ }
2053
+ // Render icon
2054
+ return render(icon.data, newProps);
2055
+ },
2056
+ });
2057
+ /**
2058
+ * Internal API
2059
+ */
2060
+ const _api = {
2061
+ getAPIConfig,
2062
+ setAPIModule,
2063
+ sendAPIQuery,
2064
+ setFetch,
2065
+ getFetch,
2066
+ listAPIProviders,
2067
+ mergeParams,
2068
+ };
2069
+
2070
+ export { Icon, _api, addAPIProvider, addCollection, addIcon, buildIcon, calculateSize, disableCache, enableCache, getIcon, iconExists, listIcons, loadIcon, loadIcons, replaceIDs, shareStorage };