'use client';
import { d as decodeRawImage } from './decodeImage-DseBx4N0.js';
import './i18next-17tp0Ngf.js';
import './isArrayLikeObject-n9ytTioB.js';

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

self.onmessage = async event => {
  const {
    id,
    image,
    options
  } = event.data;
  try {
    const buffer = new Uint8ClampedArray(image.width * image.height * 4);

    // Decode image into the provided buffer
    await decodeRawImage(image, options, buffer);

    // Clear image data for earlier Garbage Collection
    image.data.fill(0);

    // Transfer the buffer back with the message ID
    self.postMessage({
      id,
      result: buffer
    }, [buffer.buffer]);
  } catch (error) {
    self.postMessage({
      id,
      error: error instanceof Error ? error.message : "Unknown error occurred"
    });
  }
};
