{"version":3,"sources":["fitie.init.js","fitie.js"],"names":["this","fitie","init","document","body","all","querySelectorAll","index","setTimeout","test","navigator","userAgent","node","onload","removeEventListener","call","on","type","imgCSS","boxSizing","display","overflow","replace","key","getCSS","setCSS","border","margin","padding","height","width","opacity","innerWidth","videoWidth","innerHeight","videoHeight","innerRatio","imgx","createElement","appendChild","parentNode","replaceChild","runtimeStyle","newSize","objectFit","img","outerWidth","outerHeight","outerRatio","Math","round","marginLeft","marginTop","currentStyle","clientWidth","clientHeight","name","nodeName","toLowerCase","addEventListener","attachEvent","detachEvent","complete"],"mappings":"AAAAA,KAAAC,MAAAC,KAAA,WACA,GAAAC,SAAAC,KAIA,IAHA,GAAAC,GAAAF,SAAAG,iBAAA,aACAC,EAAA,GAEAF,IAAAE,IAAAN,MAAAI,EAAAE,QAEAC,YAAAP,MAAAC,OAIA,eAAAO,KAAAC,UAAAC,YAAAX,KAAAC,MAAAC,OCXAF,KAAAC,MAAA,SAAAW,GA0BA,QAAAC,KACAC,EAAAC,KAAAH,EAAAI,EAAAC,EAAAJ,EAGA,IAAAK,IACAC,UAAA,cACAC,QAAA,eACAC,SAAA,SAGA,iKAAAC,QAAA,OAAA,SAAAC,GACAL,EAAAK,GAAAC,EAAAD,KAIAE,EAAAC,OAAAD,EAAAE,OAAAF,EAAAG,QAAA,EACAH,EAAAL,QAAA,QACAK,EAAAI,OAAAJ,EAAAK,MAAA,OACAL,EAAAM,QAAA,CAEA,IAAAC,GAAApB,EAAAqB,YAAArB,EAAAkB,MACAI,EAAAtB,EAAAuB,aAAAvB,EAAAiB,OACAO,EAAAJ,EAAAE,EAGAG,EAAAlC,SAAAmC,cAAA,aAEAD,GAAAE,YAAA3B,EAAA4B,WAAAC,aAAAJ,EAAAzB,GAEA,KAAA,GAAAW,KAAAL,GAAAmB,EAAAK,aAAAnB,GAAAL,EAAAK,EAGA,IAAAoB,EAEA,UAAAC,EACAC,GACApB,EAAAK,MAAAgB,EACArB,EAAAI,OAAAkB,IAEAtB,EAAA,wBAAA,QACAA,EAAA,iBAAA,SAAAqB,EAAAd,EAAA,IAAAe,EAAAb,EAAA,MAEAc,EAAAZ,EAAA,YAAAQ,EAAA,UAAAA,IACAD,EAAAI,EAAAX,EAEAX,EAAAK,MAAAmB,KAAAC,MAAAP,GAAA,KACAlB,EAAAI,OAAAkB,EAAA,KACAtB,EAAA0B,WAAAF,KAAAC,OAAAJ,EAAAH,GAAA,GAAA,OAEAA,EAAAG,EAAAV,EAEAX,EAAAK,MAAAgB,EAAA,KACArB,EAAAI,OAAAoB,KAAAC,MAAAP,GAAA,KACAlB,EAAA2B,UAAAH,KAAAC,OAAAH,EAAAJ,GAAA,GAAA,MA7EA,GAAAC,GAAAhC,EAAAyC,aAAA,aAEA,IAAAT,GAAA,yBAAAnC,KAAAmC,GAAA,CAGA,GAAAE,GAAAlC,EAAA0C,YACAP,EAAAnC,EAAA2C,aACAP,EAAAF,EAAAC,EAEAS,EAAA5C,EAAA6C,SAAAC,cAEAjC,EAAAb,EAAA8B,aACAlB,EAAAZ,EAAAyC,aAEAM,EAAA/C,EAAA+C,kBAAA/C,EAAAgD,YACA9C,EAAAF,EAAAE,qBAAAF,EAAAiD,YACA7C,EAAAJ,EAAA+C,iBAAA,GAAA,KACAd,EAAA,QAAAW,EACAvC,EAAA4B,EAAA,OAAA,gBAEAc,GAAA5C,KAAAH,EAAAI,EAAAC,EAAAJ,GAEAD,EAAAkD,UAAAjD","file":"fitie.js","sourcesContent":["this.fitie.init = function () {\n\tif (document.body) {\n\t\tvar all = document.querySelectorAll('img,video');\n\t\tvar index = -1;\n\n\t\twhile (all[++index]) fitie(all[index]);\n\t} else {\n\t\tsetTimeout(fitie.init);\n\t}\n};\n\nif (/MSIE|Trident/.test(navigator.userAgent)) this.fitie.init();\n","this.fitie = function (node) {\n\t// restrict to valid object-fit value\n\tvar objectFit = node.currentStyle['object-fit'];\n\n\tif (!objectFit || !/^(contain|cover|fill)$/.test(objectFit)) return;\n\n\t// prepare container styles\n\tvar outerWidth = node.clientWidth;\n\tvar outerHeight = node.clientHeight;\n\tvar outerRatio = outerWidth / outerHeight;\n\n\tvar name = node.nodeName.toLowerCase();\n\n\tvar setCSS = node.runtimeStyle;\n\tvar getCSS = node.currentStyle;\n\n\tvar addEventListener = node.addEventListener || node.attachEvent;\n\tvar removeEventListener = node.removeEventListener || node.detachEvent;\n\tvar on = node.addEventListener ? '' : 'on';\n\tvar img = name === 'img';\n\tvar type = img ? 'load' : 'loadedmetadata';\n\n\taddEventListener.call(node, on + type, onload);\n\n\tif (node.complete) onload();\n\n\tfunction onload() {\n\t\tremoveEventListener.call(node, on + type, onload);\n\n\t\t// prepare container styles\n\t\tvar imgCSS = {\n\t\t\tboxSizing: 'content-box',\n\t\t\tdisplay: 'inline-block',\n\t\t\toverflow: 'hidden'\n\t\t};\n\n\t\t'backgroundColor backgroundImage borderColor borderStyle borderWidth bottom fontSize lineHeight height left opacity margin position right top visibility width'.replace(/\\w+/g, function (key) {\n\t\t\timgCSS[key] = getCSS[key];\n\t\t});\n\n\t\t// prepare image styles\n\t\tsetCSS.border = setCSS.margin = setCSS.padding = 0;\n\t\tsetCSS.display = 'block';\n\t\tsetCSS.height = setCSS.width = 'auto';\n\t\tsetCSS.opacity = 1;\n\n\t\tvar innerWidth = node.videoWidth || node.width;\n\t\tvar innerHeight = node.videoHeight || node.height;\n\t\tvar innerRatio = innerWidth / innerHeight;\n\n\t\t// style container\n\t\tvar imgx = document.createElement('object-fit');\n\n\t\timgx.appendChild(node.parentNode.replaceChild(imgx, node));\n\n\t\tfor (var key in imgCSS) imgx.runtimeStyle[key] = imgCSS[key];\n\n\t\t// style image\n\t\tvar newSize;\n\n\t\tif (objectFit === 'fill') {\n\t\t\tif (img) {\n\t\t\t\tsetCSS.width = outerWidth;\n\t\t\t\tsetCSS.height = outerHeight;\n\t\t\t} else {\n\t\t\t\tsetCSS['-ms-transform-origin'] = '0% 0%';\n\t\t\t\tsetCSS['-ms-transform'] = 'scale(' + outerWidth / innerWidth + ',' + outerHeight / innerHeight + ')';\n\t\t\t}\n\t\t} else if (innerRatio < outerRatio ? objectFit === 'contain' : objectFit === 'cover') {\n\t\t\tnewSize = outerHeight * innerRatio;\n\n\t\t\tsetCSS.width = Math.round(newSize) + 'px';\n\t\t\tsetCSS.height = outerHeight + 'px';\n\t\t\tsetCSS.marginLeft = Math.round((outerWidth - newSize) / 2) + 'px';\n\t\t} else {\n\t\t\tnewSize = outerWidth / innerRatio;\n\n\t\t\tsetCSS.width = outerWidth + 'px';\n\t\t\tsetCSS.height = Math.round(newSize) + 'px';\n\t\t\tsetCSS.marginTop = Math.round((outerHeight - newSize) / 2) + 'px';\n\t\t}\n\t}\n};\n"],"sourceRoot":"/source/"}