@deot/docs-playground 1.1.2 → 1.1.4
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/README.md +3 -0
- package/dist/cdn-BoYKnGD3.cjs +101 -0
- package/dist/cdn-DQoETju_.js +54 -0
- package/dist/compile-BHD98Ttf.js +325 -0
- package/dist/compile-Da095AyM.cjs +325 -0
- package/dist/files-BqucFldk.js +207 -0
- package/dist/files-BsAOZiPN.cjs +267 -0
- package/dist/index.cjs +221 -1050
- package/dist/index.d.ts +4 -2
- package/dist/index.js +178 -986
- package/dist/index.style.css +1 -1
- package/dist/linker-DIpEiean.cjs +167 -0
- package/dist/linker-xqjVl0X0.js +166 -0
- package/dist/local-sandbox-0ojvBQPO.cjs +432 -0
- package/dist/local-sandbox-DvcgaBOa.js +424 -0
- package/dist/modules-BGzPcoRR.js +217 -0
- package/dist/modules-E6kK6ZJH.cjs +223 -0
- package/dist/remote-BG0E1Ugo.cjs +152 -0
- package/dist/remote-mq4zvrI1.js +152 -0
- package/dist/rolldown-runtime-C0BPl7ul.cjs +43 -0
- package/dist/script-BiCcpu3G.cjs +111 -0
- package/dist/script-DjUf9uWK.js +98 -0
- package/dist/scss-B8OFbz1k.cjs +251 -0
- package/dist/scss-DIh6971q.js +227 -0
- package/dist/store-BOyC8F2y.js +910 -0
- package/dist/store-DKawhFZu.cjs +1109 -0
- package/package.json +21 -9
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
2
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
+
const require_cdn = require("./cdn-BoYKnGD3.cjs");
|
|
4
|
+
const require_store = require("./store-DKawhFZu.cjs");
|
|
5
|
+
const require_scss = require("./scss-B8OFbz1k.cjs");
|
|
6
|
+
const require_files = require("./files-BsAOZiPN.cjs");
|
|
24
7
|
let vue = require("vue");
|
|
25
8
|
let _deot_vc = require("@deot/vc");
|
|
26
9
|
let _deot_docs_locale = require("@deot/docs-locale");
|
|
27
10
|
let highlight_js = require("highlight.js");
|
|
28
|
-
highlight_js = __toESM(highlight_js);
|
|
11
|
+
highlight_js = require_rolldown_runtime.__toESM(highlight_js);
|
|
29
12
|
let _vue_repl = require("@vue/repl");
|
|
30
13
|
let codemirror = require("codemirror");
|
|
31
14
|
let _codemirror_lang_css = require("@codemirror/lang-css");
|
|
@@ -334,12 +317,6 @@ var files_preview_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
334
317
|
}
|
|
335
318
|
});
|
|
336
319
|
//#endregion
|
|
337
|
-
//#region packages/playground/src/constants.ts
|
|
338
|
-
var DEFAULT_ENTRY = "App.vue";
|
|
339
|
-
/** 预览样式和默认 import map 共用的 npm CDN 前缀。 */
|
|
340
|
-
var DEFAULT_CDN_URL = "https://cdn.jsdelivr.net/npm";
|
|
341
|
-
var NEW_SFC_CODE = `<script setup lang="ts"><\/script>\n\n<template>\n <div>\n <slot />\n <\/div>\n<\/template>\n`;
|
|
342
|
-
//#endregion
|
|
343
320
|
//#region packages/playground/src/editor/drag.ts
|
|
344
321
|
var events = typeof document !== "undefined" && "ontouchstart" in document ? {
|
|
345
322
|
start: "touchstart",
|
|
@@ -463,7 +440,7 @@ var _hoisted_5$4 = ["onKeydown"];
|
|
|
463
440
|
var _hoisted_6$3 = ["title"];
|
|
464
441
|
var _hoisted_7$3 = ["title", "aria-label"];
|
|
465
442
|
var _hoisted_8$2 = ["title", "aria-label"];
|
|
466
|
-
var _hoisted_9$
|
|
443
|
+
var _hoisted_9$1 = { class: "docs-playground-editor__actions" };
|
|
467
444
|
var _hoisted_10$1 = ["title"];
|
|
468
445
|
var _hoisted_11$1 = ["title", "disabled"];
|
|
469
446
|
var _hoisted_12$1 = {
|
|
@@ -595,7 +572,7 @@ var editor_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
595
572
|
const filename = nextFilename();
|
|
596
573
|
editorFiles.value = {
|
|
597
574
|
...editorFiles.value,
|
|
598
|
-
[filename]: NEW_SFC_CODE
|
|
575
|
+
[filename]: require_cdn.NEW_SFC_CODE
|
|
599
576
|
};
|
|
600
577
|
activeFilename.value = filename;
|
|
601
578
|
notifyFilesChange({
|
|
@@ -779,7 +756,7 @@ var editor_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
779
756
|
], 64))], 42, _hoisted_4$4);
|
|
780
757
|
}), 128))]),
|
|
781
758
|
_: 1
|
|
782
|
-
}, 512), (0, vue.createElementVNode)("div", _hoisted_9$
|
|
759
|
+
}, 512), (0, vue.createElementVNode)("div", _hoisted_9$1, [(0, vue.createElementVNode)("button", {
|
|
783
760
|
type: "button",
|
|
784
761
|
title: (0, vue.unref)(t)("playground.editor.createFile"),
|
|
785
762
|
onClick: handleCreate
|
|
@@ -860,229 +837,6 @@ var resolvePlaygroundTitleId = (title, explicitId = "", isOccupied) => {
|
|
|
860
837
|
while (isOccupied(`${base}-${index}`)) index += 1;
|
|
861
838
|
return `${base}-${index}`;
|
|
862
839
|
};
|
|
863
|
-
//#endregion
|
|
864
|
-
//#region packages/playground/src/core/preview-scroll.ts
|
|
865
|
-
/** iframe 包装成功后挂在 `html` 上,供样式与 auto-height 识别。 */
|
|
866
|
-
var PREVIEW_SCROLL_HTML_CLASS = "docs-playground-preview-scroll";
|
|
867
|
-
/** Scroller 内容节点 class,auto-height 优先测量该节点。 */
|
|
868
|
-
var PREVIEW_SCROLL_CONTENT_CLASS = "docs-playground-preview-scroll__content";
|
|
869
|
-
/** 重评时先清掉 html class,避免 `await import` 期间仍套用 `height:100%`。 */
|
|
870
|
-
var PREVIEW_SCROLL_RESET_CODE = `document.documentElement.classList.remove("${PREVIEW_SCROLL_HTML_CLASS}");`;
|
|
871
|
-
/** 动态探测 `@deot/vc`;失败时为空对象,不阻断 DocsLink / 预览挂载。 */
|
|
872
|
-
var PREVIEW_SCROLLER_IMPORT_CODE = "const __docsVc=await import(\"@deot/vc\").catch(()=>({}))";
|
|
873
|
-
/**
|
|
874
|
-
* Vue 的 `mount` 闭包的是 `createApp(root)` 时的根组件,改 `app._component` 不会生效。
|
|
875
|
-
* 因此劫持 `app.mount`:等全部 useCode 注册完后,再 `createApp` 包一层 Scroller。
|
|
876
|
-
* 前导分号避免接在 `app.component(...)` 后被 ASI 解析成调用返回值。
|
|
877
|
-
*/
|
|
878
|
-
var PREVIEW_SCROLLER_USE_CODE = [
|
|
879
|
-
";(()=>{",
|
|
880
|
-
PREVIEW_SCROLL_RESET_CODE,
|
|
881
|
-
"const __DocsScroller=__docsVc&&__docsVc.Scroller;",
|
|
882
|
-
"if(!__DocsScroller)return;",
|
|
883
|
-
"const UserApp=app._component;",
|
|
884
|
-
"app.mount=(container,...rest)=>{",
|
|
885
|
-
"const next=_createApp({",
|
|
886
|
-
"name:\"DocsPreviewRoot\",",
|
|
887
|
-
"setup(){return()=>__docsH(__DocsScroller,{",
|
|
888
|
-
"height:\"100%\",",
|
|
889
|
-
"native:false,",
|
|
890
|
-
"autoResize:true,",
|
|
891
|
-
"showBar:true,",
|
|
892
|
-
`contentClass:"${PREVIEW_SCROLL_CONTENT_CLASS}"`,
|
|
893
|
-
"},{default:()=>__docsH(UserApp)})}",
|
|
894
|
-
"});",
|
|
895
|
-
"next.config.errorHandler=app.config.errorHandler;",
|
|
896
|
-
"if(app._context&&next._context){",
|
|
897
|
-
"if(app._context.components)Object.assign(next._context.components,app._context.components);",
|
|
898
|
-
"if(app._context.directives)Object.assign(next._context.directives,app._context.directives);",
|
|
899
|
-
"Object.assign(next._context.provides,app._context.provides);",
|
|
900
|
-
"next._context.mixins.push(...app._context.mixins);",
|
|
901
|
-
"}",
|
|
902
|
-
"window.__app__=next;",
|
|
903
|
-
`document.documentElement.classList.add("${PREVIEW_SCROLL_HTML_CLASS}");`,
|
|
904
|
-
"return next.mount(container,...rest)",
|
|
905
|
-
"}",
|
|
906
|
-
"})()"
|
|
907
|
-
].join("");
|
|
908
|
-
var PREVIEW_SCROLLER_STYLE = [
|
|
909
|
-
`html.${PREVIEW_SCROLL_HTML_CLASS},`,
|
|
910
|
-
`html.${PREVIEW_SCROLL_HTML_CLASS} body,`,
|
|
911
|
-
`html.${PREVIEW_SCROLL_HTML_CLASS} #app{`,
|
|
912
|
-
"height:100%;min-height:100%;margin:0;overflow:hidden",
|
|
913
|
-
"}",
|
|
914
|
-
`html.${PREVIEW_SCROLL_HTML_CLASS} #app>.vc-scroller,`,
|
|
915
|
-
`html.${PREVIEW_SCROLL_HTML_CLASS} #app>.vc-scroller>.vc-scroller__wrapper{`,
|
|
916
|
-
"height:100%;max-height:100%;box-sizing:border-box",
|
|
917
|
-
"}"
|
|
918
|
-
].join("");
|
|
919
|
-
var resolveSandboxContainer = (sandbox) => sandbox?.container ? (0, vue.unref)(sandbox.container) : null;
|
|
920
|
-
var resolveScrollContent = (iframeDocument) => {
|
|
921
|
-
if (!iframeDocument.documentElement.classList.contains("docs-playground-preview-scroll")) return null;
|
|
922
|
-
return iframeDocument.querySelector(`.${PREVIEW_SCROLL_CONTENT_CLASS}`);
|
|
923
|
-
};
|
|
924
|
-
var useSandboxAutoHeight = (sandboxRef) => {
|
|
925
|
-
const height = (0, vue.ref)(24);
|
|
926
|
-
let container = null;
|
|
927
|
-
let iframe = null;
|
|
928
|
-
let containerObserver = null;
|
|
929
|
-
let contentObserver = null;
|
|
930
|
-
let scrollMountObserver = null;
|
|
931
|
-
let observedScrollNode = null;
|
|
932
|
-
let frameId = 0;
|
|
933
|
-
const cancelMeasure = () => {
|
|
934
|
-
if (!frameId) return;
|
|
935
|
-
cancelAnimationFrame(frameId);
|
|
936
|
-
frameId = 0;
|
|
937
|
-
};
|
|
938
|
-
const measureDocumentContent = (iframeWindow, iframeDocument) => {
|
|
939
|
-
const { body, documentElement } = iframeDocument;
|
|
940
|
-
const bodyStyle = iframeWindow.getComputedStyle(body);
|
|
941
|
-
const bodyMargins = (Number.parseFloat(bodyStyle.marginTop) || 0) + (Number.parseFloat(bodyStyle.marginBottom) || 0);
|
|
942
|
-
const rootTop = documentElement.getBoundingClientRect().top;
|
|
943
|
-
const bodyRect = body.getBoundingClientRect();
|
|
944
|
-
const collapsedTop = Math.max(0, bodyRect.top - rootTop);
|
|
945
|
-
let childrenBottom = 0;
|
|
946
|
-
for (const child of body.children) {
|
|
947
|
-
if (iframeWindow.getComputedStyle(child).position === "fixed") continue;
|
|
948
|
-
const rect = child.getBoundingClientRect();
|
|
949
|
-
const marginBottom = Number.parseFloat(iframeWindow.getComputedStyle(child).marginBottom) || 0;
|
|
950
|
-
childrenBottom = Math.max(childrenBottom, rect.bottom + marginBottom - rootTop);
|
|
951
|
-
}
|
|
952
|
-
const scrollHeight = Math.max(body.scrollHeight, documentElement.scrollHeight);
|
|
953
|
-
const overflowingHeight = scrollHeight > (iframe?.clientHeight || 0) + 1 ? scrollHeight : 0;
|
|
954
|
-
return Math.ceil(Math.max(body.offsetHeight + bodyMargins + collapsedTop, bodyRect.height + bodyMargins + collapsedTop, childrenBottom, overflowingHeight));
|
|
955
|
-
};
|
|
956
|
-
const measureScrollContent = (scrollContent) => {
|
|
957
|
-
const contentStyle = scrollContent.ownerDocument.defaultView?.getComputedStyle(scrollContent);
|
|
958
|
-
const margins = contentStyle ? (Number.parseFloat(contentStyle.marginTop) || 0) + (Number.parseFloat(contentStyle.marginBottom) || 0) : 0;
|
|
959
|
-
let childrenBottom = 0;
|
|
960
|
-
const rootTop = scrollContent.getBoundingClientRect().top;
|
|
961
|
-
for (const child of scrollContent.children) {
|
|
962
|
-
const rect = child.getBoundingClientRect();
|
|
963
|
-
const marginBottom = Number.parseFloat(scrollContent.ownerDocument.defaultView?.getComputedStyle(child).marginBottom || "0") || 0;
|
|
964
|
-
childrenBottom = Math.max(childrenBottom, rect.bottom + marginBottom - rootTop);
|
|
965
|
-
}
|
|
966
|
-
return Math.ceil(Math.max(scrollContent.scrollHeight + margins, scrollContent.offsetHeight + margins, childrenBottom + margins));
|
|
967
|
-
};
|
|
968
|
-
const isPendingPreviewApp = (iframeDocument) => {
|
|
969
|
-
const app = iframeDocument.getElementById("app");
|
|
970
|
-
return app ? app.childElementCount === 0 : !!iframe?.srcdoc;
|
|
971
|
-
};
|
|
972
|
-
const releaseBootstrapHeight = (target) => {
|
|
973
|
-
(0, vue.nextTick)(() => {
|
|
974
|
-
if (iframe === target) target.style.height = "100%";
|
|
975
|
-
});
|
|
976
|
-
};
|
|
977
|
-
const measure = () => {
|
|
978
|
-
frameId = 0;
|
|
979
|
-
if (!iframe) return;
|
|
980
|
-
try {
|
|
981
|
-
const iframeWindow = iframe.contentWindow;
|
|
982
|
-
const iframeDocument = iframe.contentDocument;
|
|
983
|
-
if (!iframeWindow || !iframeDocument?.body) return;
|
|
984
|
-
const scrollContent = resolveScrollContent(iframeDocument);
|
|
985
|
-
if (!scrollContent && isPendingPreviewApp(iframeDocument)) return;
|
|
986
|
-
const contentHeight = scrollContent ? measureScrollContent(scrollContent) : measureDocumentContent(iframeWindow, iframeDocument);
|
|
987
|
-
const nextHeight = Math.max(contentHeight, 24);
|
|
988
|
-
if (height.value !== nextHeight) height.value = nextHeight;
|
|
989
|
-
releaseBootstrapHeight(iframe);
|
|
990
|
-
} catch {
|
|
991
|
-
if (height.value !== 24) height.value = 24;
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
const scheduleMeasure = () => {
|
|
995
|
-
if (frameId) return;
|
|
996
|
-
frameId = requestAnimationFrame(measure);
|
|
997
|
-
};
|
|
998
|
-
const disconnectContent = () => {
|
|
999
|
-
contentObserver?.disconnect();
|
|
1000
|
-
contentObserver = null;
|
|
1001
|
-
scrollMountObserver?.disconnect();
|
|
1002
|
-
scrollMountObserver = null;
|
|
1003
|
-
observedScrollNode = null;
|
|
1004
|
-
cancelMeasure();
|
|
1005
|
-
};
|
|
1006
|
-
const observeContent = () => {
|
|
1007
|
-
disconnectContent();
|
|
1008
|
-
if (!iframe) return;
|
|
1009
|
-
try {
|
|
1010
|
-
const iframeWindow = iframe.contentWindow;
|
|
1011
|
-
const iframeDocument = iframe.contentDocument;
|
|
1012
|
-
const Observer = iframeWindow?.ResizeObserver;
|
|
1013
|
-
if (!iframeWindow || !iframeDocument?.body || !Observer) {
|
|
1014
|
-
scheduleMeasure();
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
const observer = new Observer(scheduleMeasure);
|
|
1018
|
-
observer.observe(iframeDocument.documentElement);
|
|
1019
|
-
observer.observe(iframeDocument.body);
|
|
1020
|
-
contentObserver = observer;
|
|
1021
|
-
const attachScrollContent = (node) => {
|
|
1022
|
-
if (!node || !contentObserver) return false;
|
|
1023
|
-
if (observedScrollNode === node) return true;
|
|
1024
|
-
if (observedScrollNode) contentObserver.unobserve(observedScrollNode);
|
|
1025
|
-
observedScrollNode = node;
|
|
1026
|
-
contentObserver.observe(node);
|
|
1027
|
-
return true;
|
|
1028
|
-
};
|
|
1029
|
-
const syncScrollContent = () => {
|
|
1030
|
-
attachScrollContent(resolveScrollContent(iframeDocument));
|
|
1031
|
-
scheduleMeasure();
|
|
1032
|
-
};
|
|
1033
|
-
scrollMountObserver = new MutationObserver(syncScrollContent);
|
|
1034
|
-
scrollMountObserver.observe(iframeDocument.documentElement, {
|
|
1035
|
-
attributes: true,
|
|
1036
|
-
attributeFilter: ["class"]
|
|
1037
|
-
});
|
|
1038
|
-
scrollMountObserver.observe(iframeDocument.body, {
|
|
1039
|
-
childList: true,
|
|
1040
|
-
subtree: true
|
|
1041
|
-
});
|
|
1042
|
-
syncScrollContent();
|
|
1043
|
-
} catch {
|
|
1044
|
-
if (height.value !== 24) height.value = 24;
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
const handleIframeLoad = () => observeContent();
|
|
1048
|
-
const setIframe = (nextIframe) => {
|
|
1049
|
-
if (iframe === nextIframe) return;
|
|
1050
|
-
iframe?.removeEventListener("load", handleIframeLoad);
|
|
1051
|
-
disconnectContent();
|
|
1052
|
-
iframe = nextIframe;
|
|
1053
|
-
if (!iframe) {
|
|
1054
|
-
height.value = 24;
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
iframe.addEventListener("load", handleIframeLoad);
|
|
1058
|
-
iframe.style.height = `${Math.max(window.innerHeight, 24)}px`;
|
|
1059
|
-
observeContent();
|
|
1060
|
-
};
|
|
1061
|
-
const syncIframe = () => setIframe(container?.querySelector("iframe") || null);
|
|
1062
|
-
const setContainer = (nextContainer) => {
|
|
1063
|
-
if (container === nextContainer) return;
|
|
1064
|
-
containerObserver?.disconnect();
|
|
1065
|
-
containerObserver = null;
|
|
1066
|
-
container = nextContainer;
|
|
1067
|
-
setIframe(null);
|
|
1068
|
-
if (!container) return;
|
|
1069
|
-
containerObserver = new MutationObserver(syncIframe);
|
|
1070
|
-
containerObserver.observe(container, {
|
|
1071
|
-
childList: true,
|
|
1072
|
-
subtree: true
|
|
1073
|
-
});
|
|
1074
|
-
syncIframe();
|
|
1075
|
-
};
|
|
1076
|
-
(0, vue.watch)(() => resolveSandboxContainer(sandboxRef.value), setContainer, {
|
|
1077
|
-
flush: "post",
|
|
1078
|
-
immediate: true
|
|
1079
|
-
});
|
|
1080
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
1081
|
-
setContainer(null);
|
|
1082
|
-
cancelMeasure();
|
|
1083
|
-
});
|
|
1084
|
-
return height;
|
|
1085
|
-
};
|
|
1086
840
|
var resolvePreviewBoxHeight = (contentHeight, verticalInset = 0, borderWidth = 1) => {
|
|
1087
841
|
const content = Number.isFinite(contentHeight) ? Math.max(0, contentHeight) : 0;
|
|
1088
842
|
const inset = Number.isFinite(verticalInset) ? Math.max(0, verticalInset) : 0;
|
|
@@ -1161,68 +915,6 @@ var scrollPlaygroundToViewportStart = (el) => {
|
|
|
1161
915
|
});
|
|
1162
916
|
};
|
|
1163
917
|
//#endregion
|
|
1164
|
-
//#region packages/playground/src/core/runtime/error-guard.ts
|
|
1165
|
-
var UNKNOWN_RUNTIME_ERROR = "运行时发生未知错误";
|
|
1166
|
-
var MODULE_SPECIFIER_RE = /Failed to resolve module specifier|Error resolving module specifier/u;
|
|
1167
|
-
var forwardSandboxRuntimeError = (event) => {
|
|
1168
|
-
if (!(event instanceof ErrorEvent) || event.error != null || !event.message) return;
|
|
1169
|
-
event.stopImmediatePropagation();
|
|
1170
|
-
if (event.message === "ResizeObserver loop limit exceeded" || event.message === "ResizeObserver loop completed with undelivered notifications.") return;
|
|
1171
|
-
window.parent.postMessage({
|
|
1172
|
-
action: "error",
|
|
1173
|
-
value: event.message
|
|
1174
|
-
}, "*");
|
|
1175
|
-
};
|
|
1176
|
-
var SANDBOX_RUNTIME_ERROR_CAPTURE_HTML = [
|
|
1177
|
-
"<script>",
|
|
1178
|
-
`window.addEventListener('error', ${forwardSandboxRuntimeError.toString()}, true);`,
|
|
1179
|
-
"<\/script>"
|
|
1180
|
-
].join("\n");
|
|
1181
|
-
var toRuntimeErrorMessage = (value, message) => {
|
|
1182
|
-
if (typeof value === "string" && value) return value;
|
|
1183
|
-
if (value instanceof Error && value.message) return value.message;
|
|
1184
|
-
if (value && typeof value === "object" && "message" in value) {
|
|
1185
|
-
const valueMessage = value.message;
|
|
1186
|
-
if (typeof valueMessage === "string" && valueMessage) return valueMessage;
|
|
1187
|
-
}
|
|
1188
|
-
if (typeof message === "string" && message) return message;
|
|
1189
|
-
if (value !== null && value !== void 0) try {
|
|
1190
|
-
return String(value);
|
|
1191
|
-
} catch {
|
|
1192
|
-
return UNKNOWN_RUNTIME_ERROR;
|
|
1193
|
-
}
|
|
1194
|
-
return UNKNOWN_RUNTIME_ERROR;
|
|
1195
|
-
};
|
|
1196
|
-
var normalizeRuntimeErrorMessage = (data) => {
|
|
1197
|
-
if (!data || typeof data !== "object") return false;
|
|
1198
|
-
const message = data;
|
|
1199
|
-
if (message.action !== "error") return false;
|
|
1200
|
-
message.value = toRuntimeErrorMessage(message.value, message.message);
|
|
1201
|
-
return true;
|
|
1202
|
-
};
|
|
1203
|
-
var toErrorText = (value) => {
|
|
1204
|
-
if (typeof value === "string" && value) return value;
|
|
1205
|
-
if (value instanceof Error && value.message) return value.message;
|
|
1206
|
-
return "";
|
|
1207
|
-
};
|
|
1208
|
-
var formatSandboxRuntimeError = (message, importMapTip) => {
|
|
1209
|
-
if (!MODULE_SPECIFIER_RE.test(message)) return message;
|
|
1210
|
-
return `${message.replace(/\. Relative references must.*$/u, "").replace(/\.$/u, "")}.\n${importMapTip}`;
|
|
1211
|
-
};
|
|
1212
|
-
var useSandboxRuntimeErrorGuard = (sandboxRef) => {
|
|
1213
|
-
const error = (0, vue.ref)("");
|
|
1214
|
-
if (typeof window === "undefined") return error;
|
|
1215
|
-
const handleMessage = (event) => {
|
|
1216
|
-
const iframe = resolveSandboxContainer(sandboxRef.value)?.querySelector("iframe");
|
|
1217
|
-
if (!iframe || event.source !== iframe.contentWindow) return;
|
|
1218
|
-
if (!normalizeRuntimeErrorMessage(event.data)) return;
|
|
1219
|
-
error.value = event.data.value;
|
|
1220
|
-
};
|
|
1221
|
-
window.addEventListener("message", handleMessage, true);
|
|
1222
|
-
(0, vue.onBeforeUnmount)(() => window.removeEventListener("message", handleMessage, true));
|
|
1223
|
-
return error;
|
|
1224
|
-
};
|
|
1225
|
-
//#endregion
|
|
1226
918
|
//#region packages/playground/src/core/runtime/viewport.ts
|
|
1227
919
|
var DEFAULT_VIEWPORT_OPTIONS = ["auto", 375];
|
|
1228
920
|
var isValidViewport = (viewport) => {
|
|
@@ -1386,7 +1078,7 @@ var useSandboxTheme = (sandboxRef) => {
|
|
|
1386
1078
|
}
|
|
1387
1079
|
syncIframe();
|
|
1388
1080
|
};
|
|
1389
|
-
(0, vue.watch)(() => resolveSandboxContainer(sandboxRef.value), setContainer, {
|
|
1081
|
+
(0, vue.watch)(() => require_store.resolveSandboxContainer(sandboxRef.value), setContainer, {
|
|
1390
1082
|
flush: "post",
|
|
1391
1083
|
immediate: true
|
|
1392
1084
|
});
|
|
@@ -1428,16 +1120,16 @@ function usePreviewHeightBridge(sandbox, maxHeight = () => Infinity) {
|
|
|
1428
1120
|
sync();
|
|
1429
1121
|
};
|
|
1430
1122
|
const handleMessage = async (event) => {
|
|
1431
|
-
const
|
|
1123
|
+
const current = require_store.resolveSandboxMessageSource(sandbox.value);
|
|
1432
1124
|
const data = event.data;
|
|
1433
|
-
if (!
|
|
1125
|
+
if (!current || event.source !== current || data?.action !== "docs:height" || typeof data.session !== "string") return;
|
|
1434
1126
|
if (data.operation === "start") {
|
|
1435
1127
|
reset();
|
|
1436
|
-
source =
|
|
1128
|
+
source = current;
|
|
1437
1129
|
session = data.session;
|
|
1438
1130
|
return;
|
|
1439
1131
|
}
|
|
1440
|
-
if (source !==
|
|
1132
|
+
if (source !== current || session !== data.session) return;
|
|
1441
1133
|
if (data.operation === "stop") {
|
|
1442
1134
|
reset();
|
|
1443
1135
|
return;
|
|
@@ -1462,7 +1154,7 @@ function usePreviewHeightBridge(sandbox, maxHeight = () => Infinity) {
|
|
|
1462
1154
|
accepted
|
|
1463
1155
|
}, "*");
|
|
1464
1156
|
};
|
|
1465
|
-
(0, vue.watch)(() =>
|
|
1157
|
+
(0, vue.watch)(() => require_store.resolveSandboxMessageSource(sandbox.value), reset, { flush: "sync" });
|
|
1466
1158
|
if (typeof window !== "undefined") window.addEventListener("message", handleMessage);
|
|
1467
1159
|
(0, vue.onBeforeUnmount)(() => {
|
|
1468
1160
|
disposed = true;
|
|
@@ -1496,7 +1188,7 @@ var _hoisted_8$1 = {
|
|
|
1496
1188
|
class: "docs-playground__tool-divider",
|
|
1497
1189
|
"aria-hidden": "true"
|
|
1498
1190
|
};
|
|
1499
|
-
var _hoisted_9
|
|
1191
|
+
var _hoisted_9 = ["aria-label"];
|
|
1500
1192
|
var _hoisted_10 = [
|
|
1501
1193
|
"title",
|
|
1502
1194
|
"aria-label",
|
|
@@ -1669,7 +1361,7 @@ var toolbar_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
1669
1361
|
"aria-pressed": item === __props.activeView,
|
|
1670
1362
|
onClick: ($event) => emit("view-change", item)
|
|
1671
1363
|
}, (0, vue.toDisplayString)(getViewLabel(item)), 11, _hoisted_10);
|
|
1672
|
-
}), 128))], 8, _hoisted_9
|
|
1364
|
+
}), 128))], 8, _hoisted_9)) : (0, vue.createCommentVNode)("v-if", true),
|
|
1673
1365
|
__props.showClose && (__props.showRuntimeActions || showViews.value) ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", _hoisted_11)) : (0, vue.createCommentVNode)("v-if", true),
|
|
1674
1366
|
__props.showClose ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
|
|
1675
1367
|
key: 3,
|
|
@@ -1688,647 +1380,6 @@ var toolbar_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
1688
1380
|
}
|
|
1689
1381
|
});
|
|
1690
1382
|
//#endregion
|
|
1691
|
-
//#region packages/playground/src/cdn.ts
|
|
1692
|
-
var PREVIEW_STYLE_ASSETS = [
|
|
1693
|
-
"@deot/style/dist/index.normalize-only.css",
|
|
1694
|
-
"@deot/vc-components/dist/index.style.css",
|
|
1695
|
-
"@deot/style/dist/index.css"
|
|
1696
|
-
];
|
|
1697
|
-
var BUILTIN_IMPORT_ASSETS = {
|
|
1698
|
-
"@deot/vc": "@deot/vc/dist/index.js",
|
|
1699
|
-
"@deot/vc-shared": "@deot/vc-shared/dist/index.js",
|
|
1700
|
-
"@deot/vc-hooks": "@deot/vc-hooks/dist/index.js",
|
|
1701
|
-
"@deot/vc-components": "@deot/vc-components/dist/index.js",
|
|
1702
|
-
"@deot/helper-resize": "@deot/helper-resize/dist/index.js",
|
|
1703
|
-
"@deot/helper-utils": "@deot/helper-utils/dist/index.js",
|
|
1704
|
-
"@deot/helper-cache": "@deot/helper-cache/dist/index.js",
|
|
1705
|
-
"@deot/helper-fp": "@deot/helper-fp/dist/index.js",
|
|
1706
|
-
"@deot/helper-dom": "@deot/helper-dom/dist/index.js",
|
|
1707
|
-
"@deot/helper-wheel": "@deot/helper-wheel/dist/index.js",
|
|
1708
|
-
"@deot/helper-validator": "@deot/helper-validator/dist/index.js",
|
|
1709
|
-
"@deot/helper-load": "@deot/helper-load/dist/index.js",
|
|
1710
|
-
"@deot/helper-scheduler": "@deot/helper-scheduler/dist/index.js",
|
|
1711
|
-
"@deot/helper-emitter": "@deot/helper-emitter/dist/index.js",
|
|
1712
|
-
"@deot/helper-is": "@deot/helper-is/dist/index.js",
|
|
1713
|
-
"@deot/helper-device": "@deot/helper-device/dist/index.js",
|
|
1714
|
-
"@deot/helper-route": "@deot/helper-route/dist/index.js",
|
|
1715
|
-
"@deot/helper-unicode": "@deot/helper-unicode/dist/index.js",
|
|
1716
|
-
"@deot/helper": "@deot/helper/dist/index.js",
|
|
1717
|
-
"normalize-wheel": "normalize-wheel-es/dist/index.mjs",
|
|
1718
|
-
"photoswipe": "photoswipe/dist/photoswipe.esm.js",
|
|
1719
|
-
"photoswipe/lightbox": "photoswipe/dist/photoswipe-lightbox.esm.js",
|
|
1720
|
-
"vue": "vue/dist/vue.runtime.esm-browser.js",
|
|
1721
|
-
"vue/server-renderer": "vue/dist/server-renderer.esm-browser.js"
|
|
1722
|
-
};
|
|
1723
|
-
var normalizeCdnURL = (cdnURL = DEFAULT_CDN_URL) => {
|
|
1724
|
-
return cdnURL.trim().replace(/\/+$/u, "") || "https://cdn.jsdelivr.net/npm";
|
|
1725
|
-
};
|
|
1726
|
-
var cdnJoin = (origin, asset) => `${origin}/${asset.replace(/^\/+/u, "")}`;
|
|
1727
|
-
var jsdelivrEsmURL = (asset) => cdnJoin(DEFAULT_CDN_URL, asset);
|
|
1728
|
-
var SASS_CDN_URL = jsdelivrEsmURL("sass/+esm");
|
|
1729
|
-
var cdnAsset = (cdnURL, asset) => cdnJoin(normalizeCdnURL(cdnURL), asset);
|
|
1730
|
-
var createBuiltinImports = (cdnURL = DEFAULT_CDN_URL) => ({
|
|
1731
|
-
...Object.fromEntries(Object.entries(BUILTIN_IMPORT_ASSETS).map(([specifier, asset]) => [specifier, cdnAsset(cdnURL, asset)])),
|
|
1732
|
-
"lodash-es": jsdelivrEsmURL("lodash-es/+esm")
|
|
1733
|
-
});
|
|
1734
|
-
var createBuiltinStyles = (cdnURL = DEFAULT_CDN_URL) => Object.fromEntries(PREVIEW_STYLE_ASSETS.map((asset) => [asset, cdnAsset(cdnURL, asset)]));
|
|
1735
|
-
//#endregion
|
|
1736
|
-
//#region packages/playground/src/import-map.ts
|
|
1737
|
-
/**
|
|
1738
|
-
* 站点级同步内存:`$docs.modules` / `$docs.styles` 与管理页 import、CSS 覆盖。
|
|
1739
|
-
*/
|
|
1740
|
-
var normalize = (value) => value.trim();
|
|
1741
|
-
var isSafePlaygroundHref = (href) => {
|
|
1742
|
-
const next = href.trim();
|
|
1743
|
-
if (!next) return false;
|
|
1744
|
-
if (/^https?:\/\//iu.test(next)) return true;
|
|
1745
|
-
return next.startsWith("/") && !next.startsWith("//");
|
|
1746
|
-
};
|
|
1747
|
-
var filterSafeHrefs = (value = {}) => Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string" && isSafePlaygroundHref(entry[1])));
|
|
1748
|
-
var sanitizeMap = (value = {}) => filterSafeHrefs(Object.fromEntries(Object.entries(value).map(([alias, url]) => [normalize(alias), normalize(url)]).filter(([alias]) => Boolean(alias))));
|
|
1749
|
-
var createMapStore = () => {
|
|
1750
|
-
let data = {};
|
|
1751
|
-
const snapshot = () => ({ ...data });
|
|
1752
|
-
const drop = (alias) => {
|
|
1753
|
-
if (data[alias] === void 0) return snapshot();
|
|
1754
|
-
const next = { ...data };
|
|
1755
|
-
delete next[alias];
|
|
1756
|
-
data = next;
|
|
1757
|
-
return snapshot();
|
|
1758
|
-
};
|
|
1759
|
-
return {
|
|
1760
|
-
get: snapshot,
|
|
1761
|
-
set: (value = {}) => {
|
|
1762
|
-
data = sanitizeMap(value);
|
|
1763
|
-
},
|
|
1764
|
-
apply: (alias, url) => {
|
|
1765
|
-
const nextAlias = normalize(alias);
|
|
1766
|
-
const nextUrl = normalize(url);
|
|
1767
|
-
if (!nextAlias) return snapshot();
|
|
1768
|
-
if (!isSafePlaygroundHref(nextUrl)) return drop(nextAlias);
|
|
1769
|
-
data = {
|
|
1770
|
-
...data,
|
|
1771
|
-
[nextAlias]: nextUrl
|
|
1772
|
-
};
|
|
1773
|
-
return snapshot();
|
|
1774
|
-
},
|
|
1775
|
-
remove: (alias) => {
|
|
1776
|
-
const nextAlias = normalize(alias);
|
|
1777
|
-
return nextAlias ? drop(nextAlias) : snapshot();
|
|
1778
|
-
}
|
|
1779
|
-
};
|
|
1780
|
-
};
|
|
1781
|
-
var siteModules = createMapStore();
|
|
1782
|
-
var siteStyles = createMapStore();
|
|
1783
|
-
var importOverrides = createMapStore();
|
|
1784
|
-
var styleOverrides = createMapStore();
|
|
1785
|
-
/**
|
|
1786
|
-
* 站点默认 import。合并时夹在内置 CDN 与实例 `builtinImportMap` 之间。
|
|
1787
|
-
*/
|
|
1788
|
-
var getPlaygroundSiteModules = siteModules.get;
|
|
1789
|
-
var setPlaygroundSiteModules = siteModules.set;
|
|
1790
|
-
/**
|
|
1791
|
-
* 站点默认预览 CSS。合并时夹在内置样式表与管理页覆盖之间。
|
|
1792
|
-
*/
|
|
1793
|
-
var getPlaygroundSiteStyles = siteStyles.get;
|
|
1794
|
-
var setPlaygroundSiteStyles = siteStyles.set;
|
|
1795
|
-
var getPlaygroundImportMapOverrides = importOverrides.get;
|
|
1796
|
-
var setPlaygroundImportMapOverrides = importOverrides.set;
|
|
1797
|
-
var applyPlaygroundImportMapOverride = importOverrides.apply;
|
|
1798
|
-
var removePlaygroundImportMapOverride = importOverrides.remove;
|
|
1799
|
-
var getPlaygroundStyleOverrides = styleOverrides.get;
|
|
1800
|
-
var setPlaygroundStyleOverrides = styleOverrides.set;
|
|
1801
|
-
var applyPlaygroundStyleOverride = styleOverrides.apply;
|
|
1802
|
-
var removePlaygroundStyleOverride = styleOverrides.remove;
|
|
1803
|
-
var clearPlaygroundMaps = () => {
|
|
1804
|
-
[
|
|
1805
|
-
siteModules,
|
|
1806
|
-
siteStyles,
|
|
1807
|
-
importOverrides,
|
|
1808
|
-
styleOverrides
|
|
1809
|
-
].forEach((store) => store.set());
|
|
1810
|
-
};
|
|
1811
|
-
//#endregion
|
|
1812
|
-
//#region packages/playground/src/preview-service.ts
|
|
1813
|
-
/** Preview iframe 内的高度服务;class 会被序列化到 iframe 执行。 */
|
|
1814
|
-
var PlaygroundService = class {
|
|
1815
|
-
target;
|
|
1816
|
-
vue;
|
|
1817
|
-
session;
|
|
1818
|
-
/* istanbul ignore next -- class 会被序列化到没有覆盖率运行时的 iframe。 */
|
|
1819
|
-
sequence = 0;
|
|
1820
|
-
/* istanbul ignore next -- class 会被序列化到没有覆盖率运行时的 iframe。 */
|
|
1821
|
-
disposed = false;
|
|
1822
|
-
manual;
|
|
1823
|
-
/* istanbul ignore next -- class 会被序列化到没有覆盖率运行时的 iframe。 */
|
|
1824
|
-
requests = /* @__PURE__ */ new Set();
|
|
1825
|
-
/* istanbul ignore next -- class 会被序列化到没有覆盖率运行时的 iframe。 */
|
|
1826
|
-
owners = /* @__PURE__ */ new Set();
|
|
1827
|
-
/**
|
|
1828
|
-
* @param target 当前预览窗口。
|
|
1829
|
-
* @param vue 与预览应用共用的 Vue 实例。
|
|
1830
|
-
*/
|
|
1831
|
-
/* istanbul ignore next -- class 会被序列化到没有覆盖率运行时的 iframe。 */
|
|
1832
|
-
constructor(target, vue) {
|
|
1833
|
-
this.target = target;
|
|
1834
|
-
this.vue = vue;
|
|
1835
|
-
this.session = `${Date.now()}-${Math.random()}`;
|
|
1836
|
-
this.dispose = this.dispose.bind(this);
|
|
1837
|
-
this.post("start");
|
|
1838
|
-
this.target.addEventListener("pagehide", this.dispose);
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* 申请手动临时高度;新请求会替换上一个手动请求。
|
|
1842
|
-
* @param height iframe 最小高度。
|
|
1843
|
-
* @returns iframe 是否在超时前应用目标高度。
|
|
1844
|
-
*/
|
|
1845
|
-
enable(height) {
|
|
1846
|
-
this.validateHeight(height);
|
|
1847
|
-
this.manual?.release();
|
|
1848
|
-
this.manual = this.createRequest(height);
|
|
1849
|
-
return this.manual.ready;
|
|
1850
|
-
}
|
|
1851
|
-
/** 释放手动临时高度,不影响 `run` 创建的请求。 */
|
|
1852
|
-
disable() {
|
|
1853
|
-
this.manual?.release();
|
|
1854
|
-
this.manual = void 0;
|
|
1855
|
-
}
|
|
1856
|
-
/**
|
|
1857
|
-
* 创建等待高度后执行的事件处理函数。
|
|
1858
|
-
* @param height iframe 最小高度。
|
|
1859
|
-
* @param optionsOrHandler 可见状态配置,或最后一个 handler。
|
|
1860
|
-
* @param lastHandler 使用配置时的最后一个 handler。
|
|
1861
|
-
* @returns 保留 handler 参数和结果的异步事件处理函数。
|
|
1862
|
-
*/
|
|
1863
|
-
run(height, optionsOrHandler, lastHandler) {
|
|
1864
|
-
this.validateHeight(height);
|
|
1865
|
-
if (optionsOrHandler === void 0) return (visible) => {
|
|
1866
|
-
if (visible) return this.enable(height);
|
|
1867
|
-
this.disable();
|
|
1868
|
-
return Promise.resolve(void 0);
|
|
1869
|
-
};
|
|
1870
|
-
const visible = (typeof optionsOrHandler === "function" ? {} : optionsOrHandler).visible;
|
|
1871
|
-
if (visible !== void 0 && !this.vue.isRef(visible) && typeof visible !== "function") throw new TypeError("Playground visible must be a ref or getter");
|
|
1872
|
-
const handler = typeof optionsOrHandler === "function" ? optionsOrHandler : lastHandler ?? (this.vue.isRef(visible) ? () => {
|
|
1873
|
-
visible.value = true;
|
|
1874
|
-
} : void 0);
|
|
1875
|
-
if (typeof handler !== "function") throw new TypeError("Playground run requires a handler");
|
|
1876
|
-
let ownerDisposed = false;
|
|
1877
|
-
let current;
|
|
1878
|
-
let pending;
|
|
1879
|
-
const disposeOwner = () => {
|
|
1880
|
-
ownerDisposed = true;
|
|
1881
|
-
current?.release();
|
|
1882
|
-
this.owners.delete(disposeOwner);
|
|
1883
|
-
};
|
|
1884
|
-
this.owners.add(disposeOwner);
|
|
1885
|
-
if (this.vue.getCurrentScope()) this.vue.onScopeDispose(disposeOwner);
|
|
1886
|
-
return (...args) => {
|
|
1887
|
-
if (this.disposed || ownerDisposed) return Promise.resolve(void 0);
|
|
1888
|
-
if (pending) return pending;
|
|
1889
|
-
const request = current = this.createRequest(height);
|
|
1890
|
-
let executionFinished = false;
|
|
1891
|
-
const unlock = () => {
|
|
1892
|
-
if (executionFinished && request.released && current === request) {
|
|
1893
|
-
pending = void 0;
|
|
1894
|
-
current = void 0;
|
|
1895
|
-
}
|
|
1896
|
-
};
|
|
1897
|
-
request.closed.then(unlock);
|
|
1898
|
-
const execution = (async () => {
|
|
1899
|
-
try {
|
|
1900
|
-
if (!await request.ready || ownerDisposed || this.disposed) return void 0;
|
|
1901
|
-
if (visible) request.watch(visible);
|
|
1902
|
-
const result = await handler(...args);
|
|
1903
|
-
if (!visible || !this.vue.toValue(visible)) request.release();
|
|
1904
|
-
return result;
|
|
1905
|
-
} catch (error) {
|
|
1906
|
-
request.release();
|
|
1907
|
-
throw error;
|
|
1908
|
-
} finally {
|
|
1909
|
-
executionFinished = true;
|
|
1910
|
-
unlock();
|
|
1911
|
-
}
|
|
1912
|
-
})();
|
|
1913
|
-
pending = execution;
|
|
1914
|
-
return execution;
|
|
1915
|
-
};
|
|
1916
|
-
}
|
|
1917
|
-
/** 释放当前预览应用持有的全部高度和监听。 */
|
|
1918
|
-
/* istanbul ignore next -- 注入测试会从序列化后的 iframe class 调用该方法。 */
|
|
1919
|
-
dispose() {
|
|
1920
|
-
if (this.disposed) return;
|
|
1921
|
-
this.disposed = true;
|
|
1922
|
-
for (const disposeOwner of this.owners) disposeOwner();
|
|
1923
|
-
for (const request of this.requests) request.release();
|
|
1924
|
-
this.post("stop");
|
|
1925
|
-
this.target.removeEventListener("pagehide", this.dispose);
|
|
1926
|
-
if (this.target.$docsPlayground === this) delete this.target.$docsPlayground;
|
|
1927
|
-
}
|
|
1928
|
-
/** @param height iframe 最小高度。 */
|
|
1929
|
-
validateHeight(height) {
|
|
1930
|
-
if (!Number.isFinite(height) || height <= 0) throw new TypeError("Playground height must be a positive finite number");
|
|
1931
|
-
}
|
|
1932
|
-
/**
|
|
1933
|
-
* @param operation 请求操作。
|
|
1934
|
-
* @param id 请求标识。
|
|
1935
|
-
* @param height iframe 最小高度。
|
|
1936
|
-
*/
|
|
1937
|
-
/* istanbul ignore next -- 构造和销毁时会从序列化后的 iframe class 调用该方法。 */
|
|
1938
|
-
post(operation, id = 0, height = 0) {
|
|
1939
|
-
this.target.parent.postMessage({
|
|
1940
|
-
action: "docs:height",
|
|
1941
|
-
session: this.session,
|
|
1942
|
-
operation,
|
|
1943
|
-
id,
|
|
1944
|
-
height
|
|
1945
|
-
}, "*");
|
|
1946
|
-
}
|
|
1947
|
-
/**
|
|
1948
|
-
* @param height iframe 最小高度。
|
|
1949
|
-
* @returns 内部等待与释放句柄。
|
|
1950
|
-
*/
|
|
1951
|
-
createRequest(height) {
|
|
1952
|
-
this.validateHeight(height);
|
|
1953
|
-
const id = ++this.sequence;
|
|
1954
|
-
let released = false;
|
|
1955
|
-
let settled = false;
|
|
1956
|
-
let frame = 0;
|
|
1957
|
-
let timer = 0;
|
|
1958
|
-
let stopWatch;
|
|
1959
|
-
let resolveReady;
|
|
1960
|
-
let resolveClosed;
|
|
1961
|
-
const ready = new Promise((resolve) => {
|
|
1962
|
-
resolveReady = resolve;
|
|
1963
|
-
});
|
|
1964
|
-
const closed = new Promise((resolve) => {
|
|
1965
|
-
resolveClosed = resolve;
|
|
1966
|
-
});
|
|
1967
|
-
const stopWaiting = () => {
|
|
1968
|
-
this.target.cancelAnimationFrame(frame);
|
|
1969
|
-
if (timer) {
|
|
1970
|
-
this.target.clearTimeout(timer);
|
|
1971
|
-
timer = 0;
|
|
1972
|
-
}
|
|
1973
|
-
this.target.removeEventListener("message", onMessage);
|
|
1974
|
-
};
|
|
1975
|
-
const release = () => {
|
|
1976
|
-
if (released) return;
|
|
1977
|
-
released = true;
|
|
1978
|
-
stopWaiting();
|
|
1979
|
-
stopWatch?.();
|
|
1980
|
-
resolveReady(false);
|
|
1981
|
-
resolveClosed();
|
|
1982
|
-
this.requests.delete(request);
|
|
1983
|
-
this.post("release", id);
|
|
1984
|
-
};
|
|
1985
|
-
const check = () => {
|
|
1986
|
-
if (released) return;
|
|
1987
|
-
if (this.target.innerHeight >= height) {
|
|
1988
|
-
settled = true;
|
|
1989
|
-
stopWaiting();
|
|
1990
|
-
resolveReady(true);
|
|
1991
|
-
} else frame = this.target.requestAnimationFrame(check);
|
|
1992
|
-
};
|
|
1993
|
-
const onMessage = (event) => {
|
|
1994
|
-
const data = event.data;
|
|
1995
|
-
if (event.source !== this.target.parent || data?.action !== "docs:height:applied" || data.session !== this.session || data.id !== id || settled) return;
|
|
1996
|
-
if (!data.accepted) release();
|
|
1997
|
-
else check();
|
|
1998
|
-
};
|
|
1999
|
-
const request = {
|
|
2000
|
-
ready,
|
|
2001
|
-
closed,
|
|
2002
|
-
get released() {
|
|
2003
|
-
return released;
|
|
2004
|
-
},
|
|
2005
|
-
release,
|
|
2006
|
-
watch: (visible) => {
|
|
2007
|
-
stopWatch = this.vue.watch(() => this.vue.toValue(visible), (value) => {
|
|
2008
|
-
if (!value) release();
|
|
2009
|
-
}, { flush: "sync" });
|
|
2010
|
-
}
|
|
2011
|
-
};
|
|
2012
|
-
this.requests.add(request);
|
|
2013
|
-
if (this.disposed) release();
|
|
2014
|
-
else {
|
|
2015
|
-
this.target.addEventListener("message", onMessage);
|
|
2016
|
-
timer = this.target.setTimeout(() => {
|
|
2017
|
-
timer = 0;
|
|
2018
|
-
release();
|
|
2019
|
-
}, 2e3);
|
|
2020
|
-
this.post("enable", id, height);
|
|
2021
|
-
}
|
|
2022
|
-
return request;
|
|
2023
|
-
}
|
|
2024
|
-
};
|
|
2025
|
-
var PREVIEW_SERVICE_IMPORT_CODE = "import * as __docsPreviewVue from \"vue\"";
|
|
2026
|
-
var PREVIEW_SERVICE_USE_CODE = [
|
|
2027
|
-
`;const __docsPlayground=new (${PlaygroundService.toString()})(window,__docsPreviewVue);`,
|
|
2028
|
-
"app.provide(\"docs:playground\",__docsPlayground);",
|
|
2029
|
-
"window.$docsPlayground=__docsPlayground;",
|
|
2030
|
-
"app.mixin({beforeUnmount(){if(this===this.$root)__docsPlayground.dispose()}});"
|
|
2031
|
-
].join("");
|
|
2032
|
-
//#endregion
|
|
2033
|
-
//#region packages/playground/src/core/scss.ts
|
|
2034
|
-
var SCHEME = "docs-playground";
|
|
2035
|
-
var STYLE_EXTS = [".scss", ".sass"];
|
|
2036
|
-
var VUE_SCSS_STYLE_RE = /<style\b[^>]*\blang\s*=\s*(['"]?)s[ac]ss\1/i;
|
|
2037
|
-
var LANG_ATTR_RE = /\s*lang\s*=\s*(['"]?)s[ac]ss\1/i;
|
|
2038
|
-
var SCSS_ERROR_MARK = "[playground-sass]";
|
|
2039
|
-
var INJECT_START = "/* docs-playground-scss-start */";
|
|
2040
|
-
var INJECT_END = "/* docs-playground-scss-end */";
|
|
2041
|
-
var EMPTY_JS = "export default {}\n";
|
|
2042
|
-
var boundStores = /* @__PURE__ */ new WeakSet();
|
|
2043
|
-
var wrappedCompilers = /* @__PURE__ */ new WeakSet();
|
|
2044
|
-
var testLoader;
|
|
2045
|
-
var loadedSass;
|
|
2046
|
-
var loadPromise;
|
|
2047
|
-
var fileCode = (value) => typeof value === "string" ? value : value.code;
|
|
2048
|
-
var playgroundPath = (url) => decodeURIComponent(url.pathname.replace(/^\/+/u, ""));
|
|
2049
|
-
var toPlaygroundUrl = (filename) => new URL(`${SCHEME}:///${filename.replace(/^\/+/u, "")}`);
|
|
2050
|
-
var basename = (path) => path.split("/").pop() || path;
|
|
2051
|
-
var scssSyntax = (filename, lang) => lang === "sass" || /\.sass$/i.test(filename) ? "indented" : "scss";
|
|
2052
|
-
var errorText = (item) => item instanceof Error ? item.message : String(item);
|
|
2053
|
-
var isScssFile = (filename) => /\.s[ac]ss$/i.test(filename);
|
|
2054
|
-
var vueSourceNeedsScss = (source) => VUE_SCSS_STYLE_RE.test(source);
|
|
2055
|
-
var resolveSassModule = async (url) => {
|
|
2056
|
-
const mod = await import(
|
|
2057
|
-
/* @vite-ignore */
|
|
2058
|
-
url
|
|
2059
|
-
);
|
|
2060
|
-
const sass = typeof mod.compileString === "function" ? mod : mod.default;
|
|
2061
|
-
if (typeof sass?.compileString !== "function") throw new Error(`Sass module at ${url} does not export compileString`);
|
|
2062
|
-
return sass;
|
|
2063
|
-
};
|
|
2064
|
-
var loadSass = () => {
|
|
2065
|
-
loadPromise ??= (testLoader ?? (() => resolveSassModule(SASS_CDN_URL)))().then((sass) => {
|
|
2066
|
-
loadedSass = sass;
|
|
2067
|
-
return sass;
|
|
2068
|
-
});
|
|
2069
|
-
return loadPromise;
|
|
2070
|
-
};
|
|
2071
|
-
var isScssPartial = (filename) => isScssFile(filename) && basename(filename).startsWith("_");
|
|
2072
|
-
var filesNeedScss = (files) => Object.entries(files).some(([filename, value]) => isScssFile(filename) || /\.vue$/i.test(filename) && vueSourceNeedsScss(fileCode(value)));
|
|
2073
|
-
var whenSassReady = (files, run) => {
|
|
2074
|
-
if (!filesNeedScss(files) || loadedSass) run();
|
|
2075
|
-
else loadSass().then(run);
|
|
2076
|
-
};
|
|
2077
|
-
var toPlaygroundFileMap = (files) => Object.fromEntries(Object.entries(files).map(([filename, value]) => [filename, fileCode(value)]));
|
|
2078
|
-
var formatScssError = (filename, message) => `${SCSS_ERROR_MARK} ${filename}: ${message}`;
|
|
2079
|
-
var scssFail = (filename, error) => formatScssError(filename, errorText(error));
|
|
2080
|
-
var withUnderscore = (path) => {
|
|
2081
|
-
const base = basename(path);
|
|
2082
|
-
if (base.startsWith("_")) return path;
|
|
2083
|
-
return `${path.slice(0, -base.length)}_${base}`;
|
|
2084
|
-
};
|
|
2085
|
-
var matchFileKey = (files, path) => [
|
|
2086
|
-
path,
|
|
2087
|
-
path.startsWith("src/") ? path : `src/${path}`,
|
|
2088
|
-
path.replace(/^src\//u, "")
|
|
2089
|
-
].find((key) => files[key] !== void 0);
|
|
2090
|
-
var stylesheetCandidates = (requestPath) => {
|
|
2091
|
-
if (isScssFile(requestPath)) return [requestPath, withUnderscore(requestPath)];
|
|
2092
|
-
return STYLE_EXTS.flatMap((ext) => [
|
|
2093
|
-
`${requestPath}${ext}`,
|
|
2094
|
-
withUnderscore(`${requestPath}${ext}`),
|
|
2095
|
-
`${requestPath}/index${ext}`,
|
|
2096
|
-
withUnderscore(`${requestPath}/index${ext}`)
|
|
2097
|
-
]);
|
|
2098
|
-
};
|
|
2099
|
-
var resolvePlaygroundStylesheet = (files, requestPath) => {
|
|
2100
|
-
const found = [...new Set(stylesheetCandidates(requestPath).map((path) => matchFileKey(files, path)).filter((key) => Boolean(key)))];
|
|
2101
|
-
if (found.length > 1) throw new Error(`Ambiguous Sass import "${requestPath}": ${found.join(", ")}`);
|
|
2102
|
-
return found[0] ?? null;
|
|
2103
|
-
};
|
|
2104
|
-
var createPlaygroundImporter = (getFiles) => ({
|
|
2105
|
-
canonicalize(url, context) {
|
|
2106
|
-
if (/^[a-zA-Z][\w+.-]*:/u.test(url) && !url.startsWith(`${SCHEME}:`)) return null;
|
|
2107
|
-
try {
|
|
2108
|
-
const resolved = resolvePlaygroundStylesheet(getFiles(), playgroundPath(new URL(url, context.containingUrl ?? toPlaygroundUrl(""))));
|
|
2109
|
-
return resolved ? toPlaygroundUrl(resolved) : null;
|
|
2110
|
-
} catch {
|
|
2111
|
-
return null;
|
|
2112
|
-
}
|
|
2113
|
-
},
|
|
2114
|
-
load(canonicalUrl) {
|
|
2115
|
-
const files = getFiles();
|
|
2116
|
-
const key = playgroundPath(canonicalUrl);
|
|
2117
|
-
return files[key] === void 0 ? null : {
|
|
2118
|
-
contents: files[key],
|
|
2119
|
-
syntax: scssSyntax(key)
|
|
2120
|
-
};
|
|
2121
|
-
}
|
|
2122
|
-
});
|
|
2123
|
-
var compileScssSource = (source, filename, sass, files, lang) => {
|
|
2124
|
-
const importer = createPlaygroundImporter(() => files);
|
|
2125
|
-
return sass.compileString(source, {
|
|
2126
|
-
syntax: scssSyntax(filename, lang),
|
|
2127
|
-
url: toPlaygroundUrl(filename),
|
|
2128
|
-
importer,
|
|
2129
|
-
importers: [importer]
|
|
2130
|
-
}).css;
|
|
2131
|
-
};
|
|
2132
|
-
var rewriteVueSfcStyles = (source, filename, parse, sass, files) => {
|
|
2133
|
-
const scssStyles = parse(source, { filename }).descriptor.styles.filter((style) => style.lang === "scss" || style.lang === "sass");
|
|
2134
|
-
if (!scssStyles.length) return {
|
|
2135
|
-
code: source,
|
|
2136
|
-
errors: []
|
|
2137
|
-
};
|
|
2138
|
-
const errors = [];
|
|
2139
|
-
let code = source;
|
|
2140
|
-
for (const style of [...scssStyles].sort((left, right) => right.loc.start.offset - left.loc.start.offset)) {
|
|
2141
|
-
const before = code.slice(0, style.loc.start.offset);
|
|
2142
|
-
const after = code.slice(style.loc.end.offset);
|
|
2143
|
-
const openStart = before.lastIndexOf("<style");
|
|
2144
|
-
if (openStart < 0) {
|
|
2145
|
-
errors.push(formatScssError(filename, "unable to locate <style> opening tag"));
|
|
2146
|
-
continue;
|
|
2147
|
-
}
|
|
2148
|
-
try {
|
|
2149
|
-
const css = compileScssSource(style.content, filename, sass, files, style.lang);
|
|
2150
|
-
code = `${before.slice(0, openStart)}${before.slice(openStart).replace(LANG_ATTR_RE, "")}${css}${after}`;
|
|
2151
|
-
} catch (error) {
|
|
2152
|
-
errors.push(scssFail(filename, error));
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
return {
|
|
2156
|
-
code,
|
|
2157
|
-
errors
|
|
2158
|
-
};
|
|
2159
|
-
};
|
|
2160
|
-
var appendParseErrors = (result, errors) => errors.length ? {
|
|
2161
|
-
...result,
|
|
2162
|
-
errors: [...result.errors, ...errors.map((item) => new Error(item))]
|
|
2163
|
-
} : result;
|
|
2164
|
-
var wrapCompiler = (compiler, getFiles) => {
|
|
2165
|
-
if (wrappedCompilers.has(compiler)) return compiler;
|
|
2166
|
-
const originalParse = compiler.parse.bind(compiler);
|
|
2167
|
-
const wrapped = { ...compiler };
|
|
2168
|
-
wrapped.parse = ((source, options) => {
|
|
2169
|
-
const filename = options?.filename || "anonymous.vue";
|
|
2170
|
-
if (!vueSourceNeedsScss(source)) return originalParse(source, options);
|
|
2171
|
-
const rewritten = loadedSass ? rewriteVueSfcStyles(source, filename, originalParse, loadedSass, getFiles()) : {
|
|
2172
|
-
code: source,
|
|
2173
|
-
errors: [formatScssError(filename, "compiler is not loaded")]
|
|
2174
|
-
};
|
|
2175
|
-
return appendParseErrors(originalParse(rewritten.errors.length ? source : rewritten.code, options), rewritten.errors);
|
|
2176
|
-
});
|
|
2177
|
-
wrappedCompilers.add(wrapped);
|
|
2178
|
-
return wrapped;
|
|
2179
|
-
};
|
|
2180
|
-
var withInjectedCss = (css, extra) => {
|
|
2181
|
-
const start = css.indexOf(INJECT_START);
|
|
2182
|
-
const end = start < 0 ? -1 : css.indexOf(INJECT_END, start);
|
|
2183
|
-
const base = (start < 0 ? css : `${css.slice(0, start)}${end >= 0 ? css.slice(end + 30) : ""}`).trimEnd();
|
|
2184
|
-
if (!extra.trim()) return base;
|
|
2185
|
-
const block = `${INJECT_START}\n${extra.trim()}\n${INJECT_END}`;
|
|
2186
|
-
return base ? `${base}\n${block}` : block;
|
|
2187
|
-
};
|
|
2188
|
-
var isStandaloneScssError = (item) => {
|
|
2189
|
-
const text = errorText(item);
|
|
2190
|
-
return text.startsWith(SCSS_ERROR_MARK) && /\.s[ac]ss:/i.test(text);
|
|
2191
|
-
};
|
|
2192
|
-
var syncScssErrors = (store, scssErrors) => {
|
|
2193
|
-
const next = [...scssErrors, ...store.errors.filter((item) => !isStandaloneScssError(item))];
|
|
2194
|
-
if (next.map(String).join("\0") === store.errors.map(String).join("\0")) return;
|
|
2195
|
-
store.errors = next;
|
|
2196
|
-
};
|
|
2197
|
-
var applyStandaloneScss = (store, sass = loadedSass) => {
|
|
2198
|
-
if (!sass) return [];
|
|
2199
|
-
const fileMap = toPlaygroundFileMap(store.files);
|
|
2200
|
-
const errors = [];
|
|
2201
|
-
const injected = [];
|
|
2202
|
-
for (const [filename, file] of Object.entries(store.files)) {
|
|
2203
|
-
if (!isScssFile(filename) || !file.compiled) continue;
|
|
2204
|
-
try {
|
|
2205
|
-
const css = compileScssSource(file.code, filename, sass, fileMap);
|
|
2206
|
-
file.compiled.css = css;
|
|
2207
|
-
file.compiled.js = EMPTY_JS;
|
|
2208
|
-
file.compiled.ssr = EMPTY_JS;
|
|
2209
|
-
if (!isScssPartial(filename) && css.trim()) injected.push(css);
|
|
2210
|
-
} catch (error) {
|
|
2211
|
-
errors.push(scssFail(filename, error));
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
const main = store.files[store.mainFile];
|
|
2215
|
-
if (main?.compiled) {
|
|
2216
|
-
const next = withInjectedCss(main.compiled.css || "", injected.join("\n"));
|
|
2217
|
-
if (next !== (main.compiled.css || "")) main.compiled.css = next;
|
|
2218
|
-
}
|
|
2219
|
-
syncScssErrors(store, errors);
|
|
2220
|
-
return errors;
|
|
2221
|
-
};
|
|
2222
|
-
var bindPlaygroundScss = (store) => {
|
|
2223
|
-
if (boundStores.has(store)) return;
|
|
2224
|
-
boundStores.add(store);
|
|
2225
|
-
const getFiles = () => toPlaygroundFileMap(store.files);
|
|
2226
|
-
const installCompiler = () => {
|
|
2227
|
-
if (typeof store.compiler?.parse === "function") store.compiler = wrapCompiler(store.compiler, getFiles);
|
|
2228
|
-
};
|
|
2229
|
-
installCompiler();
|
|
2230
|
-
(0, vue.watch)(() => store.compiler, installCompiler);
|
|
2231
|
-
(0, vue.watch)(() => [
|
|
2232
|
-
store.mainFile,
|
|
2233
|
-
store.files[store.mainFile]?.compiled?.css,
|
|
2234
|
-
store.errors.map(String).join("\0"),
|
|
2235
|
-
Object.entries(store.files).filter(([filename]) => isScssFile(filename)).map(([filename, file]) => `${filename}:${file.code}`).join("\n")
|
|
2236
|
-
].join("\0"), () => {
|
|
2237
|
-
if (loadedSass) applyStandaloneScss(store);
|
|
2238
|
-
});
|
|
2239
|
-
const originalSetFiles = store.setFiles.bind(store);
|
|
2240
|
-
store.setFiles = async (newFiles, mainFile) => {
|
|
2241
|
-
if (filesNeedScss(newFiles) && !loadedSass) await loadSass();
|
|
2242
|
-
return originalSetFiles(newFiles, mainFile);
|
|
2243
|
-
};
|
|
2244
|
-
};
|
|
2245
|
-
//#endregion
|
|
2246
|
-
//#region packages/playground/src/core/store.ts
|
|
2247
|
-
var DOCS_LINK_IMPORT_CODE = "import { h as __docsH } from \"vue\"";
|
|
2248
|
-
var DOCS_LINK_USE_CODE = [
|
|
2249
|
-
PREVIEW_SCROLL_RESET_CODE,
|
|
2250
|
-
"app.component(\"DocsLink\",{",
|
|
2251
|
-
"props:{to:{type:String,default:\"\"}},",
|
|
2252
|
-
"setup(props,{slots}){return()=>__docsH(\"a\",{",
|
|
2253
|
-
"href:props.to,",
|
|
2254
|
-
"style:{color:\"inherit\",textDecoration:\"none\"},",
|
|
2255
|
-
"onClick(event){event.preventDefault();window.parent.postMessage({action:\"docs:navigate\",to:props.to},\"*\")}",
|
|
2256
|
-
"},slots.default?.())}",
|
|
2257
|
-
"})"
|
|
2258
|
-
].join("");
|
|
2259
|
-
var escapeHtmlAttr = (value) => value.replace(/&/gu, "&").replace(/"/gu, """).replace(/'/gu, "'").replace(/</gu, "<").replace(/>/gu, ">");
|
|
2260
|
-
/**
|
|
2261
|
-
* runtime 画布色。`previewInset` 露出的 padding、iframe chrome 和 sandbox
|
|
2262
|
-
* `html`/`body` 必须共用这一变量,暗色下 `--docs-background-color` 与
|
|
2263
|
-
* `--vc-background-color-light` 不同,否则会出现色带割裂。
|
|
2264
|
-
*/
|
|
2265
|
-
var PLAYGROUND_RUNTIME_CANVAS_BACKGROUND = "var(--vc-background-color-light, var(--docs-background-color, #fff))";
|
|
2266
|
-
var createRuntimePreviewOptions = (cdnURL = DEFAULT_CDN_URL, options = {}) => {
|
|
2267
|
-
const previewScroller = options.previewScroller === true;
|
|
2268
|
-
const hrefs = Object.values({
|
|
2269
|
-
...createBuiltinStyles(cdnURL),
|
|
2270
|
-
...getPlaygroundSiteStyles(),
|
|
2271
|
-
...getPlaygroundStyleOverrides()
|
|
2272
|
-
});
|
|
2273
|
-
const styleBlocks = [
|
|
2274
|
-
`html,body{height:auto;min-height:0;background:${PLAYGROUND_RUNTIME_CANVAS_BACKGROUND}}`,
|
|
2275
|
-
"body{color:var(--vc-foreground-color,#080f20)}",
|
|
2276
|
-
...previewScroller ? [PREVIEW_SCROLLER_STYLE] : []
|
|
2277
|
-
];
|
|
2278
|
-
return {
|
|
2279
|
-
showRuntimeError: false,
|
|
2280
|
-
showRuntimeWarning: false,
|
|
2281
|
-
headHTML: [
|
|
2282
|
-
SANDBOX_RUNTIME_ERROR_CAPTURE_HTML,
|
|
2283
|
-
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",
|
|
2284
|
-
...hrefs.map((href) => `<link rel="stylesheet" href="${escapeHtmlAttr(href)}">`),
|
|
2285
|
-
"<style>",
|
|
2286
|
-
...styleBlocks,
|
|
2287
|
-
"</style>"
|
|
2288
|
-
].join("\n"),
|
|
2289
|
-
customCode: {
|
|
2290
|
-
importCode: `${DOCS_LINK_IMPORT_CODE}\n${PREVIEW_SERVICE_IMPORT_CODE}`,
|
|
2291
|
-
useCode: `${DOCS_LINK_USE_CODE}\n${PREVIEW_SERVICE_USE_CODE}`
|
|
2292
|
-
}
|
|
2293
|
-
};
|
|
2294
|
-
};
|
|
2295
|
-
var toReplFilename = (filename) => filename.startsWith("src/") ? filename : `src/${filename}`;
|
|
2296
|
-
var createReplFile = (filename, code) => {
|
|
2297
|
-
const replFilename = toReplFilename(filename);
|
|
2298
|
-
return new _vue_repl.File(replFilename, code);
|
|
2299
|
-
};
|
|
2300
|
-
var createRuntimeStore = (files, entry, options) => {
|
|
2301
|
-
const { cdnURL, builtinImportMap, ...storeOptions } = options;
|
|
2302
|
-
const replFiles = (0, vue.ref)(Object.fromEntries(Object.entries(files).map(([filename, code]) => {
|
|
2303
|
-
const file = createReplFile(filename, code);
|
|
2304
|
-
return [file.filename, file];
|
|
2305
|
-
})));
|
|
2306
|
-
const mainFile = (0, vue.ref)(toReplFilename(entry));
|
|
2307
|
-
const activeFilename = (0, vue.ref)(toReplFilename(entry));
|
|
2308
|
-
const store = (0, _vue_repl.useStore)({
|
|
2309
|
-
...storeOptions,
|
|
2310
|
-
files: replFiles,
|
|
2311
|
-
mainFile,
|
|
2312
|
-
activeFilename,
|
|
2313
|
-
builtinImportMap: (0, vue.ref)({
|
|
2314
|
-
...builtinImportMap,
|
|
2315
|
-
imports: {
|
|
2316
|
-
...createBuiltinImports(cdnURL),
|
|
2317
|
-
...getPlaygroundSiteModules(),
|
|
2318
|
-
...filterSafeHrefs(builtinImportMap?.imports),
|
|
2319
|
-
...getPlaygroundImportMapOverrides()
|
|
2320
|
-
}
|
|
2321
|
-
}),
|
|
2322
|
-
template: (0, vue.ref)({
|
|
2323
|
-
welcomeSFC: files[entry],
|
|
2324
|
-
newSFC: NEW_SFC_CODE
|
|
2325
|
-
})
|
|
2326
|
-
});
|
|
2327
|
-
bindPlaygroundScss(store);
|
|
2328
|
-
whenSassReady(files, () => store.init());
|
|
2329
|
-
return store;
|
|
2330
|
-
};
|
|
2331
|
-
//#endregion
|
|
2332
1383
|
//#region packages/playground/src/core/runtime/alone/wrapper.vue?vue&type=script&setup=true&lang.ts
|
|
2333
1384
|
var _hoisted_1$2 = ["aria-label"];
|
|
2334
1385
|
var _hoisted_2$2 = { class: "docs-playground-popup__frame" };
|
|
@@ -2355,6 +1406,17 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2355
1406
|
clearConsole: {
|
|
2356
1407
|
type: Boolean,
|
|
2357
1408
|
default: true
|
|
1409
|
+
},
|
|
1410
|
+
local: {
|
|
1411
|
+
type: Boolean,
|
|
1412
|
+
default: true
|
|
1413
|
+
},
|
|
1414
|
+
files: { default: () => ({}) },
|
|
1415
|
+
entry: { default: "" },
|
|
1416
|
+
options: { default: () => ({}) },
|
|
1417
|
+
previewScroller: {
|
|
1418
|
+
type: Boolean,
|
|
1419
|
+
default: false
|
|
2358
1420
|
}
|
|
2359
1421
|
},
|
|
2360
1422
|
emits: [
|
|
@@ -2364,20 +1426,28 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2364
1426
|
"portal-fulfilled"
|
|
2365
1427
|
],
|
|
2366
1428
|
setup(__props, { emit: __emit }) {
|
|
1429
|
+
const LocalSandbox = (0, vue.defineAsyncComponent)(() => Promise.resolve().then(() => require("./local-sandbox-0ojvBQPO.cjs")).then((n) => n.local_sandbox_exports));
|
|
2367
1430
|
const props = __props;
|
|
2368
1431
|
const emit = __emit;
|
|
2369
1432
|
const { t } = (0, _deot_docs_locale.useLocale)();
|
|
2370
1433
|
const currentViewport = (0, vue.ref)(props.viewport);
|
|
2371
1434
|
const sandboxRef = (0, vue.ref)(null);
|
|
1435
|
+
const localError = (0, vue.ref)({
|
|
1436
|
+
compile: "",
|
|
1437
|
+
runtime: ""
|
|
1438
|
+
});
|
|
1439
|
+
const handleLocalError = (payload) => {
|
|
1440
|
+
localError.value = payload;
|
|
1441
|
+
};
|
|
2372
1442
|
const availableHeight = () => Math.max(0, getWindowInnerSize().height - 40 - 44);
|
|
2373
1443
|
const temporaryHeight = usePreviewHeightBridge(sandboxRef, availableHeight);
|
|
2374
1444
|
const sandboxKey = (0, vue.ref)(0);
|
|
2375
1445
|
const layoutTick = (0, vue.ref)(0);
|
|
2376
|
-
const runtimeError = useSandboxRuntimeErrorGuard(sandboxRef);
|
|
1446
|
+
const runtimeError = require_store.useSandboxRuntimeErrorGuard(sandboxRef);
|
|
2377
1447
|
useSandboxTheme(sandboxRef);
|
|
2378
|
-
const storeErrors = (0, vue.computed)(() => (props.store
|
|
1448
|
+
const storeErrors = (0, vue.computed)(() => props.local ? localError.value.compile : (props.store?.errors || []).map(require_store.toErrorText).filter(Boolean).join("\n"));
|
|
2379
1449
|
const errorText = (0, vue.computed)(() => {
|
|
2380
|
-
const runtime = runtimeError.value ? formatSandboxRuntimeError(runtimeError.value, t("playground.runtime.importMapTip")) : "";
|
|
1450
|
+
const runtime = props.local ? localError.value.runtime : runtimeError.value ? require_store.formatSandboxRuntimeError(runtimeError.value, t("playground.runtime.importMapTip")) : "";
|
|
2381
1451
|
return [storeErrors.value, runtime].filter(Boolean).join("\n\n");
|
|
2382
1452
|
});
|
|
2383
1453
|
const layout = (0, vue.computed)(() => {
|
|
@@ -2400,10 +1470,14 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2400
1470
|
const canvasStyle = (0, vue.computed)(() => ({
|
|
2401
1471
|
width: `${layout.value.canvasWidth}px`,
|
|
2402
1472
|
height: `${layout.value.canvasHeight}px`,
|
|
2403
|
-
background: PLAYGROUND_RUNTIME_CANVAS_BACKGROUND
|
|
1473
|
+
background: require_store.PLAYGROUND_RUNTIME_CANVAS_BACKGROUND
|
|
2404
1474
|
}));
|
|
2405
1475
|
const handleRefresh = () => {
|
|
2406
1476
|
runtimeError.value = "";
|
|
1477
|
+
localError.value = {
|
|
1478
|
+
compile: "",
|
|
1479
|
+
runtime: ""
|
|
1480
|
+
};
|
|
2407
1481
|
sandboxKey.value++;
|
|
2408
1482
|
};
|
|
2409
1483
|
const handleViewportChange = (viewport) => {
|
|
@@ -2428,8 +1502,7 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2428
1502
|
layoutTick.value++;
|
|
2429
1503
|
};
|
|
2430
1504
|
const handleBridgeMessage = (event) => {
|
|
2431
|
-
|
|
2432
|
-
if (!iframe || event.source !== iframe.contentWindow) return;
|
|
1505
|
+
if (!require_store.isSandboxMessage(sandboxRef.value, event)) return;
|
|
2433
1506
|
const data = event.data;
|
|
2434
1507
|
if (!data || data.action !== "docs:navigate" || typeof data.to !== "string") return;
|
|
2435
1508
|
emit("navigate", data.to);
|
|
@@ -2491,7 +1564,23 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2491
1564
|
default: (0, vue.withCtx)(() => [(0, vue.createElementVNode)("div", {
|
|
2492
1565
|
class: "docs-playground-popup__canvas",
|
|
2493
1566
|
style: (0, vue.normalizeStyle)(canvasStyle.value)
|
|
2494
|
-
}, [((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(
|
|
1567
|
+
}, [__props.local ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(LocalSandbox), {
|
|
1568
|
+
key: sandboxKey.value,
|
|
1569
|
+
ref_key: "sandboxRef",
|
|
1570
|
+
ref: sandboxRef,
|
|
1571
|
+
files: __props.files,
|
|
1572
|
+
entry: __props.entry,
|
|
1573
|
+
options: __props.options,
|
|
1574
|
+
"preview-scroller": __props.previewScroller,
|
|
1575
|
+
"clear-console": __props.clearConsole,
|
|
1576
|
+
onError: handleLocalError
|
|
1577
|
+
}, null, 8, [
|
|
1578
|
+
"files",
|
|
1579
|
+
"entry",
|
|
1580
|
+
"options",
|
|
1581
|
+
"preview-scroller",
|
|
1582
|
+
"clear-console"
|
|
1583
|
+
])) : __props.store ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_vue_repl.Sandbox), {
|
|
2495
1584
|
key: sandboxKey.value,
|
|
2496
1585
|
ref_key: "sandboxRef",
|
|
2497
1586
|
ref: sandboxRef,
|
|
@@ -2503,7 +1592,7 @@ var wrapper_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2503
1592
|
"store",
|
|
2504
1593
|
"clear-console",
|
|
2505
1594
|
"preview-options"
|
|
2506
|
-
]))], 4)]),
|
|
1595
|
+
])) : (0, vue.createCommentVNode)("v-if", true)], 4)]),
|
|
2507
1596
|
_: 1
|
|
2508
1597
|
})])
|
|
2509
1598
|
])], 4)], 8, _hoisted_1$2);
|
|
@@ -2519,26 +1608,25 @@ var Alone = new _deot_vc.Portal(wrapper_default, {
|
|
|
2519
1608
|
});
|
|
2520
1609
|
//#endregion
|
|
2521
1610
|
//#region packages/playground/src/core/runtime/runtime.vue?vue&type=script&setup=true&lang.ts
|
|
2522
|
-
var _hoisted_1$1 = {
|
|
2523
|
-
var _hoisted_2$1 = {
|
|
1611
|
+
var _hoisted_1$1 = {
|
|
2524
1612
|
key: 0,
|
|
2525
1613
|
class: "docs-playground__runtime-error",
|
|
2526
1614
|
role: "alert"
|
|
2527
1615
|
};
|
|
2528
|
-
var
|
|
1616
|
+
var _hoisted_2$1 = {
|
|
2529
1617
|
key: 0,
|
|
2530
1618
|
class: "docs-playground__header"
|
|
2531
1619
|
};
|
|
2532
|
-
var
|
|
2533
|
-
var
|
|
2534
|
-
var
|
|
2535
|
-
var
|
|
1620
|
+
var _hoisted_3$1 = ["id", "title"];
|
|
1621
|
+
var _hoisted_4$1 = ["href"];
|
|
1622
|
+
var _hoisted_5$1 = { class: "docs-playground__title-text" };
|
|
1623
|
+
var _hoisted_6 = {
|
|
2536
1624
|
key: 1,
|
|
2537
1625
|
class: "docs-playground__runtime-error",
|
|
2538
1626
|
role: "alert"
|
|
2539
1627
|
};
|
|
2540
|
-
var
|
|
2541
|
-
var
|
|
1628
|
+
var _hoisted_7 = { class: "docs-playground-runtime__viewport-stage" };
|
|
1629
|
+
var _hoisted_8 = [
|
|
2542
1630
|
"aria-expanded",
|
|
2543
1631
|
"title",
|
|
2544
1632
|
"aria-label"
|
|
@@ -2571,7 +1659,11 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2571
1659
|
title: { default: "" },
|
|
2572
1660
|
id: { default: "" },
|
|
2573
1661
|
viewport: { default: "auto" },
|
|
2574
|
-
viewportOptions: { default: () => ["auto", 375] }
|
|
1662
|
+
viewportOptions: { default: () => ["auto", 375] },
|
|
1663
|
+
local: {
|
|
1664
|
+
type: Boolean,
|
|
1665
|
+
default: true
|
|
1666
|
+
}
|
|
2575
1667
|
},
|
|
2576
1668
|
emits: [
|
|
2577
1669
|
"files-change",
|
|
@@ -2580,6 +1672,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2580
1672
|
"navigate"
|
|
2581
1673
|
],
|
|
2582
1674
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
1675
|
+
const LocalSandbox = (0, vue.defineAsyncComponent)(() => Promise.resolve().then(() => require("./local-sandbox-0ojvBQPO.cjs")).then((n) => n.local_sandbox_exports));
|
|
2583
1676
|
const props = __props;
|
|
2584
1677
|
const { locale, t } = (0, _deot_docs_locale.useLocale)();
|
|
2585
1678
|
const displayTitle = (0, vue.computed)(() => props.title.trim());
|
|
@@ -2592,7 +1685,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2592
1685
|
const emit = __emit;
|
|
2593
1686
|
const joinCode = (...values) => values.filter(Boolean).join("\n");
|
|
2594
1687
|
const mergePreviewOptions = (extraHeadHTML) => {
|
|
2595
|
-
const runtimePreviewOptions = createRuntimePreviewOptions(props.options.cdnURL, { previewScroller: props.previewScroller });
|
|
1688
|
+
const runtimePreviewOptions = require_store.createRuntimePreviewOptions(props.options.cdnURL, { previewScroller: props.previewScroller });
|
|
2596
1689
|
return {
|
|
2597
1690
|
...runtimePreviewOptions,
|
|
2598
1691
|
...props.previewOptions,
|
|
@@ -2602,8 +1695,8 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2602
1695
|
extraHeadHTML
|
|
2603
1696
|
].filter(Boolean).join("\n"),
|
|
2604
1697
|
customCode: {
|
|
2605
|
-
importCode: joinCode(runtimePreviewOptions.customCode?.importCode, props.previewOptions?.customCode?.importCode, props.previewScroller ? PREVIEW_SCROLL_RESET_CODE : void 0, props.previewScroller ? PREVIEW_SCROLLER_IMPORT_CODE : void 0),
|
|
2606
|
-
useCode: joinCode(runtimePreviewOptions.customCode?.useCode, props.previewOptions?.customCode?.useCode, props.previewScroller ? PREVIEW_SCROLLER_USE_CODE : void 0)
|
|
1698
|
+
importCode: joinCode(runtimePreviewOptions.customCode?.importCode, props.previewOptions?.customCode?.importCode, props.previewScroller ? require_store.PREVIEW_SCROLL_RESET_CODE : void 0, props.previewScroller ? require_store.PREVIEW_SCROLLER_IMPORT_CODE : void 0),
|
|
1699
|
+
useCode: joinCode(runtimePreviewOptions.customCode?.useCode, props.previewOptions?.customCode?.useCode, props.previewScroller ? require_store.PREVIEW_SCROLLER_USE_CODE : void 0)
|
|
2607
1700
|
}
|
|
2608
1701
|
};
|
|
2609
1702
|
};
|
|
@@ -2617,21 +1710,33 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2617
1710
|
"SSR": false
|
|
2618
1711
|
}.MODE !== "development";
|
|
2619
1712
|
const copyValue = (0, vue.computed)(() => props.files[props.entry] || "");
|
|
2620
|
-
const store = createRuntimeStore(props.files, props.entry, props.options);
|
|
1713
|
+
const store = props.local ? null : require_store.createRuntimeStore(props.files, props.entry, props.options);
|
|
1714
|
+
const storeReady = (0, vue.computed)(() => store && !store.loading && Object.values(store.files).every((file) => require_files.isIgnoredFilename(file.filename) || !/\.(?:vue|[jt]sx?|json|s[ac]ss)$/.test(file.filename) || !file.code.trim() || !!file.compiled.js));
|
|
2621
1715
|
const sandboxRef = (0, vue.ref)(null);
|
|
1716
|
+
const localError = (0, vue.ref)({
|
|
1717
|
+
compile: "",
|
|
1718
|
+
runtime: ""
|
|
1719
|
+
});
|
|
1720
|
+
const handleLocalError = (payload) => {
|
|
1721
|
+
localError.value = payload;
|
|
1722
|
+
};
|
|
2622
1723
|
const temporaryHeight = usePreviewHeightBridge(sandboxRef);
|
|
2623
1724
|
const sandboxKey = (0, vue.ref)(0);
|
|
2624
|
-
const runtimeHeight = useSandboxAutoHeight(sandboxRef);
|
|
2625
|
-
const runtimeError = useSandboxRuntimeErrorGuard(sandboxRef);
|
|
1725
|
+
const runtimeHeight = require_store.useSandboxAutoHeight(sandboxRef);
|
|
1726
|
+
const runtimeError = require_store.useSandboxRuntimeErrorGuard(sandboxRef);
|
|
2626
1727
|
useSandboxTheme(sandboxRef);
|
|
2627
|
-
const compileErrorText = (0, vue.computed)(() =>
|
|
1728
|
+
const compileErrorText = (0, vue.computed)(() => {
|
|
1729
|
+
if (props.local) return localError.value.compile;
|
|
1730
|
+
return (store?.errors || []).map(require_store.toErrorText).filter(Boolean).join("\n");
|
|
1731
|
+
});
|
|
2628
1732
|
const errorText = (0, vue.computed)(() => {
|
|
2629
|
-
|
|
1733
|
+
let runtime = "";
|
|
1734
|
+
if (props.local) runtime = localError.value.runtime;
|
|
1735
|
+
else if (runtimeError.value) runtime = require_store.formatSandboxRuntimeError(runtimeError.value, t("playground.runtime.importMapTip"));
|
|
2630
1736
|
return [compileErrorText.value, runtime].filter(Boolean).join("\n\n");
|
|
2631
1737
|
});
|
|
2632
1738
|
const handleBridgeMessage = (event) => {
|
|
2633
|
-
|
|
2634
|
-
if (!iframe || event.source !== iframe.contentWindow) return;
|
|
1739
|
+
if (!require_store.isSandboxMessage(sandboxRef.value, event)) return;
|
|
2635
1740
|
const data = event.data;
|
|
2636
1741
|
if (!data || data.action !== "docs:navigate" || typeof data.to !== "string") return;
|
|
2637
1742
|
emit("navigate", data.to);
|
|
@@ -2664,16 +1769,21 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2664
1769
|
}) - vertical * 2 - 2);
|
|
2665
1770
|
};
|
|
2666
1771
|
const syncFrozenExpandedHeight = () => {
|
|
2667
|
-
if (!previewExpanded.value || props.expandable !== true) return;
|
|
1772
|
+
if (props.local || !previewExpanded.value || props.expandable !== true) return;
|
|
2668
1773
|
frozenExpandedHeight.value = measureExpandedPreviewHeight();
|
|
2669
1774
|
};
|
|
2670
1775
|
if (typeof window !== "undefined") {
|
|
2671
1776
|
window.addEventListener("message", handleBridgeMessage);
|
|
2672
1777
|
window.addEventListener("resize", syncFrozenExpandedHeight);
|
|
2673
1778
|
}
|
|
2674
|
-
const canExpandPreview = (0, vue.computed)(() => !props.styleless && isPlaygroundExpandable(props.expandable));
|
|
1779
|
+
const canExpandPreview = (0, vue.computed)(() => !props.local && !props.styleless && isPlaygroundExpandable(props.expandable));
|
|
2675
1780
|
const expandLabel = (0, vue.computed)(() => t(previewExpanded.value ? "playground.runtime.collapsePreview" : "playground.runtime.expandPreview"));
|
|
2676
1781
|
const baseViewportHeight = (0, vue.computed)(() => {
|
|
1782
|
+
if (props.local) {
|
|
1783
|
+
const fixedHeight = getViewportHeight(props.viewport);
|
|
1784
|
+
if (fixedHeight) return fixedHeight;
|
|
1785
|
+
return runtimeHeight.value;
|
|
1786
|
+
}
|
|
2677
1787
|
if (previewExpanded.value && props.expandable === true) return frozenExpandedHeight.value;
|
|
2678
1788
|
if (previewExpanded.value && isPlaygroundExpandable(props.expandable)) return resolveExpandedPreviewHeight(props.expandable, 0);
|
|
2679
1789
|
const fixedHeight = getViewportHeight(props.viewport);
|
|
@@ -2685,7 +1795,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2685
1795
|
scrollPlaygroundToViewportStart(runtimeRoot.value);
|
|
2686
1796
|
};
|
|
2687
1797
|
const handleTogglePreviewExpand = () => {
|
|
2688
|
-
if (!canExpandPreview.value) return;
|
|
1798
|
+
if (props.local || !canExpandPreview.value) return;
|
|
2689
1799
|
if (!previewExpanded.value) {
|
|
2690
1800
|
if (props.expandable === true) frozenExpandedHeight.value = measureExpandedPreviewHeight();
|
|
2691
1801
|
else frozenExpandedHeight.value = 0;
|
|
@@ -2707,7 +1817,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2707
1817
|
return {
|
|
2708
1818
|
height: `${resolvePreviewBoxHeight(desiredViewportHeight.value, vertical)}px`,
|
|
2709
1819
|
padding: vertical === horizontal ? `${vertical}px` : `${vertical}px ${horizontal}px`,
|
|
2710
|
-
background: PLAYGROUND_RUNTIME_CANVAS_BACKGROUND
|
|
1820
|
+
background: require_store.PLAYGROUND_RUNTIME_CANVAS_BACKGROUND
|
|
2711
1821
|
};
|
|
2712
1822
|
});
|
|
2713
1823
|
const stylelessStyle = (0, vue.computed)(() => errorText.value ? void 0 : { height: `${desiredViewportHeight.value}px` });
|
|
@@ -2725,42 +1835,50 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2725
1835
|
syncedFiles = { ...files };
|
|
2726
1836
|
syncedEntry = entry;
|
|
2727
1837
|
const apply = () => {
|
|
2728
|
-
switch (action.type) {
|
|
1838
|
+
if (store) switch (action.type) {
|
|
2729
1839
|
case "update": {
|
|
2730
|
-
const file = store.files[toReplFilename(action.filename)];
|
|
1840
|
+
const file = store.files[require_store.toReplFilename(action.filename)];
|
|
2731
1841
|
if (file) file.code = files[action.filename];
|
|
2732
1842
|
break;
|
|
2733
1843
|
}
|
|
2734
1844
|
case "create":
|
|
2735
|
-
store.addFile(createReplFile(action.filename, files[action.filename]));
|
|
1845
|
+
store.addFile(require_store.createReplFile(action.filename, files[action.filename]));
|
|
2736
1846
|
break;
|
|
2737
1847
|
case "rename":
|
|
2738
|
-
store.renameFile(toReplFilename(action.previousFilename), toReplFilename(action.filename));
|
|
1848
|
+
store.renameFile(require_store.toReplFilename(action.previousFilename), require_store.toReplFilename(action.filename));
|
|
2739
1849
|
break;
|
|
2740
1850
|
case "delete":
|
|
2741
|
-
store.setActive(toReplFilename(entry));
|
|
2742
|
-
delete store.files[toReplFilename(action.filename)];
|
|
1851
|
+
store.setActive(require_store.toReplFilename(entry));
|
|
1852
|
+
delete store.files[require_store.toReplFilename(action.filename)];
|
|
2743
1853
|
break;
|
|
2744
1854
|
case "entry":
|
|
2745
|
-
store.mainFile = toReplFilename(entry);
|
|
2746
|
-
store.setActive(toReplFilename(entry));
|
|
1855
|
+
store.mainFile = require_store.toReplFilename(entry);
|
|
1856
|
+
store.setActive(require_store.toReplFilename(entry));
|
|
2747
1857
|
}
|
|
2748
1858
|
emit("files-change", files, entry, action);
|
|
2749
1859
|
};
|
|
2750
|
-
whenSassReady(files, apply);
|
|
1860
|
+
if (store) require_scss.whenSassReady(files, apply);
|
|
1861
|
+
else apply();
|
|
2751
1862
|
};
|
|
2752
1863
|
const handleEditor = () => {
|
|
2753
1864
|
Editor.popup({
|
|
2754
1865
|
files: { ...props.files },
|
|
2755
1866
|
entry: props.entry,
|
|
2756
1867
|
locale: locale.value,
|
|
2757
|
-
getCodeErrors: () =>
|
|
1868
|
+
getCodeErrors: () => {
|
|
1869
|
+
if (!props.local) return store?.errors || [];
|
|
1870
|
+
return localError.value.compile ? [localError.value.compile] : [];
|
|
1871
|
+
},
|
|
2758
1872
|
onFilesChange: handleFilesChange,
|
|
2759
|
-
onActiveChange: (filename) => store
|
|
1873
|
+
onActiveChange: (filename) => store?.setActive(require_store.toReplFilename(filename))
|
|
2760
1874
|
});
|
|
2761
1875
|
};
|
|
2762
1876
|
const handleInlineRefresh = () => {
|
|
2763
1877
|
runtimeError.value = "";
|
|
1878
|
+
localError.value = {
|
|
1879
|
+
compile: "",
|
|
1880
|
+
runtime: ""
|
|
1881
|
+
};
|
|
2764
1882
|
sandboxKey.value++;
|
|
2765
1883
|
};
|
|
2766
1884
|
const handleClosePopup = () => {
|
|
@@ -2768,6 +1886,11 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2768
1886
|
};
|
|
2769
1887
|
const handleOpenPopup = () => {
|
|
2770
1888
|
Alone.popup({
|
|
1889
|
+
local: props.local,
|
|
1890
|
+
files: props.files,
|
|
1891
|
+
entry: props.entry,
|
|
1892
|
+
options: props.options,
|
|
1893
|
+
previewScroller: props.previewScroller,
|
|
2771
1894
|
store,
|
|
2772
1895
|
copyValue: copyValue.value,
|
|
2773
1896
|
title: props.title,
|
|
@@ -2788,13 +1911,18 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2788
1911
|
syncedFiles = { ...files };
|
|
2789
1912
|
syncedEntry = props.entry;
|
|
2790
1913
|
runtimeError.value = "";
|
|
2791
|
-
|
|
1914
|
+
localError.value = {
|
|
1915
|
+
compile: "",
|
|
1916
|
+
runtime: ""
|
|
1917
|
+
};
|
|
1918
|
+
if (store) store.setFiles(files, props.entry);
|
|
2792
1919
|
}, { deep: true });
|
|
2793
1920
|
(0, vue.watch)(() => props.entry, (entry) => {
|
|
2794
1921
|
if (!entry || entry === syncedEntry) return;
|
|
2795
1922
|
syncedEntry = entry;
|
|
2796
|
-
|
|
2797
|
-
store.
|
|
1923
|
+
if (!store) return;
|
|
1924
|
+
store.mainFile = require_store.toReplFilename(entry);
|
|
1925
|
+
store.setActive(require_store.toReplFilename(entry));
|
|
2798
1926
|
});
|
|
2799
1927
|
(0, vue.watch)(() => props.activeView, (view) => {
|
|
2800
1928
|
if (view !== "runtime") handleClosePopup();
|
|
@@ -2810,28 +1938,46 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2810
1938
|
openPopup: handleOpenPopup
|
|
2811
1939
|
});
|
|
2812
1940
|
return (_ctx, _cache) => {
|
|
2813
|
-
return (0, vue.openBlock)(), (0, vue.createElementBlock)("div",
|
|
1941
|
+
return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", { class: (0, vue.normalizeClass)(["docs-playground-runtime-host", { "docs-playground-runtime-host--direct": __props.local && __props.styleless }]) }, [__props.styleless ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
2814
1942
|
key: 0,
|
|
2815
1943
|
ref_key: "runtimeRoot",
|
|
2816
1944
|
ref: runtimeRoot,
|
|
2817
1945
|
class: "docs-playground-runtime--styleless",
|
|
2818
1946
|
style: (0, vue.normalizeStyle)(stylelessStyle.value)
|
|
2819
|
-
}, [errorText.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("pre",
|
|
1947
|
+
}, [errorText.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("pre", _hoisted_1$1, (0, vue.toDisplayString)(errorText.value), 1)) : (0, vue.createCommentVNode)("v-if", true), (0, vue.createElementVNode)("div", {
|
|
2820
1948
|
class: "docs-playground-runtime__viewport",
|
|
2821
1949
|
style: (0, vue.normalizeStyle)(viewportStyle.value)
|
|
2822
|
-
}, [(0, vue.
|
|
1950
|
+
}, [__props.local ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(LocalSandbox), {
|
|
1951
|
+
key: 0,
|
|
1952
|
+
ref_key: "sandboxRef",
|
|
1953
|
+
ref: sandboxRef,
|
|
1954
|
+
files: __props.files,
|
|
1955
|
+
entry: __props.entry,
|
|
1956
|
+
options: __props.options,
|
|
1957
|
+
"preview-scroller": __props.previewScroller,
|
|
1958
|
+
"clear-console": clearConsole,
|
|
1959
|
+
"auto-height": !(0, vue.unref)(getViewportHeight)(__props.viewport),
|
|
1960
|
+
onError: handleLocalError
|
|
1961
|
+
}, null, 8, [
|
|
1962
|
+
"files",
|
|
1963
|
+
"entry",
|
|
1964
|
+
"options",
|
|
1965
|
+
"preview-scroller",
|
|
1966
|
+
"auto-height"
|
|
1967
|
+
])) : (0, vue.unref)(store) && storeReady.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_vue_repl.Sandbox), {
|
|
1968
|
+
key: 1,
|
|
2823
1969
|
ref_key: "sandboxRef",
|
|
2824
1970
|
ref: sandboxRef,
|
|
2825
1971
|
store: (0, vue.unref)(store),
|
|
2826
1972
|
"auto-store-init": false,
|
|
2827
1973
|
"preview-options": mergedPreviewOptions.value
|
|
2828
|
-
}, null, 8, ["store", "preview-options"])], 4)], 4)) : ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
1974
|
+
}, null, 8, ["store", "preview-options"])) : (0, vue.createCommentVNode)("v-if", true)], 4)], 4)) : ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
2829
1975
|
key: 1,
|
|
2830
1976
|
ref_key: "runtimeRoot",
|
|
2831
1977
|
ref: runtimeRoot,
|
|
2832
1978
|
class: "docs-playground-runtime"
|
|
2833
1979
|
}, [
|
|
2834
|
-
!__props.hideChrome ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div",
|
|
1980
|
+
!__props.hideChrome ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("div", _hoisted_2$1, [displayTitle.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("span", {
|
|
2835
1981
|
key: 0,
|
|
2836
1982
|
ref_key: "titleEl",
|
|
2837
1983
|
ref: titleEl,
|
|
@@ -2842,7 +1988,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2842
1988
|
}, [(0, vue.createElementVNode)("a", {
|
|
2843
1989
|
class: "docs-playground__title-anchor",
|
|
2844
1990
|
href: `#${titleId.value}`
|
|
2845
|
-
}, "#", 8,
|
|
1991
|
+
}, "#", 8, _hoisted_4$1), (0, vue.createElementVNode)("span", _hoisted_5$1, (0, vue.toDisplayString)(displayTitle.value), 1)], 8, _hoisted_3$1)) : (0, vue.createCommentVNode)("v-if", true), (0, vue.createVNode)(toolbar_default, {
|
|
2846
1992
|
"copy-value": copyValue.value,
|
|
2847
1993
|
viewport: __props.viewport,
|
|
2848
1994
|
"viewport-options": __props.viewportOptions,
|
|
@@ -2856,14 +2002,31 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2856
2002
|
"viewport",
|
|
2857
2003
|
"viewport-options"
|
|
2858
2004
|
])])) : (0, vue.createCommentVNode)("v-if", true),
|
|
2859
|
-
errorText.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("pre",
|
|
2005
|
+
errorText.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("pre", _hoisted_6, (0, vue.toDisplayString)(errorText.value), 1)) : (0, vue.createCommentVNode)("v-if", true),
|
|
2860
2006
|
(0, vue.createElementVNode)("section", {
|
|
2861
2007
|
class: (0, vue.normalizeClass)(["docs-playground__preview", { "is-expanded": previewExpanded.value }]),
|
|
2862
2008
|
style: (0, vue.normalizeStyle)(previewStyle.value)
|
|
2863
|
-
}, [(0, vue.createElementVNode)("div",
|
|
2009
|
+
}, [(0, vue.createElementVNode)("div", _hoisted_7, [(0, vue.createElementVNode)("div", {
|
|
2864
2010
|
class: "docs-playground-runtime__viewport",
|
|
2865
2011
|
style: (0, vue.normalizeStyle)(viewportStyle.value)
|
|
2866
|
-
}, [((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(
|
|
2012
|
+
}, [__props.local ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(LocalSandbox), {
|
|
2013
|
+
key: sandboxKey.value,
|
|
2014
|
+
ref_key: "sandboxRef",
|
|
2015
|
+
ref: sandboxRef,
|
|
2016
|
+
files: __props.files,
|
|
2017
|
+
entry: __props.entry,
|
|
2018
|
+
options: __props.options,
|
|
2019
|
+
"preview-scroller": __props.previewScroller,
|
|
2020
|
+
"clear-console": clearConsole,
|
|
2021
|
+
"auto-height": !(0, vue.unref)(getViewportHeight)(__props.viewport),
|
|
2022
|
+
onError: handleLocalError
|
|
2023
|
+
}, null, 8, [
|
|
2024
|
+
"files",
|
|
2025
|
+
"entry",
|
|
2026
|
+
"options",
|
|
2027
|
+
"preview-scroller",
|
|
2028
|
+
"auto-height"
|
|
2029
|
+
])) : (0, vue.unref)(store) && storeReady.value ? ((0, vue.openBlock)(), (0, vue.createBlock)((0, vue.unref)(_vue_repl.Sandbox), {
|
|
2867
2030
|
key: sandboxKey.value,
|
|
2868
2031
|
ref_key: "sandboxRef",
|
|
2869
2032
|
ref: sandboxRef,
|
|
@@ -2871,7 +2034,7 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2871
2034
|
"auto-store-init": false,
|
|
2872
2035
|
"clear-console": clearConsole,
|
|
2873
2036
|
"preview-options": mergedPreviewOptions.value
|
|
2874
|
-
}, null, 8, ["store", "preview-options"]))], 4)]), canExpandPreview.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
|
|
2037
|
+
}, null, 8, ["store", "preview-options"])) : (0, vue.createCommentVNode)("v-if", true)], 4)]), canExpandPreview.value ? ((0, vue.openBlock)(), (0, vue.createElementBlock)("button", {
|
|
2875
2038
|
key: 0,
|
|
2876
2039
|
type: "button",
|
|
2877
2040
|
class: (0, vue.normalizeClass)(["docs-playground__expand", { "is-expanded": previewExpanded.value }]),
|
|
@@ -2880,8 +2043,8 @@ var runtime_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2880
2043
|
title: expandLabel.value,
|
|
2881
2044
|
"aria-label": expandLabel.value,
|
|
2882
2045
|
onClick: handleTogglePreviewExpand
|
|
2883
|
-
}, [(0, vue.createVNode)((0, vue.unref)(icon_default), { name: "expand" })], 10,
|
|
2884
|
-
], 512))]);
|
|
2046
|
+
}, [(0, vue.createVNode)((0, vue.unref)(icon_default), { name: "expand" })], 10, _hoisted_8)) : (0, vue.createCommentVNode)("v-if", true)], 6)
|
|
2047
|
+
], 512))], 2);
|
|
2885
2048
|
};
|
|
2886
2049
|
}
|
|
2887
2050
|
});
|
|
@@ -2922,6 +2085,10 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2922
2085
|
type: Boolean,
|
|
2923
2086
|
default: false
|
|
2924
2087
|
},
|
|
2088
|
+
local: {
|
|
2089
|
+
type: Boolean,
|
|
2090
|
+
default: true
|
|
2091
|
+
},
|
|
2925
2092
|
previewOptions: {},
|
|
2926
2093
|
locale: {}
|
|
2927
2094
|
},
|
|
@@ -2940,7 +2107,7 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
2940
2107
|
const locale = (0, vue.computed)(() => props.locale || inheritedLocale.locale.value);
|
|
2941
2108
|
(0, _deot_docs_locale.provideLocale)(locale);
|
|
2942
2109
|
const { t } = (0, _deot_docs_locale.useLocale)(locale);
|
|
2943
|
-
const initialFiles = Object.keys(props.files).length ? { ...props.files } : { [DEFAULT_ENTRY]: props.modelValue || NEW_SFC_CODE };
|
|
2110
|
+
const initialFiles = Object.keys(props.files).length ? { ...props.files } : { [require_cdn.DEFAULT_ENTRY]: props.modelValue || require_cdn.NEW_SFC_CODE };
|
|
2944
2111
|
const initialEntry = props.entry && initialFiles[props.entry] !== void 0 ? props.entry : Object.keys(initialFiles)[0];
|
|
2945
2112
|
const sourceFiles = (0, vue.ref)(initialFiles);
|
|
2946
2113
|
const currentEntry = (0, vue.ref)(initialEntry);
|
|
@@ -3080,7 +2247,8 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
3080
2247
|
"preview-options": __props.previewOptions,
|
|
3081
2248
|
"preview-inset": __props.previewInset,
|
|
3082
2249
|
"preview-scroller": __props.previewScroller,
|
|
3083
|
-
|
|
2250
|
+
local: __props.local,
|
|
2251
|
+
expandable: __props.local ? false : __props.expandable,
|
|
3084
2252
|
styleless: true,
|
|
3085
2253
|
title: __props.title,
|
|
3086
2254
|
id: __props.id,
|
|
@@ -3096,6 +2264,7 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
3096
2264
|
"preview-options",
|
|
3097
2265
|
"preview-inset",
|
|
3098
2266
|
"preview-scroller",
|
|
2267
|
+
"local",
|
|
3099
2268
|
"expandable",
|
|
3100
2269
|
"title",
|
|
3101
2270
|
"id",
|
|
@@ -3149,7 +2318,8 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
3149
2318
|
"preview-options": __props.previewOptions,
|
|
3150
2319
|
"preview-inset": __props.previewInset,
|
|
3151
2320
|
"preview-scroller": __props.previewScroller,
|
|
3152
|
-
|
|
2321
|
+
local: __props.local,
|
|
2322
|
+
expandable: __props.local ? false : __props.expandable,
|
|
3153
2323
|
"hide-chrome": true,
|
|
3154
2324
|
title: __props.title,
|
|
3155
2325
|
id: __props.id,
|
|
@@ -3167,6 +2337,7 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
3167
2337
|
"preview-options",
|
|
3168
2338
|
"preview-inset",
|
|
3169
2339
|
"preview-scroller",
|
|
2340
|
+
"local",
|
|
3170
2341
|
"expandable",
|
|
3171
2342
|
"title",
|
|
3172
2343
|
"id",
|
|
@@ -3196,35 +2367,35 @@ var playground_default = /* @__PURE__ */ (0, vue.defineComponent)({
|
|
|
3196
2367
|
});
|
|
3197
2368
|
//#endregion
|
|
3198
2369
|
exports.CodePreview = code_preview_default;
|
|
3199
|
-
exports.DEFAULT_CDN_URL = DEFAULT_CDN_URL;
|
|
2370
|
+
exports.DEFAULT_CDN_URL = require_cdn.DEFAULT_CDN_URL;
|
|
3200
2371
|
exports.Editor = Editor;
|
|
3201
|
-
exports.PREVIEW_SCROLLER_USE_CODE = PREVIEW_SCROLLER_USE_CODE;
|
|
3202
|
-
exports.PREVIEW_SCROLL_CONTENT_CLASS = PREVIEW_SCROLL_CONTENT_CLASS;
|
|
3203
|
-
exports.PREVIEW_SCROLL_HTML_CLASS = PREVIEW_SCROLL_HTML_CLASS;
|
|
2372
|
+
exports.PREVIEW_SCROLLER_USE_CODE = require_store.PREVIEW_SCROLLER_USE_CODE;
|
|
2373
|
+
exports.PREVIEW_SCROLL_CONTENT_CLASS = require_store.PREVIEW_SCROLL_CONTENT_CLASS;
|
|
2374
|
+
exports.PREVIEW_SCROLL_HTML_CLASS = require_store.PREVIEW_SCROLL_HTML_CLASS;
|
|
3204
2375
|
exports.Playground = playground_default;
|
|
3205
|
-
exports.PlaygroundService = PlaygroundService;
|
|
3206
|
-
exports.applyPlaygroundImportMapOverride = applyPlaygroundImportMapOverride;
|
|
3207
|
-
exports.applyPlaygroundStyleOverride = applyPlaygroundStyleOverride;
|
|
3208
|
-
exports.clearPlaygroundMaps = clearPlaygroundMaps;
|
|
3209
|
-
exports.createBuiltinImports = createBuiltinImports;
|
|
3210
|
-
exports.createBuiltinStyles = createBuiltinStyles;
|
|
3211
|
-
exports.createRuntimePreviewOptions = createRuntimePreviewOptions;
|
|
3212
|
-
exports.getPlaygroundImportMapOverrides = getPlaygroundImportMapOverrides;
|
|
3213
|
-
exports.getPlaygroundSiteModules = getPlaygroundSiteModules;
|
|
3214
|
-
exports.getPlaygroundSiteStyles = getPlaygroundSiteStyles;
|
|
3215
|
-
exports.getPlaygroundStyleOverrides = getPlaygroundStyleOverrides;
|
|
2376
|
+
exports.PlaygroundService = require_store.PlaygroundService;
|
|
2377
|
+
exports.applyPlaygroundImportMapOverride = require_store.applyPlaygroundImportMapOverride;
|
|
2378
|
+
exports.applyPlaygroundStyleOverride = require_store.applyPlaygroundStyleOverride;
|
|
2379
|
+
exports.clearPlaygroundMaps = require_store.clearPlaygroundMaps;
|
|
2380
|
+
exports.createBuiltinImports = require_cdn.createBuiltinImports;
|
|
2381
|
+
exports.createBuiltinStyles = require_cdn.createBuiltinStyles;
|
|
2382
|
+
exports.createRuntimePreviewOptions = require_store.createRuntimePreviewOptions;
|
|
2383
|
+
exports.getPlaygroundImportMapOverrides = require_store.getPlaygroundImportMapOverrides;
|
|
2384
|
+
exports.getPlaygroundSiteModules = require_store.getPlaygroundSiteModules;
|
|
2385
|
+
exports.getPlaygroundSiteStyles = require_store.getPlaygroundSiteStyles;
|
|
2386
|
+
exports.getPlaygroundStyleOverrides = require_store.getPlaygroundStyleOverrides;
|
|
3216
2387
|
exports.highlightCode = highlightCode;
|
|
3217
2388
|
exports.highlightCodeByLanguage = highlightCodeByLanguage;
|
|
3218
|
-
exports.isSafePlaygroundHref = isSafePlaygroundHref;
|
|
3219
|
-
exports.normalizeCdnURL = normalizeCdnURL;
|
|
2389
|
+
exports.isSafePlaygroundHref = require_store.isSafePlaygroundHref;
|
|
2390
|
+
exports.normalizeCdnURL = require_cdn.normalizeCdnURL;
|
|
3220
2391
|
exports.registerVueHighlight = registerVueHighlight;
|
|
3221
|
-
exports.removePlaygroundImportMapOverride = removePlaygroundImportMapOverride;
|
|
3222
|
-
exports.removePlaygroundStyleOverride = removePlaygroundStyleOverride;
|
|
2392
|
+
exports.removePlaygroundImportMapOverride = require_store.removePlaygroundImportMapOverride;
|
|
2393
|
+
exports.removePlaygroundStyleOverride = require_store.removePlaygroundStyleOverride;
|
|
3223
2394
|
exports.resolveHighlightLanguage = resolveHighlightLanguage;
|
|
3224
2395
|
exports.resolvePlaygroundTitleId = resolvePlaygroundTitleId;
|
|
3225
|
-
exports.setPlaygroundImportMapOverrides = setPlaygroundImportMapOverrides;
|
|
3226
|
-
exports.setPlaygroundSiteModules = setPlaygroundSiteModules;
|
|
3227
|
-
exports.setPlaygroundSiteStyles = setPlaygroundSiteStyles;
|
|
3228
|
-
exports.setPlaygroundStyleOverrides = setPlaygroundStyleOverrides;
|
|
2396
|
+
exports.setPlaygroundImportMapOverrides = require_store.setPlaygroundImportMapOverrides;
|
|
2397
|
+
exports.setPlaygroundSiteModules = require_store.setPlaygroundSiteModules;
|
|
2398
|
+
exports.setPlaygroundSiteStyles = require_store.setPlaygroundSiteStyles;
|
|
2399
|
+
exports.setPlaygroundStyleOverrides = require_store.setPlaygroundStyleOverrides;
|
|
3229
2400
|
exports.slugifyPlaygroundTitle = slugifyPlaygroundTitle;
|
|
3230
2401
|
exports.vueHighlight = vueHighlight;
|