UNPKG

@remotion/studio

Version:

APIs for interacting with the Remotion Studio

61 lines (60 loc) 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setRenderJobs = exports.setCurrentCanvasContentId = void 0; const no_react_1 = require("remotion/no-react"); const context_1 = require("../components/RenderQueue/context"); let currentItemName = null; let renderJobs = []; const setCurrentCanvasContentId = (id) => { if (!id) { currentItemName = id; updateTitle(); return; } const idWithoutFolder = id.split('/').pop(); currentItemName = idWithoutFolder; updateTitle(); }; exports.setCurrentCanvasContentId = setCurrentCanvasContentId; const setRenderJobs = (jobs) => { renderJobs = jobs; updateTitle(); }; exports.setRenderJobs = setRenderJobs; const productName = 'Remotion Studio'; const suffix = `- ${productName}`; const updateTitle = () => { if (!currentItemName) { document.title = productName; return; } const currentCompTitle = `${currentItemName} / ${window.remotion_projectName}`; document.title = [ getProgressInBrackets(currentItemName, renderJobs), `${currentCompTitle} ${suffix}`, ] .filter(no_react_1.NoReactInternals.truthy) .join(' '); }; const getProgressInBrackets = (selectedCompositionId, jobs) => { const currentRender = jobs.find((job) => job.status === 'running'); if (!currentRender) { return null; } if (currentRender.status !== 'running') { throw new Error('expected running job'); } let progInPercent; if ((0, context_1.isClientRenderJob)(currentRender)) { const { encodedFrames, totalFrames } = currentRender.progress; progInPercent = totalFrames > 0 ? Math.ceil((encodedFrames / totalFrames) * 100) : 0; } else { progInPercent = Math.ceil(currentRender.progress.value * 100); } const progressInBrackets = currentRender.compositionId === selectedCompositionId ? `[${progInPercent}%]` : `[${progInPercent}% ${currentRender.compositionId}]`; return progressInBrackets; };