@pikacss/plugin-icons 0.0.47 → 0.0.48
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/README.md +37 -0
- package/dist/index.d.mts +100 -18
- package/dist/index.mjs +35 -14
- package/package.json +12 -7
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @pikacss/plugin-icons
|
|
2
|
+
|
|
3
|
+
Iconify icons plugin for PikaCSS. Renders icons from Iconify collections as CSS mask-image or background-image.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @pikacss/plugin-icons
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineEngineConfig } from '@pikacss/core'
|
|
15
|
+
import { icons } from '@pikacss/plugin-icons'
|
|
16
|
+
|
|
17
|
+
export default defineEngineConfig({
|
|
18
|
+
plugins: [icons()],
|
|
19
|
+
icons: {
|
|
20
|
+
autoInstall: true,
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then use in templates:
|
|
26
|
+
|
|
27
|
+
```vue
|
|
28
|
+
<div :class="pika('i-mdi:home')" />
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
See the [full documentation](https://pikacss.com/guide/plugins/icons).
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -10,72 +10,154 @@ interface IconMeta {
|
|
|
10
10
|
mode?: IconsConfig['mode'];
|
|
11
11
|
}
|
|
12
12
|
type IconSource = 'custom' | 'local' | 'cdn';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration options for the PikaCSS icons plugin.
|
|
15
|
+
*
|
|
16
|
+
* @remarks Controls how icon utilities are resolved, loaded, and rendered as CSS.
|
|
17
|
+
* Icons are loaded from custom collections first, then from locally installed
|
|
18
|
+
* Iconify packages, and finally from a CDN if configured.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { defineEngineConfig } from '@pikacss/core'
|
|
23
|
+
* import { icons } from '@pikacss/plugin-icons'
|
|
24
|
+
*
|
|
25
|
+
* export default defineEngineConfig({
|
|
26
|
+
* plugins: [icons()],
|
|
27
|
+
* icons: {
|
|
28
|
+
* prefix: 'i-',
|
|
29
|
+
* mode: 'auto',
|
|
30
|
+
* scale: 1,
|
|
31
|
+
* cdn: 'https://esm.sh/@iconify-json/{collection}/icons.json',
|
|
32
|
+
* },
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
13
36
|
interface IconsConfig {
|
|
14
37
|
/**
|
|
15
|
-
*
|
|
38
|
+
* One or more prefixes used to match icon utility names. When a utility
|
|
39
|
+
* matches `<prefix><collection>:<name>`, it resolves to an icon style.
|
|
16
40
|
*
|
|
17
|
-
* @default 'i-'
|
|
41
|
+
* @default `'i-'`
|
|
18
42
|
*/
|
|
19
43
|
prefix?: string | string[];
|
|
20
44
|
/**
|
|
21
|
-
*
|
|
45
|
+
* Rendering strategy for icon SVGs. `'mask'` uses a CSS mask with
|
|
46
|
+
* `currentColor` as the fill, allowing color inheritance. `'bg'` renders
|
|
47
|
+
* the SVG as a background image with its original colors. `'auto'`
|
|
48
|
+
* chooses `'mask'` when the SVG contains `currentColor`, otherwise `'bg'`.
|
|
22
49
|
*
|
|
23
|
-
* @default 'auto'
|
|
50
|
+
* @default `'auto'`
|
|
24
51
|
*/
|
|
25
52
|
mode?: 'auto' | 'mask' | 'bg';
|
|
26
53
|
/**
|
|
27
|
-
*
|
|
54
|
+
* Multiplier applied to the icon's intrinsic width and height.
|
|
55
|
+
* Combined with `unit` to produce the final CSS dimensions.
|
|
28
56
|
*
|
|
29
|
-
* @default 1
|
|
57
|
+
* @default `1`
|
|
30
58
|
*/
|
|
31
59
|
scale?: number;
|
|
32
60
|
/**
|
|
33
|
-
*
|
|
61
|
+
* Custom icon collections keyed by collection name. Each entry maps
|
|
62
|
+
* icon names to SVG strings or async loaders, checked before local
|
|
63
|
+
* packages and the CDN.
|
|
64
|
+
*
|
|
65
|
+
* @default `undefined`
|
|
34
66
|
*/
|
|
35
67
|
collections?: CustomCollections;
|
|
36
68
|
/**
|
|
37
|
-
*
|
|
69
|
+
* Iconify customization hooks applied when loading icons. Allows
|
|
70
|
+
* transforming SVG attributes, trimming whitespace, and running
|
|
71
|
+
* per-icon logic via `iconCustomizer`.
|
|
72
|
+
*
|
|
73
|
+
* @default `{}`
|
|
38
74
|
*/
|
|
39
75
|
customizations?: IconCustomizations;
|
|
40
76
|
/**
|
|
41
|
-
*
|
|
77
|
+
* When enabled, automatically installs missing `@iconify-json/*`
|
|
78
|
+
* packages on demand during local icon resolution.
|
|
42
79
|
*
|
|
43
|
-
* @default false
|
|
80
|
+
* @default `false`
|
|
44
81
|
*/
|
|
45
82
|
autoInstall?: IconifyLoaderOptions['autoInstall'];
|
|
46
83
|
/**
|
|
47
|
-
*
|
|
84
|
+
* Working directory used by the Iconify node loader when resolving
|
|
85
|
+
* locally installed icon packages.
|
|
48
86
|
*
|
|
49
|
-
* @default
|
|
87
|
+
* @default `undefined`
|
|
50
88
|
*/
|
|
51
89
|
cwd?: IconifyLoaderOptions['cwd'];
|
|
52
90
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
91
|
+
* CDN URL template for fetching remote icon sets. Use `{collection}`
|
|
92
|
+
* as a placeholder for the collection name, or provide a base URL
|
|
93
|
+
* and the collection name will be appended as `<url>/<collection>.json`.
|
|
94
|
+
*
|
|
95
|
+
* @default `undefined`
|
|
55
96
|
*/
|
|
56
97
|
cdn?: string;
|
|
57
98
|
/**
|
|
58
|
-
* CSS unit
|
|
99
|
+
* CSS unit appended to the icon's width and height (e.g. `'em'`, `'rem'`).
|
|
100
|
+
* When set, produces explicit dimension values like `1em` based on `scale`.
|
|
101
|
+
* When omitted, dimensions are left to the SVG's intrinsic size.
|
|
102
|
+
*
|
|
103
|
+
* @default `undefined`
|
|
59
104
|
*/
|
|
60
105
|
unit?: string;
|
|
61
106
|
/**
|
|
62
|
-
* Additional CSS properties
|
|
107
|
+
* Additional CSS properties merged into every generated icon style item.
|
|
108
|
+
* Useful for adding `display`, `vertical-align`, or other layout properties.
|
|
109
|
+
*
|
|
110
|
+
* @default `{}`
|
|
63
111
|
*/
|
|
64
112
|
extraProperties?: Record<string, string>;
|
|
65
113
|
/**
|
|
66
|
-
*
|
|
114
|
+
* Post-processing callback invoked on each generated icon style item before
|
|
115
|
+
* it is returned. Receives the mutable style item and resolved icon metadata,
|
|
116
|
+
* allowing custom property injection or conditional transformations.
|
|
117
|
+
*
|
|
118
|
+
* @default `undefined`
|
|
67
119
|
*/
|
|
68
120
|
processor?: (styleItem: StyleItem, meta: Required<IconMeta>) => void;
|
|
69
121
|
/**
|
|
70
|
-
*
|
|
122
|
+
* Explicit list of icon identifiers (e.g. `'mdi:home'`) to include in
|
|
123
|
+
* editor autocomplete suggestions. Each entry is combined with every
|
|
124
|
+
* configured prefix.
|
|
125
|
+
*
|
|
126
|
+
* @default `undefined`
|
|
71
127
|
*/
|
|
72
128
|
autocomplete?: string[];
|
|
73
129
|
}
|
|
74
130
|
declare module '@pikacss/core' {
|
|
75
131
|
interface EngineConfig {
|
|
132
|
+
/**
|
|
133
|
+
* Configuration for the icons plugin. Requires the `icons()` plugin
|
|
134
|
+
* to be registered in `plugins` for this configuration to take effect.
|
|
135
|
+
*
|
|
136
|
+
* @default `undefined`
|
|
137
|
+
*/
|
|
76
138
|
icons?: IconsConfig;
|
|
77
139
|
}
|
|
78
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Creates the PikaCSS icons engine plugin.
|
|
143
|
+
*
|
|
144
|
+
* @returns An engine plugin that registers icon shortcut rules and autocomplete entries.
|
|
145
|
+
*
|
|
146
|
+
* @remarks Resolves icon SVGs from custom collections, locally installed
|
|
147
|
+
* `@iconify-json/*` packages, or a remote CDN. Each matched utility is
|
|
148
|
+
* expanded into a CSS style item using either mask or background rendering.
|
|
149
|
+
* Configure behavior through the `icons` key in your engine config.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* import { icons } from '@pikacss/plugin-icons'
|
|
154
|
+
*
|
|
155
|
+
* export default defineEngineConfig({
|
|
156
|
+
* plugins: [icons()],
|
|
157
|
+
* icons: { prefix: 'i-', mode: 'auto' },
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
79
161
|
declare function icons(): EnginePlugin;
|
|
80
162
|
//#endregion
|
|
81
163
|
export { IconsConfig, icons };
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { encodeSvgForCss, loadIcon, quicklyValidateIconSet, searchForIcon, strin
|
|
|
3
3
|
import { loadNodeIcon } from "@iconify/utils/lib/loader/node-loader";
|
|
4
4
|
import { defineEnginePlugin, log } from "@pikacss/core";
|
|
5
5
|
import { $fetch } from "ofetch";
|
|
6
|
-
|
|
7
6
|
//#region src/index.ts
|
|
8
7
|
/**
|
|
9
8
|
* Environment flags helper function to detect the current runtime environment.
|
|
@@ -16,17 +15,41 @@ function getEnvFlags() {
|
|
|
16
15
|
isESLint: isNode && !!process.env.ESLINT
|
|
17
16
|
};
|
|
18
17
|
}
|
|
18
|
+
const RE_ESCAPE_REGEXP = /[|\\{}()[\]^$+*?.-]/g;
|
|
19
|
+
const RE_CAMEL_CASE_ICON_BOUNDARY = /([a-z])([A-Z])/g;
|
|
20
|
+
const RE_DIGIT_ICON_BOUNDARY = /([a-z])(\d+)/g;
|
|
21
|
+
const RE_TRAILING_SLASH = /\/$/;
|
|
22
|
+
/**
|
|
23
|
+
* Creates the PikaCSS icons engine plugin.
|
|
24
|
+
*
|
|
25
|
+
* @returns An engine plugin that registers icon shortcut rules and autocomplete entries.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Resolves icon SVGs from custom collections, locally installed
|
|
28
|
+
* `@iconify-json/*` packages, or a remote CDN. Each matched utility is
|
|
29
|
+
* expanded into a CSS style item using either mask or background rendering.
|
|
30
|
+
* Configure behavior through the `icons` key in your engine config.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { icons } from '@pikacss/plugin-icons'
|
|
35
|
+
*
|
|
36
|
+
* export default defineEngineConfig({
|
|
37
|
+
* plugins: [icons()],
|
|
38
|
+
* icons: { prefix: 'i-', mode: 'auto' },
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
19
42
|
function icons() {
|
|
20
43
|
return createIconsPlugin();
|
|
21
44
|
}
|
|
22
45
|
const globalColonRE = /:/g;
|
|
23
46
|
const currentColorRE = /currentColor/;
|
|
24
47
|
function normalizePrefixes(prefix) {
|
|
25
|
-
const prefixes = [prefix
|
|
48
|
+
const prefixes = [prefix].flat().filter(Boolean);
|
|
26
49
|
return [...new Set(prefixes)];
|
|
27
50
|
}
|
|
28
51
|
function escapeRegExp(value) {
|
|
29
|
-
return value.replace(
|
|
52
|
+
return value.replace(RE_ESCAPE_REGEXP, "\\$&");
|
|
30
53
|
}
|
|
31
54
|
function createShortcutRegExp(prefixes) {
|
|
32
55
|
return new RegExp(`^(?:${prefixes.map(escapeRegExp).join("|")})([\\w:-]+)(?:\\?(mask|bg|auto))?$`);
|
|
@@ -34,8 +57,8 @@ function createShortcutRegExp(prefixes) {
|
|
|
34
57
|
function getPossibleIconNames(iconName) {
|
|
35
58
|
return [
|
|
36
59
|
iconName,
|
|
37
|
-
iconName.replace(
|
|
38
|
-
iconName.replace(
|
|
60
|
+
iconName.replace(RE_CAMEL_CASE_ICON_BOUNDARY, "$1-$2").toLowerCase(),
|
|
61
|
+
iconName.replace(RE_DIGIT_ICON_BOUNDARY, "$1-$2")
|
|
39
62
|
];
|
|
40
63
|
}
|
|
41
64
|
function createAutocomplete(prefixes, autocomplete = []) {
|
|
@@ -52,7 +75,7 @@ function createAutocompletePatterns(prefixes) {
|
|
|
52
75
|
}
|
|
53
76
|
function resolveCdnCollectionUrl(cdn, collection) {
|
|
54
77
|
if (cdn.includes("{collection}")) return cdn.replaceAll("{collection}", collection);
|
|
55
|
-
return `${cdn.replace(
|
|
78
|
+
return `${cdn.replace(RE_TRAILING_SLASH, "")}/${collection}.json`;
|
|
56
79
|
}
|
|
57
80
|
function createLoaderOptions(config, usedProps) {
|
|
58
81
|
const { scale = 1, collections, autoInstall = false, cwd, unit, extraProperties = {}, customizations = {} } = config;
|
|
@@ -73,10 +96,9 @@ function createLoaderOptions(config, usedProps) {
|
|
|
73
96
|
trimCustomSvg: customizations.trimCustomSvg ?? true,
|
|
74
97
|
async iconCustomizer(collection, icon, props) {
|
|
75
98
|
await iconCustomizer?.(collection, icon, props);
|
|
76
|
-
if (unit)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
99
|
+
if (!unit) return;
|
|
100
|
+
if (!props.width) props.width = `${scale}${unit}`;
|
|
101
|
+
if (!props.height) props.height = `${scale}${unit}`;
|
|
80
102
|
}
|
|
81
103
|
}
|
|
82
104
|
};
|
|
@@ -147,7 +169,7 @@ function createIconsPlugin() {
|
|
|
147
169
|
return defineEnginePlugin({
|
|
148
170
|
name: "icons",
|
|
149
171
|
configureRawConfig: async (config) => {
|
|
150
|
-
iconsConfig = config.icons
|
|
172
|
+
iconsConfig = config.icons ?? {};
|
|
151
173
|
},
|
|
152
174
|
configureEngine: async (_engine) => {
|
|
153
175
|
engine = _engine;
|
|
@@ -155,7 +177,7 @@ function createIconsPlugin() {
|
|
|
155
177
|
const prefixes = normalizePrefixes(prefix);
|
|
156
178
|
const autocomplete = createAutocomplete(prefixes, _autocomplete);
|
|
157
179
|
const autocompletePatterns = createAutocompletePatterns(prefixes);
|
|
158
|
-
engine.appendAutocomplete({ patterns: {
|
|
180
|
+
engine.appendAutocomplete({ patterns: { shortcuts: autocompletePatterns } });
|
|
159
181
|
engine.shortcuts.add({
|
|
160
182
|
shortcut: createShortcutRegExp(prefixes),
|
|
161
183
|
value: async (match) => {
|
|
@@ -212,6 +234,5 @@ function createIconsPlugin() {
|
|
|
212
234
|
}
|
|
213
235
|
});
|
|
214
236
|
}
|
|
215
|
-
|
|
216
237
|
//#endregion
|
|
217
|
-
export { icons };
|
|
238
|
+
export { icons };
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/plugin-icons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.48",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://pikacss.com",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/pikacss/pikacss.git",
|
|
10
|
+
"url": "git+https://github.com/pikacss/pikacss.git",
|
|
10
11
|
"directory": "packages/plugin-icons"
|
|
11
12
|
},
|
|
12
13
|
"bugs": {
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
"pikacss-plugin",
|
|
21
22
|
"icons"
|
|
22
23
|
],
|
|
24
|
+
"sideEffects": false,
|
|
23
25
|
"exports": {
|
|
24
26
|
".": {
|
|
25
27
|
"import": {
|
|
@@ -36,23 +38,26 @@
|
|
|
36
38
|
"files": [
|
|
37
39
|
"dist"
|
|
38
40
|
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=22"
|
|
43
|
+
},
|
|
39
44
|
"peerDependencies": {
|
|
40
|
-
"@pikacss/core": "0.0.
|
|
45
|
+
"@pikacss/core": "0.0.48"
|
|
41
46
|
},
|
|
42
47
|
"dependencies": {
|
|
43
48
|
"@iconify/utils": "^3.1.0",
|
|
44
49
|
"ofetch": "^1.5.1"
|
|
45
50
|
},
|
|
46
51
|
"devDependencies": {
|
|
47
|
-
"@pikacss/core": "0.0.
|
|
52
|
+
"@pikacss/core": "0.0.48"
|
|
48
53
|
},
|
|
49
54
|
"scripts": {
|
|
50
|
-
"build": "tsdown
|
|
55
|
+
"build": "tsdown",
|
|
51
56
|
"build:watch": "tsdown --watch",
|
|
52
57
|
"typecheck": "pnpm typecheck:package && pnpm typecheck:test",
|
|
53
58
|
"typecheck:package": "tsc --project ./tsconfig.package.json --noEmit",
|
|
54
59
|
"typecheck:test": "tsc --project ./tsconfig.tests.json --noEmit",
|
|
55
|
-
"test": "vitest run",
|
|
56
|
-
"test:watch": "vitest"
|
|
60
|
+
"test": "vitest run --config ./vitest.config.ts",
|
|
61
|
+
"test:watch": "vitest --config ./vitest.config.ts"
|
|
57
62
|
}
|
|
58
63
|
}
|