-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
43 lines (35 loc) · 907 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var getStyle = require('get-style-property');
function CssMatrixTransformation(){
this._initRegexs();
}
CssMatrixTransformation.prototype = {
_initRegexs: function(){
var floating = '(\\-?[\\d\\.e]+)';
var commaSpace = '\\,?\\s*';
this.regex = {
matrix: new RegExp(
'^matrix\\(' +
floating + commaSpace +
floating + commaSpace +
floating + commaSpace +
floating + commaSpace +
floating + commaSpace +
floating + '\\)$')
};
},
parse: function(transform){
var matrix = this.regex.matrix.exec(transform);
if (matrix) {
matrix.shift();
for (var i = matrix.length-1; i >= 0 ; i--) {
matrix[i] = parseFloat(matrix[i]);
};
}
return matrix || [ 1, 0, 0, 1, 0, 0 ];
},
fromElement: function(element){
var transform = getStyle(element, 'transform');
return this.parse(transform);
}
}
module.exports = new CssMatrixTransformation();