forked from snejugal/attheme-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattheme.min.js
5 lines (5 loc) · 1.62 KB
/
attheme.min.js
1
2
3
4
5
"use strict";class Attheme{constructor(b,a){let y=Attheme,z=this;if(!b){b=""}b=y._d(b);if(a){let c,d="defaultVariablesValues",w=window;if(typeof a=="object"){c=a}else if(w[d]){c=w[d]}else{throw new Error("`fillWithefaults` option is set to true, but `defaultVariablesValues` is not defined outside.\nIf defaults values are defined another way, pass them instead of `fillWithDefaults`")}for(let e in c){z[e]=c[e]}}for(let e in b){z[e]=b[e]}let f=y.IMAGE_KEY;if(b[f]){z[f]=b[f]}}asText(a){return Attheme.asText(this,a)}static asText(a,b){const c=n=>n.toString(16).padStart(2,"0"),d=n=>parseInt(n,16);let e="",z="length";for(let f in a){const g=c(a[f].red),h=c(a[f].green),i=c(a[f].blue),j=c(a[f].alpha),k=`#${j=="ff"?"":j}${g}${h}${i}`,l=(d(`${j}${g}${h}${i}`)<<0)+"";let m;if(!b||b=="auto"){if(k[z]>=l[z]){m=l}else{m=k}}else if(b=="hex"){m=k}else if(b=="int"){m=l}else{throw new Error("The `shorthand` option value is invalid")}e+=`${f}=${m}
`}const g=a[Attheme.IMAGE_KEY];if(g){e+=`WPS
${g}
WPE
`}return e}static _d(a=""){if(typeof a!="string"){throw new Error("Attheme.parseText requires a string");return}const z="padStart",y="slice",x="split",b=n=>n.toString(16)[z](2,"0"),c=n=>parseInt(n,16),d=a[x]("\n");let e={};for(let i=0;i<d.length;i++){let f=d[i];if(~f.indexOf("//")){f=f[x]("//")[0]}f=f.trim();if(f=="WPS"){e[Attheme.IMAGE_KEY]=d[y](i+1,-2).join("\n");break}if(!f||!/=/.test(f)){continue}const[h,j]=f[x]("=");let k=null;if(!j.startsWith("#")){k=b(parseInt(j)>>>0)[z](8,"0")}else{k=j[y](1)[z](8,"f")}k={red:c(k[y](2,4)),green:c(k[y](4,6)),blue:c(k[y](6,8)),alpha:c(k[y](0,2))};e[h]=k}return e}static get IMAGE_KEY(){return Symbol.for("image")}}