@iconify/css-solid 1.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.
- package/dist/basic.d.ts +9 -0
- package/dist/basic.js +31 -0
- package/dist/content-CDW-lEJw.js +164 -0
- package/dist/create-Dw3RUxi7.js +66 -0
- package/dist/defaults-Chz3Ncto.js +26 -0
- package/dist/helpers/add.d.ts +6 -0
- package/dist/helpers/add.js +4 -0
- package/dist/helpers/api.d.ts +63 -0
- package/dist/helpers/api.js +4 -0
- package/dist/helpers/get-icon.d.ts +9 -0
- package/dist/helpers/get-icon.js +16 -0
- package/dist/helpers/ids.d.ts +5 -0
- package/dist/helpers/ids.js +3 -0
- package/dist/helpers/load-icon.d.ts +7 -0
- package/dist/helpers/load-icon.js +32 -0
- package/dist/helpers/load-icons.d.ts +16 -0
- package/dist/helpers/load-icons.js +84 -0
- package/dist/helpers/preload.d.ts +7 -0
- package/dist/helpers/preload.js +16 -0
- package/dist/helpers/size.d.ts +16 -0
- package/dist/helpers/size.js +3 -0
- package/dist/helpers/subscribe.d.ts +17 -0
- package/dist/helpers/subscribe.js +7 -0
- package/dist/helpers/support.d.ts +7 -0
- package/dist/helpers/support.js +3 -0
- package/dist/id-T2WpjqBw.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +83 -0
- package/dist/loaders-DBdOeKSg.js +22 -0
- package/dist/name-DNHxp3hA.d.ts +12 -0
- package/dist/name-IUXED86s.js +58 -0
- package/dist/parse-BHmkG8X9.js +104 -0
- package/dist/props.d.ts +17 -0
- package/dist/props.js +1 -0
- package/dist/queue-Bmgy8iLP.js +135 -0
- package/dist/size-B1gNk5pj.js +59 -0
- package/dist/status-AnfUd3wQ.js +5 -0
- package/dist/storage-B47thT4x.js +99 -0
- package/dist/subscribe-B6af4-2Z.js +68 -0
- package/dist/subscription-CamYRvPj.js +23 -0
- package/dist/support-CYSnYd4U.js +14 -0
- package/license.txt +21 -0
- package/package.json +50 -0
package/dist/basic.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSIconComponentProps, CSSIconComponentViewbox, CSSIconElementProps } from "./props.js";
|
|
2
|
+
import { JSX } from "solid-js";
|
|
3
|
+
/**
|
|
4
|
+
* Basic icon component, without fallback
|
|
5
|
+
*
|
|
6
|
+
* Can be used when you do not need a fallback icon
|
|
7
|
+
*/
|
|
8
|
+
declare function Icon(props: CSSIconElementProps): JSX.Element;
|
|
9
|
+
export { type CSSIconComponentProps, type CSSIconComponentViewbox, type CSSIconElementProps, Icon };
|
package/dist/basic.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as renderContent } from "./content-CDW-lEJw.js";
|
|
2
|
+
import { t as getSizeProps } from "./size-B1gNk5pj.js";
|
|
3
|
+
import { createMemo, splitProps } from "solid-js";
|
|
4
|
+
import { mergeProps, spread, template } from "solid-js/web";
|
|
5
|
+
|
|
6
|
+
const _tmpl$ = /* @__PURE__ */ template(`<svg xmlns=http://www.w3.org/2000/svg>`);
|
|
7
|
+
/**
|
|
8
|
+
* Basic icon component, without fallback
|
|
9
|
+
*
|
|
10
|
+
* Can be used when you do not need a fallback icon
|
|
11
|
+
*/
|
|
12
|
+
function Icon(props) {
|
|
13
|
+
const [local, others] = splitProps(props, [
|
|
14
|
+
"content",
|
|
15
|
+
"fallback",
|
|
16
|
+
"width",
|
|
17
|
+
"height",
|
|
18
|
+
"viewBox"
|
|
19
|
+
]);
|
|
20
|
+
const renderedContent = createMemo(() => renderContent(local.content || ""));
|
|
21
|
+
const size = createMemo(() => getSizeProps(local.width, local.height, local.viewBox));
|
|
22
|
+
return (() => {
|
|
23
|
+
const _el$ = _tmpl$();
|
|
24
|
+
spread(_el$, mergeProps(size, others, { get innerHTML() {
|
|
25
|
+
return renderedContent();
|
|
26
|
+
} }), true, false);
|
|
27
|
+
return _el$;
|
|
28
|
+
})();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { Icon };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { n as replaceIDs } from "./id-T2WpjqBw.js";
|
|
2
|
+
import { n as defaultIconProps, r as defaultIconTransformations } from "./defaults-Chz3Ncto.js";
|
|
3
|
+
import { n as calculateSize } from "./size-B1gNk5pj.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Default icon customisations values
|
|
7
|
+
*/
|
|
8
|
+
const defaultIconSizeCustomisations = Object.freeze({
|
|
9
|
+
width: null,
|
|
10
|
+
height: null
|
|
11
|
+
});
|
|
12
|
+
const defaultIconCustomisations = Object.freeze({
|
|
13
|
+
...defaultIconSizeCustomisations,
|
|
14
|
+
...defaultIconTransformations
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function splitSVGDefs(content, tag = "defs") {
|
|
18
|
+
let defs = "";
|
|
19
|
+
const index = content.indexOf("<" + tag);
|
|
20
|
+
while (index >= 0) {
|
|
21
|
+
const start = content.indexOf(">", index);
|
|
22
|
+
const end = content.indexOf("</" + tag);
|
|
23
|
+
if (start === -1 || end === -1) break;
|
|
24
|
+
const endEnd = content.indexOf(">", end);
|
|
25
|
+
if (endEnd === -1) break;
|
|
26
|
+
defs += content.slice(start + 1, end).trim();
|
|
27
|
+
content = content.slice(0, index).trim() + content.slice(endEnd + 1);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
defs,
|
|
31
|
+
content
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Merge defs and content
|
|
36
|
+
*/
|
|
37
|
+
function mergeDefsAndContent(defs, content) {
|
|
38
|
+
return defs ? "<defs>" + defs + "</defs>" + content : content;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wrap SVG content, without wrapping definitions
|
|
42
|
+
*/
|
|
43
|
+
function wrapSVGContent(body, start, end) {
|
|
44
|
+
const split = splitSVGDefs(body);
|
|
45
|
+
return mergeDefsAndContent(split.defs, start + split.content + end);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Check if value should be unset. Allows multiple keywords
|
|
50
|
+
*/
|
|
51
|
+
const isUnsetKeyword = (value) => value === "unset" || value === "undefined" || value === "none";
|
|
52
|
+
/**
|
|
53
|
+
* Get SVG attributes and content from icon + customisations
|
|
54
|
+
*
|
|
55
|
+
* Does not generate style to make it compatible with frameworks that use objects for style, such as React.
|
|
56
|
+
* Instead, it generates 'inline' value. If true, rendering engine should add verticalAlign: -0.125em to icon.
|
|
57
|
+
*
|
|
58
|
+
* Customisations should be normalised by platform specific parser.
|
|
59
|
+
* Result should be converted to <svg> by platform specific parser.
|
|
60
|
+
* Use replaceIDs to generate unique IDs for body.
|
|
61
|
+
*/
|
|
62
|
+
function iconToSVG(icon, customisations) {
|
|
63
|
+
const fullIcon = {
|
|
64
|
+
...defaultIconProps,
|
|
65
|
+
...icon
|
|
66
|
+
};
|
|
67
|
+
const fullCustomisations = {
|
|
68
|
+
...defaultIconCustomisations,
|
|
69
|
+
...customisations
|
|
70
|
+
};
|
|
71
|
+
const box = {
|
|
72
|
+
left: fullIcon.left,
|
|
73
|
+
top: fullIcon.top,
|
|
74
|
+
width: fullIcon.width,
|
|
75
|
+
height: fullIcon.height
|
|
76
|
+
};
|
|
77
|
+
let body = fullIcon.body;
|
|
78
|
+
[fullIcon, fullCustomisations].forEach((props) => {
|
|
79
|
+
const transformations = [];
|
|
80
|
+
const hFlip = props.hFlip;
|
|
81
|
+
const vFlip = props.vFlip;
|
|
82
|
+
let rotation = props.rotate;
|
|
83
|
+
if (hFlip) if (vFlip) rotation += 2;
|
|
84
|
+
else {
|
|
85
|
+
transformations.push("translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")");
|
|
86
|
+
transformations.push("scale(-1 1)");
|
|
87
|
+
box.top = box.left = 0;
|
|
88
|
+
}
|
|
89
|
+
else if (vFlip) {
|
|
90
|
+
transformations.push("translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")");
|
|
91
|
+
transformations.push("scale(1 -1)");
|
|
92
|
+
box.top = box.left = 0;
|
|
93
|
+
}
|
|
94
|
+
let tempValue;
|
|
95
|
+
if (rotation < 0) rotation -= Math.floor(rotation / 4) * 4;
|
|
96
|
+
rotation = rotation % 4;
|
|
97
|
+
switch (rotation) {
|
|
98
|
+
case 1:
|
|
99
|
+
tempValue = box.height / 2 + box.top;
|
|
100
|
+
transformations.unshift("rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")");
|
|
101
|
+
break;
|
|
102
|
+
case 2:
|
|
103
|
+
transformations.unshift("rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")");
|
|
104
|
+
break;
|
|
105
|
+
case 3:
|
|
106
|
+
tempValue = box.width / 2 + box.left;
|
|
107
|
+
transformations.unshift("rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")");
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
if (rotation % 2 === 1) {
|
|
111
|
+
if (box.left !== box.top) {
|
|
112
|
+
tempValue = box.left;
|
|
113
|
+
box.left = box.top;
|
|
114
|
+
box.top = tempValue;
|
|
115
|
+
}
|
|
116
|
+
if (box.width !== box.height) {
|
|
117
|
+
tempValue = box.width;
|
|
118
|
+
box.width = box.height;
|
|
119
|
+
box.height = tempValue;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (transformations.length) body = wrapSVGContent(body, "<g transform=\"" + transformations.join(" ") + "\">", "</g>");
|
|
123
|
+
});
|
|
124
|
+
const customisationsWidth = fullCustomisations.width;
|
|
125
|
+
const customisationsHeight = fullCustomisations.height;
|
|
126
|
+
const boxWidth = box.width;
|
|
127
|
+
const boxHeight = box.height;
|
|
128
|
+
let width;
|
|
129
|
+
let height;
|
|
130
|
+
if (customisationsWidth === null) {
|
|
131
|
+
height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
|
132
|
+
width = calculateSize(height, boxWidth / boxHeight);
|
|
133
|
+
} else {
|
|
134
|
+
width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
|
|
135
|
+
height = customisationsHeight === null ? calculateSize(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
|
|
136
|
+
}
|
|
137
|
+
const attributes = {};
|
|
138
|
+
const setAttr = (prop, value) => {
|
|
139
|
+
if (!isUnsetKeyword(value)) attributes[prop] = value.toString();
|
|
140
|
+
};
|
|
141
|
+
setAttr("width", width);
|
|
142
|
+
setAttr("height", height);
|
|
143
|
+
const viewBox = [
|
|
144
|
+
box.left,
|
|
145
|
+
box.top,
|
|
146
|
+
boxWidth,
|
|
147
|
+
boxHeight
|
|
148
|
+
];
|
|
149
|
+
attributes.viewBox = viewBox.join(" ");
|
|
150
|
+
return {
|
|
151
|
+
attributes,
|
|
152
|
+
viewBox,
|
|
153
|
+
body
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Convert content to string, replacing IDs to make them unique
|
|
159
|
+
*/
|
|
160
|
+
function renderContent(content) {
|
|
161
|
+
return replaceIDs(typeof content === "string" ? content : iconToSVG(content).body);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export { renderContent as t };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { t as matchIconName } from "./name-IUXED86s.js";
|
|
2
|
+
|
|
3
|
+
const indexCache = /* @__PURE__ */ new Map();
|
|
4
|
+
const delay = 750;
|
|
5
|
+
let _fetch = fetch;
|
|
6
|
+
/**
|
|
7
|
+
* Set custom fetch function
|
|
8
|
+
*/
|
|
9
|
+
function setFetch(fetchFn) {
|
|
10
|
+
_fetch = fetchFn;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetch JSON data
|
|
14
|
+
*/
|
|
15
|
+
function fetchJSON(hosts, endpoint, init, controller) {
|
|
16
|
+
const cacheKey = hosts.join(",");
|
|
17
|
+
const startIndex = indexCache.get(cacheKey) || 0;
|
|
18
|
+
const total = hosts.length;
|
|
19
|
+
controller = controller || new AbortController();
|
|
20
|
+
init = init || {};
|
|
21
|
+
init.signal = controller.signal;
|
|
22
|
+
const promises = [];
|
|
23
|
+
for (let i = 0; i < total; i++) {
|
|
24
|
+
const scopeIndex = i;
|
|
25
|
+
const index = (startIndex + scopeIndex) % total;
|
|
26
|
+
const url = `${hosts[index]}${endpoint}`;
|
|
27
|
+
const promise = async () => {
|
|
28
|
+
for (let i = 0; i < scopeIndex; i++) {
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
30
|
+
if (controller.signal.aborted) throw new Error("Fetch aborted");
|
|
31
|
+
}
|
|
32
|
+
const response = await _fetch(url, init);
|
|
33
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
34
|
+
const result = await response.json();
|
|
35
|
+
indexCache.set(cacheKey, index);
|
|
36
|
+
controller.abort();
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
promises.push(promise());
|
|
40
|
+
}
|
|
41
|
+
return Promise.any(promises);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create loader for Iconify API
|
|
46
|
+
*/
|
|
47
|
+
function createIconifyAPILoader(host, init, checkSSR = true) {
|
|
48
|
+
const hosts = Array.isArray(host) ? host : [host];
|
|
49
|
+
const isSSR = checkSSR ? typeof window === "undefined" || !window.document : checkSSR;
|
|
50
|
+
return {
|
|
51
|
+
maxCount: 32,
|
|
52
|
+
maxLength: 480,
|
|
53
|
+
validateNames: true,
|
|
54
|
+
hosts,
|
|
55
|
+
loadIcons: async (names, prefix) => {
|
|
56
|
+
if (isSSR || !matchIconName.test(prefix)) return {
|
|
57
|
+
prefix,
|
|
58
|
+
icons: Object.create(null),
|
|
59
|
+
not_found: names
|
|
60
|
+
};
|
|
61
|
+
return await fetchJSON(hosts, `/${prefix}.json?icons=${names.join(",")}`, init);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { fetchJSON as n, setFetch as r, createIconifyAPILoader as t };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Default values for dimensions */
|
|
2
|
+
const defaultIconDimensions = Object.freeze({
|
|
3
|
+
left: 0,
|
|
4
|
+
top: 0,
|
|
5
|
+
width: 16,
|
|
6
|
+
height: 16
|
|
7
|
+
});
|
|
8
|
+
/** Default values for transformations */
|
|
9
|
+
const defaultIconTransformations = Object.freeze({
|
|
10
|
+
rotate: 0,
|
|
11
|
+
vFlip: false,
|
|
12
|
+
hFlip: false
|
|
13
|
+
});
|
|
14
|
+
/** Default values for all optional IconifyIcon properties */
|
|
15
|
+
const defaultIconProps = Object.freeze({
|
|
16
|
+
...defaultIconDimensions,
|
|
17
|
+
...defaultIconTransformations
|
|
18
|
+
});
|
|
19
|
+
/** Default values for all properties used in ExtendedIconifyIcon */
|
|
20
|
+
const defaultExtendedIconProps = Object.freeze({
|
|
21
|
+
...defaultIconProps,
|
|
22
|
+
body: "",
|
|
23
|
+
hidden: false
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { defaultIconProps as n, defaultIconTransformations as r, defaultExtendedIconProps as t };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { IconifyIcon, IconifyJSON } from "@iconify/types";
|
|
2
|
+
/**
|
|
3
|
+
* Set custom fetch function
|
|
4
|
+
*/
|
|
5
|
+
declare function setFetch(fetchFn: typeof fetch): void;
|
|
6
|
+
/**
|
|
7
|
+
* Fetch JSON data
|
|
8
|
+
*/
|
|
9
|
+
declare function fetchJSON<T>(hosts: string[], endpoint: string, init?: RequestInit, controller?: AbortController): Promise<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Configuration for splitting queue into multiple queues
|
|
12
|
+
*/
|
|
13
|
+
interface QueueSplitConfig {
|
|
14
|
+
maxLength?: number;
|
|
15
|
+
maxCount?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Loader for one icon
|
|
19
|
+
*/
|
|
20
|
+
type IconLoader = (name: string, prefix: string, provider: string) => Promise<IconifyIcon | null>;
|
|
21
|
+
interface ConfigWithIconLoader {
|
|
22
|
+
loadIcon: IconLoader;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Loader for multiple icons at once
|
|
26
|
+
*/
|
|
27
|
+
type BulkIconLoader = (names: string[], prefix: string, provider: string) => Promise<IconifyJSON | null>;
|
|
28
|
+
interface ConfigWithBulkIconLoader {
|
|
29
|
+
loadIcons: BulkIconLoader;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Loader: either for one icon or multiple icons
|
|
33
|
+
*/
|
|
34
|
+
type IconLoaderConfig = ConfigWithIconLoader | ConfigWithBulkIconLoader;
|
|
35
|
+
/**
|
|
36
|
+
* Various properties
|
|
37
|
+
*/
|
|
38
|
+
interface ConfigProps extends QueueSplitConfig {
|
|
39
|
+
validateNames?: boolean;
|
|
40
|
+
allowReload?: boolean;
|
|
41
|
+
hosts?: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration for loader
|
|
45
|
+
*/
|
|
46
|
+
type LoaderConfig = ConfigProps & IconLoaderConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Create loader for Iconify API
|
|
49
|
+
*/
|
|
50
|
+
declare function createIconifyAPILoader(host: string | string[], init?: RequestInit, checkSSR?: boolean): LoaderConfig;
|
|
51
|
+
/**
|
|
52
|
+
* Set custom loader for an icon set
|
|
53
|
+
*/
|
|
54
|
+
declare function setLoader(prefix: string, loader: LoaderConfig): void;
|
|
55
|
+
/**
|
|
56
|
+
* Set custom loader for a provider
|
|
57
|
+
*/
|
|
58
|
+
declare function setProviderLoader(provider: string, loader: LoaderConfig): void;
|
|
59
|
+
/**
|
|
60
|
+
* Get loader
|
|
61
|
+
*/
|
|
62
|
+
declare function getLoader(provider: string, prefix: string): LoaderConfig | undefined;
|
|
63
|
+
export { type LoaderConfig, createIconifyAPILoader, fetchJSON, getLoader, setFetch, setLoader, setProviderLoader };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { n as setLoader, r as setProviderLoader, t as getLoader } from "../loaders-DBdOeKSg.js";
|
|
2
|
+
import { n as fetchJSON, r as setFetch, t as createIconifyAPILoader } from "../create-Dw3RUxi7.js";
|
|
3
|
+
|
|
4
|
+
export { createIconifyAPILoader, fetchJSON, getLoader, setFetch, setLoader, setProviderLoader };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { t as IconifyIconName } from "../name-DNHxp3hA.js";
|
|
2
|
+
import { IconifyIcon } from "@iconify/types";
|
|
3
|
+
/**
|
|
4
|
+
* Get icon data
|
|
5
|
+
*
|
|
6
|
+
* Returns icon data if icon is loaded, null if icon is missing, undefined if icon is unknown
|
|
7
|
+
*/
|
|
8
|
+
declare function getLoadedIcon(iconName: string | IconifyIconName): IconifyIcon | null | undefined;
|
|
9
|
+
export { getLoadedIcon };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { n as stringToIcon } from "../name-IUXED86s.js";
|
|
2
|
+
import { t as getIconStorage } from "../storage-B47thT4x.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get icon data
|
|
6
|
+
*
|
|
7
|
+
* Returns icon data if icon is loaded, null if icon is missing, undefined if icon is unknown
|
|
8
|
+
*/
|
|
9
|
+
function getLoadedIcon(iconName) {
|
|
10
|
+
const icon = typeof iconName === "string" ? stringToIcon(iconName) : iconName;
|
|
11
|
+
if (!icon) return null;
|
|
12
|
+
const storage = getIconStorage(icon.provider, icon.prefix);
|
|
13
|
+
return storage.icons[icon.name] ?? (storage.missing.has(icon.name) ? null : void 0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getLoadedIcon };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "../loaders-DBdOeKSg.js";
|
|
2
|
+
import { n as stringToIcon } from "../name-IUXED86s.js";
|
|
3
|
+
import "../parse-BHmkG8X9.js";
|
|
4
|
+
import { t as getIconStorage } from "../storage-B47thT4x.js";
|
|
5
|
+
import { n as unsubscribeFromIconStorage, t as subscribeToIconStorage } from "../subscription-CamYRvPj.js";
|
|
6
|
+
import { t as loadIcons } from "../queue-Bmgy8iLP.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Load icon
|
|
10
|
+
*/
|
|
11
|
+
function loadIcon(iconName) {
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const icon = typeof iconName === "string" ? stringToIcon(iconName) : iconName;
|
|
14
|
+
if (!icon) return resolve(null);
|
|
15
|
+
const { provider, prefix, name } = icon;
|
|
16
|
+
const storage = getIconStorage(provider, prefix);
|
|
17
|
+
const check = () => {
|
|
18
|
+
if (storage.icons[name]) resolve(storage.icons[name]);
|
|
19
|
+
else if (storage.missing.has(name)) resolve(null);
|
|
20
|
+
else return true;
|
|
21
|
+
};
|
|
22
|
+
if (check()) {
|
|
23
|
+
const subscriber = subscribeToIconStorage(storage, [name], () => {
|
|
24
|
+
unsubscribeFromIconStorage(storage, subscriber);
|
|
25
|
+
if (check()) resolve(null);
|
|
26
|
+
});
|
|
27
|
+
loadIcons({ [provider]: { [prefix]: [name] } });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { loadIcon };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as IconifyIconName } from "../name-DNHxp3hA.js";
|
|
2
|
+
/**
|
|
3
|
+
* Provider specific data mixin: [prefix] = T
|
|
4
|
+
*/
|
|
5
|
+
type ProviderData<T> = Record<string, T>;
|
|
6
|
+
/**
|
|
7
|
+
* Icons data mixin: [provider][prefix] = T
|
|
8
|
+
*/
|
|
9
|
+
type IconsData<T> = Record<string, ProviderData<T>>;
|
|
10
|
+
/**
|
|
11
|
+
* Load icon(s)
|
|
12
|
+
*
|
|
13
|
+
* Returns function that can be used to cancel loading
|
|
14
|
+
*/
|
|
15
|
+
declare function loadIconsWithCallback(iconNames: (string | IconifyIconName)[] | IconsData<string[]>, callback: (loaded: string[], missing: string[], pending: string[]) => void): () => void;
|
|
16
|
+
export { loadIconsWithCallback };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "../loaders-DBdOeKSg.js";
|
|
2
|
+
import "../parse-BHmkG8X9.js";
|
|
3
|
+
import { n as iterateIconStorage, t as getIconStorage } from "../storage-B47thT4x.js";
|
|
4
|
+
import { n as unsubscribeFromIconStorage, t as subscribeToIconStorage } from "../subscription-CamYRvPj.js";
|
|
5
|
+
import { n as splitIconNames, t as loadIcons } from "../queue-Bmgy8iLP.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Unsubscribe from all icon storage updates
|
|
9
|
+
*/
|
|
10
|
+
function unsubscribeFromAllIconStorage(key) {
|
|
11
|
+
iterateIconStorage((storage) => {
|
|
12
|
+
unsubscribeFromIconStorage(storage, key);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Watch icon storage updates for specific names
|
|
17
|
+
*/
|
|
18
|
+
function toggleIconStorage(names, callback, key) {
|
|
19
|
+
key = key || Symbol();
|
|
20
|
+
for (const provider in names) {
|
|
21
|
+
const prefixes = names[provider];
|
|
22
|
+
for (const prefix in prefixes) {
|
|
23
|
+
const icons = prefixes[prefix];
|
|
24
|
+
const storage = getIconStorage(provider, prefix);
|
|
25
|
+
if (icons.length) subscribeToIconStorage(storage, icons, callback, key);
|
|
26
|
+
else unsubscribeFromIconStorage(storage, key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load icon(s)
|
|
34
|
+
*
|
|
35
|
+
* Returns function that can be used to cancel loading
|
|
36
|
+
*/
|
|
37
|
+
function loadIconsWithCallback(iconNames, callback) {
|
|
38
|
+
const key = Symbol();
|
|
39
|
+
let aborted = false;
|
|
40
|
+
const abort = () => {
|
|
41
|
+
aborted = true;
|
|
42
|
+
unsubscribeFromAllIconStorage(key);
|
|
43
|
+
};
|
|
44
|
+
const icons = Array.isArray(iconNames) ? splitIconNames(iconNames) : iconNames;
|
|
45
|
+
let lastPending = -1;
|
|
46
|
+
const check = () => {
|
|
47
|
+
const loaded = [];
|
|
48
|
+
const missing = [];
|
|
49
|
+
const pending = [];
|
|
50
|
+
for (const provider in icons) {
|
|
51
|
+
const providerData = icons[provider];
|
|
52
|
+
for (const prefix in providerData) {
|
|
53
|
+
const names = providerData[prefix];
|
|
54
|
+
if (names.length) {
|
|
55
|
+
const storage = getIconStorage(provider, prefix);
|
|
56
|
+
for (const name of names) {
|
|
57
|
+
const partialName = `${prefix}:${name}`;
|
|
58
|
+
const fullName = provider ? `@${provider}:${partialName}` : partialName;
|
|
59
|
+
if (storage.icons[name]) loaded.push(fullName);
|
|
60
|
+
else if (storage.missing.has(name)) missing.push(fullName);
|
|
61
|
+
else pending.push(fullName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (lastPending === -1 || lastPending !== pending.length) {
|
|
67
|
+
lastPending = pending.length;
|
|
68
|
+
if (loaded.length || missing.length) callback(loaded, missing, pending);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
check();
|
|
72
|
+
if (lastPending > 0) {
|
|
73
|
+
toggleIconStorage(icons, () => {
|
|
74
|
+
if (!aborted) {
|
|
75
|
+
check();
|
|
76
|
+
if (!lastPending) abort();
|
|
77
|
+
}
|
|
78
|
+
}, key);
|
|
79
|
+
loadIcons(icons);
|
|
80
|
+
}
|
|
81
|
+
return abort;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export { loadIconsWithCallback };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "../loaders-DBdOeKSg.js";
|
|
2
|
+
import "../parse-BHmkG8X9.js";
|
|
3
|
+
import "../storage-B47thT4x.js";
|
|
4
|
+
import { n as splitIconNames, t as loadIcons } from "../queue-Bmgy8iLP.js";
|
|
5
|
+
import { t as renderCSS } from "../status-AnfUd3wQ.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Preload icons used in fallback mode
|
|
9
|
+
*
|
|
10
|
+
* Icons are preloaded only if fallback mode is used
|
|
11
|
+
*/
|
|
12
|
+
function preloadIcons(iconNames) {
|
|
13
|
+
if (!renderCSS) loadIcons(splitIconNames(iconNames), true);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { preloadIcons };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Size {
|
|
2
|
+
width?: string;
|
|
3
|
+
height?: string;
|
|
4
|
+
viewBox?: string;
|
|
5
|
+
}
|
|
6
|
+
interface ViewBox {
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
left?: number;
|
|
10
|
+
top?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get size properties for icon
|
|
14
|
+
*/
|
|
15
|
+
declare function getSizeProps(width: string | undefined, height: string | undefined, ratio: number | ViewBox): Size;
|
|
16
|
+
export { getSizeProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { t as IconifyIconName } from "../name-DNHxp3hA.js";
|
|
2
|
+
import { IconifyIcon } from "@iconify/types";
|
|
3
|
+
type Callback = (data: IconifyIcon | null | undefined) => void;
|
|
4
|
+
interface Result {
|
|
5
|
+
change: (iconName: string | IconifyIconName | IconifyIcon) => void;
|
|
6
|
+
unsubscribe: () => void;
|
|
7
|
+
data: IconifyIcon | null | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Subscribe to icon data updates
|
|
11
|
+
*
|
|
12
|
+
* Can change icon name to watch updates for different icon
|
|
13
|
+
*
|
|
14
|
+
* Intended to be used with reactive frameworks to watch for icon data when name can change
|
|
15
|
+
*/
|
|
16
|
+
declare function subscribeToIconData(iconToRender: string | IconifyIconName | IconifyIcon, callback: Callback): Result;
|
|
17
|
+
export { subscribeToIconData };
|