vuepress-plugin-md-power 1.0.0-rc.146 → 1.0.0-rc.148
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/VPCodeTree.vue +16 -0
- package/lib/client/composables/audio.d.ts +35 -35
- package/lib/client/composables/audio.js +169 -181
- package/lib/client/composables/codeRepl.d.ts +20 -17
- package/lib/client/composables/codeRepl.js +146 -252
- package/lib/client/composables/demo.d.ts +34 -41
- package/lib/client/composables/demo.js +108 -102
- package/lib/client/composables/pdf.d.ts +4 -15
- package/lib/client/composables/pdf.js +46 -51
- package/lib/client/composables/rustRepl-iGLjb94D.js +101 -0
- package/lib/client/composables/rustRepl.d.ts +15 -7
- package/lib/client/composables/rustRepl.js +3 -104
- package/lib/client/composables/size.d.ts +11 -21
- package/lib/client/composables/size.js +35 -32
- package/lib/client/index.d.ts +1 -1
- package/lib/client/index.js +1 -2
- package/lib/client/options.d.ts +8 -8
- package/lib/client/options.js +20 -29
- package/lib/client/utils/http.d.ts +5 -3
- package/lib/client/utils/http.js +19 -24
- package/lib/client/utils/link.d.ts +3 -1
- package/lib/client/utils/link.js +6 -5
- package/lib/client/utils/sleep.d.ts +3 -1
- package/lib/client/utils/sleep.js +7 -7
- package/lib/node/index.d.ts +405 -368
- package/lib/node/index.js +3777 -3779
- package/lib/shared/index.d.ts +395 -365
- package/package.json +10 -10
|
@@ -1,266 +1,160 @@
|
|
|
1
|
-
|
|
1
|
+
import { rustExecute } from "./rustRepl-iGLjb94D.js";
|
|
2
2
|
import { onMounted, ref } from "vue";
|
|
3
3
|
import { http } from "../utils/http.js";
|
|
4
4
|
import { sleep } from "../utils/sleep.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
execute: {
|
|
13
|
-
begin: "output/execute/wsExecuteBegin",
|
|
14
|
-
// status: 'output/execute/wsExecuteStatus',
|
|
15
|
-
stderr: "output/execute/wsExecuteStderr",
|
|
16
|
-
stdout: "output/execute/wsExecuteStdout",
|
|
17
|
-
end: "output/execute/wsExecuteEnd"
|
|
18
|
-
}
|
|
6
|
+
//#region src/client/composables/codeRepl.ts
|
|
7
|
+
const ignoredNodes = [".diff.remove", ".vp-copy-ignore"];
|
|
8
|
+
const RE_LANGUAGE = /language-(\w+)/;
|
|
9
|
+
const api = {
|
|
10
|
+
go: "https://api.pengzhanbo.cn/repl/golang/run",
|
|
11
|
+
kotlin: "https://api.pengzhanbo.cn/repl/kotlin/run"
|
|
19
12
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
ws = new WebSocket(wsUrl);
|
|
27
|
-
uuid = 0;
|
|
28
|
-
ws.addEventListener("open", () => {
|
|
29
|
-
isOpen = true;
|
|
30
|
-
send(
|
|
31
|
-
payloadType.connected,
|
|
32
|
-
{ iAcceptThisIsAnUnsupportedApi: true },
|
|
33
|
-
{ websocket: true, sequenceNumber: uuid }
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
ws.addEventListener("close", () => {
|
|
37
|
-
isOpen = false;
|
|
38
|
-
ws = null;
|
|
39
|
-
});
|
|
40
|
-
tryOnScopeDispose(() => ws?.close());
|
|
41
|
-
return new Promise((resolve) => {
|
|
42
|
-
function connected(e) {
|
|
43
|
-
const data = JSON.parse(e.data);
|
|
44
|
-
if (data.type === payloadType.connected) {
|
|
45
|
-
ws?.removeEventListener("message", connected);
|
|
46
|
-
resolve();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
ws?.addEventListener("message", connected);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function send(type, payload, meta) {
|
|
53
|
-
const msg = { type, meta, payload };
|
|
54
|
-
ws?.send(JSON.stringify(msg));
|
|
55
|
-
}
|
|
56
|
-
async function rustExecute(code, { onEnd, onError, onStderr, onStdout, onBegin }) {
|
|
57
|
-
await connect();
|
|
58
|
-
const meta = { sequenceNumber: uuid++ };
|
|
59
|
-
const payload = {
|
|
60
|
-
backtrace: false,
|
|
61
|
-
channel: "stable",
|
|
62
|
-
crateType: "bin",
|
|
63
|
-
edition: "2021",
|
|
64
|
-
mode: "release",
|
|
65
|
-
tests: false,
|
|
66
|
-
code
|
|
67
|
-
};
|
|
68
|
-
send(payloadType.request, payload, meta);
|
|
69
|
-
let stdout = "";
|
|
70
|
-
let stderr = "";
|
|
71
|
-
function onMessage(e) {
|
|
72
|
-
const data = JSON.parse(e.data);
|
|
73
|
-
const { type, payload: payload2, meta: _meta = {} } = data;
|
|
74
|
-
if (_meta.sequenceNumber !== meta.sequenceNumber)
|
|
75
|
-
return;
|
|
76
|
-
if (type === payloadType.execute.begin)
|
|
77
|
-
onBegin?.();
|
|
78
|
-
if (type === payloadType.execute.stdout) {
|
|
79
|
-
stdout += payload2;
|
|
80
|
-
if (stdout.endsWith("\n")) {
|
|
81
|
-
onStdout?.(stdout);
|
|
82
|
-
stdout = "";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
if (type === payloadType.execute.stderr) {
|
|
86
|
-
stderr += payload2;
|
|
87
|
-
if (stderr.endsWith("\n")) {
|
|
88
|
-
if (stderr.startsWith("error:")) {
|
|
89
|
-
const index = stderr.indexOf("\n");
|
|
90
|
-
onStderr?.(stderr.slice(0, index));
|
|
91
|
-
onStderr?.(stderr.slice(index + 1));
|
|
92
|
-
} else {
|
|
93
|
-
onStderr?.(stderr);
|
|
94
|
-
}
|
|
95
|
-
stderr = "";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (type === payloadType.execute.end) {
|
|
99
|
-
if (payload2.success === false)
|
|
100
|
-
onError?.(payload2.exitDetail);
|
|
101
|
-
ws?.removeEventListener("message", onMessage);
|
|
102
|
-
onEnd?.();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
ws?.addEventListener("message", onMessage);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/client/composables/codeRepl.ts
|
|
109
|
-
var ignoredNodes = [".diff.remove", ".vp-copy-ignore"];
|
|
110
|
-
var RE_LANGUAGE = /language-(\w+)/;
|
|
111
|
-
var api = {
|
|
112
|
-
go: "https://api.pengzhanbo.cn/repl/golang/run",
|
|
113
|
-
kotlin: "https://api.pengzhanbo.cn/repl/kotlin/run"
|
|
13
|
+
const langAlias = {
|
|
14
|
+
kt: "kotlin",
|
|
15
|
+
kotlin: "kotlin",
|
|
16
|
+
go: "go",
|
|
17
|
+
rust: "rust",
|
|
18
|
+
rs: "rust"
|
|
114
19
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
rs: "rust"
|
|
121
|
-
};
|
|
122
|
-
var supportLang = ["kotlin", "go", "rust"];
|
|
20
|
+
const supportLang = [
|
|
21
|
+
"kotlin",
|
|
22
|
+
"go",
|
|
23
|
+
"rust"
|
|
24
|
+
];
|
|
123
25
|
function resolveLang(lang) {
|
|
124
|
-
|
|
26
|
+
return lang ? langAlias[lang] || lang : "";
|
|
125
27
|
}
|
|
126
28
|
function resolveCode(el) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
29
|
+
const clone = el.cloneNode(true);
|
|
30
|
+
clone.querySelectorAll(ignoredNodes.join(",")).forEach((node) => node.remove());
|
|
31
|
+
return clone.textContent || "";
|
|
130
32
|
}
|
|
131
33
|
function resolveCodeInfo(el) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
34
|
+
const wrapper = el.querySelector("div[class*=language-]");
|
|
35
|
+
const lang = wrapper?.className.match(RE_LANGUAGE)?.[1];
|
|
36
|
+
const codeEl = wrapper?.querySelector("pre");
|
|
37
|
+
let code = "";
|
|
38
|
+
if (codeEl) code = resolveCode(codeEl);
|
|
39
|
+
return {
|
|
40
|
+
lang: resolveLang(lang),
|
|
41
|
+
code
|
|
42
|
+
};
|
|
139
43
|
}
|
|
140
44
|
function useCodeRepl(el) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
backendVersion,
|
|
254
|
-
firstRun,
|
|
255
|
-
stderr,
|
|
256
|
-
stdout,
|
|
257
|
-
loaded,
|
|
258
|
-
finished,
|
|
259
|
-
error
|
|
260
|
-
};
|
|
45
|
+
const lang = ref();
|
|
46
|
+
const loaded = ref(true);
|
|
47
|
+
const firstRun = ref(true);
|
|
48
|
+
const finished = ref(true);
|
|
49
|
+
const stdout = ref([]);
|
|
50
|
+
const stderr = ref([]);
|
|
51
|
+
const error = ref("");
|
|
52
|
+
const backendVersion = ref("");
|
|
53
|
+
onMounted(() => {
|
|
54
|
+
if (el.value) {
|
|
55
|
+
const info = resolveCodeInfo(el.value);
|
|
56
|
+
lang.value = info.lang;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
const executeMap = {
|
|
60
|
+
kotlin: executeKotlin,
|
|
61
|
+
go: executeGolang,
|
|
62
|
+
rust: executeRust
|
|
63
|
+
};
|
|
64
|
+
function onCleanRun() {
|
|
65
|
+
loaded.value = false;
|
|
66
|
+
finished.value = false;
|
|
67
|
+
stdout.value = [];
|
|
68
|
+
stderr.value = [];
|
|
69
|
+
error.value = "";
|
|
70
|
+
firstRun.value = true;
|
|
71
|
+
backendVersion.value = "";
|
|
72
|
+
}
|
|
73
|
+
async function onRunCode() {
|
|
74
|
+
if (!el.value || !loaded.value) return;
|
|
75
|
+
const info = resolveCodeInfo(el.value);
|
|
76
|
+
lang.value = info.lang;
|
|
77
|
+
if (!lang.value || !info.code || !supportLang.includes(lang.value)) return;
|
|
78
|
+
if (firstRun.value) firstRun.value = false;
|
|
79
|
+
loaded.value = false;
|
|
80
|
+
finished.value = false;
|
|
81
|
+
stdout.value = [];
|
|
82
|
+
stderr.value = [];
|
|
83
|
+
error.value = "";
|
|
84
|
+
await executeMap[lang.value]?.(info.code);
|
|
85
|
+
}
|
|
86
|
+
async function executeGolang(code) {
|
|
87
|
+
const res = await http.post(api.go, { code });
|
|
88
|
+
backendVersion.value = `v${res.version}`;
|
|
89
|
+
loaded.value = true;
|
|
90
|
+
if (res.error) {
|
|
91
|
+
error.value = res.error;
|
|
92
|
+
finished.value = true;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const events = res.events || [];
|
|
96
|
+
for (const event of events) if (event.kind === "stdout") {
|
|
97
|
+
if (event.delay) await sleep(event.delay / 1e6);
|
|
98
|
+
stdout.value.push(event.message);
|
|
99
|
+
} else if (event.kind === "stderr") stderr.value.push(event.message);
|
|
100
|
+
finished.value = true;
|
|
101
|
+
}
|
|
102
|
+
async function executeKotlin(code) {
|
|
103
|
+
const filename = "File.kt";
|
|
104
|
+
const res = await http.post(api.kotlin, {
|
|
105
|
+
args: "",
|
|
106
|
+
files: [{
|
|
107
|
+
name: filename,
|
|
108
|
+
publicId: "",
|
|
109
|
+
text: code
|
|
110
|
+
}]
|
|
111
|
+
});
|
|
112
|
+
backendVersion.value = `v${res.version}`;
|
|
113
|
+
loaded.value = true;
|
|
114
|
+
if (res.errors) {
|
|
115
|
+
const errors = Array.isArray(res.errors[filename]) ? res.errors[filename] : [res.errors[filename]];
|
|
116
|
+
if (errors.length) errors.forEach(({ message, severity }) => severity === "ERROR" && stderr.value.push(message));
|
|
117
|
+
}
|
|
118
|
+
stdout.value.push(res.text);
|
|
119
|
+
finished.value = true;
|
|
120
|
+
}
|
|
121
|
+
async function executeRust(code) {
|
|
122
|
+
await rustExecute(code, {
|
|
123
|
+
onBegin: () => {
|
|
124
|
+
loaded.value = true;
|
|
125
|
+
finished.value = false;
|
|
126
|
+
stdout.value = [];
|
|
127
|
+
stderr.value = [];
|
|
128
|
+
error.value = "";
|
|
129
|
+
backendVersion.value = "release";
|
|
130
|
+
},
|
|
131
|
+
onError(message) {
|
|
132
|
+
error.value = message;
|
|
133
|
+
},
|
|
134
|
+
onStdout(message) {
|
|
135
|
+
stdout.value.push(message);
|
|
136
|
+
},
|
|
137
|
+
onStderr(message) {
|
|
138
|
+
stderr.value.push(message);
|
|
139
|
+
},
|
|
140
|
+
onEnd: () => {
|
|
141
|
+
finished.value = true;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
onRunCode,
|
|
147
|
+
onCleanRun,
|
|
148
|
+
lang,
|
|
149
|
+
backendVersion,
|
|
150
|
+
firstRun,
|
|
151
|
+
stderr,
|
|
152
|
+
stdout,
|
|
153
|
+
loaded,
|
|
154
|
+
finished,
|
|
155
|
+
error
|
|
156
|
+
};
|
|
261
157
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
useCodeRepl
|
|
266
|
-
};
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
export { resolveCode, resolveCodeInfo, useCodeRepl };
|
|
@@ -1,48 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ShallowRef, MaybeRefOrGetter } from 'vue';
|
|
1
|
+
import { ComputedRef, MaybeRefOrGetter, Ref, ShallowRef } from "vue";
|
|
3
2
|
|
|
3
|
+
//#region src/client/composables/demo.d.ts
|
|
4
4
|
interface DemoConfig {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
html: string;
|
|
6
|
+
css: string;
|
|
7
|
+
script: string;
|
|
8
|
+
jsLib: string[];
|
|
9
|
+
cssLib: string[];
|
|
10
10
|
}
|
|
11
|
-
declare function useExpand(defaultExpand?: boolean): readonly [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
cssType: string;
|
|
35
|
-
} | {
|
|
36
|
-
js: string;
|
|
37
|
-
css: string;
|
|
38
|
-
html: string;
|
|
39
|
-
jsType: string;
|
|
40
|
-
cssType: string;
|
|
41
|
-
}>;
|
|
11
|
+
declare function useExpand(defaultExpand?: boolean): readonly [Ref<boolean>, () => void];
|
|
12
|
+
interface ResourceItem {
|
|
13
|
+
name: string;
|
|
14
|
+
items: SubResourceItem[];
|
|
15
|
+
}
|
|
16
|
+
interface SubResourceItem {
|
|
17
|
+
name: string;
|
|
18
|
+
url: string;
|
|
19
|
+
}
|
|
20
|
+
interface UseResourcesResult {
|
|
21
|
+
resources: ComputedRef<ResourceItem[]>;
|
|
22
|
+
showResources: Ref<boolean>;
|
|
23
|
+
toggleResources: () => void;
|
|
24
|
+
}
|
|
25
|
+
declare function useResources(el: ShallowRef<HTMLDivElement | null>, config: MaybeRefOrGetter<DemoConfig | undefined>): UseResourcesResult;
|
|
26
|
+
interface FenceData {
|
|
27
|
+
js: string;
|
|
28
|
+
css: string;
|
|
29
|
+
html: string;
|
|
30
|
+
jsType: string;
|
|
31
|
+
cssType: string;
|
|
32
|
+
}
|
|
33
|
+
declare function useFence(fence: ShallowRef<HTMLDivElement | null>, config: MaybeRefOrGetter<DemoConfig | undefined>): Ref<FenceData>;
|
|
42
34
|
declare function useNormalDemo(draw: ShallowRef<HTMLIFrameElement | null>, title: MaybeRefOrGetter<string | undefined>, config: MaybeRefOrGetter<DemoConfig | undefined>): {
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
id: string;
|
|
36
|
+
height: Ref<string>;
|
|
45
37
|
};
|
|
46
38
|
declare function parseData(data: any): any;
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
export { DemoConfig, parseData, useExpand, useFence, useNormalDemo, useResources };
|