@visactor/vrender-animate 0.22.4 → 0.22.12

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 (376) hide show
  1. package/cjs/animate-extension.d.ts +12 -5
  2. package/cjs/animate-extension.js +23 -12
  3. package/cjs/animate-extension.js.map +1 -1
  4. package/cjs/animate.d.ts +2 -5
  5. package/cjs/animate.js +23 -18
  6. package/cjs/animate.js.map +1 -1
  7. package/cjs/component/component-animate-extension.d.ts +1 -0
  8. package/cjs/component/component-animate-extension.js +1 -0
  9. package/cjs/component/component-animate-extension.js.map +1 -0
  10. package/cjs/component/component-animator.d.ts +22 -0
  11. package/cjs/component/component-animator.js +67 -0
  12. package/cjs/component/component-animator.js.map +1 -0
  13. package/cjs/component/index.d.ts +1 -0
  14. package/cjs/component/index.js +21 -0
  15. package/cjs/component/index.js.map +1 -0
  16. package/cjs/config/morphing.d.ts +2 -0
  17. package/cjs/config/morphing.js +9 -0
  18. package/cjs/config/morphing.js.map +1 -0
  19. package/cjs/custom/clip-graphic.d.ts +1 -1
  20. package/cjs/custom/clip-graphic.js +2 -2
  21. package/cjs/custom/clip-graphic.js.map +1 -1
  22. package/cjs/custom/clip.d.ts +2 -1
  23. package/cjs/custom/clip.js +9 -1
  24. package/cjs/custom/clip.js.map +1 -1
  25. package/cjs/custom/common.d.ts +1 -3
  26. package/cjs/custom/common.js +21 -17
  27. package/cjs/custom/common.js.map +1 -1
  28. package/cjs/custom/custom-animate.d.ts +7 -3
  29. package/cjs/custom/custom-animate.js +13 -2
  30. package/cjs/custom/custom-animate.js.map +1 -1
  31. package/cjs/custom/fade.d.ts +1 -1
  32. package/cjs/custom/fade.js +7 -2
  33. package/cjs/custom/fade.js.map +1 -1
  34. package/cjs/custom/fromTo.d.ts +10 -0
  35. package/cjs/custom/fromTo.js +42 -0
  36. package/cjs/custom/fromTo.js.map +1 -0
  37. package/cjs/custom/groupFade.d.ts +10 -0
  38. package/cjs/custom/groupFade.js +25 -0
  39. package/cjs/custom/groupFade.js.map +1 -0
  40. package/cjs/custom/growAngle.d.ts +10 -5
  41. package/cjs/custom/growAngle.js +38 -17
  42. package/cjs/custom/growAngle.js.map +1 -1
  43. package/cjs/custom/growCenter.d.ts +1 -2
  44. package/cjs/custom/growCenter.js +16 -10
  45. package/cjs/custom/growCenter.js.map +1 -1
  46. package/cjs/custom/growHeight.d.ts +1 -3
  47. package/cjs/custom/growHeight.js +19 -13
  48. package/cjs/custom/growHeight.js.map +1 -1
  49. package/cjs/custom/growPoints.d.ts +1 -2
  50. package/cjs/custom/growPoints.js +41 -36
  51. package/cjs/custom/growPoints.js.map +1 -1
  52. package/cjs/custom/growRadius.d.ts +4 -5
  53. package/cjs/custom/growRadius.js +22 -18
  54. package/cjs/custom/growRadius.js.map +1 -1
  55. package/cjs/custom/growWidth.d.ts +1 -3
  56. package/cjs/custom/growWidth.js +15 -9
  57. package/cjs/custom/growWidth.js.map +1 -1
  58. package/cjs/custom/input-text.d.ts +1 -2
  59. package/cjs/custom/input-text.js.map +1 -1
  60. package/cjs/custom/label-item-animate.d.ts +7 -0
  61. package/cjs/custom/label-item-animate.js +221 -0
  62. package/cjs/custom/label-item-animate.js.map +1 -0
  63. package/cjs/custom/morphing.d.ts +51 -0
  64. package/cjs/custom/morphing.js +298 -0
  65. package/cjs/custom/morphing.js.map +1 -0
  66. package/cjs/custom/motionPath.d.ts +21 -0
  67. package/cjs/custom/motionPath.js +31 -0
  68. package/cjs/custom/motionPath.js.map +1 -0
  69. package/cjs/custom/move.d.ts +96 -0
  70. package/cjs/custom/move.js +133 -0
  71. package/cjs/custom/move.js.map +1 -0
  72. package/cjs/custom/number.d.ts +1 -2
  73. package/cjs/custom/number.js.map +1 -1
  74. package/cjs/custom/poptip-animate.d.ts +7 -0
  75. package/cjs/custom/poptip-animate.js +109 -0
  76. package/cjs/custom/poptip-animate.js.map +1 -0
  77. package/cjs/custom/register.d.ts +27 -0
  78. package/cjs/custom/register.js +418 -3
  79. package/cjs/custom/register.js.map +1 -1
  80. package/cjs/custom/richtext/input-richtext.d.ts +35 -0
  81. package/cjs/custom/richtext/input-richtext.js +80 -0
  82. package/cjs/custom/richtext/input-richtext.js.map +1 -0
  83. package/cjs/custom/richtext/output-richtext.d.ts +37 -0
  84. package/cjs/custom/richtext/output-richtext.js +94 -0
  85. package/cjs/custom/richtext/output-richtext.js.map +1 -0
  86. package/cjs/custom/richtext/slide-out-richtext.d.ts +38 -0
  87. package/cjs/custom/richtext/slide-out-richtext.js +146 -0
  88. package/cjs/custom/richtext/slide-out-richtext.js.map +1 -0
  89. package/cjs/custom/richtext/slide-richtext.d.ts +36 -0
  90. package/cjs/custom/richtext/slide-richtext.js +144 -0
  91. package/cjs/custom/richtext/slide-richtext.js.map +1 -0
  92. package/cjs/custom/rotate.d.ts +33 -0
  93. package/cjs/custom/rotate.js +79 -0
  94. package/cjs/custom/rotate.js.map +1 -0
  95. package/cjs/custom/scale.d.ts +6 -2
  96. package/cjs/custom/scale.js +32 -17
  97. package/cjs/custom/scale.js.map +1 -1
  98. package/cjs/custom/sphere.d.ts +2 -1
  99. package/cjs/custom/sphere.js +14 -5
  100. package/cjs/custom/sphere.js.map +1 -1
  101. package/cjs/custom/state.d.ts +1 -1
  102. package/cjs/custom/state.js +1 -1
  103. package/cjs/custom/state.js.map +1 -1
  104. package/cjs/custom/story.d.ts +196 -0
  105. package/cjs/custom/story.js +497 -0
  106. package/cjs/custom/story.js.map +1 -0
  107. package/cjs/custom/streamLight.d.ts +27 -0
  108. package/cjs/custom/streamLight.js +161 -0
  109. package/cjs/custom/streamLight.js.map +1 -0
  110. package/cjs/custom/tag-points.d.ts +2 -3
  111. package/cjs/custom/tag-points.js +20 -4
  112. package/cjs/custom/tag-points.js.map +1 -1
  113. package/cjs/custom/update.d.ts +2 -2
  114. package/cjs/custom/update.js +10 -2
  115. package/cjs/custom/update.js.map +1 -1
  116. package/cjs/executor/animate-executor.d.ts +7 -6
  117. package/cjs/executor/animate-executor.js +118 -62
  118. package/cjs/executor/animate-executor.js.map +1 -1
  119. package/cjs/executor/executor.d.ts +9 -3
  120. package/cjs/executor/executor.js.map +1 -1
  121. package/cjs/index.d.ts +8 -8
  122. package/cjs/index.js +50 -18
  123. package/cjs/index.js.map +1 -1
  124. package/cjs/interpolate/store.d.ts +6 -2
  125. package/cjs/interpolate/store.js +13 -2
  126. package/cjs/interpolate/store.js.map +1 -1
  127. package/cjs/register.js +1 -5
  128. package/cjs/register.js.map +1 -1
  129. package/cjs/state/animation-state.d.ts +20 -2
  130. package/cjs/state/animation-state.js +48 -4
  131. package/cjs/state/animation-state.js.map +1 -1
  132. package/cjs/state/animation-states-registry.js +18 -0
  133. package/cjs/state/animation-states-registry.js.map +1 -1
  134. package/cjs/state/graphic-extension.d.ts +7 -1
  135. package/cjs/state/graphic-extension.js +20 -0
  136. package/cjs/state/graphic-extension.js.map +1 -1
  137. package/cjs/step.d.ts +7 -4
  138. package/cjs/step.js +33 -15
  139. package/cjs/step.js.map +1 -1
  140. package/cjs/ticker/default-ticker.d.ts +12 -7
  141. package/cjs/ticker/default-ticker.js +38 -33
  142. package/cjs/ticker/default-ticker.js.map +1 -1
  143. package/cjs/ticker/manual-ticker.d.ts +6 -1
  144. package/cjs/ticker/manual-ticker.js +26 -4
  145. package/cjs/ticker/manual-ticker.js.map +1 -1
  146. package/cjs/timeline.d.ts +14 -7
  147. package/cjs/timeline.js +31 -18
  148. package/cjs/timeline.js.map +1 -1
  149. package/cjs/utils/transform.d.ts +2 -0
  150. package/cjs/utils/transform.js +10 -0
  151. package/cjs/utils/transform.js.map +1 -0
  152. package/dist/index.es.js +3765 -527
  153. package/es/animate-extension.d.ts +12 -5
  154. package/es/animate-extension.js +24 -11
  155. package/es/animate-extension.js.map +1 -1
  156. package/es/animate.d.ts +2 -5
  157. package/es/animate.js +14 -11
  158. package/es/animate.js.map +1 -1
  159. package/es/component/component-animate-extension.d.ts +1 -0
  160. package/es/component/component-animate-extension.js +1 -0
  161. package/es/component/component-animate-extension.js.map +1 -0
  162. package/es/component/component-animator.d.ts +22 -0
  163. package/es/component/component-animator.js +59 -0
  164. package/es/component/component-animator.js.map +1 -0
  165. package/es/component/index.d.ts +1 -0
  166. package/es/component/index.js +2 -0
  167. package/es/component/index.js.map +1 -0
  168. package/es/config/morphing.d.ts +2 -0
  169. package/es/config/morphing.js +5 -0
  170. package/es/config/morphing.js.map +1 -0
  171. package/es/custom/clip-graphic.d.ts +1 -1
  172. package/es/custom/clip-graphic.js +2 -2
  173. package/es/custom/clip-graphic.js.map +1 -1
  174. package/es/custom/clip.d.ts +2 -1
  175. package/es/custom/clip.js +9 -1
  176. package/es/custom/clip.js.map +1 -1
  177. package/es/custom/common.d.ts +1 -3
  178. package/es/custom/common.js +21 -17
  179. package/es/custom/common.js.map +1 -1
  180. package/es/custom/custom-animate.d.ts +7 -3
  181. package/es/custom/custom-animate.js +10 -1
  182. package/es/custom/custom-animate.js.map +1 -1
  183. package/es/custom/fade.d.ts +1 -1
  184. package/es/custom/fade.js +7 -2
  185. package/es/custom/fade.js.map +1 -1
  186. package/es/custom/fromTo.d.ts +10 -0
  187. package/es/custom/fromTo.js +34 -0
  188. package/es/custom/fromTo.js.map +1 -0
  189. package/es/custom/groupFade.d.ts +10 -0
  190. package/es/custom/groupFade.js +15 -0
  191. package/es/custom/groupFade.js.map +1 -0
  192. package/es/custom/growAngle.d.ts +10 -5
  193. package/es/custom/growAngle.js +39 -15
  194. package/es/custom/growAngle.js.map +1 -1
  195. package/es/custom/growCenter.d.ts +1 -2
  196. package/es/custom/growCenter.js +16 -10
  197. package/es/custom/growCenter.js.map +1 -1
  198. package/es/custom/growHeight.d.ts +1 -3
  199. package/es/custom/growHeight.js +20 -14
  200. package/es/custom/growHeight.js.map +1 -1
  201. package/es/custom/growPoints.d.ts +1 -2
  202. package/es/custom/growPoints.js +40 -36
  203. package/es/custom/growPoints.js.map +1 -1
  204. package/es/custom/growRadius.d.ts +4 -5
  205. package/es/custom/growRadius.js +22 -16
  206. package/es/custom/growRadius.js.map +1 -1
  207. package/es/custom/growWidth.d.ts +1 -3
  208. package/es/custom/growWidth.js +16 -10
  209. package/es/custom/growWidth.js.map +1 -1
  210. package/es/custom/input-text.d.ts +1 -2
  211. package/es/custom/input-text.js.map +1 -1
  212. package/es/custom/label-item-animate.d.ts +7 -0
  213. package/es/custom/label-item-animate.js +215 -0
  214. package/es/custom/label-item-animate.js.map +1 -0
  215. package/es/custom/morphing.d.ts +51 -0
  216. package/es/custom/morphing.js +289 -0
  217. package/es/custom/morphing.js.map +1 -0
  218. package/es/custom/motionPath.d.ts +21 -0
  219. package/es/custom/motionPath.js +23 -0
  220. package/es/custom/motionPath.js.map +1 -0
  221. package/es/custom/move.d.ts +96 -0
  222. package/es/custom/move.js +118 -0
  223. package/es/custom/move.js.map +1 -0
  224. package/es/custom/number.d.ts +1 -2
  225. package/es/custom/number.js.map +1 -1
  226. package/es/custom/poptip-animate.d.ts +7 -0
  227. package/es/custom/poptip-animate.js +103 -0
  228. package/es/custom/poptip-animate.js.map +1 -0
  229. package/es/custom/register.d.ts +27 -0
  230. package/es/custom/register.js +48 -1
  231. package/es/custom/register.js.map +1 -1
  232. package/es/custom/richtext/input-richtext.d.ts +35 -0
  233. package/es/custom/richtext/input-richtext.js +74 -0
  234. package/es/custom/richtext/input-richtext.js.map +1 -0
  235. package/es/custom/richtext/output-richtext.d.ts +37 -0
  236. package/es/custom/richtext/output-richtext.js +88 -0
  237. package/es/custom/richtext/output-richtext.js.map +1 -0
  238. package/es/custom/richtext/slide-out-richtext.d.ts +38 -0
  239. package/es/custom/richtext/slide-out-richtext.js +140 -0
  240. package/es/custom/richtext/slide-out-richtext.js.map +1 -0
  241. package/es/custom/richtext/slide-richtext.d.ts +36 -0
  242. package/es/custom/richtext/slide-richtext.js +138 -0
  243. package/es/custom/richtext/slide-richtext.js.map +1 -0
  244. package/es/custom/rotate.d.ts +33 -0
  245. package/es/custom/rotate.js +65 -0
  246. package/es/custom/rotate.js.map +1 -0
  247. package/es/custom/scale.d.ts +6 -2
  248. package/es/custom/scale.js +32 -17
  249. package/es/custom/scale.js.map +1 -1
  250. package/es/custom/sphere.d.ts +2 -1
  251. package/es/custom/sphere.js +14 -5
  252. package/es/custom/sphere.js.map +1 -1
  253. package/es/custom/state.d.ts +1 -1
  254. package/es/custom/state.js +1 -1
  255. package/es/custom/state.js.map +1 -1
  256. package/es/custom/story.d.ts +196 -0
  257. package/es/custom/story.js +468 -0
  258. package/es/custom/story.js.map +1 -0
  259. package/es/custom/streamLight.d.ts +27 -0
  260. package/es/custom/streamLight.js +157 -0
  261. package/es/custom/streamLight.js.map +1 -0
  262. package/es/custom/tag-points.d.ts +2 -3
  263. package/es/custom/tag-points.js +21 -5
  264. package/es/custom/tag-points.js.map +1 -1
  265. package/es/custom/update.d.ts +2 -2
  266. package/es/custom/update.js +10 -2
  267. package/es/custom/update.js.map +1 -1
  268. package/es/executor/animate-executor.d.ts +7 -6
  269. package/es/executor/animate-executor.js +116 -61
  270. package/es/executor/animate-executor.js.map +1 -1
  271. package/es/executor/executor.d.ts +9 -3
  272. package/es/executor/executor.js.map +1 -1
  273. package/es/index.d.ts +8 -8
  274. package/es/index.js +10 -12
  275. package/es/index.js.map +1 -1
  276. package/es/interpolate/store.d.ts +6 -2
  277. package/es/interpolate/store.js +13 -3
  278. package/es/interpolate/store.js.map +1 -1
  279. package/es/register.js +0 -8
  280. package/es/register.js.map +1 -1
  281. package/es/state/animation-state.d.ts +20 -2
  282. package/es/state/animation-state.js +48 -2
  283. package/es/state/animation-state.js.map +1 -1
  284. package/es/state/animation-states-registry.js +18 -0
  285. package/es/state/animation-states-registry.js.map +1 -1
  286. package/es/state/graphic-extension.d.ts +7 -1
  287. package/es/state/graphic-extension.js +20 -0
  288. package/es/state/graphic-extension.js.map +1 -1
  289. package/es/step.d.ts +7 -4
  290. package/es/step.js +34 -16
  291. package/es/step.js.map +1 -1
  292. package/es/ticker/default-ticker.d.ts +12 -7
  293. package/es/ticker/default-ticker.js +30 -27
  294. package/es/ticker/default-ticker.js.map +1 -1
  295. package/es/ticker/manual-ticker.d.ts +6 -1
  296. package/es/ticker/manual-ticker.js +27 -3
  297. package/es/ticker/manual-ticker.js.map +1 -1
  298. package/es/timeline.d.ts +14 -7
  299. package/es/timeline.js +33 -18
  300. package/es/timeline.js.map +1 -1
  301. package/es/utils/transform.d.ts +2 -0
  302. package/es/utils/transform.js +4 -0
  303. package/es/utils/transform.js.map +1 -0
  304. package/package.json +16 -16
  305. package/cjs/custom/group-fade.d.ts +0 -16
  306. package/cjs/custom/group-fade.js +0 -66
  307. package/cjs/custom/group-fade.js.map +0 -1
  308. package/cjs/custom/scale-in.d.ts +0 -13
  309. package/cjs/custom/scale-in.js +0 -57
  310. package/cjs/custom/scale-in.js.map +0 -1
  311. package/cjs/interpolate/executor.d.ts +0 -66
  312. package/cjs/interpolate/executor.js +0 -6
  313. package/cjs/interpolate/executor.js.map +0 -1
  314. package/cjs/intreface/animate.d.ts +0 -91
  315. package/cjs/intreface/animate.js +0 -10
  316. package/cjs/intreface/animate.js.map +0 -1
  317. package/cjs/intreface/easing.d.ts +0 -3
  318. package/cjs/intreface/easing.js +0 -6
  319. package/cjs/intreface/easing.js.map +0 -1
  320. package/cjs/intreface/state.d.ts +0 -35
  321. package/cjs/intreface/state.js +0 -6
  322. package/cjs/intreface/state.js.map +0 -1
  323. package/cjs/intreface/ticker.d.ts +0 -37
  324. package/cjs/intreface/ticker.js +0 -10
  325. package/cjs/intreface/ticker.js.map +0 -1
  326. package/cjs/intreface/timeline.d.ts +0 -17
  327. package/cjs/intreface/timeline.js +0 -6
  328. package/cjs/intreface/timeline.js.map +0 -1
  329. package/cjs/intreface/type.d.ts +0 -13
  330. package/cjs/intreface/type.js +0 -15
  331. package/cjs/intreface/type.js.map +0 -1
  332. package/cjs/state/animation-state-machine.d.ts +0 -22
  333. package/cjs/state/animation-state-machine.js +0 -53
  334. package/cjs/state/animation-state-machine.js.map +0 -1
  335. package/cjs/state/animation-state-queue.d.ts +0 -24
  336. package/cjs/state/animation-state-queue.js +0 -66
  337. package/cjs/state/animation-state-queue.js.map +0 -1
  338. package/cjs/state/animation-state-registry.d.ts +0 -14
  339. package/cjs/state/animation-state-registry.js +0 -53
  340. package/cjs/state/animation-state-registry.js.map +0 -1
  341. package/es/custom/group-fade.d.ts +0 -16
  342. package/es/custom/group-fade.js +0 -56
  343. package/es/custom/group-fade.js.map +0 -1
  344. package/es/custom/scale-in.d.ts +0 -13
  345. package/es/custom/scale-in.js +0 -49
  346. package/es/custom/scale-in.js.map +0 -1
  347. package/es/interpolate/executor.d.ts +0 -66
  348. package/es/interpolate/executor.js +0 -2
  349. package/es/interpolate/executor.js.map +0 -1
  350. package/es/intreface/animate.d.ts +0 -91
  351. package/es/intreface/animate.js +0 -6
  352. package/es/intreface/animate.js.map +0 -1
  353. package/es/intreface/easing.d.ts +0 -3
  354. package/es/intreface/easing.js +0 -2
  355. package/es/intreface/easing.js.map +0 -1
  356. package/es/intreface/state.d.ts +0 -35
  357. package/es/intreface/state.js +0 -2
  358. package/es/intreface/state.js.map +0 -1
  359. package/es/intreface/ticker.d.ts +0 -37
  360. package/es/intreface/ticker.js +0 -6
  361. package/es/intreface/ticker.js.map +0 -1
  362. package/es/intreface/timeline.d.ts +0 -17
  363. package/es/intreface/timeline.js +0 -2
  364. package/es/intreface/timeline.js.map +0 -1
  365. package/es/intreface/type.d.ts +0 -13
  366. package/es/intreface/type.js +0 -14
  367. package/es/intreface/type.js.map +0 -1
  368. package/es/state/animation-state-machine.d.ts +0 -22
  369. package/es/state/animation-state-machine.js +0 -47
  370. package/es/state/animation-state-machine.js.map +0 -1
  371. package/es/state/animation-state-queue.d.ts +0 -24
  372. package/es/state/animation-state-queue.js +0 -58
  373. package/es/state/animation-state-queue.js.map +0 -1
  374. package/es/state/animation-state-registry.d.ts +0 -14
  375. package/es/state/animation-state-registry.js +0 -45
  376. package/es/state/animation-state-registry.js.map +0 -1
