ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
123 lines (122 loc) • 3.65 kB
JavaScript
import { inject as A, shallowRef as C, getCurrentInstance as T, defineComponent as g, h as P, watch as v, unref as d, provide as x } from "vue";
import b from "./Cache.mjs";
import { withInstall as I, arrayType as u, booleanType as l, someType as E, stringType as f, objectType as N } from "../type.mjs";
import { StyleProvider as j } from "ant-design-vue";
const q = "data-token-hash", h = "data-css-hash", D = "data-cache-path", i = "__cssinjs_instance__";
function s() {
const e = Math.random().toString(12).slice(2);
if (typeof document < "u" && document.head && document.body) {
const o = document.body.querySelectorAll(`style[${h}]`) || [], {
firstChild: n
} = document.head;
Array.from(o).forEach((t) => {
t[i] = t[i] || e, t[i] === e && document.head.insertBefore(t, n);
});
const r = {};
Array.from(document.querySelectorAll(`style[${h}]`)).forEach((t) => {
var a;
const c = t.getAttribute(h);
r[c] ? t[i] === e && ((a = t.parentNode) == null || a.removeChild(t)) : r[c] = !0;
});
}
return new b(e);
}
const p = Symbol("StyleContextKey"), w = () => {
var n, r, t;
const e = T();
let o;
if (e && e.appContext) {
const c = (t = (r = (n = e.appContext) == null ? void 0 : n.config) == null ? void 0 : r.globalProperties) == null ? void 0 : t.__ANTDV_CSSINJS_CACHE__;
c ? o = c : (o = s(), e.appContext.config.globalProperties && (e.appContext.config.globalProperties.__ANTDV_CSSINJS_CACHE__ = o));
} else
o = s();
return o;
}, m = {
cache: s(),
defaultCache: !0,
hashPriority: "low"
}, y = () => {
const e = w();
return A(p, C({
...m,
cache: e
}));
}, S = (e) => {
const o = y(), n = C({
...m,
cache: s()
});
return v([() => d(e), o], () => {
const r = {
...o.value
}, t = d(e);
Object.keys(t).forEach((a) => {
const _ = t[a];
t[a] !== void 0 && (r[a] = _);
});
const {
cache: c
} = t;
r.cache = r.cache || s(), r.defaultCache = !c && o.value.defaultCache, n.value = r;
}, {
immediate: !0
}), x(p, n), n;
}, H = () => ({
autoClear: l(),
/** @private Test only. Not work in production. */
mock: f(),
/**
* Only set when you need ssr to extract style on you own.
* If not provided, it will auto create <style /> on the end of Provider in server side.
*/
cache: N(),
/** Tell children that this context is default generated context */
defaultCache: l(),
/** Use `:where` selector to reduce hashId css selector priority */
hashPriority: f(),
/** Tell cssinjs where to inject style in */
container: E(),
/** Component wil render inline `<style />` for fallback in SSR. Not recommend. */
ssrInline: l(),
/** Transform css before inject in document. Please note that `transformers` do not support dynamic update */
transformers: u(),
/**
* Linters to lint css before inject in document.
* Styles will be linted after transforming.
* Please note that `linters` do not support dynamic update.
*/
linters: u()
}), R = I(/* @__PURE__ */ g({
name: "AXStyleProvider",
inheritAttrs: !1,
props: H(),
setup(e, {
slots: o
}) {
return S(e), () => P(
j,
// @ts-ignore
e,
() => {
var n;
return (n = o.default) == null ? void 0 : n.call(o);
}
);
}
})), M = {
useStyleInject: y,
useStyleProvider: S,
StyleProvider: R
};
export {
D as ATTR_CACHE_PATH,
h as ATTR_MARK,
q as ATTR_TOKEN,
i as CSS_IN_JS_INSTANCE,
R as StyleProvider,
s as createCache,
M as default,
H as styleProviderProps,
y as useStyleInject,
S as useStyleProvider
};