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