vuepress-plugin-md-power 1.0.0-rc.83 → 1.0.0-rc.85

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 (2) hide show
  1. package/lib/node/index.js +15 -174
  2. package/package.json +8 -17
package/lib/node/index.js CHANGED
@@ -180,158 +180,9 @@ var pdfPlugin = (md) => {
180
180
  });
181
181
  };
182
182
 
183
- // src/node/features/icons/writer.ts
184
- import { constants, promises as fsp } from "node:fs";
185
- import { getIconContentCSS, getIconData } from "@iconify/utils";
186
- import { fs, logger } from "vuepress/utils";
187
- import { isPackageExists } from "local-pkg";
188
- import { customAlphabet as customAlphabet2 } from "nanoid";
189
-
190
- // src/node/utils/package.ts
191
- async function interopDefault(m) {
192
- const resolved = await m;
193
- return resolved.default || resolved;
194
- }
195
-
196
- // src/node/features/icons/writer.ts
197
- var nanoid2 = customAlphabet2("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 8);
198
- var iconDataCache = /* @__PURE__ */ new Map();
199
- var URL_CONTENT_RE = /(url\([\s\S]+?\))/;
200
- var CSS_PATH = "internal/md-power/icons.css";
201
- var locate;
202
- function resolveOption(opt) {
203
- const options = typeof opt === "object" ? opt : {};
204
- options.prefix ??= "vp-mdi";
205
- options.color = options.color === "currentColor" || !options.color ? "currentcolor" : options.color;
206
- options.size = options.size ? parseRect(`${options.size}`) : "1em";
207
- return options;
208
- }
209
- function createIconCSSWriter(app, opt) {
210
- const cache = /* @__PURE__ */ new Map();
211
- const isInstalled = isPackageExists("@iconify/json");
212
- const currentPath = app.dir.temp(CSS_PATH);
213
- const write = async (content) => {
214
- if (!content && app.env.isDev) {
215
- if (existsSync(currentPath) && (await fsp.stat(currentPath)).isFile()) {
216
- return;
217
- }
218
- }
219
- await app.writeTemp(CSS_PATH, content);
220
- };
221
- let timer = null;
222
- const options = resolveOption(opt);
223
- const prefix = options.prefix;
224
- const defaultContent = getDefaultContent(options);
225
- async function writeCss() {
226
- if (timer)
227
- clearTimeout(timer);
228
- timer = setTimeout(async () => {
229
- let css = defaultContent;
230
- if (cache.size > 0) {
231
- for (const [, { content, className }] of cache)
232
- css += `.${className} {
233
- --svg: ${content};
234
- }
235
- `;
236
- await write(css);
237
- }
238
- }, 100);
239
- }
240
- function addIcon(iconName) {
241
- if (!isInstalled)
242
- return;
243
- if (cache.has(iconName)) {
244
- const item2 = cache.get(iconName);
245
- return `${item2.className}${item2.background ? " bg" : ""}`;
246
- }
247
- const item = {
248
- className: `${prefix}-${nanoid2()}`,
249
- ...genIcon(iconName)
250
- };
251
- cache.set(iconName, item);
252
- writeCss();
253
- return `${item.className}${item.background ? " bg" : ""}`;
254
- }
255
- async function initIcon() {
256
- if (!opt)
257
- return await write("");
258
- if (!isInstalled) {
259
- logger.error("[plugin-md-power]: `@iconify/json` not found! Please install `@iconify/json` first.");
260
- return;
261
- }
262
- if (!locate) {
263
- const mod = await interopDefault(import("@iconify/json"));
264
- locate = mod.locate;
265
- }
266
- return await writeCss();
267
- }
268
- return { addIcon, writeCss, initIcon };
269
- }
270
- function getDefaultContent(options) {
271
- const { prefix, size, color } = options;
272
- return `[class^="${prefix}-"] {
273
- display: inline-block;
274
- width: ${size};
275
- height: ${size};
276
- vertical-align: middle;
277
- }
278
- [class^="${prefix}-"]:not(.bg) {
279
- color: inherit;
280
- background-color: ${color};
281
- -webkit-mask: var(--svg) no-repeat;
282
- mask: var(--svg) no-repeat;
283
- -webkit-mask-size: 100% 100%;
284
- mask-size: 100% 100%;
285
- }
286
- [class^="${prefix}-"].bg {
287
- background-color: transparent;
288
- background-image: var(--svg);
289
- background-repeat: no-repeat;
290
- background-size: 100% 100%;
291
- }
292
- `;
293
- }
294
- function genIcon(iconName) {
295
- if (!locate) {
296
- return { content: "", background: false };
297
- }
298
- const [collect, name] = iconName.split(":");
299
- let iconJson = iconDataCache.get(collect);
300
- if (!iconJson) {
301
- const filename = locate(collect);
302
- try {
303
- iconJson = JSON.parse(fs.readFileSync(filename, "utf-8"));
304
- iconDataCache.set(collect, iconJson);
305
- } catch {
306
- logger.warn(`[plugin-md-power] Can not find icon, ${collect} is missing!`);
307
- }
308
- }
309
- const data = getIconData(iconJson, name);
310
- if (!data) {
311
- logger.error(`[plugin-md-power] Can not read icon in ${collect}, ${name} is missing!`);
312
- return { content: "", background: false };
313
- }
314
- const content = getIconContentCSS(data, {
315
- height: data.height || 24
316
- });
317
- const match = content.match(URL_CONTENT_RE);
318
- return {
319
- content: match ? match[1] : "",
320
- background: !data.body.includes("currentColor")
321
- };
322
- }
323
- function existsSync(fp) {
324
- try {
325
- fs.accessSync(fp, constants.R_OK);
326
- return true;
327
- } catch {
328
- return false;
329
- }
330
- }
331
-
332
- // src/node/features/icons/plugin.ts
183
+ // src/node/features/icons.ts
333
184
  var [openTag, endTag] = [":[", "]:"];
334
- function createTokenizer(addIcon) {
185
+ function createTokenizer() {
335
186
  return (state, silent) => {
336
187
  let found = false;
337
188
  const max = state.posMax;
@@ -361,31 +212,25 @@ function createTokenizer(addIcon) {
361
212
  }
362
213
  state.posMax = state.pos;
363
214
  state.pos = start + 2;
364
- const [iconName, options = ""] = content.split(/\s+/);
215
+ const [name, options = ""] = content.split(/\s+/);
365
216
  const [size, color] = options.split("/");
366
- const open = state.push("iconify_open", "span", 1);
367
- open.markup = openTag;
368
- const className = addIcon(iconName);
369
- if (className)
370
- open.attrSet("class", className);
371
- let style = "";
217
+ const icon = state.push("vp_iconify_open", "VPIcon", 1);
218
+ icon.markup = openTag;
219
+ if (name)
220
+ icon.attrSet("name", name);
372
221
  if (size)
373
- style += `width:${parseRect(size)};height:${parseRect(size)};`;
222
+ icon.attrSet("size", size);
374
223
  if (color)
375
- style += `color:${color};`;
376
- if (style)
377
- open.attrSet("style", style);
378
- const text = state.push("text", "", 0);
379
- text.content = className ? "" : iconName;
380
- const close = state.push("iconify_close", "span", -1);
224
+ icon.attrSet("color", color);
225
+ const close = state.push("vp_iconify_close", "VPIcon", -1);
381
226
  close.markup = endTag;
382
227
  state.pos = state.posMax + 2;
383
228
  state.posMax = max;
384
229
  return true;
385
230
  };
386
231
  }
387
- var iconsPlugin = (md, addIcon = () => "") => {
388
- md.inline.ruler.before("emphasis", "iconify", createTokenizer(addIcon));
232
+ var iconsPlugin = (md) => {
233
+ md.inline.ruler.before("emphasis", "iconify", createTokenizer());
389
234
  };
390
235
 
391
236
  // src/node/features/video/bilibili.ts
@@ -659,7 +504,7 @@ var plotPlugin = (md) => {
659
504
 
660
505
  // src/node/features/langRepl.ts
661
506
  import container2 from "markdown-it-container";
662
- import { fs as fs2, getDirname, path as path2 } from "vuepress/utils";
507
+ import { fs, getDirname, path as path2 } from "vuepress/utils";
663
508
  var RE_INFO = /^(#editable)?(.*)$/;
664
509
  function createReplContainer(md, lang) {
665
510
  const type = `${lang}-repl`;
@@ -717,7 +562,7 @@ async function langReplPlugin(app, md, {
717
562
  }
718
563
  async function read(file) {
719
564
  try {
720
- const content = await fs2.readFile(file, "utf-8");
565
+ const content = await fs.readFile(file, "utf-8");
721
566
  return JSON.parse(content);
722
567
  } catch {
723
568
  }
@@ -735,7 +580,6 @@ var CLIENT_FOLDER = ensureEndingSlash(
735
580
  async function prepareConfigFile(app, options) {
736
581
  const imports = /* @__PURE__ */ new Set();
737
582
  const enhances = /* @__PURE__ */ new Set();
738
- imports.add(`import '@internal/md-power/icons.css'`);
739
583
  if (options.pdf) {
740
584
  imports.add(`import PDFViewer from '${CLIENT_FOLDER}components/PDFViewer.vue'`);
741
585
  enhances.add(`app.component('PDFViewer', PDFViewer)`);
@@ -785,15 +629,12 @@ ${Array.from(enhances.values()).map((item) => ` ${item}`).join("\n")}
785
629
  // src/node/plugin.ts
786
630
  function markdownPowerPlugin(options = {}) {
787
631
  return (app) => {
788
- const { initIcon, addIcon } = createIconCSSWriter(app, options.icons);
789
632
  return {
790
633
  name: "vuepress-plugin-md-power",
791
- // clientConfigFile: path.resolve(__dirname, '../client/config.js'),
792
634
  clientConfigFile: (app2) => prepareConfigFile(app2, options),
793
635
  define: {
794
636
  __MD_POWER_INJECT_OPTIONS__: options
795
637
  },
796
- onInitialized: async () => await initIcon(),
797
638
  extendsBundlerOptions(bundlerOptions) {
798
639
  if (options.repl) {
799
640
  addViteOptimizeDepsInclude(
@@ -813,7 +654,7 @@ function markdownPowerPlugin(options = {}) {
813
654
  md.use(pdfPlugin);
814
655
  }
815
656
  if (options.icons) {
816
- md.use(iconsPlugin, addIcon);
657
+ md.use(iconsPlugin);
817
658
  }
818
659
  if (options.bilibili) {
819
660
  md.use(bilibiliPlugin);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vuepress-plugin-md-power",
3
3
  "type": "module",
4
- "version": "1.0.0-rc.83",
4
+ "version": "1.0.0-rc.85",
5
5
  "description": "The Plugin for VuePress 2 - markdown power",
6
6
  "author": "pengzhanbo <volodymyr@foxmail.com>",
7
7
  "license": "MIT",
@@ -31,29 +31,20 @@
31
31
  "lib"
32
32
  ],
33
33
  "peerDependencies": {
34
- "@iconify/json": "^2",
35
34
  "vuepress": "2.0.0-rc.14"
36
35
  },
37
- "peerDependenciesMeta": {
38
- "@iconify/json": {
39
- "optional": true
40
- }
41
- },
42
36
  "dependencies": {
43
- "@iconify/utils": "^2.1.25",
44
- "@vuepress/helper": "2.0.0-rc.39",
45
- "@vueuse/core": "^10.11.0",
46
- "local-pkg": "^0.5.0",
37
+ "@vuepress/helper": "2.0.0-rc.40",
38
+ "@vueuse/core": "^10.11.1",
47
39
  "markdown-it-container": "^4.0.0",
48
40
  "nanoid": "^5.0.7",
49
- "shiki": "^1.10.3",
50
- "tm-grammars": "^1.13.13",
51
- "tm-themes": "^1.5.5",
52
- "vue": "^3.4.33"
41
+ "shiki": "^1.12.1",
42
+ "tm-grammars": "^1.16.3",
43
+ "tm-themes": "^1.6.2",
44
+ "vue": "^3.4.37"
53
45
  },
54
46
  "devDependencies": {
55
- "@iconify/json": "^2.2.229",
56
- "@types/markdown-it": "^14.1.1"
47
+ "@types/markdown-it": "^14.1.2"
57
48
  },
58
49
  "publishConfig": {
59
50
  "access": "public"