@unocss/preset-icons 0.32.0 → 0.32.8

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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -27
  3. package/package.json +3 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
3
+ Copyright (c) 2021-PRESENT Anthony Fu <https://github.com/antfu>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -90,23 +90,21 @@ You can provide collections via `@iconify-json/[the-collection-you-want]`, `@ico
90
90
 
91
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
92
  You will need to provide the `iconify` collections using `dynamic imports`, for example, on playground you have these collections:
93
+
93
94
  ```ts
94
95
  presetIcons({
95
96
  collections: {
96
97
  carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default as any),
97
98
  mdi: () => import('@iconify-json/mdi/icons.json').then(i => i.default as any),
98
99
  logos: () => import('@iconify-json/logos/icons.json').then(i => i.default as any),
99
- twemoji: () => import('@iconify-json/twemoji/icons.json').then(i => i.default as any),
100
- ri: () => import('@iconify-json/ri/icons.json').then(i => i.default as any),
101
- tabler: () => import('@iconify-json/tabler/icons.json').then(i => i.default as any),
102
- uim: () => import('@iconify-json/uim/icons.json').then(i => i.default as any)
103
100
  }
104
101
  })
105
102
  ```
106
103
 
107
- 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#L80), for example using `InlineCollection`:
104
+ 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`:
105
+
108
106
  ```ts
