@pikacss/plugin-icons 0.0.36 → 0.0.38
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 +315 -0
- package/dist/index.cjs +11 -11
- package/package.json +9 -4
package/README.md
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
# @pikacss/plugin-icons
|
|
2
|
+
|
|
3
|
+
Use thousands of icons from popular icon sets in PikaCSS.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @pikacss/plugin-icons
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
**pika.config.ts**:
|
|
14
|
+
```typescript
|
|
15
|
+
/// <reference path="./src/pika.gen.ts" />
|
|
16
|
+
|
|
17
|
+
import { defineEngineConfig } from '@pikacss/core'
|
|
18
|
+
import { icons } from '@pikacss/plugin-icons'
|
|
19
|
+
|
|
20
|
+
export default defineEngineConfig({
|
|
21
|
+
plugins: [
|
|
22
|
+
icons()
|
|
23
|
+
],
|
|
24
|
+
icons: {
|
|
25
|
+
// Configure icons plugin here
|
|
26
|
+
prefix: 'i-',
|
|
27
|
+
scale: 1,
|
|
28
|
+
mode: 'auto',
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Your code**:
|
|
34
|
+
```typescript
|
|
35
|
+
// Method 1: Direct shortcut string
|
|
36
|
+
const iconClass = pika('i-mdi:home')
|
|
37
|
+
|
|
38
|
+
// Method 2: With additional styles (shortcut as first argument)
|
|
39
|
+
const styledIcon = pika('i-mdi:home', {
|
|
40
|
+
fontSize: '24px',
|
|
41
|
+
color: 'blue'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// Method 3: Using __shortcut property in style object
|
|
45
|
+
const iconWithStyles = pika({
|
|
46
|
+
__shortcut: 'i-mdi:home',
|
|
47
|
+
fontSize: '24px'
|
|
48
|
+
})
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- 🎨 Access to 100,000+ icons from popular icon sets
|
|
54
|
+
- 🔍 Auto-installs icon collections on demand
|
|
55
|
+
- 📦 Tree-shakeable - only icons you use are included
|
|
56
|
+
- 🎯 Simple shortcut syntax with customizable prefix
|
|
57
|
+
- 🔧 Customizable icon collections
|
|
58
|
+
- ⚡ Built on top of Iconify
|
|
59
|
+
- 🎭 Supports both mask mode (for currentColor) and background mode
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Basic Icon Usage
|
|
64
|
+
|
|
65
|
+
Icons are provided as shortcuts (default prefix is `i-`):
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
// Direct shortcut string
|
|
69
|
+
const iconClass = pika('i-mdi:home')
|
|
70
|
+
|
|
71
|
+
// Combine shortcut with styles (recommended)
|
|
72
|
+
const styledIcon = pika('i-mdi:home', {
|
|
73
|
+
fontSize: '24px',
|
|
74
|
+
color: 'blue'
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Or use __shortcut property
|
|
78
|
+
const iconWithStyles = pika({
|
|
79
|
+
__shortcut: 'i-mdi:home',
|
|
80
|
+
display: 'inline-block'
|
|
81
|
+
})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Supported Icon Collections
|
|
85
|
+
|
|
86
|
+
All Iconify icon collections are supported. Some popular ones:
|
|
87
|
+
|
|
88
|
+
- **Material Design Icons**: `mdi:*`
|
|
89
|
+
- **Heroicons**: `heroicons:*`
|
|
90
|
+
- **Bootstrap Icons**: `bi:*`
|
|
91
|
+
- **Font Awesome**: `fa:*`, `fa-solid:*`, `fa-brands:*`
|
|
92
|
+
- **Tabler Icons**: `tabler:*`
|
|
93
|
+
- **Carbon**: `carbon:*`
|
|
94
|
+
- **Phosphor**: `ph:*`
|
|
95
|
+
- **Lucide**: `lucide:*`
|
|
96
|
+
|
|
97
|
+
Browse all collections at: [Iconify Icon Sets](https://icon-sets.iconify.design/)
|
|
98
|
+
|
|
99
|
+
### Usage Examples
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// Simple icon
|
|
103
|
+
const homeIcon = pika('i-mdi:home')
|
|
104
|
+
|
|
105
|
+
// Icon with size and color
|
|
106
|
+
const largeIcon = pika('i-mdi:account', {
|
|
107
|
+
fontSize: '48px',
|
|
108
|
+
color: '#3b82f6'
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
// Icon with hover effect
|
|
112
|
+
const hoverIcon = pika('i-mdi:heart', {
|
|
113
|
+
fontSize: '24px',
|
|
114
|
+
color: 'red',
|
|
115
|
+
cursor: 'pointer',
|
|
116
|
+
'$:hover': {
|
|
117
|
+
transform: 'scale(1.2)'
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
// Combining multiple shortcuts
|
|
122
|
+
const buttonWithIcon = pika('btn', 'i-mdi:send', {
|
|
123
|
+
display: 'inline-flex',
|
|
124
|
+
alignItems: 'center',
|
|
125
|
+
gap: '0.5rem'
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Icon Syntax
|
|
130
|
+
|
|
131
|
+
Icons follow the pattern: `{prefix}{collection}:{icon-name}` (default prefix is `i-`)
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
pika('i-mdi:home') // Material Design home icon
|
|
135
|
+
pika('i-heroicons:user') // Heroicons user icon
|
|
136
|
+
pika('i-carbon:cloud-upload') // Carbon cloud upload icon
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Icon Rendering Modes
|
|
140
|
+
|
|
141
|
+
Append `?mask`, `?bg`, or `?auto` to specify the rendering mode:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
pika('i-mdi:home?mask') // Mask mode (uses currentColor)
|
|
145
|
+
pika('i-mdi:home?bg') // Background mode
|
|
146
|
+
pika('i-mdi:home?auto') // Auto-detect (default)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- **auto**: Automatically selects mask or bg based on whether icon contains `currentColor`
|
|
150
|
+
- **mask**: Icon inherits the current text color (good for monochrome icons)
|
|
151
|
+
- **bg**: Uses background-image (good for multi-colored icons)
|
|
152
|
+
|
|
153
|
+
### Customizing Icon Size and Color
|
|
154
|
+
|
|
155
|
+
Icons inherit text properties:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Using shortcut with styles
|
|
159
|
+
pika('i-mdi:home', {
|
|
160
|
+
fontSize: '32px',
|
|
161
|
+
color: '#3b82f6' // Works with mask mode
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// Using __shortcut property
|
|
165
|
+
pika({
|
|
166
|
+
__shortcut: 'i-mdi:home',
|
|
167
|
+
fontSize: '32px',
|
|
168
|
+
color: '#3b82f6'
|
|
169
|
+
})
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Configuration
|
|
173
|
+
|
|
174
|
+
Configure the icons plugin using the standard plugin pattern:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
/// <reference path="./src/pika.gen.ts" />
|
|
178
|
+
|
|
179
|
+
import { defineEngineConfig } from '@pikacss/core'
|
|
180
|
+
import { icons } from '@pikacss/plugin-icons'
|
|
181
|
+
|
|
182
|
+
export default defineEngineConfig({
|
|
183
|
+
// 1. Register plugin in plugins array
|
|
184
|
+
plugins: [
|
|
185
|
+
icons() // Note: Call the function!
|
|
186
|
+
],
|
|
187
|
+
|
|
188
|
+
// 2. Configure at root level
|
|
189
|
+
icons: {
|
|
190
|
+
prefix: 'i-', // Shortcut prefix
|
|
191
|
+
scale: 1, // Icon scale multiplier
|
|
192
|
+
mode: 'auto', // 'auto' | 'mask' | 'bg'
|
|
193
|
+
cdn: 'https://esm.sh/', // CDN for icon collections
|
|
194
|
+
autoInstall: false, // Auto-install icon packages
|
|
195
|
+
// ... other options
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
::: tip Common Mistake
|
|
201
|
+
Always call the plugin function: `plugins: [icons()]` not `plugins: [icons]`
|
|
202
|
+
:::
|
|
203
|
+
|
|
204
|
+
### Available Options
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
interface IconsConfig {
|
|
208
|
+
/**
|
|
209
|
+
* Icon shortcut prefix.
|
|
210
|
+
* @default 'i-'
|
|
211
|
+
*/
|
|
212
|
+
prefix?: string | string[]
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Scale factor for icons.
|
|
216
|
+
* @default 1
|
|
217
|
+
*/
|
|
218
|
+
scale?: number
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Icon rendering mode.
|
|
222
|
+
* - 'auto': Auto-detect based on currentColor
|
|
223
|
+
* - 'mask': Use mask with currentColor
|
|
224
|
+
* - 'bg': Use background image
|
|
225
|
+
* @default 'auto'
|
|
226
|
+
*/
|
|
227
|
+
mode?: 'auto' | 'mask' | 'bg'
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* CDN base URL for loading icon collections.
|
|
231
|
+
*/
|
|
232
|
+
cdn?: string
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Custom icon collections.
|
|
236
|
+
*/
|
|
237
|
+
collections?: Record<string, any>
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Auto-install icon collections from npm.
|
|
241
|
+
* @default false
|
|
242
|
+
*/
|
|
243
|
+
autoInstall?: boolean
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Unit for icon size (when specified).
|
|
247
|
+
*/
|
|
248
|
+
unit?: string
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Extra CSS properties to apply to all icons.
|
|
252
|
+
*/
|
|
253
|
+
extraProperties?: Record<string, string>
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Custom processor for icon styles.
|
|
257
|
+
*/
|
|
258
|
+
processor?: (styleItem: StyleItem, meta: IconMeta) => void
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Icons for auto-completion.
|
|
262
|
+
*/
|
|
263
|
+
autocomplete?: string[]
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Custom Icon Prefix
|
|
268
|
+
|
|
269
|
+
Change the shortcut prefix:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
export default defineEngineConfig({
|
|
273
|
+
plugins: [icons()],
|
|
274
|
+
icons: {
|
|
275
|
+
prefix: 'icon-' // Now use icon-mdi:home
|
|
276
|
+
}
|
|
277
|
+
})
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Custom Icon Scale
|
|
281
|
+
|
|
282
|
+
Adjust the default scale of all icons:
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
export default defineEngineConfig({
|
|
286
|
+
plugins: [icons()],
|
|
287
|
+
icons: {
|
|
288
|
+
scale: 1.2 // Make all icons 20% larger
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## How It Works
|
|
294
|
+
|
|
295
|
+
The plugin automatically:
|
|
296
|
+
|
|
297
|
+
1. Detects icon usage in your code
|
|
298
|
+
2. Downloads the required icon collections from Iconify
|
|
299
|
+
3. Generates optimized SVG background images
|
|
300
|
+
4. Applies them using CSS custom properties
|
|
301
|
+
|
|
302
|
+
## Performance
|
|
303
|
+
|
|
304
|
+
- **On-demand loading**: Only downloads icon sets you actually use
|
|
305
|
+
- **Tree-shaking**: Only icons you reference are included in the build
|
|
306
|
+
- **Cached**: Downloaded icon collections are cached locally
|
|
307
|
+
- **Optimized SVG**: Icons are optimized for minimal file size
|
|
308
|
+
|
|
309
|
+
## Documentation
|
|
310
|
+
|
|
311
|
+
For complete documentation, visit: [PikaCSS Documentation](https://pikacss.dev)
|
|
312
|
+
|
|
313
|
+
## License
|
|
314
|
+
|
|
315
|
+
MIT © DevilTea
|
package/dist/index.cjs
CHANGED
|
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
//#endregion
|
|
28
28
|
let node_process = require("node:process");
|
|
29
29
|
node_process = __toESM(node_process);
|
|
30
|
-
let
|
|
31
|
-
let
|
|
32
|
-
let
|
|
30
|
+
let _iconify_utils = require("@iconify/utils");
|
|
31
|
+
let _pikacss_core = require("@pikacss/core");
|
|
32
|
+
let _unocss_preset_icons = require("@unocss/preset-icons");
|
|
33
33
|
let ofetch = require("ofetch");
|
|
34
34
|
|
|
35
35
|
//#region src/index.ts
|
|
@@ -54,25 +54,25 @@ function icons() {
|
|
|
54
54
|
return createIconsPlugin(createIconsLoader);
|
|
55
55
|
}
|
|
56
56
|
function createCDNLoader(cdnBase) {
|
|
57
|
-
return (0,
|
|
57
|
+
return (0, _unocss_preset_icons.createCDNFetchLoader)(ofetch.$fetch, cdnBase);
|
|
58
58
|
}
|
|
59
59
|
async function createIconsLoader(config) {
|
|
60
60
|
const { cdn } = config;
|
|
61
61
|
const loaders = [];
|
|
62
62
|
const { isNode, isVSCode, isESLint } = getEnvFlags();
|
|
63
63
|
if (isNode && !isVSCode && !isESLint) {
|
|
64
|
-
const nodeLoader = await (0,
|
|
64
|
+
const nodeLoader = await (0, _unocss_preset_icons.createNodeLoader)();
|
|
65
65
|
if (nodeLoader != null) loaders.push(nodeLoader);
|
|
66
66
|
}
|
|
67
67
|
if (cdn) loaders.push(createCDNLoader(cdn));
|
|
68
|
-
loaders.push(
|
|
69
|
-
return (0,
|
|
68
|
+
loaders.push(_iconify_utils.loadIcon);
|
|
69
|
+
return (0, _unocss_preset_icons.combineLoaders)(loaders);
|
|
70
70
|
}
|
|
71
71
|
const globalColonRE = /:/g;
|
|
72
72
|
function createIconsPlugin(lookupIconLoader) {
|
|
73
73
|
let engine;
|
|
74
74
|
let iconsConfig;
|
|
75
|
-
return (0,
|
|
75
|
+
return (0, _pikacss_core.defineEnginePlugin)({
|
|
76
76
|
name: "icons",
|
|
77
77
|
configureRawConfig: async (config) => {
|
|
78
78
|
iconsConfig = config.icons || {};
|
|
@@ -110,15 +110,15 @@ function createIconsPlugin(lookupIconLoader) {
|
|
|
110
110
|
let [full, body, _mode = mode] = match;
|
|
111
111
|
iconLoader = iconLoader || await lookupIconLoader(iconsConfig);
|
|
112
112
|
const usedProps = {};
|
|
113
|
-
const parsed = await (0,
|
|
113
|
+
const parsed = await (0, _unocss_preset_icons.parseIconWithLoader)(body, iconLoader, {
|
|
114
114
|
...loaderOptions,
|
|
115
115
|
usedProps
|
|
116
116
|
}, iconifyCollectionsNames);
|
|
117
117
|
if (parsed == null) {
|
|
118
|
-
|
|
118
|
+
_pikacss_core.log.warn(`failed to load icon "${full}"`);
|
|
119
119
|
return {};
|
|
120
120
|
}
|
|
121
|
-
const url = `url("data:image/svg+xml;utf8,${(0,
|
|
121
|
+
const url = `url("data:image/svg+xml;utf8,${(0, _iconify_utils.encodeSvgForCss)(parsed.svg)}")`;
|
|
122
122
|
const varName = `--${engine.config.prefix}svg-icon-${body.replace(globalColonRE, "-")}`;
|
|
123
123
|
if (engine.variables.store.has(varName) === false) engine.variables.add({ [varName]: {
|
|
124
124
|
value: url,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/plugin-icons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.38",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"directory": "packages/plugin-icons"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/pikacss/pikacss/issues"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"pikacss",
|
|
@@ -41,11 +41,16 @@
|
|
|
41
41
|
"files": [
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@pikacss/core": "0.0.38"
|
|
46
|
+
},
|
|
44
47
|
"dependencies": {
|
|
45
48
|
"@iconify/utils": "^3.1.0",
|
|
46
49
|
"@unocss/preset-icons": "^66.5.9",
|
|
47
|
-
"ofetch": "^1.5.1"
|
|
48
|
-
|
|
50
|
+
"ofetch": "^1.5.1"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@pikacss/core": "0.0.38"
|
|
49
54
|
},
|
|
50
55
|
"scripts": {
|
|
51
56
|
"build": "tsdown && pnpm exec publint",
|