@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/attributify.global.js +5 -5
- package/core.global.js +2 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.js +47 -1
- package/dist/index.mjs +47 -1
- 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,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 || {},
|
|
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 || {},
|
|
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;
|