import {
  AbortException,
  FeatureTest,
  ImageKind,
  InvalidPDFException,
  PasswordException,
  ResponseException,
  UnknownErrorException,
  assert,
  unreachable,
  warn
} from "./chunk-T2JWSGAF.js";
import {
  __privateAdd,
  __privateGet,
  __privateMethod,
  __privateSet,
  __publicField
} from "./chunk-ZFIGV5OT.js";

// src/lib/polyfills.ts
if (!Array.prototype.at) {
  Object.defineProperty(Array.prototype, "at", {
    value: function at(index) {
      return this[index >= 0 ? index : this.length + index];
    },
    enumerable: false
  });
}
if (!Promise.withResolvers) {
  Promise.withResolvers = function withResolvers() {
    let resolve;
    let reject;
    const promise = new this((res, rej) => {
      resolve = res;
      reject = rej;
    });
    return {
      resolve,
      reject,
      promise
    };
  };
}
if (!("try" in Promise)) {
  Object.defineProperty(Promise, "try", {
    value: function tryFn(fn, ...args) {
      return new this(
        (resolve, reject) => {
          try {
            resolve(fn(...args));
          } catch (error) {
            reject(error);
          }
        }
      );
    },
    enumerable: false
  });
}

// src/pdf.js/src/shared/message_handler.js
var CallbackKind = {
  DATA: 1,
  ERROR: 2
};
var StreamKind = {
  CANCEL: 1,
  CANCEL_COMPLETE: 2,
  CLOSE: 3,
  ENQUEUE: 4,
  ERROR: 5,
  PULL: 6,
  PULL_COMPLETE: 7,
  START_COMPLETE: 8
};
function onFn() {
}
function wrapReason(ex) {
  if (ex instanceof AbortException || ex instanceof InvalidPDFException || ex instanceof PasswordException || ex instanceof ResponseException || ex instanceof UnknownErrorException) {
    return ex;
  }
  if (!(ex instanceof Error || typeof ex === "object" && ex !== null)) {
    unreachable(
      'wrapReason: Expected "reason" to be a (possibly cloned) Error.'
    );
  }
  switch (ex.name) {
    case "AbortException":
      return new AbortException(ex.message);
    case "InvalidPDFException":
      return new InvalidPDFException(ex.message);
    case "PasswordException":
      return new PasswordException(ex.message, ex.code);
    case "ResponseException":
      return new ResponseException(ex.message, ex.status, ex.missing);
    case "UnknownErrorException":
      return new UnknownErrorException(ex.message, ex.details);
  }
  return new UnknownErrorException(ex.message, ex.toString());
}
var _messageAC, _MessageHandler_instances, onMessage_fn, createStreamSink_fn, processStreamMessage_fn, deleteStreamController_fn;
var MessageHandler = class {
  constructor(sourceName, targetName, comObj) {
    __privateAdd(this, _MessageHandler_instances);
    __privateAdd(this, _messageAC, new AbortController());
    this.sourceName = sourceName;
    this.targetName = targetName;
    this.comObj = comObj;
    this.callbackId = 1;
    this.streamId = 1;
    this.streamSinks = /* @__PURE__ */ Object.create(null);
    this.streamControllers = /* @__PURE__ */ Object.create(null);
    this.callbackCapabilities = /* @__PURE__ */ Object.create(null);
    this.actionHandler = /* @__PURE__ */ Object.create(null);
    comObj.addEventListener("message", __privateMethod(this, _MessageHandler_instances, onMessage_fn).bind(this), {
      signal: __privateGet(this, _messageAC).signal
    });
  }
  on(actionName, handler) {
    if (false) {
      assert(
        typeof handler === "function",
        'MessageHandler.on: Expected "handler" to be a function.'
      );
    }
    const ah = this.actionHandler;
    if (ah[actionName]) {
      throw new Error(`There is already an actionName called "${actionName}"`);
    }
    ah[actionName] = handler;
  }
  /**
   * Sends a message to the comObj to invoke the action with the supplied data.
   * @param {string} actionName - Action to call.
   * @param {JSON} data - JSON data to send.
   * @param {Array} [transfers] - List of transfers/ArrayBuffers.
   */
  send(actionName, data, transfers) {
    this.comObj.postMessage(
      {
        sourceName: this.sourceName,
        targetName: this.targetName,
        action: actionName,
        data
      },
      transfers
    );
  }
  /**
   * Sends a message to the comObj to invoke the action with the supplied data.
   * Expects that the other side will callback with the response.
   * @param {string} actionName - Action to call.
   * @param {JSON} data - JSON data to send.
   * @param {Array} [transfers] - List of transfers/ArrayBuffers.
   * @returns {Promise} Promise to be resolved with response data.
   */
  sendWithPromise(actionName, data, transfers) {
    const callbackId = this.callbackId++;
    const capability = Promise.withResolvers();
    this.callbackCapabilities[callbackId] = capability;
    try {
      this.comObj.postMessage(
        {
          sourceName: this.sourceName,
          targetName: this.targetName,
          action: actionName,
          callbackId,
          data
        },
        transfers
      );
    } catch (ex) {
      capability.reject(ex);
    }
    return capability.promise;
  }
  /**
   * Sends a message to the comObj to invoke the action with the supplied data.
   * Expect that the other side will callback to signal 'start_complete'.
   * @param {string} actionName - Action to call.
   * @param {JSON} data - JSON data to send.
   * @param {Object} queueingStrategy - Strategy to signal backpressure based on
   *                 internal queue.
   * @param {Array} [transfers] - List of transfers/ArrayBuffers.
   * @returns {ReadableStream} ReadableStream to read data in chunks.
   */
  sendWithStream(actionName, data, queueingStrategy, transfers) {
    const streamId = this.streamId++, sourceName = this.sourceName, targetName = this.targetName, comObj = this.comObj;
    return new ReadableStream(
      {
        start: (controller) => {
          const startCapability = Promise.withResolvers();
          this.streamControllers[streamId] = {
            controller,
            startCall: startCapability,
            pullCall: null,
            cancelCall: null,
            isClosed: false
          };
          comObj.postMessage(
            {
              sourceName,
              targetName,
              action: actionName,
              streamId,
              data,
              desiredSize: controller.desiredSize
            },
            transfers
          );
          return startCapability.promise;
        },
        pull: (controller) => {
          const pullCapability = Promise.withResolvers();
          this.streamControllers[streamId].pullCall = pullCapability;
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.PULL,
            streamId,
            desiredSize: controller.desiredSize
          });
          return pullCapability.promise;
        },
        cancel: (reason) => {
          assert(reason instanceof Error, "cancel must have a valid reason");
          const cancelCapability = Promise.withResolvers();
          this.streamControllers[streamId].cancelCall = cancelCapability;
          this.streamControllers[streamId].isClosed = true;
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.CANCEL,
            streamId,
            reason: wrapReason(reason)
          });
          return cancelCapability.promise;
        }
      },
      queueingStrategy
    );
  }
  destroy() {
    __privateGet(this, _messageAC)?.abort();
    __privateSet(this, _messageAC, null);
  }
};
_messageAC = new WeakMap();
_MessageHandler_instances = new WeakSet();
onMessage_fn = function({ data }) {
  if (data.targetName !== this.sourceName) {
    return;
  }
  if (data.stream) {
    __privateMethod(this, _MessageHandler_instances, processStreamMessage_fn).call(this, data);
    return;
  }
  if (data.callback) {
    const callbackId = data.callbackId;
    const capability = this.callbackCapabilities[callbackId];
    if (!capability) {
      throw new Error(`Cannot resolve callback ${callbackId}`);
    }
    delete this.callbackCapabilities[callbackId];
    if (data.callback === CallbackKind.DATA) {
      capability.resolve(data.data);
    } else if (data.callback === CallbackKind.ERROR) {
      capability.reject(wrapReason(data.reason));
    } else {
      throw new Error("Unexpected callback case");
    }
    return;
  }
  const action = this.actionHandler[data.action];
  if (!action) {
    throw new Error(`Unknown action from worker: ${data.action}`);
  }
  if (data.callbackId) {
    const sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
    Promise.try(action, data.data).then(
      function(result) {
        comObj.postMessage({
          sourceName,
          targetName,
          callback: CallbackKind.DATA,
          callbackId: data.callbackId,
          data: result
        });
      },
      function(reason) {
        comObj.postMessage({
          sourceName,
          targetName,
          callback: CallbackKind.ERROR,
          callbackId: data.callbackId,
          reason: wrapReason(reason)
        });
      }
    );
    return;
  }
  if (data.streamId) {
    __privateMethod(this, _MessageHandler_instances, createStreamSink_fn).call(this, data);
    return;
  }
  action(data.data);
};
createStreamSink_fn = function(data) {
  const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
  const self = this, action = this.actionHandler[data.action];
  const streamSink = {
    enqueue(chunk, size = 1, transfers) {
      if (this.isCancelled) {
        return;
      }
      const lastDesiredSize = this.desiredSize;
      this.desiredSize -= size;
      if (lastDesiredSize > 0 && this.desiredSize <= 0) {
        this.sinkCapability = Promise.withResolvers();
        this.ready = this.sinkCapability.promise;
      }
      comObj.postMessage(
        {
          sourceName,
          targetName,
          stream: StreamKind.ENQUEUE,
          streamId,
          chunk
        },
        transfers
      );
    },
    close() {
      if (this.isCancelled) {
        return;
      }
      this.isCancelled = true;
      comObj.postMessage({
        sourceName,
        targetName,
        stream: StreamKind.CLOSE,
        streamId
      });
      delete self.streamSinks[streamId];
    },
    error(reason) {
      assert(reason instanceof Error, "error must have a valid reason");
      if (this.isCancelled) {
        return;
      }
      this.isCancelled = true;
      comObj.postMessage({
        sourceName,
        targetName,
        stream: StreamKind.ERROR,
        streamId,
        reason: wrapReason(reason)
      });
    },
    sinkCapability: Promise.withResolvers(),
    onPull: null,
    onCancel: null,
    isCancelled: false,
    desiredSize: data.desiredSize,
    ready: null
  };
  streamSink.sinkCapability.resolve();
  streamSink.ready = streamSink.sinkCapability.promise;
  this.streamSinks[streamId] = streamSink;
  Promise.try(action, data.data, streamSink).then(
    function() {
      comObj.postMessage({
        sourceName,
        targetName,
        stream: StreamKind.START_COMPLETE,
        streamId,
        success: true
      });
    },
    function(reason) {
      comObj.postMessage({
        sourceName,
        targetName,
        stream: StreamKind.START_COMPLETE,
        streamId,
        reason: wrapReason(reason)
      });
    }
  );
};
processStreamMessage_fn = function(data) {
  const streamId = data.streamId, sourceName = this.sourceName, targetName = data.sourceName, comObj = this.comObj;
  const streamController = this.streamControllers[streamId], streamSink = this.streamSinks[streamId];
  switch (data.stream) {
    case StreamKind.START_COMPLETE:
      if (data.success) {
        streamController.startCall.resolve();
      } else {
        streamController.startCall.reject(wrapReason(data.reason));
      }
      break;
    case StreamKind.PULL_COMPLETE:
      if (data.success) {
        streamController.pullCall.resolve();
      } else {
        streamController.pullCall.reject(wrapReason(data.reason));
      }
      break;
    case StreamKind.PULL:
      if (!streamSink) {
        comObj.postMessage({
          sourceName,
          targetName,
          stream: StreamKind.PULL_COMPLETE,
          streamId,
          success: true
        });
        break;
      }
      if (streamSink.desiredSize <= 0 && data.desiredSize > 0) {
        streamSink.sinkCapability.resolve();
      }
      streamSink.desiredSize = data.desiredSize;
      Promise.try(streamSink.onPull || onFn).then(
        function() {
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.PULL_COMPLETE,
            streamId,
            success: true
          });
        },
        function(reason) {
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.PULL_COMPLETE,
            streamId,
            reason: wrapReason(reason)
          });
        }
      );
      break;
    case StreamKind.ENQUEUE:
      assert(streamController, "enqueue should have stream controller");
      if (streamController.isClosed) {
        break;
      }
      streamController.controller.enqueue(data.chunk);
      break;
    case StreamKind.CLOSE:
      assert(streamController, "close should have stream controller");
      if (streamController.isClosed) {
        break;
      }
      streamController.isClosed = true;
      streamController.controller.close();
      __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
      break;
    case StreamKind.ERROR:
      assert(streamController, "error should have stream controller");
      streamController.controller.error(wrapReason(data.reason));
      __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
      break;
    case StreamKind.CANCEL_COMPLETE:
      if (data.success) {
        streamController.cancelCall.resolve();
      } else {
        streamController.cancelCall.reject(wrapReason(data.reason));
      }
      __privateMethod(this, _MessageHandler_instances, deleteStreamController_fn).call(this, streamController, streamId);
      break;
    case StreamKind.CANCEL:
      if (!streamSink) {
        break;
      }
      const dataReason = wrapReason(data.reason);
      Promise.try(streamSink.onCancel || onFn, dataReason).then(
        function() {
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.CANCEL_COMPLETE,
            streamId,
            success: true
          });
        },
        function(reason) {
          comObj.postMessage({
            sourceName,
            targetName,
            stream: StreamKind.CANCEL_COMPLETE,
            streamId,
            reason: wrapReason(reason)
          });
        }
      );
      streamSink.sinkCapability.reject(dataReason);
      streamSink.isCancelled = true;
      delete this.streamSinks[streamId];
      break;
    default:
      throw new Error("Unexpected stream case");
  }
};
deleteStreamController_fn = async function(streamController, streamId) {
  await Promise.allSettled([
    streamController.startCall?.promise,
    streamController.pullCall?.promise,
    streamController.cancelCall?.promise
  ]);
  delete this.streamControllers[streamId];
};

