1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _typeof = require("@babel/runtime/helpers/typeof");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.default = void 0;
|
11 |
|
12 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
13 |
|
14 | var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
15 |
|
16 | var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
17 |
|
18 | var _interpolate = _interopRequireDefault(require("./interpolate"));
|
19 |
|
20 | var Easing = _interopRequireWildcard(require("./easing"));
|
21 |
|
22 | var _jsx = require("../../jsx");
|
23 |
|
24 | var _util = require("@antv/util");
|
25 |
|
26 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
27 |
|
28 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
29 |
|
30 | var Animator = function () {
|
31 | function Animator(element, animation) {
|
32 | (0, _classCallCheck2.default)(this, Animator);
|
33 |
|
34 | this.isClip = false;
|
35 | this.end = false;
|
36 | this.element = element;
|
37 | this.animation = animation;
|
38 | var _animation$property = animation.property,
|
39 | property = _animation$property === void 0 ? [] : _animation$property,
|
40 | easing = animation.easing,
|
41 | duration = animation.duration,
|
42 | _animation$delay = animation.delay,
|
43 | delay = _animation$delay === void 0 ? 0 : _animation$delay,
|
44 | start = animation.start,
|
45 | end = animation.end,
|
46 | onFrame = animation.onFrame,
|
47 | isClip = animation.isClip;
|
48 | var interpolates = property.map(function (name) {
|
49 | if ((0, _util.isString)(name)) {
|
50 | return (0, _interpolate.default)(start[name], end[name]);
|
51 | }
|
52 |
|
53 |
|
54 | if (name.interpolate) {
|
55 |
|
56 | return name.interpolate(start, end);
|
57 | }
|
58 | });
|
59 | this.easing = typeof easing === 'function' ? easing : Easing[easing] || Easing.linear;
|
60 | this.property = property;
|
61 | this.interpolates = interpolates;
|
62 | this.duration = duration;
|
63 | this.delay = delay;
|
64 | this.onFrame = onFrame;
|
65 | this.totalDuration = duration + delay;
|
66 | this.isClip = isClip;
|
67 |
|
68 | this.update(0, 0);
|
69 | }
|
70 |
|
71 | (0, _createClass2.default)(Animator, [{
|
72 | key: "to",
|
73 | value: function to(time) {
|
74 | var duration = this.duration,
|
75 | delay = this.delay,
|
76 | totalDuration = this.totalDuration,
|
77 | easing = this.easing,
|
78 | end = this.end;
|
79 |
|
80 | if (end) {
|
81 | return;
|
82 | }
|
83 |
|
84 |
|
85 | if (time <= delay || !duration) {
|
86 | return;
|
87 | }
|
88 |
|
89 |
|
90 | var t = time >= totalDuration ? 1 : (time - delay) / duration;
|
91 | this.update(easing(t), time);
|
92 |
|
93 | if (t === 1) {
|
94 | this.onEnd();
|
95 | }
|
96 | }
|
97 | }, {
|
98 | key: "update",
|
99 | value: function update(t, time) {
|
100 | var element = this.element,
|
101 | interpolates = this.interpolates,
|
102 | property = this.property,
|
103 | onFrame = this.onFrame;
|
104 | var attrs = {};
|
105 |
|
106 | for (var i = property.length - 1; i >= 0; i--) {
|
107 | var name = property[i];
|
108 |
|
109 | if ((0, _util.isString)(name)) {
|
110 | attrs[name] = interpolates[i](t);
|
111 | } else {
|
112 |
|
113 | attrs[name.name] = interpolates[i](t);
|
114 | }
|
115 | }
|
116 |
|
117 | if (onFrame) {
|
118 | attrs = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, attrs), this.onFrame(t, time));
|
119 | }
|
120 |
|
121 | element.attr(attrs);
|
122 | }
|
123 | }, {
|
124 | key: "onEnd",
|
125 | value: function onEnd() {
|
126 | var animation = this.animation,
|
127 | isClip = this.isClip,
|
128 | element = this.element;
|
129 | var onEnd = animation.onEnd;
|
130 | onEnd && onEnd.call(this);
|
131 |
|
132 | if (isClip) {
|
133 |
|
134 | element.remove(true);
|
135 | }
|
136 |
|
137 |
|
138 | if (element._attrs.status === _jsx.ElementStatus.ELEMENT_DELETE) {
|
139 | element.remove(true);
|
140 | }
|
141 |
|
142 |
|
143 | element.set('animation', null);
|
144 | this.end = true;
|
145 | }
|
146 | }]);
|
147 | return Animator;
|
148 | }();
|
149 |
|
150 | var _default = Animator;
|
151 | exports.default = _default; |
\ | No newline at end of file |