@unocss/runtime 0.30.2 → 0.30.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/README.md +18 -0
- package/attributify.global.js +5 -5
- package/core.global.js +2 -2
- package/dist/index.js +42 -11
- package/dist/index.mjs +42 -11
- package/full.global.js +5 -5
- package/mini.global.js +3 -3
- package/package.json +5 -5
- package/uno.global.js +5 -5
package/core.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var mt=Object.defineProperty,yt=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var
|
|
2
|
-
`,
|
|
1
|
+
(()=>{var mt=Object.defineProperty,yt=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var N=(n,t,e)=>t in n?mt(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)&&N(n,e,t[e]);if(k)for(var e of k(t))Z.call(t,e)&&N(n,e,t[e]);return n},V=(n,t)=>yt(n,St(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&&k)for(var r of k(n))t.indexOf(r)<0&&Z.call(n,r)&&(e[r]=n[r]);return e};function xt(n){let t=n.length,e=-1,r,i="",s=n.charCodeAt(0);for(;++e<t;){if(r=n.charCodeAt(e),r===0){i+="\uFFFD";continue}if(r===44){i+="\\2c ";continue}if(r>=1&&r<=31||r===127||e===0&&r>=48&&r<=57||e===1&&r>=48&&r<=57&&s===45){i+=`\\${r.toString(16)} `;continue}if(e===0&&t===1&&r===45){i+=`\\${n.charAt(e)}`;continue}if(r>=128||r===45||r===95||r>=48&&r<=57||r>=65&&r<=90||r>=97&&r<=122){i+=n.charAt(e);continue}i+=`\\${n.charAt(e)}`}return i}var D=xt;function P(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=>P(t)):[n]:[P(n)]}function Ct(n){return n.filter(([t,e],r)=>{if(t.startsWith("$$"))return!1;for(let i=r-1;i>=0;i--)if(n[i][0]===t&&n[i][1]===e)return!1;return!0})}function K(n){return n==null?"":Ct(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 z(n,t){let e=n,r=t;if(Array.isArray(e)&&Array.isArray(r))return[...e,...r];if(Array.isArray(e))return[...e];let i=_({},e);return L(e)&&L(r)&&Object.keys(r).forEach(s=>{L(r[s])?s in e?i[s]=z(e[s],r[s]):Object.assign(i,{[s]:r[s]}):Object.assign(i,{[s]:r[s]})}),i}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 O(n=[]){return Array.isArray(n)?n:[n]}function j(n){return Array.from(new Set(n))}var bt=/(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-?]/,F="$$shortcut-no-merge";function tt(n=""){return bt.test(n)}function et(n){return typeof n=="function"?{match:n}:n}function G(n){return n.length===3}function rt(n){return n!=null}var B=class{_map=new Map;get(t,e){let r=this._map.get(t);if(r)return r.get(e)}getFallback(t,e,r){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.has(e)||i.set(e,r),i.get(e)}set(t,e,r){let i=this._map.get(t);return i||(i=new Map,this._map.set(t,i)),i.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(([i,s])=>t(s,e,i)))}};var nt=/([!\w+:_/-]+?)([:-])\(((?:[!\w\s:/\\,%#.$-]|\[.*?\])*?)\)/gm;function it(n){return nt.lastIndex=0,n.replace(nt,(t,e,r,i)=>i.split(/\s/g).map(s=>s.replace(/^(!?)(.*)/,`$1${e}${r}$2`)).join(" "))}var st=new Set;function ot(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 wt(n){return O(n).flatMap(t=>Array.isArray(t)?[t]:Object.entries(t))}var Ut={shortcuts:-1,default:0};function I(n={},t={}){let e=Object.assign({},t,n),r=(e.presets||[]).flatMap(O),i=[...r.filter(u=>u.enforce==="pre"),...r.filter(u=>!u.enforce),...r.filter(u=>u.enforce==="post")],s=Object.assign(Ut,...r.map(u=>u.layers),n.layers);function o(u){return j([...i.flatMap(d=>O(d[u]||[])),...O(e[u]||[])])}let a=o("extractors");a.length||a.push(H),a.sort((u,d)=>(u.order||0)-(d.order||0));let l=o("rules"),f={},h=l.length;l.forEach((u,d)=>{X(u)&&(f[u[0]]=[d,u[1],u[2]],delete l[d])});let x=v([...i.map(u=>u.theme||{}),e.theme||{}].reduce((u,d)=>z(u,d),{}));o("extendTheme").forEach(u=>u(x));let C={templates:j(i.map(u=>{var d;return O((d=u.autocomplete)==null?void 0:d.templates)}).flat()),extractors:i.map(u=>{var d;return O((d=u.autocomplete)==null?void 0:d.extractors)}).flat().sort((u,d)=>(u.order||0)-(d.order||0))};return V(_({mergeSelectors:!0,warn:!0,blocklist:[],safelist:[],sortLayers:u=>u},e),{presets:i,envMode:e.envMode||"build",shortcutsLayer:e.shortcutsLayer||"shortcuts",layers:s,theme:x,rulesSize:h,rulesDynamic:l,rulesStaticMap:f,preprocess:o("preprocess"),postprocess:o("postprocess"),preflights:o("preflights"),autocomplete:C,variants:o("variants").map(et),shortcuts:wt(o("shortcuts")),extractors:a})}var at="0.30.5";var lt=class{constructor(t={},e={}){this.userConfig=t;this.defaults=e;this.config=I(t,e)}version=at;_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 i={get original(){return t},code:t,id:e};for(let s of this.config.extractors){let o=await s.extract(i);o==null||o.forEach(a=>r.add(a))}return r}makeContext(t,e){let r={rawSelector:t,currentSelector:e[1],theme:this.config.theme,generator:this,variantHandlers:e[2],constructCSS:(...i)=>this.constructCustomCSS(r,...i),variantMatch:e};return r}async parseToken(t,e){var l;if(this.blocked.has(t))return;let r=`${t}${e?` ${e}`:""}`;if(this._cache.has(r))return this._cache.get(r);let i=t;for(let f of this.config.preprocess)i=f(t);if(this.isBlocked(i)){this.blocked.add(t),this._cache.set(r,null);return}let s=this.matchVariants(t,i);if(!s||this.isBlocked(s[1])){this.blocked.add(t),this._cache.set(r,null);return}let o=this.makeContext(t,[e||s[0],s[1],s[2],s[3]]),a=this.expandShortcut(o.currentSelector,o);if(a){let f=await this.stringifyShortcuts(o.variantMatch,o,a[0],a[1]);if(f!=null&&f.length)return this._cache.set(r,f),f}else{let f=(l=await this.parseUtil(o.variantMatch,o))==null?void 0:l.map(h=>this.stringifyUtil(h)).filter(rt);if(f!=null&&f.length)return this._cache.set(r,f),f}this._cache.set(r,null)}async generate(t="",{id:e,scope:r,preflights:i=!0,safelist:s=!0,minify:o=!1}={}){let a=typeof t=="string"?await this.applyExtractors(t,e):t;s&&this.config.safelist.forEach(p=>a.add(p));let l=o?"":`
|
|
2
|
+
`,f=new Set(["default"]),h=new Set,x=new Map;await Promise.all(Array.from(a).map(async p=>{var y;if(h.has(p))return;let g=await this.parseToken(p);if(g!=null){h.add(p);for(let S of g){let R=S[3]||"";x.has(R)||x.set(R,[]),x.get(R).push(S),(y=S[4])!=null&&y.layer&&f.add(S[4].layer)}}})),i&&this.config.preflights.forEach(p=>{p.layer&&f.add(p.layer)});let C={},u=this.config.sortLayers(Array.from(f).sort((p,g)=>{var y,S;return((y=this.config.layers[p])!=null?y:0)-((S=this.config.layers[g])!=null?S:0)||p.localeCompare(g)})),d={};if(i){let p={generator:this,theme:this.config.theme};d=Object.fromEntries(await Promise.all(u.map(async g=>{let S=(await Promise.all(this.config.preflights.filter(R=>(R.layer||"default")===g).map(async R=>await R.getCSS(p)))).filter(Boolean).join(l);return[g,S]})))}let $=p=>{if(C[p])return C[p];let g=Array.from(x).sort((y,S)=>{var R,U,M;return((R=this.parentOrders.get(y[0]))!=null?R:0)-((U=this.parentOrders.get(S[0]))!=null?U:0)||((M=y[0])==null?void 0:M.localeCompare(S[0]||""))||0}).map(([y,S])=>{let R=S.length,U=S.filter(c=>{var m;return(((m=c[4])==null?void 0:m.layer)||"default")===p}).sort((c,m)=>{var w,T,E;return c[0]-m[0]||(((w=c[4])==null?void 0:w.sort)||0)-(((T=m[4])==null?void 0:T.sort)||0)||((E=c[1])==null?void 0:E.localeCompare(m[1]||""))||0}).map(c=>{var m;return[c[1]?$t(c[1],r):c[1],c[2],!!((m=c[4])!=null&&m.noMerge)]}).map(c=>[c[0]==null?c[0]:[c[0]],c[1],c[2]]);if(!U.length)return;let M=U.reverse().map(([c,m,w],T)=>{if(!w&&c&&this.config.mergeSelectors)for(let E=T+1;E<R;E++){let A=U[E];if(A&&!A[2]&&A[0]&&A[1]===m)return A[0].push(...c),null}return c?`${[...new Set(c)].join(`,${l}`)}{${m}}`:m}).filter(Boolean).reverse().join(l);return y?`${y}{${l}${M}${l}}`:M}).filter(Boolean).join(l);return i&&(g=[d[p],g].filter(Boolean).join(l)),C[p]=!o&&g?`/* layer: ${p} */${l}${g}`:g},b=(p=u,g)=>p.filter(y=>!(g!=null&&g.includes(y))).map(y=>$(y)||"").filter(Boolean).join(l);return{get css(){return b()},layers:u,getLayers:b,getLayer:$,matched:h}}matchVariants(t,e){let r=new Set,i=[],s=e||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&&r.has(l))continue;let f=l.match(s,a);if(!!f){typeof f=="string"&&(f={matcher:f}),s=f.matcher,Array.isArray(f.parent)&&this.parentOrders.set(f.parent[0],f.parent[1]),i.push(f),r.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,r]}applyVariants(t,e=t[4],r=t[1]){let i=[...e].sort((a,l)=>(a.order||0)-(l.order||0)),s=i.reduce((a,l)=>{var f;return((f=l.body)==null?void 0:f.call(l,a))||a},t[2]),o={selector:i.reduce((a,l)=>{var f;return((f=l.selector)==null?void 0:f.call(l,a,s))||a},Tt(r)),entries:s,parent:i.reduce((a,l)=>Array.isArray(l.parent)?l.parent[0]:l.parent||a,void 0),layer:i.reduce((a,l)=>l.layer||a,void 0),sort:i.reduce((a,l)=>l.sort||a,void 0)};for(let a of this.config.postprocess)a(o);return o}constructCustomCSS(t,e,r){e=P(e);let{selector:i,entries:s,parent:o}=this.applyVariants([0,r||t.rawSelector,e,void 0,t.variantHandlers]),a=`${i}{${K(s)}}`;return o?`${o}{${a}}`:a}async parseUtil(t,e,r=!1){var h,x;let[i,s,o]=typeof t=="string"?this.matchVariants(t):t,a=this.config.rulesStaticMap[s];if(a&&a[1]&&(r||!((h=a[2])!=null&&h.internal)))return[[a[0],i,P(a[1]),a[2],o]];e.variantHandlers=o;let{rulesDynamic:l,rulesSize:f}=this.config;for(let C=f-1;C>=0;C--){let u=l[C];if(!u||((x=u[2])==null?void 0:x.internal)&&!r)continue;let[d,$,b]=u,p=s.match(d);if(!p)continue;let g=await $(p,e);if(!g)continue;if(typeof g=="string")return[[C,g,b]];let y=Q(g).filter(S=>S.length);if(y.length)return y.map(S=>[C,i,S,b,o])}}stringifyUtil(t){var C;if(!t)return;if(G(t))return[t[0],void 0,t[1],void 0,t[2]];let{selector:e,entries:r,parent:i,layer:s,sort:o}=this.applyVariants(t),a=K(r);if(!a)return;let u=(C=t[3])!=null?C:{},{layer:l,sort:f}=u,h=J(u,["layer","sort"]),x=V(_({},h),{layer:s!=null?s:l,sort:o!=null?o:f});return[t[0],e,a,i,x]}expandShortcut(t,e,r=3){if(r===0)return;let i,s;for(let o of this.config.shortcuts)if(Y(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,e)),s){i=i||o[2];break}}if(typeof s=="string"&&(s=it(s).split(/\s+/g)),!!s)return[s.flatMap(o=>{var a;return((a=this.expandShortcut(o,e,r-1))==null?void 0:a[0])||[o]}).filter(o=>o!==""),i]}async stringifyShortcuts(t,e,r,i={layer:this.config.shortcutsLayer}){var f;let s=new B,o=(await Promise.all(j(r).map(async h=>{let x=await this.parseUtil(h,e,!0);return x||ot(`unmatched utility "${h}" in shortcut "${t[1]}"`),x||[]}))).flat(1).filter(Boolean).sort((h,x)=>h[0]-x[0]),[a,,l]=t;for(let h of o){if(G(h))continue;let{selector:x,entries:C,parent:u,sort:d}=this.applyVariants(h,[...h[4],...l],a);s.getFallback(x,u,[[],h[0]])[0].push([C,!!((f=h[3])!=null&&f.noMerge),d!=null?d:0])}return s.map(([h,x],C,u)=>{let d=(b,p,g)=>{let y=Math.max(...g.map(R=>R[1])),S=g.map(R=>R[0]);return(b?[S.flat(1)]:S).map(R=>{let U=K(R);if(U)return[x,C,U,u,V(_({},i),{noMerge:p,sort:y})]})};return[[h.filter(([,b])=>b).map(([b,,p])=>[b,p]),!0],[h.filter(([,b])=>!b).map(([b,,p])=>[b,p]),!1]].map(([b,p])=>[...d(!1,p,b.filter(([g])=>g.some(y=>y[0]===F))),...d(!0,p,b.filter(([g])=>g.every(y=>y[0]!==F)))])}).flat(2).filter(Boolean)}isBlocked(t){return!t||this.config.blocklist.some(e=>typeof e=="string"?e===t:e.test(t))}};function ut(n,t){return new lt(n,t)}var ft=/ \$\$ /,At=n=>n.match(ft);function $t(n,t){return At(n)?n.replace(ft,t?` ${t} `:" "):t?`${t} ${n}`:n}var ct=/^\[(.+?)(~?=)"(.*)"\]$/;function Tt(n){return ct.test(n)?n.replace(ct,(t,e,r,i)=>`[${D(e)}${r}"${D(i)}"]`):`.${D(n)}`}var Mt=n=>n.replace(/-(\w)/g,(t,e)=>e?e.toUpperCase():""),pt=n=>n.charAt(0).toUpperCase()+n.slice(1),dt=n=>n.replace(/(?:^|\B)([A-Z])/g,"-$1").toLowerCase(),gt=["Webkit","Moz","ms"];function ht(n){let t={};function e(r){let i=t[r];if(i)return i;let s=Mt(r);if(s!=="filter"&&s in n)return t[r]=dt(s);s=pt(s);for(let o=0;o<gt.length;o++){let a=`${gt[o]}${s}`;if(a in n)return t[r]=dt(pt(a))}return r}return({entries:r})=>r.forEach(i=>{i[0].startsWith("--")||(i[0]=e(i[0]))})}function q(n={}){var U,M;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&&e.autoPrefix){let c=r.postprocess;c||(c=[]),Array.isArray(c)||(c=[c]),c.unshift(ht(document.createElement("div").style)),r.postprocess=c}(U=e==null?void 0:e.configResolved)==null||U.call(e,t,r);let i,s=!0,o,a=ut(t,r),l=new Set,f,h=[],x=()=>new Promise(c=>{h.push(c),f!=null&&clearTimeout(f),f=setTimeout(()=>u().then(()=>{let m=h;h=[],m.forEach(w=>w())}),0)});function C(c=document.body){if(c.nodeType!==1)return;let m=c;m.hasAttribute("un-cloak")&&m.removeAttribute("un-cloak"),m.querySelectorAll("[un-cloak]").forEach(w=>{w.removeAttribute("un-cloak")})}async function u(){let c=await a.generate(l);i||(i=document.createElement("style"),document.documentElement.prepend(i)),i.innerHTML=c.css,l=c.matched}async function d(c){let m=l.size;await a.applyExtractors(c,void 0,l),m!==l.size&&await x()}async function $(){let c=document.body&&document.body.outerHTML;c&&(await d(c),C())}let b=new MutationObserver(c=>{s||c.forEach(async m=>{if(m.target.nodeType!==1)return;let w=m.target;if(w!==i)if(m.type==="childList")m.addedNodes.forEach(async T=>{if(T.nodeType!==1)return;let E=T;o&&!o(E)||(await d(E.outerHTML),C(E))});else{if(o&&!o(w))return;if(m.attributeName!=="un-cloak"){let T=Array.from(w.attributes).map(A=>A.value?`${A.name}="${A.value}"`:A.name).join(" "),E=`<${w.tagName.toLowerCase()} ${T}>`;await d(E)}w.hasAttribute("un-cloak")&&w.removeAttribute("un-cloak")}})}),p=!1;function g(){if(p)return;let c=document.documentElement||document.body;!c||(b.observe(c,{childList:!0,subtree:!0,attributes:!0}),p=!0)}function y(){$(),g()}function S(){document.readyState==="loading"?window.addEventListener("DOMContentLoaded",y):y()}let R=window.__unocss_runtime=window.__unocss_runtime={version:a.version,uno:a,async extract(c){typeof c!="string"&&(c.forEach(m=>l.add(m)),c=""),await d(c)},extractAll:$,inspect(c){o=c},toggleObserver(c){c===void 0?s=!s:s=!!c,!p&&!s&&S()}};((M=e==null?void 0:e.ready)==null?void 0:M.call(e,R))!==!1&&(s=!1,S())}q();})();
|
package/dist/index.js
CHANGED
|
@@ -89,6 +89,16 @@ function init(inlineConfig = {}) {
|
|
|
89
89
|
resolvers.forEach((r) => r());
|
|
90
90
|
}), 0);
|
|
91
91
|
});
|
|
92
|
+
function removeCloak(node = document.body) {
|
|
93
|
+
if (node.nodeType !== 1)
|
|
94
|
+
return;
|
|
95
|
+
const el = node;
|
|
96
|
+
if (el.hasAttribute("un-cloak"))
|
|
97
|
+
el.removeAttribute("un-cloak");
|
|
98
|
+
el.querySelectorAll("[un-cloak]").forEach((n) => {
|
|
99
|
+
n.removeAttribute("un-cloak");
|
|
100
|
+
});
|
|
101
|
+
}
|
|
92
102
|
async function updateStyle() {
|
|
93
103
|
const result = await uno.generate(tokens);
|
|
94
104
|
if (!styleElement) {
|
|
@@ -106,26 +116,46 @@ function init(inlineConfig = {}) {
|
|
|
106
116
|
}
|
|
107
117
|
async function extractAll() {
|
|
108
118
|
const html = document.body && document.body.outerHTML;
|
|
109
|
-
if (html)
|
|
119
|
+
if (html) {
|
|
110
120
|
await extract(html);
|
|
121
|
+
removeCloak();
|
|
122
|
+
}
|
|
111
123
|
}
|
|
112
124
|
const mutationObserver = new MutationObserver((mutations) => {
|
|
113
125
|
if (paused)
|
|
114
126
|
return;
|
|
115
|
-
mutations.forEach((mutation) => {
|
|
127
|
+
mutations.forEach(async (mutation) => {
|
|
128
|
+
if (mutation.target.nodeType !== 1)
|
|
129
|
+
return;
|
|
116
130
|
const target = mutation.target;
|
|
117
131
|
if (target === styleElement)
|
|
118
132
|
return;
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
133
|
+
if (mutation.type === "childList") {
|
|
134
|
+
mutation.addedNodes.forEach(async (node) => {
|
|
135
|
+
if (node.nodeType !== 1)
|
|
136
|
+
return;
|
|
137
|
+
const el = node;
|
|
138
|
+
if (inspector && !inspector(el))
|
|
139
|
+
return;
|
|
140
|
+
await extract(el.outerHTML);
|
|
141
|
+
removeCloak(el);
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
if (inspector && !inspector(target))
|
|
145
|
+
return;
|
|
146
|
+
if (mutation.attributeName !== "un-cloak") {
|
|
147
|
+
const attrs = Array.from(target.attributes).map((i) => i.value ? `${i.name}="${i.value}"` : i.name).join(" ");
|
|
148
|
+
const tag = `<${target.tagName.toLowerCase()} ${attrs}>`;
|
|
149
|
+
await extract(tag);
|
|
150
|
+
}
|
|
151
|
+
if (target.hasAttribute("un-cloak"))
|
|
152
|
+
target.removeAttribute("un-cloak");
|
|
153
|
+
}
|
|
124
154
|
});
|
|
125
155
|
});
|
|
126
156
|
let observing = false;
|
|
127
157
|
function observe() {
|
|
128
|
-
if (
|
|
158
|
+
if (observing)
|
|
129
159
|
return;
|
|
130
160
|
const target = document.documentElement || document.body;
|
|
131
161
|
if (!target)
|
|
@@ -142,9 +172,10 @@ function init(inlineConfig = {}) {
|
|
|
142
172
|
observe();
|
|
143
173
|
}
|
|
144
174
|
function ready() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
175
|
+
if (document.readyState === "loading")
|
|
176
|
+
window.addEventListener("DOMContentLoaded", execute);
|
|
177
|
+
else
|
|
178
|
+
execute();
|
|
148
179
|
}
|
|
149
180
|
const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
|
|
150
181
|
version: uno.version,
|
package/dist/index.mjs
CHANGED
|
@@ -66,6 +66,16 @@ function init(inlineConfig = {}) {
|
|
|
66
66
|
resolvers.forEach((r) => r());
|
|
67
67
|
}), 0);
|
|
68
68
|
});
|
|
69
|
+
function removeCloak(node = document.body) {
|
|
70
|
+
if (node.nodeType !== 1)
|
|
71
|
+
return;
|
|
72
|
+
const el = node;
|
|
73
|
+
if (el.hasAttribute("un-cloak"))
|
|
74
|
+
el.removeAttribute("un-cloak");
|
|
75
|
+
el.querySelectorAll("[un-cloak]").forEach((n) => {
|
|
76
|
+
n.removeAttribute("un-cloak");
|
|
77
|
+
});
|
|
78
|
+
}
|
|
69
79
|
async function updateStyle() {
|
|
70
80
|
const result = await uno.generate(tokens);
|
|
71
81
|
if (!styleElement) {
|
|
@@ -83,26 +93,46 @@ function init(inlineConfig = {}) {
|
|
|
83
93
|
}
|
|
84
94
|
async function extractAll() {
|
|
85
95
|
const html = document.body && document.body.outerHTML;
|
|
86
|
-
if (html)
|
|
96
|
+
if (html) {
|
|
87
97
|
await extract(html);
|
|
98
|
+
removeCloak();
|
|
99
|
+
}
|
|
88
100
|
}
|
|
89
101
|
const mutationObserver = new MutationObserver((mutations) => {
|
|
90
102
|
if (paused)
|
|
91
103
|
return;
|
|
92
|
-
mutations.forEach((mutation) => {
|
|
104
|
+
mutations.forEach(async (mutation) => {
|
|
105
|
+
if (mutation.target.nodeType !== 1)
|
|
106
|
+
return;
|
|
93
107
|
const target = mutation.target;
|
|
94
108
|
if (target === styleElement)
|
|
95
109
|
return;
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
110
|
+
if (mutation.type === "childList") {
|
|
111
|
+
mutation.addedNodes.forEach(async (node) => {
|
|
112
|
+
if (node.nodeType !== 1)
|
|
113
|
+
return;
|
|
114
|
+
const el = node;
|
|
115
|
+
if (inspector && !inspector(el))
|
|
116
|
+
return;
|
|
117
|
+
await extract(el.outerHTML);
|
|
118
|
+
removeCloak(el);
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
if (inspector && !inspector(target))
|
|
122
|
+
return;
|
|
123
|
+
if (mutation.attributeName !== "un-cloak") {
|
|
124
|
+
const attrs = Array.from(target.attributes).map((i) => i.value ? `${i.name}="${i.value}"` : i.name).join(" ");
|
|
125
|
+
const tag = `<${target.tagName.toLowerCase()} ${attrs}>`;
|
|
126
|
+
await extract(tag);
|
|
127
|
+
}
|
|
128
|
+
if (target.hasAttribute("un-cloak"))
|
|
129
|
+
target.removeAttribute("un-cloak");
|
|
130
|
+
}
|
|
101
131
|
});
|
|
102
132
|
});
|
|
103
133
|
let observing = false;
|
|
104
134
|
function observe() {
|
|
105
|
-
if (
|
|
135
|
+
if (observing)
|
|
106
136
|
return;
|
|
107
137
|
const target = document.documentElement || document.body;
|
|
108
138
|
if (!target)
|
|
@@ -119,9 +149,10 @@ function init(inlineConfig = {}) {
|
|
|
119
149
|
observe();
|
|
120
150
|
}
|
|
121
151
|
function ready() {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
152
|
+
if (document.readyState === "loading")
|
|
153
|
+
window.addEventListener("DOMContentLoaded", execute);
|
|
154
|
+
else
|
|
155
|
+
execute();
|
|
125
156
|
}
|
|
126
157
|
const unoCssRuntime = window.__unocss_runtime = window.__unocss_runtime = {
|
|
127
158
|
version: uno.version,
|