@unocss/runtime 0.22.4 → 0.23.0
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 +54 -39
- package/dist/index.js +40 -23
- package/dist/index.mjs +39 -17
- 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 gt=Object.defineProperty,
|
|
2
|
-
`,
|
|
1
|
+
(()=>{var gt=Object.defineProperty,mt=Object.defineProperties;var yt=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var W=(n,t,e)=>t in n?gt(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,$=(n,t)=>{for(var e in t||(t={}))N.call(t,e)&&W(n,e,t[e]);if(v)for(var e of v(t))Z.call(t,e)&&W(n,e,t[e]);return n},O=(n,t)=>mt(n,yt(t));var J=(n,t)=>{var e={};for(var r in n)N.call(n,r)&&t.indexOf(r)<0&&(e[r]=n[r]);if(n!=null&&v)for(var r of v(n))t.indexOf(r)<0&&Z.call(n,r)&&(e[r]=n[r]);return e};function St(n){let t=n.length,e=-1,r,s="",o=n.charCodeAt(0);for(;++e<t;){if(r=n.charCodeAt(e),r===0){s+="\uFFFD";continue}if(r===44){s+="\\2c ";continue}if(r>=1&&r<=31||r===127||e===0&&r>=48&&r<=57||e===1&&r>=48&&r<=57&&o===45){s+=`\\${r.toString(16)} `;continue}if(e===0&&t===1&&r===45){s+=`\\${n.charAt(e)}`;continue}if(r>=128||r===45||r===95||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122){s+=n.charAt(e);continue}s+=`\\${n.charAt(e)}`}return s}var j=St;function M(n){return(Array.isArray(n)?n:Object.entries(n)).filter(t=>t[1]!=null)}function Q(n){return Array.isArray(n)?n.find(t=>!Array.isArray(t)||Array.isArray(t[0]))?n.map(t=>M(t)):[n]:[M(n)]}function xt(n){return n.filter(([t,e],r)=>{if(t.startsWith("$$"))return!1;for(let s=r-1;s>=0;s--)if(n[s][0]===t&&n[s][1]===e)return!1;return!0})}function D(n){return n==null?"":xt(n).map(([t,e])=>e!=null?`${t}:${e};`:void 0).filter(Boolean).join("")}function L(n){return n&&typeof n=="object"&&!Array.isArray(n)}function F(n,t){let e=n,r=t;if(Array.isArray(e)&&Array.isArray(r))return[...e,...r];if(Array.isArray(e))return[...e];let s=$({},e);return L(e)&&L(r)&&Object.keys(r).forEach(o=>{L(r[o])?o in e?s[o]=F(e[o],r[o]):Object.assign(s,{[o]:r[o]}):Object.assign(s,{[o]:r[o]})}),s}function V(n){let t,e,r;if(Array.isArray(n)){for(e=Array(t=n.length);t--;)e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}if(Object.prototype.toString.call(n)==="[object Object]"){e={};for(t in n)t==="__proto__"?Object.defineProperty(e,t,{value:V(n[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(r=n[t])&&typeof r=="object"?V(r):r;return e}return n}function X(n){return typeof n[0]=="string"}function Y(n){return typeof n[0]=="string"}function P(n=[]){return Array.isArray(n)?n:[n]}function K(n){return Array.from(new Set(n))}var Ct=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,z="$$shortcut-no-merge";function tt(n=""){return Ct.test(n)}function et(n){return typeof n=="function"?{match:n}:n}function B(n){return n.length===3}function rt(n){return n!=null}var G=class{_map=new Map;get(t,e){let r=this._map.get(t);if(r)return r.get(e)}getFallback(t,e,r){let s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.has(e)||s.set(e,r),s.get(e)}set(t,e,r){let s=this._map.get(t);return s||(s=new Map,this._map.set(t,s)),s.set(e,r),this}has(t,e){var r;return(r=this._map.get(t))==null?void 0:r.has(e)}delete(t,e){var r;return((r=this._map.get(t))==null?void 0:r.delete(e))||!1}deleteTop(t){return this._map.delete(t)}map(t){return Array.from(this._map.entries()).flatMap(([e,r])=>Array.from(r.entries()).map(([s,o])=>t(o,e,s)))}};var bt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function nt(n){let t=[],e;for(;e=bt.exec(n);){let s=e.index,o=s+e[0].length,[,a,i,c]=e,u=c.split(/\s/g).map(d=>d.replace(/^(!?)(.*)/,`$1${a}${i}$2`)).join(" ");t.unshift([s,o,u])}let r=n;return t.forEach(([s,o,a])=>{r=r.slice(0,s)+a+r.slice(o)}),r}var st=new Set;function it(n){st.has(n)||(console.warn("[unocss]",n),st.add(n))}var Rt=n=>n.split(/[\s'"`;>=]+/g).filter(tt),H={name:"split",order:0,extract({code:n}){return new Set(Rt(n))}};function Ut(n){return P(n).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var wt={shortcuts:-1,default:0};function I(n={},t={}){let e=Object.assign({},t,n),r=(e.presets||[]).flatMap(P),s=[...r.filter(l=>l.enforce==="pre"),...r.filter(l=>!l.enforce),...r.filter(l=>l.enforce==="post")],o=Object.assign(wt,...r.map(l=>l.layers),n.layers);function a(l){return K([...s.flatMap(S=>P(S[l]||[])),...P(e[l]||[])])}let i=a("extractors");i.length||i.push(H),i.sort((l,S)=>(l.order||0)-(S.order||0));let c=a("rules"),u={},d=c.length;c.forEach((l,S)=>{X(l)&&(u[l[0]]=[S,l[1],l[2]],delete c[S])});let C=V([...s.map(l=>l.theme||{}),e.theme||{}].reduce((l,S)=>F(l,S),{}));return a("extendTheme").forEach(l=>l(C)),O($({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:l=>l},e),{presets:s,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:o,theme:C,rulesSize:d,rulesDynamic:c,rulesStaticMap:u,preprocess:a("preprocess"),postprocess:a("postprocess"),preflights:a("preflights"),variants:a("variants").map(et),shortcuts:Ut(a("shortcuts")),extractors:i})}var ot="0.23.0";var ct=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=I(t,e)}version=ot;_cache=new Map;config;blocked=new Set;parentOrders=new Map;setConfig(t,e){!t||(e&&(this.defaults=e),this.userConfig=t,this.config=I(t,this.defaults),this.blocked.clear(),this.parentOrders.clear(),this._cache.clear())}async applyExtractors(t,e,r=new Set){let s={get original(){return t},code:t,id:e};for(let o of this.config.extractors){let a=await o.extract(s);a==null||a.forEach(i=>r.add(i))}return r}async parseToken(t){var a;if(this.blocked.has(t))return;if(this._cache.has(t))return this._cache.get(t);let e=t;for(let i of this.config.preprocess)e=i(t);if(this.isBlocked(e)){this.blocked.add(t),this._cache.set(t,null);return}let r=this.matchVariants(t,e);if(!r||this.isBlocked(r[1])){this.blocked.add(t),this._cache.set(t,null);return}let s={rawSelector:t,currentSelector:r[1],theme:this.config.theme,generator:this,variantHandlers:r[2],constructCSS:(...i)=>this.constructCustomCSS(s,...i)},o=this.expandShortcut(r[1],s);if(o){let i=await this.stringifyShortcuts(r,s,o[0],o[1]);if(i==null?void 0:i.length)return this._cache.set(t,i),i}else{let i=(a=await this.parseUtil(r,s))==null?void 0:a.map(c=>this.stringifyUtil(c)).filter(rt);if(i==null?void 0:i.length)return this._cache.set(t,i),i}this._cache.set(t,null)}async generate(t,{id:e,scope:r,preflights:s=!0,safelist:o=!0,minify:a=!1}={}){let i=typeof t=="string"?await this.applyExtractors(t,e):t;o&&this.config.safelist.forEach(p=>i.add(p));let c=a?"":`
|
|
2
|
+
`,u=new Set(["default"]),d=new Set,C=new Map;await Promise.all(Array.from(i).map(async p=>{var y;if(d.has(p))return;let h=await this.parseToken(p);if(h!=null){d.add(p);for(let g of h){let R=g[3]||"";C.has(R)||C.set(R,[]),C.get(R).push(g),((y=g[4])==null?void 0:y.layer)&&u.add(g[4].layer)}}})),s&&this.config.preflights.forEach(p=>{p.layer&&u.add(p.layer)});let l={},S=this.config.sortLayers(Array.from(u).sort((p,h)=>{var y,g;return((y=this.config.layers[p])!=null?y:0)-((g=this.config.layers[h])!=null?g:0)||p.localeCompare(h)})),U={};s&&(U=Object.fromEntries(await Promise.all(S.map(async p=>{let y=(await Promise.all(this.config.preflights.filter(g=>(g.layer||"default")===p).map(async g=>await g.getCSS()))).filter(Boolean).join(c);return[p,y]}))));let A=p=>{if(l[p])return l[p];let h=Array.from(C).sort((y,g)=>{var R,w,f;return((R=this.parentOrders.get(y[0]))!=null?R:0)-((w=this.parentOrders.get(g[0]))!=null?w:0)||((f=y[0])==null?void 0:f.localeCompare(g[0]||""))||0}).map(([y,g])=>{let R=g.length,w=g.filter(m=>{var b;return(((b=m[4])==null?void 0:b.layer)||"default")===p}).sort((m,b)=>{var T;return m[0]-b[0]||((T=m[1])==null?void 0:T.localeCompare(b[1]||""))||0}).map(m=>{var b;return[m[1]?$t(m[1],r):m[1],m[2],!!((b=m[4])==null?void 0:b.noMerge)]}).map(m=>[m[0]==null?m[0]:[m[0]],m[1],m[2]]);if(!w.length)return;let f=w.reverse().map(([m,b,T],k)=>{if(!T&&m&&this.config.mergeSelectors)for(let E=k+1;E<R;E++){let _=w[E];if(_&&!_[2]&&_[0]&&_[1]===b)return _[0].push(...m),null}return m?`${[...new Set(m)].join(`,${c}`)}{${b}}`:b}).filter(Boolean).reverse().join(c);return y?`${y}{${c}${f}${c}}`:f}).filter(Boolean).join(c);return s&&(h=[U[p],h].filter(Boolean).join(c)),l[p]=!a&&h?`/* layer: ${p} */${c}${h}`:h},x=(p=S,h)=>p.filter(y=>!(h==null?void 0:h.includes(y))).map(y=>A(y)||"").filter(Boolean).join(c);return{get css(){return x()},layers:S,getLayers:x,getLayer:A,matched:d}}matchVariants(t,e){let r=new Set,s=[],o=e||t,a=!1,i={rawSelector:t,theme:this.config.theme,generator:this};for(;;){a=!1;for(let c of this.config.variants){if(!c.multiPass&&r.has(c))continue;let u=c.match(o,i);if(!!u&&(typeof u=="string"&&(u={matcher:u}),u)){o=u.matcher,Array.isArray(u.parent)&&this.parentOrders.set(u.parent[0],u.parent[1]),s.push(u),r.add(c),a=!0;break}}if(!a)break;if(s.length>500)throw new Error(`Too many variants applied to "${t}"`)}return[t,o,s]}applyVariants(t,e=t[4],r=t[1]){let s=[...e].sort((i,c)=>(i.order||0)-(c.order||0)),o=s.reduce((i,c)=>{var u;return((u=c.body)==null?void 0:u.call(c,i))||i},t[2]),a={selector:s.reduce((i,c)=>{var u;return((u=c.selector)==null?void 0:u.call(c,i,o))||i},Tt(r)),entries:o,parent:s.reduce((i,c)=>Array.isArray(c.parent)?c.parent[0]:c.parent||i,void 0),layer:s.reduce((i,c)=>c.layer||i,void 0)};for(let i of this.config.postprocess)i(a);return a}constructCustomCSS(t,e,r){e=M(e);let{selector:s,entries:o,parent:a}=this.applyVariants([0,r||t.rawSelector,e,void 0,t.variantHandlers]),i=`${s}{${D(o)}}`;return a?`${a}{${i}}`:i}async parseUtil(t,e,r=!1){var d,C;let[s,o,a]=typeof t=="string"?this.matchVariants(t):t,i=this.config.rulesStaticMap[o];if(i&&i[1]&&(r||!((d=i[2])==null?void 0:d.internal)))return[[i[0],s,M(i[1]),i[2],a]];e.variantHandlers=a;let{rulesDynamic:c,rulesSize:u}=this.config;for(let l=u;l>=0;l--){let S=c[l];if(!S||((C=S[2])==null?void 0:C.internal)&&!r)continue;let[U,A,x]=S,p=o.match(U);if(!p)continue;let h=await A(p,e);if(!h)continue;if(typeof h=="string")return[[l,h,x]];let y=Q(h).filter(g=>g.length);if(y.length)return y.map(g=>[l,s,g,x,a])}}stringifyUtil(t){var u;if(!t)return;if(B(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:r,parent:s,layer:o}=this.applyVariants(t),a=D(r);if(!a)return;let d=(u=t[3])!=null?u:{},{layer:i}=d,c=J(d,["layer"]);return[t[0],e,a,s,O($({},c),{layer:o!=null?o:i})]}expandShortcut(t,e,r=3){if(r===0)return;let s,o;for(let a of this.config.shortcuts)if(Y(a)){if(a[0]===t){s=s||a[2],o=a[1];break}}else{let i=t.match(a[0]);if(i&&(o=a[1](i,e)),o){s=s||a[2];break}}if(typeof o=="string"&&(o=nt(o).split(/\s+/g)),!!o)return[o.flatMap(a=>{var i;return((i=this.expandShortcut(a,e,r-1))==null?void 0:i[0])||[a]}).filter(a=>a!==""),s]}async stringifyShortcuts(t,e,r,s={layer:this.config.shortcutsLayer}){var u;let o=new G,a=(await Promise.all(K(r).map(async d=>{let C=await this.parseUtil(d,e,!0);return C||it(`unmatched utility "${d}" in shortcut "${t[1]}"`),C||[]}))).flat(1).filter(Boolean).sort((d,C)=>d[0]-C[0]),[i,,c]=t;for(let d of a){if(B(d))continue;let{selector:C,entries:l,parent:S}=this.applyVariants(d,[...d[4],...c],i);o.getFallback(C,S,[[],d[0]])[0].push([l,!!((u=d[3])==null?void 0:u.noMerge)])}return o.map(([d,C],l,S)=>{let U=x=>p=>{let h=D(p);if(h)return[C,l,h,S,O($({},s),{noMerge:x})]};return[[d.filter(([,x])=>x).map(([x])=>x),!0],[d.filter(([,x])=>!x).map(([x])=>x),!1]].map(([x,p])=>{let h=x.filter(g=>g.some(R=>R[0]===z)),y=x.filter(g=>g.every(R=>R[0]!==z));return[...h.map(U(p)),...[y.flat(1)].map(U(p))]})}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function lt(n,t){return new ct(n,t)}var ut=/ \$\$ /,At=n=>n.match(ut);function $t(n,t){return At(n)?n.replace(ut,t?` ${t} `:" "):t?`${t} ${n}`:n}var at=/^\[(.+?)(~?=)"(.*)"\]$/;function Tt(n){return at.test(n)?n.replace(at,(t,e,r,s)=>`[${j(e)}${r}"${j(s)}"]`):`.${j(n)}`}var _t=n=>n.replace(/-(\w)/g,(t,e)=>e?e.toUpperCase():""),ft=n=>n.charAt(0).toUpperCase()+n.slice(1),pt=n=>n.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),dt=["Webkit","Moz","ms"];function ht(n){let t={};function e(r){let s=t[r];if(s)return s;let o=_t(r);if(o!=="filter"&&o in n)return t[r]=pt(o);o=ft(o);for(let a=0;a<dt.length;a++){let i=`${dt[a]}${o}`;if(i in n)return t[r]=pt(ft(i))}return r}return({entries:r})=>r.forEach(s=>{s[0].startsWith("--")||(s[0]=e(s[0]))})}function q(n={}){var R,w;if(typeof window>"u"){console.warn("@unocss/runtime been used in non-browser environment, skipped.");return}let t=window.__unocss||{},e=t==null?void 0:t.runtime,r=Object.assign(n.defaults||{},e);if(e==null?void 0:e.autoPrefix){let f=r.postprocess;f||(f=[]),Array.isArray(f)||(f=[f]),f.unshift(ht(document.createElement("div").style)),r.postprocess=f}(R=e==null?void 0:e.configResolved)==null||R.call(e,t,r);let s,o=!0,a,i=lt(t,r),c=new Set,u,d=[],C=()=>new Promise(f=>{d.push(f),u!=null&&clearTimeout(u),u=setTimeout(()=>l().then(()=>{let m=d;d=[],m.forEach(b=>b())}),0)});async function l(){let f=await i.generate(c);s||(s=document.createElement("style"),document.documentElement.prepend(s)),s.innerHTML=f.css}async function S(f){await i.applyExtractors(f,void 0,c),await C()}async function U(){let f=document.body&&document.body.outerHTML;f&&await S(f)}let A=new MutationObserver(f=>{o||f.forEach(m=>{let b=m.target;if(b===s||a&&!a(b))return;let T=Array.from(b.attributes).map(E=>E.value?`${E.name}="${E.value}"`:E.name).join(" "),k=`<${b.tagName.toLowerCase()} ${T}>`;S(k)})}),x=!1;function p(){if(!x)return;let f=document.documentElement||document.body;!f||(A.observe(f,{childList:!0,subtree:!0,attributes:!0}),x=!0)}function h(){U(),p()}function y(){h(),window.addEventListener("load",h),window.addEventListener("DOMContentLoaded",h)}let g=window.__unocss_runtime=window.__unocss_runtime={version:i.version,uno:i,async extract(f){if(typeof f=="string")return await S(f);f.forEach(m=>c.add(m)),await l()},extractAll:U,inspect(f){a=f},toggleObserver(f){f===void 0?o=!o:o=!!f,!x&&!o&&y()}};((w=e==null?void 0:e.ready)==null?void 0:w.call(e,g))!==!1&&(o=!1,y())}q();})();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserConfig,
|
|
1
|
+
import { UserConfig, UserConfigDefaults, UnoGenerator } from '@unocss/core';
|
|
2
2
|
|
|
3
3
|
interface RuntimeOptions {
|
|
4
4
|
/**
|
|
@@ -10,51 +10,66 @@ interface RuntimeOptions {
|
|
|
10
10
|
* @default false
|
|
11
11
|
*/
|
|
12
12
|
autoPrefix?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Callback to modify config
|
|
15
|
+
*/
|
|
16
|
+
configResolved?: (config: UserConfig, defaults: UserConfigDefaults) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Callback when the runtime is ready. Returning false will prevent default extraction
|
|
19
|
+
*/
|
|
20
|
+
ready?: (runtime: RuntimeContext) => false | any;
|
|
13
21
|
}
|
|
14
22
|
declare type RuntimeInspectorCallback = (element: Element) => boolean;
|
|
23
|
+
interface RuntimeContext {
|
|
24
|
+
/**
|
|
25
|
+
* The UnoCSS instance.
|
|
26
|
+
*
|
|
27
|
+
* @type {UnoGenerator}
|
|
28
|
+
*/
|
|
29
|
+
uno: UnoGenerator;
|
|
30
|
+
/**
|
|
31
|
+
* Run extractor on specified tokens
|
|
32
|
+
*
|
|
33
|
+
* @returns {Promise<void>}
|
|
34
|
+
*/
|
|
35
|
+
extract: (tokens: string | string[]) => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
|
|
38
|
+
*
|
|
39
|
+
* @returns {Promise<void>}
|
|
40
|
+
*/
|
|
41
|
+
extractAll: () => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Set/unset inspection callback to allow/ignore element to be extracted.
|
|
44
|
+
*
|
|
45
|
+
* @param {RuntimeInspectorCallback} [callback] - Callback to determine whether the element will be extracted.
|
|
46
|
+
*
|
|
47
|
+
* @returns {void}
|
|
48
|
+
*/
|
|
49
|
+
inspect: (callback?: RuntimeInspectorCallback) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Pause/resume/toggle the runtime.
|
|
52
|
+
*
|
|
53
|
+
* @param {boolean} [state] - False or True respectively pause or resume the runtime. Undefined parameter toggles the pause/resume state.
|
|
54
|
+
*
|
|
55
|
+
* @returns {void}
|
|
56
|
+
*/
|
|
57
|
+
toggleObserver: (state?: boolean) => void;
|
|
58
|
+
/**
|
|
59
|
+
* The UnoCSS version.
|
|
60
|
+
*
|
|
61
|
+
* @type {string}
|
|
62
|
+
*/
|
|
63
|
+
version: string;
|
|
64
|
+
}
|
|
15
65
|
declare global {
|
|
16
66
|
interface Window {
|
|
17
67
|
__unocss?: UserConfig & {
|
|
18
68
|
runtime?: RuntimeOptions;
|
|
19
69
|
};
|
|
20
|
-
__unocss_runtime?:
|
|
21
|
-
/**
|
|
22
|
-
* The UnoCSS instance.
|
|
23
|
-
*
|
|
24
|
-
* @type {UnoGenerator}
|
|
25
|
-
*/
|
|
26
|
-
uno: UnoGenerator;
|
|
27
|
-
/**
|
|
28
|
-
* Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
|
|
29
|
-
*
|
|
30
|
-
* @returns {Promise<void>}
|
|
31
|
-
*/
|
|
32
|
-
extractAll: () => Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Set/unset inspection callback to allow/ignore element to be extracted.
|
|
35
|
-
*
|
|
36
|
-
* @param {RuntimeInspectorCallback} [callback] - Callback to determine whether the element will be extracted.
|
|
37
|
-
*
|
|
38
|
-
* @returns {void}
|
|
39
|
-
*/
|
|
40
|
-
inspect: (callback?: RuntimeInspectorCallback) => void;
|
|
41
|
-
/**
|
|
42
|
-
* Pause/resume/toggle the runtime.
|
|
43
|
-
*
|
|
44
|
-
* @param {boolean} [state] - False or True respectively pause or resume the runtime. Undefined parameter toggles the pause/resume state.
|
|
45
|
-
*
|
|
46
|
-
* @returns {void}
|
|
47
|
-
*/
|
|
48
|
-
toggleObserver: (state?: boolean) => void;
|
|
49
|
-
/**
|
|
50
|
-
* The UnoCSS version.
|
|
51
|
-
*
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
version: string;
|
|
55
|
-
};
|
|
70
|
+
__unocss_runtime?: RuntimeContext;
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
|
-
declare function init(
|
|
73
|
+
declare function init(inlineConfig?: RuntimeOptions): void;
|
|
59
74
|
|
|
60
|
-
export { RuntimeInspectorCallback, RuntimeOptions, init as default };
|
|
75
|
+
export { RuntimeContext, RuntimeInspectorCallback, RuntimeOptions, init as default };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
6
|
var __export = (target, all) => {
|
|
@@ -17,9 +15,6 @@ var __reExport = (target, module2, copyDefault, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return target;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
18
|
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
19
|
return (module2, temp) => {
|
|
25
20
|
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
@@ -31,7 +26,7 @@ var src_exports = {};
|
|
|
31
26
|
__export(src_exports, {
|
|
32
27
|
default: () => init
|
|
33
28
|
});
|
|
34
|
-
var import_core =
|
|
29
|
+
var import_core = require("@unocss/core");
|
|
35
30
|
|
|
36
31
|
// src/utils.ts
|
|
37
32
|
var camelize = (str) => str.replace(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
|
|
@@ -62,34 +57,42 @@ function autoPrefixer(style) {
|
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
// src/index.ts
|
|
65
|
-
function init(
|
|
66
|
-
var _a;
|
|
60
|
+
function init(inlineConfig = {}) {
|
|
61
|
+
var _a, _b;
|
|
67
62
|
if (typeof window == "undefined") {
|
|
68
63
|
console.warn("@unocss/runtime been used in non-browser environment, skipped.");
|
|
69
64
|
return;
|
|
70
65
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
const config = window.__unocss || {};
|
|
67
|
+
const runtime = config == null ? void 0 : config.runtime;
|
|
68
|
+
const defaultConfig = Object.assign(inlineConfig.defaults || {}, runtime);
|
|
69
|
+
if (runtime == null ? void 0 : runtime.autoPrefix) {
|
|
70
|
+
let postprocess = defaultConfig.postprocess;
|
|
74
71
|
if (!postprocess)
|
|
75
72
|
postprocess = [];
|
|
76
73
|
if (!Array.isArray(postprocess))
|
|
77
74
|
postprocess = [postprocess];
|
|
78
75
|
postprocess.unshift(autoPrefixer(document.createElement("div").style));
|
|
79
|
-
|
|
76
|
+
defaultConfig.postprocess = postprocess;
|
|
80
77
|
}
|
|
81
|
-
|
|
78
|
+
(_a = runtime == null ? void 0 : runtime.configResolved) == null ? void 0 : _a.call(runtime, config, defaultConfig);
|
|
82
79
|
let styleElement;
|
|
83
|
-
let paused =
|
|
80
|
+
let paused = true;
|
|
84
81
|
let inspector;
|
|
85
|
-
const uno = (0, import_core.createGenerator)(
|
|
82
|
+
const uno = (0, import_core.createGenerator)(config, defaultConfig);
|
|
86
83
|
const tokens = /* @__PURE__ */ new Set();
|
|
87
84
|
let _timer;
|
|
88
|
-
|
|
85
|
+
let _resolvers = [];
|
|
86
|
+
const scheduleUpdate = () => new Promise((resolve) => {
|
|
87
|
+
_resolvers.push(resolve);
|
|
89
88
|
if (_timer != null)
|
|
90
89
|
clearTimeout(_timer);
|
|
91
|
-
_timer = setTimeout(updateStyle
|
|
92
|
-
|
|
90
|
+
_timer = setTimeout(() => updateStyle().then(() => {
|
|
91
|
+
const resolvers = _resolvers;
|
|
92
|
+
_resolvers = [];
|
|
93
|
+
resolvers.forEach((r) => r());
|
|
94
|
+
}), 0);
|
|
95
|
+
});
|
|
93
96
|
async function updateStyle() {
|
|
94
97
|
const result = await uno.generate(tokens);
|
|
95
98
|
if (!styleElement) {
|
|
@@ -100,7 +103,7 @@ function init(options = {}) {
|
|
|
100
103
|
}
|
|
101
104
|
async function extract(str) {
|
|
102
105
|
await uno.applyExtractors(str, void 0, tokens);
|
|
103
|
-
scheduleUpdate();
|
|
106
|
+
await scheduleUpdate();
|
|
104
107
|
}
|
|
105
108
|
async function extractAll() {
|
|
106
109
|
const html = document.body && document.body.outerHTML;
|
|
@@ -139,9 +142,20 @@ function init(options = {}) {
|
|
|
139
142
|
extractAll();
|
|
140
143
|
observe();
|
|
141
144
|
}
|
|
142
|
-
|
|
145
|
+
function ready() {
|
|
146
|
+
execute();
|
|
147
|
+
window.addEventListener("load", execute);
|
|
148
|
+
window.addEventListener("DOMContentLoaded", execute);
|
|
149
|
+
}
|
|
150
|
+
const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
|
|
143
151
|
version: uno.version,
|
|
144
152
|
uno,
|
|
153
|
+
async extract(userTokens) {
|
|
154
|
+
if (typeof userTokens === "string")
|
|
155
|
+
return await extract(userTokens);
|
|
156
|
+
userTokens.forEach((t) => tokens.add(t));
|
|
157
|
+
await updateStyle();
|
|
158
|
+
},
|
|
145
159
|
extractAll,
|
|
146
160
|
inspect(callback) {
|
|
147
161
|
inspector = callback;
|
|
@@ -151,11 +165,14 @@ function init(options = {}) {
|
|
|
151
165
|
paused = !paused;
|
|
152
166
|
else
|
|
153
167
|
paused = !!set;
|
|
168
|
+
if (!observing && !paused)
|
|
169
|
+
ready();
|
|
154
170
|
}
|
|
155
171
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
|
|
173
|
+
paused = false;
|
|
174
|
+
ready();
|
|
175
|
+
}
|
|
159
176
|
}
|
|
160
177
|
module.exports = __toCommonJS(src_exports);
|
|
161
178
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -30,34 +30,42 @@ function autoPrefixer(style) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// src/index.ts
|
|
33
|
-
function init(
|
|
34
|
-
var _a;
|
|
33
|
+
function init(inlineConfig = {}) {
|
|
34
|
+
var _a, _b;
|
|
35
35
|
if (typeof window == "undefined") {
|
|
36
36
|
console.warn("@unocss/runtime been used in non-browser environment, skipped.");
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const config = window.__unocss || {};
|
|
40
|
+
const runtime = config == null ? void 0 : config.runtime;
|
|
41
|
+
const defaultConfig = Object.assign(inlineConfig.defaults || {}, runtime);
|
|
42
|
+
if (runtime == null ? void 0 : runtime.autoPrefix) {
|
|
43
|
+
let postprocess = defaultConfig.postprocess;
|
|
42
44
|
if (!postprocess)
|
|
43
45
|
postprocess = [];
|
|
44
46
|
if (!Array.isArray(postprocess))
|
|
45
47
|
postprocess = [postprocess];
|
|
46
48
|
postprocess.unshift(autoPrefixer(document.createElement("div").style));
|
|
47
|
-
|
|
49
|
+
defaultConfig.postprocess = postprocess;
|
|
48
50
|
}
|
|
49
|
-
|
|
51
|
+
(_a = runtime == null ? void 0 : runtime.configResolved) == null ? void 0 : _a.call(runtime, config, defaultConfig);
|
|
50
52
|
let styleElement;
|
|
51
|
-
let paused =
|
|
53
|
+
let paused = true;
|
|
52
54
|
let inspector;
|
|
53
|
-
const uno = createGenerator(
|
|
55
|
+
const uno = createGenerator(config, defaultConfig);
|
|
54
56
|
const tokens = /* @__PURE__ */ new Set();
|
|
55
57
|
let _timer;
|
|
56
|
-
|
|
58
|
+
let _resolvers = [];
|
|
59
|
+
const scheduleUpdate = () => new Promise((resolve) => {
|
|
60
|
+
_resolvers.push(resolve);
|
|
57
61
|
if (_timer != null)
|
|
58
62
|
clearTimeout(_timer);
|
|
59
|
-
_timer = setTimeout(updateStyle
|
|
60
|
-
|
|
63
|
+
_timer = setTimeout(() => updateStyle().then(() => {
|
|
64
|
+
const resolvers = _resolvers;
|
|
65
|
+
_resolvers = [];
|
|
66
|
+
resolvers.forEach((r) => r());
|
|
67
|
+
}), 0);
|
|
68
|
+
});
|
|
61
69
|
async function updateStyle() {
|
|
62
70
|
const result = await uno.generate(tokens);
|
|
63
71
|
if (!styleElement) {
|
|
@@ -68,7 +76,7 @@ function init(options = {}) {
|
|
|
68
76
|
}
|
|
69
77
|
async function extract(str) {
|
|
70
78
|
await uno.applyExtractors(str, void 0, tokens);
|
|
71
|
-
scheduleUpdate();
|
|
79
|
+
await scheduleUpdate();
|
|
72
80
|
}
|
|
73
81
|
async function extractAll() {
|
|
74
82
|
const html = document.body && document.body.outerHTML;
|
|
@@ -107,9 +115,20 @@ function init(options = {}) {
|
|
|
107
115
|
extractAll();
|
|
108
116
|
observe();
|
|
109
117
|
}
|
|
110
|
-
|
|
118
|
+
function ready() {
|
|
119
|
+
execute();
|
|
120
|
+
window.addEventListener("load", execute);
|
|
121
|
+
window.addEventListener("DOMContentLoaded", execute);
|
|
122
|
+
}
|
|
123
|
+
const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
|
|
111
124
|
version: uno.version,
|
|
112
125
|
uno,
|
|
126
|
+
async extract(userTokens) {
|
|
127
|
+
if (typeof userTokens === "string")
|
|
128
|
+
return await extract(userTokens);
|
|
129
|
+
userTokens.forEach((t) => tokens.add(t));
|
|
130
|
+
await updateStyle();
|
|
131
|
+
},
|
|
113
132
|
extractAll,
|
|
114
133
|
inspect(callback) {
|
|
115
134
|
inspector = callback;
|
|
@@ -119,11 +138,14 @@ function init(options = {}) {
|
|
|
119
138
|
paused = !paused;
|
|
120
139
|
else
|
|
121
140
|
paused = !!set;
|
|
141
|
+
if (!observing && !paused)
|
|
142
|
+
ready();
|
|
122
143
|
}
|
|
123
144
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
|
|
146
|
+
paused = false;
|
|
147
|
+
ready();
|
|
148
|
+
}
|
|
127
149
|
}
|
|
128
150
|
export {
|
|
129
151
|
init as default
|