ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
58 lines (57 loc) • 1.82 kB
JavaScript
import { m as y } from "../../../chunks/module-chunk.mjs";
import { useStyleInject as p, ATTR_TOKEN as S, CSS_IN_JS_INSTANCE as h } from "../StyleContext.mjs";
import C from "./useGlobalCache.mjs";
import { flattenToken as f, token2key as E } from "../util.mjs";
import { ref as _, computed as i } from "vue";
const k = {}, I = "css", a = /* @__PURE__ */ new Map();
function K(e) {
a.set(e, (a.get(e) || 0) + 1);
}
function N(e, s) {
typeof document < "u" && document.querySelectorAll(`style[${S}="${e}"]`).forEach((n) => {
var t;
n[h] === s && ((t = n.parentNode) == null || t.removeChild(n));
});
}
const D = 0;
function O(e, s) {
a.set(e, (a.get(e) || 0) - 1);
const o = Array.from(a.keys()), n = o.filter((t) => (a.get(t) || 0) <= 0);
o.length - n.length > D && n.forEach((t) => {
N(t, s), a.delete(t);
});
}
const A = (e, s, o, n) => {
let u = {
...o == null ? void 0 : o.getDerivativeToken(e),
...s
};
return n && (u = n(u)), u;
};
function H(e, s, o = _({})) {
const n = p(), t = i(() => Object.assign({}, ...s.value || [])), u = i(() => f(t.value)), m = i(() => {
var r;
return f(((r = o.value) == null ? void 0 : r.override) || k);
});
return C("token", i(() => {
var r, c;
return [((r = o.value) == null ? void 0 : r.salt) || "", (c = e.value) == null ? void 0 : c.id, u.value, m.value];
}), () => {
const {
salt: r = "",
override: c = k,
formatToken: g,
getComputedToken: d
} = o.value || {}, l = d ? d(t.value, c, e.value) : A(t.value, c, e.value, g), v = E(l, r);
l._tokenKey = v, K(v);
const T = `${I}-${y(v)}`;
return l._hashId = T, [l, T];
}, (r) => {
var c;
O(r[0]._tokenKey, (c = n.value) == null ? void 0 : c.cache.instanceId);
});
}
export {
H as default,
A as getComputedToken
};