@insitue/sdk 0.1.10 → 0.1.11
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/capture-only.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
setCaptureSettings,
|
|
12
12
|
stopDisplayMedia,
|
|
13
13
|
y
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-SMR4AYKA.js";
|
|
15
15
|
|
|
16
16
|
// src/capture-only.ts
|
|
17
17
|
var DEFAULT_INGEST = "https://www.insitue.com/api/v1/capture";
|
|
@@ -362,8 +362,8 @@ function CaptureOnlyApp(props) {
|
|
|
362
362
|
k("span", {}, ""),
|
|
363
363
|
k(
|
|
364
364
|
"span",
|
|
365
|
-
{ title: `@insitue/sdk@${"0.1.
|
|
366
|
-
`InSitue \xB7 v${"0.1.
|
|
365
|
+
{ title: `@insitue/sdk@${"0.1.11"}` },
|
|
366
|
+
`InSitue \xB7 v${"0.1.11"}`
|
|
367
367
|
)
|
|
368
368
|
]
|
|
369
369
|
)
|
|
@@ -1641,16 +1641,6 @@ async function toCanvas(node, options = {}) {
|
|
|
1641
1641
|
}
|
|
1642
1642
|
|
|
1643
1643
|
// src/capture.ts
|
|
1644
|
-
function crossOrigin(url) {
|
|
1645
|
-
if (!url || url.startsWith("data:") || url.startsWith("blob:")) {
|
|
1646
|
-
return false;
|
|
1647
|
-
}
|
|
1648
|
-
try {
|
|
1649
|
-
return new URL(url, location.href).origin !== location.origin;
|
|
1650
|
-
} catch {
|
|
1651
|
-
return false;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
1644
|
var IMAGE_PLACEHOLDER = "data:image/svg+xml;base64," + (typeof btoa !== "undefined" ? btoa(
|
|
1655
1645
|
'<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><rect width="32" height="32" fill="#e8e8e8"/><path d="M0 0 L32 32 M32 0 L0 32" stroke="#b0b0b0" stroke-width="1.5"/></svg>'
|
|
1656
1646
|
) : "");
|
|
@@ -1681,7 +1671,7 @@ async function renderViewportCrop(cropRect, pixelRatio) {
|
|
|
1681
1671
|
out.height = Math.max(1, Math.round(cropRect.height * pixelRatio));
|
|
1682
1672
|
const ctx = out.getContext("2d");
|
|
1683
1673
|
if (!ctx) return { dataUrl: null, failedImages };
|
|
1684
|
-
const drawnImgs = drawAbsoluteImagesOnto(
|
|
1674
|
+
const drawnImgs = await drawAbsoluteImagesOnto(
|
|
1685
1675
|
ctx,
|
|
1686
1676
|
cropRect,
|
|
1687
1677
|
pixelRatio,
|
|
@@ -1721,67 +1711,102 @@ async function renderViewportCrop(cropRect, pixelRatio) {
|
|
|
1721
1711
|
detectUnrenderedImages(ctx, cropRect, out, pixelRatio, failedImages);
|
|
1722
1712
|
return { dataUrl: out.toDataURL("image/png"), failedImages };
|
|
1723
1713
|
}
|
|
1724
|
-
function drawAbsoluteImagesOnto(ctx, cropRect, pixelRatio, failedImages) {
|
|
1714
|
+
async function drawAbsoluteImagesOnto(ctx, cropRect, pixelRatio, failedImages) {
|
|
1725
1715
|
const drawn = /* @__PURE__ */ new Set();
|
|
1726
1716
|
const imgs = Array.from(
|
|
1727
1717
|
document.querySelectorAll("img")
|
|
1728
1718
|
).filter(
|
|
1729
1719
|
(img) => !img.closest?.("#insitu-root, [data-insitu-layer]")
|
|
1730
1720
|
);
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
source.
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
dest.y,
|
|
1765
|
-
dest.w,
|
|
1766
|
-
dest.h
|
|
1721
|
+
const PER_IMAGE_TIMEOUT_MS = 3e3;
|
|
1722
|
+
await Promise.allSettled(
|
|
1723
|
+
imgs.map(async (img) => {
|
|
1724
|
+
const r3 = img.getBoundingClientRect();
|
|
1725
|
+
if (r3.width <= 0 || r3.height <= 0) return;
|
|
1726
|
+
const cs = getComputedStyle(img);
|
|
1727
|
+
if (cs.position !== "absolute" && cs.position !== "fixed") return;
|
|
1728
|
+
if (r3.right < cropRect.x || r3.left > cropRect.x + cropRect.width || r3.bottom < cropRect.y || r3.top > cropRect.y + cropRect.height) {
|
|
1729
|
+
return;
|
|
1730
|
+
}
|
|
1731
|
+
const src = img.currentSrc || img.src;
|
|
1732
|
+
if (!src) return;
|
|
1733
|
+
const usesFreshLoad = !src.startsWith("data:") && !src.startsWith("blob:");
|
|
1734
|
+
let source;
|
|
1735
|
+
if (usesFreshLoad) {
|
|
1736
|
+
try {
|
|
1737
|
+
source = await loadFresh(src, PER_IMAGE_TIMEOUT_MS);
|
|
1738
|
+
} catch {
|
|
1739
|
+
failedImages.add(img);
|
|
1740
|
+
return;
|
|
1741
|
+
}
|
|
1742
|
+
} else {
|
|
1743
|
+
if (!img.complete || img.naturalWidth === 0) {
|
|
1744
|
+
failedImages.add(img);
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
source = img;
|
|
1748
|
+
}
|
|
1749
|
+
const objFit = computeObjectFitSource(
|
|
1750
|
+
{ naturalWidth: source.naturalWidth, naturalHeight: source.naturalHeight },
|
|
1751
|
+
r3.width,
|
|
1752
|
+
r3.height,
|
|
1753
|
+
cs.objectFit || "fill"
|
|
1767
1754
|
);
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1755
|
+
const dest = {
|
|
1756
|
+
x: (r3.left - cropRect.x) * pixelRatio,
|
|
1757
|
+
y: (r3.top - cropRect.y) * pixelRatio,
|
|
1758
|
+
w: r3.width * pixelRatio,
|
|
1759
|
+
h: r3.height * pixelRatio
|
|
1760
|
+
};
|
|
1761
|
+
try {
|
|
1762
|
+
ctx.drawImage(
|
|
1763
|
+
source,
|
|
1764
|
+
objFit.sx,
|
|
1765
|
+
objFit.sy,
|
|
1766
|
+
objFit.sw,
|
|
1767
|
+
objFit.sh,
|
|
1768
|
+
dest.x,
|
|
1769
|
+
dest.y,
|
|
1770
|
+
dest.w,
|
|
1771
|
+
dest.h
|
|
1772
|
+
);
|
|
1773
|
+
drawn.add(img);
|
|
1774
|
+
} catch {
|
|
1775
|
+
failedImages.add(img);
|
|
1776
|
+
}
|
|
1777
|
+
})
|
|
1778
|
+
);
|
|
1773
1779
|
return drawn;
|
|
1774
1780
|
}
|
|
1775
|
-
function
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
+
function loadFresh(url, timeoutMs) {
|
|
1782
|
+
return new Promise((resolve, reject) => {
|
|
1783
|
+
const img = new Image();
|
|
1784
|
+
img.crossOrigin = "anonymous";
|
|
1785
|
+
const timer = setTimeout(() => {
|
|
1786
|
+
img.src = "";
|
|
1787
|
+
reject(new Error("timeout"));
|
|
1788
|
+
}, timeoutMs);
|
|
1789
|
+
img.onload = async () => {
|
|
1790
|
+
clearTimeout(timer);
|
|
1791
|
+
try {
|
|
1792
|
+
await img.decode();
|
|
1793
|
+
} catch {
|
|
1794
|
+
}
|
|
1795
|
+
resolve(img);
|
|
1796
|
+
};
|
|
1797
|
+
img.onerror = () => {
|
|
1798
|
+
clearTimeout(timer);
|
|
1799
|
+
reject(new Error("load failed"));
|
|
1800
|
+
};
|
|
1801
|
+
img.src = url;
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
function computeObjectFitSource(natural, dw, dh, fit) {
|
|
1805
|
+
const nw = natural.naturalWidth;
|
|
1806
|
+
const nh = natural.naturalHeight;
|
|
1781
1807
|
if (!nw || !nh || !dw || !dh) {
|
|
1782
1808
|
return { sx: 0, sy: 0, sw: nw || 1, sh: nh || 1 };
|
|
1783
1809
|
}
|
|
1784
|
-
const fit = cs.objectFit || "fill";
|
|
1785
1810
|
if (fit === "fill") {
|
|
1786
1811
|
return { sx: 0, sy: 0, sw: nw, sh: nh };
|
|
1787
1812
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mountCaptureOnly
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PAKDACTF.js";
|
|
4
4
|
import {
|
|
5
5
|
mountInSitue
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-DJN4LPOV.js";
|
|
7
|
+
import "./chunk-SMR4AYKA.js";
|
|
8
8
|
|
|
9
9
|
// src/InSitue.tsx
|
|
10
10
|
import { useEffect } from "react";
|
|
@@ -52,7 +52,7 @@ function InSitueCapture({
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// src/index.ts
|
|
55
|
-
var SDK_VERSION = "0.1.
|
|
55
|
+
var SDK_VERSION = "0.1.11";
|
|
56
56
|
export {
|
|
57
57
|
InSitue,
|
|
58
58
|
InSitueCapture,
|
package/dist/overlay.js
CHANGED
package/package.json
CHANGED