feedback-vos 1.0.39 → 1.0.40
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 +40 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -381,24 +381,52 @@ function ScreenshotButton({
|
|
|
381
381
|
const themeClasses = getThemeClasses(theme);
|
|
382
382
|
async function handleTakeScreenshot() {
|
|
383
383
|
setIsTakenScreenShot(true);
|
|
384
|
-
const canvas = await html2canvas(document.
|
|
384
|
+
const canvas = await html2canvas(document.documentElement, {
|
|
385
385
|
width: window.innerWidth,
|
|
386
386
|
height: window.innerHeight,
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
x: 0,
|
|
388
|
+
y: 0,
|
|
389
389
|
windowWidth: window.innerWidth,
|
|
390
390
|
windowHeight: window.innerHeight,
|
|
391
|
-
scale:
|
|
392
|
-
// Use
|
|
391
|
+
scale: 1,
|
|
392
|
+
// Use scale 1 for consistent sizing
|
|
393
393
|
useCORS: true,
|
|
394
|
-
// Enable CORS for better image rendering
|
|
395
394
|
logging: false,
|
|
396
|
-
// Disable logging for cleaner output
|
|
397
395
|
ignoreElements: (element) => {
|
|
398
396
|
return element.hasAttribute("data-feedback-widget") || element.closest("[data-feedback-widget]") !== null;
|
|
399
397
|
}
|
|
400
398
|
});
|
|
401
|
-
const
|
|
399
|
+
const targetWidth = 1920;
|
|
400
|
+
const targetHeight = 1080;
|
|
401
|
+
const normalizedCanvas = document.createElement("canvas");
|
|
402
|
+
normalizedCanvas.width = targetWidth;
|
|
403
|
+
normalizedCanvas.height = targetHeight;
|
|
404
|
+
const ctx = normalizedCanvas.getContext("2d");
|
|
405
|
+
if (!ctx) {
|
|
406
|
+
setIsTakenScreenShot(false);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
ctx.imageSmoothingEnabled = true;
|
|
410
|
+
ctx.imageSmoothingQuality = "high";
|
|
411
|
+
const sourceAspect = canvas.width / canvas.height;
|
|
412
|
+
const targetAspect = targetWidth / targetHeight;
|
|
413
|
+
let drawWidth = targetWidth;
|
|
414
|
+
let drawHeight = targetHeight;
|
|
415
|
+
let drawX = 0;
|
|
416
|
+
let drawY = 0;
|
|
417
|
+
if (sourceAspect > targetAspect) {
|
|
418
|
+
drawHeight = targetHeight;
|
|
419
|
+
drawWidth = drawHeight * sourceAspect;
|
|
420
|
+
drawX = (targetWidth - drawWidth) / 2;
|
|
421
|
+
} else {
|
|
422
|
+
drawWidth = targetWidth;
|
|
423
|
+
drawHeight = drawWidth / sourceAspect;
|
|
424
|
+
drawY = (targetHeight - drawHeight) / 2;
|
|
425
|
+
}
|
|
426
|
+
ctx.fillStyle = "#ffffff";
|
|
427
|
+
ctx.fillRect(0, 0, targetWidth, targetHeight);
|
|
428
|
+
ctx.drawImage(canvas, drawX, drawY, drawWidth, drawHeight);
|
|
429
|
+
const base64image = normalizedCanvas.toDataURL("image/png", 1);
|
|
402
430
|
onScreenshotTook(base64image);
|
|
403
431
|
setIsTakenScreenShot(false);
|
|
404
432
|
}
|
|
@@ -748,7 +776,7 @@ async function uploadFileToRepo(token, owner, repo, file, folderPath, defaultBra
|
|
|
748
776
|
return rawUrl;
|
|
749
777
|
}
|
|
750
778
|
async function uploadScreenshotToRepo(token, owner, repo, screenshot, screenshotPath) {
|
|
751
|
-
const compressedScreenshot = await compressScreenshot(screenshot,
|
|
779
|
+
const compressedScreenshot = await compressScreenshot(screenshot, 1920, 0.85);
|
|
752
780
|
const base64Content = compressedScreenshot.includes(",") ? compressedScreenshot.split(",")[1] : compressedScreenshot;
|
|
753
781
|
const repoResponse = await fetch(
|
|
754
782
|
`https://api.github.com/repos/${owner}/${repo}`,
|
|
@@ -850,7 +878,7 @@ async function uploadScreenshotToRepo(token, owner, repo, screenshot, screenshot
|
|
|
850
878
|
console.log(`Screenshot uploaded successfully to: ${rawUrl}`);
|
|
851
879
|
return rawUrl;
|
|
852
880
|
}
|
|
853
|
-
function compressScreenshot(dataUrl, maxWidth =
|
|
881
|
+
function compressScreenshot(dataUrl, maxWidth = 1920, quality = 0.85) {
|
|
854
882
|
return new Promise((resolve, reject) => {
|
|
855
883
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
856
884
|
reject(new Error("Screenshot compression only works in browser environments"));
|
|
@@ -865,9 +893,8 @@ function compressScreenshot(dataUrl, maxWidth = 2560, quality = 0.9) {
|
|
|
865
893
|
height = height * maxWidth / width;
|
|
866
894
|
width = maxWidth;
|
|
867
895
|
}
|
|
868
|
-
|
|
869
|
-
canvas.
|
|
870
|
-
canvas.height = height * dpr;
|
|
896
|
+
canvas.width = width;
|
|
897
|
+
canvas.height = height;
|
|
871
898
|
const ctx = canvas.getContext("2d");
|
|
872
899
|
if (!ctx) {
|
|
873
900
|
reject(new Error("Could not get canvas context"));
|
|
@@ -875,7 +902,6 @@ function compressScreenshot(dataUrl, maxWidth = 2560, quality = 0.9) {
|
|
|
875
902
|
}
|
|
876
903
|
ctx.imageSmoothingEnabled = true;
|
|
877
904
|
ctx.imageSmoothingQuality = "high";
|
|
878
|
-
ctx.scale(dpr, dpr);
|
|
879
905
|
ctx.drawImage(img, 0, 0, width, height);
|
|
880
906
|
const compressedDataUrl = canvas.toDataURL("image/jpeg", quality);
|
|
881
907
|
resolve(compressedDataUrl);
|