vuepress-plugin-md-power 1.0.0-rc.183 → 1.0.0-rc.184
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.
- package/lib/client/components/CanIUse.vue +11 -11
- package/lib/client/composables/codeRepl.js +1 -1
- package/lib/client/composables/rustRepl.js +102 -1
- package/lib/node/index.d.ts +2 -1
- package/lib/node/index.js +15 -9
- package/lib/shared/index.d.ts +2 -1
- package/package.json +8 -8
- package/lib/client/composables/rustRepl-DzeWGqns.js +0 -104
|
@@ -12,20 +12,21 @@ interface MessageData {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
const { feature, past = 2, future = 1, meta = '' } = defineProps<{
|
|
15
|
+
const { feature, past = 2, future = 1, meta = '', baseline = false } = defineProps<{
|
|
16
16
|
feature: string
|
|
17
17
|
past?: number
|
|
18
18
|
future?: number
|
|
19
19
|
meta?: string
|
|
20
|
+
baseline?: boolean
|
|
20
21
|
}>()
|
|
21
22
|
|
|
22
23
|
const url = 'https://caniuse.pengzhanbo.cn/'
|
|
23
24
|
|
|
24
|
-
const height = ref('
|
|
25
|
+
const height = ref(baseline ? '150px' : '350px')
|
|
25
26
|
|
|
26
27
|
const isDark = useDarkMode()
|
|
27
28
|
const source = computed(() => {
|
|
28
|
-
const source = `${url}${feature}#past=${past}&future=${future}
|
|
29
|
+
const source = `${url}${feature}${baseline ? '/baseline#' : `#past=${past}&future=${future}&`}meta=${meta}&theme=${isDark.value ? 'dark' : 'light'}`
|
|
29
30
|
|
|
30
31
|
return source
|
|
31
32
|
})
|
|
@@ -34,7 +35,7 @@ useEventListener('message', (event) => {
|
|
|
34
35
|
const data = parseData(event.data)
|
|
35
36
|
const { type, payload } = data
|
|
36
37
|
if (
|
|
37
|
-
type === '
|
|
38
|
+
type === 'ciu-embed'
|
|
38
39
|
&& payload
|
|
39
40
|
&& payload.feature === feature
|
|
40
41
|
&& payload.meta === meta
|
|
@@ -57,13 +58,7 @@ function parseData(data: string | MessageData): MessageData {
|
|
|
57
58
|
</script>
|
|
58
59
|
|
|
59
60
|
<template>
|
|
60
|
-
<div
|
|
61
|
-
class="ciu_embed"
|
|
62
|
-
:data-feature="feature"
|
|
63
|
-
:data-meta="meta"
|
|
64
|
-
:data-past="past"
|
|
65
|
-
:data-future="future"
|
|
66
|
-
>
|
|
61
|
+
<div class="ciu_embed" :class="{ baseline }">
|
|
67
62
|
<iframe :src="source" :style="{ height }" :title="`Can I use ${feature}`" />
|
|
68
63
|
</div>
|
|
69
64
|
</template>
|
|
@@ -73,6 +68,11 @@ function parseData(data: string | MessageData): MessageData {
|
|
|
73
68
|
margin: 16px -24px;
|
|
74
69
|
}
|
|
75
70
|
|
|
71
|
+
.ciu_embed.baseline {
|
|
72
|
+
overflow: hidden;
|
|
73
|
+
border-radius: 8px;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
76
|
.ciu_embed iframe {
|
|
77
77
|
width: 100%;
|
|
78
78
|
border: none;
|
|
@@ -1,3 +1,104 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tryOnScopeDispose } from "@vueuse/core";
|
|
2
2
|
|
|
3
|
+
//#region src/client/composables/rustRepl.ts
|
|
4
|
+
/**
|
|
5
|
+
* 相比于 golang 和 kotlin 可以比较简单的实现,
|
|
6
|
+
* rust 需要通过 websocket 建立连接在实现交互,因此,将其进行一些包装,
|
|
7
|
+
* 方便在 codeRepl 中使用
|
|
8
|
+
*/
|
|
9
|
+
const wsUrl = "wss://play.rust-lang.org/websocket";
|
|
10
|
+
const payloadType = {
|
|
11
|
+
connected: "websocket/connected",
|
|
12
|
+
request: "output/execute/wsExecuteRequest",
|
|
13
|
+
execute: {
|
|
14
|
+
begin: "output/execute/wsExecuteBegin",
|
|
15
|
+
stderr: "output/execute/wsExecuteStderr",
|
|
16
|
+
stdout: "output/execute/wsExecuteStdout",
|
|
17
|
+
end: "output/execute/wsExecuteEnd"
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
let ws = null;
|
|
21
|
+
let isOpen = false;
|
|
22
|
+
let uuid = 0;
|
|
23
|
+
function connect() {
|
|
24
|
+
if (isOpen) return Promise.resolve();
|
|
25
|
+
ws = new WebSocket(wsUrl);
|
|
26
|
+
uuid = 0;
|
|
27
|
+
ws.addEventListener("open", () => {
|
|
28
|
+
isOpen = true;
|
|
29
|
+
send(payloadType.connected, { iAcceptThisIsAnUnsupportedApi: true }, {
|
|
30
|
+
websocket: true,
|
|
31
|
+
sequenceNumber: uuid
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
ws.addEventListener("close", () => {
|
|
35
|
+
isOpen = false;
|
|
36
|
+
ws = null;
|
|
37
|
+
});
|
|
38
|
+
tryOnScopeDispose(() => ws?.close());
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
function connected(e) {
|
|
41
|
+
if (JSON.parse(e.data).type === payloadType.connected) {
|
|
42
|
+
ws?.removeEventListener("message", connected);
|
|
43
|
+
resolve();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
ws?.addEventListener("message", connected);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function send(type, payload, meta) {
|
|
50
|
+
const msg = {
|
|
51
|
+
type,
|
|
52
|
+
meta,
|
|
53
|
+
payload
|
|
54
|
+
};
|
|
55
|
+
ws?.send(JSON.stringify(msg));
|
|
56
|
+
}
|
|
57
|
+
async function rustExecute(code, { onEnd, onError, onStderr, onStdout, onBegin }) {
|
|
58
|
+
await connect();
|
|
59
|
+
const meta = { sequenceNumber: uuid++ };
|
|
60
|
+
const payload = {
|
|
61
|
+
backtrace: false,
|
|
62
|
+
channel: "stable",
|
|
63
|
+
crateType: "bin",
|
|
64
|
+
edition: "2021",
|
|
65
|
+
mode: "release",
|
|
66
|
+
tests: false,
|
|
67
|
+
code
|
|
68
|
+
};
|
|
69
|
+
send(payloadType.request, payload, meta);
|
|
70
|
+
let stdout = "";
|
|
71
|
+
let stderr = "";
|
|
72
|
+
function onMessage(e) {
|
|
73
|
+
const { type, payload: payload$1, meta: _meta = {} } = JSON.parse(e.data);
|
|
74
|
+
if (_meta.sequenceNumber !== meta.sequenceNumber) return;
|
|
75
|
+
if (type === payloadType.execute.begin) onBegin?.();
|
|
76
|
+
if (type === payloadType.execute.stdout) {
|
|
77
|
+
stdout += payload$1;
|
|
78
|
+
if (stdout.endsWith("\n")) {
|
|
79
|
+
onStdout?.(stdout);
|
|
80
|
+
stdout = "";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (type === payloadType.execute.stderr) {
|
|
84
|
+
stderr += payload$1;
|
|
85
|
+
if (stderr.endsWith("\n")) {
|
|
86
|
+
if (stderr.startsWith("error:")) {
|
|
87
|
+
const index = stderr.indexOf("\n");
|
|
88
|
+
onStderr?.(stderr.slice(0, index));
|
|
89
|
+
onStderr?.(stderr.slice(index + 1));
|
|
90
|
+
} else onStderr?.(stderr);
|
|
91
|
+
stderr = "";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (type === payloadType.execute.end) {
|
|
95
|
+
if (payload$1.success === false) onError?.(payload$1.exitDetail);
|
|
96
|
+
ws?.removeEventListener("message", onMessage);
|
|
97
|
+
onEnd?.();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
ws?.addEventListener("message", onMessage);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
3
104
|
export { rustExecute };
|
package/lib/node/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import "markdown-it";
|
|
|
6
6
|
import { Plugin } from "vuepress/core";
|
|
7
7
|
|
|
8
8
|
//#region src/shared/caniuse.d.ts
|
|
9
|
-
type CanIUseMode = 'embed' | '
|
|
9
|
+
type CanIUseMode = 'embed' | 'baseline'
|
|
10
|
+
/** @deprecated */ | 'image';
|
|
10
11
|
interface CanIUseTokenMeta {
|
|
11
12
|
feature: string;
|
|
12
13
|
mode: CanIUseMode;
|
package/lib/node/index.js
CHANGED
|
@@ -3311,13 +3311,13 @@ const UNDERLINE_RE = /_+/g;
|
|
|
3311
3311
|
const caniusePlugin = (md, { mode: defaultMode = "embed" } = {}) => {
|
|
3312
3312
|
createEmbedRuleBlock(md, {
|
|
3313
3313
|
type: "caniuse",
|
|
3314
|
-
syntaxPattern: /^@\[caniuse\s*(embed|image)?(?:\{([0-9,\-]*)\})?\]\(([^)]*)\)/,
|
|
3314
|
+
syntaxPattern: /^@\[caniuse\s*(embed|image|baseline)?(?:\{([0-9,\-]*)\})?\]\(([^)]*)\)/,
|
|
3315
3315
|
meta: ([, mode, versions = "", feature]) => ({
|
|
3316
3316
|
feature,
|
|
3317
3317
|
mode: mode || defaultMode,
|
|
3318
3318
|
versions
|
|
3319
3319
|
}),
|
|
3320
|
-
content: (meta) => resolveCanIUse(meta)
|
|
3320
|
+
content: (meta, _c, env) => resolveCanIUse(meta, env)
|
|
3321
3321
|
});
|
|
3322
3322
|
};
|
|
3323
3323
|
/**
|
|
@@ -3331,32 +3331,37 @@ const caniusePlugin = (md, { mode: defaultMode = "embed" } = {}) => {
|
|
|
3331
3331
|
* ```
|
|
3332
3332
|
*/
|
|
3333
3333
|
function legacyCaniuse(md, { mode = "embed" } = {}) {
|
|
3334
|
-
const modeMap = [
|
|
3334
|
+
const modeMap = [
|
|
3335
|
+
"image",
|
|
3336
|
+
"embed",
|
|
3337
|
+
"baseline"
|
|
3338
|
+
];
|
|
3335
3339
|
const isMode = (mode$1) => modeMap.includes(mode$1);
|
|
3336
3340
|
mode = isMode(mode) ? mode : modeMap[0];
|
|
3337
3341
|
createContainerPlugin(md, "caniuse", {
|
|
3338
|
-
before: (info) => {
|
|
3342
|
+
before: (info, _t, _i, _o, env) => {
|
|
3339
3343
|
const feature = info.split(/\s+/)[0];
|
|
3340
3344
|
const versions = info.match(/\{(.*)\}/)?.[1] || "";
|
|
3341
3345
|
return feature ? resolveCanIUse({
|
|
3342
3346
|
feature,
|
|
3343
3347
|
mode,
|
|
3344
3348
|
versions
|
|
3345
|
-
}) : "";
|
|
3349
|
+
}, env) : "";
|
|
3346
3350
|
},
|
|
3347
3351
|
after: () => ""
|
|
3348
3352
|
});
|
|
3349
3353
|
}
|
|
3350
|
-
function resolveCanIUse({ feature, mode, versions }) {
|
|
3354
|
+
function resolveCanIUse({ feature, mode, versions }, env) {
|
|
3351
3355
|
if (!feature) return "";
|
|
3352
3356
|
if (mode === "image") {
|
|
3357
|
+
logger$1.warn(`[caniuse] image mode is deprecated, use ${colors.cyan(`@[caniuse](${feature})`)} instead. (${colors.gray(env.filePathRelative || "")})`);
|
|
3353
3358
|
const link = "https://caniuse.bitsofco.de/image/";
|
|
3354
3359
|
const alt = `Data on support for the ${feature} feature across the major browsers from caniuse.com`;
|
|
3355
|
-
return `<
|
|
3360
|
+
return `<p><picture>
|
|
3356
3361
|
<source type="image/webp" srcset="${link}${feature}.webp">
|
|
3357
3362
|
<source type="image/png" srcset="${link}${feature}.png">
|
|
3358
3363
|
<img src="${link}${feature}.jpg" alt="${alt}" width="100%">
|
|
3359
|
-
</picture></p
|
|
3364
|
+
</picture></p>`;
|
|
3360
3365
|
}
|
|
3361
3366
|
feature = feature.replace(UNDERLINE_RE, "_");
|
|
3362
3367
|
const { past, future } = resolveVersions(versions);
|
|
@@ -3365,7 +3370,8 @@ function resolveCanIUse({ feature, mode, versions }) {
|
|
|
3365
3370
|
feature,
|
|
3366
3371
|
meta,
|
|
3367
3372
|
past,
|
|
3368
|
-
future
|
|
3373
|
+
future,
|
|
3374
|
+
baseline: mode === "baseline"
|
|
3369
3375
|
})} />`;
|
|
3370
3376
|
}
|
|
3371
3377
|
function resolveVersions(versions) {
|
package/lib/shared/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { Markdown, MarkdownEnv } from "vuepress/markdown";
|
|
|
4
4
|
import { BuiltinTheme, ThemeRegistration } from "shiki";
|
|
5
5
|
|
|
6
6
|
//#region src/shared/caniuse.d.ts
|
|
7
|
-
type CanIUseMode = 'embed' | '
|
|
7
|
+
type CanIUseMode = 'embed' | 'baseline'
|
|
8
|
+
/** @deprecated */ | 'image';
|
|
8
9
|
interface CanIUseTokenMeta {
|
|
9
10
|
feature: string;
|
|
10
11
|
mode: CanIUseMode;
|
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.
|
|
4
|
+
"version": "1.0.0-rc.184",
|
|
5
5
|
"description": "The Plugin for VuePress 2 - markdown power",
|
|
6
6
|
"author": "pengzhanbo <volodymyr@foxmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -32,15 +32,15 @@
|
|
|
32
32
|
],
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"artplayer": "^5.3.0",
|
|
35
|
-
"dashjs": "^5.1.
|
|
36
|
-
"esbuild": "^0.27.
|
|
35
|
+
"dashjs": "^5.1.1",
|
|
36
|
+
"esbuild": "^0.27.2",
|
|
37
37
|
"hls.js": "^1.6.15",
|
|
38
|
-
"less": "^4.
|
|
38
|
+
"less": "^4.5.1",
|
|
39
39
|
"markdown-it": "^14.1.0",
|
|
40
40
|
"mpegts.js": "^1.7.3",
|
|
41
41
|
"pyodide": "^0.29.0",
|
|
42
|
-
"sass": "^1.
|
|
43
|
-
"sass-embedded": "^1.
|
|
42
|
+
"sass": "^1.97.1",
|
|
43
|
+
"sass-embedded": "^1.97.1",
|
|
44
44
|
"stylus": "^0.64.0",
|
|
45
45
|
"vuepress": "2.0.0-rc.26"
|
|
46
46
|
},
|
|
@@ -98,12 +98,12 @@
|
|
|
98
98
|
"shiki": "^3.20.0",
|
|
99
99
|
"tm-grammars": "^1.26.0",
|
|
100
100
|
"tm-themes": "^1.10.13",
|
|
101
|
-
"vue": "^3.5.
|
|
101
|
+
"vue": "^3.5.26"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
104
|
"@types/markdown-it": "^14.1.2",
|
|
105
105
|
"artplayer": "^5.3.0",
|
|
106
|
-
"dashjs": "^5.1.
|
|
106
|
+
"dashjs": "^5.1.1",
|
|
107
107
|
"hls.js": "^1.6.15",
|
|
108
108
|
"mpegts.js": "1.7.3"
|
|
109
109
|
},
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { tryOnScopeDispose } from "@vueuse/core";
|
|
2
|
-
|
|
3
|
-
//#region src/client/composables/rustRepl.ts
|
|
4
|
-
/**
|
|
5
|
-
* 相比于 golang 和 kotlin 可以比较简单的实现,
|
|
6
|
-
* rust 需要通过 websocket 建立连接在实现交互,因此,将其进行一些包装,
|
|
7
|
-
* 方便在 codeRepl 中使用
|
|
8
|
-
*/
|
|
9
|
-
const wsUrl = "wss://play.rust-lang.org/websocket";
|
|
10
|
-
const payloadType = {
|
|
11
|
-
connected: "websocket/connected",
|
|
12
|
-
request: "output/execute/wsExecuteRequest",
|
|
13
|
-
execute: {
|
|
14
|
-
begin: "output/execute/wsExecuteBegin",
|
|
15
|
-
stderr: "output/execute/wsExecuteStderr",
|
|
16
|
-
stdout: "output/execute/wsExecuteStdout",
|
|
17
|
-
end: "output/execute/wsExecuteEnd"
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
let ws = null;
|
|
21
|
-
let isOpen = false;
|
|
22
|
-
let uuid = 0;
|
|
23
|
-
function connect() {
|
|
24
|
-
if (isOpen) return Promise.resolve();
|
|
25
|
-
ws = new WebSocket(wsUrl);
|
|
26
|
-
uuid = 0;
|
|
27
|
-
ws.addEventListener("open", () => {
|
|
28
|
-
isOpen = true;
|
|
29
|
-
send(payloadType.connected, { iAcceptThisIsAnUnsupportedApi: true }, {
|
|
30
|
-
websocket: true,
|
|
31
|
-
sequenceNumber: uuid
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
ws.addEventListener("close", () => {
|
|
35
|
-
isOpen = false;
|
|
36
|
-
ws = null;
|
|
37
|
-
});
|
|
38
|
-
tryOnScopeDispose(() => ws?.close());
|
|
39
|
-
return new Promise((resolve) => {
|
|
40
|
-
function connected(e) {
|
|
41
|
-
if (JSON.parse(e.data).type === payloadType.connected) {
|
|
42
|
-
ws?.removeEventListener("message", connected);
|
|
43
|
-
resolve();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
ws?.addEventListener("message", connected);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
function send(type, payload, meta) {
|
|
50
|
-
const msg = {
|
|
51
|
-
type,
|
|
52
|
-
meta,
|
|
53
|
-
payload
|
|
54
|
-
};
|
|
55
|
-
ws?.send(JSON.stringify(msg));
|
|
56
|
-
}
|
|
57
|
-
async function rustExecute(code, { onEnd, onError, onStderr, onStdout, onBegin }) {
|
|
58
|
-
await connect();
|
|
59
|
-
const meta = { sequenceNumber: uuid++ };
|
|
60
|
-
const payload = {
|
|
61
|
-
backtrace: false,
|
|
62
|
-
channel: "stable",
|
|
63
|
-
crateType: "bin",
|
|
64
|
-
edition: "2021",
|
|
65
|
-
mode: "release",
|
|
66
|
-
tests: false,
|
|
67
|
-
code
|
|
68
|
-
};
|
|
69
|
-
send(payloadType.request, payload, meta);
|
|
70
|
-
let stdout = "";
|
|
71
|
-
let stderr = "";
|
|
72
|
-
function onMessage(e) {
|
|
73
|
-
const { type, payload: payload$1, meta: _meta = {} } = JSON.parse(e.data);
|
|
74
|
-
if (_meta.sequenceNumber !== meta.sequenceNumber) return;
|
|
75
|
-
if (type === payloadType.execute.begin) onBegin?.();
|
|
76
|
-
if (type === payloadType.execute.stdout) {
|
|
77
|
-
stdout += payload$1;
|
|
78
|
-
if (stdout.endsWith("\n")) {
|
|
79
|
-
onStdout?.(stdout);
|
|
80
|
-
stdout = "";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (type === payloadType.execute.stderr) {
|
|
84
|
-
stderr += payload$1;
|
|
85
|
-
if (stderr.endsWith("\n")) {
|
|
86
|
-
if (stderr.startsWith("error:")) {
|
|
87
|
-
const index = stderr.indexOf("\n");
|
|
88
|
-
onStderr?.(stderr.slice(0, index));
|
|
89
|
-
onStderr?.(stderr.slice(index + 1));
|
|
90
|
-
} else onStderr?.(stderr);
|
|
91
|
-
stderr = "";
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (type === payloadType.execute.end) {
|
|
95
|
-
if (payload$1.success === false) onError?.(payload$1.exitDetail);
|
|
96
|
-
ws?.removeEventListener("message", onMessage);
|
|
97
|
-
onEnd?.();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
ws?.addEventListener("message", onMessage);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
//#endregion
|
|
104
|
-
export { rustExecute as t };
|