@pikacss/plugin-icons 0.0.30 → 0.0.32
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/index.cjs +151 -143
- package/dist/index.d.cts +20 -19
- package/dist/index.d.mts +20 -19
- package/dist/index.mjs +124 -142
- package/package.json +7 -8
- package/dist/index.d.ts +0 -27
package/dist/index.cjs
CHANGED
|
@@ -1,155 +1,163 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
2
26
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_process = require("node:process");
|
|
29
|
+
node_process = __toESM(node_process);
|
|
30
|
+
let __iconify_utils = require("@iconify/utils");
|
|
31
|
+
let __pikacss_core = require("@pikacss/core");
|
|
32
|
+
let __unocss_preset_icons = require("@unocss/preset-icons");
|
|
33
|
+
let ofetch = require("ofetch");
|
|
7
34
|
|
|
35
|
+
//#region src/index.ts
|
|
36
|
+
/**
|
|
37
|
+
* Environment flags helper function to detect the current runtime environment.
|
|
38
|
+
* This replaces the removed `getEnvFlags` export from `@unocss/preset-icons` v66+.
|
|
39
|
+
*
|
|
40
|
+
* @returns An object containing:
|
|
41
|
+
* - `isNode`: Whether the code is running in a Node.js environment
|
|
42
|
+
* - `isVSCode`: Whether the code is running within VS Code (extension host)
|
|
43
|
+
* - `isESLint`: Whether the code is running within ESLint
|
|
44
|
+
*/
|
|
45
|
+
function getEnvFlags() {
|
|
46
|
+
const isNode = typeof node_process.default !== "undefined" && typeof node_process.default.versions?.node !== "undefined";
|
|
47
|
+
return {
|
|
48
|
+
isNode,
|
|
49
|
+
isVSCode: isNode && !!node_process.default.env.VSCODE_PID,
|
|
50
|
+
isESLint: isNode && !!node_process.default.env.ESLINT
|
|
51
|
+
};
|
|
52
|
+
}
|
|
8
53
|
function icons() {
|
|
9
|
-
|
|
54
|
+
return createIconsPlugin(createIconsLoader);
|
|
10
55
|
}
|
|
11
56
|
function createCDNLoader(cdnBase) {
|
|
12
|
-
|
|
57
|
+
return (0, __unocss_preset_icons.createCDNFetchLoader)(ofetch.$fetch, cdnBase);
|
|
13
58
|
}
|
|
14
59
|
async function createIconsLoader(config) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const nodeLoader = await presetIcons.createNodeLoader();
|
|
26
|
-
if (nodeLoader != null)
|
|
27
|
-
loaders.push(nodeLoader);
|
|
28
|
-
}
|
|
29
|
-
if (cdn)
|
|
30
|
-
loaders.push(createCDNLoader(cdn));
|
|
31
|
-
loaders.push(utils.loadIcon);
|
|
32
|
-
return presetIcons.combineLoaders(loaders);
|
|
60
|
+
const { cdn } = config;
|
|
61
|
+
const loaders = [];
|
|
62
|
+
const { isNode, isVSCode, isESLint } = getEnvFlags();
|
|
63
|
+
if (isNode && !isVSCode && !isESLint) {
|
|
64
|
+
const nodeLoader = await (0, __unocss_preset_icons.createNodeLoader)();
|
|
65
|
+
if (nodeLoader != null) loaders.push(nodeLoader);
|
|
66
|
+
}
|
|
67
|
+
if (cdn) loaders.push(createCDNLoader(cdn));
|
|
68
|
+
loaders.push(__iconify_utils.loadIcon);
|
|
69
|
+
return (0, __unocss_preset_icons.combineLoaders)(loaders);
|
|
33
70
|
}
|
|
34
71
|
const globalColonRE = /:/g;
|
|
35
72
|
function createIconsPlugin(lookupIconLoader) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
"mask": "var(--svg-icon) no-repeat",
|
|
124
|
-
"-webkit-mask-size": "100% 100%",
|
|
125
|
-
"mask-size": "100% 100%",
|
|
126
|
-
"background-color": "currentColor",
|
|
127
|
-
// for Safari https://github.com/elk-zone/elk/pull/264
|
|
128
|
-
"color": "inherit",
|
|
129
|
-
...usedProps
|
|
130
|
-
};
|
|
131
|
-
} else {
|
|
132
|
-
styleItem = {
|
|
133
|
-
"--svg-icon": `var(${varName})`,
|
|
134
|
-
"background": "var(--svg-icon) no-repeat",
|
|
135
|
-
"background-size": "100% 100%",
|
|
136
|
-
"background-color": "transparent",
|
|
137
|
-
...usedProps
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
processor?.(
|
|
141
|
-
styleItem,
|
|
142
|
-
{
|
|
143
|
-
...parsed,
|
|
144
|
-
mode: _mode
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
return styleItem;
|
|
148
|
-
},
|
|
149
|
-
autocomplete
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
73
|
+
let engine;
|
|
74
|
+
let iconsConfig;
|
|
75
|
+
return (0, __pikacss_core.defineEnginePlugin)({
|
|
76
|
+
name: "icons",
|
|
77
|
+
configureRawConfig: async (config) => {
|
|
78
|
+
iconsConfig = config.icons || {};
|
|
79
|
+
},
|
|
80
|
+
configureEngine: async (_engine) => {
|
|
81
|
+
engine = _engine;
|
|
82
|
+
const { scale = 1, mode = "auto", prefix = "i-", iconifyCollectionsNames, collections: customCollections, customizations = {}, autoInstall = false, collectionsNodeResolvePath, unit, extraProperties = {}, processor, autocomplete: _autocomplete } = iconsConfig;
|
|
83
|
+
const loaderOptions = {
|
|
84
|
+
addXmlNs: true,
|
|
85
|
+
scale,
|
|
86
|
+
customCollections,
|
|
87
|
+
autoInstall,
|
|
88
|
+
cwd: collectionsNodeResolvePath,
|
|
89
|
+
warn: void 0,
|
|
90
|
+
customizations: {
|
|
91
|
+
...customizations,
|
|
92
|
+
additionalProps: { ...extraProperties },
|
|
93
|
+
trimCustomSvg: true,
|
|
94
|
+
async iconCustomizer(collection, icon, props) {
|
|
95
|
+
await customizations.iconCustomizer?.(collection, icon, props);
|
|
96
|
+
if (unit) {
|
|
97
|
+
if (!props.width) props.width = `${scale}${unit}`;
|
|
98
|
+
if (!props.height) props.height = `${scale}${unit}`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const prefixRE = /* @__PURE__ */ new RegExp(`^(${[prefix].flat().join("|")})`);
|
|
104
|
+
const autocompletePrefix = [prefix].flat();
|
|
105
|
+
const autocomplete = [...autocompletePrefix, ...autocompletePrefix.flatMap((p) => _autocomplete?.map((a) => `${p}${a.replace(prefixRE, "")}`) || [])];
|
|
106
|
+
let iconLoader;
|
|
107
|
+
engine.shortcuts.add({
|
|
108
|
+
shortcut: /* @__PURE__ */ new RegExp(`^(?:${[prefix].flat().join("|")})([\\w:-]+)(?:\\?(mask|bg|auto))?$`),
|
|
109
|
+
value: async (match) => {
|
|
110
|
+
let [full, body, _mode = mode] = match;
|
|
111
|
+
iconLoader = iconLoader || await lookupIconLoader(iconsConfig);
|
|
112
|
+
const usedProps = {};
|
|
113
|
+
const parsed = await (0, __unocss_preset_icons.parseIconWithLoader)(body, iconLoader, {
|
|
114
|
+
...loaderOptions,
|
|
115
|
+
usedProps
|
|
116
|
+
}, iconifyCollectionsNames);
|
|
117
|
+
if (parsed == null) {
|
|
118
|
+
(0, __pikacss_core.warn)(`failed to load icon "${full}"`);
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
const url = `url("data:image/svg+xml;utf8,${(0, __iconify_utils.encodeSvgForCss)(parsed.svg)}")`;
|
|
122
|
+
const varName = `--${engine.config.prefix}svg-icon-${body.replace(globalColonRE, "-")}`;
|
|
123
|
+
if (engine.variables.store.has(varName) === false) engine.variables.add({ [varName]: {
|
|
124
|
+
value: url,
|
|
125
|
+
autocomplete: {
|
|
126
|
+
asValueOf: "-",
|
|
127
|
+
asProperty: false
|
|
128
|
+
},
|
|
129
|
+
pruneUnused: true
|
|
130
|
+
} });
|
|
131
|
+
if (_mode === "auto") _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
|
|
132
|
+
let styleItem;
|
|
133
|
+
if (_mode === "mask") styleItem = {
|
|
134
|
+
"--svg-icon": `var(${varName})`,
|
|
135
|
+
"-webkit-mask": "var(--svg-icon) no-repeat",
|
|
136
|
+
"mask": "var(--svg-icon) no-repeat",
|
|
137
|
+
"-webkit-mask-size": "100% 100%",
|
|
138
|
+
"mask-size": "100% 100%",
|
|
139
|
+
"background-color": "currentColor",
|
|
140
|
+
"color": "inherit",
|
|
141
|
+
...usedProps
|
|
142
|
+
};
|
|
143
|
+
else styleItem = {
|
|
144
|
+
"--svg-icon": `var(${varName})`,
|
|
145
|
+
"background": "var(--svg-icon) no-repeat",
|
|
146
|
+
"background-size": "100% 100%",
|
|
147
|
+
"background-color": "transparent",
|
|
148
|
+
...usedProps
|
|
149
|
+
};
|
|
150
|
+
processor?.(styleItem, {
|
|
151
|
+
...parsed,
|
|
152
|
+
mode: _mode
|
|
153
|
+
});
|
|
154
|
+
return styleItem;
|
|
155
|
+
},
|
|
156
|
+
autocomplete
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
153
160
|
}
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
//#endregion
|
|
163
|
+
exports.icons = icons;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { Simplify, StyleItem
|
|
2
|
-
import { IconsOptions } from
|
|
1
|
+
import { EnginePlugin, Simplify, StyleItem } from "@pikacss/core";
|
|
2
|
+
import { IconsOptions } from "@unocss/preset-icons";
|
|
3
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
4
5
|
interface IconMeta {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
collection: string;
|
|
7
|
+
name: string;
|
|
8
|
+
svg: string;
|
|
9
|
+
mode?: IconsConfig['mode'];
|
|
9
10
|
}
|
|
10
11
|
type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' | 'customFetcher'> & {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Processor for the CSS object before stringify
|
|
14
|
+
*/
|
|
15
|
+
processor?: (styleItem: StyleItem, meta: Required<IconMeta>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Specify the icons for auto-completion.
|
|
18
|
+
*/
|
|
19
|
+
autocomplete?: string[];
|
|
19
20
|
}>;
|
|
20
21
|
declare module '@pikacss/core' {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
interface EngineConfig {
|
|
23
|
+
icons?: IconsConfig;
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
26
|
declare function icons(): EnginePlugin;
|
|
26
|
-
|
|
27
|
-
export {
|
|
27
|
+
//#endregion
|
|
28
|
+
export { IconsConfig, icons };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { Simplify, StyleItem
|
|
2
|
-
import { IconsOptions } from
|
|
1
|
+
import { EnginePlugin, Simplify, StyleItem } from "@pikacss/core";
|
|
2
|
+
import { IconsOptions } from "@unocss/preset-icons";
|
|
3
3
|
|
|
4
|
+
//#region src/index.d.ts
|
|
4
5
|
interface IconMeta {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
collection: string;
|
|
7
|
+
name: string;
|
|
8
|
+
svg: string;
|
|
9
|
+
mode?: IconsConfig['mode'];
|
|
9
10
|
}
|
|
10
11
|
type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' | 'customFetcher'> & {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Processor for the CSS object before stringify
|
|
14
|
+
*/
|
|
15
|
+
processor?: (styleItem: StyleItem, meta: Required<IconMeta>) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Specify the icons for auto-completion.
|
|
18
|
+
*/
|
|
19
|
+
autocomplete?: string[];
|
|
19
20
|
}>;
|
|
20
21
|
declare module '@pikacss/core' {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
interface EngineConfig {
|
|
23
|
+
icons?: IconsConfig;
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
26
|
declare function icons(): EnginePlugin;
|
|
26
|
-
|
|
27
|
-
export {
|
|
27
|
+
//#endregion
|
|
28
|
+
export { IconsConfig, icons };
|
package/dist/index.mjs
CHANGED
|
@@ -1,153 +1,135 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { encodeSvgForCss, loadIcon } from "@iconify/utils";
|
|
3
|
+
import { defineEnginePlugin, warn } from "@pikacss/core";
|
|
4
|
+
import { combineLoaders, createCDNFetchLoader, createNodeLoader, parseIconWithLoader } from "@unocss/preset-icons";
|
|
5
|
+
import { $fetch } from "ofetch";
|
|
5
6
|
|
|
7
|
+
//#region src/index.ts
|
|
8
|
+
/**
|
|
9
|
+
* Environment flags helper function to detect the current runtime environment.
|
|
10
|
+
* This replaces the removed `getEnvFlags` export from `@unocss/preset-icons` v66+.
|
|
11
|
+
*
|
|
12
|
+
* @returns An object containing:
|
|
13
|
+
* - `isNode`: Whether the code is running in a Node.js environment
|
|
14
|
+
* - `isVSCode`: Whether the code is running within VS Code (extension host)
|
|
15
|
+
* - `isESLint`: Whether the code is running within ESLint
|
|
16
|
+
*/
|
|
17
|
+
function getEnvFlags() {
|
|
18
|
+
const isNode = typeof process !== "undefined" && typeof process.versions?.node !== "undefined";
|
|
19
|
+
return {
|
|
20
|
+
isNode,
|
|
21
|
+
isVSCode: isNode && !!process.env.VSCODE_PID,
|
|
22
|
+
isESLint: isNode && !!process.env.ESLINT
|
|
23
|
+
};
|
|
24
|
+
}
|
|
6
25
|
function icons() {
|
|
7
|
-
|
|
26
|
+
return createIconsPlugin(createIconsLoader);
|
|
8
27
|
}
|
|
9
28
|
function createCDNLoader(cdnBase) {
|
|
10
|
-
|
|
29
|
+
return createCDNFetchLoader($fetch, cdnBase);
|
|
11
30
|
}
|
|
12
31
|
async function createIconsLoader(config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const nodeLoader = await createNodeLoader();
|
|
24
|
-
if (nodeLoader != null)
|
|
25
|
-
loaders.push(nodeLoader);
|
|
26
|
-
}
|
|
27
|
-
if (cdn)
|
|
28
|
-
loaders.push(createCDNLoader(cdn));
|
|
29
|
-
loaders.push(loadIcon);
|
|
30
|
-
return combineLoaders(loaders);
|
|
32
|
+
const { cdn } = config;
|
|
33
|
+
const loaders = [];
|
|
34
|
+
const { isNode, isVSCode, isESLint } = getEnvFlags();
|
|
35
|
+
if (isNode && !isVSCode && !isESLint) {
|
|
36
|
+
const nodeLoader = await createNodeLoader();
|
|
37
|
+
if (nodeLoader != null) loaders.push(nodeLoader);
|
|
38
|
+
}
|
|
39
|
+
if (cdn) loaders.push(createCDNLoader(cdn));
|
|
40
|
+
loaders.push(loadIcon);
|
|
41
|
+
return combineLoaders(loaders);
|
|
31
42
|
}
|
|
32
43
|
const globalColonRE = /:/g;
|
|
33
44
|
function createIconsPlugin(lookupIconLoader) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"mask": "var(--svg-icon) no-repeat",
|
|
122
|
-
"-webkit-mask-size": "100% 100%",
|
|
123
|
-
"mask-size": "100% 100%",
|
|
124
|
-
"background-color": "currentColor",
|
|
125
|
-
// for Safari https://github.com/elk-zone/elk/pull/264
|
|
126
|
-
"color": "inherit",
|
|
127
|
-
...usedProps
|
|
128
|
-
};
|
|
129
|
-
} else {
|
|
130
|
-
styleItem = {
|
|
131
|
-
"--svg-icon": `var(${varName})`,
|
|
132
|
-
"background": "var(--svg-icon) no-repeat",
|
|
133
|
-
"background-size": "100% 100%",
|
|
134
|
-
"background-color": "transparent",
|
|
135
|
-
...usedProps
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
processor?.(
|
|
139
|
-
styleItem,
|
|
140
|
-
{
|
|
141
|
-
...parsed,
|
|
142
|
-
mode: _mode
|
|
143
|
-
}
|
|
144
|
-
);
|
|
145
|
-
return styleItem;
|
|
146
|
-
},
|
|
147
|
-
autocomplete
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
});
|
|
45
|
+
let engine;
|
|
46
|
+
let iconsConfig;
|
|
47
|
+
return defineEnginePlugin({
|
|
48
|
+
name: "icons",
|
|
49
|
+
configureRawConfig: async (config) => {
|
|
50
|
+
iconsConfig = config.icons || {};
|
|
51
|
+
},
|
|
52
|
+
configureEngine: async (_engine) => {
|
|
53
|
+
engine = _engine;
|
|
54
|
+
const { scale = 1, mode = "auto", prefix = "i-", iconifyCollectionsNames, collections: customCollections, customizations = {}, autoInstall = false, collectionsNodeResolvePath, unit, extraProperties = {}, processor, autocomplete: _autocomplete } = iconsConfig;
|
|
55
|
+
const loaderOptions = {
|
|
56
|
+
addXmlNs: true,
|
|
57
|
+
scale,
|
|
58
|
+
customCollections,
|
|
59
|
+
autoInstall,
|
|
60
|
+
cwd: collectionsNodeResolvePath,
|
|
61
|
+
warn: void 0,
|
|
62
|
+
customizations: {
|
|
63
|
+
...customizations,
|
|
64
|
+
additionalProps: { ...extraProperties },
|
|
65
|
+
trimCustomSvg: true,
|
|
66
|
+
async iconCustomizer(collection, icon, props) {
|
|
67
|
+
await customizations.iconCustomizer?.(collection, icon, props);
|
|
68
|
+
if (unit) {
|
|
69
|
+
if (!props.width) props.width = `${scale}${unit}`;
|
|
70
|
+
if (!props.height) props.height = `${scale}${unit}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const prefixRE = /* @__PURE__ */ new RegExp(`^(${[prefix].flat().join("|")})`);
|
|
76
|
+
const autocompletePrefix = [prefix].flat();
|
|
77
|
+
const autocomplete = [...autocompletePrefix, ...autocompletePrefix.flatMap((p) => _autocomplete?.map((a) => `${p}${a.replace(prefixRE, "")}`) || [])];
|
|
78
|
+
let iconLoader;
|
|
79
|
+
engine.shortcuts.add({
|
|
80
|
+
shortcut: /* @__PURE__ */ new RegExp(`^(?:${[prefix].flat().join("|")})([\\w:-]+)(?:\\?(mask|bg|auto))?$`),
|
|
81
|
+
value: async (match) => {
|
|
82
|
+
let [full, body, _mode = mode] = match;
|
|
83
|
+
iconLoader = iconLoader || await lookupIconLoader(iconsConfig);
|
|
84
|
+
const usedProps = {};
|
|
85
|
+
const parsed = await parseIconWithLoader(body, iconLoader, {
|
|
86
|
+
...loaderOptions,
|
|
87
|
+
usedProps
|
|
88
|
+
}, iconifyCollectionsNames);
|
|
89
|
+
if (parsed == null) {
|
|
90
|
+
warn(`failed to load icon "${full}"`);
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
const url = `url("data:image/svg+xml;utf8,${encodeSvgForCss(parsed.svg)}")`;
|
|
94
|
+
const varName = `--${engine.config.prefix}svg-icon-${body.replace(globalColonRE, "-")}`;
|
|
95
|
+
if (engine.variables.store.has(varName) === false) engine.variables.add({ [varName]: {
|
|
96
|
+
value: url,
|
|
97
|
+
autocomplete: {
|
|
98
|
+
asValueOf: "-",
|
|
99
|
+
asProperty: false
|
|
100
|
+
},
|
|
101
|
+
pruneUnused: true
|
|
102
|
+
} });
|
|
103
|
+
if (_mode === "auto") _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
|
|
104
|
+
let styleItem;
|
|
105
|
+
if (_mode === "mask") styleItem = {
|
|
106
|
+
"--svg-icon": `var(${varName})`,
|
|
107
|
+
"-webkit-mask": "var(--svg-icon) no-repeat",
|
|
108
|
+
"mask": "var(--svg-icon) no-repeat",
|
|
109
|
+
"-webkit-mask-size": "100% 100%",
|
|
110
|
+
"mask-size": "100% 100%",
|
|
111
|
+
"background-color": "currentColor",
|
|
112
|
+
"color": "inherit",
|
|
113
|
+
...usedProps
|
|
114
|
+
};
|
|
115
|
+
else styleItem = {
|
|
116
|
+
"--svg-icon": `var(${varName})`,
|
|
117
|
+
"background": "var(--svg-icon) no-repeat",
|
|
118
|
+
"background-size": "100% 100%",
|
|
119
|
+
"background-color": "transparent",
|
|
120
|
+
...usedProps
|
|
121
|
+
};
|
|
122
|
+
processor?.(styleItem, {
|
|
123
|
+
...parsed,
|
|
124
|
+
mode: _mode
|
|
125
|
+
});
|
|
126
|
+
return styleItem;
|
|
127
|
+
},
|
|
128
|
+
autocomplete
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
151
132
|
}
|
|
152
133
|
|
|
153
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
export { icons };
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.32",
|
|
8
8
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
@@ -30,19 +30,18 @@
|
|
|
30
30
|
},
|
|
31
31
|
"main": "dist/index.cjs",
|
|
32
32
|
"module": "dist/index.mjs",
|
|
33
|
-
"types": "dist/index.d.
|
|
33
|
+
"types": "dist/index.d.mts",
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@iconify/utils": "^
|
|
39
|
-
"@unocss/preset-icons": "^
|
|
40
|
-
"ofetch": "^1.
|
|
41
|
-
"@pikacss/core": "0.0.
|
|
38
|
+
"@iconify/utils": "^3.1.0",
|
|
39
|
+
"@unocss/preset-icons": "^66.5.9",
|
|
40
|
+
"ofetch": "^1.5.1",
|
|
41
|
+
"@pikacss/core": "0.0.32"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "
|
|
45
|
-
"stub": "unbuild --stub",
|
|
44
|
+
"build": "tsdown",
|
|
46
45
|
"typecheck": "pnpm typecheck:package && pnpm typecheck:test",
|
|
47
46
|
"typecheck:package": "tsc --project ./tsconfig.package.json --noEmit",
|
|
48
47
|
"typecheck:test": "tsc --project ./tsconfig.tests.json --noEmit",
|
package/dist/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Simplify, StyleItem, EnginePlugin } from '@pikacss/core';
|
|
2
|
-
import { IconsOptions } from '@unocss/preset-icons';
|
|
3
|
-
|
|
4
|
-
interface IconMeta {
|
|
5
|
-
collection: string;
|
|
6
|
-
name: string;
|
|
7
|
-
svg: string;
|
|
8
|
-
mode?: IconsConfig['mode'];
|
|
9
|
-
}
|
|
10
|
-
type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' | 'customFetcher'> & {
|
|
11
|
-
/**
|
|
12
|
-
* Processor for the CSS object before stringify
|
|
13
|
-
*/
|
|
14
|
-
processor?: (styleItem: StyleItem, meta: Required<IconMeta>) => void;
|
|
15
|
-
/**
|
|
16
|
-
* Specify the icons for auto-completion.
|
|
17
|
-
*/
|
|
18
|
-
autocomplete?: string[];
|
|
19
|
-
}>;
|
|
20
|
-
declare module '@pikacss/core' {
|
|
21
|
-
interface EngineConfig {
|
|
22
|
-
icons?: IconsConfig;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
declare function icons(): EnginePlugin;
|
|
26
|
-
|
|
27
|
-
export { type IconsConfig, icons };
|