// src/pdf.js/src/shared/obj-bin-transform.js
var _buffer, _view, _decoder, _CssFontInfo_instances, readString_fn;
var _CssFontInfo = class _CssFontInfo {
  constructor(buffer) {
    __privateAdd(this, _CssFontInfo_instances);
    __privateAdd(this, _buffer);
    __privateAdd(this, _view);
    __privateAdd(this, _decoder);
    __privateSet(this, _buffer, buffer);
    __privateSet(this, _view, new DataView(__privateGet(this, _buffer)));
    __privateSet(this, _decoder, new TextDecoder());
  }
  static write(info) {
    const encoder = new TextEncoder();
    const encodedStrings = {};
    let stringsLength = 0;
    for (const prop of _CssFontInfo.strings) {
      const encoded = encoder.encode(info[prop]);
      encodedStrings[prop] = encoded;
      stringsLength += 4 + encoded.length;
    }
    const buffer = new ArrayBuffer(stringsLength);
    const data = new Uint8Array(buffer);
    const view = new DataView(buffer);
    let offset = 0;
    for (const prop of _CssFontInfo.strings) {
      const encoded = encodedStrings[prop];
      const length = encoded.length;
      view.setUint32(offset, length);
      data.set(encoded, offset + 4);
      offset += 4 + length;
    }
    assert(offset === buffer.byteLength, "CssFontInfo.write: Buffer overflow");
    return buffer;
  }
  get fontFamily() {
    return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 0);
  }
  get fontWeight() {
    return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 1);
  }
  get italicAngle() {
    return __privateMethod(this, _CssFontInfo_instances, readString_fn).call(this, 2);
  }
};
_buffer = new WeakMap();
_view = new WeakMap();
_decoder = new WeakMap();
_CssFontInfo_instances = new WeakSet();
readString_fn = function(index) {
  assert(index < _CssFontInfo.strings.length, "Invalid string index");
  let offset = 0;
  for (let i = 0; i < index; i++) {
    offset += __privateGet(this, _view).getUint32(offset) + 4;
  }
  const length = __privateGet(this, _view).getUint32(offset);
  return __privateGet(this, _decoder).decode(
    new Uint8Array(__privateGet(this, _buffer), offset + 4, length)
  );
};
__publicField(_CssFontInfo, "strings", ["fontFamily", "fontWeight", "italicAngle"]);
var CssFontInfo = _CssFontInfo;
var _buffer2, _view2, _decoder2, _SystemFontInfo_instances, readString_fn2;
var _SystemFontInfo = class _SystemFontInfo {
  constructor(buffer) {
    __privateAdd(this, _SystemFontInfo_instances);
    __privateAdd(this, _buffer2);
    __privateAdd(this, _view2);
    __privateAdd(this, _decoder2);
    __privateSet(this, _buffer2, buffer);
    __privateSet(this, _view2, new DataView(__privateGet(this, _buffer2)));
    __privateSet(this, _decoder2, new TextDecoder());
  }
  static write(info) {
    const encoder = new TextEncoder();
    const encodedStrings = {};
    let stringsLength = 0;
    for (const prop of _SystemFontInfo.strings) {
      const encoded = encoder.encode(info[prop]);
      encodedStrings[prop] = encoded;
      stringsLength += 4 + encoded.length;
    }
    stringsLength += 4;
    let encodedStyleStyle, encodedStyleWeight, lengthEstimate = 1 + stringsLength;
    if (info.style) {
      encodedStyleStyle = encoder.encode(info.style.style);
      encodedStyleWeight = encoder.encode(info.style.weight);
      lengthEstimate += 4 + encodedStyleStyle.length + 4 + encodedStyleWeight.length;
    }
    const buffer = new ArrayBuffer(lengthEstimate);
    const data = new Uint8Array(buffer);
    const view = new DataView(buffer);
    let offset = 0;
    view.setUint8(offset++, info.guessFallback ? 1 : 0);
    view.setUint32(offset, 0);
    offset += 4;
    stringsLength = 0;
    for (const prop of _SystemFontInfo.strings) {
      const encoded = encodedStrings[prop];
      const length = encoded.length;
      stringsLength += 4 + length;
      view.setUint32(offset, length);
      data.set(encoded, offset + 4);
      offset += 4 + length;
    }
    view.setUint32(offset - stringsLength - 4, stringsLength);
    if (info.style) {
      view.setUint32(offset, encodedStyleStyle.length);
      data.set(encodedStyleStyle, offset + 4);
      offset += 4 + encodedStyleStyle.length;
      view.setUint32(offset, encodedStyleWeight.length);
      data.set(encodedStyleWeight, offset + 4);
      offset += 4 + encodedStyleWeight.length;
    }
    assert(
      offset <= buffer.byteLength,
      "SubstitionInfo.write: Buffer overflow"
    );
    return buffer.transferToFixedLength(offset);
  }
  get guessFallback() {
    return __privateGet(this, _view2).getUint8(0) !== 0;
  }
  get css() {
    return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 0);
  }
  get loadedName() {
    return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 1);
  }
  get baseFontName() {
    return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 2);
  }
  get src() {
    return __privateMethod(this, _SystemFontInfo_instances, readString_fn2).call(this, 3);
  }
  get style() {
    let offset = 1;
    offset += 4 + __privateGet(this, _view2).getUint32(offset);
    const styleLength = __privateGet(this, _view2).getUint32(offset);
    const style = __privateGet(this, _decoder2).decode(
      new Uint8Array(__privateGet(this, _buffer2), offset + 4, styleLength)
    );
    offset += 4 + styleLength;
    const weightLength = __privateGet(this, _view2).getUint32(offset);
    const weight = __privateGet(this, _decoder2).decode(
      new Uint8Array(__privateGet(this, _buffer2), offset + 4, weightLength)
    );
    return { style, weight };
  }
};
_buffer2 = new WeakMap();
_view2 = new WeakMap();
_decoder2 = new WeakMap();
_SystemFontInfo_instances = new WeakSet();
readString_fn2 = function(index) {
  assert(index < _SystemFontInfo.strings.length, "Invalid string index");
  let offset = 5;
  for (let i = 0; i < index; i++) {
    offset += __privateGet(this, _view2).getUint32(offset) + 4;
  }
  const length = __privateGet(this, _view2).getUint32(offset);
  return __privateGet(this, _decoder2).decode(
    new Uint8Array(__privateGet(this, _buffer2), offset + 4, length)
  );
};
__publicField(_SystemFontInfo, "strings", ["css", "loadedName", "baseFontName", "src"]);
var SystemFontInfo = _SystemFontInfo;
var _OFFSET_NUMBERS, _OFFSET_BBOX, _OFFSET_FONT_MATRIX, _OFFSET_DEFAULT_VMETRICS, _OFFSET_STRINGS, _buffer3, _decoder3, _view3, _FontInfo_instances, readBoolean_fn, readNumber_fn, readString_fn3;
var _FontInfo = class _FontInfo {
  constructor({ data, extra }) {
    __privateAdd(this, _FontInfo_instances);
    __privateAdd(this, _buffer3);
    __privateAdd(this, _decoder3);
    __privateAdd(this, _view3);
    __privateSet(this, _buffer3, data);
    __privateSet(this, _decoder3, new TextDecoder());
    __privateSet(this, _view3, new DataView(__privateGet(this, _buffer3)));
    if (extra) {
      Object.assign(this, extra);
    }
  }
  get black() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 0);
  }
  get bold() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 1);
  }
  get disableFontFace() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 2);
  }
  get fontExtraProperties() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 3);
  }
  get isInvalidPDFjsFont() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 4);
  }
  get isType3Font() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 5);
  }
  get italic() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 6);
  }
  get missingFile() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 7);
  }
  get remeasure() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 8);
  }
  get vertical() {
    return __privateMethod(this, _FontInfo_instances, readBoolean_fn).call(this, 9);
  }
  get ascent() {
    return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 0);
  }
  get defaultWidth() {
    return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 1);
  }
  get descent() {
    return __privateMethod(this, _FontInfo_instances, readNumber_fn).call(this, 2);
  }
  get bbox() {
    let offset = __privateGet(_FontInfo, _OFFSET_BBOX);
    const numCoords = __privateGet(this, _view3).getUint8(offset);
    if (numCoords === 0) {
      return void 0;
    }
    offset += 1;
    const bbox = [];
    for (let i = 0; i < 4; i++) {
      bbox.push(__privateGet(this, _view3).getInt16(offset, true));
      offset += 2;
    }
    return bbox;
  }
  get fontMatrix() {
    let offset = __privateGet(_FontInfo, _OFFSET_FONT_MATRIX);
    const numPoints = __privateGet(this, _view3).getUint8(offset);
    if (numPoints === 0) {
      return void 0;
    }
    offset += 1;
    const fontMatrix = [];
    for (let i = 0; i < 6; i++) {
      fontMatrix.push(__privateGet(this, _view3).getFloat64(offset, true));
      offset += 8;
    }
    return fontMatrix;
  }
  get defaultVMetrics() {
    let offset = __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS);
    const numMetrics = __privateGet(this, _view3).getUint8(offset);
    if (numMetrics === 0) {
      return void 0;
    }
    offset += 1;
    const defaultVMetrics = [];
    for (let i = 0; i < 3; i++) {
      defaultVMetrics.push(__privateGet(this, _view3).getInt16(offset, true));
      offset += 2;
    }
    return defaultVMetrics;
  }
  get fallbackName() {
    return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 0);
  }
  get loadedName() {
    return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 1);
  }
  get mimetype() {
    return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 2);
  }
  get name() {
    return __privateMethod(this, _FontInfo_instances, readString_fn3).call(this, 3);
  }
  get data() {
    let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
    const stringsLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + stringsLength;
    const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + systemFontInfoLength;
    const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + cssFontInfoLength;
    const length = __privateGet(this, _view3).getUint32(offset);
    if (length === 0) {
      return void 0;
    }
    return new Uint8Array(__privateGet(this, _buffer3), offset + 4, length);
  }
  clearData() {
    let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
    const stringsLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + stringsLength;
    const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + systemFontInfoLength;
    const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + cssFontInfoLength;
    const length = __privateGet(this, _view3).getUint32(offset);
    const data = new Uint8Array(__privateGet(this, _buffer3), offset + 4, length);
    data.fill(0);
    __privateGet(this, _view3).setUint32(offset, 0);
  }
  get cssFontInfo() {
    let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
    const stringsLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + stringsLength;
    const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + systemFontInfoLength;
    const cssFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    if (cssFontInfoLength === 0) {
      return null;
    }
    const cssFontInfoData = new Uint8Array(cssFontInfoLength);
    cssFontInfoData.set(
      new Uint8Array(__privateGet(this, _buffer3), offset + 4, cssFontInfoLength)
    );
    return new CssFontInfo(cssFontInfoData.buffer);
  }
  get systemFontInfo() {
    let offset = __privateGet(_FontInfo, _OFFSET_STRINGS);
    const stringsLength = __privateGet(this, _view3).getUint32(offset);
    offset += 4 + stringsLength;
    const systemFontInfoLength = __privateGet(this, _view3).getUint32(offset);
    if (systemFontInfoLength === 0) {
      return null;
    }
    const systemFontInfoData = new Uint8Array(systemFontInfoLength);
    systemFontInfoData.set(
      new Uint8Array(__privateGet(this, _buffer3), offset + 4, systemFontInfoLength)
    );
    return new SystemFontInfo(systemFontInfoData.buffer);
  }
  static write(font) {
    const systemFontInfoBuffer = font.systemFontInfo ? SystemFontInfo.write(font.systemFontInfo) : null;
    const cssFontInfoBuffer = font.cssFontInfo ? CssFontInfo.write(font.cssFontInfo) : null;
    const encoder = new TextEncoder();
    const encodedStrings = {};
    let stringsLength = 0;
    for (const prop of _FontInfo.strings) {
      encodedStrings[prop] = encoder.encode(font[prop]);
      stringsLength += 4 + encodedStrings[prop].length;
    }
    const lengthEstimate = __privateGet(_FontInfo, _OFFSET_STRINGS) + 4 + stringsLength + 4 + (systemFontInfoBuffer ? systemFontInfoBuffer.byteLength : 0) + 4 + (cssFontInfoBuffer ? cssFontInfoBuffer.byteLength : 0) + 4 + (font.data ? font.data.length : 0);
    const buffer = new ArrayBuffer(lengthEstimate);
    const data = new Uint8Array(buffer);
    const view = new DataView(buffer);
    let offset = 0;
    const numBools = _FontInfo.bools.length;
    let boolByte = 0, boolBit = 0;
    for (let i = 0; i < numBools; i++) {
      const value = font[_FontInfo.bools[i]];
      const bits = value === void 0 ? 0 : value ? 2 : 1;
      boolByte |= bits << boolBit;
      boolBit += 2;
      if (boolBit === 8 || i === numBools - 1) {
        view.setUint8(offset++, boolByte);
        boolByte = 0;
        boolBit = 0;
      }
    }
    assert(
      offset === __privateGet(_FontInfo, _OFFSET_NUMBERS),
      "FontInfo.write: Boolean properties offset mismatch"
    );
    for (const prop of _FontInfo.numbers) {
      view.setFloat64(offset, font[prop]);
      offset += 8;
    }
    assert(
      offset === __privateGet(_FontInfo, _OFFSET_BBOX),
      "FontInfo.write: Number properties offset mismatch"
    );
    if (font.bbox) {
      view.setUint8(offset++, 4);
      for (const coord of font.bbox) {
        view.setInt16(offset, coord, true);
        offset += 2;
      }
    } else {
      view.setUint8(offset++, 0);
      offset += 2 * 4;
    }
    assert(
      offset === __privateGet(_FontInfo, _OFFSET_FONT_MATRIX),
      "FontInfo.write: BBox properties offset mismatch"
    );
    if (font.fontMatrix) {
      view.setUint8(offset++, 6);
      for (const point of font.fontMatrix) {
        view.setFloat64(offset, point, true);
        offset += 8;
      }
    } else {
      view.setUint8(offset++, 0);
      offset += 8 * 6;
    }
    assert(
      offset === __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS),
      "FontInfo.write: FontMatrix properties offset mismatch"
    );
    if (font.defaultVMetrics) {
      view.setUint8(offset++, 1);
      for (const metric of font.defaultVMetrics) {
        view.setInt16(offset, metric, true);
        offset += 2;
      }
    } else {
      view.setUint8(offset++, 0);
      offset += 3 * 2;
    }
    assert(
      offset === __privateGet(_FontInfo, _OFFSET_STRINGS),
      "FontInfo.write: DefaultVMetrics properties offset mismatch"
    );
    view.setUint32(__privateGet(_FontInfo, _OFFSET_STRINGS), 0);
    offset += 4;
    for (const prop of _FontInfo.strings) {
      const encoded = encodedStrings[prop];
      const length = encoded.length;
      view.setUint32(offset, length);
      data.set(encoded, offset + 4);
      offset += 4 + length;
    }
    view.setUint32(
      __privateGet(_FontInfo, _OFFSET_STRINGS),
      offset - __privateGet(_FontInfo, _OFFSET_STRINGS) - 4
    );
    if (!systemFontInfoBuffer) {
      view.setUint32(offset, 0);
      offset += 4;
    } else {
      const length = systemFontInfoBuffer.byteLength;
      view.setUint32(offset, length);
      assert(
        offset + 4 + length <= buffer.byteLength,
        "FontInfo.write: Buffer overflow at systemFontInfo"
      );
      data.set(new Uint8Array(systemFontInfoBuffer), offset + 4);
      offset += 4 + length;
    }
    if (!cssFontInfoBuffer) {
      view.setUint32(offset, 0);
      offset += 4;
    } else {
      const length = cssFontInfoBuffer.byteLength;
      view.setUint32(offset, length);
      assert(
        offset + 4 + length <= buffer.byteLength,
        "FontInfo.write: Buffer overflow at cssFontInfo"
      );
      data.set(new Uint8Array(cssFontInfoBuffer), offset + 4);
      offset += 4 + length;
    }
    if (font.data === void 0) {
      view.setUint32(offset, 0);
      offset += 4;
    } else {
      view.setUint32(offset, font.data.length);
      data.set(font.data, offset + 4);
      offset += 4 + font.data.length;
    }
    assert(offset <= buffer.byteLength, "FontInfo.write: Buffer overflow");
    return buffer.transferToFixedLength(offset);
  }
};
_OFFSET_NUMBERS = new WeakMap();
_OFFSET_BBOX = new WeakMap();
_OFFSET_FONT_MATRIX = new WeakMap();
_OFFSET_DEFAULT_VMETRICS = new WeakMap();
_OFFSET_STRINGS = new WeakMap();
_buffer3 = new WeakMap();
_decoder3 = new WeakMap();
_view3 = new WeakMap();
_FontInfo_instances = new WeakSet();
readBoolean_fn = function(index) {
  assert(index < _FontInfo.bools.length, "Invalid boolean index");
  const byteOffset = Math.floor(index / 4);
  const bitOffset = index * 2 % 8;
  const value = __privateGet(this, _view3).getUint8(byteOffset) >> bitOffset & 3;
  return value === 0 ? void 0 : value === 2;
};
readNumber_fn = function(index) {
  assert(index < _FontInfo.numbers.length, "Invalid number index");
  return __privateGet(this, _view3).getFloat64(__privateGet(_FontInfo, _OFFSET_NUMBERS) + index * 8);
};
readString_fn3 = function(index) {
  assert(index < _FontInfo.strings.length, "Invalid string index");
  let offset = __privateGet(_FontInfo, _OFFSET_STRINGS) + 4;
  for (let i = 0; i < index; i++) {
    offset += __privateGet(this, _view3).getUint32(offset) + 4;
  }
  const length = __privateGet(this, _view3).getUint32(offset);
  const stringData = new Uint8Array(length);
  stringData.set(new Uint8Array(__privateGet(this, _buffer3), offset + 4, length));
  return __privateGet(this, _decoder3).decode(stringData);
};
__publicField(_FontInfo, "bools", [
  "black",
  "bold",
  "disableFontFace",
  "fontExtraProperties",
  "isInvalidPDFjsFont",
  "isType3Font",
  "italic",
  "missingFile",
  "remeasure",
  "vertical"
]);
__publicField(_FontInfo, "numbers", ["ascent", "defaultWidth", "descent"]);
__publicField(_FontInfo, "strings", ["fallbackName", "loadedName", "mimetype", "name"]);
__privateAdd(_FontInfo, _OFFSET_NUMBERS, Math.ceil(_FontInfo.bools.length * 2 / 8));
__privateAdd(_FontInfo, _OFFSET_BBOX, __privateGet(_FontInfo, _OFFSET_NUMBERS) + _FontInfo.numbers.length * 8);
__privateAdd(_FontInfo, _OFFSET_FONT_MATRIX, __privateGet(_FontInfo, _OFFSET_BBOX) + 1 + 2 * 4);
__privateAdd(_FontInfo, _OFFSET_DEFAULT_VMETRICS, __privateGet(_FontInfo, _OFFSET_FONT_MATRIX) + 1 + 8 * 6);
__privateAdd(_FontInfo, _OFFSET_STRINGS, __privateGet(_FontInfo, _OFFSET_DEFAULT_VMETRICS) + 1 + 2 * 3);
var FontInfo = _FontInfo;

