@unocss/runtime 0.22.1 → 0.22.5

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 ut=Object.defineProperty,ft=Object.defineProperties;var pt=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ht=Object.prototype.propertyIsEnumerable;var q=(r,t,e)=>t in r?ut(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,j=(r,t)=>{for(var e in t||(t={}))dt.call(t,e)&&q(r,e,t[e]);if(N)for(var e of N(t))ht.call(t,e)&&q(r,e,t[e]);return r},W=(r,t)=>ft(r,pt(t));function gt(r){let t=r.length,e=-1,n,i="",s=r.charCodeAt(0);for(;++e<t;){if(n=r.charCodeAt(e),n===0){i+="\uFFFD";continue}if(n===44){i+="\\2c ";continue}if(n>=1&&n<=31||n===127||e===0&&n>=48&&n<=57||e===1&&n>=48&&n<=57&&s===45){i+=`\\${n.toString(16)} `;continue}if(e===0&&t===1&&n===45){i+=`\\${r.charAt(e)}`;continue}if(n>=128||n===45||n===95||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122){i+=r.charAt(e);continue}i+=`\\${r.charAt(e)}`}return i}var v=gt;function $(r){return(Array.isArray(r)?r:Object.entries(r)).filter(t=>t[1]!=null)}function Z(r){return Array.isArray(r)?r.find(t=>!Array.isArray(t)||Array.isArray(t[0]))?r.map(t=>$(t)):[r]:[$(r)]}function mt(r){return r.filter(([t,e],n)=>{if(t.startsWith("$$"))return!1;for(let i=n-1;i>=0;i--)if(r[i][0]===t&&r[i][1]===e)return!1;return!0})}function P(r){return r==null?"":mt(r).map(([t,e])=>e!=null?`${t}:${e};`:void 0).filter(Boolean).join("")}function L(r){return r&&typeof r=="object"&&!Array.isArray(r)}function k(r,t){let e=r,n=t;if(Array.isArray(e)&&Array.isArray(n))return[...e,...n];if(Array.isArray(e))return[...e];let i=j({},e);return L(e)&&L(n)&&Object.keys(n).forEach(s=>{L(n[s])?s in e?i[s]=k(e[s],n[s]):Object.assign(i,{[s]:n[s]}):Object.assign(i,{[s]:n[s]})}),i}function O(r){let t,e,n;if(Array.isArray(r)){for(e=Array(t=r.length);t--;)e[t]=(n=r[t])&&typeof n=="object"?O(n):n;return e}if(Object.prototype.toString.call(r)==="[object Object]"){e={};for(t in r)t==="__proto__"?Object.defineProperty(e,t,{value:O(r[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(n=r[t])&&typeof n=="object"?O(n):n;return e}return r}function J(r){return typeof r[0]=="string"}function Q(r){return typeof r[0]=="string"}function _(r=[]){return Array.isArray(r)?r:[r]}function K(r){return Array.from(new Set(r))}var yt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,F="$$shortcut-no-merge";function X(r=""){return yt.test(r)}function Y(r){return typeof r=="function"?{match:r}:r}function G(r){return r.length===3}function tt(r){return r!=null}var B=class{_map=new Map;get(t,e){let n=this._map.get(t);if(n)return n.get(e)}getFallback(t,e,n){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.has(e)||i.set(e,n),i.get(e)}set(t,e,n){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.set(e,n),this}has(t,e){var n;return(n=this._map.get(t))==null?void 0:n.has(e)}delete(t,e){var n;return((n=this._map.get(t))==null?void 0:n.delete(e))||!1}deleteTop(t){return this._map.delete(t)}map(t){return Array.from(this._map.entries()).flatMap(([e,n])=>Array.from(n.entries()).map(([i,s])=>t(s,e,i)))}};var St=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function et(r){let t=[],e;for(;e=St.exec(r);){let i=e.index,s=i+e[0].length,[,o,a,f]=e,l=f.split(/\s/g).map(m=>m.replace(/^(!?)(.*)/,`$1${o}${a}$2`)).join(" ");t.unshift([i,s,l])}let n=r;return t.forEach(([i,s,o])=>{n=n.slice(0,i)+o+n.slice(s)}),n}var rt=new Set;function nt(r){rt.has(r)||(console.warn("[unocss]",r),rt.add(r))}var xt=r=>r.split(/[\s'"`;>=]+/g).filter(X),H={name:"split",order:0,extract({code:r}){return new Set(xt(r))}};function bt(r){return _(r).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var Ct={shortcuts:-1,default:0};function z(r={},t={}){let e=Object.assign({},t,r),n=(e.presets||[]).flatMap(_),i=[...n.filter(u=>u.enforce==="pre"),...n.filter(u=>!u.enforce),...n.filter(u=>u.enforce==="post")],s=Object.assign(Ct,...n.map(u=>u.layers),r.layers);function o(u){return K([...i.flatMap(x=>_(x[u]||[])),..._(e[u]||[])])}let a=o("extractors");a.length||a.push(H),a.sort((u,x)=>(u.order||0)-(x.order||0));let f=o("rules"),l={},m=f.length;f.forEach((u,x)=>{J(u)&&(l[u[0]]=[x,u[1],u[2]],delete f[x])});let b=O([...i.map(u=>u.theme||{}),e.theme||{}].reduce((u,x)=>k(u,x),{}));return o("extendTheme").forEach(u=>u(b)),W(j({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:u=>u},e),{presets:i,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:s,theme:b,rulesSize:m,rulesDynamic:f,rulesStaticMap:l,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),variants:o("variants").map(Y),shortcuts:bt(o("shortcuts")),extractors:a})}var it="0.22.1";var st=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=z(t,e)}version=it;_cache=new Map;config;blocked=new Set;parentOrders=new Map;setConfig(t,e){!t||(e&&(this.defaults=e),this.userConfig=t,this.config=z(t,this.defaults),this.blocked.clear(),this.parentOrders.clear(),this._cache.clear())}async applyExtractors(t,e,n=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=>n.add(a))}return n}async generate(t,{id:e,scope:n,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(c=>a.add(c));let f=o?"":`
2
- `,l=new Set(["default"]),m=new Set,b=new Map,u=(c,h)=>{var p;this._cache.set(c,h),m.add(c);for(let y of h){let R=y[3]||"";b.has(R)||b.set(R,[]),b.get(R).push(y),((p=y[4])==null?void 0:p.layer)&&l.add(y[4].layer)}},x=c=>{this.blocked.add(c),this._cache.set(c,null)};await Promise.all(Array.from(a).map(async c=>{var A;if(m.has(c)||this.blocked.has(c))return;if(this._cache.has(c)){let S=this._cache.get(c);S&&u(c,S);return}let h=c;for(let S of this.config.preprocess)h=S(c);if(this.isBlocked(h))return x(h);let p=this.matchVariants(c,h);if(!p||this.isBlocked(p[1]))return x(c);let y={rawSelector:c,currentSelector:p[1],theme:this.config.theme,generator:this,variantHandlers:p[2],constructCSS:(...S)=>this.constructCustomCSS(y,...S)},R=this.expandShortcut(p[1],y);if(R){let S=await this.stringifyShortcuts(p,y,R[0],R[1]);if(S==null?void 0:S.length)return u(c,S)}else{let S=(A=await this.parseUtil(p,y))==null?void 0:A.map(g=>this.stringifyUtil(g)).filter(tt);if(S==null?void 0:S.length)return u(c,S)}this._cache.set(c,null)})),i&&this.config.preflights.forEach(c=>{c.layer&&l.add(c.layer)});let E={},C=this.config.sortLayers(Array.from(l).sort((c,h)=>{var p,y;return((p=this.config.layers[c])!=null?p:0)-((y=this.config.layers[h])!=null?y:0)||c.localeCompare(h)})),d={};i&&(d=Object.fromEntries(await Promise.all(C.map(async c=>{let p=(await Promise.all(this.config.preflights.filter(y=>(y.layer||"default")===c).map(async y=>await y.getCSS()))).filter(Boolean).join(f);return[c,p]}))));let T=c=>{if(E[c])return E[c];let h=Array.from(b).sort((p,y)=>{var R,A,S;return((R=this.parentOrders.get(p[0]))!=null?R:0)-((A=this.parentOrders.get(y[0]))!=null?A:0)||((S=p[0])==null?void 0:S.localeCompare(y[0]||""))||0}).map(([p,y])=>{let R=y.length,A=y.filter(g=>{var U;return(((U=g[4])==null?void 0:U.layer)||"default")===c}).sort((g,U)=>{var V;return g[0]-U[0]||((V=g[1])==null?void 0:V.localeCompare(U[1]||""))||0}).map(g=>{var U;return[g[1]?Ut(g[1],n):g[1],g[2],!!((U=g[4])==null?void 0:U.noMerge)]}).map(g=>[g[0]==null?g[0]:[g[0]],g[1],g[2]]);if(!A.length)return;let S=A.reverse().map(([g,U,V],lt)=>{if(g&&this.config.mergeSelectors)for(let D=lt+1;D<R;D++){let M=A[D];if(!V&&M&&M[0]&&M[1]===U)return M[0].push(...g),null}return g?`${[...new Set(g)].join(`,${f}`)}{${U}}`:U}).filter(Boolean).reverse().join(f);return p?`${p}{${f}${S}${f}}`:S}).filter(Boolean).join(f);return i&&(h=[d[c],h].filter(Boolean).join(f)),E[c]=!o&&h?`/* layer: ${c} */${f}${h}`:h},w=(c=C,h)=>c.filter(p=>!(h==null?void 0:h.includes(p))).map(p=>T(p)||"").filter(Boolean).join(f);return{get css(){return w()},layers:C,getLayers:w,getLayer:T,matched:m}}matchVariants(t,e){let n=new Set,i=[],s=e||t,o=!1,a={rawSelector:t,theme:this.config.theme,generator:this};for(;;){o=!1;for(let f of this.config.variants){if(!f.multiPass&&n.has(f))continue;let l=f.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),n.add(f),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],n=t[1]){let i=[...e].sort((a,f)=>(a.order||0)-(f.order||0)),s=i.reduce((a,f)=>{var l;return((l=f.body)==null?void 0:l.call(f,a))||a},t[2]),o={selector:i.reduce((a,f)=>{var l;return((l=f.selector)==null?void 0:l.call(f,a,s))||a},Et(n)),entries:s,parent:i.reduce((a,f)=>Array.isArray(f.parent)?f.parent[0]:f.parent||a,void 0)};for(let a of this.config.postprocess)a(o);return o}constructCustomCSS(t,e,n){e=$(e);let{selector:i,entries:s,parent:o}=this.applyVariants([0,n||t.rawSelector,e,void 0,t.variantHandlers]),a=`${i}{${P(s)}}`;return o?`${o}{${a}}`:a}async parseUtil(t,e,n=!1){var m,b;let[i,s,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[s];if(a&&a[1]&&(n||!((m=a[2])==null?void 0:m.internal)))return[[a[0],i,$(a[1]),a[2],o]];e.variantHandlers=o;let{rulesDynamic:f,rulesSize:l}=this.config;for(let u=l;u>=0;u--){let x=f[u];if(!x||((b=x[2])==null?void 0:b.internal)&&!n)continue;let[E,C,d]=x,T=s.match(E);if(!T)continue;let w=await C(T,e);if(!w)continue;if(typeof w=="string")return[[u,w,d]];let c=Z(w).filter(h=>h.length);if(c.length)return c.map(h=>[u,i,h,d,o])}}stringifyUtil(t){if(!t)return;if(G(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:n,parent:i}=this.applyVariants(t),s=P(n);if(!!s)return[t[0],e,s,i,t[3]]}expandShortcut(t,e,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,e)),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,e,n-1))==null?void 0:a[0])||[o]}).filter(o=>o!==""),i]}async stringifyShortcuts(t,e,n,i={layer:this.config.shortcutsLayer}){let s=new B,o=(await Promise.all(K(n).map(async l=>{let m=await this.parseUtil(l,e,!0);return m||nt(`unmatched utility "${l}" in shortcut "${t[1]}"`),m||[]}))).flat(1).filter(Boolean).sort((l,m)=>l[0]-m[0]),[a,,f]=t;for(let l of o){if(G(l))continue;let{selector:m,entries:b,parent:u}=this.applyVariants(l,[...l[4],...f],a);s.getFallback(m,u,[[],l[0]])[0].push(b)}return s.map(([l,m],b,u)=>{let x=l.filter(C=>C.some(d=>d[0]===F)),E=l.filter(C=>C.every(d=>d[0]!==F));return[...x,E.flat(1)].map(C=>{let d=P(C);if(d)return[m,b,d,u,i]})}).flat(1).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function ot(r,t){return new st(r,t)}var at=/ \$\$ /,Rt=r=>r.match(at);function Ut(r,t){return Rt(r)?r.replace(at,t?` ${t} `:" "):t?`${t} ${r}`:r}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Et(r){return r.startsWith("[")&&ct.test(r)?r.replace(ct,(t,e,n,i)=>`[${v(e)}${n}"${v(i)}"]`):`.${v(r)}`}function I(r={}){var C;if(typeof window=="undefined"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}Object.assign(r,(C=window.__unocss)==null?void 0:C.runtime);let t,e=!1,n,i=ot(window.__unocss||{},r.defaults),s=new Set,o;function a(){o!=null&&clearTimeout(o),o=setTimeout(f,0)}async function f(){let d=await i.generate(s);t||(t=document.createElement("style"),document.documentElement.prepend(t)),t.innerHTML=d.css}async function l(d){await i.applyExtractors(d,void 0,s),a()}async function m(){let d=document.body&&document.body.outerHTML;d&&await l(d)}let b=new MutationObserver(d=>{e||d.forEach(T=>{let w=T.target;if(w===t||n&&!n(w))return;let c=Array.from(w.attributes).map(p=>p.value?`${p.name}="${p.value}"`:p.name).join(" "),h=`<${w.tagName.toLowerCase()} ${c}>`;l(h)})}),u=!1;function x(){if(!u)return;let d=document.documentElement||document.body;!d||(b.observe(d,{childList:!0,subtree:!0,attributes:!0}),u=!0)}function E(){m(),x()}window.__unocss_runtime=window.__unocss_runtime={version:i.version,uno:i,extractAll:m,inspect(d){n=d},toggleObserver(d){d===void 0?e=!e:e=!!d}},E(),window.addEventListener("load",E),window.addEventListener("DOMContentLoaded",E)}I();})();
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.5";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;function l(){a!=null&&clearTimeout(a),a=setTimeout(p,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),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();})();
package/dist/index.d.ts CHANGED
@@ -5,6 +5,11 @@ interface RuntimeOptions {
5
5
  * Default config of UnoCSS
6
6
  */
7
7
  defaults?: UserConfigDefaults;
8
+ /**
9
+ * Enable css property auto prefixer
10
+ * @default false
11
+ */
12
+ autoPrefix?: boolean;
8
13
  }
9
14
  declare type RuntimeInspectorCallback = (element: Element) => boolean;
10
15
  declare global {
@@ -19,6 +24,12 @@ declare global {
19
24
  * @type {UnoGenerator}
20
25
  */
21
26
  uno: UnoGenerator;
27
+ /**
28
+ * Run extractor on specified tokens
29
+ *
30
+ * @returns {Promise<void>}
31
+ */
32
+ extract: (tokens: string | string[]) => Promise<void>;
22
33
  /**
23
34
  * Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
24
35
  *
package/dist/index.js CHANGED
@@ -32,17 +32,57 @@ __export(src_exports, {
32
32
  default: () => init
33
33
  });
34
34
  var import_core = __toESM(require("@unocss/core"));
35
+
36
+ // src/utils.ts
37
+ var camelize = (str) => str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
38
+ var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
39
+ var hyphenate = (str) => str.replace(/(?:^|\B)([A-Z])/g, "-$1").toLowerCase();
40
+ var prefixes = ["Webkit", "Moz", "ms"];
41
+ function autoPrefixer(style) {
42
+ const prefixCache = {};
43
+ function autoPrefix(rawName) {
44
+ const cached = prefixCache[rawName];
45
+ if (cached)
46
+ return cached;
47
+ let name = camelize(rawName);
48
+ if (name !== "filter" && name in style)
49
+ return prefixCache[rawName] = hyphenate(name);
50
+ name = capitalize(name);
51
+ for (let i = 0; i < prefixes.length; i++) {
52
+ const prefixed = `${prefixes[i]}${name}`;
53
+ if (prefixed in style)
54
+ return prefixCache[rawName] = hyphenate(capitalize(prefixed));
55
+ }
56
+ return rawName;
57
+ }
58
+ return ({ entries }) => entries.forEach((e) => {
59
+ if (!e[0].startsWith("--"))
60
+ e[0] = autoPrefix(e[0]);
61
+ });
62
+ }
63
+
64
+ // src/index.ts
35
65
  function init(options = {}) {
36
66
  var _a;
37
67
  if (typeof window == "undefined") {
38
68
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
39
69
  return;
40
70
  }
71
+ const defaultOptions = options.defaults || {};
72
+ if (options.autoPrefix) {
73
+ let postprocess = defaultOptions.postprocess;
74
+ if (!postprocess)
75
+ postprocess = [];
76
+ if (!Array.isArray(postprocess))
77
+ postprocess = [postprocess];
78
+ postprocess.unshift(autoPrefixer(document.createElement("div").style));
79
+ defaultOptions.postprocess = postprocess;
80
+ }
41
81
  Object.assign(options, (_a = window.__unocss) == null ? void 0 : _a.runtime);
42
82
  let styleElement;
43
83
  let paused = false;
44
84
  let inspector;
45
- const uno = (0, import_core.createGenerator)(window.__unocss || {}, options.defaults);
85
+ const uno = (0, import_core.createGenerator)(window.__unocss || {}, defaultOptions);
46
86
  const tokens = /* @__PURE__ */ new Set();
47
87
  let _timer;
48
88
  function scheduleUpdate() {
@@ -102,6 +142,12 @@ function init(options = {}) {
102
142
  window.__unocss_runtime = window.__unocss_runtime = {
103
143
  version: uno.version,
104
144
  uno,
145
+ async extract(userTokens) {
146
+ if (typeof userTokens === "string")
147
+ return await extract(userTokens);
148
+ userTokens.forEach((t) => tokens.add(t));
149
+ await updateStyle();
150
+ },
105
151
  extractAll,
106
152
  inspect(callback) {
107
153
  inspector = callback;
package/dist/index.mjs CHANGED
@@ -1,16 +1,56 @@
1
1
  // src/index.ts
2
2
  import { createGenerator } from "@unocss/core";
3
+
4
+ // src/utils.ts
5
+ var camelize = (str) => str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
6
+ var capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
7
+ var hyphenate = (str) => str.replace(/(?:^|\B)([A-Z])/g, "-$1").toLowerCase();
8
+ var prefixes = ["Webkit", "Moz", "ms"];
9
+ function autoPrefixer(style) {
10
+ const prefixCache = {};
11
+ function autoPrefix(rawName) {
12
+ const cached = prefixCache[rawName];
13
+ if (cached)
14
+ return cached;
15
+ let name = camelize(rawName);
16
+ if (name !== "filter" && name in style)
17
+ return prefixCache[rawName] = hyphenate(name);
18
+ name = capitalize(name);
19
+ for (let i = 0; i < prefixes.length; i++) {
20
+ const prefixed = `${prefixes[i]}${name}`;
21
+ if (prefixed in style)
22
+ return prefixCache[rawName] = hyphenate(capitalize(prefixed));
23
+ }
24
+ return rawName;
25
+ }
26
+ return ({ entries }) => entries.forEach((e) => {
27
+ if (!e[0].startsWith("--"))
28
+ e[0] = autoPrefix(e[0]);
29
+ });
30
+ }
31
+
32
+ // src/index.ts
3
33
  function init(options = {}) {
4
34
  var _a;
5
35
  if (typeof window == "undefined") {
6
36
  console.warn("@unocss/runtime been used in non-browser environment, skipped.");
7
37
  return;
8
38
  }
39
+ const defaultOptions = options.defaults || {};
40
+ if (options.autoPrefix) {
41
+ let postprocess = defaultOptions.postprocess;
42
+ if (!postprocess)
43
+ postprocess = [];
44
+ if (!Array.isArray(postprocess))
45
+ postprocess = [postprocess];
46
+ postprocess.unshift(autoPrefixer(document.createElement("div").style));
47
+ defaultOptions.postprocess = postprocess;
48
+ }
9
49
  Object.assign(options, (_a = window.__unocss) == null ? void 0 : _a.runtime);
10
50
  let styleElement;
11
51
  let paused = false;
12
52
  let inspector;
13
- const uno = createGenerator(window.__unocss || {}, options.defaults);
53
+ const uno = createGenerator(window.__unocss || {}, defaultOptions);
14
54
  const tokens = /* @__PURE__ */ new Set();
15
55
  let _timer;
16
56
  function scheduleUpdate() {
@@ -70,6 +110,12 @@ function init(options = {}) {
70
110
  window.__unocss_runtime = window.__unocss_runtime = {
71
111
  version: uno.version,
72
112
  uno,
113
+ async extract(userTokens) {
114
+ if (typeof userTokens === "string")
115
+ return await extract(userTokens);
116
+ userTokens.forEach((t) => tokens.add(t));
117
+ await updateStyle();
118
+ },
73
119
  extractAll,
74
120
  inspect(callback) {
75
121
  inspector = callback;