import g from"../../../node_modules/.pnpm/@emotion_hash@0.9.2/node_modules/@emotion/hash/dist/emotion-hash.esm.mjs";import{computed as u,ref as y}from"vue";import{useStyleInject as p,ATTR_TOKEN as S,CSS_IN_JS_INSTANCE as C}from"../StyleContext.mjs";import{flattenToken as f,token2key as E}from"../util.mjs";import _ from"./useGlobalCache.mjs";const k={},I="css",c=new Map;function K(e){c.set(e,(c.get(e)||0)+1)}function N(e,r){typeof document<"u"&&document.querySelectorAll(`style[${S}="${e}"]`).forEach(t=>{t[C]===r&&t.parentNode?.removeChild(t)})}const D=0;function O(e,r){c.set(e,(c.get(e)||0)-1);const o=Array.from(c.keys()),t=o.filter(n=>(c.get(n)||0)<=0);o.length-t.length>D&&t.forEach(n=>{N(n,r),c.delete(n)})}const A=(e,r,o,t)=>{let s={...o.getDerivativeToken(e),...r};return t&&(s=t(s)),s};function H(e,r,o=y({})){const t=p(),n=u(()=>Object.assign({},...r.value)),s=u(()=>f(n.value)),m=u(()=>f(o.value.override||k));return _("token",u(()=>[o.value.salt||"",e.value.id,s.value,m.value]),()=>{const{salt:l="",override:v=k,formatToken:h,getComputedToken:d}=o.value,a=d?d(n.value,v,e.value):A(n.value,v,e.value,h),i=E(a,l);a._tokenKey=i,K(i);const T=`${I}-${g(i)}`;return a._hashId=T,[a,T]},l=>{O(l[0]._tokenKey,t.value?.cache.instanceId)})}export{H as default,A as getComputedToken};
