@antv/g 6.2.0 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +3140 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3158 -26
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +25 -22
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +8 -8
- package/types/index.d.ts +5 -3
- package/types/index.d.ts.map +1 -1
- package/types/plugins/camera-api/AdvancedCamera.d.ts +44 -0
- package/types/plugins/camera-api/AdvancedCamera.d.ts.map +1 -0
- package/types/plugins/camera-api/index.d.ts +3 -0
- package/types/plugins/camera-api/index.d.ts.map +1 -0
- package/types/plugins/components/Arrow.d.ts +61 -0
- package/types/plugins/components/Arrow.d.ts.map +1 -0
- package/types/plugins/components/Sector.d.ts +21 -0
- package/types/plugins/components/Sector.d.ts.map +1 -0
- package/types/plugins/components/Sector2.d.ts +9 -0
- package/types/plugins/components/Sector2.d.ts.map +1 -0
- package/types/plugins/components/index.d.ts +3 -0
- package/types/plugins/components/index.d.ts.map +1 -0
- package/types/plugins/image-exporter/ImageExporter.d.ts +27 -0
- package/types/plugins/image-exporter/ImageExporter.d.ts.map +1 -0
- package/types/plugins/image-exporter/index.d.ts +3 -0
- package/types/plugins/image-exporter/index.d.ts.map +1 -0
- package/types/plugins/image-exporter/types.d.ts +12 -0
- package/types/plugins/image-exporter/types.d.ts.map +1 -0
- package/types/plugins/pattern/dots.d.ts +16 -0
- package/types/plugins/pattern/dots.d.ts.map +1 -0
- package/types/plugins/pattern/index.d.ts +4 -0
- package/types/plugins/pattern/index.d.ts.map +1 -0
- package/types/plugins/pattern/interfaces.d.ts +78 -0
- package/types/plugins/pattern/interfaces.d.ts.map +1 -0
- package/types/plugins/pattern/lines.d.ts +19 -0
- package/types/plugins/pattern/lines.d.ts.map +1 -0
- package/types/plugins/pattern/squares.d.ts +21 -0
- package/types/plugins/pattern/squares.d.ts.map +1 -0
- package/types/plugins/pattern/util.d.ts +18 -0
- package/types/plugins/pattern/util.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/Animation.d.ts +135 -0
- package/types/plugins/web-animations-api/dom/Animation.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/AnimationEffectTiming.d.ts +59 -0
- package/types/plugins/web-animations-api/dom/AnimationEffectTiming.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/AnimationEvent.d.ts +12 -0
- package/types/plugins/web-animations-api/dom/AnimationEvent.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/AnimationTimeline.d.ts +40 -0
- package/types/plugins/web-animations-api/dom/AnimationTimeline.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/KeyframeEffect.d.ts +48 -0
- package/types/plugins/web-animations-api/dom/KeyframeEffect.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/KeyframeList.d.ts +3 -0
- package/types/plugins/web-animations-api/dom/KeyframeList.d.ts.map +1 -0
- package/types/plugins/web-animations-api/dom/index.d.ts +6 -0
- package/types/plugins/web-animations-api/dom/index.d.ts.map +1 -0
- package/types/plugins/web-animations-api/index.d.ts +3 -0
- package/types/plugins/web-animations-api/index.d.ts.map +1 -0
- package/types/plugins/web-animations-api/utils/animation.d.ts +16 -0
- package/types/plugins/web-animations-api/utils/animation.d.ts.map +1 -0
- package/types/plugins/web-animations-api/utils/bezier-easing.d.ts +21 -0
- package/types/plugins/web-animations-api/utils/bezier-easing.d.ts.map +1 -0
- package/types/plugins/web-animations-api/utils/custom-easing.d.ts +16 -0
- package/types/plugins/web-animations-api/utils/custom-easing.d.ts.map +1 -0
- package/types/plugins/web-animations-api/utils/index.d.ts +5 -0
- package/types/plugins/web-animations-api/utils/index.d.ts.map +1 -0
- package/types/plugins/web-animations-api/utils/interpolation.d.ts +3 -0
- package/types/plugins/web-animations-api/utils/interpolation.d.ts.map +1 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,13 +1,3148 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* @antv/g
|
|
3
3
|
* @description A core module for rendering engine implements DOM API.
|
|
4
|
-
* @version 6.
|
|
5
|
-
* @date 12/
|
|
4
|
+
* @version 6.3.0
|
|
5
|
+
* @date 12/22/2025, 3:03:01 AM
|
|
6
6
|
* @author AntVis
|
|
7
7
|
* @docs https://g.antv.antgroup.com/
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
export * from '@antv/g-dom-mutation-observer-api';
|
|
9
|
+
import { FederatedEvent, ERROR_MSG_METHOD_NOT_IMPLEMENTED, propertyMetadataCache, runtime, getAngle, CameraType, deg2rad, createVec3, Camera, Rectangle, isBrowser, Rect, Circle, Path, CustomElement, ElementEvent, Shape, PropertySyntax, CSS } from '@antv/g-lite';
|
|
11
10
|
export * from '@antv/g-lite';
|
|
12
|
-
|
|
11
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
12
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
13
|
+
import _callSuper from '@babel/runtime/helpers/callSuper';
|
|
14
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
15
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
16
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
17
|
+
import { clamp, isNumber, isNil, isString, isNumberEqual } from '@antv/util';
|
|
18
|
+
import { quat, mat4, vec3 } from 'gl-matrix';
|
|
19
|
+
import _regeneratorRuntime from '@babel/runtime/helpers/regeneratorRuntime';
|
|
20
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
21
|
+
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
22
|
+
import html2canvas from 'html2canvas';
|
|
23
|
+
import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper';
|
|
24
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
25
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
26
|
+
import _superPropGet from '@babel/runtime/helpers/superPropGet';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationPlaybackEvent
|
|
30
|
+
*/
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
var AnimationEvent = /*#__PURE__*/function (_FederatedEvent) {
|
|
33
|
+
function AnimationEvent(manager, target, currentTime, timelineTime) {
|
|
34
|
+
var _this;
|
|
35
|
+
_classCallCheck(this, AnimationEvent);
|
|
36
|
+
_this = _callSuper(this, AnimationEvent, [manager]);
|
|
37
|
+
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
_this.currentTime = currentTime;
|
|
40
|
+
_this.timelineTime = timelineTime;
|
|
41
|
+
_this.target = target;
|
|
42
|
+
_this.type = 'finish';
|
|
43
|
+
_this.bubbles = false;
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
_this.currentTarget = target;
|
|
46
|
+
_this.defaultPrevented = false;
|
|
47
|
+
_this.eventPhase = _this.AT_TARGET;
|
|
48
|
+
_this.timeStamp = Date.now();
|
|
49
|
+
_this.currentTime = currentTime;
|
|
50
|
+
_this.timelineTime = timelineTime;
|
|
51
|
+
return _this;
|
|
52
|
+
}
|
|
53
|
+
_inherits(AnimationEvent, _FederatedEvent);
|
|
54
|
+
return _createClass(AnimationEvent);
|
|
55
|
+
}(FederatedEvent);
|
|
56
|
+
|
|
57
|
+
var sequenceNumber = 0;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/Animation
|
|
61
|
+
*/
|
|
62
|
+
var Animation = /*#__PURE__*/function () {
|
|
63
|
+
function Animation(effect, timeline) {
|
|
64
|
+
var _this$effect;
|
|
65
|
+
_classCallCheck(this, Animation);
|
|
66
|
+
this.currentTimePending = false;
|
|
67
|
+
/**
|
|
68
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/playState
|
|
69
|
+
*/
|
|
70
|
+
// playState: AnimationPlayState;
|
|
71
|
+
this._idle = true;
|
|
72
|
+
this._paused = false;
|
|
73
|
+
this._finishedFlag = true;
|
|
74
|
+
/**
|
|
75
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/currentTime
|
|
76
|
+
*/
|
|
77
|
+
this._currentTime = 0;
|
|
78
|
+
this._playbackRate = 1;
|
|
79
|
+
this._inTimeline = true;
|
|
80
|
+
this.effect = effect;
|
|
81
|
+
effect.animation = this;
|
|
82
|
+
this.timeline = timeline;
|
|
83
|
+
this.id = "".concat(sequenceNumber++);
|
|
84
|
+
this._inEffect = !!this.effect.update(0);
|
|
85
|
+
this._totalDuration = Number((_this$effect = this.effect) === null || _this$effect === void 0 ? void 0 : _this$effect.getComputedTiming().endTime);
|
|
86
|
+
this._holdTime = 0;
|
|
87
|
+
this._paused = false;
|
|
88
|
+
this.oldPlayState = 'idle';
|
|
89
|
+
this.updatePromises();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* state machine,
|
|
94
|
+
* resolve/reject ready/finished Promise according to current state
|
|
95
|
+
*/
|
|
96
|
+
return _createClass(Animation, [{
|
|
97
|
+
key: "pending",
|
|
98
|
+
get:
|
|
99
|
+
/**
|
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/effect
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/timeline
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/id
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
// animation: InternalAnimation | null;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/pending
|
|
115
|
+
*/
|
|
116
|
+
function get() {
|
|
117
|
+
return this._startTime === null && !this._paused && this.playbackRate !== 0 || this.currentTimePending;
|
|
118
|
+
}
|
|
119
|
+
}, {
|
|
120
|
+
key: "playState",
|
|
121
|
+
get: function get() {
|
|
122
|
+
if (this._idle) return 'idle';
|
|
123
|
+
if (this._isFinished) return 'finished';
|
|
124
|
+
if (this._paused) return 'paused';
|
|
125
|
+
return 'running';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* record previos state
|
|
130
|
+
*/
|
|
131
|
+
}, {
|
|
132
|
+
key: "ready",
|
|
133
|
+
get:
|
|
134
|
+
/**
|
|
135
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/ready
|
|
136
|
+
* @example
|
|
137
|
+
animation.pause();
|
|
138
|
+
animation.ready.then(function() {
|
|
139
|
+
// Displays 'running'
|
|
140
|
+
alert(animation.playState);
|
|
141
|
+
});
|
|
142
|
+
animation.play();
|
|
143
|
+
*/
|
|
144
|
+
function get() {
|
|
145
|
+
var _this = this;
|
|
146
|
+
if (!this.readyPromise) {
|
|
147
|
+
if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
|
|
148
|
+
this.timeline.animationsWithPromises.push(this);
|
|
149
|
+
}
|
|
150
|
+
this.readyPromise = new Promise(function (resolve, reject) {
|
|
151
|
+
_this.resolveReadyPromise = function () {
|
|
152
|
+
resolve(_this);
|
|
153
|
+
};
|
|
154
|
+
_this.rejectReadyPromise = function () {
|
|
155
|
+
reject(new Error());
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
if (!this.pending) {
|
|
159
|
+
this.resolveReadyPromise();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return this.readyPromise;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/finished
|
|
167
|
+
* @example
|
|
168
|
+
Promise.all(
|
|
169
|
+
elem.getAnimations().map(
|
|
170
|
+
function(animation) {
|
|
171
|
+
return animation.finished
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
).then(
|
|
175
|
+
function() {
|
|
176
|
+
return elem.remove();
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
*/
|
|
180
|
+
}, {
|
|
181
|
+
key: "finished",
|
|
182
|
+
get: function get() {
|
|
183
|
+
var _this2 = this;
|
|
184
|
+
if (!this.finishedPromise) {
|
|
185
|
+
if (this.timeline.animationsWithPromises.indexOf(this) === -1) {
|
|
186
|
+
this.timeline.animationsWithPromises.push(this);
|
|
187
|
+
}
|
|
188
|
+
this.finishedPromise = new Promise(function (resolve, reject) {
|
|
189
|
+
_this2.resolveFinishedPromise = function () {
|
|
190
|
+
resolve(_this2);
|
|
191
|
+
};
|
|
192
|
+
_this2.rejectFinishedPromise = function () {
|
|
193
|
+
reject(new Error());
|
|
194
|
+
};
|
|
195
|
+
});
|
|
196
|
+
if (this.playState === 'finished') {
|
|
197
|
+
this.resolveFinishedPromise();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return this.finishedPromise;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/onfinish
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/oncancel
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* get called after each frame when running
|
|
213
|
+
*/
|
|
214
|
+
}, {
|
|
215
|
+
key: "currentTime",
|
|
216
|
+
get: function get() {
|
|
217
|
+
this.updatePromises();
|
|
218
|
+
return this._idle || this.currentTimePending ? null : this._currentTime;
|
|
219
|
+
},
|
|
220
|
+
set: function set(newTime) {
|
|
221
|
+
newTime = Number(newTime);
|
|
222
|
+
if (isNaN(newTime)) return;
|
|
223
|
+
this.timeline.restart();
|
|
224
|
+
if (!this._paused && this._startTime !== null) {
|
|
225
|
+
var _this$timeline;
|
|
226
|
+
this._startTime = Number((_this$timeline = this.timeline) === null || _this$timeline === void 0 ? void 0 : _this$timeline.currentTime) - newTime / this.playbackRate;
|
|
227
|
+
}
|
|
228
|
+
this.currentTimePending = false;
|
|
229
|
+
if (this._currentTime === newTime) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (this._idle) {
|
|
233
|
+
this._idle = false;
|
|
234
|
+
this._paused = true;
|
|
235
|
+
}
|
|
236
|
+
this.tickCurrentTime(newTime, true);
|
|
237
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/startTime
|
|
242
|
+
*/
|
|
243
|
+
}, {
|
|
244
|
+
key: "startTime",
|
|
245
|
+
get: function get() {
|
|
246
|
+
return this._startTime;
|
|
247
|
+
},
|
|
248
|
+
set: function set(newTime) {
|
|
249
|
+
if (newTime !== null) {
|
|
250
|
+
this.updatePromises();
|
|
251
|
+
newTime = Number(newTime);
|
|
252
|
+
if (isNaN(newTime)) return;
|
|
253
|
+
if (this._paused || this._idle) return;
|
|
254
|
+
this._startTime = newTime;
|
|
255
|
+
this.tickCurrentTime((Number(this.timeline.currentTime) - this._startTime) * this.playbackRate);
|
|
256
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
257
|
+
this.updatePromises();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}, {
|
|
261
|
+
key: "playbackRate",
|
|
262
|
+
get: function get() {
|
|
263
|
+
return this._playbackRate;
|
|
264
|
+
},
|
|
265
|
+
set: function set(value) {
|
|
266
|
+
if (value === this._playbackRate) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
this.updatePromises();
|
|
270
|
+
var oldCurrentTime = this.currentTime;
|
|
271
|
+
this._playbackRate = value;
|
|
272
|
+
this.startTime = null;
|
|
273
|
+
if (this.playState !== 'paused' && this.playState !== 'idle') {
|
|
274
|
+
this._finishedFlag = false;
|
|
275
|
+
this._idle = false;
|
|
276
|
+
this.ensureAlive();
|
|
277
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
278
|
+
}
|
|
279
|
+
if (oldCurrentTime !== null) {
|
|
280
|
+
this.currentTime = oldCurrentTime;
|
|
281
|
+
}
|
|
282
|
+
this.updatePromises();
|
|
283
|
+
}
|
|
284
|
+
}, {
|
|
285
|
+
key: "_isFinished",
|
|
286
|
+
get: function get() {
|
|
287
|
+
return !this._idle && (this._playbackRate > 0 && Number(this._currentTime) >= this._totalDuration || this._playbackRate < 0 && Number(this._currentTime) <= 0);
|
|
288
|
+
}
|
|
289
|
+
}, {
|
|
290
|
+
key: "totalDuration",
|
|
291
|
+
get: function get() {
|
|
292
|
+
return this._totalDuration;
|
|
293
|
+
}
|
|
294
|
+
}, {
|
|
295
|
+
key: "_needsTick",
|
|
296
|
+
get: function get() {
|
|
297
|
+
return this.pending || this.playState === 'running' || !this._finishedFlag;
|
|
298
|
+
}
|
|
299
|
+
}, {
|
|
300
|
+
key: "updatePromises",
|
|
301
|
+
value: function updatePromises() {
|
|
302
|
+
var _this$effect$target;
|
|
303
|
+
if ((_this$effect$target = this.effect.target) !== null && _this$effect$target !== void 0 && _this$effect$target.destroyed) {
|
|
304
|
+
this.readyPromise = undefined;
|
|
305
|
+
this.finishedPromise = undefined;
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
var oldPlayState = this.oldPlayState;
|
|
309
|
+
var newPlayState = this.pending ? 'pending' : this.playState;
|
|
310
|
+
if (this.readyPromise && newPlayState !== oldPlayState) {
|
|
311
|
+
if (newPlayState === 'idle') {
|
|
312
|
+
this.rejectReadyPromise();
|
|
313
|
+
this.readyPromise = undefined;
|
|
314
|
+
} else if (oldPlayState === 'pending') {
|
|
315
|
+
this.resolveReadyPromise();
|
|
316
|
+
} else if (newPlayState === 'pending') {
|
|
317
|
+
this.readyPromise = undefined;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (this.finishedPromise && newPlayState !== oldPlayState) {
|
|
321
|
+
if (newPlayState === 'idle') {
|
|
322
|
+
this.rejectFinishedPromise();
|
|
323
|
+
this.finishedPromise = undefined;
|
|
324
|
+
} else if (newPlayState === 'finished') {
|
|
325
|
+
this.resolveFinishedPromise();
|
|
326
|
+
} else if (oldPlayState === 'finished') {
|
|
327
|
+
this.finishedPromise = undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
this.oldPlayState = newPlayState;
|
|
331
|
+
return this.readyPromise || this.finishedPromise;
|
|
332
|
+
}
|
|
333
|
+
}, {
|
|
334
|
+
key: "play",
|
|
335
|
+
value: function play() {
|
|
336
|
+
this.updatePromises();
|
|
337
|
+
this._paused = false;
|
|
338
|
+
if (this._isFinished || this._idle) {
|
|
339
|
+
this.rewind();
|
|
340
|
+
this._startTime = null;
|
|
341
|
+
}
|
|
342
|
+
this._finishedFlag = false;
|
|
343
|
+
this._idle = false;
|
|
344
|
+
this.ensureAlive();
|
|
345
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
346
|
+
if (this.timeline.animations.indexOf(this) === -1) {
|
|
347
|
+
this.timeline.animations.push(this);
|
|
348
|
+
}
|
|
349
|
+
this.updatePromises();
|
|
350
|
+
}
|
|
351
|
+
}, {
|
|
352
|
+
key: "pause",
|
|
353
|
+
value: function pause() {
|
|
354
|
+
this.updatePromises();
|
|
355
|
+
if (this.currentTime) {
|
|
356
|
+
this._holdTime = this.currentTime;
|
|
357
|
+
}
|
|
358
|
+
if (!this._isFinished && !this._paused && !this._idle) {
|
|
359
|
+
this.currentTimePending = true;
|
|
360
|
+
} else if (this._idle) {
|
|
361
|
+
this.rewind();
|
|
362
|
+
this._idle = false;
|
|
363
|
+
}
|
|
364
|
+
this._startTime = null;
|
|
365
|
+
this._paused = true;
|
|
366
|
+
this.updatePromises();
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "finish",
|
|
370
|
+
value: function finish() {
|
|
371
|
+
this.updatePromises();
|
|
372
|
+
if (this._idle) return;
|
|
373
|
+
this.currentTime = this._playbackRate > 0 ? this._totalDuration : 0;
|
|
374
|
+
this._startTime = this._totalDuration - this.currentTime;
|
|
375
|
+
this.currentTimePending = false;
|
|
376
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
377
|
+
this.updatePromises();
|
|
378
|
+
}
|
|
379
|
+
}, {
|
|
380
|
+
key: "cancel",
|
|
381
|
+
value: function cancel() {
|
|
382
|
+
var _this3 = this;
|
|
383
|
+
this.updatePromises();
|
|
384
|
+
if (!this._inEffect) return;
|
|
385
|
+
this._inEffect = false;
|
|
386
|
+
this._idle = true;
|
|
387
|
+
this._paused = false;
|
|
388
|
+
this._finishedFlag = true;
|
|
389
|
+
this._currentTime = null;
|
|
390
|
+
this._startTime = null;
|
|
391
|
+
this.effect.update(null);
|
|
392
|
+
// effects are invalid after cancellation as the animation state
|
|
393
|
+
// needs to un-apply.
|
|
394
|
+
this.timeline.applyDirtiedAnimation(this);
|
|
395
|
+
this.updatePromises();
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 1. Reject the current finished promise with a DOMException named "AbortError".
|
|
399
|
+
* 2. Let current finished promise be a new promise
|
|
400
|
+
* @see https://w3c.github.io/csswg-drafts/web-animations-1/#canceling-an-animation-section
|
|
401
|
+
*/
|
|
402
|
+
// if (this.finishedPromise) {
|
|
403
|
+
// this.rejectFinishedPromise();
|
|
404
|
+
// this.finishedPromise = undefined;
|
|
405
|
+
// }
|
|
406
|
+
|
|
407
|
+
if (this.oncancel) {
|
|
408
|
+
var event = new AnimationEvent(null, this, this.currentTime, null);
|
|
409
|
+
setTimeout(function () {
|
|
410
|
+
_this3.oncancel(event);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}, {
|
|
415
|
+
key: "reverse",
|
|
416
|
+
value: function reverse() {
|
|
417
|
+
this.updatePromises();
|
|
418
|
+
var oldCurrentTime = this.currentTime;
|
|
419
|
+
this.playbackRate *= -1;
|
|
420
|
+
this.play();
|
|
421
|
+
if (oldCurrentTime !== null) {
|
|
422
|
+
this.currentTime = oldCurrentTime;
|
|
423
|
+
}
|
|
424
|
+
this.updatePromises();
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Animation/updatePlaybackRate
|
|
429
|
+
*/
|
|
430
|
+
}, {
|
|
431
|
+
key: "updatePlaybackRate",
|
|
432
|
+
value: function updatePlaybackRate(playbackRate) {
|
|
433
|
+
this.playbackRate = playbackRate;
|
|
434
|
+
}
|
|
435
|
+
}, {
|
|
436
|
+
key: "targetAnimations",
|
|
437
|
+
value: function targetAnimations() {
|
|
438
|
+
var _this$effect2;
|
|
439
|
+
var target = (_this$effect2 = this.effect) === null || _this$effect2 === void 0 ? void 0 : _this$effect2.target;
|
|
440
|
+
return target.getAnimations();
|
|
441
|
+
}
|
|
442
|
+
}, {
|
|
443
|
+
key: "markTarget",
|
|
444
|
+
value: function markTarget() {
|
|
445
|
+
var animations = this.targetAnimations();
|
|
446
|
+
if (animations.indexOf(this) === -1) {
|
|
447
|
+
animations.push(this);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}, {
|
|
451
|
+
key: "unmarkTarget",
|
|
452
|
+
value: function unmarkTarget() {
|
|
453
|
+
var animations = this.targetAnimations();
|
|
454
|
+
var index = animations.indexOf(this);
|
|
455
|
+
if (index !== -1) {
|
|
456
|
+
animations.splice(index, 1);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}, {
|
|
460
|
+
key: "tick",
|
|
461
|
+
value: function tick(timelineTime, isAnimationFrame) {
|
|
462
|
+
if (!this._idle && !this._paused) {
|
|
463
|
+
if (this._startTime === null) {
|
|
464
|
+
if (isAnimationFrame) {
|
|
465
|
+
this.startTime = timelineTime - this._currentTime / this.playbackRate;
|
|
466
|
+
}
|
|
467
|
+
} else if (!this._isFinished) {
|
|
468
|
+
this.tickCurrentTime((timelineTime - this._startTime) * this.playbackRate);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (isAnimationFrame) {
|
|
472
|
+
this.currentTimePending = false;
|
|
473
|
+
this.fireEvents(timelineTime);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}, {
|
|
477
|
+
key: "rewind",
|
|
478
|
+
value: function rewind() {
|
|
479
|
+
if (this.playbackRate >= 0) {
|
|
480
|
+
this.currentTime = 0;
|
|
481
|
+
} else if (this._totalDuration < Infinity) {
|
|
482
|
+
this.currentTime = this._totalDuration;
|
|
483
|
+
} else {
|
|
484
|
+
throw new Error('Unable to rewind negative playback rate animation with infinite duration');
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}, {
|
|
488
|
+
key: "persist",
|
|
489
|
+
value: function persist() {
|
|
490
|
+
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
|
|
491
|
+
}
|
|
492
|
+
}, {
|
|
493
|
+
key: "addEventListener",
|
|
494
|
+
value: function addEventListener(type, listener, options) {
|
|
495
|
+
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
|
|
496
|
+
}
|
|
497
|
+
}, {
|
|
498
|
+
key: "removeEventListener",
|
|
499
|
+
value: function removeEventListener(type, listener, options) {
|
|
500
|
+
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
|
|
501
|
+
}
|
|
502
|
+
}, {
|
|
503
|
+
key: "dispatchEvent",
|
|
504
|
+
value: function dispatchEvent(event) {
|
|
505
|
+
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
|
|
506
|
+
}
|
|
507
|
+
}, {
|
|
508
|
+
key: "commitStyles",
|
|
509
|
+
value:
|
|
510
|
+
// replaceState: AnimationReplaceState;
|
|
511
|
+
function commitStyles() {
|
|
512
|
+
throw new Error(ERROR_MSG_METHOD_NOT_IMPLEMENTED);
|
|
513
|
+
}
|
|
514
|
+
}, {
|
|
515
|
+
key: "ensureAlive",
|
|
516
|
+
value: function ensureAlive() {
|
|
517
|
+
// If an animation is playing backwards and is not fill backwards/both
|
|
518
|
+
// then it should go out of effect when it reaches the start of its
|
|
519
|
+
// active interval (currentTime === 0).
|
|
520
|
+
if (this.playbackRate < 0 && this.currentTime === 0) {
|
|
521
|
+
var _this$effect3;
|
|
522
|
+
this._inEffect = !!((_this$effect3 = this.effect) !== null && _this$effect3 !== void 0 && _this$effect3.update(-1));
|
|
523
|
+
} else {
|
|
524
|
+
var _this$effect4;
|
|
525
|
+
this._inEffect = !!((_this$effect4 = this.effect) !== null && _this$effect4 !== void 0 && _this$effect4.update(this.currentTime));
|
|
526
|
+
}
|
|
527
|
+
if (!this._inTimeline && (this._inEffect || !this._finishedFlag)) {
|
|
528
|
+
this._inTimeline = true;
|
|
529
|
+
this.timeline.animations.push(this);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}, {
|
|
533
|
+
key: "tickCurrentTime",
|
|
534
|
+
value: function tickCurrentTime(newTime, ignoreLimit) {
|
|
535
|
+
if (newTime !== this._currentTime) {
|
|
536
|
+
this._currentTime = newTime;
|
|
537
|
+
if (this._isFinished && !ignoreLimit) {
|
|
538
|
+
this._currentTime = this._playbackRate > 0 ? this._totalDuration : 0;
|
|
539
|
+
}
|
|
540
|
+
this.ensureAlive();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}, {
|
|
544
|
+
key: "fireEvents",
|
|
545
|
+
value: function fireEvents(baseTime) {
|
|
546
|
+
var _this4 = this;
|
|
547
|
+
if (this._isFinished) {
|
|
548
|
+
if (!this._finishedFlag) {
|
|
549
|
+
if (this.onfinish) {
|
|
550
|
+
var event = new AnimationEvent(null, this, this.currentTime, baseTime);
|
|
551
|
+
setTimeout(function () {
|
|
552
|
+
if (_this4.onfinish) {
|
|
553
|
+
_this4.onfinish(event);
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
this._finishedFlag = true;
|
|
558
|
+
}
|
|
559
|
+
} else {
|
|
560
|
+
if (this.onframe && this.playState === 'running') {
|
|
561
|
+
var _event = new AnimationEvent(null, this, this.currentTime, baseTime);
|
|
562
|
+
this.onframe(_event);
|
|
563
|
+
}
|
|
564
|
+
this._finishedFlag = false;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}]);
|
|
568
|
+
}();
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* https://github.com/gre/bezier-easing
|
|
572
|
+
* BezierEasing - use bezier curve for transition easing function
|
|
573
|
+
* by Gaëtan Renaudeau 2014 - 2015 – MIT License
|
|
574
|
+
*/
|
|
575
|
+
|
|
576
|
+
// These values are established by empiricism with tests (tradeoff: performance VS precision)
|
|
577
|
+
var NEWTON_ITERATIONS = 4;
|
|
578
|
+
var NEWTON_MIN_SLOPE = 0.001;
|
|
579
|
+
var SUBDIVISION_PRECISION = 0.0000001;
|
|
580
|
+
var SUBDIVISION_MAX_ITERATIONS = 10;
|
|
581
|
+
var kSplineTableSize = 11;
|
|
582
|
+
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
|
583
|
+
var float32ArraySupported = typeof Float32Array === 'function';
|
|
584
|
+
var A = function A(aA1, aA2) {
|
|
585
|
+
return 1.0 - 3.0 * aA2 + 3.0 * aA1;
|
|
586
|
+
};
|
|
587
|
+
var B = function B(aA1, aA2) {
|
|
588
|
+
return 3.0 * aA2 - 6.0 * aA1;
|
|
589
|
+
};
|
|
590
|
+
var C = function C(aA1) {
|
|
591
|
+
return 3.0 * aA1;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
|
|
595
|
+
var calcBezier = function calcBezier(aT, aA1, aA2) {
|
|
596
|
+
return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
|
|
600
|
+
var getSlope = function getSlope(aT, aA1, aA2) {
|
|
601
|
+
return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
|
|
602
|
+
};
|
|
603
|
+
var binarySubdivide = function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
|
604
|
+
var currentX;
|
|
605
|
+
var currentT;
|
|
606
|
+
var i = 0;
|
|
607
|
+
do {
|
|
608
|
+
currentT = aA + (aB - aA) / 2.0;
|
|
609
|
+
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
|
610
|
+
if (currentX > 0.0) aB = currentT;else aA = currentT;
|
|
611
|
+
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
|
|
612
|
+
return currentT;
|
|
613
|
+
};
|
|
614
|
+
var newtonRaphsonIterate = function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
|
615
|
+
for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
|
|
616
|
+
var currentSlope = getSlope(aGuessT, mX1, mX2);
|
|
617
|
+
if (currentSlope === 0.0) return aGuessT;
|
|
618
|
+
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
|
619
|
+
aGuessT -= currentX / currentSlope;
|
|
620
|
+
}
|
|
621
|
+
return aGuessT;
|
|
622
|
+
};
|
|
623
|
+
var bezier = function bezier(mX1, mY1, mX2, mY2) {
|
|
624
|
+
if (!(mX1 >= 0 && mX1 <= 1 && mX2 >= 0 && mX2 <= 1)) throw new Error('bezier x values must be in [0, 1] range');
|
|
625
|
+
if (mX1 === mY1 && mX2 === mY2) return function (t) {
|
|
626
|
+
return t;
|
|
627
|
+
};
|
|
628
|
+
|
|
629
|
+
// Precompute samples table
|
|
630
|
+
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
|
|
631
|
+
for (var i = 0; i < kSplineTableSize; ++i) {
|
|
632
|
+
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
|
633
|
+
}
|
|
634
|
+
var getTForX = function getTForX(aX) {
|
|
635
|
+
var intervalStart = 0.0;
|
|
636
|
+
var currentSample = 1;
|
|
637
|
+
var lastSample = kSplineTableSize - 1;
|
|
638
|
+
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) intervalStart += kSampleStepSize;
|
|
639
|
+
--currentSample;
|
|
640
|
+
|
|
641
|
+
// Interpolate to provide an initial guess for t
|
|
642
|
+
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
|
643
|
+
var guessForT = intervalStart + dist * kSampleStepSize;
|
|
644
|
+
var initialSlope = getSlope(guessForT, mX1, mX2);
|
|
645
|
+
if (initialSlope >= NEWTON_MIN_SLOPE) return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
|
646
|
+
if (initialSlope === 0.0) return guessForT;
|
|
647
|
+
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
|
648
|
+
};
|
|
649
|
+
return function (t) {
|
|
650
|
+
// Because JavaScript number are imprecise, we should guarantee the extremes are right.
|
|
651
|
+
if (t === 0 || t === 1) return t;
|
|
652
|
+
return calcBezier(getTForX(t), mY1, mY2);
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
var convertToDash = function convertToDash(str) {
|
|
657
|
+
str = str.replace(/([A-Z])/g, function (letter) {
|
|
658
|
+
return "-".concat(letter.toLowerCase());
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// Remove first dash
|
|
662
|
+
return str.charAt(0) === '-' ? str.substring(1) : str;
|
|
663
|
+
};
|
|
664
|
+
/**
|
|
665
|
+
Easing Functions from anime.js, they are tried and true, so, its better to use them instead of other alternatives
|
|
666
|
+
*/
|
|
667
|
+
var Quad = function Quad(t) {
|
|
668
|
+
return Math.pow(t, 2);
|
|
669
|
+
};
|
|
670
|
+
var Cubic = function Cubic(t) {
|
|
671
|
+
return Math.pow(t, 3);
|
|
672
|
+
};
|
|
673
|
+
var Quart = function Quart(t) {
|
|
674
|
+
return Math.pow(t, 4);
|
|
675
|
+
};
|
|
676
|
+
var Quint = function Quint(t) {
|
|
677
|
+
return Math.pow(t, 5);
|
|
678
|
+
};
|
|
679
|
+
var Expo = function Expo(t) {
|
|
680
|
+
return Math.pow(t, 6);
|
|
681
|
+
};
|
|
682
|
+
var Sine = function Sine(t) {
|
|
683
|
+
return 1 - Math.cos(t * Math.PI / 2);
|
|
684
|
+
};
|
|
685
|
+
var Circ = function Circ(t) {
|
|
686
|
+
return 1 - Math.sqrt(1 - t * t);
|
|
687
|
+
};
|
|
688
|
+
var Back = function Back(t) {
|
|
689
|
+
return t * t * (3 * t - 2);
|
|
690
|
+
};
|
|
691
|
+
var Bounce = function Bounce(t) {
|
|
692
|
+
var pow2;
|
|
693
|
+
var b = 4;
|
|
694
|
+
while (t < ((pow2 = Math.pow(2, --b)) - 1) / 11) {}
|
|
695
|
+
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - t, 2);
|
|
696
|
+
};
|
|
697
|
+
var Elastic = function Elastic(t) {
|
|
698
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
699
|
+
var _params = _slicedToArray(params, 2),
|
|
700
|
+
_params$ = _params[0],
|
|
701
|
+
amplitude = _params$ === void 0 ? 1 : _params$,
|
|
702
|
+
_params$2 = _params[1],
|
|
703
|
+
period = _params$2 === void 0 ? 0.5 : _params$2;
|
|
704
|
+
var a = clamp(Number(amplitude), 1, 10);
|
|
705
|
+
var p = clamp(Number(period), 0.1, 2);
|
|
706
|
+
if (t === 0 || t === 1) return t;
|
|
707
|
+
return -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
|
|
708
|
+
};
|
|
709
|
+
var Spring = function Spring(t) {
|
|
710
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
711
|
+
var duration = arguments.length > 2 ? arguments[2] : undefined;
|
|
712
|
+
var _params2 = _slicedToArray(params, 4),
|
|
713
|
+
_params2$ = _params2[0],
|
|
714
|
+
mass = _params2$ === void 0 ? 1 : _params2$,
|
|
715
|
+
_params2$2 = _params2[1],
|
|
716
|
+
stiffness = _params2$2 === void 0 ? 100 : _params2$2,
|
|
717
|
+
_params2$3 = _params2[2],
|
|
718
|
+
damping = _params2$3 === void 0 ? 10 : _params2$3,
|
|
719
|
+
_params2$4 = _params2[3],
|
|
720
|
+
velocity = _params2$4 === void 0 ? 0 : _params2$4;
|
|
721
|
+
mass = clamp(mass, 0.1, 1000);
|
|
722
|
+
stiffness = clamp(stiffness, 0.1, 1000);
|
|
723
|
+
damping = clamp(damping, 0.1, 1000);
|
|
724
|
+
velocity = clamp(velocity, 0.1, 1000);
|
|
725
|
+
var w0 = Math.sqrt(stiffness / mass);
|
|
726
|
+
var zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
727
|
+
var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
|
|
728
|
+
var a = 1;
|
|
729
|
+
var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0;
|
|
730
|
+
var progress = duration ? duration * t / 1000 : t;
|
|
731
|
+
if (zeta < 1) {
|
|
732
|
+
progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress));
|
|
733
|
+
} else {
|
|
734
|
+
progress = (a + b * progress) * Math.exp(-progress * w0);
|
|
735
|
+
}
|
|
736
|
+
if (t === 0 || t === 1) return t;
|
|
737
|
+
return 1 - progress;
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Cache the durations at set easing parameters
|
|
742
|
+
*/
|
|
743
|
+
// export const EasingDurationCache: Map<string | TypeEasingFunction, number> = new Map();
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* The threshold for an infinite loop
|
|
747
|
+
*/
|
|
748
|
+
// const INTINITE_LOOP_LIMIT = 10000;
|
|
749
|
+
|
|
750
|
+
/** Convert easing parameters to Array of numbers, e.g. "spring(2, 500)" to [2, 500] */
|
|
751
|
+
// export const parseEasingParameters = (str: string) => {
|
|
752
|
+
// const match = /(\(|\s)([^)]+)\)?/.exec(str);
|
|
753
|
+
// return match
|
|
754
|
+
// ? match[2].split(',').map((value) => {
|
|
755
|
+
// const num = parseFloat(value);
|
|
756
|
+
// return !Number.isNaN(num) ? num : value.trim();
|
|
757
|
+
// })
|
|
758
|
+
// : [];
|
|
759
|
+
// };
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* The spring easing function will only look smooth at certain durations, with certain parameters.
|
|
763
|
+
* This functions returns the optimal duration to create a smooth springy animation based on physics
|
|
764
|
+
*
|
|
765
|
+
* Note: it can also be used to determine the optimal duration of other types of easing function, but be careful of 'in-'
|
|
766
|
+
* easing functions, because of the nature of the function it can sometimes create an infinite loop, I suggest only using
|
|
767
|
+
* `getEasingDuration` for `spring`, specifically 'out-spring' and 'spring'
|
|
768
|
+
*/
|
|
769
|
+
// export const getEasingDuration = (easing: string | TypeEasingFunction = 'spring') => {
|
|
770
|
+
// if (EasingDurationCache.has(easing)) return EasingDurationCache.get(easing);
|
|
771
|
+
|
|
772
|
+
// // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
773
|
+
// const easingFunction = typeof easing == 'function' ? easing : getEasingFunction(easing as string);
|
|
774
|
+
// const params = typeof easing == 'function' ? [] : parseEasingParameters(easing);
|
|
775
|
+
// const frame = 1 / 6;
|
|
776
|
+
|
|
777
|
+
// let elapsed = 0;
|
|
778
|
+
// let rest = 0;
|
|
779
|
+
// let count = 0;
|
|
780
|
+
|
|
781
|
+
// while (++count < INTINITE_LOOP_LIMIT) {
|
|
782
|
+
// elapsed += frame;
|
|
783
|
+
// if (easingFunction(elapsed, params, undefined) === 1) {
|
|
784
|
+
// rest++;
|
|
785
|
+
// if (rest >= 16) break;
|
|
786
|
+
// } else {
|
|
787
|
+
// rest = 0;
|
|
788
|
+
// }
|
|
789
|
+
// }
|
|
790
|
+
|
|
791
|
+
// const duration = elapsed * frame * 1000;
|
|
792
|
+
// EasingDurationCache.set(easing, duration);
|
|
793
|
+
// return duration;
|
|
794
|
+
// };
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
These Easing Functions are based off of the Sozi Project's easing functions
|
|
798
|
+
https://github.com/sozi-projects/Sozi/blob/d72e44ebd580dc7579d1e177406ad41e632f961d/src/js/player/Timing.js
|
|
799
|
+
*/
|
|
800
|
+
var Steps = function Steps(t) {
|
|
801
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
802
|
+
var _ref = params,
|
|
803
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
804
|
+
_ref2$ = _ref2[0],
|
|
805
|
+
steps = _ref2$ === void 0 ? 10 : _ref2$,
|
|
806
|
+
type = _ref2[1];
|
|
807
|
+
var trunc = type === 'start' ? Math.ceil : Math.floor;
|
|
808
|
+
return trunc(clamp(t, 0, 1) * steps) / steps;
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
// @ts-ignore
|
|
812
|
+
var Bezier = function Bezier(t) {
|
|
813
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
814
|
+
var _params3 = _slicedToArray(params, 4),
|
|
815
|
+
mX1 = _params3[0],
|
|
816
|
+
mY1 = _params3[1],
|
|
817
|
+
mX2 = _params3[2],
|
|
818
|
+
mY2 = _params3[3];
|
|
819
|
+
return bezier(mX1, mY1, mX2, mY2)(t);
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
/** The default `ease-in` easing function */
|
|
823
|
+
var easein = bezier(0.42, 0.0, 1.0, 1.0);
|
|
824
|
+
|
|
825
|
+
/** Converts easing functions to their `out`counter parts */
|
|
826
|
+
var EaseOut = function EaseOut(ease) {
|
|
827
|
+
return function (t) {
|
|
828
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
829
|
+
var duration = arguments.length > 2 ? arguments[2] : undefined;
|
|
830
|
+
return 1 - ease(1 - t, params, duration);
|
|
831
|
+
};
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
/** Converts easing functions to their `in-out` counter parts */
|
|
835
|
+
var EaseInOut = function EaseInOut(ease) {
|
|
836
|
+
return function (t) {
|
|
837
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
838
|
+
var duration = arguments.length > 2 ? arguments[2] : undefined;
|
|
839
|
+
return t < 0.5 ? ease(t * 2, params, duration) / 2 : 1 - ease(t * -2 + 2, params, duration) / 2;
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
/** Converts easing functions to their `out-in` counter parts */
|
|
844
|
+
var EaseOutIn = function EaseOutIn(ease) {
|
|
845
|
+
return function (t) {
|
|
846
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
847
|
+
var duration = arguments.length > 2 ? arguments[2] : undefined;
|
|
848
|
+
return t < 0.5 ? (1 - ease(1 - t * 2, params, duration)) / 2 : (ease(t * 2 - 1, params, duration) + 1) / 2;
|
|
849
|
+
};
|
|
850
|
+
};
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* The default list of easing functions, do note this is different from {@link EASING}
|
|
854
|
+
*/
|
|
855
|
+
|
|
856
|
+
var EasingFunctions = {
|
|
857
|
+
steps: Steps,
|
|
858
|
+
'step-start': function stepStart(t) {
|
|
859
|
+
return Steps(t, [1, 'start']);
|
|
860
|
+
},
|
|
861
|
+
'step-end': function stepEnd(t) {
|
|
862
|
+
return Steps(t, [1, 'end']);
|
|
863
|
+
},
|
|
864
|
+
linear: function linear(t) {
|
|
865
|
+
return t;
|
|
866
|
+
},
|
|
867
|
+
'cubic-bezier': Bezier,
|
|
868
|
+
ease: function ease(t) {
|
|
869
|
+
return Bezier(t, [0.25, 0.1, 0.25, 1.0]);
|
|
870
|
+
},
|
|
871
|
+
"in": easein,
|
|
872
|
+
out: EaseOut(easein),
|
|
873
|
+
'in-out': EaseInOut(easein),
|
|
874
|
+
'out-in': EaseOutIn(easein),
|
|
875
|
+
'in-quad': Quad,
|
|
876
|
+
'out-quad': EaseOut(Quad),
|
|
877
|
+
'in-out-quad': EaseInOut(Quad),
|
|
878
|
+
'out-in-quad': EaseOutIn(Quad),
|
|
879
|
+
'in-cubic': Cubic,
|
|
880
|
+
'out-cubic': EaseOut(Cubic),
|
|
881
|
+
'in-out-cubic': EaseInOut(Cubic),
|
|
882
|
+
'out-in-cubic': EaseOutIn(Cubic),
|
|
883
|
+
'in-quart': Quart,
|
|
884
|
+
'out-quart': EaseOut(Quart),
|
|
885
|
+
'in-out-quart': EaseInOut(Quart),
|
|
886
|
+
'out-in-quart': EaseOutIn(Quart),
|
|
887
|
+
'in-quint': Quint,
|
|
888
|
+
'out-quint': EaseOut(Quint),
|
|
889
|
+
'in-out-quint': EaseInOut(Quint),
|
|
890
|
+
'out-in-quint': EaseOutIn(Quint),
|
|
891
|
+
'in-expo': Expo,
|
|
892
|
+
'out-expo': EaseOut(Expo),
|
|
893
|
+
'in-out-expo': EaseInOut(Expo),
|
|
894
|
+
'out-in-expo': EaseOutIn(Expo),
|
|
895
|
+
'in-sine': Sine,
|
|
896
|
+
'out-sine': EaseOut(Sine),
|
|
897
|
+
'in-out-sine': EaseInOut(Sine),
|
|
898
|
+
'out-in-sine': EaseOutIn(Sine),
|
|
899
|
+
'in-circ': Circ,
|
|
900
|
+
'out-circ': EaseOut(Circ),
|
|
901
|
+
'in-out-circ': EaseInOut(Circ),
|
|
902
|
+
'out-in-circ': EaseOutIn(Circ),
|
|
903
|
+
'in-back': Back,
|
|
904
|
+
'out-back': EaseOut(Back),
|
|
905
|
+
'in-out-back': EaseInOut(Back),
|
|
906
|
+
'out-in-back': EaseOutIn(Back),
|
|
907
|
+
'in-bounce': Bounce,
|
|
908
|
+
'out-bounce': EaseOut(Bounce),
|
|
909
|
+
'in-out-bounce': EaseInOut(Bounce),
|
|
910
|
+
'out-in-bounce': EaseOutIn(Bounce),
|
|
911
|
+
'in-elastic': Elastic,
|
|
912
|
+
'out-elastic': EaseOut(Elastic),
|
|
913
|
+
'in-out-elastic': EaseInOut(Elastic),
|
|
914
|
+
'out-in-elastic': EaseOutIn(Elastic),
|
|
915
|
+
spring: Spring,
|
|
916
|
+
'spring-in': Spring,
|
|
917
|
+
'spring-out': EaseOut(Spring),
|
|
918
|
+
'spring-in-out': EaseInOut(Spring),
|
|
919
|
+
'spring-out-in': EaseOutIn(Spring)
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
/**
|
|
923
|
+
* Convert string easing to their proper form
|
|
924
|
+
*/
|
|
925
|
+
var complexEasingSyntax = function complexEasingSyntax(ease) {
|
|
926
|
+
return convertToDash(ease).replace(/^ease-/, '') // Remove the "ease-" keyword
|
|
927
|
+
.replace(/(\(|\s).+/, '') // Remove the function brackets and parameters
|
|
928
|
+
.toLowerCase().trim();
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
/** Re-maps a number from one range to another. Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful. */
|
|
932
|
+
var getEasingFunction = function getEasingFunction(ease) {
|
|
933
|
+
return EasingFunctions[complexEasingSyntax(ease)] || EasingFunctions.linear;
|
|
934
|
+
};
|
|
935
|
+
|
|
936
|
+
// /**
|
|
937
|
+
// * Allows you to register new easing functions
|
|
938
|
+
// */
|
|
939
|
+
// export const registerEasingFunction = (key: string, fn: TypeEasingFunction) => {
|
|
940
|
+
// Object.assign(EasingFunctions, {
|
|
941
|
+
// [key]: fn,
|
|
942
|
+
// });
|
|
943
|
+
// };
|
|
944
|
+
|
|
945
|
+
// /**
|
|
946
|
+
// * Allows you to register multiple new easing functions
|
|
947
|
+
// */
|
|
948
|
+
// export const registerEasingFunctions = (...obj: typeof EasingFunctions[]) => {
|
|
949
|
+
// Object.assign(EasingFunctions, ...obj);
|
|
950
|
+
// };
|
|
951
|
+
|
|
952
|
+
var linear = function linear(x) {
|
|
953
|
+
return x;
|
|
954
|
+
};
|
|
955
|
+
var Start = 1;
|
|
956
|
+
var Middle = 0.5;
|
|
957
|
+
var End = 0;
|
|
958
|
+
function step(count, pos) {
|
|
959
|
+
return function (x) {
|
|
960
|
+
if (x >= 1) {
|
|
961
|
+
return 1;
|
|
962
|
+
}
|
|
963
|
+
var stepSize = 1 / count;
|
|
964
|
+
x += pos * stepSize;
|
|
965
|
+
return x - x % stepSize;
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
var numberString = '\\s*(-?\\d+\\.?\\d*|-?\\.\\d+)\\s*';
|
|
969
|
+
var cubicBezierRe = new RegExp("cubic-bezier\\(".concat(numberString, ",").concat(numberString, ",").concat(numberString, ",").concat(numberString, "\\)"));
|
|
970
|
+
var step1Re = /steps\(\s*(\d+)\s*\)/;
|
|
971
|
+
var step2Re = /steps\(\s*(\d+)\s*,\s*(start|middle|end)\s*\)/;
|
|
972
|
+
function parseEasingFunction(normalizedEasing) {
|
|
973
|
+
var cubicData = cubicBezierRe.exec(normalizedEasing);
|
|
974
|
+
if (cubicData) {
|
|
975
|
+
// @ts-ignore
|
|
976
|
+
return bezier.apply(void 0, _toConsumableArray(cubicData.slice(1).map(Number)));
|
|
977
|
+
}
|
|
978
|
+
var step1Data = step1Re.exec(normalizedEasing);
|
|
979
|
+
if (step1Data) {
|
|
980
|
+
return step(Number(step1Data[1]), End);
|
|
981
|
+
}
|
|
982
|
+
var step2Data = step2Re.exec(normalizedEasing);
|
|
983
|
+
if (step2Data) {
|
|
984
|
+
// @ts-ignore
|
|
985
|
+
return step(Number(step2Data[1]), {
|
|
986
|
+
start: Start,
|
|
987
|
+
middle: Middle,
|
|
988
|
+
end: End
|
|
989
|
+
}[step2Data[2]]);
|
|
990
|
+
}
|
|
991
|
+
return getEasingFunction(normalizedEasing);
|
|
992
|
+
}
|
|
993
|
+
function calculateActiveDuration(timing) {
|
|
994
|
+
// @ts-ignore
|
|
995
|
+
return Math.abs(repeatedDuration(timing) / (timing.playbackRate || 1));
|
|
996
|
+
}
|
|
997
|
+
function repeatedDuration(timing) {
|
|
998
|
+
var _timing$iterations;
|
|
999
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-active-duration
|
|
1000
|
+
if (timing.duration === 0 || timing.iterations === 0) {
|
|
1001
|
+
return 0;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration#value
|
|
1005
|
+
// if (timing.duration === 'auto') {
|
|
1006
|
+
// timing.duration = 0;
|
|
1007
|
+
// }
|
|
1008
|
+
|
|
1009
|
+
return (timing.duration === 'auto' ? 0 : Number(timing.duration)) * ((_timing$iterations = timing.iterations) !== null && _timing$iterations !== void 0 ? _timing$iterations : 1);
|
|
1010
|
+
}
|
|
1011
|
+
var PhaseNone = 0;
|
|
1012
|
+
var PhaseBefore = 1;
|
|
1013
|
+
var PhaseAfter = 2;
|
|
1014
|
+
var PhaseActive = 3;
|
|
1015
|
+
function calculatePhase(activeDuration, localTime, timing) {
|
|
1016
|
+
// https://drafts.csswg.org/web-animations/#animation-effect-phases-and-states
|
|
1017
|
+
if (localTime === null) {
|
|
1018
|
+
return PhaseNone;
|
|
1019
|
+
}
|
|
1020
|
+
var endTime = timing.endTime;
|
|
1021
|
+
if (localTime < Math.min(timing.delay, endTime)) {
|
|
1022
|
+
return PhaseBefore;
|
|
1023
|
+
}
|
|
1024
|
+
if (localTime >= Math.min(timing.delay + activeDuration + timing.endDelay, endTime)) {
|
|
1025
|
+
return PhaseAfter;
|
|
1026
|
+
}
|
|
1027
|
+
return PhaseActive;
|
|
1028
|
+
}
|
|
1029
|
+
function calculateActiveTime(activeDuration, fillMode, localTime, phase, delay) {
|
|
1030
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-active-time
|
|
1031
|
+
switch (phase) {
|
|
1032
|
+
case PhaseBefore:
|
|
1033
|
+
if (fillMode === 'backwards' || fillMode === 'both') return 0;
|
|
1034
|
+
return null;
|
|
1035
|
+
case PhaseActive:
|
|
1036
|
+
return localTime - delay;
|
|
1037
|
+
case PhaseAfter:
|
|
1038
|
+
if (fillMode === 'forwards' || fillMode === 'both') return activeDuration;
|
|
1039
|
+
return null;
|
|
1040
|
+
case PhaseNone:
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
function calculateOverallProgress(iterationDuration, phase, iterations, activeTime, iterationStart) {
|
|
1045
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-overall-progress
|
|
1046
|
+
var overallProgress = iterationStart;
|
|
1047
|
+
if (iterationDuration === 0) {
|
|
1048
|
+
if (phase !== PhaseBefore) {
|
|
1049
|
+
overallProgress += iterations;
|
|
1050
|
+
}
|
|
1051
|
+
} else {
|
|
1052
|
+
overallProgress += activeTime / iterationDuration;
|
|
1053
|
+
}
|
|
1054
|
+
return overallProgress;
|
|
1055
|
+
}
|
|
1056
|
+
function calculateSimpleIterationProgress(overallProgress, iterationStart, phase, iterations, activeTime, iterationDuration) {
|
|
1057
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-simple-iteration-progress
|
|
1058
|
+
|
|
1059
|
+
var simpleIterationProgress = overallProgress === Infinity ? iterationStart % 1 : overallProgress % 1;
|
|
1060
|
+
if (simpleIterationProgress === 0 && phase === PhaseAfter && iterations !== 0 && (activeTime !== 0 || iterationDuration === 0)) {
|
|
1061
|
+
simpleIterationProgress = 1;
|
|
1062
|
+
}
|
|
1063
|
+
return simpleIterationProgress;
|
|
1064
|
+
}
|
|
1065
|
+
function calculateCurrentIteration(phase, iterations, simpleIterationProgress, overallProgress) {
|
|
1066
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-current-iteration
|
|
1067
|
+
if (phase === PhaseAfter && iterations === Infinity) {
|
|
1068
|
+
return Infinity;
|
|
1069
|
+
}
|
|
1070
|
+
if (simpleIterationProgress === 1) {
|
|
1071
|
+
return Math.floor(overallProgress) - 1;
|
|
1072
|
+
}
|
|
1073
|
+
return Math.floor(overallProgress);
|
|
1074
|
+
}
|
|
1075
|
+
function calculateDirectedProgress(playbackDirection, currentIteration, simpleIterationProgress) {
|
|
1076
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-directed-progress
|
|
1077
|
+
var currentDirection = playbackDirection;
|
|
1078
|
+
if (playbackDirection !== 'normal' && playbackDirection !== 'reverse') {
|
|
1079
|
+
var d = currentIteration;
|
|
1080
|
+
if (playbackDirection === 'alternate-reverse') {
|
|
1081
|
+
d += 1;
|
|
1082
|
+
}
|
|
1083
|
+
currentDirection = 'normal';
|
|
1084
|
+
if (d !== Infinity && d % 2 !== 0) {
|
|
1085
|
+
currentDirection = 'reverse';
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
if (currentDirection === 'normal') {
|
|
1089
|
+
return simpleIterationProgress;
|
|
1090
|
+
}
|
|
1091
|
+
return 1 - simpleIterationProgress;
|
|
1092
|
+
}
|
|
1093
|
+
function calculateIterationProgress(activeDuration, localTime, timing) {
|
|
1094
|
+
var phase = calculatePhase(activeDuration, localTime, timing);
|
|
1095
|
+
var activeTime = calculateActiveTime(activeDuration, timing.fill, localTime, phase, timing.delay);
|
|
1096
|
+
if (activeTime === null) return null;
|
|
1097
|
+
var duration = timing.duration === 'auto' ? 0 : timing.duration;
|
|
1098
|
+
var overallProgress = calculateOverallProgress(duration, phase, timing.iterations, activeTime, timing.iterationStart);
|
|
1099
|
+
var simpleIterationProgress = calculateSimpleIterationProgress(overallProgress, timing.iterationStart, phase, timing.iterations, activeTime, duration);
|
|
1100
|
+
var currentIteration = calculateCurrentIteration(phase, timing.iterations, simpleIterationProgress, overallProgress);
|
|
1101
|
+
var directedProgress = calculateDirectedProgress(timing.direction, currentIteration, simpleIterationProgress);
|
|
1102
|
+
timing.currentIteration = currentIteration;
|
|
1103
|
+
timing.progress = directedProgress;
|
|
1104
|
+
|
|
1105
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-transformed-progress
|
|
1106
|
+
// https://drafts.csswg.org/web-animations/#calculating-the-iteration-progress
|
|
1107
|
+
return timing.easingFunction(directedProgress);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
function convertEffectInput(keyframes, timing, target) {
|
|
1111
|
+
var propertySpecificKeyframeGroups = makePropertySpecificKeyframeGroups(keyframes, timing);
|
|
1112
|
+
var interpolations = makeInterpolations(propertySpecificKeyframeGroups, target);
|
|
1113
|
+
return function (target, fraction) {
|
|
1114
|
+
if (fraction !== null) {
|
|
1115
|
+
interpolations.filter(function (interpolation) {
|
|
1116
|
+
return fraction >= interpolation.applyFrom && fraction < interpolation.applyTo;
|
|
1117
|
+
}).forEach(function (interpolation) {
|
|
1118
|
+
var offsetFraction = fraction - interpolation.startOffset;
|
|
1119
|
+
var localDuration = interpolation.endOffset - interpolation.startOffset;
|
|
1120
|
+
var scaledLocalTime = localDuration === 0 ? 0 : offsetFraction / localDuration;
|
|
1121
|
+
// apply updated attribute
|
|
1122
|
+
target.setAttribute(interpolation.property, interpolation.interpolation(scaledLocalTime), false, false // disable memoize
|
|
1123
|
+
);
|
|
1124
|
+
|
|
1125
|
+
// if (interpolation.property === 'visibility') {
|
|
1126
|
+
// console.log(
|
|
1127
|
+
// scaledLocalTime,
|
|
1128
|
+
// interpolation.interpolation(scaledLocalTime),
|
|
1129
|
+
// );
|
|
1130
|
+
// }
|
|
1131
|
+
});
|
|
1132
|
+
} else {
|
|
1133
|
+
for (var property in propertySpecificKeyframeGroups) if (isNotReservedWord(property)) {
|
|
1134
|
+
// clear attribute
|
|
1135
|
+
target.setAttribute(property, null);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function isNotReservedWord(member) {
|
|
1141
|
+
return member !== 'offset' && member !== 'easing' && member !== 'composite' && member !== 'computedOffset';
|
|
1142
|
+
}
|
|
1143
|
+
function makePropertySpecificKeyframeGroups(keyframes, timing) {
|
|
1144
|
+
var propertySpecificKeyframeGroups = {};
|
|
1145
|
+
for (var i = 0; i < keyframes.length; i++) {
|
|
1146
|
+
for (var member in keyframes[i]) {
|
|
1147
|
+
if (isNotReservedWord(member)) {
|
|
1148
|
+
var propertySpecificKeyframe = {
|
|
1149
|
+
offset: keyframes[i].offset,
|
|
1150
|
+
computedOffset: keyframes[i].computedOffset,
|
|
1151
|
+
easing: keyframes[i].easing,
|
|
1152
|
+
easingFunction: parseEasingFunction(keyframes[i].easing) || timing.easingFunction,
|
|
1153
|
+
value: keyframes[i][member]
|
|
1154
|
+
};
|
|
1155
|
+
propertySpecificKeyframeGroups[member] = propertySpecificKeyframeGroups[member] || [];
|
|
1156
|
+
propertySpecificKeyframeGroups[member].push(propertySpecificKeyframe);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
return propertySpecificKeyframeGroups;
|
|
1161
|
+
}
|
|
1162
|
+
function makeInterpolations(propertySpecificKeyframeGroups, target) {
|
|
1163
|
+
var interpolations = [];
|
|
1164
|
+
for (var groupName in propertySpecificKeyframeGroups) {
|
|
1165
|
+
var keyframes = propertySpecificKeyframeGroups[groupName];
|
|
1166
|
+
for (var i = 0; i < keyframes.length - 1; i++) {
|
|
1167
|
+
var startIndex = i;
|
|
1168
|
+
var endIndex = i + 1;
|
|
1169
|
+
var startOffset = keyframes[startIndex].computedOffset;
|
|
1170
|
+
var endOffset = keyframes[endIndex].computedOffset;
|
|
1171
|
+
var applyFrom = startOffset;
|
|
1172
|
+
var applyTo = endOffset;
|
|
1173
|
+
if (i === 0) {
|
|
1174
|
+
applyFrom = -Infinity;
|
|
1175
|
+
if (endOffset === 0) {
|
|
1176
|
+
endIndex = startIndex;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if (i === keyframes.length - 2) {
|
|
1180
|
+
applyTo = Infinity;
|
|
1181
|
+
if (startOffset === 1) {
|
|
1182
|
+
startIndex = endIndex;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
interpolations.push({
|
|
1186
|
+
applyFrom: applyFrom,
|
|
1187
|
+
applyTo: applyTo,
|
|
1188
|
+
startOffset: keyframes[startIndex].computedOffset,
|
|
1189
|
+
endOffset: keyframes[endIndex].computedOffset,
|
|
1190
|
+
easingFunction: keyframes[startIndex].easingFunction,
|
|
1191
|
+
property: groupName,
|
|
1192
|
+
interpolation: propertyInterpolation(groupName, keyframes[startIndex].value, keyframes[endIndex].value, target)
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
interpolations.sort(function (leftInterpolation, rightInterpolation) {
|
|
1197
|
+
return leftInterpolation.startOffset - rightInterpolation.startOffset;
|
|
1198
|
+
});
|
|
1199
|
+
return interpolations;
|
|
1200
|
+
}
|
|
1201
|
+
var InterpolationFactory = function InterpolationFactory(from, to, convertToString) {
|
|
1202
|
+
return function (f) {
|
|
1203
|
+
var interpolated = interpolate(from, to, f);
|
|
1204
|
+
return isNumber(interpolated) ? interpolated : convertToString(interpolated);
|
|
1205
|
+
};
|
|
1206
|
+
};
|
|
1207
|
+
function propertyInterpolation(property, left, right, target) {
|
|
1208
|
+
var metadata = propertyMetadataCache[property];
|
|
1209
|
+
if (metadata && metadata.syntax && metadata["int"]) {
|
|
1210
|
+
var propertyHandler = runtime.styleValueRegistry.getPropertySyntax(metadata.syntax);
|
|
1211
|
+
if (propertyHandler) {
|
|
1212
|
+
var parser = propertyHandler.parser;
|
|
1213
|
+
var usedLeft = parser ? parser(left, target) : left;
|
|
1214
|
+
var usedRight = parser ? parser(right, target) : right;
|
|
1215
|
+
|
|
1216
|
+
// merger [left, right, n2string()]
|
|
1217
|
+
var interpolationArgs = propertyHandler.mixer(usedLeft, usedRight, target);
|
|
1218
|
+
if (interpolationArgs) {
|
|
1219
|
+
var interp = InterpolationFactory.apply(void 0, _toConsumableArray(interpolationArgs));
|
|
1220
|
+
return function (t) {
|
|
1221
|
+
if (t === 0) return left;
|
|
1222
|
+
if (t === 1) return right;
|
|
1223
|
+
return interp(t);
|
|
1224
|
+
};
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
1230
|
+
return InterpolationFactory(false, true, function (bool) {
|
|
1231
|
+
return bool ? right : left;
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* interpolate with number, boolean, number[], boolean[]
|
|
1237
|
+
*/
|
|
1238
|
+
function interpolate(from, to, f) {
|
|
1239
|
+
if (typeof from === 'number' && typeof to === 'number') {
|
|
1240
|
+
return from * (1 - f) + to * f;
|
|
1241
|
+
}
|
|
1242
|
+
if (typeof from === 'boolean' && typeof to === 'boolean' || typeof from === 'string' && typeof to === 'string' // skip string, eg. path ['M', 10, 10]
|
|
1243
|
+
) {
|
|
1244
|
+
return f < 0.5 ? from : to;
|
|
1245
|
+
}
|
|
1246
|
+
if (Array.isArray(from) && Array.isArray(to)) {
|
|
1247
|
+
// interpolate arrays/matrix
|
|
1248
|
+
var fromLength = from.length;
|
|
1249
|
+
var toLength = to.length;
|
|
1250
|
+
var length = Math.max(fromLength, toLength);
|
|
1251
|
+
var r = [];
|
|
1252
|
+
for (var i = 0; i < length; i++) {
|
|
1253
|
+
r.push(interpolate(from[i < fromLength ? i : fromLength - 1], to[i < toLength ? i : toLength - 1], f));
|
|
1254
|
+
}
|
|
1255
|
+
return r;
|
|
1256
|
+
}
|
|
1257
|
+
throw new Error("Mismatched interpolation arguments ".concat(from, ":").concat(to));
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming
|
|
1262
|
+
*/
|
|
1263
|
+
var AnimationEffectTiming = /*#__PURE__*/function () {
|
|
1264
|
+
function AnimationEffectTiming() {
|
|
1265
|
+
_classCallCheck(this, AnimationEffectTiming);
|
|
1266
|
+
/**
|
|
1267
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/delay
|
|
1268
|
+
*/
|
|
1269
|
+
this.delay = 0;
|
|
1270
|
+
/**
|
|
1271
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/direction
|
|
1272
|
+
*/
|
|
1273
|
+
this.direction = 'normal';
|
|
1274
|
+
/**
|
|
1275
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/duration
|
|
1276
|
+
*/
|
|
1277
|
+
this.duration = 'auto';
|
|
1278
|
+
/**
|
|
1279
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/easing
|
|
1280
|
+
*/
|
|
1281
|
+
this._easing = 'linear';
|
|
1282
|
+
this.easingFunction = linear;
|
|
1283
|
+
/**
|
|
1284
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/endDelay
|
|
1285
|
+
*/
|
|
1286
|
+
this.endDelay = 0;
|
|
1287
|
+
/**
|
|
1288
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/fill
|
|
1289
|
+
*/
|
|
1290
|
+
this.fill = 'auto';
|
|
1291
|
+
/**
|
|
1292
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/iterationStart
|
|
1293
|
+
*/
|
|
1294
|
+
this.iterationStart = 0;
|
|
1295
|
+
/**
|
|
1296
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EffectTiming/iterations
|
|
1297
|
+
*/
|
|
1298
|
+
this.iterations = 1;
|
|
1299
|
+
this.currentIteration = null;
|
|
1300
|
+
this.progress = null;
|
|
1301
|
+
}
|
|
1302
|
+
return _createClass(AnimationEffectTiming, [{
|
|
1303
|
+
key: "easing",
|
|
1304
|
+
get: function get() {
|
|
1305
|
+
return this._easing;
|
|
1306
|
+
},
|
|
1307
|
+
set: function set(value) {
|
|
1308
|
+
this.easingFunction = parseEasingFunction(value);
|
|
1309
|
+
this._easing = value;
|
|
1310
|
+
}
|
|
1311
|
+
}]);
|
|
1312
|
+
}();
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* @example
|
|
1316
|
+
{
|
|
1317
|
+
translateY: [200, 300],
|
|
1318
|
+
scale: [1, 10],
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
* groups' length can be different, the following config should generate 3 frames:
|
|
1322
|
+
@example
|
|
1323
|
+
{
|
|
1324
|
+
translateY: [200, 300, 400],
|
|
1325
|
+
scale: [1, 10],
|
|
1326
|
+
}
|
|
1327
|
+
*/
|
|
1328
|
+
function convertToArrayForm(effectInput) {
|
|
1329
|
+
var normalizedEffectInput = [];
|
|
1330
|
+
for (var property in effectInput) {
|
|
1331
|
+
// skip reserved props
|
|
1332
|
+
if (property in ['easing', 'offset', 'composite']) {
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// @ts-ignore
|
|
1337
|
+
var values = effectInput[property];
|
|
1338
|
+
if (!Array.isArray(values)) {
|
|
1339
|
+
values = [values];
|
|
1340
|
+
}
|
|
1341
|
+
var numKeyframes = values.length;
|
|
1342
|
+
for (var i = 0; i < numKeyframes; i++) {
|
|
1343
|
+
if (!normalizedEffectInput[i]) {
|
|
1344
|
+
var keyframe = {};
|
|
1345
|
+
if ('offset' in effectInput) {
|
|
1346
|
+
keyframe.offset = Number(effectInput.offset);
|
|
1347
|
+
}
|
|
1348
|
+
if ('easing' in effectInput) {
|
|
1349
|
+
// @ts-ignore
|
|
1350
|
+
keyframe.easing = effectInput.easing;
|
|
1351
|
+
}
|
|
1352
|
+
if ('composite' in effectInput) {
|
|
1353
|
+
// @ts-ignore
|
|
1354
|
+
keyframe.composite = effectInput.composite;
|
|
1355
|
+
}
|
|
1356
|
+
normalizedEffectInput[i] = keyframe;
|
|
1357
|
+
}
|
|
1358
|
+
if (values[i] !== undefined && values[i] !== null) {
|
|
1359
|
+
normalizedEffectInput[i][property] = values[i];
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
normalizedEffectInput.sort(function (a, b) {
|
|
1364
|
+
return (a.computedOffset || 0) - (b.computedOffset || 0);
|
|
1365
|
+
});
|
|
1366
|
+
return normalizedEffectInput;
|
|
1367
|
+
}
|
|
1368
|
+
function normalizeKeyframes(effectInput, timing) {
|
|
1369
|
+
if (effectInput === null) {
|
|
1370
|
+
return [];
|
|
1371
|
+
}
|
|
1372
|
+
if (!Array.isArray(effectInput)) {
|
|
1373
|
+
effectInput = convertToArrayForm(effectInput);
|
|
1374
|
+
}
|
|
1375
|
+
var keyframes = effectInput.map(function (originalKeyframe) {
|
|
1376
|
+
var keyframe = {};
|
|
1377
|
+
if (timing !== null && timing !== void 0 && timing.composite) {
|
|
1378
|
+
// This will be auto if the composite operation specified on the effect is being used.
|
|
1379
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats
|
|
1380
|
+
keyframe.composite = 'auto';
|
|
1381
|
+
}
|
|
1382
|
+
for (var member in originalKeyframe) {
|
|
1383
|
+
var memberValue = originalKeyframe[member];
|
|
1384
|
+
if (member === 'offset') {
|
|
1385
|
+
if (memberValue !== null) {
|
|
1386
|
+
memberValue = Number(memberValue);
|
|
1387
|
+
if (!isFinite(memberValue)) throw new Error('Keyframe offsets must be numbers.');
|
|
1388
|
+
if (memberValue < 0 || memberValue > 1) throw new Error('Keyframe offsets must be between 0 and 1.');
|
|
1389
|
+
keyframe.computedOffset = memberValue;
|
|
1390
|
+
}
|
|
1391
|
+
} else if (member === 'composite') {
|
|
1392
|
+
// TODO: Support add & accumulate in KeyframeEffect.composite
|
|
1393
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect/composite
|
|
1394
|
+
if (['replace', 'add', 'accumulate', 'auto'].indexOf(memberValue) === -1) {
|
|
1395
|
+
throw new Error("".concat(memberValue, " compositing is not supported"));
|
|
1396
|
+
}
|
|
1397
|
+
} else ;
|
|
1398
|
+
|
|
1399
|
+
// assign to keyframe, no need to parse shorthand value
|
|
1400
|
+
keyframe[member] = memberValue;
|
|
1401
|
+
}
|
|
1402
|
+
if (keyframe.offset === undefined) {
|
|
1403
|
+
keyframe.offset = null;
|
|
1404
|
+
}
|
|
1405
|
+
if (keyframe.easing === undefined) {
|
|
1406
|
+
// override with timing.easing
|
|
1407
|
+
keyframe.easing = (timing === null || timing === void 0 ? void 0 : timing.easing) || 'linear';
|
|
1408
|
+
}
|
|
1409
|
+
if (keyframe.composite === undefined) {
|
|
1410
|
+
keyframe.composite = 'auto';
|
|
1411
|
+
}
|
|
1412
|
+
return keyframe;
|
|
1413
|
+
});
|
|
1414
|
+
var everyFrameHasOffset = true;
|
|
1415
|
+
var previousOffset = -Infinity;
|
|
1416
|
+
for (var i = 0; i < keyframes.length; i++) {
|
|
1417
|
+
var offset = keyframes[i].offset;
|
|
1418
|
+
if (!isNil(offset)) {
|
|
1419
|
+
if (offset < previousOffset) {
|
|
1420
|
+
throw new TypeError('Keyframes are not loosely sorted by offset. Sort or specify offsets.');
|
|
1421
|
+
}
|
|
1422
|
+
previousOffset = offset;
|
|
1423
|
+
} else {
|
|
1424
|
+
everyFrameHasOffset = false;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
keyframes = keyframes.filter(function (keyframe) {
|
|
1428
|
+
return Number(keyframe.offset) >= 0 && Number(keyframe.offset) <= 1;
|
|
1429
|
+
});
|
|
1430
|
+
function spaceKeyframes() {
|
|
1431
|
+
var _keyframes$offset;
|
|
1432
|
+
var _keyframes = keyframes,
|
|
1433
|
+
length = _keyframes.length;
|
|
1434
|
+
keyframes[length - 1].computedOffset = Number((_keyframes$offset = keyframes[length - 1].offset) !== null && _keyframes$offset !== void 0 ? _keyframes$offset : 1);
|
|
1435
|
+
if (length > 1) {
|
|
1436
|
+
var _keyframes$0$offset;
|
|
1437
|
+
keyframes[0].computedOffset = Number((_keyframes$0$offset = keyframes[0].offset) !== null && _keyframes$0$offset !== void 0 ? _keyframes$0$offset : 0);
|
|
1438
|
+
}
|
|
1439
|
+
var previousIndex = 0;
|
|
1440
|
+
var previousOffset = Number(keyframes[0].computedOffset);
|
|
1441
|
+
for (var _i = 1; _i < length; _i++) {
|
|
1442
|
+
var _offset = keyframes[_i].computedOffset;
|
|
1443
|
+
if (!isNil(_offset) && !isNil(previousOffset)) {
|
|
1444
|
+
for (var j = 1; j < _i - previousIndex; j++) keyframes[previousIndex + j].computedOffset = previousOffset + (Number(_offset) - previousOffset) * j / (_i - previousIndex);
|
|
1445
|
+
previousIndex = _i;
|
|
1446
|
+
previousOffset = Number(_offset);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (!everyFrameHasOffset) spaceKeyframes();
|
|
1451
|
+
return keyframes;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
var fills = 'backwards|forwards|both|none'.split('|');
|
|
1455
|
+
var directions = 'reverse|alternate|alternate-reverse'.split('|');
|
|
1456
|
+
function makeTiming(timingInput, forGroup) {
|
|
1457
|
+
var timing = new AnimationEffectTiming();
|
|
1458
|
+
if (forGroup) {
|
|
1459
|
+
timing.fill = 'both';
|
|
1460
|
+
timing.duration = 'auto';
|
|
1461
|
+
}
|
|
1462
|
+
if (typeof timingInput === 'number' && !isNaN(timingInput)) {
|
|
1463
|
+
timing.duration = timingInput;
|
|
1464
|
+
} else if (timingInput !== undefined) {
|
|
1465
|
+
Object.keys(timingInput).forEach(function (property) {
|
|
1466
|
+
if (timingInput[property] !== undefined && timingInput[property] !== null && timingInput[property] !== 'auto') {
|
|
1467
|
+
if (typeof timing[property] === 'number' || property === 'duration') {
|
|
1468
|
+
if (typeof timingInput[property] !== 'number' || isNaN(timingInput[property])) {
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (property === 'fill' && fills.indexOf(timingInput[property]) === -1) {
|
|
1473
|
+
return;
|
|
1474
|
+
}
|
|
1475
|
+
if (property === 'direction' && directions.indexOf(timingInput[property]) === -1) {
|
|
1476
|
+
return;
|
|
1477
|
+
}
|
|
1478
|
+
// @ts-ignore
|
|
1479
|
+
timing[property] = timingInput[property];
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
return timing;
|
|
1484
|
+
}
|
|
1485
|
+
function normalizeTimingInput(timingInput, forGroup) {
|
|
1486
|
+
timingInput = numericTimingToObject(timingInput !== null && timingInput !== void 0 ? timingInput : {
|
|
1487
|
+
duration: 'auto'
|
|
1488
|
+
});
|
|
1489
|
+
return makeTiming(timingInput, forGroup);
|
|
1490
|
+
}
|
|
1491
|
+
function numericTimingToObject(timingInput) {
|
|
1492
|
+
if (typeof timingInput === 'number') {
|
|
1493
|
+
if (isNaN(timingInput)) {
|
|
1494
|
+
timingInput = {
|
|
1495
|
+
duration: 'auto'
|
|
1496
|
+
};
|
|
1497
|
+
} else {
|
|
1498
|
+
timingInput = {
|
|
1499
|
+
duration: timingInput
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return timingInput;
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyframeEffect
|
|
1508
|
+
* @example
|
|
1509
|
+
const circleDownKeyframes = new KeyframeEffect(
|
|
1510
|
+
circle, // element to animate
|
|
1511
|
+
[
|
|
1512
|
+
{ transform: 'translateY(0)' }, // keyframe
|
|
1513
|
+
{ transform: 'translateY(100)' } // keyframe
|
|
1514
|
+
],
|
|
1515
|
+
{ duration: 3000, fill: 'forwards' } // keyframe options
|
|
1516
|
+
);
|
|
1517
|
+
*
|
|
1518
|
+
*/
|
|
1519
|
+
var KeyframeEffect = /*#__PURE__*/function () {
|
|
1520
|
+
// pseudoElement: string | null;
|
|
1521
|
+
|
|
1522
|
+
function KeyframeEffect(target, effectInput, timingInput) {
|
|
1523
|
+
var _this = this;
|
|
1524
|
+
_classCallCheck(this, KeyframeEffect);
|
|
1525
|
+
this.composite = 'replace';
|
|
1526
|
+
this.iterationComposite = 'replace';
|
|
1527
|
+
this.target = target;
|
|
1528
|
+
this.timing = normalizeTimingInput(timingInput, false);
|
|
1529
|
+
this.timing.effect = this;
|
|
1530
|
+
this.timing.activeDuration = calculateActiveDuration(this.timing);
|
|
1531
|
+
this.timing.endTime = Math.max(0, this.timing.delay + this.timing.activeDuration + this.timing.endDelay);
|
|
1532
|
+
this.normalizedKeyframes = normalizeKeyframes(effectInput, this.timing);
|
|
1533
|
+
this.interpolations = convertEffectInput(this.normalizedKeyframes, this.timing, this.target);
|
|
1534
|
+
|
|
1535
|
+
// 不支持 proxy 时降级成 this.timing
|
|
1536
|
+
var Proxy = runtime.globalThis.Proxy;
|
|
1537
|
+
this.computedTiming = Proxy ? new Proxy(this.timing, {
|
|
1538
|
+
get: function get(target, prop) {
|
|
1539
|
+
if (prop === 'duration') {
|
|
1540
|
+
return target.duration === 'auto' ? 0 : target.duration;
|
|
1541
|
+
}
|
|
1542
|
+
if (prop === 'fill') {
|
|
1543
|
+
return target.fill === 'auto' ? 'none' : target.fill;
|
|
1544
|
+
}
|
|
1545
|
+
if (prop === 'localTime') {
|
|
1546
|
+
return _this.animation && _this.animation.currentTime || null;
|
|
1547
|
+
}
|
|
1548
|
+
if (prop === 'currentIteration') {
|
|
1549
|
+
if (!_this.animation || _this.animation.playState !== 'running') {
|
|
1550
|
+
return null;
|
|
1551
|
+
}
|
|
1552
|
+
return target.currentIteration || 0;
|
|
1553
|
+
}
|
|
1554
|
+
if (prop === 'progress') {
|
|
1555
|
+
if (!_this.animation || _this.animation.playState !== 'running') {
|
|
1556
|
+
return null;
|
|
1557
|
+
}
|
|
1558
|
+
return target.progress || 0;
|
|
1559
|
+
}
|
|
1560
|
+
return target[prop];
|
|
1561
|
+
},
|
|
1562
|
+
set: function set() {
|
|
1563
|
+
return true;
|
|
1564
|
+
}
|
|
1565
|
+
}) : this.timing;
|
|
1566
|
+
}
|
|
1567
|
+
return _createClass(KeyframeEffect, [{
|
|
1568
|
+
key: "applyInterpolations",
|
|
1569
|
+
value: function applyInterpolations() {
|
|
1570
|
+
this.interpolations(this.target, Number(this.timeFraction));
|
|
1571
|
+
}
|
|
1572
|
+
}, {
|
|
1573
|
+
key: "update",
|
|
1574
|
+
value: function update(localTime) {
|
|
1575
|
+
if (localTime === null) {
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1578
|
+
this.timeFraction = calculateIterationProgress(this.timing.activeDuration, localTime, this.timing);
|
|
1579
|
+
return this.timeFraction !== null;
|
|
1580
|
+
}
|
|
1581
|
+
}, {
|
|
1582
|
+
key: "getKeyframes",
|
|
1583
|
+
value: function getKeyframes() {
|
|
1584
|
+
return this.normalizedKeyframes;
|
|
1585
|
+
}
|
|
1586
|
+
}, {
|
|
1587
|
+
key: "setKeyframes",
|
|
1588
|
+
value: function setKeyframes(keyframes) {
|
|
1589
|
+
this.normalizedKeyframes = normalizeKeyframes(keyframes);
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getComputedTiming
|
|
1593
|
+
*/
|
|
1594
|
+
}, {
|
|
1595
|
+
key: "getComputedTiming",
|
|
1596
|
+
value: function getComputedTiming() {
|
|
1597
|
+
return this.computedTiming;
|
|
1598
|
+
}
|
|
1599
|
+
/**
|
|
1600
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/getTiming
|
|
1601
|
+
*/
|
|
1602
|
+
}, {
|
|
1603
|
+
key: "getTiming",
|
|
1604
|
+
value: function getTiming() {
|
|
1605
|
+
return this.timing;
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEffect/updateTiming
|
|
1609
|
+
*/
|
|
1610
|
+
}, {
|
|
1611
|
+
key: "updateTiming",
|
|
1612
|
+
value: function updateTiming(timing) {
|
|
1613
|
+
var _this2 = this;
|
|
1614
|
+
Object.keys(timing || {}).forEach(function (name) {
|
|
1615
|
+
_this2.timing[name] = timing[name];
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
}]);
|
|
1619
|
+
}();
|
|
1620
|
+
|
|
1621
|
+
function compareAnimations(leftAnimation, rightAnimation) {
|
|
1622
|
+
return Number(leftAnimation.id) - Number(rightAnimation.id);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
/**
|
|
1626
|
+
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web-animations-js/index.d.ts
|
|
1627
|
+
*/
|
|
1628
|
+
var AnimationTimeline = /*#__PURE__*/function () {
|
|
1629
|
+
function AnimationTimeline(document) {
|
|
1630
|
+
var _this = this;
|
|
1631
|
+
_classCallCheck(this, AnimationTimeline);
|
|
1632
|
+
/**
|
|
1633
|
+
* all active animations
|
|
1634
|
+
*/
|
|
1635
|
+
this.animations = [];
|
|
1636
|
+
this.ticking = false;
|
|
1637
|
+
this.timelineTicking = false;
|
|
1638
|
+
this.hasRestartedThisFrame = false;
|
|
1639
|
+
this.animationsWithPromises = [];
|
|
1640
|
+
this.inTick = false;
|
|
1641
|
+
this.pendingEffects = [];
|
|
1642
|
+
this.currentTime = null;
|
|
1643
|
+
this.rafId = 0;
|
|
1644
|
+
this.rafCallbacks = [];
|
|
1645
|
+
this.webAnimationsNextTick = function (t) {
|
|
1646
|
+
_this.currentTime = t;
|
|
1647
|
+
_this.discardAnimations();
|
|
1648
|
+
if (_this.animations.length === 0) {
|
|
1649
|
+
_this.timelineTicking = false;
|
|
1650
|
+
} else {
|
|
1651
|
+
_this.requestAnimationFrame(_this.webAnimationsNextTick);
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
this.processRafCallbacks = function (t) {
|
|
1655
|
+
var processing = _this.rafCallbacks;
|
|
1656
|
+
_this.rafCallbacks = [];
|
|
1657
|
+
if (t < Number(_this.currentTime)) t = Number(_this.currentTime);
|
|
1658
|
+
_this.animations.sort(compareAnimations);
|
|
1659
|
+
_this.animations = _this.tick(t, true, _this.animations)[0];
|
|
1660
|
+
processing.forEach(function (entry) {
|
|
1661
|
+
entry[1](t);
|
|
1662
|
+
});
|
|
1663
|
+
_this.applyPendingEffects();
|
|
1664
|
+
};
|
|
1665
|
+
this.document = document;
|
|
1666
|
+
}
|
|
1667
|
+
return _createClass(AnimationTimeline, [{
|
|
1668
|
+
key: "getAnimations",
|
|
1669
|
+
value: function getAnimations() {
|
|
1670
|
+
this.discardAnimations();
|
|
1671
|
+
return this.animations.slice();
|
|
1672
|
+
}
|
|
1673
|
+
}, {
|
|
1674
|
+
key: "isTicking",
|
|
1675
|
+
value: function isTicking() {
|
|
1676
|
+
return this.inTick;
|
|
1677
|
+
}
|
|
1678
|
+
}, {
|
|
1679
|
+
key: "play",
|
|
1680
|
+
value: function play(target, keyframes, options) {
|
|
1681
|
+
var effect = new KeyframeEffect(target, keyframes, options);
|
|
1682
|
+
var animation = new Animation(effect, this);
|
|
1683
|
+
this.animations.push(animation);
|
|
1684
|
+
this.restartWebAnimationsNextTick();
|
|
1685
|
+
animation.updatePromises();
|
|
1686
|
+
animation.play();
|
|
1687
|
+
animation.updatePromises();
|
|
1688
|
+
return animation;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// RAF is supposed to be the last script to occur before frame rendering but not
|
|
1692
|
+
// all browsers behave like this. This function is for synchonously updating an
|
|
1693
|
+
// animation's effects whenever its state is mutated by script to work around
|
|
1694
|
+
// incorrect script execution ordering by the browser.
|
|
1695
|
+
}, {
|
|
1696
|
+
key: "applyDirtiedAnimation",
|
|
1697
|
+
value: function applyDirtiedAnimation(animation) {
|
|
1698
|
+
var _this2 = this;
|
|
1699
|
+
if (this.inTick) {
|
|
1700
|
+
return;
|
|
1701
|
+
}
|
|
1702
|
+
// update active animations in displayobject
|
|
1703
|
+
animation.markTarget();
|
|
1704
|
+
var animations = animation.targetAnimations();
|
|
1705
|
+
animations.sort(compareAnimations);
|
|
1706
|
+
|
|
1707
|
+
// clear inactive animations
|
|
1708
|
+
var inactiveAnimations = this.tick(Number(this.currentTime), false, animations.slice())[1];
|
|
1709
|
+
inactiveAnimations.forEach(function (animation) {
|
|
1710
|
+
var index = _this2.animations.indexOf(animation);
|
|
1711
|
+
if (index !== -1) {
|
|
1712
|
+
_this2.animations.splice(index, 1);
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
this.applyPendingEffects();
|
|
1716
|
+
}
|
|
1717
|
+
}, {
|
|
1718
|
+
key: "restart",
|
|
1719
|
+
value: function restart() {
|
|
1720
|
+
if (!this.ticking) {
|
|
1721
|
+
this.ticking = true;
|
|
1722
|
+
this.requestAnimationFrame(function () {});
|
|
1723
|
+
this.hasRestartedThisFrame = true;
|
|
1724
|
+
}
|
|
1725
|
+
return this.hasRestartedThisFrame;
|
|
1726
|
+
}
|
|
1727
|
+
}, {
|
|
1728
|
+
key: "destroy",
|
|
1729
|
+
value: function destroy() {
|
|
1730
|
+
this.document.defaultView.cancelAnimationFrame(this.frameId);
|
|
1731
|
+
}
|
|
1732
|
+
}, {
|
|
1733
|
+
key: "applyPendingEffects",
|
|
1734
|
+
value: function applyPendingEffects() {
|
|
1735
|
+
this.pendingEffects.forEach(function (effect) {
|
|
1736
|
+
effect === null || effect === void 0 || effect.applyInterpolations();
|
|
1737
|
+
});
|
|
1738
|
+
this.pendingEffects = [];
|
|
1739
|
+
}
|
|
1740
|
+
}, {
|
|
1741
|
+
key: "updateAnimationsPromises",
|
|
1742
|
+
value: function updateAnimationsPromises() {
|
|
1743
|
+
this.animationsWithPromises = this.animationsWithPromises.filter(function (animation) {
|
|
1744
|
+
return animation.updatePromises();
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
}, {
|
|
1748
|
+
key: "discardAnimations",
|
|
1749
|
+
value: function discardAnimations() {
|
|
1750
|
+
this.updateAnimationsPromises();
|
|
1751
|
+
this.animations = this.animations.filter(function (animation) {
|
|
1752
|
+
return animation.playState !== 'finished' && animation.playState !== 'idle';
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
}, {
|
|
1756
|
+
key: "restartWebAnimationsNextTick",
|
|
1757
|
+
value: function restartWebAnimationsNextTick() {
|
|
1758
|
+
if (!this.timelineTicking) {
|
|
1759
|
+
this.timelineTicking = true;
|
|
1760
|
+
this.requestAnimationFrame(this.webAnimationsNextTick);
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
}, {
|
|
1764
|
+
key: "rAF",
|
|
1765
|
+
value: function rAF(f) {
|
|
1766
|
+
var id = this.rafId++;
|
|
1767
|
+
if (this.rafCallbacks.length === 0) {
|
|
1768
|
+
this.frameId = this.document.defaultView.requestAnimationFrame(this.processRafCallbacks);
|
|
1769
|
+
}
|
|
1770
|
+
this.rafCallbacks.push([id, f]);
|
|
1771
|
+
return id;
|
|
1772
|
+
}
|
|
1773
|
+
}, {
|
|
1774
|
+
key: "requestAnimationFrame",
|
|
1775
|
+
value: function requestAnimationFrame(f) {
|
|
1776
|
+
var _this3 = this;
|
|
1777
|
+
return this.rAF(function (x) {
|
|
1778
|
+
_this3.updateAnimationsPromises();
|
|
1779
|
+
f(x);
|
|
1780
|
+
_this3.updateAnimationsPromises();
|
|
1781
|
+
});
|
|
1782
|
+
}
|
|
1783
|
+
}, {
|
|
1784
|
+
key: "tick",
|
|
1785
|
+
value: function tick(t, isAnimationFrame, updatingAnimations) {
|
|
1786
|
+
var _this4 = this,
|
|
1787
|
+
_this$pendingEffects,
|
|
1788
|
+
_this$pendingEffects2;
|
|
1789
|
+
this.inTick = true;
|
|
1790
|
+
this.hasRestartedThisFrame = false;
|
|
1791
|
+
this.currentTime = t;
|
|
1792
|
+
this.ticking = false;
|
|
1793
|
+
var newPendingClears = [];
|
|
1794
|
+
var newPendingEffects = [];
|
|
1795
|
+
var activeAnimations = [];
|
|
1796
|
+
var inactiveAnimations = [];
|
|
1797
|
+
updatingAnimations.forEach(function (animation) {
|
|
1798
|
+
animation.tick(t, isAnimationFrame);
|
|
1799
|
+
if (!animation._inEffect) {
|
|
1800
|
+
newPendingClears.push(animation.effect);
|
|
1801
|
+
animation.unmarkTarget();
|
|
1802
|
+
} else {
|
|
1803
|
+
newPendingEffects.push(animation.effect);
|
|
1804
|
+
animation.markTarget();
|
|
1805
|
+
}
|
|
1806
|
+
if (animation._needsTick) _this4.ticking = true;
|
|
1807
|
+
var alive = animation._inEffect || animation._needsTick;
|
|
1808
|
+
animation._inTimeline = alive;
|
|
1809
|
+
if (alive) {
|
|
1810
|
+
activeAnimations.push(animation);
|
|
1811
|
+
} else {
|
|
1812
|
+
inactiveAnimations.push(animation);
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1815
|
+
(_this$pendingEffects = this.pendingEffects).push.apply(_this$pendingEffects, newPendingClears);
|
|
1816
|
+
(_this$pendingEffects2 = this.pendingEffects).push.apply(_this$pendingEffects2, newPendingEffects);
|
|
1817
|
+
if (this.ticking) this.requestAnimationFrame(function () {});
|
|
1818
|
+
this.inTick = false;
|
|
1819
|
+
return [activeAnimations, inactiveAnimations];
|
|
1820
|
+
}
|
|
1821
|
+
}]);
|
|
1822
|
+
}();
|
|
1823
|
+
|
|
1824
|
+
runtime.EasingFunction = parseEasingFunction;
|
|
1825
|
+
runtime.AnimationTimeline = AnimationTimeline;
|
|
1826
|
+
|
|
1827
|
+
/**
|
|
1828
|
+
* Provides camera action & animation.
|
|
1829
|
+
*/
|
|
1830
|
+
var AdvancedCamera = /*#__PURE__*/function (_Camera) {
|
|
1831
|
+
function AdvancedCamera() {
|
|
1832
|
+
var _this;
|
|
1833
|
+
_classCallCheck(this, AdvancedCamera);
|
|
1834
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1835
|
+
args[_key] = arguments[_key];
|
|
1836
|
+
}
|
|
1837
|
+
_this = _callSuper(this, AdvancedCamera, [].concat(args));
|
|
1838
|
+
/**
|
|
1839
|
+
* switch between multiple landmarks
|
|
1840
|
+
*/
|
|
1841
|
+
_this.landmarks = [];
|
|
1842
|
+
return _this;
|
|
1843
|
+
}
|
|
1844
|
+
_inherits(AdvancedCamera, _Camera);
|
|
1845
|
+
return _createClass(AdvancedCamera, [{
|
|
1846
|
+
key: "rotate",
|
|
1847
|
+
value:
|
|
1848
|
+
/**
|
|
1849
|
+
* Changes the azimuth and elevation with respect to the current camera axes
|
|
1850
|
+
* @param {Number} azimuth the relative azimuth
|
|
1851
|
+
* @param {Number} elevation the relative elevation
|
|
1852
|
+
* @param {Number} roll the relative roll
|
|
1853
|
+
*/
|
|
1854
|
+
function rotate(azimuth, elevation, roll) {
|
|
1855
|
+
this.relElevation = getAngle(elevation);
|
|
1856
|
+
this.relAzimuth = getAngle(azimuth);
|
|
1857
|
+
this.relRoll = getAngle(roll);
|
|
1858
|
+
this.elevation += this.relElevation;
|
|
1859
|
+
this.azimuth += this.relAzimuth;
|
|
1860
|
+
this.roll += this.relRoll;
|
|
1861
|
+
if (this.type === CameraType.EXPLORING) {
|
|
1862
|
+
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation));
|
|
1863
|
+
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth));
|
|
1864
|
+
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], deg2rad(this.relRoll));
|
|
1865
|
+
var rotQ = quat.multiply(quat.create(), rotY, rotX);
|
|
1866
|
+
rotQ = quat.multiply(quat.create(), rotQ, rotZ);
|
|
1867
|
+
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ);
|
|
1868
|
+
mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]);
|
|
1869
|
+
mat4.multiply(this.matrix, this.matrix, rotMatrix);
|
|
1870
|
+
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]);
|
|
1871
|
+
} else {
|
|
1872
|
+
if (Math.abs(this.elevation) > 90) {
|
|
1873
|
+
return this;
|
|
1874
|
+
}
|
|
1875
|
+
this.computeMatrix();
|
|
1876
|
+
}
|
|
1877
|
+
this._getAxes();
|
|
1878
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
1879
|
+
this._getPosition();
|
|
1880
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
1881
|
+
this._getFocalPoint();
|
|
1882
|
+
}
|
|
1883
|
+
this._update();
|
|
1884
|
+
return this;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* 沿水平(right) & 垂直(up)平移相机
|
|
1889
|
+
*/
|
|
1890
|
+
}, {
|
|
1891
|
+
key: "pan",
|
|
1892
|
+
value: function pan(tx, ty) {
|
|
1893
|
+
var coords = createVec3(tx, ty, 0);
|
|
1894
|
+
var pos = vec3.clone(this.position);
|
|
1895
|
+
vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0]));
|
|
1896
|
+
vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1]));
|
|
1897
|
+
this._setPosition(pos);
|
|
1898
|
+
this.triggerUpdate();
|
|
1899
|
+
return this;
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
/**
|
|
1903
|
+
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢
|
|
1904
|
+
*/
|
|
1905
|
+
}, {
|
|
1906
|
+
key: "dolly",
|
|
1907
|
+
value: function dolly(value) {
|
|
1908
|
+
var n = this.forward;
|
|
1909
|
+
var pos = vec3.clone(this.position);
|
|
1910
|
+
var step = value * this.dollyingStep;
|
|
1911
|
+
var updatedDistance = this.distance + value * this.dollyingStep;
|
|
1912
|
+
|
|
1913
|
+
// 限制视点距离范围
|
|
1914
|
+
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance;
|
|
1915
|
+
pos[0] += step * n[0];
|
|
1916
|
+
pos[1] += step * n[1];
|
|
1917
|
+
pos[2] += step * n[2];
|
|
1918
|
+
this._setPosition(pos);
|
|
1919
|
+
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) {
|
|
1920
|
+
// 重新计算视点距离
|
|
1921
|
+
this._getDistance();
|
|
1922
|
+
} else if (this.type === CameraType.TRACKING) {
|
|
1923
|
+
// 保持视距,移动视点位置
|
|
1924
|
+
vec3.add(this.focalPoint, pos, this.distanceVector);
|
|
1925
|
+
}
|
|
1926
|
+
this.triggerUpdate();
|
|
1927
|
+
return this;
|
|
1928
|
+
}
|
|
1929
|
+
}, {
|
|
1930
|
+
key: "cancelLandmarkAnimation",
|
|
1931
|
+
value: function cancelLandmarkAnimation() {
|
|
1932
|
+
if (this.landmarkAnimationID !== undefined) {
|
|
1933
|
+
this.canvas.cancelAnimationFrame(this.landmarkAnimationID);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
}, {
|
|
1937
|
+
key: "createLandmark",
|
|
1938
|
+
value: function createLandmark(name) {
|
|
1939
|
+
var _position$, _position$2, _focalPoint$, _focalPoint$2;
|
|
1940
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1941
|
+
var _params$position = params.position,
|
|
1942
|
+
position = _params$position === void 0 ? this.position : _params$position,
|
|
1943
|
+
_params$focalPoint = params.focalPoint,
|
|
1944
|
+
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint,
|
|
1945
|
+
roll = params.roll,
|
|
1946
|
+
zoom = params.zoom;
|
|
1947
|
+
var camera = new runtime.CameraContribution();
|
|
1948
|
+
camera.setType(this.type, undefined);
|
|
1949
|
+
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]);
|
|
1950
|
+
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]);
|
|
1951
|
+
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll);
|
|
1952
|
+
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom);
|
|
1953
|
+
var landmark = {
|
|
1954
|
+
name: name,
|
|
1955
|
+
matrix: mat4.clone(camera.getWorldTransform()),
|
|
1956
|
+
right: vec3.clone(camera.right),
|
|
1957
|
+
up: vec3.clone(camera.up),
|
|
1958
|
+
forward: vec3.clone(camera.forward),
|
|
1959
|
+
position: vec3.clone(camera.getPosition()),
|
|
1960
|
+
focalPoint: vec3.clone(camera.getFocalPoint()),
|
|
1961
|
+
distanceVector: vec3.clone(camera.getDistanceVector()),
|
|
1962
|
+
distance: camera.getDistance(),
|
|
1963
|
+
dollyingStep: camera.getDollyingStep(),
|
|
1964
|
+
azimuth: camera.getAzimuth(),
|
|
1965
|
+
elevation: camera.getElevation(),
|
|
1966
|
+
roll: camera.getRoll(),
|
|
1967
|
+
relAzimuth: camera.relAzimuth,
|
|
1968
|
+
relElevation: camera.relElevation,
|
|
1969
|
+
relRoll: camera.relRoll,
|
|
1970
|
+
zoom: camera.getZoom()
|
|
1971
|
+
};
|
|
1972
|
+
this.landmarks.push(landmark);
|
|
1973
|
+
return landmark;
|
|
1974
|
+
}
|
|
1975
|
+
}, {
|
|
1976
|
+
key: "gotoLandmark",
|
|
1977
|
+
value: function gotoLandmark(name) {
|
|
1978
|
+
var _this2 = this;
|
|
1979
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1980
|
+
var landmark = isString(name) ? this.landmarks.find(function (l) {
|
|
1981
|
+
return l.name === name;
|
|
1982
|
+
}) : name;
|
|
1983
|
+
if (landmark) {
|
|
1984
|
+
var _ref = isNumber(options) ? {
|
|
1985
|
+
duration: options
|
|
1986
|
+
} : options,
|
|
1987
|
+
_ref$easing = _ref.easing,
|
|
1988
|
+
easing = _ref$easing === void 0 ? 'linear' : _ref$easing,
|
|
1989
|
+
_ref$duration = _ref.duration,
|
|
1990
|
+
duration = _ref$duration === void 0 ? 100 : _ref$duration,
|
|
1991
|
+
_ref$easingFunction = _ref.easingFunction,
|
|
1992
|
+
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction,
|
|
1993
|
+
_ref$onfinish = _ref.onfinish,
|
|
1994
|
+
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish,
|
|
1995
|
+
_ref$onframe = _ref.onframe,
|
|
1996
|
+
onframe = _ref$onframe === void 0 ? undefined : _ref$onframe;
|
|
1997
|
+
var epsilon = 0.01;
|
|
1998
|
+
|
|
1999
|
+
// cancel ongoing animation
|
|
2000
|
+
this.cancelLandmarkAnimation();
|
|
2001
|
+
var destPosition = landmark.position;
|
|
2002
|
+
var destFocalPoint = landmark.focalPoint;
|
|
2003
|
+
var destZoom = landmark.zoom;
|
|
2004
|
+
var destRoll = landmark.roll;
|
|
2005
|
+
var easingFunc = easingFunction || runtime.EasingFunction(easing);
|
|
2006
|
+
var timeStart;
|
|
2007
|
+
var end = function end() {
|
|
2008
|
+
_this2.setFocalPoint(destFocalPoint);
|
|
2009
|
+
_this2.setPosition(destPosition);
|
|
2010
|
+
_this2.setRoll(destRoll);
|
|
2011
|
+
_this2.setZoom(destZoom);
|
|
2012
|
+
_this2.computeMatrix();
|
|
2013
|
+
_this2.triggerUpdate();
|
|
2014
|
+
onfinish === null || onfinish === void 0 || onfinish();
|
|
2015
|
+
};
|
|
2016
|
+
if (duration === 0) return end();
|
|
2017
|
+
var _animate = function animate(timestamp) {
|
|
2018
|
+
if (timeStart === undefined) {
|
|
2019
|
+
timeStart = timestamp;
|
|
2020
|
+
}
|
|
2021
|
+
var elapsed = timestamp - timeStart;
|
|
2022
|
+
if (elapsed >= duration) {
|
|
2023
|
+
end();
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
2026
|
+
// use the same ease function in animation system
|
|
2027
|
+
var t = easingFunc(elapsed / duration);
|
|
2028
|
+
var interFocalPoint = vec3.create();
|
|
2029
|
+
var interPosition = vec3.create();
|
|
2030
|
+
var interZoom = 1;
|
|
2031
|
+
var interRoll = 0;
|
|
2032
|
+
vec3.lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t);
|
|
2033
|
+
vec3.lerp(interPosition, _this2.position, destPosition, t);
|
|
2034
|
+
interRoll = _this2.roll * (1 - t) + destRoll * t;
|
|
2035
|
+
interZoom = _this2.zoom * (1 - t) + destZoom * t;
|
|
2036
|
+
_this2.setFocalPoint(interFocalPoint);
|
|
2037
|
+
_this2.setPosition(interPosition);
|
|
2038
|
+
_this2.setRoll(interRoll);
|
|
2039
|
+
_this2.setZoom(interZoom);
|
|
2040
|
+
var dist = vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition);
|
|
2041
|
+
if (dist <= epsilon && destZoom === undefined && destRoll === undefined) {
|
|
2042
|
+
return end();
|
|
2043
|
+
}
|
|
2044
|
+
_this2.computeMatrix();
|
|
2045
|
+
_this2.triggerUpdate();
|
|
2046
|
+
if (elapsed < duration) {
|
|
2047
|
+
onframe === null || onframe === void 0 || onframe(t);
|
|
2048
|
+
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(_animate);
|
|
2049
|
+
}
|
|
2050
|
+
};
|
|
2051
|
+
this.canvas.requestAnimationFrame(_animate);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
/**
|
|
2056
|
+
* Sets the camera to a distance such that the area covered by the bounding box is viewed.
|
|
2057
|
+
*/
|
|
2058
|
+
// shot(displayObject: DisplayObject) {
|
|
2059
|
+
// const aabb = displayObject.getBounds();
|
|
2060
|
+
|
|
2061
|
+
// if (!AABB.isEmpty(aabb)) {
|
|
2062
|
+
// this.setElevation(0);
|
|
2063
|
+
// this.setAzimuth(0);
|
|
2064
|
+
// this.setRoll(0);
|
|
2065
|
+
|
|
2066
|
+
// const { halfExtents, center } = aabb;
|
|
2067
|
+
// const maxDim = Math.max(halfExtents[0] * 2, halfExtents[1] * 2);
|
|
2068
|
+
|
|
2069
|
+
// const cc = center.map((c: number) => Math.round(c * 1000) / 1000) as [number, number, number];
|
|
2070
|
+
|
|
2071
|
+
// if (maxDim !== 0) {
|
|
2072
|
+
// const d = (1.5 * maxDim) / Math.tan(this.fov * DEG_2_RAD);
|
|
2073
|
+
// this.setPosition([cc[0], cc[1], cc[2] + d]);
|
|
2074
|
+
// }
|
|
2075
|
+
|
|
2076
|
+
// this.setFocalPoint(cc);
|
|
2077
|
+
// }
|
|
2078
|
+
// }
|
|
2079
|
+
}]);
|
|
2080
|
+
}(Camera);
|
|
2081
|
+
|
|
2082
|
+
runtime.CameraContribution = AdvancedCamera;
|
|
2083
|
+
|
|
2084
|
+
var _excluded$1 = ["clippingRegion", "beforeDrawImage", "afterDrawImage", "ignoreElements"];
|
|
2085
|
+
var ImageExporter = /*#__PURE__*/function () {
|
|
2086
|
+
function ImageExporter(options) {
|
|
2087
|
+
_classCallCheck(this, ImageExporter);
|
|
2088
|
+
this.options = options;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
/**
|
|
2092
|
+
* return a HTMLCanvasElement which you can call `toDataURL` later
|
|
2093
|
+
*
|
|
2094
|
+
* @example
|
|
2095
|
+
* const canvas = await exporter.toCanvas();
|
|
2096
|
+
* canvas.toDataURL(); // data:
|
|
2097
|
+
*/
|
|
2098
|
+
return _createClass(ImageExporter, [{
|
|
2099
|
+
key: "toCanvas",
|
|
2100
|
+
value: (function () {
|
|
2101
|
+
var _toCanvas = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
2102
|
+
var options,
|
|
2103
|
+
_this$options$canvas$,
|
|
2104
|
+
width,
|
|
2105
|
+
height,
|
|
2106
|
+
doc,
|
|
2107
|
+
dpr,
|
|
2108
|
+
_options$clippingRegi,
|
|
2109
|
+
clippingRegion,
|
|
2110
|
+
beforeDrawImage,
|
|
2111
|
+
afterDrawImage,
|
|
2112
|
+
_ignoreElements,
|
|
2113
|
+
rest,
|
|
2114
|
+
dataURL,
|
|
2115
|
+
image,
|
|
2116
|
+
sx,
|
|
2117
|
+
sy,
|
|
2118
|
+
sWidth,
|
|
2119
|
+
sHeight,
|
|
2120
|
+
canvas,
|
|
2121
|
+
context,
|
|
2122
|
+
sourceImageMultipiler,
|
|
2123
|
+
$dom,
|
|
2124
|
+
_canvas,
|
|
2125
|
+
_image,
|
|
2126
|
+
_args = arguments;
|
|
2127
|
+
return _regeneratorRuntime().wrap(function (_context) {
|
|
2128
|
+
while (1) switch (_context.prev = _context.next) {
|
|
2129
|
+
case 0:
|
|
2130
|
+
options = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
2131
|
+
_this$options$canvas$ = this.options.canvas.getConfig(), width = _this$options$canvas$.width, height = _this$options$canvas$.height, doc = _this$options$canvas$.document;
|
|
2132
|
+
dpr = this.options.canvas.getContextService().getDPR();
|
|
2133
|
+
_options$clippingRegi = options.clippingRegion, clippingRegion = _options$clippingRegi === void 0 ? new Rectangle(0, 0, width, height) : _options$clippingRegi, beforeDrawImage = options.beforeDrawImage, afterDrawImage = options.afterDrawImage, _ignoreElements = options.ignoreElements, rest = _objectWithoutProperties(options, _excluded$1);
|
|
2134
|
+
_context.next = 1;
|
|
2135
|
+
return this.toDataURL(rest);
|
|
2136
|
+
case 1:
|
|
2137
|
+
dataURL = _context.sent;
|
|
2138
|
+
_context.next = 2;
|
|
2139
|
+
return this.getOrCreateImage(dataURL);
|
|
2140
|
+
case 2:
|
|
2141
|
+
image = _context.sent;
|
|
2142
|
+
sx = clippingRegion.x, sy = clippingRegion.y, sWidth = clippingRegion.width, sHeight = clippingRegion.height; // TODO: provide custom `createCanvas` method like `createImage`
|
|
2143
|
+
canvas = (doc || document).createElement('canvas');
|
|
2144
|
+
canvas.width = sWidth * dpr;
|
|
2145
|
+
canvas.height = sHeight * dpr;
|
|
2146
|
+
context = canvas.getContext('2d');
|
|
2147
|
+
context.scale(dpr, dpr);
|
|
2148
|
+
if (beforeDrawImage) {
|
|
2149
|
+
beforeDrawImage(context);
|
|
2150
|
+
}
|
|
2151
|
+
sourceImageMultipiler = image.width > width ? dpr : 1;
|
|
2152
|
+
context.drawImage(image, sx * sourceImageMultipiler, sy * sourceImageMultipiler, sWidth * sourceImageMultipiler, sHeight * sourceImageMultipiler, 0, 0, sWidth, sHeight);
|
|
2153
|
+
if (this.isSVG()) {
|
|
2154
|
+
_context.next = 5;
|
|
2155
|
+
break;
|
|
2156
|
+
}
|
|
2157
|
+
$dom = this.options.canvas.getContextService().getDomElement();
|
|
2158
|
+
if (!($dom && $dom.parentElement)) {
|
|
2159
|
+
_context.next = 5;
|
|
2160
|
+
break;
|
|
2161
|
+
}
|
|
2162
|
+
_context.next = 3;
|
|
2163
|
+
return html2canvas($dom.parentElement, {
|
|
2164
|
+
backgroundColor: null,
|
|
2165
|
+
width: width,
|
|
2166
|
+
height: height,
|
|
2167
|
+
x: 0,
|
|
2168
|
+
y: 0,
|
|
2169
|
+
ignoreElements: function ignoreElements(element) {
|
|
2170
|
+
if (element === $dom) {
|
|
2171
|
+
return true;
|
|
2172
|
+
}
|
|
2173
|
+
return _ignoreElements && _ignoreElements(element);
|
|
2174
|
+
}
|
|
2175
|
+
});
|
|
2176
|
+
case 3:
|
|
2177
|
+
_canvas = _context.sent;
|
|
2178
|
+
_context.next = 4;
|
|
2179
|
+
return this.getOrCreateImage(_canvas.toDataURL());
|
|
2180
|
+
case 4:
|
|
2181
|
+
_image = _context.sent;
|
|
2182
|
+
context.drawImage(_image, sx * sourceImageMultipiler, sy * sourceImageMultipiler, sWidth * sourceImageMultipiler, sHeight * sourceImageMultipiler, 0, 0, sWidth, sHeight);
|
|
2183
|
+
case 5:
|
|
2184
|
+
if (afterDrawImage) {
|
|
2185
|
+
afterDrawImage(context);
|
|
2186
|
+
}
|
|
2187
|
+
return _context.abrupt("return", canvas);
|
|
2188
|
+
case 6:
|
|
2189
|
+
case "end":
|
|
2190
|
+
return _context.stop();
|
|
2191
|
+
}
|
|
2192
|
+
}, _callee, this);
|
|
2193
|
+
}));
|
|
2194
|
+
function toCanvas() {
|
|
2195
|
+
return _toCanvas.apply(this, arguments);
|
|
2196
|
+
}
|
|
2197
|
+
return toCanvas;
|
|
2198
|
+
}()
|
|
2199
|
+
/**
|
|
2200
|
+
* generate data url for the whole viewport
|
|
2201
|
+
*/
|
|
2202
|
+
)
|
|
2203
|
+
}, {
|
|
2204
|
+
key: "toDataURL",
|
|
2205
|
+
value: (function () {
|
|
2206
|
+
var _toDataURL = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
2207
|
+
var options,
|
|
2208
|
+
_args2 = arguments;
|
|
2209
|
+
return _regeneratorRuntime().wrap(function (_context2) {
|
|
2210
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
2211
|
+
case 0:
|
|
2212
|
+
options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
2213
|
+
return _context2.abrupt("return", this.options.canvas.getContextService().toDataURL(options));
|
|
2214
|
+
case 1:
|
|
2215
|
+
case "end":
|
|
2216
|
+
return _context2.stop();
|
|
2217
|
+
}
|
|
2218
|
+
}, _callee2, this);
|
|
2219
|
+
}));
|
|
2220
|
+
function toDataURL() {
|
|
2221
|
+
return _toDataURL.apply(this, arguments);
|
|
2222
|
+
}
|
|
2223
|
+
return toDataURL;
|
|
2224
|
+
}())
|
|
2225
|
+
}, {
|
|
2226
|
+
key: "isSVG",
|
|
2227
|
+
value: function isSVG() {
|
|
2228
|
+
return isBrowser && this.options.canvas.getContextService().getDomElement() instanceof SVGSVGElement;
|
|
2229
|
+
}
|
|
2230
|
+
}, {
|
|
2231
|
+
key: "toSVGDataURL",
|
|
2232
|
+
value: function () {
|
|
2233
|
+
var _toSVGDataURL = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
2234
|
+
return _regeneratorRuntime().wrap(function (_context3) {
|
|
2235
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
2236
|
+
case 0:
|
|
2237
|
+
if (!this.isSVG()) {
|
|
2238
|
+
_context3.next = 1;
|
|
2239
|
+
break;
|
|
2240
|
+
}
|
|
2241
|
+
return _context3.abrupt("return", this.toDataURL());
|
|
2242
|
+
case 1:
|
|
2243
|
+
case "end":
|
|
2244
|
+
return _context3.stop();
|
|
2245
|
+
}
|
|
2246
|
+
}, _callee3, this);
|
|
2247
|
+
}));
|
|
2248
|
+
function toSVGDataURL() {
|
|
2249
|
+
return _toSVGDataURL.apply(this, arguments);
|
|
2250
|
+
}
|
|
2251
|
+
return toSVGDataURL;
|
|
2252
|
+
}()
|
|
2253
|
+
}, {
|
|
2254
|
+
key: "downloadImage",
|
|
2255
|
+
value: function downloadImage(options) {
|
|
2256
|
+
var _this$options$canvas$2 = this.options.canvas.getConfig(),
|
|
2257
|
+
doc = _this$options$canvas$2.document;
|
|
2258
|
+
|
|
2259
|
+
// retrieve context at runtime
|
|
2260
|
+
var defaultFilename = this.options.defaultFilename;
|
|
2261
|
+
var dataURL = options.dataURL,
|
|
2262
|
+
_options$name = options.name,
|
|
2263
|
+
name = _options$name === void 0 ? defaultFilename || 'g' : _options$name;
|
|
2264
|
+
var mimeType = dataURL.substring(dataURL.indexOf(':') + 1, dataURL.indexOf(';'));
|
|
2265
|
+
var suffix = mimeType.split('/')[1];
|
|
2266
|
+
|
|
2267
|
+
// g-svg only support .svg
|
|
2268
|
+
var isSVG = dataURL.startsWith('data:image/svg');
|
|
2269
|
+
var fileName = "".concat(name, ".").concat(isSVG ? 'svg' : suffix);
|
|
2270
|
+
var link = (doc || document).createElement('a');
|
|
2271
|
+
if (isSVG) {
|
|
2272
|
+
link.addEventListener('click', function () {
|
|
2273
|
+
link.download = fileName;
|
|
2274
|
+
link.href = dataURL;
|
|
2275
|
+
});
|
|
2276
|
+
} else if (window.Blob && window.URL) {
|
|
2277
|
+
var arr = dataURL.split(',');
|
|
2278
|
+
var mime = '';
|
|
2279
|
+
if (arr && arr.length > 0) {
|
|
2280
|
+
var match = arr[0].match(/:(.*?);/);
|
|
2281
|
+
// eslint-disable-next-line prefer-destructuring
|
|
2282
|
+
if (match && match.length >= 2) mime = match[1];
|
|
2283
|
+
}
|
|
2284
|
+
var bstr = atob(arr[1]);
|
|
2285
|
+
var n = bstr.length;
|
|
2286
|
+
var u8arr = new Uint8Array(n);
|
|
2287
|
+
while (n--) {
|
|
2288
|
+
u8arr[n] = bstr.charCodeAt(n);
|
|
2289
|
+
}
|
|
2290
|
+
var blobObj = new Blob([u8arr], {
|
|
2291
|
+
type: mime
|
|
2292
|
+
});
|
|
2293
|
+
|
|
2294
|
+
// account for IE
|
|
2295
|
+
// @see https://stackoverflow.com/a/41434373
|
|
2296
|
+
if (runtime.globalThis.navigator.msSaveBlob) {
|
|
2297
|
+
runtime.globalThis.navigator.msSaveBlob(blobObj, fileName);
|
|
2298
|
+
} else {
|
|
2299
|
+
link.addEventListener('click', function () {
|
|
2300
|
+
link.download = fileName;
|
|
2301
|
+
link.href = window.URL.createObjectURL(blobObj);
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
// trigger click
|
|
2307
|
+
if (link.click) {
|
|
2308
|
+
link.click();
|
|
2309
|
+
} else {
|
|
2310
|
+
var e = (doc || document).createEvent('MouseEvents');
|
|
2311
|
+
e.initEvent('click', false, false);
|
|
2312
|
+
link.dispatchEvent(e);
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
}, {
|
|
2316
|
+
key: "getOrCreateImage",
|
|
2317
|
+
value: function getOrCreateImage(src) {
|
|
2318
|
+
var _this = this;
|
|
2319
|
+
return new Promise(function (resolve, reject) {
|
|
2320
|
+
// @see https://github.com/antvis/g/issues/938
|
|
2321
|
+
var image = _this.options.canvas.getConfig().createImage();
|
|
2322
|
+
if (image) {
|
|
2323
|
+
image.onload = function () {
|
|
2324
|
+
resolve(image);
|
|
2325
|
+
};
|
|
2326
|
+
image.onerror = function (ev) {
|
|
2327
|
+
reject(ev);
|
|
2328
|
+
};
|
|
2329
|
+
image.crossOrigin = 'Anonymous';
|
|
2330
|
+
image.src = src;
|
|
2331
|
+
}
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
}]);
|
|
2335
|
+
}();
|
|
2336
|
+
|
|
2337
|
+
/**
|
|
2338
|
+
* 计算贴图单元大小
|
|
2339
|
+
*
|
|
2340
|
+
* @param size 元素大小
|
|
2341
|
+
* @param padding 圆点间隔
|
|
2342
|
+
* @param isStagger 是否交错
|
|
2343
|
+
* @reutrn 返回贴图单元大小
|
|
2344
|
+
*/
|
|
2345
|
+
function getUnitPatternSize(size, padding, isStagger) {
|
|
2346
|
+
// 如果交错, unitSize 放大两倍
|
|
2347
|
+
var unitSize = size + padding;
|
|
2348
|
+
return isStagger ? unitSize * 2 : unitSize;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* 计算有交错情况的元素坐标
|
|
2353
|
+
*
|
|
2354
|
+
* @param unitSize 贴图单元大小
|
|
2355
|
+
* @param isStagger 是否交错
|
|
2356
|
+
* @reutrn 元素中心坐标 x,y 数组集合
|
|
2357
|
+
*/
|
|
2358
|
+
function getSymbolsPosition(unitSize, isStagger) {
|
|
2359
|
+
// 如果交错, 交错绘制 dot
|
|
2360
|
+
var symbolsPos = isStagger ? [[unitSize * (1 / 4), unitSize * (1 / 4)], [unitSize * (3 / 4), unitSize * (3 / 4)]] : [[unitSize * (1 / 2), unitSize * (1 / 2)]];
|
|
2361
|
+
return symbolsPos;
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
var defaultDotPatternCfg = {
|
|
2365
|
+
size: 6,
|
|
2366
|
+
padding: 2,
|
|
2367
|
+
backgroundColor: 'transparent',
|
|
2368
|
+
opacity: 1,
|
|
2369
|
+
fill: '#fff',
|
|
2370
|
+
fillOpacity: 1,
|
|
2371
|
+
stroke: 'transparent',
|
|
2372
|
+
strokeOpacity: 1,
|
|
2373
|
+
lineWidth: 0,
|
|
2374
|
+
isStagger: true
|
|
2375
|
+
};
|
|
2376
|
+
function dots(cfg) {
|
|
2377
|
+
var dotCfg = _objectSpread(_objectSpread({}, defaultDotPatternCfg), cfg);
|
|
2378
|
+
var size = dotCfg.size,
|
|
2379
|
+
padding = dotCfg.padding,
|
|
2380
|
+
isStagger = dotCfg.isStagger,
|
|
2381
|
+
backgroundColor = dotCfg.backgroundColor,
|
|
2382
|
+
backgroundOpacity = dotCfg.backgroundOpacity,
|
|
2383
|
+
opacity = dotCfg.opacity,
|
|
2384
|
+
fill = dotCfg.fill,
|
|
2385
|
+
fillOpacity = dotCfg.fillOpacity,
|
|
2386
|
+
lineWidth = dotCfg.lineWidth,
|
|
2387
|
+
stroke = dotCfg.stroke,
|
|
2388
|
+
strokeOpacity = dotCfg.strokeOpacity;
|
|
2389
|
+
|
|
2390
|
+
// 计算 画布大小,dots的位置
|
|
2391
|
+
var unitSize = getUnitPatternSize(size, padding, isStagger);
|
|
2392
|
+
var dots = getSymbolsPosition(unitSize, isStagger);
|
|
2393
|
+
var background = new Rect({
|
|
2394
|
+
style: {
|
|
2395
|
+
width: unitSize,
|
|
2396
|
+
height: unitSize,
|
|
2397
|
+
fill: backgroundColor,
|
|
2398
|
+
opacity: 1,
|
|
2399
|
+
fillOpacity: backgroundOpacity
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
var _iterator = _createForOfIteratorHelper(dots),
|
|
2403
|
+
_step;
|
|
2404
|
+
try {
|
|
2405
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2406
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
2407
|
+
cx = _step$value[0],
|
|
2408
|
+
cy = _step$value[1];
|
|
2409
|
+
var circle = new Circle({
|
|
2410
|
+
style: {
|
|
2411
|
+
opacity: opacity,
|
|
2412
|
+
fill: fill,
|
|
2413
|
+
fillOpacity: fillOpacity,
|
|
2414
|
+
cx: cx,
|
|
2415
|
+
cy: cy,
|
|
2416
|
+
r: size / 2,
|
|
2417
|
+
lineWidth: lineWidth,
|
|
2418
|
+
stroke: stroke,
|
|
2419
|
+
strokeOpacity: strokeOpacity
|
|
2420
|
+
}
|
|
2421
|
+
});
|
|
2422
|
+
background.appendChild(circle);
|
|
2423
|
+
}
|
|
2424
|
+
} catch (err) {
|
|
2425
|
+
_iterator.e(err);
|
|
2426
|
+
} finally {
|
|
2427
|
+
_iterator.f();
|
|
2428
|
+
}
|
|
2429
|
+
return background;
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
/**
|
|
2433
|
+
* linePattern 的 默认配置
|
|
2434
|
+
*/
|
|
2435
|
+
var defaultLinePatternCfg = {
|
|
2436
|
+
spacing: 5,
|
|
2437
|
+
opacity: 1,
|
|
2438
|
+
backgroundColor: 'transparent',
|
|
2439
|
+
backgroundOpacity: 1,
|
|
2440
|
+
strokeOpacity: 1,
|
|
2441
|
+
stroke: '#fff',
|
|
2442
|
+
lineWidth: 2
|
|
2443
|
+
};
|
|
2444
|
+
|
|
2445
|
+
/**
|
|
2446
|
+
* 创建 linePattern
|
|
2447
|
+
*/
|
|
2448
|
+
function lines(cfg) {
|
|
2449
|
+
var lineCfg = _objectSpread(_objectSpread({}, defaultLinePatternCfg), cfg);
|
|
2450
|
+
var spacing = lineCfg.spacing,
|
|
2451
|
+
lineWidth = lineCfg.lineWidth,
|
|
2452
|
+
backgroundColor = lineCfg.backgroundColor,
|
|
2453
|
+
backgroundOpacity = lineCfg.backgroundOpacity,
|
|
2454
|
+
opacity = lineCfg.opacity,
|
|
2455
|
+
stroke = lineCfg.stroke,
|
|
2456
|
+
strokeOpacity = lineCfg.strokeOpacity;
|
|
2457
|
+
|
|
2458
|
+
// 计算 pattern 画布的大小, path 所需的 d
|
|
2459
|
+
var width = spacing + lineWidth || 1;
|
|
2460
|
+
var height = spacing + lineWidth || 1;
|
|
2461
|
+
var d = "\n M 0 0 L ".concat(width, " 0\n M 0 ").concat(height, " L ").concat(width, " ").concat(height, "\n ");
|
|
2462
|
+
var background = new Rect({
|
|
2463
|
+
style: {
|
|
2464
|
+
width: width,
|
|
2465
|
+
height: height,
|
|
2466
|
+
fill: backgroundColor,
|
|
2467
|
+
opacity: 1,
|
|
2468
|
+
fillOpacity: backgroundOpacity
|
|
2469
|
+
}
|
|
2470
|
+
});
|
|
2471
|
+
var path = new Path({
|
|
2472
|
+
style: {
|
|
2473
|
+
d: d,
|
|
2474
|
+
opacity: opacity,
|
|
2475
|
+
stroke: stroke,
|
|
2476
|
+
strokeOpacity: strokeOpacity,
|
|
2477
|
+
fillOpacity: 1,
|
|
2478
|
+
lineWidth: lineWidth
|
|
2479
|
+
}
|
|
2480
|
+
});
|
|
2481
|
+
background.appendChild(path);
|
|
2482
|
+
return background;
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
/**
|
|
2486
|
+
* squarePattern 的 默认配置
|
|
2487
|
+
*/
|
|
2488
|
+
var defaultSquarePatternCfg = {
|
|
2489
|
+
size: 6,
|
|
2490
|
+
padding: 1,
|
|
2491
|
+
isStagger: true,
|
|
2492
|
+
backgroundColor: 'transparent',
|
|
2493
|
+
opacity: 1,
|
|
2494
|
+
fill: '#fff',
|
|
2495
|
+
fillOpacity: 1,
|
|
2496
|
+
stroke: 'transparent',
|
|
2497
|
+
lineWidth: 0
|
|
2498
|
+
};
|
|
2499
|
+
|
|
2500
|
+
/**
|
|
2501
|
+
* 创建 squarePattern
|
|
2502
|
+
*/
|
|
2503
|
+
function squares(cfg) {
|
|
2504
|
+
var squareCfg = _objectSpread(_objectSpread({}, defaultSquarePatternCfg), cfg);
|
|
2505
|
+
var size = squareCfg.size,
|
|
2506
|
+
padding = squareCfg.padding,
|
|
2507
|
+
isStagger = squareCfg.isStagger,
|
|
2508
|
+
backgroundColor = squareCfg.backgroundColor,
|
|
2509
|
+
backgroundOpacity = squareCfg.backgroundOpacity,
|
|
2510
|
+
opacity = squareCfg.opacity,
|
|
2511
|
+
fill = squareCfg.fill,
|
|
2512
|
+
fillOpacity = squareCfg.fillOpacity,
|
|
2513
|
+
stroke = squareCfg.stroke,
|
|
2514
|
+
strokeOpacity = squareCfg.strokeOpacity,
|
|
2515
|
+
lineWidth = squareCfg.lineWidth;
|
|
2516
|
+
|
|
2517
|
+
// 计算 画布大小,squares的位置
|
|
2518
|
+
var unitSize = getUnitPatternSize(size, padding, isStagger);
|
|
2519
|
+
var squares = getSymbolsPosition(unitSize, isStagger); // 计算方法与 dots 一样
|
|
2520
|
+
|
|
2521
|
+
var background = new Rect({
|
|
2522
|
+
style: {
|
|
2523
|
+
width: unitSize,
|
|
2524
|
+
height: unitSize,
|
|
2525
|
+
fill: backgroundColor,
|
|
2526
|
+
opacity: 1,
|
|
2527
|
+
fillOpacity: backgroundOpacity
|
|
2528
|
+
}
|
|
2529
|
+
});
|
|
2530
|
+
var _iterator = _createForOfIteratorHelper(squares),
|
|
2531
|
+
_step;
|
|
2532
|
+
try {
|
|
2533
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
2534
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
2535
|
+
x = _step$value[0],
|
|
2536
|
+
y = _step$value[1];
|
|
2537
|
+
var square = new Rect({
|
|
2538
|
+
style: {
|
|
2539
|
+
opacity: opacity,
|
|
2540
|
+
fill: fill,
|
|
2541
|
+
fillOpacity: fillOpacity,
|
|
2542
|
+
x: x - size / 2,
|
|
2543
|
+
y: y - size / 2,
|
|
2544
|
+
width: size,
|
|
2545
|
+
height: size,
|
|
2546
|
+
lineWidth: lineWidth,
|
|
2547
|
+
stroke: stroke,
|
|
2548
|
+
strokeOpacity: strokeOpacity
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2551
|
+
background.appendChild(square);
|
|
2552
|
+
}
|
|
2553
|
+
} catch (err) {
|
|
2554
|
+
_iterator.e(err);
|
|
2555
|
+
} finally {
|
|
2556
|
+
_iterator.f();
|
|
2557
|
+
}
|
|
2558
|
+
return background;
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
var _excluded = ["body", "startHead", "endHead", "startHeadOffset", "endHeadOffset"],
|
|
2562
|
+
_excluded2 = ["body", "startHead", "endHead", "startHeadOffset", "endHeadOffset"],
|
|
2563
|
+
_excluded3 = ["body", "startHead", "endHead", "startHeadOffset", "endHeadOffset"];
|
|
2564
|
+
/**
|
|
2565
|
+
* support 3 types of arrow line:
|
|
2566
|
+
* 1. Line
|
|
2567
|
+
* 2. Polyline
|
|
2568
|
+
* 3. Path
|
|
2569
|
+
*
|
|
2570
|
+
* support 2 types of arrow head:
|
|
2571
|
+
* 1. default(Path)
|
|
2572
|
+
* 2. custom
|
|
2573
|
+
*/
|
|
2574
|
+
var Arrow = /*#__PURE__*/function (_CustomElement) {
|
|
2575
|
+
function Arrow(config) {
|
|
2576
|
+
var _this;
|
|
2577
|
+
_classCallCheck(this, Arrow);
|
|
2578
|
+
_this = _callSuper(this, Arrow, [_objectSpread(_objectSpread({}, config), {}, {
|
|
2579
|
+
type: Arrow.tag
|
|
2580
|
+
})]);
|
|
2581
|
+
var _this$attributes = _this.attributes,
|
|
2582
|
+
body = _this$attributes.body,
|
|
2583
|
+
startHead = _this$attributes.startHead,
|
|
2584
|
+
endHead = _this$attributes.endHead;
|
|
2585
|
+
_this$attributes.startHeadOffset;
|
|
2586
|
+
_this$attributes.endHeadOffset;
|
|
2587
|
+
var rest = _objectWithoutProperties(_this$attributes, _excluded);
|
|
2588
|
+
if (!body) {
|
|
2589
|
+
throw new Error("Arrow's body is required");
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
// append arrow body
|
|
2593
|
+
_this.body = body;
|
|
2594
|
+
_this.appendChild(_this.body);
|
|
2595
|
+
_this.handleBodyAttributeChanged(_this.body);
|
|
2596
|
+
if (startHead) {
|
|
2597
|
+
_this.appendArrowHead(_this.getArrowHeadType(startHead), true);
|
|
2598
|
+
}
|
|
2599
|
+
if (endHead) {
|
|
2600
|
+
_this.appendArrowHead(_this.getArrowHeadType(endHead), false);
|
|
2601
|
+
}
|
|
2602
|
+
_this.applyArrowStyle(rest, [_this.body, _this.startHead, _this.endHead]);
|
|
2603
|
+
return _this;
|
|
2604
|
+
}
|
|
2605
|
+
_inherits(Arrow, _CustomElement);
|
|
2606
|
+
return _createClass(Arrow, [{
|
|
2607
|
+
key: "handleBodyAttributeChanged",
|
|
2608
|
+
value: function handleBodyAttributeChanged(body) {
|
|
2609
|
+
var _this2 = this;
|
|
2610
|
+
body.addEventListener(ElementEvent.ATTR_MODIFIED, function (e) {
|
|
2611
|
+
var attrName = e.attrName;
|
|
2612
|
+
if (attrName === 'x1' || attrName === 'y1') {
|
|
2613
|
+
if (_this2.startHead) {
|
|
2614
|
+
_this2.transformArrowHead(_this2.startHead, true);
|
|
2615
|
+
}
|
|
2616
|
+
} else if (attrName === 'x2' || attrName === 'y2') {
|
|
2617
|
+
if (_this2.endHead) {
|
|
2618
|
+
_this2.transformArrowHead(_this2.endHead, false);
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
// const { nodeName } = body;
|
|
2622
|
+
// if (nodeName === Shape.LINE) {
|
|
2623
|
+
// body
|
|
2624
|
+
// }
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
}, {
|
|
2628
|
+
key: "getBody",
|
|
2629
|
+
value: function getBody() {
|
|
2630
|
+
return this.body;
|
|
2631
|
+
}
|
|
2632
|
+
}, {
|
|
2633
|
+
key: "getStartHead",
|
|
2634
|
+
value: function getStartHead() {
|
|
2635
|
+
return this.startHead;
|
|
2636
|
+
}
|
|
2637
|
+
}, {
|
|
2638
|
+
key: "getEndHead",
|
|
2639
|
+
value: function getEndHead() {
|
|
2640
|
+
return this.endHead;
|
|
2641
|
+
}
|
|
2642
|
+
}, {
|
|
2643
|
+
key: "attributeChangedCallback",
|
|
2644
|
+
value: function attributeChangedCallback(name, oldValue, newValue) {
|
|
2645
|
+
if (name === 'opacity' || name === 'strokeOpacity' || name === 'stroke' || name === 'lineWidth' || name === 'increasedLineWidthForHitTesting') {
|
|
2646
|
+
this.applyArrowStyle(_defineProperty({}, name, newValue), [this.body, this.startHead, this.endHead]);
|
|
2647
|
+
} else if (name === 'startHead' || name === 'endHead') {
|
|
2648
|
+
var isStart = name === 'startHead';
|
|
2649
|
+
// delete existed arrow head first
|
|
2650
|
+
this.destroyArrowHead(isStart);
|
|
2651
|
+
if (newValue) {
|
|
2652
|
+
var _this$attributes2 = this.attributes;
|
|
2653
|
+
_this$attributes2.body;
|
|
2654
|
+
_this$attributes2.startHead;
|
|
2655
|
+
_this$attributes2.endHead;
|
|
2656
|
+
_this$attributes2.startHeadOffset;
|
|
2657
|
+
_this$attributes2.endHeadOffset;
|
|
2658
|
+
var rest = _objectWithoutProperties(_this$attributes2, _excluded2);
|
|
2659
|
+
// append new arrow head
|
|
2660
|
+
|
|
2661
|
+
this.appendArrowHead(this.getArrowHeadType(newValue), isStart);
|
|
2662
|
+
this.applyArrowStyle(rest, [isStart ? this.startHead : this.endHead]);
|
|
2663
|
+
}
|
|
2664
|
+
} else if (name === 'body') {
|
|
2665
|
+
var _this$attributes3 = this.attributes;
|
|
2666
|
+
_this$attributes3.body;
|
|
2667
|
+
_this$attributes3.startHead;
|
|
2668
|
+
_this$attributes3.endHead;
|
|
2669
|
+
_this$attributes3.startHeadOffset;
|
|
2670
|
+
_this$attributes3.endHeadOffset;
|
|
2671
|
+
var _rest = _objectWithoutProperties(_this$attributes3, _excluded3);
|
|
2672
|
+
this.body.destroy();
|
|
2673
|
+
// @ts-ignore
|
|
2674
|
+
this.body = newValue;
|
|
2675
|
+
this.appendChild(this.body);
|
|
2676
|
+
this.applyArrowStyle(_rest, [this.body]);
|
|
2677
|
+
} else if (name === 'startHeadOffset') {
|
|
2678
|
+
this.moveArrowHeadAlongTangent(newValue, true);
|
|
2679
|
+
} else if (name === 'endHeadOffset') {
|
|
2680
|
+
this.moveArrowHeadAlongTangent(newValue, false);
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
}, {
|
|
2684
|
+
key: "getArrowHeadType",
|
|
2685
|
+
value: function getArrowHeadType(head) {
|
|
2686
|
+
if (typeof head === 'boolean') {
|
|
2687
|
+
return 'default';
|
|
2688
|
+
}
|
|
2689
|
+
return 'custom';
|
|
2690
|
+
}
|
|
2691
|
+
}, {
|
|
2692
|
+
key: "appendArrowHead",
|
|
2693
|
+
value: function appendArrowHead(type, isStart) {
|
|
2694
|
+
var head;
|
|
2695
|
+
if (type === 'default') {
|
|
2696
|
+
head = this.createDefaultArrowHead();
|
|
2697
|
+
} else {
|
|
2698
|
+
// @ts-ignore
|
|
2699
|
+
head = isStart ? this.attributes.startHead : this.attributes.endHead;
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
// set position & rotation
|
|
2703
|
+
this.transformArrowHead(head, isStart);
|
|
2704
|
+
|
|
2705
|
+
// heads should display on top of body
|
|
2706
|
+
head.setAttribute('zIndex', 1);
|
|
2707
|
+
if (isStart) {
|
|
2708
|
+
this.startHead = head;
|
|
2709
|
+
} else {
|
|
2710
|
+
this.endHead = head;
|
|
2711
|
+
}
|
|
2712
|
+
this.appendChild(head);
|
|
2713
|
+
var offset = isStart ? this.attributes.startHeadOffset : this.attributes.endHeadOffset;
|
|
2714
|
+
if (offset) {
|
|
2715
|
+
this.moveArrowHeadAlongTangent(offset, isStart);
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
/**
|
|
2720
|
+
* transform arrow head according to arrow line
|
|
2721
|
+
*/
|
|
2722
|
+
}, {
|
|
2723
|
+
key: "transformArrowHead",
|
|
2724
|
+
value: function transformArrowHead(head, isStart) {
|
|
2725
|
+
var position = vec3.create();
|
|
2726
|
+
var rad = 0;
|
|
2727
|
+
var x1 = 0;
|
|
2728
|
+
var x2 = 0;
|
|
2729
|
+
var y1 = 0;
|
|
2730
|
+
var y2 = 0;
|
|
2731
|
+
var bodyType = this.body && this.body.nodeName;
|
|
2732
|
+
if (bodyType === Shape.LINE) {
|
|
2733
|
+
var _attributes = this.body.attributes,
|
|
2734
|
+
_x1 = _attributes.x1,
|
|
2735
|
+
_x2 = _attributes.x2,
|
|
2736
|
+
_y1 = _attributes.y1,
|
|
2737
|
+
_y2 = _attributes.y2;
|
|
2738
|
+
x1 = isStart ? _x2 : _x1;
|
|
2739
|
+
x2 = isStart ? _x1 : _x2;
|
|
2740
|
+
y1 = isStart ? _y2 : _y1;
|
|
2741
|
+
y2 = isStart ? _y1 : _y2;
|
|
2742
|
+
} else if (bodyType === Shape.POLYLINE) {
|
|
2743
|
+
var points = this.body.attributes.points;
|
|
2744
|
+
var length = points.length;
|
|
2745
|
+
x1 = isStart ? points[1][0] : points[length - 2][0];
|
|
2746
|
+
y1 = isStart ? points[1][1] : points[length - 2][1];
|
|
2747
|
+
x2 = isStart ? points[0][0] : points[length - 1][0];
|
|
2748
|
+
y2 = isStart ? points[0][1] : points[length - 1][1];
|
|
2749
|
+
} else if (bodyType === Shape.PATH) {
|
|
2750
|
+
var _this$getTangent = this.getTangent(this.body, isStart),
|
|
2751
|
+
_this$getTangent2 = _slicedToArray(_this$getTangent, 2),
|
|
2752
|
+
p1 = _this$getTangent2[0],
|
|
2753
|
+
p2 = _this$getTangent2[1];
|
|
2754
|
+
x1 = p1[0];
|
|
2755
|
+
y1 = p1[1];
|
|
2756
|
+
x2 = p2[0];
|
|
2757
|
+
y2 = p2[1];
|
|
2758
|
+
}
|
|
2759
|
+
var x = x1 - x2;
|
|
2760
|
+
var y = y1 - y2;
|
|
2761
|
+
rad = Math.atan2(y, x);
|
|
2762
|
+
position = vec3.fromValues(x2, y2, 0);
|
|
2763
|
+
if (isStart) {
|
|
2764
|
+
this.startHeadPosition = position;
|
|
2765
|
+
this.startHeadRad = rad;
|
|
2766
|
+
} else {
|
|
2767
|
+
this.endHeadPosition = position;
|
|
2768
|
+
this.endHeadRad = rad;
|
|
2769
|
+
}
|
|
2770
|
+
head.setLocalPosition(position);
|
|
2771
|
+
head.setLocalEulerAngles(rad * 180 / Math.PI + head.getLocalEulerAngles());
|
|
2772
|
+
}
|
|
2773
|
+
}, {
|
|
2774
|
+
key: "moveArrowHeadAlongTangent",
|
|
2775
|
+
value: function moveArrowHeadAlongTangent(offset, isStart) {
|
|
2776
|
+
var head = isStart ? this.startHead : this.endHead;
|
|
2777
|
+
if (head) {
|
|
2778
|
+
head.setLocalPosition(vec3.sub(vec3.create(), isStart ? this.startHeadPosition : this.endHeadPosition, vec3.fromValues(Math.cos(isStart ? this.startHeadRad : this.endHeadRad) * offset, Math.sin(isStart ? this.startHeadRad : this.endHeadRad) * offset, 0)));
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
// cut body
|
|
2782
|
+
if (this.body) ;
|
|
2783
|
+
}
|
|
2784
|
+
}, {
|
|
2785
|
+
key: "destroyArrowHead",
|
|
2786
|
+
value: function destroyArrowHead(isStart) {
|
|
2787
|
+
if (isStart && this.startHead) {
|
|
2788
|
+
this.startHead.destroy();
|
|
2789
|
+
this.startHead = undefined;
|
|
2790
|
+
}
|
|
2791
|
+
if (!isStart && this.endHead) {
|
|
2792
|
+
this.endHead.destroy();
|
|
2793
|
+
this.endHead = undefined;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
}, {
|
|
2797
|
+
key: "getTangent",
|
|
2798
|
+
value: function getTangent(path, isStart) {
|
|
2799
|
+
return isStart ? path.getStartTangent() : path.getEndTangent();
|
|
2800
|
+
}
|
|
2801
|
+
}, {
|
|
2802
|
+
key: "createDefaultArrowHead",
|
|
2803
|
+
value: function createDefaultArrowHead() {
|
|
2804
|
+
var _this$attributes4 = this.attributes,
|
|
2805
|
+
stroke = _this$attributes4.stroke,
|
|
2806
|
+
lineWidth = _this$attributes4.lineWidth;
|
|
2807
|
+
var sin = Math.sin,
|
|
2808
|
+
cos = Math.cos,
|
|
2809
|
+
PI = Math.PI;
|
|
2810
|
+
var width = 10 * cos(PI / 6);
|
|
2811
|
+
return new Path({
|
|
2812
|
+
style: {
|
|
2813
|
+
// draw an angle '<'
|
|
2814
|
+
d: "M".concat(width / 2, ",").concat(10 * sin(PI / 6), " L-").concat(width / 2, ",0 L").concat(width / 2, ",-").concat(10 * sin(PI / 6)),
|
|
2815
|
+
stroke: stroke,
|
|
2816
|
+
lineWidth: lineWidth,
|
|
2817
|
+
transformOrigin: 'center'
|
|
2818
|
+
}
|
|
2819
|
+
});
|
|
2820
|
+
}
|
|
2821
|
+
}, {
|
|
2822
|
+
key: "applyArrowStyle",
|
|
2823
|
+
value: function applyArrowStyle(attributes, objects) {
|
|
2824
|
+
var opacity = attributes.opacity,
|
|
2825
|
+
stroke = attributes.stroke,
|
|
2826
|
+
strokeOpacity = attributes.strokeOpacity,
|
|
2827
|
+
lineWidth = attributes.lineWidth,
|
|
2828
|
+
increasedLineWidthForHitTesting = attributes.increasedLineWidthForHitTesting;
|
|
2829
|
+
objects.forEach(function (shape) {
|
|
2830
|
+
if (shape) {
|
|
2831
|
+
if (!isNil(opacity)) {
|
|
2832
|
+
shape.style.opacity = opacity;
|
|
2833
|
+
}
|
|
2834
|
+
if (!isNil(stroke)) {
|
|
2835
|
+
shape.style.stroke = stroke;
|
|
2836
|
+
}
|
|
2837
|
+
if (!isNil(strokeOpacity)) {
|
|
2838
|
+
shape.style.strokeOpacity = strokeOpacity;
|
|
2839
|
+
}
|
|
2840
|
+
if (!isNil(lineWidth)) {
|
|
2841
|
+
shape.style.lineWidth = lineWidth;
|
|
2842
|
+
}
|
|
2843
|
+
if (!isNil(increasedLineWidthForHitTesting)) {
|
|
2844
|
+
shape.style.increasedLineWidthForHitTesting = increasedLineWidthForHitTesting;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
}]);
|
|
2850
|
+
}(CustomElement);
|
|
2851
|
+
Arrow.tag = 'arrow';
|
|
2852
|
+
Arrow.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(CustomElement.PARSED_STYLE_LIST), ['body', 'startHead', 'endHead', 'startHeadOffset', 'endHeadOffset', 'stroke', 'lineWidth', 'opacity', 'strokeOpacity']));
|
|
2853
|
+
|
|
2854
|
+
var PI = Math.PI;
|
|
2855
|
+
var PI2 = PI * 2;
|
|
2856
|
+
var mathSin = Math.sin;
|
|
2857
|
+
var mathCos = Math.cos;
|
|
2858
|
+
var mathACos = Math.acos;
|
|
2859
|
+
var mathATan2 = Math.atan2;
|
|
2860
|
+
// const mathAbs = Math.abs;
|
|
2861
|
+
var mathSqrt = Math.sqrt;
|
|
2862
|
+
var mathMax = Math.max;
|
|
2863
|
+
var mathMin = Math.min;
|
|
2864
|
+
var e = 1e-4;
|
|
2865
|
+
|
|
2866
|
+
// 注册 css 属性
|
|
2867
|
+
var SECTOR_CSS_PROPERTY = [{
|
|
2868
|
+
name: 'sr',
|
|
2869
|
+
inherits: false,
|
|
2870
|
+
interpolable: true,
|
|
2871
|
+
syntax: PropertySyntax.LENGTH_PERCENTAGE
|
|
2872
|
+
}, {
|
|
2873
|
+
name: 'sr0',
|
|
2874
|
+
inherits: false,
|
|
2875
|
+
interpolable: true,
|
|
2876
|
+
syntax: PropertySyntax.LENGTH_PERCENTAGE
|
|
2877
|
+
}, {
|
|
2878
|
+
name: 'startAngle',
|
|
2879
|
+
inherits: false,
|
|
2880
|
+
interpolable: true,
|
|
2881
|
+
syntax: PropertySyntax.ANGLE
|
|
2882
|
+
}, {
|
|
2883
|
+
name: 'endAngle',
|
|
2884
|
+
inherits: false,
|
|
2885
|
+
interpolable: true,
|
|
2886
|
+
syntax: PropertySyntax.ANGLE
|
|
2887
|
+
}];
|
|
2888
|
+
SECTOR_CSS_PROPERTY.forEach(function (property) {
|
|
2889
|
+
CSS.registerProperty(property);
|
|
2890
|
+
});
|
|
2891
|
+
var polarToCartesian = function polarToCartesian(centerX, centerY, radius, angleInRadian) {
|
|
2892
|
+
return {
|
|
2893
|
+
x: centerX + radius * Math.cos(angleInRadian),
|
|
2894
|
+
y: centerY + radius * Math.sin(angleInRadian)
|
|
2895
|
+
};
|
|
2896
|
+
};
|
|
2897
|
+
function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
|
|
2898
|
+
var dx10 = x1 - x0;
|
|
2899
|
+
var dy10 = y1 - y0;
|
|
2900
|
+
var dx32 = x3 - x2;
|
|
2901
|
+
var dy32 = y3 - y2;
|
|
2902
|
+
var t = dy32 * dx10 - dx32 * dy10;
|
|
2903
|
+
if (t * t < e) {
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
t = (dx32 * (y0 - y2) - dy32 * (x0 - x2)) / t;
|
|
2907
|
+
return [x0 + t * dx10, y0 + t * dy10];
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
// Compute perpendicular offset line of length rc.
|
|
2911
|
+
function computeCornerTangents(x0, y0, x1, y1, radius, cr, clockwise) {
|
|
2912
|
+
var x01 = x0 - x1;
|
|
2913
|
+
var y01 = y0 - y1;
|
|
2914
|
+
var lo = (clockwise ? cr : -cr) / mathSqrt(x01 * x01 + y01 * y01);
|
|
2915
|
+
var ox = lo * y01;
|
|
2916
|
+
var oy = -lo * x01;
|
|
2917
|
+
var x11 = x0 + ox;
|
|
2918
|
+
var y11 = y0 + oy;
|
|
2919
|
+
var x10 = x1 + ox;
|
|
2920
|
+
var y10 = y1 + oy;
|
|
2921
|
+
var x00 = (x11 + x10) / 2;
|
|
2922
|
+
var y00 = (y11 + y10) / 2;
|
|
2923
|
+
var dx = x10 - x11;
|
|
2924
|
+
var dy = y10 - y11;
|
|
2925
|
+
var d2 = dx * dx + dy * dy;
|
|
2926
|
+
var r = radius - cr;
|
|
2927
|
+
var s = x11 * y10 - x10 * y11;
|
|
2928
|
+
var d = (dy < 0 ? -1 : 1) * mathSqrt(mathMax(0, r * r * d2 - s * s));
|
|
2929
|
+
var cx0 = (s * dy - dx * d) / d2;
|
|
2930
|
+
var cy0 = (-s * dx - dy * d) / d2;
|
|
2931
|
+
var cx1 = (s * dy + dx * d) / d2;
|
|
2932
|
+
var cy1 = (-s * dx + dy * d) / d2;
|
|
2933
|
+
var dx0 = cx0 - x00;
|
|
2934
|
+
var dy0 = cy0 - y00;
|
|
2935
|
+
var dx1 = cx1 - x00;
|
|
2936
|
+
var dy1 = cy1 - y00;
|
|
2937
|
+
|
|
2938
|
+
// Pick the closer of the two intersection points
|
|
2939
|
+
// TODO: Is there a faster way to determine which intersection to use?
|
|
2940
|
+
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) {
|
|
2941
|
+
cx0 = cx1;
|
|
2942
|
+
cy0 = cy1;
|
|
2943
|
+
}
|
|
2944
|
+
return {
|
|
2945
|
+
cx: cx0,
|
|
2946
|
+
cy: cy0,
|
|
2947
|
+
x0: -ox,
|
|
2948
|
+
y0: -oy,
|
|
2949
|
+
x1: cx0 * (radius / r - 1),
|
|
2950
|
+
y1: cy0 * (radius / r - 1)
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
function computeArcSweep(startAngle, endAngle) {
|
|
2954
|
+
endAngle = endAngle < 0 && startAngle >= 0 ? endAngle + PI2 : endAngle;
|
|
2955
|
+
return endAngle - startAngle <= PI ? 0 : 1;
|
|
2956
|
+
}
|
|
2957
|
+
var Sector = /*#__PURE__*/function (_Path) {
|
|
2958
|
+
// parsedStyle: any;
|
|
2959
|
+
function Sector(config) {
|
|
2960
|
+
var _this;
|
|
2961
|
+
_classCallCheck(this, Sector);
|
|
2962
|
+
_this = _callSuper(this, Sector, [config]);
|
|
2963
|
+
_this.updatePath();
|
|
2964
|
+
return _this;
|
|
2965
|
+
}
|
|
2966
|
+
_inherits(Sector, _Path);
|
|
2967
|
+
return _createClass(Sector, [{
|
|
2968
|
+
key: "setAttribute",
|
|
2969
|
+
value: function setAttribute(name, value, force) {
|
|
2970
|
+
_superPropGet(Sector, "setAttribute", this, 3)([name, value, force]);
|
|
2971
|
+
if (['startAngle', 'endAngle', 'sr', 'sr0', 'radius'].indexOf(name) > -1) {
|
|
2972
|
+
this.updatePath();
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
}, {
|
|
2976
|
+
key: "updatePath",
|
|
2977
|
+
value: function updatePath() {
|
|
2978
|
+
// @ts-ignore
|
|
2979
|
+
var _this$parsedStyle = this.parsedStyle,
|
|
2980
|
+
x = _this$parsedStyle.x,
|
|
2981
|
+
y = _this$parsedStyle.y,
|
|
2982
|
+
startAngle = _this$parsedStyle.startAngle,
|
|
2983
|
+
endAngle = _this$parsedStyle.endAngle,
|
|
2984
|
+
sr = _this$parsedStyle.sr,
|
|
2985
|
+
sr0 = _this$parsedStyle.sr0,
|
|
2986
|
+
radius = _this$parsedStyle.radius;
|
|
2987
|
+
var path = this.createPath(x, y, startAngle ? deg2rad(startAngle) : 0, endAngle ? deg2rad(endAngle) : Math.PI * 2, sr || 0, sr0 || 0, radius || [0, 0, 0, 0]);
|
|
2988
|
+
_superPropGet(Sector, "setAttribute", this, 3)(['d', path]);
|
|
2989
|
+
}
|
|
2990
|
+
}, {
|
|
2991
|
+
key: "createPath",
|
|
2992
|
+
value: function createPath(x, y, startAngle, endAngle, r, r0, borderRadius) {
|
|
2993
|
+
if (r <= 0) {
|
|
2994
|
+
return;
|
|
2995
|
+
}
|
|
2996
|
+
var start = polarToCartesian(x, y, r, startAngle);
|
|
2997
|
+
var end = polarToCartesian(x, y, r, endAngle);
|
|
2998
|
+
var innerStart = polarToCartesian(x, y, r0, startAngle);
|
|
2999
|
+
var innerEnd = polarToCartesian(x, y, r0, endAngle);
|
|
3000
|
+
|
|
3001
|
+
// 整圆
|
|
3002
|
+
if (isNumberEqual(endAngle - startAngle, Math.PI * 2)) {
|
|
3003
|
+
// 整个圆是分割成两个圆
|
|
3004
|
+
var middlePoint = polarToCartesian(x, y, r, startAngle + Math.PI);
|
|
3005
|
+
var innerMiddlePoint = polarToCartesian(x, y, r0, startAngle + Math.PI);
|
|
3006
|
+
var circlePathCommands = [['M', start.x, start.y], ['A', r, r, 0, 1, 1, middlePoint.x, middlePoint.y], ['A', r, r, 0, 1, 1, end.x, end.y], ['M', innerStart.x, innerStart.y]];
|
|
3007
|
+
if (r0) {
|
|
3008
|
+
circlePathCommands.push(['A', r0, r0, 0, 1, 0, innerMiddlePoint.x, innerMiddlePoint.y]);
|
|
3009
|
+
circlePathCommands.push(['A', r0, r0, 0, 1, 0, innerEnd.x, innerEnd.y]);
|
|
3010
|
+
}
|
|
3011
|
+
circlePathCommands.push(['M', start.x, start.y]);
|
|
3012
|
+
circlePathCommands.push(['Z']);
|
|
3013
|
+
return circlePathCommands;
|
|
3014
|
+
}
|
|
3015
|
+
var angle = endAngle - startAngle;
|
|
3016
|
+
var xrs = r * mathCos(startAngle);
|
|
3017
|
+
var yrs = r * mathSin(startAngle);
|
|
3018
|
+
var xire = r0 * mathCos(endAngle);
|
|
3019
|
+
var yire = r0 * mathSin(endAngle);
|
|
3020
|
+
var xre = r * mathCos(endAngle);
|
|
3021
|
+
var yre = r * mathSin(endAngle);
|
|
3022
|
+
var xirs = r0 * mathCos(startAngle);
|
|
3023
|
+
var yirs = r0 * mathSin(startAngle);
|
|
3024
|
+
|
|
3025
|
+
// 顺时针反向,同 radius
|
|
3026
|
+
var _borderRadius = _slicedToArray(borderRadius, 4),
|
|
3027
|
+
outStartRadius = _borderRadius[0],
|
|
3028
|
+
outEndRadius = _borderRadius[1],
|
|
3029
|
+
innerEndRadius = _borderRadius[2],
|
|
3030
|
+
innerStartRadius = _borderRadius[3];
|
|
3031
|
+
var halfRadius = (r - r0) / 2;
|
|
3032
|
+
var outStartBorderRadius = mathMin(halfRadius, outStartRadius);
|
|
3033
|
+
var outEndBorderRadius = mathMin(halfRadius, outEndRadius);
|
|
3034
|
+
var innerEndBorderRadius = mathMin(halfRadius, innerEndRadius);
|
|
3035
|
+
var innerStartBorderRadius = mathMin(halfRadius, innerStartRadius);
|
|
3036
|
+
var outBorderRadiusMax = mathMax(outStartBorderRadius, outEndBorderRadius);
|
|
3037
|
+
var innerBorderRadiusMax = mathMax(innerEndBorderRadius, innerStartBorderRadius);
|
|
3038
|
+
var limitedOutBorderRadiusMax = outBorderRadiusMax;
|
|
3039
|
+
var limitedInnerBorderRadiusMax = innerBorderRadiusMax;
|
|
3040
|
+
|
|
3041
|
+
// draw corner radius
|
|
3042
|
+
if (outBorderRadiusMax > e || innerBorderRadiusMax > e) {
|
|
3043
|
+
// restrict the max value of corner radius
|
|
3044
|
+
if (angle < PI) {
|
|
3045
|
+
var it = intersect(xrs, yrs, xirs, yirs, xre, yre, xire, yire);
|
|
3046
|
+
if (it) {
|
|
3047
|
+
var x0 = xrs - it[0];
|
|
3048
|
+
var y0 = yrs - it[1];
|
|
3049
|
+
var x1 = xre - it[0];
|
|
3050
|
+
var y1 = yre - it[1];
|
|
3051
|
+
var a = 1 / mathSin(mathACos((x0 * x1 + y0 * y1) / (mathSqrt(x0 * x0 + y0 * y0) * mathSqrt(x1 * x1 + y1 * y1))) / 2);
|
|
3052
|
+
var b = mathSqrt(it[0] * it[0] + it[1] * it[1]);
|
|
3053
|
+
limitedOutBorderRadiusMax = mathMin(outBorderRadiusMax, (r - b) / (a + 1));
|
|
3054
|
+
limitedInnerBorderRadiusMax = mathMin(innerBorderRadiusMax, (r0 - b) / (a - 1));
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
var arcSweep = computeArcSweep(startAngle, endAngle);
|
|
3059
|
+
var clockwise = true;
|
|
3060
|
+
var sectorPathCommands = [];
|
|
3061
|
+
if (limitedOutBorderRadiusMax > e) {
|
|
3062
|
+
var crStart = mathMin(outStartRadius, limitedOutBorderRadiusMax);
|
|
3063
|
+
var crEnd = mathMin(outEndRadius, limitedOutBorderRadiusMax);
|
|
3064
|
+
var ct0 = computeCornerTangents(xirs, yirs, xrs, yrs, r, crStart, clockwise);
|
|
3065
|
+
var ct1 = computeCornerTangents(xre, yre, xire, yire, r, crEnd, clockwise);
|
|
3066
|
+
sectorPathCommands.push(['M', x + ct0.cx + ct0.x0, y + ct0.cy + ct0.y0]);
|
|
3067
|
+
|
|
3068
|
+
// Have the corners merged?
|
|
3069
|
+
if (limitedOutBorderRadiusMax < outBorderRadiusMax && crStart === crEnd) {
|
|
3070
|
+
var outStartBorderRadiusStartAngle = mathATan2(ct0.y0, ct0.x0);
|
|
3071
|
+
var outStartBorderRadiusEndAngle = mathATan2(ct1.y0, ct1.x0);
|
|
3072
|
+
sectorPathCommands.push(['A', limitedOutBorderRadiusMax, limitedOutBorderRadiusMax, 0, computeArcSweep(outStartBorderRadiusStartAngle, outStartBorderRadiusEndAngle), 1, x + ct1.cx + ct1.x0, y + ct1.cy + ct1.y0]);
|
|
3073
|
+
} else {
|
|
3074
|
+
// draw the two corners and the ring
|
|
3075
|
+
if (crStart > 0) {
|
|
3076
|
+
var _outStartBorderRadiusStartAngle = mathATan2(ct0.y0, ct0.x0);
|
|
3077
|
+
var _outStartBorderRadiusEndAngle = mathATan2(ct0.y1, ct0.x1);
|
|
3078
|
+
var outStartBorderRadiusEndPoint = polarToCartesian(x, y, r, _outStartBorderRadiusEndAngle);
|
|
3079
|
+
sectorPathCommands.push(['A', crStart, crStart, 0, computeArcSweep(_outStartBorderRadiusStartAngle, _outStartBorderRadiusEndAngle), 1, outStartBorderRadiusEndPoint.x, outStartBorderRadiusEndPoint.y]);
|
|
3080
|
+
}
|
|
3081
|
+
var outRadiusStartAngle = mathATan2(ct0.cy + ct0.y1, ct0.cx + ct0.x1);
|
|
3082
|
+
var outRadiusEndAngle = mathATan2(ct1.cy + ct1.y1, ct1.cx + ct1.x1);
|
|
3083
|
+
var outRadiusEndPoint = polarToCartesian(x, y, r, outRadiusEndAngle);
|
|
3084
|
+
sectorPathCommands.push(['A', r, r, 0, computeArcSweep(outRadiusStartAngle, outRadiusEndAngle), 1, outRadiusEndPoint.x, outRadiusEndPoint.y]);
|
|
3085
|
+
if (crEnd > 0) {
|
|
3086
|
+
var outEndBorderRadiusStartAngle = mathATan2(ct1.y1, ct1.x1);
|
|
3087
|
+
var outEndBorderRadiusEndAngle = mathATan2(ct1.y0, ct1.x0);
|
|
3088
|
+
sectorPathCommands.push(['A', crEnd, crEnd, 0, computeArcSweep(outEndBorderRadiusStartAngle, outEndBorderRadiusEndAngle), 1, x + ct1.cx + ct1.x0, y + ct1.cy + ct1.y0]);
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
} else {
|
|
3092
|
+
sectorPathCommands.push(['M', start.x, start.y]);
|
|
3093
|
+
sectorPathCommands.push(['A', r, r, 0, arcSweep, 1, end.x, end.y]);
|
|
3094
|
+
}
|
|
3095
|
+
|
|
3096
|
+
// no inner ring, is a circular sector
|
|
3097
|
+
if (r0 < e) {
|
|
3098
|
+
sectorPathCommands.push(['L', innerEnd.x, innerEnd.y]);
|
|
3099
|
+
}
|
|
3100
|
+
// the inner ring has corners
|
|
3101
|
+
else if (limitedInnerBorderRadiusMax > e) {
|
|
3102
|
+
var _crStart = mathMin(innerStartRadius, limitedInnerBorderRadiusMax);
|
|
3103
|
+
var _crEnd = mathMin(innerEndRadius, limitedInnerBorderRadiusMax);
|
|
3104
|
+
var _ct = computeCornerTangents(xire, yire, 0, 0, r0 - r, _crEnd, clockwise);
|
|
3105
|
+
var _ct2 = computeCornerTangents(0, 0, xirs, yirs, r0 - r, _crStart, clockwise);
|
|
3106
|
+
sectorPathCommands.push(['L', x + _ct.cx + _ct.x0, y + _ct.cy + _ct.y0]);
|
|
3107
|
+
|
|
3108
|
+
// Have the corners merged?
|
|
3109
|
+
if (limitedInnerBorderRadiusMax < innerBorderRadiusMax && _crStart === _crEnd) {
|
|
3110
|
+
var innerStartBorderRadiusStartAngle = mathATan2(_ct.y0, _ct.x0);
|
|
3111
|
+
var innerStartBorderRadiusEndAngle = mathATan2(_ct2.y0, _ct2.x0);
|
|
3112
|
+
var innerStartBorderRadiusEndPoint = polarToCartesian(x, y, r0, innerStartBorderRadiusEndAngle);
|
|
3113
|
+
sectorPathCommands.push(['A', limitedOutBorderRadiusMax, limitedOutBorderRadiusMax, 0, computeArcSweep(innerStartBorderRadiusStartAngle, innerStartBorderRadiusEndAngle), 1, innerStartBorderRadiusEndPoint.x, innerStartBorderRadiusEndPoint.y]);
|
|
3114
|
+
}
|
|
3115
|
+
// draw the two corners and the ring
|
|
3116
|
+
else {
|
|
3117
|
+
if (_crEnd > 0) {
|
|
3118
|
+
var _innerStartBorderRadiusStartAngle = mathATan2(_ct.y0, _ct.x0);
|
|
3119
|
+
var _innerStartBorderRadiusEndAngle = mathATan2(_ct.y1, _ct.x1);
|
|
3120
|
+
var _innerStartBorderRadiusEndPoint = polarToCartesian(x, y, r0 - r, _innerStartBorderRadiusEndAngle);
|
|
3121
|
+
sectorPathCommands.push(['A', _crEnd, _crEnd, 0, computeArcSweep(_innerStartBorderRadiusStartAngle, _innerStartBorderRadiusEndAngle), 1, _innerStartBorderRadiusEndPoint.x, _innerStartBorderRadiusEndPoint.y]);
|
|
3122
|
+
}
|
|
3123
|
+
var innerRadiusStartAngle = mathATan2(_ct.cy + _ct.y1, _ct.cx + _ct.x1);
|
|
3124
|
+
var innerRadiusEndAngle = mathATan2(_ct2.cy + _ct2.y1, _ct2.cx + _ct2.x1);
|
|
3125
|
+
var innerRadiusEndPoint = polarToCartesian(x, y, r0, innerRadiusEndAngle);
|
|
3126
|
+
sectorPathCommands.push(['A', r0, r0, 0, computeArcSweep(innerRadiusEndAngle, innerRadiusStartAngle), 0, innerRadiusEndPoint.x, innerRadiusEndPoint.y]);
|
|
3127
|
+
sectorPathCommands.push(['L', innerRadiusEndPoint.x, innerRadiusEndPoint.y]);
|
|
3128
|
+
if (_crStart > 0) {
|
|
3129
|
+
var innerEndBorderRadiusStartAngle = mathATan2(_ct2.y1, _ct2.x1);
|
|
3130
|
+
var innerEndBorderRadiusEndAngle = mathATan2(_ct2.y0, _ct2.x0);
|
|
3131
|
+
sectorPathCommands.push(['A', _crStart, _crStart, 0, computeArcSweep(innerEndBorderRadiusStartAngle, innerEndBorderRadiusEndAngle), 1, x + _ct2.cx + _ct2.x0, y + _ct2.cy + _ct2.y0]);
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
// the inner ring is just a circular arc
|
|
3136
|
+
else {
|
|
3137
|
+
sectorPathCommands.push(['L', innerEnd.x, innerEnd.y]);
|
|
3138
|
+
sectorPathCommands.push(['A', r0, r0, 0, arcSweep, 0, innerStart.x, innerStart.y]);
|
|
3139
|
+
}
|
|
3140
|
+
sectorPathCommands.push(['Z']);
|
|
3141
|
+
return sectorPathCommands;
|
|
3142
|
+
}
|
|
3143
|
+
}]);
|
|
3144
|
+
}(Path);
|
|
3145
|
+
Sector.PARSED_STYLE_LIST = new Set([].concat(_toConsumableArray(Path.PARSED_STYLE_LIST), ['x', 'y', 'sr', 'sr0', 'radius', 'startAngle', 'endAngle']));
|
|
3146
|
+
|
|
3147
|
+
export { AdvancedCamera, Animation, AnimationEvent, AnimationTimeline, Arrow, EasingFunctions, ImageExporter, KeyframeEffect, Sector, compareAnimations, defaultDotPatternCfg, defaultLinePatternCfg, defaultSquarePatternCfg, dots, lines, makeTiming, normalizeKeyframes, normalizeTimingInput, numericTimingToObject, squares };
|
|
13
3148
|
//# sourceMappingURL=index.esm.js.map
|