react-request-trail 1.0.0 → 1.1.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 +36 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +36 -26
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -197,19 +197,29 @@ declare function blobToBase64(blob: Blob): Promise<string>;
|
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
199
|
* Hata aninda sayfanin ekran goruntusunu alir.
|
|
200
|
-
* html2canvas kullanarak DOM'u canvas'a render eder, ardindan base64 data URL'e donusturur.
|
|
201
200
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
201
|
+
* v1.1: html2canvas yerine `modern-screenshot` kullanilir.
|
|
202
|
+
* - html2canvas her DOM node'unu recursive walk edip canvas'a yeniden cizer.
|
|
203
|
+
* Buyuk/karmasik sayfalar icin 30-60 saniye surebiliyordu.
|
|
204
|
+
* - modern-screenshot SVG `<foreignObject>` + native `Image()` API kullanir,
|
|
205
|
+
* tarayicinin kendi rasterleyicisinden faydalanir. Tipik bir sayfa icin
|
|
206
|
+
* 500ms - 2 saniye arasi.
|
|
207
|
+
*
|
|
208
|
+
* API ayni: `(targetElement?, options?) => Promise<string | null>` doner.
|
|
205
209
|
*/
|
|
206
210
|
declare function captureScreenshot(targetElement?: HTMLElement, options?: {
|
|
207
|
-
/** Kalite (0-1 arasi, default: 0.
|
|
211
|
+
/** Kalite (0-1 arasi, default: 0.92 — JPEG icin) */
|
|
208
212
|
quality?: number;
|
|
209
213
|
/** Maksimum genislik (px, default: 1400) */
|
|
210
214
|
maxWidth?: number;
|
|
211
215
|
/** Timeout (ms, default: 5000) */
|
|
212
216
|
timeout?: number;
|
|
217
|
+
/** Format. PNG buyuk, JPEG kucuk. Default: 'jpeg' */
|
|
218
|
+
format?: 'png' | 'jpeg';
|
|
219
|
+
/** DPI carpani. 1 (kucuk), 2 (retina, default), 3 (cok yuksek) */
|
|
220
|
+
scale?: number;
|
|
221
|
+
/** 10MB ustu cikti varsa otomatik JPEG'e dusur (default: true) */
|
|
222
|
+
autoCompress?: boolean;
|
|
213
223
|
}): Promise<string | null>;
|
|
214
224
|
|
|
215
225
|
declare const helpers: {
|
package/dist/index.d.ts
CHANGED
|
@@ -197,19 +197,29 @@ declare function blobToBase64(blob: Blob): Promise<string>;
|
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
199
|
* Hata aninda sayfanin ekran goruntusunu alir.
|
|
200
|
-
* html2canvas kullanarak DOM'u canvas'a render eder, ardindan base64 data URL'e donusturur.
|
|
201
200
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
201
|
+
* v1.1: html2canvas yerine `modern-screenshot` kullanilir.
|
|
202
|
+
* - html2canvas her DOM node'unu recursive walk edip canvas'a yeniden cizer.
|
|
203
|
+
* Buyuk/karmasik sayfalar icin 30-60 saniye surebiliyordu.
|
|
204
|
+
* - modern-screenshot SVG `<foreignObject>` + native `Image()` API kullanir,
|
|
205
|
+
* tarayicinin kendi rasterleyicisinden faydalanir. Tipik bir sayfa icin
|
|
206
|
+
* 500ms - 2 saniye arasi.
|
|
207
|
+
*
|
|
208
|
+
* API ayni: `(targetElement?, options?) => Promise<string | null>` doner.
|
|
205
209
|
*/
|
|
206
210
|
declare function captureScreenshot(targetElement?: HTMLElement, options?: {
|
|
207
|
-
/** Kalite (0-1 arasi, default: 0.
|
|
211
|
+
/** Kalite (0-1 arasi, default: 0.92 — JPEG icin) */
|
|
208
212
|
quality?: number;
|
|
209
213
|
/** Maksimum genislik (px, default: 1400) */
|
|
210
214
|
maxWidth?: number;
|
|
211
215
|
/** Timeout (ms, default: 5000) */
|
|
212
216
|
timeout?: number;
|
|
217
|
+
/** Format. PNG buyuk, JPEG kucuk. Default: 'jpeg' */
|
|
218
|
+
format?: 'png' | 'jpeg';
|
|
219
|
+
/** DPI carpani. 1 (kucuk), 2 (retina, default), 3 (cok yuksek) */
|
|
220
|
+
scale?: number;
|
|
221
|
+
/** 10MB ustu cikti varsa otomatik JPEG'e dusur (default: true) */
|
|
222
|
+
autoCompress?: boolean;
|
|
213
223
|
}): Promise<string | null>;
|
|
214
224
|
|
|
215
225
|
declare const helpers: {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext, Component, useRef, useState, useEffect, useCallback, useMemo, useContext } from 'react';
|
|
2
2
|
import { jsPDF } from 'jspdf';
|
|
3
|
-
import
|
|
3
|
+
import { domToCanvas, domToDataUrl } from 'modern-screenshot';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
// src/components/TrailProvider.tsx
|
|
@@ -1053,38 +1053,48 @@ async function captureScreenshot(targetElement, options) {
|
|
|
1053
1053
|
return null;
|
|
1054
1054
|
}
|
|
1055
1055
|
const element = targetElement || document.body;
|
|
1056
|
-
const quality = options?.quality ?? 0.
|
|
1056
|
+
const quality = options?.quality ?? 0.92;
|
|
1057
1057
|
const maxWidth = options?.maxWidth ?? 1400;
|
|
1058
1058
|
const timeout = options?.timeout ?? 5e3;
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1059
|
+
const format = options?.format ?? "jpeg";
|
|
1060
|
+
const scale = options?.scale ?? Math.min(window.devicePixelRatio || 1, 2);
|
|
1061
|
+
const autoCompress = options?.autoCompress !== false;
|
|
1062
|
+
const elementWidth = element.scrollWidth;
|
|
1063
|
+
let effectiveScale = scale;
|
|
1064
|
+
if (elementWidth * scale > maxWidth * 2) {
|
|
1065
|
+
effectiveScale = maxWidth * 2 / elementWidth;
|
|
1066
|
+
}
|
|
1067
|
+
const capturePromise = (async () => {
|
|
1068
|
+
if (autoCompress || format === "jpeg") {
|
|
1069
|
+
const canvas = await domToCanvas(element, {
|
|
1070
|
+
scale: effectiveScale,
|
|
1071
|
+
backgroundColor: "#ffffff",
|
|
1072
|
+
fetch: { requestInit: { credentials: "omit" } }
|
|
1073
|
+
});
|
|
1074
|
+
if (!canvas) return null;
|
|
1075
|
+
const mime = format === "png" ? "image/png" : "image/jpeg";
|
|
1076
|
+
let dataUrl2 = canvas.toDataURL(
|
|
1077
|
+
mime,
|
|
1078
|
+
format === "jpeg" ? quality : void 0
|
|
1079
|
+
);
|
|
1080
|
+
if (autoCompress && dataUrl2.length > 10 * 1024 * 1024) {
|
|
1081
|
+
dataUrl2 = canvas.toDataURL("image/jpeg", 0.5);
|
|
1082
|
+
}
|
|
1083
|
+
return dataUrl2;
|
|
1084
|
+
}
|
|
1085
|
+
return await domToDataUrl(element, {
|
|
1086
|
+
scale: effectiveScale,
|
|
1065
1087
|
backgroundColor: "#ffffff",
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
imageTimeout: 3e3,
|
|
1072
|
-
// Resim yükleme timeout'u
|
|
1073
|
-
removeContainer: true,
|
|
1074
|
-
// Geçici container'ı temizle
|
|
1075
|
-
width: Math.min(element.scrollWidth, maxWidth),
|
|
1076
|
-
windowWidth: Math.min(element.scrollWidth, maxWidth)
|
|
1077
|
-
}),
|
|
1088
|
+
fetch: { requestInit: { credentials: "omit" } }
|
|
1089
|
+
});
|
|
1090
|
+
})();
|
|
1091
|
+
const dataUrl = await Promise.race([
|
|
1092
|
+
capturePromise,
|
|
1078
1093
|
new Promise(
|
|
1079
1094
|
(_, reject) => setTimeout(() => reject(new Error("Screenshot timeout")), timeout)
|
|
1080
1095
|
)
|
|
1081
1096
|
]);
|
|
1082
|
-
|
|
1083
|
-
const dataUrl = canvas.toDataURL("image/png", quality);
|
|
1084
|
-
if (dataUrl.length > 10 * 1024 * 1024) {
|
|
1085
|
-
return canvas.toDataURL("image/jpeg", 0.5);
|
|
1086
|
-
}
|
|
1087
|
-
return dataUrl;
|
|
1097
|
+
return dataUrl ?? null;
|
|
1088
1098
|
} catch (error) {
|
|
1089
1099
|
console.warn("[react-request-trail] Screenshot yakalama basarisiz:", error);
|
|
1090
1100
|
return null;
|