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.cjs
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jspdf = require('jspdf');
|
|
5
|
-
var
|
|
5
|
+
var modernScreenshot = require('modern-screenshot');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
|
|
8
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var html2canvas__default = /*#__PURE__*/_interopDefault(html2canvas);
|
|
12
|
-
|
|
13
9
|
// src/components/TrailProvider.tsx
|
|
14
10
|
|
|
15
11
|
// src/core/TrailStore.ts
|
|
@@ -1060,38 +1056,48 @@ async function captureScreenshot(targetElement, options) {
|
|
|
1060
1056
|
return null;
|
|
1061
1057
|
}
|
|
1062
1058
|
const element = targetElement || document.body;
|
|
1063
|
-
const quality = options?.quality ?? 0.
|
|
1059
|
+
const quality = options?.quality ?? 0.92;
|
|
1064
1060
|
const maxWidth = options?.maxWidth ?? 1400;
|
|
1065
1061
|
const timeout = options?.timeout ?? 5e3;
|
|
1066
|
-
const
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1062
|
+
const format = options?.format ?? "jpeg";
|
|
1063
|
+
const scale = options?.scale ?? Math.min(window.devicePixelRatio || 1, 2);
|
|
1064
|
+
const autoCompress = options?.autoCompress !== false;
|
|
1065
|
+
const elementWidth = element.scrollWidth;
|
|
1066
|
+
let effectiveScale = scale;
|
|
1067
|
+
if (elementWidth * scale > maxWidth * 2) {
|
|
1068
|
+
effectiveScale = maxWidth * 2 / elementWidth;
|
|
1069
|
+
}
|
|
1070
|
+
const capturePromise = (async () => {
|
|
1071
|
+
if (autoCompress || format === "jpeg") {
|
|
1072
|
+
const canvas = await modernScreenshot.domToCanvas(element, {
|
|
1073
|
+
scale: effectiveScale,
|
|
1074
|
+
backgroundColor: "#ffffff",
|
|
1075
|
+
fetch: { requestInit: { credentials: "omit" } }
|
|
1076
|
+
});
|
|
1077
|
+
if (!canvas) return null;
|
|
1078
|
+
const mime = format === "png" ? "image/png" : "image/jpeg";
|
|
1079
|
+
let dataUrl2 = canvas.toDataURL(
|
|
1080
|
+
mime,
|
|
1081
|
+
format === "jpeg" ? quality : void 0
|
|
1082
|
+
);
|
|
1083
|
+
if (autoCompress && dataUrl2.length > 10 * 1024 * 1024) {
|
|
1084
|
+
dataUrl2 = canvas.toDataURL("image/jpeg", 0.5);
|
|
1085
|
+
}
|
|
1086
|
+
return dataUrl2;
|
|
1087
|
+
}
|
|
1088
|
+
return await modernScreenshot.domToDataUrl(element, {
|
|
1089
|
+
scale: effectiveScale,
|
|
1072
1090
|
backgroundColor: "#ffffff",
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
imageTimeout: 3e3,
|
|
1079
|
-
// Resim yükleme timeout'u
|
|
1080
|
-
removeContainer: true,
|
|
1081
|
-
// Geçici container'ı temizle
|
|
1082
|
-
width: Math.min(element.scrollWidth, maxWidth),
|
|
1083
|
-
windowWidth: Math.min(element.scrollWidth, maxWidth)
|
|
1084
|
-
}),
|
|
1091
|
+
fetch: { requestInit: { credentials: "omit" } }
|
|
1092
|
+
});
|
|
1093
|
+
})();
|
|
1094
|
+
const dataUrl = await Promise.race([
|
|
1095
|
+
capturePromise,
|
|
1085
1096
|
new Promise(
|
|
1086
1097
|
(_, reject) => setTimeout(() => reject(new Error("Screenshot timeout")), timeout)
|
|
1087
1098
|
)
|
|
1088
1099
|
]);
|
|
1089
|
-
|
|
1090
|
-
const dataUrl = canvas.toDataURL("image/png", quality);
|
|
1091
|
-
if (dataUrl.length > 10 * 1024 * 1024) {
|
|
1092
|
-
return canvas.toDataURL("image/jpeg", 0.5);
|
|
1093
|
-
}
|
|
1094
|
-
return dataUrl;
|
|
1100
|
+
return dataUrl ?? null;
|
|
1095
1101
|
} catch (error) {
|
|
1096
1102
|
console.warn("[react-request-trail] Screenshot yakalama basarisiz:", error);
|
|
1097
1103
|
return null;
|