vuepress-plugin-md-power 1.0.0-rc.146 → 1.0.0-rc.147
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,99 +1,112 @@
|
|
|
1
|
-
// src/client/composables/demo.ts
|
|
2
|
-
import { onClickOutside, useEventListener } from "@vueuse/core";
|
|
3
1
|
import { computed, getCurrentInstance, onMounted, ref, toValue, useId, watch } from "vue";
|
|
2
|
+
import { onClickOutside, useEventListener } from "@vueuse/core";
|
|
4
3
|
import { isPlainObject } from "vuepress/shared";
|
|
4
|
+
|
|
5
|
+
//#region src/client/composables/demo.ts
|
|
5
6
|
function useExpand(defaultExpand = true) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const expanded = ref(defaultExpand);
|
|
8
|
+
function toggle() {
|
|
9
|
+
expanded.value = !expanded.value;
|
|
10
|
+
}
|
|
11
|
+
return [expanded, toggle];
|
|
11
12
|
}
|
|
12
13
|
function useResources(el, config) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
14
|
+
const resources = computed(() => {
|
|
15
|
+
const conf = toValue(config);
|
|
16
|
+
if (!conf) return [];
|
|
17
|
+
return [{
|
|
18
|
+
name: "JavaScript",
|
|
19
|
+
items: conf.jsLib?.map((url) => ({
|
|
20
|
+
name: normalizeName(url),
|
|
21
|
+
url
|
|
22
|
+
}))
|
|
23
|
+
}, {
|
|
24
|
+
name: "CSS",
|
|
25
|
+
items: conf.cssLib?.map((url) => ({
|
|
26
|
+
name: normalizeName(url),
|
|
27
|
+
url
|
|
28
|
+
}))
|
|
29
|
+
}].filter((i) => i.items?.length);
|
|
30
|
+
});
|
|
31
|
+
function normalizeName(url) {
|
|
32
|
+
return url.slice(url.lastIndexOf("/") + 1);
|
|
33
|
+
}
|
|
34
|
+
const showResources = ref(false);
|
|
35
|
+
function toggleResources() {
|
|
36
|
+
showResources.value = !showResources.value;
|
|
37
|
+
}
|
|
38
|
+
onClickOutside(el, () => {
|
|
39
|
+
showResources.value = false;
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
resources,
|
|
43
|
+
showResources,
|
|
44
|
+
toggleResources
|
|
45
|
+
};
|
|
37
46
|
}
|
|
38
47
|
function useFence(fence, config) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
48
|
+
const data = ref({
|
|
49
|
+
js: "",
|
|
50
|
+
css: "",
|
|
51
|
+
html: "",
|
|
52
|
+
jsType: "",
|
|
53
|
+
cssType: ""
|
|
54
|
+
});
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
if (!fence.value) return;
|
|
57
|
+
const conf = toValue(config);
|
|
58
|
+
data.value.html = conf?.html ?? "";
|
|
59
|
+
const els = Array.from(fence.value.querySelectorAll("div[class*=\"language-\"]"));
|
|
60
|
+
for (const el of els) {
|
|
61
|
+
const lang = el.className.match(/language-(\w+)/)?.[1] ?? "";
|
|
62
|
+
const content = el.querySelector("pre")?.textContent ?? "";
|
|
63
|
+
if (lang === "js" || lang === "javascript") {
|
|
64
|
+
data.value.js = content;
|
|
65
|
+
data.value.jsType = "js";
|
|
66
|
+
}
|
|
67
|
+
if (lang === "ts" || lang === "typescript") {
|
|
68
|
+
data.value.js = content;
|
|
69
|
+
data.value.jsType = "ts";
|
|
70
|
+
}
|
|
71
|
+
if (lang === "css" || lang === "scss" || lang === "less" || lang === "stylus" || lang === "styl") {
|
|
72
|
+
data.value.css = content;
|
|
73
|
+
data.value.cssType = lang === "styl" ? "stylus" : lang;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
return data;
|
|
64
78
|
}
|
|
65
79
|
function useNormalDemo(draw, title, config) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return { id, height };
|
|
80
|
+
const current = getCurrentInstance();
|
|
81
|
+
const id = useId();
|
|
82
|
+
const isDark = computed(() => current?.appContext.config.globalProperties.$isDark.value);
|
|
83
|
+
const height = ref("100px");
|
|
84
|
+
onMounted(() => {
|
|
85
|
+
if (!draw.value) return;
|
|
86
|
+
const iframeDoc = draw.value.contentDocument || draw.value.contentWindow?.document;
|
|
87
|
+
if (!iframeDoc) return;
|
|
88
|
+
const templateId = `VPDemoNormalDraw${id}`;
|
|
89
|
+
useEventListener("message", (event) => {
|
|
90
|
+
const data = parseData(event.data);
|
|
91
|
+
if (data.type === templateId) height.value = `${data.height + 5}px`;
|
|
92
|
+
});
|
|
93
|
+
watch([config, title], () => {
|
|
94
|
+
iframeDoc.write(createHTMLTemplate(toValue(title) || "Demo", templateId, toValue(config)));
|
|
95
|
+
}, { immediate: true });
|
|
96
|
+
watch(isDark, () => {
|
|
97
|
+
iframeDoc.documentElement.dataset.theme = isDark.value ? "dark" : "light";
|
|
98
|
+
}, { immediate: true });
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
id,
|
|
102
|
+
height
|
|
103
|
+
};
|
|
91
104
|
}
|
|
92
105
|
function createHTMLTemplate(title, id, config) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
const { cssLib = [], jsLib = [], html, css, script } = config || {};
|
|
107
|
+
const stylesheet = cssLib.map((url) => `<link rel="stylesheet" href="${url}">`).join("");
|
|
108
|
+
const scripts = jsLib.map((url) => `<script src="${url}"></script>`).join("");
|
|
109
|
+
return `<!DOCTYPE html>
|
|
97
110
|
<html>
|
|
98
111
|
<head>
|
|
99
112
|
<meta charset="utf-8">
|
|
@@ -120,21 +133,14 @@ function createHTMLTemplate(title, id, config) {
|
|
|
120
133
|
</html>`;
|
|
121
134
|
}
|
|
122
135
|
function parseData(data) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
} catch {
|
|
131
|
-
return {};
|
|
132
|
-
}
|
|
136
|
+
try {
|
|
137
|
+
if (typeof data === "string") return JSON.parse(data);
|
|
138
|
+
else if (isPlainObject(data)) return data;
|
|
139
|
+
return {};
|
|
140
|
+
} catch {
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
133
143
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
useFence,
|
|
138
|
-
useNormalDemo,
|
|
139
|
-
useResources
|
|
140
|
-
};
|
|
144
|
+
|
|
145
|
+
//#endregion
|
|
146
|
+
export { parseData, useExpand, useFence, useNormalDemo, useResources };
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import { PDFEmbedType, PDFTokenMeta } from
|
|
1
|
+
import { PDFEmbedType, PDFTokenMeta } from "../../shared/index.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Fork for https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/components/src/client/utils/viewPDF.ts
|
|
5
|
-
*
|
|
6
|
-
* The MIT License (MIT)
|
|
7
|
-
* Copyright (C) 2021 - PRESENT by Mr.Hope<mister-hope@outlook.com>
|
|
8
|
-
*
|
|
9
|
-
* 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:
|
|
10
|
-
*
|
|
11
|
-
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
-
*
|
|
13
|
-
* 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.
|
|
14
|
-
*/
|
|
3
|
+
//#region src/client/composables/pdf.d.ts
|
|
15
4
|
|
|
16
5
|
declare function renderPDF(el: HTMLElement, url: string, embedType: PDFEmbedType, options: PDFTokenMeta): void;
|
|
17
6
|
declare function usePDF(el: HTMLElement, url: string, options: PDFTokenMeta): void;
|
|
18
|
-
|
|
19
|
-
export { renderPDF, usePDF };
|
|
7
|
+
//#endregion
|
|
8
|
+
export { renderPDF, usePDF };
|
|
@@ -1,59 +1,54 @@
|
|
|
1
|
-
// src/client/composables/pdf.ts
|
|
2
|
-
import { checkIsiPad, checkIsMobile, checkIsSafari } from "@vuepress/helper/client";
|
|
3
|
-
import { withBase } from "vuepress/client";
|
|
4
1
|
import { ensureEndingSlash, isLinkHttp } from "vuepress/shared";
|
|
2
|
+
import { checkIsMobile, checkIsSafari, checkIsiPad } from "@vuepress/helper/client";
|
|
3
|
+
import { withBase } from "vuepress/client";
|
|
5
4
|
import { pluginOptions } from "../options.js";
|
|
5
|
+
|
|
6
|
+
//#region src/client/composables/pdf.ts
|
|
6
7
|
function queryStringify(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return queryString;
|
|
8
|
+
const { page, noToolbar, zoom } = options;
|
|
9
|
+
const params = [
|
|
10
|
+
`page=${page}`,
|
|
11
|
+
`toolbar=${noToolbar ? 0 : 1}`,
|
|
12
|
+
`zoom=${zoom}`
|
|
13
|
+
];
|
|
14
|
+
let queryString = params.join("&");
|
|
15
|
+
if (queryString) queryString = `#${queryString}`;
|
|
16
|
+
return queryString;
|
|
17
17
|
}
|
|
18
18
|
function renderPDF(el, url, embedType, options) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
pdf.allow = "fullscreen";
|
|
36
|
-
el.appendChild(pdf);
|
|
19
|
+
if (!pluginOptions.pdf) return;
|
|
20
|
+
url = isLinkHttp(url) ? url : new URL(withBase(url), typeof location !== "undefined" ? location.href : "").toString();
|
|
21
|
+
const pdfOptions = pluginOptions.pdf === true ? {} : pluginOptions.pdf;
|
|
22
|
+
pdfOptions.pdfjsUrl ??= "https://static.pengzhanbo.cn/pdfjs/";
|
|
23
|
+
const pdfjsUrl = `${ensureEndingSlash(withBase(pdfOptions.pdfjsUrl))}web/viewer.html`;
|
|
24
|
+
const queryString = queryStringify(options);
|
|
25
|
+
const source = embedType === "pdfjs" ? `${pdfjsUrl}?file=${url}${queryString}` : `${url}${queryString}`;
|
|
26
|
+
const tagName = embedType === "pdfjs" || embedType === "iframe" ? "iframe" : "embed";
|
|
27
|
+
el.innerHTML = "";
|
|
28
|
+
const pdf = document.createElement(tagName);
|
|
29
|
+
pdf.className = "pdf-viewer";
|
|
30
|
+
pdf.type = "application/pdf";
|
|
31
|
+
pdf.title = options.title || "PDF Viewer";
|
|
32
|
+
pdf.src = source;
|
|
33
|
+
if (pdf instanceof HTMLIFrameElement) pdf.allow = "fullscreen";
|
|
34
|
+
el.appendChild(pdf);
|
|
37
35
|
}
|
|
38
36
|
function usePDF(el, url, options) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return renderPDF(el, url, "pdfjs", options);
|
|
37
|
+
if (typeof window === "undefined" || !window?.navigator?.userAgent) return;
|
|
38
|
+
const { navigator } = window;
|
|
39
|
+
const { userAgent } = navigator;
|
|
40
|
+
const isModernBrowser = typeof window.Promise === "function";
|
|
41
|
+
const isMobileDevice = checkIsiPad(userAgent) || checkIsMobile(userAgent);
|
|
42
|
+
const isSafariDesktop = !isMobileDevice && checkIsSafari(userAgent);
|
|
43
|
+
const isFirefoxWithPDFJS = !isMobileDevice && /firefox/iu.test(userAgent) && userAgent.split("rv:").length > 1 ? Number.parseInt(userAgent.split("rv:")[1].split(".")[0], 10) > 18 : false;
|
|
44
|
+
const supportsPDFs = !isMobileDevice && (isModernBrowser || isFirefoxWithPDFJS);
|
|
45
|
+
if (!url) return;
|
|
46
|
+
if (supportsPDFs || !isMobileDevice) {
|
|
47
|
+
const embedType = isSafariDesktop ? "iframe" : "embed";
|
|
48
|
+
return renderPDF(el, url, embedType, options);
|
|
49
|
+
}
|
|
50
|
+
return renderPDF(el, url, "pdfjs", options);
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
export { renderPDF, usePDF };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { tryOnScopeDispose } from "@vueuse/core";
|
|
2
|
+
|
|
3
|
+
//#region src/client/composables/rustRepl.ts
|
|
4
|
+
const wsUrl = "wss://play.rust-lang.org/websocket";
|
|
5
|
+
const payloadType = {
|
|
6
|
+
connected: "websocket/connected",
|
|
7
|
+
request: "output/execute/wsExecuteRequest",
|
|
8
|
+
execute: {
|
|
9
|
+
begin: "output/execute/wsExecuteBegin",
|
|
10
|
+
stderr: "output/execute/wsExecuteStderr",
|
|
11
|
+
stdout: "output/execute/wsExecuteStdout",
|
|
12
|
+
end: "output/execute/wsExecuteEnd"
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
let ws = null;
|
|
16
|
+
let isOpen = false;
|
|
17
|
+
let uuid = 0;
|
|
18
|
+
function connect() {
|
|
19
|
+
if (isOpen) return Promise.resolve();
|
|
20
|
+
ws = new WebSocket(wsUrl);
|
|
21
|
+
uuid = 0;
|
|
22
|
+
ws.addEventListener("open", () => {
|
|
23
|
+
isOpen = true;
|
|
24
|
+
send(payloadType.connected, { iAcceptThisIsAnUnsupportedApi: true }, {
|
|
25
|
+
websocket: true,
|
|
26
|
+
sequenceNumber: uuid
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
ws.addEventListener("close", () => {
|
|
30
|
+
isOpen = false;
|
|
31
|
+
ws = null;
|
|
32
|
+
});
|
|
33
|
+
tryOnScopeDispose(() => ws?.close());
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
function connected(e) {
|
|
36
|
+
const data = JSON.parse(e.data);
|
|
37
|
+
if (data.type === payloadType.connected) {
|
|
38
|
+
ws?.removeEventListener("message", connected);
|
|
39
|
+
resolve();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
ws?.addEventListener("message", connected);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function send(type, payload, meta) {
|
|
46
|
+
const msg = {
|
|
47
|
+
type,
|
|
48
|
+
meta,
|
|
49
|
+
payload
|
|
50
|
+
};
|
|
51
|
+
ws?.send(JSON.stringify(msg));
|
|
52
|
+
}
|
|
53
|
+
async function rustExecute(code, { onEnd, onError, onStderr, onStdout, onBegin }) {
|
|
54
|
+
await connect();
|
|
55
|
+
const meta = { sequenceNumber: uuid++ };
|
|
56
|
+
const payload = {
|
|
57
|
+
backtrace: false,
|
|
58
|
+
channel: "stable",
|
|
59
|
+
crateType: "bin",
|
|
60
|
+
edition: "2021",
|
|
61
|
+
mode: "release",
|
|
62
|
+
tests: false,
|
|
63
|
+
code
|
|
64
|
+
};
|
|
65
|
+
send(payloadType.request, payload, meta);
|
|
66
|
+
let stdout = "";
|
|
67
|
+
let stderr = "";
|
|
68
|
+
function onMessage(e) {
|
|
69
|
+
const data = JSON.parse(e.data);
|
|
70
|
+
const { type, payload: payload$1, meta: _meta = {} } = data;
|
|
71
|
+
if (_meta.sequenceNumber !== meta.sequenceNumber) return;
|
|
72
|
+
if (type === payloadType.execute.begin) onBegin?.();
|
|
73
|
+
if (type === payloadType.execute.stdout) {
|
|
74
|
+
stdout += payload$1;
|
|
75
|
+
if (stdout.endsWith("\n")) {
|
|
76
|
+
onStdout?.(stdout);
|
|
77
|
+
stdout = "";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (type === payloadType.execute.stderr) {
|
|
81
|
+
stderr += payload$1;
|
|
82
|
+
if (stderr.endsWith("\n")) {
|
|
83
|
+
if (stderr.startsWith("error:")) {
|
|
84
|
+
const index = stderr.indexOf("\n");
|
|
85
|
+
onStderr?.(stderr.slice(0, index));
|
|
86
|
+
onStderr?.(stderr.slice(index + 1));
|
|
87
|
+
} else onStderr?.(stderr);
|
|
88
|
+
stderr = "";
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (type === payloadType.execute.end) {
|
|
92
|
+
if (payload$1.success === false) onError?.(payload$1.exitDetail);
|
|
93
|
+
ws?.removeEventListener("message", onMessage);
|
|
94
|
+
onEnd?.();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
ws?.addEventListener("message", onMessage);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//#endregion
|
|
101
|
+
export { rustExecute };
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/client/composables/rustRepl.d.ts
|
|
2
|
+
declare function rustExecute(code: string, {
|
|
3
|
+
onEnd,
|
|
4
|
+
onError,
|
|
5
|
+
onStderr,
|
|
6
|
+
onStdout,
|
|
7
|
+
onBegin
|
|
8
|
+
}: RustExecuteOptions): Promise<void>;
|
|
2
9
|
interface RustExecuteOptions {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
onBegin?: () => void;
|
|
11
|
+
onStdout?: (message: string) => void;
|
|
12
|
+
onStderr?: (message: string) => void;
|
|
13
|
+
onEnd?: () => void;
|
|
14
|
+
onError?: (message: string) => void;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
export { rustExecute };
|
|
@@ -1,104 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var payloadType = {
|
|
5
|
-
connected: "websocket/connected",
|
|
6
|
-
request: "output/execute/wsExecuteRequest",
|
|
7
|
-
execute: {
|
|
8
|
-
begin: "output/execute/wsExecuteBegin",
|
|
9
|
-
// status: 'output/execute/wsExecuteStatus',
|
|
10
|
-
stderr: "output/execute/wsExecuteStderr",
|
|
11
|
-
stdout: "output/execute/wsExecuteStdout",
|
|
12
|
-
end: "output/execute/wsExecuteEnd"
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var ws = null;
|
|
16
|
-
var isOpen = false;
|
|
17
|
-
var uuid = 0;
|
|
18
|
-
function connect() {
|
|
19
|
-
if (isOpen)
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
ws = new WebSocket(wsUrl);
|
|
22
|
-
uuid = 0;
|
|
23
|
-
ws.addEventListener("open", () => {
|
|
24
|
-
isOpen = true;
|
|
25
|
-
send(
|
|
26
|
-
payloadType.connected,
|
|
27
|
-
{ iAcceptThisIsAnUnsupportedApi: true },
|
|
28
|
-
{ websocket: true, sequenceNumber: uuid }
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
ws.addEventListener("close", () => {
|
|
32
|
-
isOpen = false;
|
|
33
|
-
ws = null;
|
|
34
|
-
});
|
|
35
|
-
tryOnScopeDispose(() => ws?.close());
|
|
36
|
-
return new Promise((resolve) => {
|
|
37
|
-
function connected(e) {
|
|
38
|
-
const data = JSON.parse(e.data);
|
|
39
|
-
if (data.type === payloadType.connected) {
|
|
40
|
-
ws?.removeEventListener("message", connected);
|
|
41
|
-
resolve();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
ws?.addEventListener("message", connected);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function send(type, payload, meta) {
|
|
48
|
-
const msg = { type, meta, payload };
|
|
49
|
-
ws?.send(JSON.stringify(msg));
|
|
50
|
-
}
|
|
51
|
-
async function rustExecute(code, { onEnd, onError, onStderr, onStdout, onBegin }) {
|
|
52
|
-
await connect();
|
|
53
|
-
const meta = { sequenceNumber: uuid++ };
|
|
54
|
-
const payload = {
|
|
55
|
-
backtrace: false,
|
|
56
|
-
channel: "stable",
|
|
57
|
-
crateType: "bin",
|
|
58
|
-
edition: "2021",
|
|
59
|
-
mode: "release",
|
|
60
|
-
tests: false,
|
|
61
|
-
code
|
|
62
|
-
};
|
|
63
|
-
send(payloadType.request, payload, meta);
|
|
64
|
-
let stdout = "";
|
|
65
|
-
let stderr = "";
|
|
66
|
-
function onMessage(e) {
|
|
67
|
-
const data = JSON.parse(e.data);
|
|
68
|
-
const { type, payload: payload2, meta: _meta = {} } = data;
|
|
69
|
-
if (_meta.sequenceNumber !== meta.sequenceNumber)
|
|
70
|
-
return;
|
|
71
|
-
if (type === payloadType.execute.begin)
|
|
72
|
-
onBegin?.();
|
|
73
|
-
if (type === payloadType.execute.stdout) {
|
|
74
|
-
stdout += payload2;
|
|
75
|
-
if (stdout.endsWith("\n")) {
|
|
76
|
-
onStdout?.(stdout);
|
|
77
|
-
stdout = "";
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (type === payloadType.execute.stderr) {
|
|
81
|
-
stderr += payload2;
|
|
82
|
-
if (stderr.endsWith("\n")) {
|
|
83
|
-
if (stderr.startsWith("error:")) {
|
|
84
|
-
const index = stderr.indexOf("\n");
|
|
85
|
-
onStderr?.(stderr.slice(0, index));
|
|
86
|
-
onStderr?.(stderr.slice(index + 1));
|
|
87
|
-
} else {
|
|
88
|
-
onStderr?.(stderr);
|
|
89
|
-
}
|
|
90
|
-
stderr = "";
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (type === payloadType.execute.end) {
|
|
94
|
-
if (payload2.success === false)
|
|
95
|
-
onError?.(payload2.exitDetail);
|
|
96
|
-
ws?.removeEventListener("message", onMessage);
|
|
97
|
-
onEnd?.();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
ws?.addEventListener("message", onMessage);
|
|
101
|
-
}
|
|
102
|
-
export {
|
|
103
|
-
rustExecute
|
|
104
|
-
};
|
|
1
|
+
import { rustExecute } from "./rustRepl-iGLjb94D.js";
|
|
2
|
+
|
|
3
|
+
export { rustExecute };
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SizeOptions } from
|
|
1
|
+
import { Ref, ShallowRef, ToRefs } from "vue";
|
|
2
|
+
import { MaybeRef as MaybeRef$1 } from "@vueuse/core";
|
|
3
|
+
import { SizeOptions } from "../../shared/index.js";
|
|
4
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
|
-
*/
|
|
5
|
+
//#region src/client/composables/size.d.ts
|
|
17
6
|
|
|
18
7
|
interface SizeInfo<T extends HTMLElement> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
el: ShallowRef<T | undefined>;
|
|
9
|
+
width: Ref<string>;
|
|
10
|
+
height: Ref<string>;
|
|
11
|
+
resize: () => void;
|
|
23
12
|
}
|
|
24
|
-
declare function useSize<T extends HTMLElement>(options: ToRefs<SizeOptions>, extraHeight?: MaybeRef<number>): SizeInfo<T>;
|
|
13
|
+
declare function useSize<T extends HTMLElement>(options: ToRefs<SizeOptions>, extraHeight?: MaybeRef$1<number>): SizeInfo<T>;
|
|
25
14
|
|
|
26
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
export { SizeInfo, useSize };
|