vuepress-plugin-md-power 1.0.0-rc.100

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 (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +239 -0
  3. package/lib/client/components/Bilibili.vue +45 -0
  4. package/lib/client/components/CanIUse.vue +94 -0
  5. package/lib/client/components/CodeEditor.vue +146 -0
  6. package/lib/client/components/CodeRepl.vue +242 -0
  7. package/lib/client/components/CodeSandbox.vue +75 -0
  8. package/lib/client/components/FileTreeItem.vue +169 -0
  9. package/lib/client/components/IconClose.vue +8 -0
  10. package/lib/client/components/IconConsole.vue +8 -0
  11. package/lib/client/components/IconRun.vue +8 -0
  12. package/lib/client/components/Loading.vue +44 -0
  13. package/lib/client/components/PDFViewer.vue +39 -0
  14. package/lib/client/components/Plot.vue +97 -0
  15. package/lib/client/components/Replit.vue +58 -0
  16. package/lib/client/components/Youtube.vue +41 -0
  17. package/lib/client/composables/codeRepl.d.ts +22 -0
  18. package/lib/client/composables/codeRepl.js +266 -0
  19. package/lib/client/composables/pdf.d.ts +19 -0
  20. package/lib/client/composables/pdf.js +59 -0
  21. package/lib/client/composables/rustRepl.d.ts +10 -0
  22. package/lib/client/composables/rustRepl.js +104 -0
  23. package/lib/client/composables/size.d.ts +26 -0
  24. package/lib/client/composables/size.js +37 -0
  25. package/lib/client/index.d.ts +1 -0
  26. package/lib/client/index.js +2 -0
  27. package/lib/client/options.d.ts +5 -0
  28. package/lib/client/options.js +5 -0
  29. package/lib/client/shim.d.ts +7 -0
  30. package/lib/client/utils/http.d.ts +6 -0
  31. package/lib/client/utils/http.js +25 -0
  32. package/lib/client/utils/is.d.ts +5 -0
  33. package/lib/client/utils/is.js +19 -0
  34. package/lib/client/utils/link.d.ts +3 -0
  35. package/lib/client/utils/link.js +9 -0
  36. package/lib/client/utils/sleep.d.ts +3 -0
  37. package/lib/client/utils/sleep.js +9 -0
  38. package/lib/node/index.d.ts +287 -0
  39. package/lib/node/index.js +1688 -0
  40. package/lib/node/markdown-it-container.d.ts +6 -0
  41. package/lib/shared/index.d.ts +277 -0
  42. package/lib/shared/index.js +0 -0
  43. package/package.json +65 -0
@@ -0,0 +1,26 @@
1
+ import { MaybeRef } from '@vueuse/core';
2
+ import { ShallowRef, Ref, ToRefs } from 'vue';
3
+ import { SizeOptions } from '../../shared/index.js';
4
+
5
+ /**
6
+ * Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/composables/useSize.ts
7
+ *
8
+ * The MIT License (MIT)
9
+ * Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ */
17
+
18
+ interface SizeInfo<T extends HTMLElement> {
19
+ el: ShallowRef<T | undefined>;
20
+ width: Ref<string>;
21
+ height: Ref<string>;
22
+ resize: () => void;
23
+ }
24
+ declare function useSize<T extends HTMLElement>(options: ToRefs<SizeOptions>, extraHeight?: MaybeRef<number>): SizeInfo<T>;
25
+
26
+ export { type SizeInfo, useSize };
@@ -0,0 +1,37 @@
1
+ // src/client/composables/size.ts
2
+ import { useEventListener } from "@vueuse/core";
3
+ import { computed, isRef, onMounted, ref, shallowRef, toValue, watch } from "vue";
4
+ function useSize(options, extraHeight = 0) {
5
+ const el = shallowRef();
6
+ const width = computed(() => toValue(options.width) || "100%");
7
+ const height = ref("auto");
8
+ const getHeight = (width2) => {
9
+ const height2 = toValue(options.height);
10
+ const ratio = getRadio(toValue(options.ratio));
11
+ return height2 || `${Number(width2) / ratio + toValue(extraHeight)}px`;
12
+ };
13
+ const resize = () => {
14
+ if (el.value)
15
+ height.value = getHeight(el.value.offsetWidth);
16
+ };
17
+ onMounted(() => {
18
+ resize();
19
+ if (isRef(extraHeight))
20
+ watch(extraHeight, resize);
21
+ useEventListener("orientationchange", resize);
22
+ useEventListener("resize", resize);
23
+ });
24
+ return { el, width, height, resize };
25
+ }
26
+ function getRadio(ratio) {
27
+ if (typeof ratio === "string") {
28
+ const [width, height] = ratio.split(":");
29
+ const parsedRadio = Number(width) / Number(height);
30
+ if (!Number.isNaN(parsedRadio))
31
+ return parsedRadio;
32
+ }
33
+ return typeof ratio === "number" ? ratio : 16 / 9;
34
+ }
35
+ export {
36
+ useSize
37
+ };
@@ -0,0 +1 @@
1
+ export * from '../shared/index.js';
@@ -0,0 +1,2 @@
1
+ // src/client/index.ts
2
+ export * from "../shared/index.js";
@@ -0,0 +1,5 @@
1
+ import { MarkdownPowerPluginOptions } from '../shared/index.js';
2
+
3
+ declare const pluginOptions: MarkdownPowerPluginOptions;
4
+
5
+ export { pluginOptions };
@@ -0,0 +1,5 @@
1
+ // src/client/options.ts
2
+ var pluginOptions = __MD_POWER_INJECT_OPTIONS__;
3
+ export {
4
+ pluginOptions
5
+ };
@@ -0,0 +1,7 @@
1
+ import type { ReplEditorData } from '../shared/repl.js'
2
+
3
+ declare module '@internal/md-power/replEditorData' {
4
+
5
+ const res: ReplEditorData
6
+ export default res
7
+ }
@@ -0,0 +1,6 @@
1
+ declare const http: {
2
+ get: <T extends object = object, R = any>(url: string, query?: T) => Promise<R>;
3
+ post: <T extends object = object, R = any>(url: string, data?: T) => Promise<R>;
4
+ };
5
+
6
+ export { http };
@@ -0,0 +1,25 @@
1
+ // src/client/utils/http.ts
2
+ var http = {
3
+ get: async (url, query) => {
4
+ const _url = new URL(url);
5
+ if (query) {
6
+ for (const [key, value] of Object.entries(query))
7
+ _url.searchParams.append(key, value);
8
+ }
9
+ const res = await fetch(_url.toString());
10
+ return await res.json();
11
+ },
12
+ post: async (url, data) => {
13
+ const res = await fetch(url, {
14
+ method: "POST",
15
+ headers: {
16
+ "Content-Type": "application/json"
17
+ },
18
+ body: data ? JSON.stringify(data) : void 0
19
+ });
20
+ return await res.json();
21
+ }
22
+ };
23
+ export {
24
+ http
25
+ };
@@ -0,0 +1,5 @@
1
+ declare function checkIsMobile(ua: string): boolean;
2
+ declare function checkIsSafari(ua: string): boolean;
3
+ declare function checkIsiPad(ua: string): boolean;
4
+
5
+ export { checkIsMobile, checkIsSafari, checkIsiPad };
@@ -0,0 +1,19 @@
1
+ // src/client/utils/is.ts
2
+ function checkIsMobile(ua) {
3
+ return /\b(?:Android|iPhone)/i.test(ua);
4
+ }
5
+ function checkIsSafari(ua) {
6
+ return /version\/[\w.]+ .*(?:mobile ?safari|safari)/i.test(ua);
7
+ }
8
+ function checkIsiPad(ua) {
9
+ return [
10
+ /\((ipad);[-\w),; ]+apple/i,
11
+ /applecoremedia\/[\w.]+ \((ipad)/i,
12
+ /\b(ipad)\d\d?,\d\d?[;\]].+ios/i
13
+ ].some((item) => item.test(ua));
14
+ }
15
+ export {
16
+ checkIsMobile,
17
+ checkIsSafari,
18
+ checkIsiPad
19
+ };
@@ -0,0 +1,3 @@
1
+ declare function normalizeLink(url: string): string;
2
+
3
+ export { normalizeLink };
@@ -0,0 +1,9 @@
1
+ // src/client/utils/link.ts
2
+ import { withBase } from "vuepress/client";
3
+ import { isLinkHttp } from "vuepress/shared";
4
+ function normalizeLink(url) {
5
+ return isLinkHttp(url) ? url : withBase(url);
6
+ }
7
+ export {
8
+ normalizeLink
9
+ };
@@ -0,0 +1,3 @@
1
+ declare function sleep(ms: number): Promise<void>;
2
+
3
+ export { sleep };
@@ -0,0 +1,9 @@
1
+ // src/client/utils/sleep.ts
2
+ function sleep(ms) {
3
+ return new Promise((resolve) => {
4
+ setTimeout(resolve, ms);
5
+ });
6
+ }
7
+ export {
8
+ sleep
9
+ };
@@ -0,0 +1,287 @@
1
+ import { BuiltinTheme, ThemeRegistration } from 'shiki';
2
+ import { App } from 'vuepress';
3
+ import { Plugin } from 'vuepress/core';
4
+
5
+ type CanIUseMode = 'embed' | 'image';
6
+ interface CanIUseTokenMeta {
7
+ feature: string;
8
+ mode: CanIUseMode;
9
+ versions: string;
10
+ }
11
+ interface CanIUseOptions {
12
+ /**
13
+ * 嵌入模式
14
+ *
15
+ * embed 通过iframe嵌入,提供可交互视图
16
+ *
17
+ * image 通过图片嵌入,静态
18
+ *
19
+ * @default 'embed'
20
+ */
21
+ mode?: CanIUseMode;
22
+ }
23
+
24
+ interface SizeOptions {
25
+ width?: string;
26
+ height?: string;
27
+ ratio?: number | string;
28
+ }
29
+
30
+ interface CodepenTokenMeta extends SizeOptions {
31
+ title?: string;
32
+ user?: string;
33
+ slash?: string;
34
+ tab?: string;
35
+ theme?: string;
36
+ preview?: boolean;
37
+ editable?: boolean;
38
+ }
39
+
40
+ interface CodeSandboxTokenMeta extends SizeOptions {
41
+ user?: string;
42
+ id?: string;
43
+ layout?: string;
44
+ type?: 'button' | 'embed';
45
+ title?: string;
46
+ filepath?: string;
47
+ navbar?: boolean;
48
+ console?: boolean;
49
+ }
50
+
51
+ interface IconsOptions {
52
+ /**
53
+ * The prefix of the icon className
54
+ * @default 'vp-mdi'
55
+ */
56
+ prefix?: string;
57
+ /**
58
+ * The size of the icon
59
+ * @default '1em'
60
+ */
61
+ size?: string | number;
62
+ /**
63
+ * The color of the icon
64
+ * @default 'currentColor'
65
+ */
66
+ color?: string;
67
+ }
68
+
69
+ interface JSFiddleTokenMeta extends SizeOptions {
70
+ user?: string;
71
+ id?: string;
72
+ title?: string;
73
+ theme?: string;
74
+ tab?: string;
75
+ }
76
+
77
+ type PDFEmbedType = 'iframe' | 'embed' | 'pdfjs';
78
+ interface PDFTokenMeta extends SizeOptions {
79
+ page?: number;
80
+ noToolbar?: boolean;
81
+ zoom?: number;
82
+ src?: string;
83
+ title?: string;
84
+ }
85
+ interface PDFOptions {
86
+ /**
87
+ * pdfjs url
88
+ */
89
+ pdfjsUrl?: string;
90
+ }
91
+
92
+ interface PlotOptions {
93
+ /**
94
+ * 是否启用 `=| |=` markdown (该标记为非标准标记,脱离插件将不生效)
95
+ * @default true
96
+ */
97
+ tag?: boolean;
98
+ /**
99
+ * 遮罩层颜色
100
+ */
101
+ mask?: string | {
102
+ light: string;
103
+ dark: string;
104
+ };
105
+ /**
106
+ * 文本颜色
107
+ */
108
+ color?: string | {
109
+ light: string;
110
+ dark: string;
111
+ };
112
+ /**
113
+ * 触发方式
114
+ *
115
+ * @default 'hover'
116
+ */
117
+ trigger?: 'hover' | 'click';
118
+ }
119
+
120
+ type ThemeOptions = BuiltinTheme | {
121
+ light: BuiltinTheme;
122
+ dark: BuiltinTheme;
123
+ };
124
+ interface ReplOptions {
125
+ theme?: ThemeOptions;
126
+ go?: boolean;
127
+ kotlin?: boolean;
128
+ rust?: boolean;
129
+ }
130
+ interface ReplEditorData {
131
+ grammars: {
132
+ go?: any;
133
+ kotlin?: any;
134
+ rust?: any;
135
+ };
136
+ theme: ThemeRegistration | {
137
+ light: ThemeRegistration;
138
+ dark: ThemeRegistration;
139
+ };
140
+ }
141
+
142
+ interface MarkdownPowerPluginOptions {
143
+ /**
144
+ * 是否启用 PDF 嵌入语法
145
+ *
146
+ * `@[pdf](pdf_url)`
147
+ *
148
+ * @default false
149
+ */
150
+ pdf?: boolean | PDFOptions;
151
+ /**
152
+ * 是否启用 iconify 图标嵌入语法
153
+ *
154
+ * `:[collect:icon_name]:`
155
+ *
156
+ * @default false
157
+ */
158
+ icons?: boolean | IconsOptions;
159
+ /**
160
+ * 是否启用 隐秘文本 语法
161
+ *
162
+ * `!!plot_content!!`
163
+ *
164
+ * @default false
165
+ */
166
+ plot?: boolean | PlotOptions;
167
+ /**
168
+ * 是否启用 bilibili 视频嵌入
169
+ *
170
+ * `@[bilibili](bid)`
171
+ *
172
+ * @default false
173
+ */
174
+ bilibili?: boolean;
175
+ /**
176
+ * 是否启用 youtube 视频嵌入
177
+ *
178
+ * `@[youtube](video_id)`
179
+ *
180
+ * @default false
181
+ */
182
+ youtube?: boolean;
183
+ /**
184
+ * 是否启用 codepen 嵌入
185
+ *
186
+ * `@[codepen](pen_id)`
187
+ *
188
+ * @default false
189
+ */
190
+ codepen?: boolean;
191
+ /**
192
+ * @deprecated
193
+ */
194
+ replit?: boolean;
195
+ /**
196
+ * 是否启用 codeSandbox 嵌入
197
+ *
198
+ * `@[codesandbox](codesandbox_id)`
199
+ *
200
+ * @default false
201
+ */
202
+ codeSandbox?: boolean;
203
+ /**
204
+ * 是否启用 jsfiddle 嵌入
205
+ *
206
+ * `@[jsfiddle](jsfiddle_id)`
207
+ *
208
+ * @default false
209
+ */
210
+ jsfiddle?: boolean;
211
+ /**
212
+ * 是否启用 REPL 容器语法
213
+ *
214
+ * @default false
215
+ */
216
+ repl?: false | ReplOptions;
217
+ /**
218
+ * 是否启用 文件树 容器语法
219
+ *
220
+ * @default false
221
+ */
222
+ fileTree?: boolean;
223
+ /**
224
+ * 是否启用 caniuse 嵌入语法
225
+ *
226
+ * `@[caniuse](feature_name)`
227
+ *
228
+ * @default false
229
+ */
230
+ caniuse?: boolean | CanIUseOptions;
231
+ /**
232
+ * 是否启用 自动填充 图片宽高属性
233
+ *
234
+ * __请注意,无论是否启用,该功能仅在构建生产包时生效__
235
+ *
236
+ * - 如果为 `true` ,等同于 `'local'`
237
+ * - 如果为 `local`,则仅对本地图片 添加 width 和 height
238
+ * - 如果为 `all`,则对所有图片(即包括 本地 和 远程) 添加 width 和 height
239
+ *
240
+ * 图片在加载过程中如果比较慢,从加载到完成的过程会导致页面布局不稳定,导致内容闪烁等。
241
+ * 此功能通过给图片添加 `width` 和 `height` 属性来解决该问题。
242
+ *
243
+ * 请谨慎使用 `all` 选项,该选项会在构建阶段发起网络请求,尝试加载远程图片以获取图片尺寸信息,
244
+ * 这可能会导致 构建时间变得更长(幸运的是获取尺寸信息只需要加载图片 几 KB 的数据包,因此耗时不会过长)
245
+ *
246
+ * @default false
247
+ */
248
+ imageSize?: boolean | 'local' | 'all';
249
+ }
250
+
251
+ interface ReplitTokenMeta extends SizeOptions {
252
+ title?: string;
253
+ source?: string;
254
+ theme?: string;
255
+ }
256
+
257
+ interface VideoOptions {
258
+ bilibili?: boolean;
259
+ youtube?: boolean;
260
+ }
261
+ interface BilibiliTokenMeta extends SizeOptions {
262
+ title?: string;
263
+ bvid?: string;
264
+ aid?: string;
265
+ cid?: string;
266
+ autoplay?: boolean;
267
+ time?: string | number;
268
+ page?: number;
269
+ }
270
+ interface YoutubeTokenMeta extends SizeOptions {
271
+ title?: string;
272
+ id: string;
273
+ autoplay?: boolean;
274
+ loop?: boolean;
275
+ start?: string | number;
276
+ end?: string | number;
277
+ }
278
+
279
+ interface ImgSize {
280
+ width: number;
281
+ height: number;
282
+ }
283
+ declare function resolveImageSize(app: App, url: string, remote?: boolean): Promise<ImgSize>;
284
+
285
+ declare function markdownPowerPlugin(options?: MarkdownPowerPluginOptions): Plugin;
286
+
287
+ export { type BilibiliTokenMeta, type CanIUseMode, type CanIUseOptions, type CanIUseTokenMeta, type CodeSandboxTokenMeta, type CodepenTokenMeta, type IconsOptions, type JSFiddleTokenMeta, type MarkdownPowerPluginOptions, type PDFEmbedType, type PDFOptions, type PDFTokenMeta, type PlotOptions, type ReplEditorData, type ReplOptions, type ReplitTokenMeta, type SizeOptions, type ThemeOptions, type VideoOptions, type YoutubeTokenMeta, markdownPowerPlugin, resolveImageSize };