vuepress-plugin-md-power 1.0.0-rc.80 → 1.0.0-rc.82

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 (93) hide show
  1. package/lib/client/components/CodeEditor.vue +4 -3
  2. package/lib/client/components/CodeSandbox.vue +1 -1
  3. package/lib/client/components/PDFViewer.vue +1 -1
  4. package/lib/client/components/Plot.vue +1 -1
  5. package/lib/client/components/Replit.vue +1 -1
  6. package/lib/client/composables/codeRepl.d.ts +7 -5
  7. package/lib/client/composables/codeRepl.js +253 -145
  8. package/lib/client/composables/pdf.d.ts +7 -3
  9. package/lib/client/composables/pdf.js +55 -81
  10. package/lib/client/composables/rustRepl.d.ts +3 -2
  11. package/lib/client/composables/rustRepl.js +96 -94
  12. package/lib/client/composables/size.d.ts +9 -5
  13. package/lib/client/composables/size.js +36 -44
  14. package/lib/client/index.js +2 -1
  15. package/lib/client/options.d.ts +5 -2
  16. package/lib/client/options.js +5 -1
  17. package/lib/client/utils/http.d.ts +3 -1
  18. package/lib/client/utils/http.js +24 -20
  19. package/lib/client/utils/is.d.ts +5 -3
  20. package/lib/client/utils/is.js +16 -10
  21. package/lib/client/utils/link.d.ts +3 -1
  22. package/lib/client/utils/link.js +8 -4
  23. package/lib/client/utils/sleep.d.ts +3 -1
  24. package/lib/client/utils/sleep.js +8 -4
  25. package/lib/node/index.d.ts +188 -2
  26. package/lib/node/index.js +847 -2
  27. package/lib/shared/index.d.ts +185 -10
  28. package/lib/shared/index.js +0 -10
  29. package/package.json +9 -9
  30. package/lib/node/features/caniuse.d.ts +0 -25
  31. package/lib/node/features/caniuse.js +0 -87
  32. package/lib/node/features/codeSandbox.d.ts +0 -7
  33. package/lib/node/features/codeSandbox.js +0 -29
  34. package/lib/node/features/codepen.d.ts +0 -7
  35. package/lib/node/features/codepen.js +0 -42
  36. package/lib/node/features/icons/index.d.ts +0 -2
  37. package/lib/node/features/icons/index.js +0 -2
  38. package/lib/node/features/icons/plugin.d.ts +0 -10
  39. package/lib/node/features/icons/plugin.js +0 -61
  40. package/lib/node/features/icons/writer.d.ts +0 -11
  41. package/lib/node/features/icons/writer.js +0 -126
  42. package/lib/node/features/jsfiddle.d.ts +0 -6
  43. package/lib/node/features/jsfiddle.js +0 -28
  44. package/lib/node/features/langRepl.d.ts +0 -4
  45. package/lib/node/features/langRepl.js +0 -59
  46. package/lib/node/features/pdf.d.ts +0 -2
  47. package/lib/node/features/pdf.js +0 -31
  48. package/lib/node/features/plot.d.ts +0 -5
  49. package/lib/node/features/plot.js +0 -48
  50. package/lib/node/features/replit.d.ts +0 -7
  51. package/lib/node/features/replit.js +0 -22
  52. package/lib/node/features/video/bilibili.d.ts +0 -2
  53. package/lib/node/features/video/bilibili.js +0 -58
  54. package/lib/node/features/video/youtube.d.ts +0 -2
  55. package/lib/node/features/video/youtube.js +0 -47
  56. package/lib/node/plugin.d.ts +0 -3
  57. package/lib/node/plugin.js +0 -80
  58. package/lib/node/prepareConfigFile.d.ts +0 -3
  59. package/lib/node/prepareConfigFile.js +0 -59
  60. package/lib/node/utils/createRuleBlock.d.ts +0 -18
  61. package/lib/node/utils/createRuleBlock.js +0 -34
  62. package/lib/node/utils/package.d.ts +0 -4
  63. package/lib/node/utils/package.js +0 -4
  64. package/lib/node/utils/parseRect.d.ts +0 -1
  65. package/lib/node/utils/parseRect.js +0 -5
  66. package/lib/node/utils/resolveAttrs.d.ts +0 -4
  67. package/lib/node/utils/resolveAttrs.js +0 -29
  68. package/lib/node/utils/timeToSeconds.d.ts +0 -1
  69. package/lib/node/utils/timeToSeconds.js +0 -8
  70. package/lib/shared/caniuse.d.ts +0 -18
  71. package/lib/shared/caniuse.js +0 -1
  72. package/lib/shared/codeSandbox.d.ts +0 -11
  73. package/lib/shared/codeSandbox.js +0 -1
  74. package/lib/shared/codepen.d.ts +0 -10
  75. package/lib/shared/codepen.js +0 -1
  76. package/lib/shared/icons.d.ts +0 -17
  77. package/lib/shared/icons.js +0 -1
  78. package/lib/shared/jsfiddle.d.ts +0 -8
  79. package/lib/shared/jsfiddle.js +0 -1
  80. package/lib/shared/pdf.d.ts +0 -15
  81. package/lib/shared/pdf.js +0 -1
  82. package/lib/shared/plot.d.ts +0 -27
  83. package/lib/shared/plot.js +0 -1
  84. package/lib/shared/plugin.d.ts +0 -21
  85. package/lib/shared/plugin.js +0 -1
  86. package/lib/shared/repl.d.ts +0 -22
  87. package/lib/shared/repl.js +0 -1
  88. package/lib/shared/replit.d.ts +0 -6
  89. package/lib/shared/replit.js +0 -1
  90. package/lib/shared/size.d.ts +0 -5
  91. package/lib/shared/size.js +0 -1
  92. package/lib/shared/video.d.ts +0 -22
  93. package/lib/shared/video.js +0 -1
