html2canvas
Version:
Screenshots with JavaScript
67 lines (50 loc) • 1.83 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.parseTransform = void 0;
var _Length = _interopRequireDefault(require("../Length"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var toFloat = function toFloat(s) {
return parseFloat(s.trim());
};
var MATRIX = /(matrix|matrix3d)\((.+)\)/;
var parseTransform = function parseTransform(style) {
var transform = parseTransformMatrix(style.transform || style.webkitTransform || style.mozTransform || // $FlowFixMe
style.msTransform || // $FlowFixMe
style.oTransform);
if (transform === null) {
return null;
}
return {
transform: transform,
transformOrigin: parseTransformOrigin(style.transformOrigin || style.webkitTransformOrigin || style.mozTransformOrigin || // $FlowFixMe
style.msTransformOrigin || // $FlowFixMe
style.oTransformOrigin)
};
}; // $FlowFixMe
exports.parseTransform = parseTransform;
var parseTransformOrigin = function parseTransformOrigin(origin) {
if (typeof origin !== 'string') {
var v = new _Length.default('0');
return [v, v];
}
var values = origin.split(' ').map(_Length.default.create);
return [values[0], values[1]];
}; // $FlowFixMe
var parseTransformMatrix = function parseTransformMatrix(transform) {
if (transform === 'none' || typeof transform !== 'string') {
return null;
}
var match = transform.match(MATRIX);
if (match) {
if (match[1] === 'matrix') {
var matrix = match[2].split(',').map(toFloat);
return [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]];
} else {
var matrix3d = match[2].split(',').map(toFloat);
return [matrix3d[0], matrix3d[1], matrix3d[4], matrix3d[5], matrix3d[12], matrix3d[13]];
}
}
return null;
};
;