UNPKG

3.84 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.deleteProps = deleteProps;
5exports.nextTick = nextTick;
6exports.now = now;
7exports.getTranslate = getTranslate;
8exports.isObject = isObject;
9exports.extend = extend;
10exports.bindModuleMethods = bindModuleMethods;
11
12var _ssrWindow = require("ssr-window");
13
14function deleteProps(obj) {
15 var object = obj;
16 Object.keys(object).forEach(function (key) {
17 try {
18 object[key] = null;
19 } catch (e) {// no getter for object
20 }
21
22 try {
23 delete object[key];
24 } catch (e) {// something got wrong
25 }
26 });
27}
28
29function nextTick(callback, delay) {
30 if (delay === void 0) {
31 delay = 0;
32 }
33
34 return setTimeout(callback, delay);
35}
36
37function now() {
38 return Date.now();
39}
40
41function getTranslate(el, axis) {
42 if (axis === void 0) {
43 axis = 'x';
44 }
45
46 var window = (0, _ssrWindow.getWindow)();
47 var matrix;
48 var curTransform;
49 var transformMatrix;
50 var curStyle = window.getComputedStyle(el, null);
51
52 if (window.WebKitCSSMatrix) {
53 curTransform = curStyle.transform || curStyle.webkitTransform;
54
55 if (curTransform.split(',').length > 6) {
56 curTransform = curTransform.split(', ').map(function (a) {
57 return a.replace(',', '.');
58 }).join(', ');
59 } // Some old versions of Webkit choke when 'none' is passed; pass
60 // empty string instead in this case
61
62
63 transformMatrix = new window.WebKitCSSMatrix(curTransform === 'none' ? '' : curTransform);
64 } else {
65 transformMatrix = curStyle.MozTransform || curStyle.OTransform || curStyle.MsTransform || curStyle.msTransform || curStyle.transform || curStyle.getPropertyValue('transform').replace('translate(', 'matrix(1, 0, 0, 1,');
66 matrix = transformMatrix.toString().split(',');
67 }
68
69 if (axis === 'x') {
70 // Latest Chrome and webkits Fix
71 if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41; // Crazy IE10 Matrix
72 else if (matrix.length === 16) curTransform = parseFloat(matrix[12]); // Normal Browsers
73 else curTransform = parseFloat(matrix[4]);
74 }
75
76 if (axis === 'y') {
77 // Latest Chrome and webkits Fix
78 if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42; // Crazy IE10 Matrix
79 else if (matrix.length === 16) curTransform = parseFloat(matrix[13]); // Normal Browsers
80 else curTransform = parseFloat(matrix[5]);
81 }
82
83 return curTransform || 0;
84}
85
86function isObject(o) {
87 return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object;
88}
89
90function extend() {
91 var to = Object(arguments.length <= 0 ? undefined : arguments[0]);
92
93 for (var i = 1; i < arguments.length; i += 1) {
94 var nextSource = i < 0 || arguments.length <= i ? undefined : arguments[i];
95
96 if (nextSource !== undefined && nextSource !== null) {
97 var keysArray = Object.keys(Object(nextSource));
98
99 for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex += 1) {
100 var nextKey = keysArray[nextIndex];
101 var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
102
103 if (desc !== undefined && desc.enumerable) {
104 if (isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
105 extend(to[nextKey], nextSource[nextKey]);
106 } else if (!isObject(to[nextKey]) && isObject(nextSource[nextKey])) {
107 to[nextKey] = {};
108 extend(to[nextKey], nextSource[nextKey]);
109 } else {
110 to[nextKey] = nextSource[nextKey];
111 }
112 }
113 }
114 }
115 }
116
117 return to;
118}
119
120function bindModuleMethods(instance, obj) {
121 Object.keys(obj).forEach(function (key) {
122 if (isObject(obj[key])) {
123 Object.keys(obj[key]).forEach(function (subKey) {
124 if (typeof obj[key][subKey] === 'function') {
125 obj[key][subKey] = obj[key][subKey].bind(instance);
126 }
127 });
128 }
129
130 instance[key] = obj[key];
131 });
132}
\No newline at end of file