@visactor/vrender-animate 0.22.4

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 (303) hide show
  1. package/README.md +177 -0
  2. package/cjs/animate-extension.d.ts +15 -0
  3. package/cjs/animate-extension.js +46 -0
  4. package/cjs/animate-extension.js.map +1 -0
  5. package/cjs/animate.d.ts +71 -0
  6. package/cjs/animate.js +210 -0
  7. package/cjs/animate.js.map +1 -0
  8. package/cjs/custom/clip-graphic.d.ts +53 -0
  9. package/cjs/custom/clip-graphic.js +146 -0
  10. package/cjs/custom/clip-graphic.js.map +1 -0
  11. package/cjs/custom/clip.d.ts +13 -0
  12. package/cjs/custom/clip.js +24 -0
  13. package/cjs/custom/clip.js.map +1 -0
  14. package/cjs/custom/common.d.ts +22 -0
  15. package/cjs/custom/common.js +58 -0
  16. package/cjs/custom/common.js.map +1 -0
  17. package/cjs/custom/custom-animate.d.ts +15 -0
  18. package/cjs/custom/custom-animate.js +25 -0
  19. package/cjs/custom/custom-animate.js.map +1 -0
  20. package/cjs/custom/fade.d.ts +13 -0
  21. package/cjs/custom/fade.js +24 -0
  22. package/cjs/custom/fade.js.map +1 -0
  23. package/cjs/custom/group-fade.d.ts +16 -0
  24. package/cjs/custom/group-fade.js +66 -0
  25. package/cjs/custom/group-fade.js.map +1 -0
  26. package/cjs/custom/growAngle.d.ts +37 -0
  27. package/cjs/custom/growAngle.js +140 -0
  28. package/cjs/custom/growAngle.js.map +1 -0
  29. package/cjs/custom/growCenter.d.ts +17 -0
  30. package/cjs/custom/growCenter.js +161 -0
  31. package/cjs/custom/growCenter.js.map +1 -0
  32. package/cjs/custom/growHeight.d.ts +36 -0
  33. package/cjs/custom/growHeight.js +154 -0
  34. package/cjs/custom/growHeight.js.map +1 -0
  35. package/cjs/custom/growPoints.d.ts +52 -0
  36. package/cjs/custom/growPoints.js +227 -0
  37. package/cjs/custom/growPoints.js.map +1 -0
  38. package/cjs/custom/growRadius.d.ts +41 -0
  39. package/cjs/custom/growRadius.js +113 -0
  40. package/cjs/custom/growRadius.js.map +1 -0
  41. package/cjs/custom/growWidth.d.ts +36 -0
  42. package/cjs/custom/growWidth.js +154 -0
  43. package/cjs/custom/growWidth.js.map +1 -0
  44. package/cjs/custom/input-text.d.ts +29 -0
  45. package/cjs/custom/input-text.js +45 -0
  46. package/cjs/custom/input-text.js.map +1 -0
  47. package/cjs/custom/number.d.ts +25 -0
  48. package/cjs/custom/number.js +102 -0
  49. package/cjs/custom/number.js.map +1 -0
  50. package/cjs/custom/register.d.ts +1 -0
  51. package/cjs/custom/register.js +35 -0
  52. package/cjs/custom/register.js.map +1 -0
  53. package/cjs/custom/scale-in.d.ts +13 -0
  54. package/cjs/custom/scale-in.js +57 -0
  55. package/cjs/custom/scale-in.js.map +1 -0
  56. package/cjs/custom/scale.d.ts +20 -0
  57. package/cjs/custom/scale.js +106 -0
  58. package/cjs/custom/scale.js.map +1 -0
  59. package/cjs/custom/sphere.d.ts +20 -0
  60. package/cjs/custom/sphere.js +26 -0
  61. package/cjs/custom/sphere.js.map +1 -0
  62. package/cjs/custom/state.d.ts +13 -0
  63. package/cjs/custom/state.js +25 -0
  64. package/cjs/custom/state.js.map +1 -0
  65. package/cjs/custom/tag-points.d.ts +26 -0
  66. package/cjs/custom/tag-points.js +81 -0
  67. package/cjs/custom/tag-points.js.map +1 -0
  68. package/cjs/custom/update.d.ts +14 -0
  69. package/cjs/custom/update.js +26 -0
  70. package/cjs/custom/update.js.map +1 -0
  71. package/cjs/executor/animate-executor.d.ts +36 -0
  72. package/cjs/executor/animate-executor.js +177 -0
  73. package/cjs/executor/animate-executor.js.map +1 -0
  74. package/cjs/executor/executor.d.ts +69 -0
  75. package/cjs/executor/executor.js +6 -0
  76. package/cjs/executor/executor.js.map +1 -0
  77. package/cjs/index.d.ts +25 -0
  78. package/cjs/index.js +214 -0
  79. package/cjs/index.js.map +1 -0
  80. package/cjs/interpolate/executor.d.ts +66 -0
  81. package/cjs/interpolate/executor.js +6 -0
  82. package/cjs/interpolate/executor.js.map +1 -0
  83. package/cjs/interpolate/number.d.ts +1 -0
  84. package/cjs/interpolate/number.js +10 -0
  85. package/cjs/interpolate/number.js.map +1 -0
  86. package/cjs/interpolate/store.d.ts +32 -0
  87. package/cjs/interpolate/store.js +96 -0
  88. package/cjs/interpolate/store.js.map +1 -0
  89. package/cjs/intreface/animate.d.ts +91 -0
  90. package/cjs/intreface/animate.js +10 -0
  91. package/cjs/intreface/animate.js.map +1 -0
  92. package/cjs/intreface/easing.d.ts +3 -0
  93. package/cjs/intreface/easing.js +6 -0
  94. package/cjs/intreface/easing.js.map +1 -0
  95. package/cjs/intreface/state.d.ts +35 -0
  96. package/cjs/intreface/state.js +6 -0
  97. package/cjs/intreface/state.js.map +1 -0
  98. package/cjs/intreface/ticker.d.ts +37 -0
  99. package/cjs/intreface/ticker.js +10 -0
  100. package/cjs/intreface/ticker.js.map +1 -0
  101. package/cjs/intreface/timeline.d.ts +17 -0
  102. package/cjs/intreface/timeline.js +6 -0
  103. package/cjs/intreface/timeline.js.map +1 -0
  104. package/cjs/intreface/type.d.ts +13 -0
  105. package/cjs/intreface/type.js +15 -0
  106. package/cjs/intreface/type.js.map +1 -0
  107. package/cjs/register.d.ts +1 -0
  108. package/cjs/register.js +19 -0
  109. package/cjs/register.js.map +1 -0
  110. package/cjs/state/animation-state-machine.d.ts +22 -0
  111. package/cjs/state/animation-state-machine.js +53 -0
  112. package/cjs/state/animation-state-machine.js.map +1 -0
  113. package/cjs/state/animation-state-queue.d.ts +24 -0
  114. package/cjs/state/animation-state-queue.js +66 -0
  115. package/cjs/state/animation-state-queue.js.map +1 -0
  116. package/cjs/state/animation-state-registry.d.ts +14 -0
  117. package/cjs/state/animation-state-registry.js +53 -0
  118. package/cjs/state/animation-state-registry.js.map +1 -0
  119. package/cjs/state/animation-state.d.ts +25 -0
  120. package/cjs/state/animation-state.js +80 -0
  121. package/cjs/state/animation-state.js.map +1 -0
  122. package/cjs/state/animation-states-registry.d.ts +17 -0
  123. package/cjs/state/animation-states-registry.js +95 -0
  124. package/cjs/state/animation-states-registry.js.map +1 -0
  125. package/cjs/state/graphic-extension.d.ts +12 -0
  126. package/cjs/state/graphic-extension.js +37 -0
  127. package/cjs/state/graphic-extension.js.map +1 -0
  128. package/cjs/state/index.d.ts +3 -0
  129. package/cjs/state/index.js +22 -0
  130. package/cjs/state/index.js.map +1 -0
  131. package/cjs/state/types.d.ts +11 -0
  132. package/cjs/state/types.js +6 -0
  133. package/cjs/state/types.js.map +1 -0
  134. package/cjs/step.d.ts +49 -0
  135. package/cjs/step.js +124 -0
  136. package/cjs/step.js.map +1 -0
  137. package/cjs/ticker/default-ticker.d.ts +39 -0
  138. package/cjs/ticker/default-ticker.js +133 -0
  139. package/cjs/ticker/default-ticker.js.map +1 -0
  140. package/cjs/ticker/manual-ticker.d.ts +6 -0
  141. package/cjs/ticker/manual-ticker.js +37 -0
  142. package/cjs/ticker/manual-ticker.js.map +1 -0
  143. package/cjs/timeline.d.ts +34 -0
  144. package/cjs/timeline.js +84 -0
  145. package/cjs/timeline.js.map +1 -0
  146. package/cjs/utils/easing-func.d.ts +1 -0
  147. package/cjs/utils/easing-func.js +16 -0
  148. package/cjs/utils/easing-func.js.map +1 -0
  149. package/cjs/utils/easing.d.ts +49 -0
  150. package/cjs/utils/easing.js +141 -0
  151. package/cjs/utils/easing.js.map +1 -0
  152. package/dist/index.es.js +3824 -0
  153. package/es/animate-extension.d.ts +15 -0
  154. package/es/animate-extension.js +42 -0
  155. package/es/animate-extension.js.map +1 -0
  156. package/es/animate.d.ts +71 -0
  157. package/es/animate.js +207 -0
  158. package/es/animate.js.map +1 -0
  159. package/es/custom/clip-graphic.d.ts +53 -0
  160. package/es/custom/clip-graphic.js +134 -0
  161. package/es/custom/clip-graphic.js.map +1 -0
  162. package/es/custom/clip.d.ts +13 -0
  163. package/es/custom/clip.js +14 -0
  164. package/es/custom/clip.js.map +1 -0
  165. package/es/custom/common.d.ts +22 -0
  166. package/es/custom/common.js +48 -0
  167. package/es/custom/common.js.map +1 -0
  168. package/es/custom/custom-animate.d.ts +15 -0
  169. package/es/custom/custom-animate.js +17 -0
  170. package/es/custom/custom-animate.js.map +1 -0
  171. package/es/custom/fade.d.ts +13 -0
  172. package/es/custom/fade.js +14 -0
  173. package/es/custom/fade.js.map +1 -0
  174. package/es/custom/group-fade.d.ts +16 -0
  175. package/es/custom/group-fade.js +56 -0
  176. package/es/custom/group-fade.js.map +1 -0
  177. package/es/custom/growAngle.d.ts +37 -0
  178. package/es/custom/growAngle.js +132 -0
  179. package/es/custom/growAngle.js.map +1 -0
  180. package/es/custom/growCenter.d.ts +17 -0
  181. package/es/custom/growCenter.js +155 -0
  182. package/es/custom/growCenter.js.map +1 -0
  183. package/es/custom/growHeight.d.ts +36 -0
  184. package/es/custom/growHeight.js +144 -0
  185. package/es/custom/growHeight.js.map +1 -0
  186. package/es/custom/growPoints.d.ts +52 -0
  187. package/es/custom/growPoints.js +219 -0
  188. package/es/custom/growPoints.js.map +1 -0
  189. package/es/custom/growRadius.d.ts +41 -0
  190. package/es/custom/growRadius.js +105 -0
  191. package/es/custom/growRadius.js.map +1 -0
  192. package/es/custom/growWidth.d.ts +36 -0
  193. package/es/custom/growWidth.js +144 -0
  194. package/es/custom/growWidth.js.map +1 -0
  195. package/es/custom/input-text.d.ts +29 -0
  196. package/es/custom/input-text.js +37 -0
  197. package/es/custom/input-text.js.map +1 -0
  198. package/es/custom/number.d.ts +25 -0
  199. package/es/custom/number.js +94 -0
  200. package/es/custom/number.js.map +1 -0
  201. package/es/custom/register.d.ts +1 -0
  202. package/es/custom/register.js +39 -0
  203. package/es/custom/register.js.map +1 -0
  204. package/es/custom/scale-in.d.ts +13 -0
  205. package/es/custom/scale-in.js +49 -0
  206. package/es/custom/scale-in.js.map +1 -0
  207. package/es/custom/scale.d.ts +20 -0
  208. package/es/custom/scale.js +96 -0
  209. package/es/custom/scale.js.map +1 -0
  210. package/es/custom/sphere.d.ts +20 -0
  211. package/es/custom/sphere.js +20 -0
  212. package/es/custom/sphere.js.map +1 -0
  213. package/es/custom/state.d.ts +13 -0
  214. package/es/custom/state.js +17 -0
  215. package/es/custom/state.js.map +1 -0
  216. package/es/custom/tag-points.d.ts +26 -0
  217. package/es/custom/tag-points.js +77 -0
  218. package/es/custom/tag-points.js.map +1 -0
  219. package/es/custom/update.d.ts +14 -0
  220. package/es/custom/update.js +18 -0
  221. package/es/custom/update.js.map +1 -0
  222. package/es/executor/animate-executor.d.ts +36 -0
  223. package/es/executor/animate-executor.js +169 -0
  224. package/es/executor/animate-executor.js.map +1 -0
  225. package/es/executor/executor.d.ts +69 -0
  226. package/es/executor/executor.js +2 -0
  227. package/es/executor/executor.js.map +1 -0
  228. package/es/index.d.ts +25 -0
  229. package/es/index.js +50 -0
  230. package/es/index.js.map +1 -0
  231. package/es/interpolate/executor.d.ts +66 -0
  232. package/es/interpolate/executor.js +2 -0
  233. package/es/interpolate/executor.js.map +1 -0
  234. package/es/interpolate/number.d.ts +1 -0
  235. package/es/interpolate/number.js +4 -0
  236. package/es/interpolate/number.js.map +1 -0
  237. package/es/interpolate/store.d.ts +32 -0
  238. package/es/interpolate/store.js +88 -0
  239. package/es/interpolate/store.js.map +1 -0
  240. package/es/intreface/animate.d.ts +91 -0
  241. package/es/intreface/animate.js +6 -0
  242. package/es/intreface/animate.js.map +1 -0
  243. package/es/intreface/easing.d.ts +3 -0
  244. package/es/intreface/easing.js +2 -0
  245. package/es/intreface/easing.js.map +1 -0
  246. package/es/intreface/state.d.ts +35 -0
  247. package/es/intreface/state.js +2 -0
  248. package/es/intreface/state.js.map +1 -0
  249. package/es/intreface/ticker.d.ts +37 -0
  250. package/es/intreface/ticker.js +6 -0
  251. package/es/intreface/ticker.js.map +1 -0
  252. package/es/intreface/timeline.d.ts +17 -0
  253. package/es/intreface/timeline.js +2 -0
  254. package/es/intreface/timeline.js.map +1 -0
  255. package/es/intreface/type.d.ts +13 -0
  256. package/es/intreface/type.js +14 -0
  257. package/es/intreface/type.js.map +1 -0
  258. package/es/register.d.ts +1 -0
  259. package/es/register.js +20 -0
  260. package/es/register.js.map +1 -0
  261. package/es/state/animation-state-machine.d.ts +22 -0
  262. package/es/state/animation-state-machine.js +47 -0
  263. package/es/state/animation-state-machine.js.map +1 -0
  264. package/es/state/animation-state-queue.d.ts +24 -0
  265. package/es/state/animation-state-queue.js +58 -0
  266. package/es/state/animation-state-queue.js.map +1 -0
  267. package/es/state/animation-state-registry.d.ts +14 -0
  268. package/es/state/animation-state-registry.js +45 -0
  269. package/es/state/animation-state-registry.js.map +1 -0
  270. package/es/state/animation-state.d.ts +25 -0
  271. package/es/state/animation-state.js +72 -0
  272. package/es/state/animation-state.js.map +1 -0
  273. package/es/state/animation-states-registry.d.ts +17 -0
  274. package/es/state/animation-states-registry.js +87 -0
  275. package/es/state/animation-states-registry.js.map +1 -0
  276. package/es/state/graphic-extension.d.ts +12 -0
  277. package/es/state/graphic-extension.js +29 -0
  278. package/es/state/graphic-extension.js.map +1 -0
  279. package/es/state/index.d.ts +3 -0
  280. package/es/state/index.js +6 -0
  281. package/es/state/index.js.map +1 -0
  282. package/es/state/types.d.ts +11 -0
  283. package/es/state/types.js +2 -0
  284. package/es/state/types.js.map +1 -0
  285. package/es/step.d.ts +49 -0
  286. package/es/step.js +120 -0
  287. package/es/step.js.map +1 -0
  288. package/es/ticker/default-ticker.d.ts +39 -0
  289. package/es/ticker/default-ticker.js +129 -0
  290. package/es/ticker/default-ticker.js.map +1 -0
  291. package/es/ticker/manual-ticker.d.ts +6 -0
  292. package/es/ticker/manual-ticker.js +29 -0
  293. package/es/ticker/manual-ticker.js.map +1 -0
  294. package/es/timeline.d.ts +34 -0
  295. package/es/timeline.js +79 -0
  296. package/es/timeline.js.map +1 -0
  297. package/es/utils/easing-func.d.ts +1 -0
  298. package/es/utils/easing-func.js +8 -0
  299. package/es/utils/easing-func.js.map +1 -0
  300. package/es/utils/easing.d.ts +49 -0
  301. package/es/utils/easing.js +134 -0
  302. package/es/utils/easing.js.map +1 -0
  303. package/package.json +72 -0
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.AnimationStateManager = exports.AnimationStateStore = void 0;
6
+
7
+ const animation_states_registry_1 = require("./animation-states-registry"), animate_executor_1 = require("../executor/animate-executor");
8
+
9
+ class AnimationStateStore {
10
+ constructor(graphic) {
11
+ this.graphic = graphic;
12
+ }
13
+ registerState(state) {
14
+ this.states || (this.states = new Map), this.states.set(state.name, state);
15
+ }
16
+ clearStates() {
17
+ var _a;
18
+ null === (_a = this.states) || void 0 === _a || _a.clear();
19
+ }
20
+ }
21
+
22
+ exports.AnimationStateStore = AnimationStateStore;
23
+
24
+ class AnimationStateManager {
25
+ constructor(graphic) {
26
+ this.stateList = null, this.graphic = graphic;
27
+ }
28
+ applyState(nextState, animationConfig, callback) {
29
+ const registry = animation_states_registry_1.AnimationTransitionRegistry.getInstance(), shouldStopState = [], shouldApplyState = [];
30
+ if (this.stateList && this.stateList.length ? nextState.forEach(((state, index) => {
31
+ const result = {
32
+ allowTransition: !0,
33
+ stopOriginalTransition: !0
34
+ };
35
+ this.stateList.forEach((currState => {
36
+ const _result = registry.isTransitionAllowed(currState.state, state, this.graphic);
37
+ result.allowTransition = result.allowTransition && _result.allowTransition;
38
+ })), result.allowTransition && (shouldApplyState.push({
39
+ state: state,
40
+ animationConfig: animationConfig[index].animation,
41
+ executor: new animate_executor_1.AnimateExecutor(this.graphic)
42
+ }), this.stateList.forEach((currState => {
43
+ registry.isTransitionAllowed(currState.state, state, this.graphic).stopOriginalTransition && shouldStopState.push(currState);
44
+ })));
45
+ })) : nextState.forEach(((state, index) => {
46
+ shouldApplyState.push({
47
+ state: state,
48
+ animationConfig: animationConfig[index].animation,
49
+ executor: new animate_executor_1.AnimateExecutor(this.graphic)
50
+ });
51
+ })), shouldStopState.forEach((state => {
52
+ state.executor.stop();
53
+ })), shouldApplyState.length) {
54
+ shouldApplyState[0].executor.execute(shouldApplyState[0].animationConfig);
55
+ for (let i = 0; i < shouldApplyState.length; i++) {
56
+ const nextState = shouldApplyState[i + 1], currentState = shouldApplyState[i];
57
+ currentState.executor.onEnd((() => {
58
+ nextState && nextState.executor.execute(nextState.animationConfig), this.stateList = this.stateList.filter((state => state !== currentState)),
59
+ i === shouldApplyState.length - 1 && callback && callback(!1);
60
+ }));
61
+ }
62
+ } else callback && callback(!0);
63
+ this.stateList ? this.stateList = this.stateList.filter((state => !shouldStopState.includes(state))) : this.stateList = [],
64
+ this.stateList.push(...shouldApplyState);
65
+ }
66
+ stopState(state, type) {
67
+ var _a;
68
+ const stateInfo = null === (_a = this.stateList) || void 0 === _a ? void 0 : _a.find((stateInfo => stateInfo.state === state));
69
+ stateInfo && stateInfo.executor.stop(type);
70
+ }
71
+ clearState() {
72
+ var _a;
73
+ null === (_a = this.stateList) || void 0 === _a || _a.forEach((state => {
74
+ state.executor.stop();
75
+ })), this.stateList = null;
76
+ }
77
+ }
78
+
79
+ exports.AnimationStateManager = AnimationStateManager;
80
+ //# sourceMappingURL=animation-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/animation-state.ts"],"names":[],"mappings":";;;AAEA,2EAA0E;AAE1E,mEAA+D;AAE/D,MAAa,mBAAmB;IAG9B,YAAY,OAAiB;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAMD,aAAa,CAAC,KAAsB;QAClC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;SACzB;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,WAAW;;QACT,MAAA,IAAI,CAAC,MAAM,0CAAE,KAAK,EAAE,CAAC;IACvB,CAAC;CACF;AArBD,kDAqBC;AASD,MAAa,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AY,CAAC,CAAC;oBAGxE,IAAI,CAAC,KAAK,gBAAgB,CAAC,MAAM,GAAG,CAAC,IAAI,QAAQ,EAAE;wBACjD,QAAQ,CAAC,KAAK,CAAC,CAAC;qBACjB;gBACH,CAAC,CAAC,CAAC;aACJ;SACF;aAAM,IAAI,QAAQ,EAAE;YAEnB,QAAQ,CAAC,IAAI,CAAC,CAAC;SAChB;QAED,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;SACnF;aAAM;YACL,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;SACrB;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;IAC3C,CAAC;IAED,SAAS,CAAC,KAAa,EAAE,IAA4C;;QACnE,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,SAAS,0CAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAC/E,IAAI,SAAS,EAAE;YACb,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC/B;IACH,CAAC;IAED,UAAU;;QAER,MAAA,IAAI,CAAC,SAAS,0CAAE,OAAO,CAAC,KAAK,CAAC,EAAE;YAC9B,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACxB,CAAC;CAKF;AAvHD,sDAuHC","file":"animation-state.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IAnimationState } from './types';\nimport { AnimationTransitionRegistry } from './animation-states-registry';\nimport type { IAnimationConfig } from '../executor/executor';\nimport { AnimateExecutor } from '../executor/animate-executor';\n\nexport class AnimationStateStore {\n graphic: IGraphic;\n\n constructor(graphic: IGraphic) {\n this.graphic = graphic;\n }\n\n // 动画状态配置\n // 并不是所有图元都有(只有mark才有),所以在应用状态的时候,需要额外传入\n states?: Map<string, IAnimationState>;\n\n registerState(state: IAnimationState): void {\n if (!this.states) {\n this.states = new Map();\n }\n this.states.set(state.name, state);\n }\n\n clearStates(): void {\n this.states?.clear();\n }\n}\n\n// 一个状态对应一个执行器,每个图元都有一一对应\ninterface IStateInfo {\n state: string;\n animationConfig: IAnimationConfig;\n executor: AnimateExecutor;\n}\n\nexport class AnimationStateManager {\n protected graphic: IGraphic;\n\n // 当前状态\n // TODO(注意,这里无法了解动画的顺序,既有串行也有并行,具体在执行的时候确定,执行之后就无法获取串行或并行配置了)\n stateList: IStateInfo[] | null = null;\n\n constructor(graphic: IGraphic) {\n this.graphic = graphic;\n }\n\n // TODO 这里因为只有状态变更才会调用,所以代码写的比较宽松,如果有性能问题需要优化\n /**\n * 应用状态\n * @param nextState 下一个状态数组,如果传入数组,那么状态是串行的。但是每次applyState都会立即执行动画,也就是applyState和applyState之间是并行\n * @param animationConfig 动画配置\n * @param callback 动画结束后的回调函数,参数empty为true表示没有动画需要执行直接调的回调\n */\n applyState(nextState: string[], animationConfig: IAnimationState[], callback?: (empty?: boolean) => void): void {\n const registry = AnimationTransitionRegistry.getInstance();\n\n // TODO 这里指判断第一个状态,后续如果需要的话要循环判断\n // 检查是否需要停止当前状态,以及下一个状态是否需要应用\n const shouldStopState: IStateInfo[] = [];\n const shouldApplyState: IStateInfo[] = [];\n if (!(this.stateList && this.stateList.length)) {\n nextState.forEach((state, index) => {\n shouldApplyState.push({\n state,\n animationConfig: animationConfig[index].animation,\n executor: new AnimateExecutor(this.graphic)\n });\n });\n } else {\n // const _stateList = this.stateList[0];\n nextState.forEach((state, index) => {\n // 遍历this.stateList,获取result,只要有一个是false,那这个result就是false\n const result: { allowTransition: boolean; stopOriginalTransition: boolean } = {\n allowTransition: true,\n stopOriginalTransition: true\n };\n this.stateList.forEach(currState => {\n const _result = registry.isTransitionAllowed(currState.state, state, this.graphic);\n result.allowTransition = result.allowTransition && _result.allowTransition;\n });\n // 所有状态都允许过渡,则添加到shouldApplyState\n if (result.allowTransition) {\n shouldApplyState.push({\n state,\n animationConfig: animationConfig[index].animation,\n executor: new AnimateExecutor(this.graphic)\n });\n // 允许过渡的话,需要重新遍历this.stateList,获取stopOriginalTransition\n this.stateList.forEach(currState => {\n const _result = registry.isTransitionAllowed(currState.state, state, this.graphic);\n if (_result.stopOriginalTransition) {\n shouldStopState.push(currState);\n }\n });\n }\n });\n }\n\n // 停止动画\n shouldStopState.forEach(state => {\n state.executor.stop();\n });\n\n // 立即应用动画,串行的应用\n if (shouldApplyState.length) {\n shouldApplyState[0].executor.execute(shouldApplyState[0].animationConfig);\n // 如果下一个状态存在,那么下一个状态的动画在当前状态动画结束后立即执行\n for (let i = 0; i < shouldApplyState.length; i++) {\n const nextState = shouldApplyState[i + 1];\n const currentState = shouldApplyState[i];\n currentState.executor.onEnd(() => {\n if (nextState) {\n nextState.executor.execute(nextState.animationConfig);\n }\n // 删除这个状态\n this.stateList = this.stateList.filter(state => state !== currentState);\n\n // 如果是最后一个状态且有回调,则调用回调\n if (i === shouldApplyState.length - 1 && callback) {\n callback(false);\n }\n });\n }\n } else if (callback) {\n // 如果没有需要应用的动画状态,直接调用回调\n callback(true);\n }\n\n if (this.stateList) {\n this.stateList = this.stateList.filter(state => !shouldStopState.includes(state));\n } else {\n this.stateList = [];\n }\n this.stateList.push(...shouldApplyState);\n }\n\n stopState(state: string, type?: 'start' | 'end' | Record<string, any>): void {\n const stateInfo = this.stateList?.find(stateInfo => stateInfo.state === state);\n if (stateInfo) {\n stateInfo.executor.stop(type);\n }\n }\n\n clearState(): void {\n // 清空状态\n this.stateList?.forEach(state => {\n state.executor.stop();\n });\n this.stateList = null;\n }\n\n // getstateList(): string[] | null {\n // return this.stateList;\n // }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { IGraphic } from '@visactor/vrender-core';
2
+ interface ITransitionResult {
3
+ allowTransition: boolean;
4
+ stopOriginalTransition: boolean;
5
+ }
6
+ export type TransitionFunction = (graphic: IGraphic, fromState: string) => ITransitionResult;
7
+ export declare class AnimationTransitionRegistry {
8
+ private static instance;
9
+ private transitions;
10
+ constructor();
11
+ static getInstance(): AnimationTransitionRegistry;
12
+ private registerDefaultTransitions;
13
+ isTransitionAllowed(fromState: string, toState: string, graphic: IGraphic): ITransitionResult;
14
+ registerTransition(fromState: string, toState: string, transition: TransitionFunction): void;
15
+ }
16
+ declare const transitionRegistry: AnimationTransitionRegistry;
17
+ export { transitionRegistry };
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.transitionRegistry = exports.AnimationTransitionRegistry = void 0;
6
+
7
+ class AnimationTransitionRegistry {
8
+ constructor() {
9
+ this.transitions = new Map, this.registerDefaultTransitions();
10
+ }
11
+ static getInstance() {
12
+ return AnimationTransitionRegistry.instance || (AnimationTransitionRegistry.instance = new AnimationTransitionRegistry),
13
+ AnimationTransitionRegistry.instance;
14
+ }
15
+ registerDefaultTransitions() {
16
+ this.registerTransition("appear", "*", (() => ({
17
+ allowTransition: !0,
18
+ stopOriginalTransition: !1
19
+ }))), this.registerTransition("appear", "appear", (() => ({
20
+ allowTransition: !1,
21
+ stopOriginalTransition: !1
22
+ }))), this.registerTransition("appear", "disappear", (() => ({
23
+ allowTransition: !0,
24
+ stopOriginalTransition: !0
25
+ }))), this.registerTransition("appear", "exit", (() => ({
26
+ allowTransition: !0,
27
+ stopOriginalTransition: !0
28
+ }))), this.registerTransition("normal", "*", (() => ({
29
+ allowTransition: !0,
30
+ stopOriginalTransition: !1
31
+ }))), this.registerTransition("normal", "normal", (() => ({
32
+ allowTransition: !1,
33
+ stopOriginalTransition: !1
34
+ }))), this.registerTransition("normal", "disappear", (() => ({
35
+ allowTransition: !0,
36
+ stopOriginalTransition: !0
37
+ }))), this.registerTransition("normal", "exit", (() => ({
38
+ allowTransition: !0,
39
+ stopOriginalTransition: !0
40
+ }))), this.registerTransition("exit", "*", (() => ({
41
+ allowTransition: !1,
42
+ stopOriginalTransition: !1
43
+ }))), this.registerTransition("exit", "disappear", (() => ({
44
+ allowTransition: !0,
45
+ stopOriginalTransition: !0
46
+ }))), this.registerTransition("exit", "enter", (() => ({
47
+ allowTransition: !0,
48
+ stopOriginalTransition: !0
49
+ }))), this.registerTransition("exit", "exit", (() => ({
50
+ allowTransition: !1,
51
+ stopOriginalTransition: !1
52
+ }))), this.registerTransition("enter", "*", (() => ({
53
+ allowTransition: !0,
54
+ stopOriginalTransition: !1
55
+ }))), this.registerTransition("enter", "enter", (() => ({
56
+ allowTransition: !1,
57
+ stopOriginalTransition: !1
58
+ }))), this.registerTransition("enter", "disappear", (() => ({
59
+ allowTransition: !0,
60
+ stopOriginalTransition: !0
61
+ }))), this.registerTransition("enter", "exit", (() => ({
62
+ allowTransition: !0,
63
+ stopOriginalTransition: !0
64
+ }))), this.registerTransition("disappear", "*", (() => ({
65
+ allowTransition: !1,
66
+ stopOriginalTransition: !1
67
+ }))), this.registerTransition("disappear", "appear", (() => ({
68
+ allowTransition: !0,
69
+ stopOriginalTransition: !0
70
+ })));
71
+ }
72
+ isTransitionAllowed(fromState, toState, graphic) {
73
+ var _a, _b, _c, _d;
74
+ let func = null === (_a = this.transitions.get(fromState)) || void 0 === _a ? void 0 : _a.get(toState);
75
+ return func ? func(graphic, fromState) : (func = null === (_b = this.transitions.get(fromState)) || void 0 === _b ? void 0 : _b.get("*"),
76
+ func ? func(graphic, fromState) : (func = null === (_c = this.transitions.get("*")) || void 0 === _c ? void 0 : _c.get(toState),
77
+ func ? func(graphic, fromState) : (func = null === (_d = this.transitions.get("*")) || void 0 === _d ? void 0 : _d.get("*"),
78
+ func ? func(graphic, fromState) : {
79
+ allowTransition: !0,
80
+ stopOriginalTransition: !0
81
+ })));
82
+ }
83
+ registerTransition(fromState, toState, transition) {
84
+ let fromStateMap = this.transitions.get(fromState);
85
+ fromStateMap || (fromStateMap = new Map, this.transitions.set(fromState, fromStateMap)),
86
+ fromStateMap.set(toState, transition);
87
+ }
88
+ }
89
+
90
+ exports.AnimationTransitionRegistry = AnimationTransitionRegistry;
91
+
92
+ const transitionRegistry = AnimationTransitionRegistry.getInstance();
93
+
94
+ exports.transitionRegistry = transitionRegistry;
95
+ //# sourceMappingURL=animation-states-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/animation-states-registry.ts"],"names":[],"mappings":";;;AAgBA,MAAa,2BAA2B;IAMtC;QAFQ,gBAAW,GAAiD,IAAI,GAAG,EAAE,CAAC;QAG5E,IAAI,CAAC,0BAA0B,EAAE,CAAC;IACpC,CAAC;IAKD,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,2BAA2B,CAAC,QAAQ,EAAE;YACzC,2BAA2B,CAAC,QAAQ,GAAG,IAAI,2BAA2B,EAAE,CAAC;SAC1E;QACD,OAAO,2BAA2B,CAAC,QAAQ,CAAC;IAC9C,CAAC;IAKO,0BAA0B;QAEhC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;YAC5C,eAAe,EAAE,IAAI;YACrB,sBAAsB,EAAE,KAAK;SAC9B,CAAC,CAAC,CAAC;QAEJ,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;YACjD,eAAe,EAAE,KAAK;YACtB,sBAAsB,EAAE,KAAK;SAC9B,CAAC,CAAC,CAAC;QACJ,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC;YACpD,eAAe,EAAE,IAAI;YACrB,sBAAsB,EAAE,IAAI;SAC7B,CAAC,CAAC,CAAC;QACJ,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,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AkB","file":"animation-states-registry.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\n\ninterface ITransitionResult {\n allowTransition: boolean;\n stopOriginalTransition: boolean;\n}\n\n/**\n * 注册动画状态切换的转换函数\n */\nexport type TransitionFunction = (graphic: IGraphic, fromState: string) => ITransitionResult;\n\n/**\n * 动画状态切换的注册表\n * 管理所有图形的动画状态切换逻辑\n */\nexport class AnimationTransitionRegistry {\n private static instance: AnimationTransitionRegistry;\n\n // 源状态到目标状态的映射,每个目标状态都有一个转换函数\n private transitions: Map<string, Map<string, TransitionFunction>> = new Map();\n\n constructor() {\n this.registerDefaultTransitions();\n }\n\n /**\n * 获取注册表的单例实例\n */\n static getInstance(): AnimationTransitionRegistry {\n if (!AnimationTransitionRegistry.instance) {\n AnimationTransitionRegistry.instance = new AnimationTransitionRegistry();\n }\n return AnimationTransitionRegistry.instance;\n }\n\n /**\n * 注册默认的转换规则\n */\n private registerDefaultTransitions(): void {\n // appear动画,可以被任何动画覆盖,但不会停止(disappear、exit除外)\n this.registerTransition('appear', '*', () => ({\n allowTransition: true,\n stopOriginalTransition: false\n }));\n // appear 动画碰到appear动画,什么都不会发生\n this.registerTransition('appear', 'appear', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n this.registerTransition('appear', 'disappear', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n this.registerTransition('appear', 'exit', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n\n // 循环动画(normal),可以被任何动画覆盖,但不会停止(disappear、exit除外)\n this.registerTransition('normal', '*', () => ({\n allowTransition: true,\n stopOriginalTransition: false\n }));\n // 循环动画碰到循环动画,什么都不会发生\n this.registerTransition('normal', 'normal', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n this.registerTransition('normal', 'disappear', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n this.registerTransition('normal', 'exit', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n\n // 退出动画不能被覆盖或停止(disappear除外)\n this.registerTransition('exit', '*', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n this.registerTransition('exit', 'disappear', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n // 退出动画碰到enter动画,会立即停止\n this.registerTransition('exit', 'enter', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n // 退出动画碰到退出,什么都不会发生\n this.registerTransition('exit', 'exit', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n\n // enter 动画可以被任何动画覆盖,但不会停止(exit、disappear除外)\n this.registerTransition('enter', '*', () => ({\n allowTransition: true,\n stopOriginalTransition: false\n }));\n // enter 动画碰到enter动画,什么都不会发生\n this.registerTransition('enter', 'enter', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n this.registerTransition('enter', 'disappear', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n this.registerTransition('enter', 'exit', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n\n // disappear 动画碰到任何动画,什么都不会发生(appear除外)\n this.registerTransition('disappear', '*', () => ({\n allowTransition: false,\n stopOriginalTransition: false\n }));\n\n // disappear 动画碰到appear动画,会立即停止\n this.registerTransition('disappear', 'appear', () => ({\n allowTransition: true,\n stopOriginalTransition: true\n }));\n }\n\n /**\n * 检查两个状态之间是否允许转换\n */\n isTransitionAllowed(fromState: string, toState: string, graphic: IGraphic): ITransitionResult {\n // 直接转换规则\n let func = this.transitions.get(fromState)?.get(toState);\n if (func) {\n return func(graphic, fromState);\n }\n\n // 状态到通配符\n func = this.transitions.get(fromState)?.get('*');\n if (func) {\n return func(graphic, fromState);\n }\n\n // 通配符到状态\n func = this.transitions.get('*')?.get(toState);\n if (func) {\n return func(graphic, fromState);\n }\n\n // 通配符到通配符\n func = this.transitions.get('*')?.get('*');\n if (func) {\n return func(graphic, fromState);\n }\n\n // 默认允许转换\n return {\n allowTransition: true,\n stopOriginalTransition: true\n };\n }\n\n /**\n * 注册两个状态之间的转换\n */\n registerTransition(fromState: string, toState: string, transition: TransitionFunction): void {\n let fromStateMap = this.transitions.get(fromState);\n\n if (!fromStateMap) {\n fromStateMap = new Map();\n this.transitions.set(fromState, fromStateMap);\n }\n\n fromStateMap.set(toState, transition);\n }\n}\n\n// 初始化单例转换注册表\nconst transitionRegistry = AnimationTransitionRegistry.getInstance();\n\nexport { transitionRegistry };\n"]}
@@ -0,0 +1,12 @@
1
+ import type { IGraphic } from '@visactor/vrender-core';
2
+ import type { IAnimationState } from './types';
3
+ import { AnimationStateManager, AnimationStateStore } from './animation-state';
4
+ export declare class GraphicStateExtension {
5
+ _getAnimationStateManager(graphic: IGraphic): AnimationStateManager;
6
+ _getAnimationStateStore(graphic: IGraphic): AnimationStateStore;
7
+ registerAnimationState(state: IAnimationState): this;
8
+ applyAnimationState(state: string[], animationConfig: IAnimationState[], callback?: (empty?: boolean) => void): this;
9
+ stopAnimationState(state: string, type?: 'start' | 'end' | Record<string, any>): this;
10
+ clearAnimationStates(): this;
11
+ static extend(graphic: IGraphic): IGraphic;
12
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.GraphicStateExtension = void 0;
6
+
7
+ const animation_state_1 = require("./animation-state");
8
+
9
+ class GraphicStateExtension {
10
+ _getAnimationStateManager(graphic) {
11
+ return graphic._animationStateManager || (graphic._animationStateManager = new animation_state_1.AnimationStateManager(graphic)),
12
+ graphic._animationStateManager;
13
+ }
14
+ _getAnimationStateStore(graphic) {
15
+ return graphic._animationStateStore || (graphic._animationStateStore = new animation_state_1.AnimationStateStore(graphic)),
16
+ graphic._animationStateStore;
17
+ }
18
+ registerAnimationState(state) {
19
+ return this._getAnimationStateStore(this).registerState(state), this;
20
+ }
21
+ applyAnimationState(state, animationConfig, callback) {
22
+ return this._getAnimationStateManager(this).applyState(state, animationConfig, callback),
23
+ this;
24
+ }
25
+ stopAnimationState(state, type) {
26
+ return this._getAnimationStateManager(this).stopState(state, type), this;
27
+ }
28
+ clearAnimationStates() {
29
+ return this._getAnimationStateManager(this).clearState(), this;
30
+ }
31
+ static extend(graphic) {
32
+ return (new GraphicStateExtension)._getAnimationStateManager(graphic), graphic;
33
+ }
34
+ }
35
+
36
+ exports.GraphicStateExtension = GraphicStateExtension;
37
+ //# sourceMappingURL=graphic-extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/graphic-extension.ts"],"names":[],"mappings":";;;AAEA,uDAA+E;AAK/E,MAAa,qBAAqB;IAChC,yBAAyB,CAAC,OAAiB;QACzC,IAAI,CAAE,OAAe,CAAC,sBAAsB,EAAE;YAE3C,OAAe,CAAC,sBAAsB,GAAG,IAAI,uCAAqB,CAAC,OAAO,CAAC,CAAC;SAC9E;QACD,OAAQ,OAAe,CAAC,sBAAsB,CAAC;IACjD,CAAC;IACD,uBAAuB,CAAC,OAAiB;QACvC,IAAI,CAAE,OAAe,CAAC,oBAAoB,EAAE;YAEzC,OAAe,CAAC,oBAAoB,GAAG,IAAI,qCAAmB,CAAC,OAAO,CAAC,CAAC;SAC1E;QACD,OAAQ,OAAe,CAAC,oBAAoB,CAAC;IAC/C,CAAC;IAKD,sBAAsB,CAAC,KAAsB;QAC3C,IAAI,CAAC,uBAAuB,CAAC,IAA2B,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC/E,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,mBAAmB,CAAC,KAAe,EAAE,eAAkC,EAAE,QAAoC;QAC3G,IAAI,CAAC,yBAAyB,CAAC,IAA2B,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;QACzG,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,kBAAkB,CAAC,KAAa,EAAE,IAA4C;QAC5E,IAAI,CAAC,yBAAyB,CAAC,IAA2B,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACnF,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,oBAAoB;QAClB,IAAI,CAAC,yBAAyB,CAAC,IAA2B,CAAC,CAAC,UAAU,EAAE,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IAYD,MAAM,CAAC,MAAM,CAAC,OAAiB;QAC7B,MAAM,SAAS,GAAG,IAAI,qBAAqB,EAAE,CAAC;QAC9C,SAAS,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA/DD,sDA+DC","file":"graphic-extension.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IAnimationState } from './types';\nimport { AnimationStateManager, AnimationStateStore } from './animation-state';\n\n/**\n * 将动画状态方法作为混入扩展 Graphic 的类\n */\nexport class GraphicStateExtension {\n _getAnimationStateManager(graphic: IGraphic): AnimationStateManager {\n if (!(graphic as any)._animationStateManager) {\n // Create the appropriate manager type based on whether this is a group\n (graphic as any)._animationStateManager = new AnimationStateManager(graphic);\n }\n return (graphic as any)._animationStateManager;\n }\n _getAnimationStateStore(graphic: IGraphic): AnimationStateStore {\n if (!(graphic as any)._animationStateStore) {\n // Create the appropriate manager type based on whether this is a group\n (graphic as any)._animationStateStore = new AnimationStateStore(graphic);\n }\n return (graphic as any)._animationStateStore;\n }\n\n /**\n * 注册一个动画状态\n */\n registerAnimationState(state: IAnimationState): this {\n this._getAnimationStateStore(this as unknown as IGraphic).registerState(state);\n return this;\n }\n\n /**\n * 应用一个动画状态到图形\n */\n applyAnimationState(state: string[], animationConfig: IAnimationState[], callback?: (empty?: boolean) => void): this {\n this._getAnimationStateManager(this as unknown as IGraphic).applyState(state, animationConfig, callback);\n return this;\n }\n\n /**\n * 停止一个动画状态\n */\n stopAnimationState(state: string, type?: 'start' | 'end' | Record<string, any>): this {\n this._getAnimationStateManager(this as unknown as IGraphic).stopState(state, type);\n return this;\n }\n\n /**\n * 清除图形上的所有动画状态\n */\n clearAnimationStates(): this {\n this._getAnimationStateManager(this as unknown as IGraphic).clearState();\n return this;\n }\n\n // /**\n // * 获取图形当前的动画状态\n // */\n // getCurrentAnimationState(): string[] | null {\n // return this._getAnimationStateManager(this as unknown as IGraphic).getCurrentState();\n // }\n\n /**\n * 继承\n */\n static extend(graphic: IGraphic): IGraphic {\n const extension = new GraphicStateExtension();\n extension._getAnimationStateManager(graphic);\n return graphic;\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export * from './animation-state';
2
+ export * from './graphic-extension';
3
+ export * from './animation-states-registry';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function(o, m, k, k2) {
4
+ void 0 === k2 && (k2 = k);
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ desc && !("get" in desc ? !m.__esModule : desc.writable || desc.configurable) || (desc = {
7
+ enumerable: !0,
8
+ get: function() {
9
+ return m[k];
10
+ }
11
+ }), Object.defineProperty(o, k2, desc);
12
+ } : function(o, m, k, k2) {
13
+ void 0 === k2 && (k2 = k), o[k2] = m[k];
14
+ }), __exportStar = this && this.__exportStar || function(m, exports) {
15
+ for (var p in m) "default" === p || Object.prototype.hasOwnProperty.call(exports, p) || __createBinding(exports, m, p);
16
+ };
17
+
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: !0
20
+ }), __exportStar(require("./animation-state"), exports), __exportStar(require("./graphic-extension"), exports),
21
+ __exportStar(require("./animation-states-registry"), exports);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,sDAAoC;AACpC,8DAA4C","file":"index.js","sourcesContent":["export * from './animation-state';\nexport * from './graphic-extension';\nexport * from './animation-states-registry';\n"]}
@@ -0,0 +1,11 @@
1
+ import type { IAnimationConfig } from '../executor/executor';
2
+ export interface IAnimationState {
3
+ name: string;
4
+ animation: IAnimationConfig;
5
+ }
6
+ export interface IAnimationStateManager {
7
+ registerState: (state: IAnimationState) => void;
8
+ applyState: (state: string | string[]) => void;
9
+ clearStates: () => void;
10
+ getCurrentState: () => string | string[] | null;
11
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/state/types.ts"],"names":[],"mappings":"","file":"types.js","sourcesContent":["import type { IGraphic } from '@visactor/vrender-core';\nimport type { IAnimationConfig } from '../executor/executor';\n\nexport interface IAnimationState {\n /**\n * 状态名称\n */\n name: string;\n\n /**\n * 动画配置\n */\n animation: IAnimationConfig;\n}\n\n/**\n * Animation state manager for a graphic\n */\nexport interface IAnimationStateManager {\n /**\n * Register a state for the graphic\n */\n registerState: (state: IAnimationState) => void;\n\n /**\n * Apply a state to the graphic\n */\n applyState: (state: string | string[]) => void;\n\n /**\n * Clear all states from the graphic\n */\n clearStates: () => void;\n\n /**\n * Get the current state of the graphic\n */\n getCurrentState: () => string | string[] | null;\n}\n"]}
package/cjs/step.d.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { type IGraphic } from '@visactor/vrender-core';
2
+ import type { IAnimate, IStep } from './intreface/animate';
3
+ import type { EasingType, EasingTypeFunc } from './intreface/easing';
4
+ import type { IAnimateStepType } from './intreface/type';
5
+ export declare class Step implements IStep {
6
+ type: IAnimateStepType;
7
+ prev?: IStep;
8
+ duration: number;
9
+ next?: IStep;
10
+ props?: Record<string, any>;
11
+ propKeys?: string[];
12
+ interpolateUpdateFunctions?: ((key: string, from: number, to: number, ratio: number, step: IStep, target: IGraphic) => void)[];
13
+ easing: EasingTypeFunc;
14
+ animate: IAnimate;
15
+ target: IGraphic;
16
+ fromProps: Record<string, any>;
17
+ fromParsedProps: Record<string, any>;
18
+ toParsedProps: Record<string, any>;
19
+ protected _startTime: number;
20
+ _hasFirstRun: boolean;
21
+ protected _endCb?: (animate: IAnimate, step: IStep) => void;
22
+ constructor(type: IAnimateStepType, props: Record<string, any>, duration: number, easing: EasingType);
23
+ bind(target: IGraphic, animate: IAnimate): void;
24
+ append(step: IStep): void;
25
+ private updateDownstreamStartTimes;
26
+ getLastProps(): any;
27
+ setDuration(duration: number, updateDownstream?: boolean): void;
28
+ getDuration(): number;
29
+ determineInterpolateUpdateFunction(): void;
30
+ setStartTime(time: number, updateDownstream?: boolean): void;
31
+ getStartTime(): number;
32
+ onBind(): void;
33
+ onFirstRun(): void;
34
+ onStart(): void;
35
+ protected tryPreventConflict(): void;
36
+ deleteSelfAttr(key: string): void;
37
+ trySyncStartProps(): void;
38
+ update(end: boolean, ratio: number, out: Record<string, any>): void;
39
+ onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
40
+ onEnd(cb?: (animate: IAnimate, step: IStep) => void): void;
41
+ getEndProps(): Record<string, any>;
42
+ getFromProps(): Record<string, any>;
43
+ getMergedEndProps(): Record<string, any> | void;
44
+ }
45
+ export declare class WaitStep extends Step {
46
+ constructor(type: IAnimateStepType, props: Record<string, any>, duration: number, easing: EasingType);
47
+ update(end: boolean, ratio: number, out: Record<string, any>): void;
48
+ determineInterpolateUpdateFunction(): void;
49
+ }
package/cjs/step.js ADDED
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.WaitStep = exports.Step = void 0;
6
+
7
+ const vrender_core_1 = require("@visactor/vrender-core"), easing_1 = require("./utils/easing"), store_1 = require("./interpolate/store"), vutils_1 = require("@visactor/vutils");
8
+
9
+ function noop() {}
10
+
11
+ class Step {
12
+ constructor(type, props, duration, easing) {
13
+ this._startTime = 0, this._hasFirstRun = !1, this.type = type, this.props = props,
14
+ this.duration = duration, this.easing = easing ? "function" == typeof easing ? easing : easing_1.Easing[easing] : easing_1.Easing.linear,
15
+ "wait" === type && (this.onUpdate = noop);
16
+ }
17
+ bind(target, animate) {
18
+ this.target = target, this.animate = animate, this.onBind();
19
+ }
20
+ append(step) {
21
+ this.next = step, step.prev = this, step.setStartTime(this.getStartTime() + this.duration, !1);
22
+ }
23
+ updateDownstreamStartTimes() {
24
+ let currentStep = this.next, currentStartTime = this._startTime + this.duration;
25
+ for (;currentStep; ) currentStep.setStartTime(currentStartTime, !1), currentStartTime += currentStep.duration,
26
+ currentStep = currentStep.next;
27
+ this.animate.updateDuration();
28
+ }
29
+ getLastProps() {
30
+ return this.prev ? this.prev.props || {} : this.animate.getStartProps();
31
+ }
32
+ setDuration(duration, updateDownstream = !0) {
33
+ this.duration = duration, updateDownstream && this.updateDownstreamStartTimes();
34
+ }
35
+ getDuration() {
36
+ return this.duration;
37
+ }
38
+ determineInterpolateUpdateFunction() {
39
+ if (!this.props) return;
40
+ const funcs = [];
41
+ this.propKeys.forEach((key => {
42
+ if ("fill" === key || "stroke" === key) {
43
+ const from = this.getLastProps()[key], to = this.props[key];
44
+ if ((0, vutils_1.isString)(from) && (0, vutils_1.isString)(to)) {
45
+ const fromArray = vrender_core_1.ColorStore.Get(from, vrender_core_1.ColorType.Color255), toArray = vrender_core_1.ColorStore.Get(to, vrender_core_1.ColorType.Color255);
46
+ this.fromParsedProps || (this.fromParsedProps = {}), this.toParsedProps || (this.toParsedProps = {}),
47
+ this.fromParsedProps[key] = fromArray, this.toParsedProps[key] = toArray;
48
+ }
49
+ funcs.push(store_1.interpolateUpdateStore["fill" === key ? "fillPure" : "strokePure"]);
50
+ } else store_1.interpolateUpdateStore[key] ? funcs.push(store_1.interpolateUpdateStore[key]) : funcs.push(store_1.commonInterpolateUpdate);
51
+ })), this.interpolateUpdateFunctions = funcs;
52
+ }
53
+ setStartTime(time, updateDownstream = !0) {
54
+ this._startTime = time, updateDownstream && this.updateDownstreamStartTimes();
55
+ }
56
+ getStartTime() {
57
+ return this._startTime;
58
+ }
59
+ onBind() {}
60
+ onFirstRun() {}
61
+ onStart() {
62
+ this._hasFirstRun || (this._hasFirstRun = !0, this.fromProps = this.getLastProps(),
63
+ this.determineInterpolateUpdateFunction(), this.tryPreventConflict(), this.trySyncStartProps(),
64
+ this.onFirstRun());
65
+ }
66
+ tryPreventConflict() {
67
+ const animate = this.animate;
68
+ this.target.animates.forEach((a => {
69
+ if (a === animate || a.priority > animate.priority) return;
70
+ const fromProps = a.getStartProps();
71
+ this.propKeys.forEach((key => {
72
+ null != fromProps[key] && a.preventAttr(key);
73
+ }));
74
+ }));
75
+ }
76
+ deleteSelfAttr(key) {
77
+ var _a;
78
+ delete this.props[key], this.fromProps && delete this.fromProps[key];
79
+ const index = this.propKeys.indexOf(key);
80
+ -1 !== index && (this.propKeys.splice(index, 1), null === (_a = this.interpolateUpdateFunctions) || void 0 === _a || _a.splice(index, 1));
81
+ }
82
+ trySyncStartProps() {
83
+ this.propKeys.forEach((key => {
84
+ this.fromProps[key] = this.animate.target.getComputedAttribute(key);
85
+ }));
86
+ }
87
+ update(end, ratio, out) {
88
+ if (this.onStart(), !this.props || !this.propKeys) return;
89
+ const easedRatio = this.easing(ratio);
90
+ this.animate.interpolateUpdateFunction ? this.animate.interpolateUpdateFunction(this.fromProps, this.props, easedRatio, this, this.target) : this.interpolateUpdateFunctions.forEach(((func, index) => {
91
+ if (!this.animate.validAttr(this.propKeys[index])) return;
92
+ const key = this.propKeys[index];
93
+ func(key, this.fromProps[key], this.props[key], easedRatio, this, this.target);
94
+ })), this.onUpdate(end, easedRatio, out);
95
+ }
96
+ onUpdate(end, ratio, out) {}
97
+ onEnd(cb) {
98
+ cb ? this._endCb = cb : this._endCb && (this.target.setAttributes(this.props), this._endCb(this.animate, this));
99
+ }
100
+ getEndProps() {
101
+ return this.props;
102
+ }
103
+ getFromProps() {
104
+ return this.fromProps;
105
+ }
106
+ getMergedEndProps() {
107
+ return this.getEndProps();
108
+ }
109
+ }
110
+
111
+ exports.Step = Step;
112
+
113
+ class WaitStep extends Step {
114
+ constructor(type, props, duration, easing) {
115
+ super(type, props, duration, easing);
116
+ }
117
+ update(end, ratio, out) {
118
+ this.onStart();
119
+ }
120
+ determineInterpolateUpdateFunction() {}
121
+ }
122
+
123
+ exports.WaitStep = WaitStep;
124
+ //# sourceMappingURL=step.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/step.ts"],"names":[],"mappings":";;;AAAA,yDAA8E;AAI9E,2CAAwC;AACxC,+CAAsF;AACtF,6CAA4C;AAE5C,SAAS,IAAI;AAEb,CAAC;AAED,MAAa,IAAI;IA4Bf,YAAY,IAAsB,EAAE,KAA0B,EAAE,QAAgB,EAAE,MAAkB;QAL1F,eAAU,GAAW,CAAC,CAAC;QACjC,iBAAY,GAAY,KAAK,CAAC;QAK5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,MAAM,EAAE;YACV,IAAI,CAAC,MAAM,GAAG,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAM,CAAC,MAAM,CAAC,CAAC;SACtE;aAAM;YACL,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,MAAM,CAAC;SAC7B;QACD,IAAI,IAAI,KAAK,MAAM,EAAE;YACnB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;IACH,CAAC;IAED,IAAI,CAAC,MAAgB,EAAE,OAAiB;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,IAAW;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAGjB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChE,CA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U,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;QACP,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,QAAQ,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;IAE9D,CAAC;IAMD,KAAK,CAAC,EAA6C;QACjD,IAAI,EAAE,EAAE;YACN,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;SAClB;aAAM,IAAI,IAAI,CAAC,MAAM,EAAE;YACtB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACtC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;SACjC;IACH,CAAC;IAMD,WAAW;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAMD,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAMD,iBAAiB;QACf,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;CACF;AAhRD,oBAgRC;AAED,MAAa,QAAS,SAAQ,IAAI;IAChC,YAAY,IAAsB,EAAE,KAA0B,EAAE,QAAgB,EAAE,MAAkB;QAClG,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,GAAY,EAAE,KAAa,EAAE,GAAwB;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;IAEjB,CAAC;IAED,kCAAkC;QAChC,OAAO;IACT,CAAC;CACF;AAbD,4BAaC","file":"step.js","sourcesContent":["import { ColorStore, ColorType, type IGraphic } from '@visactor/vrender-core';\nimport type { IAnimate, IStep } from './intreface/animate';\nimport type { EasingType, EasingTypeFunc } from './intreface/easing';\nimport type { IAnimateStepType } from './intreface/type';\nimport { Easing } from './utils/easing';\nimport { commonInterpolateUpdate, interpolateUpdateStore } from './interpolate/store';\nimport { isString } from '@visactor/vutils';\n\nfunction noop() {\n //...\n}\n\nexport class Step implements IStep {\n type: IAnimateStepType;\n prev?: IStep;\n duration: number;\n next?: IStep;\n props?: Record<string, any>;\n propKeys?: string[];\n interpolateUpdateFunctions?: ((\n key: string,\n from: number,\n to: number,\n ratio: number,\n step: IStep,\n target: IGraphic\n ) => void)[];\n easing: EasingTypeFunc;\n animate: IAnimate;\n target: IGraphic;\n fromProps: Record<string, any>;\n fromParsedProps: Record<string, any>;\n toParsedProps: Record<string, any>;\n\n // 内部状态\n protected _startTime: number = 0;\n _hasFirstRun: boolean = false;\n\n protected _endCb?: (animate: IAnimate, step: IStep) => void;\n\n constructor(type: IAnimateStepType, props: Record<string, any>, duration: number, easing: EasingType) {\n this.type = type;\n this.props = props;\n this.duration = duration;\n // 设置缓动函数\n if (easing) {\n this.easing = typeof easing === 'function' ? easing : Easing[easing];\n } else {\n this.easing = Easing.linear;\n }\n if (type === 'wait') {\n this.onUpdate = noop;\n }\n }\n\n bind(target: IGraphic, animate: IAnimate): void {\n this.target = target;\n this.animate = animate;\n this.onBind();\n }\n\n append(step: IStep): void {\n this.next = step;\n step.prev = this;\n\n // 更新绝对时间\n step.setStartTime(this.getStartTime() + this.duration, false);\n }\n\n // 更新下游节点的开始时间\n private updateDownstreamStartTimes(): void {\n let currentStep = this.next;\n let currentStartTime = this._startTime + this.duration;\n\n while (currentStep) {\n currentStep.setStartTime(currentStartTime, false);\n currentStartTime += currentStep.duration;\n currentStep = currentStep.next;\n }\n this.animate.updateDuration();\n }\n\n getLastProps(): any {\n if (this.prev) {\n return this.prev.props || {};\n }\n return this.animate.getStartProps();\n }\n\n setDuration(duration: number, updateDownstream: boolean = true): void {\n this.duration = duration;\n\n // 如果有后续节点,更新所有后续节点的开始时间\n if (updateDownstream) {\n this.updateDownstreamStartTimes();\n }\n }\n\n getDuration(): number {\n return this.duration;\n }\n\n determineInterpolateUpdateFunction(): void {\n // 根据属性类型确定插值更新函数\n // 这里可以进行优化,例如缓存不同类型属性的插值更新函数\n if (!this.props) {\n return;\n }\n\n const funcs: ((key: string, from: number, to: number, ratio: number, step: IStep, target: IGraphic) => void)[] = [];\n this.propKeys.forEach(key => {\n // 普通颜色特殊处理,需要提前解析成number[]\n if (key === 'fill' || key === 'stroke') {\n const from = this.getLastProps()[key];\n const to = this.props[key];\n if (isString(from) && isString(to)) {\n const fromArray = ColorStore.Get(from, ColorType.Color255);\n const toArray = ColorStore.Get(to, ColorType.Color255);\n if (!this.fromParsedProps) {\n this.fromParsedProps = {};\n }\n if (!this.toParsedProps) {\n this.toParsedProps = {};\n }\n this.fromParsedProps[key] = fromArray;\n this.toParsedProps[key] = toArray;\n }\n funcs.push((interpolateUpdateStore as any)[key === 'fill' ? 'fillPure' : 'strokePure']);\n } else if ((interpolateUpdateStore as any)[key]) {\n funcs.push((interpolateUpdateStore as any)[key]);\n } else {\n funcs.push(commonInterpolateUpdate);\n }\n });\n this.interpolateUpdateFunctions = funcs;\n }\n\n setStartTime(time: number, updateDownstream: boolean = true): void {\n this._startTime = time;\n if (updateDownstream) {\n this.updateDownstreamStartTimes();\n }\n }\n\n getStartTime(): number {\n return this._startTime;\n }\n\n onBind(): void {\n // 在第一次绑定到Animate的时候触发\n }\n\n /**\n * 首次运行逻辑\n * 如果跳帧了就不一定会执行\n */\n onFirstRun(): void {\n // 首次运行逻辑\n }\n\n /**\n * 开始执行的时候调用\n * 如果跳帧了就不一定会执行\n */\n onStart(): void {\n if (!this._hasFirstRun) {\n this._hasFirstRun = true;\n // 获取上一步的属性值作为起始值\n this.fromProps = this.getLastProps();\n this.determineInterpolateUpdateFunction();\n this.tryPreventConflict();\n this.trySyncStartProps();\n this.onFirstRun();\n }\n }\n\n protected tryPreventConflict(): void {\n // 屏蔽掉之前动画冲突的属性\n const animate = this.animate;\n const target = this.target;\n target.animates.forEach((a: any) => {\n if (a === animate || a.priority > animate.priority) {\n return;\n }\n const fromProps = a.getStartProps();\n this.propKeys.forEach(key => {\n if (fromProps[key] != null) {\n a.preventAttr(key);\n }\n });\n });\n }\n\n /**\n * 删除自身属性,会直接从props等内容里删除掉\n */\n deleteSelfAttr(key: string): void {\n delete this.props[key];\n // fromProps在动画开始时才会计算,这时可能不在\n this.fromProps && delete this.fromProps[key];\n const index = this.propKeys.indexOf(key);\n if (index !== -1) {\n this.propKeys.splice(index, 1);\n this.interpolateUpdateFunctions?.splice(index, 1);\n }\n }\n\n /**\n * 尝试同步startProps,因为当前animate的startProps仅包含当前animate的信息,不排除过程中有其他animate的干扰\n * 所以为了避免属性突变,需要确保startProps的属性值是最新的\n */\n trySyncStartProps(): void {\n this.propKeys.forEach(key => {\n this.fromProps[key] = this.animate.target.getComputedAttribute(key);\n });\n }\n\n /**\n * 更新执行的时候调用\n * 如果跳帧了就不一定会执行\n */\n update(end: boolean, ratio: number, out: Record<string, any>): void {\n // TODO 需要修复,只有在开始的时候才调用\n this.onStart();\n if (!this.props || !this.propKeys) {\n return;\n }\n // 应用缓动函数\n const easedRatio = this.easing(ratio);\n this.animate.interpolateUpdateFunction\n ? this.animate.interpolateUpdateFunction(this.fromProps, this.props, easedRatio, this, this.target)\n : this.interpolateUpdateFunctions.forEach((func, index) => {\n // 如果这个属性被屏蔽了,直接跳过\n if (!this.animate.validAttr(this.propKeys[index])) {\n return;\n }\n const key = this.propKeys[index];\n const fromValue = this.fromProps[key];\n const toValue = this.props[key];\n func(key, fromValue, toValue, easedRatio, this, this.target);\n });\n this.onUpdate(end, easedRatio, out);\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n // ...\n }\n\n /**\n * 结束执行的时候调用\n * 如果跳帧了就不一定会执行\n */\n onEnd(cb?: (animate: IAnimate, step: IStep) => void): void {\n if (cb) {\n this._endCb = cb;\n } else if (this._endCb) {\n this.target.setAttributes(this.props);\n this._endCb(this.animate, this);\n }\n }\n\n /**\n * 获取结束的属性,包含前序的终值,是merge过的\n * @returns\n */\n getEndProps(): Record<string, any> {\n return this.props;\n }\n\n /**\n * 获取开始的属性,是前序的终值\n * @returns\n */\n getFromProps(): Record<string, any> {\n return this.fromProps;\n }\n\n /**\n * 获取结束的属性,包含前序的终值,是merge过的,同getEndProps\n * @returns\n */\n getMergedEndProps(): Record<string, any> | void {\n return this.getEndProps();\n }\n}\n\nexport class WaitStep extends Step {\n constructor(type: IAnimateStepType, props: Record<string, any>, duration: number, easing: EasingType) {\n super(type, props, duration, easing);\n }\n\n update(end: boolean, ratio: number, out: Record<string, any>): void {\n this.onStart();\n // 其他的不执行\n }\n\n determineInterpolateUpdateFunction(): void {\n return;\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import { EventEmitter } from '@visactor/vutils';
2
+ import type { IStage } from '@visactor/vrender-core';
3
+ import { type ITickHandler, type ITicker, STATUS } from '../intreface/ticker';
4
+ import type { ITimeline } from '../intreface/timeline';
5
+ export declare class DefaultTicker extends EventEmitter implements ITicker {
6
+ protected interval: number;
7
+ protected tickerHandler: ITickHandler;
8
+ protected status: STATUS;
9
+ protected lastFrameTime: number;
10
+ protected lastExecutionTime: number;
11
+ protected tickCounts: number;
12
+ protected stage: IStage;
13
+ timelines: ITimeline[];
14
+ autoStop: boolean;
15
+ constructor(stage: IStage);
16
+ init(): void;
17
+ addTimeline(timeline: ITimeline): void;
18
+ remTimeline(timeline: ITimeline): void;
19
+ getTimelines(): ITimeline[];
20
+ protected initHandler(): void;
21
+ protected setupTickHandler(): boolean;
22
+ setInterval(interval: number): void;
23
+ getInterval(): number;
24
+ setFPS(fps: number): void;
25
+ getFPS(): number;
26
+ tick(interval: number): void;
27
+ tickTo(t: number): void;
28
+ pause(): boolean;
29
+ resume(): boolean;
30
+ ifCanStop(): boolean;
31
+ start(force?: boolean): boolean;
32
+ stop(): void;
33
+ trySyncTickStatus(): void;
34
+ release(): void;
35
+ protected handleTick: (handler: ITickHandler, params?: {
36
+ once?: boolean;
37
+ }) => void;
38
+ protected _handlerTick: () => void;
39
+ }