The viewer JS/HTML/bundles are now committed in javascript/ (declared via pyproject [tool.comfy] web = "javascript") instead of being copied from the shared comfy-3d-viewers pip package at prestartup. Consequences: - requirements.txt is now just comfy-env (host env installs nothing else, per the never-touch-the-host-env principle) - prestartup_script.py no longer copies viewers or web_src; it keeps only setup_env() and the input-asset copies - WEB_DIRECTORY attribute removed; the pyproject declaration is the single source (served at /extensions/comfyui-geometrypack/, keyed by project name) - web_src/ deleted; its 6 widgets now live in javascript/js/ as the tracked source, edited directly - viewer_pbr.html hardcoded-fallback URL updated to the new mount name Iframe URLs auto-detect the mount from import.meta.url, so the folder rename and mount-name change are transparent at runtime.
98 lines
2.9 KiB
JavaScript
98 lines
2.9 KiB
JavaScript
/**
|
|
* ScreenshotCapture - Screenshot functionality for VTK viewers
|
|
*
|
|
* Handles capturing screenshots from VTK render windows and
|
|
* sending them via postMessage or triggering downloads.
|
|
*/
|
|
|
|
import { sendScreenshot } from '../utils/MessageHandler.js';
|
|
|
|
export class ScreenshotCapture {
|
|
/**
|
|
* Create a ScreenshotCapture instance
|
|
* @param {Object} renderWindow - VTK render window
|
|
*/
|
|
constructor(renderWindow) {
|
|
this.renderWindow = renderWindow;
|
|
}
|
|
|
|
/**
|
|
* Capture a screenshot as a base64 PNG data URL
|
|
* @returns {Promise<string>} Base64 PNG data URL
|
|
*/
|
|
async capture() {
|
|
const images = await this.renderWindow.captureImages();
|
|
return images[0]; // Returns base64 PNG data URL
|
|
}
|
|
|
|
/**
|
|
* Capture and send screenshot to parent window via postMessage
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async captureAndSend() {
|
|
try {
|
|
const image = await this.capture();
|
|
sendScreenshot(image);
|
|
console.log('[ScreenshotCapture] Screenshot captured and sent to parent');
|
|
} catch (error) {
|
|
console.error('[ScreenshotCapture] Error capturing screenshot:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Capture and download screenshot as a file
|
|
* @param {string} filename - Download filename (default: "screenshot.png")
|
|
* @returns {Promise<void>}
|
|
*/
|
|
async captureAndDownload(filename = 'screenshot.png') {
|
|
try {
|
|
const image = await this.capture();
|
|
|
|
// Create download link
|
|
const link = document.createElement('a');
|
|
link.href = image;
|
|
link.download = filename;
|
|
link.style.display = 'none';
|
|
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
|
|
console.log('[ScreenshotCapture] Screenshot downloaded:', filename);
|
|
} catch (error) {
|
|
console.error('[ScreenshotCapture] Error downloading screenshot:', error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Capture screenshot and return as Blob
|
|
* @returns {Promise<Blob>} PNG Blob
|
|
*/
|
|
async captureAsBlob() {
|
|
const image = await this.capture();
|
|
|
|
// Convert base64 to blob
|
|
const response = await fetch(image);
|
|
return response.blob();
|
|
}
|
|
|
|
/**
|
|
* Generate a timestamp-based filename
|
|
* @param {string} prefix - Filename prefix (default: "screenshot")
|
|
* @param {string} extension - File extension (default: "png")
|
|
* @returns {string} Filename with timestamp
|
|
*/
|
|
static generateFilename(prefix = 'screenshot', extension = 'png') {
|
|
const now = new Date();
|
|
const timestamp = now.toISOString()
|
|
.replace(/[:.]/g, '-')
|
|
.replace('T', '_')
|
|
.slice(0, 19);
|
|
return `${prefix}_${timestamp}.${extension}`;
|
|
}
|
|
}
|
|
|
|
export default ScreenshotCapture;
|