// src/pdf.js/src/core/bidi.js
var baseTypes = [
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "S",
  "B",
  "S",
  "WS",
  "B",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "B",
  "B",
  "B",
  "S",
  "WS",
  "ON",
  "ON",
  "ET",
  "ET",
  "ET",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "ES",
  "CS",
  "ES",
  "CS",
  "CS",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "CS",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "ON",
  "ON",
  "ON",
  "ON",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "B",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "BN",
  "CS",
  "ON",
  "ET",
  "ET",
  "ET",
  "ET",
  "ON",
  "ON",
  "ON",
  "ON",
  "L",
  "ON",
  "ON",
  "BN",
  "ON",
  "ON",
  "ET",
  "ET",
  "EN",
  "EN",
  "ON",
  "L",
  "ON",
  "ON",
  "ON",
  "EN",
  "L",
  "ON",
  "ON",
  "ON",
  "ON",
  "ON",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "ON",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "ON",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L",
  "L"
];
var arabicTypes = [
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "ON",
  "ON",
  "AL",
  "ET",
  "ET",
  "AL",
  "CS",
  "AL",
  "ON",
  "ON",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "AL",
  "AL",
  "",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "AN",
  "ET",
  "AN",
  "AN",
  "AL",
  "AL",
  "AL",
  "NSM",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "AN",
  "ON",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "AL",
  "AL",
  "NSM",
  "NSM",
  "ON",
  "NSM",
  "NSM",
  "NSM",
  "NSM",
  "AL",
  "AL",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "EN",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL",
  "AL"
];
function isOdd(i) {
  return (i & 1) !== 0;
}
function isEven(i) {
  return (i & 1) === 0;
}
function findUnequal(arr, start, value) {
  let j, jj;
  for (j = start, jj = arr.length; j < jj; ++j) {
    if (arr[j] !== value) {
      return j;
    }
  }
  return j;
}
function reverseValues(arr, start, end) {
  for (let i = start, j = end - 1; i < j; ++i, --j) {
    const temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
}
function createBidiText(str, isLTR, vertical = false) {
  let dir = "ltr";
  if (vertical) {
    dir = "ttb";
  } else if (!isLTR) {
    dir = "rtl";
  }
  return { str, dir };
}
var chars = [];
var types = [];
function bidi(str, startLevel = -1, vertical = false) {
  let isLTR = true;
  const strLength = str.length;
  if (strLength === 0 || vertical) {
    return createBidiText(str, isLTR, vertical);
  }
  chars.length = strLength;
  types.length = strLength;
  let numBidi = 0;
  let i, ii;
  for (i = 0; i < strLength; ++i) {
    chars[i] = str.charAt(i);
    const charCode = str.charCodeAt(i);
    let charType = "L";
    if (charCode <= 255) {
      charType = baseTypes[charCode];
    } else if (1424 <= charCode && charCode <= 1524) {
      charType = "R";
    } else if (1536 <= charCode && charCode <= 1791) {
      charType = arabicTypes[charCode & 255];
      if (!charType) {
        warn("Bidi: invalid Unicode character " + charCode.toString(16));
      }
    } else if (1792 <= charCode && charCode <= 2220 || 64336 <= charCode && charCode <= 65023 || 65136 <= charCode && charCode <= 65279) {
      charType = "AL";
    }
    if (charType === "R" || charType === "AL" || charType === "AN") {
      numBidi++;
    }
    types[i] = charType;
  }
  if (numBidi === 0) {
    isLTR = true;
    return createBidiText(str, isLTR);
  }
  if (startLevel === -1) {
    if (numBidi / strLength < 0.3 && strLength > 4) {
      isLTR = true;
      startLevel = 0;
    } else {
      isLTR = false;
      startLevel = 1;
    }
  }
  const levels = [];
  for (i = 0; i < strLength; ++i) {
    levels[i] = startLevel;
  }
  const e = isOdd(startLevel) ? "R" : "L";
  const sor = e;
  const eor = sor;
  let lastType = sor;
  for (i = 0; i < strLength; ++i) {
    if (types[i] === "NSM") {
      types[i] = lastType;
    } else {
      lastType = types[i];
    }
  }
  lastType = sor;
  let t;
  for (i = 0; i < strLength; ++i) {
    t = types[i];
    if (t === "EN") {
      types[i] = lastType === "AL" ? "AN" : "EN";
    } else if (t === "R" || t === "L" || t === "AL") {
      lastType = t;
    }
  }
  for (i = 0; i < strLength; ++i) {
    t = types[i];
    if (t === "AL") {
      types[i] = "R";
    }
  }
  for (i = 1; i < strLength - 1; ++i) {
    if (types[i] === "ES" && types[i - 1] === "EN" && types[i + 1] === "EN") {
      types[i] = "EN";
    }
    if (types[i] === "CS" && (types[i - 1] === "EN" || types[i - 1] === "AN") && types[i + 1] === types[i - 1]) {
      types[i] = types[i - 1];
    }
  }
  for (i = 0; i < strLength; ++i) {
    if (types[i] === "EN") {
      for (let j = i - 1; j >= 0; --j) {
        if (types[j] !== "ET") {
          break;
        }
        types[j] = "EN";
      }
      for (let j = i + 1; j < strLength; ++j) {
        if (types[j] !== "ET") {
          break;
        }
        types[j] = "EN";
      }
    }
  }
  for (i = 0; i < strLength; ++i) {
    t = types[i];
    if (t === "WS" || t === "ES" || t === "ET" || t === "CS") {
      types[i] = "ON";
    }
  }
  lastType = sor;
  for (i = 0; i < strLength; ++i) {
    t = types[i];
    if (t === "EN") {
      types[i] = lastType === "L" ? "L" : "EN";
    } else if (t === "R" || t === "L") {
      lastType = t;
    }
  }
  for (i = 0; i < strLength; ++i) {
    if (types[i] === "ON") {
      const end = findUnequal(types, i + 1, "ON");
      let before = sor;
      if (i > 0) {
        before = types[i - 1];
      }
      let after = eor;
      if (end + 1 < strLength) {
        after = types[end + 1];
      }
      if (before !== "L") {
        before = "R";
      }
      if (after !== "L") {
        after = "R";
      }
      if (before === after) {
        types.fill(before, i, end);
      }
      i = end - 1;
    }
  }
  for (i = 0; i < strLength; ++i) {
    if (types[i] === "ON") {
      types[i] = e;
    }
  }
  for (i = 0; i < strLength; ++i) {
    t = types[i];
    if (isEven(levels[i])) {
      if (t === "R") {
        levels[i] += 1;
      } else if (t === "AN" || t === "EN") {
        levels[i] += 2;
      }
    } else if (
      /* isOdd && */
      t === "L" || t === "AN" || t === "EN"
    ) {
      levels[i] += 1;
    }
  }
  let highestLevel = -1;
  let lowestOddLevel = 99;
  let level;
  for (i = 0, ii = levels.length; i < ii; ++i) {
    level = levels[i];
    if (highestLevel < level) {
      highestLevel = level;
    }
    if (lowestOddLevel > level && isOdd(level)) {
      lowestOddLevel = level;
    }
  }
  for (level = highestLevel; level >= lowestOddLevel; --level) {
    let start = -1;
    for (i = 0, ii = levels.length; i < ii; ++i) {
      if (levels[i] < level) {
        if (start >= 0) {
          reverseValues(chars, start, i);
          start = -1;
        }
      } else if (start < 0) {
        start = i;
      }
    }
    if (start >= 0) {
      reverseValues(chars, start, levels.length);
    }
  }
  for (i = 0, ii = chars.length; i < ii; ++i) {
    const ch = chars[i];
    if (ch === "<" || ch === ">") {
      chars[i] = "";
    }
  }
  return createBidiText(chars.join(""), isLTR);
}

// src/pdf.js/src/shared/scripting_utils.js
function makeColorComp(n) {
  return Math.floor(Math.max(0, Math.min(1, n)) * 255).toString(16).padStart(2, "0");
}
function scaleAndClamp(x) {
  return Math.max(0, Math.min(255, 255 * x));
}
var ColorConverters = class {
  static CMYK_G([c, y, m, k]) {
    return ["G", 1 - Math.min(1, 0.3 * c + 0.59 * m + 0.11 * y + k)];
  }
  static G_CMYK([g]) {
    return ["CMYK", 0, 0, 0, 1 - g];
  }
  static G_RGB([g]) {
    return ["RGB", g, g, g];
  }
  static G_rgb([g]) {
    g = scaleAndClamp(g);
    return [g, g, g];
  }
  static G_HTML([g]) {
    const G = makeColorComp(g);
    return `#${G}${G}${G}`;
  }
  static RGB_G([r, g, b]) {
    return ["G", 0.3 * r + 0.59 * g + 0.11 * b];
  }
  static RGB_rgb(color) {
    return color.map(scaleAndClamp);
  }
  static RGB_HTML(color) {
    return `#${color.map(makeColorComp).join("")}`;
  }
  static T_HTML() {
    return "#00000000";
  }
  static T_rgb() {
    return [null];
  }
  static CMYK_RGB([c, y, m, k]) {
    return [
      "RGB",
      1 - Math.min(1, c + k),
      1 - Math.min(1, m + k),
      1 - Math.min(1, y + k)
    ];
  }
  static CMYK_rgb([c, y, m, k]) {
    return [
      scaleAndClamp(1 - Math.min(1, c + k)),
      scaleAndClamp(1 - Math.min(1, m + k)),
      scaleAndClamp(1 - Math.min(1, y + k))
    ];
  }
  static CMYK_HTML(components) {
    const rgb = this.CMYK_RGB(components).slice(1);
    return this.RGB_HTML(rgb);
  }
  static RGB_CMYK([r, g, b]) {
    const c = 1 - r;
    const m = 1 - g;
    const y = 1 - b;
    const k = Math.min(c, m, y);
    return ["CMYK", c, m, y, k];
  }
};
var DateFormats = [
  "m/d",
  "m/d/yy",
  "mm/dd/yy",
  "mm/yy",
  "d-mmm",
  "d-mmm-yy",
  "dd-mmm-yy",
  "yy-mm-dd",
  "mmm-yy",
  "mmmm-yy",
  "mmm d, yyyy",
  "mmmm d, yyyy",
  "m/d/yy h:MM tt",
  "m/d/yy HH:MM"
];
var TimeFormats = ["HH:MM", "h:MM tt", "HH:MM:ss", "h:MM:ss tt"];

// src/pdf.js/src/shared/murmurhash3.js
var SEED = 3285377520;
var MASK_HIGH = 4294901760;
var MASK_LOW = 65535;
var MurmurHash3_64 = class {
  constructor(seed) {
    this.h1 = seed ? seed & 4294967295 : SEED;
    this.h2 = seed ? seed & 4294967295 : SEED;
  }
  update(input) {
    let data, length;
    if (typeof input === "string") {
      data = new Uint8Array(input.length * 2);
      length = 0;
      for (let i = 0, ii = input.length; i < ii; i++) {
        const code = input.charCodeAt(i);
        if (code <= 255) {
          data[length++] = code;
        } else {
          data[length++] = code >>> 8;
          data[length++] = code & 255;
        }
      }
    } else if (ArrayBuffer.isView(input)) {
      data = input.slice();
      length = data.byteLength;
    } else {
      throw new Error("Invalid data format, must be a string or TypedArray.");
    }
    const blockCounts = length >> 2;
    const tailLength = length - blockCounts * 4;
    const dataUint32 = new Uint32Array(data.buffer, 0, blockCounts);
    let k1 = 0, k2 = 0;
    let h1 = this.h1, h2 = this.h2;
    const C1 = 3432918353, C2 = 461845907;
    const C1_LOW = C1 & MASK_LOW, C2_LOW = C2 & MASK_LOW;
    for (let i = 0; i < blockCounts; i++) {
      if (i & 1) {
        k1 = dataUint32[i];
        k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
        k1 = k1 << 15 | k1 >>> 17;
        k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
        h1 ^= k1;
        h1 = h1 << 13 | h1 >>> 19;
        h1 = h1 * 5 + 3864292196;
      } else {
        k2 = dataUint32[i];
        k2 = k2 * C1 & MASK_HIGH | k2 * C1_LOW & MASK_LOW;
        k2 = k2 << 15 | k2 >>> 17;
        k2 = k2 * C2 & MASK_HIGH | k2 * C2_LOW & MASK_LOW;
        h2 ^= k2;
        h2 = h2 << 13 | h2 >>> 19;
        h2 = h2 * 5 + 3864292196;
      }
    }
    k1 = 0;
    switch (tailLength) {
      case 3:
        k1 ^= data[blockCounts * 4 + 2] << 16;
      /* falls through */
      case 2:
        k1 ^= data[blockCounts * 4 + 1] << 8;
      /* falls through */
      case 1:
        k1 ^= data[blockCounts * 4];
        k1 = k1 * C1 & MASK_HIGH | k1 * C1_LOW & MASK_LOW;
        k1 = k1 << 15 | k1 >>> 17;
        k1 = k1 * C2 & MASK_HIGH | k1 * C2_LOW & MASK_LOW;
        if (blockCounts & 1) {
          h1 ^= k1;
        } else {
          h2 ^= k1;
        }
    }
    this.h1 = h1;
    this.h2 = h2;
  }
  hexdigest() {
    let h1 = this.h1, h2 = this.h2;
    h1 ^= h2 >>> 1;
    h1 = h1 * 3981806797 & MASK_HIGH | h1 * 36045 & MASK_LOW;
    h2 = h2 * 4283543511 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 2950163797 & MASK_HIGH) >>> 16;
    h1 ^= h2 >>> 1;
    h1 = h1 * 444984403 & MASK_HIGH | h1 * 60499 & MASK_LOW;
    h2 = h2 * 3301882366 & MASK_HIGH | ((h2 << 16 | h1 >>> 16) * 3120437893 & MASK_HIGH) >>> 16;
    h1 ^= h2 >>> 1;
    return (h1 >>> 0).toString(16).padStart(8, "0") + (h2 >>> 0).toString(16).padStart(8, "0");
  }
};

