import { o as c } from "./rolldown-runtime.js";
import { i as a, n as l } from "./vendor/react.js";
var p = /* @__PURE__ */ c(a(), 1), u = l();
function o(t, e) {
  if (t !== null)
    switch (e) {
      case "number":
        return Number(t);
      case "boolean":
        return t !== "false" && t !== "0";
      case "json":
        try {
          return JSON.parse(t);
        } catch {
          return t;
        }
      default:
        return t;
    }
}
function f(t, e) {
  if (e === "boolean" && typeof t == "boolean" || e === "number" && typeof t == "number" || e === "string" && typeof t == "string" || e === "json" && typeof t == "object" && t !== null) return t;
  if (typeof t == "string") switch (e) {
    case "boolean":
      return t !== "false" && t !== "0" && t !== "";
    case "number":
      return Number(t);
    case "json":
      try {
        return JSON.parse(t);
      } catch {
        return t;
      }
    default:
      return t;
  }
  return t;
}
function i(t) {
  return t.replace(/([A-Z])/g, "-$1").toLowerCase();
}
function h(t) {
  const e = /* @__PURE__ */ new Map();
  for (const r of Array.from(t.children)) {
    const n = r.getAttribute("slot") ?? "", s = e.get(n) ?? [];
    s.push(r), e.set(n, s);
  }
  return e;
}
function b(t) {
  return t ? p.createElement("span", {
    ref: (e) => {
      e && t && e.replaceWith(t);
    },
    style: { display: "contents" }
  }) : null;
}
function _(t) {
  const e = document.createElement("div");
  e.style.display = "contents";
  for (const r of t) e.appendChild(r);
  return e;
}
function C(t, e, r) {
  t.dispatchEvent(new CustomEvent(e, {
    detail: r,
    bubbles: !0,
    composed: !0
  }));
}
var g = class extends HTMLElement {
  _root = null;
  _reactContainer = null;
  _props = {};
  _slotContainers = /* @__PURE__ */ new Map();
  _defaultSlotContainer = null;
  _initialized = !1;
  connectedCallback() {
    setTimeout(() => this._initialize(), 0);
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null, this._reactContainer = null;
  }
  _initialize() {
    if (this._initialized) return;
    this._initialized = !0;
    const t = h(this);
    for (const [e, r] of t) {
      const n = _(r);
      e === "" ? this._defaultSlotContainer = n : this._slotContainers.set(e, n);
    }
    for (; this.firstChild; ) this.removeChild(this.firstChild);
    this._reactContainer = document.createElement("div"), this._reactContainer.style.display = "contents", this.appendChild(this._reactContainer), this._root = (0, u.createRoot)(this._reactContainer), this._render();
  }
  attributeChangedCallback(t, e, r) {
    this._render();
  }
  _getProp(t) {
    if (t in this._props) return this._props[t];
    const e = i(t), r = this.propDefs[t] ?? "string";
    return o(this.getAttribute(e), r);
  }
  _setProp(t, e) {
    const r = this.propDefs[t] ?? "string";
    this._props[t] = f(e, r), this._render();
  }
  _readAllProps() {
    const t = {};
    for (const [e, r] of Object.entries(this.propDefs)) if (e in this._props) t[e] = this._props[e];
    else {
      const n = i(e);
      t[e] = o(this.getAttribute(n), r);
    }
    return t;
  }
  _getSlot(t) {
    return this._slotContainers.get(t) ?? null;
  }
  _getDefaultSlot() {
    return this._defaultSlotContainer;
  }
  _render() {
    !this._root || !this._initialized || this._root.render(this._renderReact());
  }
};
function y(t, e) {
  for (const r of Object.keys(e)) Object.defineProperty(t.prototype, r, {
    get() {
      return this._getProp(r);
    },
    set(n) {
      this._setProp(r, n);
    },
    enumerable: !0,
    configurable: !0
  });
}
function E(t, e) {
  typeof customElements < "u" && !customElements.get(t) && customElements.define(t, e);
}
export {
  b as a,
  y as i,
  i as n,
  E as o,
  C as r,
  g as t
};

//# sourceMappingURL=_shared.js.map