@insitue/sdk 0.1.5 → 0.1.7

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.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mountCaptureOnly
3
- } from "./chunk-Z7GTGO4C.js";
4
- import "./chunk-2QO63Y4R.js";
3
+ } from "./chunk-3ZUAZAJB.js";
4
+ import "./chunk-AMC2RGMK.js";
5
5
  export {
6
6
  mountCaptureOnly
7
7
  };
@@ -10,7 +10,7 @@ import {
10
10
  retryDisplayMedia,
11
11
  stopDisplayMedia,
12
12
  y
13
- } from "./chunk-2QO63Y4R.js";
13
+ } from "./chunk-AMC2RGMK.js";
14
14
 
15
15
  // src/capture-only.ts
16
16
  var DEFAULT_INGEST = "https://www.insitue.com/api/v1/capture";
@@ -353,8 +353,8 @@ function CaptureOnlyApp(props) {
353
353
  k("span", {}, "\u{1F512} Secrets scrubbed automatically"),
354
354
  k(
355
355
  "span",
356
- { title: `@insitue/sdk@${"0.1.5"}` },
357
- `InSitue \xB7 v${"0.1.5"}`
356
+ { title: `@insitue/sdk@${"0.1.7"}` },
357
+ `InSitue \xB7 v${"0.1.7"}`
358
358
  )
359
359
  ]
360
360
  )
