var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var _a, _b, _c, _d, _e;
import { _ as Logger, c as Objects } from "./button-Dj4BTre0.js";
import { St as isObject, a as loader, c as typeParsers$1, gt as isArray, o as read$1, wt as isString } from "./vega-loader.browser-3_z8GoFC.js";
var pkg = { version: "1.1.0" };
function formatValue(m2, U, G, K) {
  if (isArray(m2)) return `[${m2.map((m3) => U(isString(m3) ? m3 : stringify(m3, G))).join(", ")}]`;
  if (isObject(m2)) {
    let q = "", { title: J, image: Y, ...X } = m2;
    J && (q += `<h2>${U(J)}</h2>`), Y && (q += `<img src="${new URL(U(Y), K || location.href).href}">`);
    let Z = Object.keys(X);
    if (Z.length > 0) {
      q += "<table>";
      for (let m3 of Z) {
        let K2 = X[m3];
        K2 !== void 0 && (isObject(K2) && (K2 = stringify(K2, G)), q += `<tr><td class="key">${U(m3)}</td><td class="value">${U(K2)}</td></tr>`);
      }
      q += "</table>";
    }
    return q || "{}";
  }
  return U(m2);
}
function replacer(m2) {
  let U = [];
  return function(W, G) {
    return typeof G != "object" || !G ? G : (U.length = U.indexOf(this) + 1, U.length > m2 ? "[Object]" : U.indexOf(G) >= 0 ? "[Circular]" : (U.push(G), G));
  };
}
function stringify(m2, U) {
  return JSON.stringify(m2, replacer(U));
}
var defaultStyle = "#vg-tooltip-element {\n  visibility: hidden;\n  padding: 8px;\n  position: fixed;\n  z-index: 1000;\n  font-family: sans-serif;\n  font-size: 11px;\n  border-radius: 3px;\n  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);\n  white-space: pre-line;\n}\n#vg-tooltip-element.visible {\n  visibility: visible;\n}\n#vg-tooltip-element h2 {\n  margin-top: 0;\n  margin-bottom: 10px;\n  font-size: 13px;\n}\n#vg-tooltip-element table {\n  border-spacing: 0;\n}\n#vg-tooltip-element table tr {\n  border: none;\n}\n#vg-tooltip-element table tr td {\n  overflow: hidden;\n  text-overflow: ellipsis;\n  padding-top: 2px;\n  padding-bottom: 2px;\n  vertical-align: text-top;\n}\n#vg-tooltip-element table tr td.key {\n  color: #808080;\n  max-width: 150px;\n  text-align: right;\n  padding-right: 4px;\n}\n#vg-tooltip-element table tr td.value {\n  display: block;\n  max-width: 300px;\n  max-height: 7em;\n  text-align: left;\n}\n#vg-tooltip-element {\n  /* The default theme is the light theme. */\n  background-color: rgba(255, 255, 255, 0.95);\n  border: 1px solid #d9d9d9;\n  color: black;\n}\n#vg-tooltip-element.dark-theme {\n  background-color: rgba(32, 32, 32, 0.9);\n  border: 1px solid #f5f5f5;\n  color: white;\n}\n#vg-tooltip-element.dark-theme td.key {\n  color: #bfbfbf;\n}\n", EL_ID = "vg-tooltip-element", DEFAULT_OPTIONS = {
  offsetX: 10,
  offsetY: 10,
  id: EL_ID,
  styleId: "vega-tooltip-style",
  theme: "light",
  disableDefaultStyle: false,
  sanitize: escapeHTML,
  maxDepth: 2,
  formatTooltip: formatValue,
  baseURL: "",
  anchor: "cursor",
  position: [
    "top",
    "bottom",
    "left",
    "right",
    "top-left",
    "top-right",
    "bottom-left",
    "bottom-right"
  ]
};
function escapeHTML(m2) {
  return String(m2).replace(/&/g, "&amp;").replace(/</g, "&lt;");
}
function createDefaultStyle(m2) {
  if (!/^[A-Za-z]+[-:.\w]*$/.test(m2)) throw Error("Invalid HTML ID");
  return defaultStyle.toString().replaceAll(EL_ID, m2);
}
function calculatePositionRelativeToCursor(m2, U, { offsetX: W, offsetY: G }) {
  let K = getPositions({
    x1: m2.clientX,
    x2: m2.clientX,
    y1: m2.clientY,
    y2: m2.clientY
  }, U, W, G);
  for (let m3 of [
    "bottom-right",
    "bottom-left",
    "top-right",
    "top-left"
  ]) if (tooltipIsInViewport(K[m3], U)) return K[m3];
  return K["top-left"];
}
function calculatePositionRelativeToMark(m2, U, W, G, K) {
  let { position: q, offsetX: J, offsetY: Y } = K, X = m2._el.getBoundingClientRect(), Z = m2._origin, Q = getPositions(getMarkBounds(X, Z, W), G, J, Y), $ = Array.isArray(q) ? q : [q];
  for (let m3 of $) if (tooltipIsInViewport(Q[m3], G) && !mouseIsOnTooltip(U, Q[m3], G)) return Q[m3];
  return calculatePositionRelativeToCursor(U, G, K);
}
function getMarkBounds(m2, U, W) {
  let G = W.isVoronoi ? W.datum.bounds : W.bounds, K = m2.left + U[0] + G.x1, q = m2.top + U[1] + G.y1, J = W;
  for (; J.mark.group; ) J = J.mark.group, K += J.x ?? 0, q += J.y ?? 0;
  let Y = G.x2 - G.x1, X = G.y2 - G.y1;
  return {
    x1: K,
    x2: K + Y,
    y1: q,
    y2: q + X
  };
}
function getPositions(m2, U, W, G) {
  let K = (m2.x1 + m2.x2) / 2, q = (m2.y1 + m2.y2) / 2, J = m2.x1 - U.width - W, Y = K - U.width / 2, X = m2.x2 + W, Z = m2.y1 - U.height - G, Q = q - U.height / 2, $ = m2.y2 + G;
  return {
    top: {
      x: Y,
      y: Z
    },
    bottom: {
      x: Y,
      y: $
    },
    left: {
      x: J,
      y: Q
    },
    right: {
      x: X,
      y: Q
    },
    "top-left": {
      x: J,
      y: Z
    },
    "top-right": {
      x: X,
      y: Z
    },
    "bottom-left": {
      x: J,
      y: $
    },
    "bottom-right": {
      x: X,
      y: $
    }
  };
}
function tooltipIsInViewport(m2, U) {
  return m2.x >= 0 && m2.y >= 0 && m2.x + U.width <= window.innerWidth && m2.y + U.height <= window.innerHeight;
}
function mouseIsOnTooltip(m2, U, W) {
  return m2.clientX >= U.x && m2.clientX <= U.x + W.width && m2.clientY >= U.y && m2.clientY <= U.y + W.height;
}
var Handler = class {
  constructor(m2) {
    __publicField(this, "call");
    __publicField(this, "options");
    __publicField(this, "el");
    this.options = {
      ...DEFAULT_OPTIONS,
      ...m2
    };
    let U = this.options.id;
    if (this.el = null, this.call = this.tooltipHandler.bind(this), !this.options.disableDefaultStyle && !document.getElementById(this.options.styleId)) {
      let m3 = document.createElement("style");
      m3.setAttribute("id", this.options.styleId), m3.innerHTML = createDefaultStyle(U);
      let W = document.head;
      W.childNodes.length > 0 ? W.insertBefore(m3, W.childNodes[0]) : W.appendChild(m3);
    }
  }
  tooltipHandler(m2, U, W, G) {
    if (this.el = document.getElementById(this.options.id), this.el || (this.el = document.createElement("div"), this.el.setAttribute("id", this.options.id), this.el.classList.add("vg-tooltip"), (document.fullscreenElement ?? document.body).appendChild(this.el)), G == null || G === "") {
      this.el.classList.remove("visible", `${this.options.theme}-theme`);
      return;
    }
    this.el.innerHTML = this.options.formatTooltip(G, this.options.sanitize, this.options.maxDepth, this.options.baseURL), this.el.classList.add("visible", `${this.options.theme}-theme`);
    let { x: K, y: q } = this.options.anchor === "mark" ? calculatePositionRelativeToMark(m2, U, W, this.el.getBoundingClientRect(), this.options) : calculatePositionRelativeToCursor(U, this.el.getBoundingClientRect(), this.options);
    this.el.style.top = `${q}px`, this.el.style.left = `${K}px`;
  }
};
pkg.version;
const tooltipHandler = new Handler();
function getContainerWidth(m2) {
  if (typeof m2 == "object" && m2) {
    if ("width" in m2) return m2.width;
    if ("spec" in m2) return getContainerWidth(m2.spec);
  }
}
function getVegaFieldTypes(m2) {
  return !m2 || Object.keys(m2).length === 0 ? "auto" : Objects.mapValues(m2, (m3) => m3 === "date" || m3 === "time" ? "string" : m3 === "datetime" ? "date" : m3);
}
const MAGIC = Uint8Array.of(65, 82, 82, 79, 87, 49), Version = {
  V1: 0,
  V2: 1,
  V3: 2,
  V4: 3,
  V5: 4
}, MessageHeader = {
  NONE: 0,
  Schema: 1,
  DictionaryBatch: 2,
  RecordBatch: 3,
  Tensor: 4,
  SparseTensor: 5
}, Type = {
  Dictionary: -1,
  NONE: 0,
  Null: 1,
  Int: 2,
  Float: 3,
  Binary: 4,
  Utf8: 5,
  Bool: 6,
  Decimal: 7,
  Date: 8,
  Time: 9,
  Timestamp: 10,
  Interval: 11,
  List: 12,
  Struct: 13,
  Union: 14,
  FixedSizeBinary: 15,
  FixedSizeList: 16,
  Map: 17,
  Duration: 18,
  LargeBinary: 19,
  LargeUtf8: 20,
  LargeList: 21,
  RunEndEncoded: 22,
  BinaryView: 23,
  Utf8View: 24,
  ListView: 25,
  LargeListView: 26
}, Precision = {
  HALF: 0,
  SINGLE: 1,
  DOUBLE: 2
}, DateUnit = {
  DAY: 0,
  MILLISECOND: 1
}, TimeUnit = {
  SECOND: 0,
  MILLISECOND: 1,
  MICROSECOND: 2,
  NANOSECOND: 3
}, IntervalUnit = {
  YEAR_MONTH: 0,
  DAY_TIME: 1,
  MONTH_DAY_NANO: 2
}, UnionMode = {
  Sparse: 0,
  Dense: 1
}, uint8Array = Uint8Array, uint16Array = Uint16Array, uint32Array = Uint32Array, uint64Array = BigUint64Array, int8Array = Int8Array, int16Array = Int16Array, int32Array = Int32Array, int64Array = BigInt64Array, float32Array = Float32Array, float64Array = Float64Array;
function intArrayType(m2, U) {
  let W = Math.log2(m2) - 3;
  return (U ? [
    int8Array,
    int16Array,
    int32Array,
    int64Array
  ] : [
    uint8Array,
    uint16Array,
    uint32Array,
    uint64Array
  ])[W];
}
Object.getPrototypeOf(Int8Array);
function bisect(m2, U) {
  let W = 0, G = m2.length;
  if (G <= 2147483648) do {
    let K = W + G >>> 1;
    m2[K] <= U ? W = K + 1 : G = K;
  } while (W < G);
  else do {
    let K = Math.trunc((W + G) / 2);
    m2[K] <= U ? W = K + 1 : G = K;
  } while (W < G);
  return W;
}
function check(m2, U, W) {
  if (U(m2)) return m2;
  throw Error(W(m2));
}
function checkOneOf(m2, U, W) {
  return U = Array.isArray(U) ? U : Object.values(U), check(m2, (m3) => U.includes(m3), W ?? (() => `${m2} must be one of ${U}`));
}
function keyFor(m2, U) {
  for (let [W, G] of Object.entries(m2)) if (G === U) return W;
  return "<Unknown>";
}
const invalidDataType = (m2) => `Unsupported data type: "${keyFor(Type, m2)}" (id ${m2})`, field = (m2, U, W = true, G = null) => ({
  name: m2,
  type: U,
  nullable: W,
  metadata: G
});
function isField(m2) {
  return Object.hasOwn(m2, "name") && isDataType(m2.type);
}
function isDataType(m2) {
  return typeof (m2 == null ? void 0 : m2.typeId) == "number";
}
function asField(m2, U = "", W = true) {
  return isField(m2) ? m2 : field(U, check(m2, isDataType, () => "Data type expected."), W);
}
const dictionary = (m2, U, W = false, G = -1) => ({
  typeId: Type.Dictionary,
  id: G,
  dictionary: m2,
  indices: U || int32(),
  ordered: W
}), int = (m2 = 32, U = true) => ({
  typeId: Type.Int,
  bitWidth: checkOneOf(m2, [
    8,
    16,
    32,
    64
  ]),
  signed: U,
  values: intArrayType(m2, U)
}), int32 = () => int(32), float = (m2 = 2) => ({
  typeId: Type.Float,
  precision: checkOneOf(m2, Precision),
  values: [
    uint16Array,
    float32Array,
    float64Array
  ][m2]
}), binary = () => ({
  typeId: Type.Binary,
  offsets: int32Array
}), utf8 = () => ({
  typeId: Type.Utf8,
  offsets: int32Array
}), decimal = (m2, U, W = 128) => ({
  typeId: Type.Decimal,
  precision: m2,
  scale: U,
  bitWidth: checkOneOf(W, [128, 256]),
  values: uint64Array
}), date = (m2) => ({
  typeId: Type.Date,
  unit: checkOneOf(m2, DateUnit),
  values: m2 === DateUnit.DAY ? int32Array : int64Array
}), time = (m2 = TimeUnit.MILLISECOND, U = 32) => ({
  typeId: Type.Time,
  unit: checkOneOf(m2, TimeUnit),
  bitWidth: checkOneOf(U, [32, 64]),
  values: U === 32 ? int32Array : int64Array
}), timestamp = (m2 = TimeUnit.MILLISECOND, U = null) => ({
  typeId: Type.Timestamp,
  unit: checkOneOf(m2, TimeUnit),
  timezone: U,
  values: int64Array
}), interval = (m2 = IntervalUnit.MONTH_DAY_NANO) => ({
  typeId: Type.Interval,
  unit: checkOneOf(m2, IntervalUnit),
  values: m2 === IntervalUnit.MONTH_DAY_NANO ? void 0 : int32Array
}), list = (m2) => ({
  typeId: Type.List,
  children: [asField(m2)],
  offsets: int32Array
}), struct = (m2) => ({
  typeId: Type.Struct,
  children: Array.isArray(m2) && isField(m2[0]) ? m2 : Object.entries(m2).map(([m3, U]) => field(m3, U))
}), union = (m2, U, W, G) => (W ?? (W = U.map((m3, U2) => U2)), {
  typeId: Type.Union,
  mode: checkOneOf(m2, UnionMode),
  typeIds: W,
  typeMap: W.reduce((m3, U2, W2) => (m3[U2] = W2, m3), {}),
  children: U.map((m3, U2) => asField(m3, `_${U2}`)),
  typeIdForValue: G,
  offsets: int32Array
}), fixedSizeBinary = (m2) => ({
  typeId: Type.FixedSizeBinary,
  stride: m2
}), fixedSizeList = (m2, U) => ({
  typeId: Type.FixedSizeList,
  stride: U,
  children: [asField(m2)]
}), mapType = (m2, U) => ({
  typeId: Type.Map,
  keysSorted: m2,
  children: [U],
  offsets: int32Array
}), duration = (m2 = TimeUnit.MILLISECOND) => ({
  typeId: Type.Duration,
  unit: checkOneOf(m2, TimeUnit),
  values: int64Array
}), largeBinary = () => ({
  typeId: Type.LargeBinary,
  offsets: int64Array
}), largeUtf8 = () => ({
  typeId: Type.LargeUtf8,
  offsets: int64Array
}), largeList = (m2) => ({
  typeId: Type.LargeList,
  children: [asField(m2)],
  offsets: int64Array
}), runEndEncoded = (m2, U) => ({
  typeId: Type.RunEndEncoded,
  children: [check(asField(m2, "run_ends"), (m3) => m3.type.typeId === Type.Int, () => "Run-ends must have an integer type."), asField(U, "values")]
}), listView = (m2) => ({
  typeId: Type.ListView,
  children: [asField(m2, "value")],
  offsets: int32Array
}), largeListView = (m2) => ({
  typeId: Type.LargeListView,
  children: [asField(m2, "value")],
  offsets: int64Array
});
var buf = new float64Array(2).buffer;
new int64Array(buf), new uint32Array(buf), new int32Array(buf), new uint8Array(buf);
function toNumber(m2) {
  if (m2 > 2 ** 53 - 1 || m2 < -(2 ** 53 - 1)) throw Error(`BigInt exceeds integer number representation: ${m2}`);
  return Number(m2);
}
function divide(m2, U) {
  return Number(m2 / U) + Number(m2 % U) / Number(U);
}
var asUint64 = (m2) => BigInt.asUintN(64, m2);
function fromDecimal128(m2, U) {
  let W = U << 1, G;
  return BigInt.asIntN(64, m2[W + 1]) < 0 ? (G = asUint64(~m2[W]) | asUint64(~m2[W + 1]) << 64n, G = -(G + 1n)) : G = m2[W] | m2[W + 1] << 64n, G;
}
function fromDecimal256(m2, U) {
  let W = U << 2, G;
  return BigInt.asIntN(64, m2[W + 3]) < 0 ? (G = asUint64(~m2[W]) | asUint64(~m2[W + 1]) << 64n | asUint64(~m2[W + 2]) << 128n | asUint64(~m2[W + 3]) << 192n, G = -(G + 1n)) : G = m2[W] | m2[W + 1] << 64n | m2[W + 2] << 128n | m2[W + 3] << 192n, G;
}
var textDecoder = new TextDecoder("utf-8");
new TextEncoder();
function decodeUtf8(m2) {
  return textDecoder.decode(m2);
}
function decodeBit(m2, U) {
  return (m2[U >> 3] & 1 << U % 8) != 0;
}
function readObject(m2, U) {
  let W = U + readInt32(m2, U), G = W - readInt32(m2, W), K = readInt16(m2, G);
  return (U2, q, J = null) => {
    if (U2 < K) {
      let K2 = readInt16(m2, G + U2);
      if (K2) return q(m2, W + K2);
    }
    return J;
  };
}
function readOffset(m2, U) {
  return U;
}
function readBoolean(m2, U) {
  return !!readInt8(m2, U);
}
function readInt8(m2, U) {
  return readUint8(m2, U) << 24 >> 24;
}
function readUint8(m2, U) {
  return m2[U];
}
function readInt16(m2, U) {
  return readUint16(m2, U) << 16 >> 16;
}
function readUint16(m2, U) {
  return m2[U] | m2[U + 1] << 8;
}
function readInt32(m2, U) {
  return m2[U] | m2[U + 1] << 8 | m2[U + 2] << 16 | m2[U + 3] << 24;
}
function readUint32(m2, U) {
  return readInt32(m2, U) >>> 0;
}
function readInt64(m2, U) {
  return toNumber(BigInt.asIntN(64, BigInt(readUint32(m2, U)) + (BigInt(readUint32(m2, U + 4)) << 32n)));
}
function readString(m2, U) {
  let W = U + readInt32(m2, U), G = readInt32(m2, W);
  return W += 4, decodeUtf8(m2.subarray(W, W + G));
}
function readVector(m2, U, W, G) {
  if (!U) return [];
  let K = U + readInt32(m2, U);
  return Array.from({ length: readInt32(m2, K) }, (U2, q) => G(m2, K + 4 + q * W));
}
const RowIndex = /* @__PURE__ */ Symbol("rowIndex");
function proxyFactory(m2, U) {
  class W {
    constructor(m3) {
      this[RowIndex] = m3;
    }
    toJSON() {
      return structObject(m2, U, this[RowIndex]);
    }
  }
  let G = W.prototype;
  for (let W2 = 0; W2 < m2.length; ++W2) {
    if (Object.hasOwn(G, m2[W2])) continue;
    let K = U[W2];
    Object.defineProperty(G, m2[W2], {
      get() {
        return K.at(this[RowIndex]);
      },
      enumerable: true
    });
  }
  return (m3) => new W(m3);
}
function objectFactory(m2, U) {
  return (W) => structObject(m2, U, W);
}
function structObject(m2, U, W) {
  let G = {};
  for (let K = 0; K < m2.length; ++K) G[m2[K]] = U[K].at(W);
  return G;
}
function isDirectBatch(m2) {
  return m2 instanceof DirectBatch;
}
var Batch = (_a = class {
  constructor({ length: m2, nullCount: U, type: W, validity: G, values: K, offsets: q, sizes: J, children: Y }) {
    this.length = m2, this.nullCount = U, this.type = W, this.validity = G, this.values = K, this.offsets = q, this.sizes = J, this.children = Y, (!U || !this.validity) && (this.at = (m3) => this.value(m3));
  }
  get [Symbol.toStringTag]() {
    return "Batch";
  }
  at(m2) {
    return this.isValid(m2) ? this.value(m2) : null;
  }
  isValid(m2) {
    return decodeBit(this.validity, m2);
  }
  value(m2) {
    return this.values[m2];
  }
  slice(m2, U) {
    let W = U - m2, G = Array(W);
    for (let U2 = 0; U2 < W; ++U2) G[U2] = this.at(m2 + U2);
    return G;
  }
  *[Symbol.iterator]() {
    for (let m2 = 0; m2 < this.length; ++m2) yield this.at(m2);
  }
}, __publicField(_a, "ArrayType", null), _a), DirectBatch = class extends Batch {
  constructor(m2) {
    super(m2);
    let { length: U, values: W } = this;
    this.values = W.subarray(0, U);
  }
  slice(m2, U) {
    return this.nullCount ? super.slice(m2, U) : this.values.subarray(m2, U);
  }
  [Symbol.iterator]() {
    return this.nullCount ? super[Symbol.iterator]() : this.values[Symbol.iterator]();
  }
}, NumberBatch = (_b = class extends Batch {
}, __publicField(_b, "ArrayType", float64Array), _b), ArrayBatch = (_c = class extends Batch {
}, __publicField(_c, "ArrayType", Array), _c), NullBatch = class extends ArrayBatch {
  value(m2) {
    return null;
  }
}, Int64Batch = class extends NumberBatch {
  value(m2) {
    return toNumber(this.values[m2]);
  }
}, Float16Batch = class extends NumberBatch {
  value(m2) {
    let U = this.values[m2], W = (U & 31744) >> 10, G = (U & 1023) / 1024, K = (-1) ** ((U & 32768) >> 15);
    switch (W) {
      case 31:
        return K * (G ? NaN : Infinity);
      case 0:
        return K * (G ? 6103515625e-14 * G : 0);
    }
    return K * 2 ** (W - 15) * (1 + G);
  }
}, BoolBatch = class extends ArrayBatch {
  value(m2) {
    return decodeBit(this.values, m2);
  }
}, DecimalBatch = class extends Batch {
  constructor(m2) {
    super(m2);
    let { bitWidth: U, scale: W } = this.type;
    this.decimal = U === 128 ? fromDecimal128 : fromDecimal256, this.scale = 10n ** BigInt(W);
  }
}, DecimalNumberBatch = (_d = class extends DecimalBatch {
  value(m2) {
    return divide(this.decimal(this.values, m2), this.scale);
  }
}, __publicField(_d, "ArrayType", float64Array), _d), DecimalBigIntBatch = (_e = class extends DecimalBatch {
  value(m2) {
    return this.decimal(this.values, m2);
  }
}, __publicField(_e, "ArrayType", Array), _e), DateBatch = class extends ArrayBatch {
  constructor(m2) {
    super(m2), this.source = m2;
  }
  value(m2) {
    return new Date(this.source.value(m2));
  }
}, DateDayBatch = class extends NumberBatch {
  value(m2) {
    return 864e5 * this.values[m2];
  }
};
const DateDayMillisecondBatch = Int64Batch;
var TimestampSecondBatch = class extends Int64Batch {
  value(m2) {
    return super.value(m2) * 1e3;
  }
};
const TimestampMillisecondBatch = Int64Batch;
var TimestampMicrosecondBatch = class extends Int64Batch {
  value(m2) {
    return divide(this.values[m2], 1000n);
  }
}, TimestampNanosecondBatch = class extends Int64Batch {
  value(m2) {
    return divide(this.values[m2], 1000000n);
  }
}, IntervalDayTimeBatch = class extends ArrayBatch {
  value(m2) {
    return this.values.subarray(m2 << 1, m2 + 1 << 1);
  }
}, IntervalMonthDayNanoBatch = class extends ArrayBatch {
  value(m2) {
    let U = this.values, W = m2 << 4;
    return Float64Array.of(readInt32(U, W), readInt32(U, W + 4), readInt64(U, W + 8));
  }
}, offset32 = ({ values: m2, offsets: U }, W) => m2.subarray(U[W], U[W + 1]), offset64 = ({ values: m2, offsets: U }, W) => m2.subarray(toNumber(U[W]), toNumber(U[W + 1])), BinaryBatch = class extends ArrayBatch {
  value(m2) {
    return offset32(this, m2);
  }
}, LargeBinaryBatch = class extends ArrayBatch {
  value(m2) {
    return offset64(this, m2);
  }
}, Utf8Batch = class extends ArrayBatch {
  value(m2) {
    return decodeUtf8(offset32(this, m2));
  }
}, LargeUtf8Batch = class extends ArrayBatch {
  value(m2) {
    return decodeUtf8(offset64(this, m2));
  }
}, ListBatch = class extends ArrayBatch {
  value(m2) {
    let U = this.offsets;
    return this.children[0].slice(U[m2], U[m2 + 1]);
  }
}, LargeListBatch = class extends ArrayBatch {
  value(m2) {
    let U = this.offsets;
    return this.children[0].slice(toNumber(U[m2]), toNumber(U[m2 + 1]));
  }
}, ListViewBatch = class extends ArrayBatch {
  value(m2) {
    let U = this.offsets[m2], W = U + this.sizes[m2];
    return this.children[0].slice(U, W);
  }
}, LargeListViewBatch = class extends ArrayBatch {
  value(m2) {
    let U = this.offsets[m2], W = U + this.sizes[m2];
    return this.children[0].slice(toNumber(U), toNumber(W));
  }
}, FixedBatch = class extends ArrayBatch {
  constructor(m2) {
    super(m2), this.stride = this.type.stride;
  }
}, FixedBinaryBatch = class extends FixedBatch {
  value(m2) {
    let { stride: U, values: W } = this;
    return W.subarray(m2 * U, (m2 + 1) * U);
  }
}, FixedListBatch = class extends FixedBatch {
  value(m2) {
    let { children: U, stride: W } = this;
    return U[0].slice(m2 * W, (m2 + 1) * W);
  }
};
function pairs({ children: m2, offsets: U }, W) {
  let [G, K] = m2[0].children, q = U[W], J = U[W + 1], Y = [];
  for (let m3 = q; m3 < J; ++m3) Y.push([G.at(m3), K.at(m3)]);
  return Y;
}
var MapEntryBatch = class extends ArrayBatch {
  value(m2) {
    return pairs(this, m2);
  }
}, MapBatch = class extends ArrayBatch {
  value(m2) {
    return new Map(pairs(this, m2));
  }
}, SparseUnionBatch = class extends ArrayBatch {
  constructor({ typeIds: m2, ...U }) {
    super(U), this.typeIds = m2, this.typeMap = this.type.typeMap;
  }
  value(m2, U = m2) {
    let { typeIds: W, children: G, typeMap: K } = this;
    return G[K[W[m2]]].at(U);
  }
}, DenseUnionBatch = class extends SparseUnionBatch {
  value(m2) {
    return super.value(m2, this.offsets[m2]);
  }
}, StructBatch = class extends ArrayBatch {
  constructor(m2, U = objectFactory) {
    super(m2), this.names = this.type.children.map((m3) => m3.name), this.factory = U(this.names, this.children);
  }
  value(m2) {
    return this.factory(m2);
  }
}, StructProxyBatch = class extends StructBatch {
  constructor(m2) {
    super(m2, proxyFactory);
  }
}, RunEndEncodedBatch = class extends ArrayBatch {
  value(m2) {
    let [{ values: U }, W] = this.children;
    return W.at(bisect(U, m2));
  }
}, DictionaryBatch = class extends ArrayBatch {
  setDictionary(m2) {
    return this.dictionary = m2, this.cache = m2.cache(), this;
  }
  value(m2) {
    return this.cache[this.key(m2)];
  }
  key(m2) {
    return this.values[m2];
  }
}, ViewBatch = class extends ArrayBatch {
  constructor({ data: m2, ...U }) {
    super(U), this.data = m2;
  }
  view(m2) {
    let { values: U, data: W } = this, G = m2 << 4, K = G + 4, q = U, J = readInt32(q, G);
    return J > 12 && (K = readInt32(q, G + 12), q = W[readInt32(q, G + 8)]), q.subarray(K, K + J);
  }
}, BinaryViewBatch = class extends ViewBatch {
  value(m2) {
    return this.view(m2);
  }
}, Utf8ViewBatch = class extends ViewBatch {
  value(m2) {
    return decodeUtf8(this.view(m2));
  }
};
function columnBuilder(m2) {
  let U = [];
  return {
    add(m3) {
      return U.push(m3), this;
    },
    clear: () => U = [],
    done: () => new Column(U, m2)
  };
}
var Column = class {
  constructor(m2, U = ((_f) => (_f = m2[0]) == null ? void 0 : _f.type)()) {
    this.type = U, this.length = m2.reduce((m3, U2) => m3 + U2.length, 0), this.nullCount = m2.reduce((m3, U2) => m3 + U2.nullCount, 0), this.data = m2;
    let W = m2.length, G = new Int32Array(W + 1);
    if (W === 1) {
      let [U2] = m2;
      G[1] = U2.length, this.at = (m3) => U2.at(m3);
    } else for (let U2 = 0, K = 0; U2 < W; ++U2) G[U2 + 1] = K += m2[U2].length;
    this.offsets = G;
  }
  get [Symbol.toStringTag]() {
    return "Column";
  }
  [Symbol.iterator]() {
    let m2 = this.data;
    return m2.length === 1 ? m2[0][Symbol.iterator]() : batchedIterator(m2);
  }
  at(m2) {
    var _a2;
    let { data: U, offsets: W } = this, G = bisect(W, m2) - 1;
    return (_a2 = U[G]) == null ? void 0 : _a2.at(m2 - W[G]);
  }
  get(m2) {
    return this.at(m2);
  }
  toArray() {
    let { length: m2, nullCount: U, data: W } = this, G = !U && isDirectBatch(W[0]), K = W.length;
    if (G && K === 1) return W[0].values;
    let q = new (!K || U > 0 ? Array : W[0].constructor.ArrayType ?? W[0].values.constructor)(m2);
    return G ? copyArray(q, W) : extractArray(q, W);
  }
  cache() {
    return this._cache ?? (this._cache = this.toArray());
  }
};
function* batchedIterator(m2) {
  for (let U = 0; U < m2.length; ++U) {
    let W = m2[U][Symbol.iterator]();
    for (let m3 = W.next(); !m3.done; m3 = W.next()) yield m3.value;
  }
}
function copyArray(m2, U) {
  for (let W = 0, G = 0; W < U.length; ++W) {
    let { values: K } = U[W];
    m2.set(K, G), G += K.length;
  }
  return m2;
}
function extractArray(m2, U) {
  let W = -1;
  for (let G = 0; G < U.length; ++G) {
    let K = U[G];
    for (let U2 = 0; U2 < K.length; ++U2) m2[++W] = K.at(U2);
  }
  return m2;
}
var Table = class m {
  constructor(m2, U, W = false) {
    let G = m2.fields.map((m3) => m3.name);
    this.schema = m2, this.names = G, this.children = U, this.factory = W ? proxyFactory : objectFactory;
    let K = [];
    this.getFactory = (m3) => K[m3] ?? (K[m3] = this.factory(G, U.map((U2) => U2.data[m3])));
  }
  get [Symbol.toStringTag]() {
    return "Table";
  }
  get numCols() {
    return this.names.length;
  }
  get numRows() {
    var _a2;
    return ((_a2 = this.children[0]) == null ? void 0 : _a2.length) ?? 0;
  }
  getChildAt(m2) {
    return this.children[m2];
  }
  getChild(m2) {
    let U = this.names.findIndex((U2) => U2 === m2);
    return U > -1 ? this.children[U] : void 0;
  }
  selectAt(U, W = []) {
    let { children: G, factory: K, schema: q } = this, { fields: J } = q;
    return new m({
      ...q,
      fields: U.map((m2, U2) => renameField(J[m2], W[U2]))
    }, U.map((m2) => G[m2]), K === proxyFactory);
  }
  select(m2, U) {
    let W = this.names, G = m2.map((m3) => W.indexOf(m3));
    return this.selectAt(G, U);
  }
  toColumns() {
    let { children: m2, names: U } = this, W = {};
    return U.forEach((U2, G) => {
      var _a2;
      return W[U2] = ((_a2 = m2[G]) == null ? void 0 : _a2.toArray()) ?? [];
    }), W;
  }
  toArray() {
    var _a2;
    let { children: m2, getFactory: U, numRows: W } = this, G = ((_a2 = m2[0]) == null ? void 0 : _a2.data) ?? [], K = Array(W);
    for (let m3 = 0, W2 = -1; m3 < G.length; ++m3) {
      let q = U(m3);
      for (let U2 = 0; U2 < G[m3].length; ++U2) K[++W2] = q(U2);
    }
    return K;
  }
  *[Symbol.iterator]() {
    var _a2;
    let { children: m2, getFactory: U } = this, W = ((_a2 = m2[0]) == null ? void 0 : _a2.data) ?? [];
    for (let m3 = 0; m3 < W.length; ++m3) {
      let G = U(m3);
      for (let U2 = 0; U2 < W[m3].length; ++U2) yield G(U2);
    }
  }
  at(m2) {
    let { children: U, getFactory: W, numRows: G } = this;
    if (m2 < 0 || m2 >= G) return null;
    let [{ offsets: K }] = U, q = bisect(K, m2) - 1;
    return W(q)(m2 - K[q]);
  }
  get(m2) {
    return this.at(m2);
  }
};
function renameField(m2, U) {
  return U != null && U !== m2.name ? {
    ...m2,
    name: U
  } : m2;
}
function batchType(m2, U = {}) {
  let { typeId: W, bitWidth: G, precision: K, unit: q } = m2, { useBigInt: J, useDate: Y, useDecimalBigInt: X, useMap: Z, useProxy: Q } = U;
  switch (W) {
    case Type.Null:
      return NullBatch;
    case Type.Bool:
      return BoolBatch;
    case Type.Int:
    case Type.Time:
    case Type.Duration:
      return J || G < 64 ? DirectBatch : Int64Batch;
    case Type.Float:
      return K ? DirectBatch : Float16Batch;
    case Type.Date:
      return wrap(q === DateUnit.DAY ? DateDayBatch : DateDayMillisecondBatch, Y && DateBatch);
    case Type.Timestamp:
      return wrap(q === TimeUnit.SECOND ? TimestampSecondBatch : q === TimeUnit.MILLISECOND ? TimestampMillisecondBatch : q === TimeUnit.MICROSECOND ? TimestampMicrosecondBatch : TimestampNanosecondBatch, Y && DateBatch);
    case Type.Decimal:
      return X ? DecimalBigIntBatch : DecimalNumberBatch;
    case Type.Interval:
      return q === IntervalUnit.DAY_TIME ? IntervalDayTimeBatch : q === IntervalUnit.YEAR_MONTH ? DirectBatch : IntervalMonthDayNanoBatch;
    case Type.FixedSizeBinary:
      return FixedBinaryBatch;
    case Type.Utf8:
      return Utf8Batch;
    case Type.LargeUtf8:
      return LargeUtf8Batch;
    case Type.Binary:
      return BinaryBatch;
    case Type.LargeBinary:
      return LargeBinaryBatch;
    case Type.BinaryView:
      return BinaryViewBatch;
    case Type.Utf8View:
      return Utf8ViewBatch;
    case Type.List:
      return ListBatch;
    case Type.LargeList:
      return LargeListBatch;
    case Type.Map:
      return Z ? MapBatch : MapEntryBatch;
    case Type.ListView:
      return ListViewBatch;
    case Type.LargeListView:
      return LargeListViewBatch;
    case Type.FixedSizeList:
      return FixedListBatch;
    case Type.Struct:
      return Q ? StructProxyBatch : StructBatch;
    case Type.RunEndEncoded:
      return RunEndEncodedBatch;
    case Type.Dictionary:
      return DictionaryBatch;
    case Type.Union:
      return m2.mode ? DenseUnionBatch : SparseUnionBatch;
  }
  throw Error(invalidDataType(W));
}
function wrap(m2, U) {
  return U ? class extends U {
    constructor(U2) {
      super(new m2(U2));
    }
  } : m2;
}
function decodeBlock(m2, U) {
  return {
    offset: readInt64(m2, U),
    metadataLength: readInt32(m2, U + 8),
    bodyLength: readInt64(m2, U + 16)
  };
}
function decodeBlocks(m2, U) {
  return readVector(m2, U, 24, decodeBlock);
}
function decodeRecordBatch(m2, U, W) {
  let G = readObject(m2, U);
  if (G(10, readOffset, 0)) throw Error("Record batch compression not implemented");
  let K = W < Version.V4 ? 8 : 0;
  return {
    length: G(4, readInt64, 0),
    nodes: readVector(m2, G(6, readOffset), 16, (m3, U2) => ({
      length: readInt64(m3, U2),
      nullCount: readInt64(m3, U2 + 8)
    })),
    regions: readVector(m2, G(8, readOffset), 16 + K, (m3, U2) => ({
      offset: readInt64(m3, U2 + K),
      length: readInt64(m3, U2 + K + 8)
    })),
    variadic: readVector(m2, G(12, readOffset), 8, readInt64)
  };
}
function decodeDictionaryBatch(m2, U, W) {
  let G = readObject(m2, U);
  return {
    id: G(4, readInt64, 0),
    data: G(6, (m3, U2) => decodeRecordBatch(m3, U2, W)),
    isDelta: G(8, readBoolean, false)
  };
}
function decodeDataType(m2, U, W, G) {
  checkOneOf(W, Type, invalidDataType);
  let K = readObject(m2, U);
  switch (W) {
    case Type.Binary:
      return binary();
    case Type.Utf8:
      return utf8();
    case Type.LargeBinary:
      return largeBinary();
    case Type.LargeUtf8:
      return largeUtf8();
    case Type.List:
      return list(G[0]);
    case Type.ListView:
      return listView(G[0]);
    case Type.LargeList:
      return largeList(G[0]);
    case Type.LargeListView:
      return largeListView(G[0]);
    case Type.Struct:
      return struct(G);
    case Type.RunEndEncoded:
      return runEndEncoded(G[0], G[1]);
    case Type.Int:
      return int(K(4, readInt32, 0), K(6, readBoolean, false));
    case Type.Float:
      return float(K(4, readInt16, Precision.HALF));
    case Type.Decimal:
      return decimal(K(4, readInt32, 0), K(6, readInt32, 0), K(8, readInt32, 128));
    case Type.Date:
      return date(K(4, readInt16, DateUnit.MILLISECOND));
    case Type.Time:
      return time(K(4, readInt16, TimeUnit.MILLISECOND), K(6, readInt32, 32));
    case Type.Timestamp:
      return timestamp(K(4, readInt16, TimeUnit.SECOND), K(6, readString));
    case Type.Interval:
      return interval(K(4, readInt16, IntervalUnit.YEAR_MONTH));
    case Type.Duration:
      return duration(K(4, readInt16, TimeUnit.MILLISECOND));
    case Type.FixedSizeBinary:
      return fixedSizeBinary(K(4, readInt32, 0));
    case Type.FixedSizeList:
      return fixedSizeList(G[0], K(4, readInt32, 0));
    case Type.Map:
      return mapType(K(4, readBoolean, false), G[0]);
    case Type.Union:
      return union(K(4, readInt16, UnionMode.Sparse), G, readVector(m2, K(6, readOffset), 4, readInt32));
  }
  return { typeId: W };
}
function decodeMetadata(m2, U) {
  let W = readVector(m2, U, 4, (m3, U2) => {
    let W2 = readObject(m3, U2);
    return [W2(4, readString), W2(6, readString)];
  });
  return W.length ? new Map(W) : null;
}
function decodeSchema(m2, U, W) {
  let G = readObject(m2, U);
  return {
    version: W,
    endianness: G(4, readInt16, 0),
    fields: G(6, decodeSchemaFields, []),
    metadata: G(8, decodeMetadata)
  };
}
function decodeSchemaFields(m2, U) {
  return readVector(m2, U, 4, decodeField);
}
function decodeField(m2, U) {
  let W = readObject(m2, U), G = W(8, readUint8, Type.NONE), K = W(10, readOffset, 0), q = W(12, decodeDictionary), J = decodeDataType(m2, K, G, W(14, (m3, U2) => decodeFieldChildren(m3, U2)));
  return q && (q.dictionary = J, J = q), {
    name: W(4, readString),
    type: J,
    nullable: W(6, readBoolean, false),
    metadata: W(16, decodeMetadata)
  };
}
function decodeFieldChildren(m2, U) {
  let W = readVector(m2, U, 4, decodeField);
  return W.length ? W : null;
}
function decodeDictionary(m2, U) {
  if (!U) return null;
  let W = readObject(m2, U);
  return dictionary(null, W(6, decodeInt, int32()), W(8, readBoolean, false), W(4, readInt64, 0));
}
function decodeInt(m2, U) {
  return decodeDataType(m2, U, Type.Int);
}
var invalidMessageMetadata = (m2, U) => `Expected to read ${m2} metadata bytes, but only read ${U}.`, invalidMessageBodyLength = (m2, U) => `Expected to read ${m2} bytes for message body, but only read ${U}.`, invalidMessageType = (m2) => `Unsupported message type: ${m2} (${keyFor(MessageHeader, m2)})`;
function decodeMessage(m2, U) {
  let W = readInt32(m2, U) || 0;
  if (U += 4, W === -1 && (W = readInt32(m2, U) || 0, U += 4), W === 0) return null;
  let G = m2.subarray(U, U += W);
  if (G.byteLength < W) throw Error(invalidMessageMetadata(W, G.byteLength));
  let K = readObject(G, 0), q = K(4, readInt16, Version.V1), J = K(6, readUint8, MessageHeader.NONE), Y = K(8, readOffset, 0), X = K(10, readInt64, 0), Z;
  if (Y) {
    let W2 = J === MessageHeader.Schema ? decodeSchema : J === MessageHeader.DictionaryBatch ? decodeDictionaryBatch : J === MessageHeader.RecordBatch ? decodeRecordBatch : null;
    if (!W2) throw Error(invalidMessageType(J));
    if (Z = W2(G, Y, q), X > 0) {
      let W3 = m2.subarray(U, U += X);
      if (W3.byteLength < X) throw Error(invalidMessageBodyLength(X, W3.byteLength));
      Z.body = W3;
    }
  }
  return {
    version: q,
    type: J,
    index: U,
    content: Z
  };
}
function decodeIPC(m2) {
  let U = m2 instanceof ArrayBuffer ? new Uint8Array(m2) : m2;
  return U instanceof Uint8Array && isArrowFileFormat(U) ? decodeIPCFile(U) : decodeIPCStream(U);
}
function isArrowFileFormat(m2) {
  if (!m2 || m2.length < 4) return false;
  for (let U = 0; U < 6; ++U) if (MAGIC[U] !== m2[U]) return false;
  return true;
}
function decodeIPCStream(m2) {
  let U = [m2].flat(), W, G = [], K = [];
  for (let m3 of U) {
    if (!(m3 instanceof Uint8Array)) throw Error("IPC data batch was not a Uint8Array.");
    let U2 = 0;
    for (; ; ) {
      let q = decodeMessage(m3, U2);
      if (q === null) break;
      if (U2 = q.index, q.content) switch (q.type) {
        case MessageHeader.Schema:
          W || (W = q.content);
          break;
        case MessageHeader.RecordBatch:
          G.push(q.content);
          break;
        case MessageHeader.DictionaryBatch:
          K.push(q.content);
          break;
      }
    }
  }
  return {
    schema: W,
    dictionaries: K,
    records: G,
    metadata: null
  };
}
function decodeIPCFile(m2) {
  let U = m2.byteLength - (MAGIC.length + 4), W = readObject(m2, U - readInt32(m2, U)), G = W(4, readInt16, Version.V1), K = W(8, decodeBlocks, []), q = W(10, decodeBlocks, []);
  return {
    schema: W(6, (m3, U2) => decodeSchema(m3, U2, G)),
    dictionaries: K.map(({ offset: U2 }) => decodeMessage(m2, U2).content),
    records: q.map(({ offset: U2 }) => decodeMessage(m2, U2).content),
    metadata: W(12, decodeMetadata)
  };
}
function tableFromIPC(m2, U) {
  return createTable(decodeIPC(m2), U);
}
function createTable(m2, U = {}) {
  let { schema: W = { fields: [] }, dictionaries: G, records: K } = m2, { version: q, fields: J } = W, Y = /* @__PURE__ */ new Map(), X = contextGenerator(U, q, Y), Z = /* @__PURE__ */ new Map();
  visitSchemaFields(W, (m3) => {
    let U2 = m3.type;
    U2.typeId === Type.Dictionary && Z.set(U2.id, U2.dictionary);
  });
  let Q = /* @__PURE__ */ new Map();
  for (let m3 of G) {
    let { id: U2, data: W2, isDelta: G2, body: K2 } = m3, q2 = Z.get(U2), J2 = visit(q2, X({
      ...W2,
      body: K2
    }));
    if (Q.has(U2)) {
      let m4 = Q.get(U2);
      G2 || m4.clear(), m4.add(J2);
    } else {
      if (G2) throw Error("Delta update can not be first dictionary batch.");
      Q.set(U2, columnBuilder(q2).add(J2));
    }
  }
  Q.forEach((m3, U2) => Y.set(U2, m3.done()));
  let $ = J.map((m3) => columnBuilder(m3.type));
  for (let m3 of K) {
    let U2 = X(m3);
    J.forEach((m4, W2) => $[W2].add(visit(m4.type, U2)));
  }
  return new Table(W, $.map((m3) => m3.done()), U.useProxy);
}
function visitSchemaFields(m2, U) {
  m2.fields.forEach(function m3(W) {
    var _a2, _b2, _c2;
    U(W), (_b2 = (_a2 = W.type.dictionary) == null ? void 0 : _a2.children) == null ? void 0 : _b2.forEach(m3), (_c2 = W.type.children) == null ? void 0 : _c2.forEach(m3);
  });
}
function contextGenerator(m2, U, W) {
  let G = {
    version: U,
    options: m2,
    dictionary: (m3) => W.get(m3)
  };
  return (m3) => {
    let { length: U2, nodes: W2, regions: K, variadic: q, body: J } = m3, Y = -1, X = -1, Z = -1;
    return {
      ...G,
      length: U2,
      node: () => W2[++Y],
      buffer: (m4) => {
        let { length: U3, offset: W3 } = K[++X];
        return m4 ? new m4(J.buffer, J.byteOffset + W3, U3 / m4.BYTES_PER_ELEMENT) : J.subarray(W3, W3 + U3);
      },
      variadic: () => q[++Z],
      visit(m4) {
        return m4.map((m5) => visit(m5.type, this));
      }
    };
  };
}
function visit(m2, U) {
  let { typeId: W } = m2, { length: G, options: K, node: q, buffer: J, variadic: Y, version: X } = U, Z = batchType(m2, K);
  if (W === Type.Null) return new Z({
    length: G,
    nullCount: G,
    type: m2
  });
  let Q = {
    ...q(),
    type: m2
  };
  switch (W) {
    case Type.Bool:
    case Type.Int:
    case Type.Time:
    case Type.Duration:
    case Type.Float:
    case Type.Decimal:
    case Type.Date:
    case Type.Timestamp:
    case Type.Interval:
    case Type.FixedSizeBinary:
      return new Z({
        ...Q,
        validity: J(),
        values: J(m2.values)
      });
    case Type.Utf8:
    case Type.LargeUtf8:
    case Type.Binary:
    case Type.LargeBinary:
      return new Z({
        ...Q,
        validity: J(),
        offsets: J(m2.offsets),
        values: J()
      });
    case Type.BinaryView:
    case Type.Utf8View:
      return new Z({
        ...Q,
        validity: J(),
        values: J(),
        data: Array.from({ length: Y() }, () => J())
      });
    case Type.List:
    case Type.LargeList:
    case Type.Map:
      return new Z({
        ...Q,
        validity: J(),
        offsets: J(m2.offsets),
        children: U.visit(m2.children)
      });
    case Type.ListView:
    case Type.LargeListView:
      return new Z({
        ...Q,
        validity: J(),
        offsets: J(m2.offsets),
        sizes: J(m2.offsets),
        children: U.visit(m2.children)
      });
    case Type.FixedSizeList:
    case Type.Struct:
      return new Z({
        ...Q,
        validity: J(),
        children: U.visit(m2.children)
      });
    case Type.RunEndEncoded:
      return new Z({
        ...Q,
        children: U.visit(m2.children)
      });
    case Type.Dictionary: {
      let { id: W2, indices: G2 } = m2;
      return new Z({
        ...Q,
        validity: J(),
        values: J(G2.values)
      }).setDictionary(U.dictionary(W2));
    }
    case Type.Union:
      return X < Version.V5 && J(), new Z({
        ...Q,
        typeIds: J(int8Array),
        offsets: m2.mode === UnionMode.Sparse ? null : J(m2.offsets),
        children: U.visit(m2.children)
      });
    default:
      throw Error(invalidDataType(W));
  }
}
new Uint16Array(new Uint8Array([1, 0]).buffer)[0];
function batch(m2, U) {
  let W = /* @__PURE__ */ new Map();
  return (...G) => {
    let K = U(...G);
    if (W.has(K)) return W.get(K);
    let q = m2(...G).finally(() => {
      W.delete(K);
    });
    return W.set(K, q), q;
  };
}
function read(m2, U) {
  return read$1(m2, U);
}
function createLoader() {
  return loader();
}
const typeParsers = typeParsers$1;
function createBatchedLoader() {
  let m2 = withArrowSupport(createLoader()), U = (m3) => JSON.stringify(m3);
  return {
    load: batch(m2.load.bind(m2), U),
    sanitize: batch(m2.sanitize.bind(m2), U),
    http: batch(m2.http.bind(m2), U),
    file: batch(m2.file.bind(m2), U)
  };
}
function withArrowSupport(m2) {
  return {
    ...m2,
    async load(U, W) {
      return U.endsWith(".arrow") ? tableFromIPC(await batchedArrowLoader(U), { useProxy: false }).toArray() : m2.load(U, W);
    }
  };
}
const batchedArrowLoader = batch((m2) => fetch(m2).then((m3) => m3.arrayBuffer()), (m2) => m2);
var previousIntegerParser = typeParsers.integer, previousNumberParser = typeParsers.number, previousDateParser = typeParsers.date, previousBooleanParser = typeParsers.boolean, BIG_INT_MIDDLEWARE = () => (typeParsers.integer = (m2) => {
  if (m2 === "") return "";
  if (m2 === "-inf" || m2 === "inf") return m2;
  function U(m3) {
    let U2 = previousIntegerParser(m3);
    return Number.isNaN(U2) ? m3 : U2;
  }
  let W = Number.parseInt(m2, 10);
  if (Number.isNaN(W)) return m2;
  if (!(Math.abs(W) > 2 ** 53 - 1)) return U(m2);
  try {
    return BigInt(m2);
  } catch {
    return U(m2);
  }
}, typeParsers.number = (m2) => {
  if (m2 === "-inf" || m2 === "inf") return m2;
  let U = previousNumberParser(m2);
  return Number.isNaN(U) ? m2 : U;
}, () => {
  typeParsers.integer = previousIntegerParser, typeParsers.number = previousNumberParser;
}), DATE_MIDDLEWARE = () => (typeParsers.date = (U) => {
  if (U === "") return "";
  if (U == null) return null;
  if (!/^\d{4}-\d{2}-\d{2}(T[\d.:]+(Z|[+-]\d{2}:?\d{2})?)?$/.test(U)) return U;
  try {
    let m2 = new Date(U);
    return Number.isNaN(m2.getTime()) ? U : m2;
  } catch {
    return Logger.warn(`Failed to parse date: ${U}`), U;
  }
}, () => {
  typeParsers.date = previousDateParser;
});
typeParsers.boolean = (m2) => m2 === "True" ? true : m2 === "False" ? false : previousBooleanParser(m2);
const vegaLoader = createBatchedLoader();
async function vegaLoadData(m2, W, G = {}) {
  let { handleBigIntAndNumberLike: K = false, replacePeriod: q = false } = G;
  if (m2.endsWith(".arrow") || (W == null ? void 0 : W.type) === "arrow") return tableFromIPC(await batchedArrowLoader(m2), {
    useProxy: true,
    useDate: true,
    useBigInt: K
  }).toArray();
  let J = [DATE_MIDDLEWARE];
  K && J.push(BIG_INT_MIDDLEWARE);
  let Y = [];
  try {
    let G2 = await vegaLoader.load(m2);
    if (!W) {
      if (typeof G2 == "string") try {
        JSON.parse(G2), W = { type: "json" };
      } catch {
        W = {
          type: "csv",
          parse: "auto"
        };
      }
      typeof G2 == "object" && (W = { type: "json" });
    }
    let K2 = (W == null ? void 0 : W.type) === "csv";
    K2 && typeof G2 == "string" && (G2 = uniquifyColumnNames(G2)), K2 && typeof G2 == "string" && q && (G2 = replacePeriodsInColumnNames(G2));
    let X = (W == null ? void 0 : W.parse) || "auto";
    return typeof X == "object" && (X = Objects.mapValues(X, (m3) => m3 === "time" ? "string" : m3 === "datetime" ? "date" : m3)), Y = J.map((m3) => m3()), K2 ? read(G2, {
      ...W,
      parse: X
    }) : read(G2, W);
  } finally {
    Y.forEach((m3) => m3());
  }
}
function parseCsvData(m2, U = true) {
  let W = [DATE_MIDDLEWARE];
  U && W.push(BIG_INT_MIDDLEWARE);
  let G = W.map((m3) => m3()), K = read(m2, {
    type: "csv",
    parse: "auto"
  });
  return G.forEach((m3) => m3()), K;
}
function uniquifyColumnNames(m2) {
  return (m2 == null ? void 0 : m2.includes(",")) ? mapColumnNames(m2, (m3) => {
    let U = /* @__PURE__ */ new Set();
    return m3.map((m4) => {
      let W = getUniqueKey(m4, U);
      return U.add(W), W;
    });
  }) : m2;
}
function replacePeriodsInColumnNames(m2) {
  return (m2 == null ? void 0 : m2.includes(".")) ? mapColumnNames(m2, (m3) => m3.map((m4) => m4.replaceAll(".", "\u2024"))) : m2;
}
function mapColumnNames(m2, U) {
  let W = m2.split("\n");
  return W[0] = U(W[0].split(",")).join(","), W.join("\n");
}
var ZERO_WIDTH_SPACE = "\u200B";
function getUniqueKey(m2, U) {
  let W = m2, G = 1;
  for (; U.has(W); ) W = `${m2}${ZERO_WIDTH_SPACE.repeat(G)}`, G++;
  return W;
}
export {
  getContainerWidth as a,
  tableFromIPC as i,
  vegaLoadData as n,
  getVegaFieldTypes as o,
  createBatchedLoader as r,
  tooltipHandler as s,
  parseCsvData as t
};
