UNPKG

zaftig

Version:
2 lines 4.47 kB
const{isArray:t}=Array,{hasOwnProperty:r,getPrototypeOf:e}=Object,n=(...t)=>console.error("zaftig:",...t),o=(t,r={})=>e=>e in r?r[e]:r[e]=t(e),i=document.documentMode||/Edge\//.test(navigator.userAgent)?"ms":navigator.vendor?"webkit":"moz",s=t=>r.call(t,"width")?t:s(e(t)),c=Object.keys(s(document.documentElement.style)).filter((t=>t.indexOf("-")<0&&"length"!=t)),a={},u={};c.concat(["backgroundColor","borderBottom","borderRadius","bottom","boxShadow","color","display","flexDirection","float","fontFamily","fontSize","height","margin","marginTop","marginBottom","opacity","padding","paddingBottom","right","textAlign","textDecoration","top","whiteSpace","width"].filter((t=>c.indexOf(t)>=0))).forEach((t=>{let r=t.replace(/[A-Z]/g,(t=>"-"+t.toLowerCase()));let e=(n=t)[0]+n.slice(1).replace(/[a-z]/g,"").toLowerCase();var n;0==t.toLowerCase().indexOf(i)?(e=e.slice(1),r="-"==r[0]?r:"-"+r,u[e]||(u[e]=r)):u[e]=r,a[r]=!0}));const d=document.createElement("div"),l=o((t=>["0","0 0"].some((r=>(d.style.cssText=`${t}: ${r};`,"px;"==d.style.cssText.slice(-3))))),{flex:!1,border:!0,"border-left":!0,"border-right":!0,"border-top":!0,"border-bottom":!0}),f=/\s*,\s*/,g=(t,r)=>t&&r?`\n${t} {\n${r}}\n`:"",m=r=>function(e,...o){try{return t(e)?r.call(this,((t,r)=>t.reduce(((t,e,n)=>t+e+(null==r[n]?"":String(r[n]))),""))(e,o)):r.call(this,e)}catch(t){return n("error `",e,"`",o,"\n",t),""}},h=()=>document.head.appendChild(document.createElement("style"));let p;const $=(t,r="")=>{try{p&&p.sheet||(p=h()),p.sheet.insertRule(`${t}{${r}}`,0);const e=r&&p.sheet.cssRules[0].cssText.replace(/\s/g,"");return p.sheet.deleteRule(0),!e||e.length>t.length+2}catch(t){return!1}},y=(t={})=>{const{helpers:r={},unit:e="px",id:s="z"+Math.random().toString(36).slice(2)}=t;let{style:c,dot:d=!0,debug:p=!1}=t,b=0;class v{constructor(t){this.class=t,this.className=t}toString(){return this.class}valueOf(){return d?"."+this.class:this.class}z(...t){return this.concat(B(...t))}concat(...t){return z(this.class,...t)}}const z=(...t)=>{const r=[];return t.forEach((t=>{t&&("string"==typeof t?r.push(t):t.className&&r.push(t.className))})),new v(r.join(" "))},w=(t,r,e)=>{const o=g(e?(t=>t.replace(/(::?)([a-z-]+)(\()?/gi,((t,r,e,n)=>("placeholder"==e&&"moz"!=i?e="input-"+e:"matches"==e&&(e="any"),"-"==e[0]||$(n?t+".f)":t)?t:`${r}-${i}-${e}${n||""}`))))(t):t,r);if(o){c||(c=h(),c.id=s);try{c.sheet.insertRule(o,c.sheet.cssRules.length),p&&(c.textContent+=o)}catch(o){!e&&t.indexOf(":")>=0?w(t,r,!0):n("insert failed",t,r,o)}}},x=t=>t.replace(/^/gm," ")+"\n",O=(t,r,e="",o)=>{if(!t)return p&&n("missing selector",r);if(/^@(media|keyframes|supports)/.test(t))return((t,r,e,n)=>{r.t=g(""==e?":root":e,r.t),r.o.forEach((t=>O(t.i,t,e,r))),n?n.t+=g(t,x(r.t)):w(t,x(r.t))})(t,r,e,o);!e||o&&(t=>t&&0==t.indexOf("@keyframes"))(o.i)||(t=((t,r)=>r.split(f).reduce(((r,e)=>r.concat(t.split(f).map((t=>t.indexOf("&")>=0?t.replace(/&/g,e):e+(":"==t[0]||"["==t[0]?"":" ")+t)))),[]).join(",\n"))(t,e)),o?o.t+=g(t,r.t):w(t,r.t);const i=":root"==t?"":t;r.o.forEach((t=>O(t.i,t,i,o)))},k=(t,e)=>{const n=r[t];return"function"==typeof n?n(...e?e.split(" "):[]):n&&n+" "+e},S=(t,r,o)=>{if(o&&!r&&(r=o,o=""),!r)return;if("$"==r[0]){if("$name"==r)return t.u=o;if("$compose"==r)return t.l=o;r="--"+r.slice(1)}const c=k(r,o);if(c){const r=_(c);return t.t+=r.t,void(t.o=t.o.concat(r.o))}if(!o)return p&&n("no value for",r);if(r=u[r]||r,!a[r]){const t=`-${i}-${r}`;a[t]&&(r=t)}o.indexOf("$")>=0&&(o=o.replace(/\$([a-z0-9-]+)/gi,"var(--$1)")),l(r)&&(o=o.split(" ").map((t=>isNaN(t)?t:t+e)).join(" "));const d=` ${r}: ${o};\n`;p&&!$(s,d)&&n("invalid css",d),t.t+=d},_=o((t=>{const r=[{t:"",o:[]}];if(!(t=t&&t.trim()))return r[0];t+=";";let e=1,n="",o=0,i="",s="";for(let c=0;c<t.length;c++){const a=t[c];"\n"!=a&&(";"!=a&&"}"!=a||i)?"{"!=a||i?1==e?" "==a?(s=n.trim())&&(e=2,n=""):n+=a:2==e&&(i?a==i&&"\\"!=t[c-1]&&(i=""):"'"!=a&&'"'!=a||(i=a),n+=a):(r[++o]={i:k(s,n.trim())||(s+" "+n).trim(),t:"",o:[]},e=1,s=n=""):(S(r[o],s,n.trim()+i),"}"==a&&r[--o].o.push(r.pop()),e=1,s=n=i="")}return r[0]})),A=o((t=>{const r="anim-"+s+"-"+(b+=1);return O("@keyframes "+r,_(t)),r})),j=o((t=>{const r=_(t),e=(r.u?r.u+"-":"")+s+"-"+(b+=1);return O("."+e,r),new v(e+(r.l?" "+r.l:""))})),B=m(j);return B.anim=m(A),B.concat=z,B.getSheet=()=>c,B.global=m((t=>O(":root",_(t)))),B.helper=t=>Object.assign(r,t),B.new=y,B.setDebug=t=>p=t,B.setDot=t=>d=t,B.style=m((t=>_(t).t)),B};export default y(); //# sourceMappingURL=zaftig.min.js.map