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