@odopod/odo-object-fit
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -7,4 +7,2 @@ (function (global, factory) { | ||
var babelHelpers = {}; | ||
var classCallCheck = function (instance, Constructor) { | ||
@@ -34,10 +32,2 @@ if (!(instance instanceof Constructor)) { | ||
babelHelpers; | ||
/** | ||
@@ -260,3 +250,3 @@ * @fileoverview A helper which fits media elements (img, video). It polyfills | ||
if (elements.length) { | ||
for (var i = 0, length = elements.length; i < length; i++) { | ||
for (var i = 0; i < elements.length; i++) { | ||
new ObjectFit(elements[i], type); // eslint-disable-line no-new | ||
@@ -271,3 +261,3 @@ } | ||
key: '_loadEventName', | ||
get: function get() { | ||
get: function get$$1() { | ||
return this._isVideo ? 'loadedmetadata' : 'load'; | ||
@@ -274,0 +264,0 @@ } |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.OdoObjectFit=t()}(this,function(){"use strict";var e=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),i=function(){function i(t,n){e(this,i),this.element=t,this.style=n,this._isVideo="video"===t.nodeName.toLowerCase(),this._mediaRatio=null,this._listenForMediaLoad()}return i.prototype._fit=function(e){var t=this._getParentSize(),i=this._getFitSize(t.width,t.height);e.style.width=i.width+"px",e.style.height=i.height+"px",e.style.marginLeft=(t.width-i.width)/2+"px",e.style.marginTop=(t.height-i.height)/2+"px"},i.prototype._getParentSize=function(){return{width:this.element.parentNode.offsetWidth,height:this.element.parentNode.offsetHeight}},i.prototype._getFitSize=function(e,t){var n=e/t,o=void 0,a=void 0;return this.style===i.Style.COVER?this._mediaRatio>n?(o=t*this._mediaRatio,a=t):(o=e,a=e/this._mediaRatio):this._mediaRatio>n?(o=e,a=e/this._mediaRatio):(o=t*this._mediaRatio,a=t),{width:Math.round(o),height:Math.round(a)}},i.prototype._getMediaRatio=function(){return this._isVideo?this.element.videoWidth/this.element.videoHeight:this.element.naturalWidth/this.element.naturalHeight},i.prototype._listenForMediaLoad=function(){this._mediaLoadedHandler=this._handleMediaLoaded.bind(this),this._isMediaLoaded(this.element)?this._mediaLoadedHandler():this.element.addEventListener(this._loadEventName,this._mediaLoadedHandler)},i.prototype._isMediaLoaded=function(e){return e.readyState>0||e.src&&e.complete||e.naturalWidth>0},i.prototype._unlistenForMediaLoad=function(){this.element.removeEventListener(this._loadEventName,this._mediaLoadedHandler)},i.prototype._handleMediaLoaded=function(){this._unlistenForMediaLoad(),this._mediaRatio=this._getMediaRatio(),this._fit(this.element),this.element=null},i.cover=function(e){i._run(e,i.Style.COVER)},i.contain=function(e){i._run(e,i.Style.CONTAIN)},i._run=function(e,t){if(!(i.SUPPORTED||!e||e&&0===e.length))if(e.length)for(var n=0,o=e.length;n<o;n++)new i(e[n],t);else new i(e,t)},t(i,[{key:"_loadEventName",get:function(){return this._isVideo?"loadedmetadata":"load"}}]),i}();return i.SUPPORTED=""===document.createElement("div").style.objectFit,i.Style={COVER:1,CONTAIN:2},i}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.OdoObjectFit=t()}(this,function(){"use strict";var e=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},t=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),i=function(){function i(t,n){e(this,i),this.element=t,this.style=n,this._isVideo="video"===t.nodeName.toLowerCase(),this._mediaRatio=null,this._listenForMediaLoad()}return i.prototype._fit=function(e){var t=this._getParentSize(),i=this._getFitSize(t.width,t.height);e.style.width=i.width+"px",e.style.height=i.height+"px",e.style.marginLeft=(t.width-i.width)/2+"px",e.style.marginTop=(t.height-i.height)/2+"px"},i.prototype._getParentSize=function(){return{width:this.element.parentNode.offsetWidth,height:this.element.parentNode.offsetHeight}},i.prototype._getFitSize=function(e,t){var n=e/t,o=void 0,a=void 0;return this.style===i.Style.COVER?this._mediaRatio>n?(o=t*this._mediaRatio,a=t):(o=e,a=e/this._mediaRatio):this._mediaRatio>n?(o=e,a=e/this._mediaRatio):(o=t*this._mediaRatio,a=t),{width:Math.round(o),height:Math.round(a)}},i.prototype._getMediaRatio=function(){return this._isVideo?this.element.videoWidth/this.element.videoHeight:this.element.naturalWidth/this.element.naturalHeight},i.prototype._listenForMediaLoad=function(){this._mediaLoadedHandler=this._handleMediaLoaded.bind(this),this._isMediaLoaded(this.element)?this._mediaLoadedHandler():this.element.addEventListener(this._loadEventName,this._mediaLoadedHandler)},i.prototype._isMediaLoaded=function(e){return e.readyState>0||e.src&&e.complete||e.naturalWidth>0},i.prototype._unlistenForMediaLoad=function(){this.element.removeEventListener(this._loadEventName,this._mediaLoadedHandler)},i.prototype._handleMediaLoaded=function(){this._unlistenForMediaLoad(),this._mediaRatio=this._getMediaRatio(),this._fit(this.element),this.element=null},i.cover=function(e){i._run(e,i.Style.COVER)},i.contain=function(e){i._run(e,i.Style.CONTAIN)},i._run=function(e,t){if(!(i.SUPPORTED||!e||e&&0===e.length))if(e.length)for(var n=0;n<e.length;n++)new i(e[n],t);else new i(e,t)},t(i,[{key:"_loadEventName",get:function(){return this._isVideo?"loadedmetadata":"load"}}]),i}();return i.SUPPORTED=""===document.createElement("div").style.objectFit,i.Style={COVER:1,CONTAIN:2},i}); | ||
//# sourceMappingURL=odo-object-fit.min.js.map |
{ | ||
"name": "@odopod/odo-object-fit", | ||
"description": "Fits media elements (img, video). It polyfills CSS' object-fit: cover; If the browser supports object-fit, it will not run.", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"main": "dist/odo-object-fit.js", | ||
@@ -6,0 +6,0 @@ "odoModule": "src/object-fit.js", |
@@ -198,3 +198,3 @@ /** | ||
if (elements.length) { | ||
for (let i = 0, length = elements.length; i < length; i++) { | ||
for (let i = 0; i < elements.length; i++) { | ||
new ObjectFit(elements[i], type); // eslint-disable-line no-new | ||
@@ -201,0 +201,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
37554
432