import { Scalar as u } from "./accelbyte-widgets651.mjs";
import { stringifyString as d } from "./accelbyte-widgets652.mjs";
const y = {
  identify: (t) => t instanceof Uint8Array,
  default: !1,
  tag: "tag:yaml.org,2002:binary",
  resolve(t, e) {
    if (typeof Buffer == "function")
      return Buffer.from(t, "base64");
    if (typeof atob == "function") {
      const s = atob(t.replace(/[\n\r]/g, "")), r = new Uint8Array(s.length);
      for (let n = 0; n < s.length; ++n)
        r[n] = s.charCodeAt(n);
      return r;
    } else
      return e("This environment does not support reading binary tags; either Buffer or atob is required"), t;
  },
  stringify({ comment: t, type: e, value: s }, r, n, h) {
    const a = s;
    let o;
    if (typeof Buffer == "function")
      o = a instanceof Buffer ? a.toString("base64") : Buffer.from(a.buffer).toString("base64");
    else if (typeof btoa == "function") {
      let i = "";
      for (let f = 0; f < a.length; ++f)
        i += String.fromCharCode(a[f]);
      o = btoa(i);
    } else
      throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
    if (e || (e = u.BLOCK_LITERAL), e !== u.QUOTE_DOUBLE) {
      const i = Math.max(r.options.lineWidth - r.indent.length, r.options.minContentWidth), f = Math.ceil(o.length / i), g = new Array(f);
      for (let l = 0, b = 0; l < f; ++l, b += i)
        g[l] = o.substr(b, i);
      o = g.join(e === u.BLOCK_LITERAL ? `
` : " ");
    }
    return d({ comment: t, type: e, value: o }, r, n, h);
  }
};
export {
  y as binary
};
