var q = Object.defineProperty;
var B = (e, t, o) => t in e ? q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o;
var j = (e, t, o) => B(e, typeof t != "symbol" ? t + "" : t, o);
function g(e, t, o) {
  return Math.min(Math.max(e, o), t);
}
class E extends Error {
  constructor(t) {
    super(`Failed to parse color: "${t}"`);
  }
}
var b = E;
function L(e) {
  if (typeof e != "string") throw new b(e);
  if (e.trim().toLowerCase() === "transparent") return [0, 0, 0, 0];
  let t = e.trim();
  t = D.test(e) ? M(e) : e;
  const o = R.exec(t);
  if (o) {
    const s = Array.from(o).slice(1);
    return [...s.slice(0, 3).map((i) => parseInt(w(i, 2), 16)), parseInt(w(s[3] || "f", 2), 16) / 255];
  }
  const r = A.exec(t);
  if (r) {
    const s = Array.from(r).slice(1);
    return [...s.slice(0, 3).map((i) => parseInt(i, 16)), parseInt(s[3] || "ff", 16) / 255];
  }
  const n = I.exec(t);
  if (n) {
    const s = Array.from(n).slice(1);
    return [...s.slice(0, 3).map((i) => parseInt(i, 10)), parseFloat(s[3] || "1")];
  }
  const a = P.exec(t);
  if (a) {
    const [s, i, l, _] = Array.from(a).slice(1).map(parseFloat);
    if (g(0, 100, i) !== i) throw new b(e);
    if (g(0, 100, l) !== l) throw new b(e);
    return [...H(s, i, l), Number.isNaN(_) ? 1 : _];
  }
  throw new b(e);
}
function S(e) {
  let t = 5381, o = e.length;
  for (; o; )
    t = t * 33 ^ e.charCodeAt(--o);
  return (t >>> 0) % 2341;
}
const C = (e) => parseInt(e.replace(/_/g, ""), 36), F = "1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((e, t) => {
  const o = C(t.substring(0, 3)), r = C(t.substring(3)).toString(16);
  let n = "";
  for (let a = 0; a < 6 - r.length; a++)
    n += "0";
  return e[o] = `${n}${r}`, e;
}, {});
function M(e) {
  const t = e.toLowerCase().trim(), o = F[S(t)];
  if (!o) throw new b(e);
  return `#${o}`;
}
const w = (e, t) => Array.from(Array(t)).map(() => e).join(""), R = new RegExp(`^#${w("([a-f0-9])", 3)}([a-f0-9])?$`, "i"), A = new RegExp(`^#${w("([a-f0-9]{2})", 3)}([a-f0-9]{2})?$`, "i"), I = new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${w(",\\s*(\\d+)\\s*", 2)}(?:,\\s*([\\d.]+))?\\s*\\)$`, "i"), P = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i, D = /^[a-z]+$/i, v = (e) => Math.round(e * 255), H = (e, t, o) => {
  let r = o / 100;
  if (t === 0)
    return [r, r, r].map(v);
  const n = (e % 360 + 360) % 360 / 60, a = (1 - Math.abs(2 * r - 1)) * (t / 100), s = a * (1 - Math.abs(n % 2 - 1));
  let i = 0, l = 0, _ = 0;
  n >= 0 && n < 1 ? (i = a, l = s) : n >= 1 && n < 2 ? (i = s, l = a) : n >= 2 && n < 3 ? (l = a, _ = s) : n >= 3 && n < 4 ? (l = s, _ = a) : n >= 4 && n < 5 ? (i = s, _ = a) : n >= 5 && n < 6 && (i = a, _ = s);
  const c = r - a / 2, d = i + c, h = l + c, p = _ + c;
  return [d, h, p].map(v);
};
function N(e, t, o, r) {
  return `rgba(${g(0, 255, e).toFixed()}, ${g(0, 255, t).toFixed()}, ${g(0, 255, o).toFixed()}, ${parseFloat(g(0, 1, r).toFixed(3))})`;
}
function O(e, t) {
  const [o, r, n, a] = L(e);
  return N(o, r, n, a - t);
}
class G {
  constructor(t) {
    j(this, "attrs");
    this.attrs = t;
  }
  get(t, o) {
    let r = null;
    return Object.keys(this.attrs).forEach((a) => {
      var i;
      const s = (i = window.Bokeh.Models) == null ? void 0 : i[a];
      s && t instanceof s && (r = a);
    }), r === null ? void 0 : (this.attrs[r] ?? {})[o] ?? void 0;
  }
}
function U(e) {
  const { backgroundColor: t, secondaryBackgroundColor: o, textColor: r, font: n } = e, a = O(r, 0.8);
  return new G({
    Plot: {
      background_fill_color: t,
      border_fill_color: t,
      outline_line_color: "transparent",
      outline_line_alpha: 0.25
    },
    Grid: {
      grid_line_color: a,
      grid_line_alpha: 0.5
    },
    Axis: {
      major_tick_line_alpha: 0,
      major_tick_line_color: r,
      minor_tick_line_alpha: 0,
      minor_tick_line_color: r,
      axis_line_alpha: 0,
      axis_line_color: r,
      major_label_text_color: r,
      major_label_text_font: n,
      major_label_text_font_size: "1em",
      axis_label_standoff: 10,
      axis_label_text_color: r,
      axis_label_text_font: n,
      axis_label_text_font_size: "1em",
      axis_label_text_font_style: "normal"
    },
    Legend: {
      spacing: 8,
      glyph_width: 15,
      label_standoff: 8,
      label_text_color: r,
      label_text_font: n,
      label_text_font_size: "1.025em",
      border_line_alpha: 0,
      background_fill_alpha: 0.25,
      background_fill_color: a
    },
    BaseColorBar: {
      title_text_color: r,
      title_text_font: n,
      title_text_font_size: "1.025em",
      title_text_font_style: "normal",
      major_label_text_color: r,
      major_label_text_font: n,
      major_label_text_font_size: "1.025em",
      background_fill_color: o,
      major_tick_line_alpha: 0,
      bar_line_alpha: 0
    },
    Title: {
      text_color: r,
      text_font: n,
      text_font_size: "1.15em"
    }
  });
}
const u = "../bokeh/";
function f(e) {
  try {
    return new URL(e, import.meta.url).href;
  } catch {
    return e;
  }
}
const y = /* @__PURE__ */ new Map();
let x = null;
function W(e) {
  return document.head.querySelector(`script[src="${e}"]`) || document.body.querySelector(
    `script[src="${e}"]`
  );
}
function $(e, t = 1e4) {
  var a;
  const o = y.get(e);
  if (o) return o;
  const r = W(e);
  if (r && ((a = r.dataset) == null ? void 0 : a.loaded) === "true") {
    const s = Promise.resolve();
    return y.set(e, s), s;
  }
  const n = new Promise((s, i) => {
    const l = r ?? document.createElement("script");
    r || (l.src = e, l.async = !0, l.crossOrigin = "anonymous", document.head.appendChild(l));
    let _ = !1;
    const c = () => {
      _ || (_ = !0, l.setAttribute("data-loaded", "true"), h(), s());
    }, d = () => {
      _ || (_ = !0, h(), i(new Error(`Failed to load script ${e}`)));
    }, h = () => {
      l.removeEventListener("load", c), l.removeEventListener("error", d), clearTimeout(p);
    };
    l.addEventListener("load", c), l.addEventListener("error", d);
    const p = setTimeout(() => d(), t);
    r && r.readyState === "complete" && setTimeout(c, 0);
  });
  return y.set(e, n), n;
}
async function J(e, t = 1e4) {
  if (!window.Bokeh)
    return x || (x = (async () => {
      await $(e, t), window.Bokeh || await new Promise((o, r) => {
        const n = Date.now(), a = () => {
          if (window.Bokeh) return o();
          if (Date.now() - n > t)
            return r(
              new Error("Bokeh global not available after core load")
            );
          setTimeout(a, 50);
        };
        a();
      });
    })(), x);
}
const m = {
  core: f(`${u}bokeh-3.9.0.min.js`),
  widgets: f(`${u}bokeh-widgets-3.9.0.min.js`),
  tables: f(`${u}bokeh-tables-3.9.0.min.js`),
  api: f(`${u}bokeh-api-3.9.0.min.js`),
  gl: f(`${u}bokeh-gl-3.9.0.min.js`),
  mathjax: f(`${u}bokeh-mathjax-3.9.0.min.js`)
}, K = [
  m.widgets,
  m.tables,
  m.api,
  m.gl,
  m.mathjax
], V = async () => {
  await J(m.core, 1e4), await Promise.all(K.map((e) => $(e, 1e4)));
}, Q = 400, X = 350, Y = () => {
  let e = null, t = null;
  return (o) => o !== e ? (e = o, t = JSON.parse(o), { data: t, hasChanged: !0 }) : { data: t, hasChanged: !1 };
}, Z = () => {
  let e = null, t = null;
  return (o, r) => {
    let n = !1;
    const a = JSON.stringify(r);
    if (o !== e || e === "streamlit" && t !== a) {
      e = o, t = a;
      const { use_theme: s } = window.Bokeh.require("core/properties");
      e === "streamlit" || !(e in window.Bokeh.Themes) ? (s(U(r)), n = !0) : (s(window.Bokeh.Themes[e]), n = !0);
    }
    return n;
  };
};
function ee(e, t, o) {
  const r = e.attributes.width ?? Q, n = e.attributes.height ?? X;
  let a = r, s = n;
  return t && (a = o.clientWidth, s = a / r * n), { width: a, height: s };
}
function te(e) {
  for (; e.lastChild; )
    e.lastChild.remove();
}
async function re(e, t = !1, o, r, n) {
  var s, i;
  const a = (i = (s = e == null ? void 0 : e.doc) == null ? void 0 : s.roots) == null ? void 0 : i[0];
  if (a) {
    const { width: l, height: _ } = ee(
      a,
      t,
      r
    );
    l > 0 && (a.attributes.width = l), _ > 0 && (a.attributes.height = _);
  }
  te(o), await window.Bokeh.embed.embed_item(e, n);
}
const oe = (e, t) => {
  const o = e.querySelector(`#${t}`);
  if (!o) {
    const r = document.createElement("div");
    return r.id = t, e.appendChild(r), r;
  }
  return o;
}, z = /* @__PURE__ */ new WeakMap(), ne = (e) => {
  let t = z.get(e);
  return t || (t = {
    initialized: !1,
    setChartTheme: Z(),
    getChartData: Y()
  }, z.set(e, t)), t;
}, k = (e, t) => {
  var r;
  return (r = getComputedStyle(t).getPropertyValue(e)) == null ? void 0 : r.trim();
}, se = async (e) => {
  const { parentElement: t, data: o, key: r } = e, {
    figure: n,
    bokeh_theme: a,
    use_container_width: s
  } = o, i = ne(t);
  i.initialized || (await V(), i.initialized = !0);
  const { setChartTheme: l, getChartData: _ } = i, c = t.querySelector(".stBokehContainer");
  if (!c)
    throw new Error("Container not found");
  const d = oe(c, r), { data: h, hasChanged: p } = _(n), T = l(a, {
    backgroundColor: k("--st-background-color", c),
    secondaryBackgroundColor: k(
      "--st-secondary-background-color",
      c
    ),
    textColor: k("--st-text-color", c),
    font: k("--st-font", c)
  });
  return (p || T) && await re(h, s, d, c, r), () => {
    z.delete(t);
  };
};
export {
  se as default,
  Y as getChartDataGenerator,
  ee as getChartDimensions,
  Z as setChartThemeGenerator
};
