@botim/mp-debug-sdk 0.1.0 → 0.3.0
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 +8 -0
- package/dist/index.cjs +95 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +95 -43
- package/dist/index.js.map +1 -1
- package/dist/vite/plugin.cjs +62 -15
- package/dist/vite/plugin.cjs.map +1 -1
- package/dist/vite/plugin.d.cts +76 -1
- package/dist/vite/plugin.d.ts +76 -1
- package/dist/vite/plugin.js +62 -15
- package/dist/vite/plugin.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -772,32 +772,95 @@ async function defaultDomScreenshot() {
|
|
|
772
772
|
return await captureViaHtmlSnapshot();
|
|
773
773
|
}
|
|
774
774
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
775
|
+
var VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
776
|
+
"area",
|
|
777
|
+
"base",
|
|
778
|
+
"br",
|
|
779
|
+
"col",
|
|
780
|
+
"embed",
|
|
781
|
+
"hr",
|
|
782
|
+
"img",
|
|
783
|
+
"input",
|
|
784
|
+
"link",
|
|
785
|
+
"meta",
|
|
786
|
+
"source",
|
|
787
|
+
"track",
|
|
788
|
+
"wbr"
|
|
789
|
+
]);
|
|
790
|
+
var SKIP_TAGS = /* @__PURE__ */ new Set(["script", "noscript", "template"]);
|
|
791
|
+
var DEVTOOL_OVERLAY_PREFIXES = ["vite-", "astro-dev-", "next-route-"];
|
|
792
|
+
function isDevtoolOverlay(tag) {
|
|
793
|
+
return DEVTOOL_OVERLAY_PREFIXES.some((p) => tag.startsWith(p));
|
|
794
|
+
}
|
|
795
|
+
function escapeText(s) {
|
|
796
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
797
|
+
}
|
|
798
|
+
function escapeAttr(s) {
|
|
799
|
+
return s.replace(/&/g, "&").replace(/"/g, """);
|
|
800
|
+
}
|
|
801
|
+
function serializeComposed(node, opts, depth) {
|
|
802
|
+
if (depth > 256) return "";
|
|
803
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
804
|
+
return escapeText(node.textContent ?? "");
|
|
805
|
+
}
|
|
806
|
+
if (node.nodeType === Node.COMMENT_NODE) return "";
|
|
807
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return "";
|
|
808
|
+
const el = node;
|
|
809
|
+
const tag = el.tagName.toLowerCase();
|
|
810
|
+
if (SKIP_TAGS.has(tag)) return "";
|
|
811
|
+
if (isDevtoolOverlay(tag)) return "";
|
|
812
|
+
if (tag === "slot") {
|
|
813
|
+
const slot = el;
|
|
814
|
+
let assigned = [];
|
|
815
|
+
try {
|
|
816
|
+
assigned = slot.assignedNodes({ flatten: true });
|
|
817
|
+
} catch {
|
|
818
|
+
}
|
|
819
|
+
const source = assigned.length > 0 ? assigned : Array.from(el.childNodes);
|
|
820
|
+
return source.map((c) => serializeComposed(c, opts, depth + 1)).join("");
|
|
821
|
+
}
|
|
822
|
+
if (tag === "link" && (el.getAttribute("rel") || "").toLowerCase() === "stylesheet") {
|
|
823
|
+
return "";
|
|
824
|
+
}
|
|
825
|
+
if (tag === "style") {
|
|
826
|
+
return `<style>${el.textContent ?? ""}</style>`;
|
|
827
|
+
}
|
|
828
|
+
if (tag === "img" && opts.stripCrossOriginImages) {
|
|
829
|
+
const src = el.getAttribute("src") || "";
|
|
830
|
+
if (/^(https?:|\/\/)/i.test(src)) {
|
|
787
831
|
try {
|
|
788
832
|
const u = new URL(src, location.href);
|
|
789
|
-
if (u.origin !== location.origin)
|
|
833
|
+
if (u.origin !== location.origin) return "";
|
|
790
834
|
} catch {
|
|
791
|
-
|
|
835
|
+
return "";
|
|
792
836
|
}
|
|
793
837
|
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
const
|
|
800
|
-
|
|
838
|
+
}
|
|
839
|
+
if (tag === "canvas") return `<canvas></canvas>`;
|
|
840
|
+
const attrs = Array.from(el.attributes).filter((a) => !a.name.startsWith("on")).map((a) => ` ${a.name}="${escapeAttr(a.value)}"`).join("");
|
|
841
|
+
if (VOID_ELEMENTS.has(tag)) return `<${tag}${attrs}>`;
|
|
842
|
+
const childSource = el.shadowRoot ?? el;
|
|
843
|
+
const inner = Array.from(childSource.childNodes).map((c) => serializeComposed(c, opts, depth + 1)).join("");
|
|
844
|
+
return `<${tag}${attrs}>${inner}</${tag}>`;
|
|
845
|
+
}
|
|
846
|
+
function readInlineableStyles() {
|
|
847
|
+
const chunks = [];
|
|
848
|
+
for (const sheet of Array.from(document.styleSheets)) {
|
|
849
|
+
try {
|
|
850
|
+
const rules = sheet.cssRules;
|
|
851
|
+
for (const rule of Array.from(rules)) chunks.push(rule.cssText);
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return chunks.join("\n");
|
|
856
|
+
}
|
|
857
|
+
async function captureViaSvgForeignObject() {
|
|
858
|
+
const dpr = Math.min(window.devicePixelRatio || 1, 2);
|
|
859
|
+
const w = Math.max(1, Math.min(window.innerWidth || document.documentElement.clientWidth || 1024, 2400));
|
|
860
|
+
const h = Math.max(1, Math.min(document.documentElement.scrollHeight, 4e3));
|
|
861
|
+
const inlinedCss = readInlineableStyles();
|
|
862
|
+
const bodyHtml = serializeComposed(document.body, { stripCrossOriginImages: true }, 0);
|
|
863
|
+
const htmlStr = `<html xmlns="http://www.w3.org/1999/xhtml"><body>${bodyHtml}</body></html>`;
|
|
801
864
|
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}"><foreignObject width="100%" height="100%">` + (inlinedCss ? `<style xmlns="http://www.w3.org/1999/xhtml">${escapeForXml(inlinedCss)}</style>` : "") + htmlStr + `</foreignObject></svg>`;
|
|
802
865
|
const blobUrl = URL.createObjectURL(
|
|
803
866
|
new Blob([svg], { type: "image/svg+xml;charset=utf-8" })
|
|
@@ -831,30 +894,19 @@ function loadImage(src) {
|
|
|
831
894
|
function escapeForXml(s) {
|
|
832
895
|
return s.replace(/]]>/g, "]]>").replace(/<\//g, "</");
|
|
833
896
|
}
|
|
834
|
-
function readInlineableStyles() {
|
|
835
|
-
const chunks = [];
|
|
836
|
-
for (const sheet of Array.from(document.styleSheets)) {
|
|
837
|
-
try {
|
|
838
|
-
const rules = sheet.cssRules;
|
|
839
|
-
for (const rule of Array.from(rules)) chunks.push(rule.cssText);
|
|
840
|
-
} catch {
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
return chunks.join("\n");
|
|
844
|
-
}
|
|
845
897
|
async function captureViaHtmlSnapshot() {
|
|
846
898
|
const inlinedCss = readInlineableStyles();
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
899
|
+
const bodyHtml = serializeComposed(document.body, { stripCrossOriginImages: false }, 0);
|
|
900
|
+
const html = `<!DOCTYPE html>
|
|
901
|
+
<html lang="en">
|
|
902
|
+
<head>
|
|
903
|
+
<meta charset="utf-8">
|
|
904
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
905
|
+
<base href="${escapeAttr(location.href)}">
|
|
906
|
+
` + (inlinedCss ? `<style data-botim-snapshot="1">${inlinedCss}</style>
|
|
907
|
+
` : "") + `</head>
|
|
908
|
+
<body>${bodyHtml}</body>
|
|
909
|
+
</html>`;
|
|
858
910
|
return {
|
|
859
911
|
data: JSON.stringify({
|
|
860
912
|
html,
|