"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 Base64Codec_exports = {};
__export(Base64Codec_exports, {
  Base64: () => Base64
});
module.exports = __toCommonJS(Base64Codec_exports);
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
function cp(text) {
  return text.codePointAt(0) ?? 0;
}
const A2B = [];
const B2A = new Uint8Array(64);
const B2A_URL = new Uint8Array(64);
const PAD = cp("=");
{
  let addRange2 = function(start, stop) {
    const end = cp(stop) + 1;
    for (let i = cp(start); i < end; i++) {
      A2B[i] = pos;
      B2A[pos++] = i;
    }
  };
  var addRange = addRange2;
  let pos = 0;
  addRange2("A", "Z");
  addRange2("a", "z");
  addRange2("0", "9");
  addRange2("+", "+");
  addRange2("/", "/");
  const slashValue = A2B[cp("/")];
  const plusValue = A2B[cp("+")];
  A2B[cp("_")] = slashValue;
  A2B[cp("-")] = plusValue;
  B2A_URL.set(B2A);
  B2A_URL[slashValue] = cp("_");
  B2A_URL[plusValue] = cp("-");
}
var Base64;
((Base642) => {
  function encode(input, url = false) {
    const dict = url ? B2A_URL : B2A;
    let outLength = Math.trunc(input.length / 3) * 4;
    if (url) {
      const partial = input.length % 3;
      if (partial) outLength += partial + 1;
    } else {
      outLength += input.length % 3 ? 4 : 0;
    }
    const out = new Uint8Array(outLength);
    for (let inPos = 0, outPos = 0; outPos < outLength; ) {
      const n = (input[inPos++] << 16) + ((input[inPos++] ?? 0) << 8) + (input[inPos++] ?? 0);
      out[outPos++] = dict[n >>> 18];
      out[outPos++] = dict[n >>> 12 & 63];
      if (inPos - input.length === 2) {
        if (!url) out[outPos++] = PAD;
      } else {
        out[outPos++] = dict[n >>> 6 & 63];
      }
      if (inPos > input.length) {
        if (!url) out[outPos++] = PAD;
      } else {
        out[outPos++] = dict[n & 63];
      }
    }
    return new TextDecoder().decode(out);
  }
  Base642.encode = encode;
  function decode(input) {
    if (!input.length) {
      return new Uint8Array();
    }
    let inputLength = input.length;
    while (input.codePointAt(inputLength - 1) === PAD) inputLength--;
    let outLength = Math.trunc(inputLength / 4) * 3;
    switch (inputLength % 4) {
      case 3:
        outLength += 2;
        break;
      case 2:
        outLength += 1;
        break;
      case 1:
        throw new SyntaxError("Invalid base-64 encoding");
    }
    const out = new Uint8Array(outLength);
    for (let inPos = 0, outPos = 0; ; ) {
      let lookup2 = function() {
        if (inPos >= inputLength) return 0;
        const v = A2B[input.codePointAt(inPos++) ?? -1];
        if (v === void 0) {
          throw new SyntaxError("Invalid base-64 encoding");
        }
        return v;
      };
      var lookup = lookup2;
      const n = (lookup2() << 18) + (lookup2() << 12) + (lookup2() << 6) + lookup2();
      out[outPos++] = n >>> 16;
      if (outPos < outLength) {
        out[outPos++] = n >>> 8 & 255;
      } else {
        break;
      }
      if (outPos < outLength) {
        out[outPos++] = n & 255;
      } else {
        break;
      }
    }
    return out;
  }
  Base642.decode = decode;
})(Base64 || (Base64 = {}));
//# sourceMappingURL=Base64Codec.js.map
