@unocss/preset-icons 0.14.2 → 0.15.2

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/dist/fs.cjs ADDED
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const fs = require('fs');
6
+ const localPkg = require('local-pkg');
7
+
8
+ const _collections = {};
9
+ const isLegacyExists = localPkg.isPackageExists("@iconify/json");
10
+ async function loadCollectionFromFS(name) {
11
+ if (!_collections[name])
12
+ _collections[name] = task();
13
+ return _collections[name];
14
+ async function task() {
15
+ let jsonPath = localPkg.resolveModule(`@iconify-json/${name}/icons.json`);
16
+ if (!jsonPath && isLegacyExists)
17
+ jsonPath = localPkg.resolveModule(`@iconify/json/json/${name}.json`);
18
+ if (jsonPath) {
19
+ const icons = JSON.parse(await fs.promises.readFile(jsonPath, "utf8"));
20
+ return icons;
21
+ } else {
22
+ return void 0;
23
+ }
24
+ }
25
+ }
26
+
27
+ exports.loadCollectionFromFS = loadCollectionFromFS;
package/dist/fs.mjs CHANGED
@@ -1,8 +1,8 @@
1
- // src/fs.ts
2
- import { promises as fs } from "fs";
3
- import { resolveModule, isPackageExists } from "local-pkg";
4
- var _collections = {};
5
- var isLegacyExists = isPackageExists("@iconify/json");
1
+ import { promises } from 'fs';
2
+ import { isPackageExists, resolveModule } from 'local-pkg';
3
+
4
+ const _collections = {};
5
+ const isLegacyExists = isPackageExists("@iconify/json");
6
6
  async function loadCollectionFromFS(name) {
7
7
  if (!_collections[name])
8
8
  _collections[name] = task();
@@ -12,13 +12,12 @@ async function loadCollectionFromFS(name) {
12
12
  if (!jsonPath && isLegacyExists)
13
13
  jsonPath = resolveModule(`@iconify/json/json/${name}.json`);
14
14
  if (jsonPath) {
15
- const icons = JSON.parse(await fs.readFile(jsonPath, "utf8"));
15
+ const icons = JSON.parse(await promises.readFile(jsonPath, "utf8"));
16
16
  return icons;
17
17
  } else {
18
18
  return void 0;
19
19
  }
20
20
  }
21
21
  }
22
- export {
23
- loadCollectionFromFS
24
- };
22
+
23
+ export { loadCollectionFromFS };
@@ -1,37 +1,41 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ 'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
3
4
 
4
- var _chunkBS7EEF5Tjs = require('./chunk-BS7EEF5T.js');
5
+ const core = require('@unocss/core');
6
+ const build = require('@iconify/utils/lib/svg/build');
7
+ const customisations = require('@iconify/utils/lib/customisations');
8
+ const getIcon = require('@iconify/utils/lib/icon-set/get-icon');
5
9
 
