feedback-vos 1.0.45 → 1.0.46

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