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