testcafe-browser-tools
Advanced tools
Comparing version 1.4.1-git.201708221245 to 1.4.1-git.201708221400
'use strict'; | ||
var _Promise = require('babel-runtime/core-js/promise').default; | ||
var _regeneratorRuntime = require('babel-runtime/regenerator').default; | ||
@@ -15,11 +13,11 @@ | ||
var _gracefulFs = require('graceful-fs'); | ||
var _utilsEnsureDirectory = require('../utils/ensure-directory'); | ||
var _gracefulFs2 = _interopRequireDefault(_gracefulFs); | ||
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,87 +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) { | ||
return new _Promise(function (resolve, reject) { | ||
var srcFileData = _gracefulFs2.default.readFileSync(src); | ||
var srcImage = new _pngjs.PNG(); | ||
srcImage.parse(srcFileData, function (e) { | ||
if (e) reject(e); | ||
try { | ||
var dstImage = scale(srcImage, width, height); | ||
var dstFileData = _pngjs.PNG.sync.write(dstImage); | ||
_gracefulFs2.default.writeFileSync(dst, dstFileData); | ||
resolve(); | ||
} catch (e3) { | ||
reject(e3); | ||
} | ||
}); | ||
}); | ||
} | ||
function getThumbnailPath(imagePath) { | ||
@@ -158,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])); | ||
@@ -161,0 +74,0 @@ case 6: |
@@ -28,4 +28,3 @@ 'use strict'; | ||
var stat = _promisify2.default(_gracefulFs2.default.stat); | ||
var open = _promisify2.default(_gracefulFs2.default.open); | ||
var close = _promisify2.default(_gracefulFs2.default.close); | ||
var readdir = _promisify2.default(_gracefulFs2.default.readdir); | ||
var mkdir = _promisify2.default(_mkdirp2.default); | ||
@@ -59,5 +58,4 @@ | ||
function openFile(fileName) { | ||
var fd; | ||
return _regeneratorRuntime.async(function openFile$(context$1$0) { | ||
function readDirectory(directoryPath) { | ||
return _regeneratorRuntime.async(function readDirectory$(context$1$0) { | ||
while (1) switch (context$1$0.prev = context$1$0.next) { | ||
@@ -67,90 +65,84 @@ case 0: | ||
context$1$0.next = 3; | ||
return _regeneratorRuntime.awrap(open(fileName, 'a')); | ||
return _regeneratorRuntime.awrap(readdir(directoryPath)); | ||
case 3: | ||
fd = context$1$0.sent; | ||
context$1$0.next = 6; | ||
return _regeneratorRuntime.awrap(close(fd)); | ||
return context$1$0.abrupt('return', true); | ||
case 6: | ||
return context$1$0.abrupt('return', true); | ||
case 9: | ||
context$1$0.prev = 9; | ||
context$1$0.prev = 6; | ||
context$1$0.t0 = context$1$0['catch'](0); | ||
return context$1$0.abrupt('return', false); | ||
case 12: | ||
case 9: | ||
case 'end': | ||
return context$1$0.stop(); | ||
} | ||
}, null, this, [[0, 9]]); | ||
}, null, this, [[0, 6]]); | ||
} | ||
function ensureFile(fileName) { | ||
var directoryPath, fileEnsured, i; | ||
return _regeneratorRuntime.async(function ensureFile$(context$1$0) { | ||
function ensureDirectory(directoryPath) { | ||
var fileEnsured, i; | ||
return _regeneratorRuntime.async(function ensureDirectory$(context$1$0) { | ||
while (1) switch (context$1$0.prev = context$1$0.next) { | ||
case 0: | ||
directoryPath = _path.dirname(fileName); | ||
context$1$0.next = 3; | ||
context$1$0.next = 2; | ||
return _regeneratorRuntime.awrap(createDirectory(directoryPath)); | ||
case 3: | ||
case 2: | ||
context$1$0.t0 = context$1$0.sent; | ||
if (!context$1$0.t0) { | ||
context$1$0.next = 8; | ||
context$1$0.next = 7; | ||
break; | ||
} | ||
context$1$0.next = 7; | ||
return _regeneratorRuntime.awrap(openFile(fileName)); | ||
context$1$0.next = 6; | ||
return _regeneratorRuntime.awrap(readDirectory(directoryPath)); | ||
case 7: | ||
case 6: | ||
context$1$0.t0 = context$1$0.sent; | ||
case 8: | ||
case 7: | ||
fileEnsured = context$1$0.t0; | ||
i = 0; | ||
case 10: | ||
case 9: | ||
if (!(i < MAX_RETRY_COUNT && !fileEnsured)) { | ||
context$1$0.next = 24; | ||
context$1$0.next = 23; | ||
break; | ||
} | ||
context$1$0.next = 13; | ||
context$1$0.next = 12; | ||
return _regeneratorRuntime.awrap(_delay2.default(RETRY_DELAY)); | ||
case 13: | ||
context$1$0.next = 15; | ||
case 12: | ||
context$1$0.next = 14; | ||
return _regeneratorRuntime.awrap(createDirectory(directoryPath)); | ||
case 15: | ||
case 14: | ||
context$1$0.t1 = context$1$0.sent; | ||
if (!context$1$0.t1) { | ||
context$1$0.next = 20; | ||
context$1$0.next = 19; | ||
break; | ||
} | ||
context$1$0.next = 19; | ||
return _regeneratorRuntime.awrap(openFile(fileName)); | ||
context$1$0.next = 18; | ||
return _regeneratorRuntime.awrap(readDirectory(directoryPath)); | ||
case 19: | ||
case 18: | ||
context$1$0.t1 = context$1$0.sent; | ||
case 20: | ||
case 19: | ||
fileEnsured = context$1$0.t1; | ||
case 21: | ||
case 20: | ||
i++; | ||
context$1$0.next = 10; | ||
context$1$0.next = 9; | ||
break; | ||
case 24: | ||
case 23: | ||
return context$1$0.abrupt('return', fileEnsured); | ||
case 25: | ||
case 24: | ||
case 'end': | ||
@@ -186,3 +178,3 @@ return context$1$0.stop(); | ||
context$1$0.next = 13; | ||
return _regeneratorRuntime.awrap(ensureFile(fileName)); | ||
return _regeneratorRuntime.awrap(ensureDirectory(directoryPath)); | ||
@@ -189,0 +181,0 @@ case 13: |
{ | ||
"name": "testcafe-browser-tools", | ||
"version": "1.4.1-git.201708221245", | ||
"version": "1.4.1-git.201708221400", | ||
"description": "An utility library for performing platform-dependent actions on browsers.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/DevExpress/testcafe-browser-tools", |
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
1597174
1632