vuepress-plugin-md-power 1.0.0-rc.74 → 1.0.0-rc.76
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.
|
@@ -7,5 +7,5 @@ export interface IconCacheItem {
|
|
|
7
7
|
export declare function createIconCSSWriter(app: App, opt?: boolean | IconsOptions): {
|
|
8
8
|
addIcon: (iconName: string) => string | undefined;
|
|
9
9
|
writeCss: () => Promise<void>;
|
|
10
|
-
initIcon: () => Promise<
|
|
10
|
+
initIcon: () => Promise<void>;
|
|
11
11
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { constants, promises as fsp } from 'node:fs';
|
|
1
2
|
import { getIconContentCSS, getIconData } from '@iconify/utils';
|
|
2
3
|
import { fs, logger } from 'vuepress/utils';
|
|
3
4
|
import { isPackageExists } from 'local-pkg';
|
|
@@ -7,6 +8,7 @@ import { parseRect } from '../../utils/parseRect.js';
|
|
|
7
8
|
const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 8);
|
|
8
9
|
const iconDataCache = new Map();
|
|
9
10
|
const URL_CONTENT_RE = /(url\([^]+?\))/;
|
|
11
|
+
const CSS_PATH = 'internal/md-power/icons.css';
|
|
10
12
|
function resolveOption(opt) {
|
|
11
13
|
const options = typeof opt === 'object' ? opt : {};
|
|
12
14
|
options.prefix ??= 'vp-mdi';
|
|
@@ -17,7 +19,15 @@ function resolveOption(opt) {
|
|
|
17
19
|
export function createIconCSSWriter(app, opt) {
|
|
18
20
|
const cache = new Map();
|
|
19
21
|
const isInstalled = isPackageExists('@iconify/json');
|
|
20
|
-
const
|
|
22
|
+
const currentPath = app.dir.temp(CSS_PATH);
|
|
23
|
+
const write = async (content) => {
|
|
24
|
+
if (!content && app.env.isDev) {
|
|
25
|
+
if (existsSync(currentPath) && (await fsp.stat(currentPath)).isFile()) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
await app.writeTemp(CSS_PATH, content);
|
|
30
|
+
};
|
|
21
31
|
let timer = null;
|
|
22
32
|
const options = resolveOption(opt);
|
|
23
33
|
const prefix = options.prefix;
|
|
@@ -27,9 +37,11 @@ export function createIconCSSWriter(app, opt) {
|
|
|
27
37
|
clearTimeout(timer);
|
|
28
38
|
timer = setTimeout(async () => {
|
|
29
39
|
let css = defaultContent;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
if (cache.size > 0) {
|
|
41
|
+
for (const [, { content, className }] of cache)
|
|
42
|
+
css += `.${className} {\n --svg: ${content};\n}\n`;
|
|
43
|
+
await write(css);
|
|
44
|
+
}
|
|
33
45
|
}, 100);
|
|
34
46
|
}
|
|
35
47
|
function addIcon(iconName) {
|
|
@@ -103,3 +115,12 @@ async function genIconContent(iconName, cb) {
|
|
|
103
115
|
const match = content.match(URL_CONTENT_RE);
|
|
104
116
|
return cb(match ? match[1] : '');
|
|
105
117
|
}
|
|
118
|
+
function existsSync(fp) {
|
|
119
|
+
try {
|
|
120
|
+
fs.accessSync(fp, constants.R_OK);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
package/package.json
CHANGED