1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.deleteProps = deleteProps;
|
5 | exports.nextTick = nextTick;
|
6 | exports.now = now;
|
7 | exports.getTranslate = getTranslate;
|
8 | exports.isObject = isObject;
|
9 | exports.extend = extend;
|
10 | exports.bindModuleMethods = bindModuleMethods;
|
11 |
|
12 | var _ssrWindow = require("ssr-window");
|
13 |
|
14 | function deleteProps(obj) {
|
15 | var object = obj;
|
16 | Object.keys(object).forEach(function (key) {
|
17 | try {
|
18 | object[key] = null;
|
19 | } catch (e) {
|
20 | }
|
21 |
|
22 | try {
|
23 | delete object[key];
|
24 | } catch (e) {
|
25 | }
|
26 | });
|
27 | }
|
28 |
|
29 | function nextTick(callback, delay) {
|
30 | if (delay === void 0) {
|
31 | delay = 0;
|
32 | }
|
33 |
|
34 | return setTimeout(callback, delay);
|
35 | }
|
36 |
|
37 | function now() {
|
38 | return Date.now();
|
39 | }
|
40 |
|
41 | function 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 | }
|
60 |
|
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 |
|
71 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m41;
|
72 | else if (matrix.length === 16) curTransform = parseFloat(matrix[12]);
|
73 | else curTransform = parseFloat(matrix[4]);
|
74 | }
|
75 |
|
76 | if (axis === 'y') {
|
77 |
|
78 | if (window.WebKitCSSMatrix) curTransform = transformMatrix.m42;
|
79 | else if (matrix.length === 16) curTransform = parseFloat(matrix[13]);
|
80 | else curTransform = parseFloat(matrix[5]);
|
81 | }
|
82 |
|
83 | return curTransform || 0;
|
84 | }
|
85 |
|
86 | function isObject(o) {
|
87 | return typeof o === 'object' && o !== null && o.constructor && o.constructor === Object;
|
88 | }
|
89 |
|
90 | function 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 |
|
120 | function 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 |