feedback-vos 1.0.45 → 1.0.47
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 +67 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -393,62 +393,76 @@ function ScreenshotButton({
|
|
|
393
393
|
const [tempScreenshot, setTempScreenshot] = useState(null);
|
|
394
394
|
const themeClasses = getThemeClasses(theme);
|
|
395
395
|
async function handleTakeScreenshot() {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
396
|
+
try {
|
|
397
|
+
setIsTakenScreenShot(true);
|
|
398
|
+
const canvas = await html2canvas(document.body, {
|
|
399
|
+
width: window.innerWidth,
|
|
400
|
+
height: window.innerHeight,
|
|
401
|
+
windowWidth: window.innerWidth,
|
|
402
|
+
windowHeight: window.innerHeight,
|
|
403
|
+
scrollX: -window.scrollX,
|
|
404
|
+
scrollY: -window.scrollY,
|
|
405
|
+
scale: 1,
|
|
406
|
+
// Use scale 1 for consistent sizing
|
|
407
|
+
useCORS: true,
|
|
408
|
+
allowTaint: true,
|
|
409
|
+
// Allow external images for better rendering
|
|
410
|
+
backgroundColor: null,
|
|
411
|
+
// Preserve page background
|
|
412
|
+
removeContainer: false,
|
|
413
|
+
// Maintain proper container rendering
|
|
414
|
+
logging: false,
|
|
415
|
+
ignoreElements: (element) => {
|
|
416
|
+
const isWidget = element.hasAttribute("data-feedback-widget") || element.closest("[data-feedback-widget]") !== null;
|
|
417
|
+
if (isWidget) return true;
|
|
418
|
+
if (element.tagName === "IMG" || element.tagName === "CANVAS" || element.tagName === "VIDEO") {
|
|
419
|
+
const rect = element.getBoundingClientRect();
|
|
420
|
+
if (rect.width === 0 || rect.height === 0) return true;
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
if (canvas.width === 0 || canvas.height === 0) {
|
|
426
|
+
console.warn("Screenshot failed: Captured canvas has 0 width or height");
|
|
427
|
+
return;
|
|
416
428
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
429
|
+
const isMobile = window.innerWidth < 768;
|
|
430
|
+
const targetWidth = isMobile ? 1080 : 1920;
|
|
431
|
+
const targetHeight = isMobile ? 1920 : 1080;
|
|
432
|
+
const normalizedCanvas = document.createElement("canvas");
|
|
433
|
+
normalizedCanvas.width = targetWidth;
|
|
434
|
+
normalizedCanvas.height = targetHeight;
|
|
435
|
+
const ctx = normalizedCanvas.getContext("2d");
|
|
436
|
+
if (!ctx) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
ctx.imageSmoothingEnabled = true;
|
|
440
|
+
ctx.imageSmoothingQuality = "high";
|
|
441
|
+
const sourceAspect = canvas.width / canvas.height;
|
|
442
|
+
const targetAspect = targetWidth / targetHeight;
|
|
443
|
+
let drawWidth = targetWidth;
|
|
444
|
+
let drawHeight = targetHeight;
|
|
445
|
+
let drawX = 0;
|
|
446
|
+
let drawY = 0;
|
|
447
|
+
if (sourceAspect > targetAspect) {
|
|
448
|
+
drawHeight = targetHeight;
|
|
449
|
+
drawWidth = drawHeight * sourceAspect;
|
|
450
|
+
drawX = (targetWidth - drawWidth) / 2;
|
|
451
|
+
} else {
|
|
452
|
+
drawWidth = targetWidth;
|
|
453
|
+
drawHeight = drawWidth / sourceAspect;
|
|
454
|
+
drawY = (targetHeight - drawHeight) / 2;
|
|
455
|
+
}
|
|
456
|
+
ctx.fillStyle = "#ffffff";
|
|
457
|
+
ctx.fillRect(0, 0, targetWidth, targetHeight);
|
|
458
|
+
ctx.drawImage(canvas, drawX, drawY, drawWidth, drawHeight);
|
|
459
|
+
const base64image = normalizedCanvas.toDataURL("image/png", 1);
|
|
460
|
+
onScreenshotTook(base64image);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
console.error("Failed to take screenshot:", error);
|
|
463
|
+
} finally {
|
|
426
464
|
setIsTakenScreenShot(false);
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
ctx.imageSmoothingEnabled = true;
|
|
430
|
-
ctx.imageSmoothingQuality = "high";
|
|
431
|
-
const sourceAspect = canvas.width / canvas.height;
|
|
432
|
-
const targetAspect = targetWidth / targetHeight;
|
|
433
|
-
let drawWidth = targetWidth;
|
|
434
|
-
let drawHeight = targetHeight;
|
|
435
|
-
let drawX = 0;
|
|
436
|
-
let drawY = 0;
|
|
437
|
-
if (sourceAspect > targetAspect) {
|
|
438
|
-
drawHeight = targetHeight;
|
|
439
|
-
drawWidth = drawHeight * sourceAspect;
|
|
440
|
-
drawX = (targetWidth - drawWidth) / 2;
|
|
441
|
-
} else {
|
|
442
|
-
drawWidth = targetWidth;
|
|
443
|
-
drawHeight = drawWidth / sourceAspect;
|
|
444
|
-
drawY = (targetHeight - drawHeight) / 2;
|
|
445
465
|
}
|
|
446
|
-
ctx.fillStyle = "#ffffff";
|
|
447
|
-
ctx.fillRect(0, 0, targetWidth, targetHeight);
|
|
448
|
-
ctx.drawImage(canvas, drawX, drawY, drawWidth, drawHeight);
|
|
449
|
-
const base64image = normalizedCanvas.toDataURL("image/png", 1);
|
|
450
|
-
onScreenshotTook(base64image);
|
|
451
|
-
setIsTakenScreenShot(false);
|
|
452
466
|
}
|
|
453
467
|
function handleEditorSave(editedScreenshot) {
|
|
454
468
|
onScreenshotTook(editedScreenshot);
|