// src/pdf.js/src/shared/image_utils.js
function convertToRGBA(params) {
  switch (params.kind) {
    case ImageKind.GRAYSCALE_1BPP:
      return convertBlackAndWhiteToRGBA(params);
    case ImageKind.RGB_24BPP:
      return convertRGBToRGBA(params);
  }
  return null;
}
function convertBlackAndWhiteToRGBA({
  src,
  srcPos = 0,
  dest,
  width,
  height,
  nonBlackColor = 4294967295,
  inverseDecode = false
}) {
  const black = FeatureTest.isLittleEndian ? 4278190080 : 255;
  const [zeroMapping, oneMapping] = inverseDecode ? [nonBlackColor, black] : [black, nonBlackColor];
  const widthInSource = width >> 3;
  const widthRemainder = width & 7;
  const srcLength = src.length;
  dest = new Uint32Array(dest.buffer);
  let destPos = 0;
  for (let i = 0; i < height; i++) {
    for (const max = srcPos + widthInSource; srcPos < max; srcPos++) {
      const elem2 = srcPos < srcLength ? src[srcPos] : 255;
      dest[destPos++] = elem2 & 128 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 64 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 32 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 16 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 8 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 4 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 2 ? oneMapping : zeroMapping;
      dest[destPos++] = elem2 & 1 ? oneMapping : zeroMapping;
    }
    if (widthRemainder === 0) {
      continue;
    }
    const elem = srcPos < srcLength ? src[srcPos++] : 255;
    for (let j = 0; j < widthRemainder; j++) {
      dest[destPos++] = elem & 1 << 7 - j ? oneMapping : zeroMapping;
    }
  }
  return { srcPos, destPos };
}
function convertRGBToRGBA({
  src,
  srcPos = 0,
  dest,
  destPos = 0,
  width,
  height
}) {
  let i = 0;
  const len = width * height * 3;
  const len32 = len >> 2;
  const src32 = new Uint32Array(src.buffer, srcPos, len32);
  if (FeatureTest.isLittleEndian) {
    for (; i < len32 - 2; i += 3, destPos += 4) {
      const s1 = src32[i];
      const s2 = src32[i + 1];
      const s3 = src32[i + 2];
      dest[destPos] = s1 | 4278190080;
      dest[destPos + 1] = s1 >>> 24 | s2 << 8 | 4278190080;
      dest[destPos + 2] = s2 >>> 16 | s3 << 16 | 4278190080;
      dest[destPos + 3] = s3 >>> 8 | 4278190080;
    }
    for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
      dest[destPos++] = src[j] | src[j + 1] << 8 | src[j + 2] << 16 | 4278190080;
    }
  } else {
    for (; i < len32 - 2; i += 3, destPos += 4) {
      const s1 = src32[i];
      const s2 = src32[i + 1];
      const s3 = src32[i + 2];
      dest[destPos] = s1 | 255;
      dest[destPos + 1] = s1 << 24 | s2 >>> 8 | 255;
      dest[destPos + 2] = s2 << 16 | s3 >>> 16 | 255;
      dest[destPos + 3] = s3 << 8 | 255;
    }
    for (let j = i * 4, jj = srcPos + len; j < jj; j += 3) {
      dest[destPos++] = src[j] << 24 | src[j + 1] << 16 | src[j + 2] << 8 | 255;
    }
  }
  return { srcPos: srcPos + len, destPos };
}
function grayToRGBA(src, dest) {
  if (FeatureTest.isLittleEndian) {
    for (let i = 0, ii = src.length; i < ii; i++) {
      dest[i] = src[i] * 65793 | 4278190080;
    }
  } else {
    for (let i = 0, ii = src.length; i < ii; i++) {
      dest[i] = src[i] * 16843008 | 255;
    }
  }
}

export {
  MurmurHash3_64,
  wrapReason,
  MessageHandler,
  convertToRGBA,
  convertBlackAndWhiteToRGBA,
  grayToRGBA,
  FontInfo,
  bidi,
  ColorConverters,
  DateFormats,
  TimeFormats
};