6
- // src/index.ts
7
- var _core = require('@unocss/core');
8
- var _build = require('@iconify/utils/lib/svg/build');
9
- var _customisations = require('@iconify/utils/lib/customisations');
10
- var _geticon = require('@iconify/utils/lib/icon-set/get-icon');
11
- var COLLECTION_NAME_PARTS_MAX = 3;
10
+ const isNode = typeof process < "u" && typeof process.stdout < "u";
11
+ function encodeSvg(svg) {
12
+ return svg.replace("<svg", ~svg.indexOf("xmlns") ? "<svg" : '<svg xmlns="http://www.w3.org/2000/svg"').replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/{/g, "%7B").replace(/}/g, "%7D").replace(/</g, "%3C").replace(/>/g, "%3E");
13
+ }
14
+
15
+ const COLLECTION_NAME_PARTS_MAX = 3;
12
16
  async function searchForIcon(collection, id, collections, scale) {
13
17
  if (!collection || !id)
14
18
  return;
15
19
  let iconSet = collections[collection];
16
20
  if (typeof iconSet === "function")
17
21
  iconSet = await iconSet();
18
- if (!iconSet && _chunkBS7EEF5Tjs.isNode) {
19
- const { loadCollectionFromFS } = await Promise.resolve().then(() => require("./fs.js"));
22
+ if (!iconSet && isNode) {
23
+ const { loadCollectionFromFS } = await import('./fs.cjs');
20
24
  iconSet = await loadCollectionFromFS(collection);
21
25
  }
22
26
  if (!iconSet)
23
27
  return;
24
- const iconData = _geticon.getIconData.call(void 0, iconSet, id, true);
28
+ const iconData = getIcon.getIconData(iconSet, id, true);
25
29
  if (iconData) {
26
- const { attributes, body } = _build.iconToSVG.call(void 0, iconData, {
27
- ..._customisations.defaults,
30
+ const { attributes, body } = build.iconToSVG(iconData, {
31
+ ...customisations.defaults,
28
32
  height: `${scale}em`,
29
33
  width: `${scale}em`
30
34
  });
31
35
  return `<svg ${Object.entries(attributes).map((i) => `${i[0]}="${i[1]}"`).join(" ")}>${body}</svg>`;
32
36
  }
33
37
  }
34
- var preset = (options = {}) => {
38
+ const preset = (options = {}) => {
35
39
  const {
36
40
  scale = 1,
37
41
  mode = "auto",
@@ -69,13 +73,13 @@ var preset = (options = {}) => {
69
73
  }
70
74
  if (!svg) {
71
75
  if (warn)
72
- _core.warnOnce.call(void 0, `failed to load icon "${full}"`);
76
+ core.warnOnce(`failed to load icon "${full}"`);
73
77
  return;
74
78
  }
75
79
  let _mode = mode;
76
80
  if (_mode === "auto")
77
81
  _mode = svg.includes("currentColor") ? "mask" : "background-img";
78
- const url = `url("data:image/svg+xml;utf8,${_chunkBS7EEF5Tjs.encodeSvg.call(void 0, svg)}")`;
82
+ const url = `url("data:image/svg+xml;utf8,${encodeSvg(svg)}")`;
79
83
  if (_mode === "mask") {
80
84
  return {
81
85
  "--un-icon": url,
@@ -103,8 +107,6 @@ var preset = (options = {}) => {
103
107
  ]]
104
108
  };
105
109
  };
106
- var src_default = preset;
107
-
108
-
109
110
 
110
- exports.default = src_default; exports.preset = preset;
111
+ exports["default"] = preset;
112
+ exports.preset = preset;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,55 @@
1
- import { Preset } from '@unocss/core';
2
- import { IconsOptions } from './types';
3
- export { IconsOptions } from './types';
4
- import '@iconify/types';
1
+ import { Awaitable, Preset } from '@unocss/core';
2
+ import { IconifyJSON } from '@iconify/types';
3
+
4
+ interface IconsOptions {
5
+ /**
6
+ * Scale related to the current font size (1em).
7
+ *
8
+ * @default 1
9
+ */
10
+ scale?: number;
11
+ /**
12
+ * Mode of generated CSS icons.
13
+ *
14
+ * - `mask` - use background color and the `mask` property for monochrome icons
15
+ * - `background-img` - use background image for the icons, colors are static
16
+ * - `auto` - smartly decide mode between `mask` and `background-img` per icon based on its style
17
+ *
18
+ * @default 'auto'
19
+ * @see https://antfu.me/posts/icons-in-pure-css
20
+ */
21
+ mode?: 'mask' | 'background-img' | 'auto';
22
+ /**
23
+ * Class prefix for matching icon rules.
24
+ *
25
+ * @default `i-`
26
+ */
27
+ prefix?: string;
28
+ /**
29
+ * Extra CSS properties applied to the generated CSS
30
+ *
31
+ * @default {}
32
+ */
33
+ extraProperties?: Record<string, string>;
34
+ /**
35
+ * Emit warning when missing icons are matched
36
+ *
37
+ * @default false
38
+ */
39
+ warn?: boolean;
40
+ /**
41
+ * In Node.js environment, the preset will search for the installed iconify dataset automatically.
42
+ * When using in the browser, this options is provided to provide dataset with custom loading mechanism.
43
+ */
44
+ collections?: Record<string, IconifyJSON | undefined | (() => Awaitable<IconifyJSON | undefined>)>;
45
+ /**
46
+ * Rule layer
47
+ *
48
+ * @default 'icons'
49
+ */
50
+ layer?: string;
51
+ }
5
52
 
6
53
  declare const preset: (options?: IconsOptions) => Preset;
7
54
 
8
- export { preset as default, preset };
55
+ export { IconsOptions, preset as default, preset };
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
- import {
2
- encodeSvg,
3
- isNode
4
- } from "./chunk-IMDMXLHC.mjs";
1
+ import { warnOnce } from '@unocss/core';
2
+ import { iconToSVG } from '@iconify/utils/lib/svg/build';
3
+ import { defaults } from '@iconify/utils/lib/customisations';
4
+ import { getIconData } from '@iconify/utils/lib/icon-set/get-icon';
5
5
 
6
- // src/index.ts
7
- import { warnOnce } from "@unocss/core";
8
- import { iconToSVG } from "@iconify/utils/lib/svg/build";
9
- import { defaults as DefaultIconCustomizations } from "@iconify/utils/lib/customisations";
10
- import { getIconData } from "@iconify/utils/lib/icon-set/get-icon";
11
- var COLLECTION_NAME_PARTS_MAX = 3;
6
+ const isNode = typeof process < "u" && typeof process.stdout < "u";
7
+ function encodeSvg(svg) {
8
+ return svg.replace("<svg", ~svg.indexOf("xmlns") ? "<svg" : '<svg xmlns="http://www.w3.org/2000/svg"').replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/{/g, "%7B").replace(/}/g, "%7D").replace(/</g, "%3C").replace(/>/g, "%3E");
9
+ }
10
+
11
+ const COLLECTION_NAME_PARTS_MAX = 3;
12
12
  async function searchForIcon(collection, id, collections, scale) {
13
13
  if (!collection || !id)
14
14
  return;
@@ -16,7 +16,7 @@ async function searchForIcon(collection, id, collections, scale) {
16
16
  if (typeof iconSet === "function")
17
17
  iconSet = await iconSet();
18
18
  if (!iconSet && isNode) {
19
- const { loadCollectionFromFS } = await import("./fs.mjs");
19
+ const { loadCollectionFromFS } = await import('./fs.mjs');
20
20
  iconSet = await loadCollectionFromFS(collection);
21
21
  }
22
22
  if (!iconSet)
@@ -24,14 +24,14 @@ async function searchForIcon(collection, id, collections, scale) {
24
24
  const iconData = getIconData(iconSet, id, true);
25
25
  if (iconData) {
26
26
  const { attributes, body } = iconToSVG(iconData, {
27
- ...DefaultIconCustomizations,
27
+ ...defaults,
28
28
  height: `${scale}em`,
29
29
  width: `${scale}em`
30
30
  });
31
31
  return `<svg ${Object.entries(attributes).map((i) => `${i[0]}="${i[1]}"`).join(" ")}>${body}</svg>`;
32
32
  }
33
33
  }
34
- var preset = (options = {}) => {
34
+ const preset = (options = {}) => {
35
35
  const {
36
36
  scale = 1,
37
37
  mode = "auto",
@@ -103,8 +103,5 @@ var preset = (options = {}) => {
103
103
  ]]
104
104
  };
105
105
  };
106
- var src_default = preset;
107
- export {
108
- src_default as default,
109
- preset
110
- };
106
+
107
+ export { preset as default, preset };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-icons",
3
- "version": "0.14.2",
3
+ "version": "0.15.2",
4
4
  "description": "Pure CSS Icons for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -24,17 +24,17 @@
24
24
  "sideEffects": false,
25
25
  "exports": {
26
26
  ".": {
27
- "require": "./dist/index.js",
27
+ "require": "./dist/index.cjs",
28
28
  "import": "./dist/index.mjs",
29
29
  "types": "./dist/index.d.ts"
30
30
  },
31
31
  "./fs": {
32
- "require": "./dist/fs.js",
32
+ "require": "./dist/fs.cjs",
33
33
  "import": "./dist/fs.mjs",
34
34
  "types": "./dist/fs.d.ts"
35
35
  }
36
36
  },
37
- "main": "dist/index.js",
37
+ "main": "dist/index.cjs",
38
38
  "module": "dist/index.mjs",
39
39
  "types": "dist/index.d.ts",
40
40
  "files": [
@@ -42,15 +42,15 @@
42
42
  "*.css"
43
43
  ],
44
44
  "dependencies": {
45
- "@iconify/utils": "^1.0.19",
46
- "@unocss/core": "0.14.2",
45
+ "@iconify/utils": "^1.0.20",
46
+ "@unocss/core": "0.15.2",
47
47
  "local-pkg": "^0.4.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@iconify/types": "^1.0.12"
51
51
  },
52
52
  "scripts": {
53
- "build": "tsup",
54
- "dev": "tsup --watch src"
53
+ "build": "unbuild",
54
+ "stub": "unbuild --stub"
55
55
  }
56
56
  }
@@ -1,10 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils.ts
2
- var isNode = typeof process < "u" && typeof process.stdout < "u";
3
- function encodeSvg(svg) {
4
- return svg.replace("<svg", ~svg.indexOf("xmlns") ? "<svg" : '<svg xmlns="http://www.w3.org/2000/svg"').replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/{/g, "%7B").replace(/}/g, "%7D").replace(/</g, "%3C").replace(/>/g, "%3E");
5
- }
6
-
7
-
8
-
9
-
10
- exports.isNode = isNode; exports.encodeSvg = encodeSvg;
@@ -1,10 +0,0 @@
1
- // src/utils.ts
2
- var isNode = typeof process < "u" && typeof process.stdout < "u";
3
- function encodeSvg(svg) {
4
- return svg.replace("<svg", ~svg.indexOf("xmlns") ? "<svg" : '<svg xmlns="http://www.w3.org/2000/svg"').replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/{/g, "%7B").replace(/}/g, "%7D").replace(/</g, "%3C").replace(/>/g, "%3E");
5
- }
6
-
7
- export {
8
- isNode,
9
- encodeSvg
10
- };
package/dist/fs.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/fs.ts
2
- var _fs = require('fs');
3
- var _localpkg = require('local-pkg');
4
- var _collections = {};
5
- var isLegacyExists = _localpkg.isPackageExists.call(void 0, "@iconify/json");
6
- async function loadCollectionFromFS(name) {
7
- if (!_collections[name])
8
- _collections[name] = task();
9
- return _collections[name];
10
- async function task() {
11
- let jsonPath = _localpkg.resolveModule.call(void 0, `@iconify-json/${name}/icons.json`);
12
- if (!jsonPath && isLegacyExists)
13
- jsonPath = _localpkg.resolveModule.call(void 0, `@iconify/json/json/${name}.json`);
14
- if (jsonPath) {
15
- const icons = JSON.parse(await _fs.promises.readFile(jsonPath, "utf8"));
16
- return icons;
17
- } else {
18
- return void 0;
19
- }
20
- }
21
- }
22
-
23
-
24
- exports.loadCollectionFromFS = loadCollectionFromFS;
package/dist/types.d.ts DELETED
@@ -1,53 +0,0 @@
1
- import { Awaitable } from '@unocss/core';
2
- import { IconifyJSON } from '@iconify/types';
3
-
4
- interface IconsOptions {
5
- /**
6
- * Scale related to the current font size (1em).
7
- *
8
- * @default 1
9
- */
10
- scale?: number;
11
- /**
12
- * Mode of generated CSS icons.
13
- *
14
- * - `mask` - use background color and the `mask` property for monochrome icons
15
- * - `background-img` - use background image for the icons, colors are static
16
- * - `auto` - smartly decide mode between `mask` and `background-img` per icon based on its style
17
- *
18
- * @default 'auto'
19
- * @see https://antfu.me/posts/icons-in-pure-css
20
- */
21
- mode?: 'mask' | 'background-img' | 'auto';
22
- /**
23
- * Class prefix for matching icon rules.
24
- *
25
- * @default `i-`
26
- */
27
- prefix?: string;
28
- /**
29
- * Extra CSS properties applied to the generated CSS
30
- *
31
- * @default {}
32
- */
33
- extraProperties?: Record<string, string>;
34
- /**
35
- * Emit warning when missing icons are matched
36
- *
37
- * @default false
38
- */
39
- warn?: boolean;
40
- /**
41
- * In Node.js environment, the preset will search for the installed iconify dataset automatically.
42
- * When using in the browser, this options is provided to provide dataset with custom loading mechanism.
43
- */
44
- collections?: Record<string, IconifyJSON | undefined | (() => Awaitable<IconifyJSON | undefined>)>;
45
- /**
46
- * Rule layer
47
- *
48
- * @default 'icons'
49
- */
50
- layer?: string;
51
- }
52
-
53
- export { IconsOptions };
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- "use strict";
package/dist/types.mjs DELETED
File without changes
package/dist/utils.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare const isNode: boolean;
2
- declare function encodeSvg(svg: string): string;
3
-
4
- export { encodeSvg, isNode };
package/dist/utils.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
- var _chunkBS7EEF5Tjs = require('./chunk-BS7EEF5T.js');
5
-
6
-
7
-
8
- exports.encodeSvg = _chunkBS7EEF5Tjs.encodeSvg; exports.isNode = _chunkBS7EEF5Tjs.isNode;
package/dist/utils.mjs DELETED
@@ -1,8 +0,0 @@
1
- import {
2
- encodeSvg,
3
- isNode
4
- } from "./chunk-IMDMXLHC.mjs";
5
- export {
6
- encodeSvg,
7
- isNode
8
- };