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