"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var WordArray_exports = {};
__export(WordArray_exports, {
  WordArray: () => WordArray
});
module.exports = __toCommonJS(WordArray_exports);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function WordArray(length) {
  return new Int32Array(length);
}
const endianConversionView = new DataView(new ArrayBuffer(4));
const endianConversionBytes = new Uint8Array(endianConversionView.buffer);
((WordArray2) => {
  function fromByteArray(bytes, alignment = 1) {
    return fromByteView(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength), alignment);
  }
  WordArray2.fromByteArray = fromByteArray;
  function fromByteView(bytes, alignment = 1) {
    const inputBytes = bytes.byteLength;
    const allocWords = Math.ceil(inputBytes / 4 / alignment) * alignment;
    const result = WordArray2(allocWords);
    let i = 0;
    for (; i + 4 <= inputBytes; i += 4) {
      result[i / 4] = bytes.getInt32(i);
    }
    if (i < inputBytes) {
      result[i / 4] = readPartialWord(bytes, i, inputBytes - i);
    }
    return result;
  }
  WordArray2.fromByteView = fromByteView;
  function bytesToBlock(bytes, block, byteOffset) {
    if (byteOffset === void 0) {
      byteOffset = 0;
    }
    for (let i = 0; i < 4; i++, byteOffset += 4) {
      if (byteOffset + 4 <= bytes.byteLength) {
        block[i] = bytes.getInt32(byteOffset);
      } else if (byteOffset >= bytes.byteLength) {
        block[i] = 0;
      } else {
        block[i] = readPartialWord(bytes, byteOffset);
      }
    }
  }
  WordArray2.bytesToBlock = bytesToBlock;
  function readPartialWord(bytes, offset, bytesAvailable = bytes.byteLength - offset) {
    for (let i = 0; i < 4; i++) {
      if (i < bytesAvailable) {
        endianConversionBytes[i] = bytes.getUint8(offset + i);
      } else {
        endianConversionBytes[i] = 0;
      }
    }
    return endianConversionView.getUint32(0);
  }
  WordArray2.readPartialWord = readPartialWord;
  function writePartialWord(word, bytes, offset, bytesAvailable = Math.max(bytes.byteLength - offset, 4)) {
    endianConversionView.setUint32(0, word);
    endianConversionBytes[0] = word >>> 24;
    endianConversionBytes[1] = word >> 16 & 255;
    endianConversionBytes[2] = word >> 8 & 255;
    endianConversionBytes[3] = word & 255;
    for (let i = 0; i < bytesAvailable; i++) {
      bytes.setUint8(offset + i, endianConversionBytes[i]);
    }
  }
  WordArray2.writePartialWord = writePartialWord;
})(WordArray || (WordArray = {}));
//# sourceMappingURL=WordArray.js.map
