-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtextblock.min.js
1 lines (1 loc) · 2.09 KB
/
textblock.min.js
1
window.Textblock=function(t){var e;function n(){a(t,function(t){var i=function(t){return Object.assign({minWidth:320,maxWidth:960,minWidth_FontSize:1,maxWidth_FontSize:1.8,minWidth_LineHeight:1.33,maxWidth_LineHeight:1.25,container:"parent",fontSize_units:"em"},t)}(t);a(function(t){return document.querySelectorAll(t)}(i.target),function(t){var e=function(t,e){if(t){var n=e.minWidth,i=e.maxWidth,a=e.container,o=e.minFontSize||e.minWidthFontSize||e.minWidth_FontSize,d=e.maxFontSize||e.maxWidthFontSize||e.maxWidth_FontSize,r=e.minLineHeight||e.minWidthLineHeight||e.minWidth_LineHeight,m=e.maxLineHeight||e.maxWidthLineHeight||e.maxWidth_LineHeight,h=e.minVariableGrade||e.minWidthVariableGrade||e.minWidth_VariableGrade,u=e.maxVariableGrade||e.maxWidthVariableGrade||e.maxWidth_VariableGrade,c=g("self"===a?t:t.parentNode),l=(Math.min(Math.max(c,n),i)-n)/(i-n);return{fontSize:f(o,d,l),lineHeight:f(r,m,l),fontVariationSettings:'"wght" '+f(h,u,l)}}}(t,i);if(e){var n=i.units||i.fontSize_units;t.style.fontSize=e.fontSize+n,t.style.lineHeight=e.lineHeight,t.style.fontVariationSettings=e.fontVariationSettings}})})}function f(t,e,n){return t+(e-t)*n}function a(t,e){for(var n=0;n<t.length;n++)e&&e(t[n],n)}function g(t){var e=parseInt(i(t,"padding-left"))+parseInt(i(t,"padding-right")),n=parseInt(i(t,"border-left-width"))+parseInt(i(t,"border-right-width"));return t.offsetWidth-e-n}function i(t,e){return window.getComputedStyle?window.getComputedStyle(t,null).getPropertyValue(e):t.currentStyle[e]}e=function(){n(),function(t){window.attachEvent?window.attachEvent("onresize",function(){t&&t()}):window.addEventListener&&window.addEventListener("resize",function(){t&&t()},!0)}(n)},document.addEventListener?"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?e&&e():document.addEventListener("DOMContentLoaded",function(){e&&e()}):document.attachEvent&&document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&(document.detachEvent("onreadystatechange",arguments.callee),e&&e())})},"undefined"!=typeof module&&module.exports&&(module.exports=Textblock);