@@ -1,10 +1,185 @@
1
- export * from './caniuse.js';
2
- export * from './pdf.js';
3
- export * from './icons.js';
4
- export * from './video.js';
5
- export * from './codepen.js';
6
- export * from './codeSandbox.js';
7
- export * from './replit.js';
8
- export * from './jsfiddle.js';
9
- export * from './plot.js';
10
- export * from './plugin.js';
1
+ import { BuiltinTheme, ThemeRegistration } from 'shiki';
2
+
3
+ type CanIUseMode = 'embed' | 'image';
4
+ interface CanIUseTokenMeta {
5
+ feature: string;
6
+ mode: CanIUseMode;
7
+ versions: string;
8
+ }
9
+ interface CanIUseOptions {
10
+ /**
11
+ * 嵌入模式
12
+ *
13
+ * embed 通过iframe嵌入,提供可交互视图
14
+ *
15
+ * image 通过图片嵌入,静态
16
+ *
17
+ * @default 'embed'
18
+ */
19
+ mode?: CanIUseMode;
20
+ }
21
+
22
+ interface SizeOptions {
23
+ width?: string;
24
+ height?: string;
25
+ ratio?: number | string;
26
+ }
27
+
28
+ type PDFEmbedType = 'iframe' | 'embed' | 'pdfjs';
29
+ interface PDFTokenMeta extends SizeOptions {
30
+ page?: number;
31
+ noToolbar?: boolean;
32
+ zoom?: number;
33
+ src?: string;
34
+ title?: string;
35
+ }
36
+ interface PDFOptions {
37
+ /**
38
+ * pdfjs url
39
+ */
40
+ pdfjsUrl?: string;
41
+ }
42
+
43
+ interface IconsOptions {
44
+ /**
45
+ * The prefix of the icon className
46
+ * @default 'vp-mdi'
47
+ */
48
+ prefix?: string;
49
+ /**
50
+ * The size of the icon
51
+ * @default '1em'
52
+ */
53
+ size?: string | number;
54
+ /**
55
+ * The color of the icon
56
+ * @default 'currentColor'
57
+ */
58
+ color?: string;
59
+ }
60
+
61
+ interface VideoOptions {
62
+ bilibili?: boolean;
63
+ youtube?: boolean;
64
+ }
65
+ interface BilibiliTokenMeta extends SizeOptions {
66
+ title?: string;
67
+ bvid?: string;
68
+ aid?: string;
69
+ cid?: string;
70
+ autoplay?: boolean;
71
+ time?: string | number;
72
+ page?: number;
73
+ }
74
+ interface YoutubeTokenMeta extends SizeOptions {
75
+ title?: string;
76
+ id: string;
77
+ autoplay?: boolean;
78
+ loop?: boolean;
79
+ start?: string | number;
80
+ end?: string | number;
81
+ }
82
+
83
+ interface CodepenTokenMeta extends SizeOptions {
84
+ title?: string;
85
+ user?: string;
86
+ slash?: string;
87
+ tab?: string;
88
+ theme?: string;
89
+ preview?: boolean;
90
+ editable?: boolean;
91
+ }
92
+
93
+ interface CodeSandboxTokenMeta extends SizeOptions {
94
+ user?: string;
95
+ id?: string;
96
+ layout?: string;
97
+ type?: 'button' | 'embed';
98
+ title?: string;
99
+ filepath?: string;
100
+ navbar?: boolean;
101
+ console?: boolean;
102
+ }
103
+
104
+ type ThemeOptions = BuiltinTheme | {
105
+ light: BuiltinTheme;
106
+ dark: BuiltinTheme;
107
+ };
108
+ interface ReplOptions {
109
+ theme?: ThemeOptions;
110
+ go?: boolean;
111
+ kotlin?: boolean;
112
+ rust?: boolean;
113
+ }
114
+ interface ReplEditorData {
115
+ grammars: {
116
+ go?: any;
117
+ kotlin?: any;
118
+ rust?: any;
119
+ };
120
+ theme: ThemeRegistration | {
121
+ light: ThemeRegistration;
122
+ dark: ThemeRegistration;
123
+ };
124
+ }
125
+
126
+ interface ReplitTokenMeta extends SizeOptions {
127
+ title?: string;
128
+ source?: string;
129
+ theme?: string;
130
+ }
131
+
132
+ interface JSFiddleTokenMeta extends SizeOptions {
133
+ user?: string;
134
+ id?: string;
135
+ title?: string;
136
+ theme?: string;
137
+ tab?: string;
138
+ }
139
+
140
+ interface PlotOptions {
141
+ /**
142
+ * 是否启用 `=| |=` markdown (该标记为非标准标记,脱离插件将不生效)
143
+ * @default true
144
+ */
145
+ tag?: boolean;
146
+ /**
147
+ * 遮罩层颜色
148
+ */
149
+ mask?: string | {
150
+ light: string;
151
+ dark: string;
152
+ };
153
+ /**
154
+ * 文本颜色
155
+ */
156
+ color?: string | {
157
+ light: string;
158
+ dark: string;
159
+ };
160
+ /**
161
+ * 触发方式
162
+ *
163
+ * @default 'hover'
164
+ */
165
+ trigger?: 'hover' | 'click';
166
+ }
167
+
168
+ interface MarkdownPowerPluginOptions {
169
+ pdf?: boolean | PDFOptions;
170
+ icons?: boolean | IconsOptions;
171
+ plot?: boolean | PlotOptions;
172
+ bilibili?: boolean;
173
+ youtube?: boolean;
174
+ codepen?: boolean;
175
+ /**
176
+ * @deprecated
177
+ */
178
+ replit?: boolean;
179
+ codeSandbox?: boolean;
180
+ jsfiddle?: boolean;
181
+ repl?: false | ReplOptions;
182
+ caniuse?: boolean | CanIUseOptions;
183
+ }
184
+
185
+ export type { BilibiliTokenMeta, CanIUseMode, CanIUseOptions, CanIUseTokenMeta, CodeSandboxTokenMeta, CodepenTokenMeta, IconsOptions, JSFiddleTokenMeta, MarkdownPowerPluginOptions, PDFEmbedType, PDFOptions, PDFTokenMeta, PlotOptions, ReplEditorData, ReplOptions, ReplitTokenMeta, SizeOptions, ThemeOptions, VideoOptions, YoutubeTokenMeta };
@@ -1,10 +0,0 @@
1
- export * from './caniuse.js';
2
- export * from './pdf.js';
3
- export * from './icons.js';
4
- export * from './video.js';
5
- export * from './codepen.js';
6
- export * from './codeSandbox.js';
7
- export * from './replit.js';
8
- export * from './jsfiddle.js';
9
- export * from './plot.js';
10
- export * from './plugin.js';
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.80",
4
+ "version": "1.0.0-rc.82",
5
5
  "description": "The Plugin for VuePress 2 - markdown power",
