animation.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. /**
  41. * Animate multiple elements with a single done-callback.
  42. *
  43. * @example
  44. * animation
  45. * .createWrap()
  46. * .add(el1, {x: 10, y: 10})
  47. * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400)
  48. * .done(function () { // done })
  49. * .start('cubicOut');
  50. */
  51. var AnimationWrap = /** @class */function () {
  52. function AnimationWrap() {
  53. this._storage = [];
  54. this._elExistsMap = {};
  55. }
  56. /**
  57. * Caution: a el can only be added once, otherwise 'done'
  58. * might not be called. This method checks this (by el.id),
  59. * suppresses adding and returns false when existing el found.
  60. *
  61. * @return Whether adding succeeded.
  62. */
  63. AnimationWrap.prototype.add = function (el, target, duration, delay, easing) {
  64. if (this._elExistsMap[el.id]) {
  65. return false;
  66. }
  67. this._elExistsMap[el.id] = true;
  68. this._storage.push({
  69. el: el,
  70. target: target,
  71. duration: duration,
  72. delay: delay,
  73. easing: easing
  74. });
  75. return true;
  76. };
  77. /**
  78. * Only execute when animation done/aborted.
  79. */
  80. AnimationWrap.prototype.finished = function (callback) {
  81. this._finishedCallback = callback;
  82. return this;
  83. };
  84. /**
  85. * Will stop exist animation firstly.
  86. */
  87. AnimationWrap.prototype.start = function () {
  88. var _this = this;
  89. var count = this._storage.length;
  90. var checkTerminate = function () {
  91. count--;
  92. if (count <= 0) {
  93. // Guard.
  94. _this._storage.length = 0;
  95. _this._elExistsMap = {};
  96. _this._finishedCallback && _this._finishedCallback();
  97. }
  98. };
  99. for (var i = 0, len = this._storage.length; i < len; i++) {
  100. var item = this._storage[i];
  101. item.el.animateTo(item.target, {
  102. duration: item.duration,
  103. delay: item.delay,
  104. easing: item.easing,
  105. setToFinal: true,
  106. done: checkTerminate,
  107. aborted: checkTerminate
  108. });
  109. }
  110. return this;
  111. };
  112. return AnimationWrap;
  113. }();
  114. export function createWrap() {
  115. return new AnimationWrap();
  116. }