import { useState, useEffect, useCallback, useLayoutEffect, useMemo, } from "react"; import useFileDrop from "components/system/Files/FileManager/useFileDrop"; import { PREVENT_SCROLL } from "utils/constants"; import { useProcesses } from "contexts/process"; import { useSession } from "contexts/session"; type ContentWindow = Window & typeof globalThis; const alwaysPreserveDrawingBuffer = (contentWindow: ContentWindow): void => { // eslint-disable-next-line @typescript-eslint/unbound-method const canvasGetContext = contentWindow.HTMLCanvasElement.prototype.getContext; // eslint-disable-next-line no-param-reassign contentWindow.HTMLCanvasElement.prototype.getContext = function getContext( this: typeof canvasGetContext, contextId: "webgl" | "webgl2", options?: WebGLContextAttributes ) { if (contextId === "webgl" || contextId === "webgl2") { // eslint-disable-next-line no-param-reassign options = Object.assign(options || {}, { preserveDrawingBuffer: true }); } return canvasGetContext.call(this, contextId, options); } as typeof canvasGetContext; }; const createCanvas = (contentDocument: Document): HTMLCanvasElement => { const canvas = contentDocument.createElement("canvas"); canvas.id = "canvas"; canvas.style.width = "100%"; canvas.style.height = "100%"; canvas.tabIndex = -1; contentDocument.body.append(canvas); return canvas; }; const createIframe = ( id: string, container: HTMLDivElement, styles?: string ): HTMLIFrameElement => { const iframe = document.createElement("iframe"); iframe.title = id; iframe.style.backgroundColor = "transparent"; iframe.style.border = "0"; iframe.style.width = "100%"; iframe.style.height = "100%"; container.append(iframe); const contentDocument = iframe.contentDocument as Document; contentDocument.open(); // eslint-disable-next-line deprecation/deprecation contentDocument.write(` ${styles ? `
` : "