import { u as uuid } from "./watermark.js";
function sendMessage(type, data, worker) {
  const promiseMap = {};
  const payloadMap = {};
  const asyncId = uuid();
  const message = {
    type,
    data,
    asyncId
  };
  worker.onmessage = function(event) {
    let { asyncId: asyncId2, payload } = event.data;
    if (payload.framesLength && asyncId2) {
      if (!payloadMap[asyncId2]) {
        payloadMap[asyncId2] = payload;
      } else {
        payloadMap[asyncId2].frames = payloadMap[asyncId2].frames.concat(payload.frames);
      }
      payload = payloadMap[asyncId2];
      payload.frames.sort((a, b) => a.index - b.index);
    }
    if (asyncId2 && promiseMap[asyncId2] && (payload.frames.length === payload.framesLength || !payload.framesLength)) {
      promiseMap[asyncId2][0](payload);
      delete promiseMap[asyncId2];
    }
  };
  worker.onerror = function(event) {
    const { message: message2 } = event;
    if (asyncId && promiseMap[asyncId]) {
      promiseMap[asyncId][1](message2);
      delete promiseMap[asyncId];
    }
    console.error(message2);
  };
  return new Promise((resolve, reject) => {
    promiseMap[message.asyncId] = [resolve, reject];
    worker.postMessage(message);
  });
}
function WorkerWrapper() {
  return new Worker("/assets/gif-apng.worker.9618315e.js", {
    "type": "module"
  });
}
export { WorkerWrapper as W, sendMessage as s };