@@ -0,0 +1,37 @@
1
+ import { ACustomAnimate } from '../custom-animate';
2
+ import type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';
3
+ export declare class OutputRichText extends ACustomAnimate<{
4
+ textConfig: IRichTextCharacter[];
5
+ }> {
6
+ valid: boolean;
7
+ private fromTextConfig;
8
+ private toTextConfig;
9
+ private originalTextConfig;
10
+ private showCursor;
11
+ private cursorChar;
12
+ private blinkCursor;
13
+ private beforeText;
14
+ private afterText;
15
+ private fadeOutChars;
16
+ private fadeOutDuration;
17
+ private direction;
18
+ constructor(from: {
19
+ textConfig: IRichTextCharacter[];
20
+ }, to: {
21
+ textConfig: IRichTextCharacter[];
22
+ }, duration: number, easing: EasingType, params?: {
23
+ showCursor?: boolean;
24
+ cursorChar?: string;
25
+ blinkCursor?: boolean;
26
+ beforeText?: string;
27
+ afterText?: string;
28
+ fadeOutChars?: boolean;
29
+ fadeOutDuration?: number;
30
+ direction?: 'forward' | 'backward';
31
+ });
32
+ onFirstRun(): void;
33
+ onEnd(cb?: (animate: IAnimate, step: IStep) => void): void;
34
+ onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
35
+ private applyFadeEffect;
36
+ private addCursor;
37
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.OutputRichText = void 0;
6
+
7
+ const custom_animate_1 = require("../custom-animate"), vrender_core_1 = require("@visactor/vrender-core");
8
+
9
+ class OutputRichText extends custom_animate_1.ACustomAnimate {
10
+ constructor(from, to, duration, easing, params) {
11
+ super(from, to, duration, easing, params), this.fromTextConfig = [], this.toTextConfig = [],
12
+ this.originalTextConfig = [], this.showCursor = !1, this.cursorChar = "|", this.blinkCursor = !0,
13
+ this.beforeText = "", this.afterText = "", this.fadeOutChars = !1, this.fadeOutDuration = .3,
14
+ this.direction = "backward", void 0 !== (null == params ? void 0 : params.showCursor) && (this.showCursor = params.showCursor),
15
+ void 0 !== (null == params ? void 0 : params.cursorChar) && (this.cursorChar = params.cursorChar),
16
+ void 0 !== (null == params ? void 0 : params.blinkCursor) && (this.blinkCursor = params.blinkCursor),
17
+ void 0 !== (null == params ? void 0 : params.beforeText) && (this.beforeText = params.beforeText),
18
+ void 0 !== (null == params ? void 0 : params.afterText) && (this.afterText = params.afterText),
19
+ void 0 !== (null == params ? void 0 : params.fadeOutChars) && (this.fadeOutChars = params.fadeOutChars),
20
+ void 0 !== (null == params ? void 0 : params.fadeOutDuration) && (this.fadeOutDuration = params.fadeOutDuration),
21
+ void 0 !== (null == params ? void 0 : params.direction) && (this.direction = params.direction),
22
+ this.propKeys = [ "textConfig" ];
23
+ }
24
+ onFirstRun() {
25
+ const fromProps = this.getLastProps(), toProps = this.getEndProps();
26
+ this.originalTextConfig = fromProps.textConfig ? [ ...fromProps.textConfig ] : [],
27
+ this.valid = !0, this.originalTextConfig && 0 !== this.originalTextConfig.length ? (this.fromTextConfig = vrender_core_1.RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig),
28
+ this.toTextConfig = toProps.textConfig && toProps.textConfig.length > 0 ? vrender_core_1.RichText.TransformTextConfig2SingleCharacter(toProps.textConfig) : []) : this.valid = !1;
29
+ }
30
+ onEnd(cb) {
31
+ super.onEnd(cb), cb || (this.toTextConfig.length > 0 ? this.target.setAttribute("textConfig", this.toTextConfig) : this.target.setAttribute("textConfig", []));
32
+ }
33
+ onUpdate(end, ratio, out) {
34
+ if (!this.valid) return;
35
+ const fromItems = this.fromTextConfig.length, maxTextHideRatio = this.fadeOutChars ? 1 - this.fadeOutDuration : 1;
36
+ let displayedLength;
37
+ if ("forward" === this.direction) {
38
+ if (this.fadeOutChars) {
39
+ const adjustedRatio = Math.min(1, ratio / maxTextHideRatio);
40
+ displayedLength = Math.round(fromItems * (1 - adjustedRatio));
41
+ } else displayedLength = Math.round(fromItems * (1 - ratio));
42
+ let currentTextConfig = "forward" === this.direction ? this.fromTextConfig.slice(fromItems - displayedLength) : this.fromTextConfig.slice(0, displayedLength);
43
+ this.fadeOutChars && (currentTextConfig = this.applyFadeEffect(currentTextConfig, ratio, fromItems, displayedLength)),
44
+ this.showCursor && displayedLength > 0 && (currentTextConfig = this.addCursor(currentTextConfig, ratio)),
45
+ this.target.setAttribute("textConfig", currentTextConfig);
46
+ } else {
47
+ if (this.fadeOutChars) {
48
+ const adjustedRatio = Math.min(1, ratio / maxTextHideRatio);
49
+ displayedLength = Math.round(fromItems * (1 - adjustedRatio));
50
+ } else displayedLength = Math.round(fromItems * (1 - ratio));
51
+ let currentTextConfig = this.fromTextConfig.slice(0, displayedLength);
52
+ this.fadeOutChars && (currentTextConfig = this.applyFadeEffect(currentTextConfig, ratio, fromItems, displayedLength)),
53
+ this.showCursor && displayedLength > 0 && (currentTextConfig = this.addCursor(currentTextConfig, ratio)),
54
+ this.target.setAttribute("textConfig", currentTextConfig);
55
+ }
56
+ }
57
+ applyFadeEffect(textConfig, ratio, totalItems, displayedLength) {
58
+ let fadeIndex;
59
+ fadeIndex = "forward" === this.direction ? totalItems - displayedLength : displayedLength;
60
+ const fadeProgress = (ratio - (1 - this.fadeOutDuration)) / this.fadeOutDuration, fadeOpacity = Math.max(0, 1 - Math.min(1, fadeProgress));
61
+ return textConfig.map(((item, index) => {
62
+ if ("forward" === this.direction) {
63
+ if (0 === index && "text" in item) return Object.assign(Object.assign({}, item), {
64
+ opacity: fadeOpacity
65
+ });
66
+ } else if (index === textConfig.length - 1 && "text" in item) return Object.assign(Object.assign({}, item), {
67
+ opacity: fadeOpacity
68
+ });
69
+ return item;
70
+ }));
71
+ }
72
+ addCursor(textConfig, ratio) {
73
+ let shouldShowCursor = !0;
74
+ if (this.blinkCursor) {
75
+ const blinkRate = .1;
76
+ shouldShowCursor = Math.floor(ratio / blinkRate) % 2 == 0;
77
+ }
78
+ if (shouldShowCursor && textConfig.length > 0) {
79
+ const cursorIndex = "forward" === this.direction ? 0 : textConfig.length - 1, cursorItem = textConfig[cursorIndex];
80
+ if ("text" in cursorItem) {
81
+ const result = [ ...textConfig ];
82
+ return "forward" === this.direction ? result[cursorIndex] = Object.assign(Object.assign({}, cursorItem), {
83
+ text: this.cursorChar + String(cursorItem.text)
84
+ }) : result[cursorIndex] = Object.assign(Object.assign({}, cursorItem), {
85
+ text: String(cursorItem.text) + this.cursorChar
86
+ }), result;
87
+ }
88
+ }
89
+ return textConfig;
90
+ }
91
+ }
92
+
93
+ exports.OutputRichText = OutputRichText;
94
+ //# sourceMappingURL=output-richtext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/custom/richtext/output-richtext.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,yDAAkD;AASlD,MAAa,cAAe,SAAQ,+BAAoD;IAetF,YACE,IAA0C,EAC1C,EAAwC,EACxC,QAAgB,EAChB,MAAkB,EAClB,MASC;QAED,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QA5BpC,mBAAc,GAAyB,EAAE,CAAC;QAC1C,iBAAY,GAAyB,EAAE,CAAC;QACxC,uBAAkB,GAAyB,EAAE,CAAC;QAC9C,eAAU,GAAY,KAAK,CAAC;QAC5B,eAAU,GAAW,GAAG,CAAC;QACzB,gBAAW,GAAY,IAAI,CAAC;QAC5B,eAAU,GAAW,EAAE,CAAC;QACxB,cAAS,GAAW,EAAE,CAAC;QACvB,iBAAY,GAAY,KAAK,CAAC;QAC9B,oBAAe,GAAW,GAAG,CAAC;QAC9B,cAAS,GAA2B,UAAU,CAAC;QAqBrD,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,MAAK,SAAS,EAAE;YACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;SACrC;QACD,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,MAAK,SAAS,EAAE;YACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;SACrC;QACD,IAA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type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';\nimport { RichText } from '@visactor/vrender-core';\n\n/**\n * 富文本退出动画,实现类似打字机的字符逐个消失效果\n * 支持通过beforeText和afterText参数添加前缀和后缀\n * 支持通过showCursor参数显示光标,cursorChar自定义光标字符\n * 支持通过fadeOutChars参数开启字符透明度渐变效果\n * 支持通过direction参数控制消失方向(从头到尾或从尾到头)\n */\nexport class OutputRichText extends ACustomAnimate<{ textConfig: IRichTextCharacter[] }> {\n declare valid: boolean;\n\n private fromTextConfig: IRichTextCharacter[] = [];\n private toTextConfig: IRichTextCharacter[] = [];\n private originalTextConfig: IRichTextCharacter[] = [];\n private showCursor: boolean = false;\n private cursorChar: string = '|';\n private blinkCursor: boolean = true;\n private beforeText: string = '';\n private afterText: string = '';\n private fadeOutChars: boolean = false;\n private fadeOutDuration: number = 0.3; // 透明度渐变持续时间,以动画总时长的比例表示\n private direction: 'forward' | 'backward' = 'backward'; // 字符消失方向,默认从尾到头(backward)\n\n constructor(\n from: { textConfig: IRichTextCharacter[] },\n to: { textConfig: IRichTextCharacter[] },\n duration: number,\n easing: EasingType,\n params?: {\n showCursor?: boolean;\n cursorChar?: string;\n blinkCursor?: boolean;\n beforeText?: string;\n afterText?: string;\n fadeOutChars?: boolean;\n fadeOutDuration?: number;\n direction?: 'forward' | 'backward';\n }\n ) {\n super(from, to, duration, easing, params);\n\n // 配置光标相关选项\n if (params?.showCursor !== undefined) {\n this.showCursor = params.showCursor;\n }\n if (params?.cursorChar !== undefined) {\n this.cursorChar = params.cursorChar;\n }\n if (params?.blinkCursor !== undefined) {\n this.blinkCursor = params.blinkCursor;\n }\n\n // 配置前缀和后缀文本\n if (params?.beforeText !== undefined) {\n this.beforeText = params.beforeText;\n }\n if (params?.afterText !== undefined) {\n this.afterText = params.afterText;\n }\n\n // 配置字符透明度渐变效果\n if (params?.fadeOutChars !== undefined) {\n this.fadeOutChars = params.fadeOutChars;\n }\n if (params?.fadeOutDuration !== undefined) {\n this.fadeOutDuration = params.fadeOutDuration;\n }\n\n // 配置方向\n if (params?.direction !== undefined) {\n this.direction = params.direction;\n }\n\n this.propKeys = ['textConfig'];\n }\n\n onFirstRun(): void {\n const fromProps = this.getLastProps();\n const toProps = this.getEndProps();\n\n // 存储原始配置(这里是起始状态,显示所有文本)\n this.originalTextConfig = fromProps.textConfig ? [...fromProps.textConfig] : [];\n\n // 初始化解析结果\n this.valid = true;\n\n // 确保from不为空\n if (!this.originalTextConfig || this.originalTextConfig.length === 0) {\n this.valid = false;\n return;\n }\n\n // 将文本拆分为单个字符,使用RichText的静态方法\n this.fromTextConfig = RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig);\n\n // 目标状态是空文本(或指定的目标)\n this.toTextConfig =\n toProps.textConfig && toProps.textConfig.length > 0\n ? RichText.TransformTextConfig2SingleCharacter(toProps.textConfig)\n : [];\n }\n\n onEnd(cb?: (animate: IAnimate, step: IStep) => void): void {\n super.onEnd(cb);\n if (!cb) {\n // 动画结束时,应用最终textConfig(通常是空的或特定的toTextConfig)\n if (this.toTextConfig.length > 0) {\n this.target.setAttribute('textConfig', this.toTextConfig);\n } else {\n this.target.setAttribute('textConfig', []);\n }\n }\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this.valid) {\n return;\n }\n\n // 获取当前应该显示的字符\n const fromItems = this.fromTextConfig.length;\n\n // 计算文本显示比例上限 - 如果有渐变效果,需要为尾部字符的渐变留出时间\n const maxTextHideRatio = this.fadeOutChars ? 1 - this.fadeOutDuration : 1;\n\n // 根据方向确定字符消失的顺序\n let displayedLength: number;\n\n if (this.direction === 'forward') {\n // 从前往后消失(类似于正向打字效果)\n if (this.fadeOutChars) {\n // 当ratio达到maxTextHideRatio时,应该已经隐藏全部文本\n const adjustedRatio = Math.min(1, ratio / maxTextHideRatio);\n displayedLength = Math.round(fromItems * (1 - adjustedRatio));\n } else {\n // 无渐变效果时,正常隐藏\n displayedLength = Math.round(fromItems * (1 - ratio));\n }\n\n // 构建从头开始删除的文本配置\n let currentTextConfig =\n this.direction === 'forward'\n ? this.fromTextConfig.slice(fromItems - displayedLength) // 从头开始隐藏,保留尾部\n : this.fromTextConfig.slice(0, displayedLength); // 从尾开始隐藏,保留头部\n\n // 应用透明度渐变效果\n if (this.fadeOutChars) {\n currentTextConfig = this.applyFadeEffect(currentTextConfig, ratio, fromItems, displayedLength);\n }\n\n // 如果启用了光标\n if (this.showCursor && displayedLength > 0) {\n currentTextConfig = this.addCursor(currentTextConfig, ratio);\n }\n\n // 更新富文本的textConfig属性\n this.target.setAttribute('textConfig', currentTextConfig);\n } else {\n // 从后往前消失(类似于退格删除效果)\n if (this.fadeOutChars) {\n // 当ratio达到maxTextHideRatio时,应该已经隐藏全部文本\n const adjustedRatio = Math.min(1, ratio / maxTextHideRatio);\n displayedLength = Math.round(fromItems * (1 - adjustedRatio));\n } else {\n // 无渐变效果时,正常隐藏\n displayedLength = Math.round(fromItems * (1 - ratio));\n }\n\n // 构建从尾开始删除的文本配置\n let currentTextConfig = this.fromTextConfig.slice(0, displayedLength);\n\n // 应用透明度渐变效果\n if (this.fadeOutChars) {\n currentTextConfig = this.applyFadeEffect(currentTextConfig, ratio, fromItems, displayedLength);\n }\n\n // 如果启用了光标\n if (this.showCursor && displayedLength > 0) {\n currentTextConfig = this.addCursor(currentTextConfig, ratio);\n }\n\n // 更新富文本的textConfig属性\n this.target.setAttribute('textConfig', currentTextConfig);\n }\n }\n\n // 应用透明度渐变效果\n private applyFadeEffect(\n textConfig: IRichTextCharacter[],\n ratio: number,\n totalItems: number,\n displayedLength: number\n ): IRichTextCharacter[] {\n // 计算边界字符的索引,这是正在淡出的字符\n let fadeIndex: number;\n\n if (this.direction === 'forward') {\n // 从前往后消失,当前正在淡出的是第displayedLength个字符\n fadeIndex = totalItems - displayedLength;\n } else {\n // 从后往前消失,当前正在淡出的是第displayedLength个字符\n fadeIndex = displayedLength;\n }\n\n // 计算边界字符的透明度\n const fadeProgress = (ratio - (1 - this.fadeOutDuration)) / this.fadeOutDuration;\n const fadeOpacity = Math.max(0, 1 - Math.min(1, fadeProgress));\n\n return textConfig.map((item, index) => {\n if (this.direction === 'forward') {\n // 从前往后消失,第一个字符最先淡出\n if (index === 0 && 'text' in item) {\n return {\n ...item,\n opacity: fadeOpacity\n };\n }\n } else {\n // 从后往前消失,最后一个字符最先淡出\n if (index === textConfig.length - 1 && 'text' in item) {\n return {\n ...item,\n opacity: fadeOpacity\n };\n }\n }\n return item;\n });\n }\n\n // 添加光标\n private addCursor(textConfig: IRichTextCharacter[], ratio: number): IRichTextCharacter[] {\n // 判断是否应该显示光标\n let shouldShowCursor = true;\n\n if (this.blinkCursor) {\n // 闪烁效果:在动画期间,光标每半个周期闪烁一次\n const blinkRate = 0.1; // 光标闪烁频率(每10%动画进度闪烁一次)\n shouldShowCursor = Math.floor(ratio / blinkRate) % 2 === 0;\n }\n\n if (shouldShowCursor && textConfig.length > 0) {\n // 确定光标位置(根据direction)\n const cursorIndex = this.direction === 'forward' ? 0 : textConfig.length - 1;\n const cursorItem = textConfig[cursorIndex];\n\n if ('text' in cursorItem) {\n // 复制数组\n const result = [...textConfig];\n\n if (this.direction === 'forward') {\n // 光标在前面\n result[cursorIndex] = {\n ...cursorItem,\n text: this.cursorChar + String(cursorItem.text)\n };\n } else {\n // 光标在后面\n result[cursorIndex] = {\n ...cursorItem,\n text: String(cursorItem.text) + this.cursorChar\n };\n }\n\n return result;\n }\n }\n\n return textConfig;\n }\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { ACustomAnimate } from '../custom-animate';
2
+ import type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';
3
+ export declare class SlideOutRichText extends ACustomAnimate<{
4
+ textConfig: IRichTextCharacter[];
5
+ }> {
6
+ valid: boolean;
7
+ private fromTextConfig;
8
+ private toTextConfig;
9
+ private originalTextConfig;
10
+ private singleCharConfig;
11
+ private fadeOutDuration;
12
+ private slideDirection;
13
+ private slideDistance;
14
+ private wordByWord;
15
+ private wordRegex;
16
+ private wordGroups;
17
+ private reverseOrder;
18
+ constructor(from: {
19
+ textConfig: IRichTextCharacter[];
20
+ }, to: {
21
+ textConfig: IRichTextCharacter[];
22
+ }, duration: number, easing: EasingType, params?: {
23
+ fadeOutDuration?: number;
24
+ slideDirection?: 'up' | 'down' | 'left' | 'right';
25
+ slideDistance?: number;
26
+ wordByWord?: boolean;
27
+ wordRegex?: RegExp;
28
+ reverseOrder?: boolean;
29
+ });
30
+ onFirstRun(): void;
31
+ private calculateWordGroups;
32
+ private getTargetDx;
33
+ private getTargetDy;
34
+ onEnd(cb?: (animate: IAnimate, step: IStep) => void): void;
35
+ onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
36
+ private updateByWord;
37
+ private updateByCharacter;
38
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.SlideOutRichText = void 0;
6
+
7
+ const custom_animate_1 = require("../custom-animate"), vrender_core_1 = require("@visactor/vrender-core");
8
+
9
+ class SlideOutRichText extends custom_animate_1.ACustomAnimate {
10
+ constructor(from, to, duration, easing, params) {
11
+ super(from, to, duration, easing, params), this.fromTextConfig = [], this.toTextConfig = [],
12
+ this.originalTextConfig = [], this.singleCharConfig = [], this.fadeOutDuration = .3,
13
+ this.slideDirection = "right", this.slideDistance = 30, this.wordByWord = !1, this.wordRegex = /[a-zA-Z]+(-[a-zA-Z]+)*|[\u4e00-\u9fa5]+|[0-9]+|[^\s\w\u4e00-\u9fa5]/g,
14
+ this.wordGroups = [], this.reverseOrder = !1, void 0 !== (null == params ? void 0 : params.fadeOutDuration) && (this.fadeOutDuration = params.fadeOutDuration),
15
+ void 0 !== (null == params ? void 0 : params.slideDirection) && (this.slideDirection = params.slideDirection),
16
+ void 0 !== (null == params ? void 0 : params.slideDistance) && (this.slideDistance = params.slideDistance),
17
+ void 0 !== (null == params ? void 0 : params.wordByWord) && (this.wordByWord = params.wordByWord),
18
+ void 0 !== (null == params ? void 0 : params.wordRegex) && (this.wordRegex = params.wordRegex),
19
+ void 0 !== (null == params ? void 0 : params.reverseOrder) && (this.reverseOrder = params.reverseOrder),
20
+ this.propKeys = [ "textConfig" ];
21
+ }
22
+ onFirstRun() {
23
+ const fromProps = this.getLastProps(), toProps = this.getEndProps();
24
+ this.originalTextConfig = fromProps.textConfig ? [ ...fromProps.textConfig ] : [],
25
+ this.valid = !0, this.originalTextConfig && 0 !== this.originalTextConfig.length ? (this.fromTextConfig = vrender_core_1.RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig),
26
+ this.toTextConfig = toProps.textConfig && toProps.textConfig.length > 0 ? vrender_core_1.RichText.TransformTextConfig2SingleCharacter(toProps.textConfig) : [],
27
+ this.singleCharConfig = this.fromTextConfig.map((item => "text" in item ? Object.assign(Object.assign({}, item), {
28
+ opacity: 1,
29
+ dx: 0,
30
+ dy: 0
31
+ }) : Object.assign(Object.assign({}, item), {
32
+ opacity: 1
33
+ }))), this.wordByWord && this.calculateWordGroups()) : this.valid = !1;
34
+ }
35
+ calculateWordGroups() {
36
+ this.wordGroups = [];
37
+ let fullText = "";
38
+ const charMap = {};
39
+ let match, fullTextIndex = 0;
40
+ for ((this.fromTextConfig.forEach(((item, configIndex) => {
41
+ if ("text" in item) {
42
+ const text = String(item.text);
43
+ fullText += text, charMap[fullTextIndex] = configIndex, fullTextIndex++;
44
+ }
45
+ })), this.wordRegex.lastIndex = 0); null !== (match = this.wordRegex.exec(fullText)); ) {
46
+ const wordStart = match.index, wordEnd = match.index + match[0].length, wordIndices = [];
47
+ for (let i = wordStart; i < wordEnd; i++) void 0 !== charMap[i] && wordIndices.push(charMap[i]);
48
+ wordIndices.length > 0 && this.wordGroups.push(wordIndices);
49
+ }
50
+ const allocatedIndices = new Set;
51
+ this.wordGroups.forEach((group => {
52
+ group.forEach((index => allocatedIndices.add(index)));
53
+ }));
54
+ for (let i = 0; i < this.fromTextConfig.length; i++) "text" in this.fromTextConfig[i] && !allocatedIndices.has(i) && this.wordGroups.push([ i ]);
55
+ }
56
+ getTargetDx() {
57
+ switch (this.slideDirection) {
58
+ case "left":
59
+ return -this.slideDistance;
60
+
61
+ case "right":
62
+ return this.slideDistance;
63
+
64
+ default:
65
+ return 0;
66
+ }
67
+ }
68
+ getTargetDy() {
69
+ switch (this.slideDirection) {
70
+ case "up":
71
+ return -this.slideDistance;
72
+
73
+ case "down":
74
+ return this.slideDistance;
75
+
76
+ default:
77
+ return 0;
78
+ }
79
+ }
80
+ onEnd(cb) {
81
+ super.onEnd(cb), cb || (this.toTextConfig.length > 0 ? this.target.setAttribute("textConfig", this.toTextConfig) : this.target.setAttribute("textConfig", []));
82
+ }
83
+ onUpdate(end, ratio, out) {
84
+ if (!this.valid) return;
85
+ const maxTextShowRatio = 1 - this.fadeOutDuration;
86
+ let updatedTextConfig;
87
+ updatedTextConfig = this.wordByWord && this.wordGroups.length > 0 ? this.updateByWord(ratio, maxTextShowRatio) : this.updateByCharacter(ratio, maxTextShowRatio),
88
+ this.target.setAttribute("textConfig", updatedTextConfig);
89
+ }
90
+ updateByWord(ratio, maxTextShowRatio) {
91
+ const totalGroups = this.wordGroups.length, updatedTextConfig = [ ...this.singleCharConfig ];
92
+ for (let groupIndex = 0; groupIndex < this.wordGroups.length; groupIndex++) {
93
+ let disappearTime;
94
+ if (disappearTime = this.reverseOrder ? "left" === this.slideDirection ? groupIndex / totalGroups * maxTextShowRatio : (totalGroups - 1 - groupIndex) / totalGroups * maxTextShowRatio : "left" === this.slideDirection ? (totalGroups - 1 - groupIndex) / totalGroups * maxTextShowRatio : groupIndex / totalGroups * maxTextShowRatio,
95
+ ratio < disappearTime) {
96
+ for (const charIndex of this.wordGroups[groupIndex]) {
97
+ const item = updatedTextConfig[charIndex];
98
+ "text" in item && (updatedTextConfig[charIndex] = Object.assign(Object.assign({}, item), {
99
+ opacity: 1,
100
+ dx: 0,
101
+ dy: 0
102
+ }));
103
+ }
104
+ continue;
105
+ }
106
+ const animProgress = (ratio - disappearTime) / this.fadeOutDuration, progress = Math.max(0, Math.min(1, animProgress)), dx = this.getTargetDx() * progress, dy = this.getTargetDy() * progress, opacity = 1 - progress;
107
+ for (const charIndex of this.wordGroups[groupIndex]) {
108
+ const item = updatedTextConfig[charIndex];
109
+ "text" in item && (updatedTextConfig[charIndex] = Object.assign(Object.assign({}, item), {
110
+ opacity: opacity,
111
+ dx: dx,
112
+ dy: dy
113
+ }));
114
+ }
115
+ }
116
+ return updatedTextConfig;
117
+ }
118
+ updateByCharacter(ratio, maxTextShowRatio) {
119
+ const totalItems = this.fromTextConfig.length, updatedTextConfig = [ ...this.singleCharConfig ];
120
+ for (let index = 0; index < updatedTextConfig.length; index++) {
121
+ const item = updatedTextConfig[index];
122
+ if ("text" in item) {
123
+ let disappearTime;
124
+ if (disappearTime = this.reverseOrder ? "left" === this.slideDirection ? index / totalItems * maxTextShowRatio : (totalItems - 1 - index) / totalItems * maxTextShowRatio : "left" === this.slideDirection ? (totalItems - 1 - index) / totalItems * maxTextShowRatio : index / totalItems * maxTextShowRatio,
125
+ ratio < disappearTime) {
126
+ updatedTextConfig[index] = Object.assign(Object.assign({}, item), {
127
+ opacity: 1,
128
+ dx: 0,
129
+ dy: 0
130
+ });
131
+ continue;
132
+ }
133
+ const animProgress = (ratio - disappearTime) / this.fadeOutDuration, progress = Math.max(0, Math.min(1, animProgress)), dx = this.getTargetDx() * progress, dy = this.getTargetDy() * progress, opacity = 1 - progress;
134
+ updatedTextConfig[index] = Object.assign(Object.assign({}, item), {
135
+ opacity: opacity,
136
+ dx: dx,
137
+ dy: dy
138
+ });
139
+ }
140
+ }
141
+ return updatedTextConfig;
142
+ }
143
+ }
144
+
145
+ exports.SlideOutRichText = SlideOutRichText;
146
+ //# sourceMappingURL=slide-out-richtext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/custom/richtext/slide-out-richtext.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,yDA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K,CAAC,mCACnB,IAAI,KACP,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,EACL,EAAE,EAAE,CAAC,GACN,CAAC;oBACF,SAAS;iBACV;gBAGD,MAAM,YAAY,GAAG,CAAC,KAAK,GAAG,aAAa,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC;gBACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;gBAGxD,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC;gBACzC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC;gBACzC,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC;gBAE7B,iBAAiB,CAAC,KAAK,CAAC,mCACnB,IAAI,KACP,OAAO;oBACP,EAAE;oBACF,EAAE,GACH,CAAC;aACH;SACF;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AAvWD,4CAuWC","file":"slide-out-richtext.js","sourcesContent":["import { ACustomAnimate } from '../custom-animate';\nimport type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';\nimport { RichText } from '@visactor/vrender-core';\n\n/**\n * 滑动富文本退出动画,文字会向指定方向滑出,同时逐字消失\n * 支持上、下、左、右四个方向\n * 支持按单词或字符退场\n */\nexport class SlideOutRichText extends ACustomAnimate<{ textConfig: IRichTextCharacter[] }> {\n declare valid: boolean;\n\n private fromTextConfig: IRichTextCharacter[] = [];\n private toTextConfig: IRichTextCharacter[] = [];\n private originalTextConfig: IRichTextCharacter[] = [];\n private singleCharConfig: IRichTextCharacter[] = [];\n private fadeOutDuration: number = 0.3; // 透明度渐变持续时间,以动画总时长的比例表示\n private slideDirection: 'up' | 'down' | 'left' | 'right' = 'right'; // 滑动方向\n private slideDistance: number = 30; // 滑动距离(像素)\n private wordByWord: boolean = false; // 是否按单词为单位进行动画\n // 默认正则表达式: 匹配英文单词(含中间连字符),连续中文字符,数字,以及独立的符号和空格\n private wordRegex: RegExp = /[a-zA-Z]+(-[a-zA-Z]+)*|[\\u4e00-\\u9fa5]+|[0-9]+|[^\\s\\w\\u4e00-\\u9fa5]/g;\n private wordGroups: number[][] = []; // 存储单词分组信息,每个数组包含属于同一单词的字符索引\n private reverseOrder: boolean = false; // 是否反转字符/单词的消失顺序\n\n constructor(\n from: { textConfig: IRichTextCharacter[] },\n to: { textConfig: IRichTextCharacter[] },\n duration: number,\n easing: EasingType,\n params?: {\n fadeOutDuration?: number;\n slideDirection?: 'up' | 'down' | 'left' | 'right';\n slideDistance?: number;\n wordByWord?: boolean;\n wordRegex?: RegExp;\n reverseOrder?: boolean;\n }\n ) {\n super(from, to, duration, easing, params);\n\n // 配置透明度渐变效果\n if (params?.fadeOutDuration !== undefined) {\n this.fadeOutDuration = params.fadeOutDuration;\n }\n\n // 配置滑动方向和距离\n if (params?.slideDirection !== undefined) {\n this.slideDirection = params.slideDirection;\n }\n if (params?.slideDistance !== undefined) {\n this.slideDistance = params.slideDistance;\n }\n\n // 配置按单词动画\n if (params?.wordByWord !== undefined) {\n this.wordByWord = params.wordByWord;\n }\n if (params?.wordRegex !== undefined) {\n this.wordRegex = params.wordRegex;\n }\n\n // 配置顺序\n if (params?.reverseOrder !== undefined) {\n this.reverseOrder = params.reverseOrder;\n }\n\n this.propKeys = ['textConfig'];\n }\n\n onFirstRun(): void {\n const fromProps = this.getLastProps();\n const toProps = this.getEndProps();\n\n // 存储原始配置\n this.originalTextConfig = fromProps.textConfig ? [...fromProps.textConfig] : [];\n\n // 初始化解析结果\n this.valid = true;\n\n // 确保from不为空\n if (!this.originalTextConfig || this.originalTextConfig.length === 0) {\n this.valid = false;\n return;\n }\n\n // 将文本拆分为单个字符,使用RichText的静态方法\n this.fromTextConfig = RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig);\n\n // 目标状态是空文本(或指定的目标)\n this.toTextConfig =\n toProps.textConfig && toProps.textConfig.length > 0\n ? RichText.TransformTextConfig2SingleCharacter(toProps.textConfig)\n : [];\n\n // 创建单字符数组,用于动画初始状态\n this.singleCharConfig = this.fromTextConfig.map(item => {\n if ('text' in item) {\n // 文本字符初始设置为完全可见且无偏移\n return {\n ...item,\n opacity: 1,\n dx: 0,\n dy: 0\n };\n }\n return { ...item, opacity: 1 };\n });\n\n // 如果启用按单词动画,则计算单词分组\n if (this.wordByWord) {\n this.calculateWordGroups();\n }\n }\n\n // 计算单词分组\n private calculateWordGroups(): void {\n // 重置单词分组\n this.wordGroups = [];\n\n // 构建完整文本用于正则匹配\n let fullText = '';\n const charMap: Record<number, number> = {}; // 映射全文索引到字符配置索引\n let fullTextIndex = 0;\n\n // 构建全文和映射\n this.fromTextConfig.forEach((item, configIndex) => {\n if ('text' in item) {\n const text = String(item.text);\n fullText += text;\n // 为每个字符创建映射\n charMap[fullTextIndex] = configIndex;\n fullTextIndex++;\n }\n });\n\n // 使用正则表达式查找单词\n let match;\n\n // 重置正则表达式状态\n this.wordRegex.lastIndex = 0;\n\n while ((match = this.wordRegex.exec(fullText)) !== null) {\n const wordStart = match.index;\n const wordEnd = match.index + match[0].length;\n\n // 找出属于这个单词的所有字符索引\n const wordIndices = [];\n\n for (let i = wordStart; i < wordEnd; i++) {\n if (charMap[i] !== undefined) {\n wordIndices.push(charMap[i]);\n }\n }\n\n // 添加到单词分组\n if (wordIndices.length > 0) {\n this.wordGroups.push(wordIndices);\n }\n }\n\n // 处理没有分配到任何单词的字符\n const allocatedIndices = new Set<number>();\n this.wordGroups.forEach(group => {\n group.forEach(index => allocatedIndices.add(index));\n });\n\n for (let i = 0; i < this.fromTextConfig.length; i++) {\n if ('text' in this.fromTextConfig[i] && !allocatedIndices.has(i)) {\n // 单独为每个未分配的字符创建一个\"单词\"\n this.wordGroups.push([i]);\n }\n }\n }\n\n // 根据滑动方向计算目标x偏移(最终位置)\n private getTargetDx(): number {\n switch (this.slideDirection) {\n case 'left':\n return -this.slideDistance;\n case 'right':\n return this.slideDistance;\n default:\n return 0;\n }\n }\n\n // 根据滑动方向计算目标y偏移(最终位置)\n private getTargetDy(): number {\n switch (this.slideDirection) {\n case 'up':\n return -this.slideDistance;\n case 'down':\n return this.slideDistance;\n default:\n return 0;\n }\n }\n\n onEnd(cb?: (animate: IAnimate, step: IStep) => void): void {\n super.onEnd(cb);\n if (!cb) {\n // 动画结束时,应用最终textConfig(通常是空的或特定的toTextConfig)\n if (this.toTextConfig.length > 0) {\n this.target.setAttribute('textConfig', this.toTextConfig);\n } else {\n this.target.setAttribute('textConfig', []);\n }\n }\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this.valid) {\n return;\n }\n\n // 计算文本显示时间比例上限 - 为尾部字符的渐变和滑动效果留出时间\n const maxTextShowRatio = 1 - this.fadeOutDuration;\n\n let updatedTextConfig: IRichTextCharacter[];\n\n if (this.wordByWord && this.wordGroups.length > 0) {\n // 按单词动画\n updatedTextConfig = this.updateByWord(ratio, maxTextShowRatio);\n } else {\n // 按字符动画\n updatedTextConfig = this.updateByCharacter(ratio, maxTextShowRatio);\n }\n\n // 更新富文本的textConfig属性\n this.target.setAttribute('textConfig', updatedTextConfig);\n }\n\n // 按单词更新文本配置\n private updateByWord(ratio: number, maxTextShowRatio: number): IRichTextCharacter[] {\n const totalGroups = this.wordGroups.length;\n const updatedTextConfig = [...this.singleCharConfig];\n\n // 处理单词分组\n for (let groupIndex = 0; groupIndex < this.wordGroups.length; groupIndex++) {\n // 计算这个单词组的消失时间点\n let disappearTime;\n\n if (this.reverseOrder) {\n // 反转顺序 (与入场顺序相反)\n if (this.slideDirection === 'left') {\n // 从左到右的顺序 (第一个单词先消失)\n disappearTime = (groupIndex / totalGroups) * maxTextShowRatio;\n } else {\n // 从右到左的顺序 (最后的单词先消失)\n disappearTime = ((totalGroups - 1 - groupIndex) / totalGroups) * maxTextShowRatio;\n }\n } else {\n // 标准顺序 (与入场顺序相同)\n if (this.slideDirection === 'left') {\n // 从右到左的顺序 (最后的单词先消失)\n disappearTime = ((totalGroups - 1 - groupIndex) / totalGroups) * maxTextShowRatio;\n } else {\n // 从左到右的顺序 (第一个单词先消失)\n disappearTime = (groupIndex / totalGroups) * maxTextShowRatio;\n }\n }\n\n // 如果当前时间还没到显示这个单词的消失时间点,保持可见状态\n if (ratio < disappearTime) {\n for (const charIndex of this.wordGroups[groupIndex]) {\n const item = updatedTextConfig[charIndex];\n if ('text' in item) {\n updatedTextConfig[charIndex] = {\n ...item,\n opacity: 1,\n dx: 0,\n dy: 0\n };\n }\n }\n continue;\n }\n\n // 计算动画进度(0-1之间)\n const animProgress = (ratio - disappearTime) / this.fadeOutDuration;\n const progress = Math.max(0, Math.min(1, animProgress));\n\n // 计算当前偏移和透明度\n const dx = this.getTargetDx() * progress;\n const dy = this.getTargetDy() * progress;\n const opacity = 1 - progress;\n\n // 更新这个单词的所有字符\n for (const charIndex of this.wordGroups[groupIndex]) {\n const item = updatedTextConfig[charIndex];\n if ('text' in item) {\n updatedTextConfig[charIndex] = {\n ...item,\n opacity,\n dx,\n dy\n };\n }\n }\n }\n\n return updatedTextConfig;\n }\n\n // 按字符更新文本配置\n private updateByCharacter(ratio: number, maxTextShowRatio: number): IRichTextCharacter[] {\n const totalItems = this.fromTextConfig.length;\n const updatedTextConfig = [...this.singleCharConfig];\n\n // 更新每个字符的状态\n for (let index = 0; index < updatedTextConfig.length; index++) {\n const item = updatedTextConfig[index];\n if ('text' in item) {\n // 计算每个字符的消失时间点\n let disappearTime;\n\n if (this.reverseOrder) {\n // 反转入场顺序\n if (this.slideDirection === 'left') {\n // 从左到右的顺序 (第一个字符先消失)\n disappearTime = (index / totalItems) * maxTextShowRatio;\n } else {\n // 从右到左的顺序 (最后的字符先消失)\n disappearTime = ((totalItems - 1 - index) / totalItems) * maxTextShowRatio;\n }\n } else {\n // 与入场顺序相同\n if (this.slideDirection === 'left') {\n // 从右到左的顺序 (最后的字符先消失)\n disappearTime = ((totalItems - 1 - index) / totalItems) * maxTextShowRatio;\n } else {\n // 标准顺序 (第一个字符先消失)\n disappearTime = (index / totalItems) * maxTextShowRatio;\n }\n }\n\n // 如果当前时间还没到这个字符的消失时间点,保持可见状态\n if (ratio < disappearTime) {\n updatedTextConfig[index] = {\n ...item,\n opacity: 1,\n dx: 0,\n dy: 0\n };\n continue;\n }\n\n // 计算动画进度(0-1之间)\n const animProgress = (ratio - disappearTime) / this.fadeOutDuration;\n const progress = Math.max(0, Math.min(1, animProgress));\n\n // 计算当前偏移和透明度\n const dx = this.getTargetDx() * progress;\n const dy = this.getTargetDy() * progress;\n const opacity = 1 - progress;\n\n updatedTextConfig[index] = {\n ...item,\n opacity,\n dx,\n dy\n };\n }\n }\n\n return updatedTextConfig;\n }\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { ACustomAnimate } from '../custom-animate';
2
+ import type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';
3
+ export declare class SlideRichText extends ACustomAnimate<{
4
+ textConfig: IRichTextCharacter[];
5
+ }> {
6
+ valid: boolean;
7
+ private fromTextConfig;
8
+ private toTextConfig;
9
+ private originalTextConfig;
10
+ private singleCharConfig;
11
+ private fadeInDuration;
12
+ private slideDirection;
13
+ private slideDistance;
14
+ private wordByWord;
15
+ private wordRegex;
16
+ private wordGroups;
17
+ constructor(from: {
18
+ textConfig: IRichTextCharacter[];
19
+ }, to: {
20
+ textConfig: IRichTextCharacter[];
21
+ }, duration: number, easing: EasingType, params?: {
22
+ fadeInDuration?: number;
23
+ slideDirection?: 'up' | 'down' | 'left' | 'right';
24
+ slideDistance?: number;
25
+ wordByWord?: boolean;
26
+ wordRegex?: RegExp;
27
+ });
28
+ onFirstRun(): void;
29
+ private calculateWordGroups;
30
+ private getInitialDx;
31
+ private getInitialDy;
32
+ onEnd(cb?: (animate: IAnimate, step: IStep) => void): void;
33
+ onUpdate(end: boolean, ratio: number, out: Record<string, any>): void;
34
+ private updateByWord;
35
+ private updateByCharacter;
36
+ }
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: !0
5
+ }), exports.SlideRichText = void 0;
6
+
7
+ const custom_animate_1 = require("../custom-animate"), vrender_core_1 = require("@visactor/vrender-core");
8
+
9
+ class SlideRichText extends custom_animate_1.ACustomAnimate {
10
+ constructor(from, to, duration, easing, params) {
11
+ super(from, to, duration, easing, params), this.fromTextConfig = [], this.toTextConfig = [],
12
+ this.originalTextConfig = [], this.singleCharConfig = [], this.fadeInDuration = .3,
13
+ this.slideDirection = "right", this.slideDistance = 30, this.wordByWord = !1, this.wordRegex = /[a-zA-Z]+(-[a-zA-Z]+)*|[\u4e00-\u9fa5]+|[0-9]+|[^\s\w\u4e00-\u9fa5]/g,
14
+ this.wordGroups = [], void 0 !== (null == params ? void 0 : params.fadeInDuration) && (this.fadeInDuration = params.fadeInDuration),
15
+ void 0 !== (null == params ? void 0 : params.slideDirection) && (this.slideDirection = params.slideDirection),
16
+ void 0 !== (null == params ? void 0 : params.slideDistance) && (this.slideDistance = params.slideDistance),
17
+ void 0 !== (null == params ? void 0 : params.wordByWord) && (this.wordByWord = params.wordByWord),
18
+ void 0 !== (null == params ? void 0 : params.wordRegex) && (this.wordRegex = params.wordRegex);
19
+ }
20
+ onFirstRun() {
21
+ const fromProps = this.getLastProps(), toProps = this.getEndProps();
22
+ this.originalTextConfig = toProps.textConfig ? [ ...toProps.textConfig ] : [], this.valid = !0,
23
+ this.originalTextConfig && 0 !== this.originalTextConfig.length ? (this.fromTextConfig = fromProps.textConfig && fromProps.textConfig.length > 0 ? vrender_core_1.RichText.TransformTextConfig2SingleCharacter(fromProps.textConfig) : [],
24
+ this.toTextConfig = vrender_core_1.RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig),
25
+ this.singleCharConfig = this.toTextConfig.map((item => "text" in item ? Object.assign(Object.assign({}, item), {
26
+ opacity: 0,
27
+ dx: this.getInitialDx(),
28
+ dy: this.getInitialDy()
29
+ }) : Object.assign(Object.assign({}, item), {
30
+ opacity: 0
31
+ }))), this.wordByWord && this.calculateWordGroups()) : this.valid = !1;
32
+ }
33
+ calculateWordGroups() {
34
+ this.wordGroups = [];
35
+ let fullText = "";
36
+ const charMap = {};
37
+ let match, fullTextIndex = 0;
38
+ for ((this.toTextConfig.forEach(((item, configIndex) => {
39
+ if ("text" in item) {
40
+ const text = String(item.text);
41
+ fullText += text, charMap[fullTextIndex] = configIndex, fullTextIndex++;
42
+ }
43
+ })), this.wordRegex.lastIndex = 0); null !== (match = this.wordRegex.exec(fullText)); ) {
44
+ const wordStart = match.index, wordEnd = match.index + match[0].length, wordIndices = [];
45
+ for (let i = wordStart; i < wordEnd; i++) void 0 !== charMap[i] && wordIndices.push(charMap[i]);
46
+ wordIndices.length > 0 && this.wordGroups.push(wordIndices);
47
+ }
48
+ const allocatedIndices = new Set;
49
+ this.wordGroups.forEach((group => {
50
+ group.forEach((index => allocatedIndices.add(index)));
51
+ }));
52
+ for (let i = 0; i < this.toTextConfig.length; i++) "text" in this.toTextConfig[i] && !allocatedIndices.has(i) && this.wordGroups.push([ i ]);
53
+ }
54
+ getInitialDx() {
55
+ switch (this.slideDirection) {
56
+ case "left":
57
+ return -this.slideDistance;
58
+
59
+ case "right":
60
+ return this.slideDistance;
61
+
62
+ default:
63
+ return 0;
64
+ }
65
+ }
66
+ getInitialDy() {
67
+ switch (this.slideDirection) {
68
+ case "up":
69
+ return -this.slideDistance;
70
+
71
+ case "down":
72
+ return this.slideDistance;
73
+
74
+ default:
75
+ return 0;
76
+ }
77
+ }
78
+ onEnd(cb) {
79
+ super.onEnd(cb), cb || this.target.setAttribute("textConfig", this.originalTextConfig);
80
+ }
81
+ onUpdate(end, ratio, out) {
82
+ if (!this.valid) return;
83
+ const maxTextShowRatio = 1 - this.fadeInDuration;
84
+ let updatedTextConfig;
85
+ updatedTextConfig = this.wordByWord && this.wordGroups.length > 0 ? this.updateByWord(ratio, maxTextShowRatio) : this.updateByCharacter(ratio, maxTextShowRatio),
86
+ this.target.setAttribute("textConfig", updatedTextConfig);
87
+ }
88
+ updateByWord(ratio, maxTextShowRatio) {
89
+ const totalGroups = this.wordGroups.length, updatedTextConfig = [ ...this.singleCharConfig ];
90
+ for (let groupIndex = 0; groupIndex < this.wordGroups.length; groupIndex++) {
91
+ let appearTime;
92
+ if (appearTime = "left" === this.slideDirection ? (totalGroups - 1 - groupIndex) / totalGroups * maxTextShowRatio : groupIndex / totalGroups * maxTextShowRatio,
93
+ ratio < appearTime) {
94
+ for (const charIndex of this.wordGroups[groupIndex]) {
95
+ const item = updatedTextConfig[charIndex];
96
+ "text" in item && (updatedTextConfig[charIndex] = Object.assign(Object.assign({}, item), {
97
+ opacity: 0,
98
+ dx: this.getInitialDx(),
99
+ dy: this.getInitialDy()
100
+ }));
101
+ }
102
+ continue;
103
+ }
104
+ const animProgress = (ratio - appearTime) / this.fadeInDuration, progress = Math.max(0, Math.min(1, animProgress)), dx = this.getInitialDx() * (1 - progress), dy = this.getInitialDy() * (1 - progress);
105
+ for (const charIndex of this.wordGroups[groupIndex]) {
106
+ const item = updatedTextConfig[charIndex];
107
+ "text" in item && (updatedTextConfig[charIndex] = Object.assign(Object.assign({}, item), {
108
+ opacity: progress,
109
+ dx: dx,
110
+ dy: dy
111
+ }));
112
+ }
113
+ }
114
+ return updatedTextConfig;
115
+ }
116
+ updateByCharacter(ratio, maxTextShowRatio) {
117
+ const totalItems = this.toTextConfig.length, updatedTextConfig = [ ...this.singleCharConfig ];
118
+ for (let index = 0; index < updatedTextConfig.length; index++) {
119
+ const item = updatedTextConfig[index];
120
+ if ("text" in item) {
121
+ let appearTime;
122
+ if (appearTime = "left" === this.slideDirection ? (totalItems - 1 - index) / totalItems * maxTextShowRatio : index / totalItems * maxTextShowRatio,
123
+ ratio < appearTime) {
124
+ updatedTextConfig[index] = Object.assign(Object.assign({}, item), {
125
+ opacity: 0,
126
+ dx: this.getInitialDx(),
127
+ dy: this.getInitialDy()
128
+ });
129
+ continue;
130
+ }
131
+ const animProgress = (ratio - appearTime) / this.fadeInDuration, progress = Math.max(0, Math.min(1, animProgress)), dx = this.getInitialDx() * (1 - progress), dy = this.getInitialDy() * (1 - progress);
132
+ updatedTextConfig[index] = Object.assign(Object.assign({}, item), {
133
+ opacity: progress,
134
+ dx: dx,
135
+ dy: dy
136
+ });
137
+ }
138
+ }
139
+ return updatedTextConfig;
140
+ }
141
+ }
142
+
143
+ exports.SlideRichText = SlideRichText;
144
+ //# sourceMappingURL=slide-richtext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/custom/richtext/slide-richtext.ts"],"names":[],"mappings":";;;AAAA,sDAAmD;AAEnD,yDAAkD;AAQlD,MAAa,aAAc,SAAQ,+BAAoD;IAerF,YACE,IAA0C,EAC1C,EAAwC,EACxC,QAAgB,EAChB,MAAkB,EAClB,MAMC;QAED,KAAK,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAzBpC,mBAAc,GAAyB,EAAE,CAAC;QAC1C,iBAAY,GAAyB,EAAE,CAAC;QACxC,uBAAkB,GAAyB,EAAE,CAAC;QAC9C,qBAAgB,GAAyB,EAAE,CAAC;QAC5C,mBAAc,GAAW,GAAG,CAAC;QAC7B,mBAAc,GAAqC,OAAO,CAAC;QAC3D,kBAAa,GAAW,EAAE,CAAC;QAC3B,eAAU,GAAY,KAAK,CAAC;QAE5B,cAAS,GAAW,sEAAsE,CAAC;QAC3F,eAAU,GAAe,EAAE,CAAC;QAkBlC,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,MAAK,SAAS,EAAE;YACxC,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC;SAC7C;QAGD,IAAI,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,cAAc,MAAK,SAAS,EAAE;YACxC,IAAI,CAAC,cAAc,GAAG,MAAM,C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;gBAChD,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC;gBAEhD,iBAAiB,CAAC,KAAK,CAAC,mCACnB,IAAI,KACP,OAAO,EAAE,QAAQ,EACjB,EAAE;oBACF,EAAE,GACH,CAAC;aACH;SACF;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC;CACF;AA9TD,sCA8TC","file":"slide-richtext.js","sourcesContent":["import { ACustomAnimate } from '../custom-animate';\nimport type { IRichTextCharacter, IAnimate, IStep, EasingType } from '@visactor/vrender-core';\nimport { RichText } from '@visactor/vrender-core';\n\n/**\n * 滑动富文本动画,结合打字效果和方向滑动效果\n * 文字会从指定方向滑入,同时逐字显示和渐入\n * 支持上、下、左、右四个方向\n * 支持按单词或字符入场\n */\nexport class SlideRichText extends ACustomAnimate<{ textConfig: IRichTextCharacter[] }> {\n declare valid: boolean;\n\n private fromTextConfig: IRichTextCharacter[] = [];\n private toTextConfig: IRichTextCharacter[] = [];\n private originalTextConfig: IRichTextCharacter[] = [];\n private singleCharConfig: IRichTextCharacter[] = [];\n private fadeInDuration: number = 0.3; // 透明度渐变持续时间,以动画总时长的比例表示\n private slideDirection: 'up' | 'down' | 'left' | 'right' = 'right'; // 滑动方向\n private slideDistance: number = 30; // 滑动距离(像素)\n private wordByWord: boolean = false; // 是否按单词为单位进行动画\n // 默认正则表达式: 匹配英文单词(含中间连字符),连续中文字符,数字,以及独立的符号和空格\n private wordRegex: RegExp = /[a-zA-Z]+(-[a-zA-Z]+)*|[\\u4e00-\\u9fa5]+|[0-9]+|[^\\s\\w\\u4e00-\\u9fa5]/g;\n private wordGroups: number[][] = []; // 存储单词分组信息,每个数组包含属于同一单词的字符索引\n\n constructor(\n from: { textConfig: IRichTextCharacter[] },\n to: { textConfig: IRichTextCharacter[] },\n duration: number,\n easing: EasingType,\n params?: {\n fadeInDuration?: number;\n slideDirection?: 'up' | 'down' | 'left' | 'right';\n slideDistance?: number;\n wordByWord?: boolean;\n wordRegex?: RegExp;\n }\n ) {\n super(from, to, duration, easing, params);\n\n // 配置透明度渐变效果\n if (params?.fadeInDuration !== undefined) {\n this.fadeInDuration = params.fadeInDuration;\n }\n\n // 配置滑动方向和距离\n if (params?.slideDirection !== undefined) {\n this.slideDirection = params.slideDirection;\n }\n if (params?.slideDistance !== undefined) {\n this.slideDistance = params.slideDistance;\n }\n\n // 配置按单词动画\n if (params?.wordByWord !== undefined) {\n this.wordByWord = params.wordByWord;\n }\n if (params?.wordRegex !== undefined) {\n this.wordRegex = params.wordRegex;\n }\n }\n\n onFirstRun(): void {\n const fromProps = this.getLastProps();\n const toProps = this.getEndProps();\n\n // 存储原始配置\n this.originalTextConfig = toProps.textConfig ? [...toProps.textConfig] : [];\n\n // 初始化解析结果\n this.valid = true;\n\n // 确保to不为空\n if (!this.originalTextConfig || this.originalTextConfig.length === 0) {\n this.valid = false;\n return;\n }\n\n // 将文本拆分为单个字符,使用RichText的静态方法\n this.fromTextConfig =\n fromProps.textConfig && fromProps.textConfig.length > 0\n ? RichText.TransformTextConfig2SingleCharacter(fromProps.textConfig)\n : [];\n\n this.toTextConfig = RichText.TransformTextConfig2SingleCharacter(this.originalTextConfig);\n\n // 创建单字符数组,用于动画\n this.singleCharConfig = this.toTextConfig.map(item => {\n if ('text' in item) {\n // 文本字符初始设置为透明\n return {\n ...item,\n opacity: 0,\n dx: this.getInitialDx(),\n dy: this.getInitialDy()\n };\n }\n return { ...item, opacity: 0 };\n });\n\n // 如果启用按单词动画,则计算单词分组\n if (this.wordByWord) {\n this.calculateWordGroups();\n }\n }\n\n // 计算单词分组\n private calculateWordGroups(): void {\n // 重置单词分组\n this.wordGroups = [];\n\n // 构建完整文本用于正则匹配\n let fullText = '';\n const charMap: Record<number, number> = {}; // 映射全文索引到字符配置索引\n let fullTextIndex = 0;\n\n // 构建全文和映射\n this.toTextConfig.forEach((item, configIndex) => {\n if ('text' in item) {\n const text = String(item.text);\n fullText += text;\n // 为每个字符创建映射\n charMap[fullTextIndex] = configIndex;\n fullTextIndex++;\n }\n });\n\n // 使用正则表达式查找单词\n let match;\n\n // 重置正则表达式状态\n this.wordRegex.lastIndex = 0;\n\n while ((match = this.wordRegex.exec(fullText)) !== null) {\n const wordStart = match.index;\n const wordEnd = match.index + match[0].length;\n\n // 找出属于这个单词的所有字符索引\n const wordIndices = [];\n\n for (let i = wordStart; i < wordEnd; i++) {\n if (charMap[i] !== undefined) {\n wordIndices.push(charMap[i]);\n }\n }\n\n // 添加到单词分组\n if (wordIndices.length > 0) {\n this.wordGroups.push(wordIndices);\n }\n }\n\n // 处理没有分配到任何单词的字符\n const allocatedIndices = new Set<number>();\n this.wordGroups.forEach(group => {\n group.forEach(index => allocatedIndices.add(index));\n });\n\n for (let i = 0; i < this.toTextConfig.length; i++) {\n if ('text' in this.toTextConfig[i] && !allocatedIndices.has(i)) {\n // 单独为每个未分配的字符创建一个\"单词\"\n this.wordGroups.push([i]);\n }\n }\n }\n\n // 根据滑动方向计算初始x偏移\n private getInitialDx(): number {\n switch (this.slideDirection) {\n case 'left':\n return -this.slideDistance;\n case 'right':\n return this.slideDistance;\n default:\n return 0;\n }\n }\n\n // 根据滑动方向计算初始y偏移\n private getInitialDy(): number {\n switch (this.slideDirection) {\n case 'up':\n return -this.slideDistance;\n case 'down':\n return this.slideDistance;\n default:\n return 0;\n }\n }\n\n onEnd(cb?: (animate: IAnimate, step: IStep) => void): void {\n super.onEnd(cb);\n if (!cb) {\n // 动画结束时,恢复原始textConfig\n this.target.setAttribute('textConfig', this.originalTextConfig);\n }\n }\n\n onUpdate(end: boolean, ratio: number, out: Record<string, any>): void {\n if (!this.valid) {\n return;\n }\n\n // 计算文本显示比例上限 - 为尾部字符的渐变和滑动效果留出时间\n const maxTextShowRatio = 1 - this.fadeInDuration;\n\n let updatedTextConfig: IRichTextCharacter[];\n\n if (this.wordByWord && this.wordGroups.length > 0) {\n // 按单词动画\n updatedTextConfig = this.updateByWord(ratio, maxTextShowRatio);\n } else {\n // 按字符动画\n updatedTextConfig = this.updateByCharacter(ratio, maxTextShowRatio);\n }\n\n // 更新富文本的textConfig属性\n this.target.setAttribute('textConfig', updatedTextConfig);\n }\n\n // 按单词更新文本配置\n private updateByWord(ratio: number, maxTextShowRatio: number): IRichTextCharacter[] {\n const totalGroups = this.wordGroups.length;\n const updatedTextConfig = [...this.singleCharConfig];\n\n // 处理单词分组\n for (let groupIndex = 0; groupIndex < this.wordGroups.length; groupIndex++) {\n // 计算这个单词组的显示时间点\n let appearTime;\n if (this.slideDirection === 'left') {\n // 从右到左顺序(最后的单词先出现)\n appearTime = ((totalGroups - 1 - groupIndex) / totalGroups) * maxTextShowRatio;\n } else {\n // 标准顺序(第一个单词先出现)\n appearTime = (groupIndex / totalGroups) * maxTextShowRatio;\n }\n\n // 如果当前时间还没到显示这个单词的时间点,保持隐藏状态\n if (ratio < appearTime) {\n for (const charIndex of this.wordGroups[groupIndex]) {\n const item = updatedTextConfig[charIndex];\n if ('text' in item) {\n updatedTextConfig[charIndex] = {\n ...item,\n opacity: 0,\n dx: this.getInitialDx(),\n dy: this.getInitialDy()\n };\n }\n }\n continue;\n }\n\n // 计算动画进度(0-1之间)\n const animProgress = (ratio - appearTime) / this.fadeInDuration;\n const progress = Math.max(0, Math.min(1, animProgress));\n\n // 计算当前偏移和透明度\n const dx = this.getInitialDx() * (1 - progress);\n const dy = this.getInitialDy() * (1 - progress);\n\n // 更新这个单词的所有字符\n for (const charIndex of this.wordGroups[groupIndex]) {\n const item = updatedTextConfig[charIndex];\n if ('text' in item) {\n updatedTextConfig[charIndex] = {\n ...item,\n opacity: progress,\n dx,\n dy\n };\n }\n }\n }\n\n return updatedTextConfig;\n }\n\n // 按字符更新文本配置\n private updateByCharacter(ratio: number, maxTextShowRatio: number): IRichTextCharacter[] {\n const totalItems = this.toTextConfig.length;\n const updatedTextConfig = [...this.singleCharConfig];\n\n // 更新每个字符的状态\n for (let index = 0; index < updatedTextConfig.length; index++) {\n const item = updatedTextConfig[index];\n if ('text' in item) {\n // 计算每个字符的显示时间点\n // 对于left方向,反转显示顺序(从右到左)\n let appearTime;\n if (this.slideDirection === 'left') {\n // 从右到左的顺序 (最后的字符先出现)\n appearTime = ((totalItems - 1 - index) / totalItems) * maxTextShowRatio;\n } else {\n // 标准顺序 (第一个字符先出现)\n appearTime = (index / totalItems) * maxTextShowRatio;\n }\n\n // 如果当前时间还没到显示这个字符的时间点,保持隐藏状态\n if (ratio < appearTime) {\n updatedTextConfig[index] = {\n ...item,\n opacity: 0,\n dx: this.getInitialDx(),\n dy: this.getInitialDy()\n };\n continue;\n }\n\n // 计算动画进度(0-1之间)\n const animProgress = (ratio - appearTime) / this.fadeInDuration;\n const progress = Math.max(0, Math.min(1, animProgress));\n\n // 计算当前偏移和透明度\n const dx = this.getInitialDx() * (1 - progress);\n const dy = this.getInitialDy() * (1 - progress);\n\n updatedTextConfig[index] = {\n ...item,\n opacity: progress,\n dx,\n dy\n };\n }\n }\n\n return updatedTextConfig;\n }\n}\n"]}