@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.js CHANGED
@@ -7869,27 +7869,48 @@ function ScreenAnnotator({ zIndex: zIndex2, onCapture, onCancel }) {
7869
7869
  return;
7870
7870
  }
7871
7871
  setPhase("capturing");
7872
+ const sx = window.scrollX ?? window.pageXOffset ?? 0;
7873
+ const sy = window.scrollY ?? window.pageYOffset ?? 0;
7874
+ const dpr = window.devicePixelRatio ?? 1;
7875
+ const vw = window.innerWidth;
7876
+ const vh = window.innerHeight;
7872
7877
  await new Promise(
7873
7878
  (resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve()))
7874
7879
  );
7875
7880
  const unpatch = patchGetComputedStyle();
7876
7881
  try {
7877
- const canvas = await html2canvas_esm_default(document.body, {
7882
+ const fullCanvas = await html2canvas_esm_default(document.body, {
7878
7883
  useCORS: true,
7879
7884
  logging: false,
7880
7885
  allowTaint: true,
7886
+ scale: dpr,
7887
+ scrollX: -sx,
7888
+ scrollY: -sy,
7881
7889
  ignoreElements: (el) => el === overlayRef.current
7882
7890
  });
7883
7891
  unpatch();
7884
- const dpr = window.devicePixelRatio ?? 1;
7885
- const sx = window.scrollX ?? window.pageXOffset ?? 0;
7886
- const sy = window.scrollY ?? window.pageYOffset ?? 0;
7892
+ const canvas = document.createElement("canvas");
7893
+ canvas.width = vw * dpr;
7894
+ canvas.height = vh * dpr;
7887
7895
  const ctx = canvas.getContext("2d");
7896
+ ctx.drawImage(
7897
+ fullCanvas,
7898
+ sx * dpr,
7899
+ sy * dpr,
7900
+ vw * dpr,
7901
+ vh * dpr,
7902
+ // source: viewport region from full capture
7903
+ 0,
7904
+ 0,
7905
+ vw * dpr,
7906
+ vh * dpr
7907
+ // dest: fill the cropped canvas
7908
+ );
7888
7909
  ctx.fillStyle = "rgba(255,200,0,0.25)";
7889
- ctx.fillRect((finalRect.x + sx) * dpr, (finalRect.y + sy) * dpr, finalRect.w * dpr, finalRect.h * dpr);
7910
+ ctx.fillRect(finalRect.x * dpr, finalRect.y * dpr, finalRect.w * dpr, finalRect.h * dpr);
7890
7911
  ctx.strokeStyle = "#f97316";
7891
7912
  ctx.lineWidth = 3 * dpr;
7892
- ctx.strokeRect((finalRect.x + sx) * dpr, (finalRect.y + sy) * dpr, finalRect.w * dpr, finalRect.h * dpr);
7913
+ ctx.strokeRect(finalRect.x * dpr, finalRect.y * dpr, finalRect.w * dpr, finalRect.h * dpr);
7893
7914
  canvas.toBlob((blob) => {
7894
7915
  if (blob) {
7895
7916
  onCapture(new File([blob], "annotation.png", { type: "image/png" }));
@@ -8376,7 +8397,7 @@ function FlintModal({
8376
8397
  onCancel: () => setAnnotating(false)
8377
8398
  }
8378
8399
  ),
8379
- /* @__PURE__ */ jsx2("div", { ref: overlayRef, style: { ...overlayStyle, opacity: annotating ? 0 : 1, pointerEvents: annotating ? "none" : "auto" }, onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs2("div", { style: modalStyle, role: "dialog", "aria-modal": "true", "aria-labelledby": "flint-modal-title", children: [
8400
+ !annotating && /* @__PURE__ */ jsx2("div", { ref: overlayRef, style: overlayStyle, onClick: handleOverlayClick, children: /* @__PURE__ */ jsxs2("div", { style: modalStyle, role: "dialog", "aria-modal": "true", "aria-labelledby": "flint-modal-title", children: [
8380
8401
  /* @__PURE__ */ jsx2(
8381
8402
  ModalHeader,
8382
8403
  {
@@ -8914,10 +8935,11 @@ var BLOCKED_HOSTS = /* @__PURE__ */ new Set([
8914
8935
  "logs.browser-intake-datadoghq.com",
8915
8936
  "session-replay.browser-intake-datadoghq.com"
8916
8937
  ]);
8917
- function isBlockedUrl(url) {
8938
+ function isBlockedUrl(url, extra) {
8918
8939
  try {
8919
8940
  const host = new URL(url, location.href).hostname;
8920
- return BLOCKED_HOSTS.has(host) || [...BLOCKED_HOSTS].some((b) => host.endsWith("." + b));
8941
+ const all = [...BLOCKED_HOSTS, ...extra];
8942
+ return all.some((b) => host === b || host.endsWith("." + b));
8921
8943
  } catch {
8922
8944
  return false;
8923
8945
  }
@@ -8931,8 +8953,9 @@ function truncateUrl(url) {
8931
8953
  return url.length > 200 ? url.slice(0, 200) + "\u2026" : url;
8932
8954
  }
8933
8955
  }
8934
- function createNetworkCollector() {
8956
+ function createNetworkCollector(extraBlockedHosts = []) {
8935
8957
  const entries = [];
8958
+ const blocked = new Set(extraBlockedHosts);
8936
8959
  let origFetch = null;
8937
8960
  let origXHROpen = null;
8938
8961
  let active = false;
@@ -8950,7 +8973,7 @@ function createNetworkCollector() {
8950
8973
  const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
8951
8974
  const startTime = Date.now();
8952
8975
  const res = await origFetch.call(window, input, init);
8953
- if (!isBlockedUrl(url)) {
8976
+ if (!isBlockedUrl(url, blocked)) {
8954
8977
  push({
8955
8978
  method,
8956
8979
  url: truncateUrl(url),
@@ -8966,7 +8989,7 @@ function createNetworkCollector() {
8966
8989
  const startTime = Date.now();
8967
8990
  const urlStr = typeof url === "string" ? url : url.href;
8968
8991
  this.addEventListener("load", () => {
8969
- if (!isBlockedUrl(urlStr)) {
8992
+ if (!isBlockedUrl(urlStr, blocked)) {
8970
8993
  push({
8971
8994
  method: method.toUpperCase(),
8972
8995
  url: truncateUrl(urlStr),
@@ -9066,7 +9089,14 @@ function WidgetContent({
9066
9089
  consoleCollector.current.start();
9067
9090
  }
9068
9091
  if (!networkCollector.current) {
9069
- networkCollector.current = createNetworkCollector();
9092
+ const flintHost = (() => {
9093
+ try {
9094
+ return new URL(serverUrl).hostname;
9095
+ } catch {
9096
+ return "";
9097
+ }
9098
+ })();
9099
+ networkCollector.current = createNetworkCollector(flintHost ? [flintHost] : []);
9070
9100
  networkCollector.current.start();
9071
9101
  }
9072
9102
  useEffect3(() => {