@unocss/preset-icons 0.65.4 → 65.4.2

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/browser.mjs CHANGED
@@ -1,7 +1,11 @@
1
- import { c as createCDNLoader } from './shared/preset-icons.BL7F4I2g.mjs';
2
- import { c as createPresetIcons, b as createCDNFetchLoader, l as loadIcon } from './shared/preset-icons.D5PlqJL2.mjs';
3
- export { a as combineLoaders, g as getEnvFlags, i as icons, p as parseIconWithLoader } from './shared/preset-icons.D5PlqJL2.mjs';
1
+ import { loadIcon } from '@iconify/utils';
2
+ import { c as createCDNLoader } from './shared/preset-icons.DE2iazBM.mjs';
3
+ import { createPresetIcons, createCDNFetchLoader } from './core.mjs';
4
+ export { combineLoaders, getEnvFlags, icons, parseIconWithLoader } from './core.mjs';
4
5
  import 'ofetch';
6
+ import '@iconify/utils/lib/loader/loader';
7
+ import '@iconify/utils/lib/loader/modern';
8
+ import '@iconify/utils/lib/svg/encode-svg-for-css';
5
9
  import '@unocss/core';
6
10
 
7
11
  const presetIcons = createPresetIcons(async (options) => {
package/dist/core.mjs CHANGED
@@ -1,2 +1,407 @@
1
- export { a as combineLoaders, b as createCDNFetchLoader, c as createPresetIcons, g as getEnvFlags, i as icons, p as parseIconWithLoader } from './shared/preset-icons.D5PlqJL2.mjs';
2
- import '@unocss/core';
1
+ import { loadIcon } from '@iconify/utils/lib/loader/loader';
2
+ import { searchForIcon } from '@iconify/utils/lib/loader/modern';
3
+ import { encodeSvgForCss } from '@iconify/utils/lib/svg/encode-svg-for-css';
4
+ import { definePreset, warnOnce } from '@unocss/core';
5
+
6
+ function getDefaultExportFromCjs (x) {
7
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
8
+ }
9
+
10
+ var collections;
11
+ var hasRequiredCollections;
12
+
13
+ function requireCollections () {
14
+ if (hasRequiredCollections) return collections;
15
+ hasRequiredCollections = 1;
16
+ collections = [
17
+ "academicons",
18
+ "akar-icons",
19
+ "ant-design",
20
+ "arcticons",
21
+ "basil",
22
+ "bi",
23
+ "bitcoin-icons",
24
+ "bpmn",
25
+ "brandico",
26
+ "bubbles",
27
+ "bx",
28
+ "bxl",
29
+ "bxs",
30
+ "bytesize",
31
+ "carbon",
32
+ "catppuccin",
33
+ "cbi",
34
+ "charm",
35
+ "ci",
36
+ "cib",
37
+ "cif",
38
+ "cil",
39
+ "circle-flags",
40
+ "circum",
41
+ "clarity",
42
+ "codex",
43
+ "codicon",
44
+ "covid",
45
+ "cryptocurrency-color",
46
+ "cryptocurrency",
47
+ "cuida",
48
+ "dashicons",
49
+ "devicon-line",
50
+ "devicon-original",
51
+ "devicon-plain",
52
+ "devicon",
53
+ "duo-icons",
54
+ "ei",
55
+ "el",
56
+ "emblemicons",
57
+ "emojione-monotone",
58
+ "emojione-v1",
59
+ "emojione",
60
+ "entypo-social",
61
+ "entypo",
62
+ "eos-icons",
63
+ "ep",
64
+ "et",
65
+ "eva",
66
+ "f7",
67
+ "fa-brands",
68
+ "fa-regular",
69
+ "fa-solid",
70
+ "fa",
71
+ "fa6-brands",
72
+ "fa6-regular",
73
+ "fa6-solid",
74
+ "fad",
75
+ "famicons",
76
+ "fe",
77
+ "feather",
78
+ "file-icons",
79
+ "flag",
80
+ "flagpack",
81
+ "flat-color-icons",
82
+ "flat-ui",
83
+ "flowbite",
84
+ "fluent-color",
85
+ "fluent-emoji-flat",
86
+ "fluent-emoji-high-contrast",
87
+ "fluent-emoji",
88
+ "fluent-mdl2",
89
+ "fluent",
90
+ "fontelico",
91
+ "fontisto",
92
+ "formkit",
93
+ "foundation",
94
+ "fxemoji",
95
+ "gala",
96
+ "game-icons",
97
+ "garden",
98
+ "geo",
99
+ "gg",
100
+ "gis",
101
+ "gravity-ui",
102
+ "gridicons",
103
+ "grommet-icons",
104
+ "guidance",
105
+ "healthicons",
106
+ "heroicons-outline",
107
+ "heroicons-solid",
108
+ "heroicons",
109
+ "hugeicons",
110
+ "humbleicons",
111
+ "ic",
112
+ "icomoon-free",
113
+ "icon-park-outline",
114
+ "icon-park-solid",
115
+ "icon-park-twotone",
116
+ "icon-park",
117
+ "iconamoon",
118
+ "iconoir",
119
+ "icons8",
120
+ "il",
121
+ "ion",
122
+ "iwwa",
123
+ "ix",
124
+ "jam",
125
+ "la",
126
+ "lets-icons",
127
+ "line-md",
128
+ "lineicons",
129
+ "logos",
130
+ "ls",
131
+ "lsicon",
132
+ "lucide-lab",
133
+ "lucide",
134
+ "mage",
135
+ "majesticons",
136
+ "maki",
137
+ "map",
138
+ "marketeq",
139
+ "material-symbols-light",
140
+ "material-symbols",
141
+ "mdi-light",
142
+ "mdi",
143
+ "medical-icon",
144
+ "memory",
145
+ "meteocons",
146
+ "meteor-icons",
147
+ "mi",
148
+ "mingcute",
149
+ "mono-icons",
150
+ "mynaui",
151
+ "nimbus",
152
+ "nonicons",
153
+ "noto-v1",
154
+ "noto",
155
+ "nrk",
156
+ "octicon",
157
+ "oi",
158
+ "ooui",
159
+ "openmoji",
160
+ "oui",
161
+ "pajamas",
162
+ "pepicons-pencil",
163
+ "pepicons-pop",
164
+ "pepicons-print",
165
+ "pepicons",
166
+ "ph",
167
+ "pixelarticons",
168
+ "prime",
169
+ "proicons",
170
+ "ps",
171
+ "qlementine-icons",
172
+ "quill",
173
+ "radix-icons",
174
+ "raphael",
175
+ "ri",
176
+ "rivet-icons",
177
+ "si-glyph",
178
+ "si",
179
+ "simple-icons",
180
+ "simple-line-icons",
181
+ "skill-icons",
182
+ "solar",
183
+ "stash",
184
+ "streamline-emojis",
185
+ "streamline",
186
+ "subway",
187
+ "svg-spinners",
188
+ "system-uicons",
189
+ "tabler",
190
+ "tdesign",
191
+ "teenyicons",
192
+ "token-branded",
193
+ "token",
194
+ "topcoat",
195
+ "twemoji",
196
+ "typcn",
197
+ "uil",
198
+ "uim",
199
+ "uis",
200
+ "uit",
201
+ "uiw",
202
+ "unjs",
203
+ "vaadin",
204
+ "vs",
205
+ "vscode-icons",
206
+ "websymbol",
207
+ "weui",
208
+ "whh",
209
+ "wi",
210
+ "wpf",
211
+ "zmdi",
212
+ "zondicons"
213
+ ];
214
+ return collections;
215
+ }
216
+
217
+ var collectionsExports = /*@__PURE__*/ requireCollections();
218
+ const icons = /*@__PURE__*/getDefaultExportFromCjs(collectionsExports);
219
+
220
+ const COLLECTION_NAME_PARTS_MAX = 3;
221
+ function createPresetIcons(lookupIconLoader) {
222
+ return definePreset((options = {}) => {
223
+ const {
224
+ scale = 1,
225
+ mode = "auto",
226
+ prefix = "i-",
227
+ warn = false,
228
+ iconifyCollectionsNames,
229
+ collections: customCollections,
230
+ extraProperties = {},
231
+ customizations = {},
232
+ autoInstall = false,
233
+ collectionsNodeResolvePath,
234
+ layer = "icons",
235
+ unit,
236
+ processor
237
+ } = options;
238
+ const flags = getEnvFlags();
239
+ const loaderOptions = {
240
+ addXmlNs: true,
241
+ scale,
242
+ customCollections,
243
+ autoInstall,
244
+ cwd: collectionsNodeResolvePath,
245
+ // avoid warn from @iconify/loader: we'll warn below if not found
246
+ warn: undefined,
247
+ customizations: {
248
+ ...customizations,
249
+ additionalProps: { ...extraProperties },
250
+ trimCustomSvg: true,
251
+ async iconCustomizer(collection, icon, props) {
252
+ await customizations.iconCustomizer?.(collection, icon, props);
253
+ if (unit) {
254
+ if (!props.width)
255
+ props.width = `${scale}${unit}`;
256
+ if (!props.height)
257
+ props.height = `${scale}${unit}`;
258
+ }
259
+ }
260
+ }
261
+ };
262
+ let iconLoader;
263
+ return {
264
+ name: "@unocss/preset-icons",
265
+ enforce: "pre",
266
+ options,
267
+ layers: { icons: -30 },
268
+ api: {
269
+ encodeSvgForCss,
270
+ parseIconWithLoader
271
+ },
272
+ rules: [[
273
+ /^([\w:-]+)(?:\?(mask|bg|auto))?$/,
274
+ async (matcher) => {
275
+ let [full, body, _mode = mode] = matcher;
276
+ iconLoader = iconLoader || await lookupIconLoader(options);
277
+ const usedProps = {};
278
+ const parsed = await parseIconWithLoader(
279
+ body,
280
+ iconLoader,
281
+ { ...loaderOptions, usedProps },
282
+ iconifyCollectionsNames
283
+ );
284
+ if (!parsed) {
285
+ if (warn && !flags.isESLint)
286
+ warnOnce(`failed to load icon "${full}"`);
287
+ return;
288
+ }
289
+ let cssObject;
290
+ const url = `url("data:image/svg+xml;utf8,${encodeSvgForCss(parsed.svg)}")`;
291
+ if (_mode === "auto")
292
+ _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
293
+ if (_mode === "mask") {
294
+ cssObject = {
295
+ "--un-icon": url,
296
+ "-webkit-mask": "var(--un-icon) no-repeat",
297
+ "mask": "var(--un-icon) no-repeat",
298
+ "-webkit-mask-size": "100% 100%",
299
+ "mask-size": "100% 100%",
300
+ "background-color": "currentColor",
301
+ // for Safari https://github.com/elk-zone/elk/pull/264
302
+ "color": "inherit",
303
+ ...usedProps
304
+ };
305
+ } else {
306
+ cssObject = {
307
+ "background": `${url} no-repeat`,
308
+ "background-size": "100% 100%",
309
+ "background-color": "transparent",
310
+ ...usedProps
311
+ };
312
+ }
313
+ processor?.(cssObject, {
314
+ ...parsed,
315
+ icon: parsed.name,
316
+ mode: _mode
317
+ });
318
+ return cssObject;
319
+ },
320
+ { layer, prefix }
321
+ ]]
322
+ };
323
+ });
324
+ }
325
+ function combineLoaders(loaders) {
326
+ return async (...args) => {
327
+ for (const loader of loaders) {
328
+ if (!loader)
329
+ continue;
330
+ const result = await loader(...args);
331
+ if (result)
332
+ return result;
333
+ }
334
+ };
335
+ }
336
+ function createCDNFetchLoader(fetcher, cdnBase) {
337
+ const cache = /* @__PURE__ */ new Map();
338
+ function fetchCollection(name) {
339
+ if (!icons.includes(name))
340
+ return undefined;
341
+ if (!cache.has(name))
342
+ cache.set(name, fetcher(`${cdnBase}@iconify-json/${name}/icons.json`));
343
+ return cache.get(name);
344
+ }
345
+ return async (collection, icon, options) => {
346
+ let result = await loadIcon(collection, icon, options);
347
+ if (result)
348
+ return result;
349
+ const iconSet = await fetchCollection(collection);
350
+ if (iconSet) {
351
+ const ids = [
352
+ icon,
353
+ icon.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
354
+ icon.replace(/([a-z])(\d+)/g, "$1-$2")
355
+ ];
356
+ result = await searchForIcon(iconSet, collection, ids, options);
357
+ }
358
+ return result;
359
+ };
360
+ }
361
+ function getEnvFlags() {
362
+ const isNode = typeof process !== "undefined" && process.stdout && !process.versions.deno;
363
+ const isVSCode = isNode && !!process.env.VSCODE_CWD;
364
+ const isESLint = isNode && !!process.env.ESLINT;
365
+ return {
366
+ isNode,
367
+ isVSCode,
368
+ isESLint
369
+ };
370
+ }
371
+ async function parseIconWithLoader(body, loader, options = {}, safeCollectionsNames = []) {
372
+ let collection = "";
373
+ let name = "";
374
+ let svg;
375
+ const allCollections = /* @__PURE__ */ new Set([
376
+ ...icons,
377
+ ...safeCollectionsNames,
378
+ ...Object.keys(options.customCollections || {})
379
+ ]);
380
+ if (body.includes(":")) {
381
+ [collection, name] = body.split(":");
382
+ if (!allCollections.has(collection))
383
+ return;
384
+ svg = await loader(collection, name, options);
385
+ } else {
386
+ const parts = body.split(/-/g);
387
+ for (let i = COLLECTION_NAME_PARTS_MAX; i >= 1; i--) {
388
+ collection = parts.slice(0, i).join("-");
389
+ if (!allCollections.has(collection))
390
+ continue;
391
+ name = parts.slice(i).join("-");
392
+ svg = await loader(collection, name, options);
393
+ if (svg)
394
+ break;
395
+ }
396
+ }
397
+ if (!svg) {
398
+ return;
399
+ }
400
+ return {
401
+ collection,
402
+ name,
403
+ svg
404
+ };
405
+ }
406
+
407
+ export { combineLoaders, createCDNFetchLoader, createPresetIcons, getEnvFlags, icons, parseIconWithLoader };
package/dist/index.mjs CHANGED
@@ -1,8 +1,12 @@
1
+ import { loadIcon } from '@iconify/utils';
1
2
  import { definePreset } from '@unocss/core';
2
- import { c as createCDNLoader } from './shared/preset-icons.BL7F4I2g.mjs';
3
- import { c as createPresetIcons, g as getEnvFlags, a as combineLoaders, l as loadIcon } from './shared/preset-icons.D5PlqJL2.mjs';
4
- export { b as createCDNFetchLoader, i as icons, p as parseIconWithLoader } from './shared/preset-icons.D5PlqJL2.mjs';
3
+ import { c as createCDNLoader } from './shared/preset-icons.DE2iazBM.mjs';
4
+ import { createPresetIcons, getEnvFlags, combineLoaders } from './core.mjs';
5
+ export { createCDNFetchLoader, icons, parseIconWithLoader } from './core.mjs';
5
6
  import 'ofetch';
7
+ import '@iconify/utils/lib/loader/loader';
8
+ import '@iconify/utils/lib/loader/modern';
9
+ import '@iconify/utils/lib/svg/encode-svg-for-css';
6
10
 
7
11
  const _factory = /* @__PURE__ */ createPresetIcons(async (options) => {
8
12
  const {
@@ -16,7 +20,7 @@ const _factory = /* @__PURE__ */ createPresetIcons(async (options) => {
16
20
  } = getEnvFlags();
17
21
  if (isNode && !isVSCode && !isESLint) {
18
22
  const nodeLoader = await createNodeLoader();
19
- if (nodeLoader !== void 0)
23
+ if (nodeLoader !== undefined)
20
24
  loaders.push(nodeLoader);
21
25
  }
22
26
  if (cdn)
@@ -1,5 +1,5 @@
1
1
  import { $fetch } from 'ofetch';
2
- import { b as createCDNFetchLoader } from './preset-icons.D5PlqJL2.mjs';
2
+ import { createCDNFetchLoader } from '../core.mjs';
3
3
 
4
4
  function createCDNLoader(cdnBase) {
5
5
  return createCDNFetchLoader($fetch, cdnBase);
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@unocss/preset-icons",
3
3
  "type": "module",
4
- "version": "0.65.4",
4
+ "version": "65.4.2",
5
5
  "description": "Pure CSS Icons for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/antfu",
9
- "homepage": "https://github.com/unocss/unocss/tree/main/packages/preset-icons#readme",
9
+ "homepage": "https://unocss.dev",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/unocss/unocss",
13
- "directory": "packages/preset-icons"
13
+ "directory": "packages-presets/preset-icons"
14
14
  },
15
15
  "bugs": {
16
16
  "url": "https://github.com/unocss/unocss/issues"
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@iconify/utils": "^2.2.1",
57
57
  "ofetch": "^1.4.1",
58
- "@unocss/core": "0.65.4"
58
+ "@unocss/core": "65.4.2"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@iconify/types": "^2.0.0"
@@ -1,943 +0,0 @@
1
- import { definePreset, warnOnce } from '@unocss/core';
2
-
3
- const defaultIconDimensions = Object.freeze(
4
- {
5
- left: 0,
6
- top: 0,
7
- width: 16,
8
- height: 16
9
- }
10
- );
11
- const defaultIconTransformations = Object.freeze({
12
- rotate: 0,
13
- vFlip: false,
14
- hFlip: false
15
- });
16
- const defaultIconProps = Object.freeze({
17
- ...defaultIconDimensions,
18
- ...defaultIconTransformations
19
- });
20
- const defaultExtendedIconProps = Object.freeze({
21
- ...defaultIconProps,
22
- body: "",
23
- hidden: false
24
- });
25
-
26
- const defaultIconSizeCustomisations = Object.freeze({
27
- width: null,
28
- height: null
29
- });
30
- const defaultIconCustomisations = Object.freeze({
31
- // Dimensions
32
- ...defaultIconSizeCustomisations,
33
- // Transformations
34
- ...defaultIconTransformations
35
- });
36
-
37
- function mergeIconTransformations(obj1, obj2) {
38
- const result = {};
39
- if (!obj1.hFlip !== !obj2.hFlip) {
40
- result.hFlip = true;
41
- }
42
- if (!obj1.vFlip !== !obj2.vFlip) {
43
- result.vFlip = true;
44
- }
45
- const rotate = ((obj1.rotate || 0) + (obj2.rotate || 0)) % 4;
46
- if (rotate) {
47
- result.rotate = rotate;
48
- }
49
- return result;
50
- }
51
-
52
- function mergeIconData(parent, child) {
53
- const result = mergeIconTransformations(parent, child);
54
- for (const key in defaultExtendedIconProps) {
55
- if (key in defaultIconTransformations) {
56
- if (key in parent && !(key in result)) {
57
- result[key] = defaultIconTransformations[key];
58
- }
59
- } else if (key in child) {
60
- result[key] = child[key];
61
- } else if (key in parent) {
62
- result[key] = parent[key];
63
- }
64
- }
65
- return result;
66
- }
67
-
68
- function getIconsTree(data, names) {
69
- const icons = data.icons;
70
- const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
71
- const resolved = /* @__PURE__ */ Object.create(null);
72
- function resolve(name) {
73
- if (icons[name]) {
74
- return resolved[name] = [];
75
- }
76
- if (!(name in resolved)) {
77
- resolved[name] = null;
78
- const parent = aliases[name] && aliases[name].parent;
79
- const value = parent && resolve(parent);
80
- if (value) {
81
- resolved[name] = [parent].concat(value);
82
- }
83
- }
84
- return resolved[name];
85
- }
86
- (names).forEach(resolve);
87
- return resolved;
88
- }
89
-
90
- function internalGetIconData(data, name, tree) {
91
- const icons = data.icons;
92
- const aliases = data.aliases || /* @__PURE__ */ Object.create(null);
93
- let currentProps = {};
94
- function parse(name2) {
95
- currentProps = mergeIconData(
96
- icons[name2] || aliases[name2],
97
- currentProps
98
- );
99
- }
100
- parse(name);
101
- tree.forEach(parse);
102
- return mergeIconData(data, currentProps);
103
- }
104
- function getIconData(data, name) {
105
- if (data.icons[name]) {
106
- return internalGetIconData(data, name, []);
107
- }
108
- const tree = getIconsTree(data, [name])[name];
109
- return tree ? internalGetIconData(data, name, tree) : null;
110
- }
111
-
112
- const unitsSplit = /(-?[0-9.]*[0-9]+[0-9.]*)/g;
113
- const unitsTest = /^-?[0-9.]*[0-9]+[0-9.]*$/g;
114
- function calculateSize(size, ratio, precision) {
115
- if (ratio === 1) {
116
- return size;
117
- }
118
- precision = precision || 100;
119
- if (typeof size === "number") {
120
- return Math.ceil(size * ratio * precision) / precision;
121
- }
122
- if (typeof size !== "string") {
123
- return size;
124
- }
125
- const oldParts = size.split(unitsSplit);
126
- if (oldParts === null || !oldParts.length) {
127
- return size;
128
- }
129
- const newParts = [];
130
- let code = oldParts.shift();
131
- let isNumber = unitsTest.test(code);
132
- while (true) {
133
- if (isNumber) {
134
- const num = parseFloat(code);
135
- if (isNaN(num)) {
136
- newParts.push(code);
137
- } else {
138
- newParts.push(Math.ceil(num * ratio * precision) / precision);
139
- }
140
- } else {
141
- newParts.push(code);
142
- }
143
- code = oldParts.shift();
144
- if (code === void 0) {
145
- return newParts.join("");
146
- }
147
- isNumber = !isNumber;
148
- }
149
- }
150
-
151
- function splitSVGDefs(content, tag = "defs") {
152
- let defs = "";
153
- const index = content.indexOf("<" + tag);
154
- while (index >= 0) {
155
- const start = content.indexOf(">", index);
156
- const end = content.indexOf("</" + tag);
157
- if (start === -1 || end === -1) {
158
- break;
159
- }
160
- const endEnd = content.indexOf(">", end);
161
- if (endEnd === -1) {
162
- break;
163
- }
164
- defs += content.slice(start + 1, end).trim();
165
- content = content.slice(0, index).trim() + content.slice(endEnd + 1);
166
- }
167
- return {
168
- defs,
169
- content
170
- };
171
- }
172
- function mergeDefsAndContent(defs, content) {
173
- return defs ? "<defs>" + defs + "</defs>" + content : content;
174
- }
175
- function wrapSVGContent(body, start, end) {
176
- const split = splitSVGDefs(body);
177
- return mergeDefsAndContent(split.defs, start + split.content + end);
178
- }
179
-
180
- const isUnsetKeyword = (value) => value === "unset" || value === "undefined" || value === "none";
181
- function iconToSVG(icon, customisations) {
182
- const fullIcon = {
183
- ...defaultIconProps,
184
- ...icon
185
- };
186
- const fullCustomisations = {
187
- ...defaultIconCustomisations,
188
- ...customisations
189
- };
190
- const box = {
191
- left: fullIcon.left,
192
- top: fullIcon.top,
193
- width: fullIcon.width,
194
- height: fullIcon.height
195
- };
196
- let body = fullIcon.body;
197
- [fullIcon, fullCustomisations].forEach((props) => {
198
- const transformations = [];
199
- const hFlip = props.hFlip;
200
- const vFlip = props.vFlip;
201
- let rotation = props.rotate;
202
- if (hFlip) {
203
- if (vFlip) {
204
- rotation += 2;
205
- } else {
206
- transformations.push(
207
- "translate(" + (box.width + box.left).toString() + " " + (0 - box.top).toString() + ")"
208
- );
209
- transformations.push("scale(-1 1)");
210
- box.top = box.left = 0;
211
- }
212
- } else if (vFlip) {
213
- transformations.push(
214
- "translate(" + (0 - box.left).toString() + " " + (box.height + box.top).toString() + ")"
215
- );
216
- transformations.push("scale(1 -1)");
217
- box.top = box.left = 0;
218
- }
219
- let tempValue;
220
- if (rotation < 0) {
221
- rotation -= Math.floor(rotation / 4) * 4;
222
- }
223
- rotation = rotation % 4;
224
- switch (rotation) {
225
- case 1:
226
- tempValue = box.height / 2 + box.top;
227
- transformations.unshift(
228
- "rotate(90 " + tempValue.toString() + " " + tempValue.toString() + ")"
229
- );
230
- break;
231
- case 2:
232
- transformations.unshift(
233
- "rotate(180 " + (box.width / 2 + box.left).toString() + " " + (box.height / 2 + box.top).toString() + ")"
234
- );
235
- break;
236
- case 3:
237
- tempValue = box.width / 2 + box.left;
238
- transformations.unshift(
239
- "rotate(-90 " + tempValue.toString() + " " + tempValue.toString() + ")"
240
- );
241
- break;
242
- }
243
- if (rotation % 2 === 1) {
244
- if (box.left !== box.top) {
245
- tempValue = box.left;
246
- box.left = box.top;
247
- box.top = tempValue;
248
- }
249
- if (box.width !== box.height) {
250
- tempValue = box.width;
251
- box.width = box.height;
252
- box.height = tempValue;
253
- }
254
- }
255
- if (transformations.length) {
256
- body = wrapSVGContent(
257
- body,
258
- '<g transform="' + transformations.join(" ") + '">',
259
- "</g>"
260
- );
261
- }
262
- });
263
- const customisationsWidth = fullCustomisations.width;
264
- const customisationsHeight = fullCustomisations.height;
265
- const boxWidth = box.width;
266
- const boxHeight = box.height;
267
- let width;
268
- let height;
269
- if (customisationsWidth === null) {
270
- height = customisationsHeight === null ? "1em" : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
271
- width = calculateSize(height, boxWidth / boxHeight);
272
- } else {
273
- width = customisationsWidth === "auto" ? boxWidth : customisationsWidth;
274
- height = customisationsHeight === null ? calculateSize(width, boxHeight / boxWidth) : customisationsHeight === "auto" ? boxHeight : customisationsHeight;
275
- }
276
- const attributes = {};
277
- const setAttr = (prop, value) => {
278
- if (!isUnsetKeyword(value)) {
279
- attributes[prop] = value.toString();
280
- }
281
- };
282
- setAttr("width", width);
283
- setAttr("height", height);
284
- const viewBox = [box.left, box.top, boxWidth, boxHeight];
285
- attributes.viewBox = viewBox.join(" ");
286
- return {
287
- attributes,
288
- viewBox,
289
- body
290
- };
291
- }
292
-
293
- function encodeSVGforURL(svg) {
294
- return svg.replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ");
295
- }
296
-
297
- function encodeSvgForCss(svg) {
298
- let useSvg = svg.startsWith("<svg>") ? svg.replace("<svg>", "<svg >") : svg;
299
- if (!useSvg.includes(" xmlns:xlink=") && useSvg.includes(" xlink:")) {
300
- useSvg = useSvg.replace(
301
- "<svg ",
302
- '<svg xmlns:xlink="http://www.w3.org/1999/xlink" '
303
- );
304
- }
305
- if (!useSvg.includes(" xmlns=")) {
306
- useSvg = useSvg.replace(
307
- "<svg ",
308
- '<svg xmlns="http://www.w3.org/2000/svg" '
309
- );
310
- }
311
- return encodeSVGforURL(useSvg);
312
- }
313
-
314
- function trimSVG(str) {
315
- return str.replace(/(['"])\s*\n\s*([^>\\/\s])/g, "$1 $2").replace(/(["';{}><])\s*\n\s*/g, "$1").replace(/\s*\n\s*/g, " ").replace(/\s+"/g, '"').replace(/="\s+/g, '="').replace(/(\s)+\/>/g, "/>").trim();
316
- }
317
-
318
- const svgWidthRegex = /\swidth\s*=\s*["']([\w.]+)["']/;
319
- const svgHeightRegex = /\sheight\s*=\s*["']([\w.]+)["']/;
320
- const svgTagRegex = /<svg\s+/;
321
- function configureSvgSize(svg, props, scale) {
322
- const svgNode = svg.slice(0, svg.indexOf(">"));
323
- const check = (prop, regex) => {
324
- const result = regex.exec(svgNode);
325
- const isSet = result != null;
326
- const propValue = props[prop];
327
- if (!propValue && !isUnsetKeyword(propValue)) {
328
- if (typeof scale === "number") {
329
- if (scale > 0) {
330
- props[prop] = calculateSize(
331
- // Base on result from iconToSVG() or 1em
332
- result?.[1] ?? "1em",
333
- scale
334
- );
335
- }
336
- } else if (result) {
337
- props[prop] = result[1];
338
- }
339
- }
340
- return isSet;
341
- };
342
- return [check("width", svgWidthRegex), check("height", svgHeightRegex)];
343
- }
344
- async function mergeIconProps(svg, collection, icon, options, propsProvider, afterCustomizations) {
345
- const { scale, addXmlNs = false } = options ?? {};
346
- const { additionalProps = {}, iconCustomizer } = options?.customizations ?? {};
347
- const props = await propsProvider?.() ?? {};
348
- await iconCustomizer?.(collection, icon, props);
349
- Object.keys(additionalProps).forEach((p) => {
350
- const v = additionalProps[p];
351
- if (v !== void 0 && v !== null)
352
- props[p] = v;
353
- });
354
- afterCustomizations?.(props);
355
- const [widthOnSvg, heightOnSvg] = configureSvgSize(svg, props, scale);
356
- if (addXmlNs) {
357
- if (!svg.includes("xmlns=") && !props["xmlns"]) {
358
- props["xmlns"] = "http://www.w3.org/2000/svg";
359
- }
360
- if (!svg.includes("xmlns:xlink=") && svg.includes("xlink:") && !props["xmlns:xlink"]) {
361
- props["xmlns:xlink"] = "http://www.w3.org/1999/xlink";
362
- }
363
- }
364
- const propsToAdd = Object.keys(props).map(
365
- (p) => p === "width" && widthOnSvg || p === "height" && heightOnSvg ? null : `${p}="${props[p]}"`
366
- ).filter((p) => p != null);
367
- if (propsToAdd.length) {
368
- svg = svg.replace(svgTagRegex, `<svg ${propsToAdd.join(" ")} `);
369
- }
370
- if (options) {
371
- const { defaultStyle, defaultClass } = options;
372
- if (defaultClass && !svg.includes("class=")) {
373
- svg = svg.replace(svgTagRegex, `<svg class="${defaultClass}" `);
374
- }
375
- if (defaultStyle && !svg.includes("style=")) {
376
- svg = svg.replace(svgTagRegex, `<svg style="${defaultStyle}" `);
377
- }
378
- }
379
- const usedProps = options?.usedProps;
380
- if (usedProps) {
381
- Object.keys(additionalProps).forEach((p) => {
382
- const v = props[p];
383
- if (v !== void 0 && v !== null)
384
- usedProps[p] = v;
385
- });
386
- if (typeof props.width !== "undefined" && props.width !== null) {
387
- usedProps.width = props.width;
388
- }
389
- if (typeof props.height !== "undefined" && props.height !== null) {
390
- usedProps.height = props.height;
391
- }
392
- }
393
- return svg;
394
- }
395
-
396
- async function getCustomIcon(custom, collection, icon, options) {
397
- let result;
398
- try {
399
- if (typeof custom === "function") {
400
- result = await custom(icon);
401
- } else {
402
- const inline = custom[icon];
403
- result = typeof inline === "function" ? await inline() : inline;
404
- }
405
- } catch (err) {
406
- console.warn(
407
- `Failed to load custom icon "${icon}" in "${collection}":`,
408
- err
409
- );
410
- return;
411
- }
412
- if (result) {
413
- const cleanupIdx = result.indexOf("<svg");
414
- if (cleanupIdx > 0)
415
- result = result.slice(cleanupIdx);
416
- const { transform } = options?.customizations ?? {};
417
- result = typeof transform === "function" ? await transform(result, collection, icon) : result;
418
- if (!result.startsWith("<svg")) {
419
- console.warn(
420
- `Custom icon "${icon}" in "${collection}" is not a valid SVG`
421
- );
422
- return result;
423
- }
424
- return await mergeIconProps(
425
- options?.customizations?.trimCustomSvg === true ? trimSVG(result) : result,
426
- collection,
427
- icon,
428
- options,
429
- void 0
430
- );
431
- }
432
- }
433
-
434
- async function searchForIcon(iconSet, collection, ids, options) {
435
- let iconData;
436
- const { customize } = options?.customizations ?? {};
437
- for (const id of ids) {
438
- iconData = getIconData(iconSet, id);
439
- if (iconData) {
440
- let defaultCustomizations = {
441
- ...defaultIconCustomisations
442
- };
443
- if (typeof customize === "function") {
444
- iconData = Object.assign({}, iconData);
445
- defaultCustomizations = customize(
446
- defaultCustomizations,
447
- iconData,
448
- `${collection}:${id}`
449
- ) ?? defaultCustomizations;
450
- }
451
- const {
452
- attributes: { width, height, ...restAttributes },
453
- body
454
- } = iconToSVG(iconData, defaultCustomizations);
455
- const scale = options?.scale;
456
- return await mergeIconProps(
457
- // DON'T remove space on <svg >
458
- `<svg >${body}</svg>`,
459
- collection,
460
- id,
461
- options,
462
- () => {
463
- return { ...restAttributes };
464
- },
465
- (props) => {
466
- const check = (prop, defaultValue) => {
467
- const propValue = props[prop];
468
- let value;
469
- if (!isUnsetKeyword(propValue)) {
470
- if (propValue) {
471
- return;
472
- }
473
- if (typeof scale === "number") {
474
- if (scale) {
475
- value = calculateSize(
476
- // Base on result from iconToSVG() or 1em
477
- defaultValue ?? "1em",
478
- scale
479
- );
480
- }
481
- } else {
482
- value = defaultValue;
483
- }
484
- }
485
- if (!value) {
486
- delete props[prop];
487
- } else {
488
- props[prop] = value;
489
- }
490
- };
491
- check("width", width);
492
- check("height", height);
493
- }
494
- );
495
- }
496
- }
497
- }
498
-
499
- const loadIcon = async (collection, icon, options) => {
500
- const custom = options?.customCollections?.[collection];
501
- if (custom) {
502
- if (typeof custom === "function") {
503
- let result;
504
- try {
505
- result = await custom(icon);
506
- } catch (err) {
507
- console.warn(
508
- `Failed to load custom icon "${icon}" in "${collection}":`,
509
- err
510
- );
511
- return;
512
- }
513
- if (result) {
514
- if (typeof result === "string") {
515
- return await getCustomIcon(
516
- () => result,
517
- collection,
518
- icon,
519
- options
520
- );
521
- }
522
- if ("icons" in result) {
523
- const ids = [
524
- icon,
525
- icon.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
526
- icon.replace(/([a-z])(\d+)/g, "$1-$2")
527
- ];
528
- return await searchForIcon(
529
- result,
530
- collection,
531
- ids,
532
- options
533
- );
534
- }
535
- }
536
- } else {
537
- return await getCustomIcon(custom, collection, icon, options);
538
- }
539
- }
540
- };
541
-
542
- function getDefaultExportFromCjs (x) {
543
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
544
- }
545
-
546
- var collections;
547
- var hasRequiredCollections;
548
-
549
- function requireCollections () {
550
- if (hasRequiredCollections) return collections;
551
- hasRequiredCollections = 1;
552
- collections = [
553
- "academicons",
554
- "akar-icons",
555
- "ant-design",
556
- "arcticons",
557
- "basil",
558
- "bi",
559
- "bitcoin-icons",
560
- "bpmn",
561
- "brandico",
562
- "bubbles",
563
- "bx",
564
- "bxl",
565
- "bxs",
566
- "bytesize",
567
- "carbon",
568
- "catppuccin",
569
- "cbi",
570
- "charm",
571
- "ci",
572
- "cib",
573
- "cif",
574
- "cil",
575
- "circle-flags",
576
- "circum",
577
- "clarity",
578
- "codex",
579
- "codicon",
580
- "covid",
581
- "cryptocurrency-color",
582
- "cryptocurrency",
583
- "cuida",
584
- "dashicons",
585
- "devicon-line",
586
- "devicon-original",
587
- "devicon-plain",
588
- "devicon",
589
- "duo-icons",
590
- "ei",
591
- "el",
592
- "emblemicons",
593
- "emojione-monotone",
594
- "emojione-v1",
595
- "emojione",
596
- "entypo-social",
597
- "entypo",
598
- "eos-icons",
599
- "ep",
600
- "et",
601
- "eva",
602
- "f7",
603
- "fa-brands",
604
- "fa-regular",
605
- "fa-solid",
606
- "fa",
607
- "fa6-brands",
608
- "fa6-regular",
609
- "fa6-solid",
610
- "fad",
611
- "famicons",
612
- "fe",
613
- "feather",
614
- "file-icons",
615
- "flag",
616
- "flagpack",
617
- "flat-color-icons",
618
- "flat-ui",
619
- "flowbite",
620
- "fluent-color",
621
- "fluent-emoji-flat",
622
- "fluent-emoji-high-contrast",
623
- "fluent-emoji",
624
- "fluent-mdl2",
625
- "fluent",
626
- "fontelico",
627
- "fontisto",
628
- "formkit",
629
- "foundation",
630
- "fxemoji",
631
- "gala",
632
- "game-icons",
633
- "garden",
634
- "geo",
635
- "gg",
636
- "gis",
637
- "gravity-ui",
638
- "gridicons",
639
- "grommet-icons",
640
- "guidance",
641
- "healthicons",
642
- "heroicons-outline",
643
- "heroicons-solid",
644
- "heroicons",
645
- "hugeicons",
646
- "humbleicons",
647
- "ic",
648
- "icomoon-free",
649
- "icon-park-outline",
650
- "icon-park-solid",
651
- "icon-park-twotone",
652
- "icon-park",
653
- "iconamoon",
654
- "iconoir",
655
- "icons8",
656
- "il",
657
- "ion",
658
- "iwwa",
659
- "ix",
660
- "jam",
661
- "la",
662
- "lets-icons",
663
- "line-md",
664
- "lineicons",
665
- "logos",
666
- "ls",
667
- "lsicon",
668
- "lucide-lab",
669
- "lucide",
670
- "mage",
671
- "majesticons",
672
- "maki",
673
- "map",
674
- "marketeq",
675
- "material-symbols-light",
676
- "material-symbols",
677
- "mdi-light",
678
- "mdi",
679
- "medical-icon",
680
- "memory",
681
- "meteocons",
682
- "meteor-icons",
683
- "mi",
684
- "mingcute",
685
- "mono-icons",
686
- "mynaui",
687
- "nimbus",
688
- "nonicons",
689
- "noto-v1",
690
- "noto",
691
- "nrk",
692
- "octicon",
693
- "oi",
694
- "ooui",
695
- "openmoji",
696
- "oui",
697
- "pajamas",
698
- "pepicons-pencil",
699
- "pepicons-pop",
700
- "pepicons-print",
701
- "pepicons",
702
- "ph",
703
- "pixelarticons",
704
- "prime",
705
- "proicons",
706
- "ps",
707
- "qlementine-icons",
708
- "quill",
709
- "radix-icons",
710
- "raphael",
711
- "ri",
712
- "rivet-icons",
713
- "si-glyph",
714
- "si",
715
- "simple-icons",
716
- "simple-line-icons",
717
- "skill-icons",
718
- "solar",
719
- "stash",
720
- "streamline-emojis",
721
- "streamline",
722
- "subway",
723
- "svg-spinners",
724
- "system-uicons",
725
- "tabler",
726
- "tdesign",
727
- "teenyicons",
728
- "token-branded",
729
- "token",
730
- "topcoat",
731
- "twemoji",
732
- "typcn",
733
- "uil",
734
- "uim",
735
- "uis",
736
- "uit",
737
- "uiw",
738
- "unjs",
739
- "vaadin",
740
- "vs",
741
- "vscode-icons",
742
- "websymbol",
743
- "weui",
744
- "whh",
745
- "wi",
746
- "wpf",
747
- "zmdi",
748
- "zondicons"
749
- ];
750
- return collections;
751
- }
752
-
753
- var collectionsExports = /*@__PURE__*/ requireCollections();
754
- const icons = /*@__PURE__*/getDefaultExportFromCjs(collectionsExports);
755
-
756
- const COLLECTION_NAME_PARTS_MAX = 3;
757
- function createPresetIcons(lookupIconLoader) {
758
- return definePreset((options = {}) => {
759
- const {
760
- scale = 1,
761
- mode = "auto",
762
- prefix = "i-",
763
- warn = false,
764
- iconifyCollectionsNames,
765
- collections: customCollections,
766
- extraProperties = {},
767
- customizations = {},
768
- autoInstall = false,
769
- collectionsNodeResolvePath,
770
- layer = "icons",
771
- unit,
772
- processor
773
- } = options;
774
- const flags = getEnvFlags();
775
- const loaderOptions = {
776
- addXmlNs: true,
777
- scale,
778
- customCollections,
779
- autoInstall,
780
- cwd: collectionsNodeResolvePath,
781
- // avoid warn from @iconify/loader: we'll warn below if not found
782
- warn: void 0,
783
- customizations: {
784
- ...customizations,
785
- additionalProps: { ...extraProperties },
786
- trimCustomSvg: true,
787
- async iconCustomizer(collection, icon, props) {
788
- await customizations.iconCustomizer?.(collection, icon, props);
789
- if (unit) {
790
- if (!props.width)
791
- props.width = `${scale}${unit}`;
792
- if (!props.height)
793
- props.height = `${scale}${unit}`;
794
- }
795
- }
796
- }
797
- };
798
- let iconLoader;
799
- return {
800
- name: "@unocss/preset-icons",
801
- enforce: "pre",
802
- options,
803
- layers: { icons: -30 },
804
- api: {
805
- encodeSvgForCss,
806
- parseIconWithLoader
807
- },
808
- rules: [[
809
- /^([\w:-]+)(?:\?(mask|bg|auto))?$/,
810
- async (matcher) => {
811
- let [full, body, _mode = mode] = matcher;
812
- iconLoader = iconLoader || await lookupIconLoader(options);
813
- const usedProps = {};
814
- const parsed = await parseIconWithLoader(
815
- body,
816
- iconLoader,
817
- { ...loaderOptions, usedProps },
818
- iconifyCollectionsNames
819
- );
820
- if (!parsed) {
821
- if (warn && !flags.isESLint)
822
- warnOnce(`failed to load icon "${full}"`);
823
- return;
824
- }
825
- let cssObject;
826
- const url = `url("data:image/svg+xml;utf8,${encodeSvgForCss(parsed.svg)}")`;
827
- if (_mode === "auto")
828
- _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
829
- if (_mode === "mask") {
830
- cssObject = {
831
- "--un-icon": url,
832
- "-webkit-mask": "var(--un-icon) no-repeat",
833
- "mask": "var(--un-icon) no-repeat",
834
- "-webkit-mask-size": "100% 100%",
835
- "mask-size": "100% 100%",
836
- "background-color": "currentColor",
837
- // for Safari https://github.com/elk-zone/elk/pull/264
838
- "color": "inherit",
839
- ...usedProps
840
- };
841
- } else {
842
- cssObject = {
843
- "background": `${url} no-repeat`,
844
- "background-size": "100% 100%",
845
- "background-color": "transparent",
846
- ...usedProps
847
- };
848
- }
849
- processor?.(cssObject, {
850
- ...parsed,
851
- icon: parsed.name,
852
- mode: _mode
853
- });
854
- return cssObject;
855
- },
856
- { layer, prefix }
857
- ]]
858
- };
859
- });
860
- }
861
- function combineLoaders(loaders) {
862
- return async (...args) => {
863
- for (const loader of loaders) {
864
- if (!loader)
865
- continue;
866
- const result = await loader(...args);
867
- if (result)
868
- return result;
869
- }
870
- };
871
- }
872
- function createCDNFetchLoader(fetcher, cdnBase) {
873
- const cache = /* @__PURE__ */ new Map();
874
- function fetchCollection(name) {
875
- if (!icons.includes(name))
876
- return void 0;
877
- if (!cache.has(name))
878
- cache.set(name, fetcher(`${cdnBase}@iconify-json/${name}/icons.json`));
879
- return cache.get(name);
880
- }
881
- return async (collection, icon, options) => {
882
- let result = await loadIcon(collection, icon, options);
883
- if (result)
884
- return result;
885
- const iconSet = await fetchCollection(collection);
886
- if (iconSet) {
887
- const ids = [
888
- icon,
889
- icon.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(),
890
- icon.replace(/([a-z])(\d+)/g, "$1-$2")
891
- ];
892
- result = await searchForIcon(iconSet, collection, ids, options);
893
- }
894
- return result;
895
- };
896
- }
897
- function getEnvFlags() {
898
- const isNode = typeof process !== "undefined" && process.stdout && !process.versions.deno;
899
- const isVSCode = isNode && !!process.env.VSCODE_CWD;
900
- const isESLint = isNode && !!process.env.ESLINT;
901
- return {
902
- isNode,
903
- isVSCode,
904
- isESLint
905
- };
906
- }
907
- async function parseIconWithLoader(body, loader, options = {}, safeCollectionsNames = []) {
908
- let collection = "";
909
- let name = "";
910
- let svg;
911
- const allCollections = /* @__PURE__ */ new Set([
912
- ...icons,
913
- ...safeCollectionsNames,
914
- ...Object.keys(options.customCollections || {})
915
- ]);
916
- if (body.includes(":")) {
917
- [collection, name] = body.split(":");
918
- if (!allCollections.has(collection))
919
- return;
920
- svg = await loader(collection, name, options);
921
- } else {
922
- const parts = body.split(/-/g);
923
- for (let i = COLLECTION_NAME_PARTS_MAX; i >= 1; i--) {
924
- collection = parts.slice(0, i).join("-");
925
- if (!allCollections.has(collection))
926
- continue;
927
- name = parts.slice(i).join("-");
928
- svg = await loader(collection, name, options);
929
- if (svg)
930
- break;
931
- }
932
- }
933
- if (!svg) {
934
- return;
935
- }
936
- return {
937
- collection,
938
- name,
939
- svg
940
- };
941
- }
942
-
943
- export { combineLoaders as a, createCDNFetchLoader as b, createPresetIcons as c, getEnvFlags as g, icons as i, loadIcon as l, parseIconWithLoader as p };