UNPKG

zaftig

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