@unocss/runtime 0.21.1 → 0.22.2

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