@impakers/debug 1.4.2 → 1.4.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/react.js CHANGED
@@ -1484,15 +1484,20 @@ function probeComponentSource(fiber) {
1484
1484
  return result;
1485
1485
  }
1486
1486
  function probeSourceWalk(fiber, maxDepth = 15) {
1487
+ const results = [];
1488
+ const seenFileNames = /* @__PURE__ */ new Set();
1487
1489
  let current = fiber;
1488
1490
  let depth = 0;
1489
1491
  while (current && depth < maxDepth) {
1490
1492
  const source = probeComponentSource(current);
1491
- if (source) return source;
1493
+ if (source && !seenFileNames.has(source.fileName)) {
1494
+ seenFileNames.add(source.fileName);
1495
+ results.push(source);
1496
+ }
1492
1497
  current = current.return;
1493
1498
  depth++;
1494
1499
  }
1495
- return null;
1500
+ return results;
1496
1501
  }
1497
1502
  function getSourceLocation(element) {
1498
1503
  const fiber = getFiberFromElement2(element);
@@ -1521,9 +1526,15 @@ function getSourceLocation(element) {
1521
1526
  isProduction: false
1522
1527
  };
1523
1528
  }
1524
- const probed = probeSourceWalk(fiber);
1525
- if (probed) {
1526
- return { found: true, source: probed, isReactApp: true, isProduction: false };
1529
+ const probedList = probeSourceWalk(fiber);
1530
+ if (probedList.length > 0) {
1531
+ return {
1532
+ found: true,
1533
+ source: probedList[0],
1534
+ sourceCandidates: probedList,
1535
+ isReactApp: true,
1536
+ isProduction: false
1537
+ };
1527
1538
  }
1528
1539
  return {
1529
1540
  found: false,
@@ -2430,7 +2441,18 @@ function CommentThread({
2430
2441
  useCORS: true,
2431
2442
  allowTaint: true,
2432
2443
  scale: Math.min(window.devicePixelRatio, 2),
2433
- logging: false
2444
+ logging: false,
2445
+ onclone: (clonedDoc) => {
2446
+ const unsupported = /oklab|oklch|color-mix|(?<![a-z])lch|(?<![a-z])lab/i;
2447
+ clonedDoc.querySelectorAll("style").forEach((styleEl) => {
2448
+ if (unsupported.test(styleEl.textContent || "")) {
2449
+ styleEl.textContent = (styleEl.textContent || "").replace(
2450
+ /[^{};\n]+:\s*[^;{}]*(?:oklab|oklch|color-mix|lch|lab)\([^)]*(?:\([^)]*\))*[^)]*\)[^;{}]*/gi,
2451
+ ""
2452
+ );
2453
+ }
2454
+ });
2455
+ }
2434
2456
  });
2435
2457
  const base64 = canvas.toDataURL("image/jpeg", 0.7);
2436
2458
  setPendingImage(base64);
@@ -3359,6 +3381,17 @@ function detectSourceFile(element) {
3359
3381
  }
3360
3382
  return void 0;
3361
3383
  }
3384
+ function detectSourceFileCandidates(element) {
3385
+ const result = getSourceLocation(element);
3386
+ const loc = result.found ? result : findNearestComponentSource(element);
3387
+ if (loc.found && loc.sourceCandidates && loc.sourceCandidates.length > 0) {
3388
+ return loc.sourceCandidates.map((s) => formatSourceLocation(s, "path"));
3389
+ }
3390
+ if (loc.found && loc.source) {
3391
+ return [formatSourceLocation(loc.source, "path")];
3392
+ }
3393
+ return [];
3394
+ }
3362
3395
  var STORAGE_PREFIX = "impakers-debug-markers-";
3363
3396
  function getRouteKey() {
3364
3397
  return STORAGE_PREFIX + window.location.pathname;
@@ -3631,25 +3664,36 @@ function DebugWidget({ endpoint, getUser, onHide }) {
3631
3664
  targetElement: elementUnder
3632
3665
  });
3633
3666
  setHoverInfo(null);
