@unocss/runtime 0.28.0 → 0.28.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
- (()=>{var mt=Object.defineProperty,yt=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var W=(n,t,e)=>t in n?mt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,$=(n,t)=>{for(var e in t||(t={}))N.call(t,e)&&W(n,e,t[e]);if(j)for(var e of j(t))Z.call(t,e)&&W(n,e,t[e]);return n},O=(n,t)=>yt(n,St(t));var J=(n,t)=>{var e={};for(var r in n)N.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&j)for(var r of j(n))t.indexOf(r)<0&&Z.call(n,r)&&(e[r]=n[r]);return e};function xt(n){let t=n.length,e=-1,r,s="",i=n.charCodeAt(0);for(;++e<t;){if(r=n.charCodeAt(e),r===0){s+="\uFFFD";continue}if(r===44){s+="\\2c ";continue}if(r>=1&&r<=31||r===127||e===0&&r>=48&&r<=57||e===1&&r>=48&&r<=57&&i===45){s+=`\\${r.toString(16)} `;continue}if(e===0&&t===1&&r===45){s+=`\\${n.charAt(e)}`;continue}if(r>=128||r===45||r===95||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122){s+=n.charAt(e);continue}s+=`\\${n.charAt(e)}`}return s}var D=xt;function v(n){return(Array.isArray(n)?n:Object.entries(n)).filter(t=>t[1]!=null)}function Q(n){return Array.isArray(n)?n.find(t=>!Array.isArray(t)||Array.isArray(t[0]))?n.map(t=>v(t)):[n]:[v(n)]}function Ct(n){return n.filter(([t,e],r)=>{if(t.startsWith("$$"))return!1;for(let s=r-1;s>=0;s--)if(n[s][0]===t&&n[s][1]===e)return!1;return!0})}function K(n){return n==null?"":Ct(n).map(([t,e])=>e!=null?`${t}:${e};`:void 0).filter(Boolean).join("")}function L(n){return n&&typeof n=="object"&&!Array.isArray(n)}function F(n,t){let e=n,r=t;if(Array.isArray(e)&&Array.isArray(r))return[...e,...r];if(Array.isArray(e))return[...e];let s=$({},e);return L(e)&&L(r)&&Object.keys(r).forEach(i=>{L(r[i])?i in e?s[i]=F(e[i],r[i]):Object.assign(s,{[i]:r[i]}):Object.assign(s,{[i]:r[i]})}),s}function V(n){let t,e,r;if(Array.isArray(n)){for(e=Array(t=n.length);t--;)e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}if(Object.prototype.toString.call(n)==="[object Object]"){e={};for(t in n)t==="__proto__"?Object.defineProperty(e,t,{value:V(n[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}return n}function X(n){return typeof n[0]=="string"}function Y(n){return typeof n[0]=="string"}function P(n=[]){return Array.isArray(n)?n:[n]}function k(n){return Array.from(new Set(n))}var bt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,G="$$shortcut-no-merge";function tt(n=""){return bt.test(n)}function et(n){return typeof n=="function"?{match:n}:n}function z(n){return n.length===3}function rt(n){return n!=null}var B=class{_map=new Map;get(t,e){let r=this._map.get(t);if(r)return r.get(e)}getFallback(t,e,r){let s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.has(e)||s.set(e,r),s.get(e)}set(t,e,r){let s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.set(e,r),this}has(t,e){var r;return(r=this._map.get(t))==null?void 0:r.has(e)}delete(t,e){var r;return((r=this._map.get(t))==null?void 0:r.delete(e))||!1}deleteTop(t){return this._map.delete(t)}map(t){return Array.from(this._map.entries()).flatMap(([e,r])=>Array.from(r.entries()).map(([s,i])=>t(i,e,s)))}};var nt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function st(n){return nt.lastIndex=0,n.replace(nt,(t,e,r,s)=>s.split(/\s/g).map(i=>i.replace(/^(!?)(.*)/,`$1${e}${r}$2`)).join(" "))}var it=new Set;function ot(n){it.has(n)||(console.warn("[unocss]",n),it.add(n))}var Rt=n=>n.split(/[\s'"`;>=]+/g).filter(tt),H={name:"split",order:0,extract({code:n}){return new Set(Rt(n))}};function wt(n){return P(n).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var Ut={shortcuts:-1,default:0};function I(n={},t={}){let e=Object.assign({},t,n),r=(e.presets||[]).flatMap(P),s=[...r.filter(l=>l.enforce==="pre"),...r.filter(l=>!l.enforce),...r.filter(l=>l.enforce==="post")],i=Object.assign(Ut,...r.map(l=>l.layers),n.layers);function a(l){return k([...s.flatMap(y=>P(y[l]||[])),...P(e[l]||[])])}let o=a("extractors");o.length||o.push(H),o.sort((l,y)=>(l.order||0)-(y.order||0));let c=a("rules"),f={},u=c.length;c.forEach((l,y)=>{X(l)&&(f[l[0]]=[y,l[1],l[2]],delete c[y])});let S=V([...s.map(l=>l.theme||{}),e.theme||{}].reduce((l,y)=>F(l,y),{}));return a("extendTheme").forEach(l=>l(S)),O($({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:l=>l},e),{presets:s,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:i,theme:S,rulesSize:u,rulesDynamic:c,rulesStaticMap:f,preprocess:a("preprocess"),postprocess:a("postprocess"),preflights:a("preflights"),variants:a("variants").map(et),shortcuts:wt(a("shortcuts")),extractors:o})}var at="0.28.0";var lt=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=I(t,e)}version=at;_cache=new Map;config;blocked=new Set;parentOrders=new Map;setConfig(t,e){!t||(e&&(this.defaults=e),this.userConfig=t,this.config=I(t,this.defaults),this.blocked.clear(),this.parentOrders.clear(),this._cache.clear())}async applyExtractors(t,e,r=new Set){let s={get original(){return t},code:t,id:e};for(let i of this.config.extractors){let a=await i.extract(s);a==null||a.forEach(o=>r.add(o))}return r}makeContext(t,e){let r={rawSelector:t,currentSelector:e[1],theme:this.config.theme,generator:this,variantHandlers:e[2],constructCSS:(...s)=>this.constructCustomCSS(r,...s),variantMatch:e};return r}async parseToken(t,e){var f;if(this.blocked.has(t))return;let r=`${t}${e?` ${e}`:""}`,s=this._cache.get(r);if(s)return s;let i=t;for(let u of this.config.preprocess)i=u(t);if(this.isBlocked(i)){this.blocked.add(t),this._cache.set(r,null);return}let a=this.matchVariants(t,i);if(!a||this.isBlocked(a[1])){this.blocked.add(t),this._cache.set(r,null);return}let o=this.makeContext(t,[e||a[0],a[1],a[2]]),c=this.expandShortcut(o.currentSelector,o);if(c){let u=await this.stringifyShortcuts(o.variantMatch,o,c[0],c[1]);if(u==null?void 0:u.length)return this._cache.set(r,u),u}else{let u=(f=await this.parseUtil(o.variantMatch,o))==null?void 0:f.map(S=>this.stringifyUtil(S)).filter(rt);if(u==null?void 0:u.length)return this._cache.set(r,u),u}this._cache.set(r,null)}async generate(t,{id:e,scope:r,preflights:s=!0,safelist:i=!0,minify:a=!1}={}){let o=typeof t=="string"?await this.applyExtractors(t,e):t;i&&this.config.safelist.forEach(p=>o.add(p));let c=a?"":`
2
- `,f=new Set(["default"]),u=new Set,S=new Map;await Promise.all(Array.from(o).map(async p=>{var h;if(u.has(p))return;let g=await this.parseToken(p);if(g!=null){u.add(p);for(let x of g){let b=x[3]||"";S.has(b)||S.set(b,[]),S.get(b).push(x),((h=x[4])==null?void 0:h.layer)&&f.add(x[4].layer)}}})),s&&this.config.preflights.forEach(p=>{p.layer&&f.add(p.layer)});let l={},y=this.config.sortLayers(Array.from(f).sort((p,g)=>{var h,x;return((h=this.config.layers[p])!=null?h:0)-((x=this.config.layers[g])!=null?x:0)||p.localeCompare(g)})),w={};if(s){let p={generator:this,theme:this.config.theme};w=Object.fromEntries(await Promise.all(y.map(async g=>{let x=(await Promise.all(this.config.preflights.filter(b=>(b.layer||"default")===g).map(async b=>await b.getCSS(p)))).filter(Boolean).join(c);return[g,x]})))}let A=p=>{if(l[p])return l[p];let g=Array.from(S).sort((h,x)=>{var b,U,d;return((b=this.parentOrders.get(h[0]))!=null?b:0)-((U=this.parentOrders.get(x[0]))!=null?U:0)||((d=h[0])==null?void 0:d.localeCompare(x[0]||""))||0}).map(([h,x])=>{let b=x.length,U=x.filter(m=>{var R;return(((R=m[4])==null?void 0:R.layer)||"default")===p}).sort((m,R)=>{var M,T,E;return m[0]-R[0]||(((M=m[4])==null?void 0:M.sort)||0)-(((T=R[4])==null?void 0:T.sort)||0)||((E=m[1])==null?void 0:E.localeCompare(R[1]||""))||0}).map(m=>{var R;return[m[1]?$t(m[1],r):m[1],m[2],!!((R=m[4])==null?void 0:R.noMerge)]}).map(m=>[m[0]==null?m[0]:[m[0]],m[1],m[2]]);if(!U.length)return;let d=U.reverse().map(([m,R,M],T)=>{if(!M&&m&&this.config.mergeSelectors)for(let E=T+1;E<b;E++){let _=U[E];if(_&&!_[2]&&_[0]&&_[1]===R)return _[0].push(...m),null}return m?`${[...new Set(m)].join(`,${c}`)}{${R}}`:R}).filter(Boolean).reverse().join(c);return h?`${h}{${c}${d}${c}}`:d}).filter(Boolean).join(c);return s&&(g=[w[p],g].filter(Boolean).join(c)),l[p]=!a&&g?`/* layer: ${p} */${c}${g}`:g},C=(p=y,g)=>p.filter(h=>!(g==null?void 0:g.includes(h))).map(h=>A(h)||"").filter(Boolean).join(c);return{get css(){return C()},layers:y,getLayers:C,getLayer:A,matched:u}}matchVariants(t,e){let r=new Set,s=[],i=e||t,a=!1,o={rawSelector:t,theme:this.config.theme,generator:this};for(;;){a=!1;for(let c of this.config.variants){if(!c.multiPass&&r.has(c))continue;let f=c.match(i,o);if(!!f&&(typeof f=="string"&&(f={matcher:f}),f)){i=f.matcher,Array.isArray(f.parent)&&this.parentOrders.set(f.parent[0],f.parent[1]),s.push(f),r.add(c),a=!0;break}}if(!a)break;if(s.length>500)throw new Error(`Too many variants applied to "${t}"`)}return[t,i,s]}applyVariants(t,e=t[4],r=t[1]){let s=[...e].sort((o,c)=>(o.order||0)-(c.order||0)),i=s.reduce((o,c)=>{var f;return((f=c.body)==null?void 0:f.call(c,o))||o},t[2]),a={selector:s.reduce((o,c)=>{var f;return((f=c.selector)==null?void 0:f.call(c,o,i))||o},Mt(r)),entries:i,parent:s.reduce((o,c)=>Array.isArray(c.parent)?c.parent[0]:c.parent||o,void 0),layer:s.reduce((o,c)=>c.layer||o,void 0),sort:s.reduce((o,c)=>c.sort||o,void 0)};for(let o of this.config.postprocess)o(a);return a}constructCustomCSS(t,e,r){e=v(e);let{selector:s,entries:i,parent:a}=this.applyVariants([0,r||t.rawSelector,e,void 0,t.variantHandlers]),o=`${s}{${K(i)}}`;return a?`${a}{${o}}`:o}async parseUtil(t,e,r=!1){var u,S;let[s,i,a]=typeof t=="string"?this.matchVariants(t):t,o=this.config.rulesStaticMap[i];if(o&&o[1]&&(r||!((u=o[2])==null?void 0:u.internal)))return[[o[0],s,v(o[1]),o[2],a]];e.variantHandlers=a;let{rulesDynamic:c,rulesSize:f}=this.config;for(let l=f;l>=0;l--){let y=c[l];if(!y||((S=y[2])==null?void 0:S.internal)&&!r)continue;let[w,A,C]=y,p=i.match(w);if(!p)continue;let g=await A(p,e);if(!g)continue;if(typeof g=="string")return[[l,g,C]];let h=Q(g).filter(x=>x.length);if(h.length)return h.map(x=>[l,s,x,C,a])}}stringifyUtil(t){var l;if(!t)return;if(z(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:r,parent:s,layer:i,sort:a}=this.applyVariants(t),o=K(r);if(!o)return;let y=(l=t[3])!=null?l:{},{layer:c,sort:f}=y,u=J(y,["layer","sort"]),S=O($({},u),{layer:i!=null?i:c,sort:a!=null?a:f});return[t[0],e,o,s,S]}expandShortcut(t,e,r=3){if(r===0)return;let s,i;for(let a of this.config.shortcuts)if(Y(a)){if(a[0]===t){s=s||a[2],i=a[1];break}}else{let o=t.match(a[0]);if(o&&(i=a[1](o,e)),i){s=s||a[2];break}}if(typeof i=="string"&&(i=st(i).split(/\s+/g)),!!i)return[i.flatMap(a=>{var o;return((o=this.expandShortcut(a,e,r-1))==null?void 0:o[0])||[a]}).filter(a=>a!==""),s]}async stringifyShortcuts(t,e,r,s={layer:this.config.shortcutsLayer}){var f;let i=new B,a=(await Promise.all(k(r).map(async u=>{let S=await this.parseUtil(u,e,!0);return S||ot(`unmatched utility "${u}" in shortcut "${t[1]}"`),S||[]}))).flat(1).filter(Boolean).sort((u,S)=>u[0]-S[0]),[o,,c]=t;for(let u of a){if(z(u))continue;let{selector:S,entries:l,parent:y,sort:w}=this.applyVariants(u,[...u[4],...c],o);i.getFallback(S,y,[[],u[0]])[0].push([l,!!((f=u[3])==null?void 0:f.noMerge),w!=null?w:0])}return i.map(([u,S],l,y)=>{let w=(C,p,g)=>{let h=Math.max(...g.map(b=>b[1])),x=g.map(b=>b[0]);return(C?[x.flat(1)]:x).map(b=>{let U=K(b);if(U)return[S,l,U,y,O($({},s),{noMerge:p,sort:h})]})};return[[u.filter(([,C])=>C).map(([C,,p])=>[C,p]),!0],[u.filter(([,C])=>!C).map(([C,,p])=>[C,p]),!1]].map(([C,p])=>[...w(!1,p,C.filter(([g])=>g.some(h=>h[0]===G))),...w(!0,p,C.filter(([g])=>g.every(h=>h[0]!==G)))])}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function ut(n,t){return new lt(n,t)}var ft=/ \$\$ /,At=n=>n.match(ft);function $t(n,t){return At(n)?n.replace(ft,t?` ${t} `:" "):t?`${t} ${n}`:n}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Mt(n){return ct.test(n)?n.replace(ct,(t,e,r,s)=>`[${D(e)}${r}"${D(s)}"]`):`.${D(n)}`}var Tt=n=>n.replace(/-(\w)/g,(t,e)=>e?e.toUpperCase():""),pt=n=>n.charAt(0).toUpperCase()+n.slice(1),dt=n=>n.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),gt=["Webkit","Moz","ms"];function ht(n){let t={};function e(r){let s=t[r];if(s)return s;let i=Tt(r);if(i!=="filter"&&i in n)return t[r]=dt(i);i=pt(i);for(let a=0;a<gt.length;a++){let o=`${gt[a]}${i}`;if(o in n)return t[r]=dt(pt(o))}return r}return({entries:r})=>r.forEach(s=>{s[0].startsWith("--")||(s[0]=e(s[0]))})}function q(n={}){var b,U;if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let t=window.__unocss||{},e=t==null?void 0:t.runtime,r=Object.assign(n.defaults||{},e);if(e==null?void 0:e.autoPrefix){let d=r.postprocess;d||(d=[]),Array.isArray(d)||(d=[d]),d.unshift(ht(document.createElement("div").style)),r.postprocess=d}(b=e==null?void 0:e.configResolved)==null||b.call(e,t,r);let s,i=!0,a,o=ut(t,r),c=new Set,f,u=[],S=()=>new Promise(d=>{u.push(d),f!=null&&clearTimeout(f),f=setTimeout(()=>l().then(()=>{let m=u;u=[],m.forEach(R=>R())}),0)});async function l(){let d=await o.generate(c);s||(s=document.createElement("style"),document.documentElement.prepend(s)),s.innerHTML=d.css}async function y(d){await o.applyExtractors(d,void 0,c),await S()}async function w(){let d=document.body&&document.body.outerHTML;d&&await y(d)}let A=new MutationObserver(d=>{i||d.forEach(m=>{let R=m.target;if(R===s||a&&!a(R))return;let M=Array.from(R.attributes).map(E=>E.value?`${E.name}="${E.value}"`:E.name).join(" "),T=`<${R.tagName.toLowerCase()} ${M}>`;y(T)})}),C=!1;function p(){if(!C)return;let d=document.documentElement||document.body;!d||(A.observe(d,{childList:!0,subtree:!0,attributes:!0}),C=!0)}function g(){w(),p()}function h(){g(),window.addEventListener("load",g),window.addEventListener("DOMContentLoaded",g)}let x=window.__unocss_runtime=window.__unocss_runtime={version:o.version,uno:o,async extract(d){if(typeof d=="string")return await y(d);d.forEach(m=>c.add(m)),await l()},extractAll:w,inspect(d){a=d},toggleObserver(d){d===void 0?i=!i:i=!!d,!C&&!i&&h()}};((U=e==null?void 0:e.ready)==null?void 0:U.call(e,x))!==!1&&(i=!1,h())}q();})();
1
+ (()=>{var mt=Object.defineProperty,yt=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var W=(n,t,e)=>t in n?mt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,$=(n,t)=>{for(var e in t||(t={}))N.call(t,e)&&W(n,e,t[e]);if(j)for(var e of j(t))Z.call(t,e)&&W(n,e,t[e]);return n},O=(n,t)=>yt(n,St(t));var J=(n,t)=>{var e={};for(var r in n)N.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&j)for(var r of j(n))t.indexOf(r)<0&&Z.call(n,r)&&(e[r]=n[r]);return e};function xt(n){let t=n.length,e=-1,r,i="",s=n.charCodeAt(0);for(;++e<t;){if(r=n.charCodeAt(e),r===0){i+="\uFFFD";continue}if(r===44){i+="\\2c ";continue}if(r>=1&&r<=31||r===127||e===0&&r>=48&&r<=57||e===1&&r>=48&&r<=57&&s===45){i+=`\\${r.toString(16)} `;continue}if(e===0&&t===1&&r===45){i+=`\\${n.charAt(e)}`;continue}if(r>=128||r===45||r===95||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122){i+=n.charAt(e);continue}i+=`\\${n.charAt(e)}`}return i}var D=xt;function v(n){return(Array.isArray(n)?n:Object.entries(n)).filter(t=>t[1]!=null)}function Q(n){return Array.isArray(n)?n.find(t=>!Array.isArray(t)||Array.isArray(t[0]))?n.map(t=>v(t)):[n]:[v(n)]}function Ct(n){return n.filter(([t,e],r)=>{if(t.startsWith("$$"))return!1;for(let i=r-1;i>=0;i--)if(n[i][0]===t&&n[i][1]===e)return!1;return!0})}function K(n){return n==null?"":Ct(n).map(([t,e])=>e!=null?`${t}:${e};`:void 0).filter(Boolean).join("")}function L(n){return n&&typeof n=="object"&&!Array.isArray(n)}function z(n,t){let e=n,r=t;if(Array.isArray(e)&&Array.isArray(r))return[...e,...r];if(Array.isArray(e))return[...e];let i=$({},e);return L(e)&&L(r)&&Object.keys(r).forEach(s=>{L(r[s])?s in e?i[s]=z(e[s],r[s]):Object.assign(i,{[s]:r[s]}):Object.assign(i,{[s]:r[s]})}),i}function V(n){let t,e,r;if(Array.isArray(n)){for(e=Array(t=n.length);t--;)e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}if(Object.prototype.toString.call(n)==="[object Object]"){e={};for(t in n)t==="__proto__"?Object.defineProperty(e,t,{value:V(n[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}return n}function X(n){return typeof n[0]=="string"}function Y(n){return typeof n[0]=="string"}function P(n=[]){return Array.isArray(n)?n:[n]}function k(n){return Array.from(new Set(n))}var bt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,F="$$shortcut-no-merge";function tt(n=""){return bt.test(n)}function et(n){return typeof n=="function"?{match:n}:n}function G(n){return n.length===3}function rt(n){return n!=null}var B=class{_map=new Map;get(t,e){let r=this._map.get(t);if(r)return r.get(e)}getFallback(t,e,r){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.has(e)||i.set(e,r),i.get(e)}set(t,e,r){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.set(e,r),this}has(t,e){var r;return(r=this._map.get(t))==null?void 0:r.has(e)}delete(t,e){var r;return((r=this._map.get(t))==null?void 0:r.delete(e))||!1}deleteTop(t){return this._map.delete(t)}map(t){return Array.from(this._map.entries()).flatMap(([e,r])=>Array.from(r.entries()).map(([i,s])=>t(s,e,i)))}};var nt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function it(n){return nt.lastIndex=0,n.replace(nt,(t,e,r,i)=>i.split(/\s/g).map(s=>s.replace(/^(!?)(.*)/,`$1${e}${r}$2`)).join(" "))}var st=new Set;function ot(n){st.has(n)||(console.warn("[unocss]",n),st.add(n))}var Rt=n=>n.split(/[\s'"`;>=]+/g).filter(tt),H={name:"split",order:0,extract({code:n}){return new Set(Rt(n))}};function wt(n){return P(n).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var Ut={shortcuts:-1,default:0};function I(n={},t={}){let e=Object.assign({},t,n),r=(e.presets||[]).flatMap(P),i=[...r.filter(u=>u.enforce==="pre"),...r.filter(u=>!u.enforce),...r.filter(u=>u.enforce==="post")],s=Object.assign(Ut,...r.map(u=>u.layers),n.layers);function o(u){return k([...i.flatMap(y=>P(y[u]||[])),...P(e[u]||[])])}let a=o("extractors");a.length||a.push(H),a.sort((u,y)=>(u.order||0)-(y.order||0));let c=o("rules"),l={},g=c.length;c.forEach((u,y)=>{X(u)&&(l[u[0]]=[y,u[1],u[2]],delete c[y])});let x=V([...i.map(u=>u.theme||{}),e.theme||{}].reduce((u,y)=>z(u,y),{}));return o("extendTheme").forEach(u=>u(x)),O($({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:u=>u},e),{presets:i,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:s,theme:x,rulesSize:g,rulesDynamic:c,rulesStaticMap:l,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),variants:o("variants").map(et),shortcuts:wt(o("shortcuts")),extractors:a})}var at="0.28.1";var lt=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=I(t,e)}version=at;_cache=new Map;config;blocked=new Set;parentOrders=new Map;setConfig(t,e){!t||(e&&(this.defaults=e),this.userConfig=t,this.config=I(t,this.defaults),this.blocked.clear(),this.parentOrders.clear(),this._cache.clear())}async applyExtractors(t,e,r=new Set){let i={get original(){return t},code:t,id:e};for(let s of this.config.extractors){let o=await s.extract(i);o==null||o.forEach(a=>r.add(a))}return r}makeContext(t,e){let r={rawSelector:t,currentSelector:e[1],theme:this.config.theme,generator:this,variantHandlers:e[2],constructCSS:(...i)=>this.constructCustomCSS(r,...i),variantMatch:e};return r}async parseToken(t,e){var c;if(this.blocked.has(t))return;let r=`${t}${e?` ${e}`:""}`;if(this._cache.has(r))return this._cache.get(r);let i=t;for(let l of this.config.preprocess)i=l(t);if(this.isBlocked(i)){this.blocked.add(t),this._cache.set(r,null);return}let s=this.matchVariants(t,i);if(!s||this.isBlocked(s[1])){this.blocked.add(t),this._cache.set(r,null);return}let o=this.makeContext(t,[e||s[0],s[1],s[2]]),a=this.expandShortcut(o.currentSelector,o);if(a){let l=await this.stringifyShortcuts(o.variantMatch,o,a[0],a[1]);if(l==null?void 0:l.length)return this._cache.set(r,l),l}else{let l=(c=await this.parseUtil(o.variantMatch,o))==null?void 0:c.map(g=>this.stringifyUtil(g)).filter(rt);if(l==null?void 0:l.length)return this._cache.set(r,l),l}this._cache.set(r,null)}async generate(t,{id:e,scope:r,preflights:i=!0,safelist:s=!0,minify:o=!1}={}){let a=typeof t=="string"?await this.applyExtractors(t,e):t;s&&this.config.safelist.forEach(p=>a.add(p));let c=o?"":`
2
+ `,l=new Set(["default"]),g=new Set,x=new Map;await Promise.all(Array.from(a).map(async p=>{var m;if(g.has(p))return;let d=await this.parseToken(p);if(d!=null){g.add(p);for(let S of d){let b=S[3]||"";x.has(b)||x.set(b,[]),x.get(b).push(S),((m=S[4])==null?void 0:m.layer)&&l.add(S[4].layer)}}})),i&&this.config.preflights.forEach(p=>{p.layer&&l.add(p.layer)});let u={},y=this.config.sortLayers(Array.from(l).sort((p,d)=>{var m,S;return((m=this.config.layers[p])!=null?m:0)-((S=this.config.layers[d])!=null?S:0)||p.localeCompare(d)})),w={};if(i){let p={generator:this,theme:this.config.theme};w=Object.fromEntries(await Promise.all(y.map(async d=>{let S=(await Promise.all(this.config.preflights.filter(b=>(b.layer||"default")===d).map(async b=>await b.getCSS(p)))).filter(Boolean).join(c);return[d,S]})))}let A=p=>{if(u[p])return u[p];let d=Array.from(x).sort((m,S)=>{var b,U,f;return((b=this.parentOrders.get(m[0]))!=null?b:0)-((U=this.parentOrders.get(S[0]))!=null?U:0)||((f=m[0])==null?void 0:f.localeCompare(S[0]||""))||0}).map(([m,S])=>{let b=S.length,U=S.filter(h=>{var R;return(((R=h[4])==null?void 0:R.layer)||"default")===p}).sort((h,R)=>{var M,_,E;return h[0]-R[0]||(((M=h[4])==null?void 0:M.sort)||0)-(((_=R[4])==null?void 0:_.sort)||0)||((E=h[1])==null?void 0:E.localeCompare(R[1]||""))||0}).map(h=>{var R;return[h[1]?$t(h[1],r):h[1],h[2],!!((R=h[4])==null?void 0:R.noMerge)]}).map(h=>[h[0]==null?h[0]:[h[0]],h[1],h[2]]);if(!U.length)return;let f=U.reverse().map(([h,R,M],_)=>{if(!M&&h&&this.config.mergeSelectors)for(let E=_+1;E<b;E++){let T=U[E];if(T&&!T[2]&&T[0]&&T[1]===R)return T[0].push(...h),null}return h?`${[...new Set(h)].join(`,${c}`)}{${R}}`:R}).filter(Boolean).reverse().join(c);return m?`${m}{${c}${f}${c}}`:f}).filter(Boolean).join(c);return i&&(d=[w[p],d].filter(Boolean).join(c)),u[p]=!o&&d?`/* layer: ${p} */${c}${d}`:d},C=(p=y,d)=>p.filter(m=>!(d==null?void 0:d.includes(m))).map(m=>A(m)||"").filter(Boolean).join(c);return{get css(){return C()},layers:y,getLayers:C,getLayer:A,matched:g}}matchVariants(t,e){let r=new Set,i=[],s=e||t,o=!1,a={rawSelector:t,theme:this.config.theme,generator:this};for(;;){o=!1;for(let c of this.config.variants){if(!c.multiPass&&r.has(c))continue;let l=c.match(s,a);if(!!l&&(typeof l=="string"&&(l={matcher:l}),l)){s=l.matcher,Array.isArray(l.parent)&&this.parentOrders.set(l.parent[0],l.parent[1]),i.push(l),r.add(c),o=!0;break}}if(!o)break;if(i.length>500)throw new Error(`Too many variants applied to "${t}"`)}return[t,s,i]}applyVariants(t,e=t[4],r=t[1]){let i=[...e].sort((a,c)=>(a.order||0)-(c.order||0)),s=i.reduce((a,c)=>{var l;return((l=c.body)==null?void 0:l.call(c,a))||a},t[2]),o={selector:i.reduce((a,c)=>{var l;return((l=c.selector)==null?void 0:l.call(c,a,s))||a},Mt(r)),entries:s,parent:i.reduce((a,c)=>Array.isArray(c.parent)?c.parent[0]:c.parent||a,void 0),layer:i.reduce((a,c)=>c.layer||a,void 0),sort:i.reduce((a,c)=>c.sort||a,void 0)};for(let a of this.config.postprocess)a(o);return o}constructCustomCSS(t,e,r){e=v(e);let{selector:i,entries:s,parent:o}=this.applyVariants([0,r||t.rawSelector,e,void 0,t.variantHandlers]),a=`${i}{${K(s)}}`;return o?`${o}{${a}}`:a}async parseUtil(t,e,r=!1){var g,x;let[i,s,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[s];if(a&&a[1]&&(r||!((g=a[2])==null?void 0:g.internal)))return[[a[0],i,v(a[1]),a[2],o]];e.variantHandlers=o;let{rulesDynamic:c,rulesSize:l}=this.config;for(let u=l;u>=0;u--){let y=c[u];if(!y||((x=y[2])==null?void 0:x.internal)&&!r)continue;let[w,A,C]=y,p=s.match(w);if(!p)continue;let d=await A(p,e);if(!d)continue;if(typeof d=="string")return[[u,d,C]];let m=Q(d).filter(S=>S.length);if(m.length)return m.map(S=>[u,i,S,C,o])}}stringifyUtil(t){var u;if(!t)return;if(G(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:r,parent:i,layer:s,sort:o}=this.applyVariants(t),a=K(r);if(!a)return;let y=(u=t[3])!=null?u:{},{layer:c,sort:l}=y,g=J(y,["layer","sort"]),x=O($({},g),{layer:s!=null?s:c,sort:o!=null?o:l});return[t[0],e,a,i,x]}expandShortcut(t,e,r=3){if(r===0)return;let i,s;for(let o of this.config.shortcuts)if(Y(o)){if(o[0]===t){i=i||o[2],s=o[1];break}}else{let a=t.match(o[0]);if(a&&(s=o[1](a,e)),s){i=i||o[2];break}}if(typeof s=="string"&&(s=it(s).split(/\s+/g)),!!s)return[s.flatMap(o=>{var a;return((a=this.expandShortcut(o,e,r-1))==null?void 0:a[0])||[o]}).filter(o=>o!==""),i]}async stringifyShortcuts(t,e,r,i={layer:this.config.shortcutsLayer}){var l;let s=new B,o=(await Promise.all(k(r).map(async g=>{let x=await this.parseUtil(g,e,!0);return x||ot(`unmatched utility "${g}" in shortcut "${t[1]}"`),x||[]}))).flat(1).filter(Boolean).sort((g,x)=>g[0]-x[0]),[a,,c]=t;for(let g of o){if(G(g))continue;let{selector:x,entries:u,parent:y,sort:w}=this.applyVariants(g,[...g[4],...c],a);s.getFallback(x,y,[[],g[0]])[0].push([u,!!((l=g[3])==null?void 0:l.noMerge),w!=null?w:0])}return s.map(([g,x],u,y)=>{let w=(C,p,d)=>{let m=Math.max(...d.map(b=>b[1])),S=d.map(b=>b[0]);return(C?[S.flat(1)]:S).map(b=>{let U=K(b);if(U)return[x,u,U,y,O($({},i),{noMerge:p,sort:m})]})};return[[g.filter(([,C])=>C).map(([C,,p])=>[C,p]),!0],[g.filter(([,C])=>!C).map(([C,,p])=>[C,p]),!1]].map(([C,p])=>[...w(!1,p,C.filter(([d])=>d.some(m=>m[0]===F))),...w(!0,p,C.filter(([d])=>d.every(m=>m[0]!==F)))])}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function ut(n,t){return new lt(n,t)}var ft=/ \$\$ /,At=n=>n.match(ft);function $t(n,t){return At(n)?n.replace(ft,t?` ${t} `:" "):t?`${t} ${n}`:n}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Mt(n){return ct.test(n)?n.replace(ct,(t,e,r,i)=>`[${D(e)}${r}"${D(i)}"]`):`.${D(n)}`}var _t=n=>n.replace(/-(\w)/g,(t,e)=>e?e.toUpperCase():""),pt=n=>n.charAt(0).toUpperCase()+n.slice(1),dt=n=>n.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),gt=["Webkit","Moz","ms"];function ht(n){let t={};function e(r){let i=t[r];if(i)return i;let s=_t(r);if(s!=="filter"&&s in n)return t[r]=dt(s);s=pt(s);for(let o=0;o<gt.length;o++){let a=`${gt[o]}${s}`;if(a in n)return t[r]=dt(pt(a))}return r}return({entries:r})=>r.forEach(i=>{i[0].startsWith("--")||(i[0]=e(i[0]))})}function q(n={}){var b,U;if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let t=window.__unocss||{},e=t==null?void 0:t.runtime,r=Object.assign(n.defaults||{},e);if(e==null?void 0:e.autoPrefix){let f=r.postprocess;f||(f=[]),Array.isArray(f)||(f=[f]),f.unshift(ht(document.createElement("div").style)),r.postprocess=f}(b=e==null?void 0:e.configResolved)==null||b.call(e,t,r);let i,s=!0,o,a=ut(t,r),c=new Set,l,g=[],x=()=>new Promise(f=>{g.push(f),l!=null&&clearTimeout(l),l=setTimeout(()=>u().then(()=>{let h=g;g=[],h.forEach(R=>R())}),0)});async function u(){let f=await a.generate(c);i||(i=document.createElement("style"),document.documentElement.prepend(i)),i.innerHTML=f.css,c=f.matched}async function y(f){let h=c.size;await a.applyExtractors(f,void 0,c),h!==c.size&&await x()}async function w(){let f=document.body&&document.body.outerHTML;f&&await y(f)}let A=new MutationObserver(f=>{s||f.forEach(h=>{let R=h.target;if(R===i||o&&!o(R))return;let M=Array.from(R.attributes).map(E=>E.value?`${E.name}="${E.value}"`:E.name).join(" "),_=`<${R.tagName.toLowerCase()} ${M}>`;y(_)})}),C=!1;function p(){if(!C)return;let f=document.documentElement||document.body;!f||(A.observe(f,{childList:!0,subtree:!0,attributes:!0}),C=!0)}function d(){w(),p()}function m(){d(),window.addEventListener("load",d),window.addEventListener("DOMContentLoaded",d)}let S=window.__unocss_runtime=window.__unocss_runtime={version:a.version,uno:a,async extract(f){typeof f!="string"&&(f.forEach(h=>c.add(h)),f=""),await y(f)},extractAll:w,inspect(f){o=f},toggleObserver(f){f===void 0?s=!s:s=!!f,!C&&!s&&m()}};((U=e==null?void 0:e.ready)==null?void 0:U.call(e,S))!==!1&&(s=!1,m())}q();})();
package/dist/index.js CHANGED
@@ -80,7 +80,7 @@ function init(inlineConfig = {}) {
80
80
  let paused = true;
81
81
  let inspector;
82
82
  const uno = (0, import_core.createGenerator)(config, defaultConfig);
83
- const tokens = /* @__PURE__ */ new Set();
83
+ let tokens = /* @__PURE__ */ new Set();
84
84
  let _timer;
85
85
  let _resolvers = [];
86
86
  const scheduleUpdate = () => new Promise((resolve) => {
@@ -100,10 +100,13 @@ function init(inlineConfig = {}) {
100
100
  document.documentElement.prepend(styleElement);
101
101
  }
102
102
  styleElement.innerHTML = result.css;
103
+ tokens = result.matched;
103
104
  }
104
105
  async function extract(str) {
106
+ const tokenSize = tokens.size;
105
107
  await uno.applyExtractors(str, void 0, tokens);
106
- await scheduleUpdate();
108
+ if (tokenSize !== tokens.size)
109
+ await scheduleUpdate();
107
110
  }
108
111
  async function extractAll() {
109
112
  const html = document.body && document.body.outerHTML;
@@ -151,10 +154,11 @@ function init(inlineConfig = {}) {
151
154
  version: uno.version,
152
155
  uno,
153
156
  async extract(userTokens) {
154
- if (typeof userTokens === "string")
155
- return await extract(userTokens);
156
- userTokens.forEach((t) => tokens.add(t));
157
- await updateStyle();
157
+ if (typeof userTokens !== "string") {
158
+ userTokens.forEach((t) => tokens.add(t));
159
+ userTokens = "";
160
+ }
161
+ await extract(userTokens);
158
162
  },
159
163
  extractAll,
160
164
  inspect(callback) {
package/dist/index.mjs CHANGED
@@ -53,7 +53,7 @@ function init(inlineConfig = {}) {
53
53
  let paused = true;
54
54
  let inspector;
55
55
  const uno = createGenerator(config, defaultConfig);
56
- const tokens = /* @__PURE__ */ new Set();
56
+ let tokens = /* @__PURE__ */ new Set();
57
57
  let _timer;
58
58
  let _resolvers = [];
59
59
  const scheduleUpdate = () => new Promise((resolve) => {
@@ -73,10 +73,13 @@ function init(inlineConfig = {}) {
73
73
  document.documentElement.prepend(styleElement);
74
74
  }
75
75
  styleElement.innerHTML = result.css;
76
+ tokens = result.matched;
76
77
  }
77
78
  async function extract(str) {
79
+ const tokenSize = tokens.size;
78
80
  await uno.applyExtractors(str, void 0, tokens);
79
- await scheduleUpdate();
81
+ if (tokenSize !== tokens.size)
82
+ await scheduleUpdate();
80
83
  }
81
84
  async function extractAll() {
82
85
  const html = document.body && document.body.outerHTML;
@@ -124,10 +127,11 @@ function init(inlineConfig = {}) {
124
127
  version: uno.version,
125
128
  uno,
126
129
  async extract(userTokens) {
127
- if (typeof userTokens === "string")
128
- return await extract(userTokens);
129
- userTokens.forEach((t) => tokens.add(t));
130
- await updateStyle();
130
+ if (typeof userTokens !== "string") {
131
+ userTokens.forEach((t) => tokens.add(t));
132
+ userTokens = "";
133
+ }
134
+ await extract(userTokens);
131
135
  },
132
136
  extractAll,
133
137
  inspect(callback) {