6
6
  "author": "pengzhanbo <volodymyr@foxmail.com>",
7
7
  "license": "MIT",
@@ -41,18 +41,18 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@iconify/utils": "^2.1.25",
44
- "@vuepress/helper": "2.0.0-rc.38",
44
+ "@vuepress/helper": "2.0.0-rc.39",
45
45
  "@vueuse/core": "^10.11.0",
46
46
  "local-pkg": "^0.5.0",
47
47
  "markdown-it-container": "^4.0.0",
48
48
  "nanoid": "^5.0.7",
49
49
  "shiki": "^1.10.3",
50
- "tm-grammars": "^1.13.11",
51
- "tm-themes": "^1.5.3",
52
- "vue": "^3.4.31"
50
+ "tm-grammars": "^1.13.13",
51
+ "tm-themes": "^1.5.5",
52
+ "vue": "^3.4.33"
53
53
  },
54
54
  "devDependencies": {
55
- "@iconify/json": "^2.2.228",
55
+ "@iconify/json": "^2.2.229",
56
56
  "@types/markdown-it": "^14.1.1"
57
57
  },
58
58
  "publishConfig": {
@@ -65,9 +65,9 @@
65
65
  "vuepress-plugin-md-power"
66
66
  ],
67
67
  "scripts": {
68
- "build": "pnpm run copy && pnpm run ts",
69
- "clean": "rimraf --glob ./lib ./*.tsbuildinfo",
68
+ "build": "pnpm copy && pnpm tsup",
69
+ "clean": "rimraf --glob ./lib",
70
70
  "copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib",
71
- "ts": "tsc -b tsconfig.build.json"
71
+ "tsup": "tsup --config tsup.config.ts"
72
72
  }
