{
  "version": 3,
  "sources": ["../src/video-conversion-worker.ts"],
  "sourcesContent": ["import { wrap, terminate, type Remote } from '@wordpress/worker-threads';\nimport type { ItemId } from './types.ts';\nimport type { WorkerAPI } from './worker.ts';\nimport { workerCode } from './worker-code.ts';\n\n/**\n * The worker instance, lazily created on first use.\n */\nlet worker: Worker | undefined;\n\n/**\n * The wrapped worker API for RPC calls.\n */\nlet workerAPI: Remote< WorkerAPI > | undefined;\n\n/**\n * The Blob URL for the worker, kept for cleanup.\n */\nlet workerBlobUrl: string | undefined;\n\n/**\n * Gets or creates the video conversion worker instance.\n * Uses lazy initialization to only create the worker when needed.\n *\n * The worker code is bundled inline and loaded via a Blob URL.\n * This avoids issues with import.meta.url not being available\n * when the code is bundled via webpack.\n *\n * @return The wrapped worker API.\n */\nfunction getWorkerAPI(): Remote< WorkerAPI > {\n\tif ( workerAPI === undefined ) {\n\t\t// Create worker from inline code via Blob URL.\n\t\t// This approach works regardless of how the code is bundled.\n\t\tconst blob = new Blob( [ workerCode ], {\n\t\t\ttype: 'application/javascript',\n\t\t} );\n\t\tworkerBlobUrl = URL.createObjectURL( blob );\n\t\tworker = new Worker( workerBlobUrl, { type: 'module' } );\n\t\tworkerAPI = wrap< WorkerAPI >( worker );\n\t}\n\treturn workerAPI;\n}\n\n/**\n * Converts an animated GIF to a video file using the worker pipeline.\n *\n * @param id             Item ID.\n * @param gifSource      GIF file as a Blob/File or ArrayBuffer.\n * @param outputMimeType Output MIME type ('video/mp4' or 'video/webm').\n * @param maxDimensions  Optional maximum dimension for downscaling.\n * @param maxTotalPixels Optional budget for total decoded pixels\n *                       (width × height × frame count); `0` disables.\n * @return Video file buffer.\n */\nexport async function convertGifToVideo(\n\tid: ItemId,\n\tgifSource: ArrayBuffer | Blob,\n\toutputMimeType: string,\n\tmaxDimensions?: number,\n\tmaxTotalPixels?: number\n): Promise< ArrayBuffer > {\n\tconst api = getWorkerAPI();\n\treturn api.convertGifToVideo(\n\t\tid,\n\t\tgifSource,\n\t\toutputMimeType,\n\t\tmaxDimensions,\n\t\tmaxTotalPixels\n\t);\n}\n\n/**\n * Cancels all ongoing GIF-to-video conversions for a given item ID.\n *\n * @param id Item ID.\n * @return Whether any operation was cancelled.\n */\nexport async function cancelGifToVideoOperations(\n\tid: ItemId\n): Promise< boolean > {\n\tconst api = getWorkerAPI();\n\treturn api.cancelOperations( id );\n}\n\n/**\n * Terminates the video conversion worker if it exists.\n * Call this to free up resources when video conversion is no longer needed.\n */\nexport function terminateVideoConversionWorker(): void {\n\tif ( workerAPI ) {\n\t\tterminate( workerAPI );\n\t\tworkerAPI = undefined;\n\t\tworker = undefined;\n\t}\n\tif ( workerBlobUrl ) {\n\t\tURL.revokeObjectURL( workerBlobUrl );\n\t\tworkerBlobUrl = undefined;\n\t}\n}\n"],
  "mappings": ";AAAA,SAAS,MAAM,iBAA8B;AAG7C,SAAS,kBAAkB;AAK3B,IAAI;AAKJ,IAAI;AAKJ,IAAI;AAYJ,SAAS,eAAoC;AAC5C,MAAK,cAAc,QAAY;AAG9B,UAAM,OAAO,IAAI,KAAM,CAAE,UAAW,GAAG;AAAA,MACtC,MAAM;AAAA,IACP,CAAE;AACF,oBAAgB,IAAI,gBAAiB,IAAK;AAC1C,aAAS,IAAI,OAAQ,eAAe,EAAE,MAAM,SAAS,CAAE;AACvD,gBAAY,KAAmB,MAAO;AAAA,EACvC;AACA,SAAO;AACR;AAaA,eAAsB,kBACrB,IACA,WACA,gBACA,eACA,gBACyB;AACzB,QAAM,MAAM,aAAa;AACzB,SAAO,IAAI;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAQA,eAAsB,2BACrB,IACqB;AACrB,QAAM,MAAM,aAAa;AACzB,SAAO,IAAI,iBAAkB,EAAG;AACjC;AAMO,SAAS,iCAAuC;AACtD,MAAK,WAAY;AAChB,cAAW,SAAU;AACrB,gBAAY;AACZ,aAAS;AAAA,EACV;AACA,MAAK,eAAgB;AACpB,QAAI,gBAAiB,aAAc;AACnC,oBAAgB;AAAA,EACjB;AACD;",
  "names": []
}
