@visactor/vrender-core 0.21.7 → 0.22.0-vstory.1

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 (342) hide show
  1. package/cjs/animate/Ticker/default-ticker.d.ts +2 -0
  2. package/cjs/animate/Ticker/default-ticker.js +7 -1
  3. package/cjs/animate/Ticker/default-ticker.js.map +1 -1
  4. package/cjs/animate/animate.js +1 -1
  5. package/cjs/animate/animate.js.map +1 -1
  6. package/cjs/animate/custom-animate.js +14 -25
  7. package/cjs/animate/custom-animate.js.map +1 -1
  8. package/cjs/animate/easing-func.d.ts +1 -0
  9. package/cjs/animate/easing-func.js +16 -0
  10. package/cjs/animate/easing-func.js.map +1 -0
  11. package/cjs/animate/easing.d.ts +4 -0
  12. package/cjs/animate/easing.js +24 -1
  13. package/cjs/animate/easing.js.map +1 -1
  14. package/cjs/animate/index.d.ts +1 -0
  15. package/cjs/animate/index.js +1 -1
  16. package/cjs/animate/index.js.map +1 -1
  17. package/cjs/color-string/store.js +1 -2
  18. package/cjs/common/3d-interceptor.js +2 -1
  19. package/cjs/common/bezier-utils.d.ts +3 -0
  20. package/cjs/common/bezier-utils.js +17 -2
  21. package/cjs/common/bezier-utils.js.map +1 -1
  22. package/cjs/common/custom-path2d.d.ts +4 -0
  23. package/cjs/common/custom-path2d.js +43 -11
  24. package/cjs/common/custom-path2d.js.map +1 -1
  25. package/cjs/common/render-area.js +0 -1
  26. package/cjs/common/render-command-list.js +2 -1
  27. package/cjs/common/segment/curve/arc.d.ts +4 -1
  28. package/cjs/common/segment/curve/arc.js +10 -1
  29. package/cjs/common/segment/curve/arc.js.map +1 -1
  30. package/cjs/common/segment/curve/base.d.ts +4 -1
  31. package/cjs/common/segment/curve/base.js.map +1 -1
  32. package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
  33. package/cjs/common/segment/curve/cubic-bezier.js +24 -3
  34. package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
  35. package/cjs/common/segment/curve/curve-context.js +5 -4
  36. package/cjs/common/segment/curve/curve-context.js.map +1 -1
  37. package/cjs/common/segment/curve/ellipse.d.ts +4 -1
  38. package/cjs/common/segment/curve/ellipse.js +9 -0
  39. package/cjs/common/segment/curve/ellipse.js.map +1 -1
  40. package/cjs/common/segment/curve/line.d.ts +4 -1
  41. package/cjs/common/segment/curve/line.js +18 -0
  42. package/cjs/common/segment/curve/line.js.map +1 -1
  43. package/cjs/common/segment/curve/move.d.ts +4 -1
  44. package/cjs/common/segment/curve/move.js +9 -0
  45. package/cjs/common/segment/curve/move.js.map +1 -1
  46. package/cjs/common/segment/curve/path.d.ts +2 -1
  47. package/cjs/common/segment/curve/path.js +5 -2
  48. package/cjs/common/segment/curve/path.js.map +1 -1
  49. package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
  50. package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
  51. package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
  52. package/cjs/common/shape/rect.d.ts +1 -1
  53. package/cjs/common/shape/rect.js +30 -25
  54. package/cjs/common/shape/rect.js.map +1 -1
  55. package/cjs/common/store.js +1 -1
  56. package/cjs/core/contributions/env/base-contribution.d.ts +2 -0
  57. package/cjs/core/contributions/env/base-contribution.js +6 -0
  58. package/cjs/core/contributions/env/base-contribution.js.map +1 -1
  59. package/cjs/core/global.d.ts +5 -0
  60. package/cjs/core/global.js +13 -1
  61. package/cjs/core/global.js.map +1 -1
  62. package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
  63. package/cjs/graphic/builtin-symbol/rect.js +28 -0
  64. package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
  65. package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
  66. package/cjs/graphic/builtin-symbol/utils.js +5 -0
  67. package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
  68. package/cjs/graphic/config.js +19 -5
  69. package/cjs/graphic/config.js.map +1 -1
  70. package/cjs/graphic/graphic.js +15 -1
  71. package/cjs/graphic/graphic.js.map +1 -1
  72. package/cjs/graphic/richtext/line.js +1 -1
  73. package/cjs/graphic/richtext/line.js.map +1 -1
  74. package/cjs/graphic/richtext/paragraph.d.ts +1 -1
  75. package/cjs/graphic/richtext/paragraph.js +9 -4
  76. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  77. package/cjs/graphic/richtext/utils.d.ts +4 -0
  78. package/cjs/graphic/richtext/utils.js +19 -6
  79. package/cjs/graphic/richtext/utils.js.map +1 -1
  80. package/cjs/graphic/richtext/wrapper.d.ts +1 -0
  81. package/cjs/graphic/richtext/wrapper.js +1 -1
  82. package/cjs/graphic/richtext/wrapper.js.map +1 -1
  83. package/cjs/graphic/richtext.d.ts +7 -2
  84. package/cjs/graphic/richtext.js +33 -3
  85. package/cjs/graphic/richtext.js.map +1 -1
  86. package/cjs/index.d.ts +2 -0
  87. package/cjs/index.js +2 -1
  88. package/cjs/index.js.map +1 -1
  89. package/cjs/interface/animate.d.ts +5 -39
  90. package/cjs/interface/animate.js.map +1 -1
  91. package/cjs/interface/context.d.ts +1 -0
  92. package/cjs/interface/context.js.map +1 -1
  93. package/cjs/interface/global.d.ts +5 -0
  94. package/cjs/interface/global.js.map +1 -1
  95. package/cjs/interface/graphic/group.d.ts +1 -0
  96. package/cjs/interface/graphic/group.js.map +1 -1
  97. package/cjs/interface/graphic/image.d.ts +1 -0
  98. package/cjs/interface/graphic/image.js.map +1 -1
  99. package/cjs/interface/graphic/path.d.ts +1 -0
  100. package/cjs/interface/graphic/path.js.map +1 -1
  101. package/cjs/interface/graphic/rect.d.ts +1 -0
  102. package/cjs/interface/graphic/rect.js.map +1 -1
  103. package/cjs/interface/graphic/richText.d.ts +2 -0
  104. package/cjs/interface/graphic/richText.js.map +1 -1
  105. package/cjs/interface/graphic/symbol.d.ts +2 -0
  106. package/cjs/interface/graphic/symbol.js.map +1 -1
  107. package/cjs/interface/graphic.d.ts +11 -2
  108. package/cjs/interface/graphic.js.map +1 -1
  109. package/cjs/interface/path.d.ts +5 -0
  110. package/cjs/interface/path.js.map +1 -1
  111. package/cjs/interface/picker.d.ts +13 -0
  112. package/cjs/interface/picker.js.map +1 -1
  113. package/cjs/picker/constants.d.ts +2 -0
  114. package/cjs/picker/constants.js +3 -2
  115. package/cjs/picker/constants.js.map +1 -1
  116. package/cjs/picker/pick-interceptor.d.ts +7 -2
  117. package/cjs/picker/pick-interceptor.js +19 -2
  118. package/cjs/picker/pick-interceptor.js.map +1 -1
  119. package/cjs/picker/pick-modules.js +7 -4
  120. package/cjs/picker/pick-modules.js.map +1 -1
  121. package/cjs/picker/picker-service.d.ts +4 -2
  122. package/cjs/picker/picker-service.js +13 -12
  123. package/cjs/picker/picker-service.js.map +1 -1
  124. package/cjs/plugins/builtin-plugin/edit-module.d.ts +15 -5
  125. package/cjs/plugins/builtin-plugin/edit-module.js +123 -42
  126. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  127. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  128. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  129. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  130. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +62 -29
  131. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +346 -212
  132. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  133. package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
  134. package/cjs/render/contributions/render/base-render.d.ts +1 -0
  135. package/cjs/render/contributions/render/base-render.js +20 -2
  136. package/cjs/render/contributions/render/base-render.js.map +1 -1
  137. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  138. package/cjs/render/contributions/render/contributions/base-contribution-render.js +16 -8
  139. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  140. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  141. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  142. package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -3
  143. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  144. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  145. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  146. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  147. package/cjs/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  148. package/cjs/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  149. package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  150. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
  151. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  152. package/cjs/render/contributions/render/contributions/text-contribution-render.js +5 -3
  153. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  154. package/cjs/render/contributions/render/group-render.js +2 -2
  155. package/cjs/render/contributions/render/group-render.js.map +1 -1
  156. package/cjs/render/contributions/render/image-render.js +3 -3
  157. package/cjs/render/contributions/render/image-render.js.map +1 -1
  158. package/cjs/render/contributions/render/path-render.js.map +1 -1
  159. package/cjs/render/contributions/render/polygon-render.js.map +1 -1
  160. package/cjs/render/contributions/render/rect-render.js +2 -2
  161. package/cjs/render/contributions/render/rect-render.js.map +1 -1
  162. package/cjs/render/contributions/render/richtext-render.js +1 -1
  163. package/cjs/render/contributions/render/richtext-render.js.map +1 -1
  164. package/cjs/render/contributions/render/symbol-render.js +15 -13
  165. package/cjs/render/contributions/render/symbol-render.js.map +1 -1
  166. package/cjs/render/contributions/render/utils.d.ts +1 -2
  167. package/cjs/render/contributions/render/utils.js +4 -20
  168. package/cjs/render/contributions/render/utils.js.map +1 -1
  169. package/cjs/resource-loader/loader.js +1 -1
  170. package/cjs/resource-loader/loader.js.map +1 -1
  171. package/dist/index.es.js +8652 -7685
  172. package/es/animate/Ticker/default-ticker.d.ts +2 -0
  173. package/es/animate/Ticker/default-ticker.js +7 -1
  174. package/es/animate/Ticker/default-ticker.js.map +1 -1
  175. package/es/animate/animate.js +1 -1
  176. package/es/animate/animate.js.map +1 -1
  177. package/es/animate/custom-animate.js +14 -25
  178. package/es/animate/custom-animate.js.map +1 -1
  179. package/es/animate/easing-func.d.ts +1 -0
  180. package/es/animate/easing-func.js +10 -0
  181. package/es/animate/easing-func.js.map +1 -0
  182. package/es/animate/easing.d.ts +4 -0
  183. package/es/animate/easing.js +24 -1
  184. package/es/animate/easing.js.map +1 -1
  185. package/es/animate/index.d.ts +1 -0
  186. package/es/animate/index.js +2 -0
  187. package/es/animate/index.js.map +1 -1
  188. package/es/color-string/store.js +1 -2
  189. package/es/common/3d-interceptor.js +2 -1
  190. package/es/common/bezier-utils.d.ts +3 -0
  191. package/es/common/bezier-utils.js +14 -0
  192. package/es/common/bezier-utils.js.map +1 -1
  193. package/es/common/custom-path2d.d.ts +4 -0
  194. package/es/common/custom-path2d.js +44 -12
  195. package/es/common/custom-path2d.js.map +1 -1
  196. package/es/common/render-area.js +1 -2
  197. package/es/common/render-command-list.js +2 -1
  198. package/es/common/segment/curve/arc.d.ts +4 -1
  199. package/es/common/segment/curve/arc.js +10 -1
  200. package/es/common/segment/curve/arc.js.map +1 -1
  201. package/es/common/segment/curve/base.d.ts +4 -1
  202. package/es/common/segment/curve/base.js.map +1 -1
  203. package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
  204. package/es/common/segment/curve/cubic-bezier.js +22 -1
  205. package/es/common/segment/curve/cubic-bezier.js.map +1 -1
  206. package/es/common/segment/curve/curve-context.js +6 -3
  207. package/es/common/segment/curve/curve-context.js.map +1 -1
  208. package/es/common/segment/curve/ellipse.d.ts +4 -1
  209. package/es/common/segment/curve/ellipse.js +9 -0
  210. package/es/common/segment/curve/ellipse.js.map +1 -1
  211. package/es/common/segment/curve/line.d.ts +4 -1
  212. package/es/common/segment/curve/line.js +18 -0
  213. package/es/common/segment/curve/line.js.map +1 -1
  214. package/es/common/segment/curve/move.d.ts +4 -1
  215. package/es/common/segment/curve/move.js +9 -0
  216. package/es/common/segment/curve/move.js.map +1 -1
  217. package/es/common/segment/curve/path.d.ts +2 -1
  218. package/es/common/segment/curve/path.js +5 -2
  219. package/es/common/segment/curve/path.js.map +1 -1
  220. package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
  221. package/es/common/segment/curve/quadratic-bezier.js +28 -5
  222. package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
  223. package/es/common/shape/rect.d.ts +1 -1
  224. package/es/common/shape/rect.js +30 -25
  225. package/es/common/shape/rect.js.map +1 -1
  226. package/es/common/store.js +1 -1
  227. package/es/core/contributions/env/base-contribution.d.ts +2 -0
  228. package/es/core/contributions/env/base-contribution.js +6 -0
  229. package/es/core/contributions/env/base-contribution.js.map +1 -1
  230. package/es/core/global.d.ts +5 -0
  231. package/es/core/global.js +14 -1
  232. package/es/core/global.js.map +1 -1
  233. package/es/graphic/builtin-symbol/rect.d.ts +2 -1
  234. package/es/graphic/builtin-symbol/rect.js +28 -0
  235. package/es/graphic/builtin-symbol/rect.js.map +1 -1
  236. package/es/graphic/builtin-symbol/utils.d.ts +2 -1
  237. package/es/graphic/builtin-symbol/utils.js +5 -0
  238. package/es/graphic/builtin-symbol/utils.js.map +1 -1
  239. package/es/graphic/config.js +19 -5
  240. package/es/graphic/config.js.map +1 -1
  241. package/es/graphic/graphic.js +15 -1
  242. package/es/graphic/graphic.js.map +1 -1
  243. package/es/graphic/richtext/line.js +1 -1
  244. package/es/graphic/richtext/line.js.map +1 -1
  245. package/es/graphic/richtext/paragraph.d.ts +1 -1
  246. package/es/graphic/richtext/paragraph.js +9 -4
  247. package/es/graphic/richtext/paragraph.js.map +1 -1
  248. package/es/graphic/richtext/utils.d.ts +4 -0
  249. package/es/graphic/richtext/utils.js +15 -2
  250. package/es/graphic/richtext/utils.js.map +1 -1
  251. package/es/graphic/richtext/wrapper.d.ts +1 -0
  252. package/es/graphic/richtext/wrapper.js +1 -1
  253. package/es/graphic/richtext/wrapper.js.map +1 -1
  254. package/es/graphic/richtext.d.ts +7 -2
  255. package/es/graphic/richtext.js +33 -4
  256. package/es/graphic/richtext.js.map +1 -1
  257. package/es/index.d.ts +2 -0
  258. package/es/index.js +4 -0
  259. package/es/index.js.map +1 -1
  260. package/es/interface/animate.d.ts +5 -39
  261. package/es/interface/animate.js.map +1 -1
  262. package/es/interface/context.d.ts +1 -0
  263. package/es/interface/context.js.map +1 -1
  264. package/es/interface/global.d.ts +5 -0
  265. package/es/interface/global.js.map +1 -1
  266. package/es/interface/graphic/group.d.ts +1 -0
  267. package/es/interface/graphic/group.js.map +1 -1
  268. package/es/interface/graphic/image.d.ts +1 -0
  269. package/es/interface/graphic/image.js.map +1 -1
  270. package/es/interface/graphic/path.d.ts +1 -0
  271. package/es/interface/graphic/path.js.map +1 -1
  272. package/es/interface/graphic/rect.d.ts +1 -0
  273. package/es/interface/graphic/rect.js.map +1 -1
  274. package/es/interface/graphic/richText.d.ts +2 -0
  275. package/es/interface/graphic/richText.js.map +1 -1
  276. package/es/interface/graphic/symbol.d.ts +2 -0
  277. package/es/interface/graphic/symbol.js.map +1 -1
  278. package/es/interface/graphic.d.ts +11 -2
  279. package/es/interface/graphic.js.map +1 -1
  280. package/es/interface/path.d.ts +5 -0
  281. package/es/interface/path.js.map +1 -1
  282. package/es/interface/picker.d.ts +13 -0
  283. package/es/interface/picker.js.map +1 -1
  284. package/es/picker/constants.d.ts +2 -0
  285. package/es/picker/constants.js +4 -0
  286. package/es/picker/constants.js.map +1 -1
  287. package/es/picker/pick-interceptor.d.ts +7 -2
  288. package/es/picker/pick-interceptor.js +19 -1
  289. package/es/picker/pick-interceptor.js.map +1 -1
  290. package/es/picker/pick-modules.js +5 -3
  291. package/es/picker/pick-modules.js.map +1 -1
  292. package/es/picker/picker-service.d.ts +4 -2
  293. package/es/picker/picker-service.js +13 -13
  294. package/es/picker/picker-service.js.map +1 -1
  295. package/es/plugins/builtin-plugin/edit-module.d.ts +15 -5
  296. package/es/plugins/builtin-plugin/edit-module.js +119 -40
  297. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  298. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  299. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  300. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  301. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +62 -29
  302. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +349 -211
  303. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  304. package/es/render/contributions/render/arc3d-render.js.map +1 -1
  305. package/es/render/contributions/render/base-render.d.ts +1 -0
  306. package/es/render/contributions/render/base-render.js +21 -2
  307. package/es/render/contributions/render/base-render.js.map +1 -1
  308. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  309. package/es/render/contributions/render/contributions/base-contribution-render.js +16 -8
  310. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  311. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  312. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  313. package/es/render/contributions/render/contributions/group-contribution-render.js +8 -3
  314. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  315. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  316. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  317. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  318. package/es/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  319. package/es/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  320. package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  321. package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
  322. package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  323. package/es/render/contributions/render/contributions/text-contribution-render.js +5 -3
  324. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  325. package/es/render/contributions/render/group-render.js +2 -2
  326. package/es/render/contributions/render/group-render.js.map +1 -1
  327. package/es/render/contributions/render/image-render.js +3 -2
  328. package/es/render/contributions/render/image-render.js.map +1 -1
  329. package/es/render/contributions/render/path-render.js.map +1 -1
  330. package/es/render/contributions/render/polygon-render.js.map +1 -1
  331. package/es/render/contributions/render/rect-render.js +2 -2
  332. package/es/render/contributions/render/rect-render.js.map +1 -1
  333. package/es/render/contributions/render/richtext-render.js +1 -1
  334. package/es/render/contributions/render/richtext-render.js.map +1 -1
  335. package/es/render/contributions/render/symbol-render.js +16 -14
  336. package/es/render/contributions/render/symbol-render.js.map +1 -1
  337. package/es/render/contributions/render/utils.d.ts +1 -2
  338. package/es/render/contributions/render/utils.js +0 -18
  339. package/es/render/contributions/render/utils.js.map +1 -1
  340. package/es/resource-loader/loader.js +1 -1
  341. package/es/resource-loader/loader.js.map +1 -1
  342. package/package.json +3 -3