73
73
  }
@@ -1,25 +0,0 @@
1
- /**
2
- * @[caniuse embed{1,2,3,4}](feature_name)
3
- * @[caniuse image](feature_name)
4
- */
5
- import type { PluginWithOptions } from 'markdown-it';
6
- import type MarkdownIt from 'markdown-it';
7
- import type { CanIUseOptions } from '../../shared/index.js';
8
- /**
9
- * @example
10
- * ```md
11
- * @[caniuse](feature_name)
12
- * ```
13
- */
14
- export declare const caniusePlugin: PluginWithOptions<CanIUseOptions>;
15
- /**
16
- * @deprecated use caniuse plugin
17
- *
18
- * 兼容旧语法
19
- * @example
20
- * ```md
21
- * :::caniuse <feature_name>
22
- * :::
23
- * ```
24
- */
25
- export declare function legacyCaniuse(md: MarkdownIt, { mode }?: CanIUseOptions): void;
@@ -1,87 +0,0 @@
1
- import container from 'markdown-it-container';
2
- import { customAlphabet } from 'nanoid';
3
- import { createRuleBlock } from '../utils/createRuleBlock.js';
4
- const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5);
5
- const UNDERLINE_RE = /_+/g;
6
- /**
7
- * @example
8
- * ```md
9
- * @[caniuse](feature_name)
10
- * ```
11
- */
12
- export const caniusePlugin = (md, { mode: defaultMode = 'embed' } = {}) => {
13
- createRuleBlock(md, {
14
- type: 'caniuse',
15
- syntaxPattern: /^@\[caniuse(?:\s*?(embed|image)?(?:{([0-9,\-]*?)})?)\]\(([^)]*)\)/,
16
- meta: ([, mode, versions = '', feature]) => ({
17
- feature,
18
- mode: mode || defaultMode,
19
- versions,
20
- }),
21
- content: meta => resolveCanIUse(meta),
22
- });
23
- };
24
- /**
25
- * @deprecated use caniuse plugin
26
- *
27
- * 兼容旧语法
28
- * @example
29
- * ```md
30
- * :::caniuse <feature_name>
31
- * :::
32
- * ```
33
- */
34
- export function legacyCaniuse(md, { mode = 'embed' } = {}) {
35
- const modeMap = ['image', 'embed'];
36
- const isMode = (mode) => modeMap.includes(mode);
37
- mode = isMode(mode) ? mode : modeMap[0];
38
- const type = 'caniuse';
39
- const validateReg = new RegExp(`^${type}\\s+(.*)$`);
40
- const validate = (info) => {
41
- return validateReg.test(info.trim());
42
- };
43
- const render = (tokens, index) => {
44
- const token = tokens[index];
45
- if (token.nesting === 1) {
46
- const info = token.info.trim().slice(type.length).trim() || '';
47
- const feature = info.split(/\s+/)[0];
48
- const versions = info.match(/\{(.*)\}/)?.[1] || '';
49
- return feature ? resolveCanIUse({ feature, mode, versions }) : '';
50
- }
51
- else {
52
- return '';
53
- }
54
- };
55
- md.use(container, type, { validate, render });
56
- }
57
- function resolveCanIUse({ feature, mode, versions }) {
58
- if (!feature)
59
- return '';
60
- if (mode === 'image') {
61
- const link = 'https://caniuse.bitsofco.de/image/';
62
- const alt = `Data on support for the ${feature} feature across the major browsers from caniuse.com`;
63
- return `<ClientOnly><p><picture>
64
- <source type="image/webp" srcset="${link}${feature}.webp">
65
- <source type="image/png" srcset="${link}${feature}.png">
66
- <img src="${link}${feature}.jpg" alt="${alt}" width="100%">
67
- </picture></p></ClientOnly>`;
68
- }
69
- feature = feature.replace(UNDERLINE_RE, '_');
70
- const { past, future } = resolveVersions(versions);
71
- const meta = nanoid();
72
- return `<CanIUseViewer feature="${feature}" meta="${meta}" past="${past}" future="${future}" />`;
73
- }
74
- function resolveVersions(versions) {
75
- if (!versions)
76
- return { past: 2, future: 1 };
77
- const list = versions
78
- .split(',')
79
- .map(v => Number(v.trim()))
80
- .filter(v => !Number.isNaN(v) && v >= -5 && v <= 3);
81
- list.push(0);
82
- const uniq = [...new Set(list)].sort((a, b) => b - a);
83
- return {
84
- future: uniq[0],
85
- past: Math.abs(uniq[uniq.length - 1]),
86
- };
87
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * @[codesandbox](id)
3
- * @[codesandbox share](user/id)
4
- * @[codesanbox title="xxx" layout="Editor+Preview" height="500px" navbar="false" console="false"](id#filepath)
5
- */
6
- import type { PluginWithOptions } from 'markdown-it';
7
- export declare const codeSandboxPlugin: PluginWithOptions<never>;
@@ -1,29 +0,0 @@
1
- import { resolveAttrs } from '../utils/resolveAttrs.js';
2
- import { parseRect } from '../utils/parseRect.js';
3
- import { createRuleBlock } from '../utils/createRuleBlock.js';
4
- export const codeSandboxPlugin = (md) => {
5
- createRuleBlock(md, {
6
- type: 'codesandbox',
7
- syntaxPattern: /^@\[codesandbox(?:\s+(embed|button))?(?:\s+([^]*?))?\]\(([^)]*?)\)/,
8
- meta([, type, info = '', source = '']) {
9
- const { attrs } = resolveAttrs(info);
10
- const [profile, filepath = ''] = source.split('#');
11
- const [user, id] = profile.includes('/') ? profile.split('/') : ['', profile];
12
- return {
13
- width: attrs.width ? parseRect(attrs.width) : '100%',
14
- height: attrs.height ? parseRect(attrs.height) : '500px',
15
- user,
16
- id,
17
- title: attrs.title ?? '',
18
- console: attrs.console ?? false,
19
- navbar: attrs.navbar ?? true,
20
- layout: attrs.layout ?? '',
21
- type: (type || 'embed'),
22
- filepath,
23
- };
24
- },
25
- content({ title, height, width, user, id, type, filepath, console, navbar, layout }) {
26
- return `<CodeSandboxViewer title="${title}" height="${height}" width="${width}" user="${user}" id="${id}" type="${type}" filepath="${filepath}" :console=${console} :navbar=${navbar} layout="${layout}" />`;
27
- },
28
- });
29
- };
@@ -1,7 +0,0 @@
1
- /**
2
- * @[codepen](user/slash)
3
- * @[codepen preview](user/slash)
4
- * @[codepen preview editable title="" height="400px" tab="css,result" theme="dark"](user/slash)
5
- */
6
- import type { PluginWithOptions } from 'markdown-it';
7
- export declare const codepenPlugin: PluginWithOptions<never>;
@@ -1,42 +0,0 @@
1
- import { resolveAttrs } from '../utils/resolveAttrs.js';
2
- import { parseRect } from '../utils/parseRect.js';
3
- import { createRuleBlock } from '../utils/createRuleBlock.js';
4
- const CODEPEN_LINK = 'https://codepen.io/';
5
- export const codepenPlugin = (md) => {
6
- createRuleBlock(md, {
7
- type: 'codepen',
8
- syntaxPattern: /^@\[codepen(?:\s+([^]*?))?\]\(([^)]*?)\)/,
9
- meta: ([, info = '', source = '']) => {
10
- const { attrs } = resolveAttrs(info);
11
- const [user, slash] = source.split('/');
12
- return {
13
- width: attrs.width ? parseRect(attrs.width) : '100%',
14
- height: attrs.height ? parseRect(attrs.height) : '400px',
15
- user,
16
- slash,
17
- title: attrs.title,
18
- preview: attrs.preview,
19
- editable: attrs.editable,
20
- tab: attrs.tab ?? 'result',
21
- theme: attrs.theme,
22
- };
23
- },
24
- content: (meta) => {
25
- const { title = 'Codepen', height, width } = meta;
26
- const params = new URLSearchParams();
27
- if (meta.editable) {
28
- params.set('editable', 'true');
29
- }
30
- if (meta.tab) {
31
- params.set('default-tab', meta.tab);
32
- }
33
- if (meta.theme) {
34
- params.set('theme-id', meta.theme);
35
- }
36
- const middle = meta.preview ? '/embed/preview/' : '/embed/';
37
- const link = `${CODEPEN_LINK}${meta.user}${middle}${meta.slash}?${params.toString()}`;
38
- const style = `width:${width};height:${height};margin:16px auto;border-radius:5px;`;
39
- return `<iframe class="code-pen-iframe-wrapper" src="${link}" title="${title}" style="${style}" frameborder="no" loading="lazy" allowtransparency="true" allowfullscreen="true">See the Pen <a href="${CODEPEN_LINK}${meta.user}/pen/${meta.slash}">${title}</a> by ${meta.user} (<a href="${CODEPEN_LINK}${meta.user}">@${meta.user}</a>) on <a href="${CODEPEN_LINK}">CodePen</a>.</iframe>`;
40
- },
41
- });
42
- };
@@ -1,2 +0,0 @@
1
- export * from './writer.js';
2
- export * from './plugin.js';
@@ -1,2 +0,0 @@
1
- export * from './writer.js';
2
- export * from './plugin.js';
@@ -1,10 +0,0 @@
1
- /**
2
- * :[mdi:11]:
3
- * :[mdi:11 24px]:
4
- * :[mid:11 /#ccc]:
5
- * :[fluent-mdl2:toggle-filled 128px/#fff]:
6
- */
7
- import type { PluginWithOptions } from 'markdown-it';
8
- type AddIcon = (iconName: string) => string | undefined;
9
- export declare const iconsPlugin: PluginWithOptions<AddIcon>;
10
- export {};
@@ -1,61 +0,0 @@
1
- import { parseRect } from '../../utils/parseRect.js';
2
- const [openTag, endTag] = [':[', ']:'];
3
- function createTokenizer(addIcon) {
4
- return (state, silent) => {
5
- let found = false;
6
- const max = state.posMax;
7
- const start = state.pos;
8
- if (state.src.slice(start, start + 2) !== openTag)
9
- return false;
10
- if (silent)
11
- return false;
12
- // :[]:
13
- if (max - start < 5)
14
- return false;
15
- state.pos = start + 2;
16
- while (state.pos < max) {
17
- if (state.src.slice(state.pos, state.pos + 2) === endTag) {
18
- found = true;
19
- break;
20
- }
21
- state.md.inline.skipToken(state);
22
- }
23
- if (!found || start + 2 === state.pos) {
24
- state.pos = start;
25
- return false;
26
- }
27
- const content = state.src.slice(start + 2, state.pos);
28
- // 不允许前后带有空格
29
- if (/^\s|\s$/.test(content)) {
30
- state.pos = start;
31
- return false;
32
- }
33
- // found!
34
- state.posMax = state.pos;
35
- state.pos = start + 2;
36
- const [iconName, options = ''] = content.split(/\s+/);
37
- const [size, color] = options.split('/');
38
- const open = state.push('iconify_open', 'span', 1);
39
- open.markup = openTag;
40
- const className = addIcon(iconName);
41
- if (className)
42
- open.attrSet('class', className);
43
- let style = '';
44
- if (size)
45
- style += `width:${parseRect(size)};height:${parseRect(size)};`;
46
- if (color)
47
- style += `color:${color};`;
48
- if (style)
49
- open.attrSet('style', style);
50
- const text = state.push('text', '', 0);
51
- text.content = className ? '' : iconName;
52
- const close = state.push('iconify_close', 'span', -1);
53
- close.markup = endTag;
54
- state.pos = state.posMax + 2;
55
- state.posMax = max;
56
- return true;
57
- };
58
- }
59
- export const iconsPlugin = (md, addIcon = () => '') => {
60
- md.inline.ruler.before('emphasis', 'iconify', createTokenizer(addIcon));
61
- };
@@ -1,11 +0,0 @@
1
- import type { App } from 'vuepress/core';
2
- import type { IconsOptions } from '../../../shared/icons.js';
3
- export interface IconCacheItem {
4
- className: string;
5
- content: string;
6
- }
7
- export declare function createIconCSSWriter(app: App, opt?: boolean | IconsOptions): {
8
- addIcon: (iconName: string) => string | undefined;
9
- writeCss: () => Promise<void>;
10
- initIcon: () => Promise<void>;
11
- };
@@ -1,126 +0,0 @@
1
- import { constants, promises as fsp } from 'node:fs';
2
- import { getIconContentCSS, getIconData } from '@iconify/utils';
3
- import { fs, logger } from 'vuepress/utils';
4
- import { isPackageExists } from 'local-pkg';
5
- import { customAlphabet } from 'nanoid';
6
- import { interopDefault } from '../../utils/package.js';
7
- import { parseRect } from '../../utils/parseRect.js';
8
- const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 8);
9
- const iconDataCache = new Map();
10
- const URL_CONTENT_RE = /(url\([^]+?\))/;
11
- const CSS_PATH = 'internal/md-power/icons.css';
12
- function resolveOption(opt) {
13
- const options = typeof opt === 'object' ? opt : {};
14
- options.prefix ??= 'vp-mdi';
15
- options.color = options.color === 'currentColor' || !options.color ? 'currentcolor' : options.color;
16
- options.size = options.size ? parseRect(`${options.size}`) : '1em';
17
- return options;
18
- }
19
- export function createIconCSSWriter(app, opt) {
20
- const cache = new Map();
21
- const isInstalled = isPackageExists('@iconify/json');
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
- };
31
- let timer = null;
32
- const options = resolveOption(opt);
33
- const prefix = options.prefix;
34
- const defaultContent = getDefaultContent(options);
35
- async function writeCss() {
36
- if (timer)
37
- clearTimeout(timer);
38
- timer = setTimeout(async () => {
39
- let css = defaultContent;
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
- }
45
- }, 100);
46
- }
47
- function addIcon(iconName) {
48
- if (!isInstalled)
49
- return;
50
- if (cache.has(iconName))
51
- return cache.get(iconName).className;
52
- const item = {
53
- className: `${prefix}-${nanoid()}`,
54
- content: '',
55
- };
56
- cache.set(iconName, item);
57
- genIconContent(iconName, (content) => {
58
- item.content = content;
59
- writeCss();
60
- });
61
- return item.className;
62
- }
63
- async function initIcon() {
64
- if (!opt)
65
- return await write('');
66
- if (!isInstalled) {
67
- logger.error('[plugin-md-power]: `@iconify/json` not found! Please install `@iconify/json` first.');
68
- return;
69
- }
70
- return await writeCss();
71
- }
72
- return { addIcon, writeCss, initIcon };
73
- }
74
- function getDefaultContent(options) {
75
- const { prefix, size, color } = options;
76
- return `[class^="${prefix}-"],
77
- [class*=" ${prefix}-"] {
78
- display: inline-block;
79
- width: ${size};
80
- height: ${size};
81
- vertical-align: middle;
82
- color: inherit;
83
- background-color: ${color};
84
- -webkit-mask: var(--svg) no-repeat;
85
- mask: var(--svg) no-repeat;
86
- -webkit-mask-size: 100% 100%;
87
- mask-size: 100% 100%;
88
- }
89
- `;
90
- }
91
- let locate;
92
- async function genIconContent(iconName, cb) {
93
- if (!locate) {
94
- const mod = await interopDefault(import('@iconify/json'));
95
- locate = mod.locate;
96
- }
97
- const [collect, name] = iconName.split(':');
98
- let iconJson = iconDataCache.get(collect);
99
- if (!iconJson) {
100
- const filename = locate(collect);
101
- try {
102
- iconJson = JSON.parse(await fs.readFile(filename, 'utf-8'));
103
- iconDataCache.set(collect, iconJson);
104
- }
105
- catch {
106
- logger.warn(`[plugin-md-power] Can not find icon, ${collect} is missing!`);
107
- }
108
- }
109
- const data = getIconData(iconJson, name);
110
- if (!data)
111
- return logger.error(`[plugin-md-power] Can not read icon in ${collect}, ${name} is missing!`);
112
- const content = getIconContentCSS(data, {
113
- height: data.height || 24,
114
- });
115
- const match = content.match(URL_CONTENT_RE);
116
- return cb(match ? match[1] : '');
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
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * @[jsfiddle](user/id)
3
- * @[jsfiddle theme="dark" tab="js,css,html,result"](user/id)
4
- */
5
- import type { PluginWithOptions } from 'markdown-it';
6
- export declare const jsfiddlePlugin: PluginWithOptions<never>;