@@ -1644,72 +1644,6 @@ async function toCanvas(node, options = {}) {
1644
1644
  var IMAGE_PLACEHOLDER = "data:image/svg+xml;base64," + (typeof btoa !== "undefined" ? btoa(
1645
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>'
1646
1646
  ) : "");
1647
- async function preResolveImages(cropRect) {
1648
- const restorations = [];
1649
- const failedImages = /* @__PURE__ */ new Set();
1650
- const PAD = 64;
1651
- const images = Array.from(
1652
- document.querySelectorAll("img")
1653
- ).filter((img) => {
1654
- if (img.closest?.("#insitu-root, [data-insitu-layer]")) return false;
1655
- if (!cropRect) return true;
1656
- const r3 = img.getBoundingClientRect();
1657
- if (r3.width <= 0 || r3.height <= 0) return false;
1658
- return r3.right >= cropRect.x - PAD && r3.left <= cropRect.x + cropRect.width + PAD && r3.bottom >= cropRect.y - PAD && r3.top <= cropRect.y + cropRect.height + PAD;
1659
- });
1660
- const PER_IMAGE_TIMEOUT_MS = 3e3;
1661
- await Promise.allSettled(
1662
- images.map(async (img) => {
1663
- const srcToFetch = img.currentSrc || img.src;
1664
- if (!srcToFetch || srcToFetch.startsWith("data:") || srcToFetch.startsWith("blob:")) {
1665
- return;
1666
- }
1667
- const ac = new AbortController();
1668
- const timer = setTimeout(() => ac.abort(), PER_IMAGE_TIMEOUT_MS);
1669
- try {
1670
- const res = await fetch(srcToFetch, {
1671
- cache: "force-cache",
1672
- signal: ac.signal
1673
- });
1674
- if (!res.ok) {
1675
- failedImages.add(img);
1676
- return;
1677
- }
1678
- const blob = await res.blob();
1679
- const dataUrl = await new Promise((resolve, reject) => {
1680
- const reader = new FileReader();
1681
- reader.onload = () => resolve(reader.result);
1682
- reader.onerror = () => reject(reader.error);
1683
- reader.readAsDataURL(blob);
1684
- });
1685
- const origSrc = img.getAttribute("src");
1686
- const origSrcset = img.getAttribute("srcset");
1687
- restorations.push(() => {
1688
- if (origSrc != null) img.setAttribute("src", origSrc);
1689
- else img.removeAttribute("src");
1690
- if (origSrcset != null) img.setAttribute("srcset", origSrcset);
1691
- else img.removeAttribute("srcset");
1692
- });
1693
- img.removeAttribute("srcset");
1694
- img.src = dataUrl;
1695
- try {
1696
- await img.decode();
1697
- } catch {
1698
- }
1699
- } catch {
1700
- failedImages.add(img);
1701
- } finally {
1702
- clearTimeout(timer);
1703
- }
1704
- })
1705
- );
1706
- return {
1707
- restore: () => {
1708
- for (const r3 of restorations) r3();
1709
- },
1710
- failedImages
1711
- };
1712
- }
1713
1647
  function findContextAncestor(el) {
1714
1648
  const minW = 420;
1715
1649
  const minH = 140;
@@ -1731,41 +1665,83 @@ async function renderViewportCrop(cropRect, pixelRatio) {
1731
1665
  const bodyBg = getComputedStyle(document.body).backgroundColor;
1732
1666
  const htmlBg = getComputedStyle(document.documentElement).backgroundColor;
1733
1667
  const backgroundColor = bodyBg && bodyBg !== "rgba(0, 0, 0, 0)" && bodyBg !== "transparent" ? bodyBg : htmlBg && htmlBg !== "rgba(0, 0, 0, 0)" && htmlBg !== "transparent" ? htmlBg : "#ffffff";
1734
- const { restore: restoreImages, failedImages } = await preResolveImages(cropRect);
1735
- try {
1736
- const fullCanvas = await toCanvas(document.documentElement, {
1737
- pixelRatio,
1738
- // cacheBust off — we've already swapped srcs to data URLs.
1739
- cacheBust: false,
1740
- backgroundColor,
1741
- imagePlaceholder: IMAGE_PLACEHOLDER,
1742
- // Strip only our own overlay layers.
1743
- filter: (n2) => !(n2 instanceof Element && n2.closest?.("#insitu-root, [data-insitu-layer]"))
1744
- });
1745
- const sx = window.scrollX;
1746
- const sy = window.scrollY;
1747
- const out = document.createElement("canvas");
1748
- out.width = Math.max(1, Math.round(cropRect.width * pixelRatio));
1749
- out.height = Math.max(1, Math.round(cropRect.height * pixelRatio));
1750
- const ctx = out.getContext("2d");
1751
- if (!ctx) return { dataUrl: null, failedImages };
1752
- ctx.drawImage(
1753
- fullCanvas,
1754
- Math.round((cropRect.x + sx) * pixelRatio),
1755
- Math.round((cropRect.y + sy) * pixelRatio),
1756
- Math.round(cropRect.width * pixelRatio),
1757
- Math.round(cropRect.height * pixelRatio),
1758
- 0,
1759
- 0,
1760
- out.width,
1761
- out.height
1762
- );
1763
- if (looksBlankUniform(ctx, out.width, out.height)) {
1764
- return { dataUrl: null, failedImages };
1668
+ const failedImages = /* @__PURE__ */ new Set();
1669
+ const fullCanvas = await toCanvas(document.documentElement, {
1670
+ pixelRatio,
1671
+ cacheBust: true,
1672
+ backgroundColor,
1673
+ imagePlaceholder: IMAGE_PLACEHOLDER,
1674
+ filter: (n2) => !(n2 instanceof Element && n2.closest?.("#insitu-root, [data-insitu-layer]"))
1675
+ });
1676
+ const sx = window.scrollX;
1677
+ const sy = window.scrollY;
1678
+ const out = document.createElement("canvas");
1679
+ out.width = Math.max(1, Math.round(cropRect.width * pixelRatio));
1680
+ out.height = Math.max(1, Math.round(cropRect.height * pixelRatio));
1681
+ const ctx = out.getContext("2d");
1682
+ if (!ctx) return { dataUrl: null, failedImages };
1683
+ ctx.drawImage(
1684
+ fullCanvas,
1685
+ Math.round((cropRect.x + sx) * pixelRatio),
1686
+ Math.round((cropRect.y + sy) * pixelRatio),
1687
+ Math.round(cropRect.width * pixelRatio),
1688
+ Math.round(cropRect.height * pixelRatio),
1689
+ 0,
1690
+ 0,
1691
+ out.width,
1692
+ out.height
1693
+ );
1694
+ if (looksBlankUniform(ctx, out.width, out.height)) {
1695
+ return { dataUrl: null, failedImages };
1696
+ }
1697
+ detectUnrenderedImages(ctx, cropRect, out, pixelRatio, failedImages);
1698
+ return { dataUrl: out.toDataURL("image/png"), failedImages };
1699
+ }
1700
+ function detectUnrenderedImages(cropCtx, cropRect, cropCanvas, pixelRatio, failedImages) {
1701
+ const imgs = Array.from(
1702
+ document.querySelectorAll("img")
1703
+ ).filter(
1704
+ (img) => !img.closest?.("#insitu-root, [data-insitu-layer]")
1705
+ );
1706
+ for (const img of imgs) {
1707
+ if (failedImages.has(img)) continue;
1708
+ const r3 = img.getBoundingClientRect();
1709
+ if (r3.width < 32 || r3.height < 32) continue;
1710
+ const overlapX = Math.min(r3.right, cropRect.x + cropRect.width) - Math.max(r3.left, cropRect.x);
1711
+ const overlapY = Math.min(r3.bottom, cropRect.y + cropRect.height) - Math.max(r3.top, cropRect.y);
1712
+ if (overlapX <= 0 || overlapY <= 0) continue;
1713
+ const baseX = Math.max(r3.left, cropRect.x);
1714
+ const baseY = Math.max(r3.top, cropRect.y);
1715
+ const samples = /* @__PURE__ */ new Set();
1716
+ try {
1717
+ for (let i3 = 0; i3 < 3; i3++) {
1718
+ for (let j3 = 0; j3 < 3; j3++) {
1719
+ const px2 = baseX + overlapX * (i3 + 0.5) / 3;
1720
+ const py = baseY + overlapY * (j3 + 0.5) / 3;
1721
+ const cx = Math.max(
1722
+ 0,
1723
+ Math.min(
1724
+ cropCanvas.width - 1,
1725
+ Math.round((px2 - cropRect.x) * pixelRatio)
1726
+ )
1727
+ );
1728
+ const cy = Math.max(
1729
+ 0,
1730
+ Math.min(
1731
+ cropCanvas.height - 1,
1732
+ Math.round((py - cropRect.y) * pixelRatio)
1733
+ )
1734
+ );
1735
+ const d3 = cropCtx.getImageData(cx, cy, 1, 1).data;
1736
+ samples.add(`${d3[0]},${d3[1]},${d3[2]},${d3[3]}`);
1737
+ }
1738
+ }
1739
+ } catch {
1740
+ continue;
1741
+ }
1742
+ if (samples.size === 1) {
1743
+ failedImages.add(img);
1765
1744
  }
1766
- return { dataUrl: out.toDataURL("image/png"), failedImages };
1767
- } finally {
1768
- restoreImages();
1769
1745
  }
1770
1746
  }
1771
1747
  function looksBlankUniform(ctx, w3, h3) {
@@ -15,7 +15,7 @@ import {
15
15
  setCaptureSettings,
16
16
  stopDisplayMedia,
17
17
  y
18
- } from "./chunk-2QO63Y4R.js";
18
+ } from "./chunk-AMC2RGMK.js";
19
19
 
20
20
  // src/client.ts
21
21
  var CompanionClient = class {
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  mountCaptureOnly
3
- } from "./chunk-Z7GTGO4C.js";
3
+ } from "./chunk-3ZUAZAJB.js";
4
4
  import {
5
5
  mountInSitue
6
- } from "./chunk-QL6QPM2A.js";
7
- import "./chunk-2QO63Y4R.js";
6
+ } from "./chunk-DBHURN5L.js";
7
+ import "./chunk-AMC2RGMK.js";
8
8
 
9
9
  // src/InSitue.tsx
10
10
  import { useEffect } from "react";
@@ -46,7 +46,7 @@ function InSitueCapture({
46
46
  }
47
47
 
48
48
  // src/index.ts
49
- var SDK_VERSION = "0.1.5";
49
+ var SDK_VERSION = "0.1.7";
50
50
  export {
51
51
  InSitue,
52
52
  InSitueCapture,
package/dist/overlay.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  mountInSitue
3
- } from "./chunk-QL6QPM2A.js";
4
- import "./chunk-2QO63Y4R.js";
3
+ } from "./chunk-DBHURN5L.js";
4
+ import "./chunk-AMC2RGMK.js";
5
5
  export {
6
6
  mountInSitue
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insitue/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "InSitue capture SDK — drop one snippet into your deployed app; your users point at a bug, InSitue opens a verified pull request.",
5
5
  "license": "MIT",
6
6
  "type": "module",