@unocss/runtime 0.22.6 → 0.22.7
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 -45
- package/dist/index.js +30 -14
- package/dist/index.mjs +30 -14
- 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 W=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable;var Z=(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={}))W.call(t,e)&&Z(n,e,t[e]);if(v)for(var e of v(t))N.call(t,e)&&Z(n,e,t[e]);return n},O=(n,t)=>mt(n,yt(t));var J=(n,t)=>{var e={};for(var r in n)W.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&&N.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 V(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=>V(t)):[n]:[V(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 M(n){let t,e,r;if(Array.isArray(n)){for(e=Array(t=n.length);t--;)e[t]=(r=n[t])&&typeof r=="object"?M(r):r;return e}if(Object.prototype.toString.call(n)==="[object Object]"){e={};for(t in n)t==="__proto__"?Object.defineProperty(e,t,{value:M(n[t]),configurable:!0,enumerable:!0,writable:!0}):e[t]=(r=n[t])&&typeof r=="object"?M(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=M([...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.22.7";var at=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=V(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,V(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 ct(n,t){return new at(n,t)}var lt=/ \$\$ /,At=n=>n.match(lt);function $t(n,t){return At(n)?n.replace(lt,t?` ${t} `:" "):t?`${t} ${n}`:n}var ut=/^\[(.+?)(~?=)"(.*)"\]$/;function Tt(n){return ut.test(n)?n.replace(ut,(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=="undefined"){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=ct(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,57 +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
|
-
* Run extractor on specified tokens
|
|
29
|
-
*
|
|
30
|
-
* @returns {Promise<void>}
|
|
31
|
-
*/
|
|
32
|
-
extract: (tokens: string | string[]) => Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Rerun extractor on the whole <body>, regardless of paused status or inspection limitation.
|
|
35
|
-
*
|
|
36
|
-
* @returns {Promise<void>}
|
|
37
|
-
*/
|
|
38
|
-
extractAll: () => Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Set/unset inspection callback to allow/ignore element to be extracted.
|
|
41
|
-
*
|
|
42
|
-
* @param {RuntimeInspectorCallback} [callback] - Callback to determine whether the element will be extracted.
|
|
43
|
-
*
|
|
44
|
-
* @returns {void}
|
|
45
|
-
*/
|
|
46
|
-
inspect: (callback?: RuntimeInspectorCallback) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Pause/resume/toggle the runtime.
|
|
49
|
-
*
|
|
50
|
-
* @param {boolean} [state] - False or True respectively pause or resume the runtime. Undefined parameter toggles the pause/resume state.
|
|
51
|
-
*
|
|
52
|
-
* @returns {void}
|
|
53
|
-
*/
|
|
54
|
-
toggleObserver: (state?: boolean) => void;
|
|
55
|
-
/**
|
|
56
|
-
* The UnoCSS version.
|
|
57
|
-
*
|
|
58
|
-
* @type {string}
|
|
59
|
-
*/
|
|
60
|
-
version: string;
|
|
61
|
-
};
|
|
70
|
+
__unocss_runtime?: RuntimeContext;
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
|
-
declare function init(
|
|
73
|
+
declare function init(inlineConfig?: RuntimeOptions): void;
|
|
65
74
|
|
|
66
|
-
export { RuntimeInspectorCallback, RuntimeOptions, init as default };
|
|
75
|
+
export { RuntimeContext, RuntimeInspectorCallback, RuntimeOptions, init as default };
|
package/dist/index.js
CHANGED
|
@@ -62,33 +62,41 @@ function autoPrefixer(style) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/index.ts
|
|
65
|
-
function init(
|
|
66
|
-
var _a;
|
|
65
|
+
function init(inlineConfig = {}) {
|
|
66
|
+
var _a, _b;
|
|
67
67
|
if (typeof window == "undefined") {
|
|
68
68
|
console.warn("@unocss/runtime been used in non-browser environment, skipped.");
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const config = window.__unocss || {};
|
|
72
|
+
const runtime = config == null ? void 0 : config.runtime;
|
|
73
|
+
const defaultConfig = Object.assign(inlineConfig.defaults || {}, runtime);
|
|
74
|
+
if (runtime == null ? void 0 : runtime.autoPrefix) {
|
|
75
|
+
let postprocess = defaultConfig.postprocess;
|
|
74
76
|
if (!postprocess)
|
|
75
77
|
postprocess = [];
|
|
76
78
|
if (!Array.isArray(postprocess))
|
|
77
79
|
postprocess = [postprocess];
|
|
78
80
|
postprocess.unshift(autoPrefixer(document.createElement("div").style));
|
|
79
|
-
|
|
81
|
+
defaultConfig.postprocess = postprocess;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
(_a = runtime == null ? void 0 : runtime.configResolved) == null ? void 0 : _a.call(runtime, config, defaultConfig);
|
|
82
84
|
let styleElement;
|
|
83
|
-
let paused =
|
|
85
|
+
let paused = true;
|
|
84
86
|
let inspector;
|
|
85
|
-
const uno = (0, import_core.createGenerator)(
|
|
87
|
+
const uno = (0, import_core.createGenerator)(config, defaultConfig);
|
|
86
88
|
const tokens = /* @__PURE__ */ new Set();
|
|
87
89
|
let _timer;
|
|
90
|
+
let _resolvers = [];
|
|
88
91
|
const scheduleUpdate = () => new Promise((resolve) => {
|
|
92
|
+
_resolvers.push(resolve);
|
|
89
93
|
if (_timer != null)
|
|
90
94
|
clearTimeout(_timer);
|
|
91
|
-
_timer = setTimeout(() => updateStyle().then(
|
|
95
|
+
_timer = setTimeout(() => updateStyle().then(() => {
|
|
96
|
+
const resolvers = _resolvers;
|
|
97
|
+
_resolvers = [];
|
|
98
|
+
resolvers.forEach((r) => r());
|
|
99
|
+
}), 0);
|
|
92
100
|
});
|
|
93
101
|
async function updateStyle() {
|
|
94
102
|
const result = await uno.generate(tokens);
|
|
@@ -139,7 +147,12 @@ function init(options = {}) {
|
|
|
139
147
|
extractAll();
|
|
140
148
|
observe();
|
|
141
149
|
}
|
|
142
|
-
|
|
150
|
+
function ready() {
|
|
151
|
+
execute();
|
|
152
|
+
window.addEventListener("load", execute);
|
|
153
|
+
window.addEventListener("DOMContentLoaded", execute);
|
|
154
|
+
}
|
|
155
|
+
const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
|
|
143
156
|
version: uno.version,
|
|
144
157
|
uno,
|
|
145
158
|
async extract(userTokens) {
|
|
@@ -157,11 +170,14 @@ function init(options = {}) {
|
|
|
157
170
|
paused = !paused;
|
|
158
171
|
else
|
|
159
172
|
paused = !!set;
|
|
173
|
+
if (!observing && !paused)
|
|
174
|
+
ready();
|
|
160
175
|
}
|
|
161
176
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
177
|
+
if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
|
|
178
|
+
paused = false;
|
|
179
|
+
ready();
|
|
180
|
+
}
|
|
165
181
|
}
|
|
166
182
|
module.exports = __toCommonJS(src_exports);
|
|
167
183
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -30,33 +30,41 @@ 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;
|
|
58
|
+
let _resolvers = [];
|
|
56
59
|
const scheduleUpdate = () => new Promise((resolve) => {
|
|
60
|
+
_resolvers.push(resolve);
|
|
57
61
|
if (_timer != null)
|
|
58
62
|
clearTimeout(_timer);
|
|
59
|
-
_timer = setTimeout(() => updateStyle().then(
|
|
63
|
+
_timer = setTimeout(() => updateStyle().then(() => {
|
|
64
|
+
const resolvers = _resolvers;
|
|
65
|
+
_resolvers = [];
|
|
66
|
+
resolvers.forEach((r) => r());
|
|
67
|
+
}), 0);
|
|
60
68
|
});
|
|
61
69
|
async function updateStyle() {
|
|
62
70
|
const result = await uno.generate(tokens);
|
|
@@ -107,7 +115,12 @@ 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,
|
|
113
126
|
async extract(userTokens) {
|
|
@@ -125,11 +138,14 @@ function init(options = {}) {
|
|
|
125
138
|
paused = !paused;
|
|
126
139
|
else
|
|
127
140
|
paused = !!set;
|
|
141
|
+
if (!observing && !paused)
|
|
142
|
+
ready();
|
|
128
143
|
}
|
|
129
144
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
145
|
+
if (((_b = runtime == null ? void 0 : runtime.ready) == null ? void 0 : _b.call(runtime, unoCssRuntime)) !== false) {
|
|
146
|
+
paused = false;
|
|
147
|
+
ready();
|
|
148
|
+
}
|
|
133
149
|
}
|
|
134
150
|
export {
|
|
135
151
|
init as default
|