@@ -1,38 +1,55 @@
1
- import { isObject, isString, merge } from "@visactor/vutils";
1
+ import { isObject, merge } from "@visactor/vutils";
2
2
 
3
3
  import { Generator } from "../../common/generator";
4
4
 
5
- import { createGroup, createLine, createRect } from "../../graphic";
5
+ import { createGroup, createLine, createRect, RichText } from "../../graphic";
6
6
 
7
- import { EditModule, findCursorIndexIgnoreLinebreak } from "./edit-module";
7
+ import { DefaultTicker, DefaultTimeline } from "../../animate";
8
+
9
+ import { EditModule, findConfigIndexByCursorIdx } from "./edit-module";
10
+
11
+ import { application } from "../../application";
12
+
13
+ import { getWordStartEndIdx } from "../../graphic/richtext/utils";
8
14
 
9
15
  class Selection {
10
- constructor(cacheSelectionStartCursorIdx, cacheCurCursorIdx, selectionStartCursorIdx, curCursorIdx, rt) {
16
+ constructor(selectionStartCursorIdx, curCursorIdx, rt) {
11
17
  this.curCursorIdx = curCursorIdx, this.selectionStartCursorIdx = selectionStartCursorIdx,
12
- this.cacheCurCursorIdx = cacheCurCursorIdx, this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx,
13
18
  this.rt = rt;
14
19
  }
20
+ isEmpty() {
21
+ return this.selectionStartCursorIdx === this.curCursorIdx;
22
+ }
23
+ getSelectionPureText() {
24
+ const minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
25
+ if (minCursorIdx === maxCursorIdx) return "";
26
+ const config = this.rt.attribute.textConfig, startIdx = findConfigIndexByCursorIdx(config, Math.ceil(minCursorIdx)), endIdx = findConfigIndexByCursorIdx(config, Math.floor(maxCursorIdx));
27
+ let str = "";
28
+ for (let i = startIdx; i <= endIdx; i++) str += config[i].text;
29
+ return str;
30
+ }
15
31
  hasFormat(key) {
16
32
  return null != this.getFormat(key);
17
33
  }
18
- getFormat(key) {
34
+ _getFormat(key, cursorIdx) {
35
+ var _a;
19
36
  if (!this.rt) return null;
20
- const config = this.rt.attribute.textConfig, val = config[this.selectionStartCursorIdx + 1][key];
21
- if (null == val) return null;
22
- for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
23
- if (val !== config[i][key]) return null;
24
- }
25
- return val;
37
+ let idx = Math.round(cursorIdx);
38
+ const config = this.rt.attribute.textConfig;
39
+ for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
40
+ return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
41
+ }
42
+ getFormat(key) {
43
+ return this.getAllFormat(key)[0];
26
44
  }
27
45
  getAllFormat(key) {
28
- if (!this.rt) return [];
29
- const config = this.rt.attribute.textConfig, val = config[this.selectionStartCursorIdx + 1][key], set = new Set;
30
- set.add(val);
31
- for (let i = this.selectionStartCursorIdx + 2; i <= this.curCursorIdx; i++) {
32
- const item = config[i];
33
- set.add(item[key]);
46
+ const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
47
+ if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
48
+ for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
49
+ const val = this._getFormat(key, i);
50
+ val && valSet.add(val);
34
51
  }
35
- return Array.from(set.values());
52
+ return Array.from(valSet.values());
36
53
  }
37
54
  }
38
55
 
@@ -41,39 +58,57 @@ export const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
41
58
  export const FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
42
59
 
43
60
  export class RichTextEditPlugin {
61
+ static tryUpdateRichtext(richtext) {
62
+ const cache = richtext.getFrameCache();
63
+ if (!RichText.AllSingleCharacter(cache)) {
64
+ const tc = RichText.TransformTextConfig2SingleCharacter(richtext.attribute.textConfig);
65
+ richtext.setAttributes({
66
+ textConfig: tc
67
+ }), richtext.doUpdateFrameCache(tc);
68
+ }
69
+ }
70
+ static CreateSelection(rt) {
71
+ if (!rt) return null;
72
+ const {textConfig: textConfig = []} = rt.attribute;
73
+ return new Selection(0, textConfig.length - 1, rt);
74
+ }
44
75
  constructor() {
45
76
  this.name = "RichTextEditPlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(),
46
- this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.handleInput = (text, isComposing, cursorIdx, rt, orient) => {
47
- const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
48
- this.hideSelection(), this.setCursor(p.x, p.y1, p.y2), this.updateCbs.forEach((cb => cb("input", this)));
49
- }, this.handleChange = (text, isComposing, cursorIdx, rt, orient) => {
50
- const p = this.getPointByColumnIdx(cursorIdx, rt, orient);
51
- this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx, this.setCursorAndTextArea(p.x, p.y1, p.y2, rt),
52
- this.hideSelection(), this.updateCbs.forEach((cb => cb("change", this)));
77
+ this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.handleKeyDown = e => {
78
+ this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
79
+ }, this.handleInput = (text, isComposing, cursorIdx, rt) => {
80
+ this.hideSelection(), this.updateCbs.forEach((cb => cb("input", this)));
81
+ }, this.handleChange = (text, isComposing, cursorIdx, rt) => {
82
+ this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx;
83
+ const p = this.computedCursorPosByCursorIdx(cursorIdx, rt);
84
+ this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach((cb => cb("change", this)));
85
+ }, this.handleFocusIn = () => {}, this.handleFocusOut = () => {
86
+ this.editing = !1, this.deFocus(), this.pointerDown = !1, this.triggerRender(),
87
+ this.updateCbs.forEach((cb => cb("defocus", this)));
53
88
  }, this.handleMove = e => {
54
89
  this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave),
55
- this.showSelection(e));
56
- }, this.handlePointerDown = e => {
57
- this.editing ? this.onFocus(e) : this.deFocus(e), this.applyUpdate(), this.pointerDown = !0,
58
- this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
59
- }, this.handlePointerUp = e => {
60
- this.pointerDown = !1;
90
+ this.tryShowSelection(e, !1));
61
91
  }, this.handleEnter = e => {
62
92
  this.editing = !0, this.pluginService.stage.setCursor("text");
63
93
  }, this.handleLeave = e => {
64
94
  this.editing = !1, this.pluginService.stage.setCursor("default");
95
+ }, this.handlePointerDown = e => {
96
+ this.editing ? this.onFocus(e) : this.deFocus(), this.triggerRender(), this.pointerDown = !0,
97
+ this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
98
+ }, this.handlePointerUp = e => {
99
+ this.pointerDown = !1;
100
+ }, this.handleDBLClick = e => {
101
+ this.editing && this.tryShowSelection(e, !0);
65
102
  }, this.commandCbs = new Map, this.commandCbs.set(FORMAT_TEXT_COMMAND, [ this.formatTextCommandCb ]),
66
- this.updateCbs = [];
67
- }
68
- getSelection() {
69
- return this.selectionStartCursorIdx && this.curCursorIdx && this.selectionStartCursorIdx !== this.curCursorIdx && this.currRt ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.selectionStartCursorIdx), findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.curCursorIdx), this.currRt) : null;
103
+ this.updateCbs = [], this.timeline = new DefaultTimeline, this.ticker = new DefaultTicker([ this.timeline ]),
104
+ this.deltaX = 0, this.deltaY = 0;
70
105
  }
