resemblejs
Advanced tools
Comparing version 3.2.4 to 3.2.5
@@ -0,0 +0,0 @@ const resemble = require("./resemble"); |
{ | ||
"name": "resemblejs", | ||
"version": "3.2.4", | ||
"version": "3.2.5", | ||
"description": "Image analysis and comparison with HTML5", | ||
@@ -8,3 +8,3 @@ "main": "resemble.js", | ||
"type": "git", | ||
"url": "https://github.com/Huddle/Resemble.js.git" | ||
"url": "https://github.com/rsmbl/Resemble.js.git" | ||
}, | ||
@@ -22,5 +22,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/Huddle/Resemble.js/issues" | ||
"url": "https://github.com/rsmbl/Resemble.js/issues" | ||
}, | ||
"homepage": "https://github.com/Huddle/Resemble.js", | ||
"homepage": "https://github.com/rsmbl/Resemble.js", | ||
"scripts": { | ||
@@ -49,12 +49,10 @@ "test": "jest nodejs-tests", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-es5": "^0.5.0", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"eslint": "^7.6.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"husky": "^3.1.0", | ||
"jest": "^24.9.0", | ||
"jest-cli": "^24.9.0", | ||
"jest": "^25.1.0", | ||
"jest-cli": "^25.1.0", | ||
"lint-staged": "^9.5.0", | ||
"prettier": "^1.19.1" | ||
"prettier": "^2.0.0" | ||
}, | ||
@@ -61,0 +59,0 @@ "jest": { |
315
resemble.js
@@ -6,7 +6,47 @@ /* | ||
var isNode = new Function( | ||
"return (typeof process !== 'undefined') && process.versions && process.versions.node" | ||
); //eslint-disable-line | ||
var naiveFallback = function () { | ||
// ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js | ||
if (typeof self === "object" && self) { | ||
return self; | ||
} | ||
if (typeof window === "object" && window) { | ||
return window; | ||
} | ||
throw new Error("Unable to resolve global `this`"); | ||
}; | ||
(function(root, factory) { | ||
var getGlobalThis = function () { | ||
// ISC (c) 2011-2019 https://github.com/medikoo/es5-ext/blob/master/global.js | ||
// Fallback to standard globalThis if available | ||
if (typeof globalThis === "object" && globalThis) { | ||
return globalThis; | ||
} | ||
try { | ||
Object.defineProperty(Object.prototype, "__global__", { | ||
get: function () { | ||
return this; | ||
}, | ||
configurable: true | ||
}); | ||
} catch (error) { | ||
return naiveFallback(); | ||
} | ||
try { | ||
// eslint-disable-next-line no-undef | ||
if (!__global__) { | ||
return naiveFallback(); | ||
} | ||
return __global__; // eslint-disable-line no-undef | ||
} finally { | ||
delete Object.prototype.__global__; | ||
} | ||
}; | ||
var isNode = function () { | ||
const globalPolyfill = getGlobalThis(); | ||
return typeof globalPolyfill.process !== "undefined" && globalPolyfill.process.versions && globalPolyfill.process.versions.node; | ||
}; | ||
(function (root, factory) { | ||
"use strict"; | ||
@@ -20,3 +60,3 @@ if (typeof define === "function" && define.amd) { | ||
} | ||
})(this /* eslint-disable-line no-invalid-this*/, function() { | ||
})(this /* eslint-disable-line no-invalid-this*/, function () { | ||
"use strict"; | ||
@@ -50,3 +90,3 @@ | ||
var resemble = function(fileData) { | ||
var resemble = function (fileData) { | ||
var pixelTransparency = 1; | ||
@@ -65,3 +105,3 @@ | ||
var errorPixelTransform = { | ||
flat: function(px, offset) { | ||
flat: function (px, offset) { | ||
px[offset] = errorPixelColor.red; | ||
@@ -72,17 +112,9 @@ px[offset + 1] = errorPixelColor.green; | ||
}, | ||
movement: function(px, offset, d1, d2) { | ||
px[offset] = | ||
(d2.r * (errorPixelColor.red / 255) + errorPixelColor.red) / | ||
2; | ||
px[offset + 1] = | ||
(d2.g * (errorPixelColor.green / 255) + | ||
errorPixelColor.green) / | ||
2; | ||
px[offset + 2] = | ||
(d2.b * (errorPixelColor.blue / 255) + | ||
errorPixelColor.blue) / | ||
2; | ||
movement: function (px, offset, d1, d2) { | ||
px[offset] = (d2.r * (errorPixelColor.red / 255) + errorPixelColor.red) / 2; | ||
px[offset + 1] = (d2.g * (errorPixelColor.green / 255) + errorPixelColor.green) / 2; | ||
px[offset + 2] = (d2.b * (errorPixelColor.blue / 255) + errorPixelColor.blue) / 2; | ||
px[offset + 3] = d2.a; | ||
}, | ||
flatDifferenceIntensity: function(px, offset, d1, d2) { | ||
flatDifferenceIntensity: function (px, offset, d1, d2) { | ||
px[offset] = errorPixelColor.red; | ||
@@ -93,17 +125,11 @@ px[offset + 1] = errorPixelColor.green; | ||
}, | ||
movementDifferenceIntensity: function(px, offset, d1, d2) { | ||
movementDifferenceIntensity: function (px, offset, d1, d2) { | ||
var ratio = (colorsDistance(d1, d2) / 255) * 0.8; | ||
px[offset] = | ||
(1 - ratio) * (d2.r * (errorPixelColor.red / 255)) + | ||
ratio * errorPixelColor.red; | ||
px[offset + 1] = | ||
(1 - ratio) * (d2.g * (errorPixelColor.green / 255)) + | ||
ratio * errorPixelColor.green; | ||
px[offset + 2] = | ||
(1 - ratio) * (d2.b * (errorPixelColor.blue / 255)) + | ||
ratio * errorPixelColor.blue; | ||
px[offset] = (1 - ratio) * (d2.r * (errorPixelColor.red / 255)) + ratio * errorPixelColor.red; | ||
px[offset + 1] = (1 - ratio) * (d2.g * (errorPixelColor.green / 255)) + ratio * errorPixelColor.green; | ||
px[offset + 2] = (1 - ratio) * (d2.b * (errorPixelColor.blue / 255)) + ratio * errorPixelColor.blue; | ||
px[offset + 3] = d2.a; | ||
}, | ||
diffOnly: function(px, offset, d1, d2) { | ||
diffOnly: function (px, offset, d1, d2) { | ||
px[offset] = d2.r; | ||
@@ -144,17 +170,7 @@ px[offset + 1] = d2.g; | ||
function colorsDistance(c1, c2) { | ||
return ( | ||
(Math.abs(c1.r - c2.r) + | ||
Math.abs(c1.g - c2.g) + | ||
Math.abs(c1.b - c2.b)) / | ||
3 | ||
); | ||
return (Math.abs(c1.r - c2.r) + Math.abs(c1.g - c2.g) + Math.abs(c1.b - c2.b)) / 3; | ||
} | ||
function withinBoundingBox(x, y, width, height, box) { | ||
return ( | ||
x > (box.left || 0) && | ||
x < (box.right || width) && | ||
y > (box.top || 0) && | ||
y < (box.bottom || height) | ||
); | ||
return x > (box.left || 0) && x < (box.right || width) && y > (box.top || 0) && y < (box.bottom || height); | ||
} | ||
@@ -241,3 +257,3 @@ | ||
loop(width, height, function(horizontalPos, verticalPos) { | ||
loop(width, height, function (horizontalPos, verticalPos) { | ||
var offset = (verticalPos * width + horizontalPos) * 4; | ||
@@ -291,8 +307,4 @@ var red = sourceImageData[offset]; | ||
hiddenCanvas | ||
.getContext("2d") | ||
.drawImage(hiddenImage, 0, 0, width, height); | ||
imageData = hiddenCanvas | ||
.getContext("2d") | ||
.getImageData(0, 0, width, height); | ||
hiddenCanvas.getContext("2d").drawImage(hiddenImage, 0, 0, width, height); | ||
imageData = hiddenCanvas.getContext("2d").getImageData(0, 0, width, height); | ||
@@ -316,3 +328,3 @@ images.push(imageData); | ||
hiddenImage.onerror = function(err) { | ||
hiddenImage.onerror = function (err) { | ||
hiddenImage.onload = null; | ||
@@ -324,3 +336,3 @@ hiddenImage.onerror = null; // fixes pollution between calls | ||
hiddenImage.onload = function() { | ||
hiddenImage.onload = function () { | ||
hiddenImage.onload = null; // fixes pollution between calls | ||
@@ -333,7 +345,3 @@ hiddenImage.onerror = null; | ||
hiddenImage.src = fileDataForImage; | ||
if ( | ||
!isNode() && | ||
hiddenImage.complete && | ||
hiddenImage.naturalWidth > 0 | ||
) { | ||
if (!isNode() && hiddenImage.complete && hiddenImage.naturalWidth > 0) { | ||
hiddenImage.onload(); | ||
@@ -348,11 +356,4 @@ } | ||
callback( | ||
fileDataForImage, | ||
fileDataForImage.width, | ||
fileDataForImage.height | ||
); | ||
} else if ( | ||
typeof Buffer !== "undefined" && | ||
fileDataForImage instanceof Buffer | ||
) { | ||
callback(fileDataForImage, fileDataForImage.width, fileDataForImage.height); | ||
} else if (typeof Buffer !== "undefined" && fileDataForImage instanceof Buffer) { | ||
// If we have Buffer, assume we're on Node+Canvas and its supported | ||
@@ -362,3 +363,3 @@ // hiddenImage.src = fileDataForImage; | ||
loadNodeCanvasImage(fileDataForImage) | ||
.then(function(image) { | ||
.then(function (image) { | ||
hiddenImage.onload = null; // fixes pollution between calls | ||
@@ -368,3 +369,3 @@ hiddenImage.onerror = null; | ||
}) | ||
.catch(function(err) { | ||
.catch(function (err) { | ||
images.push({ | ||
@@ -377,3 +378,3 @@ error: err ? err + "" : "Image load error." | ||
fileReader = new FileReader(); | ||
fileReader.onload = function(event) { | ||
fileReader.onload = function (event) { | ||
hiddenImage.src = event.target.result; | ||
@@ -405,7 +406,3 @@ }; | ||
var alpha = isColorSimilar(d1.a, d2.a, "alpha"); | ||
var brightness = isColorSimilar( | ||
d1.brightness, | ||
d2.brightness, | ||
"minBrightness" | ||
); | ||
var brightness = isColorSimilar(d1.brightness, d2.brightness, "minBrightness"); | ||
return brightness && alpha; | ||
@@ -435,6 +432,3 @@ } | ||
function isContrasting(d1, d2) { | ||
return ( | ||
Math.abs(d1.brightness - d2.brightness) > | ||
tolerance.maxBrightness | ||
); | ||
return Math.abs(d1.brightness - d2.brightness) > tolerance.maxBrightness; | ||
} | ||
@@ -473,10 +467,3 @@ | ||
function isAntialiased( | ||
sourcePix, | ||
pix, | ||
cacheSet, | ||
verticalPos, | ||
horizontalPos, | ||
width | ||
) { | ||
function isAntialiased(sourcePix, pix, cacheSet, verticalPos, horizontalPos, width) { | ||
var offset; | ||
@@ -497,5 +484,3 @@ var distance = 1; | ||
} else { | ||
offset = | ||
((verticalPos + j) * width + (horizontalPos + i)) * | ||
4; | ||
offset = ((verticalPos + j) * width + (horizontalPos + i)) * 4; | ||
@@ -521,6 +506,3 @@ if (!getPixelInfo(targetPix, pix, offset, cacheSet)) { | ||
if ( | ||
hasSiblingWithDifferentHue > 1 || | ||
hasHighContrastSibling > 1 | ||
) { | ||
if (hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1) { | ||
return true; | ||
@@ -605,3 +587,3 @@ } | ||
}; | ||
var updateBounds = function(x, y) { | ||
var updateBounds = function (x, y) { | ||
diffBounds.left = Math.min(x, diffBounds.left); | ||
@@ -617,7 +599,3 @@ diffBounds.right = Math.max(x, diffBounds.right); | ||
if ( | ||
!!largeImageThreshold && | ||
ignoreAntialiasing && | ||
(width > largeImageThreshold || height > largeImageThreshold) | ||
) { | ||
if (!!largeImageThreshold && ignoreAntialiasing && (width > largeImageThreshold || height > largeImageThreshold)) { | ||
skip = 6; | ||
@@ -631,3 +609,3 @@ } | ||
loop(width, height, function(horizontalPos, verticalPos) { | ||
loop(width, height, function (horizontalPos, verticalPos) { | ||
if (skipTheRest) { | ||
@@ -639,6 +617,3 @@ return; | ||
// only skip if the image isn't small | ||
if ( | ||
verticalPos % skip === 0 || | ||
horizontalPos % skip === 0 | ||
) { | ||
if (verticalPos % skip === 0 || horizontalPos % skip === 0) { | ||
return; | ||
@@ -649,16 +624,7 @@ } | ||
var offset = (verticalPos * width + horizontalPos) * 4; | ||
if ( | ||
!getPixelInfo(pixel1, data1, offset, 1) || | ||
!getPixelInfo(pixel2, data2, offset, 2) | ||
) { | ||
if (!getPixelInfo(pixel1, data1, offset, 1) || !getPixelInfo(pixel2, data2, offset, 2)) { | ||
return; | ||
} | ||
var isWithinComparedArea = withinComparedArea( | ||
horizontalPos, | ||
verticalPos, | ||
width, | ||
height, | ||
pixel2 | ||
); | ||
var isWithinComparedArea = withinComparedArea(horizontalPos, verticalPos, width, height, pixel2); | ||
@@ -669,6 +635,3 @@ if (ignoreColors) { | ||
if ( | ||
isPixelBrightnessSimilar(pixel1, pixel2) || | ||
!isWithinComparedArea | ||
) { | ||
if (isPixelBrightnessSimilar(pixel1, pixel2) || !isWithinComparedArea) { | ||
if (!compareOnly) { | ||
@@ -696,23 +659,5 @@ copyGrayScalePixel(pix, offset, pixel2); | ||
addBrightnessInfo(pixel2), | ||
isAntialiased( | ||
pixel1, | ||
data1, | ||
1, | ||
verticalPos, | ||
horizontalPos, | ||
width | ||
) || | ||
isAntialiased( | ||
pixel2, | ||
data2, | ||
2, | ||
verticalPos, | ||
horizontalPos, | ||
width | ||
)) | ||
isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width)) | ||
) { | ||
if ( | ||
isPixelBrightnessSimilar(pixel1, pixel2) || | ||
!isWithinComparedArea | ||
) { | ||
if (isPixelBrightnessSimilar(pixel1, pixel2) || !isWithinComparedArea) { | ||
if (!compareOnly) { | ||
@@ -739,4 +684,3 @@ copyGrayScalePixel(pix, offset, pixel2); | ||
if (compareOnly) { | ||
var currentMisMatchPercent = | ||
(mismatchCount / (height * width)) * 100; | ||
var currentMisMatchPercent = (mismatchCount / (height * width)) * 100; | ||
@@ -749,4 +693,3 @@ if (currentMisMatchPercent > returnEarlyThreshold) { | ||
data.rawMisMatchPercentage = | ||
(mismatchCount / (height * width)) * 100; | ||
data.rawMisMatchPercentage = (mismatchCount / (height * width)) * 100; | ||
data.misMatchPercentage = data.rawMisMatchPercentage.toFixed(2); | ||
@@ -756,7 +699,5 @@ data.diffBounds = diffBounds; | ||
data.getImageDataUrl = function(text) { | ||
data.getImageDataUrl = function (text) { | ||
if (compareOnly) { | ||
throw Error( | ||
"No diff image available - ran in compareOnly mode" | ||
); | ||
throw Error("No diff image available - ran in compareOnly mode"); | ||
} | ||
@@ -776,3 +717,3 @@ | ||
if (!compareOnly && hiddenCanvas.toBuffer) { | ||
data.getBuffer = function(includeOriginal) { | ||
data.getBuffer = function (includeOriginal) { | ||
if (includeOriginal) { | ||
@@ -839,6 +780,3 @@ var imageWidth = hiddenCanvas.width + 2; | ||
if (options.errorColor.hasOwnProperty(key)) { | ||
errorPixelColor[key] = | ||
options.errorColor[key] === void 0 | ||
? errorPixelColor[key] | ||
: options.errorColor[key]; | ||
errorPixelColor[key] = options.errorColor[key] === void 0 ? errorPixelColor[key] : options.errorColor[key]; | ||
} | ||
@@ -853,12 +791,7 @@ } | ||
if ( | ||
options.errorPixel && | ||
typeof options.errorPixel === "function" | ||
) { | ||
if (options.errorPixel && typeof options.errorPixel === "function") { | ||
errorPixel = options.errorPixel; | ||
} | ||
pixelTransparency = isNaN(Number(options.transparency)) | ||
? pixelTransparency | ||
: options.transparency; | ||
pixelTransparency = isNaN(Number(options.transparency)) ? pixelTransparency : options.transparency; | ||
@@ -905,21 +838,10 @@ if (options.largeImageThreshold !== undefined) { | ||
data = {}; | ||
data.error = images[0].error | ||
? images[0].error | ||
: images[1].error; | ||
data.error = images[0].error ? images[0].error : images[1].error; | ||
triggerDataUpdate(); | ||
return; | ||
} | ||
width = | ||
images[0].width > images[1].width | ||
? images[0].width | ||
: images[1].width; | ||
height = | ||
images[0].height > images[1].height | ||
? images[0].height | ||
: images[1].height; | ||
width = images[0].width > images[1].width ? images[0].width : images[1].width; | ||
height = images[0].height > images[1].height ? images[0].height : images[1].height; | ||
if ( | ||
images[0].width === images[1].width && | ||
images[0].height === images[1].height | ||
) { | ||
if (images[0].width === images[1].width && images[0].height === images[1].height) { | ||
data.isSameDimensions = true; | ||
@@ -935,8 +857,3 @@ } else { | ||
analyseImages( | ||
normalise(images[0], width, height), | ||
normalise(images[1], width, height), | ||
width, | ||
height | ||
); | ||
analyseImages(normalise(images[0], width, height), normalise(images[1], width, height), width, height); | ||
@@ -962,3 +879,3 @@ triggerDataUpdate(); | ||
var self = { | ||
setReturnEarlyThreshold: function(threshold) { | ||
setReturnEarlyThreshold: function (threshold) { | ||
if (threshold) { | ||
@@ -970,3 +887,3 @@ compareOnly = true; | ||
}, | ||
scaleToSameSize: function() { | ||
scaleToSameSize: function () { | ||
scaleToSameSize = true; | ||
@@ -979,3 +896,3 @@ | ||
}, | ||
useOriginalSize: function() { | ||
useOriginalSize: function () { | ||
scaleToSameSize = false; | ||
@@ -988,3 +905,3 @@ | ||
}, | ||
ignoreNothing: function() { | ||
ignoreNothing: function () { | ||
tolerance.red = 0; | ||
@@ -1005,3 +922,3 @@ tolerance.green = 0; | ||
}, | ||
ignoreLess: function() { | ||
ignoreLess: function () { | ||
tolerance.red = 16; | ||
@@ -1022,3 +939,3 @@ tolerance.green = 16; | ||
}, | ||
ignoreAntialiasing: function() { | ||
ignoreAntialiasing: function () { | ||
tolerance.red = 32; | ||
@@ -1039,3 +956,3 @@ tolerance.green = 32; | ||
}, | ||
ignoreColors: function() { | ||
ignoreColors: function () { | ||
tolerance.alpha = 16; | ||
@@ -1053,3 +970,3 @@ tolerance.minBrightness = 16; | ||
}, | ||
ignoreAlpha: function() { | ||
ignoreAlpha: function () { | ||
tolerance.red = 16; | ||
@@ -1070,3 +987,3 @@ tolerance.green = 16; | ||
}, | ||
repaint: function() { | ||
repaint: function () { | ||
if (hasMethod) { | ||
@@ -1077,10 +994,10 @@ param(); | ||
}, | ||
outputSettings: function(options) { | ||
outputSettings: function (options) { | ||
outputSettings(options); | ||
return self; | ||
}, | ||
onComplete: function(callback) { | ||
onComplete: function (callback) { | ||
updateCallbackArray.push(callback); | ||
var wrapper = function() { | ||
var wrapper = function () { | ||
compare(fileData, secondFileData); | ||
@@ -1099,12 +1016,12 @@ }; | ||
var rootSelf = { | ||
onComplete: function(callback) { | ||
onComplete: function (callback) { | ||
updateCallbackArray.push(callback); | ||
loadImageData(fileData, function(imageData, width, height) { | ||
loadImageData(fileData, function (imageData, width, height) { | ||
parseImage(imageData.data, width, height); | ||
}); | ||
}, | ||
compareTo: function(secondFileData) { | ||
compareTo: function (secondFileData) { | ||
return getCompareApi(secondFileData); | ||
}, | ||
outputSettings: function(options) { | ||
outputSettings: function (options) { | ||
outputSettings(options); | ||
@@ -1145,3 +1062,3 @@ return rootSelf; | ||
resemble.compare = function(image1, image2, options, cb) { | ||
resemble.compare = function (image1, image2, options, cb) { | ||
var callback; | ||
@@ -1178,3 +1095,3 @@ var opt; | ||
} else if (opt.ignore && opt.ignore.forEach) { | ||
opt.ignore.forEach(function(v) { | ||
opt.ignore.forEach(function (v) { | ||
applyIgnore(compare, v); | ||
@@ -1184,3 +1101,3 @@ }); | ||
compare.onComplete(function(data) { | ||
compare.onComplete(function (data) { | ||
if (data.error) { | ||
@@ -1187,0 +1104,0 @@ callback(data.error); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
9
11
0
49642
904