-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcore-min.js
1 lines (1 loc) · 7.63 KB
/
core-min.js
1
!function(){"use strict";var e={},t=["woff","woff2","ttf"],n,o=document.createElement("style"),a,i=[],r,c="",d=[],s={},l=2e3,u=" ",f="\n",m=function(e,t){var n=1024,o=1024*n,a=1024*o,i=1024*a;return e>=0&&n>e?e+" B":e>=n&&o>e?(e/n).toFixed(t)+" KB":e>=o&&a>e?(e/o).toFixed(t)+" MB":e>=a&&i>e?(e/a).toFixed(t)+" GB":e>=i?(e/i).toFixed(t)+" TB":e+" B"},p=function(e){return encodeURI(e).split(/%..|./).length-1},h=function(e){o.innerHTML=e},v=function(e){e.stopPropagation(),e.preventDefault(),e.target.className="dragover"===e.type?"hover":""},y=function(e){return-1===t.indexOf(e.split(".").pop().toLowerCase())?!1:d.some(function(t){return t.filename===e})?!1:!0},g=function(e){switch(e){case"ttf":return"application/x-font-ttf";case"woff":return"application/font-woff";case"woff2":return"application/font-woff2";case"svg":return"image/svg+xml";default:return"font/truetype"}},w=function(e){switch(e){case"ttf":return"truetype";case"woff":return"woff";case"woff2":return"woff2";case"svg":return"svg";case"eot":return"eot";default:return"truetype"}},E=function(e){var t=e.replace(/\..+$/,"");return t=t.replace(/(bold)/i,""),t=t.replace(/-/g,"")},L=function(e){var t=500;return/(light)|(thin)/i.test(e)&&(t=300),/(book)/i.test(e)&&(t=400),/(demi)|(semi)/i.test(e)&&(t=600),/(bold)/i.test(e)&&(t=700),/(heavy)|(extrabold)/i.test(e)&&(t=800),t},B=function(e,t){return e.weight-t.weight?e.weight-t.weight:e.style>t.style?-1:e.style<t.style?1:void 0},S=function(e){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n="",o=0,a=e.length,i,r,c;a>o;){if(i=255&e.charCodeAt(o++),o===a){n+=t.charAt(i>>2),n+=t.charAt((3&i)<<4),n+="==";break}if(r=e.charCodeAt(o++),o===a){n+=t.charAt(i>>2),n+=t.charAt((3&i)<<4|(240&r)>>4),n+=t.charAt((15&r)<<2),n+="=";break}c=e.charCodeAt(o++),n+=t.charAt(i>>2),n+=t.charAt((3&i)<<4|(240&r)>>4),n+=t.charAt((15&r)<<2|(192&c)>>6),n+=t.charAt(63&c)}return n},_=function(){var e="",t=u,n=f;c="",document.getElementById("nominifycss").checked||(t="",n=""),d.forEach(function(o,a){c+="@font-face{"+n+t+"font-family: '"+r.value+"';"+n+t+"font-weight: "+o.weight+";"+n+t+"font-style: "+o.style+";"+n+t+"src:url(data:"+o.mime+";charset=utf-8;base64,"+o.base64+") format('"+o.format+"');"+n+"}"+n,e+="."+o.style+a+o.weight+o.extension+"{"+t+"font-family: '"+r.value+"', serif;"+n+t+"font-weight: "+o.weight+";"+n+t+"font-style: "+o.style+";"+n+"}"}),document.getElementById("outputcss").value=c,document.getElementById("csssize").innerHTML="("+m(p(c))+")",h(c+e),document.querySelector(".fontform").classList.add("done"),document.querySelector(".output-wrap").classList.add("done"),document.querySelector("body").classList.add("done")},T=function(e,t,n){"familyname"===t?_():d[e][t]!==n.value&&(d[e][t]=n.value,b())},x=function(){clearTimeout(s)},k=function(e,t,n){x(),s=setTimeout(function(){T(e,t,n)},l)},I=function(){document.querySelector(".fontform").classList.remove("done"),document.querySelector(".output-wrap").classList.remove("done"),document.querySelector("body").classList.remove("done"),setTimeout(function(){d=[],b(),document.querySelector(".fontform").classList.remove("done"),document.querySelector(".output-wrap").classList.remove("done"),document.querySelector("body").classList.remove("done"),document.getElementById("font_family").innerHTML="",document.getElementById("csssize").innerHTML="",r=void 0,n.innerHTML="/font.css",F()},900)},b=function(){var e=[];d.constructor===Array&&(e=d.splice()),d.sort(B),e.length&&e===d||(A(),_())},A=function(){a.innerHTML="",d.forEach(function(e,t){var n=document.createElement("div");n.classList.add("font");var o=document.createElement("div");o.classList.add("font__demo"),o.innerHTML="Demo: "+e.filename+" - Lorem ipsum dolor sit amet, consectetur adipiscing elit.";var i=document.createElement("input");i.classList.add("field"),i.value=e.mime,i.addEventListener("keyup",function(){k(t,"mime",this)},!1),i.addEventListener("keydown",x,!1);var r=document.createElement("input");r.classList.add("field"),r.placeholder="normal",r.value=e.style,r.addEventListener("keyup",function(){k(t,"style",this)},!1),r.addEventListener("keydown",x,!1);var c=document.createElement("input");c.classList.add("field"),c.type="number",c.step=100,c.placeholder="500",c.value=e.weight,c.addEventListener("keyup",function(){k(t,"weight",this)},!1),c.addEventListener("keydown",x,!1);var s=document.createElement("button");s.classList.add("field"),s.innerHTML="Remove",s.addEventListener("click",function(){this.parentNode.parentNode.removeChild(this.parentNode),d.indexOf(e)>-1&&d.splice(d.indexOf(e),1),b(),0===d.length&&I()}),n.classList.add(e.style+t+e.weight+e.extension),n.appendChild(o),n.appendChild(i),n.appendChild(c),n.appendChild(r),n.appendChild(s),e.data=n,a.appendChild(e.data)})},C=function(){r||(r=document.createElement("input"),r.placeholder="Set to localFont for extra fun.",r.value=E(d[0].filename)||"Family name",r.addEventListener("keyup",function(){k(0,"familyname",this)},!1),r.addEventListener("keydown",x,!1),document.getElementById("font_family").appendChild(r)),b()},M=function(t){return t<d.length?(e.onload=function(e){var n=e.target.result;d[t].base64=S(n),M(t+1)},void e.readAsBinaryString(d[t].file)):t===d.length?void C():void 0},q=function(e){var t={file:e,filename:e.name,extension:e.name.split(".").pop(),style:/(italic)/i.test(e.name)?"italic":"normal",weight:L(e.name)};t.mime=g(t.extension),t.format=w(t.extension),d.push(t)},H=function(t){var n=d.length||0,o=!1;if(a=document.getElementById("font_list"),v(t),i=t.dataTransfer.files){e=new FileReader;for(var r=0;r<i.length;r++)y(i[r].name)&&(q(i[r]),o=!0);o&&M(n)}},F=function(){document.getElementById("pathspan").innerHTML=n.value,/\.(css)$/i.test(n.value)?document.getElementById("outputjs").value='<script type="text/javascript">!function(){"use strict";function e(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,n)}function t(e){return window.localStorage&&localStorage.font_css_cache&&localStorage.font_css_cache_file===e}function n(){if(window.localStorage&&window.XMLHttpRequest)if(t(o))c(localStorage.font_css_cache);else{var n=new XMLHttpRequest;n.open("GET",o,!0),e(n,"load",function(){4===n.readyState&&(c(n.responseText),localStorage.font_css_cache=n.responseText,localStorage.font_css_cache_file=o)}),n.send()}else{var a=document.createElement("link");a.href=o,a.rel="stylesheet",a.type="text/css",document.getElementsByTagName("head")[0].appendChild(a),document.cookie="font_css_cache"}}function c(e){var t=document.createElement("style");t.innerHTML=e,document.getElementsByTagName("head")[0].appendChild(t)}var o="/'+n.value+'";window.localStorage&&localStorage.font_css_cache||document.cookie.indexOf("font_css_cache")>-1?n():e(window,"load",n)}();</script><noscript><link rel="stylesheet" href="/'+n.value+'"></noscript>':document.getElementById("outputjs").value="I need a *.css file in order to work!"},N=function(){document.getElementsByTagName("head")[0].appendChild(o),document.getElementById("filedrag").addEventListener("dragover",v,!1),document.getElementById("filedrag").addEventListener("dragleave",v,!1),document.getElementById("fileselect").addEventListener("change",H,!1),document.getElementById("filedrag").addEventListener("drop",H,!1),document.getElementById("nominifycss").addEventListener("change",_,!1),document.getElementById("clearAll").addEventListener("click",I,!1),n=document.getElementById("css_path"),n.addEventListener("keyup",F,!1),document.querySelector(".fontform").classList.add("hidden"),document.querySelector(".output-wrap").classList.add("hidden")};document.addEventListener("DOMContentLoaded",function(){window.File&&window.FileReader&&window.FileList&&window.Blob?N():window.alert("The File APIs are not fully supported in this browser.")})}();