71
106
  formatTextCommandCb(payload, p) {
72
107
  const rt = p.currRt;
73
108
  if (!rt) return;
74
109
  const selectionData = p.getSelection();
75
110
  if (!selectionData) return;
76
- const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, config = rt.attribute.textConfig.slice(selectionStartCursorIdx + 1, curCursorIdx + 1);
111
+ const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
77
112
  "bold" === payload ? config.forEach((item => item.fontWeight = "bold")) : "italic" === payload ? config.forEach((item => item.fontStyle = "italic")) : "underline" === payload ? config.forEach((item => item.underline = !0)) : "lineThrough" === payload ? config.forEach((item => item.lineThrough = !0)) : isObject(payload) && config.forEach((item => merge(item, payload))),
78
113
  rt.setAttributes(rt.attribute);
79
114
  }
@@ -90,125 +125,102 @@ export class RichTextEditPlugin {
90
125
  activate(context) {
91
126
  this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove),
92
127
  context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
93
- context.stage.on("pointerleave", this.handlePointerUp), this.editModule.onInput(this.handleInput),
94
- this.editModule.onChange(this.handleChange);
128
+ context.stage.on("pointerleave", this.handlePointerUp), context.stage.on("dblclick", this.handleDBLClick),
129
+ application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
130
+ this.editModule.onChange(this.handleChange), this.editModule.onFocusOut(this.handleFocusOut);
95
131
  }
