import ft, { createContext as Le, useRef as $, useState as de, useEffect as O, useCallback as W, useMemo as K, useContext as R } from "react";
import { LazyActive as k, generateId as re, useEffectCallback as oe, useRefState as Jt, useLazyActive as ee, isPrefixPath as ot } from "@easy-coder/sdk/helper";
import { getVariableByPath as je } from "@easy-coder/sdk/variable";
var ke = { exports: {} }, ce = {};
/**
 * @license React
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var it;
function Kt() {
  if (it)
    return ce;
  it = 1;
  var t = ft, r = Symbol.for("react.element"), a = Symbol.for("react.fragment"), n = Object.prototype.hasOwnProperty, s = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = {
    key: !0,
    ref: !0,
    __self: !0,
    __source: !0
  };
  function c(d, l, p) {
    var f, y = {}, V = null, b = null;
    p !== void 0 && (V = "" + p), l.key !== void 0 && (V = "" + l.key), l.ref !== void 0 && (b = l.ref);
    for (f in l)
      n.call(l, f) && !i.hasOwnProperty(f) && (y[f] = l[f]);
    if (d && d.defaultProps)
      for (f in l = d.defaultProps, l)
        y[f] === void 0 && (y[f] = l[f]);
    return {
      $$typeof: r,
      type: d,
      key: V,
      ref: b,
      props: y,
      _owner: s.current
    };
  }
  return ce.Fragment = a, ce.jsx = c, ce.jsxs = c, ce;
}
var fe = {};
/**
 * @license React
 * react-jsx-runtime.development.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var st;
function Xt() {
  return st || (st = 1, process.env.NODE_ENV !== "production" && function() {
    var t = ft, r = Symbol.for("react.element"), a = Symbol.for("react.portal"), n = Symbol.for("react.fragment"), s = Symbol.for("react.strict_mode"), i = Symbol.for("react.profiler"), c = Symbol.for("react.provider"), d = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), y = Symbol.for("react.memo"), V = Symbol.for("react.lazy"), b = Symbol.for("react.offscreen"), g = Symbol.iterator, w = "@@iterator";
    function A(e) {
      if (e === null || typeof e != "object")
        return null;
      var o = g && e[g] || e[w];
      return typeof o == "function" ? o : null;
    }
    var T = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
    function _(e) {
      {
        for (var o = arguments.length, u = new Array(o > 1 ? o - 1 : 0), v = 1; v < o; v++)
          u[v - 1] = arguments[v];
        L("error", e, u);
      }
    }
    function L(e, o, u) {
      {
        var v = T.ReactDebugCurrentFrame, E = v.getStackAddendum();
        E !== "" && (o += "%s", u = u.concat([E]));
        var S = u.map(function(h) {
          return String(h);
        });
        S.unshift("Warning: " + o), Function.prototype.apply.call(console[e], console, S);
      }
    }
    var Y = !1, z = !1, I = !1, F = !1, U = !1, X;
    X = Symbol.for("react.module.reference");
    function C(e) {
      return !!(typeof e == "string" || typeof e == "function" || e === n || e === i || U || e === s || e === p || e === f || F || e === b || Y || z || I || typeof e == "object" && e !== null && (e.$$typeof === V || e.$$typeof === y || e.$$typeof === c || e.$$typeof === d || e.$$typeof === l || // This needs to include all possible module reference object
      // types supported by any Flight configuration anywhere since
      // we don't know which Flight build this will end up being used
      // with.
      e.$$typeof === X || e.getModuleId !== void 0));
    }
    function j(e, o, u) {
      var v = e.displayName;
      if (v)
        return v;
      var E = o.displayName || o.name || "";
      return E !== "" ? u + "(" + E + ")" : u;
    }
    function J(e) {
      return e.displayName || "Context";
    }
    function x(e) {
      if (e == null)
        return null;
      if (typeof e.tag == "number" && _("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
        return e.displayName || e.name || null;
      if (typeof e == "string")
        return e;
      switch (e) {
        case n:
          return "Fragment";
        case a:
          return "Portal";
        case i:
          return "Profiler";
        case s:
          return "StrictMode";
        case p:
          return "Suspense";
        case f:
          return "SuspenseList";
      }
      if (typeof e == "object")
        switch (e.$$typeof) {
          case d:
            var o = e;
            return J(o) + ".Consumer";
          case c:
            var u = e;
            return J(u._context) + ".Provider";
          case l:
            return j(e, e.render, "ForwardRef");
          case y:
            var v = e.displayName || null;
            return v !== null ? v : x(e.type) || "Memo";
          case V: {
            var E = e, S = E._payload, h = E._init;
            try {
              return x(h(S));
            } catch {
              return null;
            }
          }
        }
      return null;
    }
    var H = Object.assign, se = 0, Ie, Fe, Ge, Ne, Be, $e, We;
    function Ye() {
    }
    Ye.__reactDisabledLog = !0;
    function ht() {
      {
        if (se === 0) {
          Ie = console.log, Fe = console.info, Ge = console.warn, Ne = console.error, Be = console.group, $e = console.groupCollapsed, We = console.groupEnd;
          var e = {
            configurable: !0,
            enumerable: !0,
            value: Ye,
            writable: !0
          };
          Object.defineProperties(console, {
            info: e,
            log: e,
            warn: e,
            error: e,
            group: e,
            groupCollapsed: e,
            groupEnd: e
          });
        }
        se++;
      }
    }
    function Et() {
      {
        if (se--, se === 0) {
          var e = {
            configurable: !0,
            enumerable: !0,
            writable: !0
          };
          Object.defineProperties(console, {
            log: H({}, e, {
              value: Ie
            }),
            info: H({}, e, {
              value: Fe
            }),
            warn: H({}, e, {
              value: Ge
            }),
            error: H({}, e, {
              value: Ne
            }),
            group: H({}, e, {
              value: Be
            }),
            groupCollapsed: H({}, e, {
              value: $e
            }),
            groupEnd: H({}, e, {
              value: We
            })
          });
        }
        se < 0 && _("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
      }
    }
    var _e = T.ReactCurrentDispatcher, Se;
    function ve(e, o, u) {
      {
        if (Se === void 0)
          try {
            throw Error();
          } catch (E) {
            var v = E.stack.trim().match(/\n( *(at )?)/);
            Se = v && v[1] || "";
          }
        return `
` + Se + e;
      }
    }
    var Pe = !1, ye;
    {
      var Vt = typeof WeakMap == "function" ? WeakMap : Map;
      ye = new Vt();
    }
    function Ue(e, o) {
      if (!e || Pe)
        return "";
      {
        var u = ye.get(e);
        if (u !== void 0)
          return u;
      }
      var v;
      Pe = !0;
      var E = Error.prepareStackTrace;
      Error.prepareStackTrace = void 0;
      var S;
      S = _e.current, _e.current = null, ht();
      try {
        if (o) {
          var h = function() {
            throw Error();
          };
          if (Object.defineProperty(h.prototype, "props", {
            set: function() {
              throw Error();
            }
          }), typeof Reflect == "object" && Reflect.construct) {
            try {
              Reflect.construct(h, []);
            } catch (N) {
              v = N;
            }
            Reflect.construct(e, [], h);
          } else {
            try {
              h.call();
            } catch (N) {
              v = N;
            }
            e.call(h.prototype);
          }
        } else {
          try {
            throw Error();
          } catch (N) {
            v = N;
          }
          e();
        }
      } catch (N) {
        if (N && v && typeof N.stack == "string") {
          for (var m = N.stack.split(`
`), G = v.stack.split(`
`), M = m.length - 1, D = G.length - 1; M >= 1 && D >= 0 && m[M] !== G[D]; )
            D--;
          for (; M >= 1 && D >= 0; M--, D--)
            if (m[M] !== G[D]) {
              if (M !== 1 || D !== 1)
                do
                  if (M--, D--, D < 0 || m[M] !== G[D]) {
                    var B = `
` + m[M].replace(" at new ", " at ");
                    return e.displayName && B.includes("<anonymous>") && (B = B.replace("<anonymous>", e.displayName)), typeof e == "function" && ye.set(e, B), B;
                  }
                while (M >= 1 && D >= 0);
              break;
            }
        }
      } finally {
        Pe = !1, _e.current = S, Et(), Error.prepareStackTrace = E;
      }
      var ae = e ? e.displayName || e.name : "", te = ae ? ve(ae) : "";
      return typeof e == "function" && ye.set(e, te), te;
    }
    function Rt(e, o, u) {
      return Ue(e, !1);
    }
    function _t(e) {
      var o = e.prototype;
      return !!(o && o.isReactComponent);
    }
    function be(e, o, u) {
      if (e == null)
        return "";
      if (typeof e == "function")
        return Ue(e, _t(e));
      if (typeof e == "string")
        return ve(e);
      switch (e) {
        case p:
          return ve("Suspense");
        case f:
          return ve("SuspenseList");
      }
      if (typeof e == "object")
        switch (e.$$typeof) {
          case l:
            return Rt(e.render);
          case y:
            return be(e.type, o, u);
          case V: {
            var v = e, E = v._payload, S = v._init;
            try {
              return be(S(E), o, u);
            } catch {
            }
          }
        }
      return "";
    }
    var ue = Object.prototype.hasOwnProperty, Je = {}, Ke = T.ReactDebugCurrentFrame;
    function me(e) {
      if (e) {
        var o = e._owner, u = be(e.type, e._source, o ? o.type : null);
        Ke.setExtraStackFrame(u);
      } else
        Ke.setExtraStackFrame(null);
    }
    function St(e, o, u, v, E) {
      {
        var S = Function.call.bind(ue);
        for (var h in e)
          if (S(e, h)) {
            var m = void 0;
            try {
              if (typeof e[h] != "function") {
                var G = Error((v || "React class") + ": " + u + " type `" + h + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[h] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
                throw G.name = "Invariant Violation", G;
              }
              m = e[h](o, h, v, u, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
            } catch (M) {
              m = M;
            }
            m && !(m instanceof Error) && (me(E), _("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", v || "React class", u, h, typeof m), me(null)), m instanceof Error && !(m.message in Je) && (Je[m.message] = !0, me(E), _("Failed %s type: %s", u, m.message), me(null));
          }
      }
    }
    var Pt = Array.isArray;
    function we(e) {
      return Pt(e);
    }
    function wt(e) {
      {
        var o = typeof Symbol == "function" && Symbol.toStringTag, u = o && e[Symbol.toStringTag] || e.constructor.name || "Object";
        return u;
      }
    }
    function Ct(e) {
      try {
        return Xe(e), !1;
      } catch {
        return !0;
      }
    }
    function Xe(e) {
      return "" + e;
    }
    function qe(e) {
      if (Ct(e))
        return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", wt(e)), Xe(e);
    }
    var le = T.ReactCurrentOwner, xt = {
      key: !0,
      ref: !0,
      __self: !0,
      __source: !0
    }, ze, He, Ce;
    Ce = {};
    function Mt(e) {
      if (ue.call(e, "ref")) {
        var o = Object.getOwnPropertyDescriptor(e, "ref").get;
        if (o && o.isReactWarning)
          return !1;
      }
      return e.ref !== void 0;
    }
    function Dt(e) {
      if (ue.call(e, "key")) {
        var o = Object.getOwnPropertyDescriptor(e, "key").get;
        if (o && o.isReactWarning)
          return !1;
      }
      return e.key !== void 0;
    }
    function Tt(e, o) {
      if (typeof e.ref == "string" && le.current && o && le.current.stateNode !== o) {
        var u = x(le.current.type);
        Ce[u] || (_('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', x(le.current.type), e.ref), Ce[u] = !0);
      }
    }
    function jt(e, o) {
      {
        var u = function() {
          ze || (ze = !0, _("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", o));
        };
        u.isReactWarning = !0, Object.defineProperty(e, "key", {
          get: u,
          configurable: !0
        });
      }
    }
    function Ot(e, o) {
      {
        var u = function() {
          He || (He = !0, _("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", o));
        };
        u.isReactWarning = !0, Object.defineProperty(e, "ref", {
          get: u,
          configurable: !0
        });
      }
    }
    var kt = function(e, o, u, v, E, S, h) {
      var m = {
        // This tag allows us to uniquely identify this as a React Element
        $$typeof: r,
        // Built-in properties that belong on the element
        type: e,
        key: o,
        ref: u,
        props: h,
        // Record the component responsible for creating this element.
        _owner: S
      };
      return m._store = {}, Object.defineProperty(m._store, "validated", {
        configurable: !1,
        enumerable: !1,
        writable: !0,
        value: !1
      }), Object.defineProperty(m, "_self", {
        configurable: !1,
        enumerable: !1,
        writable: !1,
        value: v
      }), Object.defineProperty(m, "_source", {
        configurable: !1,
        enumerable: !1,
        writable: !1,
        value: E
      }), Object.freeze && (Object.freeze(m.props), Object.freeze(m)), m;
    };
    function At(e, o, u, v, E) {
      {
        var S, h = {}, m = null, G = null;
        u !== void 0 && (qe(u), m = "" + u), Dt(o) && (qe(o.key), m = "" + o.key), Mt(o) && (G = o.ref, Tt(o, E));
        for (S in o)
          ue.call(o, S) && !xt.hasOwnProperty(S) && (h[S] = o[S]);
        if (e && e.defaultProps) {
          var M = e.defaultProps;
          for (S in M)
            h[S] === void 0 && (h[S] = M[S]);
        }
        if (m || G) {
          var D = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
          m && jt(h, D), G && Ot(h, D);
        }
        return kt(e, m, G, E, v, le.current, h);
      }
    }
    var xe = T.ReactCurrentOwner, Ze = T.ReactDebugCurrentFrame;
    function ne(e) {
      if (e) {
        var o = e._owner, u = be(e.type, e._source, o ? o.type : null);
        Ze.setExtraStackFrame(u);
      } else
        Ze.setExtraStackFrame(null);
    }
    var Me;
    Me = !1;
    function De(e) {
      return typeof e == "object" && e !== null && e.$$typeof === r;
    }
    function Qe() {
      {
        if (xe.current) {
          var e = x(xe.current.type);
          if (e)
            return `

Check the render method of \`` + e + "`.";
        }
        return "";
      }
    }
    function Lt(e) {
      {
        if (e !== void 0) {
          var o = e.fileName.replace(/^.*[\\\/]/, ""), u = e.lineNumber;
          return `

Check your code at ` + o + ":" + u + ".";
        }
        return "";
      }
    }
    var et = {};
    function It(e) {
      {
        var o = Qe();
        if (!o) {
          var u = typeof e == "string" ? e : e.displayName || e.name;
          u && (o = `

Check the top-level render call using <` + u + ">.");
        }
        return o;
      }
    }
    function tt(e, o) {
      {
        if (!e._store || e._store.validated || e.key != null)
          return;
        e._store.validated = !0;
        var u = It(o);
        if (et[u])
          return;
        et[u] = !0;
        var v = "";
        e && e._owner && e._owner !== xe.current && (v = " It was passed a child from " + x(e._owner.type) + "."), ne(e), _('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', u, v), ne(null);
      }
    }
    function rt(e, o) {
      {
        if (typeof e != "object")
          return;
        if (we(e))
          for (var u = 0; u < e.length; u++) {
            var v = e[u];
            De(v) && tt(v, o);
          }
        else if (De(e))
          e._store && (e._store.validated = !0);
        else if (e) {
          var E = A(e);
          if (typeof E == "function" && E !== e.entries)
            for (var S = E.call(e), h; !(h = S.next()).done; )
              De(h.value) && tt(h.value, o);
        }
      }
    }
    function Ft(e) {
      {
        var o = e.type;
        if (o == null || typeof o == "string")
          return;
        var u;
        if (typeof o == "function")
          u = o.propTypes;
        else if (typeof o == "object" && (o.$$typeof === l || // Note: Memo only checks outer props here.
        // Inner props are checked in the reconciler.
        o.$$typeof === y))
          u = o.propTypes;
        else
          return;
        if (u) {
          var v = x(o);
          St(u, e.props, "prop", v, e);
        } else if (o.PropTypes !== void 0 && !Me) {
          Me = !0;
          var E = x(o);
          _("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", E || "Unknown");
        }
        typeof o.getDefaultProps == "function" && !o.getDefaultProps.isReactClassApproved && _("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
      }
    }
    function Gt(e) {
      {
        for (var o = Object.keys(e.props), u = 0; u < o.length; u++) {
          var v = o[u];
          if (v !== "children" && v !== "key") {
            ne(e), _("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", v), ne(null);
            break;
          }
        }
        e.ref !== null && (ne(e), _("Invalid attribute `ref` supplied to `React.Fragment`."), ne(null));
      }
    }
    var nt = {};
    function at(e, o, u, v, E, S) {
      {
        var h = C(e);
        if (!h) {
          var m = "";
          (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (m += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
          var G = Lt(E);
          G ? m += G : m += Qe();
          var M;
          e === null ? M = "null" : we(e) ? M = "array" : e !== void 0 && e.$$typeof === r ? (M = "<" + (x(e.type) || "Unknown") + " />", m = " Did you accidentally export a JSX literal instead of a component?") : M = typeof e, _("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", M, m);
        }
        var D = At(e, o, u, E, S);
        if (D == null)
          return D;
        if (h) {
          var B = o.children;
          if (B !== void 0)
            if (v)
              if (we(B)) {
                for (var ae = 0; ae < B.length; ae++)
                  rt(B[ae], e);
                Object.freeze && Object.freeze(B);
              } else
                _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
            else
              rt(B, e);
        }
        if (ue.call(o, "key")) {
          var te = x(e), N = Object.keys(o).filter(function(Ut) {
            return Ut !== "key";
          }), Te = N.length > 0 ? "{key: someKey, " + N.join(": ..., ") + ": ...}" : "{key: someKey}";
          if (!nt[te + Te]) {
            var Yt = N.length > 0 ? "{" + N.join(": ..., ") + ": ...}" : "{}";
            _(`A props object containing a "key" prop is being spread into JSX:
  let props = %s;
  <%s {...props} />
React keys must be passed directly to JSX without using spread:
  let props = %s;
  <%s key={someKey} {...props} />`, Te, te, Yt, te), nt[te + Te] = !0;
          }
        }
        return e === n ? Gt(D) : Ft(D), D;
      }
    }
    function Nt(e, o, u) {
      return at(e, o, u, !0);
    }
    function Bt(e, o, u) {
      return at(e, o, u, !1);
    }
    var $t = Bt, Wt = Nt;
    fe.Fragment = n, fe.jsx = $t, fe.jsxs = Wt;
  }()), fe;
}
process.env.NODE_ENV === "production" ? ke.exports = Kt() : ke.exports = Xt();
var pe = ke.exports;
const ge = Le({});
function qt({
  children: t
}) {
  return /* @__PURE__ */ pe.jsx(ge.Provider, {
    value: {},
    children: t
  });
}
const P = Le({
  state: new k({
    editorMap: {},
    elementMap: {}
  }),
  globalVariable: new k({}),
  globalClassName: new k({}),
  globalStyleVarGroups: new k([]),
  variableStore: new k({}),
  variableDefine: new k({}),
  elements: new k({}),
  eventFlow: new k({}),
  eventDefine: new k({}),
  env: {
    isPreviewing: !1
  }
}), ie = "componentVariable", he = "componentEvent", q = "slotVariable", Ee = "globalVariable", Q = [ie], Ae = [he], pt = [q], Re = [Ee];
function dt() {
  return {
    padding: [{
      value: 8,
      unit: "px"
    }, {
      value: 8,
      unit: "px"
    }, {
      value: 8,
      unit: "px"
    }, {
      value: 8,
      unit: "px"
    }],
    boxSizing: "border-box"
  };
}
function zt() {
  return {
    id: re("style_var_group"),
    alias: "默认",
    vars: {},
    active: !0
  };
}
function cr(t) {
  return !!t.elements;
}
function ut(t, r, a) {
  const n = t.editorMap[a];
  if (n)
    return n.type !== "slot" ? !1 : n.elementId === r ? !0 : ut(t, r, n.elementId);
  const s = t.elementMap[a];
  return s ? s.editorId === r ? !0 : ut(t, r, s.editorId) : !1;
}
function Ht(t) {
  return t.type === "ref";
}
function fr(t, r) {
  if (!t)
    return;
  let a = r;
  for (const n of t)
    a = a == null ? void 0 : a[n];
  return a;
}
function Z(t, r) {
  if (t.type === "object") {
    const a = {};
    for (const n in t.prototype)
      a[n] = Z(t.prototype[n], n);
    return {
      ...t,
      apiName: r,
      prototype: a
    };
  }
  return t.type === "array" ? {
    ...t,
    apiName: r,
    item: Z(t.item, void 0)
  } : {
    ...t,
    apiName: r
  };
}
async function Zt(t, r, a) {
  const n = {
    type: "object",
    label: "全局变量",
    apiName: Ee,
    prototype: {}
  };
  for (const p in a)
    n.prototype[p] = a[p].define;
  const s = {
    type: "object",
    label: "组件变量",
    apiName: ie,
    prototype: {}
  }, i = {
    type: "object",
    label: "插槽变量",
    apiName: q,
    prototype: {}
  }, c = {
    [ie]: s,
    [q]: i
  };
  Object.keys(n.prototype).length > 0 && (c[Ee] = n);
  const d = {
    type: "path",
    label: "组件方法",
    children: {}
  }, l = {
    [he]: d
  };
  for (const p in t.editorMap) {
    const f = t.editorMap[p];
    f.type === "modal" && (s.prototype[p] = rr(p, f.alias), d.children[p] = nr(p, f.alias));
  }
  for (const p in t.elementMap) {
    const f = await Qt(t, r, p, c);
    f && (Object.keys(f.elementVariableDefine.prototype).length > 0 && (s.prototype[p] = f.elementVariableDefine), i.prototype = {
      ...i.prototype,
      ...f.slotVariableMap
    });
    const y = await er(t, r, p, c);
    y && (d.children[p] = y);
  }
  return Object.keys(s.prototype).length === 0 && delete c[ie], Object.keys(i.prototype).length === 0 && delete c[q], Object.keys(d.children).length === 0 && delete l[he], {
    variableDefine: c,
    eventDefine: l
  };
}
async function Qt(t, r, a, n) {
  var y, V, b;
  const s = t.elementMap[a], i = r[s == null ? void 0 : s.type];
  if (!i)
    return;
  const c = {};
  for (const g in i.attr) {
    const w = (y = s.props) == null ? void 0 : y[g];
    c[g] = w;
  }
  const d = {
    type: "object",
    label: s.alias || i.label,
    apiName: a,
    prototype: {}
  }, l = (g) => Ve(t, r, n, a, g, []), p = ((V = i.export) == null ? void 0 : V.attr) || {};
  for (const g in p) {
    const w = p[g];
    if (typeof w == "function") {
      const A = await w(c, l);
      A && (d.prototype[g] = Z(A, g));
    } else
      d.prototype[g] = Z(w, g);
  }
  const f = {};
  for (const g in s.slotMap) {
    const w = s.slotMap[g], A = {
      type: "object",
      label: `${t.editorMap[w].alias}(${s.alias || i.label})`,
      apiName: w,
      prototype: {}
    }, T = (b = i.slot) == null ? void 0 : b[g];
    if (T != null && T.payload) {
      for (const _ in T.payload) {
        const L = T.payload[_];
        if (typeof L == "function") {
          const Y = await L(c, l);
          Y && (A.prototype[_] = Z(Y, _));
        } else
          A.prototype[_] = Z(L, _);
      }
      Object.keys(A.prototype).length > 0 && (f[w] = A);
    }
  }
  return {
    elementVariableDefine: d,
    slotVariableMap: f
  };
}
async function er(t, r, a, n) {
  var d;
  const s = t.elementMap[a], i = r[s == null ? void 0 : s.type];
  if (!i)
    return;
  const c = {};
  for (const l in (d = i.export) == null ? void 0 : d.event) {
    const p = i.export.event[l], f = await tr(a, p, t, r, n);
    c[l] = {
      ...f,
      type: "event"
    };
  }
  if (Object.keys(c).length !== 0)
    return {
      type: "path",
      label: s.alias || i.label,
      children: c
    };
}
async function tr(t, r, a, n, s) {
  const i = [];
  let c;
  const d = (l) => Ve(a, n, s, t, l, []);
  if (r.params)
    for (const l of r.params)
      if (typeof l == "function") {
        const p = await l(a.elementMap[t].props, d);
        if (!p) {
          i.length = 0;
          break;
        }
        i.push(Z(p, ""));
      } else
        i.push(Z(l, ""));
  return typeof r.return == "function" && (r.return = await r.return(a.elementMap[t].props, d)), r.return && (c = Z(r.return, "")), {
    label: r.label,
    params: i,
    return: c
  };
}
async function Ve(t, r, a, n, s, i) {
  var V, b, g, w, A, T, _;
  if (i.some((L) => L.id === n && L.key === s)) {
    console.error("计算属性值错误：存在循环依赖");
    return;
  }
  const c = [...i, {
    id: n,
    key: s
  }], d = t.elementMap[n];
  if (!d)
    return;
  const l = r[d.type];
  if (!l)
    return;
  const p = (V = l.attr) == null ? void 0 : V[s];
  if (!p)
    return;
  if (!Ht(p))
    return p;
  const f = (b = d.props) == null ? void 0 : b[s];
  if (!f)
    return;
  const y = await je(f, a);
  if (y)
    return y;
  if (f[0] === ie) {
    const L = f[1], Y = f[2], z = f.slice(3), I = t.elementMap[L];
    if (!I)
      return;
    const F = r[I.type];
    if (!F)
      return;
    const U = (w = (g = F.export) == null ? void 0 : g.attr) == null ? void 0 : w[Y];
    if (!U)
      return;
    const X = (j) => Ve(t, r, a, L, j, c), C = typeof U == "function" ? await U(I.props, X) : U;
    return C ? z.length === 0 ? C : C.type !== "object" ? void 0 : await je(z, C.prototype) : void 0;
  }
  if (f[0] === q) {
    const L = f[1], Y = f[2], z = f.slice(3), I = t.editorMap[L];
    if (!I || I.type !== "slot")
      return;
    const F = t.elementMap[I.elementId];
    if (!d)
      return;
    const U = r[F.type];
    if (!U)
      return;
    let X;
    for (const x in F.slotMap)
      F.slotMap[x] === L && (X = x);
    if (!X)
      return;
    const C = (_ = (T = (A = U.slot) == null ? void 0 : A[X]) == null ? void 0 : T.payload) == null ? void 0 : _[Y];
    if (!C)
      return;
    const j = (x) => Ve(t, r, a, I.elementId, x, c), J = typeof C == "function" ? await C(F.props, j) : C;
    return J ? z.length === 0 ? J : J.type !== "object" ? void 0 : await je(z, J.prototype) : void 0;
  }
}
function rr(t, r) {
  return {
    type: "object",
    label: r || "弹窗",
    apiName: t,
    prototype: {
      visible: {
        type: "boolean",
        label: "是否打开",
        apiName: "visible"
      }
    }
  };
}
function nr(t, r) {
  return {
    type: "path",
    label: r || "弹窗",
    children: {
      open: {
        type: "event",
        label: "打开"
      },
      close: {
        type: "event",
        label: "关闭"
      }
    }
  };
}
function ar(t, r, a) {
  return t.some((n) => {
    if (n[0] === "elementMap" && n.length > 2 && n[2] === "alias")
      return !0;
    if (n[0] === "elementMap" && n.length > 2 && n[2] === "props") {
      const s = n[1], i = r.elementMap[s], c = a[i == null ? void 0 : i.type];
      if (!c)
        return !1;
      for (const d in c.attr) {
        const l = c.attr[d];
        if ((l == null ? void 0 : l.type) === "ref")
          return !0;
      }
    }
    return n.length <= 2;
  });
}
function pr(t) {
  const r = t.variableStore.getValue(Ae);
  function a(i, c) {
    t.state.getValue().editorMap[i].type === "modal" && t.variableStore.updateValueByPath([...Q, i, "visible"], c);
  }
  const n = {}, {
    editorMap: s
  } = t.state.getValue();
  for (const i in s)
    s[i].type === "modal" && (n[i] = {
      open: () => a(i, !0),
      close: () => a(i, !1)
    });
  return {
    [he]: {
      ...r,
      ...n
    }
  };
}
function or(t, r) {
  var s;
  const a = t.getValue(pt), n = {};
  for (const i in r) {
    const c = r[i];
    n[i] = (s = a == null ? void 0 : a[i]) == null ? void 0 : s[c];
  }
  return {
    [ie]: t.getValue(Q),
    [q]: n,
    [Ee]: t.getValue(Re)
  };
}
function dr({
  children: t,
  state: r,
  elements: a,
  env: n,
  globalVariable: s,
  globalClassName: i,
  globalStyleVarGroups: c,
  eventFlow: d,
  fetchElementByType: l,
  getModalContainer: p,
  onChange: f
}) {
  const y = $(new k(r || {
    elementMap: {},
    editorMap: {
      [re("root")]: {
        type: "root",
        alias: "页面",
        elements: [],
        style: dt()
      }
    }
  })), V = $(new k(a || {})), b = $(new k(s || {})), g = $(new k(i || {})), w = $(new k(c || [zt()])), A = $(new k(d || {})), T = $(new k({})), _ = $(new k({})), L = $(new k({})), [Y, z] = de(n || {
    isPreviewing: !1
  });
  O(() => {
    r && y.current.updateValue(r);
  }, [r]), O(() => {
    a && V.current.updateValue(a);
  }, [a]), O(() => {
    n && z(n);
  }, [n]), O(() => {
    s && b.current.updateValue(s);
  }, [s]), O(() => {
    i && g.current.updateValue(i);
  }, [i]), O(() => {
    c && w.current.updateValue(c);
  }, [c]), O(() => {
    d && A.current.updateValue(d);
  }, [d]), O(() => {
    const C = {};
    for (const j in s)
      C[j] = s[j].defaultValue;
    T.current.updateValueByPath(Re, JSON.parse(JSON.stringify(C)));
  }, [s]);
  const I = W(async () => {
    const {
      variableDefine: C,
      eventDefine: j
    } = await Zt(y.current.getValue(), V.current.getValue(), b.current.getValue());
    L.current.updateValue(j), _.current.updateValue(C);
  }, []);
  O(() => {
    I();
    const C = y.current.addChangeListener((x) => {
      ar(x, y.current.getValue(), V.current.getValue()) && I();
    }), j = V.current.addChangeListener((x) => {
      I();
    }), J = b.current.addChangeListener((x) => {
      I();
    });
    return () => {
      C(), j(), J();
    };
  }, []);
  const F = oe(() => {
    f && f({
      state: y.current.getValue(),
      globalVariable: b.current.getValue(),
      globalClassName: g.current.getValue(),
      globalStyleVarGroups: w.current.getValue(),
      eventFlow: A.current.getValue()
    });
  }, [f]), U = oe(async (C) => {
    if (!l)
      return;
    const j = await l(C);
    return j && V.current.updateValueByPath([C], j), j;
  }, [l]);
  O(() => {
    const C = y.current.addChangeListener(F), j = b.current.addChangeListener(F), J = g.current.addChangeListener(F), x = w.current.addChangeListener(F), H = A.current.addChangeListener(F);
    return () => {
      C(), j(), J(), x(), H();
    };
  }, []);
  const X = K(() => ({
    state: y.current,
    elements: V.current,
    env: Y,
    globalVariable: b.current,
    globalClassName: g.current,
    globalStyleVarGroups: w.current,
    variableStore: T.current,
    variableDefine: _.current,
    eventFlow: A.current,
    eventDefine: L.current,
    fetchElementByType: U,
    getModalContainer: p
  }), [Y, p]);
  return /* @__PURE__ */ pe.jsx(P.Provider, {
    value: X,
    children: /* @__PURE__ */ pe.jsx(qt, {
      children: t
    })
  });
}
function vr() {
  const {
    state: t
  } = R(P), [r, a, n] = Jt(lt(t.getValue()));
  return O(() => t.addChangeListener((s) => {
    const i = lt(t.getValue(), a.current);
    i !== a.current && n(i);
  }), []), r;
}
function lt(t, r) {
  var a;
  if (r && ((a = t.editorMap[r]) == null ? void 0 : a.type) === "root")
    return r;
  for (const n in t.editorMap)
    if (t.editorMap[n].type === "root")
      return n;
}
function yr(t) {
  const r = R(P);
  return W((...n) => {
    r[t].updateValue(...n);
  }, [t]);
}
function br(t, r) {
  const {
    state: a
  } = R(P), n = K(() => [t === "editor" ? "editorMap" : "elementMap", r], [t, r]);
  return ee(a, n, !0);
}
function mr() {
  const {
    state: t
  } = R(P), r = K(() => [], []);
  return ee(t, r, !0);
}
function gr() {
  const {
    state: t
  } = R(P);
  return W((a) => {
    t.updateValue((n) => {
      const s = {
        ...t.getValue().editorMap
      }, i = {
        ...t.getValue().elementMap
      };
      vt(s, i, a), n.editorMap = s, n.elementMap = i;
    });
  }, []);
}
function vt(t, r, a) {
  const n = r[a];
  if (!n)
    return;
  delete r[a];
  const s = t[n.editorId];
  s && (s.elements = s.elements.filter((i) => i !== a));
  for (const i in n.slotMap)
    yt(t, r, n.slotMap[i]);
}
function yt(t, r, a) {
  const n = t[a];
  !n || n.type === "root" || (delete t[a], n.elements.map((s) => vt(t, r, s)));
}
function hr() {
  const {
    state: t
  } = R(P);
  return W((a) => {
    t.updateValue((n) => {
      yt(n.editorMap, n.elementMap, a);
    });
  }, []);
}
function Er() {
  const {
    state: t,
    variableStore: r
  } = R(P);
  return W((n, s) => {
    const i = t.getValue().editorMap[n];
    (i == null ? void 0 : i.type) === "modal" && r.updateValueByPath([...Q, n, "visible"], s);
  }, []);
}
function Vr() {
  return R(P);
}
function Rr(t) {
  const {
    elements: r,
    fetchElementByType: a
  } = R(P);
  O(() => {
    r.getValue([t]) || a == null || a(t);
  }, [t]);
  const n = K(() => [t], [t]);
  return ee(r, n, !0);
}
function _r() {
  const {
    state: t,
    elements: r,
    fetchElementByType: a
  } = R(P);
  return W(async (s, i, c) => {
    const d = r.getValue();
    return new Promise((l) => {
      t.updateValue(async (p) => {
        const f = await bt(p, d, s, i, void 0, a), y = p.editorMap[i], V = [...t.getValue(["editorMap", i, "elements"])];
        if (!c)
          V.push(f);
        else {
          const b = V.findIndex((g) => g === c);
          if (b === -1) {
            l();
            return;
          }
          V.splice(b, 0, f);
        }
        y.elements = V, l(f);
      });
    });
  }, []);
}
async function bt(t, r, a, n, s, i) {
  var y, V;
  let c = r[a];
  if (!c && i) {
    const b = await i(a);
    b && (c = b);
  }
  if (!c)
    throw new Error(`未找到type: ${a}的组件`);
  const d = re("element"), l = {};
  for (const b in c.slot) {
    const g = c.slot[b], w = re("slot");
    t.editorMap[w] = {
      type: "slot",
      alias: g.label,
      elementId: d,
      elements: [],
      style: g.defaultStyle || dt()
    }, l[b] = w;
  }
  const p = {
    ...c.defaultAttr
  };
  for (const b in c.style) {
    const g = (y = c.style[b]) == null ? void 0 : y.defaultValue;
    g && (p[b] = JSON.parse(JSON.stringify(g)));
  }
  const f = {
    type: a,
    editorId: n,
    alias: c.label,
    slotMap: l,
    props: {
      ...p,
      ...s
    }
  };
  return await ((V = c.onCreate) == null ? void 0 : V.call(c, {
    currentElement: f,
    getEditorById: (b) => t.editorMap[b],
    getElementById: (b) => t.elementMap[b],
    createElement: (b, g, w) => bt(t, r, b, g, w, i)
  })), t.elementMap[d] = f, d;
}
function Sr() {
  const {
    state: t,
    variableStore: r
  } = R(P), [a, n] = de(Oe(t.getValue(), r));
  return O(() => {
    const s = r.addChangeListener((c) => {
      c.some((l) => {
        if (ot(l, Q))
          return !0;
        if (!ot(Q, l))
          return !1;
        const p = l.slice(Q.length);
        if (p.length === 0)
          return !1;
        const f = t.getValue(["editorMap", p[0]]);
        return (f == null ? void 0 : f.type) !== "modal" ? !1 : p[1] === "visible";
      }) && n(Oe(t.getValue(), r));
    }), i = t.addChangeListener(() => {
      n(Oe(t.getValue(), r));
    });
    return () => {
      s(), i();
    };
  }, []), a;
}
function Oe(t, r) {
  const a = [];
  for (const n in t.editorMap) {
    const s = t.editorMap[n];
    s.type === "modal" && r.getValue([...Q, n, "visible"]) && a.push({
      id: n,
      modal: s
    });
  }
  return a;
}
function Pr() {
  const {
    state: t
  } = R(P);
  return W(() => new Promise((a) => {
    t.updateValue((n) => {
      const s = {
        type: "modal",
        elements: [],
        header: "弹窗",
        alias: "弹窗"
      }, i = re("modal");
      a(i), n.editorMap[i] = s;
    });
  }), []);
}
function wr() {
  const {
    globalVariable: t,
    variableStore: r
  } = R(P);
  return W((n, s) => {
    const i = re("global_variable");
    t.updateValue((c) => {
      c[i] = {
        define: n,
        defaultValue: s
      };
    }), r.updateValueByPath([...Re, i], s);
  }, []);
}
function Cr() {
  const {
    globalVariable: t,
    variableStore: r
  } = R(P);
  return W((n, s, i) => {
    t.updateValue((c) => {
      c[n] = {
        define: s,
        defaultValue: i
      };
    }), r.updateValueByPath([...Re, n], i);
  }, []);
}
function xr() {
  const {
    globalVariable: t
  } = R(P), r = K(() => [], []);
  return ee(t, r, !0);
}
function Mr({
  id: t,
  payload: r,
  children: a
}) {
  const n = R(ge), s = $(re("slot_key")), {
    variableStore: i
  } = R(P), c = K(() => ({
    ...n,
    [t]: s.current
  }), [n, r, t]);
  return O(() => {
    i.updateValueByPath([...pt, t, s.current], r);
  }, [r, t]), /* @__PURE__ */ pe.jsx(ge.Provider, {
    value: c,
    children: a
  });
}
function mt() {
  return R(ge);
}
function Dr() {
  const {
    variableDefine: t
  } = R(P), [r, a] = de({}), n = $(!1), s = mt(), i = W(async () => {
    var f;
    const c = t.getValue(), d = {
      ...c
    }, l = {
      ...c[q]
    }, p = {};
    for (const y in s)
      (f = l.prototype) != null && f[y] && (p[y] = l.prototype[y]);
    Object.keys(p).length > 0 ? (l.prototype = p, d[q] = l) : delete d[q], a(d), n.current = !0;
  }, [s]);
  return O(() => (i(), t.addChangeListener((d) => {
    i();
  })), [i]), {
    variableDefine: r,
    initComplete: n.current
  };
}
function Tr() {
  const {
    state: t,
    variableStore: r
  } = R(P), [a, n] = de({}), s = $([]), i = mt(), c = W((p = []) => {
    s.current.push(p);
  }, []), d = W(() => {
    s.current = [];
  }, []), l = oe(() => {
    n(or(r, i));
  }, [t, i, r]);
  return O(() => (l(), r.addChangeListener((f) => {
    s.current.some((V) => f.some((b) => ir(b, V))) && l();
  })), [r]), O(() => {
    d();
  }, [a]), {
    variableValue: a,
    addDependent: c,
    clearDependent: d
  };
}
function ir(t, r) {
  const a = [...t];
  if (a[0] === q && a.splice(2, 1), a.length > r.length)
    return !1;
  for (let n = 0; n < a.length; n++)
    if (a[n] !== r[n])
      return !1;
  return !0;
}
function jr() {
  const {
    env: t
  } = R(P);
  return t;
}
function Or() {
  const {
    getModalContainer: t
  } = R(P);
  return t;
}
function kr() {
  const {
    globalClassName: t
  } = R(P), r = K(() => [], []);
  return ee(t, r, !0);
}
function Ar() {
  const {
    globalStyleVarGroups: t
  } = R(P), [r, a] = de(ct(t.getValue()));
  return O(() => t.addChangeListener((n) => {
    a(ct(t.getValue()));
  }), []), r;
}
function ct(t) {
  return t.find((r) => r.active);
}
function Lr() {
  const {
    globalStyleVarGroups: t
  } = R(P), r = K(() => [], []);
  return ee(t, r, !0);
}
function Ir(t) {
  const {
    eventFlow: r
  } = R(P), a = K(() => t ? [t] : [], [t]);
  return ee(r, a, !0);
}
function Fr() {
  const {
    eventDefine: t
  } = R(P), r = K(() => [], []);
  return ee(t, r, !0);
}
const gt = Le({
  id: "",
  exportAttr: () => {
  },
  exportEvent: () => {
  },
  updateProps: () => {
  }
});
function Gr({
  id: t,
  children: r
}) {
  const {
    variableStore: a,
    state: n
  } = R(P), s = oe((l, p) => {
    typeof l == "object" ? a.updateValueByPath([...Q, t], l) : a.updateValueByPath([...Q, t, l], p);
  }, [t, a]), i = oe((l, p) => {
    typeof l == "object" ? a.updateValueByPath([...Ae, t], l) : a.updateValueByPath([...Ae, t, l], p);
  }, [t, a]), c = oe((l, p) => {
    n.updateValue((f) => {
      const y = f.elementMap[t];
      y && (y.props = typeof l == "object" ? l : {
        ...n.getValue(["elementMap", t, "props"]),
        [l]: p
      });
    });
  }, [t]), d = K(() => ({
    id: t,
    exportAttr: s,
    exportEvent: i,
    updateProps: c
  }), [t]);
  return /* @__PURE__ */ pe.jsx(gt.Provider, {
    value: d,
    children: r
  });
}
function Nr() {
  return R(gt);
}
export {
  he as COMPONENT_EVENT,
  Ae as COMPONENT_EXPORT_EVENT_PREFIX,
  Q as COMPONENT_EXPORT_VARIABLE_PREFIX,
  ie as COMPONENT_VARIABLE,
  Gr as ElementProvider,
  Ee as GLOBAL_VARIABLE,
  Re as GLOBAL_VARIABLE_PREFIX,
  q as SLOT_VARIABLE,
  pt as SLOT_VARIABLE_PREFIX,
  Mr as SlotProvider,
  dr as StoreProvider,
  Zt as computedDefine,
  Z as fillVariableApiName,
  zt as getDefaultGlobalStyleVarGroup,
  dt as getEditorStyleDefaultValue,
  or as getElementVariable,
  pr as getMethodFromStore,
  fr as getValueByPath,
  cr as isEditor,
  ut as isOffspring,
  Ht as isRefVariableDefine,
  ar as needRecomputedDefineWhenUpdateState,
  tr as parseEvent,
  Ar as useActiveGlobalStyleVarGroup,
  wr as useAddGlobalVariable,
  Er as useChangeModalVisible,
  Rr as useElement,
  Nr as useElementContext,
  jr as useEnv,
  Fr as useEventDefine,
  Ir as useEventFlow,
  Or as useGetModalContainer,
  kr as useGlobalClassName,
  Lr as useGlobalStyleVarGroup,
  xr as useGlobalVariable,
  _r as useInsertElement,
  Pr as useInsertModal,
  gr as useRemoveElement,
  hr as useRemoveModal,
  vr as useRootId,
  mt as useSlotContext,
  br as useStateById,
  mr as useStateValue,
  Vr as useStore,
  Cr as useUpdateGlobalVariable,
  yr as useUpdateStore,
  Dr as useVariableDefine,
  Tr as useVariableValue,
  Sr as useVisibleModals
};
