-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstretch-font.min.js
2 lines (2 loc) · 5.17 KB
/
stretch-font.min.js
1
2
var stretchFont=function(){"use strict";function t(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function e(e){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?t(Object(i),!0).forEach((function(t){n(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function n(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=i(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,o=function(){};return{s:o,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:o}}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 a,c=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return c=t.done,t},e:function(t){u=!0,a=t},f:function(){try{c||null==n.return||n.return()}finally{if(u)throw a}}}}return function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"stretch-font",o=[.99,.99,.99,.98,.98,.92,.92,.92,.92],c="stretch-font__tmpl",u=new Map,l=new ResizeObserver((function(t){self.requestAnimationFrame((function(){return t.forEach((function(t){return d(t.target,t.contentRect)}))}))})),f=new MutationObserver((function(t){var e=r(new Set(t.map((function(t){return t.target}))));if(e.length){var n,o=[],c=a(e);try{for(c.s();!(n=c.n()).done;){var u=n.value;u.classList.contains(i)&&o.push(u),o=[].concat(r(o),r(v(u)))}}catch(t){c.e(t)}finally{c.f()}var l,f=a(o.values());try{for(f.s();!(l=f.n()).done;){y(l.value)}}catch(t){f.e(t)}finally{f.f()}}}));function s(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n||Object.keys(n).length){var r=u.get(t);u.set(t,e(e({},r),n))}}function d(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;e||(e=t.getBoundingClientRect());var n=u.get(t),r=n.size,i=n.min,a=n.max,c=n.width,l=n.height,f=n.freeze,s=n.weight,d=o.at(s/100-1),v=(f[0]||e.width)/c*r*d,h=(f[1]||e.height)/l*r*d,y=v>a||h>a?a:v<i||h<i?i:v<h?v:h;"stretchX"in t.dataset&&!("stretchY"in t.dataset)&&(y=v>a?a:v<i?i:v),"stretchY"in t.dataset&&!("stretchX"in t.dataset)&&(y=h>a?a:h<i?i:h),t.style.fontSize=y+"px"}function v(t){return t.querySelectorAll("."+i)||[]}function h(e){!function(t){"inline"===self.getComputedStyle(t).display&&t.classList.add("stretch-font__inline")}(e),"stretchMin"in e.dataset&&function(t){var e;null!==(e=u.get(t))&&void 0!==e&&e.min||s(t,{min:+t.dataset.stretchMin})}(e),"stretchMax"in e.dataset&&function(t){var e;null!==(e=u.get(t))&&void 0!==e&&e.max||s(t,{max:+t.dataset.stretchMax})}(e),function(t){var e;null!==(e=u.get(t))&&void 0!==e&&e.size||s(t,{size:+self.getComputedStyle(t).fontSize.slice(0,-2)})}(e),function(t){var e;null!==(e=u.get(t))&&void 0!==e&&e.weight||s(t,{weight:self.getComputedStyle(t).fontWeight})}(e),function(e){var n,r=document.createElement("span");r.innerHTML=e.innerHTML,r.style.fontSize=null===(n=u.get(e))||void 0===n?void 0:n.size,t.appendChild(r);var i,o=u.get(e).freeze,a=r.getBoundingClientRect(),c=a.width,l=a.height;"stretch"in e.dataset||"stretchX"in e.dataset||"stretchY"in e.dataset?o=[0,0]:null!==(i=o)&&void 0!==i||(o=[c,l]),s(e,{width:c,height:l,freeze:o}),r.remove()}(e)}function y(t){h(t),d(t),l.observe(t)}self.addEventListener("DOMContentLoaded",(function(){t=function(){var t=document.querySelector("."+c);return t||((t=document.createElement("div")).classList.add(c),document.querySelector("body").appendChild(t)),t}();var e,r=a(v(n).values());try{for(r.s();!(e=r.n()).done;){y(e.value)}}catch(t){r.e(t)}finally{r.f()}f.observe(n,{childList:!0,subtree:!0})}))}}();
//# sourceMappingURL=stretch-font.min.js.map