Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-fit-images

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-fit-images - npm Package Compare versions

Comparing version 2.5.1 to 2.5.2

61

dist/ofi.common-js.js
'use strict';
var ಠ = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent image, used as accessor and replacing image
var ಠಠ = ಠ + ಠ; // additional permanent settings accessor
var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g;

@@ -25,6 +24,7 @@ var testImg = new Image();

function fixOne(el, requestedSrc) {
if (el[ಠಠ].parsingSrcset) {
if (el[ಠ].parsingSrcset) {
return;
}
var style = getStyle(el);
style['object-fit'] = style['object-fit'] || 'fill'; // default value

@@ -35,11 +35,11 @@ // If the fix was already applied, don't try to skip fixing,

// - This ain't rap, bro.
if (!el[ಠ] && !el[ಠಠ].skipTest) {
if (!style['object-fit'] || // if image doesn't use object-fit
style['object-fit'] === 'fill' // fill is the default behavior
) {
return;
}
if (!el[ಠ].s) {
// fill is the default behavior so no action is necessary
if (style['object-fit'] === 'fill') {
return;
}
// Where object-fit is supported and object-position isn't (Safari < 10)
if (supportsObjectFit && // if browser already supports object-fit
if (!el[ಠ].skipTest && // unless user wants to apply regardless of browser support
supportsObjectFit && // if browser already supports object-fit
!style['object-position'] // unless object-position is used

@@ -55,10 +55,12 @@ ) {

// explicitly requested src takes precedence
// TODO: this still should overwrite srcset
src = requestedSrc;
} else if (el.srcset && !supportsCurrentSrc && window.picturefill) {
var pf = window.picturefill._.ns;
// prevent infinite loop
// fillImg sets the src which in turn calls fixOne
el[ಠಠ].parsingSrcset = true;
el[ಠ].parsingSrcset = true;
// parse srcset with picturefill where currentSrc isn't available
if (!el[window.picturefill._.ns] || !el[window.picturefill._.ns].evaled) {
if (!el[pf] || !el[pf].evaled) {
// force synchronous srcset parsing

@@ -68,16 +70,15 @@ window.picturefill._.fillImg(el, { reselect: true });

var imageData = el[window.picturefill._.ns];
if (!imageData.curSrc) {
if (!el[pf].curSrc) {
// force picturefill to parse srcset
imageData.supported = false;
el[pf].supported = false;
window.picturefill._.fillImg(el, { reselect: true });
}
delete el[ಠಠ].parsingSrcset;
delete el[ಠ].parsingSrcset;
// retrieve parsed currentSrc, if any
src = imageData.curSrc || src;
src = el[pf].curSrc || src;
}
// store info on object for later use
if (el[ಠ]) {
if (el[ಠ].s) {
el[ಠ].s = src;

@@ -101,3 +102,3 @@ if (requestedSrc) {

// restore non-working srcset property
// restore non-browser-readable srcset property
Object.defineProperty(el, 'srcset', {

@@ -159,11 +160,2 @@ value: el[ಠ].srcsetAttr

function watchMQ(imgs, opts) {
window.addEventListener('resize', fix.bind(null, imgs, opts));
}
function onInsert(e) {
if (e.target.tagName === 'IMG') {
fixOne(e.target);
}
}
function hijackAttributes() {

@@ -205,3 +197,3 @@ if (!supportsObjectPosition) {

for (var i = 0; i < imgs.length; i++) {
imgs[i][ಠಠ] = opts;
imgs[i][ಠ] = imgs[i][ಠ] || opts;
fixOne(imgs[i]);

@@ -211,3 +203,9 @@ }

if (startAutoMode) {
document.body.addEventListener('load', onInsert, true);
document.body.addEventListener('load', function (e) {
if (e.target.tagName === 'IMG') {
fix(e.target, {
skipTest: opts.skipTest
});
}
}, true);
autoModeEnabled = true;

@@ -219,4 +217,5 @@ imgs = 'img'; // reset to a generic selector for watchMQ

if (opts.watchMQ) {
delete opts.watchMQ;
watchMQ(imgs, opts);
window.addEventListener('resize', fix.bind(null, imgs, {
skipTest: opts.skipTest
}));
}

@@ -223,0 +222,0 @@ }

var ಠ = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent image, used as accessor and replacing image
var ಠಠ = ಠ + ಠ; // additional permanent settings accessor
var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g;

@@ -23,6 +22,7 @@ var testImg = new Image();

function fixOne(el, requestedSrc) {
if (el[ಠಠ].parsingSrcset) {
if (el[ಠ].parsingSrcset) {
return;
}
var style = getStyle(el);
style['object-fit'] = style['object-fit'] || 'fill'; // default value

@@ -33,11 +33,11 @@ // If the fix was already applied, don't try to skip fixing,

// - This ain't rap, bro.
if (!el[ಠ] && !el[ಠಠ].skipTest) {
if (!style['object-fit'] || // if image doesn't use object-fit
style['object-fit'] === 'fill' // fill is the default behavior
) {
return;
}
if (!el[ಠ].s) {
// fill is the default behavior so no action is necessary
if (style['object-fit'] === 'fill') {
return;
}
// Where object-fit is supported and object-position isn't (Safari < 10)
if (supportsObjectFit && // if browser already supports object-fit
if (!el[ಠ].skipTest && // unless user wants to apply regardless of browser support
supportsObjectFit && // if browser already supports object-fit
!style['object-position'] // unless object-position is used

@@ -53,10 +53,12 @@ ) {

// explicitly requested src takes precedence
// TODO: this still should overwrite srcset
src = requestedSrc;
} else if (el.srcset && !supportsCurrentSrc && window.picturefill) {
var pf = window.picturefill._.ns;
// prevent infinite loop
// fillImg sets the src which in turn calls fixOne
el[ಠಠ].parsingSrcset = true;
el[ಠ].parsingSrcset = true;
// parse srcset with picturefill where currentSrc isn't available
if (!el[window.picturefill._.ns] || !el[window.picturefill._.ns].evaled) {
if (!el[pf] || !el[pf].evaled) {
// force synchronous srcset parsing

@@ -66,16 +68,15 @@ window.picturefill._.fillImg(el, { reselect: true });

var imageData = el[window.picturefill._.ns];
if (!imageData.curSrc) {
if (!el[pf].curSrc) {
// force picturefill to parse srcset
imageData.supported = false;
el[pf].supported = false;
window.picturefill._.fillImg(el, { reselect: true });
}
delete el[ಠಠ].parsingSrcset;
delete el[ಠ].parsingSrcset;
// retrieve parsed currentSrc, if any
src = imageData.curSrc || src;
src = el[pf].curSrc || src;
}
// store info on object for later use
if (el[ಠ]) {
if (el[ಠ].s) {
el[ಠ].s = src;

@@ -99,3 +100,3 @@ if (requestedSrc) {

// restore non-working srcset property
// restore non-browser-readable srcset property
Object.defineProperty(el, 'srcset', {

@@ -157,11 +158,2 @@ value: el[ಠ].srcsetAttr

function watchMQ(imgs, opts) {
window.addEventListener('resize', fix.bind(null, imgs, opts));
}
function onInsert(e) {
if (e.target.tagName === 'IMG') {
fixOne(e.target);
}
}
function hijackAttributes() {

@@ -203,3 +195,3 @@ if (!supportsObjectPosition) {

for (var i = 0; i < imgs.length; i++) {
imgs[i][ಠಠ] = opts;
imgs[i][ಠ] = imgs[i][ಠ] || opts;
fixOne(imgs[i]);

@@ -209,3 +201,9 @@ }

if (startAutoMode) {
document.body.addEventListener('load', onInsert, true);
document.body.addEventListener('load', function (e) {
if (e.target.tagName === 'IMG') {
fix(e.target, {
skipTest: opts.skipTest
});
}
}, true);
autoModeEnabled = true;

@@ -217,4 +215,5 @@ imgs = 'img'; // reset to a generic selector for watchMQ

if (opts.watchMQ) {
delete opts.watchMQ;
watchMQ(imgs, opts);
window.addEventListener('resize', fix.bind(null, imgs, {
skipTest: opts.skipTest
}));
}

@@ -221,0 +220,0 @@ }

{
"name": "object-fit-images",
"version": "2.5.1",
"version": "2.5.2",
"description": "Polyfill object-fit and object-position on images on IE9, IE10, IE11, Edge, Safari, ...",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc