vuepress-plugin-md-power 1.0.0-rc.152 → 1.0.0-rc.154

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.
@@ -11,7 +11,7 @@ let container: HTMLPreElement | null = null
11
11
  let lineNumbers: HTMLDivElement | null = null
12
12
  const { grammars, theme } = editorData
13
13
 
14
- const lang = ref<'go' | 'rust' | 'kotlin'>()
14
+ const lang = ref<'go' | 'rust' | 'kotlin' | 'python'>()
15
15
 
16
16
  const editorEl = shallowRef<HTMLDivElement>()
17
17
  const textAreaEl = shallowRef<HTMLTextAreaElement>()
@@ -1,61 +1,46 @@
1
1
  <script setup lang="ts">
2
2
  import type { PlotOptions } from '../../shared/index.js'
3
3
  import { onClickOutside, useMediaQuery } from '@vueuse/core'
4
- import { computed, ref, shallowRef } from 'vue'
4
+ import { computed, onMounted, ref, useTemplateRef } from 'vue'
5
5
  import { usePageFrontmatter } from 'vuepress/client'
6
6
  import { pluginOptions } from '../options.js'
7
7
 
8
- const props = defineProps<Omit<PlotOptions, 'tag'>>()
8
+ const props = defineProps<PlotOptions>()
9
9
 
10
10
  const matter = usePageFrontmatter()
11
+ const isMobile = useMediaQuery('(max-width: 768px)')
11
12
 
