-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathautofit.min.js
1 lines (1 loc) · 5.43 KB
/
autofit.min.js
1
!function(t,e){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).autofit=e()}(this,(function(){"use strict";function t(t,n){var o="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!o){if(Array.isArray(t)||(o=function(t,n){if(t){if("string"==typeof t)return e(t,n);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,n):void 0}}(t))||n&&t&&"number"==typeof t.length){o&&(t=o);var i=0,r=function(){};return{s:r,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l,c=!0,a=!1;return{s:function(){o=o.call(t)},n:function(){var t=o.next();return c=t.done,t},e:function(t){a=!0,l=t},f:function(){try{c||null==o.return||o.return()}finally{if(a)throw l}}}}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=null,i="",r="",l="",c=null,a=null,u=1,s=!1,f={isAutofitRunnig:!1,init:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(!(arguments.length>1&&void 0!==arguments[1])||arguments[1])&&console.log("autofit.js is running");var e=t.dw,n=void 0===e?1920:e,u=t.dh,f=void 0===u?1080:u,y=t.el,h=void 0===y?"string"==typeof t?t:"body":y,v=t.resize,g=void 0===v||v,p=t.ignore,b=void 0===p?[]:p,S=t.transition,w=void 0===S?"none":S,A=t.delay,x=void 0===A?0:A,j=t.limit,T=void 0===j?.1:j,M=t.cssMode,q=void 0===M?"scale":M,z=t.allowScroll,H=void 0!==z&&z;o=h;var R=document.querySelector(h);if(R){var E=document.createElement("style"),L=document.createElement("style");E.lang="text/css",L.lang="text/css",E.id="autofit-style",L.id="ignoreStyle",!H&&(E.innerHTML="body {overflow: hidden;}");var N=document.querySelector("body");N.appendChild(E),N.appendChild(L),R.style.height="".concat(f,"px"),R.style.width="".concat(n,"px"),R.style.transformOrigin="0 0",!H&&(R.style.overflow="hidden"),m(n,f,R,b,T,q),c=function(){clearTimeout(a),0!=x?a=setTimeout((function(){m(n,f,R,b,T,q),s&&d(i,l,r)}),x):(m(n,f,R,b,T,q),s&&d(i,l,r))},g&&window.addEventListener("resize",c),this.isAutofitRunnig=!0,setTimeout((function(){R.style.transition="".concat(w,"s")}))}else console.error("autofit: '".concat(h,"' is not exist"))},off:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"body";try{var e;window.removeEventListener("resize",c),null===(e=document.querySelector("#autofit-style"))||void 0===e||e.remove();var n=document.querySelector("#ignoreStyle");n&&n.remove();var i=document.querySelector(o||t);i&&(i.style=""),s&&y()}catch(t){console.error("autofit: Failed to remove normally",t),this.isAutofitRunnig=!1}this.isAutofitRunnig&&console.log("autofit.js is off")},elRectification:null};function d(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;f.isAutofitRunnig||console.error("autofit.js:autofit has not been initialized yet"),y(),!t&&console.error("autofit.js:bad selector: ".concat(t)),i=t,r=n,l=e;var o=Array.from(document.querySelectorAll(t));if(0!=o.length){for(var c=0,a=o;c<a.length;c++){var d=a[c],m=1==u?1:Number(u)*Number(n);s||(d.originalWidth=d.clientWidth,d.originalHeight=d.clientHeight),e?(d.style.width="".concat(d.originalWidth*m,"px"),d.style.height="".concat(d.originalHeight*m,"px")):(d.style.width="".concat(100*m,"%"),d.style.height="".concat(100*m,"%")),d.style.transform="scale(".concat(1/Number(u),")"),d.style.transformOrigin="0 0"}s=!0}else console.error("autofit.js:elRectification found no element")}function y(){if(i){s=!1;for(var t=0,e=Array.from(document.querySelectorAll(i));t<e.length;t++){var n=e[t];n.style.width="",n.style.height="",n.style.transform=""}}}function m(e,o,i,r,l){var c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"scale",a=document.documentElement.clientHeight,s=document.documentElement.clientWidth;u=s/a<e/o?s/e:a/o,u=Math.abs(1-u)>l?u:1;var f=Math.round(a/Number(u)),d=Math.round(s/Number(u));i.style.height="".concat(f,"px"),i.style.width="".concat(d,"px"),"zoom"===c?i.style.zoom="".concat(u):i.style.transform="scale(".concat(u,")");var y=document.querySelector("#ignoreStyle");y.innerHTML="";var m,h=t(r);try{for(h.s();!(m=h.n()).done;){var v=m.value,g=v.el||v.dom;if("string"==typeof v&&(g=v),g&&("object"!==n(g)||Object.keys(g).length)){var p=v.scale?v.scale:1/Number(u),b=p!=u&&v.fontSize,S=p!=u&&v.width,w=p!=u&&v.height;y.innerHTML+="\n".concat(g," { \n transform: scale(").concat(p,")!important;\n transform-origin: 0 0;\n ").concat(S?"width: ".concat(S,"!important;"):"","\n ").concat(w?"height: ".concat(w,"!important;"):"","\n }"),b&&(y.innerHTML+="\n".concat(g," div ,").concat(g," span,").concat(g," a,").concat(g," * {\n font-size: ").concat(b,"px;\n }"))}else console.error("autofit: found invalid or empty selector/object: ".concat(g))}}catch(t){h.e(t)}finally{h.f()}}return f.elRectification=d,f}));