3634
- const rawSource = detectSourceFile(elementUnder);
3635
- if (rawSource?.includes("/chunks/")) {
3636
- resolveSourceString(rawSource).then((resolved) => {
3637
- if (resolved) {
3638
- setPendingAnnotation(
3639
- (prev) => prev ? {
3640
- ...prev,
3641
- resolvedSource: `${resolved.source}:${resolved.line}`,
3642
- resolvedName: resolved.name ?? void 0
3643
- } : prev
3644
- );
3667
+ const candidates = detectSourceFileCandidates(elementUnder);
3668
+ const chunkCandidates = candidates.filter((c) => c.includes("/chunks/"));
3669
+ if (chunkCandidates.length > 0) {
3670
+ (async () => {
3671
+ for (const candidate of chunkCandidates) {
3672
+ try {
3673
+ const resolved = await resolveSourceString(candidate);
3674
+ if (resolved) {
3675
+ setPendingAnnotation(
3676
+ (prev) => prev ? {
3677
+ ...prev,
3678
+ resolvedSource: `${resolved.source}:${resolved.line}`,
3679
+ resolvedName: resolved.name ?? void 0
3680
+ } : prev
3681
+ );
3682
+ break;
3683
+ }
3684
+ } catch {
3685
+ }
3645
3686
  }
3646
- }).catch(() => {
3647
- });
3687
+ })();
3648
3688
  }
3649
3689
  };
3650
3690
  document.addEventListener("click", handleClick, true);
3651
3691
  return () => document.removeEventListener("click", handleClick, true);
3652
3692
  }, [isActive, pendingAnnotation]);
3693
+ const showErrorToast = (0, import_react7.useCallback)((msg) => {
3694
+ setToastError(msg);
3695
+ originalSetTimeout(() => setToastError(null), 4e3);
3696
+ }, []);
3653
3697
  const addAnnotation = (0, import_react7.useCallback)(
3654
3698
  async (comment) => {
3655
3699
  if (!pendingAnnotation || submitting) return;
@@ -3665,19 +3709,29 @@ function DebugWidget({ endpoint, getUser, onHide }) {
3665
3709
  useCORS: true,
3666
3710
  allowTaint: true,
3667
3711
  scale: 1,
3668
- // 1x로 줄여서 용량 절약
3669
3712
  logging: false,
3670
3713
  width: window.innerWidth,
3671
- height: window.innerHeight
3714
+ height: window.innerHeight,
3715
+ onclone: (clonedDoc) => {
3716
+ const unsupported = /oklab|oklch|color-mix|(?<![a-z])lch|(?<![a-z])lab/i;
3717
+ clonedDoc.querySelectorAll("style").forEach((styleEl) => {
3718
+ if (unsupported.test(styleEl.textContent || "")) {
3719
+ styleEl.textContent = (styleEl.textContent || "").replace(
3720
+ /[^{};\n]+:\s*[^;{}]*(?:oklab|oklch|color-mix|lch|lab)\([^)]*(?:\([^)]*\))*[^)]*\)[^;{}]*/gi,
3721
+ ""
3722
+ );
3723
+ }
3724
+ });
3725
+ }
3672
3726
  });
3673
3727
  screenshot = canvas.toDataURL("image/jpeg", 0.5);
3674
3728
  } catch {
3675
3729
  } finally {
3676
3730
  debugEls.forEach((el) => el.style.visibility = "");
3677
3731
  }
3678
- let resolvedSource = pendingAnnotation.sourceFile || "";
3679
- let resolvedName = null;
3680
- if (pendingAnnotation.sourceFile?.includes("/chunks/")) {
3732
+ let resolvedSource = pendingAnnotation.resolvedSource || pendingAnnotation.sourceFile || "";
3733
+ let resolvedName = pendingAnnotation.resolvedName || null;
3734
+ if (!pendingAnnotation.resolvedSource && pendingAnnotation.sourceFile?.includes("/chunks/")) {
3681
3735
  try {
3682
3736
  const resolved = await resolveSourceString(pendingAnnotation.sourceFile);
3683
3737
  if (resolved) {
@@ -3816,10 +3870,6 @@ ${elementInfo.join("\n")}`);
3816
3870
  });
3817
3871
  return unsubscribe;
3818
3872
  }, [activeThread, endpoint]);
3819
- const showErrorToast = (0, import_react7.useCallback)((msg) => {
3820
- setToastError(msg);
3821
- originalSetTimeout(() => setToastError(null), 4e3);
3822
- }, []);
3823
3873
  const handleThreadReply = (0, import_react7.useCallback)(async (taskId, content, screenshot, file) => {
3824
3874
  const authorName = getUser?.()?.name ? String(getUser().name) : "\uC775\uBA85";
3825
3875
  const authorId = getUser?.()?.id ? String(getUser().id) : void 0;