12
- const options = computed(() => {
13
- const plot = typeof pluginOptions.plot === 'object' ? pluginOptions.plot : {}
14
-
13
+ const plot = computed(() => {
14
+ const global = typeof pluginOptions.plot === 'object' ? pluginOptions.plot : {}
15
+ const current = (typeof matter.value.plot === 'object' ? matter.value.plot : {}) as PlotOptions
15
16
  return {
16
- trigger: props.trigger || matter.value.plotTrigger || plot.trigger || 'hover',
17
- color: props.color || plot.color,
18
- mask: props.mask || plot.mask,
17
+ trigger: isMobile.value ? 'click' : props.trigger ?? current.trigger ?? global.trigger ?? 'hover',
18
+ effect: props.effect ?? current.effect ?? global.effect ?? 'mask',
19
19
  }
20
20
  })
21
+ const active = ref(false)
22
+ const el = useTemplateRef<HTMLElement>('el')
23
+ const classes = ref<string[]>([])
21
24
 
22
- const styles = computed(() => {
23
- const plot = options.value
24
- if (!plot.color && !plot.mask)
25
- return {}
26
- const style: Record<string, string> = {}
27
- if (plot.color) {
28
- if (typeof plot.color === 'string') {
29
- style['--vp-c-plot-light'] = plot.color
30
- }
31
- else {
32
- style['--vp-c-plot-light'] = plot.color.light
33
- style['--vp-c-plot-dark'] = plot.color.dark
34
- }
25
+ onMounted(() => {
26
+ if (!el.value)
27
+ return
28
+ const classList = el.value.classList
29
+ if (!classList.contains('hover') && !classList.contains('click')) {
30
+ classes.value.push(plot.value.trigger)
35
31
  }
36
- if (plot.mask) {
37
- if (typeof plot.mask === 'string') {
38
- style['--vp-c-bg-plot-light'] = plot.mask
39
- }
40
- else {
41
- style['--vp-c-bg-plot-light'] = plot.mask.light
42
- style['--vp-c-bg-plot-dark'] = plot.mask.dark
43
- }
32
+ if (!classList.contains('mask') && !classList.contains('blur')) {
33
+ classes.value.push(plot.value.effect)
44
34
  }
45
- return style
46
35
  })
47
36
 
48
- const isMobile = useMediaQuery('(max-width: 768px)')
49
- const active = ref(false)
50
- const el = shallowRef<HTMLElement>()
51
-
52
37
  onClickOutside(el, () => {
53
- if (options.value.trigger === 'click' || isMobile.value)
38
+ if (plot.value.trigger === 'click' || el.value?.classList.contains('click'))
54
39
  active.value = false
55
40
  })
56
41
 
57
42
  function onClick() {
58
- if (props.trigger === 'click' || isMobile.value)
43
+ if (plot.value.trigger === 'click' || el.value?.classList.contains('click'))
59
44
  active.value = !active.value
60
45
  }
61
46
  </script>
@@ -64,8 +49,7 @@ function onClick() {
64
49
  <span
65
50
  ref="el"
66
51
  class="vp-plot"
67
- :class="{ hover: options.trigger !== 'click', active }"
68
- :style="styles"
52
+ :class="[{ active }, ...classes]"
69
53
  @click="onClick"
70
54
  >
71
55
  <slot />
@@ -73,25 +57,39 @@ function onClick() {
73
57
  </template>
74
58
 
75
59
  <style>
60
+ :root {
61
+ --vp-plot-bg: var(--vp-c-text-1);
62
+ --vp-plot-c-text: var(--vp-c-neutral-inverse);
63
+ --vp-plot-blur: 0.2rem;
64
+ }
65
+
76
66
  .vp-plot {
77
67
  padding-right: 2px;
78
68
  padding-left: 2px;
79
- color: transparent;
80
- background-color: var(--vp-c-bg-plot-light, #000);
81
- transition: color ease 0.25s, background-color ease 0.25s;
82
69
  }
83
70
 
84
- [data-theme="dark"] .vp-plot {
85
- background-color: var(--vp-c-bg-plot-dark, #fff);
71
+ .vp-plot.click {
72
+ cursor: pointer;
73
+ }
74
+
75
+ .vp-plot:where(.blur) {
76
+ filter: blur(var(--vp-plot-blur));
77
+ transition: filter var(--vp-t-color);
78
+ }
79
+
80
+ .vp-plot:where(.mask) {
81
+ color: transparent;
82
+ background-color: var(--vp-plot-bg);
83
+ transition: color var(--vp-t-color), background-color var(--vp-t-color);
86
84
  }
87
85
 
88
- .vp-plot.hover:hover,
89
- .vp-plot.active {
90
- color: var(--vp-c-plot-light, #fff);
86
+ .vp-plot:where(.blur.hover):hover,
87
+ .vp-plot:where(.blur).active {
88
+ filter: blur(0);
91
89
  }
92
90
 
93
- [data-theme="dark"] .vp-plot.hover:hover,
94
- [data-theme="dark"] .vp-plot.active {
95
- color: var(--vp-c-plot-dark, #000);
91
+ .vp-plot:where(.mask.hover):hover,
92
+ .vp-plot:where(.mask).active {
93
+ color: var(--vp-plot-c-text);
96
94
  }
97
95
  </style>
@@ -36,5 +36,6 @@ interface UseAudioPlayerResult {
36
36
  setVolume: (volume: number) => void;
37
37
  destroy: () => void;
38
38
  }
39
- declare function useAudioPlayer(source: MaybeRef<string>, options?: AudioPlayerOptions): UseAudioPlayerResult; //#endregion
39
+ declare function useAudioPlayer(source: MaybeRef<string>, options?: AudioPlayerOptions): UseAudioPlayerResult;
40
+ //#endregion
40
41
  export { AudioPlayerOptions, BufferedRange, useAudioPlayer };
@@ -1,7 +1,7 @@
1
1
  import { Ref } from "vue";
2
2
 
3
3
  //#region src/client/composables/codeRepl.d.ts
4
- type Lang = "kotlin" | "go" | "rust";
4
+ type Lang = "kotlin" | "go" | "rust" | "python";
5
5
  declare function resolveCode(el: HTMLElement): string;
6
6
  declare function resolveCodeInfo(el: HTMLDivElement): {
7
7
  lang: Lang;
@@ -20,6 +20,5 @@ interface UseCodeReplResult {
20
20
  onRunCode: () => Promise<void>;
21
21
  }
22
22
  declare function useCodeRepl(el: Ref<HTMLDivElement | null>): UseCodeReplResult;
23
-
24
23
  //#endregion
25
24
  export { resolveCode, resolveCodeInfo, useCodeRepl };
@@ -10,17 +10,21 @@ const api = {
10
10
  go: "https://api.pengzhanbo.cn/repl/golang/run",
11
11
  kotlin: "https://api.pengzhanbo.cn/repl/kotlin/run"
12
12
  };
13
+ let pyodide = null;
13
14
  const langAlias = {
14
15
  kt: "kotlin",
15
16
  kotlin: "kotlin",
16
17
  go: "go",
17
18
  rust: "rust",
18
- rs: "rust"
19
+ rs: "rust",
20
+ py: "python",
21
+ python: "python"
19
22
  };
20
23
  const supportLang = [
21
24
  "kotlin",
22
25
  "go",
23
- "rust"
26
+ "rust",
27
+ "python"
24
28
  ];
25
29
  function resolveLang(lang) {
26
30
  return lang ? langAlias[lang] || lang : "";
@@ -59,7 +63,8 @@ function useCodeRepl(el) {
59
63
  const executeMap = {
60
64
  kotlin: executeKotlin,
61
65
  go: executeGolang,
62
- rust: executeRust
66
+ rust: executeRust,
67
+ python: executePython
63
68
  };
64
69
  function onCleanRun() {
65
70
  loaded.value = false;
@@ -142,6 +147,24 @@ function useCodeRepl(el) {
142
147
  }
143
148
  });
144
149
  }
150
+ async function executePython(code) {
151
+ loaded.value = false;
152
+ finished.value = false;
153
+ if (pyodide === null) {
154
+ const { loadPyodide, version } = await import(
155
+ /* webpackChunkName: "pyodide" */
156
+ "pyodide");
157
+ pyodide = await loadPyodide({ indexURL: `https://cdn.jsdelivr.net/pyodide/v${version}/full/` });
158
+ }
159
+ pyodide.setStdout({ batched: (msg) => stdout.value.push(msg) });
160
+ try {
161
+ stdout.value.push(pyodide.runPython(code));
162
+ } catch (e) {
163
+ stderr.value.push(String(e));
164
+ }
165
+ loaded.value = true;
166
+ finished.value = true;
167
+ }
145
168
  return {
146
169
  onRunCode,
147
170
  onCleanRun,
@@ -36,6 +36,5 @@ declare function useNormalDemo(draw: ShallowRef<HTMLIFrameElement | null>, title
36
36
  height: Ref<string>;
37
37
  };
38
38
  declare function parseData(data: any): any;
39
-
40
39
  //#endregion
41
40
  export { DemoConfig, parseData, useExpand, useFence, useNormalDemo, useResources };
@@ -13,6 +13,5 @@ interface RustExecuteOptions {
13
13
  onEnd?: () => void;
14
14
  onError?: (message: string) => void;
15
15
  }
16
-
17
16
  //#endregion
18
17
  export { rustExecute };
@@ -11,6 +11,5 @@ interface SizeInfo<T extends HTMLElement> {
11
11
  resize: () => void;
12
12
  }
13
13
  declare function useSize<T extends HTMLElement>(options: ToRefs<SizeOptions>, extraHeight?: MaybeRef$1<number>): SizeInfo<T>;
14
-
15
14
  //#endregion
16
15
  export { SizeInfo, useSize };
@@ -9,5 +9,6 @@ declare const installed: {
9
9
  };
10
10
  declare const ART_PLAYER_SUPPORTED_VIDEO_TYPES: string[];
11
11
  declare const INJECT_TIMELINE_KEY: symbol;
12
- declare const INJECT_COLLAPSE_KEY: symbol; //#endregion
12
+ declare const INJECT_COLLAPSE_KEY: symbol;
13
+ //#endregion
13
14
  export { ART_PLAYER_SUPPORTED_VIDEO_TYPES, INJECT_COLLAPSE_KEY, INJECT_TIMELINE_KEY, installed, pluginOptions };
@@ -3,6 +3,5 @@ declare const http: {
3
3
  get: <T extends object = object, R = any>(url: string, query?: T) => Promise<R>;
4
4
  post: <T extends object = object, R = any>(url: string, data?: T) => Promise<R>;
5
5
  };
6
-
7
6
  //#endregion
8
7
  export { http };
@@ -1,5 +1,4 @@
1
1
  //#region src/client/utils/link.d.ts
2
2
  declare function normalizeLink(url: string): string;
3
-
4
3
  //#endregion
5
4
  export { normalizeLink };
@@ -1,5 +1,4 @@
1
1
  //#region src/client/utils/sleep.d.ts
2
2
  declare function sleep(ms: number): Promise<void>;
3
-
4
3
  //#endregion
5
4
  export { sleep };
@@ -23,14 +23,14 @@ interface CanIUseOptions {
23
23
  * @default 'embed'
24
24
  */
25
25
  mode?: CanIUseMode;
26
- } //#endregion
26
+ }
27
+ //#endregion
27
28
  //#region src/shared/size.d.ts
28
29
  interface SizeOptions {
29
30
  width?: string;
30
31
  height?: string;
31
32
  ratio?: number | string;
32
33
  }
33
-
34
34
  //#endregion
35
35
  //#region src/shared/codepen.d.ts
36
36
  interface CodepenTokenMeta extends SizeOptions {
@@ -42,7 +42,6 @@ interface CodepenTokenMeta extends SizeOptions {
42
42
  preview?: boolean;
43
43
  editable?: boolean;
44
44
  }
45
-
46
45
  //#endregion
47
46
  //#region src/shared/codeSandbox.d.ts
48
47
  interface CodeSandboxTokenMeta extends SizeOptions {
@@ -55,7 +54,6 @@ interface CodeSandboxTokenMeta extends SizeOptions {
55
54
  navbar?: boolean;
56
55
  console?: boolean;
57
56
  }
58
-
59
57
  //#endregion
60
58
  //#region src/shared/codeTabs.d.ts
61
59
  interface CodeTabsOptions {
@@ -64,7 +62,6 @@ interface CodeTabsOptions {
64
62
  extensions?: false | string[];
65
63
  };
66
64
  }
67
-
68
65
  //#endregion
69
66
  //#region src/shared/demo.d.ts
70
67
  interface DemoFile {
@@ -89,14 +86,12 @@ interface DemoContainerRender {
89
86
  after: () => string;
90
87
  token?: (token: Token, tokens: Token[], index: number) => void;
91
88
  }
92
-
93
89
  //#endregion
94
90
  //#region src/shared/fileTree.d.ts
95
91
  type FileTreeIconMode = "simple" | "colored";
96
92
  interface FileTreeOptions {
97
93
  icon?: FileTreeIconMode;
98
94
  }
99
-
100
95
  //#endregion
101
96
  //#region src/shared/icon.d.ts
102
97
  type IconOptions = IconifyProvider | IconFontProvider | FontAwesomeProvider;
@@ -159,7 +154,6 @@ type IconifyPrefix = "material-symbols" | "material-symbols-light" | "ic" | "mdi
159
154
  type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
160
155
  zz_IGNORE_ME?: never;
161
156
  });
162
-
163
157
  //#endregion
164
158
  //#region src/shared/jsfiddle.d.ts
165
159
  interface JSFiddleTokenMeta extends SizeOptions {
@@ -168,14 +162,12 @@ interface JSFiddleTokenMeta extends SizeOptions {
168
162
  theme?: string;
169
163
  tab?: string;
170
164
  }
171
-
172
165
  //#endregion
173
166
  //#region src/shared/npmTo.d.ts
174
167
  type NpmToPackageManager = "npm" | "pnpm" | "yarn" | "bun" | "deno";
175
168
  type NpmToOptions = NpmToPackageManager[] | {
176
169
  tabs?: NpmToPackageManager[];
177
170
  };
178
-
179
171
  //#endregion
180
172
  //#region src/shared/pdf.d.ts
181
173
  type PDFEmbedType = "iframe" | "embed" | "pdfjs";
@@ -192,44 +184,31 @@ interface PDFOptions {
192
184
  */
193
185
  pdfjsUrl?: string;
194
186
  }
195
-
196
187
  //#endregion
197
188
  //#region src/shared/plot.d.ts
189
+ /**
190
+ * 是否启用 `!! !!` markdown (该标记为非标准标记,脱离插件将不生效)
191
+ */
198
192
  interface PlotOptions {
199
- /**
200
- * 是否启用 `!! !!` markdown (该标记为非标准标记,脱离插件将不生效)
201
- * @default true
202
- */
203
- tag?: boolean;
204
- /**
205
- * 遮罩层颜色
206
- */
207
- mask?: string | {
208
- light: string;
209
- dark: string;
210
- };
211
- /**
212
- * 文本颜色
213
- */
214
- color?: string | {
215
- light: string;
216
- dark: string;
217
- };
218
193
  /**
219
194
  * 触发方式
220
195
  *
221
196
  * @default 'hover'
222
197
  */
223
198
  trigger?: "hover" | "click";
199
+ /**
200
+ * 遮罩层效果
201
+ *
202
+ * @default 'mask'
203
+ */
204
+ effect?: "mask" | "blur";
224
205
  }
225
-
226
206
  //#endregion
227
207
  //#region src/shared/codeTree.d.ts
228
208
  interface CodeTreeOptions {
229
209
  icon?: FileTreeIconMode;
230
210
  height?: string | number;
231
211
  }
232
-
233
212
  //#endregion
234
213
  //#region src/shared/repl.d.ts
235
214
  type ThemeOptions = BuiltinTheme | {
@@ -241,19 +220,20 @@ interface ReplOptions {
241
220
  go?: boolean;
242
221
  kotlin?: boolean;
243
222
  rust?: boolean;
223
+ python?: boolean;
244
224
  }
245
225
  interface ReplEditorData {
246
226
  grammars: {
247
227
  go?: any;
248
228
  kotlin?: any;
249
229
  rust?: any;
230
+ python?: any;
250
231
  };
251
232
  theme: ThemeRegistration | {
252
233
  light: ThemeRegistration;
253
234
  dark: ThemeRegistration;
254
235
  };
255
236
  }
256
-
257
237
  //#endregion
258
238
  //#region src/shared/plugin.d.ts
259
239
  interface MarkdownPowerPluginOptions {
@@ -482,14 +462,14 @@ interface MarkdownPowerPluginOptions {
482
462
  * @default false
483
463
  */
484
464
  imageSize?: boolean | "local" | "all";
485
- } //#endregion
465
+ }
466
+ //#endregion
486
467
  //#region src/shared/replit.d.ts
487
468
  interface ReplitTokenMeta extends SizeOptions {
488
469
  title?: string;
489
470
  source?: string;
490
471
  theme?: string;
491
472
  }
492
-
493
473
  //#endregion
494
474
  //#region src/shared/video.d.ts
495
475
  interface VideoOptions {
@@ -523,11 +503,9 @@ interface ArtPlayerTokenMeta extends SizeOptions {
523
503
  url: string;
524
504
  type?: string;
525
505
  }
526
-
527
506
  //#endregion
528
507
  //#region src/node/container/codeTabs.d.ts
529
508
  declare function createCodeTabIconGetter(options?: CodeTabsOptions): (filename: string) => string | void;
530
-
531
509
  //#endregion
532
510
  //#region src/node/enhance/imageSize.d.ts
533
511
  interface ImgSize {
@@ -535,10 +513,8 @@ interface ImgSize {
535
513
  height: number;
536
514
  }
537
515
  declare function resolveImageSize(app: App, url: string, remote?: boolean): Promise<ImgSize>;
538
-
539
516
  //#endregion
540
517
  //#region src/node/plugin.d.ts
541
518
  declare function markdownPowerPlugin(options?: MarkdownPowerPluginOptions): Plugin;
542
-
543
519
  //#endregion
544
520
  export { ArtPlayerTokenMeta, BilibiliTokenMeta, CanIUseMode, CanIUseOptions, CanIUseTokenMeta, CodeSandboxTokenMeta, CodeTabsOptions, CodepenTokenMeta, DemoContainerRender, DemoFile, DemoMeta, FileTreeIconMode, FileTreeOptions, FontAwesomeAssetBuiltIn, FontAwesomePrefix, FontAwesomeProvider, IconAssetLink, IconFontProvider, IconOptions, IconProviderBase, IconifyPrefix, IconifyProvider, JSFiddleTokenMeta, LiteralUnion, MarkdownDemoEnv, MarkdownPowerPluginOptions, NpmToOptions, NpmToPackageManager, PDFEmbedType, PDFOptions, PDFTokenMeta, PlotOptions, ReplEditorData, ReplOptions, ReplitTokenMeta, SizeOptions, ThemeOptions, VideoOptions, YoutubeTokenMeta, createCodeTabIconGetter, markdownPowerPlugin, resolveImageSize };