@unocss/runtime 0.22.0 → 0.22.4

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 ct=Object.defineProperty,lt=Object.defineProperties;var ut=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var ft=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var q=(r,t,e)=>t in r?ct(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,j=(r,t)=>{for(var e in t||(t={}))ft.call(t,e)&&q(r,e,t[e]);if(N)for(var e of N(t))pt.call(t,e)&&q(r,e,t[e]);return r},W=(r,t)=>lt(r,ut(t));function dt(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=dt;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 ht(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?"":ht(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 gt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,F="$$shortcut-no-merge";function X(r=""){return gt.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 mt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function et(r){let t=[],e;for(;e=mt.exec(r);){let i=e.index,s=i+e[0].length,[,o,a,f]=e,l=f.split(/\s/g).map(g=>g.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 yt=r=>r.split(/[\s'"`;>=]+/g).filter(X),H={name:"split",order:0,extract({code:r}){return new Set(yt(r))}};function St(r){return _(r).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var xt={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(xt,...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={},g=f.length;f.forEach((u,x)=>{J(u)&&(l[u[0]]=[x,u[1],u[2]],delete f[x])});let C=O([...i.map(u=>u.theme||{}),e.theme||{}].reduce((u,x)=>k(u,x),{}));return o("extendTheme").forEach(u=>u(C)),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:C,rulesSize:g,rulesDynamic:f,rulesStaticMap:l,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),variants:o("variants").map(Y),shortcuts:St(o("shortcuts")),extractors:a})}var it="0.22.0";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"]),g=new Set,C=new Map,u=(c,h)=>{var p;this._cache.set(c,h),g.add(c);for(let m of h){let R=m[3]||"";C.has(R)||C.set(R,[]),C.get(R).push(m),((p=m[4])==null?void 0:p.layer)&&l.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 A;if(g.has(c)||this.blocked.has(c))return;if(this._cache.has(c)){let y=this._cache.get(c);y&&u(c,y);return}let h=c;for(let y of this.config.preprocess)h=y(c);if(this.isBlocked(h))return x(h);let p=this.matchVariants(c,h);if(!p||this.isBlocked(p[1]))return x(c);let m={rawSelector:c,currentSelector:p[1],theme:this.config.theme,generator:this,variantHandlers:p[2],constructCSS:(...y)=>this.constructCustomCSS(m,...y)},R=this.expandShortcut(p[1],m);if(R){let y=await this.stringifyShortcuts(p,m,R[0],R[1]);if(y==null?void 0:y.length)return u(c,y)}else{let y=(A=await this.parseUtil(p,m))==null?void 0:A.map(S=>this.stringifyUtil(S)).filter(tt);if(y==null?void 0:y.length)return u(c,y)}this._cache.set(c,null)})),i&&this.config.preflights.forEach(c=>{c.layer&&l.add(c.layer)});let U={},b=this.config.sortLayers(Array.from(l).sort((c,h)=>{var p,m;return((p=this.config.layers[c])!=null?p:0)-((m=this.config.layers[h])!=null?m:0)||c.localeCompare(h)})),d={};i&&(d=Object.fromEntries(await Promise.all(b.map(async c=>{let p=(await Promise.all(this.config.preflights.filter(m=>(m.layer||"default")===c).map(async m=>await m.getCSS()))).filter(Boolean).join(f);return[c,p]}))));let T=c=>{if(U[c])return U[c];let h=Array.from(C).sort((p,m)=>{var R,A,y;return((R=this.parentOrders.get(p[0]))!=null?R:0)-((A=this.parentOrders.get(m[0]))!=null?A:0)||((y=p[0])==null?void 0:y.localeCompare(m[0]||""))||0}).map(([p,m])=>{let R=m.length,A=m.filter(S=>{var E;return(((E=S[4])==null?void 0:E.layer)||"default")===c}).sort((S,E)=>{var V;return S[0]-E[0]||((V=S[1])==null?void 0:V.localeCompare(E[1]||""))||0}).map(S=>[S[1]?wt(S[1],n):S[1],S[2]]).map(S=>[S[0]==null?S[0]:[S[0]],S[1]]);if(!A.length)return;let y=A.reverse().map(([S,E],V)=>{if(S&&this.config.mergeSelectors)for(let D=V+1;D<R;D++){let M=A[D];if(M&&M[0]&&M[1]===E)return M[0].push(...S),null}return S?`${[...new Set(S)].join(`,${f}`)}{${E}}`:E}).filter(Boolean).reverse().join(f);return p?`${p}{${f}${y}${f}}`:y}).filter(Boolean).join(f);return i&&(h=[d[c],h].filter(Boolean).join(f)),U[c]=!o&&h?`/* layer: ${c} */${f}${h}`:h},w=(c=b,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:b,getLayers:w,getLayer:T,matched:g}}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},Rt(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 g,C;let[i,s,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[s];if(a&&a[1]&&(n||!((g=a[2])==null?void 0:g.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||((C=x[2])==null?void 0:C.internal)&&!n)continue;let[U,b,d]=x,T=s.match(U);if(!T)continue;let w=await b(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 g=await this.parseUtil(l,e,!0);return g||nt(`unmatched utility "${l}" in shortcut "${t[1]}"`),g||[]}))).flat(1).filter(Boolean).sort((l,g)=>l[0]-g[0]),[a,,f]=t;for(let l of o){if(G(l))continue;let{selector:g,entries:C,parent:u}=this.applyVariants(l,[...l[4],...f],a);s.getFallback(g,u,[[],l[0]])[0].push(C)}return s.map(([l,g],C,u)=>{let x=l.filter(b=>b.some(d=>d[0]===F)),U=l.filter(b=>b.every(d=>d[0]!==F));return[...x,U.flat(1)].map(b=>{let d=P(b);if(d)return[g,C,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=/ \$\$ /,bt=r=>r.match(at);function wt(r,t){return bt(r)?r.replace(at,t?` ${t} `:" "):t?`${t} ${r}`:r}function Rt(r){return r.startsWith("[")?r.replace(/^\[(.+?)(~?=)"(.*)"\]$/,(t,e,n,i)=>`[${v(e)}${n}"${v(i)}"]`):`.${v(r)}`}function I(r={}){var b;if(typeof window=="undefined"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}Object.assign(r,(b=window.__unocss)==null?void 0:b.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.head.appendChild(t)),t.innerHTML=d.css}async function l(d){await i.applyExtractors(d,void 0,s),a()}async function g(){let d=document.body&&document.body.outerHTML;d&&await l(d)}let C=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||(C.observe(d,{childList:!0,subtree:!0,attributes:!0}),u=!0)}function U(){g(),x()}window.__unocss_runtime=window.__unocss_runtime={version:i.version,uno:i,extractAll:g,inspect(d){n=d},toggleObserver(d){d===void 0?e=!e:e=!!d}},U(),window.addEventListener("load",U),window.addEventListener("DOMContentLoaded",U)}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,T=(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,s="",i=e.charCodeAt(0);for(;++r<t;){if(n=e.charCodeAt(r),n===0){s+="\uFFFD";continue}if(n===44){s+="\\2c ";continue}if(n>=1&&n<=31||n===127||r===0&&n>=48&&n<=57||r===1&&n>=48&&n<=57&&i===45){s+=`\\${n.toString(16)} `;continue}if(r===0&&t===1&&n===45){s+=`\\${e.charAt(r)}`;continue}if(n>=128||n===45||n===95||n>=48&&n<=57||n>=65&&n<=90||n>=97&&n<=122){s+=e.charAt(r);continue}s+=`\\${e.charAt(r)}`}return s}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 s=n-1;s>=0;s--)if(e[s][0]===t&&e[s][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 s=T({},r);return k(r)&&k(n)&&Object.keys(n).forEach(i=>{k(n[i])?i in r?s[i]=F(r[i],n[i]):Object.assign(s,{[i]:n[i]}):Object.assign(s,{[i]:n[i]})}),s}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 s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.has(r)||s.set(r,n),s.get(r)}set(t,r,n){let s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.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(([s,i])=>t(i,r,s)))}};var Rt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function et(e){let t=[],r;for(;r=Rt.exec(e);){let s=r.index,i=s+r[0].length,[,o,a,l]=r,p=l.split(/\s/g).map(h=>h.replace(/^(!?)(.*)/,`$1${o}${a}$2`)).join(" ");t.unshift([s,i,p])}let n=e;return t.forEach(([s,i,o])=>{n=n.slice(0,s)+o+n.slice(i)}),n}var rt=new Set;function nt(e){rt.has(e)||(console.warn("[unocss]",e),rt.add(e))}var Ut=e=>e.split(/[\s'"`;>=]+/g).filter(X),H={name:"split",order:0,extract({code:e}){return new Set(Ut(e))}};function wt(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),s=[...n.filter(u=>u.enforce==="pre"),...n.filter(u=>!u.enforce),...n.filter(u=>u.enforce==="post")],i=Object.assign(Et,...n.map(u=>u.layers),e.layers);function o(u){return K([...s.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([...s.map(u=>u.theme||{}),r.theme||{}].reduce((u,x)=>F(u,x),{}));return o("extendTheme").forEach(u=>u(S)),j(T({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:u=>u},r),{presets:s,envMode:r.envMode||"build",shortcutsLayer:r.shortcutsLayer||"shortcuts",layers:i,theme:S,rulesSize:h,rulesDynamic:l,rulesStaticMap:p,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),variants:o("variants").map(Y),shortcuts:wt(o("shortcuts")),extractors:a})}var st="0.22.4";var it=class{constructor(t={},r={}){this.userConfig=t;this.defaults=r;this.config=I(t,r)}version=st;_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 s={get original(){return t},code:t,id:r};for(let i of this.config.extractors){let o=await i.extract(s);o==null||o.forEach(a=>n.add(a))}return n}async generate(t,{id:r,scope:n,preflights:s=!0,safelist:i=!0,minify:o=!1}={}){let a=typeof t=="string"?await this.applyExtractors(t,r):t;i&&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 U=m[3]||"";S.has(U)||S.set(U,[]),S.get(U).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)},U=this.expandShortcut(g[1],m);if(U){let C=await this.stringifyShortcuts(g,m,U[0],U[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)})),s&&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={};s&&(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 U,$,C;return((U=this.parentOrders.get(g[0]))!=null?U:0)-(($=this.parentOrders.get(m[0]))!=null?$:0)||((C=g[0])==null?void 0:C.localeCompare(m[0]||""))||0}).map(([g,m])=>{let U=m.length,$=m.filter(y=>{var w;return(((w=y[4])==null?void 0:w.layer)||"default")===c}).sort((y,w)=>{var P;return y[0]-w[0]||((P=y[1])==null?void 0:P.localeCompare(w[1]||""))||0}).map(y=>{var w;return[y[1]?Tt(y[1],n):y[1],y[2],!!((w=y[4])==null?void 0:w.noMerge)]}).map(y=>[y[0]==null?y[0]:[y[0]],y[1],y[2]]);if(!$.length)return;let C=$.reverse().map(([y,w,P],dt)=>{if(!P&&y&&this.config.mergeSelectors)for(let L=dt+1;L<U;L++){let O=$[L];if(O&&!O[2]&&O[0]&&O[1]===w)return O[0].push(...y),null}return y?`${[...new Set(y)].join(`,${l}`)}{${w}}`:w}).filter(Boolean).reverse().join(l);return g?`${g}{${l}${C}${l}}`:C}).filter(Boolean).join(l);return s&&(d=[b[c],d].filter(Boolean).join(l)),E[c]=!o&&d?`/* layer: ${c} */${l}${d}`:d},R=(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 R()},layers:A,getLayers:R,getLayer:f,matched:h}}matchVariants(t,r){let n=new Set,s=[],i=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(i,a);if(!!p&&(typeof p=="string"&&(p={matcher:p}),p)){i=p.matcher,Array.isArray(p.parent)&&this.parentOrders.set(p.parent[0],p.parent[1]),s.push(p),n.add(l),o=!0;break}}if(!o)break;if(s.length>500)throw new Error(`Too many variants applied to "${t}"`)}return[t,i,s]}applyVariants(t,r=t[4],n=t[1]){let s=[...r].sort((a,l)=>(a.order||0)-(l.order||0)),i=s.reduce((a,l)=>{var p;return((p=l.body)==null?void 0:p.call(l,a))||a},t[2]),o={selector:s.reduce((a,l)=>{var p;return((p=l.selector)==null?void 0:p.call(l,a,i))||a},Ot(n)),entries:i,parent:s.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:s,entries:i,parent:o}=this.applyVariants([0,n||t.rawSelector,r,void 0,t.variantHandlers]),a=`${s}{${D(i)}}`;return o?`${o}{${a}}`:a}async parseUtil(t,r,n=!1){var h,S;let[s,i,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[i];if(a&&a[1]&&(n||!((h=a[2])==null?void 0:h.internal)))return[[a[0],s,_(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=i.match(E);if(!f)continue;let R=await A(f,r);if(!R)continue;if(typeof R=="string")return[[u,R,b]];let c=Z(R).filter(d=>d.length);if(c.length)return c.map(d=>[u,s,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:s}=this.applyVariants(t),i=D(n);if(!!i)return[t[0],r,i,s,t[3]]}expandShortcut(t,r,n=3){if(n===0)return;let s,i;for(let o of this.config.shortcuts)if(Q(o)){if(o[0]===t){s=s||o[2],i=o[1];break}}else{let a=t.match(o[0]);if(a&&(i=o[1](a,r)),i){s=s||o[2];break}}if(typeof i=="string"&&(i=et(i).split(/\s+/g)),!!i)return[i.flatMap(o=>{var a;return((a=this.expandShortcut(o,r,n-1))==null?void 0:a[0])||[o]}).filter(o=>o!==""),s]}async stringifyShortcuts(t,r,n,s={layer:this.config.shortcutsLayer}){var p;let i=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);i.getFallback(S,x,[[],h[0]])[0].push([u,!!((p=h[3])==null?void 0:p.noMerge)])}return i.map(([h,S],u,x)=>{let E=b=>f=>{let R=D(f);if(R)return[S,u,R,x,j(T({},s),{noMerge:b})]};return[[h.filter(([,b])=>b).map(([b])=>b),!0],[h.filter(([,b])=>!b).map(([b])=>b),!1]].map(([b,f])=>{let R=b.filter(d=>d.some(g=>g[0]===z)),c=b.filter(d=>d.every(g=>g[0]!==z));return[...R.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 it(e,t)}var at=/ \$\$ /,$t=e=>e.match(at);function Tt(e,t){return $t(e)?e.replace(at,t?` ${t} `:" "):t?`${t} ${e}`:e}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Ot(e){return ct.test(e)?e.replace(ct,(t,r,n,s)=>`[${v(r)}${n}"${v(s)}"]`):`.${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 s=t[n];if(s)return s;let i=_t(n);if(i!=="filter"&&i in e)return t[n]=ut(i);i=lt(i);for(let o=0;o<ft.length;o++){let a=`${ft[o]}${i}`;if(a in e)return t[n]=ut(lt(a))}return n}return({entries:n})=>n.forEach(s=>{s[0].startsWith("--")||(s[0]=r(s[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,s,i=ot(window.__unocss||{},t),o=new Set,a;function l(){a!=null&&clearTimeout(a),a=setTimeout(p,0)}async function p(){let f=await i.generate(o);r||(r=document.createElement("style"),document.documentElement.prepend(r)),r.innerHTML=f.css}async function h(f){await i.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(R=>{let c=R.target;if(c===r||s&&!s(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:i.version,uno:i,extractAll:S,inspect(f){s=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 {
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
- let el;
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() {
@@ -52,11 +92,11 @@ function init(options = {}) {
52
92
  }
53
93
  async function updateStyle() {
54
94
  const result = await uno.generate(tokens);
55
- if (!el) {
56
- el = document.createElement("style");
57
- document.head.appendChild(el);
95
+ if (!styleElement) {
96
+ styleElement = document.createElement("style");
97
+ document.documentElement.prepend(styleElement);
58
98
  }
59
- el.innerHTML = result.css;
99
+ styleElement.innerHTML = result.css;
60
100
  }
61
101
  async function extract(str) {
62
102
  await uno.applyExtractors(str, void 0, tokens);
@@ -72,7 +112,7 @@ function init(options = {}) {
72
112
  return;
73
113
  mutations.forEach((mutation) => {
74
114
  const target = mutation.target;
75
- if (target === el)
115
+ if (target === styleElement)
76
116
  return;
77
117
  if (inspector && !inspector(target))
78
118
  return;
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
- let el;
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() {
@@ -20,11 +60,11 @@ function init(options = {}) {
20
60
  }
21
61
  async function updateStyle() {
22
62
  const result = await uno.generate(tokens);
23
- if (!el) {
24
- el = document.createElement("style");
25
- document.head.appendChild(el);
63
+ if (!styleElement) {
64
+ styleElement = document.createElement("style");
65
+ document.documentElement.prepend(styleElement);
26
66
  }
27
- el.innerHTML = result.css;
67
+ styleElement.innerHTML = result.css;
28
68
  }
29
69
  async function extract(str) {
30
70
  await uno.applyExtractors(str, void 0, tokens);
@@ -40,7 +80,7 @@ function init(options = {}) {
40
80
  return;
41
81
  mutations.forEach((mutation) => {
42
82
  const target = mutation.target;
43
- if (target === el)
83
+ if (target === styleElement)
44
84
  return;
45
85
  if (inspector && !inspector(target))
46
86
  return;