@unocss/runtime 0.22.6 → 0.22.7

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 gt=Object.defineProperty,ht=Object.defineProperties;var mt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var yt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable;var N=(e,t,r)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,O=(e,t)=>{for(var r in t||(t={}))yt.call(t,r)&&N(e,r,t[r]);if(W)for(var r of W(t))St.call(t,r)&&N(e,r,t[r]);return e},j=(e,t)=>ht(e,mt(t));function xt(e){let t=e.length,r=-1,n,i="",s=e.charCodeAt(0);for(;++r<t;){if(n=e.charCodeAt(r),n===0){i+="\uFFFD";continue}if(n===44){i+="\\2c ";continue}if(n>=1&&n<=31||n===127||r===0&&n>=48&&n<=57||r===1&&n>=48&&n<=57&&s===45){i+=`\\${n.toString(16)} `;continue}if(r===0&&t===1&&n===45){i+=`\\${e.charAt(r)}`;continue}if(n>=128||n===45||n===95||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122){i+=e.charAt(r);continue}i+=`\\${e.charAt(r)}`}return i}var v=xt;function _(e){return(Array.isArray(e)?e:Object.entries(e)).filter(t=>t[1]!=null)}function Z(e){return Array.isArray(e)?e.find(t=>!Array.isArray(t)||Array.isArray(t[0]))?e.map(t=>_(t)):[e]:[_(e)]}function Ct(e){return e.filter(([t,r],n)=>{if(t.startsWith("$$"))return!1;for(let i=n-1;i>=0;i--)if(e[i][0]===t&&e[i][1]===r)return!1;return!0})}function D(e){return e==null?"":Ct(e).map(([t,r])=>r!=null?`${t}:${r};`:void 0).filter(Boolean).join("")}function k(e){return e&&typeof e=="object"&&!Array.isArray(e)}function F(e,t){let r=e,n=t;if(Array.isArray(r)&&Array.isArray(n))return[...r,...n];if(Array.isArray(r))return[...r];let i=O({},r);return k(r)&&k(n)&&Object.keys(n).forEach(s=>{k(n[s])?s in r?i[s]=F(r[s],n[s]):Object.assign(i,{[s]:n[s]}):Object.assign(i,{[s]:n[s]})}),i}function V(e){let t,r,n;if(Array.isArray(e)){for(r=Array(t=e.length);t--;)r[t]=(n=e[t])&&typeof n=="object"?V(n):n;return r}if(Object.prototype.toString.call(e)==="[object Object]"){r={};for(t in e)t==="__proto__"?Object.defineProperty(r,t,{value:V(e[t]),configurable:!0,enumerable:!0,writable:!0}):r[t]=(n=e[t])&&typeof n=="object"?V(n):n;return r}return e}function J(e){return typeof e[0]=="string"}function Q(e){return typeof e[0]=="string"}function M(e=[]){return Array.isArray(e)?e:[e]}function K(e){return Array.from(new Set(e))}var bt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,z="$$shortcut-no-merge";function X(e=""){return bt.test(e)}function Y(e){return typeof e=="function"?{match:e}:e}function B(e){return e.length===3}function tt(e){return e!=null}var G=class{_map=new Map;get(t,r){let n=this._map.get(t);if(n)return n.get(r)}getFallback(t,r,n){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.has(r)||i.set(r,n),i.get(r)}set(t,r,n){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.set(r,n),this}has(t,r){var n;return(n=this._map.get(t))==null?void 0:n.has(r)}delete(t,r){var n;return((n=this._map.get(t))==null?void 0:n.delete(r))||!1}deleteTop(t){return this._map.delete(t)}map(t){return Array.from(this._map.entries()).flatMap(([r,n])=>Array.from(n.entries()).map(([i,s])=>t(s,r,i)))}};var wt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function et(e){let t=[],r;for(;r=wt.exec(e);){let i=r.index,s=i+r[0].length,[,o,a,l]=r,p=l.split(/\s/g).map(h=>h.replace(/^(!?)(.*)/,`$1${o}${a}$2`)).join(" ");t.unshift([i,s,p])}let n=e;return t.forEach(([i,s,o])=>{n=n.slice(0,i)+o+n.slice(s)}),n}var rt=new Set;function nt(e){rt.has(e)||(console.warn("[unocss]",e),rt.add(e))}var Rt=e=>e.split(/[\s'"`;>=]+/g).filter(X),H={name:"split",order:0,extract({code:e}){return new Set(Rt(e))}};function Ut(e){return M(e).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var Et={shortcuts:-1,default:0};function I(e={},t={}){let r=Object.assign({},t,e),n=(r.presets||[]).flatMap(M),i=[...n.filter(u=>u.enforce==="pre"),...n.filter(u=>!u.enforce),...n.filter(u=>u.enforce==="post")],s=Object.assign(Et,...n.map(u=>u.layers),e.layers);function o(u){return K([...i.flatMap(x=>M(x[u]||[])),...M(r[u]||[])])}let a=o("extractors");a.length||a.push(H),a.sort((u,x)=>(u.order||0)-(x.order||0));let l=o("rules"),p={},h=l.length;l.forEach((u,x)=>{J(u)&&(p[u[0]]=[x,u[1],u[2]],delete l[x])});let S=V([...i.map(u=>u.theme||{}),r.theme||{}].reduce((u,x)=>F(u,x),{}));return o("extendTheme").forEach(u=>u(S)),j(O({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:u=>u},r),{presets:i,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:s,theme:S,rulesSize:h,rulesDynamic:l,rulesStaticMap:p,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),variants:o("variants").map(Y),shortcuts:Ut(o("shortcuts")),extractors:a})}var it="0.22.6";var st=class{constructor(t={},r={}){this.userConfig=t;this.defaults=r;this.config=I(t,r)}version=it;_cache=new Map;config;blocked=new Set;parentOrders=new Map;setConfig(t,r){!t||(r&&(this.defaults=r),this.userConfig=t,this.config=I(t,this.defaults),this.blocked.clear(),this.parentOrders.clear(),this._cache.clear())}async applyExtractors(t,r,n=new Set){let i={get original(){return t},code:t,id:r};for(let s of this.config.extractors){let o=await s.extract(i);o==null||o.forEach(a=>n.add(a))}return n}async generate(t,{id:r,scope:n,preflights:i=!0,safelist:s=!0,minify:o=!1}={}){let a=typeof t=="string"?await this.applyExtractors(t,r):t;s&&this.config.safelist.forEach(c=>a.add(c));let l=o?"":`
2
- `,p=new Set(["default"]),h=new Set,S=new Map,u=(c,d)=>{var g;this._cache.set(c,d),h.add(c);for(let m of d){let R=m[3]||"";S.has(R)||S.set(R,[]),S.get(R).push(m),((g=m[4])==null?void 0:g.layer)&&p.add(m[4].layer)}},x=c=>{this.blocked.add(c),this._cache.set(c,null)};await Promise.all(Array.from(a).map(async c=>{var $;if(h.has(c)||this.blocked.has(c))return;if(this._cache.has(c)){let C=this._cache.get(c);C&&u(c,C);return}let d=c;for(let C of this.config.preprocess)d=C(c);if(this.isBlocked(d))return x(d);let g=this.matchVariants(c,d);if(!g||this.isBlocked(g[1]))return x(c);let m={rawSelector:c,currentSelector:g[1],theme:this.config.theme,generator:this,variantHandlers:g[2],constructCSS:(...C)=>this.constructCustomCSS(m,...C)},R=this.expandShortcut(g[1],m);if(R){let C=await this.stringifyShortcuts(g,m,R[0],R[1]);if(C==null?void 0:C.length)return u(c,C)}else{let C=($=await this.parseUtil(g,m))==null?void 0:$.map(y=>this.stringifyUtil(y)).filter(tt);if(C==null?void 0:C.length)return u(c,C)}this._cache.set(c,null)})),i&&this.config.preflights.forEach(c=>{c.layer&&p.add(c.layer)});let E={},A=this.config.sortLayers(Array.from(p).sort((c,d)=>{var g,m;return((g=this.config.layers[c])!=null?g:0)-((m=this.config.layers[d])!=null?m:0)||c.localeCompare(d)})),b={};i&&(b=Object.fromEntries(await Promise.all(A.map(async c=>{let g=(await Promise.all(this.config.preflights.filter(m=>(m.layer||"default")===c).map(async m=>await m.getCSS()))).filter(Boolean).join(l);return[c,g]}))));let f=c=>{if(E[c])return E[c];let d=Array.from(S).sort((g,m)=>{var R,$,C;return((R=this.parentOrders.get(g[0]))!=null?R:0)-(($=this.parentOrders.get(m[0]))!=null?$:0)||((C=g[0])==null?void 0:C.localeCompare(m[0]||""))||0}).map(([g,m])=>{let R=m.length,$=m.filter(y=>{var U;return(((U=y[4])==null?void 0:U.layer)||"default")===c}).sort((y,U)=>{var P;return y[0]-U[0]||((P=y[1])==null?void 0:P.localeCompare(U[1]||""))||0}).map(y=>{var U;return[y[1]?Ot(y[1],n):y[1],y[2],!!((U=y[4])==null?void 0:U.noMerge)]}).map(y=>[y[0]==null?y[0]:[y[0]],y[1],y[2]]);if(!$.length)return;let C=$.reverse().map(([y,U,P],dt)=>{if(!P&&y&&this.config.mergeSelectors)for(let L=dt+1;L<R;L++){let T=$[L];if(T&&!T[2]&&T[0]&&T[1]===U)return T[0].push(...y),null}return y?`${[...new Set(y)].join(`,${l}`)}{${U}}`:U}).filter(Boolean).reverse().join(l);return g?`${g}{${l}${C}${l}}`:C}).filter(Boolean).join(l);return i&&(d=[b[c],d].filter(Boolean).join(l)),E[c]=!o&&d?`/* layer: ${c} */${l}${d}`:d},w=(c=A,d)=>c.filter(g=>!(d==null?void 0:d.includes(g))).map(g=>f(g)||"").filter(Boolean).join(l);return{get css(){return w()},layers:A,getLayers:w,getLayer:f,matched:h}}matchVariants(t,r){let n=new Set,i=[],s=r||t,o=!1,a={rawSelector:t,theme:this.config.theme,generator:this};for(;;){o=!1;for(let l of this.config.variants){if(!l.multiPass&&n.has(l))continue;let p=l.match(s,a);if(!!p&&(typeof p=="string"&&(p={matcher:p}),p)){s=p.matcher,Array.isArray(p.parent)&&this.parentOrders.set(p.parent[0],p.parent[1]),i.push(p),n.add(l),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,r=t[4],n=t[1]){let i=[...r].sort((a,l)=>(a.order||0)-(l.order||0)),s=i.reduce((a,l)=>{var p;return((p=l.body)==null?void 0:p.call(l,a))||a},t[2]),o={selector:i.reduce((a,l)=>{var p;return((p=l.selector)==null?void 0:p.call(l,a,s))||a},Tt(n)),entries:s,parent:i.reduce((a,l)=>Array.isArray(l.parent)?l.parent[0]:l.parent||a,void 0)};for(let a of this.config.postprocess)a(o);return o}constructCustomCSS(t,r,n){r=_(r);let{selector:i,entries:s,parent:o}=this.applyVariants([0,n||t.rawSelector,r,void 0,t.variantHandlers]),a=`${i}{${D(s)}}`;return o?`${o}{${a}}`:a}async parseUtil(t,r,n=!1){var h,S;let[i,s,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[s];if(a&&a[1]&&(n||!((h=a[2])==null?void 0:h.internal)))return[[a[0],i,_(a[1]),a[2],o]];r.variantHandlers=o;let{rulesDynamic:l,rulesSize:p}=this.config;for(let u=p;u>=0;u--){let x=l[u];if(!x||((S=x[2])==null?void 0:S.internal)&&!n)continue;let[E,A,b]=x,f=s.match(E);if(!f)continue;let w=await A(f,r);if(!w)continue;if(typeof w=="string")return[[u,w,b]];let c=Z(w).filter(d=>d.length);if(c.length)return c.map(d=>[u,i,d,b,o])}}stringifyUtil(t){if(!t)return;if(B(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:r,entries:n,parent:i}=this.applyVariants(t),s=D(n);if(!!s)return[t[0],r,s,i,t[3]]}expandShortcut(t,r,n=3){if(n===0)return;let i,s;for(let o of this.config.shortcuts)if(Q(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,r)),s){i=i||o[2];break}}if(typeof s=="string"&&(s=et(s).split(/\s+/g)),!!s)return[s.flatMap(o=>{var a;return((a=this.expandShortcut(o,r,n-1))==null?void 0:a[0])||[o]}).filter(o=>o!==""),i]}async stringifyShortcuts(t,r,n,i={layer:this.config.shortcutsLayer}){var p;let s=new G,o=(await Promise.all(K(n).map(async h=>{let S=await this.parseUtil(h,r,!0);return S||nt(`unmatched utility "${h}" in shortcut "${t[1]}"`),S||[]}))).flat(1).filter(Boolean).sort((h,S)=>h[0]-S[0]),[a,,l]=t;for(let h of o){if(B(h))continue;let{selector:S,entries:u,parent:x}=this.applyVariants(h,[...h[4],...l],a);s.getFallback(S,x,[[],h[0]])[0].push([u,!!((p=h[3])==null?void 0:p.noMerge)])}return s.map(([h,S],u,x)=>{let E=b=>f=>{let w=D(f);if(w)return[S,u,w,x,j(O({},i),{noMerge:b})]};return[[h.filter(([,b])=>b).map(([b])=>b),!0],[h.filter(([,b])=>!b).map(([b])=>b),!1]].map(([b,f])=>{let w=b.filter(d=>d.some(g=>g[0]===z)),c=b.filter(d=>d.every(g=>g[0]!==z));return[...w.map(E(f)),...[c.flat(1)].map(E(f))]})}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(r=>typeof r=="string"?r===t:r.test(t))}};function ot(e,t){return new st(e,t)}var at=/ \$\$ /,$t=e=>e.match(at);function Ot(e,t){return $t(e)?e.replace(at,t?` ${t} `:" "):t?`${t} ${e}`:e}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Tt(e){return ct.test(e)?e.replace(ct,(t,r,n,i)=>`[${v(r)}${n}"${v(i)}"]`):`.${v(e)}`}var _t=e=>e.replace(/-(\w)/g,(t,r)=>r?r.toUpperCase():""),lt=e=>e.charAt(0).toUpperCase()+e.slice(1),ut=e=>e.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),ft=["Webkit","Moz","ms"];function pt(e){let t={};function r(n){let i=t[n];if(i)return i;let s=_t(n);if(s!=="filter"&&s in e)return t[n]=ut(s);s=lt(s);for(let o=0;o<ft.length;o++){let a=`${ft[o]}${s}`;if(a in e)return t[n]=ut(lt(a))}return n}return({entries:n})=>n.forEach(i=>{i[0].startsWith("--")||(i[0]=r(i[0]))})}function q(e={}){var b;if(typeof window=="undefined"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let t=e.defaults||{};if(e.autoPrefix){let f=t.postprocess;f||(f=[]),Array.isArray(f)||(f=[f]),f.unshift(pt(document.createElement("div").style)),t.postprocess=f}Object.assign(e,(b=window.__unocss)==null?void 0:b.runtime);let r,n=!1,i,s=ot(window.__unocss||{},t),o=new Set,a,l=()=>new Promise(f=>{a!=null&&clearTimeout(a),a=setTimeout(()=>p().then(f),0)});async function p(){let f=await s.generate(o);r||(r=document.createElement("style"),document.documentElement.prepend(r)),r.innerHTML=f.css}async function h(f){await s.applyExtractors(f,void 0,o),await l()}async function S(){let f=document.body&&document.body.outerHTML;f&&await h(f)}let u=new MutationObserver(f=>{n||f.forEach(w=>{let c=w.target;if(c===r||i&&!i(c))return;let d=Array.from(c.attributes).map(m=>m.value?`${m.name}="${m.value}"`:m.name).join(" "),g=`<${c.tagName.toLowerCase()} ${d}>`;h(g)})}),x=!1;function E(){if(!x)return;let f=document.documentElement||document.body;!f||(u.observe(f,{childList:!0,subtree:!0,attributes:!0}),x=!0)}function A(){S(),E()}window.__unocss_runtime=window.__unocss_runtime={version:s.version,uno:s,async extract(f){if(typeof f=="string")return await h(f);f.forEach(w=>o.add(w)),await p()},extractAll:S,inspect(f){i=f},toggleObserver(f){f===void 0?n=!n:n=!!f}},A(),window.addEventListener("load",A),window.addEventListener("DOMContentLoaded",A)}q();})();
1
+ (()=>{var gt=Object.defineProperty,mt=Object.defineProperties;var yt=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var Z=(n,t,e)=>t in n?gt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,$=(n,t)=>{for(var e in t||(t={}))W.call(t,e)&&Z(n,e,t[e]);if(v)for(var e of v(t))N.call(t,e)&&Z(n,e,t[e]);return n},O=(n,t)=>mt(n,yt(t));var J=(n,t)=>{var e={};for(var r in n)W.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&v)for(var r of v(n))t.indexOf(r)<0&&N.call(n,r)&&(e[r]=n[r]);return e};function St(n){let t=n.length,e=-1,r,s="",o=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&&o===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 j=St;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 xt(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 D(n){return n==null?"":xt(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(o=>{L(r[o])?o in e?s[o]=F(e[o],r[o]):Object.assign(s,{[o]:r[o]}):Object.assign(s,{[o]:r[o]})}),s}function M(n){let t,e,r;if(Array.isArray(n)){for(e=Array(t=n.length);t--;)e[t]=(r=n[t])&&typeof r=="object"?M(r):r;return e}if(Object.prototype.toString.call(n)==="[object Object]"){e={};for(t in n)t==="__proto__"?Object.defineProperty(e,t,{value:M(n[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(r=n[t])&&typeof r=="object"?M(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 Ct=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,z="$$shortcut-no-merge";function tt(n=""){return Ct.test(n)}function et(n){return typeof n=="function"?{match:n}:n}function B(n){return n.length===3}function rt(n){return n!=null}var G=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,o])=>t(o,e,s)))}};var bt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function nt(n){let t=[],e;for(;e=bt.exec(n);){let s=e.index,o=s+e[0].length,[,a,i,c]=e,u=c.split(/\s/g).map(d=>d.replace(/^(!?)(.*)/,`$1${a}${i}$2`)).join(" ");t.unshift([s,o,u])}let r=n;return t.forEach(([s,o,a])=>{r=r.slice(0,s)+a+r.slice(o)}),r}var st=new Set;function it(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 Ut(n){return P(n).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var wt={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")],o=Object.assign(wt,...r.map(l=>l.layers),n.layers);function a(l){return K([...s.flatMap(S=>P(S[l]||[])),...P(e[l]||[])])}let i=a("extractors");i.length||i.push(H),i.sort((l,S)=>(l.order||0)-(S.order||0));let c=a("rules"),u={},d=c.length;c.forEach((l,S)=>{X(l)&&(u[l[0]]=[S,l[1],l[2]],delete c[S])});let C=M([...s.map(l=>l.theme||{}),e.theme||{}].reduce((l,S)=>F(l,S),{}));return a("extendTheme").forEach(l=>l(C)),O($({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:l=>l},e),{presets:s,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:o,theme:C,rulesSize:d,rulesDynamic:c,rulesStaticMap:u,preprocess:a("preprocess"),postprocess:a("postprocess"),preflights:a("preflights"),variants:a("variants").map(et),shortcuts:Ut(a("shortcuts")),extractors:i})}var ot="0.22.7";var at=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=I(t,e)}version=ot;_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 o of this.config.extractors){let a=await o.extract(s);a==null||a.forEach(i=>r.add(i))}return r}async parseToken(t){var a;if(this.blocked.has(t))return;if(this._cache.has(t))return this._cache.get(t);let e=t;for(let i of this.config.preprocess)e=i(t);if(this.isBlocked(e)){this.blocked.add(t),this._cache.set(t,null);return}let r=this.matchVariants(t,e);if(!r||this.isBlocked(r[1])){this.blocked.add(t),this._cache.set(t,null);return}let s={rawSelector:t,currentSelector:r[1],theme:this.config.theme,generator:this,variantHandlers:r[2],constructCSS:(...i)=>this.constructCustomCSS(s,...i)},o=this.expandShortcut(r[1],s);if(o){let i=await this.stringifyShortcuts(r,s,o[0],o[1]);if(i==null?void 0:i.length)return this._cache.set(t,i),i}else{let i=(a=await this.parseUtil(r,s))==null?void 0:a.map(c=>this.stringifyUtil(c)).filter(rt);if(i==null?void 0:i.length)return this._cache.set(t,i),i}this._cache.set(t,null)}async generate(t,{id:e,scope:r,preflights:s=!0,safelist:o=!0,minify:a=!1}={}){let i=typeof t=="string"?await this.applyExtractors(t,e):t;o&&this.config.safelist.forEach(p=>i.add(p));let c=a?"":`
2
+ `,u=new Set(["default"]),d=new Set,C=new Map;await Promise.all(Array.from(i).map(async p=>{var y;if(d.has(p))return;let h=await this.parseToken(p);if(h!=null){d.add(p);for(let g of h){let R=g[3]||"";C.has(R)||C.set(R,[]),C.get(R).push(g),((y=g[4])==null?void 0:y.layer)&&u.add(g[4].layer)}}})),s&&this.config.preflights.forEach(p=>{p.layer&&u.add(p.layer)});let l={},S=this.config.sortLayers(Array.from(u).sort((p,h)=>{var y,g;return((y=this.config.layers[p])!=null?y:0)-((g=this.config.layers[h])!=null?g:0)||p.localeCompare(h)})),U={};s&&(U=Object.fromEntries(await Promise.all(S.map(async p=>{let y=(await Promise.all(this.config.preflights.filter(g=>(g.layer||"default")===p).map(async g=>await g.getCSS()))).filter(Boolean).join(c);return[p,y]}))));let A=p=>{if(l[p])return l[p];let h=Array.from(C).sort((y,g)=>{var R,w,f;return((R=this.parentOrders.get(y[0]))!=null?R:0)-((w=this.parentOrders.get(g[0]))!=null?w:0)||((f=y[0])==null?void 0:f.localeCompare(g[0]||""))||0}).map(([y,g])=>{let R=g.length,w=g.filter(m=>{var b;return(((b=m[4])==null?void 0:b.layer)||"default")===p}).sort((m,b)=>{var T;return m[0]-b[0]||((T=m[1])==null?void 0:T.localeCompare(b[1]||""))||0}).map(m=>{var b;return[m[1]?$t(m[1],r):m[1],m[2],!!((b=m[4])==null?void 0:b.noMerge)]}).map(m=>[m[0]==null?m[0]:[m[0]],m[1],m[2]]);if(!w.length)return;let f=w.reverse().map(([m,b,T],k)=>{if(!T&&m&&this.config.mergeSelectors)for(let E=k+1;E<R;E++){let _=w[E];if(_&&!_[2]&&_[0]&&_[1]===b)return _[0].push(...m),null}return m?`${[...new Set(m)].join(`,${c}`)}{${b}}`:b}).filter(Boolean).reverse().join(c);return y?`${y}{${c}${f}${c}}`:f}).filter(Boolean).join(c);return s&&(h=[U[p],h].filter(Boolean).join(c)),l[p]=!a&&h?`/* layer: ${p} */${c}${h}`:h},x=(p=S,h)=>p.filter(y=>!(h==null?void 0:h.includes(y))).map(y=>A(y)||"").filter(Boolean).join(c);return{get css(){return x()},layers:S,getLayers:x,getLayer:A,matched:d}}matchVariants(t,e){let r=new Set,s=[],o=e||t,a=!1,i={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 u=c.match(o,i);if(!!u&&(typeof u=="string"&&(u={matcher:u}),u)){o=u.matcher,Array.isArray(u.parent)&&this.parentOrders.set(u.parent[0],u.parent[1]),s.push(u),r.add(c),a=!0;break}}if(!a)break;if(s.length>500)throw new Error(`Too many variants applied to "${t}"`)}return[t,o,s]}applyVariants(t,e=t[4],r=t[1]){let s=[...e].sort((i,c)=>(i.order||0)-(c.order||0)),o=s.reduce((i,c)=>{var u;return((u=c.body)==null?void 0:u.call(c,i))||i},t[2]),a={selector:s.reduce((i,c)=>{var u;return((u=c.selector)==null?void 0:u.call(c,i,o))||i},Tt(r)),entries:o,parent:s.reduce((i,c)=>Array.isArray(c.parent)?c.parent[0]:c.parent||i,void 0),layer:s.reduce((i,c)=>c.layer||i,void 0)};for(let i of this.config.postprocess)i(a);return a}constructCustomCSS(t,e,r){e=V(e);let{selector:s,entries:o,parent:a}=this.applyVariants([0,r||t.rawSelector,e,void 0,t.variantHandlers]),i=`${s}{${D(o)}}`;return a?`${a}{${i}}`:i}async parseUtil(t,e,r=!1){var d,C;let[s,o,a]=typeof t=="string"?this.matchVariants(t):t,i=this.config.rulesStaticMap[o];if(i&&i[1]&&(r||!((d=i[2])==null?void 0:d.internal)))return[[i[0],s,V(i[1]),i[2],a]];e.variantHandlers=a;let{rulesDynamic:c,rulesSize:u}=this.config;for(let l=u;l>=0;l--){let S=c[l];if(!S||((C=S[2])==null?void 0:C.internal)&&!r)continue;let[U,A,x]=S,p=o.match(U);if(!p)continue;let h=await A(p,e);if(!h)continue;if(typeof h=="string")return[[l,h,x]];let y=Q(h).filter(g=>g.length);if(y.length)return y.map(g=>[l,s,g,x,a])}}stringifyUtil(t){var u;if(!t)return;if(B(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:r,parent:s,layer:o}=this.applyVariants(t),a=D(r);if(!a)return;let d=(u=t[3])!=null?u:{},{layer:i}=d,c=J(d,["layer"]);return[t[0],e,a,s,O($({},c),{layer:o!=null?o:i})]}expandShortcut(t,e,r=3){if(r===0)return;let s,o;for(let a of this.config.shortcuts)if(Y(a)){if(a[0]===t){s=s||a[2],o=a[1];break}}else{let i=t.match(a[0]);if(i&&(o=a[1](i,e)),o){s=s||a[2];break}}if(typeof o=="string"&&(o=nt(o).split(/\s+/g)),!!o)return[o.flatMap(a=>{var i;return((i=this.expandShortcut(a,e,r-1))==null?void 0:i[0])||[a]}).filter(a=>a!==""),s]}async stringifyShortcuts(t,e,r,s={layer:this.config.shortcutsLayer}){var u;let o=new G,a=(await Promise.all(K(r).map(async d=>{let C=await this.parseUtil(d,e,!0);return C||it(`unmatched utility "${d}" in shortcut "${t[1]}"`),C||[]}))).flat(1).filter(Boolean).sort((d,C)=>d[0]-C[0]),[i,,c]=t;for(let d of a){if(B(d))continue;let{selector:C,entries:l,parent:S}=this.applyVariants(d,[...d[4],...c],i);o.getFallback(C,S,[[],d[0]])[0].push([l,!!((u=d[3])==null?void 0:u.noMerge)])}return o.map(([d,C],l,S)=>{let U=x=>p=>{let h=D(p);if(h)return[C,l,h,S,O($({},s),{noMerge:x})]};return[[d.filter(([,x])=>x).map(([x])=>x),!0],[d.filter(([,x])=>!x).map(([x])=>x),!1]].map(([x,p])=>{let h=x.filter(g=>g.some(R=>R[0]===z)),y=x.filter(g=>g.every(R=>R[0]!==z));return[...h.map(U(p)),...[y.flat(1)].map(U(p))]})}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function ct(n,t){return new at(n,t)}var lt=/ \$\$ /,At=n=>n.match(lt);function $t(n,t){return At(n)?n.replace(lt,t?` ${t} `:" "):t?`${t} ${n}`:n}var ut=/^\[(.+?)(~?=)"(.*)"\]$/;function Tt(n){return ut.test(n)?n.replace(ut,(t,e,r,s)=>`[${j(e)}${r}"${j(s)}"]`):`.${j(n)}`}var _t=n=>n.replace(/-(\w)/g,(t,e)=>e?e.toUpperCase():""),ft=n=>n.charAt(0).toUpperCase()+n.slice(1),pt=n=>n.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),dt=["Webkit","Moz","ms"];function ht(n){let t={};function e(r){let s=t[r];if(s)return s;let o=_t(r);if(o!=="filter"&&o in n)return t[r]=pt(o);o=ft(o);for(let a=0;a<dt.length;a++){let i=`${dt[a]}${o}`;if(i in n)return t[r]=pt(ft(i))}return r}return({entries:r})=>r.forEach(s=>{s[0].startsWith("--")||(s[0]=e(s[0]))})}function q(n={}){var R,w;if(typeof window=="undefined"){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}(R=e==null?void 0:e.configResolved)==null||R.call(e,t,r);let s,o=!0,a,i=ct(t,r),c=new Set,u,d=[],C=()=>new Promise(f=>{d.push(f),u!=null&&clearTimeout(u),u=setTimeout(()=>l().then(()=>{let m=d;d=[],m.forEach(b=>b())}),0)});async function l(){let f=await i.generate(c);s||(s=document.createElement("style"),document.documentElement.prepend(s)),s.innerHTML=f.css}async function S(f){await i.applyExtractors(f,void 0,c),await C()}async function U(){let f=document.body&&document.body.outerHTML;f&&await S(f)}let A=new MutationObserver(f=>{o||f.forEach(m=>{let b=m.target;if(b===s||a&&!a(b))return;let T=Array.from(b.attributes).map(E=>E.value?`${E.name}="${E.value}"`:E.name).join(" "),k=`<${b.tagName.toLowerCase()} ${T}>`;S(k)})}),x=!1;function p(){if(!x)return;let f=document.documentElement||document.body;!f||(A.observe(f,{childList:!0,subtree:!0,attributes:!0}),x=!0)}function h(){U(),p()}function y(){h(),window.addEventListener("load",h),window.addEventListener("DOMContentLoaded",h)}let g=window.__unocss_runtime=window.__unocss_runtime={version:i.version,uno:i,async extract(f){if(typeof f=="string")return await S(f);f.forEach(m=>c.add(m)),await l()},extractAll:U,inspect(f){a=f},toggleObserver(f){f===void 0?o=!o:o=!!f,!x&&!o&&y()}};((w=e==null?void 0:e.ready)==null?void 0:w.call(e,g))!==!1&&(o=!1,y())}q();})();
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UserConfig, UnoGenerator, UserConfigDefaults } from '@unocss/core';
1
+ import { UserConfig, UserConfigDefaults, UnoGenerator } from '@unocss/core';
2
2
 
3
3
  interface RuntimeOptions {
4
4
  /**
@@ -10,57 +10,66 @@ interface RuntimeOptions {
10
10
  * @default false
11
11
  */
12
12
  autoPrefix?: boolean;
13
+ /**
14
+ * Callback to modify config
15
+ */
16
+ configResolved?: (config: UserConfig, defaults: UserConfigDefaults) => void;
17
+ /**
18
+ * Callback when the runtime is ready. Returning false will prevent default extraction
19
+ */
20
+ ready?: (runtime: RuntimeContext) => false | any;
13
21
  }
14
22
  declare type RuntimeInspectorCallback = (element: Element) => boolean;
23
+ interface RuntimeContext {
24
+ /**
25
+ * The UnoCSS instance.
26
+ *
27
+ * @type {UnoGenerator}
28
+ */
29
+ uno: UnoGenerator;
30
+ /**
31
+ * Run extractor on specified tokens
32
+ *
33
+ * @returns {Promise<void>}
34
+ */
35
+ extract: (tokens: string | string[]) => Promise<void>;
36
+ /**
37
+ * Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
38
+ *
39
+ * @returns {Promise<void>}
40
+ */
41
+ extractAll: () => Promise<void>;
42
+ /**
43
+ * Set/unset inspection callback to allow/ignore element to be extracted.
44
+ *
45
+ * @param {RuntimeInspectorCallback} [callback] - Callback to determine whether the element will be extracted.
46
+ *
47
+ * @returns {void}
48
+ */
49
+ inspect: (callback?: RuntimeInspectorCallback) => void;
50
+ /**
51
+ * Pause/resume/toggle the runtime.
52
+ *
53
+ * @param {boolean} [state] - False or True respectively pause or resume the runtime. Undefined parameter toggles the pause/resume state.
54
+ *
55
+ * @returns {void}
56
+ */
57
+ toggleObserver: (state?: boolean) => void;
58
+ /**
59
+ * The UnoCSS version.
60
+ *
61
+ * @type {string}
62
+ */
63
+ version: string;
64
+ }
15
65
  declare global {
16
66
  interface Window {
17
67
  __unocss?: UserConfig & {
18
68
  runtime?: RuntimeOptions;
19
69
  };
20
- __unocss_runtime?: {
21
- /**
22
- * The UnoCSS instance.
23
- *
24
- * @type {UnoGenerator}
25
- */
26
- uno: UnoGenerator;
27
- /**
28
- * Run extractor on specified tokens
29
- *
30
- * @returns {Promise<void>}
31
- */
32
- extract: (tokens: string | string[]) => Promise<void>;
33
- /**
34
- * Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
35
- *
36
- * @returns {Promise<void>}
37
- */
38
- extractAll: () => Promise<void>;
39
- /**
40
- * Set/unset inspection callback to allow/ignore element to be extracted.
41
- *
42
- * @param {RuntimeInspectorCallback} [callback] - Callback to determine whether the element will be extracted.
43
- *
44
- * @returns {void}
45
- */
46
- inspect: (callback?: RuntimeInspectorCallback) => void;
47
- /**
48
- * Pause/resume/toggle the runtime.
49
- *
50
- * @param {boolean} [state] - False or True respectively pause or resume the runtime. Undefined parameter toggles the pause/resume state.
51
- *
52
- * @returns {void}
53
- */
54
- toggleObserver: (state?: boolean) => void;
55
- /**
56
- * The UnoCSS version.
57
- *
58
- * @type {string}
59
- */
60
- version: string;
61
- };
70
+ __unocss_runtime?: RuntimeContext;
62
71
  }
63
72
  }
64
- declare function init(options?: RuntimeOptions): void;
73
+ declare function init(inlineConfig?: RuntimeOptions): void;
65
74
 
66
- export { RuntimeInspectorCallback, RuntimeOptions, init as default };
75
+ export { RuntimeContext, RuntimeInspectorCallback, RuntimeOptions, init as default };
package/dist/index.js CHANGED
@@ -62,33 +62,41 @@ function autoPrefixer(style) {
62
62
  }
63
63
 
64
64
  // src/index.ts
65
- function init(options = {}) {
66
- var _a;
65
+ function init(inlineConfig = {}) {
66
+ var _a, _b;
67
67
  if (typeof window == "undefined") {
68
68
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
69
69
  return;
70
70
  }
71
- const defaultOptions = options.defaults || {};
72
- if (options.autoPrefix) {
73
- let postprocess = defaultOptions.postprocess;
71
+ const config = window.__unocss || {};
72
+ const runtime = config == null ? void 0 : config.runtime;
73
+ const defaultConfig = Object.assign(inlineConfig.defaults || {}, runtime);
74
+ if (runtime == null ? void 0 : runtime.autoPrefix) {
75
+ let postprocess = defaultConfig.postprocess;
74
76
  if (!postprocess)
75
77
  postprocess = [];
76
78
  if (!Array.isArray(postprocess))
77
79
  postprocess = [postprocess];
78
80
  postprocess.unshift(autoPrefixer(document.createElement("div").style));
79
- defaultOptions.postprocess = postprocess;
81
+ defaultConfig.postprocess = postprocess;
80
82
  }
81
- Object.assign(options, (_a = window.__unocss) == null ? void 0 : _a.runtime);
83
+ (_a = runtime == null ? void 0 : runtime.configResolved) == null ? void 0 : _a.call(runtime, config, defaultConfig);
82
84
  let styleElement;
83
- let paused = false;
85
+ let paused = true;
84
86
  let inspector;
85
- const uno = (0, import_core.createGenerator)(window.__unocss || {}, defaultOptions);
87
+ const uno = (0, import_core.createGenerator)(config, defaultConfig);
86
88
  const tokens = /* @__PURE__ */ new Set();
87
89
  let _timer;
90
+ let _resolvers = [];
88
91
  const scheduleUpdate = () => new Promise((resolve) => {
92
+ _resolvers.push(resolve);
89
93
  if (_timer != null)
90
94
  clearTimeout(_timer);
91
- _timer = setTimeout(() => updateStyle().then(resolve), 0);
95
+ _timer = setTimeout(() => updateStyle().then(() => {
96
+ const resolvers = _resolvers;
97
+ _resolvers = [];
98
+ resolvers.forEach((r) => r());
99
+ }), 0);
92
100
  });
93
101
  async function updateStyle() {
94
102
  const result = await uno.generate(tokens);
@@ -139,7 +147,12 @@ function init(options = {}) {
139
147
  extractAll();
140
148
  observe();
141
149
  }
142
- window.__unocss_runtime = window.__unocss_runtime = {
150
+ function ready() {
151
+ execute();
152
+ window.addEventListener("load", execute);
153
+ window.addEventListener("DOMContentLoaded", execute);
154
+ }
155
+ const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
143
156
  version: uno.version,
144
157
  uno,
145
158
  async extract(userTokens) {
@@ -157,11 +170,14 @@ function init(options = {}) {
157
170
  paused = !paused;
158
171
  else
159
172
  paused = !!set;
173
+ if (!observing && !paused)
174
+ ready();
160
175
  }
161
176
  };
162
- execute();
163
- window.addEventListener("load", execute);
164
- window.addEventListener("DOMContentLoaded", execute);
177
+ if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
178
+ paused = false;
179
+ ready();
180
+ }
165
181
  }
166
182
  module.exports = __toCommonJS(src_exports);
167
183
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -30,33 +30,41 @@ function autoPrefixer(style) {
30
30
  }
31
31
 
32
32
  // src/index.ts
33
- function init(options = {}) {
34
- var _a;
33
+ function init(inlineConfig = {}) {
34
+ var _a, _b;
35
35
  if (typeof window == "undefined") {
36
36
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
37
37
  return;
38
38
  }
39
- const defaultOptions = options.defaults || {};
40
- if (options.autoPrefix) {
41
- let postprocess = defaultOptions.postprocess;
39
+ const config = window.__unocss || {};
40
+ const runtime = config == null ? void 0 : config.runtime;
41
+ const defaultConfig = Object.assign(inlineConfig.defaults || {}, runtime);
42
+ if (runtime == null ? void 0 : runtime.autoPrefix) {
43
+ let postprocess = defaultConfig.postprocess;
42
44
  if (!postprocess)
43
45
  postprocess = [];
44
46
  if (!Array.isArray(postprocess))
45
47
  postprocess = [postprocess];
46
48
  postprocess.unshift(autoPrefixer(document.createElement("div").style));
47
- defaultOptions.postprocess = postprocess;
49
+ defaultConfig.postprocess = postprocess;
48
50
  }
49
- Object.assign(options, (_a = window.__unocss) == null ? void 0 : _a.runtime);
51
+ (_a = runtime == null ? void 0 : runtime.configResolved) == null ? void 0 : _a.call(runtime, config, defaultConfig);
50
52
  let styleElement;
51
- let paused = false;
53
+ let paused = true;
52
54
  let inspector;
53
- const uno = createGenerator(window.__unocss || {}, defaultOptions);
55
+ const uno = createGenerator(config, defaultConfig);
54
56
  const tokens = /* @__PURE__ */ new Set();
55
57
  let _timer;
58
+ let _resolvers = [];
56
59
  const scheduleUpdate = () => new Promise((resolve) => {
60
+ _resolvers.push(resolve);
57
61
  if (_timer != null)
58
62
  clearTimeout(_timer);
59
- _timer = setTimeout(() => updateStyle().then(resolve), 0);
63
+ _timer = setTimeout(() => updateStyle().then(() => {
64
+ const resolvers = _resolvers;
65
+ _resolvers = [];
66
+ resolvers.forEach((r) => r());
67
+ }), 0);
60
68
  });
61
69
  async function updateStyle() {
62
70
  const result = await uno.generate(tokens);
@@ -107,7 +115,12 @@ function init(options = {}) {
107
115
  extractAll();
108
116
  observe();
109
117
  }
110
- window.__unocss_runtime = window.__unocss_runtime = {
118
+ function ready() {
119
+ execute();
120
+ window.addEventListener("load", execute);
121
+ window.addEventListener("DOMContentLoaded", execute);
122
+ }
123
+ const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
111
124
  version: uno.version,
112
125
  uno,
113
126
  async extract(userTokens) {
@@ -125,11 +138,14 @@ function init(options = {}) {
125
138
  paused = !paused;
126
139
  else
127
140
  paused = !!set;
141
+ if (!observing && !paused)
142
+ ready();
128
143
  }
129
144
  };
130
- execute();
131
- window.addEventListener("load", execute);
132
- window.addEventListener("DOMContentLoaded", execute);
145
+ if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
146
+ paused = false;
147
+ ready();
148
+ }
133
149
  }
134
150
  export {
135
151
  init as default