109
- UnoCss({
107
+ UnoCSS({
110
108
  presets: [
111
109
  presetIcons({
112
110
  collections: {
@@ -128,29 +126,30 @@ And then, you can use it on your html: `<span class="i-custom:circle"></span>`
128
126
 
129
127
  In `Node.js` the preset will search for the installed iconify dataset automatically and so you don't need to register the `iconify` collections.
130
128
 
131
- 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#L80).
129
+ 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).
132
130
 
133
131
  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`.
132
+
134
133
  ```ts
135
134
  // vite.config.ts
136
135
  import { promises as fs } from 'fs'
137
136
  // loader helpers
138
137
  import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
139
138
 
140
- UnoCss({
141
- presets: [
139
+ UnoCSS({
140
+ presets: [
142
141
  presetIcons({
143
142
  collections: {
144
143
  // key as the collection name
145
144
  'my-icons': {
146
- 'account': '<svg><!-- ... --></svg>',
145
+ account: '<svg><!-- ... --></svg>',
147
146
  // load your custom icon lazily
148
- 'settings': () => fs.readFile('./path/to/my-icon.svg', 'utf-8'),
147
+ settings: () => fs.readFile('./path/to/my-icon.svg', 'utf-8'),
149
148
  /* ... */
150
149
  },
151
150
  'my-other-icons': async (iconName) => {
152
151
  // your custom loader here. Do whatever you want.
153
- // for example, fetch from a remote server:
152
+ // for example, fetch from a remote server:
154
153
  return await fetch(`https://example.com/icons/${iconName}.svg`).then(res => res.text())
155
154
  },
156
155
  // a helper to load icons from the file system
@@ -158,7 +157,7 @@ UnoCss({
158
157
  // you can also provide a transform callback to change each icon (optional)
159
158
  'my-yet-other-icons': FileSystemIconLoader(
160
159
  './assets/icons',
161
- svg => svg.replace(/^<svg /, '<svg fill="currentColor" ')
160
+ svg => svg.replace(/#fff/, 'currentColor')
162
161
  )
163
162
  }
164
163
  })
@@ -168,14 +167,16 @@ UnoCss({
168
167
 
169
168
  ## Icon Customizations
170
169
 
171
- You can customize all icons using `customizations` configuration option.
170
+ You can customize all icons using `customizations` configuration option.
172
171
 
173
172
  Available customizations functions:
173
+
174
174
  - `transform`: transform raw `svg`, will be only applied when using `custom` icon collection (`iconify` collections excluded).
175
175
  - `customize`: change default icon customizations values.
176
176
  - `iconCustomizer`: change default icon customizations values.
177
177
 
178
178
  For each loaded icon, the customizations will be applied in this order:
179
+
179
180
  - apply `transform` to raw `svg`, if provided and using custom icon collection
180
181
  - apply `customize` with default customizations, if provided
181
182
  - apply `iconCustomizer` with `customize` customizations, if provided
@@ -183,13 +184,14 @@ For each loaded icon, the customizations will be applied in this order:
183
184
  ### Global Custom Icon Transformation
184
185
 
185
186
  When loading your custom icons, you can transform them, for example adding `fill` attribute with `currentColor`:
187
+
186
188
  ```ts
187
- UnoCss({
189
+ UnoCSS({
188
190
  presets: [
189
191
  presetIcons({
190
192
  customizations: {
191
193
  transform(svg) {
192
- return svg.replace(/^<svg /, '<svg fill="currentColor" ')
194
+ return svg.replace(/#fff/, 'currentColor')
193
195
  }
194
196
  }
195
197
  })
@@ -198,8 +200,9 @@ UnoCss({
198
200
  ```
199
201
 
200
202
  From version `0.30.8` the `transform` provides the `collection` and `icon` names:
203
+
201
204
  ```ts
202
- UnoCss({
205
+ UnoCSS({
203
206
  presets: [
204
207
  presetIcons({
205
208
  customizations: {
@@ -207,8 +210,7 @@ UnoCss({
207
210
  // do not apply fill to this icons on this collection
208
211
  if (collection === 'custom' && icon === 'my-icon')
209
212
  return svg
210
-
211
- return svg.replace(/^<svg /, '<svg fill="currentColor" ')
213
+ return svg.replace(/#fff/, 'currentColor')
212
214
  }
213
215
  }
214
216
  })
@@ -219,8 +221,9 @@ UnoCss({
219
221
  ### Global Icon Customization
220
222
 
221
223
  When loading any icon you can customize common properties to all of them, for example configuring the same size:
224
+
222
225
  ```ts
223
- UnoCss({
226
+ UnoCSS({
224
227
  presets: [
225
228
  presetIcons({
226
229
  customizations: {
@@ -244,13 +247,14 @@ The `iconCustomizer` will take precedence over configuration.
244
247
  The `iconCustomizer` will be applied to any collection, that is, for each icon from `custom` loader, `inlined` on `custom collections` or from `@iconify`.
245
248
 
246
249
  For example, you can configure `iconCustomizer` to change all icons for a collection or individual icons on a collection:
250
+
247
251
  ```ts
248
- UnoCss({
252
+ UnoCSS({
249
253
  presets: [
250
254
  presetIcons({
251
255
  customizations: {
252
256
  iconCustomizer(collection, icon, props) {
253
- // customize all icons in this collection
257
+ // customize all icons in this collection
254
258
  if (collection === 'my-other-icons') {
255
259
  props.width = '4em'
256
260
  props.height = '4em'
@@ -260,7 +264,7 @@ UnoCss({
260
264
  props.width = '6em'
261
265
  props.height = '6em'
262
266
  }
263
- // customize this @iconify icon in this collection
267
+ // customize this @iconify icon in this collection
264
268
  if (collection === 'mdi' && icon === 'account') {
265
269
  props.width = '2em'
266
270
  props.height = '2em'
@@ -269,14 +273,14 @@ UnoCss({
269
273
  }
270
274
  })
271
275
  ]
272
- })
276
+ })
273
277
  ```
274
278
 
275
- ### Advanced Custom Icon Set Cleanup
279
+ ### Advanced Custom Icon Set Cleanup
276
280
 
277
281
  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/).
278
282
 
279
- You can check this repo, using this preset on a `Vue 3` project: https://github.com/iconify/tools/tree/main/%40iconify-demo/unocss.
283
+ 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).
280
284
 
281
285
  Read [Cleaning up icons](https://docs.iconify.design/articles/cleaning-up-icons/) article from [Iconify](https://iconify.design/) for more details.
282
286
 
@@ -286,4 +290,4 @@ This preset is inspired from [this issue](https://github.com/antfu/unplugin-icon
286
290
 
287
291
  ## License
288
292
 
289
- MIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
293
+ MIT License &copy; 2021-PRESENT [Anthony Fu](https://github.com/antfu)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-icons",
3
- "version": "0.32.0",
3
+ "version": "0.32.8",
4
4
  "description": "Pure CSS Icons for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -38,7 +38,7 @@
38
38
  "sideEffects": false,
39
39
  "dependencies": {
40
40
  "@iconify/utils": "^1.0.32",
41
- "@unocss/core": "0.32.0"
41
+ "@unocss/core": "0.32.8"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@iconify/types": "^1.1.0"
@@ -46,6 +46,5 @@
46
46
  "scripts": {
47
47
  "build": "unbuild",
48
48
  "stub": "unbuild --stub"
49
- },
50
- "readme": "# @unocss/preset-icons\n\nUse **any** icons with **Pure CSS** for [UnoCSS](https://github.com/unocss/unocss).\n\n<blockquote>\n<p>💡 Recommend reading - <br><a href=\"https://antfu.me/posts/icons-in-pure-css\"><strong>Icons in Pure CSS</strong></a><br></p>\n</blockquote>\n\nFollow the following conventions to use the icons\n\n- `<prefix><collection>-<icon>`\n- `<prefix><collection>:<icon>`\n\nFor examples:\n\n```html\n<!-- A basic anchor icon from Phosphor icons -->\n<div class=\"i-ph-anchor-simple-thin\" />\n<!-- An orange alarm from Material Design Icons -->\n<div class=\"i-mdi-alarm text-orange-400\" />\n<!-- A large Vue logo -->\n<div class=\"i-logos-vue text-3xl\" />\n<!-- Sun in light mode, Moon in dark mode, from Carbon -->\n<button class=\"i-carbon-sun dark:i-carbon-moon\" />\n<!-- Twemoji of laugh, turns to tear on hovering -->\n<div class=\"i-twemoji-grinning-face-with-smiling-eyes hover:i-twemoji-face-with-tears-of-joy\" />\n```\n\n<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>\n\n## Install\n\n```bash\nnpm i -D @unocss/preset-icons @iconify-json/[the-collection-you-want]\n```\n\nWe 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.\n\n```ts\nimport presetIcons from '@unocss/preset-icons'\n\nUnocss({\n presets: [\n presetIcons({ /* options */ }),\n // ...other presets\n ],\n})\n```\n\n> 💡 You can also use this preset alone as a complement to your existing UI frameworks to have pure CSS icons!\n\nIf you prefer to install the all the icon sets available on Iconify at once (~130MB):\n\n```bash\nnpm i -D @iconify/json\n```\n\n## Configuration\n\nRefer to the [type definition](https://github.com/unocss/unocss/blob/main/packages/preset-icons/src/types.ts#L4) for all configurations avaliable.\n\n### Extra Properties\n\nYou 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:\n\n```ts\npresetIcons({\n extraProperties: {\n 'display': 'inline-block',\n 'vertical-align': 'middle',\n // ...\n },\n})\n```\n\n## Modes Overriding\n\nBy 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.\n\n- `?bg` for `background-img` - renders the icon as a background image\n- `?mask` for `mask` - renders the icon as a mask image\n\nFor example, `vscode-icons:file-type-light-db`, an icon with colors that will be rendered as a background image. Use `vscode-icons:file-type-light-db?bg` to render it as a mask image and bypass it's colors.\n\n## Configuring collections and icons resolvers\n\nYou can provide collections via `@iconify-json/[the-collection-you-want]`, `@iconify/json` or using your custom ones using `collections` option on your `UnoCSS` configuration.\n\n### Browser\n\nTo load `iconify` collections you should use `@iconify-json/[the-collection-you-want]` and not `@iconify/json` since the `json` file is huge.\nYou will need to provide the `iconify` collections using `dynamic imports`, for example, on playground you have these collections:\n```ts\npresetIcons({\n collections: {\n carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default as any),\n mdi: () => import('@iconify-json/mdi/icons.json').then(i => i.default as any),\n logos: () => import('@iconify-json/logos/icons.json').then(i => i.default as any),\n twemoji: () => import('@iconify-json/twemoji/icons.json').then(i => i.default as any),\n ri: () => import('@iconify-json/ri/icons.json').then(i => i.default as any),\n tabler: () => import('@iconify-json/tabler/icons.json').then(i => i.default as any),\n uim: () => import('@iconify-json/uim/icons.json').then(i => i.default as any)\n }\n})\n```\n\nYou 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#L80), for example using `InlineCollection`:\n```ts\nUnoCss({\n presets: [\n presetIcons({\n collections: {\n custom: {\n circle: '<svg viewBox=\"0 0 120 120\"><circle cx=\"60\" cy=\"60\" r=\"50\"></circle></svg>',\n /* ... */\n },\n carbon: () => import('@iconify-json/carbon/icons.json').then(i => i.default as any),\n /* ... */\n }\n })\n ]\n})\n```\n\nAnd then, you can use it on your html: `<span class=\"i-custom:circle\"></span>`\n\n### Node.js\n\nIn `Node.js` the preset will search for the installed iconify dataset automatically and so you don't need to register the `iconify` collections.\n\nYou 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#L80).\n\nAdditionally, 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`.\n```ts\n// vite.config.ts\nimport { promises as fs } from 'fs'\n// loader helpers\nimport { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'\n\nUnoCss({\n presets: [ \n presetIcons({\n collections: {\n // key as the collection name\n 'my-icons': {\n 'account': '<svg><!-- ... --></svg>',\n // load your custom icon lazily\n 'settings': () => fs.readFile('./path/to/my-icon.svg', 'utf-8'),\n /* ... */\n },\n 'my-other-icons': async (iconName) => {\n // your custom loader here. Do whatever you want.\n // for example, fetch from a remote server: \n return await fetch(`https://example.com/icons/${iconName}.svg`).then(res => res.text())\n },\n // a helper to load icons from the file system\n // files under `./assets/icons` with `.svg` extension will be loaded as it's file name\n // you can also provide a transform callback to change each icon (optional)\n 'my-yet-other-icons': FileSystemIconLoader(\n './assets/icons',\n svg => svg.replace(/^<svg /, '<svg fill=\"currentColor\" ')\n )\n }\n })\n ]\n})\n```\n\n## Icon Customizations\n\nYou can customize all icons using `customizations` configuration option. \n\nAvailable customizations functions:\n- `transform`: transform raw `svg`, will be only applied when using `custom` icon collection (`iconify` collections excluded).\n- `customize`: change default icon customizations values.\n- `iconCustomizer`: change default icon customizations values.\n\nFor each loaded icon, the customizations will be applied in this order:\n- apply `transform` to raw `svg`, if provided and using custom icon collection\n- apply `customize` with default customizations, if provided\n- apply `iconCustomizer` with `customize` customizations, if provided\n\n### Global Custom Icon Transformation\n\nWhen loading your custom icons, you can transform them, for example adding `fill` attribute with `currentColor`:\n```ts\nUnoCss({\n presets: [\n presetIcons({\n customizations: {\n transform(svg) {\n return svg.replace(/^<svg /, '<svg fill=\"currentColor\" ') \n }\n }\n })\n ]\n})\n```\n\nFrom version `0.30.8` the `transform` provides the `collection` and `icon` names:\n```ts\nUnoCss({\n presets: [\n presetIcons({\n customizations: {\n transform(svg, collection, icon) {\n // do not apply fill to this icons on this collection\n if (collection === 'custom' && icon === 'my-icon')\n return svg\n \n return svg.replace(/^<svg /, '<svg fill=\"currentColor\" ') \n }\n }\n })\n ]\n})\n```\n\n### Global Icon Customization\n\nWhen loading any icon you can customize common properties to all of them, for example configuring the same size:\n```ts\nUnoCss({\n presets: [\n presetIcons({\n customizations: {\n customize(props) {\n props.width = '2em'\n props.height = '2em'\n return props\n }\n }\n })\n ]\n})\n```\n\n### Icon/Collection Customization\n\nYou can customize each icon using `iconCustomizer` configuration option.\n\nThe `iconCustomizer` will take precedence over configuration.\n\nThe `iconCustomizer` will be applied to any collection, that is, for each icon from `custom` loader, `inlined` on `custom collections` or from `@iconify`.\n\nFor example, you can configure `iconCustomizer` to change all icons for a collection or individual icons on a collection:\n```ts\nUnoCss({\n presets: [\n presetIcons({\n customizations: {\n iconCustomizer(collection, icon, props) {\n // customize all icons in this collection \n if (collection === 'my-other-icons') {\n props.width = '4em'\n props.height = '4em'\n }\n // customize this icon in this collection\n if (collection === 'my-icons' && icon === 'account') {\n props.width = '6em'\n props.height = '6em'\n }\n // customize this @iconify icon in this collection \n if (collection === 'mdi' && icon === 'account') {\n props.width = '2em'\n props.height = '2em'\n }\n }\n }\n })\n ]\n}) \n```\n\n### Advanced Custom Icon Set Cleanup \n\nWhen 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/).\n\nYou can check this repo, using this preset on a `Vue 3` project: https://github.com/iconify/tools/tree/main/%40iconify-demo/unocss.\n\nRead [Cleaning up icons](https://docs.iconify.design/articles/cleaning-up-icons/) article from [Iconify](https://iconify.design/) for more details.\n\n## Credits\n\nThis preset is inspired from [this issue](https://github.com/antfu/unplugin-icons/issues/88) created by [@husayt](https://github.com/husayt). Based on the work of [this PR](https://github.com/antfu/unplugin-icons/pull/90) by [@userquin](https://github.com/userquin).\n\n## License\n\nMIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)\n"
49
+ }
51
50
  }