@diegotsi/flint-react 0.3.3 → 0.4.0

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
@@ -7897,27 +7897,48 @@ function ScreenAnnotator({ zIndex: zIndex2, onCapture, onCancel }) {
7897
7897
  return;
7898
7898
  }
7899
7899
  setPhase("capturing");
7900
+ const sx = window.scrollX ?? window.pageXOffset ?? 0;
7901
+ const sy = window.scrollY ?? window.pageYOffset ?? 0;
7902
+ const dpr = window.devicePixelRatio ?? 1;
7903
+ const vw = window.innerWidth;
7904
+ const vh = window.innerHeight;
7900
7905
  await new Promise(
7901
7906
  (resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
7902
7907
  );
7903
7908
  const unpatch = patchGetComputedStyle();
7904
7909
  try {
7905
- const canvas = await html2canvas_esm_default(document.body, {
7910
+ const fullCanvas = await html2canvas_esm_default(document.body, {
7906
7911
  useCORS: true,
7907
7912
  logging: false,
7908
7913
  allowTaint: true,
7914
+ scale: dpr,
7915
+ scrollX: -sx,
7916
+ scrollY: -sy,
7909
7917
  ignoreElements: (el) => el === overlayRef.current
7910
7918
  });
7911
7919
  unpatch();
7912
- const dpr = window.devicePixelRatio ?? 1;
7913
- const sx = window.scrollX ?? window.pageXOffset ?? 0;
7914
- const sy = window.scrollY ?? window.pageYOffset ?? 0;
7920
+ const canvas = document.createElement("canvas");
7921
+ canvas.width = vw * dpr;
7922
+ canvas.height = vh * dpr;
7915
7923
  const ctx = canvas.getContext("2d");
7924
+ ctx.drawImage(
7925
+ fullCanvas,
7926
+ sx * dpr,
7927
+ sy * dpr,
7928
+ vw * dpr,
7929
+ vh * dpr,
7930
+ // source: viewport region from full capture
7931
+ 0,
7932
+ 0,
7933
+ vw * dpr,
7934
+ vh * dpr
7935
+ // dest: fill the cropped canvas
7936
+ );
7916
7937
  ctx.fillStyle = "rgba(255,200,0,0.25)";
7917
- ctx.fillRect((finalRect.x + sx) * dpr, (finalRect.y + sy) * dpr, finalRect.w * dpr, finalRect.h * dpr);
7938
+ ctx.fillRect(finalRect.x * dpr, finalRect.y * dpr, finalRect.w * dpr, finalRect.h * dpr);
7918
7939
  ctx.strokeStyle = "#f97316";
7919
7940
  ctx.lineWidth = 3 * dpr;
7920
- ctx.strokeRect((finalRect.x + sx) * dpr, (finalRect.y + sy) * dpr, finalRect.w * dpr, finalRect.h * dpr);
7941
+ ctx.strokeRect(finalRect.x * dpr, finalRect.y * dpr, finalRect.w * dpr, finalRect.h * dpr);
7921
7942
  canvas.toBlob((blob) => {
7922
7943
  if (blob) {
7923
7944
  onCapture(new File([blob], "annotation.png", { type: "image/png" }));
@@ -8404,7 +8425,7 @@ function FlintModal({
8404
8425
  onCancel: () => setAnnotating(false)
8405
8426
  }
8406
8427
  ),
8407
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: overlayRef, style: { ...overlayStyle, opacity: annotating ? 0 : 1, pointerEvents: annotating ? "none" : "auto" }, onClick: handleOverlayClick, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: modalStyle, role: "dialog", "aria-modal": "true", "aria-labelledby": "flint-modal-title", children: [
8428
+ !annotating && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ref: overlayRef, style: overlayStyle, onClick: handleOverlayClick, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: modalStyle, role: "dialog", "aria-modal": "true", "aria-labelledby": "flint-modal-title", children: [
8408
8429
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8409
8430
  ModalHeader,
8410
8431
  {
@@ -8942,10 +8963,11 @@ var BLOCKED_HOSTS = /* @__PURE__ */ new Set([
8942
8963
  "logs.browser-intake-datadoghq.com",
8943
8964
  "session-replay.browser-intake-datadoghq.com"
8944
8965
  ]);
8945
- function isBlockedUrl(url) {
8966
+ function isBlockedUrl(url, extra) {
8946
8967
  try {
8947
8968
  const host = new URL(url, location.href).hostname;
8948
- return BLOCKED_HOSTS.has(host) || [...BLOCKED_HOSTS].some((b) => host.endsWith("." + b));
8969
+ const all = [...BLOCKED_HOSTS, ...extra];
8970
+ return all.some((b) => host === b || host.endsWith("." + b));
8949
8971
  } catch {
8950
8972
  return false;
8951
8973
  }
@@ -8959,8 +8981,9 @@ function truncateUrl(url) {
8959
8981
  return url.length > 200 ? url.slice(0, 200) + "\u2026" : url;
8960
8982
  }
8961
8983
  }
8962
- function createNetworkCollector() {
8984
+ function createNetworkCollector(extraBlockedHosts = []) {
8963
8985
  const entries = [];
8986
+ const blocked = new Set(extraBlockedHosts);
8964
8987
  let origFetch = null;
8965
8988
  let origXHROpen = null;
8966
8989
  let active = false;
@@ -8978,7 +9001,7 @@ function createNetworkCollector() {
8978
9001
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
8979
9002
  const startTime = Date.now();
8980
9003
  const res = await origFetch.call(window, input, init);
8981
- if (!isBlockedUrl(url)) {
9004
+ if (!isBlockedUrl(url, blocked)) {
8982
9005
  push({
8983
9006
  method,
8984
9007
  url: truncateUrl(url),
@@ -8994,7 +9017,7 @@ function createNetworkCollector() {
8994
9017
  const startTime = Date.now();
8995
9018
  const urlStr = typeof url === "string" ? url : url.href;
8996
9019
  this.addEventListener("load", () => {
8997
- if (!isBlockedUrl(urlStr)) {
9020
+ if (!isBlockedUrl(urlStr, blocked)) {
8998
9021
  push({
8999
9022
  method: method.toUpperCase(),
9000
9023
  url: truncateUrl(urlStr),
@@ -9094,7 +9117,14 @@ function WidgetContent({
9094
9117
  consoleCollector.current.start();
9095
9118
  }
9096
9119
  if (!networkCollector.current) {
9097
- networkCollector.current = createNetworkCollector();
9120
+ const flintHost = (() => {
9121
+ try {
9122
+ return new URL(serverUrl).hostname;
9123
+ } catch {
9124
+ return "";
9125
+ }
9126
+ })();
9127
+ networkCollector.current = createNetworkCollector(flintHost ? [flintHost] : []);
9098
9128
  networkCollector.current.start();
9099
9129
  }
9100
9130
  (0, import_react4.useEffect)(() => {