@bagelink/vue 1.2.149 → 1.2.153

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,1771 @@
1
+ import { defineComponent, ref, shallowRef, onMounted, watch, onUnmounted, h, nextTick } from "vue";
2
+ const matchIconName = /^[a-z0-9]+(-[a-z0-9]+)*$/;
3
+ const stringToIcon = (value, validate, allowSimpleName, provider = "") => {
4
+ const colonSeparated = value.split(":");
5
+ if (value.slice(0, 1) === "@") {
6
+ if (colonSeparated.length < 2 || colonSeparated.length > 3) {
7
+ return null;
8
+ }
9
+ provider = colonSeparated.shift().slice(1);
10
+ }
11
+ if (colonSeparated.length > 3 || !colonSeparated.length) {
12
+ return null;
13
+ }
14
+ if (colonSeparated.length > 1) {
15
+ const name2 = colonSeparated.pop();
16
+ const prefix = colonSeparated.pop();
17
+ const result = {
18
+ // Allow provider without '@': "provider:prefix:name"
19
+ provider: colonSeparated.length > 0 ? colonSeparated[0] : provider,
20
+ prefix,
21
+ name: name2
22
+ };
23
+ return validate && !validateIconName(result) ? null : result;
24
+ }
25
+ const name = colonSeparated[0];
26
+ const dashSeparated = name.split("-");
27
+ if (dashSeparated.length > 1) {
28
+ const result = {
29
+ provider,
30
+ prefix: dashSeparated.shift(),
31
+ name: dashSeparated.join("-")
32
+ };
33
+ return validate && !validateIconName(result) ? null : result;
34
+ }
35
+ if (allowSimpleName && provider === "") {
36
+ const result = {
37
+ provider,
38
+ prefix: "",
39
+ name
40
+ };
41
+ return validate && !validateIconName(result, allowSimpleName) ? null : result;
42
+ }
43
+ return null;
44
+ };
45
+ const validateIconName = (icon, allowSimpleName) => {
46
+ if (!icon) {
47
+ return false;
48
+ }
49
+ return !!// Check prefix: cannot be empty, unless allowSimpleName is enabled
50
+ // Check name: cannot be empty
51
+ ((allowSimpleName && icon.prefix === "" || !!icon.prefix) && !!icon.name);
52
+ };
53
+ const defaultIconDimensions = Object.freeze(
54
+ {
55
+ left: 0,
56
+ top: 0,
57
+ width: 16,
58
+ height: 16
59
+ }
60
+ );
61
+ const defaultIconTransformations = Object.freeze({
62
+ rotate: 0,
63
+ vFlip: false,
64
+ hFlip: false
65
+ });
66
+ const defaultIconProps = Object.freeze({
67
+ ...defaultIconDimensions,
68
+ ...defaultIconTransformations
69
+ });
70
+ const defaultExtendedIconProps = Object.freeze({
71
+ ...defaultIconProps,
72
+ body: "",
73
+ hidden: false
74
+ });
75
+ function mergeIconTransformations(obj1, obj2) {
76
+ const result = {};
77
+ if (!obj1.hFlip !== !obj2.hFlip) {
78
+ result.hFlip = true;
79
+ }
80
+ if (!obj1.vFlip !== !obj2.vFlip) {
81
+ result.vFlip = true;
82
+ }
83
+ const rotate = ((obj1.rotate || 0) + (obj2.rotate || 0)) % 4;
84
+ if (rotate) {
85
+ result.rotate = rotate;
86
+ }
87
+ return result;
88
+ }
89
+ function mergeIconData(parent, child) {
90
+ const result = mergeIconTransformations(parent, child);
91
+ for (const key in defaultExtendedIconProps) {
92
+ if (key in defaultIconTransformations) {
93
+ if (key in parent && !(key in result)) {
94
+ result[key] = defaultIconTransformations[key];
95
+ }
96
+ } else if (key in child) {
97
+ result[key] = child[key];
98
+ } else if (key in parent) {
99
+ result[key] = parent[key];
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ function getIconsTree(data, names) {
105
+ const icons = data.icons;
106
+ const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
107
+ const resolved = /* @__PURE__ */ Object.create(null);
108
+ function resolve(name) {
109
+ if (icons[name]) {
110
+ return resolved[name] = [];
111
+ }
112
+ if (!(name in resolved)) {
113
+ resolved[name] = null;
114
+ const parent = aliases[name] && aliases[name].parent;
115
+ const value = parent && resolve(parent);
116
+ if (value) {
117
+ resolved[name] = [parent].concat(value);
118
+ }
119
+ }
120
+ return resolved[name];
121
+ }
122
+ Object.keys(icons).concat(Object.keys(aliases)).forEach(resolve);
123
+ return resolved;
124
+ }
125
+ function internalGetIconData(data, name, tree) {
126
+ const icons = data.icons;
127
+ const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
128
+ let currentProps = {};
129
+ function parse(name2) {
130
+ currentProps = mergeIconData(
131
+ icons[name2] || aliases[name2],
132
+ currentProps
133
+ );
134
+ }
135
+ parse(name);
136
+ tree.forEach(parse);
137
+ return mergeIconData(data, currentProps);
138
+ }
139
+ function parseIconSet(data, callback) {
140
+ const names = [];
141
+ if (typeof data !== "object" || typeof data.icons !== "object") {
142
+ return names;
143
+ }
144
+ if (data.not_found instanceof Array) {
145
+ data.not_found.forEach((name) => {
146
+ callback(name, null);
147
+ names.push(name);
148
+ });
149
+ }
150
+ const tree = getIconsTree(data);
151
+ for (const name in tree) {
152
+ const item = tree[name];
153
+ if (item) {
154
+ callback(name, internalGetIconData(data, name, item));
155
+ names.push(name);
156
+ }
157
+ }
158
+ return names;
159
+ }
160
+ const optionalPropertyDefaults = {
161
+ provider: "",
162
+ aliases: {},
163
+ not_found: {},
164
+ ...defaultIconDimensions
165
+ };
166
+ function checkOptionalProps(item, defaults) {
167
+ for (const prop in defaults) {
168
+ if (prop in item && typeof item[prop] !== typeof defaults[prop]) {
169
+ return false;
170
+ }
171
+ }
172
+ return true;
173
+ }
174
+ function quicklyValidateIconSet(obj) {
175
+ if (typeof obj !== "object" || obj === null) {
176
+ return null;
177
+ }
178
+ const data = obj;
179
+ if (typeof data.prefix !== "string" || !obj.icons || typeof obj.icons !== "object") {
180
+ return null;
181
+ }
182
+ if (!checkOptionalProps(obj, optionalPropertyDefaults)) {
183
+ return null;
184
+ }
185
+ const icons = data.icons;
186
+ for (const name in icons) {
187
+ const icon = icons[name];
188
+ if (
189
+ // Name cannot be empty
190
+ !name || // Must have body
191
+ typeof icon.body !== "string" || // Check other props
192
+ !checkOptionalProps(
193
+ icon,
194
+ defaultExtendedIconProps
195
+ )
196
+ ) {
197
+ return null;
198
+ }
199
+ }
200
+ const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
201
+ for (const name in aliases) {
202
+ const icon = aliases[name];
203
+ const parent = icon.parent;
204
+ if (
205
+ // Name cannot be empty
206
+ !name || // Parent must be set and point to existing icon
207
+ typeof parent !== "string" || !icons[parent] && !aliases[parent] || // Check other props
208
+ !checkOptionalProps(
209
+ icon,
210
+ defaultExtendedIconProps
211
+ )
212
+ ) {
213
+ return null;
214
+ }
215
+ }
216
+ return data;
217
+ }
218
+ const dataStorage = /* @__PURE__ */ Object.create(null);
219
+ function newStorage(provider, prefix) {
220
+ return {
221
+ provider,
222
+ prefix,
223
+ icons: /* @__PURE__ */ Object.create(null),
224
+ missing: /* @__PURE__ */ new Set()
225
+ };
226
+ }
227
+ function getStorage(provider, prefix) {
228
+ const providerStorage = dataStorage[provider] || (dataStorage[provider] = /* @__PURE__ */ Object.create(null));
229
+ return providerStorage[prefix] || (providerStorage[prefix] = newStorage(provider, prefix));
230
+ }
231
+ function addIconSet(storage2, data) {
232
+ if (!quicklyValidateIconSet(data)) {
233
+ return [];
234
+ }
235
+ return parseIconSet(data, (name, icon) => {
236
+ if (icon) {
237
+ storage2.icons[name] = icon;
238
+ } else {
239
+ storage2.missing.add(name);
240
+ }
241
+ });
242
+ }
243
+ function addIconToStorage(storage2, name, icon) {
244
+ try {
245
+ if (typeof icon.body === "string") {
246
+ storage2.icons[name] = { ...icon };
247
+ return true;
248
+ }
249
+ } catch (err) {
250
+ }
251
+ return false;
252
+ }
253
+ function listIcons(provider, prefix) {
254
+ let allIcons = [];
255
+ const providers = typeof provider === "string" ? [provider] : Object.keys(dataStorage);
256
+ providers.forEach((provider2) => {
257
+ const prefixes = typeof provider2 === "string" && typeof prefix === "string" ? [prefix] : Object.keys(dataStorage[provider2] || {});
258
+ prefixes.forEach((prefix2) => {
259
+ const storage2 = getStorage(provider2, prefix2);
260
+ allIcons = allIcons.concat(
261
+ Object.keys(storage2.icons).map(
262
+ (name) => (provider2 !== "" ? "@" + provider2 + ":" : "") + prefix2 + ":" + name
263
+ )
264
+ );
265
+ });
266
+ });
267
+ return allIcons;
268
+ }
269
+ let simpleNames = false;
270
+ function allowSimpleNames(allow) {
271
+ if (typeof allow === "boolean") {
272
+ simpleNames = allow;
273
+ }
274
+ return simpleNames;
275
+ }
276
+ function getIconData(name) {
277
+ const icon = typeof name === "string" ? stringToIcon(name, true, simpleNames) : name;
278
+ if (icon) {
279
+ const storage2 = getStorage(icon.provider, icon.prefix);
280
+ const iconName = icon.name;
281
+ return storage2.icons[iconName] || (storage2.missing.has(iconName) ? null : void 0);
282
+ }
283
+ }
284
+ function addIcon(name, data) {
285
+ const icon = stringToIcon(name, true, simpleNames);
286
+ if (!icon) {
287
+ return false;
288
+ }
289
+ const storage2 = getStorage(icon.provider, icon.prefix);
290
+ if (data) {
291
+ return addIconToStorage(storage2, icon.name, data);
292
+ } else {
293
+ storage2.missing.add(icon.name);
294
+ return true;
295
+ }
296
+ }
297
+ function addCollection(data, provider) {
298
+ if (typeof data !== "object") {
299
+ return false;
300
+ }
301
+ if (typeof provider !== "string") {
302
+ provider = data.provider || "";
303
+ }
304
+ if (simpleNames && !provider && !data.prefix) {
305
+ let added = false;
306
+ if (quicklyValidateIconSet(data)) {
307
+ data.prefix = "";
308
+ parseIconSet(data, (name, icon) => {
309
+ if (addIcon(name, icon)) {
310
+ added = true;
311
+ }
312
+ });
313
+ }
314
+ return added;
315
+ }
316
+ const prefix = data.prefix;
317
+ if (!validateIconName({
318
+ prefix,
319
+ name: "a"
320
+ })) {
321
+ return false;
322
+ }
323
+ const storage2 = getStorage(provider, prefix);
324
+ return !!addIconSet(storage2, data);
325
+ }
326
+ function iconLoaded(name) {
327
+ return !!getIconData(name);
328
+ }
329
+ function getIcon(name) {
330
+ const result = getIconData(name);
331
+ return result ? {
332
+ ...defaultIconProps,
333
+ ...result
334
+ } : result;
335
+ }
336
+ const defaultIconSizeCustomisations = Object.freeze({
337
+ width: null,
338
+ height: null
339
+ });
340
+ const defaultIconCustomisations = Object.freeze({
341
+ // Dimensions
342
+ ...defaultIconSizeCustomisations,
343
+ // Transformations
344
+ ...defaultIconTransformations
345
+ });
346
+ const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
347
+ const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
348
+ function calculateSize(size, ratio, precision) {
349
+ if (ratio === 1) {
350
+ return size;
351
+ }
352
+ precision = precision || 100;
353
+ if (typeof size === "number") {
354
+ return Math.ceil(size * ratio * precision) / precision;
355
+ }
356
+ if (typeof size !== "string") {
357
+ return size;
358
+ }
359
+ const oldParts = size.split(unitsSplit);
360
+ if (oldParts === null || !oldParts.length) {
361
+ return size;
362
+ }
363
+ const newParts = [];
364
+ let code = oldParts.shift();
365
+ let isNumber = unitsTest.test(code);
366
+ while (true) {
367
+ if (isNumber) {
368
+ const num = parseFloat(code);
369
+ if (isNaN(num)) {
370
+ newParts.push(code);
371
+ } else {
372
+ newParts.push(Math.ceil(num * ratio * precision) / precision);
373
+ }
374
+ } else {
375
+ newParts.push(code);
376
+ }
377
+ code = oldParts.shift();
378
+ if (code === void 0) {
379
+ return newParts.join("");
380
+ }
381
+ isNumber = !isNumber;
382
+ }
383
+ }
384
+ function splitSVGDefs(content, tag = "defs") {
385
+ let defs = "";
386
+ const index = content.indexOf("<" + tag);
387
+ while (index >= 0) {
388
+ const start = content.indexOf(">", index);
389
+ const end = content.indexOf("</" + tag);
390
+ if (start === -1 || end === -1) {
391
+ break;
392
+ }
393
+ const endEnd = content.indexOf(">", end);
394
+ if (endEnd === -1) {
395
+ break;
396
+ }
397
+ defs += content.slice(start + 1, end).trim();
398
+ content = content.slice(0, index).trim() + content.slice(endEnd + 1);
399
+ }
400
+ return {
401
+ defs,
402
+ content
403
+ };
404
+ }
405
+ function mergeDefsAndContent(defs, content) {
406
+ return defs ? "<defs>" + defs + "</defs>" + content : content;
407
+ }
408
+ function wrapSVGContent(body, start, end) {
409
+ const split = splitSVGDefs(body);
410
+ return mergeDefsAndContent(split.defs, start + split.content + end);
411
+ }
412
+ const isUnsetKeyword = (value) => value === "unset" || value === "undefined" || value === "none";
413
+ function iconToSVG(icon, customisations) {
414
+ const fullIcon = {
415
+ ...defaultIconProps,
416
+ ...icon
417
+ };
418
+ const fullCustomisations = {
419
+ ...defaultIconCustomisations,
420
+ ...customisations
421
+ };
422
+ const box = {
423
+ left: fullIcon.left,
424
+ top: fullIcon.top,
425
+ width: fullIcon.width,
426
+ height: fullIcon.height
427
+ };
428
+ let body = fullIcon.body;
429
+ [fullIcon, fullCustomisations].forEach((props) => {
430
+ const transformations = [];
431
+ const hFlip = props.hFlip;
432
+ const vFlip = props.vFlip;
433
+ let rotation = props.rotate;
434
+ if (hFlip) {
435
+ if (vFlip) {
436
+ rotation += 2;
437
+ } else {
438
+ transformations.push(
439
+ "translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")"
440
+ );
441
+ transformations.push("scale(-1 1)");
442
+ box.top = box.left = 0;
443
+ }
444
+ } else if (vFlip) {
445
+ transformations.push(
446
+ "translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")"
447
+ );
448
+ transformations.push("scale(1 -1)");
449
+ box.top = box.left = 0;
450
+ }
451
+ let tempValue;
452
+ if (rotation < 0) {
453
+ rotation -= Math.floor(rotation / 4) * 4;
454
+ }
455
+ rotation = rotation % 4;
456
+ switch (rotation) {
457
+ case 1:
458
+ tempValue = box.height / 2 + box.top;
459
+ transformations.unshift(
460
+ "rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")"
461
+ );
462
+ break;
463
+ case 2:
464
+ transformations.unshift(
465
+ "rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")"
466
+ );
467
+ break;
468
+ case 3:
469
+ tempValue = box.width / 2 + box.left;
470
+ transformations.unshift(
471
+ "rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")"
472
+ );
473
+ break;
474
+ }
475
+ if (rotation % 2 === 1) {
476
+ if (box.left !== box.top) {
477
+ tempValue = box.left;
478
+ box.left = box.top;
479
+ box.top = tempValue;
480
+ }
481
+ if (box.width !== box.height) {
482
+ tempValue = box.width;
483
+ box.width = box.height;
484
+ box.height = tempValue;
485
+ }
486
+ }
487
+ if (transformations.length) {
488
+ body = wrapSVGContent(
489
+ body,
490
+ '<g transform="' + transformations.join(" ") + '">',
491
+ "</g>"
492
+ );
493
+ }
494
+ });
495
+ const customisationsWidth = fullCustomisations.width;
496
+ const customisationsHeight = fullCustomisations.height;
497
+ const boxWidth = box.width;
498
+ const boxHeight = box.height;
499
+ let width;
500
+ let height;
501
+ if (customisationsWidth === null) {
502
+ height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
503
+ width = calculateSize(height, boxWidth / boxHeight);
504
+ } else {
505
+ width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
506
+ height = customisationsHeight === null ? calculateSize(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
507
+ }
508
+ const attributes = {};
509
+ const setAttr = (prop, value) => {
510
+ if (!isUnsetKeyword(value)) {
511
+ attributes[prop] = value.toString();
512
+ }
513
+ };
514
+ setAttr("width", width);
515
+ setAttr("height", height);
516
+ const viewBox = [box.left, box.top, boxWidth, boxHeight];
517
+ attributes.viewBox = viewBox.join(" ");
518
+ return {
519
+ attributes,
520
+ viewBox,
521
+ body
522
+ };
523
+ }
524
+ const regex = /\sid="(\S+)"/g;
525
+ const randomPrefix = "IconifyId" + Date.now().toString(16) + (Math.random() * 16777216 | 0).toString(16);
526
+ let counter = 0;
527
+ function replaceIDs(body, prefix = randomPrefix) {
528
+ const ids = [];
529
+ let match;
530
+ while (match = regex.exec(body)) {
531
+ ids.push(match[1]);
532
+ }
533
+ if (!ids.length) {
534
+ return body;
535
+ }
536
+ const suffix = "suffix" + (Math.random() * 16777216 | Date.now()).toString(16);
537
+ ids.forEach((id) => {
538
+ const newID = typeof prefix === "function" ? prefix(id) : prefix + (counter++).toString();
539
+ const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
540
+ body = body.replace(
541
+ // Allowed characters before id: [#;"]
542
+ // Allowed characters after id: [)"], .[a-z]
543
+ new RegExp('([#;"])(' + escapedID + ')([")]|\\.[a-z])', "g"),
544
+ "$1" + newID + suffix + "$3"
545
+ );
546
+ });
547
+ body = body.replace(new RegExp(suffix, "g"), "");
548
+ return body;
549
+ }
550
+ const storage = /* @__PURE__ */ Object.create(null);
551
+ function setAPIModule(provider, item) {
552
+ storage[provider] = item;
553
+ }
554
+ function getAPIModule(provider) {
555
+ return storage[provider] || storage[""];
556
+ }
557
+ function createAPIConfig(source) {
558
+ let resources;
559
+ if (typeof source.resources === "string") {
560
+ resources = [source.resources];
561
+ } else {
562
+ resources = source.resources;
563
+ if (!(resources instanceof Array) || !resources.length) {
564
+ return null;
565
+ }
566
+ }
567
+ const result = {
568
+ // API hosts
569
+ resources,
570
+ // Root path
571
+ path: source.path || "/",
572
+ // URL length limit
573
+ maxURL: source.maxURL || 500,
574
+ // Timeout before next host is used.
575
+ rotate: source.rotate || 750,
576
+ // Timeout before failing query.
577
+ timeout: source.timeout || 5e3,
578
+ // Randomise default API end point.
579
+ random: source.random === true,
580
+ // Start index
581
+ index: source.index || 0,
582
+ // Receive data after time out (used if time out kicks in first, then API module sends data anyway).
583
+ dataAfterTimeout: source.dataAfterTimeout !== false
584
+ };
585
+ return result;
586
+ }
587
+ const configStorage = /* @__PURE__ */ Object.create(null);
588
+ const fallBackAPISources = [
589
+ "https://api.simplesvg.com",
590
+ "https://api.unisvg.com"
591
+ ];
592
+ const fallBackAPI = [];
593
+ while (fallBackAPISources.length > 0) {
594
+ if (fallBackAPISources.length === 1) {
595
+ fallBackAPI.push(fallBackAPISources.shift());
596
+ } else {
597
+ if (Math.random() > 0.5) {
598
+ fallBackAPI.push(fallBackAPISources.shift());
599
+ } else {
600
+ fallBackAPI.push(fallBackAPISources.pop());
601
+ }
602
+ }
603
+ }
604
+ configStorage[""] = createAPIConfig({
605
+ resources: ["https://api.iconify.design"].concat(fallBackAPI)
606
+ });
607
+ function addAPIProvider(provider, customConfig) {
608
+ const config = createAPIConfig(customConfig);
609
+ if (config === null) {
610
+ return false;
611
+ }
612
+ configStorage[provider] = config;
613
+ return true;
614
+ }
615
+ function getAPIConfig(provider) {
616
+ return configStorage[provider];
617
+ }
618
+ function listAPIProviders() {
619
+ return Object.keys(configStorage);
620
+ }
621
+ const detectFetch = () => {
622
+ let callback;
623
+ try {
624
+ callback = fetch;
625
+ if (typeof callback === "function") {
626
+ return callback;
627
+ }
628
+ } catch (err) {
629
+ }
630
+ };
631
+ let fetchModule = detectFetch();
632
+ function setFetch(fetch2) {
633
+ fetchModule = fetch2;
634
+ }
635
+ function getFetch() {
636
+ return fetchModule;
637
+ }
638
+ function calculateMaxLength(provider, prefix) {
639
+ const config = getAPIConfig(provider);
640
+ if (!config) {
641
+ return 0;
642
+ }
643
+ let result;
644
+ if (!config.maxURL) {
645
+ result = 0;
646
+ } else {
647
+ let maxHostLength = 0;
648
+ config.resources.forEach((item) => {
649
+ const host = item;
650
+ maxHostLength = Math.max(maxHostLength, host.length);
651
+ });
652
+ const url = prefix + ".json?icons=";
653
+ result = config.maxURL - maxHostLength - config.path.length - url.length;
654
+ }
655
+ return result;
656
+ }
657
+ function shouldAbort(status) {
658
+ return status === 404;
659
+ }
660
+ const prepare = (provider, prefix, icons) => {
661
+ const results = [];
662
+ const maxLength = calculateMaxLength(provider, prefix);
663
+ const type = "icons";
664
+ let item = {
665
+ type,
666
+ provider,
667
+ prefix,
668
+ icons: []
669
+ };
670
+ let length = 0;
671
+ icons.forEach((name, index) => {
672
+ length += name.length + 1;
673
+ if (length >= maxLength && index > 0) {
674
+ results.push(item);
675
+ item = {
676
+ type,
677
+ provider,
678
+ prefix,
679
+ icons: []
680
+ };
681
+ length = name.length;
682
+ }
683
+ item.icons.push(name);
684
+ });
685
+ results.push(item);
686
+ return results;
687
+ };
688
+ function getPath(provider) {
689
+ if (typeof provider === "string") {
690
+ const config = getAPIConfig(provider);
691
+ if (config) {
692
+ return config.path;
693
+ }
694
+ }
695
+ return "/";
696
+ }
697
+ const send = (host, params, callback) => {
698
+ if (!fetchModule) {
699
+ callback("abort", 424);
700
+ return;
701
+ }
702
+ let path = getPath(params.provider);
703
+ switch (params.type) {
704
+ case "icons": {
705
+ const prefix = params.prefix;
706
+ const icons = params.icons;
707
+ const iconsList = icons.join(",");
708
+ const urlParams = new URLSearchParams({
709
+ icons: iconsList
710
+ });
711
+ path += prefix + ".json?" + urlParams.toString();
712
+ break;
713
+ }
714
+ case "custom": {
715
+ const uri = params.uri;
716
+ path += uri.slice(0, 1) === "/" ? uri.slice(1) : uri;
717
+ break;
718
+ }
719
+ default:
720
+ callback("abort", 400);
721
+ return;
722
+ }
723
+ let defaultError = 503;
724
+ fetchModule(host + path).then((response) => {
725
+ const status = response.status;
726
+ if (status !== 200) {
727
+ setTimeout(() => {
728
+ callback(shouldAbort(status) ? "abort" : "next", status);
729
+ });
730
+ return;
731
+ }
732
+ defaultError = 501;
733
+ return response.json();
734
+ }).then((data) => {
735
+ if (typeof data !== "object" || data === null) {
736
+ setTimeout(() => {
737
+ if (data === 404) {
738
+ callback("abort", data);
739
+ } else {
740
+ callback("next", defaultError);
741
+ }
742
+ });
743
+ return;
744
+ }
745
+ setTimeout(() => {
746
+ callback("success", data);
747
+ });
748
+ }).catch(() => {
749
+ callback("next", defaultError);
750
+ });
751
+ };
752
+ const fetchAPIModule = {
753
+ prepare,
754
+ send
755
+ };
756
+ function sortIcons(icons) {
757
+ const result = {
758
+ loaded: [],
759
+ missing: [],
760
+ pending: []
761
+ };
762
+ const storage2 = /* @__PURE__ */ Object.create(null);
763
+ icons.sort((a, b) => {
764
+ if (a.provider !== b.provider) {
765
+ return a.provider.localeCompare(b.provider);
766
+ }
767
+ if (a.prefix !== b.prefix) {
768
+ return a.prefix.localeCompare(b.prefix);
769
+ }
770
+ return a.name.localeCompare(b.name);
771
+ });
772
+ let lastIcon = {
773
+ provider: "",
774
+ prefix: "",
775
+ name: ""
776
+ };
777
+ icons.forEach((icon) => {
778
+ if (lastIcon.name === icon.name && lastIcon.prefix === icon.prefix && lastIcon.provider === icon.provider) {
779
+ return;
780
+ }
781
+ lastIcon = icon;
782
+ const provider = icon.provider;
783
+ const prefix = icon.prefix;
784
+ const name = icon.name;
785
+ const providerStorage = storage2[provider] || (storage2[provider] = /* @__PURE__ */ Object.create(null));
786
+ const localStorage = providerStorage[prefix] || (providerStorage[prefix] = getStorage(provider, prefix));
787
+ let list;
788
+ if (name in localStorage.icons) {
789
+ list = result.loaded;
790
+ } else if (prefix === "" || localStorage.missing.has(name)) {
791
+ list = result.missing;
792
+ } else {
793
+ list = result.pending;
794
+ }
795
+ const item = {
796
+ provider,
797
+ prefix,
798
+ name
799
+ };
800
+ list.push(item);
801
+ });
802
+ return result;
803
+ }
804
+ function removeCallback(storages, id) {
805
+ storages.forEach((storage2) => {
806
+ const items = storage2.loaderCallbacks;
807
+ if (items) {
808
+ storage2.loaderCallbacks = items.filter((row) => row.id !== id);
809
+ }
810
+ });
811
+ }
812
+ function updateCallbacks(storage2) {
813
+ if (!storage2.pendingCallbacksFlag) {
814
+ storage2.pendingCallbacksFlag = true;
815
+ setTimeout(() => {
816
+ storage2.pendingCallbacksFlag = false;
817
+ const items = storage2.loaderCallbacks ? storage2.loaderCallbacks.slice(0) : [];
818
+ if (!items.length) {
819
+ return;
820
+ }
821
+ let hasPending = false;
822
+ const provider = storage2.provider;
823
+ const prefix = storage2.prefix;
824
+ items.forEach((item) => {
825
+ const icons = item.icons;
826
+ const oldLength = icons.pending.length;
827
+ icons.pending = icons.pending.filter((icon) => {
828
+ if (icon.prefix !== prefix) {
829
+ return true;
830
+ }
831
+ const name = icon.name;
832
+ if (storage2.icons[name]) {
833
+ icons.loaded.push({
834
+ provider,
835
+ prefix,
836
+ name
837
+ });
838
+ } else if (storage2.missing.has(name)) {
839
+ icons.missing.push({
840
+ provider,
841
+ prefix,
842
+ name
843
+ });
844
+ } else {
845
+ hasPending = true;
846
+ return true;
847
+ }
848
+ return false;
849
+ });
850
+ if (icons.pending.length !== oldLength) {
851
+ if (!hasPending) {
852
+ removeCallback([storage2], item.id);
853
+ }
854
+ item.callback(
855
+ icons.loaded.slice(0),
856
+ icons.missing.slice(0),
857
+ icons.pending.slice(0),
858
+ item.abort
859
+ );
860
+ }
861
+ });
862
+ });
863
+ }
864
+ }
865
+ let idCounter = 0;
866
+ function storeCallback(callback, icons, pendingSources) {
867
+ const id = idCounter++;
868
+ const abort = removeCallback.bind(null, pendingSources, id);
869
+ if (!icons.pending.length) {
870
+ return abort;
871
+ }
872
+ const item = {
873
+ id,
874
+ icons,
875
+ callback,
876
+ abort
877
+ };
878
+ pendingSources.forEach((storage2) => {
879
+ (storage2.loaderCallbacks || (storage2.loaderCallbacks = [])).push(item);
880
+ });
881
+ return abort;
882
+ }
883
+ function listToIcons(list, validate = true, simpleNames2 = false) {
884
+ const result = [];
885
+ list.forEach((item) => {
886
+ const icon = typeof item === "string" ? stringToIcon(item, validate, simpleNames2) : item;
887
+ if (icon) {
888
+ result.push(icon);
889
+ }
890
+ });
891
+ return result;
892
+ }
893
+ var defaultConfig = {
894
+ resources: [],
895
+ index: 0,
896
+ timeout: 2e3,
897
+ rotate: 750,
898
+ random: false,
899
+ dataAfterTimeout: false
900
+ };
901
+ function sendQuery(config, payload, query, done) {
902
+ const resourcesCount = config.resources.length;
903
+ const startIndex = config.random ? Math.floor(Math.random() * resourcesCount) : config.index;
904
+ let resources;
905
+ if (config.random) {
906
+ let list = config.resources.slice(0);
907
+ resources = [];
908
+ while (list.length > 1) {
909
+ const nextIndex = Math.floor(Math.random() * list.length);
910
+ resources.push(list[nextIndex]);
911
+ list = list.slice(0, nextIndex).concat(list.slice(nextIndex + 1));
912
+ }
913
+ resources = resources.concat(list);
914
+ } else {
915
+ resources = config.resources.slice(startIndex).concat(config.resources.slice(0, startIndex));
916
+ }
917
+ const startTime = Date.now();
918
+ let status = "pending";
919
+ let queriesSent = 0;
920
+ let lastError;
921
+ let timer = null;
922
+ let queue = [];
923
+ let doneCallbacks = [];
924
+ if (typeof done === "function") {
925
+ doneCallbacks.push(done);
926
+ }
927
+ function resetTimer() {
928
+ if (timer) {
929
+ clearTimeout(timer);
930
+ timer = null;
931
+ }
932
+ }
933
+ function abort() {
934
+ if (status === "pending") {
935
+ status = "aborted";
936
+ }
937
+ resetTimer();
938
+ queue.forEach((item) => {
939
+ if (item.status === "pending") {
940
+ item.status = "aborted";
941
+ }
942
+ });
943
+ queue = [];
944
+ }
945
+ function subscribe(callback, overwrite) {
946
+ if (overwrite) {
947
+ doneCallbacks = [];
948
+ }
949
+ if (typeof callback === "function") {
950
+ doneCallbacks.push(callback);
951
+ }
952
+ }
953
+ function getQueryStatus() {
954
+ return {
955
+ startTime,
956
+ payload,
957
+ status,
958
+ queriesSent,
959
+ queriesPending: queue.length,
960
+ subscribe,
961
+ abort
962
+ };
963
+ }
964
+ function failQuery() {
965
+ status = "failed";
966
+ doneCallbacks.forEach((callback) => {
967
+ callback(void 0, lastError);
968
+ });
969
+ }
970
+ function clearQueue() {
971
+ queue.forEach((item) => {
972
+ if (item.status === "pending") {
973
+ item.status = "aborted";
974
+ }
975
+ });
976
+ queue = [];
977
+ }
978
+ function moduleResponse(item, response, data) {
979
+ const isError = response !== "success";
980
+ queue = queue.filter((queued) => queued !== item);
981
+ switch (status) {
982
+ case "pending":
983
+ break;
984
+ case "failed":
985
+ if (isError || !config.dataAfterTimeout) {
986
+ return;
987
+ }
988
+ break;
989
+ default:
990
+ return;
991
+ }
992
+ if (response === "abort") {
993
+ lastError = data;
994
+ failQuery();
995
+ return;
996
+ }
997
+ if (isError) {
998
+ lastError = data;
999
+ if (!queue.length) {
1000
+ if (!resources.length) {
1001
+ failQuery();
1002
+ } else {
1003
+ execNext();
1004
+ }
1005
+ }
1006
+ return;
1007
+ }
1008
+ resetTimer();
1009
+ clearQueue();
1010
+ if (!config.random) {
1011
+ const index = config.resources.indexOf(item.resource);
1012
+ if (index !== -1 && index !== config.index) {
1013
+ config.index = index;
1014
+ }
1015
+ }
1016
+ status = "completed";
1017
+ doneCallbacks.forEach((callback) => {
1018
+ callback(data);
1019
+ });
1020
+ }
1021
+ function execNext() {
1022
+ if (status !== "pending") {
1023
+ return;
1024
+ }
1025
+ resetTimer();
1026
+ const resource = resources.shift();
1027
+ if (resource === void 0) {
1028
+ if (queue.length) {
1029
+ timer = setTimeout(() => {
1030
+ resetTimer();
1031
+ if (status === "pending") {
1032
+ clearQueue();
1033
+ failQuery();
1034
+ }
1035
+ }, config.timeout);
1036
+ return;
1037
+ }
1038
+ failQuery();
1039
+ return;
1040
+ }
1041
+ const item = {
1042
+ status: "pending",
1043
+ resource,
1044
+ callback: (status2, data) => {
1045
+ moduleResponse(item, status2, data);
1046
+ }
1047
+ };
1048
+ queue.push(item);
1049
+ queriesSent++;
1050
+ timer = setTimeout(execNext, config.rotate);
1051
+ query(resource, payload, item.callback);
1052
+ }
1053
+ setTimeout(execNext);
1054
+ return getQueryStatus;
1055
+ }
1056
+ function initRedundancy(cfg) {
1057
+ const config = {
1058
+ ...defaultConfig,
1059
+ ...cfg
1060
+ };
1061
+ let queries = [];
1062
+ function cleanup() {
1063
+ queries = queries.filter((item) => item().status === "pending");
1064
+ }
1065
+ function query(payload, queryCallback, doneCallback) {
1066
+ const query2 = sendQuery(
1067
+ config,
1068
+ payload,
1069
+ queryCallback,
1070
+ (data, error) => {
1071
+ cleanup();
1072
+ if (doneCallback) {
1073
+ doneCallback(data, error);
1074
+ }
1075
+ }
1076
+ );
1077
+ queries.push(query2);
1078
+ return query2;
1079
+ }
1080
+ function find(callback) {
1081
+ return queries.find((value) => {
1082
+ return callback(value);
1083
+ }) || null;
1084
+ }
1085
+ const instance = {
1086
+ query,
1087
+ find,
1088
+ setIndex: (index) => {
1089
+ config.index = index;
1090
+ },
1091
+ getIndex: () => config.index,
1092
+ cleanup
1093
+ };
1094
+ return instance;
1095
+ }
1096
+ function emptyCallback$1() {
1097
+ }
1098
+ const redundancyCache = /* @__PURE__ */ Object.create(null);
1099
+ function getRedundancyCache(provider) {
1100
+ if (!redundancyCache[provider]) {
1101
+ const config = getAPIConfig(provider);
1102
+ if (!config) {
1103
+ return;
1104
+ }
1105
+ const redundancy = initRedundancy(config);
1106
+ const cachedReundancy = {
1107
+ config,
1108
+ redundancy
1109
+ };
1110
+ redundancyCache[provider] = cachedReundancy;
1111
+ }
1112
+ return redundancyCache[provider];
1113
+ }
1114
+ function sendAPIQuery(target, query, callback) {
1115
+ let redundancy;
1116
+ let send2;
1117
+ if (typeof target === "string") {
1118
+ const api = getAPIModule(target);
1119
+ if (!api) {
1120
+ callback(void 0, 424);
1121
+ return emptyCallback$1;
1122
+ }
1123
+ send2 = api.send;
1124
+ const cached = getRedundancyCache(target);
1125
+ if (cached) {
1126
+ redundancy = cached.redundancy;
1127
+ }
1128
+ } else {
1129
+ const config = createAPIConfig(target);
1130
+ if (config) {
1131
+ redundancy = initRedundancy(config);
1132
+ const moduleKey = target.resources ? target.resources[0] : "";
1133
+ const api = getAPIModule(moduleKey);
1134
+ if (api) {
1135
+ send2 = api.send;
1136
+ }
1137
+ }
1138
+ }
1139
+ if (!redundancy || !send2) {
1140
+ callback(void 0, 424);
1141
+ return emptyCallback$1;
1142
+ }
1143
+ return redundancy.query(query, send2, callback)().abort;
1144
+ }
1145
+ function emptyCallback() {
1146
+ }
1147
+ function loadedNewIcons(storage2) {
1148
+ if (!storage2.iconsLoaderFlag) {
1149
+ storage2.iconsLoaderFlag = true;
1150
+ setTimeout(() => {
1151
+ storage2.iconsLoaderFlag = false;
1152
+ updateCallbacks(storage2);
1153
+ });
1154
+ }
1155
+ }
1156
+ function checkIconNamesForAPI(icons) {
1157
+ const valid = [];
1158
+ const invalid = [];
1159
+ icons.forEach((name) => {
1160
+ (name.match(matchIconName) ? valid : invalid).push(name);
1161
+ });
1162
+ return {
1163
+ valid,
1164
+ invalid
1165
+ };
1166
+ }
1167
+ function parseLoaderResponse(storage2, icons, data) {
1168
+ function checkMissing() {
1169
+ const pending = storage2.pendingIcons;
1170
+ icons.forEach((name) => {
1171
+ if (pending) {
1172
+ pending.delete(name);
1173
+ }
1174
+ if (!storage2.icons[name]) {
1175
+ storage2.missing.add(name);
1176
+ }
1177
+ });
1178
+ }
1179
+ if (data && typeof data === "object") {
1180
+ try {
1181
+ const parsed = addIconSet(storage2, data);
1182
+ if (!parsed.length) {
1183
+ checkMissing();
1184
+ return;
1185
+ }
1186
+ } catch (err) {
1187
+ console.error(err);
1188
+ }
1189
+ }
1190
+ checkMissing();
1191
+ loadedNewIcons(storage2);
1192
+ }
1193
+ function parsePossiblyAsyncResponse(response, callback) {
1194
+ if (response instanceof Promise) {
1195
+ response.then((data) => {
1196
+ callback(data);
1197
+ }).catch(() => {
1198
+ callback(null);
1199
+ });
1200
+ } else {
1201
+ callback(response);
1202
+ }
1203
+ }
1204
+ function loadNewIcons(storage2, icons) {
1205
+ if (!storage2.iconsToLoad) {
1206
+ storage2.iconsToLoad = icons;
1207
+ } else {
1208
+ storage2.iconsToLoad = storage2.iconsToLoad.concat(icons).sort();
1209
+ }
1210
+ if (!storage2.iconsQueueFlag) {
1211
+ storage2.iconsQueueFlag = true;
1212
+ setTimeout(() => {
1213
+ storage2.iconsQueueFlag = false;
1214
+ const { provider, prefix } = storage2;
1215
+ const icons2 = storage2.iconsToLoad;
1216
+ delete storage2.iconsToLoad;
1217
+ if (!icons2 || !icons2.length) {
1218
+ return;
1219
+ }
1220
+ const customIconLoader = storage2.loadIcon;
1221
+ if (storage2.loadIcons && (icons2.length > 1 || !customIconLoader)) {
1222
+ parsePossiblyAsyncResponse(
1223
+ storage2.loadIcons(icons2, prefix, provider),
1224
+ (data) => {
1225
+ parseLoaderResponse(storage2, icons2, data);
1226
+ }
1227
+ );
1228
+ return;
1229
+ }
1230
+ if (customIconLoader) {
1231
+ icons2.forEach((name) => {
1232
+ const response = customIconLoader(name, prefix, provider);
1233
+ parsePossiblyAsyncResponse(response, (data) => {
1234
+ const iconSet = data ? {
1235
+ prefix,
1236
+ icons: {
1237
+ [name]: data
1238
+ }
1239
+ } : null;
1240
+ parseLoaderResponse(storage2, [name], iconSet);
1241
+ });
1242
+ });
1243
+ return;
1244
+ }
1245
+ const { valid, invalid } = checkIconNamesForAPI(icons2);
1246
+ if (invalid.length) {
1247
+ parseLoaderResponse(storage2, invalid, null);
1248
+ }
1249
+ if (!valid.length) {
1250
+ return;
1251
+ }
1252
+ const api = prefix.match(matchIconName) ? getAPIModule(provider) : null;
1253
+ if (!api) {
1254
+ parseLoaderResponse(storage2, valid, null);
1255
+ return;
1256
+ }
1257
+ const params = api.prepare(provider, prefix, valid);
1258
+ params.forEach((item) => {
1259
+ sendAPIQuery(provider, item, (data) => {
1260
+ parseLoaderResponse(storage2, item.icons, data);
1261
+ });
1262
+ });
1263
+ });
1264
+ }
1265
+ }
1266
+ const loadIcons = (icons, callback) => {
1267
+ const cleanedIcons = listToIcons(icons, true, allowSimpleNames());
1268
+ const sortedIcons = sortIcons(cleanedIcons);
1269
+ if (!sortedIcons.pending.length) {
1270
+ let callCallback = true;
1271
+ if (callback) {
1272
+ setTimeout(() => {
1273
+ if (callCallback) {
1274
+ callback(
1275
+ sortedIcons.loaded,
1276
+ sortedIcons.missing,
1277
+ sortedIcons.pending,
1278
+ emptyCallback
1279
+ );
1280
+ }
1281
+ });
1282
+ }
1283
+ return () => {
1284
+ callCallback = false;
1285
+ };
1286
+ }
1287
+ const newIcons = /* @__PURE__ */ Object.create(null);
1288
+ const sources = [];
1289
+ let lastProvider, lastPrefix;
1290
+ sortedIcons.pending.forEach((icon) => {
1291
+ const { provider, prefix } = icon;
1292
+ if (prefix === lastPrefix && provider === lastProvider) {
1293
+ return;
1294
+ }
1295
+ lastProvider = provider;
1296
+ lastPrefix = prefix;
1297
+ sources.push(getStorage(provider, prefix));
1298
+ const providerNewIcons = newIcons[provider] || (newIcons[provider] = /* @__PURE__ */ Object.create(null));
1299
+ if (!providerNewIcons[prefix]) {
1300
+ providerNewIcons[prefix] = [];
1301
+ }
1302
+ });
1303
+ sortedIcons.pending.forEach((icon) => {
1304
+ const { provider, prefix, name } = icon;
1305
+ const storage2 = getStorage(provider, prefix);
1306
+ const pendingQueue = storage2.pendingIcons || (storage2.pendingIcons = /* @__PURE__ */ new Set());
1307
+ if (!pendingQueue.has(name)) {
1308
+ pendingQueue.add(name);
1309
+ newIcons[provider][prefix].push(name);
1310
+ }
1311
+ });
1312
+ sources.forEach((storage2) => {
1313
+ const list = newIcons[storage2.provider][storage2.prefix];
1314
+ if (list.length) {
1315
+ loadNewIcons(storage2, list);
1316
+ }
1317
+ });
1318
+ return callback ? storeCallback(callback, sortedIcons, sources) : emptyCallback;
1319
+ };
1320
+ const loadIcon = (icon) => {
1321
+ return new Promise((fulfill, reject) => {
1322
+ const iconObj = typeof icon === "string" ? stringToIcon(icon, true) : icon;
1323
+ if (!iconObj) {
1324
+ reject(icon);
1325
+ return;
1326
+ }
1327
+ loadIcons([iconObj || icon], (loaded) => {
1328
+ if (loaded.length && iconObj) {
1329
+ const data = getIconData(iconObj);
1330
+ if (data) {
1331
+ fulfill({
1332
+ ...defaultIconProps,
1333
+ ...data
1334
+ });
1335
+ return;
1336
+ }
1337
+ }
1338
+ reject(icon);
1339
+ });
1340
+ });
1341
+ };
1342
+ function setCustomIconsLoader(loader, prefix, provider) {
1343
+ getStorage(provider || "", prefix).loadIcons = loader;
1344
+ }
1345
+ function setCustomIconLoader(loader, prefix, provider) {
1346
+ getStorage(provider || "", prefix).loadIcon = loader;
1347
+ }
1348
+ function mergeCustomisations(defaults, item) {
1349
+ const result = {
1350
+ ...defaults
1351
+ };
1352
+ for (const key in item) {
1353
+ const value = item[key];
1354
+ const valueType = typeof value;
1355
+ if (key in defaultIconSizeCustomisations) {
1356
+ if (value === null || value && (valueType === "string" || valueType === "number")) {
1357
+ result[key] = value;
1358
+ }
1359
+ } else if (valueType === typeof result[key]) {
1360
+ result[key] = key === "rotate" ? value % 4 : value;
1361
+ }
1362
+ }
1363
+ return result;
1364
+ }
1365
+ const separator = /[\s,]+/;
1366
+ function flipFromString(custom, flip) {
1367
+ flip.split(separator).forEach((str) => {
1368
+ const value = str.trim();
1369
+ switch (value) {
1370
+ case "horizontal":
1371
+ custom.hFlip = true;
1372
+ break;
1373
+ case "vertical":
1374
+ custom.vFlip = true;
1375
+ break;
1376
+ }
1377
+ });
1378
+ }
1379
+ function rotateFromString(value, defaultValue = 0) {
1380
+ const units = value.replace(/^-?[0-9.]*/, "");
1381
+ function cleanup(value2) {
1382
+ while (value2 < 0) {
1383
+ value2 += 4;
1384
+ }
1385
+ return value2 % 4;
1386
+ }
1387
+ if (units === "") {
1388
+ const num = parseInt(value);
1389
+ return isNaN(num) ? 0 : cleanup(num);
1390
+ } else if (units !== value) {
1391
+ let split = 0;
1392
+ switch (units) {
1393
+ case "%":
1394
+ split = 25;
1395
+ break;
1396
+ case "deg":
1397
+ split = 90;
1398
+ }
1399
+ if (split) {
1400
+ let num = parseFloat(value.slice(0, value.length - units.length));
1401
+ if (isNaN(num)) {
1402
+ return 0;
1403
+ }
1404
+ num = num / split;
1405
+ return num % 1 === 0 ? cleanup(num) : 0;
1406
+ }
1407
+ }
1408
+ return defaultValue;
1409
+ }
1410
+ function iconToHTML(body, attributes) {
1411
+ let renderAttribsHTML = body.indexOf("xlink:") === -1 ? "" : ' xmlns:xlink="http://www.w3.org/1999/xlink"';
1412
+ for (const attr in attributes) {
1413
+ renderAttribsHTML += " " + attr + '="' + attributes[attr] + '"';
1414
+ }
1415
+ return '<svg xmlns="http://www.w3.org/2000/svg"' + renderAttribsHTML + ">" + body + "</svg>";
1416
+ }
1417
+ function encodeSVGforURL(svg) {
1418
+ return svg.replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ");
1419
+ }
1420
+ function svgToData(svg) {
1421
+ return "data:image/svg+xml," + encodeSVGforURL(svg);
1422
+ }
1423
+ function svgToURL(svg) {
1424
+ return 'url("' + svgToData(svg) + '")';
1425
+ }
1426
+ const defaultExtendedIconCustomisations = {
1427
+ ...defaultIconCustomisations,
1428
+ inline: false
1429
+ };
1430
+ const svgDefaults = {
1431
+ "xmlns": "http://www.w3.org/2000/svg",
1432
+ "xmlns:xlink": "http://www.w3.org/1999/xlink",
1433
+ "aria-hidden": true,
1434
+ "role": "img"
1435
+ };
1436
+ const commonProps = {
1437
+ display: "inline-block"
1438
+ };
1439
+ const monotoneProps = {
1440
+ backgroundColor: "currentColor"
1441
+ };
1442
+ const coloredProps = {
1443
+ backgroundColor: "transparent"
1444
+ };
1445
+ const propsToAdd = {
1446
+ Image: "var(--svg)",
1447
+ Repeat: "no-repeat",
1448
+ Size: "100% 100%"
1449
+ };
1450
+ const propsToAddTo = {
1451
+ webkitMask: monotoneProps,
1452
+ mask: monotoneProps,
1453
+ background: coloredProps
1454
+ };
1455
+ for (const prefix in propsToAddTo) {
1456
+ const list = propsToAddTo[prefix];
1457
+ for (const prop in propsToAdd) {
1458
+ list[prefix + prop] = propsToAdd[prop];
1459
+ }
1460
+ }
1461
+ const customisationAliases = {};
1462
+ ["horizontal", "vertical"].forEach((prefix) => {
1463
+ const attr = prefix.slice(0, 1) + "Flip";
1464
+ customisationAliases[prefix + "-flip"] = attr;
1465
+ customisationAliases[prefix.slice(0, 1) + "-flip"] = attr;
1466
+ customisationAliases[prefix + "Flip"] = attr;
1467
+ });
1468
+ function fixSize(value) {
1469
+ return value + (value.match(/^[-0-9.]+$/) ? "px" : "");
1470
+ }
1471
+ const render = (icon, props) => {
1472
+ const customisations = mergeCustomisations(defaultExtendedIconCustomisations, props);
1473
+ const componentProps = { ...svgDefaults };
1474
+ const mode = props.mode || "svg";
1475
+ const style = {};
1476
+ const propsStyle = props.style;
1477
+ const customStyle = typeof propsStyle === "object" && !(propsStyle instanceof Array) ? propsStyle : {};
1478
+ for (let key in props) {
1479
+ const value = props[key];
1480
+ if (value === void 0) {
1481
+ continue;
1482
+ }
1483
+ switch (key) {
1484
+ // Properties to ignore
1485
+ case "icon":
1486
+ case "style":
1487
+ case "onLoad":
1488
+ case "mode":
1489
+ case "ssr":
1490
+ break;
1491
+ // Boolean attributes
1492
+ case "inline":
1493
+ case "hFlip":
1494
+ case "vFlip":
1495
+ customisations[key] = value === true || value === "true" || value === 1;
1496
+ break;
1497
+ // Flip as string: 'horizontal,vertical'
1498
+ case "flip":
1499
+ if (typeof value === "string") {
1500
+ flipFromString(customisations, value);
1501
+ }
1502
+ break;
1503
+ // Color: override style
1504
+ case "color":
1505
+ style.color = value;
1506
+ break;
1507
+ // Rotation as string
1508
+ case "rotate":
1509
+ if (typeof value === "string") {
1510
+ customisations[key] = rotateFromString(value);
1511
+ } else if (typeof value === "number") {
1512
+ customisations[key] = value;
1513
+ }
1514
+ break;
1515
+ // Remove aria-hidden
1516
+ case "ariaHidden":
1517
+ case "aria-hidden":
1518
+ if (value !== true && value !== "true") {
1519
+ delete componentProps["aria-hidden"];
1520
+ }
1521
+ break;
1522
+ default: {
1523
+ const alias = customisationAliases[key];
1524
+ if (alias) {
1525
+ if (value === true || value === "true" || value === 1) {
1526
+ customisations[alias] = true;
1527
+ }
1528
+ } else if (defaultExtendedIconCustomisations[key] === void 0) {
1529
+ componentProps[key] = value;
1530
+ }
1531
+ }
1532
+ }
1533
+ }
1534
+ const item = iconToSVG(icon, customisations);
1535
+ const renderAttribs = item.attributes;
1536
+ if (customisations.inline) {
1537
+ style.verticalAlign = "-0.125em";
1538
+ }
1539
+ if (mode === "svg") {
1540
+ componentProps.style = {
1541
+ ...style,
1542
+ ...customStyle
1543
+ };
1544
+ Object.assign(componentProps, renderAttribs);
1545
+ let localCounter = 0;
1546
+ let id = props.id;
1547
+ if (typeof id === "string") {
1548
+ id = id.replace(/-/g, "_");
1549
+ }
1550
+ componentProps["innerHTML"] = replaceIDs(item.body, id ? () => id + "ID" + localCounter++ : "iconifyVue");
1551
+ return h("svg", componentProps);
1552
+ }
1553
+ const { body, width, height } = icon;
1554
+ const useMask = mode === "mask" || (mode === "bg" ? false : body.indexOf("currentColor") !== -1);
1555
+ const html = iconToHTML(body, {
1556
+ ...renderAttribs,
1557
+ width: width + "",
1558
+ height: height + ""
1559
+ });
1560
+ componentProps.style = {
1561
+ ...style,
1562
+ "--svg": svgToURL(html),
1563
+ "width": fixSize(renderAttribs.width),
1564
+ "height": fixSize(renderAttribs.height),
1565
+ ...commonProps,
1566
+ ...useMask ? monotoneProps : coloredProps,
1567
+ ...customStyle
1568
+ };
1569
+ return h("span", componentProps);
1570
+ };
1571
+ allowSimpleNames(true);
1572
+ setAPIModule("", fetchAPIModule);
1573
+ if (typeof document !== "undefined" && typeof window !== "undefined") {
1574
+ const _window = window;
1575
+ if (_window.IconifyPreload !== void 0) {
1576
+ const preload = _window.IconifyPreload;
1577
+ const err = "Invalid IconifyPreload syntax.";
1578
+ if (typeof preload === "object" && preload !== null) {
1579
+ (preload instanceof Array ? preload : [preload]).forEach((item) => {
1580
+ try {
1581
+ if (
1582
+ // Check if item is an object and not null/array
1583
+ typeof item !== "object" || item === null || item instanceof Array || // Check for 'icons' and 'prefix'
1584
+ typeof item.icons !== "object" || typeof item.prefix !== "string" || // Add icon set
1585
+ !addCollection(item)
1586
+ ) {
1587
+ console.error(err);
1588
+ }
1589
+ } catch (e) {
1590
+ console.error(err);
1591
+ }
1592
+ });
1593
+ }
1594
+ }
1595
+ if (_window.IconifyProviders !== void 0) {
1596
+ const providers = _window.IconifyProviders;
1597
+ if (typeof providers === "object" && providers !== null) {
1598
+ for (let key in providers) {
1599
+ const err = "IconifyProviders[" + key + "] is invalid.";
1600
+ try {
1601
+ const value = providers[key];
1602
+ if (typeof value !== "object" || !value || value.resources === void 0) {
1603
+ continue;
1604
+ }
1605
+ if (!addAPIProvider(key, value)) {
1606
+ console.error(err);
1607
+ }
1608
+ } catch (e) {
1609
+ console.error(err);
1610
+ }
1611
+ }
1612
+ }
1613
+ }
1614
+ }
1615
+ const emptyIcon = {
1616
+ ...defaultIconProps,
1617
+ body: ""
1618
+ };
1619
+ const Icon = defineComponent((props, { emit }) => {
1620
+ const loader = ref(null);
1621
+ function abortLoading() {
1622
+ var _a, _b;
1623
+ if (loader.value) {
1624
+ (_b = (_a = loader.value).abort) == null ? void 0 : _b.call(_a);
1625
+ loader.value = null;
1626
+ }
1627
+ }
1628
+ const rendering = ref(!!props.ssr);
1629
+ const lastRenderedIconName = ref("");
1630
+ const iconData = shallowRef(null);
1631
+ function getIcon2() {
1632
+ const icon = props.icon;
1633
+ if (typeof icon === "object" && icon !== null && typeof icon.body === "string") {
1634
+ lastRenderedIconName.value = "";
1635
+ return {
1636
+ data: icon
1637
+ };
1638
+ }
1639
+ let iconName;
1640
+ if (typeof icon !== "string" || (iconName = stringToIcon(icon, false, true)) === null) {
1641
+ return null;
1642
+ }
1643
+ let data = getIconData(iconName);
1644
+ if (!data) {
1645
+ const oldState = loader.value;
1646
+ if (!oldState || oldState.name !== icon) {
1647
+ if (data === null) {
1648
+ loader.value = {
1649
+ name: icon
1650
+ };
1651
+ } else {
1652
+ loader.value = {
1653
+ name: icon,
1654
+ abort: loadIcons([iconName], updateIconData)
1655
+ };
1656
+ }
1657
+ }
1658
+ return null;
1659
+ }
1660
+ abortLoading();
1661
+ if (lastRenderedIconName.value !== icon) {
1662
+ lastRenderedIconName.value = icon;
1663
+ nextTick(() => {
1664
+ emit("load", icon);
1665
+ });
1666
+ }
1667
+ const customise = props.customise;
1668
+ if (customise) {
1669
+ data = Object.assign({}, data);
1670
+ const customised = customise(data.body, iconName.name, iconName.prefix, iconName.provider);
1671
+ if (typeof customised === "string") {
1672
+ data.body = customised;
1673
+ }
1674
+ }
1675
+ const classes = ["iconify"];
1676
+ if (iconName.prefix !== "") {
1677
+ classes.push("iconify--" + iconName.prefix);
1678
+ }
1679
+ if (iconName.provider !== "") {
1680
+ classes.push("iconify--" + iconName.provider);
1681
+ }
1682
+ return { data, classes };
1683
+ }
1684
+ function updateIconData() {
1685
+ var _a;
1686
+ const icon = getIcon2();
1687
+ if (!icon) {
1688
+ iconData.value = null;
1689
+ } else if (icon.data !== ((_a = iconData.value) == null ? void 0 : _a.data)) {
1690
+ iconData.value = icon;
1691
+ }
1692
+ }
1693
+ if (rendering.value) {
1694
+ updateIconData();
1695
+ } else {
1696
+ onMounted(() => {
1697
+ rendering.value = true;
1698
+ updateIconData();
1699
+ });
1700
+ }
1701
+ watch(() => props.icon, updateIconData);
1702
+ onUnmounted(abortLoading);
1703
+ return () => {
1704
+ const icon = iconData.value;
1705
+ if (!icon) {
1706
+ return render(emptyIcon, props);
1707
+ }
1708
+ let newProps = props;
1709
+ if (icon.classes) {
1710
+ newProps = {
1711
+ ...props,
1712
+ class: icon.classes.join(" ")
1713
+ };
1714
+ }
1715
+ return render({
1716
+ ...defaultIconProps,
1717
+ ...icon.data
1718
+ }, newProps);
1719
+ };
1720
+ }, {
1721
+ props: [
1722
+ // Icon and render mode
1723
+ "icon",
1724
+ "mode",
1725
+ "ssr",
1726
+ // Layout and style
1727
+ "width",
1728
+ "height",
1729
+ "style",
1730
+ "color",
1731
+ "inline",
1732
+ // Transformations
1733
+ "rotate",
1734
+ "hFlip",
1735
+ "horizontalFlip",
1736
+ "vFlip",
1737
+ "verticalFlip",
1738
+ "flip",
1739
+ // Misc
1740
+ "id",
1741
+ "ariaHidden",
1742
+ "customise",
1743
+ "title"
1744
+ ],
1745
+ emits: ["load"]
1746
+ });
1747
+ const _api = {
1748
+ getAPIConfig,
1749
+ setAPIModule,
1750
+ sendAPIQuery,
1751
+ setFetch,
1752
+ getFetch,
1753
+ listAPIProviders
1754
+ };
1755
+ export {
1756
+ Icon,
1757
+ _api,
1758
+ addAPIProvider,
1759
+ addCollection,
1760
+ addIcon,
1761
+ iconToSVG as buildIcon,
1762
+ calculateSize,
1763
+ getIcon,
1764
+ iconLoaded,
1765
+ listIcons,
1766
+ loadIcon,
1767
+ loadIcons,
1768
+ replaceIDs,
1769
+ setCustomIconLoader,
1770
+ setCustomIconsLoader
1771
+ };