UNPKG

@aplus-frontend/ui

Version:

69 lines (68 loc) 2.03 kB
import { ref as T, computed as a, watch as f } from "vue"; import { injectGlobal as g, cx as S } from "@emotion/css"; import b from "@emotion/css/create-instance"; import { useToken as V } from "../../config-provider/hooks/use-token.mjs"; import "../../config-provider/index.mjs"; import { camelToKebab as w, generateCssVar as A } from "./utils.mjs"; import { omit as C, isFunction as h } from "lodash-unified"; import { css as j } from "./instance.mjs"; import { downSpecificityPlugin as G } from "./plugin-specificity.mjs"; import { TokenUtil as P } from "./TokenUtil.mjs"; import { useGlobalConfig as x } from "../../config-provider/hooks/use-global-config.mjs"; const { css: L } = b({ key: "css-dev-only", stylisPlugins: [G] }); function E(l) { const t = {}; for (const n in l) t[n] = `var(${w(n)})`; return t; } function M(l, t, n, d) { return (s) => { const p = l.split("."), { token: c, rootCls: u } = V(), k = T(), m = x("namespace"), $ = a(() => ({ ...C(c.value || {}, "components"), ...c.value.components?.[p[0]] || {} })), i = a(() => { const e = c.value.components?.[p[0]] || {}; return { ...h(n) ? n($.value) : n || {}, ...e }; }), v = a(() => ({ ...C(c.value || {}, "components"), ...i.value, componentCls: `.${m.value}-${s}`, namespace: m.value })); return f( () => m.value, (e) => { const o = E( v.value ); o.componentCls = `.${e}-${s}`, o.namespace = e, o.calc = (y) => new P(y); const r = t(o, { ...v.value, componentCls: `.${e}-${s}`, namespace: e }); g(r); }, { immediate: !0 } ), f( [() => i.value, () => u.value], ([e, o]) => { const r = A(e, d); Object.keys(r).length && j({ [`.${o}.${m.value}-${s}`]: r }); }, { deep: !0, immediate: !0 } ), a(() => S(u.value, k.value)); }; } export { M as genComponentStyleHook };