testcafe-browser-tools
Advanced tools
Comparing version 1.4.1-git.201708221000 to 1.4.1-git.201708221145
'use strict'; | ||
var _Promise = require('babel-runtime/core-js/promise').default; | ||
var _regeneratorRuntime = require('babel-runtime/regenerator').default; | ||
@@ -15,11 +13,11 @@ | ||
var _fs = require('fs'); | ||
var _utilsEnsureDirectory = require('../utils/ensure-directory'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _utilsEnsureDirectory2 = _interopRequireDefault(_utilsEnsureDirectory); | ||
var _pngjs = require('pngjs'); | ||
var _utilsExec = require('../utils/exec'); | ||
var _utilsEnsureDirectory = require('../utils/ensure-directory'); | ||
var _binaries = require('../binaries'); | ||
var _utilsEnsureDirectory2 = _interopRequireDefault(_utilsEnsureDirectory); | ||
var _binaries2 = _interopRequireDefault(_binaries); | ||
@@ -29,135 +27,2 @@ var DEFAULT_THUMBNAIL_WIDTH = 240; | ||
function cubicInterpolation(t, t2, t3, f) { | ||
var C = [0 - 1 * t + 2 * t2 - 1 * t3, 2 + 0 * t - 5 * t2 + 3 * t3, 0 + 1 * t + 4 * t2 - 3 * t3, 0 + 0 * t - 1 * t2 + 1 * t3]; | ||
return 0.5 * (C[0] * f[0] + C[1] * f[1] + C[2] * f[2] + C[3] * f[3]); | ||
} | ||
function getSubpixel(img, y, x, channel) { | ||
if (y >= img.height || x >= img.width || y < 0 || x < 0) return 0; | ||
return img.data[y * img.width * 4 + x * 4 + channel]; | ||
} | ||
function setSubpixel(img, y, x, channel, color) { | ||
if (y >= img.height || x >= img.width || y < 0 || x < 0) return; | ||
if (color > 255) color = 255;else if (color < 0) color = 0; | ||
img.data[y * img.width * 4 + x * 4 + channel] = color; | ||
} | ||
function scale(src, width, height) { | ||
var dst = new _pngjs.PNG({ width: width, height: height }); | ||
var cx = src.width / width; | ||
var cy = src.height / height; | ||
var interpolated = [0, 0, 0, 0]; | ||
for (var i = 0; i < height; ++i) { | ||
var targetY = cy * i; | ||
var sourceY = Math.floor(targetY); | ||
var dy = targetY - sourceY; | ||
var dy2 = dy * dy; | ||
var dy3 = dy2 * dy; | ||
for (var j = 0; j < width; ++j) { | ||
var targetX = cx * j; | ||
var sourceX = Math.floor(targetX); | ||
var dx = targetX - sourceX; | ||
var dx2 = dx * dx; | ||
var dx3 = dx2 * dx; | ||
for (var k = 0; k < 3; ++k) { | ||
for (var ii = 0, interpolY = sourceY - 1; ii < 4; ++ii, ++interpolY) { | ||
var pixels = [getSubpixel(src, interpolY, sourceX - 1, k), getSubpixel(src, interpolY, sourceX, k), getSubpixel(src, interpolY, sourceX + 1, k), getSubpixel(src, interpolY, sourceX + 2, k)]; | ||
interpolated[ii] = cubicInterpolation(dx, dx2, dx3, pixels); | ||
} | ||
setSubpixel(dst, i, j, k, cubicInterpolation(dy, dy2, dy3, interpolated)); | ||
} | ||
setSubpixel(dst, i, j, 3, 255); | ||
} | ||
} | ||
return dst; | ||
} | ||
function generate(src, dst, width, height) { | ||
var _this = this; | ||
return new _Promise(function (resolve, reject) { | ||
var srcFileData = _fs2.default.readFileSync(src); | ||
var srcImage = new _pngjs.PNG(); | ||
srcImage.parse(srcFileData, function callee$2$0(e) { | ||
var dstImage, dstFileData; | ||
return _regeneratorRuntime.async(function callee$2$0$(context$3$0) { | ||
while (1) switch (context$3$0.prev = context$3$0.next) { | ||
case 0: | ||
if (e) reject(e); | ||
context$3$0.prev = 1; | ||
dstImage = scale(srcImage, width, height); | ||
dstFileData = _pngjs.PNG.sync.write(dstImage); | ||
context$3$0.prev = 4; | ||
_fs2.default.writeFileSync(dst, dstFileData); | ||
context$3$0.next = 18; | ||
break; | ||
case 8: | ||
context$3$0.prev = 8; | ||
context$3$0.t0 = context$3$0['catch'](4); | ||
context$3$0.t1 = context$3$0.t0.code !== 'ENOENT'; | ||
if (context$3$0.t1) { | ||
context$3$0.next = 15; | ||
break; | ||
} | ||
context$3$0.next = 14; | ||
return _regeneratorRuntime.awrap(_utilsEnsureDirectory2.default(dst)); | ||
case 14: | ||
context$3$0.t1 = !context$3$0.sent; | ||
case 15: | ||
if (!context$3$0.t1) { | ||
context$3$0.next = 17; | ||
break; | ||
} | ||
throw context$3$0.t0; | ||
case 17: | ||
_fs2.default.writeFileSync(dst, dstFileData); | ||
case 18: | ||
resolve(); | ||
context$3$0.next = 24; | ||
break; | ||
case 21: | ||
context$3$0.prev = 21; | ||
context$3$0.t2 = context$3$0['catch'](1); | ||
reject(context$3$0.t2); | ||
case 24: | ||
case 'end': | ||
return context$3$0.stop(); | ||
} | ||
}, null, _this, [[1, 21], [4, 8]]); | ||
}); | ||
}); | ||
} | ||
function getThumbnailPath(imagePath) { | ||
@@ -206,3 +71,3 @@ var imageName = _path2.default.basename(imagePath); | ||
context$2$0.next = 6; | ||
return _regeneratorRuntime.awrap(generate(sourcePath, thumbnailPath, width, height)); | ||
return _regeneratorRuntime.awrap(_utilsExec.execFile(_binaries2.default.generateThumbnail, [sourcePath, thumbnailPath, width, height])); | ||
@@ -209,0 +74,0 @@ case 6: |
@@ -41,4 +41,8 @@ 'use strict'; | ||
case 0: | ||
if (_utilsEnsureDirectory2.default(screenshotPath)) { | ||
context$1$0.next = 2; | ||
context$1$0.next = 2; | ||
return _regeneratorRuntime.awrap(_utilsEnsureDirectory2.default(screenshotPath)); | ||
case 2: | ||
if (context$1$0.sent) { | ||
context$1$0.next = 4; | ||
break; | ||
@@ -49,24 +53,24 @@ } | ||
case 2: | ||
case 4: | ||
if (!(typeof windowDescriptor === 'string')) { | ||
context$1$0.next = 8; | ||
context$1$0.next = 10; | ||
break; | ||
} | ||
context$1$0.next = 5; | ||
context$1$0.next = 7; | ||
return _regeneratorRuntime.awrap(_findWindow2.default(windowDescriptor)); | ||
case 5: | ||
case 7: | ||
context$1$0.t0 = context$1$0.sent; | ||
context$1$0.next = 9; | ||
context$1$0.next = 11; | ||
break; | ||
case 8: | ||
case 10: | ||
context$1$0.t0 = windowDescriptor; | ||
case 9: | ||
case 11: | ||
windowDescription = context$1$0.t0; | ||
if (windowDescription) { | ||
context$1$0.next = 12; | ||
context$1$0.next = 14; | ||
break; | ||
@@ -77,3 +81,3 @@ } | ||
case 12: | ||
case 14: | ||
screenshotArguments = void 0; | ||
@@ -83,6 +87,6 @@ | ||
context$1$0.next = 16; | ||
context$1$0.next = 18; | ||
return _regeneratorRuntime.awrap(_utilsExec.execFile(_binaries2.default.screenshot, screenshotArguments.concat(screenshotPath))); | ||
case 16: | ||
case 18: | ||
case 'end': | ||
@@ -89,0 +93,0 @@ return context$1$0.stop(); |
@@ -1,2 +0,1 @@ | ||
/*eslint-disable*/ | ||
'use strict'; | ||
@@ -16,2 +15,6 @@ | ||
var _mkdirp = require('mkdirp'); | ||
var _mkdirp2 = _interopRequireDefault(_mkdirp); | ||
var _promisify = require('./promisify'); | ||
@@ -21,6 +24,2 @@ | ||
var _mkdirp = require('mkdirp'); | ||
var _mkdirp2 = _interopRequireDefault(_mkdirp); | ||
var stat = _promisify2.default(_fs2.default.stat); | ||
@@ -34,22 +33,18 @@ var mkdir = _promisify2.default(_mkdirp2.default); | ||
context$1$0.prev = 0; | ||
console.log('directory created', directoryPath); | ||
context$1$0.next = 4; | ||
context$1$0.next = 3; | ||
return _regeneratorRuntime.awrap(mkdir(directoryPath)); | ||
case 4: | ||
case 3: | ||
return context$1$0.abrupt('return', true); | ||
case 7: | ||
context$1$0.prev = 7; | ||
case 6: | ||
context$1$0.prev = 6; | ||
context$1$0.t0 = context$1$0['catch'](0); | ||
console.log('failed to create directory', directoryPath); | ||
return context$1$0.abrupt('return', false); | ||
case 11: | ||
case 9: | ||
case 'end': | ||
return context$1$0.stop(); | ||
} | ||
}, null, this, [[0, 7]]); | ||
}, null, this, [[0, 6]]); | ||
} | ||
@@ -56,0 +51,0 @@ |
{ | ||
"name": "testcafe-browser-tools", | ||
"version": "1.4.1-git.201708221000", | ||
"version": "1.4.1-git.201708221145", | ||
"description": "An utility library for performing platform-dependent actions on browsers.", | ||
@@ -24,3 +24,2 @@ "homepage": "https://github.com/DevExpress/testcafe-browser-tools", | ||
"pinkie": "^2.0.1", | ||
"pngjs": "^3.3.0", | ||
"read-file-relative": "^1.2.0", | ||
@@ -27,0 +26,0 @@ "which-promise": "^1.0.0" |
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
9
3
1594071
1554
- Removedpngjs@^3.3.0
- Removedpngjs@3.4.0(transitive)