import{inject as _,shallowRef as p,getCurrentInstance as S,defineComponent as A,watch as g,unref as u,provide as T}from"vue";import{withInstall as b,arrayType as d,booleanType as l,someType as x,stringType as f,objectType as v}from"../type.mjs";import I from"./Cache.mjs";const H="data-token-hash",h="data-css-hash",s="__cssinjs_instance__";function r(){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[s]=t[s]||e,t[s]===e&&document.head.insertBefore(t,n)});const c={};Array.from(document.querySelectorAll(`style[${h}]`)).forEach(t=>{const a=t.getAttribute(h);c[a]?t[s]===e&&t.parentNode?.removeChild(t):c[a]=!0})}return new I(e)}const C=Symbol("StyleContextKey"),P=()=>{const e=S();let o;if(e&&e.appContext){const n=e.appContext?.config?.globalProperties?.__ANTDV_CSSINJS_CACHE__;n?o=n:(o=r(),e.appContext.config.globalProperties&&(e.appContext.config.globalProperties.__ANTDV_CSSINJS_CACHE__=o))}else o=r();return o},m={cache:r(),defaultCache:!0,hashPriority:"low"},N=()=>{const e=P();return _(C,p({...m,cache:e}))},E=e=>{const o=N(),n=p({...m,cache:r()});return g([()=>u(e),o],()=>{const c={...o.value},t=u(e);Object.keys(t).forEach(i=>{const y=t[i];t[i]!==void 0&&(c[i]=y)});const{cache:a}=t;c.cache=c.cache||r(),c.defaultCache=!a&&o.value.defaultCache,n.value=c},{immediate:!0}),T(C,n),n},j=()=>({autoClear:l(),mock:f(),cache:v(),defaultCache:l(),hashPriority:f(),container:x(),ssrInline:l(),transformers:d(),linters:d()}),J=b(A({name:"AStyleProvider",inheritAttrs:!1,props:j(),setup(e,{slots:o}){return E(e),()=>o.default?.()}}));export{h as ATTR_MARK,H as ATTR_TOKEN,s as CSS_IN_JS_INSTANCE,J as StyleProvider,r as createCache,j as styleProviderProps,N as useStyleInject,E as useStyleProvider};
