@pikacss/plugin-icons 0.0.39 → 0.0.40
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 +338 -173
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
<!-- eslint-disable -->
|
|
1
2
|
# @pikacss/plugin-icons
|
|
2
3
|
|
|
3
|
-
Use thousands of icons from popular icon sets in PikaCSS.
|
|
4
|
+
Use thousands of icons from popular icon sets in PikaCSS with full TypeScript autocomplete.
|
|
4
5
|
|
|
5
6
|
## Installation
|
|
6
7
|
|
|
@@ -18,84 +19,149 @@ import { defineEngineConfig } from '@pikacss/core'
|
|
|
18
19
|
import { icons } from '@pikacss/plugin-icons'
|
|
19
20
|
|
|
20
21
|
export default defineEngineConfig({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
22
|
+
plugins: [
|
|
23
|
+
icons() // ⚠️ Must be a function call!
|
|
24
|
+
],
|
|
25
|
+
icons: {
|
|
26
|
+
prefix: 'i-',
|
|
27
|
+
scale: 1,
|
|
28
|
+
mode: 'auto',
|
|
29
|
+
}
|
|
30
30
|
})
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
**
|
|
33
|
+
**Module Augmentation** (TypeScript autocomplete support):
|
|
34
|
+
```typescript
|
|
35
|
+
declare module '@pikacss/core' {
|
|
36
|
+
interface EngineConfig {
|
|
37
|
+
icons?: {
|
|
38
|
+
prefix?: string | string[] // Default: 'i-'
|
|
39
|
+
scale?: number // Default: 1
|
|
40
|
+
mode?: 'auto' | 'mask' | 'bg' // Default: 'auto'
|
|
41
|
+
cdn?: string // CDN base URL
|
|
42
|
+
collections?: Record<string, any> // Custom icon collections
|
|
43
|
+
autoInstall?: boolean // Default: false
|
|
44
|
+
unit?: string // Size unit for icons
|
|
45
|
+
extraProperties?: Record<string, string> // Extra CSS props
|
|
46
|
+
processor?: (styleItem: StyleItem, meta: IconMeta) => void
|
|
47
|
+
autocomplete?: string[] // Icons for autocomplete
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default defineEngineConfig({
|
|
53
|
+
plugins: [icons()],
|
|
54
|
+
icons: { // ✅ Full autocomplete for all options
|
|
55
|
+
prefix: 'icon-',
|
|
56
|
+
scale: 1.2,
|
|
57
|
+
mode: 'mask'
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Your code** (3 usage methods):
|
|
34
63
|
```typescript
|
|
35
64
|
// Method 1: Direct shortcut string
|
|
36
65
|
const iconClass = pika('i-mdi:home')
|
|
37
66
|
|
|
38
|
-
// Method 2:
|
|
67
|
+
// Method 2: Shortcut with additional styles (recommended)
|
|
39
68
|
const styledIcon = pika('i-mdi:home', {
|
|
40
|
-
|
|
41
|
-
|
|
69
|
+
fontSize: '24px',
|
|
70
|
+
color: 'blue'
|
|
42
71
|
})
|
|
43
72
|
|
|
44
73
|
// Method 3: Using __shortcut property in style object
|
|
45
74
|
const iconWithStyles = pika({
|
|
46
|
-
|
|
47
|
-
|
|
75
|
+
__shortcut: 'i-mdi:home',
|
|
76
|
+
fontSize: '24px'
|
|
48
77
|
})
|
|
49
78
|
```
|
|
50
79
|
|
|
51
80
|
## Features
|
|
52
81
|
|
|
53
|
-
- 🎨
|
|
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
|
|
59
|
-
- 🎭
|
|
82
|
+
- 🎨 **100,000+ icons** from popular icon sets via Iconify
|
|
83
|
+
- 🔍 **Auto-installs** icon collections on demand (optional)
|
|
84
|
+
- 📦 **Tree-shakeable** - only icons you use are included
|
|
85
|
+
- 🎯 **Simple shortcut syntax** with customizable prefix
|
|
86
|
+
- 🔧 **Customizable** icon collections and CDN
|
|
87
|
+
- ⚡ **Built on Iconify** - reliable and fast
|
|
88
|
+
- 🎭 **3 rendering modes**: auto, mask (currentColor), bg (background)
|
|
89
|
+
- 💡 **Full TypeScript autocomplete** via module augmentation
|
|
60
90
|
|
|
61
91
|
## Usage
|
|
62
92
|
|
|
63
|
-
###
|
|
93
|
+
### Three Usage Methods
|
|
64
94
|
|
|
65
|
-
|
|
95
|
+
PikaCSS provides three ways to use icons:
|
|
66
96
|
|
|
97
|
+
**Method 1: Direct shortcut string** (simplest)
|
|
67
98
|
```typescript
|
|
68
|
-
// Direct shortcut string
|
|
69
99
|
const iconClass = pika('i-mdi:home')
|
|
100
|
+
```
|
|
70
101
|
|
|
71
|
-
|
|
102
|
+
**Method 2: Shortcut with additional styles** (recommended)
|
|
103
|
+
```typescript
|
|
72
104
|
const styledIcon = pika('i-mdi:home', {
|
|
73
|
-
|
|
74
|
-
|
|
105
|
+
fontSize: '24px',
|
|
106
|
+
color: 'blue'
|
|
75
107
|
})
|
|
108
|
+
```
|
|
76
109
|
|
|
77
|
-
|
|
110
|
+
**Method 3: Using `__shortcut` property** (for complex objects)
|
|
111
|
+
```typescript
|
|
78
112
|
const iconWithStyles = pika({
|
|
79
|
-
|
|
80
|
-
|
|
113
|
+
__shortcut: 'i-mdi:home',
|
|
114
|
+
fontSize: '24px',
|
|
115
|
+
display: 'inline-block'
|
|
81
116
|
})
|
|
82
117
|
```
|
|
83
118
|
|
|
119
|
+
All three methods produce the same underlying shortcut registration - choose based on your coding style.
|
|
120
|
+
|
|
84
121
|
### Supported Icon Collections
|
|
85
122
|
|
|
86
|
-
All Iconify icon collections are supported.
|
|
123
|
+
All Iconify icon collections are supported (100,000+ icons). Popular collections include:
|
|
87
124
|
|
|
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:*`
|
|
125
|
+
- **Material Design Icons**: `i-mdi:*` (5,000+ icons)
|
|
126
|
+
- **Heroicons**: `i-heroicons:*` (300+ icons)
|
|
127
|
+
- **Bootstrap Icons**: `i-bi:*` (1,800+ icons)
|
|
128
|
+
- **Font Awesome**: `i-fa:*`, `i-fa-solid:*`, `i-fa-brands:*` (2,000+ icons)
|
|
129
|
+
- **Tabler Icons**: `i-tabler:*` (4,000+ icons)
|
|
130
|
+
- **Carbon**: `i-carbon:*` (2,000+ icons)
|
|
131
|
+
- **Phosphor**: `i-ph:*` (6,000+ icons)
|
|
132
|
+
- **Lucide**: `i-lucide:*` (1,000+ icons)
|
|
96
133
|
|
|
97
134
|
Browse all collections at: [Iconify Icon Sets](https://icon-sets.iconify.design/)
|
|
98
135
|
|
|
136
|
+
### Icon Syntax
|
|
137
|
+
|
|
138
|
+
Icons follow the pattern: **`{prefix}{collection}:{icon-name}`**
|
|
139
|
+
|
|
140
|
+
Default prefix is `i-`, so the full syntax is: `i-{collection}:{name}`
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
pika('i-mdi:home') // Material Design home icon
|
|
144
|
+
pika('i-heroicons:user') // Heroicons user icon
|
|
145
|
+
pika('i-carbon:cloud-upload') // Carbon cloud upload icon
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Icon Rendering Modes
|
|
149
|
+
|
|
150
|
+
Append `?mask`, `?bg`, or `?auto` to specify the rendering mode:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
pika('i-mdi:home?mask') // Mask mode (uses currentColor)
|
|
154
|
+
pika('i-mdi:home?bg') // Background mode
|
|
155
|
+
pika('i-mdi:home?auto') // Auto-detect (default)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Mode descriptions:**
|
|
159
|
+
- **`auto`** (default): Automatically selects `mask` or `bg` based on whether the icon's SVG contains `currentColor`
|
|
160
|
+
- **`mask`**: Icon uses CSS mask with `currentColor`, inheriting text color (best for monochrome icons)
|
|
161
|
+
- **`bg`**: Icon uses `background-image` (best for multi-colored icons)
|
|
162
|
+
|
|
163
|
+
**Implementation detail:** The mode detection happens at build time by checking if the icon's SVG source includes the string `"currentColor"`. If found, mode defaults to `mask`; otherwise, it defaults to `bg`.
|
|
164
|
+
|
|
99
165
|
### Usage Examples
|
|
100
166
|
|
|
101
167
|
```typescript
|
|
@@ -104,74 +170,52 @@ const homeIcon = pika('i-mdi:home')
|
|
|
104
170
|
|
|
105
171
|
// Icon with size and color
|
|
106
172
|
const largeIcon = pika('i-mdi:account', {
|
|
107
|
-
|
|
108
|
-
|
|
173
|
+
fontSize: '48px',
|
|
174
|
+
color: '#3b82f6'
|
|
109
175
|
})
|
|
110
176
|
|
|
111
177
|
// Icon with hover effect
|
|
112
178
|
const hoverIcon = pika('i-mdi:heart', {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
179
|
+
'fontSize': '24px',
|
|
180
|
+
'color': 'red',
|
|
181
|
+
'cursor': 'pointer',
|
|
182
|
+
'$:hover': {
|
|
183
|
+
transform: 'scale(1.2)'
|
|
184
|
+
}
|
|
119
185
|
})
|
|
120
186
|
|
|
121
187
|
// Combining multiple shortcuts
|
|
122
188
|
const buttonWithIcon = pika('btn', 'i-mdi:send', {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
189
|
+
display: 'inline-flex',
|
|
190
|
+
alignItems: 'center',
|
|
191
|
+
gap: '0.5rem'
|
|
126
192
|
})
|
|
127
193
|
```
|
|
128
194
|
|
|
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
195
|
### Customizing Icon Size and Color
|
|
154
196
|
|
|
155
|
-
Icons inherit text properties:
|
|
197
|
+
Icons inherit text properties by default:
|
|
156
198
|
|
|
157
199
|
```typescript
|
|
158
|
-
//
|
|
200
|
+
// Method 2: Shortcut with styles
|
|
159
201
|
pika('i-mdi:home', {
|
|
160
|
-
|
|
161
|
-
|
|
202
|
+
fontSize: '32px', // Controls icon size
|
|
203
|
+
color: '#3b82f6' // Works with mask mode
|
|
162
204
|
})
|
|
163
205
|
|
|
164
|
-
//
|
|
206
|
+
// Method 3: __shortcut property
|
|
165
207
|
pika({
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
208
|
+
__shortcut: 'i-mdi:home',
|
|
209
|
+
fontSize: '32px',
|
|
210
|
+
color: '#3b82f6'
|
|
169
211
|
})
|
|
170
212
|
```
|
|
171
213
|
|
|
214
|
+
**Note:** Color inheritance only works in `mask` mode. In `bg` mode, the icon retains its original colors.
|
|
215
|
+
|
|
172
216
|
## Configuration
|
|
173
217
|
|
|
174
|
-
|
|
218
|
+
The icons plugin is configured using the standard PikaCSS plugin pattern with full TypeScript autocomplete:
|
|
175
219
|
|
|
176
220
|
```typescript
|
|
177
221
|
/// <reference path="./src/pika.gen.ts" />
|
|
@@ -180,124 +224,245 @@ import { defineEngineConfig } from '@pikacss/core'
|
|
|
180
224
|
import { icons } from '@pikacss/plugin-icons'
|
|
181
225
|
|
|
182
226
|
export default defineEngineConfig({
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
227
|
+
// 1. Register plugin in plugins array
|
|
228
|
+
plugins: [
|
|
229
|
+
icons() // ⚠️ Must be a function call: icons() not icons
|
|
230
|
+
],
|
|
231
|
+
|
|
232
|
+
// 2. Configure at root level with full autocomplete
|
|
233
|
+
icons: {
|
|
234
|
+
prefix: 'i-', // Shortcut prefix
|
|
235
|
+
scale: 1, // Icon scale multiplier
|
|
236
|
+
mode: 'auto', // 'auto' | 'mask' | 'bg'
|
|
237
|
+
cdn: 'https://esm.sh/', // CDN for icon collections
|
|
238
|
+
autoInstall: false, // Auto-install icon packages
|
|
239
|
+
// ... other options
|
|
240
|
+
}
|
|
197
241
|
})
|
|
198
242
|
```
|
|
199
243
|
|
|
200
|
-
:::
|
|
244
|
+
::: warning Common Mistake
|
|
201
245
|
Always call the plugin function: `plugins: [icons()]` not `plugins: [icons]`
|
|
202
246
|
:::
|
|
203
247
|
|
|
204
|
-
###
|
|
248
|
+
### All Configuration Options
|
|
205
249
|
|
|
206
250
|
```typescript
|
|
207
251
|
interface IconsConfig {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Icon shortcut prefix.
|
|
254
|
+
* Can be a single string or array of prefixes.
|
|
255
|
+
* @default 'i-'
|
|
256
|
+
*/
|
|
257
|
+
prefix?: string | string[]
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Scale factor for icons.
|
|
261
|
+
* Multiplies icon dimensions.
|
|
262
|
+
* @default 1
|
|
263
|
+
*/
|
|
264
|
+
scale?: number
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Icon rendering mode.
|
|
268
|
+
* - 'auto': Auto-detect based on currentColor in SVG
|
|
269
|
+
* - 'mask': Use CSS mask with currentColor (inherits text color)
|
|
270
|
+
* - 'bg': Use background-image (preserves original colors)
|
|
271
|
+
* @default 'auto'
|
|
272
|
+
*/
|
|
273
|
+
mode?: 'auto' | 'mask' | 'bg'
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* CDN base URL for loading icon collections.
|
|
277
|
+
* Icons are fetched from this CDN when not found locally.
|
|
278
|
+
* @example 'https://esm.sh/'
|
|
279
|
+
*/
|
|
280
|
+
cdn?: string
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Custom icon collections.
|
|
284
|
+
* Define your own icons as SVG strings.
|
|
285
|
+
* @example
|
|
286
|
+
* {
|
|
287
|
+
* 'my-icons': {
|
|
288
|
+
* 'logo': '<svg>...</svg>',
|
|
289
|
+
* 'custom': '<svg>...</svg>'
|
|
290
|
+
* }
|
|
291
|
+
* }
|
|
292
|
+
*/
|
|
293
|
+
collections?: Record<string, any>
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Auto-install icon collections from npm.
|
|
297
|
+
* When enabled, missing icon packages are automatically installed.
|
|
298
|
+
* @default false
|
|
299
|
+
*/
|
|
300
|
+
autoInstall?: boolean
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Unit for icon size (when specified).
|
|
304
|
+
* Applied to width and height when using scale with unit.
|
|
305
|
+
* @example 'em', 'rem', 'px'
|
|
306
|
+
*/
|
|
307
|
+
unit?: string
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Extra CSS properties to apply to all icons.
|
|
311
|
+
* Merged into every generated icon style.
|
|
312
|
+
* @example { verticalAlign: 'middle' }
|
|
313
|
+
*/
|
|
314
|
+
extraProperties?: Record<string, string>
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Custom processor for icon styles before rendering.
|
|
318
|
+
* Allows modifying the generated CSS object.
|
|
319
|
+
*/
|
|
320
|
+
processor?: (styleItem: StyleItem, meta: IconMeta) => void
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Icons for auto-completion in your editor.
|
|
324
|
+
* List of icon shortcuts to provide autocomplete suggestions.
|
|
325
|
+
* @example ['mdi:home', 'heroicons:user']
|
|
326
|
+
*/
|
|
327
|
+
autocomplete?: string[]
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Iconify collection names for validation.
|
|
331
|
+
*/
|
|
332
|
+
iconifyCollectionsNames?: string[]
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Path for resolving icon collection node modules.
|
|
336
|
+
*/
|
|
337
|
+
collectionsNodeResolvePath?: string
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Customizations for icon SVG processing.
|
|
341
|
+
*/
|
|
342
|
+
customizations?: IconifyLoaderCustomizations
|
|
264
343
|
}
|
|
265
344
|
```
|
|
266
345
|
|
|
267
|
-
###
|
|
346
|
+
### Configuration Examples
|
|
268
347
|
|
|
269
|
-
|
|
348
|
+
#### Custom Icon Prefix
|
|
349
|
+
|
|
350
|
+
Change the shortcut prefix to avoid conflicts:
|
|
270
351
|
|
|
271
352
|
```typescript
|
|
272
353
|
export default defineEngineConfig({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
354
|
+
plugins: [icons()],
|
|
355
|
+
icons: {
|
|
356
|
+
prefix: 'icon-' // Now use: icon-mdi:home
|
|
357
|
+
}
|
|
277
358
|
})
|
|
359
|
+
|
|
360
|
+
// Usage with custom prefix
|
|
361
|
+
const iconClass = pika('icon-mdi:home')
|
|
278
362
|
```
|
|
279
363
|
|
|
280
|
-
|
|
364
|
+
#### Custom Icon Scale
|
|
281
365
|
|
|
282
366
|
Adjust the default scale of all icons:
|
|
283
367
|
|
|
284
368
|
```typescript
|
|
285
369
|
export default defineEngineConfig({
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
370
|
+
plugins: [icons()],
|
|
371
|
+
icons: {
|
|
372
|
+
scale: 1.2 // Make all icons 20% larger
|
|
373
|
+
}
|
|
290
374
|
})
|
|
291
375
|
```
|
|
292
376
|
|
|
377
|
+
#### Force Specific Rendering Mode
|
|
378
|
+
|
|
379
|
+
Override auto-detection to always use mask or bg mode:
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
export default defineEngineConfig({
|
|
383
|
+
plugins: [icons()],
|
|
384
|
+
icons: {
|
|
385
|
+
mode: 'mask' // All icons inherit text color
|
|
386
|
+
}
|
|
387
|
+
})
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### Multiple Prefixes
|
|
391
|
+
|
|
392
|
+
Support multiple shortcut prefixes:
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
export default defineEngineConfig({
|
|
396
|
+
plugins: [icons()],
|
|
397
|
+
icons: {
|
|
398
|
+
prefix: ['i-', 'icon-'] // Both work
|
|
399
|
+
}
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
// Both are valid
|
|
403
|
+
const icon1 = pika('i-mdi:home')
|
|
404
|
+
const icon2 = pika('icon-mdi:home')
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
#### Custom Icon Collections
|
|
408
|
+
|
|
409
|
+
Define your own icon collections:
|
|
410
|
+
|
|
411
|
+
```typescript
|
|
412
|
+
export default defineEngineConfig({
|
|
413
|
+
plugins: [icons()],
|
|
414
|
+
icons: {
|
|
415
|
+
collections: {
|
|
416
|
+
'my-icons': {
|
|
417
|
+
logo: '<svg viewBox="0 0 24 24"><path d="..." /></svg>',
|
|
418
|
+
custom: '<svg>...</svg>'
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
// Usage
|
|
425
|
+
const myIcon = pika('i-my-icons:logo')
|
|
426
|
+
```
|
|
427
|
+
|
|
293
428
|
## How It Works
|
|
294
429
|
|
|
295
|
-
The plugin
|
|
430
|
+
The plugin registers icon shortcuts using the PikaCSS shortcut system:
|
|
431
|
+
|
|
432
|
+
1. **Pattern Detection**: Icons matching `{prefix}{collection}:{name}` pattern (e.g., `i-mdi:home`) are detected in your `pika()` calls
|
|
433
|
+
2. **SVG Loading**: Icon SVG is loaded from Iconify (via CDN or local node_modules)
|
|
434
|
+
3. **CSS Variable Generation**: SVG is encoded and stored as a CSS custom property (e.g., `--pika-svg-icon-mdi-home`)
|
|
435
|
+
4. **Mode Selection**: Based on mode setting and SVG content:
|
|
436
|
+
- **auto**: Checks if SVG contains `currentColor` → mask mode if yes, bg mode if no
|
|
437
|
+
- **mask**: Uses CSS mask properties with `background-color: currentColor` (icon inherits text color)
|
|
438
|
+
- **bg**: Uses `background-image` (icon retains original colors)
|
|
439
|
+
5. **Style Application**: CSS properties are applied to create the final icon appearance
|
|
296
440
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
441
|
+
**Example flow:**
|
|
442
|
+
```typescript
|
|
443
|
+
pika('i-mdi:home', { fontSize: '24px', color: 'blue' })
|
|
444
|
+
```
|
|
445
|
+
1. Plugin detects `i-mdi:home` shortcut
|
|
446
|
+
2. Loads Material Design Icons "home" icon from Iconify
|
|
447
|
+
3. Encodes SVG: `url("data:image/svg+xml;utf8,...")`
|
|
448
|
+
4. Stores in CSS variable: `--pika-svg-icon-mdi-home`
|
|
449
|
+
5. Applies mask mode (if icon uses currentColor):
|
|
450
|
+
```css
|
|
451
|
+
.generated-class {
|
|
452
|
+
--svg-icon: var(--pika-svg-icon-mdi-home);
|
|
453
|
+
-webkit-mask: var(--svg-icon) no-repeat;
|
|
454
|
+
mask: var(--svg-icon) no-repeat;
|
|
455
|
+
mask-size: 100% 100%;
|
|
456
|
+
background-color: currentColor;
|
|
457
|
+
font-size: 24px;
|
|
458
|
+
color: blue;
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
This approach ensures:
|
|
463
|
+
- **Efficient CSS**: Icons are stored once as CSS variables and reused
|
|
464
|
+
- **Color Inheritance**: Mask mode allows icons to inherit text color dynamically
|
|
465
|
+
- **Performance**: Only icons you use are included in the bundle
|
|
301
466
|
|
|
302
467
|
## Performance
|
|
303
468
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/plugin-icons",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.40",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/pikacss/pikacss.git",
|
|
9
|
+
"url": "https://github.com/pikacss/pikacss.github.io.git",
|
|
10
10
|
"directory": "packages/plugin-icons"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/pikacss/pikacss/issues"
|
|
13
|
+
"url": "https://github.com/pikacss/pikacss.github.io/issues"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"pikacss",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"dist"
|
|
43
43
|
],
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@pikacss/core": "0.0.
|
|
45
|
+
"@pikacss/core": "0.0.40"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@iconify/utils": "^3.1.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"ofetch": "^1.5.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@pikacss/core": "0.0.
|
|
53
|
+
"@pikacss/core": "0.0.40"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "tsdown && pnpm exec publint",
|