@merittdev/horus-lens 0.1.0 → 0.1.1

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.cjs CHANGED
@@ -29381,6 +29381,11 @@ var ReplayRecorder = class {
29381
29381
  emit: (event, isCheckout) => this.onEmit(event, isCheckout),
29382
29382
  checkoutEveryNms: this.windowMs,
29383
29383
  recordCanvas: false,
29384
+ // Inline same-origin + CORS images as data URIs at snapshot time so the
29385
+ // dashboard replay paints on a different origin (tainted cross-origin
29386
+ // images fall back to their URL, which is fine for public CDNs).
29387
+ inlineImages: true,
29388
+ collectFonts: true,
29384
29389
  // Keep the Lens overlay itself out of every recording.
29385
29390
  blockSelector: `#${LENS_OVERLAY_HOST_ID}`
29386
29391
  });
@@ -29487,7 +29492,7 @@ var ReplayRecorder = class {
29487
29492
  console.warn("[lens] rrweb recording unavailable; replay disabled", err);
29488
29493
  }
29489
29494
  };
29490
- async function captureScreenshot(excludeHost) {
29495
+ async function captureScreenshot(excludeHost, crop) {
29491
29496
  if (typeof document === "undefined" || typeof window === "undefined") return null;
29492
29497
  try {
29493
29498
  const viewportPixels = window.innerWidth * window.innerHeight || 1;
@@ -29521,12 +29526,50 @@ async function captureScreenshot(excludeHost) {
29521
29526
  );
29522
29527
  return null;
29523
29528
  }
29529
+ if (crop) {
29530
+ const cropped = await cropBlob(blob2, crop, scale);
29531
+ return cropped ?? blob2;
29532
+ }
29524
29533
  return blob2;
29525
29534
  } catch (err) {
29526
29535
  console.warn("[lens] screenshot capture failed:", err);
29527
29536
  return null;
29528
29537
  }
29529
29538
  }
29539
+ async function cropBlob(blob2, crop, scale) {
29540
+ try {
29541
+ if (typeof createImageBitmap !== "function" || typeof document === "undefined") return null;
29542
+ const bitmap = await createImageBitmap(blob2);
29543
+ let sx = Math.round(crop.x * scale);
29544
+ let sy = Math.round(crop.y * scale);
29545
+ let sw = Math.round(crop.width * scale);
29546
+ let sh = Math.round(crop.height * scale);
29547
+ sx = Math.max(0, Math.min(sx, bitmap.width));
29548
+ sy = Math.max(0, Math.min(sy, bitmap.height));
29549
+ sw = Math.min(sw, bitmap.width - sx);
29550
+ sh = Math.min(sh, bitmap.height - sy);
29551
+ if (sw <= 0 || sh <= 0) {
29552
+ bitmap.close?.();
29553
+ return null;
29554
+ }
29555
+ const canvas = document.createElement("canvas");
29556
+ canvas.width = sw;
29557
+ canvas.height = sh;
29558
+ const ctx = canvas.getContext("2d");
29559
+ if (!ctx) {
29560
+ bitmap.close?.();
29561
+ return null;
29562
+ }
29563
+ ctx.drawImage(bitmap, sx, sy, sw, sh, 0, 0, sw, sh);
29564
+ bitmap.close?.();
29565
+ return await new Promise((resolve) => {
29566
+ canvas.toBlob((out) => resolve(out), "image/jpeg", 0.82);
29567
+ });
29568
+ } catch (err) {
29569
+ console.warn("[lens] screenshot crop failed:", err);
29570
+ return null;
29571
+ }
29572
+ }
29530
29573
  function parseBrowser(ua) {
29531
29574
  if (!ua) return void 0;
29532
29575
  const checks = [
@@ -29791,7 +29834,7 @@ var LensClient = class {
29791
29834
  const wantErrors = include.errors !== false;
29792
29835
  const wantScreenshot = include.screenshot !== false;
29793
29836
  const wantDom = include.dom !== false;
29794
- const screenshotPromise = this.screenshotEnabled && wantScreenshot ? captureScreenshot(input2.excludeFromScreenshot) : Promise.resolve(null);
29837
+ const screenshotPromise = this.screenshotEnabled && wantScreenshot ? captureScreenshot(input2.excludeFromScreenshot, input2.screenshotCrop) : Promise.resolve(null);
29795
29838
  const replayEvents = wantReplay ? this.replay?.snapshot() ?? [] : [];
29796
29839
  const errorEntries = this.errorBuffer.drain();
29797
29840
  const consoleTail = this.consoleBuffer.tail(CONSOLE_TAIL_SIZE);