@loupekit/sdk 0.3.3 → 0.3.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/dist/index.global.js +21 -12
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +21 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1920,17 +1920,29 @@ function captureElementContext(el2) {
|
|
|
1920
1920
|
}
|
|
1921
1921
|
return { html, styles };
|
|
1922
1922
|
}
|
|
1923
|
+
async function fontsReady() {
|
|
1924
|
+
try {
|
|
1925
|
+
const fonts = document.fonts;
|
|
1926
|
+
if (fonts?.ready) await fonts.ready;
|
|
1927
|
+
} catch {
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
function captureFilter(node) {
|
|
1931
|
+
if (!(node instanceof Element)) return true;
|
|
1932
|
+
if (node.id === "loupe-root") return false;
|
|
1933
|
+
if (node.hasAttribute("data-loupe-redact")) return false;
|
|
1934
|
+
return true;
|
|
1935
|
+
}
|
|
1923
1936
|
async function captureScreenshot(el2) {
|
|
1924
1937
|
try {
|
|
1938
|
+
await fontsReady();
|
|
1925
1939
|
return await domToPng(el2, {
|
|
1926
1940
|
scale: Math.min(window.devicePixelRatio || 1, 2),
|
|
1927
1941
|
backgroundColor: getComputedStyle(document.body).backgroundColor || "#ffffff",
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
return true;
|
|
1933
|
-
}
|
|
1942
|
+
// Give cross-origin font/asset fetches time to embed (default is short) so
|
|
1943
|
+
// the capture matches the page instead of falling back to system fonts.
|
|
1944
|
+
timeout: 3e4,
|
|
1945
|
+
filter: captureFilter
|
|
1934
1946
|
});
|
|
1935
1947
|
} catch (err) {
|
|
1936
1948
|
console.warn("[loupe] screenshot capture failed", err);
|
|
@@ -1939,16 +1951,13 @@ async function captureScreenshot(el2) {
|
|
|
1939
1951
|
}
|
|
1940
1952
|
async function captureRegionScreenshot(rect) {
|
|
1941
1953
|
try {
|
|
1954
|
+
await fontsReady();
|
|
1942
1955
|
const scale = Math.min(window.devicePixelRatio || 1, 2);
|
|
1943
1956
|
const full = await domToPng(document.body, {
|
|
1944
1957
|
scale,
|
|
1945
1958
|
backgroundColor: getComputedStyle(document.body).backgroundColor || "#ffffff",
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
if (node.id === "loupe-root") return false;
|
|
1949
|
-
if (node.hasAttribute("data-loupe-redact")) return false;
|
|
1950
|
-
return true;
|
|
1951
|
-
}
|
|
1959
|
+
timeout: 3e4,
|
|
1960
|
+
filter: captureFilter
|
|
1952
1961
|
});
|
|
1953
1962
|
const bodyRect = document.body.getBoundingClientRect();
|
|
1954
1963
|
const redact = Array.from(document.querySelectorAll("[data-loupe-redact]")).map(
|