@unocss/preset-icons 0.50.5 → 0.50.7

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 CHANGED
@@ -2,306 +2,9 @@
2
2
 
3
3
  Use **any** icons with **Pure CSS** for [UnoCSS](https://github.com/unocss/unocss).
4
4
 
5
- <blockquote>
6
- <p>💡 Recommend reading - <br><a href="https://antfu.me/posts/icons-in-pure-css"><strong>Icons in Pure CSS</strong></a><br></p>
7
- </blockquote>
5
+ ## Documentation
8
6
 
9
- Follow the following conventions to use the icons
10
-
11
- - `<prefix><collection>-<icon>`
12
- - `<prefix><collection>:<icon>`
13
-
14
- For examples:
15
-
16
- ```html
17
- <!-- A basic anchor icon from Phosphor icons -->
18
- <div class="i-ph-anchor-simple-thin" />
19
- <!-- An orange alarm from Material Design Icons -->
20
- <div class="i-mdi-alarm text-orange-400" />
21
- <!-- A large Vue logo -->
22
- <div class="i-logos-vue text-3xl" />
23
- <!-- Sun in light mode, Moon in dark mode, from Carbon -->
24
- <button class="i-carbon-sun dark:i-carbon-moon" />
25
- <!-- Twemoji of laugh, turns to tear on hovering -->
26
- <div class="i-twemoji-grinning-face-with-smiling-eyes hover:i-twemoji-face-with-tears-of-joy" />
27
- ```
28
-
29
- <img src="https://user-images.githubusercontent.com/11247099/136709053-31b4db79-eddc-4dc6-aa2d-388086332630.gif" height="100"><br><sup>This is powered by pure CSS</sup>
30
-
31
- ## Install
32
-
33
- ```bash
34
- npm i -D @unocss/preset-icons @iconify-json/[the-collection-you-want]
35
- ```
36
-
37
- We use [Iconify](https://iconify.design) as our data source of icons. You need to install the corresponding iconset in `devDependencies` by following the `@iconify-json/*` pattern. For example, `@iconify-json/mdi` for [Material Design Icons](https://materialdesignicons.com/), `@iconify-json/tabler` for [Tabler](https://tabler-icons.io/). You can refer to [Icônes](https://icones.js.org/) or [Iconify](https://icon-sets.iconify.design/) for all the collections available.
38
-
39
- ```ts
40
- import presetIcons from '@unocss/preset-icons'
41
-
42
- UnoCSS({
43
- presets: [
44
- presetIcons({ /* options */ }),
45
- // ...other presets
46
- ],
47
- })
48
- ```
49
-
50
- > 💡 You can also use this preset alone as a complement to your existing UI frameworks to have pure CSS icons!
51
-
52
- If you prefer to install the all the icon sets available on Iconify at once (~130MB):
53
-
54
- ```bash
55
- npm i -D @iconify/json
56
- ```
57
-
58
- ## Configuration
59
-
60
- Refer to the [type definition](https://github.com/unocss/unocss/blob/main/packages/preset-icons/src/types.ts#L4) for all configurations available.
61
-
62
- ### Extra Properties
63
-
64
- You can provide the extra CSS properties to control the default behavior of the icons. The following is an example of make icons inlined by default:
65
-
66
- ```ts
67
- presetIcons({
68
- extraProperties: {
69
- 'display': 'inline-block',
70
- 'vertical-align': 'middle',
71
- // ...
72
- },
73
- })
74
- ```
75
-
76
- ## Modes Overriding
77
-
78
- By default, this preset will choose the rendering modes automatically for each icon based on the icons' characteristics. You can read more in this [blog post](https://antfu.me/posts/icons-in-pure-css). In some cases, you may want to explicitly set the rendering modes for each icon.
79
-
80
- - `?bg` for `background-img` - renders the icon as a background image
81
- - `?mask` for `mask` - renders the icon as a mask image
82
-
83
- For example, `vscode-icons:file-type-light-pnpm`, an icon with colors (the `svg` doesn't contain `currentColor`) that will be rendered as a background image. Use `vscode-icons:file-type-light-pnpm?mask` to render it as a mask image and bypass it's colors.
84
-
85
- ## Configuring collections and icons resolvers
86
-
87
- You can provide collections via `@iconify-json/[the-collection-you-want]`, `@iconify/json` or using your custom ones using `collections` option on your `UnoCSS` configuration.
88
-
89
- ### Browser
90
-
91
- To load `iconify` collections you should use `@iconify-json/[the-collection-you-want]` and not `@iconify/json` since the `json` file is huge.
92
-
93
- #### Bundler
94
-
95
- When using bundlers, you can provide the collections using `dynamic imports` so they will be bundler as async chunk and loaded on demand.
96
-
97
- ```ts
98
- import presetIcons from '@unocss/preset-icons/browser'
99
-
100
- presetIcons({
101
- collections: {
102
- carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default),
103
- mdi: () => import('@iconify-json/mdi/icons.json').then(i => i.default),
104
- logos: () => import('@iconify-json/logos/icons.json').then(i => i.default),
105
- }
106
- })
107
- ```
108
-
109
- #### CDN
110
-
111
- Or if you prefer to fetch them from CDN, you can specify the `cdn` option since `v0.32.10`. We recommend [esm.sh](https://esm.sh/) as the CDN provider.
112
-
113
- ```ts
114
- import presetIcons from '@unocss/preset-icons/browser'
115
-
116
- presetIcons({
117
- cdn: 'https://esm.sh/'
118
- })
119
- ```
120
-
121
- #### Customization
122
-
123
- You can also provide your own custom collections using [CustomIconLoader](https://github.com/iconify/iconify/blob/master/packages/utils/src/loader/types.ts#L17) or [InlineCollection](https://github.com/iconify/iconify/blob/master/packages/utils/src/loader/types.ts#L86), for example using `InlineCollection`:
124
-
125
- ```ts
126
- UnoCSS({
127
- presets: [
128
- presetIcons({
129
- collections: {
130
- custom: {
131
- circle: '<svg viewBox="0 0 120 120"><circle cx="60" cy="60" r="50"></circle></svg>',
132
- /* ... */
133
- },
134
- carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default as any),
135
- /* ... */
136
- }
137
- })
138
- ]
139
- })
140
- ```
141
-
142
- And then, you can use it on your html: `<span class="i-custom:circle"></span>`
143
-
144
- ### Node.js
145
-
146
- In `Node.js` the preset will search for the installed iconify dataset automatically and so you don't need to register the `iconify` collections.
147
-
148
- You can also provide your own custom collections using also [CustomIconLoader](https://github.com/iconify/iconify/blob/master/packages/utils/src/loader/types.ts#L17) or [InlineCollection](https://github.com/iconify/iconify/blob/master/packages/utils/src/loader/types.ts#L86).
149
-
150
- Additionally, you can also use [FileSystemIconLoader](https://github.com/iconify/iconify/blob/master/packages/utils/src/loader/node-loaders.ts#L9) to load your custom icons from your file system. You will need to install `@iconify/utils` package as `dev dependency`.
151
-
152
- ```ts
153
- // vite.config.ts
154
- import fs from 'node:fs/promises'
155
- // loader helpers
156
- import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
157
-
158
- UnoCSS({
159
- presets: [
160
- presetIcons({
161
- collections: {
162
- // key as the collection name
163
- 'my-icons': {
164
- account: '<svg><!-- ... --></svg>',
165
- // load your custom icon lazily
166
- settings: () => fs.readFile('./path/to/my-icon.svg', 'utf-8'),
167
- /* ... */
168
- },
169
- 'my-other-icons': async (iconName) => {
170
- // your custom loader here. Do whatever you want.
171
- // for example, fetch from a remote server:
172
- return await fetch(`https://example.com/icons/${iconName}.svg`).then(res => res.text())
173
- },
174
- // a helper to load icons from the file system
175
- // files under `./assets/icons` with `.svg` extension will be loaded as it's file name
176
- // you can also provide a transform callback to change each icon (optional)
177
- 'my-yet-other-icons': FileSystemIconLoader(
178
- './assets/icons',
179
- svg => svg.replace(/#fff/, 'currentColor')
180
- )
181
- }
182
- })
183
- ]
184
- })
185
- ```
186
-
187
- ## Icon Customizations
188
-
189
- You can customize all icons using `customizations` configuration option.
190
-
191
- Available customizations functions:
192
-
193
- - `transform`: transform raw `svg`, will be only applied when using `custom` icon collection (`iconify` collections excluded).
194
- - `customize`: change default icon customizations values.
195
- - `iconCustomizer`: change default icon customizations values.
196
-
197
- For each loaded icon, the customizations will be applied in this order:
198
-
199
- - apply `transform` to raw `svg`, if provided and using custom icon collection
200
- - apply `customize` with default customizations, if provided
201
- - apply `iconCustomizer` with `customize` customizations, if provided
202
-
203
- ### Global Custom Icon Transformation
204
-
205
- When loading your custom icons, you can transform them, for example adding `fill` attribute with `currentColor`:
206
-
207
- ```ts
208
- UnoCSS({
209
- presets: [
210
- presetIcons({
211
- customizations: {
212
- transform(svg) {
213
- return svg.replace(/#fff/, 'currentColor')
214
- }
215
- }
216
- })
217
- ]
218
- })
219
- ```
220
-
221
- From version `0.30.8` the `transform` provides the `collection` and `icon` names:
222
-
223
- ```ts
224
- UnoCSS({
225
- presets: [
226
- presetIcons({
227
- customizations: {
228
- transform(svg, collection, icon) {
229
- // do not apply fill to this icons on this collection
230
- if (collection === 'custom' && icon === 'my-icon')
231
- return svg
232
- return svg.replace(/#fff/, 'currentColor')
233
- }
234
- }
235
- })
236
- ]
237
- })
238
- ```
239
-
240
- ### Global Icon Customization
241
-
242
- When loading any icon you can customize common properties to all of them, for example configuring the same size:
243
-
244
- ```ts
245
- UnoCSS({
246
- presets: [
247
- presetIcons({
248
- customizations: {
249
- customize(props) {
250
- props.width = '2em'
251
- props.height = '2em'
252
- return props
253
- }
254
- }
255
- })
256
- ]
257
- })
258
- ```
259
-
260
- ### Icon/Collection Customization
261
-
262
- You can customize each icon using `iconCustomizer` configuration option.
263
-
264
- The `iconCustomizer` will take precedence over configuration.
265
-
266
- The `iconCustomizer` will be applied to any collection, that is, for each icon from `custom` loader, `inlined` on `custom collections` or from `@iconify`.
267
-
268
- For example, you can configure `iconCustomizer` to change all icons for a collection or individual icons on a collection:
269
-
270
- ```ts
271
- UnoCSS({
272
- presets: [
273
- presetIcons({
274
- customizations: {
275
- iconCustomizer(collection, icon, props) {
276
- // customize all icons in this collection
277
- if (collection === 'my-other-icons') {
278
- props.width = '4em'
279
- props.height = '4em'
280
- }
281
- // customize this icon in this collection
282
- if (collection === 'my-icons' && icon === 'account') {
283
- props.width = '6em'
284
- props.height = '6em'
285
- }
286
- // customize this @iconify icon in this collection
287
- if (collection === 'mdi' && icon === 'account') {
288
- props.width = '2em'
289
- props.height = '2em'
290
- }
291
- }
292
- }
293
- })
294
- ]
295
- })
296
- ```
297
-
298
- ### Advanced Custom Icon Set Cleanup
299
-
300
- When using this preset with your custom icons, consider using a cleanup process similar to that done by [Iconify](https://iconify.design/) for any icons sets. All the tools you need are available in [Iconify Tools](https://docs.iconify.design/tools/tools2/).
301
-
302
- You can check this repo, using this preset on a `Vue 3` project: [@iconify/tools/@iconify-demo/unocss](https://github.com/iconify/tools/tree/main/%40iconify-demo/unocss).
303
-
304
- Read [Cleaning up icons](https://docs.iconify.design/articles/cleaning-up-icons/) article from [Iconify](https://iconify.design/) for more details.
7
+ Please refer to the [documentation](https://unocss.dev/presets/icons).
305
8
 
306
9
  ## Credits
307
10
 
package/dist/browser.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const cdn = require('./shared/preset-icons.4314ccea.cjs');
5
+ const cdn = require('./shared/preset-icons.0125705d.cjs');
6
6
  const core = require('./core.cjs');
7
7
  require('ofetch');
8
8
  require('@unocss/core');
package/dist/browser.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createCDNLoader, l as loadIcon } from './shared/preset-icons.da12ef7d.mjs';
1
+ import { c as createCDNLoader, l as loadIcon } from './shared/preset-icons.0f6fae9a.mjs';
2
2
  import { createPresetIcons } from './core.mjs';
3
3
  export { combineLoaders, createPresetIcons } from './core.mjs';
4
4
  import 'ofetch';
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const cdn = require('./shared/preset-icons.4314ccea.cjs');
5
+ const cdn = require('./shared/preset-icons.0125705d.cjs');
6
6
  const core = require('./core.cjs');
7
7
  require('ofetch');
8
8
  require('@unocss/core');
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { c as createCDNLoader, l as loadIcon } from './shared/preset-icons.da12ef7d.mjs';
1
+ import { c as createCDNLoader, l as loadIcon } from './shared/preset-icons.0f6fae9a.mjs';
2
2
  import { createPresetIcons, combineLoaders } from './core.mjs';
3
3
  export { combineLoaders, createPresetIcons } from './core.mjs';
4
4
  import 'ofetch';
@@ -768,6 +768,8 @@ var collections = [
768
768
  "simple-icons",
769
769
  "simple-line-icons",
770
770
  "skill-icons",
771
+ "solar",
772
+ "streamline",
771
773
  "subway",
772
774
  "svg-spinners",
773
775
  "system-uicons",
@@ -766,6 +766,8 @@ var collections = [
766
766
  "simple-icons",
767
767
  "simple-line-icons",
768
768
  "skill-icons",
769
+ "solar",
770
+ "streamline",
769
771
  "subway",
770
772
  "svg-spinners",
771
773
  "system-uicons",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-icons",
3
- "version": "0.50.5",
3
+ "version": "0.50.7",
4
4
  "description": "Pure CSS Icons for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  "dependencies": {
50
50
  "@iconify/utils": "^2.1.5",
51
51
  "ofetch": "^1.0.1",
52
- "@unocss/core": "0.50.5"
52
+ "@unocss/core": "0.50.7"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@iconify/types": "^2.0.0"