@master/css 2.0.0-beta.124 → 2.0.0-beta.126
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/dist/cjs/config/index.js +1 -1
- package/dist/cjs/css.js +1 -1
- package/dist/cjs/index.browser.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/methods/index.js +1 -1
- package/dist/cjs/theme.js +1 -1
- package/dist/config/index.d.ts +1 -4
- package/dist/css.d.ts +0 -2
- package/dist/esm/config/index.js +1 -1
- package/dist/esm/css.js +1 -1
- package/dist/esm/index.browser.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/methods/index.js +1 -1
- package/dist/esm/theme.js +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +5 -5
- package/dist/index.mjs +6 -6
- package/dist/methods/index.d.ts +0 -1
- package/dist/theme.d.ts +21 -14
- package/package.json +1 -1
- package/dist/cjs/config/theme.js +0 -1
- package/dist/cjs/methods/get-sync-with-stored-theme-script.js +0 -1
- package/dist/config/theme.d.ts +0 -2
- package/dist/esm/config/theme.js +0 -1
- package/dist/esm/methods/get-sync-with-stored-theme-script.js +0 -1
- package/dist/methods/get-sync-with-stored-theme-script.d.ts +0 -1
package/dist/cjs/config/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty;var
|
|
1
|
+
var t=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var o in e)t(r,o,{get:e[o],enumerable:!0})},B=(r,e,o,k)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of b(e))!S.call(r,s)&&s!==o&&t(r,s,{get:()=>e[s],enumerable:!(k=C(e,s))||k.enumerable});return r};var v=r=>B(t({},"__esModule",{value:!0}),r);var R={};d(R,{breakpoints:()=>i.breakpoints,colors:()=>n.colors,config:()=>Q,important:()=>y.important,observe:()=>u.observe,override:()=>f.override,rootSize:()=>m.rootSize,rules:()=>g.rules,scope:()=>a.scope,selectors:()=>p.selectors,semantics:()=>l.semantics,themes:()=>c.themes});module.exports=v(R);var i=require("./breakpoints"),n=require("./colors"),m=require("./root-size"),a=require("./scope"),p=require("./selectors"),l=require("./semantics"),c=require("./themes"),g=require("./rules"),f=require("./override"),u=require("./observe"),y=require("./important"),Q={breakpoints:i.breakpoints,colors:n.colors,rootSize:m.rootSize,scope:a.scope,selectors:p.selectors,semantics:l.semantics,themes:c.themes,rules:g.rules,override:f.override,observe:u.observe,important:y.important};0&&(module.exports={breakpoints,colors,config,important,observe,override,rootSize,rules,scope,selectors,semantics,themes});
|
package/dist/cjs/css.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var A=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var P=(y,e,t)=>e in y?A(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t;var U=(y,e)=>{for(var t in e)A(y,t,{get:e[t],enumerable:!0})},Y=(y,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of q(e))!Z.call(y,a)&&a!==t&&A(y,a,{get:()=>e[a],enumerable:!(s=_(e,a))||s.enumerable});return y};var G=y=>Y(A({},"__esModule",{value:!0}),y);var S=(y,e,t)=>(P(y,typeof e!="symbol"?e+"":e,t),t);var J={};U(J,{MasterCSS:()=>W});module.exports=G(J);function I(y){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&y instanceof e||y instanceof Date||y instanceof RegExp)}function B(y){if(typeof Buffer<"u"&&Buffer&&y instanceof Buffer){let e=Buffer.alloc(y.length);return y.copy(e),e}else{if(y instanceof Date)return new Date(y.getTime());if(y instanceof RegExp)return new RegExp(y);throw new Error("Unexpected situation")}}function V(y){let e=[];return y.forEach(function(t,s){typeof t=="object"&&t!==null?Array.isArray(t)?e[s]=V(t):I(t)?e[s]=B(t):e[s]=k({},t):e[s]=t}),e}function N(y,e){return e==="__proto__"?void 0:y[e]}function k(...y){let e={},t,s;return y.forEach(function(a){typeof a!="object"||a===null||Array.isArray(a)||Object.keys(a).forEach(function(C){if(s=N(e,C),t=N(a,C),t!==e)if(typeof t!="object"||t===null){e[C]=t;return}else if(Array.isArray(t)){e[C]=V(t);return}else if(I(t)){e[C]=B(t);return}else if(typeof s!="object"||s===null||Array.isArray(s)){e[C]=k({},t);return}else{e[C]=k(s,t);return}})}),e}var $=require("./rule"),F=require("./config"),D=require("./theme"),H=require("./utils/rgb-to-hex"),Q=require("./constants/selector-symbols");var L=typeof window<"u",j=class{constructor(e){this.config=e;this.config?.override||(this.config=k(F.config,e)),this.cache(),L&&this.config.observe&&this.observe(document),j.instances.push(this),this.ready=!0}rules=[];ruleOfClass={};countOfClass={};ready=!1;e=L?new MutationObserver(e=>{let t={},s=[],a=[],C=[],w=(c,n)=>{n?c.classList.forEach(b):c.classList.forEach(g);let l=c.children;for(let m=0;m<l.length;m++){let u=l[m];u.classList&&(a.push(u),w(u,n))}},g=c=>{c in t?t[c]++:t[c]=1},b=c=>{c in t?t[c]--:c in this.countOfClass&&(t[c]=-1)},O=(c,n)=>{for(let l=0;l<c.length;l++){let m=c[l];m.classList&&!a.includes(m)&&!C.includes(m)&&(m.isConnected!==n?(a.push(m),w(m,n)):C.push(m))}};for(let c=0;c<e.length;c++){let n=e[c],{addedNodes:l,removedNodes:m,type:u,target:f}=n;if(u==="attributes"){if(s.find(v=>v.target===f))continue;s.push(n)}else O(l,!1),(!f.isConnected||!a.includes(f))&&O(m,!0)}if(!(!s.length&&!Object.keys(t).length)){for(let{oldValue:c,target:n}of s){let l=a.includes(n),m=n.classList,u=c?c.split(" "):[];if(l){if(n.isConnected)continue;for(let f of u)m.contains(f)||b(f)}else if(n.isConnected){m.forEach(f=>{u.includes(f)||g(f)});for(let f of u)m.contains(f)||b(f)}}for(let c in t){let n=t[c],l=(this.countOfClass[c]||0)+n;l===0?(delete this.countOfClass[c],this.delete(c)):(c in this.countOfClass||this.insert(c),this.countOfClass[c]=l)}}}):null;cache(){this.semantics=[],this.classes={},this.colorThemesMap={},this.relationThemesMap={},this.relations={},this.colorNames=[],this.themeNames=[""],this.selectors={},this.values={},this.globalValues={},this.breakpoints={},this.mediaQueries={},this.matches={};let{semantics:e,classes:t,selectors:s,themes:a,colors:C,values:w,breakpoints:g,mediaQueries:b,rules:O}=this.config;function c(r){return r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function n(r,o,i="",d={}){let h=x=>x?(i?i+"-":"")+x:i,R=Object.entries(r),p=[],T=[];for(let x of R){let E=x[1];(typeof E=="object"&&!Array.isArray(E)?p:T).push(x)}for(let[x,E]of p)n(E,o,h(x),d);if(o&&i)T.length&&(d[i]=T.reduce((x,[E,z])=>(x[E]=z,x),{}));else for(let[x,E]of T)d[h(x)]=E;return d}if(e)for(let[r,o]of Object.entries(n(e,!0)))this.semantics.push([new RegExp("^"+c(r)+"(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)","m"),[r,o]]);if(s)for(let[r,o]of Object.entries(n(s,!1))){let i=new RegExp(c(r)+"(?![a-z-])");for(let d of Array.isArray(o)?o:[o]){let h=d.match(/^::-[a-z]+-/m)?.[0]??"",R=this.selectors[h];R||(R=this.selectors[h]=[]);let p=R.find(([T])=>T===i);p||(p=[i,[]],R.push(p)),p[1].push(d)}}w&&(this.globalValues=n(w,!1)),g&&(this.breakpoints=n(g,!1)),b&&(this.mediaQueries=n(b,!1));let l=t?n(t,!1):{},m=a&&!Array.isArray(a)?Object.entries(a).filter(([,{classes:r}])=>r).reduce((r,[o,{classes:i}])=>(r[o]=n(i,!1),r),{}):{},u=[...Object.keys(l),...Object.entries(m).flatMap(([r,o])=>Object.keys(o))],f=r=>{if(r in this.classes)return;let o=this.classes[r]=[],i=(d,h)=>{if(!h)return;let R=Array.isArray(h)?h:h.replace(/(?:\n(?:\s*))+/g," ").trim().split(" ");for(let p of R){let T=x=>{x in this.relationThemesMap?d in this.relationThemesMap[x]?this.relationThemesMap[x][d].push(r):this.relationThemesMap[x][d]=[r]:this.relationThemesMap[x]={[d]:[r]},o.includes(x)||o.push(x)};if(u.includes(p)){f(p);for(let x of this.classes[p])T(x)}else T(p)}};i("",l?.[r]);for(let[d,h]of Object.entries(m))i(d,h?.[r])};for(let r of u)f(r);for(let r in this.relationThemesMap){let o=this.relations[r]=[];for(let i of Object.values(this.relationThemesMap[r]))for(let d of i)o.includes(d)||o.push(d)}let v=(r,o)=>{if(!o)return;let i=n(o,!0);for(let[d,h]of Object.entries(i)){let R=typeof h=="string"?{"":h}:h;for(let[p,T]of Object.entries(R)){let x=d+(p?"-"+p:"");x in this.colorThemesMap?this.colorThemesMap[x][r]=T:this.colorThemesMap[x]={[r]:T}}}for(let d in o)this.colorNames.includes(d)||this.colorNames.push(d)};if(v("",C),a)if(Array.isArray(a))this.themeNames.push(...a);else for(let r in a){let o=a[r];v(r,o.colors),this.themeNames.push(r)}let M=r=>{for(let[o,i]of Object.entries(this.colorThemesMap))for(let[d,h]of Object.entries(i))h.startsWith("#")||r(o,i,d,h)};if(M((r,o,i,d)=>{let h=/^rgba?\( *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?:(?:\/|,) *0?(\.[0-9]))?\)$/.exec(d);if(h){let R="#"+(0,H.rgbToHex)(+h[1],+h[2],+h[3]);h[4]&&(R+=Math.round(255*+h[4]).toString(16)),o[i]=R}}),M((r,o,i,d)=>{let[h,R]=d.split("/"),p=this.colorThemesMap[h];if(p){let T=(i?p[i]:void 0)??p[""];o[i]=R?T.slice(0,7)+Math.round(255*+R).toString(16):T}else console.warn(`\`${d}\` doesn't exist in the extended config \`.colors\``),delete o[i],Object.keys(o).length||delete this.colorThemesMap[r]}),O)for(let r in O){let o=O[r],{matches:i,prop:d,values:h}=o;if(o.id=r,o.prop=d===!1?"":r.replace(/(?!^)[A-Z]/g,R=>"-"+R).toLowerCase(),h&&(this.values[r]=n(h,!1)),i){let R=Object.keys(this.values[r]??{}),p=i.indexOf("$values");this.matches[r]=new RegExp(p===-1?i:R.length?i.slice(0,p)+R.join("|")+i.slice(p+7):i.slice(0,p-(i[p-1]==="|"?1:0))+i.slice(p+7+(i[p+7]==="|"?1:0)))}}}observe(e,t={subtree:!0,childList:!0}){if(L&&e){this.root=e;let s=e===document;s&&(j.root=this),this.host=s?document.documentElement:root.host,this.theme=new D.Theme(this.host,this.config.theme);let a=s?document.head:e,C=s?document.styleSheets:e.styleSheets;for(let g of C){let{title:b,href:O,ownerNode:c}=g;(b==="master"||O&&O.startsWith(window.location.origin)&&/master(?:\..+)?\.css/.test(O))&&(this.style=c)}if(this.style)for(let g=0;g<this.style.sheet.cssRules.length;g++){let b=c=>{if(c.selectorText){let l=c.selectorText.split(", ")[0].split(" ");for(let m=0;m<l.length;m++){let u=l[m];if(u[0]==="."){let f=u.slice(1),v="";for(let M=0;M<f.length;M++){let r=f[M],o=f[M+1];if(r==="\\"){if(M++,o!=="\\"){v+=o;continue}}else if(Q.SELECTOR_SYMBOLS.includes(r))break;v+=r}if(!(v in this.ruleOfClass)&&!(v in this.classes)){let M=this.create(v)[0];if(M)return M}}}}else if(c.cssRules)for(let n=0;n<c.cssRules.length;n++){let l=b(c.cssRules[n]);if(l)return l}},O=b(this.style.sheet.cssRules[g]);if(O){this.rules.push(O),this.ruleOfClass[O.className]=O;for(let c=0;c<O.natives.length;c++)O.natives[c].cssRule=this.style.sheet.cssRules[g+c];g+=O.natives.length-1}}else{this.style=document.createElement("style"),this.style.title="master";let g=a.querySelector('link[rel="styleSheet"], style');g?g.before(this.style):a.append(this.style)}let w=g=>{g.forEach(b=>{b in this.countOfClass?this.countOfClass[b]++:(this.countOfClass[b]=1,this.insert(b))})};w(this.host.classList),t.subtree&&this.host.querySelectorAll("[class]").forEach(g=>w(g.classList)),this.e.observe(e,{...t,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]})}return this}disconnect(){this.e.disconnect(),this.ruleOfClass={},this.countOfClass={},this.rules.length=0;let e=this.style.sheet;if(e)for(let t=e.cssRules.length-1;t>=0;t--)e.deleteRule(t);this.style.remove(),this.style=null,this.theme?.destroy(),this.theme=null}match(e){for(let t in this.config.rules){let s=this.config.rules[t],a=this.matches[t],{colorStarts:C,symbol:w,prop:g}=s,{colorNames:b,colorThemesMap:O}=this;if(a&&a.test(e))return{origin:"matches",config:s};if(C){if(e.match("^"+C+"(?:(?:#|(rgb|hsl)\\(.*\\))((?!\\|).)*$|(?:transparent|current|inherit))"))return{origin:"matches",config:s};if(b.length&&e.indexOf("|")===-1){let c=e.match("^"+C+"((?:"+b.join("|")+")[0-9a-zA-Z-]*)");if(c&&c[1]in O)return{origin:"matches",config:s}}}if(w&&e.startsWith(w))return{origin:"symbol",config:s};if(g&&e.startsWith(g+":"))return{origin:"matches",config:s}}for(let t of this.semantics)if(e.match(t[0]))return{origin:"semantics",value:t[1]}}create(e){let t=s=>{if(s in this.ruleOfClass)return this.ruleOfClass[s];let a=this.match(s);if(a)return new $.Rule(s,a,this)};return(e in this.classes?this.classes[e].map(s=>t(s)):[t(e)]).filter(s=>s&&s.text)}refresh(e){if(e?.override?this.config=e:this.config=k(F.config,e),this.cache(),!this.style)return;let t=document.createElement("style");t.title="master",this.style.replaceWith(t),this.style=t,this.rules.length=0,this.ruleOfClass={};for(let s in this.countOfClass)this.insert(s)}destroy(){let e=j.instances;this.disconnect(),e.splice(e.indexOf(this),1)}delete(e){let t=this.style.sheet,s=a=>{let C=this.ruleOfClass[a];if(!(!C||a in this.relations&&this.relations[a].some(w=>w in this.countOfClass))){if(C.natives.length){let w=C.natives[0];for(let g=0;g<t.cssRules.length;g++)if(t.cssRules[g]===w.cssRule){for(let O=0;O<C.natives.length;O++)t.deleteRule(g);this.rules.splice(this.rules.indexOf(C),1);break}}delete this.ruleOfClass[a]}};if(e in this.classes){for(let a of this.classes[e])a in this.countOfClass||s(a);delete this.ruleOfClass[e]}else s(e)}insert(e){let t=this.create(e);return t.length?(this.insertRules(t),!0):!1}insertRules(e){for(let t of e){if(this.ruleOfClass[t.className])continue;let s,a=this.rules.length-1,{media:C,order:w,priority:g,hasWhere:b,className:O}=t,c=(n,l,m,u)=>{let f=0,v;l&&(f=n.findIndex(l)),m&&(v=n.findIndex(m)),f===-1&&(f=n.length),(v===void 0||v===-1)&&(v=n.length);let M=n.slice(f,v);for(let r=0;r<M.length;r++){let o=M[r];if(!(o.priority===-1||u&&u(o))&&(o.priority<g||o.priority===g&&(b&&!o.hasWhere||o.order>=w)))return f+r}return f+M.length};if(C){let n=this.rules.findIndex(l=>l.media);if(n!==-1){let l=C.features["max-width"],m=C.features["min-width"];if(l&&m){let u=l.value-m.value;for(let f=a;f>=n;f--){s=f;let v=this.rules[f],M=v.media,r=M.features["max-width"],o=M.features["min-width"];if(!r||!o){s++;break}let i=r.value-o.value;if(i===u){if(b!==v.hasWhere)continue;if(g!==-1){let d=[this.rules[f]];for(let h=f-1;h>=n;h--){let R=this.rules[h];if(R.hasWhere!==b)break;let p=R.media,T=p.features["max-width"],x=p.features["min-width"];if(!T||!x||T.value-x.value!==i)break;d.unshift(this.rules[h])}s=c(this.rules,h=>h.media&&h.priority!==-1&&h.media.features["min-width"]&&h.media.features["max-width"])}break}else if(i>u)break}}else if(m)for(let u=n;u<=a;u++){s=u;let f=this.rules[u],v=f.media,M=v.features["max-width"],r=v.features["min-width"];if(M){if(r)break;continue}let o=r?.value;if(o===m.value){if(!b&&f.hasWhere){s++;continue}if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else for(let i=u;i<=a;i++){let d=this.rules[i],h=d.media,R=h.features["min-width"];if(!h.features["max-width"]){if(d.hasWhere!==b||R.value!==o||d.order>=w)break;s=i+1}}break}else{if(o>m.value)break;s++}}else if(l)for(let u=a;u>=n;u--){s=u;let f=this.rules[u],v=f.media,M=v.features["max-width"];if(v.features["min-width"])continue;let o=M?.value;if(!o||o>l.value){s++;break}else if(o===l.value){if(b&&!f.hasWhere)continue;if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else{let i=[this.rules[u]];for(let d=u-1;d>=n;d--){let h=this.rules[d],R=h.media,p=R.features["min-width"],T=R.features["max-width"];if(!p&&(!T||T.value!==o||h.hasWhere!==b))break;i.unshift(h)}for(let d=0;d<i.length;d++){let h=i[d];if(!h.media.features["min-width"]){if(h.order>=w)break;s=u-i.length+2+d}}}break}}}if(s===void 0)if(n===-1)s=a+1;else if(g!==-1)s=n+c(this.rules.slice(n),void 0,l=>l.media.features["max-width"]||l.media.features["min-width"]);else if(b){let l=n;for(;l<this.rules.length;l++){let m=this.rules[l];if(m.priority!==-1||!m.hasWhere||m.order>=w){s=l;break}}s===void 0&&(s=l)}else for(let l=n;l<=a;l++){s=l;let m=this.rules[l],u=m.media;if(m.priority!==-1||u.features["max-width"]||u.features["min-width"])break;if(m.hasWhere)s++;else if(m.order>=w)break}}else if(g===-1)if(b)s=this.rules.findIndex(n=>!n.hasWhere||n.media||n.priority!==-1||n.order>=w),s===-1&&(s=a+1);else{let n=0;for(;n<this.rules.length;n++){let l=this.rules[n];if(l.media||!l.hasWhere&&(l.order>=w||l.priority!==-1)){s=n;break}}s===void 0&&(s=n)}else s=c(this.rules,void 0,n=>n.media);if(this.rules.splice(s,0,t),this.ruleOfClass[O]=t,this.style){let n=this.style.sheet,l=0,m=u=>{let f=this.rules[u];if(f){if(!f.natives.length)return m(u-1);let v=f.natives[f.natives.length-1].cssRule;for(let M=0;M<n.cssRules.length;M++)if(n.cssRules[M]===v){l=M+1;break}}};m(s-1);for(let u=0;u<t.natives.length;)try{let f=t.natives[u];n.insertRule(f.text,l),f.cssRule=n.cssRules[l++],u++}catch(f){console.error(f),t.natives.splice(u,1)}}}}get text(){return this.rules.map(e=>e.text).join("")}},W=j;S(W,"root"),S(W,"config",F.config),S(W,"instances",[]),S(W,"refresh",e=>{for(let t of j.instances)t.refresh(e)});L&&(window.MasterCSS=W);0&&(module.exports={MasterCSS});
|
|
1
|
+
var A=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var Z=(y,e,t)=>e in y?A(y,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):y[e]=t;var P=(y,e)=>{for(var t in e)A(y,t,{get:e[t],enumerable:!0})},U=(y,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of _(e))!q.call(y,a)&&a!==t&&A(y,a,{get:()=>e[a],enumerable:!(s=H(e,a))||s.enumerable});return y};var Y=y=>U(A({},"__esModule",{value:!0}),y);var S=(y,e,t)=>(Z(y,typeof e!="symbol"?e+"":e,t),t);var G={};P(G,{MasterCSS:()=>W});module.exports=Y(G);function I(y){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&y instanceof e||y instanceof Date||y instanceof RegExp)}function B(y){if(typeof Buffer<"u"&&Buffer&&y instanceof Buffer){let e=Buffer.alloc(y.length);return y.copy(e),e}else{if(y instanceof Date)return new Date(y.getTime());if(y instanceof RegExp)return new RegExp(y);throw new Error("Unexpected situation")}}function V(y){let e=[];return y.forEach(function(t,s){typeof t=="object"&&t!==null?Array.isArray(t)?e[s]=V(t):I(t)?e[s]=B(t):e[s]=k({},t):e[s]=t}),e}function N(y,e){return e==="__proto__"?void 0:y[e]}function k(...y){let e={},t,s;return y.forEach(function(a){typeof a!="object"||a===null||Array.isArray(a)||Object.keys(a).forEach(function(C){if(s=N(e,C),t=N(a,C),t!==e)if(typeof t!="object"||t===null){e[C]=t;return}else if(Array.isArray(t)){e[C]=V(t);return}else if(I(t)){e[C]=B(t);return}else if(typeof s!="object"||s===null||Array.isArray(s)){e[C]=k({},t);return}else{e[C]=k(s,t);return}})}),e}var $=require("./rule"),F=require("./config"),D=require("./utils/rgb-to-hex"),Q=require("./constants/selector-symbols");var L=typeof window<"u",j=class{constructor(e){this.config=e;this.config?.override||(this.config=k(F.config,e)),this.cache(),L&&this.config.observe&&this.observe(document),j.instances.push(this),this.ready=!0}rules=[];ruleOfClass={};countOfClass={};ready=!1;e=L?new MutationObserver(e=>{let t={},s=[],a=[],C=[],w=(c,n)=>{n?c.classList.forEach(b):c.classList.forEach(g);let l=c.children;for(let m=0;m<l.length;m++){let u=l[m];u.classList&&(a.push(u),w(u,n))}},g=c=>{c in t?t[c]++:t[c]=1},b=c=>{c in t?t[c]--:c in this.countOfClass&&(t[c]=-1)},O=(c,n)=>{for(let l=0;l<c.length;l++){let m=c[l];m.classList&&!a.includes(m)&&!C.includes(m)&&(m.isConnected!==n?(a.push(m),w(m,n)):C.push(m))}};for(let c=0;c<e.length;c++){let n=e[c],{addedNodes:l,removedNodes:m,type:u,target:f}=n;if(u==="attributes"){if(s.find(v=>v.target===f))continue;s.push(n)}else O(l,!1),(!f.isConnected||!a.includes(f))&&O(m,!0)}if(!(!s.length&&!Object.keys(t).length)){for(let{oldValue:c,target:n}of s){let l=a.includes(n),m=n.classList,u=c?c.split(" "):[];if(l){if(n.isConnected)continue;for(let f of u)m.contains(f)||b(f)}else if(n.isConnected){m.forEach(f=>{u.includes(f)||g(f)});for(let f of u)m.contains(f)||b(f)}}for(let c in t){let n=t[c],l=(this.countOfClass[c]||0)+n;l===0?(delete this.countOfClass[c],this.delete(c)):(c in this.countOfClass||this.insert(c),this.countOfClass[c]=l)}}}):null;cache(){this.semantics=[],this.classes={},this.colorThemesMap={},this.relationThemesMap={},this.relations={},this.colorNames=[],this.themeNames=[""],this.selectors={},this.values={},this.globalValues={},this.breakpoints={},this.mediaQueries={},this.matches={};let{semantics:e,classes:t,selectors:s,themes:a,colors:C,values:w,breakpoints:g,mediaQueries:b,rules:O}=this.config;function c(r){return r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function n(r,o,i="",d={}){let h=x=>x?(i?i+"-":"")+x:i,R=Object.entries(r),p=[],T=[];for(let x of R){let E=x[1];(typeof E=="object"&&!Array.isArray(E)?p:T).push(x)}for(let[x,E]of p)n(E,o,h(x),d);if(o&&i)T.length&&(d[i]=T.reduce((x,[E,z])=>(x[E]=z,x),{}));else for(let[x,E]of T)d[h(x)]=E;return d}if(e)for(let[r,o]of Object.entries(n(e,!0)))this.semantics.push([new RegExp("^"+c(r)+"(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)","m"),[r,o]]);if(s)for(let[r,o]of Object.entries(n(s,!1))){let i=new RegExp(c(r)+"(?![a-z-])");for(let d of Array.isArray(o)?o:[o]){let h=d.match(/^::-[a-z]+-/m)?.[0]??"",R=this.selectors[h];R||(R=this.selectors[h]=[]);let p=R.find(([T])=>T===i);p||(p=[i,[]],R.push(p)),p[1].push(d)}}w&&(this.globalValues=n(w,!1)),g&&(this.breakpoints=n(g,!1)),b&&(this.mediaQueries=n(b,!1));let l=t?n(t,!1):{},m=a&&!Array.isArray(a)?Object.entries(a).filter(([,{classes:r}])=>r).reduce((r,[o,{classes:i}])=>(r[o]=n(i,!1),r),{}):{},u=[...Object.keys(l),...Object.entries(m).flatMap(([r,o])=>Object.keys(o))],f=r=>{if(r in this.classes)return;let o=this.classes[r]=[],i=(d,h)=>{if(!h)return;let R=Array.isArray(h)?h:h.replace(/(?:\n(?:\s*))+/g," ").trim().split(" ");for(let p of R){let T=x=>{x in this.relationThemesMap?d in this.relationThemesMap[x]?this.relationThemesMap[x][d].push(r):this.relationThemesMap[x][d]=[r]:this.relationThemesMap[x]={[d]:[r]},o.includes(x)||o.push(x)};if(u.includes(p)){f(p);for(let x of this.classes[p])T(x)}else T(p)}};i("",l?.[r]);for(let[d,h]of Object.entries(m))i(d,h?.[r])};for(let r of u)f(r);for(let r in this.relationThemesMap){let o=this.relations[r]=[];for(let i of Object.values(this.relationThemesMap[r]))for(let d of i)o.includes(d)||o.push(d)}let v=(r,o)=>{if(!o)return;let i=n(o,!0);for(let[d,h]of Object.entries(i)){let R=typeof h=="string"?{"":h}:h;for(let[p,T]of Object.entries(R)){let x=d+(p?"-"+p:"");x in this.colorThemesMap?this.colorThemesMap[x][r]=T:this.colorThemesMap[x]={[r]:T}}}for(let d in o)this.colorNames.includes(d)||this.colorNames.push(d)};if(v("",C),a)if(Array.isArray(a))this.themeNames.push(...a);else for(let r in a){let o=a[r];v(r,o.colors),this.themeNames.push(r)}let M=r=>{for(let[o,i]of Object.entries(this.colorThemesMap))for(let[d,h]of Object.entries(i))h.startsWith("#")||r(o,i,d,h)};if(M((r,o,i,d)=>{let h=/^rgba?\( *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?:(?:\/|,) *0?(\.[0-9]))?\)$/.exec(d);if(h){let R="#"+(0,D.rgbToHex)(+h[1],+h[2],+h[3]);h[4]&&(R+=Math.round(255*+h[4]).toString(16)),o[i]=R}}),M((r,o,i,d)=>{let[h,R]=d.split("/"),p=this.colorThemesMap[h];if(p){let T=(i?p[i]:void 0)??p[""];o[i]=R?T.slice(0,7)+Math.round(255*+R).toString(16):T}else console.warn(`\`${d}\` doesn't exist in the extended config \`.colors\``),delete o[i],Object.keys(o).length||delete this.colorThemesMap[r]}),O)for(let r in O){let o=O[r],{matches:i,prop:d,values:h}=o;if(o.id=r,o.prop=d===!1?"":r.replace(/(?!^)[A-Z]/g,R=>"-"+R).toLowerCase(),h&&(this.values[r]=n(h,!1)),i){let R=Object.keys(this.values[r]??{}),p=i.indexOf("$values");this.matches[r]=new RegExp(p===-1?i:R.length?i.slice(0,p)+R.join("|")+i.slice(p+7):i.slice(0,p-(i[p-1]==="|"?1:0))+i.slice(p+7+(i[p+7]==="|"?1:0)))}}}observe(e,t={subtree:!0,childList:!0}){if(L&&e){this.root=e;let s=e===document;s&&(j.root=this),this.host=s?document.documentElement:root.host;let a=s?document.head:e,C=s?document.styleSheets:e.styleSheets;for(let g of C){let{title:b,href:O,ownerNode:c}=g;(b==="master"||O&&O.startsWith(window.location.origin)&&/master(?:\..+)?\.css/.test(O))&&(this.style=c)}if(this.style)for(let g=0;g<this.style.sheet.cssRules.length;g++){let b=c=>{if(c.selectorText){let l=c.selectorText.split(", ")[0].split(" ");for(let m=0;m<l.length;m++){let u=l[m];if(u[0]==="."){let f=u.slice(1),v="";for(let M=0;M<f.length;M++){let r=f[M],o=f[M+1];if(r==="\\"){if(M++,o!=="\\"){v+=o;continue}}else if(Q.SELECTOR_SYMBOLS.includes(r))break;v+=r}if(!(v in this.ruleOfClass)&&!(v in this.classes)){let M=this.create(v)[0];if(M)return M}}}}else if(c.cssRules)for(let n=0;n<c.cssRules.length;n++){let l=b(c.cssRules[n]);if(l)return l}},O=b(this.style.sheet.cssRules[g]);if(O){this.rules.push(O),this.ruleOfClass[O.className]=O;for(let c=0;c<O.natives.length;c++)O.natives[c].cssRule=this.style.sheet.cssRules[g+c];g+=O.natives.length-1}}else{this.style=document.createElement("style"),this.style.title="master";let g=a.querySelector('link[rel="styleSheet"], style');g?g.before(this.style):a.append(this.style)}let w=g=>{g.forEach(b=>{b in this.countOfClass?this.countOfClass[b]++:(this.countOfClass[b]=1,this.insert(b))})};w(this.host.classList),t.subtree&&this.host.querySelectorAll("[class]").forEach(g=>w(g.classList)),this.e.observe(e,{...t,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]})}return this}disconnect(){this.e.disconnect(),this.ruleOfClass={},this.countOfClass={},this.rules.length=0;let e=this.style.sheet;if(e)for(let t=e.cssRules.length-1;t>=0;t--)e.deleteRule(t);this.style.remove(),this.style=null}match(e){for(let t in this.config.rules){let s=this.config.rules[t],a=this.matches[t],{colorStarts:C,symbol:w,prop:g}=s,{colorNames:b,colorThemesMap:O}=this;if(a&&a.test(e))return{origin:"matches",config:s};if(C){if(e.match("^"+C+"(?:(?:#|(rgb|hsl)\\(.*\\))((?!\\|).)*$|(?:transparent|current|inherit))"))return{origin:"matches",config:s};if(b.length&&e.indexOf("|")===-1){let c=e.match("^"+C+"((?:"+b.join("|")+")[0-9a-zA-Z-]*)");if(c&&c[1]in O)return{origin:"matches",config:s}}}if(w&&e.startsWith(w))return{origin:"symbol",config:s};if(g&&e.startsWith(g+":"))return{origin:"matches",config:s}}for(let t of this.semantics)if(e.match(t[0]))return{origin:"semantics",value:t[1]}}create(e){let t=s=>{if(s in this.ruleOfClass)return this.ruleOfClass[s];let a=this.match(s);if(a)return new $.Rule(s,a,this)};return(e in this.classes?this.classes[e].map(s=>t(s)):[t(e)]).filter(s=>s&&s.text)}refresh(e){if(e?.override?this.config=e:this.config=k(F.config,e),this.cache(),!this.style)return;let t=document.createElement("style");t.title="master",this.style.replaceWith(t),this.style=t,this.rules.length=0,this.ruleOfClass={};for(let s in this.countOfClass)this.insert(s)}destroy(){let e=j.instances;this.disconnect(),e.splice(e.indexOf(this),1)}delete(e){let t=this.style.sheet,s=a=>{let C=this.ruleOfClass[a];if(!(!C||a in this.relations&&this.relations[a].some(w=>w in this.countOfClass))){if(C.natives.length){let w=C.natives[0];for(let g=0;g<t.cssRules.length;g++)if(t.cssRules[g]===w.cssRule){for(let O=0;O<C.natives.length;O++)t.deleteRule(g);this.rules.splice(this.rules.indexOf(C),1);break}}delete this.ruleOfClass[a]}};if(e in this.classes){for(let a of this.classes[e])a in this.countOfClass||s(a);delete this.ruleOfClass[e]}else s(e)}insert(e){let t=this.create(e);return t.length?(this.insertRules(t),!0):!1}insertRules(e){for(let t of e){if(this.ruleOfClass[t.className])continue;let s,a=this.rules.length-1,{media:C,order:w,priority:g,hasWhere:b,className:O}=t,c=(n,l,m,u)=>{let f=0,v;l&&(f=n.findIndex(l)),m&&(v=n.findIndex(m)),f===-1&&(f=n.length),(v===void 0||v===-1)&&(v=n.length);let M=n.slice(f,v);for(let r=0;r<M.length;r++){let o=M[r];if(!(o.priority===-1||u&&u(o))&&(o.priority<g||o.priority===g&&(b&&!o.hasWhere||o.order>=w)))return f+r}return f+M.length};if(C){let n=this.rules.findIndex(l=>l.media);if(n!==-1){let l=C.features["max-width"],m=C.features["min-width"];if(l&&m){let u=l.value-m.value;for(let f=a;f>=n;f--){s=f;let v=this.rules[f],M=v.media,r=M.features["max-width"],o=M.features["min-width"];if(!r||!o){s++;break}let i=r.value-o.value;if(i===u){if(b!==v.hasWhere)continue;if(g!==-1){let d=[this.rules[f]];for(let h=f-1;h>=n;h--){let R=this.rules[h];if(R.hasWhere!==b)break;let p=R.media,T=p.features["max-width"],x=p.features["min-width"];if(!T||!x||T.value-x.value!==i)break;d.unshift(this.rules[h])}s=c(this.rules,h=>h.media&&h.priority!==-1&&h.media.features["min-width"]&&h.media.features["max-width"])}break}else if(i>u)break}}else if(m)for(let u=n;u<=a;u++){s=u;let f=this.rules[u],v=f.media,M=v.features["max-width"],r=v.features["min-width"];if(M){if(r)break;continue}let o=r?.value;if(o===m.value){if(!b&&f.hasWhere){s++;continue}if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else for(let i=u;i<=a;i++){let d=this.rules[i],h=d.media,R=h.features["min-width"];if(!h.features["max-width"]){if(d.hasWhere!==b||R.value!==o||d.order>=w)break;s=i+1}}break}else{if(o>m.value)break;s++}}else if(l)for(let u=a;u>=n;u--){s=u;let f=this.rules[u],v=f.media,M=v.features["max-width"];if(v.features["min-width"])continue;let o=M?.value;if(!o||o>l.value){s++;break}else if(o===l.value){if(b&&!f.hasWhere)continue;if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else{let i=[this.rules[u]];for(let d=u-1;d>=n;d--){let h=this.rules[d],R=h.media,p=R.features["min-width"],T=R.features["max-width"];if(!p&&(!T||T.value!==o||h.hasWhere!==b))break;i.unshift(h)}for(let d=0;d<i.length;d++){let h=i[d];if(!h.media.features["min-width"]){if(h.order>=w)break;s=u-i.length+2+d}}}break}}}if(s===void 0)if(n===-1)s=a+1;else if(g!==-1)s=n+c(this.rules.slice(n),void 0,l=>l.media.features["max-width"]||l.media.features["min-width"]);else if(b){let l=n;for(;l<this.rules.length;l++){let m=this.rules[l];if(m.priority!==-1||!m.hasWhere||m.order>=w){s=l;break}}s===void 0&&(s=l)}else for(let l=n;l<=a;l++){s=l;let m=this.rules[l],u=m.media;if(m.priority!==-1||u.features["max-width"]||u.features["min-width"])break;if(m.hasWhere)s++;else if(m.order>=w)break}}else if(g===-1)if(b)s=this.rules.findIndex(n=>!n.hasWhere||n.media||n.priority!==-1||n.order>=w),s===-1&&(s=a+1);else{let n=0;for(;n<this.rules.length;n++){let l=this.rules[n];if(l.media||!l.hasWhere&&(l.order>=w||l.priority!==-1)){s=n;break}}s===void 0&&(s=n)}else s=c(this.rules,void 0,n=>n.media);if(this.rules.splice(s,0,t),this.ruleOfClass[O]=t,this.style){let n=this.style.sheet,l=0,m=u=>{let f=this.rules[u];if(f){if(!f.natives.length)return m(u-1);let v=f.natives[f.natives.length-1].cssRule;for(let M=0;M<n.cssRules.length;M++)if(n.cssRules[M]===v){l=M+1;break}}};m(s-1);for(let u=0;u<t.natives.length;)try{let f=t.natives[u];n.insertRule(f.text,l),f.cssRule=n.cssRules[l++],u++}catch(f){console.error(f),t.natives.splice(u,1)}}}}get text(){return this.rules.map(e=>e.text).join("")}},W=j;S(W,"root"),S(W,"config",F.config),S(W,"instances",[]),S(W,"refresh",e=>{for(let t of j.instances)t.refresh(e)});L&&(window.MasterCSS=W);0&&(module.exports={MasterCSS});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=require("./css");new e.MasterCSS(window.masterCSSConfig);
|
|
1
|
+
var e=require("./css"),a=require("./theme");new e.MasterCSS(window.masterCSSConfig);new a.Theme(window.masterCSSThemeSettings);
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var c=Object.defineProperty;var
|
|
1
|
+
var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var B=(f,t)=>{for(var n in t)c(f,n,{get:t[n],enumerable:!0})},l=(f,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of E(t))!d.call(f,u)&&u!==n&&c(f,u,{get:()=>t[u],enumerable:!(o=A(t,u))||o.enumerable});return f},r=(f,t,n)=>(l(f,t,"default"),n&&l(n,t,"default"));var b=f=>l(c({},"__esModule",{value:!0}),f);var e={};B(e,{default:()=>m.MasterCSS,extend:()=>a});module.exports=b(e);r(e,require("./css"),module.exports);r(e,require("./rule"),module.exports);r(e,require("./theme"),module.exports);var m=require("./css");function p(f){let t=typeof Buffer<"u"?Buffer:null;return!!(t&&f instanceof t||f instanceof Date||f instanceof RegExp)}function y(f){if(typeof Buffer<"u"&&Buffer&&f instanceof Buffer){let t=Buffer.alloc(f.length);return f.copy(t),t}else{if(f instanceof Date)return new Date(f.getTime());if(f instanceof RegExp)return new RegExp(f);throw new Error("Unexpected situation")}}function x(f){let t=[];return f.forEach(function(n,o){typeof n=="object"&&n!==null?Array.isArray(n)?t[o]=x(n):p(n)?t[o]=y(n):t[o]=a({},n):t[o]=n}),t}function s(f,t){return t==="__proto__"?void 0:f[t]}function a(...f){let t={},n,o;return f.forEach(function(u){typeof u!="object"||u===null||Array.isArray(u)||Object.keys(u).forEach(function(i){if(o=s(t,i),n=s(u,i),n!==t)if(typeof n!="object"||n===null){t[i]=n;return}else if(Array.isArray(n)){t[i]=x(n);return}else if(p(n)){t[i]=y(n);return}else if(typeof o!="object"||o===null||Array.isArray(o)){t[i]=a({},n);return}else{t[i]=a(o,n);return}})}),t}r(e,require("./methods"),module.exports);r(e,require("./config"),module.exports);0&&(module.exports={extend});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./render"),module.exports);r(o,require("./render-from-html"),module.exports);r(o,require("./render-into-html"),module.exports);r(o,require("./fill-color-scale"),module.exports);r(o,require("./define-content"),module.exports);
|
|
1
|
+
var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,e,p,x)=>{if(e&&typeof e=="object"||typeof e=="function")for(let m of c(e))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>e[m],enumerable:!(x=b(e,m))||x.enumerable});return f},r=(f,e,p)=>(t(f,e,"default"),p&&t(p,e,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var o={};module.exports=g(o);r(o,require("./render"),module.exports);r(o,require("./render-from-html"),module.exports);r(o,require("./render-into-html"),module.exports);r(o,require("./fill-color-scale"),module.exports);r(o,require("./define-content"),module.exports);
|
package/dist/cjs/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var a=Object.defineProperty;var
|
|
1
|
+
var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var v=(s,e)=>{for(var t in e)a(s,t,{get:e[t],enumerable:!0})},E=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of p(e))!y.call(s,r)&&r!==t&&a(s,r,{get:()=>e[r],enumerable:!(i=g(e,r))||i.enumerable});return s};var S=s=>E(a({},"__esModule",{value:!0}),s);var T={};v(T,{Theme:()=>h,getDocThemeInitScript:()=>x,themeSettings:()=>c});module.exports=S(T);function u(s){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&s instanceof e||s instanceof Date||s instanceof RegExp)}function f(s){if(typeof Buffer<"u"&&Buffer&&s instanceof Buffer){let e=Buffer.alloc(s.length);return s.copy(e),e}else{if(s instanceof Date)return new Date(s.getTime());if(s instanceof RegExp)return new RegExp(s);throw new Error("Unexpected situation")}}function m(s){let e=[];return s.forEach(function(t,i){typeof t=="object"&&t!==null?Array.isArray(t)?e[i]=m(t):u(t)?e[i]=f(t):e[i]=o({},t):e[i]=t}),e}function l(s,e){return e==="__proto__"?void 0:s[e]}function o(...s){let e={},t,i;return s.forEach(function(r){typeof r!="object"||r===null||Array.isArray(r)||Object.keys(r).forEach(function(n){if(i=l(e,n),t=l(r,n),t!==e)if(typeof t!="object"||t===null){e[n]=t;return}else if(Array.isArray(t)){e[n]=m(t);return}else if(u(t)){e[n]=f(t);return}else if(typeof i!="object"||i===null||Array.isArray(i)){e[n]=o({},t);return}else{e[n]=o(i,t);return}})}),e}var c={store:"theme",init:!0},b=typeof document<"u",d=typeof localStorage<"u",h=class{constructor(e,t=b?document.documentElement:null){this.settings=e;this.host=t;this.settings=e?o(c,e):c,this.settings.init&&this.init()}e=typeof matchMedia<"u"?matchMedia?.("(prefers-color-scheme:dark)"):void 0;s;t;init(){let e=this.settings.default,t=this.storage;t&&(e=t),this.value=e}get storage(){let{store:e}=this.settings;if(d&&e)return localStorage.getItem(e)}get systemValue(){return this.e.matches?"dark":"light"}set value(e){this.s=e,e==="system"?(this.e?.addEventListener?.("change",this.i),this.current=this.systemValue):(this.r(),this.current=e)}get value(){return this.s}set current(e){let t=this.t;this.t=e,this.host&&(t&&this.host.classList.remove(t),this.host.classList.contains(e)||(this.host.classList.add(e),this.host.style&&(this.host.style.colorScheme=e)))}get current(){return this.t}switch(e,t={store:!0,emit:!0}){e&&e!==this.value&&(this.value=e,d&&this.storage!==e&&this.settings.store&&localStorage.setItem(this.settings.store,e),t.emit&&this.host.dispatchEvent(new CustomEvent("theme",{detail:this})))}r(){this.e?.removeEventListener("change",this.i)}i=e=>{this.current=e.matches?"dark":"light"};destroy(){this.r()}};function x(s){return s=Object.assign({store:"theme"},s),`let e${s.default?`='${s.default}'`:""};const c=localStorage.getItem("${s.store}");c&&(e=c);let t=e;e==="system"&&(t=matchMedia("(prefers-color-scheme:dark)").matches?"dark":"light");const s=document.documentElement;s.classList.add(t);s.style.colorScheme=t;`}0&&(module.exports={Theme,getDocThemeInitScript,themeSettings});
|
package/dist/config/index.d.ts
CHANGED
|
@@ -5,15 +5,13 @@ import { scope } from './scope';
|
|
|
5
5
|
import { selectors } from './selectors';
|
|
6
6
|
import { semantics } from './semantics';
|
|
7
7
|
import { themes } from './themes';
|
|
8
|
-
import { theme } from './theme';
|
|
9
8
|
import { rules } from './rules';
|
|
10
9
|
import { override } from './override';
|
|
11
10
|
import { observe } from './observe';
|
|
12
11
|
import { important } from './important';
|
|
13
12
|
declare const config: Config;
|
|
14
|
-
export { config, breakpoints, colors, rootSize, scope, selectors, semantics, themes,
|
|
13
|
+
export { config, breakpoints, colors, rootSize, scope, selectors, semantics, themes, rules, override, observe, important };
|
|
15
14
|
import type { RuleConfig } from '../rule';
|
|
16
|
-
import type { ThemeConfig } from '../theme';
|
|
17
15
|
type Classes = {
|
|
18
16
|
[key: string]: string | Classes;
|
|
19
17
|
};
|
|
@@ -54,7 +52,6 @@ export interface Config {
|
|
|
54
52
|
rootSize?: number;
|
|
55
53
|
scope?: string;
|
|
56
54
|
important?: boolean;
|
|
57
|
-
theme?: ThemeConfig;
|
|
58
55
|
override?: boolean;
|
|
59
56
|
observe?: boolean;
|
|
60
57
|
}
|
package/dist/css.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Rule, RuleMeta } from './rule';
|
|
2
2
|
import type { Config } from './config';
|
|
3
|
-
import { Theme } from './theme';
|
|
4
3
|
export interface MasterCSS {
|
|
5
4
|
readonly style: HTMLStyleElement;
|
|
6
5
|
readonly host: Element;
|
|
@@ -18,7 +17,6 @@ export interface MasterCSS {
|
|
|
18
17
|
breakpoints: Record<string, number>;
|
|
19
18
|
mediaQueries: Record<string, string>;
|
|
20
19
|
matches: Record<string, RegExp>;
|
|
21
|
-
theme: Theme | undefined;
|
|
22
20
|
}
|
|
23
21
|
export declare class MasterCSS {
|
|
24
22
|
config?: Config;
|
package/dist/esm/config/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{breakpoints as e}from"./breakpoints.js";import{colors as r}from"./colors.js";import{rootSize as s}from"./root-size.js";import{scope as o}from"./scope.js";import{selectors as t}from"./selectors.js";import{semantics as i}from"./semantics.js";import{themes as
|
|
1
|
+
import{breakpoints as e}from"./breakpoints.js";import{colors as r}from"./colors.js";import{rootSize as s}from"./root-size.js";import{scope as o}from"./scope.js";import{selectors as t}from"./selectors.js";import{semantics as i}from"./semantics.js";import{themes as n}from"./themes.js";import{rules as m}from"./rules.js";import{override as a}from"./override.js";import{observe as p}from"./observe.js";import{important as l}from"./important.js";var v={breakpoints:e,colors:r,rootSize:s,scope:o,selectors:t,semantics:i,themes:n,rules:m,override:a,observe:p,important:l};export{e as breakpoints,r as colors,v as config,l as important,p as observe,a as override,s as rootSize,m as rules,o as scope,t as selectors,i as semantics,n as themes};
|
package/dist/esm/css.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var $=Object.defineProperty;var D=(O,e,t)=>e in O?$(O,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):O[e]=t;var S=(O,e,t)=>(D(O,typeof e!="symbol"?e+"":e,t),t);function N(O){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&O instanceof e||O instanceof Date||O instanceof RegExp)}function I(O){if(typeof Buffer<"u"&&Buffer&&O instanceof Buffer){let e=Buffer.alloc(O.length);return O.copy(e),e}else{if(O instanceof Date)return new Date(O.getTime());if(O instanceof RegExp)return new RegExp(O);throw new Error("Unexpected situation")}}function B(O){let e=[];return O.forEach(function(t,s){typeof t=="object"&&t!==null?Array.isArray(t)?e[s]=B(t):N(t)?e[s]=I(t):e[s]=k({},t):e[s]=t}),e}function L(O,e){return e==="__proto__"?void 0:O[e]}function k(...O){let e={},t,s;return O.forEach(function(d){typeof d!="object"||d===null||Array.isArray(d)||Object.keys(d).forEach(function(x){if(s=L(e,x),t=L(d,x),t!==e)if(typeof t!="object"||t===null){e[x]=t;return}else if(Array.isArray(t)){e[x]=B(t);return}else if(N(t)){e[x]=I(t);return}else if(typeof s!="object"||s===null||Array.isArray(s)){e[x]=k({},t);return}else{e[x]=k(s,t);return}})}),e}import{Rule as H}from"./rule.js";import{config as F}from"./config/index.js";import{Theme as Q}from"./theme.js";import{rgbToHex as z}from"./utils/rgb-to-hex.js";import{SELECTOR_SYMBOLS as _}from"./constants/selector-symbols.js";var A=typeof window<"u",j=class{constructor(e){this.config=e;this.config?.override||(this.config=k(F,e)),this.cache(),A&&this.config.observe&&this.observe(document),j.instances.push(this),this.ready=!0}rules=[];ruleOfClass={};countOfClass={};ready=!1;e=A?new MutationObserver(e=>{let t={},s=[],d=[],x=[],w=(c,n)=>{n?c.classList.forEach(y):c.classList.forEach(g);let l=c.children;for(let m=0;m<l.length;m++){let f=l[m];f.classList&&(d.push(f),w(f,n))}},g=c=>{c in t?t[c]++:t[c]=1},y=c=>{c in t?t[c]--:c in this.countOfClass&&(t[c]=-1)},M=(c,n)=>{for(let l=0;l<c.length;l++){let m=c[l];m.classList&&!d.includes(m)&&!x.includes(m)&&(m.isConnected!==n?(d.push(m),w(m,n)):x.push(m))}};for(let c=0;c<e.length;c++){let n=e[c],{addedNodes:l,removedNodes:m,type:f,target:h}=n;if(f==="attributes"){if(s.find(C=>C.target===h))continue;s.push(n)}else M(l,!1),(!h.isConnected||!d.includes(h))&&M(m,!0)}if(!(!s.length&&!Object.keys(t).length)){for(let{oldValue:c,target:n}of s){let l=d.includes(n),m=n.classList,f=c?c.split(" "):[];if(l){if(n.isConnected)continue;for(let h of f)m.contains(h)||y(h)}else if(n.isConnected){m.forEach(h=>{f.includes(h)||g(h)});for(let h of f)m.contains(h)||y(h)}}for(let c in t){let n=t[c],l=(this.countOfClass[c]||0)+n;l===0?(delete this.countOfClass[c],this.delete(c)):(c in this.countOfClass||this.insert(c),this.countOfClass[c]=l)}}}):null;cache(){this.semantics=[],this.classes={},this.colorThemesMap={},this.relationThemesMap={},this.relations={},this.colorNames=[],this.themeNames=[""],this.selectors={},this.values={},this.globalValues={},this.breakpoints={},this.mediaQueries={},this.matches={};let{semantics:e,classes:t,selectors:s,themes:d,colors:x,values:w,breakpoints:g,mediaQueries:y,rules:M}=this.config;function c(r){return r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function n(r,o,i="",u={}){let a=R=>R?(i?i+"-":"")+R:i,b=Object.entries(r),p=[],T=[];for(let R of b){let E=R[1];(typeof E=="object"&&!Array.isArray(E)?p:T).push(R)}for(let[R,E]of p)n(E,o,a(R),u);if(o&&i)T.length&&(u[i]=T.reduce((R,[E,V])=>(R[E]=V,R),{}));else for(let[R,E]of T)u[a(R)]=E;return u}if(e)for(let[r,o]of Object.entries(n(e,!0)))this.semantics.push([new RegExp("^"+c(r)+"(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)","m"),[r,o]]);if(s)for(let[r,o]of Object.entries(n(s,!1))){let i=new RegExp(c(r)+"(?![a-z-])");for(let u of Array.isArray(o)?o:[o]){let a=u.match(/^::-[a-z]+-/m)?.[0]??"",b=this.selectors[a];b||(b=this.selectors[a]=[]);let p=b.find(([T])=>T===i);p||(p=[i,[]],b.push(p)),p[1].push(u)}}w&&(this.globalValues=n(w,!1)),g&&(this.breakpoints=n(g,!1)),y&&(this.mediaQueries=n(y,!1));let l=t?n(t,!1):{},m=d&&!Array.isArray(d)?Object.entries(d).filter(([,{classes:r}])=>r).reduce((r,[o,{classes:i}])=>(r[o]=n(i,!1),r),{}):{},f=[...Object.keys(l),...Object.entries(m).flatMap(([r,o])=>Object.keys(o))],h=r=>{if(r in this.classes)return;let o=this.classes[r]=[],i=(u,a)=>{if(!a)return;let b=Array.isArray(a)?a:a.replace(/(?:\n(?:\s*))+/g," ").trim().split(" ");for(let p of b){let T=R=>{R in this.relationThemesMap?u in this.relationThemesMap[R]?this.relationThemesMap[R][u].push(r):this.relationThemesMap[R][u]=[r]:this.relationThemesMap[R]={[u]:[r]},o.includes(R)||o.push(R)};if(f.includes(p)){h(p);for(let R of this.classes[p])T(R)}else T(p)}};i("",l?.[r]);for(let[u,a]of Object.entries(m))i(u,a?.[r])};for(let r of f)h(r);for(let r in this.relationThemesMap){let o=this.relations[r]=[];for(let i of Object.values(this.relationThemesMap[r]))for(let u of i)o.includes(u)||o.push(u)}let C=(r,o)=>{if(!o)return;let i=n(o,!0);for(let[u,a]of Object.entries(i)){let b=typeof a=="string"?{"":a}:a;for(let[p,T]of Object.entries(b)){let R=u+(p?"-"+p:"");R in this.colorThemesMap?this.colorThemesMap[R][r]=T:this.colorThemesMap[R]={[r]:T}}}for(let u in o)this.colorNames.includes(u)||this.colorNames.push(u)};if(C("",x),d)if(Array.isArray(d))this.themeNames.push(...d);else for(let r in d){let o=d[r];C(r,o.colors),this.themeNames.push(r)}let v=r=>{for(let[o,i]of Object.entries(this.colorThemesMap))for(let[u,a]of Object.entries(i))a.startsWith("#")||r(o,i,u,a)};if(v((r,o,i,u)=>{let a=/^rgba?\( *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?:(?:\/|,) *0?(\.[0-9]))?\)$/.exec(u);if(a){let b="#"+z(+a[1],+a[2],+a[3]);a[4]&&(b+=Math.round(255*+a[4]).toString(16)),o[i]=b}}),v((r,o,i,u)=>{let[a,b]=u.split("/"),p=this.colorThemesMap[a];if(p){let T=(i?p[i]:void 0)??p[""];o[i]=b?T.slice(0,7)+Math.round(255*+b).toString(16):T}else console.warn(`\`${u}\` doesn't exist in the extended config \`.colors\``),delete o[i],Object.keys(o).length||delete this.colorThemesMap[r]}),M)for(let r in M){let o=M[r],{matches:i,prop:u,values:a}=o;if(o.id=r,o.prop=u===!1?"":r.replace(/(?!^)[A-Z]/g,b=>"-"+b).toLowerCase(),a&&(this.values[r]=n(a,!1)),i){let b=Object.keys(this.values[r]??{}),p=i.indexOf("$values");this.matches[r]=new RegExp(p===-1?i:b.length?i.slice(0,p)+b.join("|")+i.slice(p+7):i.slice(0,p-(i[p-1]==="|"?1:0))+i.slice(p+7+(i[p+7]==="|"?1:0)))}}}observe(e,t={subtree:!0,childList:!0}){if(A&&e){this.root=e;let s=e===document;s&&(j.root=this),this.host=s?document.documentElement:root.host,this.theme=new Q(this.host,this.config.theme);let d=s?document.head:e,x=s?document.styleSheets:e.styleSheets;for(let g of x){let{title:y,href:M,ownerNode:c}=g;(y==="master"||M&&M.startsWith(window.location.origin)&&/master(?:\..+)?\.css/.test(M))&&(this.style=c)}if(this.style)for(let g=0;g<this.style.sheet.cssRules.length;g++){let y=c=>{if(c.selectorText){let l=c.selectorText.split(", ")[0].split(" ");for(let m=0;m<l.length;m++){let f=l[m];if(f[0]==="."){let h=f.slice(1),C="";for(let v=0;v<h.length;v++){let r=h[v],o=h[v+1];if(r==="\\"){if(v++,o!=="\\"){C+=o;continue}}else if(_.includes(r))break;C+=r}if(!(C in this.ruleOfClass)&&!(C in this.classes)){let v=this.create(C)[0];if(v)return v}}}}else if(c.cssRules)for(let n=0;n<c.cssRules.length;n++){let l=y(c.cssRules[n]);if(l)return l}},M=y(this.style.sheet.cssRules[g]);if(M){this.rules.push(M),this.ruleOfClass[M.className]=M;for(let c=0;c<M.natives.length;c++)M.natives[c].cssRule=this.style.sheet.cssRules[g+c];g+=M.natives.length-1}}else{this.style=document.createElement("style"),this.style.title="master";let g=d.querySelector('link[rel="styleSheet"], style');g?g.before(this.style):d.append(this.style)}let w=g=>{g.forEach(y=>{y in this.countOfClass?this.countOfClass[y]++:(this.countOfClass[y]=1,this.insert(y))})};w(this.host.classList),t.subtree&&this.host.querySelectorAll("[class]").forEach(g=>w(g.classList)),this.e.observe(e,{...t,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]})}return this}disconnect(){this.e.disconnect(),this.ruleOfClass={},this.countOfClass={},this.rules.length=0;let e=this.style.sheet;if(e)for(let t=e.cssRules.length-1;t>=0;t--)e.deleteRule(t);this.style.remove(),this.style=null,this.theme?.destroy(),this.theme=null}match(e){for(let t in this.config.rules){let s=this.config.rules[t],d=this.matches[t],{colorStarts:x,symbol:w,prop:g}=s,{colorNames:y,colorThemesMap:M}=this;if(d&&d.test(e))return{origin:"matches",config:s};if(x){if(e.match("^"+x+"(?:(?:#|(rgb|hsl)\\(.*\\))((?!\\|).)*$|(?:transparent|current|inherit))"))return{origin:"matches",config:s};if(y.length&&e.indexOf("|")===-1){let c=e.match("^"+x+"((?:"+y.join("|")+")[0-9a-zA-Z-]*)");if(c&&c[1]in M)return{origin:"matches",config:s}}}if(w&&e.startsWith(w))return{origin:"symbol",config:s};if(g&&e.startsWith(g+":"))return{origin:"matches",config:s}}for(let t of this.semantics)if(e.match(t[0]))return{origin:"semantics",value:t[1]}}create(e){let t=s=>{if(s in this.ruleOfClass)return this.ruleOfClass[s];let d=this.match(s);if(d)return new H(s,d,this)};return(e in this.classes?this.classes[e].map(s=>t(s)):[t(e)]).filter(s=>s&&s.text)}refresh(e){if(e?.override?this.config=e:this.config=k(F,e),this.cache(),!this.style)return;let t=document.createElement("style");t.title="master",this.style.replaceWith(t),this.style=t,this.rules.length=0,this.ruleOfClass={};for(let s in this.countOfClass)this.insert(s)}destroy(){let e=j.instances;this.disconnect(),e.splice(e.indexOf(this),1)}delete(e){let t=this.style.sheet,s=d=>{let x=this.ruleOfClass[d];if(!(!x||d in this.relations&&this.relations[d].some(w=>w in this.countOfClass))){if(x.natives.length){let w=x.natives[0];for(let g=0;g<t.cssRules.length;g++)if(t.cssRules[g]===w.cssRule){for(let M=0;M<x.natives.length;M++)t.deleteRule(g);this.rules.splice(this.rules.indexOf(x),1);break}}delete this.ruleOfClass[d]}};if(e in this.classes){for(let d of this.classes[e])d in this.countOfClass||s(d);delete this.ruleOfClass[e]}else s(e)}insert(e){let t=this.create(e);return t.length?(this.insertRules(t),!0):!1}insertRules(e){for(let t of e){if(this.ruleOfClass[t.className])continue;let s,d=this.rules.length-1,{media:x,order:w,priority:g,hasWhere:y,className:M}=t,c=(n,l,m,f)=>{let h=0,C;l&&(h=n.findIndex(l)),m&&(C=n.findIndex(m)),h===-1&&(h=n.length),(C===void 0||C===-1)&&(C=n.length);let v=n.slice(h,C);for(let r=0;r<v.length;r++){let o=v[r];if(!(o.priority===-1||f&&f(o))&&(o.priority<g||o.priority===g&&(y&&!o.hasWhere||o.order>=w)))return h+r}return h+v.length};if(x){let n=this.rules.findIndex(l=>l.media);if(n!==-1){let l=x.features["max-width"],m=x.features["min-width"];if(l&&m){let f=l.value-m.value;for(let h=d;h>=n;h--){s=h;let C=this.rules[h],v=C.media,r=v.features["max-width"],o=v.features["min-width"];if(!r||!o){s++;break}let i=r.value-o.value;if(i===f){if(y!==C.hasWhere)continue;if(g!==-1){let u=[this.rules[h]];for(let a=h-1;a>=n;a--){let b=this.rules[a];if(b.hasWhere!==y)break;let p=b.media,T=p.features["max-width"],R=p.features["min-width"];if(!T||!R||T.value-R.value!==i)break;u.unshift(this.rules[a])}s=c(this.rules,a=>a.media&&a.priority!==-1&&a.media.features["min-width"]&&a.media.features["max-width"])}break}else if(i>f)break}}else if(m)for(let f=n;f<=d;f++){s=f;let h=this.rules[f],C=h.media,v=C.features["max-width"],r=C.features["min-width"];if(v){if(r)break;continue}let o=r?.value;if(o===m.value){if(!y&&h.hasWhere){s++;continue}if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else for(let i=f;i<=d;i++){let u=this.rules[i],a=u.media,b=a.features["min-width"];if(!a.features["max-width"]){if(u.hasWhere!==y||b.value!==o||u.order>=w)break;s=i+1}}break}else{if(o>m.value)break;s++}}else if(l)for(let f=d;f>=n;f--){s=f;let h=this.rules[f],C=h.media,v=C.features["max-width"];if(C.features["min-width"])continue;let o=v?.value;if(!o||o>l.value){s++;break}else if(o===l.value){if(y&&!h.hasWhere)continue;if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else{let i=[this.rules[f]];for(let u=f-1;u>=n;u--){let a=this.rules[u],b=a.media,p=b.features["min-width"],T=b.features["max-width"];if(!p&&(!T||T.value!==o||a.hasWhere!==y))break;i.unshift(a)}for(let u=0;u<i.length;u++){let a=i[u];if(!a.media.features["min-width"]){if(a.order>=w)break;s=f-i.length+2+u}}}break}}}if(s===void 0)if(n===-1)s=d+1;else if(g!==-1)s=n+c(this.rules.slice(n),void 0,l=>l.media.features["max-width"]||l.media.features["min-width"]);else if(y){let l=n;for(;l<this.rules.length;l++){let m=this.rules[l];if(m.priority!==-1||!m.hasWhere||m.order>=w){s=l;break}}s===void 0&&(s=l)}else for(let l=n;l<=d;l++){s=l;let m=this.rules[l],f=m.media;if(m.priority!==-1||f.features["max-width"]||f.features["min-width"])break;if(m.hasWhere)s++;else if(m.order>=w)break}}else if(g===-1)if(y)s=this.rules.findIndex(n=>!n.hasWhere||n.media||n.priority!==-1||n.order>=w),s===-1&&(s=d+1);else{let n=0;for(;n<this.rules.length;n++){let l=this.rules[n];if(l.media||!l.hasWhere&&(l.order>=w||l.priority!==-1)){s=n;break}}s===void 0&&(s=n)}else s=c(this.rules,void 0,n=>n.media);if(this.rules.splice(s,0,t),this.ruleOfClass[M]=t,this.style){let n=this.style.sheet,l=0,m=f=>{let h=this.rules[f];if(h){if(!h.natives.length)return m(f-1);let C=h.natives[h.natives.length-1].cssRule;for(let v=0;v<n.cssRules.length;v++)if(n.cssRules[v]===C){l=v+1;break}}};m(s-1);for(let f=0;f<t.natives.length;)try{let h=t.natives[f];n.insertRule(h.text,l),h.cssRule=n.cssRules[l++],f++}catch(h){console.error(h),t.natives.splice(f,1)}}}}get text(){return this.rules.map(e=>e.text).join("")}},W=j;S(W,"root"),S(W,"config",F),S(W,"instances",[]),S(W,"refresh",e=>{for(let t of j.instances)t.refresh(e)});A&&(window.MasterCSS=W);export{W as MasterCSS};
|
|
1
|
+
var $=Object.defineProperty;var D=(O,e,t)=>e in O?$(O,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):O[e]=t;var S=(O,e,t)=>(D(O,typeof e!="symbol"?e+"":e,t),t);function N(O){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&O instanceof e||O instanceof Date||O instanceof RegExp)}function I(O){if(typeof Buffer<"u"&&Buffer&&O instanceof Buffer){let e=Buffer.alloc(O.length);return O.copy(e),e}else{if(O instanceof Date)return new Date(O.getTime());if(O instanceof RegExp)return new RegExp(O);throw new Error("Unexpected situation")}}function B(O){let e=[];return O.forEach(function(t,s){typeof t=="object"&&t!==null?Array.isArray(t)?e[s]=B(t):N(t)?e[s]=I(t):e[s]=k({},t):e[s]=t}),e}function L(O,e){return e==="__proto__"?void 0:O[e]}function k(...O){let e={},t,s;return O.forEach(function(d){typeof d!="object"||d===null||Array.isArray(d)||Object.keys(d).forEach(function(x){if(s=L(e,x),t=L(d,x),t!==e)if(typeof t!="object"||t===null){e[x]=t;return}else if(Array.isArray(t)){e[x]=B(t);return}else if(N(t)){e[x]=I(t);return}else if(typeof s!="object"||s===null||Array.isArray(s)){e[x]=k({},t);return}else{e[x]=k(s,t);return}})}),e}import{Rule as Q}from"./rule.js";import{config as F}from"./config/index.js";import{rgbToHex as z}from"./utils/rgb-to-hex.js";import{SELECTOR_SYMBOLS as H}from"./constants/selector-symbols.js";var A=typeof window<"u",j=class{constructor(e){this.config=e;this.config?.override||(this.config=k(F,e)),this.cache(),A&&this.config.observe&&this.observe(document),j.instances.push(this),this.ready=!0}rules=[];ruleOfClass={};countOfClass={};ready=!1;e=A?new MutationObserver(e=>{let t={},s=[],d=[],x=[],w=(c,n)=>{n?c.classList.forEach(y):c.classList.forEach(g);let l=c.children;for(let m=0;m<l.length;m++){let f=l[m];f.classList&&(d.push(f),w(f,n))}},g=c=>{c in t?t[c]++:t[c]=1},y=c=>{c in t?t[c]--:c in this.countOfClass&&(t[c]=-1)},M=(c,n)=>{for(let l=0;l<c.length;l++){let m=c[l];m.classList&&!d.includes(m)&&!x.includes(m)&&(m.isConnected!==n?(d.push(m),w(m,n)):x.push(m))}};for(let c=0;c<e.length;c++){let n=e[c],{addedNodes:l,removedNodes:m,type:f,target:h}=n;if(f==="attributes"){if(s.find(C=>C.target===h))continue;s.push(n)}else M(l,!1),(!h.isConnected||!d.includes(h))&&M(m,!0)}if(!(!s.length&&!Object.keys(t).length)){for(let{oldValue:c,target:n}of s){let l=d.includes(n),m=n.classList,f=c?c.split(" "):[];if(l){if(n.isConnected)continue;for(let h of f)m.contains(h)||y(h)}else if(n.isConnected){m.forEach(h=>{f.includes(h)||g(h)});for(let h of f)m.contains(h)||y(h)}}for(let c in t){let n=t[c],l=(this.countOfClass[c]||0)+n;l===0?(delete this.countOfClass[c],this.delete(c)):(c in this.countOfClass||this.insert(c),this.countOfClass[c]=l)}}}):null;cache(){this.semantics=[],this.classes={},this.colorThemesMap={},this.relationThemesMap={},this.relations={},this.colorNames=[],this.themeNames=[""],this.selectors={},this.values={},this.globalValues={},this.breakpoints={},this.mediaQueries={},this.matches={};let{semantics:e,classes:t,selectors:s,themes:d,colors:x,values:w,breakpoints:g,mediaQueries:y,rules:M}=this.config;function c(r){return r.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")}function n(r,o,i="",u={}){let a=R=>R?(i?i+"-":"")+R:i,b=Object.entries(r),p=[],T=[];for(let R of b){let E=R[1];(typeof E=="object"&&!Array.isArray(E)?p:T).push(R)}for(let[R,E]of p)n(E,o,a(R),u);if(o&&i)T.length&&(u[i]=T.reduce((R,[E,V])=>(R[E]=V,R),{}));else for(let[R,E]of T)u[a(R)]=E;return u}if(e)for(let[r,o]of Object.entries(n(e,!0)))this.semantics.push([new RegExp("^"+c(r)+"(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)","m"),[r,o]]);if(s)for(let[r,o]of Object.entries(n(s,!1))){let i=new RegExp(c(r)+"(?![a-z-])");for(let u of Array.isArray(o)?o:[o]){let a=u.match(/^::-[a-z]+-/m)?.[0]??"",b=this.selectors[a];b||(b=this.selectors[a]=[]);let p=b.find(([T])=>T===i);p||(p=[i,[]],b.push(p)),p[1].push(u)}}w&&(this.globalValues=n(w,!1)),g&&(this.breakpoints=n(g,!1)),y&&(this.mediaQueries=n(y,!1));let l=t?n(t,!1):{},m=d&&!Array.isArray(d)?Object.entries(d).filter(([,{classes:r}])=>r).reduce((r,[o,{classes:i}])=>(r[o]=n(i,!1),r),{}):{},f=[...Object.keys(l),...Object.entries(m).flatMap(([r,o])=>Object.keys(o))],h=r=>{if(r in this.classes)return;let o=this.classes[r]=[],i=(u,a)=>{if(!a)return;let b=Array.isArray(a)?a:a.replace(/(?:\n(?:\s*))+/g," ").trim().split(" ");for(let p of b){let T=R=>{R in this.relationThemesMap?u in this.relationThemesMap[R]?this.relationThemesMap[R][u].push(r):this.relationThemesMap[R][u]=[r]:this.relationThemesMap[R]={[u]:[r]},o.includes(R)||o.push(R)};if(f.includes(p)){h(p);for(let R of this.classes[p])T(R)}else T(p)}};i("",l?.[r]);for(let[u,a]of Object.entries(m))i(u,a?.[r])};for(let r of f)h(r);for(let r in this.relationThemesMap){let o=this.relations[r]=[];for(let i of Object.values(this.relationThemesMap[r]))for(let u of i)o.includes(u)||o.push(u)}let C=(r,o)=>{if(!o)return;let i=n(o,!0);for(let[u,a]of Object.entries(i)){let b=typeof a=="string"?{"":a}:a;for(let[p,T]of Object.entries(b)){let R=u+(p?"-"+p:"");R in this.colorThemesMap?this.colorThemesMap[R][r]=T:this.colorThemesMap[R]={[r]:T}}}for(let u in o)this.colorNames.includes(u)||this.colorNames.push(u)};if(C("",x),d)if(Array.isArray(d))this.themeNames.push(...d);else for(let r in d){let o=d[r];C(r,o.colors),this.themeNames.push(r)}let v=r=>{for(let[o,i]of Object.entries(this.colorThemesMap))for(let[u,a]of Object.entries(i))a.startsWith("#")||r(o,i,u,a)};if(v((r,o,i,u)=>{let a=/^rgba?\( *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?: |,) *([0-9]{1,3}) *(?:(?:\/|,) *0?(\.[0-9]))?\)$/.exec(u);if(a){let b="#"+z(+a[1],+a[2],+a[3]);a[4]&&(b+=Math.round(255*+a[4]).toString(16)),o[i]=b}}),v((r,o,i,u)=>{let[a,b]=u.split("/"),p=this.colorThemesMap[a];if(p){let T=(i?p[i]:void 0)??p[""];o[i]=b?T.slice(0,7)+Math.round(255*+b).toString(16):T}else console.warn(`\`${u}\` doesn't exist in the extended config \`.colors\``),delete o[i],Object.keys(o).length||delete this.colorThemesMap[r]}),M)for(let r in M){let o=M[r],{matches:i,prop:u,values:a}=o;if(o.id=r,o.prop=u===!1?"":r.replace(/(?!^)[A-Z]/g,b=>"-"+b).toLowerCase(),a&&(this.values[r]=n(a,!1)),i){let b=Object.keys(this.values[r]??{}),p=i.indexOf("$values");this.matches[r]=new RegExp(p===-1?i:b.length?i.slice(0,p)+b.join("|")+i.slice(p+7):i.slice(0,p-(i[p-1]==="|"?1:0))+i.slice(p+7+(i[p+7]==="|"?1:0)))}}}observe(e,t={subtree:!0,childList:!0}){if(A&&e){this.root=e;let s=e===document;s&&(j.root=this),this.host=s?document.documentElement:root.host;let d=s?document.head:e,x=s?document.styleSheets:e.styleSheets;for(let g of x){let{title:y,href:M,ownerNode:c}=g;(y==="master"||M&&M.startsWith(window.location.origin)&&/master(?:\..+)?\.css/.test(M))&&(this.style=c)}if(this.style)for(let g=0;g<this.style.sheet.cssRules.length;g++){let y=c=>{if(c.selectorText){let l=c.selectorText.split(", ")[0].split(" ");for(let m=0;m<l.length;m++){let f=l[m];if(f[0]==="."){let h=f.slice(1),C="";for(let v=0;v<h.length;v++){let r=h[v],o=h[v+1];if(r==="\\"){if(v++,o!=="\\"){C+=o;continue}}else if(H.includes(r))break;C+=r}if(!(C in this.ruleOfClass)&&!(C in this.classes)){let v=this.create(C)[0];if(v)return v}}}}else if(c.cssRules)for(let n=0;n<c.cssRules.length;n++){let l=y(c.cssRules[n]);if(l)return l}},M=y(this.style.sheet.cssRules[g]);if(M){this.rules.push(M),this.ruleOfClass[M.className]=M;for(let c=0;c<M.natives.length;c++)M.natives[c].cssRule=this.style.sheet.cssRules[g+c];g+=M.natives.length-1}}else{this.style=document.createElement("style"),this.style.title="master";let g=d.querySelector('link[rel="styleSheet"], style');g?g.before(this.style):d.append(this.style)}let w=g=>{g.forEach(y=>{y in this.countOfClass?this.countOfClass[y]++:(this.countOfClass[y]=1,this.insert(y))})};w(this.host.classList),t.subtree&&this.host.querySelectorAll("[class]").forEach(g=>w(g.classList)),this.e.observe(e,{...t,attributes:!0,attributeOldValue:!0,attributeFilter:["class"]})}return this}disconnect(){this.e.disconnect(),this.ruleOfClass={},this.countOfClass={},this.rules.length=0;let e=this.style.sheet;if(e)for(let t=e.cssRules.length-1;t>=0;t--)e.deleteRule(t);this.style.remove(),this.style=null}match(e){for(let t in this.config.rules){let s=this.config.rules[t],d=this.matches[t],{colorStarts:x,symbol:w,prop:g}=s,{colorNames:y,colorThemesMap:M}=this;if(d&&d.test(e))return{origin:"matches",config:s};if(x){if(e.match("^"+x+"(?:(?:#|(rgb|hsl)\\(.*\\))((?!\\|).)*$|(?:transparent|current|inherit))"))return{origin:"matches",config:s};if(y.length&&e.indexOf("|")===-1){let c=e.match("^"+x+"((?:"+y.join("|")+")[0-9a-zA-Z-]*)");if(c&&c[1]in M)return{origin:"matches",config:s}}}if(w&&e.startsWith(w))return{origin:"symbol",config:s};if(g&&e.startsWith(g+":"))return{origin:"matches",config:s}}for(let t of this.semantics)if(e.match(t[0]))return{origin:"semantics",value:t[1]}}create(e){let t=s=>{if(s in this.ruleOfClass)return this.ruleOfClass[s];let d=this.match(s);if(d)return new Q(s,d,this)};return(e in this.classes?this.classes[e].map(s=>t(s)):[t(e)]).filter(s=>s&&s.text)}refresh(e){if(e?.override?this.config=e:this.config=k(F,e),this.cache(),!this.style)return;let t=document.createElement("style");t.title="master",this.style.replaceWith(t),this.style=t,this.rules.length=0,this.ruleOfClass={};for(let s in this.countOfClass)this.insert(s)}destroy(){let e=j.instances;this.disconnect(),e.splice(e.indexOf(this),1)}delete(e){let t=this.style.sheet,s=d=>{let x=this.ruleOfClass[d];if(!(!x||d in this.relations&&this.relations[d].some(w=>w in this.countOfClass))){if(x.natives.length){let w=x.natives[0];for(let g=0;g<t.cssRules.length;g++)if(t.cssRules[g]===w.cssRule){for(let M=0;M<x.natives.length;M++)t.deleteRule(g);this.rules.splice(this.rules.indexOf(x),1);break}}delete this.ruleOfClass[d]}};if(e in this.classes){for(let d of this.classes[e])d in this.countOfClass||s(d);delete this.ruleOfClass[e]}else s(e)}insert(e){let t=this.create(e);return t.length?(this.insertRules(t),!0):!1}insertRules(e){for(let t of e){if(this.ruleOfClass[t.className])continue;let s,d=this.rules.length-1,{media:x,order:w,priority:g,hasWhere:y,className:M}=t,c=(n,l,m,f)=>{let h=0,C;l&&(h=n.findIndex(l)),m&&(C=n.findIndex(m)),h===-1&&(h=n.length),(C===void 0||C===-1)&&(C=n.length);let v=n.slice(h,C);for(let r=0;r<v.length;r++){let o=v[r];if(!(o.priority===-1||f&&f(o))&&(o.priority<g||o.priority===g&&(y&&!o.hasWhere||o.order>=w)))return h+r}return h+v.length};if(x){let n=this.rules.findIndex(l=>l.media);if(n!==-1){let l=x.features["max-width"],m=x.features["min-width"];if(l&&m){let f=l.value-m.value;for(let h=d;h>=n;h--){s=h;let C=this.rules[h],v=C.media,r=v.features["max-width"],o=v.features["min-width"];if(!r||!o){s++;break}let i=r.value-o.value;if(i===f){if(y!==C.hasWhere)continue;if(g!==-1){let u=[this.rules[h]];for(let a=h-1;a>=n;a--){let b=this.rules[a];if(b.hasWhere!==y)break;let p=b.media,T=p.features["max-width"],R=p.features["min-width"];if(!T||!R||T.value-R.value!==i)break;u.unshift(this.rules[a])}s=c(this.rules,a=>a.media&&a.priority!==-1&&a.media.features["min-width"]&&a.media.features["max-width"])}break}else if(i>f)break}}else if(m)for(let f=n;f<=d;f++){s=f;let h=this.rules[f],C=h.media,v=C.features["max-width"],r=C.features["min-width"];if(v){if(r)break;continue}let o=r?.value;if(o===m.value){if(!y&&h.hasWhere){s++;continue}if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else for(let i=f;i<=d;i++){let u=this.rules[i],a=u.media,b=a.features["min-width"];if(!a.features["max-width"]){if(u.hasWhere!==y||b.value!==o||u.order>=w)break;s=i+1}}break}else{if(o>m.value)break;s++}}else if(l)for(let f=d;f>=n;f--){s=f;let h=this.rules[f],C=h.media,v=C.features["max-width"];if(C.features["min-width"])continue;let o=v?.value;if(!o||o>l.value){s++;break}else if(o===l.value){if(y&&!h.hasWhere)continue;if(g!==-1)s=c(this.rules,i=>i.media,i=>i.media&&i.priority!==-1&&i.media.features["min-width"]&&i.media.features["max-width"],i=>!i.media.features["min-width"]&&!i.media.features["max-width"]);else{let i=[this.rules[f]];for(let u=f-1;u>=n;u--){let a=this.rules[u],b=a.media,p=b.features["min-width"],T=b.features["max-width"];if(!p&&(!T||T.value!==o||a.hasWhere!==y))break;i.unshift(a)}for(let u=0;u<i.length;u++){let a=i[u];if(!a.media.features["min-width"]){if(a.order>=w)break;s=f-i.length+2+u}}}break}}}if(s===void 0)if(n===-1)s=d+1;else if(g!==-1)s=n+c(this.rules.slice(n),void 0,l=>l.media.features["max-width"]||l.media.features["min-width"]);else if(y){let l=n;for(;l<this.rules.length;l++){let m=this.rules[l];if(m.priority!==-1||!m.hasWhere||m.order>=w){s=l;break}}s===void 0&&(s=l)}else for(let l=n;l<=d;l++){s=l;let m=this.rules[l],f=m.media;if(m.priority!==-1||f.features["max-width"]||f.features["min-width"])break;if(m.hasWhere)s++;else if(m.order>=w)break}}else if(g===-1)if(y)s=this.rules.findIndex(n=>!n.hasWhere||n.media||n.priority!==-1||n.order>=w),s===-1&&(s=d+1);else{let n=0;for(;n<this.rules.length;n++){let l=this.rules[n];if(l.media||!l.hasWhere&&(l.order>=w||l.priority!==-1)){s=n;break}}s===void 0&&(s=n)}else s=c(this.rules,void 0,n=>n.media);if(this.rules.splice(s,0,t),this.ruleOfClass[M]=t,this.style){let n=this.style.sheet,l=0,m=f=>{let h=this.rules[f];if(h){if(!h.natives.length)return m(f-1);let C=h.natives[h.natives.length-1].cssRule;for(let v=0;v<n.cssRules.length;v++)if(n.cssRules[v]===C){l=v+1;break}}};m(s-1);for(let f=0;f<t.natives.length;)try{let h=t.natives[f];n.insertRule(h.text,l),h.cssRule=n.cssRules[l++],f++}catch(h){console.error(h),t.natives.splice(f,1)}}}}get text(){return this.rules.map(e=>e.text).join("")}},W=j;S(W,"root"),S(W,"config",F),S(W,"instances",[]),S(W,"refresh",e=>{for(let t of j.instances)t.refresh(e)});A&&(window.MasterCSS=W);export{W as MasterCSS};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MasterCSS as e}from"./css.js";new e(window.masterCSSConfig);
|
|
1
|
+
import{MasterCSS as e}from"./css.js";import{Theme as a}from"./theme.js";new e(window.masterCSSConfig);new a(window.masterCSSThemeSettings);
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./css.js";export*from"./rule.js";export*from"./theme.js";import{MasterCSS as
|
|
1
|
+
export*from"./css.js";export*from"./rule.js";export*from"./theme.js";import{MasterCSS as E}from"./css.js";function a(t){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&t instanceof e||t instanceof Date||t instanceof RegExp)}function l(t){if(typeof Buffer<"u"&&Buffer&&t instanceof Buffer){let e=Buffer.alloc(t.length);return t.copy(e),e}else{if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t);throw new Error("Unexpected situation")}}function c(t){let e=[];return t.forEach(function(r,n){typeof r=="object"&&r!==null?Array.isArray(r)?e[n]=c(r):a(r)?e[n]=l(r):e[n]=u({},r):e[n]=r}),e}function i(t,e){return e==="__proto__"?void 0:t[e]}function u(...t){let e={},r,n;return t.forEach(function(o){typeof o!="object"||o===null||Array.isArray(o)||Object.keys(o).forEach(function(f){if(n=i(e,f),r=i(o,f),r!==e)if(typeof r!="object"||r===null){e[f]=r;return}else if(Array.isArray(r)){e[f]=c(r);return}else if(a(r)){e[f]=l(r);return}else if(typeof n!="object"||n===null||Array.isArray(n)){e[f]=u({},r);return}else{e[f]=u(n,r);return}})}),e}export*from"./methods/index.js";export*from"./config/index.js";export{E as default,u as extend};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./render.js";export*from"./render-from-html.js";export*from"./render-into-html.js";export*from"./fill-color-scale.js";export*from"./define-content.js";
|
|
1
|
+
export*from"./render.js";export*from"./render-from-html.js";export*from"./render-into-html.js";export*from"./fill-color-scale.js";export*from"./define-content.js";
|
package/dist/esm/theme.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function c(s){let e=typeof Buffer<"u"?Buffer:null;return!!(e&&s instanceof e||s instanceof Date||s instanceof RegExp)}function h(s){if(typeof Buffer<"u"&&Buffer&&s instanceof Buffer){let e=Buffer.alloc(s.length);return s.copy(e),e}else{if(s instanceof Date)return new Date(s.getTime());if(s instanceof RegExp)return new RegExp(s);throw new Error("Unexpected situation")}}function l(s){let e=[];return s.forEach(function(t,i){typeof t=="object"&&t!==null?Array.isArray(t)?e[i]=l(t):c(t)?e[i]=h(t):e[i]=o({},t):e[i]=t}),e}function a(s,e){return e==="__proto__"?void 0:s[e]}function o(...s){let e={},t,i;return s.forEach(function(n){typeof n!="object"||n===null||Array.isArray(n)||Object.keys(n).forEach(function(r){if(i=a(e,r),t=a(n,r),t!==e)if(typeof t!="object"||t===null){e[r]=t;return}else if(Array.isArray(t)){e[r]=l(t);return}else if(c(t)){e[r]=h(t);return}else if(typeof i!="object"||i===null||Array.isArray(i)){e[r]=o({},t);return}else{e[r]=o(i,t);return}})}),e}var u={store:"theme",init:!0},d=typeof document<"u",f=typeof localStorage<"u",m=class{constructor(e,t=d?document.documentElement:null){this.settings=e;this.host=t;this.settings=e?o(u,e):u,this.settings.init&&this.init()}e=typeof matchMedia<"u"?matchMedia?.("(prefers-color-scheme:dark)"):void 0;s;t;init(){let e=this.settings.default,t=this.storage;t&&(e=t),this.value=e}get storage(){let{store:e}=this.settings;if(f&&e)return localStorage.getItem(e)}get systemValue(){return this.e.matches?"dark":"light"}set value(e){this.s=e,e==="system"?(this.e?.addEventListener?.("change",this.i),this.current=this.systemValue):(this.r(),this.current=e)}get value(){return this.s}set current(e){let t=this.t;this.t=e,this.host&&(t&&this.host.classList.remove(t),this.host.classList.contains(e)||(this.host.classList.add(e),this.host.style&&(this.host.style.colorScheme=e)))}get current(){return this.t}switch(e,t={store:!0,emit:!0}){e&&e!==this.value&&(this.value=e,f&&this.storage!==e&&this.settings.store&&localStorage.setItem(this.settings.store,e),t.emit&&this.host.dispatchEvent(new CustomEvent("theme",{detail:this})))}r(){this.e?.removeEventListener("change",this.i)}i=e=>{this.current=e.matches?"dark":"light"};destroy(){this.r()}};function y(s){return s=Object.assign({store:"theme"},s),`let e${s.default?`='${s.default}'`:""};const c=localStorage.getItem("${s.store}");c&&(e=c);let t=e;e==="system"&&(t=matchMedia("(prefers-color-scheme:dark)").matches?"dark":"light");const s=document.documentElement;s.classList.add(t);s.style.colorScheme=t;`}export{m as Theme,y as getDocThemeInitScript,u as themeSettings};
|