@pikacss/plugin-icons 0.0.13 → 0.0.15

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/index.cjs CHANGED
@@ -5,6 +5,9 @@ const core = require('@pikacss/core');
5
5
  const presetIcons = require('@unocss/preset-icons');
6
6
  const ofetch = require('ofetch');
7
7
 
8
+ function icons() {
9
+ return createIconsPlugin(createIconsLoader);
10
+ }
8
11
  function createCDNLoader(cdnBase) {
9
12
  return presetIcons.createCDNFetchLoader(ofetch.$fetch, cdnBase);
10
13
  }
@@ -20,7 +23,7 @@ async function createIconsLoader(config) {
20
23
  } = presetIcons.getEnvFlags();
21
24
  if (isNode && !isVSCode && !isESLint) {
22
25
  const nodeLoader = await presetIcons.createNodeLoader();
23
- if (nodeLoader !== void 0)
26
+ if (nodeLoader != null)
24
27
  loaders.push(nodeLoader);
25
28
  }
26
29
  if (cdn)
@@ -31,12 +34,14 @@ async function createIconsLoader(config) {
31
34
  const globalColonRE = /:/g;
32
35
  function createIconsPlugin(lookupIconLoader) {
33
36
  let engine;
34
- let enginePrefix = "";
35
- const registeredIconVariables = /* @__PURE__ */ new Map();
37
+ let iconsConfig;
36
38
  return core.defineEnginePlugin({
37
39
  name: "icons",
38
- config: async (config) => {
39
- const iconsConfig = config.icons || {};
40
+ configureRawConfig: async (config) => {
41
+ iconsConfig = config.icons || {};
42
+ },
43
+ configureEngine: async (_engine) => {
44
+ engine = _engine;
40
45
  const {
41
46
  scale = 1,
42
47
  mode = "auto",
@@ -81,20 +86,7 @@ function createIconsPlugin(lookupIconLoader) {
81
86
  ...autocompletePrefix.flatMap((p) => _autocomplete?.map((a) => `${p}${a.replace(prefixRE, "")}`) || [])
82
87
  ];
83
88
  let iconLoader;
84
- config.preflights ||= [];
85
- config.preflights.push((_, isFormatted) => {
86
- return core.renderCSSStyleBlocks(
87
- /* @__PURE__ */ new Map([[
88
- ":root",
89
- {
90
- properties: [...registeredIconVariables.entries()].map(([name, value]) => ({ property: name, value }))
91
- }
92
- ]]),
93
- isFormatted
94
- );
95
- });
96
- config.shortcuts ||= [];
97
- config.shortcuts.push({
89
+ engine.shortcuts.add({
98
90
  shortcut: new RegExp(`^(?:${[prefix].flat().join("|")})([\\w:-]+)(?:\\?(mask|bg|auto))?$`),
99
91
  value: async (match) => {
100
92
  let [full, body, _mode = mode] = match;
@@ -111,10 +103,9 @@ function createIconsPlugin(lookupIconLoader) {
111
103
  return {};
112
104
  }
113
105
  const url = `url("data:image/svg+xml;utf8,${utils.encodeSvgForCss(parsed.svg)}")`;
114
- const varName = `--${enginePrefix}svg-icon-${body.replace(globalColonRE, "-")}`;
115
- if (registeredIconVariables.has(varName) === false) {
116
- registeredIconVariables.set(varName, url);
117
- engine.notifyPreflightUpdated();
106
+ const varName = `--${engine.config.prefix}svg-icon-${body.replace(globalColonRE, "-")}`;
107
+ if (engine.variables.store.has(varName) === false) {
108
+ engine.variables.add([varName, url, { asValueOf: "-", asProperty: false }]);
118
109
  }
119
110
  if (_mode === "auto")
120
111
  _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
@@ -151,15 +142,8 @@ function createIconsPlugin(lookupIconLoader) {
151
142
  },
152
143
  autocomplete
153
144
  });
154
- },
155
- engineInitialized: (_engine) => {
156
- engine = _engine;
157
- enginePrefix = _engine.config.prefix;
158
145
  }
159
146
  });
160
147
  }
161
- function icons() {
162
- return createIconsPlugin(createIconsLoader);
163
- }
164
148
 
165
149
  exports.icons = icons;
package/dist/index.d.cts CHANGED
@@ -17,10 +17,11 @@ type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' |
17
17
  */
18
18
  autocomplete?: string[];
19
19
  }>;
20
- interface IconsPluginConfig {
21
- icons?: IconsConfig;
20
+ declare module '@pikacss/core' {
21
+ interface EngineConfig {
22
+ icons?: IconsConfig;
23
+ }
22
24
  }
23
- type IconsPlugin = EnginePlugin<IconsPluginConfig>;
24
- declare function icons(): IconsPlugin;
25
+ declare function icons(): EnginePlugin;
25
26
 
26
- export { type IconsConfig, type IconsPlugin, icons };
27
+ export { type IconsConfig, icons };
package/dist/index.d.mts CHANGED
@@ -17,10 +17,11 @@ type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' |
17
17
  */
18
18
  autocomplete?: string[];
19
19
  }>;
20
- interface IconsPluginConfig {
21
- icons?: IconsConfig;
20
+ declare module '@pikacss/core' {
21
+ interface EngineConfig {
22
+ icons?: IconsConfig;
23
+ }
22
24
  }
23
- type IconsPlugin = EnginePlugin<IconsPluginConfig>;
24
- declare function icons(): IconsPlugin;
25
+ declare function icons(): EnginePlugin;
25
26
 
26
- export { type IconsConfig, type IconsPlugin, icons };
27
+ export { type IconsConfig, icons };
package/dist/index.d.ts CHANGED
@@ -17,10 +17,11 @@ type IconsConfig = Simplify<Omit<IconsOptions, 'warn' | 'layer' | 'processor' |
17
17
  */
18
18
  autocomplete?: string[];
19
19
  }>;
20
- interface IconsPluginConfig {
21
- icons?: IconsConfig;
20
+ declare module '@pikacss/core' {
21
+ interface EngineConfig {
22
+ icons?: IconsConfig;
23
+ }
22
24
  }
23
- type IconsPlugin = EnginePlugin<IconsPluginConfig>;
24
- declare function icons(): IconsPlugin;
25
+ declare function icons(): EnginePlugin;
25
26
 
26
- export { type IconsConfig, type IconsPlugin, icons };
27
+ export { type IconsConfig, icons };
package/dist/index.mjs CHANGED
@@ -1,8 +1,11 @@
1
1
  import { encodeSvgForCss, loadIcon } from '@iconify/utils';
2
- import { defineEnginePlugin, renderCSSStyleBlocks, warn } from '@pikacss/core';
2
+ import { defineEnginePlugin, warn } from '@pikacss/core';
3
3
  import { parseIconWithLoader, getEnvFlags, createNodeLoader, combineLoaders, createCDNFetchLoader } from '@unocss/preset-icons';
4
4
  import { $fetch } from 'ofetch';
5
5
 
6
+ function icons() {
7
+ return createIconsPlugin(createIconsLoader);
8
+ }
6
9
  function createCDNLoader(cdnBase) {
7
10
  return createCDNFetchLoader($fetch, cdnBase);
8
11
  }
@@ -18,7 +21,7 @@ async function createIconsLoader(config) {
18
21
  } = getEnvFlags();
19
22
  if (isNode && !isVSCode && !isESLint) {
20
23
  const nodeLoader = await createNodeLoader();
21
- if (nodeLoader !== void 0)
24
+ if (nodeLoader != null)
22
25
  loaders.push(nodeLoader);
23
26
  }
24
27
  if (cdn)
@@ -29,12 +32,14 @@ async function createIconsLoader(config) {
29
32
  const globalColonRE = /:/g;
30
33
  function createIconsPlugin(lookupIconLoader) {
31
34
  let engine;
32
- let enginePrefix = "";
33
- const registeredIconVariables = /* @__PURE__ */ new Map();
35
+ let iconsConfig;
34
36
  return defineEnginePlugin({
35
37
  name: "icons",
36
- config: async (config) => {
37
- const iconsConfig = config.icons || {};
38
+ configureRawConfig: async (config) => {
39
+ iconsConfig = config.icons || {};
40
+ },
41
+ configureEngine: async (_engine) => {
42
+ engine = _engine;
38
43
  const {
39
44
  scale = 1,
40
45
  mode = "auto",
@@ -79,20 +84,7 @@ function createIconsPlugin(lookupIconLoader) {
79
84
  ...autocompletePrefix.flatMap((p) => _autocomplete?.map((a) => `${p}${a.replace(prefixRE, "")}`) || [])
80
85
  ];
81
86
  let iconLoader;
82
- config.preflights ||= [];
83
- config.preflights.push((_, isFormatted) => {
84
- return renderCSSStyleBlocks(
85
- /* @__PURE__ */ new Map([[
86
- ":root",
87
- {
88
- properties: [...registeredIconVariables.entries()].map(([name, value]) => ({ property: name, value }))
89
- }
90
- ]]),
91
- isFormatted
92
- );
93
- });
94
- config.shortcuts ||= [];
95
- config.shortcuts.push({
87
+ engine.shortcuts.add({
96
88
  shortcut: new RegExp(`^(?:${[prefix].flat().join("|")})([\\w:-]+)(?:\\?(mask|bg|auto))?$`),
97
89
  value: async (match) => {
98
90
  let [full, body, _mode = mode] = match;
@@ -109,10 +101,9 @@ function createIconsPlugin(lookupIconLoader) {
109
101
  return {};
110
102
  }
111
103
  const url = `url("data:image/svg+xml;utf8,${encodeSvgForCss(parsed.svg)}")`;
112
- const varName = `--${enginePrefix}svg-icon-${body.replace(globalColonRE, "-")}`;
113
- if (registeredIconVariables.has(varName) === false) {
114
- registeredIconVariables.set(varName, url);
115
- engine.notifyPreflightUpdated();
104
+ const varName = `--${engine.config.prefix}svg-icon-${body.replace(globalColonRE, "-")}`;
105
+ if (engine.variables.store.has(varName) === false) {
106
+ engine.variables.add([varName, url, { asValueOf: "-", asProperty: false }]);
116
107
  }
117
108
  if (_mode === "auto")
118
109
  _mode = parsed.svg.includes("currentColor") ? "mask" : "bg";
@@ -149,15 +140,8 @@ function createIconsPlugin(lookupIconLoader) {
149
140
  },
150
141
  autocomplete
151
142
  });
152
- },
153
- engineInitialized: (_engine) => {
154
- engine = _engine;
155
- enginePrefix = _engine.config.prefix;
156
143
  }
157
144
  });
158
145
  }
159
- function icons() {
160
- return createIconsPlugin(createIconsLoader);
161
- }
162
146
 
163
147
  export { icons };
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.0.13",
7
+ "version": "0.0.15",
8
8
  "author": "DevilTea <ch19980814@gmail.com>",
9
9
  "license": "MIT",
10
10
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "@iconify/utils": "^2.3.0",
39
39
  "@unocss/preset-icons": "^65.4.3",
40
40
  "ofetch": "^1.4.1",
41
- "@pikacss/core": "0.0.13"
41
+ "@pikacss/core": "0.0.15"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "unbuild",