@unocss/runtime 0.46.5 → 0.47.1

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 be(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=be;function O(t=[]){return Array.isArray(t)?t:[t]}function P(t){return Array.from(new Set(t))}function R(t){return typeof t=="string"}function L(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=>L(e)):[t]:[L(t)]}function Re(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 G(t){return t==null?"":Re(t).map(([e,r])=>r!=null?`${e}:${r};`:void 0).filter(Boolean).join("")}function F(t){return t&&typeof t=="object"&&!Array.isArray(t)}function N(t,e){let r=t,n=e;if(Array.isArray(r))return[...n];let s={...r};return F(r)&&F(n)&&Object.keys(n).forEach(i=>{F(r[i])&&F(n[i])||Array.isArray(r[i])&&Array.isArray(n[i])?s[i]=N(r[i],n[i]):Object.assign(s,{[i]:n[i]})}),s}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 ve=/[\w\u00A0-\uFFFF-_:%-?]/,W="$$shortcut-no-merge";function ne(t=""){return ve.test(t)}function se(t){return typeof t=="function"?{match:t}:t}function Y(t){return t.length===3}function ie(t){return t!=null}function oe(){}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){var n;return(n=this._map.get(e))==null?void 0:n.has(r)}delete(e,r){var n;return((n=this._map.get(e))==null?void 0:n.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 ae=/((?:[!\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function ce(t,e=["-",":"],r=5){ae.lastIndex=0;let n=!1,s=t.toString();do{let i=s;s=s.replace(ae,(o,d,a,c)=>e.includes(a)?c.split(/\s/g).filter(Boolean).map(p=>p==="~"?d:p.replace(/^(!?)(.*)/,`$1${d}${a}$2`)).join(" "):o),n=s!==i,r-=1}while(n&&r);return typeof t=="string"?s:t.length()?t.overwrite(0,t.length(),s):t}var le=new Set;function ue(t){le.has(t)||(console.warn("[unocss]",t),le.add(t))}var Ae=t=>[...new Set(t.split(/\\?[\s'"`;{}]+/g))].filter(ne),q={name:"split",order:0,extract({code:t}){return Ae(t)}};function fe(){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 z="default",I="preflights",Ue="shortcuts",pe={[I]:-100,[Ue]:-10,[z]:0};function de(t){return O(t).flatMap(e=>Array.isArray(e)?[e]:Object.entries(e))}function we(t){var r;let e=t.shortcuts?de(t.shortcuts):void 0;if(t.shortcuts=e,t.prefix||t.layer){let n=s=>{s[2]||(s[2]={});let i=s[2];i.prefix==null&&t.prefix&&(i.prefix=t.prefix),i.layer==null&&t.layer&&(i.prefix=t.layer)};e==null||e.forEach(n),(r=t.rules)==null||r.forEach(n)}return t}function Z(t={},e={}){let r=Object.assign({},e,t),n=(r.presets||[]).flatMap(O).map(we),s=[...n.filter(l=>l.enforce==="pre"),...n.filter(l=>!l.enforce),...n.filter(l=>l.enforce==="post")],i=Object.assign(pe,...n.map(l=>l.layers),t.layers);function o(l){return P([...s.flatMap(g=>O(g[l]||[])),...O(r[l]||[])])}let d=o("extractors");d.length||d.push(q),d.sort((l,g)=>(l.order||0)-(g.order||0));let a=o("rules"),c={},p=a.length,u=a.map((l,g)=>{var w;if(te(l)){let S=((w=l[2])==null?void 0:w.prefix)||"";c[S+l[0]]=[g,l[1],l[2],l];return}return[g,...l]}).filter(Boolean).reverse(),y=K([...s.map(l=>l.theme||{}),r.theme||{}].reduce((l,g)=>N(l,g),{}));o("extendTheme").forEach(l=>l(y));let C={templates:P(s.map(l=>{var g;return O((g=l.autocomplete)==null?void 0:g.templates)}).flat()),extractors:s.map(l=>{var g;return O((g=l.autocomplete)==null?void 0:g.extractors)}).flat().sort((l,g)=>(l.order||0)-(g.order||0))};return{mergeSelectors:!0,warn:!0,blocklist:[],sortLayers:l=>l,...r,presets:s,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:i,theme:y,rulesSize:p,rulesDynamic:u,rulesStaticMap:c,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),autocomplete:C,variants:o("variants").map(se),shortcuts:de(o("shortcuts")),extractors:d,safelist:o("safelist")}}var he="0.46.5";var J=class{constructor(e={},r={}){this.userConfig=e;this.defaults=r;this.config=Z(e,r),this.events.emit("config",this.config)}version=he;_cache=new Map;config;blocked=new Set;parentOrders=new Map;events=fe();setConfig(e,r){!e||(r&&(this.defaults=r),this.userConfig=e,this.blocked.clear(),this.parentOrders.clear(),this._cache.clear(),this.config=Z(e,this.defaults),this.events.emit("config",this.config))}async applyExtractors(e,r,n=new Set){let s={get original(){return e},code:e,id:r};for(let i of this.config.extractors){let o=await i.extract(s);if(o)for(let d of o)n.add(d)}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){var c;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 p of this.config.preprocess)s=p(e);if(this.isBlocked(s)){this.blocked.add(e),this._cache.set(n,null);return}let i=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 d=this.expandShortcut(o.currentSelector,o),a=d?await this.stringifyShortcuts(o.variantMatch,o,d[0],d[1]):(c=await this.parseUtil(o.variantMatch,o))==null?void 0:c.map(p=>this.stringifyUtil(p,o)).filter(ie);if(a!=null&&a.length)return this._cache.set(n,a),a;this._cache.set(n,null)}async generate(e,r={}){let{id:n,scope:s,preflights:i=!0,safelist:o=!0,minify:d=!1}=r,a=R(e)?await this.applyExtractors(e,n):Array.isArray(e)?new Set(e):e;o&&this.config.safelist.forEach(m=>a.add(m));let c=d?"":`
2
- `,p=new Set([z]),u=new Set,y=new Map,C={},l=Array.from(a).map(async m=>{var E;if(u.has(m))return;let x=await this.parseToken(m);if(x!=null){u.add(m);for(let v of x){let A=v[3]||"",V=(E=v[4])==null?void 0:E.layer;y.has(A)||y.set(A,[]),y.get(A).push(v),V&&p.add(V)}}});await Promise.all(l),await(async()=>{if(!i)return;let m={generator:this,theme:this.config.theme},x=new Set([]);this.config.preflights.forEach(({layer:E=I})=>{p.add(E),x.add(E)}),C=Object.fromEntries(await Promise.all(Array.from(x).map(async E=>{let A=(await Promise.all(this.config.preflights.filter(V=>(V.layer||I)===E).map(async V=>await V.getCSS(m)))).filter(Boolean).join(c);return[E,A]})))})();let g=this.config.sortLayers(Array.from(p).sort((m,x)=>(this.config.layers[m]??0)-(this.config.layers[x]??0)||m.localeCompare(x))),w={},S=m=>{if(w[m])return w[m];let x=Array.from(y).sort((v,A)=>{var V;return(this.parentOrders.get(v[0])??0)-(this.parentOrders.get(A[0])??0)||((V=v[0])==null?void 0:V.localeCompare(A[0]||""))||0}).map(([v,A])=>{let V=A.length,j=A.filter(f=>{var h;return(((h=f[4])==null?void 0:h.layer)||z)===m}).sort((f,h)=>{var T,M,$,U;return f[0]-h[0]||(((T=f[4])==null?void 0:T.sort)||0)-(((M=h[4])==null?void 0:M.sort)||0)||(($=f[1])==null?void 0:$.localeCompare(h[1]||""))||((U=f[2])==null?void 0:U.localeCompare(h[2]||""))||0}).map(([,f,h,,T,,M])=>[[[(f&&Me(f,s))??"",(T==null?void 0:T.sort)??0]],h,!!(M??(T==null?void 0:T.noMerge))]);if(!j.length)return;let D=j.reverse().map(([f,h,T],M)=>{if(!T&&this.config.mergeSelectors)for(let U=M+1;U<V;U++){let _=j[U];if(_&&!_[2]&&(f&&_[0]||f==null&&_[0]==null)&&_[1]===h)return f&&_[0]&&_[0].push(...f),null}let $=f?P(f.sort((U,_)=>{var X;return U[1]-_[1]||((X=U[0])==null?void 0:X.localeCompare(_[0]||""))||0}).map(U=>U[0]).filter(Boolean)):[];return $.length?`${$.join(`,${c}`)}{${h}}`:h}).filter(Boolean).reverse().join(c);if(!v)return D;let k=v.split(" $$ ");return`${k.join("{")}{${c}${D}${c}}${k.map(f=>"").join("}")}`}).filter(Boolean).join(c);i&&(x=[C[m],x].filter(Boolean).join(c));let E=d?"":`/* layer: ${m} */${c}`;return w[m]=x?E+x:""},b=(m=g,x)=>m.filter(E=>!(x!=null&&x.includes(E))).map(E=>S(E)||"").filter(Boolean).join(c);return{get css(){return b()},layers:g,matched:u,getLayers:b,getLayer:S}}matchVariants(e,r){let n=new Set,s=[],i=r||e,o=!1,d={rawSelector:e,theme:this.config.theme,generator:this};for(;;){o=!1;for(let a of this.config.variants){if(!a.multiPass&&n.has(a))continue;let c=a.match(i,d);if(!!c){R(c)&&(c={matcher:c}),i=c.matcher,s.unshift(c),n.add(a),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((c,p)=>(c.order||0)-(p.order||0)).reduceRight((c,p)=>u=>{var l,g;let y=((l=p.body)==null?void 0:l.call(p,u.entries))||u.entries,C=Array.isArray(p.parent)?p.parent:[p.parent,void 0];return(p.handle??Pe)({...u,entries:y,selector:((g=p.selector)==null?void 0:g.call(p,u.selector,y))||u.selector,parent:C[0]||u.parent,parentOrder:C[1]||u.parentOrder,layer:p.layer||u.layer,sort:p.sort||u.sort},c)},c=>c)({prefix:"",selector:Oe(n),pseudo:"",entries:e[2]}),{parent:o,parentOrder:d}=i;o!=null&&d!=null&&this.parentOrders.set(o,d);let a={selector:_e([i.prefix,i.selector,i.pseudo].join("")),entries:i.entries,parent:o,layer:i.layer,sort:i.sort,noMerge:i.noMerge};for(let c of this.config.postprocess)c(a);return a}constructCustomCSS(e,r,n){let s=L(r);if(R(s))return s;let{selector:i,entries:o,parent:d}=this.applyVariants([0,n||e.rawSelector,s,void 0,e.variantHandlers]),a=`${i}{${G(o)}}`;return d?`${d}{${a}}`:a}async parseUtil(e,r,n=!1,s=void 0){var p;let[i,o,d]=R(e)?this.matchVariants(e):e;this.config.details&&(r.rules=r.rules??[]);let a=this.config.rulesStaticMap[o];if(a&&a[1]&&(n||!((p=a[2])!=null&&p.internal))){this.config.details&&r.rules.push(a[3]);let u=a[0],y=L(a[1]),C=a[2];return R(y)?[[u,y,C]]:[[u,i,y,C,d]]}r.variantHandlers=d;let{rulesDynamic:c}=this.config;for(let[u,y,C,l]of c){if((l==null?void 0:l.internal)&&!n)continue;let g=o;if(l!=null&&l.prefix)if(s){if(s!==l.prefix)continue}else{if(!o.startsWith(l.prefix))continue;g=o.slice(l.prefix.length)}let w=g.match(y);if(!w)continue;let S=await C(w,r);if(!S)continue;this.config.details&&r.rules.push([y,C,l]);let b=ee(S).filter(m=>m.length);if(b.length)return b.map(m=>R(m)?[u,m,l]:[u,i,m,l,d])}}stringifyUtil(e,r){if(!e)return;if(Y(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:d,noMerge:a}=this.applyVariants(e),c=G(s);if(!c)return;let{layer:p,sort:u,...y}=e[3]??{},C={...y,layer:o??p,sort:d??u};return[e[0],n,c,i,C,this.config.details?r:void 0,a]}expandShortcut(e,r,n=5){var d;if(n===0)return;let s=this.config.details?a=>{r.shortcuts=r.shortcuts??[],r.shortcuts.push(a)}:oe,i,o;for(let a of this.config.shortcuts){let c=e;if((d=a[2])!=null&&d.prefix){if(!e.startsWith(a[2].prefix))continue;c=e.slice(a[2].prefix.length)}if(re(a)){if(a[0]===c){i=i||a[2],o=a[1],s(a);break}}else{let p=c.match(a[0]);if(p&&(o=a[1](p,r)),o){i=i||a[2],s(a);break}}}if(R(o)&&(o=ce(o.trim()).split(/\s+/g)),!o){let[a,c]=R(e)?this.matchVariants(e):e;if(a!==c){let p=this.expandShortcut(c,r,n-1);p&&(o=p[0].map(u=>R(u)?a.replace(c,u):u))}}if(!!o)return[o.flatMap(a=>{var c;return(R(a)?(c=this.expandShortcut(a,r,n-1))==null?void 0:c[0]:void 0)||[a]}).filter(Boolean),i]}async stringifyShortcuts(e,r,n,s={layer:this.config.shortcutsLayer}){var p;let i=new B,o=(await Promise.all(P(n).map(async u=>{let y=R(u)?await this.parseUtil(u,r,!0,s.prefix):[[1/0,"{inline}",L(u),void 0,[]]];return y||ue(`unmatched utility "${u}" in shortcut "${e[1]}"`),y||[]}))).flat(1).filter(Boolean).sort((u,y)=>u[0]-y[0]),[d,,a]=e,c=[];for(let u of o){if(Y(u)){c.push([u[0],void 0,u[1],void 0,u[2],r,void 0]);continue}let{selector:y,entries:C,parent:l,sort:g,noMerge:w}=this.applyVariants(u,[...u[4],...a],d);i.getFallback(y,l,[[],u[0]])[0].push([C,!!(w??((p=u[3])==null?void 0:p.noMerge)),g??0])}return c.concat(i.map(([u,y],C,l)=>{let g=(S,b,m)=>{let x=Math.max(...m.map(v=>v[1])),E=m.map(v=>v[0]);return(S?[E.flat(1)]:E).map(v=>{let A=G(v);if(A)return[y,C,A,l,{...s,noMerge:b,sort:x},r,void 0]})};return[[u.filter(([,S])=>S).map(([S,,b])=>[S,b]),!0],[u.filter(([,S])=>!S).map(([S,,b])=>[S,b]),!1]].map(([S,b])=>[...g(!1,b,S.filter(([m])=>m.some(x=>x[0]===W))),...g(!0,b,S.filter(([m])=>m.every(x=>x[0]!==W)))])}).flat(2).filter(Boolean))}isBlocked(e){return!e||this.config.blocklist.some(r=>R(r)?r===e:r.test(e))}};function ge(t,e){return new J(t,e)}var ye=/ \$\$ /,$e=t=>t.match(ye);function Me(t,e){return $e(t)?t.replace(ye,e?` ${e} `:" "):e?`${e} ${t}`:t}function _e(t){let e=t.match(/::[\w-]+(\([\w-]+\))?/g);if(e){for(let r of e)t=t.replace(r,"");t+=e.join("")}return t}var me=/^\[(.+?)(~?=)"(.*)"\]$/;function Oe(t){return me.test(t)?t.replace(me,(e,r,n,s)=>`[${H(r)}${n}"${H(s)}"]`):`.${H(t)}`}function Pe(t,e){return e(t)}var Le=t=>t.replace(/-(\w)/g,(e,r)=>r?r.toUpperCase():""),xe=t=>t.charAt(0).toUpperCase()+t.slice(1),Se=t=>t.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),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 d=`${Ce[o]}${i}`;if(d in t)return e[n]=Se(xe(d))}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 Q(t={}){var D,k;if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let e=window,r=document,n=e.__unocss||{},s=Object.assign({},t,n.runtime),i=s.defaults||{},o=s.cloakAttribute??"un-cloak";s.autoPrefix&&(i.postprocess=O(i.postprocess)).unshift(Te(r.createElement("div").style)),(D=s.configResolved)==null||D.call(s,n,i);let d=ge(n,i),a=!0,c=new Set,p,u,y,C=[],l=()=>new Promise(f=>{C.push(f),y!=null&&clearTimeout(y),y=setTimeout(()=>S().then(()=>{let h=C;C=[],h.forEach(T=>T())}),0)});function g(f){if(f.nodeType!==1)return;let h=f;h.hasAttribute(o)&&h.removeAttribute(o),h.querySelectorAll(`[${o}]`).forEach(T=>{T.removeAttribute(o)})}function w(){return p||(p=r.createElement("style"),r.documentElement.prepend(p)),p}async function S(){let f=await d.generate(c),h=w();return h.innerHTML=f.css,c=f.matched,{...f,styleElement:h}}async function b(f){let h=c.size;await d.applyExtractors(f,void 0,c),h!==c.size&&await l()}async function m(){let f=r.body,h=f&&f.outerHTML;h&&(await b(`${h} ${Ee(h)}`),g(f))}let x=new MutationObserver(f=>{a||f.forEach(async h=>{if(h.target.nodeType!==1)return;let T=h.target;if(T!==p)if(h.type==="childList")h.addedNodes.forEach(async M=>{if(M.nodeType!==1)return;let $=M;u&&!u($)||(await b($.outerHTML),g($))});else{if(u&&!u(T))return;if(h.attributeName!==o){let M=Array.from(T.attributes).map(U=>U.value?`${U.name}="${U.value}"`:U.name).join(" "),$=`<${T.tagName.toLowerCase()} ${M}>`;await b($)}T.hasAttribute(o)&&T.removeAttribute(o)}})}),E=!1;function v(){if(E)return;let f=r.documentElement||r.body;!f||(x.observe(f,{childList:!0,subtree:!0,attributes:!0}),E=!0)}function A(){m(),v()}function V(){r.readyState==="loading"?e.addEventListener("DOMContentLoaded",A):A()}let j=e.__unocss_runtime=e.__unocss_runtime={version:d.version,uno:d,async extract(f){R(f)||(f.forEach(h=>c.add(h)),f=""),await b(f)},extractAll:m,inspect(f){u=f},toggleObserver(f){f===void 0?a=!a:a=!!f,!E&&!a&&V()},update:S};((k=s.ready)==null?void 0:k.call(s,j))!==!1&&(a=!1,V())}Q();})();
1
+ "use strict";(()=>{function be(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 K=be;function M(t=[]){return Array.isArray(t)?t:[t]}function L(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 Re(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?"":Re(t).map(([e,r])=>r!=null?`${e}:${r};`:void 0).filter(Boolean).join("")}function H(t){return t&&typeof t=="object"&&!Array.isArray(t)}function W(t,e){let r=t,n=e;if(Array.isArray(r))return[...n];let s={...r};return H(r)&&H(n)&&Object.keys(n).forEach(i=>{H(r[i])&&H(n[i])||Array.isArray(r[i])&&Array.isArray(n[i])?s[i]=W(r[i],n[i]):Object.assign(s,{[i]:n[i]})}),s}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 ve=/[\w\u00A0-\uFFFF-_:%-?]/,N="$$shortcut-no-merge";function ne(t=""){return ve.test(t)}function se(t){return typeof t=="function"?{match:t}:t}function Y(t){return t.length===3}function ie(t){return t!=null}function oe(){}var G=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 ae=/((?:[!\w+:_/-]|\[&?>?:?.*\])+?)([:-])\(((?:[~!\w\s:/\\,%#.$-]|\[.*?\])+?)\)(?!\s*?=>)/gm;function ce(t,e=["-",":"],r=5){ae.lastIndex=0;let n=!1,s=t.toString();do{let i=s;s=s.replace(ae,(o,a,u,l)=>e.includes(u)?l.split(/\s/g).filter(Boolean).map(c=>c==="~"?a:c.replace(/^(!?)(.*)/,`$1${a}${u}$2`)).join(" "):o),n=s!==i,r-=1}while(n&&r);return typeof t=="string"?s:t.length()?t.overwrite(0,t.length(),s):t}var le=new Set;function ue(t){le.has(t)||(console.warn("[unocss]",t),le.add(t))}var Ae=/\\?[\s'"`;{}]+/g,q=/\[(\\\W|[\w-])+:['"]?\S+?['"]?\]/g,Ue=new RegExp(`^${q.source}$`),we=t=>{let e=new Set;for(let r of t.matchAll(q))!t[r.index-1]?.match(/^[\s'"`]/)||e.add(r[0]);return t.split(Ae).forEach(r=>{ne(r)&&!Ue.test(r)&&e.add(r)}),[...e]},Z={name:"split",order:0,extract({code:t}){return we(t)}};function fe(){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 B="default",z="preflights",$e="shortcuts",pe={[z]:-100,[$e]:-10,[B]:0};function de(t){return M(t).flatMap(e=>Array.isArray(e)?[e]:Object.entries(e))}function Ve(t){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=t.prefix),s.layer==null&&t.layer&&(s.prefix=t.layer)};e?.forEach(r),t.rules?.forEach(r)}return t}function J(t={},e={}){let r=Object.assign({},e,t),n=(r.presets||[]).flatMap(M).map(Ve),s=[...n.filter(f=>f.enforce==="pre"),...n.filter(f=>!f.enforce),...n.filter(f=>f.enforce==="post")],i=Object.assign(pe,...n.map(f=>f.layers),t.layers);function o(f){return L([...s.flatMap(E=>M(E[f]||[])),...M(r[f]||[])])}let a=o("extractors");a.length||a.push(Z),a.sort((f,E)=>(f.order||0)-(E.order||0));let u=o("rules"),l={},c=u.length,p=u.map((f,E)=>{if(te(f)){let C=f[2]?.prefix||"";l[C+f[0]]=[E,f[1],f[2],f];return}return[E,...f]}).filter(Boolean).reverse(),g=k([...s.map(f=>f.theme||{}),r.theme||{}].reduce((f,E)=>W(f,E),{}));o("extendTheme").forEach(f=>f(g));let y={templates:L(s.map(f=>M(f.autocomplete?.templates)).flat()),extractors:s.map(f=>M(f.autocomplete?.extractors)).flat().sort((f,E)=>(f.order||0)-(E.order||0))};return{mergeSelectors:!0,warn:!0,blocklist:[],sortLayers:f=>f,...r,presets:s,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:i,theme:g,rulesSize:c,rulesDynamic:p,rulesStaticMap:l,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),autocomplete:y,variants:o("variants").map(se),shortcuts:de(o("shortcuts")),extractors:a,safelist:o("safelist")}}var he="0.47.1";var Q=class{constructor(e={},r={}){this.userConfig=e;this.defaults=r;this.config=J(e,r),this.events.emit("config",this.config)}version=he;_cache=new Map;config;blocked=new Set;parentOrders=new Map;events=fe();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={get original(){return e},code:e,id:r};for(let i of this.config.extractors){let o=await i.extract(s);if(o)for(let a of o)n.add(a)}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 l of this.config.preprocess)s=l(e);if(this.isBlocked(s)){this.blocked.add(e),this._cache.set(n,null);return}let i=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 a=this.expandShortcut(o.currentSelector,o),u=a?await this.stringifyShortcuts(o.variantMatch,o,a[0],a[1]):(await this.parseUtil(o.variantMatch,o))?.map(l=>this.stringifyUtil(l,o)).filter(ie);if(u?.length)return this._cache.set(n,u),u;this._cache.set(n,null)}async generate(e,r={}){let{id:n,scope:s,preflights:i=!0,safelist:o=!0,minify:a=!1}=r,u=R(e)?await this.applyExtractors(e,n):Array.isArray(e)?new Set(e):e;o&&this.config.safelist.forEach(m=>u.add(m));let l=a?"":`
2
+ `,c=new Set([B]),p=new Set,g=new Map,y={},f=Array.from(u).map(async m=>{if(p.has(m))return;let b=await this.parseToken(m);if(b!=null){p.add(m);for(let x of b){let A=x[3]||"",w=x[4]?.layer;g.has(A)||g.set(A,[]),g.get(A).push(x),w&&c.add(w)}}});await Promise.all(f),await(async()=>{if(!i)return;let m={generator:this,theme:this.config.theme},b=new Set([]);this.config.preflights.forEach(({layer:x=z})=>{c.add(x),b.add(x)}),y=Object.fromEntries(await Promise.all(Array.from(b).map(async x=>{let w=(await Promise.all(this.config.preflights.filter(_=>(_.layer||z)===x).map(async _=>await _.getCSS(m)))).filter(Boolean).join(l);return[x,w]})))})();let E=this.config.sortLayers(Array.from(c).sort((m,b)=>(this.config.layers[m]??0)-(this.config.layers[b]??0)||m.localeCompare(b))),C={},v=m=>{if(C[m])return C[m];let b=Array.from(g).sort((A,w)=>(this.parentOrders.get(A[0])??0)-(this.parentOrders.get(w[0])??0)||A[0]?.localeCompare(w[0]||"")||0).map(([A,w])=>{let _=w.length,D=w.filter(h=>(h[4]?.layer||B)===m).sort((h,U)=>h[0]-U[0]||(h[4]?.sort||0)-(U[4]?.sort||0)||h[1]?.localeCompare(U[1]||"")||h[2]?.localeCompare(U[2]||"")||0).map(([,h,U,,$,,O])=>[[[(h&&Oe(h,s))??"",$?.sort??0]],U,!!(O??$?.noMerge)]);if(!D.length)return;let d=D.reverse().map(([h,U,$],O)=>{if(!$&&this.config.mergeSelectors)for(let P=O+1;P<_;P++){let V=D[P];if(V&&!V[2]&&(h&&V[0]||h==null&&V[0]==null)&&V[1]===U)return h&&V[0]&&V[0].push(...h),null}let I=h?L(h.sort((P,V)=>P[1]-V[1]||P[0]?.localeCompare(V[0]||"")||0).map(P=>P[0]).filter(Boolean)):[];return I.length?`${I.join(`,${l}`)}{${U}}`:U}).filter(Boolean).reverse().join(l);if(!A)return d;let S=A.split(" $$ ");return`${S.join("{")}{${l}${d}${l}}${S.map(h=>"").join("}")}`}).filter(Boolean).join(l);i&&(b=[y[m],b].filter(Boolean).join(l));let x=a?"":`/* layer: ${m} */${l}`;return C[m]=b?x+b:""},T=(m=E,b)=>m.filter(x=>!b?.includes(x)).map(x=>v(x)||"").filter(Boolean).join(l);return{get css(){return T()},layers:E,matched:p,getLayers:T,getLayer:v}}matchVariants(e,r){let n=new Set,s=[],i=r||e,o=!1,a={rawSelector:e,theme:this.config.theme,generator:this};for(;;){o=!1;for(let u of this.config.variants){if(!u.multiPass&&n.has(u))continue;let l=u.match(i,a);if(!!l){R(l)&&(l={matcher:l}),i=l.matcher,s.unshift(l),n.add(u),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((l,c)=>(l.order||0)-(c.order||0)).reduceRight((l,c)=>p=>{let g=c.body?.(p.entries)||p.entries,y=Array.isArray(c.parent)?c.parent:[c.parent,void 0];return(c.handle??je)({...p,entries:g,selector:c.selector?.(p.selector,g)||p.selector,parent:y[0]||p.parent,parentOrder:y[1]||p.parentOrder,layer:c.layer||p.layer,sort:c.sort||p.sort},l)},l=>l)({prefix:"",selector:Le(n),pseudo:"",entries:e[2]}),{parent:o,parentOrder:a}=i;o!=null&&a!=null&&this.parentOrders.set(o,a);let u={selector:Pe([i.prefix,i.selector,i.pseudo].join("")),entries:i.entries,parent:o,layer:i.layer,sort:i.sort,noMerge:i.noMerge};for(let l of this.config.postprocess)l(u);return u}constructCustomCSS(e,r,n){let s=j(r);if(R(s))return s;let{selector:i,entries:o,parent:a}=this.applyVariants([0,n||e.rawSelector,s,void 0,e.variantHandlers]),u=`${i}{${F(o)}}`;return a?`${a}{${u}}`:u}async parseUtil(e,r,n=!1,s=void 0){let[i,o,a]=R(e)?this.matchVariants(e):e;this.config.details&&(r.rules=r.rules??[]);let u=this.config.rulesStaticMap[o];if(u&&u[1]&&(n||!u[2]?.internal)){this.config.details&&r.rules.push(u[3]);let c=u[0],p=j(u[1]),g=u[2];return R(p)?[[c,p,g]]:[[c,i,p,g,a]]}r.variantHandlers=a;let{rulesDynamic:l}=this.config;for(let[c,p,g,y]of l){if(y?.internal&&!n)continue;let f=o;if(y?.prefix)if(s){if(s!==y.prefix)continue}else{if(!o.startsWith(y.prefix))continue;f=o.slice(y.prefix.length)}let E=f.match(p);if(!E)continue;let C=await g(E,r);if(!C)continue;this.config.details&&r.rules.push([p,g,y]);let v=ee(C).filter(T=>T.length);if(v.length)return v.map(T=>R(T)?[c,T,y]:[c,i,T,y,a])}}stringifyUtil(e,r){if(!e)return;if(Y(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:a,noMerge:u}=this.applyVariants(e),l=F(s);if(!l)return;let{layer:c,sort:p,...g}=e[3]??{},y={...g,layer:o??c,sort:a??p};return[e[0],n,l,i,y,this.config.details?r:void 0,u]}expandShortcut(e,r,n=5){if(n===0)return;let s=this.config.details?a=>{r.shortcuts=r.shortcuts??[],r.shortcuts.push(a)}:oe,i,o;for(let a of this.config.shortcuts){let u=e;if(a[2]?.prefix){if(!e.startsWith(a[2].prefix))continue;u=e.slice(a[2].prefix.length)}if(re(a)){if(a[0]===u){i=i||a[2],o=a[1],s(a);break}}else{let l=u.match(a[0]);if(l&&(o=a[1](l,r)),o){i=i||a[2],s(a);break}}}if(R(o)&&(o=ce(o.trim()).split(/\s+/g)),!o){let[a,u]=R(e)?this.matchVariants(e):e;if(a!==u){let l=this.expandShortcut(u,r,n-1);l&&(o=l[0].map(c=>R(c)?a.replace(u,c):c))}}if(!!o)return[o.flatMap(a=>(R(a)?this.expandShortcut(a,r,n-1)?.[0]:void 0)||[a]).filter(Boolean),i]}async stringifyShortcuts(e,r,n,s={layer:this.config.shortcutsLayer}){let i=new G,o=(await Promise.all(L(n).map(async c=>{let p=R(c)?await this.parseUtil(c,r,!0,s.prefix):[[1/0,"{inline}",j(c),void 0,[]]];return p||ue(`unmatched utility "${c}" in shortcut "${e[1]}"`),p||[]}))).flat(1).filter(Boolean).sort((c,p)=>c[0]-p[0]),[a,,u]=e,l=[];for(let c of o){if(Y(c)){l.push([c[0],void 0,c[1],void 0,c[2],r,void 0]);continue}let{selector:p,entries:g,parent:y,sort:f,noMerge:E}=this.applyVariants(c,[...c[4],...u],a);i.getFallback(p,y,[[],c[0]])[0].push([g,!!(E??c[3]?.noMerge),f??0])}return l.concat(i.map(([c,p],g,y)=>{let f=(C,v,T)=>{let m=Math.max(...T.map(x=>x[1])),b=T.map(x=>x[0]);return(C?[b.flat(1)]:b).map(x=>{let A=F(x);if(A)return[p,g,A,y,{...s,noMerge:v,sort:m},r,void 0]})};return[[c.filter(([,C])=>C).map(([C,,v])=>[C,v]),!0],[c.filter(([,C])=>!C).map(([C,,v])=>[C,v]),!1]].map(([C,v])=>[...f(!1,v,C.filter(([T])=>T.some(m=>m[0]===N))),...f(!0,v,C.filter(([T])=>T.every(m=>m[0]!==N)))])}).flat(2).filter(Boolean))}isBlocked(e){return!e||this.config.blocklist.some(r=>R(r)?r===e:r.test(e))}};function ge(t,e){return new Q(t,e)}var ye=/ \$\$ /,_e=t=>t.match(ye);function Oe(t,e){return _e(t)?t.replace(ye,e?` ${e} `:" "):e?`${e} ${t}`:t}function Pe(t){let e=t.match(/::[\w-]+(\([\w-]+\))?/g);if(e){for(let r of e)t=t.replace(r,"");t+=e.join("")}return t}var me=/^\[(.+?)(~?=)"(.*)"\]$/;function Le(t){return me.test(t)?t.replace(me,(e,r,n,s)=>`[${K(r)}${n}"${K(s)}"]`):`.${K(t)}`}function je(t,e){return e(t)}var De=t=>t.replace(/-(\w)/g,(e,r)=>r?r.toUpperCase():""),xe=t=>t.charAt(0).toUpperCase()+t.slice(1),Se=t=>t.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),Ce=["Webkit","Moz","ms"];function Ee(t){let e={};function r(n){let s=e[n];if(s)return s;let i=De(n);if(i!=="filter"&&i in t)return e[n]=Se(i);i=xe(i);for(let o=0;o<Ce.length;o++){let a=`${Ce[o]}${i}`;if(a in t)return e[n]=Se(xe(a))}return n}return({entries:n})=>n.forEach(s=>{s[0].startsWith("--")||(s[0]=r(s[0]))})}function Te(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=document,n=e.__unocss||{},s=Object.assign({},t,n.runtime),i=s.defaults||{},o=s.cloakAttribute??"un-cloak";s.autoPrefix&&(i.postprocess=M(i.postprocess)).unshift(Ee(r.createElement("div").style)),s.configResolved?.(n,i);let a=ge(n,i),u=!0,l=new Set,c,p,g,y=[],f=()=>new Promise(d=>{y.push(d),g!=null&&clearTimeout(g),g=setTimeout(()=>v().then(()=>{let S=y;y=[],S.forEach(h=>h())}),0)});function E(d){if(d.nodeType!==1)return;let S=d;S.hasAttribute(o)&&S.removeAttribute(o),S.querySelectorAll(`[${o}]`).forEach(h=>{h.removeAttribute(o)})}function C(){return c||(c=r.createElement("style"),r.documentElement.prepend(c)),c}async function v(){let d=await a.generate(l),S=C();return S.innerHTML=d.css,l=d.matched,{...d,styleElement:S}}async function T(d){let S=l.size;await a.applyExtractors(d,void 0,l),S!==l.size&&await f()}async function m(){let d=r.body,S=d&&d.outerHTML;S&&(await T(`${S} ${Te(S)}`),E(d))}let b=new MutationObserver(d=>{u||d.forEach(async S=>{if(S.target.nodeType!==1)return;let h=S.target;if(h!==c)if(S.type==="childList")S.addedNodes.forEach(async U=>{if(U.nodeType!==1)return;let $=U;p&&!p($)||(await T($.outerHTML),E($))});else{if(p&&!p(h))return;if(S.attributeName!==o){let U=Array.from(h.attributes).map(O=>O.value?`${O.name}="${O.value}"`:O.name).join(" "),$=`<${h.tagName.toLowerCase()} ${U}>`;await T($)}h.hasAttribute(o)&&h.removeAttribute(o)}})}),x=!1;function A(){if(x)return;let d=r.documentElement||r.body;!d||(b.observe(d,{childList:!0,subtree:!0,attributes:!0}),x=!0)}function w(){m(),A()}function _(){r.readyState==="loading"?e.addEventListener("DOMContentLoaded",w):w()}let D=e.__unocss_runtime=e.__unocss_runtime={version:a.version,uno:a,async extract(d){R(d)||(d.forEach(S=>l.add(S)),d=""),await T(d)},extractAll:m,inspect(d){p=d},toggleObserver(d){d===void 0?u=!u:u=!!d,!x&&!u&&_()},update:v};s.ready?.(D)!==!1&&(u=!1,_())}X();})();
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ interface RuntimeOptions {
24
24
  */
25
25
  ready?: (runtime: RuntimeContext) => false | any;
26
26
  }
27
- declare type RuntimeInspectorCallback = (element: Element) => boolean;
27
+ type RuntimeInspectorCallback = (element: Element) => boolean;
28
28
  interface RuntimeContext {
29
29
  /**
30
30
  * The UnoCSS instance.
package/dist/index.js CHANGED
@@ -58,7 +58,6 @@ function decodeHtml(html) {
58
58
 
59
59
  // src/index.ts
60
60
  function init(inlineConfig = {}) {
61
- var _a, _b;
62
61
  if (typeof window == "undefined") {
63
62
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
64
63
  return;
@@ -73,7 +72,7 @@ function init(inlineConfig = {}) {
73
72
  const postprocessors = userConfigDefaults.postprocess = (0, import_core.toArray)(userConfigDefaults.postprocess);
74
73
  postprocessors.unshift(autoPrefixer(defaultDocument.createElement("div").style));
75
74
  }
76
- (_a = runtimeOptions.configResolved) == null ? void 0 : _a.call(runtimeOptions, userConfig, userConfigDefaults);
75
+ runtimeOptions.configResolved?.(userConfig, userConfigDefaults);
77
76
  const uno = (0, import_core.createGenerator)(userConfig, userConfigDefaults);
78
77
  let paused = true;
79
78
  let tokens = /* @__PURE__ */ new Set();
@@ -212,7 +211,7 @@ function init(inlineConfig = {}) {
212
211
  },
213
212
  update: updateStyle
214
213
  };
215
- if (((_b = runtimeOptions.ready) == null ? void 0 : _b.call(runtimeOptions, unoCssRuntime)) !== false) {
214
+ if (runtimeOptions.ready?.(unoCssRuntime) !== false) {
216
215
  paused = false;
217
216
  ready();
218
217
  }
package/dist/index.mjs CHANGED
@@ -34,7 +34,6 @@ function decodeHtml(html) {
34
34
 
35
35
  // src/index.ts
36
36
  function init(inlineConfig = {}) {
37
- var _a, _b;
38
37
  if (typeof window == "undefined") {
39
38
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
40
39
  return;
@@ -49,7 +48,7 @@ function init(inlineConfig = {}) {
49
48
  const postprocessors = userConfigDefaults.postprocess = toArray(userConfigDefaults.postprocess);
50
49
  postprocessors.unshift(autoPrefixer(defaultDocument.createElement("div").style));
51
50
  }
52
- (_a = runtimeOptions.configResolved) == null ? void 0 : _a.call(runtimeOptions, userConfig, userConfigDefaults);
51
+ runtimeOptions.configResolved?.(userConfig, userConfigDefaults);
53
52
  const uno = createGenerator(userConfig, userConfigDefaults);
54
53
  let paused = true;
55
54
  let tokens = /* @__PURE__ */ new Set();
@@ -188,7 +187,7 @@ function init(inlineConfig = {}) {
188
187
  },
189
188
  update: updateStyle
190
189
  };
191
- if (((_b = runtimeOptions.ready) == null ? void 0 : _b.call(runtimeOptions, unoCssRuntime)) !== false) {
190
+ if (runtimeOptions.ready?.(unoCssRuntime) !== false) {
192
191
  paused = false;
193
192
  ready();
194
193
  }