import L from"../../../../node_modules/.pnpm/@emotion_hash@0.9.2/node_modules/@emotion/hash/dist/emotion-hash.esm.mjs";import M from"../../../../node_modules/.pnpm/@emotion_unitless@0.10.0/node_modules/@emotion/unitless/dist/emotion-unitless.esm.mjs";import{computed as I}from"vue";import K from"../../../canUseDom.mjs";import{removeCSS as q,updateCSS as x}from"../../../../vc-util/Dom/dynamicCSS.mjs";import{useStyleInject as U,CSS_IN_JS_INSTANCE as W,ATTR_TOKEN as z,ATTR_MARK as P}from"../../StyleContext.mjs";import{supportLayer as D}from"../../util.mjs";import J from"../useGlobalCache.mjs";import{existPath as Q,getStyleAndHash as Z,ATTR_CACHE_MAP as T,serialize as B}from"./cacheMapUtil.mjs";import{serialize as F,stringify as G}from"../../../../node_modules/.pnpm/stylis@4.3.6/node_modules/stylis/src/Serializer.mjs";import{compile as V}from"../../../../node_modules/.pnpm/stylis@4.3.6/node_modules/stylis/src/Parser.mjs";const H=K(),X="_skip_check_",R="_multi_value_";function b(e){return F(V(e),G).replace(/\{%%%:[^;];\}/g,";")}function Y(e){return typeof e=="object"&&e&&(X in e||R in e)}function ee(e,f,y){if(!f)return e;const p=`.${f}`,S=y==="low"?`:where(${p})`:p;return e.split(",").map(a=>{const d=a.trim().split(/\s+/);let j=d[0]||"";const t=j.match(/^\w+/)?.[0]||"";return j=`${t}${S}${j.slice(t.length)}`,[j,...d.slice(1)].join(" ")}).join(",")}const O=new Set,k=(e,f={},{root:y,injectHash:p,parentSelectors:S}={root:!0,parentSelectors:[]})=>{const{hashId:m,layer:a,path:d,hashPriority:j,transformers:t=[],linters:v=[]}=f;let o="",u={};function _(r){const n=r.getName(m);if(!u[n]){const[l]=k(r.style,f,{root:!1,parentSelectors:S});u[n]=`@keyframes ${r.getName(m)}${l}`}}function g(r,n=[]){return r.forEach(l=>{Array.isArray(l)?g(l,n):l&&n.push(l)}),n}if(g(Array.isArray(e)?e:[e]).forEach(r=>{const n=typeof r=="string"&&!y?{}:r;if(typeof n=="string")o+=`${n}
`;else if(n._keyframe)_(n);else{const l=t.reduce((h,s)=>s?.visit?.(h)||h,n);Object.keys(l).forEach(h=>{const s=l[h];if(typeof s=="object"&&s&&(h!=="animationName"||!s._keyframe)&&!Y(s)){let E=!1,i=h.trim(),c=!1;(y||p)&&m?i.startsWith("@")?E=!0:i=ee(h,m,j):y&&!m&&(i==="&"||i==="")&&(i="",c=!0);const[$,N]=k(s,f,{root:c,injectHash:E,parentSelectors:[...S,i]});u={...u,...N},o+=`${i}${$}`}else{let E=function(c,$){const N=c.replace(/[A-Z]/g,w=>`-${w.toLowerCase()}`);let C=$;!M[c]&&typeof C=="number"&&C!==0&&(C=`${C}px`),c==="animationName"&&$?._keyframe&&(_($),C=$.getName(m)),o+=`${N}:${C};`};const i=s?.value??s;typeof s=="object"&&s?.[R]&&Array.isArray(i)?i.forEach(c=>{E(h,c)}):E(h,i)}})}}),!y)o=`{${o}}`;else if(a&&D()){const r=a.split(",");o=`@layer ${r[r.length-1].trim()} {${o}}`,r.length>1&&(o=`@layer ${a}{%%%:%}${o}`)}return[o,u]};function te(e,f){return L(`${e.join("%")}${f}`)}function me(e,f){const y=U(),p=I(()=>e.value.token._tokenKey),S=I(()=>[p.value,...e.value.path]);let m=H;return J("style",S,()=>{const{path:a,hashId:d,layer:j,nonce:t,clientOnly:v,order:o=0}=e.value,u=S.value.join("|");if(Q(u)){const[c,$]=Z(u);if(c)return[c,p.value,$,{},v,o]}const _=f(),{hashPriority:g,container:A,transformers:r,linters:n,cache:l}=y.value,[h,s]=k(_,{hashId:d,hashPriority:g,layer:j,path:a.join("-"),transformers:r,linters:n}),E=b(h),i=te(S.value,E);if(m){const c={mark:P,prepend:"queue",attachTo:A},$=typeof t=="function"?t():t;$&&(c.csp={nonce:$});const N=x(E,i,c);N[W]=l.instanceId,N.setAttribute(z,p.value),Object.keys(s).forEach(C=>{O.has(C)||(O.add(C),x(b(s[C]),`_effect-${C}`,{mark:P,prepend:"queue",attachTo:A}))})}return[E,p.value,i,s,v,o]},([,,a],d)=>{(d||y.value.autoClear)&&H&&q(a,{mark:P})}),a=>a}function he(e,f=!1){const y="style%",p=Array.from(e.cache.keys()).filter(t=>t.startsWith(y)),S={},m={};let a="";function d(t,v,o,u={}){const _={...u,[z]:v,[P]:o},g=Object.keys(_).map(A=>{const r=_[A];return r?`${A}="${r}"`:null}).filter(A=>A).join(" ");return f?t:`<style ${g}>${t}</style>`}return p.map(t=>{const v=t.slice(y.length).replace(/%/g,"|"),[o,u,_,g,A,r]=e.cache.get(t)[1];if(A)return null;const n={"data-vc-order":"prependQueue","data-vc-priority":`${r}`};let l=d(o,u,_,n);return m[v]=_,g&&Object.keys(g).forEach(s=>{S[s]||(S[s]=!0,l+=d(b(g[s]),u,`_effect-${s}`,n))}),[r,l]}).filter(t=>t).sort((t,v)=>t[0]-v[0]).forEach(([,t])=>{a+=t}),a+=d(`.${T}{content:"${B(m)}";}`,void 0,void 0,{[T]:T}),a}export{me as default,he as extractStyle,b as normalizeStyle,k as parseStyle};
