@unocss/runtime 0.21.2 → 0.22.3
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/attributify.global.js +5 -5
- package/core.global.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +47 -7
- package/dist/index.mjs +47 -7
- package/mini.global.js +3 -3
- package/package.json +4 -4
- package/uno.global.js +5 -5
package/core.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var
|
|
2
|
-
`,
|
|
1
|
+
(()=>{var gt=Object.defineProperty,ht=Object.defineProperties;var mt=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var yt=Object.prototype.hasOwnProperty,St=Object.prototype.propertyIsEnumerable;var N=(e,t,r)=>t in e?gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,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.3";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
|
|
82
|
+
let styleElement;
|
|
43
83
|
let paused = false;
|
|
44
84
|
let inspector;
|
|
45
|
-
const uno = (0, import_core.createGenerator)(window.__unocss || {},
|
|
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 (!
|
|
56
|
-
|
|
57
|
-
document.
|
|
95
|
+
if (!styleElement) {
|
|
96
|
+
styleElement = document.createElement("style");
|
|
97
|
+
document.documentElement.prepend(styleElement);
|
|
58
98
|
}
|
|
59
|
-
|
|
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 ===
|
|
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
|
|
50
|
+
let styleElement;
|
|
11
51
|
let paused = false;
|
|
12
52
|
let inspector;
|
|
13
|
-
const uno = createGenerator(window.__unocss || {},
|
|
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 (!
|
|
24
|
-
|
|
25
|
-
document.
|
|
63
|
+
if (!styleElement) {
|
|
64
|
+
styleElement = document.createElement("style");
|
|
65
|
+
document.documentElement.prepend(styleElement);
|
|
26
66
|
}
|
|
27
|
-
|
|
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 ===
|
|
83
|
+
if (target === styleElement)
|
|
44
84
|
return;
|
|
45
85
|
if (inspector && !inspector(target))
|
|
46
86
|
return;
|