96
- showSelection(e) {
97
- const cache = e.target.getFrameCache();
98
- if (cache && this.editBg && this.pointerDown) {
99
- let p0 = this.lastPoint, p1 = this.getEventPosition(e), line1Info = this.getLineByPoint(cache, p1);
100
- const column1 = this.getColumnByLinePoint(line1Info, p1), y1 = line1Info.top, y2 = line1Info.top + line1Info.height;
101
- let x = column1.left + column1.width, cursorIndex = this.getColumnIndex(cache, column1);
102
- p1.x < column1.left + column1.width / 2 && (x = column1.left, cursorIndex -= 1),
103
- p1.x = x, p1.y = (y1 + y2) / 2;
104
- let line0Info = this.getLineByPoint(cache, p0);
105
- if ((p0.y > p1.y || p0.y === p1.y && p0.x > p1.x) && ([p0, p1] = [ p1, p0 ], [line1Info, line0Info] = [ line0Info, line1Info ]),
106
- this.editBg.removeAllChild(), line0Info === line1Info) {
107
- const column0 = this.getColumnByLinePoint(line0Info, p0);
108
- this.editBg.setAttributes({
109
- x: p0.x,
110
- y: line0Info.top,
111
- width: p1.x - p0.x,
112
- height: column0.height,
113
- fill: "#336df4",
114
- fillOpacity: .2
115
- });
116
- } else {
117
- this.editBg.setAttributes({
118
- x: 0,
119
- y: line0Info.top,
120
- width: 0,
121
- height: 0
122
- });
123
- const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
124
- let y = 0;
125
- for (let i = startIdx; i <= endIdx; i++) {
126
- const line = cache.lines[i];
127
- if (i === startIdx) {
128
- const p = line.paragraphs[line.paragraphs.length - 1];
129
- this.editBg.add(createRect({
130
- x: p0.x,
131
- y: y,
132
- width: p.left + p.width - p0.x,
133
- height: line.height,
134
- fill: "#336df4",
135
- fillOpacity: .2
136
- }));
137
- } else if (i === endIdx) {
138
- const p = line.paragraphs[0];
139
- this.editBg.add(createRect({
140
- x: p.left,
141
- y: y,
142
- width: p1.x - p.left,
143
- height: line.height,
144
- fill: "#336df4",
145
- fillOpacity: .2
146
- }));
147
- } else {
148
- const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
149
- this.editBg.add(createRect({
150
- x: p0.left,
151
- y: y,
152
- width: p1.left + p1.width - p0.left,
153
- height: line.height,
154
- fill: "#336df4",
155
- fillOpacity: .2
156
- }));
157
- }
158
- y += line.height;
159
- }
160
- }
161
- this.curCursorIdx = cursorIndex, this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target),
162
- this.applyUpdate(), this.updateCbs.forEach((cb => cb("selection", this)));
132
+ copyToClipboard(e) {
133
+ if (application.global.isMacOS() && e.metaKey && "c" === e.key || !application.global.isMacOS() && e.ctrlKey && "c" === e.key) {
134
+ const text = this.getSelection().getSelectionPureText();
135
+ return application.global.copyToClipBoard(text), e.preventDefault(), !0;
163
136
  }
137
+ return !1;
164
138
  }
165
- hideSelection() {
166
- this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
167
- fill: "transparent"
168
- }));
169
- }
170
- isRichtext(e) {
171
- return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
172
- }
173
- getEventPosition(e) {
174
- const p = this.pluginService.stage.eventPointTransform(e), p1 = {
175
- x: 0,
176
- y: 0
139
+ selectionRange(startIdx, endIdx) {
140
+ const currRt = this.currRt;
141
+ if (!currRt) return;
142
+ const cache = currRt.getFrameCache();
143
+ if (!cache) return;
144
+ const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
145
+ startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), startIdx = Math.min(Math.max(startIdx, -.1), totalCursorCount + .1),
146
+ endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.curCursorIdx = endIdx,
147
+ this.selectionStartCursorIdx = startIdx;
148
+ const {x: x, y1: y1, y2: y2} = this.computedCursorPosByCursorIdx(this.selectionStartCursorIdx, this.currRt);
149
+ this.startCursorPos = {
150
+ x: x,
151
+ y: (y1 + y2) / 2
177
152
  };
178
- return e.target.globalTransMatrix.transformPoint(p, p1), p1;
153
+ const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
154
+ this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
179
155
  }
180
- getLineByPoint(cache, p1) {
181
- let lineInfo = cache.lines[0];
182
- for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
183
- return lineInfo;
156
+ fullSelection(e) {
157
+ if (application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) {
158
+ const currRt = this.currRt;
159
+ if (!currRt) return;
160
+ const cache = currRt.getFrameCache();
161
+ if (!cache) return;
162
+ const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
163
+ return this.selectionRange(-.1, totalCursorCount + .1), e.preventDefault(), !0;
164
+ }
165
+ return !1;
166
+ }
167
+ directKey(e) {
168
+ if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
169
+ const cache = this.currRt.getFrameCache();
170
+ if (!cache) return !1;
171
+ let x = 0, y = 0;
172
+ "ArrowUp" === e.key ? y = -1 : "ArrowDown" === e.key ? y = 1 : "ArrowLeft" === e.key ? x = -1 : "ArrowRight" === e.key && (x = 1);
173
+ const {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, Math.round(this.curCursorIdx)), {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
174
+ if (x) {
175
+ x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 2] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + .2 : x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 1] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + 1 - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - 1 + .2 : this.curCursorIdx += x,
176
+ this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
177
+ const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
178
+ this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
179
+ }
180
+ if (y) {
181
+ if (y > 0 && lineInfo === cache.lines[cache.lines.length - 1]) return;
182
+ if (y < 0 && lineInfo === cache.lines[0]) return;
183
+ const lineIdx = cache.lines.findIndex((item => item === lineInfo)) + y;
184
+ if (lineIdx < 0 || lineIdx >= cache.lines.length) return;
185
+ const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt), posX = pos.x;
186
+ let posY = (pos.y1 + pos.y2) / 2;
187
+ posY += y * lineInfo.height;
188
+ const nextLineInfo = cache.lines[lineIdx], {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(nextLineInfo, {
189
+ x: posX,
190
+ y: posY
191
+ });
192
+ if (!columnInfo) return;
193
+ let cursorIdx = this.getColumnIndex(cache, columnInfo) + delta;
194
+ const data = this.computedCursorPosByCursorIdx(cursorIdx, this.currRt);
195
+ cursorIdx < -.1 ? cursorIdx = -.1 : cursorIdx > totalCursorCount + .1 && (cursorIdx = totalCursorCount + .1),
196
+ this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx, this.setCursorAndTextArea(data.x, data.y1, data.y2, this.currRt);
197
+ }
198
+ return !0;
184
199
  }
185
- getColumnByLinePoint(lineInfo, p1) {
186
- let columnInfo = lineInfo.paragraphs[0];
187
- for (let i = 0; i < lineInfo.paragraphs.length && !(columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x); i++) columnInfo = lineInfo.paragraphs[i];
188
- return columnInfo;
200
+ deactivate(context) {
201
+ context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
202
+ context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
203
+ context.stage.off("dblclick", this.handleDBLClick), application.global.addEventListener("keydown", this.handleKeyDown);
189
204
  }
190
205
  onFocus(e) {
191
- this.deFocus(e);
206
+ this.deFocus(), this.currRt = e.target;
192
207
  const target = e.target;
193
- this.tryUpdateRichtext(target);
194
- const shadowRoot = target.attachShadow();
195
- shadowRoot.setAttributes({
196
- shadowRootIdx: -1
197
- });
198
- const cache = target.getFrameCache();
208
+ RichTextEditPlugin.tryUpdateRichtext(target);
209
+ const shadowRoot = target.attachShadow(), cache = target.getFrameCache();
199
210
  if (!cache) return;
200
- if (!this.editLine) {
211
+ if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
212
+ shadowRootIdx: 1,
213
+ pickable: !1,
214
+ x: this.deltaX,
215
+ y: this.deltaY
216
+ }), !this.editLine) {
201
217
  const line = createLine({
202
218
  x: 0,
203
219
  y: 0,
204
220
  lineWidth: 1,
205
221
  stroke: "black"
206
222
  });
207
- line.animate().to({
208
- opacity: 1
209
- }, 10, "linear").wait(700).to({
210
- opacity: 0
211
- }, 10, "linear").wait(700).loop(1 / 0), this.editLine = line;
223
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
212
224
  const g = createGroup({
213
225
  x: 0,
214
226
  y: 0,
@@ -217,28 +229,141 @@ export class RichTextEditPlugin {
217
229
  });
218
230
  this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
219
231
  }
220
- const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
221
- if (lineInfo) {
222
- const columnInfo = this.getColumnByLinePoint(lineInfo, p1);
223
- if (!columnInfo) return;
224
- let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height, x = columnInfo.left + columnInfo.width;
225
- y1 += 2, y2 -= 2;
226
- let cursorIndex = this.getColumnIndex(cache, columnInfo);
227
- p1.x < columnInfo.left + columnInfo.width / 2 && (x = columnInfo.left, cursorIndex -= 1),
228
- this.lastPoint = {
232
+ const data = this.computedCursorPosByEvent(e, cache);
233
+ if (data) {
234
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
235
+ this.startCursorPos = {
229
236
  x: x,
230
237
  y: (y1 + y2) / 2
231
238
  }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
232
239
  this.setCursorAndTextArea(x, y1, y2, target);
233
240
  }
234
241
  }
235
- getPointByColumnIdx(idx, rt, orient) {
236
- const cache = rt.getFrameCache(), {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, idx);
237
- let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
238
- return y1 += 2, y2 -= 2, {
239
- x: columnInfo.left + ("left" === orient ? 0 : columnInfo.width),
240
- y1: y1,
241
- y2: y2
242
+ deFocus() {
243
+ const target = this.currRt;
244
+ target && (target.detachShadow(), this.currRt = null, this.editLine && (this.editLine.parent.removeChild(this.editLine),
245
+ this.editLine.release(), this.editLine = null, this.editBg.parent.removeChild(this.editBg),
246
+ this.editBg.release(), this.editBg = null));
247
+ }
248
+ addAnimateToLine(line) {
249
+ line.animates && line.animates.forEach((animate => {
250
+ animate.stop(), animate.release();
251
+ }));
252
+ const animate = line.animate();
253
+ animate.setTimeline(this.timeline), animate.to({
254
+ opacity: 1
255
+ }, 10, "linear").wait(700).to({
256
+ opacity: 0
257
+ }, 10, "linear").wait(700).loop(1 / 0);
258
+ }
259
+ tryShowSelection(e, dblclick) {
260
+ const cache = e.target.getFrameCache();
261
+ if (cache && this.editBg && this.startCursorPos) if (dblclick) {
262
+ const currCursorData = this.computedCursorPosByEvent(e, cache);
263
+ if (!currCursorData) return;
264
+ const lineInfo = currCursorData.lineInfo, columnIndex = lineInfo.paragraphs.findIndex((item => item === currCursorData.columnInfo));
265
+ if (columnIndex < 0) return;
266
+ const str = lineInfo.paragraphs.reduce(((str, item) => str + item.text), "");
267
+ let idx = 0;
268
+ for (let i = 0; i < cache.lines.length; i++) {
269
+ const line = cache.lines[i];
270
+ if (line === lineInfo) break;
271
+ idx += line.paragraphs.length;
272
+ }
273
+ const {startIdx: startIdx, endIdx: endIdx} = getWordStartEndIdx(str, columnIndex);
274
+ this.selectionRange(idx + startIdx - .1, idx + endIdx - .1);
275
+ } else if (this.pointerDown) {
276
+ const currCursorData = this.computedCursorPosByEvent(e, cache);
277
+ if (!currCursorData) return;
278
+ this.curCursorIdx = currCursorData.cursorIndex, this._tryShowSelection(currCursorData, cache);
279
+ }
280
+ }
281
+ _tryShowSelection(currCursorData, cache) {
282
+ let startCursorPos = this.startCursorPos, endCursorPos = {
283
+ x: currCursorData.x,
284
+ y: (currCursorData.y1 + currCursorData.y2) / 2
285
+ }, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
286
+ if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
287
+ [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
288
+ x: startCursorPos.x,
289
+ y: line0Info.top,
290
+ width: endCursorPos.x - startCursorPos.x,
291
+ height: line0Info.height,
292
+ fill: "#336df4",
293
+ fillOpacity: .2
294
+ }); else {
295
+ this.editBg.setAttributes({
296
+ x: 0,
297
+ y: line0Info.top,
298
+ width: 0,
299
+ height: 0
300
+ });
301
+ const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
302
+ let y = 0;
303
+ for (let i = startIdx; i <= endIdx; i++) {
304
+ const line = cache.lines[i];
305
+ if (i === startIdx) {
306
+ const p = line.paragraphs[line.paragraphs.length - 1];
307
+ this.editBg.add(createRect({
308
+ x: startCursorPos.x,
309
+ y: y,
310
+ width: p.left + p.width - startCursorPos.x,
311
+ height: line.height,
312
+ fill: "#336df4",
313
+ fillOpacity: .2
314
+ }));
315
+ } else if (i === endIdx) {
316
+ const p = line.paragraphs[0];
317
+ this.editBg.add(createRect({
318
+ x: p.left,
319
+ y: y,
320
+ width: endCursorPos.x - p.left,
321
+ height: line.height,
322
+ fill: "#336df4",
323
+ fillOpacity: .2
324
+ }));
325
+ } else {
326
+ const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
327
+ this.editBg.add(createRect({
328
+ x: p0.left,
329
+ y: y,
330
+ width: p1.left + p1.width - p0.left,
331
+ height: line.height,
332
+ fill: "#336df4",
333
+ fillOpacity: .2
334
+ }));
335
+ }
336
+ y += line.height;
337
+ }
338
+ }
339
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1 + 2, currCursorData.y2 - 2, this.currRt),
340
+ this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
341
+ }
342
+ hideSelection() {
343
+ this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
344
+ fill: "transparent"
345
+ }));
346
+ }
347
+ getLineByPoint(cache, p1) {
348
+ let lineInfo = cache.lines[0];
349
+ for (let i = 0; i < cache.lines.length && !(lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y); i++) lineInfo = cache.lines[i + 1];
350
+ return lineInfo;
351
+ }
352
+ getColumnAndIndexByLinePoint(lineInfo, p1) {
353
+ let columnInfo = lineInfo.paragraphs[0], delta = 0;
354
+ if (lineInfo.paragraphs.length) {
355
+ const start = lineInfo.paragraphs[0], end = lineInfo.paragraphs[lineInfo.paragraphs.length - 1];
356
+ p1.x <= start.left ? (delta = -.1, columnInfo = start) : p1.x >= end.left + end.width && (delta = .1,
357
+ columnInfo = end);
358
+ }
359
+ if (!delta) for (let i = 0; i < lineInfo.paragraphs.length; i++) if (columnInfo = lineInfo.paragraphs[i],
360
+ columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x) {
361
+ delta = p1.x > columnInfo.left + columnInfo.width / 2 ? .1 : -.1;
362
+ break;
363
+ }
364
+ return {
365
+ columnInfo: columnInfo,
366
+ delta: delta
242
367
  };
243
368
  }
