@master/css-runtime 2.0.0-rc.4 → 2.0.0-rc.41

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.
@@ -1 +0,0 @@
1
- "use strict";var v=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var N=(f,d)=>{for(var c in d)v(f,c,{get:d[c],enumerable:!0})},L=(f,d,c,h)=>{if(d&&typeof d=="object"||typeof d=="function")for(let s of T(d))!w.call(f,s)&&s!==c&&v(f,s,{get:()=>d[s],enumerable:!(h=E(d,s))||h.enumerable});return f};var M=f=>L(v({},"__esModule",{value:!0}),f);var j={};N(j,{CSSRuntime:()=>m,default:()=>m,initCSSRuntime:()=>O});module.exports=M(j);var g=require("@master/css");var m=class extends g.MasterCSS{constructor(c=document,h=g.config){super(h);this.root=c;this.customConfig=h;c||(this.root=document),this.root===document?(globalThis.cssRuntime=this,this.container=document.head,this.host=document.documentElement):(this.container=this.root,this.host=this.root.host),C.push(this)}host;observing=!1;container;observer;observe(c={subtree:!0,childList:!0}){if(this.observing||!this.root)return this;if(C.find(s=>s!==this&&s.root===this.root))return console.warn("Cannot observe the same root element repeatedly."),this;if(this.root?.styleSheets)for(let s of this.root.styleSheets){let{ownerNode:t}=s;if(t&&t.id==="master"){this.style=t;break}}if(this.style?.sheet){let s=0;for(;s<this.style.sheet.cssRules.length;s++){let t=this.style.sheet.cssRules[s];switch(t.constructor.name){case"CSSKeyframesRule":continue;case"CSSMeidaRule":if(this.config.themeDriver==="media"){let o=/\(prefers-color-scheme: (.*?)\)/.exec(t.conditionText);if(o){let r=t.cssRules[0];if(r?.constructor.name==="CSSStyleRule"&&r.selectorText===":root"){this.pushVariableNativeRule(o[1],r);continue}}}break;case"CSSStyleRule":let l=t.selectorText;if(t.style.length){let o=!0;for(let r=0;r<t.style.length;r++)if(!t.style[r]?.startsWith("--")){o=!1;break}if(o){if(l===":root"){this.pushVariableNativeRule("",t);continue}else if(this.config.themeDriver==="host"){let r=/:host(.*?)/.exec(l);if(r){this.pushVariableNativeRule(r[1],t);continue}}else if(!l.startsWith(".\\$")){this.pushVariableNativeRule(l.slice(1),t);continue}}}break}break}for(;s<this.style.sheet.cssRules.length;s++){let t=o=>{if(o.selectorText){let S=o.selectorText.split(", ")[0].split(" ");for(let p=0;p<S.length;p++){let R=S[p];if(R[0]==="."){let b=R.slice(1),e="";for(let i=0;i<b.length;i++){let a=b[i],n=b[i+1];if(a==="\\"){if(i++,n!=="\\"){e+=n;continue}}else if([",",".","#","[","!","*",">","+","~",":","@"].includes(a))break;e+=a}if(!Object.prototype.hasOwnProperty.call(this.ruleBy,e)&&!Object.prototype.hasOwnProperty.call(this.styles,e)){let i=this.generate(e)[0];if(i)return i}}}}else if(o.cssRules)for(let r=0;r<o.cssRules.length;r++){let S=t(o.cssRules[r]);if(S)return S}},l=t(this.style.sheet.cssRules[s]);if(l){this.rules.push(l),this.ruleBy[l.className]=l;for(let o=0;o<l.natives.length;o++)l.natives[o].cssRule=this.style.sheet.cssRules[s+o];s+=l.natives.length-1,this.handleRuleWithVariableNames(l,!0),this.handleRuleWithAnimationNames(l,!0),l.definition.insert?.call(l)}}}else this.style=document.createElement("style"),this.style.id="master",this.container.append(this.style);let h=s=>{s.forEach(t=>{Object.prototype.hasOwnProperty.call(this.classesUsage,t)?this.classesUsage[t]++:(this.classesUsage[t]=1,this.add(t))})};return h(this.host.classList),c.subtree&&this.host.querySelectorAll("[class]").forEach(s=>h(s.classList)),this.observer=new MutationObserver(s=>{let t={},l=[],o=[],r=[],S=(e,i)=>{i?e.classList.forEach(R):e.classList.forEach(p);let a=e.children;for(let n=0;n<a.length;n++){let y=a[n];y.classList&&(o.push(y),S(y,i))}},p=e=>{Object.prototype.hasOwnProperty.call(t,e)?t[e]++:t[e]=1},R=e=>{Object.prototype.hasOwnProperty.call(t,e)?t[e]--:Object.prototype.hasOwnProperty.call(this.classesUsage,e)&&(t[e]=-1)},b=(e,i)=>{for(let a=0;a<e.length;a++){let n=e[a];n.classList&&!o.includes(n)&&!r.includes(n)&&(n.isConnected!==i?(o.push(n),S(n,i)):r.push(n))}};for(let e=0;e<s.length;e++){let i=s[e],{addedNodes:a,removedNodes:n,type:y,target:u}=i;if(y==="attributes"){if(l.find(x=>x.target===u))continue;l.push(i)}else b(a,!1),(!u.isConnected||!o.includes(u))&&b(n,!0)}if(!(!l.length&&!Object.keys(t).length)){for(let{oldValue:e,target:i}of l){let a=o.includes(i),n=i.classList,y=e?e.split(" "):[];if(a){if(i.isConnected)continue;for(let u of y)n.contains(u)||R(u)}else if(i.isConnected){n.forEach(u=>{y.includes(u)||p(u)});for(let u of y)n.contains(u)||R(u)}}for(let e in t){let i=t[e],a=(this.classesUsage[e]||0)+i;a===0?(delete this.classesUsage[e],this.delete(e)):(Object.prototype.hasOwnProperty.call(this.classesUsage,e)||this.add(e),this.classesUsage[e]=a)}}}),this.observer.observe(this.root,{...c,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]}),this.host.style.removeProperty("display"),this.observing=!0,this}refresh(c=this.customConfig){let h=document.createElement("style");return h.id="master",this.style.replaceWith(h),this.style=h,super.refresh(c),this}reset(){super.reset();let c=this.style?.sheet;if(c?.cssRules)for(let h=c.cssRules.length-1;h>=0;h--)c.deleteRule(h);return this.style?.remove(),this.style=null,this}disconnect(){return this.observer&&(this.observer.disconnect(),this.observer=null),this.observing=!1,this.reset(),this}destroy(){return this.disconnect(),C.splice(C.indexOf(this),1),this}},C=[];globalThis.CSSRuntime=m,globalThis.cssRuntimes=C;function O(f){return new m(document,f).observe()}
@@ -1 +0,0 @@
1
- import{MasterCSS as v,config as O}from"@master/css";var y=class extends v{constructor(u=document,c=O){super(c);this.root=u;this.customConfig=c;u||(this.root=document),this.root===document?(globalThis.cssRuntime=this,this.container=document.head,this.host=document.documentElement):(this.container=this.root,this.host=this.root.host),R.push(this)}host;observing=!1;container;observer;observe(u={subtree:!0,childList:!0}){if(this.observing||!this.root)return this;if(R.find(l=>l!==this&&l.root===this.root))return console.warn("Cannot observe the same root element repeatedly."),this;if(this.root?.styleSheets)for(let l of this.root.styleSheets){let{ownerNode:t}=l;if(t&&t.id==="master"){this.style=t;break}}if(this.style?.sheet){let l=0;for(;l<this.style.sheet.cssRules.length;l++){let t=this.style.sheet.cssRules[l];switch(t.constructor.name){case"CSSKeyframesRule":continue;case"CSSMeidaRule":if(this.config.themeDriver==="media"){let i=/\(prefers-color-scheme: (.*?)\)/.exec(t.conditionText);if(i){let r=t.cssRules[0];if(r?.constructor.name==="CSSStyleRule"&&r.selectorText===":root"){this.pushVariableNativeRule(i[1],r);continue}}}break;case"CSSStyleRule":let o=t.selectorText;if(t.style.length){let i=!0;for(let r=0;r<t.style.length;r++)if(!t.style[r]?.startsWith("--")){i=!1;break}if(i){if(o===":root"){this.pushVariableNativeRule("",t);continue}else if(this.config.themeDriver==="host"){let r=/:host(.*?)/.exec(o);if(r){this.pushVariableNativeRule(r[1],t);continue}}else if(!o.startsWith(".\\$")){this.pushVariableNativeRule(o.slice(1),t);continue}}}break}break}for(;l<this.style.sheet.cssRules.length;l++){let t=i=>{if(i.selectorText){let d=i.selectorText.split(", ")[0].split(" ");for(let S=0;S<d.length;S++){let m=d[S];if(m[0]==="."){let p=m.slice(1),e="";for(let s=0;s<p.length;s++){let a=p[s],n=p[s+1];if(a==="\\"){if(s++,n!=="\\"){e+=n;continue}}else if([",",".","#","[","!","*",">","+","~",":","@"].includes(a))break;e+=a}if(!Object.prototype.hasOwnProperty.call(this.ruleBy,e)&&!Object.prototype.hasOwnProperty.call(this.styles,e)){let s=this.generate(e)[0];if(s)return s}}}}else if(i.cssRules)for(let r=0;r<i.cssRules.length;r++){let d=t(i.cssRules[r]);if(d)return d}},o=t(this.style.sheet.cssRules[l]);if(o){this.rules.push(o),this.ruleBy[o.className]=o;for(let i=0;i<o.natives.length;i++)o.natives[i].cssRule=this.style.sheet.cssRules[l+i];l+=o.natives.length-1,this.handleRuleWithVariableNames(o,!0),this.handleRuleWithAnimationNames(o,!0),o.definition.insert?.call(o)}}}else this.style=document.createElement("style"),this.style.id="master",this.container.append(this.style);let c=l=>{l.forEach(t=>{Object.prototype.hasOwnProperty.call(this.classesUsage,t)?this.classesUsage[t]++:(this.classesUsage[t]=1,this.add(t))})};return c(this.host.classList),u.subtree&&this.host.querySelectorAll("[class]").forEach(l=>c(l.classList)),this.observer=new MutationObserver(l=>{let t={},o=[],i=[],r=[],d=(e,s)=>{s?e.classList.forEach(m):e.classList.forEach(S);let a=e.children;for(let n=0;n<a.length;n++){let f=a[n];f.classList&&(i.push(f),d(f,s))}},S=e=>{Object.prototype.hasOwnProperty.call(t,e)?t[e]++:t[e]=1},m=e=>{Object.prototype.hasOwnProperty.call(t,e)?t[e]--:Object.prototype.hasOwnProperty.call(this.classesUsage,e)&&(t[e]=-1)},p=(e,s)=>{for(let a=0;a<e.length;a++){let n=e[a];n.classList&&!i.includes(n)&&!r.includes(n)&&(n.isConnected!==s?(i.push(n),d(n,s)):r.push(n))}};for(let e=0;e<l.length;e++){let s=l[e],{addedNodes:a,removedNodes:n,type:f,target:h}=s;if(f==="attributes"){if(o.find(g=>g.target===h))continue;o.push(s)}else p(a,!1),(!h.isConnected||!i.includes(h))&&p(n,!0)}if(!(!o.length&&!Object.keys(t).length)){for(let{oldValue:e,target:s}of o){let a=i.includes(s),n=s.classList,f=e?e.split(" "):[];if(a){if(s.isConnected)continue;for(let h of f)n.contains(h)||m(h)}else if(s.isConnected){n.forEach(h=>{f.includes(h)||S(h)});for(let h of f)n.contains(h)||m(h)}}for(let e in t){let s=t[e],a=(this.classesUsage[e]||0)+s;a===0?(delete this.classesUsage[e],this.delete(e)):(Object.prototype.hasOwnProperty.call(this.classesUsage,e)||this.add(e),this.classesUsage[e]=a)}}}),this.observer.observe(this.root,{...u,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]}),this.host.style.removeProperty("display"),this.observing=!0,this}refresh(u=this.customConfig){let c=document.createElement("style");return c.id="master",this.style.replaceWith(c),this.style=c,super.refresh(u),this}reset(){super.reset();let u=this.style?.sheet;if(u?.cssRules)for(let c=u.cssRules.length-1;c>=0;c--)u.deleteRule(c);return this.style?.remove(),this.style=null,this}disconnect(){return this.observer&&(this.observer.disconnect(),this.observer=null),this.observing=!1,this.reset(),this}destroy(){return this.disconnect(),R.splice(R.indexOf(this),1),this}},R=[];globalThis.CSSRuntime=y,globalThis.cssRuntimes=R;function C(b){return new y(document,b).observe()}export{y as CSSRuntime,y as default,C as initCSSRuntime};
File without changes