@unocss/runtime 0.51.6 → 0.51.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core.global.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";(()=>{function Re(t){let e=t.length,r=-1,n,s="",i=t.charCodeAt(0);for(;++r<e;){if(n=t.charCodeAt(r),n===0){s+="\uFFFD";continue}if(n===44){s+="\\,";continue}if(n>=1&&n<=31||n===127||r===0&&n>=48&&n<=57||r===1&&n>=48&&n<=57&&i===45){s+=`\\${n.toString(16)} `;continue}if(r===0&&e===1&&n===45){s+=`\\${t.charAt(r)}`;continue}if(n>=128||n===45||n===95||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122){s+=t.charAt(r);continue}s+=`\\${t.charAt(r)}`}return s}var H=Re;function A(t=[]){return Array.isArray(t)?t:[t]}function D(t){return Array.from(new Set(t))}function R(t){return typeof t=="string"}function j(t){return R(t)?t:(Array.isArray(t)?t:Object.entries(t)).filter(e=>e[1]!=null)}function ee(t){return Array.isArray(t)?t.find(e=>!Array.isArray(e)||Array.isArray(e[0]))?t.map(e=>j(e)):[t]:[j(t)]}function be(t){return t.filter(([e,r],n)=>{if(e.startsWith("$$"))return!1;for(let s=n-1;s>=0;s--)if(t[s][0]===e&&t[s][1]===r)return!1;return!0})}function F(t){return t==null?"":be(t).map(([e,r])=>r!=null?`${e}:${r};`:void 0).filter(Boolean).join("")}function G(t){return t&&typeof t=="object"&&!Array.isArray(t)}function Y(t,e,r=!1){let n=t,s=e;if(Array.isArray(s))return r&&Array.isArray(s)?[...n,...s]:[...s];let i={...n};return G(n)&&G(s)&&Object.keys(s).forEach(o=>{G(n[o])&&G(s[o])||Array.isArray(n[o])&&Array.isArray(s[o])?i[o]=Y(n[o],s[o],r):Object.assign(i,{[o]:s[o]})}),i}function k(t){let e,r,n;if(Array.isArray(t)){for(r=Array(e=t.length);e--;)r[e]=(n=t[e])&&typeof n=="object"?k(n):n;return r}if(Object.prototype.toString.call(t)==="[object Object]"){r={};for(e in t)e==="__proto__"?Object.defineProperty(r,e,{value:k(t[e]),configurable:!0,enumerable:!0,writable:!0}):r[e]=(n=t[e])&&typeof n=="object"?k(n):n;return r}return t}function te(t){return R(t[0])}function re(t){return R(t[0])}var q="$$shortcut-no-merge";function ne(t){return typeof t=="function"?{match:t}:t}function Z(t){return t.length===3}function se(t){return t!=null}function ie(){}var B=class{_map=new Map;get(e,r){let n=this._map.get(e);if(n)return n.get(r)}getFallback(e,r,n){let s=this._map.get(e);return s||(s=new Map,this._map.set(e,s)),s.has(r)||s.set(r,n),s.get(r)}set(e,r,n){let s=this._map.get(e);return s||(s=new Map,this._map.set(e,s)),s.set(r,n),this}has(e,r){return this._map.get(e)?.has(r)}delete(e,r){return this._map.get(e)?.delete(r)||!1}deleteTop(e){return this._map.delete(e)}map(e){return Array.from(this._map.entries()).flatMap(([r,n])=>Array.from(n.entries()).map(([s,i])=>e(i,r,s)))}};var z={};function ve(t=["-",":"]){let e=t.join("|");return z[e]||(z[e]=new RegExp(`((?:[!@\\w+:_/-]|\\[&?>?:?\\S*\\])+?)(${e})\\(((?:[~!<>\\w\\s:/\\\\,%#.$?-]|\\[.*?\\])+?)\\)(?!\\s*?=>)`,"gm")),z[e].lastIndex=0,z[e]}function we(t,e=["-",":"],r=5){let n=ve(e),s=!1,i=t.toString(),o=new Set;do{let l=i;i=i.replace(n,(f,u,c,d)=>e.includes(c)?(o.add(u+c),d.split(/\s/g).filter(Boolean).map(y=>y==="~"?u:y.replace(/^(!?)(.*)/,`$1${u}${c}$2`)).join(" ")):f),s=i!==l,r-=1}while(s&&r);return{prefixes:Array.from(o),expanded:i,hasChanged:s}}function oe(t,e=["-",":"],r=5){let{expanded:n}=we(t.toString(),e,r);return typeof t=="string"?n:t.length()?t.overwrite(0,t.length(),n):t}var ae=new Set;function ce(t){ae.has(t)||(console.warn("[unocss]",t),ae.add(t))}var le=/[\\:]?[\s'"`;{}]+/g;function Ae(t){return[...new Set(t.split(le))]}var I={name:"@unocss/core/extractor-split",order:0,extract({code:t}){return Ae(t)}};function ue(){return{events:{},emit(t,...e){(this.events[t]||[]).forEach(r=>r(...e))},on(t,e){return(this.events[t]=this.events[t]||[]).push(e),()=>this.events[t]=(this.events[t]||[]).filter(r=>r!==e)}}}var N="default",W="preflights",Ue="shortcuts",fe={[W]:-100,[Ue]:-10,[N]:0};function de(t){return A(t).flatMap(e=>Array.isArray(e)?[e]:Object.entries(e))}var pe="_uno_resolved";function Me(t){if(pe in t)return t;t={...t},Object.defineProperty(t,pe,{value:!0,enumerable:!1});let e=t.shortcuts?de(t.shortcuts):void 0;if(t.shortcuts=e,t.prefix||t.layer){let r=n=>{n[2]||(n[2]={});let s=n[2];s.prefix==null&&t.prefix&&(s.prefix=A(t.prefix)),s.layer==null&&t.layer&&(s.layer=t.layer)};e?.forEach(r),t.rules?.forEach(r)}return t}function he(t){let e=Me(t);if(!e.presets)return[e];let r=(e.presets||[]).flatMap(A).flatMap(he);return[e,...r]}function J(t={},e={}){let r=Object.assign({},e,t),n=D((r.presets||[]).flatMap(A).flatMap(he)),s=[...n.filter(a=>a.enforce==="pre"),...n.filter(a=>!a.enforce),...n.filter(a=>a.enforce==="post")],i=[...s,r],o=[...i].reverse(),l=Object.assign({},fe,...i.map(a=>a.layers));function f(a){return D(i.flatMap(g=>A(g[a]||[])))}let u=f("extractors"),c=o.find(a=>a.extractorDefault!==void 0)?.extractorDefault;c===void 0&&(c=I),c&&!u.includes(c)&&u.unshift(c),u.sort((a,g)=>(a.order||0)-(g.order||0));let d=f("rules"),y={},T=d.length,v=d.map((a,g)=>{if(te(a)){A(a[2]?.prefix||"").forEach(U=>{y[U+a[0]]=[g,a[1],a[2],a]});return}return[g,...a]}).filter(Boolean).reverse(),w=i.map(a=>a.theme?k(a.theme):{}).reduce((a,g)=>Y(a,g),{}),S=f("extendTheme");for(let a of S)w=a(w)||w;let E={templates:D(i.flatMap(a=>A(a.autocomplete?.templates))),extractors:i.flatMap(a=>A(a.autocomplete?.extractors)).sort((a,g)=>(a.order||0)-(g.order||0))},C=f("separators");C.length||(C=[":","-"]);let h={mergeSelectors:!0,warn:!0,blocklist:[],sortLayers:a=>a,...r,presets:s,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:l,theme:w,rulesSize:T,rulesDynamic:v,rulesStaticMap:y,preprocess:f("preprocess"),postprocess:f("postprocess"),preflights:f("preflights"),autocomplete:E,variants:f("variants").map(ne).sort((a,g)=>(a.order||0)-(g.order||0)),shortcuts:de(f("shortcuts")).reverse(),extractors:u,safelist:f("safelist"),separators:C};for(let a of i)a?.configResolved?.(h);return h}var me="0.51.6";var Q=class{constructor(e={},r={}){this.userConfig=e;this.defaults=r;this.config=J(e,r),this.events.emit("config",this.config)}version=me;_cache=new Map;config;blocked=new Set;parentOrders=new Map;events=ue();setConfig(e,r){e&&(r&&(this.defaults=r),this.userConfig=e,this.blocked.clear(),this.parentOrders.clear(),this._cache.clear(),this.config=J(e,this.defaults),this.events.emit("config",this.config))}async applyExtractors(e,r,n=new Set){let s={original:e,code:e,id:r,extracted:n};for(let i of this.config.extractors){let o=await i.extract?.(s);if(o)for(let l of o)n.add(l)}return n}makeContext(e,r){let n={rawSelector:e,currentSelector:r[1],theme:this.config.theme,generator:this,variantHandlers:r[2],constructCSS:(...s)=>this.constructCustomCSS(n,...s),variantMatch:r};return n}async parseToken(e,r){if(this.blocked.has(e))return;let n=`${e}${r?` ${r}`:""}`;if(this._cache.has(n))return this._cache.get(n);let s=e;for(let u of this.config.preprocess)s=u(e);if(this.isBlocked(s)){this.blocked.add(e),this._cache.set(n,null);return}let i=await this.matchVariants(e,s);if(!i||this.isBlocked(i[1])){this.blocked.add(e),this._cache.set(n,null);return}let o=this.makeContext(e,[r||i[0],i[1],i[2],i[3]]);this.config.details&&(o.variants=[...i[3]]);let l=await this.expandShortcut(o.currentSelector,o),f=l?await this.stringifyShortcuts(o.variantMatch,o,l[0],l[1]):(await this.parseUtil(o.variantMatch,o))?.map(u=>this.stringifyUtil(u,o)).filter(se);if(f?.length)return this._cache.set(n,f),f;this._cache.set(n,null)}async generate(e,r={}){let{id:n,scope:s,preflights:i=!0,safelist:o=!0,minify:l=!1}=r,f=R(e)?await this.applyExtractors(e,n):Array.isArray(e)?new Set(e):e;o&&this.config.safelist.forEach(h=>f.add(h));let u=l?"":`
2
- `,c=new Set([N]),d=new Set,y=new Map,T={},v=Array.from(f).map(async h=>{if(d.has(h))return;let a=await this.parseToken(h);if(a!=null){d.add(h);for(let g of a){let b=g[3]||"",U=g[4]?.layer;y.has(b)||y.set(b,[]),y.get(b).push(g),U&&c.add(U)}}});await Promise.all(v),await(async()=>{if(!i)return;let h={generator:this,theme:this.config.theme},a=new Set([]);this.config.preflights.forEach(({layer:g=W})=>{c.add(g),a.add(g)}),T=Object.fromEntries(await Promise.all(Array.from(a).map(async g=>{let U=(await Promise.all(this.config.preflights.filter(_=>(_.layer||W)===g).map(async _=>await _.getCSS(h)))).filter(Boolean).join(u);return[g,U]})))})();let w=this.config.sortLayers(Array.from(c).sort((h,a)=>(this.config.layers[h]??0)-(this.config.layers[a]??0)||h.localeCompare(a))),S={},E=h=>{if(S[h])return S[h];let a=Array.from(y).sort((b,U)=>(this.parentOrders.get(b[0])??0)-(this.parentOrders.get(U[0])??0)||b[0]?.localeCompare(U[0]||"")||0).map(([b,U])=>{let _=U.length,L=U.filter(p=>(p[4]?.layer||N)===h).sort((p,x)=>p[0]-x[0]||(p[4]?.sort||0)-(x[4]?.sort||0)||p[5]?.currentSelector?.localeCompare(x[5]?.currentSelector??"")||p[1]?.localeCompare(x[1]||"")||p[2]?.localeCompare(x[2]||"")||0).map(([,p,x,,M,,V])=>[[[(p&&Oe(p,s))??"",M?.sort??0]],x,!!(V??M?.noMerge)]);if(!L.length)return;let K=L.reverse().map(([p,x,M],V)=>{if(!M&&this.config.mergeSelectors)for(let P=V+1;P<_;P++){let $=L[P];if($&&!$[2]&&(p&&$[0]||p==null&&$[0]==null)&&$[1]===x)return p&&$[0]&&$[0].push(...p),null}let O=p?D(p.sort((P,$)=>P[1]-$[1]||P[0]?.localeCompare($[0]||"")||0).map(P=>P[0]).filter(Boolean)):[];return O.length?`${O.join(`,${u}`)}{${x}}`:x}).filter(Boolean).reverse().join(u);if(!b)return K;let m=b.split(" $$ ");return`${m.join("{")}{${u}${K}${u}}${m.map(p=>"").join("}")}`}).filter(Boolean).join(u);i&&(a=[T[h],a].filter(Boolean).join(u));let g=l?"":`/* layer: ${h} */${u}`;return S[h]=a?g+a:""},C=(h=w,a)=>h.filter(g=>!a?.includes(g)).map(g=>E(g)||"").filter(Boolean).join(u);return{get css(){return C()},layers:w,matched:d,getLayers:C,getLayer:E}}async matchVariants(e,r){let n=new Set,s=[],i=r||e,o=!1,l={rawSelector:e,theme:this.config.theme,generator:this};for(;;){o=!1;for(let f of this.config.variants){if(!f.multiPass&&n.has(f))continue;let u=await f.match(i,l);if(u){R(u)&&(u={matcher:u}),i=u.matcher,s.unshift(u),n.add(f),o=!0;break}}if(!o)break;if(s.length>500)throw new Error(`Too many variants applied to "${e}"`)}return[e,i,s,n]}applyVariants(e,r=e[4],n=e[1]){let i=r.slice().sort((u,c)=>(u.order||0)-(c.order||0)).reduceRight((u,c)=>d=>{let y=c.body?.(d.entries)||d.entries,T=Array.isArray(c.parent)?c.parent:[c.parent,void 0];return(c.handle??De)({...d,entries:y,selector:c.selector?.(d.selector,y)||d.selector,parent:T[0]||d.parent,parentOrder:T[1]||d.parentOrder,layer:c.layer||d.layer,sort:c.sort||d.sort},u)},u=>u)({prefix:"",selector:Pe(n),pseudo:"",entries:e[2]}),{parent:o,parentOrder:l}=i;o!=null&&l!=null&&this.parentOrders.set(o,l);let f={selector:[i.prefix,i.selector,i.pseudo].join(""),entries:i.entries,parent:o,layer:i.layer,sort:i.sort,noMerge:i.noMerge};for(let u of this.config.postprocess)u(f);return f}constructCustomCSS(e,r,n){let s=j(r);if(R(s))return s;let{selector:i,entries:o,parent:l}=this.applyVariants([0,n||e.rawSelector,s,void 0,e.variantHandlers]),f=`${i}{${F(o)}}`;return l?`${l}{${f}}`:f}async parseUtil(e,r,n=!1,s){let[i,o,l]=R(e)?await this.matchVariants(e):e;this.config.details&&(r.rules=r.rules??[]);let f=this.config.rulesStaticMap[o];if(f&&f[1]&&(n||!f[2]?.internal)){this.config.details&&r.rules.push(f[3]);let c=f[0],d=j(f[1]),y=f[2];return R(d)?[[c,d,y]]:[[c,i,d,y,l]]}r.variantHandlers=l;let{rulesDynamic:u}=this.config;for(let[c,d,y,T]of u){if(T?.internal&&!n)continue;let v=o;if(T?.prefix){let C=A(T.prefix);if(s){let h=A(s);if(!C.some(a=>h.includes(a)))continue}else{let h=C.find(a=>o.startsWith(a));if(h==null)continue;v=o.slice(h.length)}}let w=v.match(d);if(!w)continue;let S=await y(w,r);if(!S)continue;this.config.details&&r.rules.push([d,y,T]);let E=ee(S).filter(C=>C.length);if(E.length)return E.map(C=>R(C)?[c,C,T]:[c,i,C,T,l])}}stringifyUtil(e,r){if(!e)return;if(Z(e))return[e[0],void 0,e[1],void 0,e[2],this.config.details?r:void 0,void 0];let{selector:n,entries:s,parent:i,layer:o,sort:l,noMerge:f}=this.applyVariants(e),u=F(s);if(!u)return;let{layer:c,sort:d,...y}=e[3]??{},T={...y,layer:o??c,sort:l??d};return[e[0],n,u,i,T,this.config.details?r:void 0,f]}async expandShortcut(e,r,n=5){if(n===0)return;let s=this.config.details?l=>{r.shortcuts=r.shortcuts??[],r.shortcuts.push(l)}:ie,i,o;for(let l of this.config.shortcuts){let f=e;if(l[2]?.prefix){let c=A(l[2].prefix).find(d=>e.startsWith(d));if(c==null)continue;f=e.slice(c.length)}if(re(l)){if(l[0]===f){i=i||l[2],o=l[1],s(l);break}}else{let u=f.match(l[0]);if(u&&(o=l[1](u,r)),o){i=i||l[2],s(l);break}}}if(R(o)&&(o=oe(o.trim()).split(/\s+/g)),!o){let[l,f]=R(e)?await this.matchVariants(e):e;if(l!==f){let u=await this.expandShortcut(f,r,n-1);u&&(o=u[0].map(c=>R(c)?l.replace(f,c):c))}}if(o)return[(await Promise.all(o.map(async l=>(R(l)?(await this.expandShortcut(l,r,n-1))?.[0]:void 0)||[l]))).flat(1).filter(Boolean),i]}async stringifyShortcuts(e,r,n,s={layer:this.config.shortcutsLayer}){let i=new B,o=(await Promise.all(D(n).map(async c=>{let d=R(c)?await this.parseUtil(c,r,!0,s.prefix):[[1/0,"{inline}",j(c),void 0,[]]];return d||ce(`unmatched utility "${c}" in shortcut "${e[1]}"`),d||[]}))).flat(1).filter(Boolean).sort((c,d)=>c[0]-d[0]),[l,,f]=e,u=[];for(let c of o){if(Z(c)){u.push([c[0],void 0,c[1],void 0,c[2],r,void 0]);continue}let{selector:d,entries:y,parent:T,sort:v,noMerge:w}=this.applyVariants(c,[...c[4],...f],l);i.getFallback(d,T,[[],c[0]])[0].push([y,!!(w??c[3]?.noMerge),v??0])}return u.concat(i.map(([c,d],y,T)=>{let v=(S,E,C)=>{let h=Math.max(...C.map(g=>g[1])),a=C.map(g=>g[0]);return(S?[a.flat(1)]:a).map(g=>{let b=F(g);if(b)return[d,y,b,T,{...s,noMerge:E,sort:h},r,void 0]})};return[[c.filter(([,S])=>S).map(([S,,E])=>[S,E]),!0],[c.filter(([,S])=>!S).map(([S,,E])=>[S,E]),!1]].map(([S,E])=>[...v(!1,E,S.filter(([C])=>C.some(h=>h[0]===q))),...v(!0,E,S.filter(([C])=>C.every(h=>h[0]!==q)))])}).flat(2).filter(Boolean))}isBlocked(e){return!e||this.config.blocklist.some(r=>R(r)?r===e:r.test(e))}};function xe(t,e){return new Q(t,e)}var $e=/\s\$\$\s+/g;function _e(t){return t.match(/\s\$\$\s/)}function Oe(t,e){return _e(t)?t.replace($e,e?` ${e} `:" "):e?`${e} ${t}`:t}var ge=/^\[(.+?)(~?=)"(.*)"\]$/;function Pe(t){return ge.test(t)?t.replace(ge,(e,r,n,s)=>`[${H(r)}${n}"${H(s)}"]`):`.${H(t)}`}function De(t,e){return e(t)}function Le(t){return t.replace(/-(\w)/g,(e,r)=>r?r.toUpperCase():"")}function ye(t){return t.charAt(0).toUpperCase()+t.slice(1)}function Se(t){return t.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase()}var Ce=["Webkit","Moz","ms"];function Te(t){let e={};function r(n){let s=e[n];if(s)return s;let i=Le(n);if(i!=="filter"&&i in t)return e[n]=Se(i);i=ye(i);for(let o=0;o<Ce.length;o++){let l=`${Ce[o]}${i}`;if(l in t)return e[n]=Se(ye(l))}return n}return({entries:n})=>n.forEach(s=>{s[0].startsWith("--")||(s[0]=r(s[0]))})}function Ee(t){return t.replace(/&amp;/g,"&").replace(/&gt;/g,">").replace(/&lt;/g,"<")}function X(t={}){if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let e=window,r=window.document,n=()=>r.documentElement,s=e.__unocss||{},i=Object.assign({},t,s.runtime),o=i.defaults||{},l=i.cloakAttribute??"un-cloak";i.autoPrefix&&(o.postprocess=A(o.postprocess)).unshift(Te(r.createElement("div").style)),i.configResolved?.(s,o);let f=xe(s,o),u=new Map,c=!0,d=new Set,y,T,v=[],w=()=>new Promise(m=>{v.push(m),T!=null&&clearTimeout(T),T=setTimeout(()=>C().then(()=>{let p=v;v=[],p.forEach(x=>x())}),0)});function S(m){if(m.nodeType!==1)return;let p=m;p.hasAttribute(l)&&p.removeAttribute(l),p.querySelectorAll(`[${l}]`).forEach(x=>{x.removeAttribute(l)})}function E(m,p){let x=u.get(m);if(!x)if(x=r.createElement("style"),u.set(m,x),p==null)n().prepend(x);else{let M=E(p),V=M.parentNode;V?V.insertBefore(x,M.nextSibling):n().prepend(x)}return x}async function C(){let m=await f.generate(d);return m.layers.reduce((p,x)=>(E(x,p).innerHTML=m.getLayer(x)??"",x),void 0),d=m.matched,{...m,getStyleElement:p=>u.get(p),getStyleElements:()=>u}}async function h(m){let p=d.size;await f.applyExtractors(m,void 0,d),p!==d.size&&await w()}async function a(){let m=r.body,p=m&&m.outerHTML;p&&(await h(`${p} ${Ee(p)}`),S(n()),S(m))}let g=new MutationObserver(m=>{c||m.forEach(async p=>{if(p.target.nodeType!==1)return;let x=p.target;for(let M of u)if(x===M[1])return;if(p.type==="childList")p.addedNodes.forEach(async M=>{if(M.nodeType!==1)return;let V=M;y&&!y(V)||(await h(V.outerHTML),S(V))});else{if(y&&!y(x))return;if(p.attributeName!==l){let M=Array.from(x.attributes).map(O=>O.value?`${O.name}="${O.value}"`:O.name).join(" "),V=`<${x.tagName.toLowerCase()} ${M}>`;await h(V)}x.hasAttribute(l)&&x.removeAttribute(l)}})}),b=!1;function U(){if(b)return;let m=n()||r.body;m&&(g.observe(m,{childList:!0,subtree:!0,attributes:!0}),b=!0)}function _(){a(),U()}function L(){r.readyState==="loading"?e.addEventListener("DOMContentLoaded",_):_()}let K=e.__unocss_runtime=e.__unocss_runtime={version:f.version,uno:f,async extract(m){R(m)||(m.forEach(p=>d.add(p)),m=""),await h(m)},extractAll:a,inspect(m){y=m},toggleObserver(m){m===void 0?c=!c:c=!!m,!b&&!c&&L()},update:C};i.ready?.(K)!==!1&&(c=!1,L())}X();})();
1
+ "use strict";(()=>{function Re(t){let e=t.length,r=-1,n,s="",i=t.charCodeAt(0);for(;++r<e;){if(n=t.charCodeAt(r),n===0){s+="\uFFFD";continue}if(n===44){s+="\\,";continue}if(n>=1&&n<=31||n===127||r===0&&n>=48&&n<=57||r===1&&n>=48&&n<=57&&i===45){s+=`\\${n.toString(16)} `;continue}if(r===0&&e===1&&n===45){s+=`\\${t.charAt(r)}`;continue}if(n>=128||n===45||n===95||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122){s+=t.charAt(r);continue}s+=`\\${t.charAt(r)}`}return s}var H=Re;function A(t=[]){return Array.isArray(t)?t:[t]}function D(t){return Array.from(new Set(t))}function R(t){return typeof t=="string"}function j(t){return R(t)?t:(Array.isArray(t)?t:Object.entries(t)).filter(e=>e[1]!=null)}function ee(t){return Array.isArray(t)?t.find(e=>!Array.isArray(e)||Array.isArray(e[0]))?t.map(e=>j(e)):[t]:[j(t)]}function be(t){return t.filter(([e,r],n)=>{if(e.startsWith("$$"))return!1;for(let s=n-1;s>=0;s--)if(t[s][0]===e&&t[s][1]===r)return!1;return!0})}function F(t){return t==null?"":be(t).map(([e,r])=>r!=null?`${e}:${r};`:void 0).filter(Boolean).join("")}function G(t){return t&&typeof t=="object"&&!Array.isArray(t)}function Y(t,e,r=!1){let n=t,s=e;if(Array.isArray(s))return r&&Array.isArray(s)?[...n,...s]:[...s];let i={...n};return G(n)&&G(s)&&Object.keys(s).forEach(o=>{G(n[o])&&G(s[o])||Array.isArray(n[o])&&Array.isArray(s[o])?i[o]=Y(n[o],s[o],r):Object.assign(i,{[o]:s[o]})}),i}function k(t){let e,r,n;if(Array.isArray(t)){for(r=Array(e=t.length);e--;)r[e]=(n=t[e])&&typeof n=="object"?k(n):n;return r}if(Object.prototype.toString.call(t)==="[object Object]"){r={};for(e in t)e==="__proto__"?Object.defineProperty(r,e,{value:k(t[e]),configurable:!0,enumerable:!0,writable:!0}):r[e]=(n=t[e])&&typeof n=="object"?k(n):n;return r}return t}function te(t){return R(t[0])}function re(t){return R(t[0])}var q="$$shortcut-no-merge";function ne(t){return typeof t=="function"?{match:t}:t}function Z(t){return t.length===3}function se(t){return t!=null}function ie(){}var B=class{_map=new Map;get(e,r){let n=this._map.get(e);if(n)return n.get(r)}getFallback(e,r,n){let s=this._map.get(e);return s||(s=new Map,this._map.set(e,s)),s.has(r)||s.set(r,n),s.get(r)}set(e,r,n){let s=this._map.get(e);return s||(s=new Map,this._map.set(e,s)),s.set(r,n),this}has(e,r){return this._map.get(e)?.has(r)}delete(e,r){return this._map.get(e)?.delete(r)||!1}deleteTop(e){return this._map.delete(e)}map(e){return Array.from(this._map.entries()).flatMap(([r,n])=>Array.from(n.entries()).map(([s,i])=>e(i,r,s)))}};var z={};function ve(t=["-",":"]){let e=t.join("|");return z[e]||(z[e]=new RegExp(`((?:[!@\\w+:_/-]|\\[&?>?:?\\S*\\])+?)(${e})\\(((?:[~!<>\\w\\s:/\\\\,%#.$?-]|\\[.*?\\])+?)\\)(?!\\s*?=>)`,"gm")),z[e].lastIndex=0,z[e]}function we(t,e=["-",":"],r=5){let n=ve(e),s=!1,i=t.toString(),o=new Set;do{let l=i;i=i.replace(n,(f,u,c,d)=>e.includes(c)?(o.add(u+c),d.split(/\s/g).filter(Boolean).map(x=>x==="~"?u:x.replace(/^(!?)(.*)/,`$1${u}${c}$2`)).join(" ")):f),s=i!==l,r-=1}while(s&&r);return{prefixes:Array.from(o),expanded:i,hasChanged:s}}function oe(t,e=["-",":"],r=5){let{expanded:n}=we(t.toString(),e,r);return typeof t=="string"?n:t.length()?t.overwrite(0,t.length(),n):t}var ae=new Set;function ce(t){ae.has(t)||(console.warn("[unocss]",t),ae.add(t))}var le=/[\\:]?[\s'"`;{}]+/g;function Ae(t){return[...new Set(t.split(le))]}var I={name:"@unocss/core/extractor-split",order:0,extract({code:t}){return Ae(t)}};function ue(){return{events:{},emit(t,...e){(this.events[t]||[]).forEach(r=>r(...e))},on(t,e){return(this.events[t]=this.events[t]||[]).push(e),()=>this.events[t]=(this.events[t]||[]).filter(r=>r!==e)}}}var W="default",N="preflights",Ue="shortcuts",fe={[N]:-100,[Ue]:-10,[W]:0};function de(t){return A(t).flatMap(e=>Array.isArray(e)?[e]:Object.entries(e))}var pe="_uno_resolved";function Me(t){if(pe in t)return t;t={...t},Object.defineProperty(t,pe,{value:!0,enumerable:!1});let e=t.shortcuts?de(t.shortcuts):void 0;if(t.shortcuts=e,t.prefix||t.layer){let r=n=>{n[2]||(n[2]={});let s=n[2];s.prefix==null&&t.prefix&&(s.prefix=A(t.prefix)),s.layer==null&&t.layer&&(s.layer=t.layer)};e?.forEach(r),t.rules?.forEach(r)}return t}function he(t){let e=Me(t);if(!e.presets)return[e];let r=(e.presets||[]).flatMap(A).flatMap(he);return[e,...r]}function J(t={},e={}){let r=Object.assign({},e,t),n=D((r.presets||[]).flatMap(A).flatMap(he)),s=[...n.filter(a=>a.enforce==="pre"),...n.filter(a=>!a.enforce),...n.filter(a=>a.enforce==="post")],i=[...s,r],o=[...i].reverse(),l=Object.assign({},fe,...i.map(a=>a.layers));function f(a){return D(i.flatMap(g=>A(g[a]||[])))}let u=f("extractors"),c=o.find(a=>a.extractorDefault!==void 0)?.extractorDefault;c===void 0&&(c=I),c&&!u.includes(c)&&u.unshift(c),u.sort((a,g)=>(a.order||0)-(g.order||0));let d=f("rules"),x={},T=d.length,v=d.map((a,g)=>{if(te(a)){A(a[2]?.prefix||"").forEach(U=>{x[U+a[0]]=[g,a[1],a[2],a]});return}return[g,...a]}).filter(Boolean).reverse(),w=i.map(a=>a.theme?k(a.theme):{}).reduce((a,g)=>Y(a,g),{}),S=f("extendTheme");for(let a of S)w=a(w)||w;let E={templates:D(i.flatMap(a=>A(a.autocomplete?.templates))),extractors:i.flatMap(a=>A(a.autocomplete?.extractors)).sort((a,g)=>(a.order||0)-(g.order||0))},C=f("separators");C.length||(C=[":","-"]);let h={mergeSelectors:!0,warn:!0,blocklist:[],sortLayers:a=>a,...r,presets:s,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:l,theme:w,rulesSize:T,rulesDynamic:v,rulesStaticMap:x,preprocess:f("preprocess"),postprocess:f("postprocess"),preflights:f("preflights"),autocomplete:E,variants:f("variants").map(ne).sort((a,g)=>(a.order||0)-(g.order||0)),shortcuts:de(f("shortcuts")).reverse(),extractors:u,safelist:f("safelist"),separators:C};for(let a of i)a?.configResolved?.(h);return h}var me="0.51.8";var Q=class{constructor(e={},r={}){this.userConfig=e;this.defaults=r;this.config=J(e,r),this.events.emit("config",this.config)}version=me;_cache=new Map;config;blocked=new Set;parentOrders=new Map;events=ue();setConfig(e,r){e&&(r&&(this.defaults=r),this.userConfig=e,this.blocked.clear(),this.parentOrders.clear(),this._cache.clear(),this.config=J(e,this.defaults),this.events.emit("config",this.config))}async applyExtractors(e,r,n=new Set){let s={original:e,code:e,id:r,extracted:n};for(let i of this.config.extractors){let o=await i.extract?.(s);if(o)for(let l of o)n.add(l)}return n}makeContext(e,r){let n={rawSelector:e,currentSelector:r[1],theme:this.config.theme,generator:this,variantHandlers:r[2],constructCSS:(...s)=>this.constructCustomCSS(n,...s),variantMatch:r};return n}async parseToken(e,r){if(this.blocked.has(e))return;let n=`${e}${r?` ${r}`:""}`;if(this._cache.has(n))return this._cache.get(n);let s=e;for(let u of this.config.preprocess)s=u(e);if(this.isBlocked(s)){this.blocked.add(e),this._cache.set(n,null);return}let i=await this.matchVariants(e,s);if(!i||this.isBlocked(i[1])){this.blocked.add(e),this._cache.set(n,null);return}let o=this.makeContext(e,[r||i[0],i[1],i[2],i[3]]);this.config.details&&(o.variants=[...i[3]]);let l=await this.expandShortcut(o.currentSelector,o),f=l?await this.stringifyShortcuts(o.variantMatch,o,l[0],l[1]):(await this.parseUtil(o.variantMatch,o))?.map(u=>this.stringifyUtil(u,o)).filter(se);if(f?.length)return this._cache.set(n,f),f;this._cache.set(n,null)}async generate(e,r={}){let{id:n,scope:s,preflights:i=!0,safelist:o=!0,minify:l=!1}=r,f=R(e)?await this.applyExtractors(e,n):Array.isArray(e)?new Set(e):e;o&&this.config.safelist.forEach(h=>f.add(h));let u=l?"":`
2
+ `,c=new Set([W]),d=new Set,x=new Map,T={},v=Array.from(f).map(async h=>{if(d.has(h))return;let a=await this.parseToken(h);if(a!=null){d.add(h);for(let g of a){let b=g[3]||"",U=g[4]?.layer;x.has(b)||x.set(b,[]),x.get(b).push(g),U&&c.add(U)}}});await Promise.all(v),await(async()=>{if(!i)return;let h={generator:this,theme:this.config.theme},a=new Set([]);this.config.preflights.forEach(({layer:g=N})=>{c.add(g),a.add(g)}),T=Object.fromEntries(await Promise.all(Array.from(a).map(async g=>{let U=(await Promise.all(this.config.preflights.filter(_=>(_.layer||N)===g).map(async _=>await _.getCSS(h)))).filter(Boolean).join(u);return[g,U]})))})();let w=this.config.sortLayers(Array.from(c).sort((h,a)=>(this.config.layers[h]??0)-(this.config.layers[a]??0)||h.localeCompare(a))),S={},E=h=>{if(S[h])return S[h];let a=Array.from(x).sort((b,U)=>(this.parentOrders.get(b[0])??0)-(this.parentOrders.get(U[0])??0)||b[0]?.localeCompare(U[0]||"")||0).map(([b,U])=>{let _=U.length,L=U.filter(p=>(p[4]?.layer||W)===h).sort((p,y)=>p[0]-y[0]||(p[4]?.sort||0)-(y[4]?.sort||0)||p[5]?.currentSelector?.localeCompare(y[5]?.currentSelector??"")||p[1]?.localeCompare(y[1]||"")||p[2]?.localeCompare(y[2]||"")||0).map(([,p,y,,M,,V])=>[[[(p&&Oe(p,s))??"",M?.sort??0]],y,!!(V??M?.noMerge)]);if(!L.length)return;let K=L.reverse().map(([p,y,M],V)=>{if(!M&&this.config.mergeSelectors)for(let P=V+1;P<_;P++){let $=L[P];if($&&!$[2]&&(p&&$[0]||p==null&&$[0]==null)&&$[1]===y)return p&&$[0]&&$[0].push(...p),null}let O=p?D(p.sort((P,$)=>P[1]-$[1]||P[0]?.localeCompare($[0]||"")||0).map(P=>P[0]).filter(Boolean)):[];return O.length?`${O.join(`,${u}`)}{${y}}`:y}).filter(Boolean).reverse().join(u);if(!b)return K;let m=b.split(" $$ ");return`${m.join("{")}{${u}${K}${u}}${m.map(p=>"").join("}")}`}).filter(Boolean).join(u);i&&(a=[T[h],a].filter(Boolean).join(u));let g=l?"":`/* layer: ${h} */${u}`;return S[h]=a?g+a:""},C=(h=w,a)=>h.filter(g=>!a?.includes(g)).map(g=>E(g)||"").filter(Boolean).join(u);return{get css(){return C()},layers:w,matched:d,getLayers:C,getLayer:E}}async matchVariants(e,r){let n=new Set,s=[],i=r||e,o=!1,l={rawSelector:e,theme:this.config.theme,generator:this};for(;;){o=!1;for(let f of this.config.variants){if(!f.multiPass&&n.has(f))continue;let u=await f.match(i,l);if(u){R(u)&&(u={matcher:u}),i=u.matcher,s.unshift(u),n.add(f),o=!0;break}}if(!o)break;if(s.length>500)throw new Error(`Too many variants applied to "${e}"`)}return[e,i,s,n]}applyVariants(e,r=e[4],n=e[1]){let i=r.slice().sort((u,c)=>(u.order||0)-(c.order||0)).reduceRight((u,c)=>d=>{let x=c.body?.(d.entries)||d.entries,T=Array.isArray(c.parent)?c.parent:[c.parent,void 0];return(c.handle??De)({...d,entries:x,selector:c.selector?.(d.selector,x)||d.selector,parent:T[0]||d.parent,parentOrder:T[1]||d.parentOrder,layer:c.layer||d.layer,sort:c.sort||d.sort},u)},u=>u)({prefix:"",selector:Pe(n),pseudo:"",entries:e[2]}),{parent:o,parentOrder:l}=i;o!=null&&l!=null&&this.parentOrders.set(o,l);let f={selector:[i.prefix,i.selector,i.pseudo].join(""),entries:i.entries,parent:o,layer:i.layer,sort:i.sort,noMerge:i.noMerge};for(let u of this.config.postprocess)u(f);return f}constructCustomCSS(e,r,n){let s=j(r);if(R(s))return s;let{selector:i,entries:o,parent:l}=this.applyVariants([0,n||e.rawSelector,s,void 0,e.variantHandlers]),f=`${i}{${F(o)}}`;return l?`${l}{${f}}`:f}async parseUtil(e,r,n=!1,s){let[i,o,l]=R(e)?await this.matchVariants(e):e;this.config.details&&(r.rules=r.rules??[]);let f=this.config.rulesStaticMap[o];if(f&&f[1]&&(n||!f[2]?.internal)){this.config.details&&r.rules.push(f[3]);let c=f[0],d=j(f[1]),x=f[2];return R(d)?[[c,d,x]]:[[c,i,d,x,l]]}r.variantHandlers=l;let{rulesDynamic:u}=this.config;for(let[c,d,x,T]of u){if(T?.internal&&!n)continue;let v=o;if(T?.prefix){let C=A(T.prefix);if(s){let h=A(s);if(!C.some(a=>h.includes(a)))continue}else{let h=C.find(a=>o.startsWith(a));if(h==null)continue;v=o.slice(h.length)}}let w=v.match(d);if(!w)continue;let S=await x(w,r);if(!S)continue;this.config.details&&r.rules.push([d,x,T]);let E=ee(S).filter(C=>C.length);if(E.length)return E.map(C=>R(C)?[c,C,T]:[c,i,C,T,l])}}stringifyUtil(e,r){if(!e)return;if(Z(e))return[e[0],void 0,e[1],void 0,e[2],this.config.details?r:void 0,void 0];let{selector:n,entries:s,parent:i,layer:o,sort:l,noMerge:f}=this.applyVariants(e),u=F(s);if(!u)return;let{layer:c,sort:d,...x}=e[3]??{},T={...x,layer:o??c,sort:l??d};return[e[0],n,u,i,T,this.config.details?r:void 0,f]}async expandShortcut(e,r,n=5){if(n===0)return;let s=this.config.details?l=>{r.shortcuts=r.shortcuts??[],r.shortcuts.push(l)}:ie,i,o;for(let l of this.config.shortcuts){let f=e;if(l[2]?.prefix){let c=A(l[2].prefix).find(d=>e.startsWith(d));if(c==null)continue;f=e.slice(c.length)}if(re(l)){if(l[0]===f){i=i||l[2],o=l[1],s(l);break}}else{let u=f.match(l[0]);if(u&&(o=l[1](u,r)),o){i=i||l[2],s(l);break}}}if(R(o)&&(o=oe(o.trim()).split(/\s+/g)),!o){let[l,f]=R(e)?await this.matchVariants(e):e;if(l!==f){let u=await this.expandShortcut(f,r,n-1);u&&(o=u[0].map(c=>R(c)?l.replace(f,c):c))}}if(o)return[(await Promise.all(o.map(async l=>(R(l)?(await this.expandShortcut(l,r,n-1))?.[0]:void 0)||[l]))).flat(1).filter(Boolean),i]}async stringifyShortcuts(e,r,n,s={layer:this.config.shortcutsLayer}){let i=new B,o=(await Promise.all(D(n).map(async c=>{let d=R(c)?await this.parseUtil(c,r,!0,s.prefix):[[1/0,"{inline}",j(c),void 0,[]]];return d||ce(`unmatched utility "${c}" in shortcut "${e[1]}"`),d||[]}))).flat(1).filter(Boolean).sort((c,d)=>c[0]-d[0]),[l,,f]=e,u=[];for(let c of o){if(Z(c)){u.push([c[0],void 0,c[1],void 0,c[2],r,void 0]);continue}let{selector:d,entries:x,parent:T,sort:v,noMerge:w}=this.applyVariants(c,[...c[4],...f],l);i.getFallback(d,T,[[],c[0]])[0].push([x,!!(w??c[3]?.noMerge),v??0])}return u.concat(i.map(([c,d],x,T)=>{let v=(S,E,C)=>{let h=Math.max(...C.map(g=>g[1])),a=C.map(g=>g[0]);return(S?[a.flat(1)]:a).map(g=>{let b=F(g);if(b)return[d,x,b,T,{...s,noMerge:E,sort:h},r,void 0]})};return[[c.filter(([,S])=>S).map(([S,,E])=>[S,E]),!0],[c.filter(([,S])=>!S).map(([S,,E])=>[S,E]),!1]].map(([S,E])=>[...v(!1,E,S.filter(([C])=>C.some(h=>h[0]===q))),...v(!0,E,S.filter(([C])=>C.every(h=>h[0]!==q)))])}).flat(2).filter(Boolean))}isBlocked(e){return!e||this.config.blocklist.some(r=>R(r)?r===e:r.test(e))}};function ye(t,e){return new Q(t,e)}var $e=/\s\$\$\s+/g;function _e(t){return t.match(/\s\$\$\s/)}function Oe(t,e){return _e(t)?t.replace($e,e?` ${e} `:" "):e?`${e} ${t}`:t}var ge=/^\[(.+?)(~?=)"(.*)"\]$/;function Pe(t){return ge.test(t)?t.replace(ge,(e,r,n,s)=>`[${H(r)}${n}"${H(s)}"]`):`.${H(t)}`}function De(t,e){return e(t)}function Le(t){return t.replace(/-(\w)/g,(e,r)=>r?r.toUpperCase():"")}function xe(t){return t.charAt(0).toUpperCase()+t.slice(1)}function Se(t){return t.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase()}var Ce=["Webkit","Moz","ms"];function Te(t){let e={};function r(n){let s=e[n];if(s)return s;let i=Le(n);if(i!=="filter"&&i in t)return e[n]=Se(i);i=xe(i);for(let o=0;o<Ce.length;o++){let l=`${Ce[o]}${i}`;if(l in t)return e[n]=Se(xe(l))}return n}return({entries:n})=>n.forEach(s=>{s[0].startsWith("--")||(s[0]=r(s[0]))})}function Ee(t){return t.replace(/&amp;/g,"&").replace(/&gt;/g,">").replace(/&lt;/g,"<")}function X(t={}){if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let e=window,r=window.document,n=()=>r.documentElement,s=e.__unocss||{},i=Object.assign({},t,s.runtime),o=i.defaults||{},l=i.cloakAttribute??"un-cloak";i.autoPrefix&&(o.postprocess=A(o.postprocess)).unshift(Te(r.createElement("div").style)),i.configResolved?.(s,o);let f=ye(s,o),u=new Map,c=!0,d=new Set,x,T,v=[],w=()=>new Promise(m=>{v.push(m),T!=null&&clearTimeout(T),T=setTimeout(()=>C().then(()=>{let p=v;v=[],p.forEach(y=>y())}),0)});function S(m){if(m.nodeType!==1)return;let p=m;p.hasAttribute(l)&&p.removeAttribute(l),p.querySelectorAll(`[${l}]`).forEach(y=>{y.removeAttribute(l)})}function E(m,p){let y=u.get(m);if(!y)if(y=r.createElement("style"),y.setAttribute("data-unocss-runtime-layer",m),u.set(m,y),p==null)n().prepend(y);else{let M=E(p),V=M.parentNode;V?V.insertBefore(y,M.nextSibling):n().prepend(y)}return y}async function C(){let m=await f.generate(d);return m.layers.reduce((p,y)=>(E(y,p).innerHTML=m.getLayer(y)??"",y),void 0),d=m.matched,{...m,getStyleElement:p=>u.get(p),getStyleElements:()=>u}}async function h(m){let p=d.size;await f.applyExtractors(m,void 0,d),p!==d.size&&await w()}async function a(){let m=r.body,p=m&&m.outerHTML;p&&(await h(`${p} ${Ee(p)}`),S(n()),S(m))}let g=new MutationObserver(m=>{c||m.forEach(async p=>{if(p.target.nodeType!==1)return;let y=p.target;for(let M of u)if(y===M[1])return;if(p.type==="childList")p.addedNodes.forEach(async M=>{if(M.nodeType!==1)return;let V=M;x&&!x(V)||(await h(V.outerHTML),S(V))});else{if(x&&!x(y))return;if(p.attributeName!==l){let M=Array.from(y.attributes).map(O=>O.value?`${O.name}="${O.value}"`:O.name).join(" "),V=`<${y.tagName.toLowerCase()} ${M}>`;await h(V)}y.hasAttribute(l)&&y.removeAttribute(l)}})}),b=!1;function U(){if(b)return;let m=n()||r.body;m&&(g.observe(m,{childList:!0,subtree:!0,attributes:!0}),b=!0)}function _(){i.bypassDefined&&je(f.blocked),a(),U()}function L(){r.readyState==="loading"?e.addEventListener("DOMContentLoaded",_):_()}let K=e.__unocss_runtime=e.__unocss_runtime={version:f.version,uno:f,async extract(m){R(m)||(m.forEach(p=>d.add(p)),m=""),await h(m)},extractAll:a,inspect(m){x=m},toggleObserver(m){m===void 0?c=!c:c=!!m,!b&&!c&&L()},update:C};i.ready?.(K)!==!1&&(c=!1,L())}function je(t=new Set){for(let e=0;e<document.styleSheets.length;e++){let r=document.styleSheets[e],n;try{if(n=r.cssRules||r.rules,!n)continue;Array.from(n).flatMap(s=>s.selectorText?.split(/,/g)||[]).forEach(s=>{s&&(s=s.trim(),s.startsWith(".")&&(s=s.slice(1)),t.add(s))})}catch{continue}}return t}X();})();
package/dist/index.d.ts CHANGED
@@ -27,6 +27,11 @@ interface RuntimeOptions {
27
27
  * Callback when the runtime is ready. Returning false will prevent default extraction
28
28
  */
29
29
  ready?: (runtime: RuntimeContext) => false | any;
30
+ /**
31
+ * When enabled, UnoCSS will look for the existing selectors defined in the stylesheet and bypass them.
32
+ * This is useful when using the runtime alongwith the build-time UnoCSS.
33
+ */
34
+ bypassDefined?: boolean;
30
35
  }
31
36
  type RuntimeInspectorCallback = (element: Element) => boolean;
32
37
  interface RuntimeContext {
package/dist/index.js CHANGED
@@ -111,6 +111,7 @@ function init(inlineConfig = {}) {
111
111
  let styleElement = styleElements.get(layer);
112
112
  if (!styleElement) {
113
113
  styleElement = defaultDocument.createElement("style");
114
+ styleElement.setAttribute("data-unocss-runtime-layer", layer);
114
115
  styleElements.set(layer, styleElement);
115
116
  if (previousLayer == null) {
116
117
  html().prepend(styleElement);
@@ -202,6 +203,8 @@ function init(inlineConfig = {}) {
202
203
  observing = true;
203
204
  }
204
205
  function execute() {
206
+ if (runtimeOptions.bypassDefined)
207
+ getDefinedCssSelectors(uno.blocked);
205
208
  extractAll();
206
209
  observe();
207
210
  }
@@ -240,5 +243,27 @@ function init(inlineConfig = {}) {
240
243
  ready();
241
244
  }
242
245
  }
246
+ function getDefinedCssSelectors(selectors = /* @__PURE__ */ new Set()) {
247
+ for (let i = 0; i < document.styleSheets.length; i++) {
248
+ const sheet = document.styleSheets[i];
249
+ let list;
250
+ try {
251
+ list = sheet.cssRules || sheet.rules;
252
+ if (!list)
253
+ continue;
254
+ Array.from(list).flatMap((r) => r.selectorText?.split(/,/g) || []).forEach((s) => {
255
+ if (!s)
256
+ return;
257
+ s = s.trim();
258
+ if (s.startsWith("."))
259
+ s = s.slice(1);
260
+ selectors.add(s);
261
+ });
262
+ } catch (e) {
263
+ continue;
264
+ }
265
+ }
266
+ return selectors;
267
+ }
243
268
  // Annotate the CommonJS export names for ESM import in node:
244
269
  0 && (module.exports = {});
package/dist/index.mjs CHANGED
@@ -87,6 +87,7 @@ function init(inlineConfig = {}) {
87
87
  let styleElement = styleElements.get(layer);
88
88
  if (!styleElement) {
89
89
  styleElement = defaultDocument.createElement("style");
90
+ styleElement.setAttribute("data-unocss-runtime-layer", layer);
90
91
  styleElements.set(layer, styleElement);
91
92
  if (previousLayer == null) {
92
93
  html().prepend(styleElement);
@@ -178,6 +179,8 @@ function init(inlineConfig = {}) {
178
179
  observing = true;
179
180
  }
180
181
  function execute() {
182
+ if (runtimeOptions.bypassDefined)
183
+ getDefinedCssSelectors(uno.blocked);
181
184
  extractAll();
182
185
  observe();
183
186
  }
@@ -216,6 +219,28 @@ function init(inlineConfig = {}) {
216
219
  ready();
217
220
  }
218
221
  }
222
+ function getDefinedCssSelectors(selectors = /* @__PURE__ */ new Set()) {
223
+ for (let i = 0; i < document.styleSheets.length; i++) {
224
+ const sheet = document.styleSheets[i];
225
+ let list;
226
+ try {
227
+ list = sheet.cssRules || sheet.rules;
228
+ if (!list)
229
+ continue;
230
+ Array.from(list).flatMap((r) => r.selectorText?.split(/,/g) || []).forEach((s) => {
231
+ if (!s)
232
+ return;
233
+ s = s.trim();
234
+ if (s.startsWith("."))
235
+ s = s.slice(1);
236
+ selectors.add(s);
237
+ });
238
+ } catch (e) {
239
+ continue;
240
+ }
241
+ }
242
+ return selectors;
243
+ }
219
244
  export {
220
245
  init as default
221
246
  };