244
369
  getColumnIndex(cache, cInfo) {
@@ -249,19 +374,25 @@ export class RichTextEditPlugin {
249
374
  }
250
375
  return -1;
251
376
  }
252
- getColumnByIndex(cache, index) {
253
- let inputIndex = -1;
254
- for (let i = 0; i < cache.lines.length; i++) {
255
- const lineInfo = cache.lines[i];
256
- for (let j = 0; j < lineInfo.paragraphs.length; j++) {
257
- const columnInfo = lineInfo.paragraphs[j];
258
- if (inputIndex++, inputIndex === index) return {
259
- lineInfo: lineInfo,
260
- columnInfo: columnInfo
261
- };
262
- }
263
- }
264
- return null;
377
+ isRichtext(e) {
378
+ return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
379
+ }
380
+ triggerRender() {
381
+ this.pluginService.stage.renderNextFrame();
382
+ }
383
+ computeGlobalDelta(cache) {
384
+ this.deltaX = 0, this.deltaY = 0;
385
+ const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
386
+ "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
387
+ "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
388
+ }
389
+ getEventPosition(e) {
390
+ const p = this.pluginService.stage.eventPointTransform(e), p1 = {
391
+ x: 0,
392
+ y: 0
393
+ };
394
+ return e.target.globalTransMatrix.transformPoint(p, p1), p1.x -= this.deltaX, p1.y -= this.deltaY,
395
+ p1;
265
396
  }
266
397
  setCursorAndTextArea(x, y1, y2, rt) {
267
398
  this.editLine.setAttributes({
@@ -272,7 +403,7 @@ export class RichTextEditPlugin {
272
403
  x: x,
273
404
  y: y2
274
405
  } ]
275
- });
406
+ }), this.addAnimateToLine(this.editLine);
276
407
  const out = {
277
408
  x: 0,
278
409
  y: 0
@@ -284,52 +415,59 @@ export class RichTextEditPlugin {
284
415
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
285
416
  out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
286
417
  }
287
- setCursor(x, y1, y2) {
288
- this.editLine.setAttributes({
289
- points: [ {
290
- x: x,
291
- y: y1
292
- }, {
293
- x: x,
294
- y: y2
295
- } ]
296
- });
297
- }
298
- applyUpdate() {
299
- this.pluginService.stage.renderNextFrame();
418
+ computedCursorPosByEvent(e, cache) {
419
+ const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
420
+ if (!lineInfo) return;
421
+ const {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(lineInfo, p1);
422
+ if (!columnInfo) return;
423
+ let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
424
+ y1 += 2, y2 -= 2;
425
+ let cursorIndex = this.getColumnIndex(cache, columnInfo);
426
+ cursorIndex += delta;
427
+ return {
428
+ x: columnInfo.left + (delta > 0 ? columnInfo.width : 0),
429
+ y1: y1,
430
+ y2: y2,
431
+ cursorIndex: cursorIndex,
432
+ lineInfo: lineInfo,
433
+ columnInfo: columnInfo
434
+ };
300
435
  }
301
- deFocus(e) {
302
- const target = this.currRt;
303
- target && (target.detachShadow(), this.currRt = null, this.editLine && (this.editLine.parent.removeChild(this.editLine),
304
- this.editLine.release(), this.editLine = null, this.editBg.parent.removeChild(this.editBg),
305
- this.editBg.release(), this.editBg = null));
436
+ computedCursorPosByCursorIdx(cursorIdx, rt) {
437
+ var _a, _b, _c;
438
+ const idx = Math.round(cursorIdx), leftRight = cursorIdx - idx, cache = rt.getFrameCache(), column = this.getColumnByIndex(cache, idx), height = null !== (_a = rt.attribute.fontSize) && void 0 !== _a ? _a : null === (_c = null === (_b = rt.attribute.textConfig) || void 0 === _b ? void 0 : _b[0]) || void 0 === _c ? void 0 : _c.fontSize;
439
+ if (!column) return {
440
+ x: 0,
441
+ y1: 0,
442
+ y2: height
443
+ };
444
+ const {lineInfo: lineInfo, columnInfo: columnInfo} = column;
445
+ let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
446
+ return y1 += 2, y2 -= 2, {
447
+ x: columnInfo.left + (leftRight < 0 ? 0 : columnInfo.width),
448
+ y1: y1,
449
+ y2: y2
450
+ };
306
451
  }
307
- splitText(text) {
308
- return Array.from(text);
309
- }
310
- tryUpdateRichtext(richtext) {
311
- if (!richtext.getFrameCache().lines.every((line => line.paragraphs.every((item => !(item.text && isString(item.text) && this.splitText(item.text).length > 1)))))) {
312
- const tc = [];
313
- richtext.attribute.textConfig.forEach((item => {
314
- const textList = this.splitText(item.text.toString());
315
- if (isString(item.text) && textList.length > 1) for (let i = 0; i < textList.length; i++) {
316
- const t = textList[i];
317
- tc.push(Object.assign(Object.assign({}, item), {
318
- text: t
319
- }));
320
- } else tc.push(item);
321
- })), richtext.setAttributes({
322
- textConfig: tc
323
- }), richtext.doUpdateFrameCache(tc);
452
+ getColumnByIndex(cache, index) {
453
+ for (let i = 0, inputIndex = 0; i < cache.lines.length; i++) {
454
+ const lineInfo = cache.lines[i];
455
+ for (let j = 0; j < lineInfo.paragraphs.length; j++) {
456
+ const columnInfo = lineInfo.paragraphs[j];
457
+ if (inputIndex === index) return {
458
+ lineInfo: lineInfo,
459
+ columnInfo: columnInfo
460
+ };
461
+ inputIndex++;
462
+ }
324
463
  }
325
- }
326
- onSelect() {}
327
- deactivate(context) {
328
- context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
329
- context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp);
464
+ return null;
330
465
  }
331
466
  release() {
332
- this.editModule.release();
467
+ this.deactivate(this.pluginService), this.editModule.release();
468
+ }
469
+ getSelection(defaultAll = !1) {
470
+ return this.currRt ? null != this.selectionStartCursorIdx && null != this.curCursorIdx ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, this.currRt) : defaultAll ? RichTextEditPlugin.CreateSelection(this.currRt) : null : null;
333
471
  }
334
472
  }
335
473
  //# sourceMappingURL=richtext-edit-plugin.js.map