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