@impakers/debug 1.4.5 → 1.4.6

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/react.js CHANGED
@@ -1569,35 +1569,34 @@ function findNearestComponentSource(element, maxAncestors = 10) {
1569
1569
  }
1570
1570
 
1571
1571
  // src/utils/capture-element.ts
1572
+ var UNSUPPORTED_COLOR_RE = /oklab|oklch|color-mix/i;
1573
+ var COLOR_DECLARATION_RE = /[^{};\n]+:\s*[^;{}]*(?:oklab|oklch|color-mix|lch|lab)\([^)]*(?:\([^)]*\))*[^)]*\)[^;{}]*/gi;
1574
+ function sanitizeUnsupportedColors(clonedDoc) {
1575
+ clonedDoc.querySelectorAll("style").forEach((styleEl) => {
1576
+ const text = styleEl.textContent || "";
1577
+ if (UNSUPPORTED_COLOR_RE.test(text)) {
1578
+ styleEl.textContent = text.replace(COLOR_DECLARATION_RE, "");
1579
+ }
1580
+ });
1581
+ clonedDoc.querySelectorAll("*").forEach((el) => {
1582
+ const s = el.style;
1583
+ if (!s?.cssText) return;
1584
+ if (UNSUPPORTED_COLOR_RE.test(s.cssText)) {
1585
+ s.cssText = s.cssText.replace(COLOR_DECLARATION_RE, "");
1586
+ }
1587
+ });
1588
+ }
1572
1589
  async function captureElement(el, options = {}) {
1573
1590
  const { quality = 0.7, maxScale = 2 } = options;
1574
- const rect = el.getBoundingClientRect();
1575
- const scale = Math.min(window.devicePixelRatio, maxScale);
1576
- const canvas = document.createElement("canvas");
1577
- canvas.width = rect.width * scale;
1578
- canvas.height = rect.height * scale;
1579
- const ctx = canvas.getContext("2d");
1580
- ctx.scale(scale, scale);
1581
- const clone = el.cloneNode(true);
1582
- inlineComputedStyles(el, clone);
1583
- clone.style.margin = "0";
1584
- clone.style.position = "static";
1585
- const serializer = new XMLSerializer();
1586
- const html = serializer.serializeToString(clone);
1587
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${rect.width}" height="${rect.height}">
1588
- <foreignObject width="100%" height="100%">
1589
- <div xmlns="http://www.w3.org/1999/xhtml" style="width:${rect.width}px;height:${rect.height}px;overflow:hidden">${html}</div>
1590
- </foreignObject>
1591
- </svg>`;
1592
- const blob = new Blob([svg], { type: "image/svg+xml;charset=utf-8" });
1593
- const url = URL.createObjectURL(blob);
1594
- try {
1595
- const img = await loadImage(url);
1596
- ctx.drawImage(img, 0, 0, rect.width, rect.height);
1597
- return canvas.toDataURL("image/jpeg", quality);
1598
- } finally {
1599
- URL.revokeObjectURL(url);
1600
- }
1591
+ const html2canvas = (await import("html2canvas")).default;
1592
+ const canvas = await html2canvas(el, {
1593
+ useCORS: true,
1594
+ allowTaint: true,
1595
+ scale: Math.min(window.devicePixelRatio, maxScale),
1596
+ logging: false,
1597
+ onclone: (clonedDoc) => sanitizeUnsupportedColors(clonedDoc)
1598
+ });
1599
+ return canvas.toDataURL("image/jpeg", quality);
1601
1600
  }
1602
1601
  async function captureFullPage(options = {}) {
1603
1602
  const { quality = 0.5, hideSelectors = [] } = options;
@@ -1614,17 +1613,7 @@ async function captureFullPage(options = {}) {
1614
1613
  logging: false,
1615
1614
  width: window.innerWidth,
1616
1615
  height: window.innerHeight,
1617
- onclone: (clonedDoc) => {
1618
- const unsupported = /oklab|oklch|color-mix/i;
1619
- clonedDoc.querySelectorAll("style").forEach((styleEl) => {
1620
- if (unsupported.test(styleEl.textContent || "")) {
1621
- styleEl.textContent = (styleEl.textContent || "").replace(
1622
- /[^{};\n]+:\s*[^;{}]*(?:oklab|oklch|color-mix|lch|lab)\([^)]*(?:\([^)]*\))*[^)]*\)[^;{}]*/gi,
1623
- ""
1624
- );
1625
- }
1626
- });
1627
- }
1616
+ onclone: (clonedDoc) => sanitizeUnsupportedColors(clonedDoc)
1628
1617
  });
1629
1618
  return canvas.toDataURL("image/jpeg", quality);
1630
1619
  } catch {
@@ -1633,23 +1622,6 @@ async function captureFullPage(options = {}) {
1633
1622
  hiddenEls.forEach((el) => el.style.visibility = "");
1634
1623
  }
1635
1624
  }
1636
- function loadImage(src) {
1637
- return new Promise((resolve, reject) => {
1638
- const img = new Image();
1639
- img.onload = () => resolve(img);
1640
- img.onerror = () => reject(new Error("\uC774\uBBF8\uC9C0 \uB85C\uB4DC \uC2E4\uD328"));
1641
- img.src = src;
1642
- });
1643
- }
1644
- function inlineComputedStyles(src, dst) {
1645
- const cs = window.getComputedStyle(src);
1646
- dst.style.cssText = cs.cssText;
1647
- const srcChildren = src.children;
1648
- const dstChildren = dst.children;
1649
- for (let i = 0; i < srcChildren.length && i < dstChildren.length; i++) {
1650
- inlineComputedStyles(srcChildren[i], dstChildren[i]);
1651
- }
1652
- }
1653
1625
 
1654
1626
  // src/core/collector.ts
1655
1627
  var MAX_ERRORS = 20;