@visactor/vrender-core 0.21.14 → 0.22.0-vstory.10

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 (394) 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 +2 -2
  5. package/cjs/animate/animate.js.map +1 -1
  6. package/cjs/animate/custom-animate.js +15 -27
  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/canvas/util.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/inversify/container.js +6 -9
  26. package/cjs/common/inversify/container.js.map +1 -1
  27. package/cjs/common/render-area.d.ts +4 -0
  28. package/cjs/common/render-area.js +76 -17
  29. package/cjs/common/render-area.js.map +1 -1
  30. package/cjs/common/render-command-list.js +2 -1
  31. package/cjs/common/render-curve.d.ts +1 -1
  32. package/cjs/common/render-curve.js.map +1 -1
  33. package/cjs/common/segment/curve/arc.d.ts +4 -1
  34. package/cjs/common/segment/curve/arc.js +10 -1
  35. package/cjs/common/segment/curve/arc.js.map +1 -1
  36. package/cjs/common/segment/curve/base.d.ts +4 -1
  37. package/cjs/common/segment/curve/base.js.map +1 -1
  38. package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
  39. package/cjs/common/segment/curve/cubic-bezier.js +24 -3
  40. package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
  41. package/cjs/common/segment/curve/curve-context.js +5 -4
  42. package/cjs/common/segment/curve/curve-context.js.map +1 -1
  43. package/cjs/common/segment/curve/ellipse.d.ts +4 -1
  44. package/cjs/common/segment/curve/ellipse.js +9 -0
  45. package/cjs/common/segment/curve/ellipse.js.map +1 -1
  46. package/cjs/common/segment/curve/line.d.ts +4 -1
  47. package/cjs/common/segment/curve/line.js +18 -0
  48. package/cjs/common/segment/curve/line.js.map +1 -1
  49. package/cjs/common/segment/curve/move.d.ts +4 -1
  50. package/cjs/common/segment/curve/move.js +9 -0
  51. package/cjs/common/segment/curve/move.js.map +1 -1
  52. package/cjs/common/segment/curve/path.d.ts +2 -1
  53. package/cjs/common/segment/curve/path.js +5 -2
  54. package/cjs/common/segment/curve/path.js.map +1 -1
  55. package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
  56. package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
  57. package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
  58. package/cjs/common/segment/step.js +1 -1
  59. package/cjs/common/segment/step.js.map +1 -1
  60. package/cjs/common/shape/rect.d.ts +1 -1
  61. package/cjs/common/shape/rect.js +30 -25
  62. package/cjs/common/shape/rect.js.map +1 -1
  63. package/cjs/common/store.js +1 -1
  64. package/cjs/core/contributions/env/base-contribution.d.ts +2 -0
  65. package/cjs/core/contributions/env/base-contribution.js +6 -0
  66. package/cjs/core/contributions/env/base-contribution.js.map +1 -1
  67. package/cjs/core/contributions/textMeasure/AtextMeasure.js +0 -10
  68. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  69. package/cjs/core/global.d.ts +2 -3
  70. package/cjs/core/global.js +7 -7
  71. package/cjs/core/global.js.map +1 -1
  72. package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
  73. package/cjs/graphic/builtin-symbol/rect.js +28 -0
  74. package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
  75. package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
  76. package/cjs/graphic/builtin-symbol/utils.js +5 -0
  77. package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
  78. package/cjs/graphic/config.js +20 -5
  79. package/cjs/graphic/config.js.map +1 -1
  80. package/cjs/graphic/graphic.d.ts +1 -1
  81. package/cjs/graphic/graphic.js +20 -6
  82. package/cjs/graphic/graphic.js.map +1 -1
  83. package/cjs/graphic/group.js +1 -1
  84. package/cjs/graphic/group.js.map +1 -1
  85. package/cjs/graphic/line.js +2 -2
  86. package/cjs/graphic/line.js.map +1 -1
  87. package/cjs/graphic/richtext/line.js +13 -1
  88. package/cjs/graphic/richtext/line.js.map +1 -1
  89. package/cjs/graphic/richtext/paragraph.d.ts +9 -1
  90. package/cjs/graphic/richtext/paragraph.js +49 -5
  91. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  92. package/cjs/graphic/richtext/utils.d.ts +4 -0
  93. package/cjs/graphic/richtext/utils.js +23 -10
  94. package/cjs/graphic/richtext/utils.js.map +1 -1
  95. package/cjs/graphic/richtext/wrapper.d.ts +1 -0
  96. package/cjs/graphic/richtext/wrapper.js +1 -1
  97. package/cjs/graphic/richtext/wrapper.js.map +1 -1
  98. package/cjs/graphic/richtext.d.ts +8 -2
  99. package/cjs/graphic/richtext.js +43 -4
  100. package/cjs/graphic/richtext.js.map +1 -1
  101. package/cjs/index.d.ts +2 -0
  102. package/cjs/index.js +2 -1
  103. package/cjs/index.js.map +1 -1
  104. package/cjs/interface/animate.d.ts +5 -39
  105. package/cjs/interface/animate.js.map +1 -1
  106. package/cjs/interface/color.js.map +1 -1
  107. package/cjs/interface/context.d.ts +1 -0
  108. package/cjs/interface/context.js.map +1 -1
  109. package/cjs/interface/global.d.ts +4 -1
  110. package/cjs/interface/global.js.map +1 -1
  111. package/cjs/interface/graphic/group.d.ts +1 -0
  112. package/cjs/interface/graphic/group.js.map +1 -1
  113. package/cjs/interface/graphic/image.d.ts +1 -0
  114. package/cjs/interface/graphic/image.js.map +1 -1
  115. package/cjs/interface/graphic/path.d.ts +1 -0
  116. package/cjs/interface/graphic/path.js.map +1 -1
  117. package/cjs/interface/graphic/rect.d.ts +1 -0
  118. package/cjs/interface/graphic/rect.js.map +1 -1
  119. package/cjs/interface/graphic/richText.d.ts +13 -0
  120. package/cjs/interface/graphic/richText.js.map +1 -1
  121. package/cjs/interface/graphic/symbol.d.ts +2 -0
  122. package/cjs/interface/graphic/symbol.js.map +1 -1
  123. package/cjs/interface/graphic.d.ts +12 -3
  124. package/cjs/interface/graphic.js.map +1 -1
  125. package/cjs/interface/path.d.ts +5 -0
  126. package/cjs/interface/path.js.map +1 -1
  127. package/cjs/interface/picker.d.ts +13 -0
  128. package/cjs/interface/picker.js.map +1 -1
  129. package/cjs/picker/constants.d.ts +2 -0
  130. package/cjs/picker/constants.js +3 -2
  131. package/cjs/picker/constants.js.map +1 -1
  132. package/cjs/picker/pick-interceptor.d.ts +7 -2
  133. package/cjs/picker/pick-interceptor.js +19 -2
  134. package/cjs/picker/pick-interceptor.js.map +1 -1
  135. package/cjs/picker/pick-modules.js +7 -4
  136. package/cjs/picker/pick-modules.js.map +1 -1
  137. package/cjs/picker/picker-service.d.ts +4 -2
  138. package/cjs/picker/picker-service.js +13 -12
  139. package/cjs/picker/picker-service.js.map +1 -1
  140. package/cjs/plugins/builtin-plugin/edit-module.d.ts +17 -6
  141. package/cjs/plugins/builtin-plugin/edit-module.js +128 -42
  142. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  143. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  144. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  145. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  146. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +91 -32
  147. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +517 -193
  148. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  149. package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
  150. package/cjs/render/contributions/render/area-render.d.ts +1 -1
  151. package/cjs/render/contributions/render/area-render.js +36 -16
  152. package/cjs/render/contributions/render/area-render.js.map +1 -1
  153. package/cjs/render/contributions/render/base-render.d.ts +1 -0
  154. package/cjs/render/contributions/render/base-render.js +20 -2
  155. package/cjs/render/contributions/render/base-render.js.map +1 -1
  156. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  157. package/cjs/render/contributions/render/contributions/base-contribution-render.js +16 -8
  158. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  159. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  160. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  161. package/cjs/render/contributions/render/contributions/group-contribution-render.js +8 -3
  162. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  163. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  164. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  165. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  166. package/cjs/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  167. package/cjs/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  168. package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  169. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
  170. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  171. package/cjs/render/contributions/render/contributions/text-contribution-render.js +5 -3
  172. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  173. package/cjs/render/contributions/render/draw-contribution.js +3 -3
  174. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  175. package/cjs/render/contributions/render/group-render.js +2 -2
  176. package/cjs/render/contributions/render/group-render.js.map +1 -1
  177. package/cjs/render/contributions/render/image-render.js +3 -3
  178. package/cjs/render/contributions/render/image-render.js.map +1 -1
  179. package/cjs/render/contributions/render/line-render.js +31 -9
  180. package/cjs/render/contributions/render/line-render.js.map +1 -1
  181. package/cjs/render/contributions/render/path-render.js.map +1 -1
  182. package/cjs/render/contributions/render/polygon-render.js.map +1 -1
  183. package/cjs/render/contributions/render/rect-render.js +2 -2
  184. package/cjs/render/contributions/render/rect-render.js.map +1 -1
  185. package/cjs/render/contributions/render/richtext-render.js +1 -1
  186. package/cjs/render/contributions/render/richtext-render.js.map +1 -1
  187. package/cjs/render/contributions/render/symbol-render.js +15 -13
  188. package/cjs/render/contributions/render/symbol-render.js.map +1 -1
  189. package/cjs/render/contributions/render/utils.d.ts +1 -2
  190. package/cjs/render/contributions/render/utils.js +4 -20
  191. package/cjs/render/contributions/render/utils.js.map +1 -1
  192. package/cjs/resource-loader/loader.js +1 -1
  193. package/cjs/resource-loader/loader.js.map +1 -1
  194. package/dist/index.es.js +9073 -7513
  195. package/es/animate/Ticker/default-ticker.d.ts +2 -0
  196. package/es/animate/Ticker/default-ticker.js +7 -1
  197. package/es/animate/Ticker/default-ticker.js.map +1 -1
  198. package/es/animate/animate.js +4 -5
  199. package/es/animate/animate.js.map +1 -1
  200. package/es/animate/custom-animate.js +15 -27
  201. package/es/animate/custom-animate.js.map +1 -1
  202. package/es/animate/easing-func.d.ts +1 -0
  203. package/es/animate/easing-func.js +10 -0
  204. package/es/animate/easing-func.js.map +1 -0
  205. package/es/animate/easing.d.ts +4 -0
  206. package/es/animate/easing.js +24 -1
  207. package/es/animate/easing.js.map +1 -1
  208. package/es/animate/index.d.ts +1 -0
  209. package/es/animate/index.js +2 -0
  210. package/es/animate/index.js.map +1 -1
  211. package/es/canvas/util.js +1 -2
  212. package/es/common/3d-interceptor.js +2 -1
  213. package/es/common/bezier-utils.d.ts +3 -0
  214. package/es/common/bezier-utils.js +14 -0
  215. package/es/common/bezier-utils.js.map +1 -1
  216. package/es/common/custom-path2d.d.ts +4 -0
  217. package/es/common/custom-path2d.js +44 -12
  218. package/es/common/custom-path2d.js.map +1 -1
  219. package/es/common/inversify/container.js +6 -9
  220. package/es/common/inversify/container.js.map +1 -1
  221. package/es/common/render-area.d.ts +4 -0
  222. package/es/common/render-area.js +77 -18
  223. package/es/common/render-area.js.map +1 -1
  224. package/es/common/render-command-list.js +2 -1
  225. package/es/common/render-curve.d.ts +1 -1
  226. package/es/common/render-curve.js.map +1 -1
  227. package/es/common/segment/curve/arc.d.ts +4 -1
  228. package/es/common/segment/curve/arc.js +10 -1
  229. package/es/common/segment/curve/arc.js.map +1 -1
  230. package/es/common/segment/curve/base.d.ts +4 -1
  231. package/es/common/segment/curve/base.js.map +1 -1
  232. package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
  233. package/es/common/segment/curve/cubic-bezier.js +22 -1
  234. package/es/common/segment/curve/cubic-bezier.js.map +1 -1
  235. package/es/common/segment/curve/curve-context.js +6 -3
  236. package/es/common/segment/curve/curve-context.js.map +1 -1
  237. package/es/common/segment/curve/ellipse.d.ts +4 -1
  238. package/es/common/segment/curve/ellipse.js +9 -0
  239. package/es/common/segment/curve/ellipse.js.map +1 -1
  240. package/es/common/segment/curve/line.d.ts +4 -1
  241. package/es/common/segment/curve/line.js +18 -0
  242. package/es/common/segment/curve/line.js.map +1 -1
  243. package/es/common/segment/curve/move.d.ts +4 -1
  244. package/es/common/segment/curve/move.js +9 -0
  245. package/es/common/segment/curve/move.js.map +1 -1
  246. package/es/common/segment/curve/path.d.ts +2 -1
  247. package/es/common/segment/curve/path.js +5 -2
  248. package/es/common/segment/curve/path.js.map +1 -1
  249. package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
  250. package/es/common/segment/curve/quadratic-bezier.js +28 -5
  251. package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
  252. package/es/common/segment/step.js +1 -1
  253. package/es/common/segment/step.js.map +1 -1
  254. package/es/common/shape/rect.d.ts +1 -1
  255. package/es/common/shape/rect.js +30 -25
  256. package/es/common/shape/rect.js.map +1 -1
  257. package/es/common/store.js +1 -1
  258. package/es/core/contributions/env/base-contribution.d.ts +2 -0
  259. package/es/core/contributions/env/base-contribution.js +6 -0
  260. package/es/core/contributions/env/base-contribution.js.map +1 -1
  261. package/es/core/contributions/textMeasure/AtextMeasure.js +0 -10
  262. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  263. package/es/core/global.d.ts +2 -3
  264. package/es/core/global.js +7 -8
  265. package/es/core/global.js.map +1 -1
  266. package/es/graphic/builtin-symbol/rect.d.ts +2 -1
  267. package/es/graphic/builtin-symbol/rect.js +28 -0
  268. package/es/graphic/builtin-symbol/rect.js.map +1 -1
  269. package/es/graphic/builtin-symbol/utils.d.ts +2 -1
  270. package/es/graphic/builtin-symbol/utils.js +5 -0
  271. package/es/graphic/builtin-symbol/utils.js.map +1 -1
  272. package/es/graphic/config.js +20 -5
  273. package/es/graphic/config.js.map +1 -1
  274. package/es/graphic/graphic.d.ts +1 -1
  275. package/es/graphic/graphic.js +20 -6
  276. package/es/graphic/graphic.js.map +1 -1
  277. package/es/graphic/group.js +1 -1
  278. package/es/graphic/group.js.map +1 -1
  279. package/es/graphic/line.js +2 -2
  280. package/es/graphic/line.js.map +1 -1
  281. package/es/graphic/richtext/line.js +13 -1
  282. package/es/graphic/richtext/line.js.map +1 -1
  283. package/es/graphic/richtext/paragraph.d.ts +9 -1
  284. package/es/graphic/richtext/paragraph.js +49 -5
  285. package/es/graphic/richtext/paragraph.js.map +1 -1
  286. package/es/graphic/richtext/utils.d.ts +4 -0
  287. package/es/graphic/richtext/utils.js +19 -6
  288. package/es/graphic/richtext/utils.js.map +1 -1
  289. package/es/graphic/richtext/wrapper.d.ts +1 -0
  290. package/es/graphic/richtext/wrapper.js +1 -1
  291. package/es/graphic/richtext/wrapper.js.map +1 -1
  292. package/es/graphic/richtext.d.ts +8 -2
  293. package/es/graphic/richtext.js +43 -5
  294. package/es/graphic/richtext.js.map +1 -1
  295. package/es/index.d.ts +2 -0
  296. package/es/index.js +4 -0
  297. package/es/index.js.map +1 -1
  298. package/es/interface/animate.d.ts +5 -39
  299. package/es/interface/animate.js.map +1 -1
  300. package/es/interface/color.js.map +1 -1
  301. package/es/interface/context.d.ts +1 -0
  302. package/es/interface/context.js.map +1 -1
  303. package/es/interface/global.d.ts +4 -1
  304. package/es/interface/global.js.map +1 -1
  305. package/es/interface/graphic/group.d.ts +1 -0
  306. package/es/interface/graphic/group.js.map +1 -1
  307. package/es/interface/graphic/image.d.ts +1 -0
  308. package/es/interface/graphic/image.js.map +1 -1
  309. package/es/interface/graphic/path.d.ts +1 -0
  310. package/es/interface/graphic/path.js.map +1 -1
  311. package/es/interface/graphic/rect.d.ts +1 -0
  312. package/es/interface/graphic/rect.js.map +1 -1
  313. package/es/interface/graphic/richText.d.ts +13 -0
  314. package/es/interface/graphic/richText.js.map +1 -1
  315. package/es/interface/graphic/symbol.d.ts +2 -0
  316. package/es/interface/graphic/symbol.js.map +1 -1
  317. package/es/interface/graphic.d.ts +12 -3
  318. package/es/interface/graphic.js.map +1 -1
  319. package/es/interface/path.d.ts +5 -0
  320. package/es/interface/path.js.map +1 -1
  321. package/es/interface/picker.d.ts +13 -0
  322. package/es/interface/picker.js.map +1 -1
  323. package/es/picker/constants.d.ts +2 -0
  324. package/es/picker/constants.js +4 -0
  325. package/es/picker/constants.js.map +1 -1
  326. package/es/picker/pick-interceptor.d.ts +7 -2
  327. package/es/picker/pick-interceptor.js +19 -1
  328. package/es/picker/pick-interceptor.js.map +1 -1
  329. package/es/picker/pick-modules.js +5 -3
  330. package/es/picker/pick-modules.js.map +1 -1
  331. package/es/picker/picker-service.d.ts +4 -2
  332. package/es/picker/picker-service.js +13 -13
  333. package/es/picker/picker-service.js.map +1 -1
  334. package/es/plugins/builtin-plugin/edit-module.d.ts +17 -6
  335. package/es/plugins/builtin-plugin/edit-module.js +123 -40
  336. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  337. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  338. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  339. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  340. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +91 -32
  341. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +516 -189
  342. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  343. package/es/render/contributions/render/arc3d-render.js.map +1 -1
  344. package/es/render/contributions/render/area-render.d.ts +1 -1
  345. package/es/render/contributions/render/area-render.js +36 -16
  346. package/es/render/contributions/render/area-render.js.map +1 -1
  347. package/es/render/contributions/render/base-render.d.ts +1 -0
  348. package/es/render/contributions/render/base-render.js +21 -2
  349. package/es/render/contributions/render/base-render.js.map +1 -1
  350. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +7 -1
  351. package/es/render/contributions/render/contributions/base-contribution-render.js +16 -8
  352. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  353. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  354. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  355. package/es/render/contributions/render/contributions/group-contribution-render.js +8 -3
  356. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  357. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  358. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  359. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  360. package/es/render/contributions/render/contributions/rect-contribution-render.js +4 -4
  361. package/es/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  362. package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  363. package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
  364. package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  365. package/es/render/contributions/render/contributions/text-contribution-render.js +5 -3
  366. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  367. package/es/render/contributions/render/draw-contribution.js +4 -5
  368. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  369. package/es/render/contributions/render/group-render.js +2 -2
  370. package/es/render/contributions/render/group-render.js.map +1 -1
  371. package/es/render/contributions/render/image-render.js +3 -2
  372. package/es/render/contributions/render/image-render.js.map +1 -1
  373. package/es/render/contributions/render/line-render.js +31 -9
  374. package/es/render/contributions/render/line-render.js.map +1 -1
  375. package/es/render/contributions/render/path-render.js.map +1 -1
  376. package/es/render/contributions/render/polygon-render.js.map +1 -1
  377. package/es/render/contributions/render/rect-render.js +2 -2
  378. package/es/render/contributions/render/rect-render.js.map +1 -1
  379. package/es/render/contributions/render/richtext-render.js +1 -1
  380. package/es/render/contributions/render/richtext-render.js.map +1 -1
  381. package/es/render/contributions/render/symbol-render.js +16 -14
  382. package/es/render/contributions/render/symbol-render.js.map +1 -1
  383. package/es/render/contributions/render/utils.d.ts +1 -2
  384. package/es/render/contributions/render/utils.js +0 -18
  385. package/es/render/contributions/render/utils.js.map +1 -1
  386. package/es/resource-loader/loader.js +1 -1
  387. package/es/resource-loader/loader.js.map +1 -1
  388. package/package.json +2 -2
  389. package/cjs/common/inversify/annotation/optional.d.ts +0 -2
  390. package/cjs/common/inversify/annotation/optional.js +0 -14
  391. package/cjs/common/inversify/annotation/optional.js.map +0 -1
  392. package/es/common/inversify/annotation/optional.d.ts +0 -2
  393. package/es/common/inversify/annotation/optional.js +0 -12
  394. package/es/common/inversify/annotation/optional.js.map +0 -1
@@ -1,65 +1,123 @@
1
- export function findCursorIndexIgnoreLinebreak(textConfig, cursorIndex) {
2
- let index = 0;
3
- for (index = 0; index < textConfig.length; index++) {
4
- const c = textConfig[index];
5
- if (c.text && "\n" === c.text || cursorIndex--, cursorIndex < 0) break;
1
+ var __rest = this && this.__rest || function(s, e) {
2
+ var t = {};
3
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
4
+ if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
5
+ var i = 0;
6
+ for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
6
7
  }
7
- return index;
8
+ return t;
9
+ };
10
+
11
+ import { application } from "../../application";
12
+
13
+ export function getDefaultCharacterConfig(attribute) {
14
+ const {fill: fill = "black", stroke: stroke = !1, fontWeight: fontWeight = "normal", fontFamily: fontFamily = "Arial"} = attribute;
15
+ let {fontSize: fontSize = 12} = attribute;
16
+ return isFinite(fontSize) || (fontSize = 12), {
17
+ fill: fill,
18
+ stroke: stroke,
19
+ fontSize: fontSize,
20
+ fontWeight: fontWeight,
21
+ fontFamily: fontFamily
22
+ };
23
+ }
24
+
25
+ export function findConfigIndexByCursorIdx(textConfig, cursorIndex) {
26
+ if (cursorIndex < 0) return 0;
27
+ const intCursorIndex = Math.round(cursorIndex);
28
+ let tempCursorIndex = intCursorIndex, lineBreak = !1, configIdx = 0;
29
+ for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {
30
+ "\n" === textConfig[configIdx].text ? (tempCursorIndex -= Number(lineBreak), lineBreak = !0) : (tempCursorIndex--,
31
+ lineBreak = !1);
32
+ }
33
+ return tempCursorIndex >= 0 ? textConfig.length : (configIdx -= 1, cursorIndex > intCursorIndex && !lineBreak && (configIdx += 1),
34
+ configIdx);
35
+ }
36
+
37
+ export function findCursorIdxByConfigIndex(textConfig, configIndex) {
38
+ var _a, _b, _c;
39
+ let cursorIndex = 0;
40
+ if (configIndex < 0) return -.1;
41
+ let lastLineBreak = !1;
42
+ for (let i = 0; i <= configIndex && i < textConfig.length; i++) {
43
+ "\n" === textConfig[i].text ? (cursorIndex += Number(lastLineBreak), lastLineBreak = !0) : (cursorIndex++,
44
+ lastLineBreak = !1);
45
+ }
46
+ if (cursorIndex = Math.max(cursorIndex - 1, 0), configIndex > textConfig.length - 1) return "\n" === (null === (_a = textConfig[textConfig.length - 1]) || void 0 === _a ? void 0 : _a.text) ? cursorIndex + .9 : cursorIndex + .1;
47
+ const lineBreak = "\n" === (null === (_b = textConfig[configIndex]) || void 0 === _b ? void 0 : _b.text);
48
+ if (configIndex >= textConfig.length - 1 && lineBreak) return cursorIndex + 1 - .1;
49
+ return cursorIndex -= .1, lineBreak && "\n" !== (null === (_c = textConfig[configIndex - 1]) || void 0 === _c ? void 0 : _c.text) && (cursorIndex += .2),
50
+ cursorIndex;
8
51
  }
9
52
 
10
53
  export class EditModule {
11
54
  constructor(container) {
12
- this.handleKeyDown = e => {
55
+ this.handleFocusIn = () => {}, this.handleFocusOut = () => {}, this.handleKeyDown = e => {
13
56
  "Delete" !== e.key && "Backspace" !== e.key || this.handleInput({
14
57
  data: null,
15
58
  type: "Backspace"
16
59
  });
17
60
  }, this.handleCompositionStart = () => {
18
- const {textConfig: textConfig = []} = this.currRt.attribute, cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex), lastConfig = textConfig[cursorIndex];
19
- textConfig.splice(cursorIndex + 1, 0, Object.assign(Object.assign({}, lastConfig), {
20
- text: ""
21
- })), this.isComposing = !0;
61
+ this.isComposing = !0;
62
+ const {textConfig: textConfig = []} = this.currRt.attribute;
63
+ if (this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex),
64
+ this.cursorIndex < 0) {
65
+ const config = textConfig[0];
66
+ textConfig.unshift(Object.assign(Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), config), {
67
+ text: ""
68
+ }));
69
+ } else {
70
+ const configIdx = this.composingConfigIdx, lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];
71
+ textConfig.splice(configIdx, 0, Object.assign(Object.assign({}, lastConfig), {
72
+ text: ""
73
+ }));
74
+ }
22
75
  }, this.handleCompositionEnd = () => {
23
76
  this.isComposing = !1;
24
- const {textConfig: textConfig = []} = this.currRt.attribute, curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1), lastConfig = textConfig[curIdx];
25
- textConfig.splice(curIdx, 1);
26
- const text = lastConfig.text, textList = Array.from(text.toString());
27
- for (let i = 0; i < textList.length; i++) textConfig.splice(i + curIdx, 0, Object.assign(Object.assign({}, lastConfig), {
28
- text: textList[i]
29
- }));
30
- this.currRt.setAttributes({
31
- textConfig: textConfig
32
- }), this.onChangeCbList.forEach((cb => {
33
- cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, "right");
77
+ const text = this.parseCompositionStr(this.composingConfigIdx);
78
+ this.composingConfigIdx = -1, this.onChangeCbList.forEach((cb => {
79
+ cb(text, this.isComposing, this.cursorIndex, this.currRt);
34
80
  }));
35
81
  }, this.handleInput = ev => {
36
82
  if (!this.currRt) return;
83
+ if ("historyUndo" === ev.inputType) return;
84
+ const _a = this.currRt.attribute, {textConfig: textConfig = []} = _a, rest = __rest(_a, [ "textConfig" ]);
85
+ if ("Backspace" === ev.type && !textConfig.length) return;
37
86
  let str = ev.data;
38
- "Backspace" === ev.type || str || (str = "\n");
39
- const {textConfig: textConfig = []} = this.currRt.attribute;
40
- let startIdx = this.selectionStartCursorIdx, endIdx = this.cursorIndex;
41
- startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), this.selectionStartCursorIdx = startIdx,
42
- this.cursorIndex = startIdx, startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);
43
- const delta = this.selectionStartCursorIdx - startIdx;
44
- endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);
45
- const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];
46
- let currConfig = lastConfig;
47
- "Backspace" !== ev.type || this.isComposing ? (startIdx !== endIdx && textConfig.splice(startIdx + 1, endIdx - startIdx),
48
- this.isComposing || (currConfig = Object.assign(Object.assign({}, lastConfig), {
87
+ this.isComposing || "Backspace" === ev.type || str || (str = "\n"), this.selectionStartCursorIdx > this.cursorIndex && ([this.cursorIndex, this.selectionStartCursorIdx] = [ this.selectionStartCursorIdx, this.cursorIndex ]);
88
+ const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx), endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);
89
+ let lastConfig = textConfig[this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0)];
90
+ lastConfig || (lastConfig = getDefaultCharacterConfig(rest));
91
+ let nextConfig = lastConfig;
92
+ startIdx !== endIdx && (textConfig.splice(startIdx, endIdx - startIdx), this.isComposing && (this.composingConfigIdx = startIdx));
93
+ let nextConfigIdx = startIdx;
94
+ if ("Backspace" !== ev.type || this.isComposing) this.isComposing || (nextConfig = Object.assign(Object.assign({
95
+ fill: "black"
96
+ }, lastConfig), {
49
97
  text: ""
50
- }), startIdx += 1, textConfig.splice(startIdx, 0, currConfig)), currConfig.text = str) : startIdx !== endIdx ? textConfig.splice(startIdx + 1, endIdx - startIdx) : (textConfig.splice(startIdx, 1),
51
- startIdx -= 1), this.currRt.setAttributes({
98
+ }), textConfig.splice(startIdx, 0, nextConfig), nextConfigIdx++), nextConfig.text = str,
99
+ nextConfig.isComposing = this.isComposing; else if (startIdx === endIdx) {
100
+ if (startIdx <= 0) return;
101
+ textConfig.splice(startIdx - 1, 1), nextConfigIdx = Math.max(startIdx - 1, 0);
102
+ }
103
+ this.currRt.setAttributes({
52
104
  textConfig: textConfig
53
- }), this.isComposing ? this.onInputCbList.forEach((cb => {
54
- cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
105
+ });
106
+ let cursorIndex = this.cursorIndex;
107
+ str && str.length > 1 && !this.isComposing ? (this.parseCompositionStr(nextConfigIdx - 1),
108
+ cursorIndex = this.cursorIndex) : (cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx),
109
+ this.isComposing ? this.cursorIndex = this.selectionStartCursorIdx : this.cursorIndex = cursorIndex),
110
+ this.isComposing ? this.onInputCbList.forEach((cb => {
111
+ cb(str, this.isComposing, cursorIndex, this.currRt);
55
112
  })) : this.onChangeCbList.forEach((cb => {
56
- cb(str, this.isComposing, startIdx + delta, this.currRt, "\n" === str ? "left" : "right");
113
+ cb(str, this.isComposing, cursorIndex, this.currRt);
57
114
  }));
58
115
  }, this.container = null != container ? container : document.body;
59
116
  const textAreaDom = document.createElement("textarea");
60
117
  textAreaDom.autocomplete = "off", textAreaDom.innerText = "", this.applyStyle(textAreaDom),
61
118
  this.container.append(textAreaDom), this.textAreaDom = textAreaDom, this.isComposing = !1,
62
- this.onInputCbList = [], this.onChangeCbList = [];
119
+ this.composingConfigIdx = -1, this.onInputCbList = [], this.onChangeCbList = [],
120
+ this.onFocusInList = [], this.onFocusOutList = [];
63
121
  }
64
122
  onInput(cb) {
65
123
  this.onInputCbList.push(cb);
@@ -67,10 +125,34 @@ export class EditModule {
67
125
  onChange(cb) {
68
126
  this.onChangeCbList.push(cb);
69
127
  }
128
+ onFocusIn(cb) {
129
+ this.onFocusInList.push(cb);
130
+ }
131
+ onFocusOut(cb) {
132
+ this.onFocusOutList.push(cb);
133
+ }
70
134
  applyStyle(textAreaDom) {
71
135
  textAreaDom.setAttribute("style", "width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;"),
72
136
  textAreaDom.addEventListener("input", this.handleInput), textAreaDom.addEventListener("compositionstart", this.handleCompositionStart),
73
- textAreaDom.addEventListener("compositionend", this.handleCompositionEnd), window.addEventListener("keydown", this.handleKeyDown);
137
+ textAreaDom.addEventListener("compositionend", this.handleCompositionEnd), textAreaDom.addEventListener("focusin", this.handleFocusIn),
138
+ textAreaDom.addEventListener("focusout", this.handleFocusOut), application.global.addEventListener("keydown", this.handleKeyDown);
139
+ }
140
+ parseCompositionStr(configIdx) {
141
+ const {textConfig: textConfig = []} = this.currRt.attribute, lastConfig = textConfig[configIdx];
142
+ textConfig.splice(configIdx, 1);
143
+ const text = lastConfig.text, textList = text ? Array.from(text.toString()) : [];
144
+ for (let i = 0; i < textList.length; i++) textConfig.splice(i + configIdx, 0, Object.assign(Object.assign(Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), {
145
+ fill: "black"
146
+ }), lastConfig), {
147
+ isComposing: !1,
148
+ text: textList[i]
149
+ }));
150
+ this.currRt.setAttributes({
151
+ textConfig: textConfig
152
+ });
153
+ const nextConfigIdx = configIdx + textList.length;
154
+ return this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx),
155
+ text;
74
156
  }
75
157
  moveTo(x, y, rt, cursorIndex, selectionStartCursorIdx) {
76
158
  this.textAreaDom.style.left = `${x}px`, this.textAreaDom.style.top = `${y}px`, setTimeout((() => {
@@ -80,7 +162,8 @@ export class EditModule {
80
162
  release() {
81
163
  this.textAreaDom.removeEventListener("input", this.handleInput), this.textAreaDom.removeEventListener("compositionstart", this.handleCompositionStart),
82
164
  this.textAreaDom.removeEventListener("compositionend", this.handleCompositionEnd),
83
- window.removeEventListener("keydown", this.handleKeyDown);
165
+ this.textAreaDom.addEventListener("focusin", this.handleFocusOut), this.textAreaDom.addEventListener("focusout", this.handleFocusOut),
166
+ application.global.removeEventListener("keydown", this.handleKeyDown);
84
167
  }
85
168
  }
86
169
  //# sourceMappingURL=edit-module.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,8BAA8B,CAAC,UAAgC,EAAE,WAAmB;IAClG,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAClD,MAAM,CAAC,GAAG,UAAU,CAAC,KAAK,CAAgC,C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O;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC5D,CAAC;CACF","file":"edit-module.js","sourcesContent":["import type { IRichText, IRichTextCharacter, IRichTextParagraphCharacter } from '../../interface';\nimport { IRichTextIcon, IRichTextParagraph } from '../../interface';\n\nexport function findCursorIndexIgnoreLinebreak(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n let index = 0;\n for (index = 0; index < textConfig.length; index++) {\n const c = textConfig[index] as IRichTextParagraphCharacter;\n if (!(c.text && c.text === '\\n')) {\n cursorIndex--;\n }\n if (cursorIndex < 0) {\n break;\n }\n }\n return index;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<\n (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void\n >;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, pos: 'left' | 'right') => void) {\n this.onChangeCbList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n window.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n const { textConfig = [] } = this.currRt.attribute;\n const cursorIndex = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex);\n const lastConfig = textConfig[cursorIndex];\n textConfig.splice(cursorIndex + 1, 0, { ...lastConfig, text: '' });\n this.isComposing = true;\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n // 拆分上一次的内容\n const { textConfig = [] } = this.currRt.attribute;\n const curIdx = findCursorIndexIgnoreLinebreak(textConfig, this.cursorIndex + 1);\n\n const lastConfig = textConfig[curIdx];\n textConfig.splice(curIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = Array.from(text.toString());\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + curIdx, 0, { ...lastConfig, text: textList[i] });\n }\n this.currRt.setAttributes({ textConfig });\n this.onChangeCbList.forEach(cb => {\n cb(text, this.isComposing, this.cursorIndex + textList.length, this.currRt, 'right');\n });\n };\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n let str = (ev as any).data;\n if (ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n // 如果是回车,那就不往后+1\n const { textConfig = [] } = this.currRt.attribute;\n\n // 如果有选中多个文字,那就先删除\n let startIdx = this.selectionStartCursorIdx;\n let endIdx = this.cursorIndex;\n if (startIdx > endIdx) {\n [startIdx, endIdx] = [endIdx, startIdx];\n }\n // 无论是否composition都立刻恢复到没有选中的idx状态\n this.selectionStartCursorIdx = startIdx;\n this.cursorIndex = startIdx;\n\n // 转换成基于textConfig的\n startIdx = findCursorIndexIgnoreLinebreak(textConfig, startIdx);\n const delta = this.selectionStartCursorIdx - startIdx;\n endIdx = findCursorIndexIgnoreLinebreak(textConfig, endIdx);\n\n const lastConfig = textConfig[startIdx + (this.isComposing ? 1 : 0)];\n let currConfig = lastConfig;\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n } else {\n textConfig.splice(startIdx, 1);\n startIdx -= 1;\n }\n } else {\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx + 1, endIdx - startIdx);\n }\n\n if (!this.isComposing) {\n currConfig = { ...lastConfig, text: '' };\n startIdx += 1;\n textConfig.splice(startIdx, 0, currConfig);\n }\n (currConfig as any).text = str;\n }\n\n this.currRt.setAttributes({ textConfig });\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, startIdx + delta, this.currRt, str === '\\n' ? 'left' : 'right');\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n window.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/plugins/builtin-plugin/edit-module.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAmBhD,MAAM,UAAU,yBAAyB,CAAC,SAAoC;IAC5E,MAAM,EAAE,IAAI,GAAG,OAAO,EAAE,MAAM,GAAG,KAAK,EAAE,UAAU,GAAG,QAAQ,EAAE,UAAU,GAAG,OAAO,EAAE,GAAG,SAAS,CAAC;IAClG,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,SAAS,CAAC;IAClC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACvB,QAAQ,GAAG,EAAE,CAAC;KACf;IACD,OAAO;QACL,IAAI;QACJ,MAAM;QACN,QAAQ;QACR,UAAU;QACV,UAAU;KACJ,CAAC;AACX,CAAC;AAQD,MAAM,UAAU,0BAA0B,CAAC,UAAgC,EAAE,WAAmB;IAC9F,IAAI,WAAW,GAAG,CAAC,EAAE;QACnB,OAAO,CAAC,CAAC;KACV;IAGD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,eAAe,GAAG,cAAc,CAAC;IAErC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,KAAK,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,MAAM,IAAI,eAAe,IAAI,CAAC,EAAE,SAAS,EAAE,EAAE;QACtF,MAAM,CAAC,GAAG,UAAU,CAAC,SAAS,CAAgC,CAAC;QAC/D,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE;YACnB,eAA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;IACzD,CAAC;IAED,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,CAAC;QACtF,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC,gBAAgB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAClF,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QACnE,WAAW,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IACxE,CAAC;CACF","file":"edit-module.js","sourcesContent":["import { application } from '../../application';\nimport type {\n IRichText,\n IRichTextCharacter,\n IRichTextGraphicAttribute,\n IRichTextParagraphCharacter\n} from '../../interface';\n\n// function getMaxConfigIndexIgnoreLinebreak(textConfig: IRichTextCharacter[]) {\n// let idx = 0;\n// for (let i = 0; i < textConfig.length; i++) {\n// const c = textConfig[i] as IRichTextParagraphCharacter;\n// if (c.text !== '\\n') {\n// idx++;\n// }\n// }\n// return Math.max(idx - 1, 0);\n// }\n\nexport function getDefaultCharacterConfig(attribute: IRichTextGraphicAttribute) {\n const { fill = 'black', stroke = false, fontWeight = 'normal', fontFamily = 'Arial' } = attribute;\n let { fontSize = 12 } = attribute;\n if (!isFinite(fontSize)) {\n fontSize = 12;\n }\n return {\n fill,\n stroke,\n fontSize,\n fontWeight,\n fontFamily\n } as any;\n}\n\n/**\n * 找到cursorIndex所在的textConfig的位置,给出的index就是要插入的准确位置\n * @param textConfig\n * @param cursorIndex\n * @returns\n */\nexport function findConfigIndexByCursorIdx(textConfig: IRichTextCharacter[], cursorIndex: number): number {\n if (cursorIndex < 0) {\n return 0;\n }\n\n // 排序找到对应的元素\n const intCursorIndex = Math.round(cursorIndex);\n let tempCursorIndex = intCursorIndex;\n // 跳过连续换行符中的第一个换行符\n let lineBreak = false;\n let configIdx = 0;\n for (configIdx = 0; configIdx < textConfig.length && tempCursorIndex >= 0; configIdx++) {\n const c = textConfig[configIdx] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n tempCursorIndex -= Number(lineBreak);\n lineBreak = true;\n } else {\n tempCursorIndex--;\n lineBreak = false;\n }\n }\n // 说明过限了\n if (tempCursorIndex >= 0) {\n return textConfig.length;\n }\n configIdx -= 1;\n\n // 如果有换行,一定在换行符左边写\n if (cursorIndex > intCursorIndex && !lineBreak) {\n configIdx += 1;\n }\n return configIdx;\n}\n\n/**\n * 根据configIndex找到cursorIndex的位置,忽略单个换行符,连续换行符的时候只忽略第一个\n * @param textConfig\n * @param configIndex\n * @returns\n */\nexport function findCursorIdxByConfigIndex(textConfig: IRichTextCharacter[], configIndex: number): number {\n let cursorIndex = 0;\n if (configIndex < 0) {\n return -0.1;\n }\n // 仅有一个\\n,那不算\n // 如果有连续的\\n,那就少算一个\n let lastLineBreak = false;\n\n for (let i = 0; i <= configIndex && i < textConfig.length; i++) {\n const c = textConfig[i] as IRichTextParagraphCharacter;\n if (c.text === '\\n') {\n cursorIndex += Number(lastLineBreak);\n lastLineBreak = true;\n } else {\n cursorIndex++;\n lastLineBreak = false;\n }\n }\n cursorIndex = Math.max(cursorIndex - 1, 0);\n\n // 超出区间了直接设置到尾部,configIndex超过区间,cursorIndex不会超过\n if (configIndex > textConfig.length - 1) {\n // 如果最后一行是一个换行符,那么就得是xx.9否则就是xx.1\n if ((textConfig[textConfig.length - 1] as any)?.text === '\\n') {\n return cursorIndex + 0.9;\n }\n return cursorIndex + 0.1;\n }\n\n // 如果是这个configIdx对应到的是单个换行的话,那么算到下一个字符上\n const lineBreak = (textConfig[configIndex] as any)?.text === '\\n';\n if (configIndex >= textConfig.length - 1 && lineBreak) {\n return cursorIndex + 1 - 0.1;\n }\n const singleLineBreak = lineBreak && (textConfig[configIndex - 1] as any)?.text !== '\\n';\n\n // 光标往左放\n cursorIndex -= 0.1;\n\n // 如果是单行,那么这一个换行符没有算字符,光标要往右放\n if (singleLineBreak) {\n cursorIndex += 0.2;\n }\n return cursorIndex;\n}\n\nexport class EditModule {\n container: HTMLElement;\n textAreaDom: HTMLTextAreaElement;\n currRt: IRichText;\n isComposing: boolean;\n composingConfigIdx: number;\n cursorIndex: number;\n selectionStartCursorIdx: number;\n // 输入的回调(composing的时候每次也会触发)\n onInputCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n // change的回调(composing确认才会触发)\n onChangeCbList: Array<(text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void>;\n onFocusInList: Array<() => void>;\n onFocusOutList: Array<() => void>;\n focusOutTimer: number;\n\n constructor(container?: HTMLElement) {\n this.container = container ?? document.body;\n\n const textAreaDom = document.createElement('textarea');\n textAreaDom.autocomplete = 'off';\n textAreaDom.innerText = '';\n this.applyStyle(textAreaDom);\n this.container.append(textAreaDom);\n this.textAreaDom = textAreaDom;\n this.isComposing = false;\n this.composingConfigIdx = -1;\n this.onInputCbList = [];\n this.onChangeCbList = [];\n this.onFocusInList = [];\n this.onFocusOutList = [];\n }\n\n onInput(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onInputCbList.push(cb);\n }\n\n onChange(cb: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void) {\n this.onChangeCbList.push(cb);\n }\n\n onFocusIn(cb: () => void) {\n this.onFocusInList.push(cb);\n }\n\n onFocusOut(cb: () => void) {\n this.onFocusOutList.push(cb);\n }\n\n applyStyle(textAreaDom: HTMLTextAreaElement) {\n textAreaDom.setAttribute(\n 'style',\n `width: 100px; height: 30px; left: 0; top: 0; position: absolute; z-index: -1; outline: none; resize: none; border: none; overflow: hidden; color: transparent; user-select: none; caret-color: transparent;background-color: transparent;`\n );\n\n textAreaDom.addEventListener('input', this.handleInput);\n textAreaDom.addEventListener('compositionstart', this.handleCompositionStart);\n textAreaDom.addEventListener('compositionend', this.handleCompositionEnd);\n // 监听焦点\n textAreaDom.addEventListener('focusin', this.handleFocusIn);\n textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.addEventListener('keydown', this.handleKeyDown);\n }\n\n handleFocusIn = () => {\n // this.focusOutTimer && clearTimeout(this.focusOutTimer);\n // this.focusOutTimer = 0;\n // this.onFocusInList && this.onFocusInList.forEach(cb => cb());\n };\n handleFocusOut = () => {\n // 暂时注释,会导致非期待情况下的误关闭\n // // 延时触发,避免误关闭\n // this.focusOutTimer = setTimeout(() => {\n // this.onFocusOutList && this.onFocusOutList.forEach(cb => cb());\n // }, 100);\n };\n\n handleKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n this.handleInput({ data: null, type: 'Backspace' });\n }\n };\n\n handleCompositionStart = () => {\n this.isComposing = true;\n const { textConfig = [] } = this.currRt.attribute;\n this.composingConfigIdx = this.cursorIndex < 0 ? 0 : findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n if (this.cursorIndex < 0) {\n const config = textConfig[0];\n textConfig.unshift({ ...getDefaultCharacterConfig(this.currRt.attribute), ...config, text: '' });\n } else {\n const configIdx = this.composingConfigIdx;\n const lastConfig = textConfig[configIdx] || textConfig[configIdx - 1];\n textConfig.splice(configIdx, 0, { ...lastConfig, text: '' });\n }\n };\n handleCompositionEnd = () => {\n this.isComposing = false;\n\n const text = this.parseCompositionStr(this.composingConfigIdx);\n // 拆分上一次的内容\n // const { textConfig = [] } = this.currRt.attribute;\n // const configIdx = this.composingConfigIdx;\n\n // const lastConfig = textConfig[configIdx];\n // textConfig.splice(configIdx, 1);\n // const text = (lastConfig as any).text;\n // const textList: string[] = text ? Array.from(text.toString()) : [];\n // for (let i = 0; i < textList.length; i++) {\n // textConfig.splice(i + configIdx, 0, { ...lastConfig, isComposing: false, text: textList[i] } as any);\n // }\n // this.currRt.setAttributes({ textConfig });\n // const nextConfigIdx = configIdx + textList.length;\n // this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n this.composingConfigIdx = -1;\n\n this.onChangeCbList.forEach(cb => {\n cb(\n text,\n this.isComposing,\n // TODO 当换行后刚开始输入会有问题,后续看这里具体Cursor变换逻辑\n this.cursorIndex,\n this.currRt\n );\n });\n };\n\n /**\n * 复合输入以及粘贴,都会复制出一大段内容,这时候需要重新处理textConfig和cursorIndex\n * 1. 拆分text到textConfig\n * 2. 计算新的cursorIndex\n * @param configIdx\n */\n parseCompositionStr(configIdx: number) {\n const { textConfig = [] } = this.currRt.attribute;\n\n const lastConfig = textConfig[configIdx];\n textConfig.splice(configIdx, 1);\n const text = (lastConfig as any).text;\n const textList: string[] = text ? Array.from(text.toString()) : [];\n for (let i = 0; i < textList.length; i++) {\n textConfig.splice(i + configIdx, 0, {\n ...getDefaultCharacterConfig(this.currRt.attribute),\n fill: 'black',\n ...lastConfig,\n isComposing: false,\n text: textList[i]\n } as any);\n }\n this.currRt.setAttributes({ textConfig });\n const nextConfigIdx = configIdx + textList.length;\n this.cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n return text;\n }\n\n handleInput = (ev: any) => {\n if (!this.currRt) {\n return;\n }\n if (ev.inputType === 'historyUndo') {\n return;\n }\n const { textConfig = [], ...rest } = this.currRt.attribute;\n // 删完了,直接返回\n if (ev.type === 'Backspace' && !textConfig.length) {\n return;\n }\n\n let str = (ev as any).data;\n if (!this.isComposing && ev.type !== 'Backspace' && !str) {\n str = '\\n';\n }\n\n // 处理正反选\n if (this.selectionStartCursorIdx > this.cursorIndex) {\n [this.cursorIndex, this.selectionStartCursorIdx] = [this.selectionStartCursorIdx, this.cursorIndex];\n }\n\n const startIdx = findConfigIndexByCursorIdx(textConfig, this.selectionStartCursorIdx);\n const endIdx = findConfigIndexByCursorIdx(textConfig, this.cursorIndex);\n\n // composing的话会插入一个字符,所以往右加一个\n const lastConfigIdx = this.isComposing ? this.composingConfigIdx : Math.max(startIdx - 1, 0);\n // 算一个默认属性\n let lastConfig: any = textConfig[lastConfigIdx];\n if (!lastConfig) {\n lastConfig = getDefaultCharacterConfig(rest);\n }\n let nextConfig = lastConfig;\n\n if (startIdx !== endIdx) {\n textConfig.splice(startIdx, endIdx - startIdx);\n if (this.isComposing) {\n this.composingConfigIdx = startIdx;\n }\n }\n\n let nextConfigIdx = startIdx;\n\n // 删除键\n if (ev.type === 'Backspace' && !this.isComposing) {\n if (startIdx === endIdx) {\n if (startIdx <= 0) {\n return;\n }\n // 删除\n textConfig.splice(startIdx - 1, 1);\n nextConfigIdx = Math.max(startIdx - 1, 0);\n } else {\n // 不插入内容\n }\n } else {\n // 插入\n if (!this.isComposing) {\n nextConfig = { fill: 'black', ...lastConfig, text: '' };\n textConfig.splice(startIdx, 0, nextConfig);\n nextConfigIdx++;\n }\n // 插入\n nextConfig.text = str;\n // 标记isComposing,用来判定是否应该拆分成单个字符\n nextConfig.isComposing = this.isComposing;\n }\n\n this.currRt.setAttributes({ textConfig });\n // 重新计算cursorIdx\n // nextConfigIdx = Math.min(nextConfigIdx, textConfig.length - 1);\n\n let cursorIndex = this.cursorIndex;\n if (str && str.length > 1 && !this.isComposing) {\n // 如果字符长度大于1且不是composing,那说明是粘贴\n // 拆分\n this.parseCompositionStr(nextConfigIdx - 1);\n cursorIndex = this.cursorIndex;\n } else {\n // composing的时候不偏移,只有完整输入后才偏移\n cursorIndex = findCursorIdxByConfigIndex(textConfig, nextConfigIdx);\n if (!this.isComposing) {\n this.cursorIndex = cursorIndex;\n } else {\n this.cursorIndex = this.selectionStartCursorIdx;\n }\n }\n\n if (!this.isComposing) {\n this.onChangeCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n } else {\n this.onInputCbList.forEach(cb => {\n cb(str, this.isComposing, cursorIndex, this.currRt);\n });\n }\n };\n\n moveTo(x: number, y: number, rt: IRichText, cursorIndex: number, selectionStartCursorIdx: number) {\n this.textAreaDom.style.left = `${x}px`;\n this.textAreaDom.style.top = `${y}px`;\n setTimeout(() => {\n this.textAreaDom.focus();\n this.textAreaDom.setSelectionRange(0, 0);\n });\n this.currRt = rt;\n\n this.cursorIndex = cursorIndex;\n this.selectionStartCursorIdx = selectionStartCursorIdx;\n }\n\n release() {\n this.textAreaDom.removeEventListener('input', this.handleInput);\n this.textAreaDom.removeEventListener('compositionstart', this.handleCompositionStart);\n this.textAreaDom.removeEventListener('compositionend', this.handleCompositionEnd);\n this.textAreaDom.addEventListener('focusin', this.handleFocusOut);\n this.textAreaDom.addEventListener('focusout', this.handleFocusOut);\n application.global.removeEventListener('keydown', this.handleKeyDown);\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+
2
+
3
+ //# sourceMappingURL=richtext-edit-plugin-old.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugins/builtin-plugin/richtext-edit-plugin-old.ts"],"names":[],"mappings":"","file":"richtext-edit-plugin-old.js","sourcesContent":["// import type { IPointLike } from '@visactor/vutils';\n// import { isObject, isString, max, merge } from '@visactor/vutils';\n// import { Generator } from '../../common/generator';\n// import { createGroup, createLine, createRect } from '../../graphic';\n// import type {\n// IGroup,\n// ILine,\n// IPlugin,\n// IPluginService,\n// IRect,\n// IRichText,\n// IRichTextCharacter,\n// IRichTextFrame,\n// IRichTextIcon,\n// IRichTextLine,\n// IRichTextParagraph,\n// IRichTextParagraphCharacter,\n// ITicker,\n// ITimeline\n// } from '../../interface';\n// import { EditModule, findCursorIndexIgnoreLinebreak } from './edit-module';\n// import { Animate, DefaultTicker, DefaultTimeline } from '../../animate';\n\n// type UpdateType = 'input' | 'change' | 'onfocus' | 'defocus' | 'selection' | 'dispatch';\n\n// class Selection {\n// cacheSelectionStartCursorIdx: number;\n// cacheCurCursorIdx: number;\n// selectionStartCursorIdx: number;\n// curCursorIdx: number;\n// rt: IRichText;\n\n// constructor(\n// cacheSelectionStartCursorIdx: number,\n// cacheCurCursorIdx: number,\n// selectionStartCursorIdx: number,\n// curCursorIdx: number,\n// rt: IRichText\n// ) {\n// this.curCursorIdx = curCursorIdx;\n// this.selectionStartCursorIdx = selectionStartCursorIdx;\n// this.cacheCurCursorIdx = cacheCurCursorIdx;\n// this.cacheSelectionStartCursorIdx = cacheSelectionStartCursorIdx;\n// this.rt = rt;\n// }\n\n// isEmpty(): boolean {\n// return this.selectionStartCursorIdx === this.curCursorIdx;\n// }\n\n// hasFormat(key: string): boolean {\n// return this.getFormat(key) != null;\n// }\n\n// /**\n// * 获取第idx中key的值\n// * @param key\n// * @param idx cursor左侧字符的值,如果idx为-1则认为是特殊情况,为右侧字符的值\n// */\n// _getFormat(key: string, idx: number) {\n// if (!this.rt) {\n// return null;\n// }\n// const config = this.rt.attribute.textConfig as any;\n// if (idx < 0) {\n// idx = 0;\n// }\n// if (idx >= config.length) {\n// return null;\n// }\n// return config[idx][key] ?? (this.rt.attribute as any)[key];\n// }\n// getFormat(key: string): any {\n// return this.getAllFormat(key)[0];\n// }\n\n// getAllFormat(key: string): any {\n// const valSet = new Set();\n// let minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx);\n// let maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);\n// if (minCursorIdx === maxCursorIdx) {\n// return [this._getFormat(key, minCursorIdx)];\n// }\n// minCursorIdx++;\n// maxCursorIdx++;\n// const maxConfigIdx = this.rt.attribute.textConfig.length - 1;\n// if (minCursorIdx > maxConfigIdx) {\n// minCursorIdx = maxConfigIdx;\n// }\n// if (maxCursorIdx > maxConfigIdx) {\n// maxCursorIdx = maxConfigIdx;\n// }\n// for (let i = minCursorIdx; i < maxCursorIdx; i++) {\n// const val = this._getFormat(key, i);\n// val && valSet.add(val);\n// }\n// return Array.from(valSet.values());\n// }\n// }\n\n// export const FORMAT_TEXT_COMMAND = 'FORMAT_TEXT_COMMAND';\n// export const FORMAT_ELEMENT_COMMAND = 'FORMAT_ELEMENT_COMMAND';\n// export class RichTextEditPlugin implements IPlugin {\n// name: 'RichTextEditPlugin' = 'RichTextEditPlugin';\n// activeEvent: 'onRegister' = 'onRegister';\n// pluginService: IPluginService;\n// _uid: number = Generator.GenAutoIncrementId();\n// key: string = this.name + this._uid;\n// editing: boolean = false;\n// editLine: ILine;\n// editBg: IGroup;\n// pointerDown: boolean = false;\n// // 用于selection中保存上一次click时候的位置\n// lastPoint?: IPointLike;\n// editModule: EditModule;\n// currRt: IRichText;\n\n// // 当前的cursor信息\n// // 0.1为第一个字符右侧, -0.1为第一个字符左侧\n// // 1.1为第二个字符右侧,0.9为第二个字符左侧\n// curCursorIdx: number;\n// selectionStartCursorIdx: number;\n\n// commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;\n// updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;\n\n// ticker: ITicker;\n// timeline: ITimeline;\n\n// // 富文本有align或者baseline的时候,需要对光标做偏移\n// protected declare deltaX: number;\n// protected declare deltaY: number;\n\n// constructor() {\n// this.commandCbs = new Map();\n// this.commandCbs.set(FORMAT_TEXT_COMMAND, [this.formatTextCommandCb]);\n// this.updateCbs = [];\n// this.timeline = new DefaultTimeline();\n// this.ticker = new DefaultTicker([this.timeline]);\n// this.deltaX = 0;\n// this.deltaY = 0;\n// }\n\n// static CreateSelection(rt: IRichText) {\n// if (!rt) {\n// return null;\n// }\n// const { textConfig = [] } = rt.attribute;\n// return new Selection(\n// -1,\n// textConfig.length - 1,\n// findCursorIndexIgnoreLinebreak(textConfig, -1),\n// findCursorIndexIgnoreLinebreak(textConfig, textConfig.length - 1),\n// rt\n// );\n// }\n\n// /**\n// * 获取当前选择的区间范围\n// * @param defaultAll 如果force为true,又没有选择,则认为选择了所有然后进行匹配,如果为false,则认为什么都没有选择,返回null\n// * @returns\n// */\n// getSelection(defaultAll: boolean = false) {\n// if (!this.currRt) {\n// return null;\n// }\n// if (\n// this.selectionStartCursorIdx != null &&\n// this.curCursorIdx != null\n// // this.selectionStartCursorIdx !== this.curCursorIdx &&\n// ) {\n// return new Selection(\n// this.selectionStartCursorIdx,\n// this.curCursorIdx,\n// findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.selectionStartCursorIdx),\n// findCursorIndexIgnoreLinebreak(this.currRt.attribute.textConfig, this.curCursorIdx),\n// this.currRt\n// );\n// } else if (defaultAll) {\n// return RichTextEditPlugin.CreateSelection(this.currRt);\n// }\n// return null;\n// }\n\n// /* command */\n// formatTextCommandCb(payload: string, p: RichTextEditPlugin) {\n// const rt = p.currRt;\n// if (!rt) {\n// return;\n// }\n// const selectionData = p.getSelection();\n// if (!selectionData) {\n// return;\n// }\n// const { selectionStartCursorIdx, curCursorIdx } = selectionData;\n// const minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx);\n// const maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx);\n// const config = rt.attribute.textConfig.slice(minCursorIdx + 1, maxCursorIdx + 1);\n// if (payload === 'bold') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.fontWeight = 'bold'));\n// } else if (payload === 'italic') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.fontStyle = 'italic'));\n// } else if (payload === 'underline') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.underline = true));\n// } else if (payload === 'lineThrough') {\n// config.forEach((item: IRichTextParagraphCharacter) => (item.lineThrough = true));\n// } else if (isObject(payload)) {\n// config.forEach((item: IRichTextParagraphCharacter) => merge(item, payload));\n// }\n// rt.setAttributes(rt.attribute);\n// }\n\n// dispatchCommand(command: string, payload: any) {\n// const cbs = this.commandCbs.get(command);\n// cbs && cbs.forEach(cb => cb(payload, this));\n// this.updateCbs.forEach(cb => cb('dispatch', this));\n// }\n\n// registerCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void) {\n// const cbs: Array<(payload: any, p: RichTextEditPlugin) => void> = this.commandCbs.get(command) || [];\n// cbs.push(cb);\n// }\n\n// registerUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void) {\n// const cbs = this.updateCbs || [];\n// cbs.push(cb);\n// }\n\n// activate(context: IPluginService): void {\n// this.pluginService = context;\n// this.editModule = new EditModule();\n// // context.stage.on('click', this.handleClick);\n// context.stage.on('pointermove', this.handleMove);\n// context.stage.on('pointerdown', this.handlePointerDown);\n// context.stage.on('pointerup', this.handlePointerUp);\n// context.stage.on('pointerleave', this.handlePointerUp);\n\n// this.editModule.onInput(this.handleInput);\n// this.editModule.onChange(this.handleChange);\n// }\n\n// handleInput = (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => {\n// // 修改cursor的位置,但并不同步,因为这可能是临时的\n// const p = this.getPointByColumnIdx(cursorIdx, rt, orient);\n// this.hideSelection();\n// this.setCursor(p.x, p.y1, p.y2);\n// this.updateCbs.forEach(cb => cb('input', this));\n// };\n// handleChange = (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => {\n// // 修改cursor的位置,并同步到editModule\n// const p = this.getPointByColumnIdx(cursorIdx, rt, orient);\n// this.curCursorIdx = cursorIdx;\n// this.selectionStartCursorIdx = cursorIdx;\n// this.setCursorAndTextArea(p.x, p.y1, p.y2, rt);\n// this.hideSelection();\n// this.updateCbs.forEach(cb => cb('change', this));\n// };\n\n// handleMove = (e: PointerEvent) => {\n// if (!this.isRichtext(e)) {\n// return;\n// }\n// this.currRt = e.target as IRichText;\n// this.handleEnter(e);\n// (e.target as any).once('pointerleave', this.handleLeave);\n\n// this.showSelection(e);\n// };\n\n// showSelection(e: PointerEvent) {\n// const cache = (e.target as IRichText).getFrameCache();\n// if (!(cache && this.editBg)) {\n// return;\n// }\n// if (this.pointerDown) {\n// let p0 = this.lastPoint;\n// // 计算p1在字符中的位置\n// let p1 = this.getEventPosition(e);\n// let line1Info = this.getLineByPoint(cache, p1);\n// if (!line1Info) {\n// return;\n// }\n// const column1 = this.getColumnByLinePoint(line1Info, p1);\n// const y1 = line1Info.top;\n// const y2 = line1Info.top + line1Info.height;\n// let x = column1.left + column1.width;\n// let cursorIndex = this.getColumnIndex(cache, column1);\n// if (p1.x < column1.left + column1.width / 2) {\n// x = column1.left;\n// cursorIndex -= 1;\n// }\n// p1.x = x;\n// p1.y = (y1 + y2) / 2;\n// let line0Info = this.getLineByPoint(cache, p0);\n// if (p0.y > p1.y || (p0.y === p1.y && p0.x > p1.x)) {\n// [p0, p1] = [p1, p0];\n// [line1Info, line0Info] = [line0Info, line1Info];\n// }\n\n// this.editBg.removeAllChild();\n// if (line0Info === line1Info) {\n// // const column0 = this.getColumnByLinePoint(line0Info, p0);\n// this.editBg.setAttributes({\n// x: p0.x,\n// y: line0Info.top,\n// width: p1.x - p0.x,\n// height: line0Info.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// });\n// } else {\n// this.editBg.setAttributes({ x: 0, y: line0Info.top, width: 0, height: 0 });\n// const startIdx = cache.lines.findIndex(item => item === line0Info);\n// const endIdx = cache.lines.findIndex(item => item === line1Info);\n// let y = 0;\n// for (let i = startIdx; i <= endIdx; i++) {\n// const line = cache.lines[i];\n// if (i === startIdx) {\n// const p = line.paragraphs[line.paragraphs.length - 1];\n// this.editBg.add(\n// createRect({\n// x: p0.x,\n// y,\n// width: p.left + p.width - p0.x,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// } else if (i === endIdx) {\n// const p = line.paragraphs[0];\n// this.editBg.add(\n// createRect({\n// x: p.left,\n// y,\n// width: p1.x - p.left,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// } else {\n// const p0 = line.paragraphs[0];\n// const p1 = line.paragraphs[line.paragraphs.length - 1];\n// this.editBg.add(\n// createRect({\n// x: p0.left,\n// y,\n// width: p1.left + p1.width - p0.left,\n// height: line.height,\n// fill: '#336df4',\n// fillOpacity: 0.2\n// })\n// );\n// }\n// y += line.height;\n// }\n// }\n\n// this.curCursorIdx = cursorIndex;\n// this.setCursorAndTextArea(x, y1 + 2, y2 - 2, e.target as IRichText);\n\n// this.applyUpdate();\n// this.updateCbs.forEach(cb => cb('selection', this));\n// }\n// }\n\n// hideSelection() {\n// if (this.editBg) {\n// this.editBg.removeAllChild();\n// this.editBg.setAttributes({ fill: 'transparent' });\n// }\n// }\n\n// handlePointerDown = (e: PointerEvent) => {\n// if (this.editing) {\n// this.onFocus(e);\n// } else {\n// this.deFocus(e);\n// }\n// this.applyUpdate();\n// this.pointerDown = true;\n// this.updateCbs.forEach(cb => cb(this.editing ? 'onfocus' : 'defocus', this));\n// console.log(this.selectionStartCursorIdx);\n// };\n// handlePointerUp = (e: PointerEvent) => {\n// this.pointerDown = false;\n// };\n\n// forceFocus(e: PointerEvent) {\n// this.handleEnter(e);\n// this.handlePointerDown(e);\n// this.handlePointerUp(e);\n// }\n\n// // 鼠标进入\n// handleEnter = (e: PointerEvent) => {\n// this.editing = true;\n// this.pluginService.stage.setCursor('text');\n// };\n\n// // 鼠标离开\n// handleLeave = (e: PointerEvent) => {\n// this.editing = false;\n// this.pluginService.stage.setCursor('default');\n// };\n\n// isRichtext(e: PointerEvent) {\n// return !!(e.target && (e.target as any).type === 'richtext' && (e.target as any).attribute.editable);\n// }\n\n// protected getEventPosition(e: PointerEvent): IPointLike {\n// const p = this.pluginService.stage.eventPointTransform(e);\n\n// const p1 = { x: 0, y: 0 };\n// (e.target as IRichText).globalTransMatrix.transformPoint(p, p1);\n// p1.x -= this.deltaX;\n// p1.y -= this.deltaY;\n// return p1;\n// }\n\n// protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine {\n// let lineInfo = cache.lines[0];\n// for (let i = 0; i < cache.lines.length; i++) {\n// if (lineInfo.top <= p1.y && lineInfo.top + lineInfo.height >= p1.y) {\n// break;\n// }\n// lineInfo = cache.lines[i + 1];\n// }\n\n// return lineInfo;\n// }\n// protected getColumnByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): IRichTextParagraph | IRichTextIcon {\n// let columnInfo = lineInfo.paragraphs[0];\n// for (let i = 0; i < lineInfo.paragraphs.length; i++) {\n// if (columnInfo.left <= p1.x && columnInfo.left + columnInfo.width >= p1.x) {\n// break;\n// }\n// columnInfo = lineInfo.paragraphs[i];\n// }\n\n// return columnInfo;\n// }\n\n// onFocus(e: PointerEvent) {\n// this.deFocus(e);\n// this.currRt = e.target as IRichText;\n\n// // 添加shadowGraphic\n// const target = e.target as IRichText;\n// RichTextEditPlugin.tryUpdateRichtext(target);\n// const shadowRoot = target.attachShadow();\n// const cache = target.getFrameCache();\n// if (!cache) {\n// return;\n// }\n\n// this.deltaX = 0;\n// this.deltaY = 0;\n// const height = cache.actualHeight;\n// const width = cache.lines.reduce((w, item) => Math.max(w, item.actualWidth), 0);\n// if (cache.globalAlign === 'center') {\n// this.deltaX = -width / 2;\n// } else if (cache.globalAlign === 'right') {\n// this.deltaX = -width;\n// }\n// if (cache.globalBaseline === 'middle') {\n// this.deltaY = -height / 2;\n// } else if (cache.globalBaseline === 'bottom') {\n// this.deltaY = -height;\n// }\n\n// shadowRoot.setAttributes({ shadowRootIdx: -1, x: this.deltaX, y: this.deltaY });\n// if (!this.editLine) {\n// const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });\n// // 不使用stage的Ticker,避免影响其他的动画以及受到其他动画影响\n// const animate = line.animate();\n// animate.setTimeline(this.timeline);\n// animate.to({ opacity: 1 }, 10, 'linear').wait(700).to({ opacity: 0 }, 10, 'linear').wait(700).loop(Infinity);\n// this.editLine = line;\n// this.ticker.start(true);\n\n// const g = createGroup({ x: 0, y: 0, width: 0, height: 0 });\n// this.editBg = g;\n// shadowRoot.add(this.editLine);\n// shadowRoot.add(this.editBg);\n// }\n\n// const p1 = this.getEventPosition(e);\n\n// const lineInfo = this.getLineByPoint(cache, p1);\n\n// if (lineInfo) {\n// const columnInfo = this.getColumnByLinePoint(lineInfo, p1);\n// if (!columnInfo) {\n// return;\n// }\n\n// let y1 = lineInfo.top;\n// let y2 = lineInfo.top + lineInfo.height;\n// let x = columnInfo.left + columnInfo.width;\n// y1 += 2;\n// y2 -= 2;\n// let cursorIndex = this.getColumnIndex(cache, columnInfo);\n// if (p1.x < columnInfo.left + columnInfo.width / 2) {\n// x = columnInfo.left;\n// cursorIndex -= 1;\n// }\n\n// this.lastPoint = { x, y: (y1 + y2) / 2 };\n\n// this.curCursorIdx = cursorIndex;\n// this.selectionStartCursorIdx = cursorIndex;\n// this.setCursorAndTextArea(x, y1, y2, target);\n// }\n// }\n\n// protected getPointByColumnIdx(idx: number, rt: IRichText, orient: 'left' | 'right') {\n// const cache = rt.getFrameCache();\n// const column = this.getColumnByIndex(cache, idx);\n// const height = rt.attribute.fontSize ?? (rt.attribute.textConfig?.[0] as any)?.fontSize;\n// if (!column) {\n// return {\n// x: 0,\n// y1: 0,\n// y2: height\n// };\n// }\n// const { lineInfo, columnInfo } = column;\n// let y1 = lineInfo.top;\n// let y2 = lineInfo.top + lineInfo.height;\n// const x = columnInfo.left + (orient === 'left' ? 0 : columnInfo.width);\n// y1 += 2;\n// y2 -= 2;\n\n// return { x, y1, y2 };\n// }\n\n// protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon) {\n// // TODO 认为都是单个字符拆分的\n// let inputIndex = -1;\n// for (let i = 0; i < cache.lines.length; i++) {\n// const line = cache.lines[i];\n// for (let j = 0; j < line.paragraphs.length; j++) {\n// inputIndex++;\n// if (cInfo === line.paragraphs[j]) {\n// return inputIndex;\n// }\n// }\n// }\n// return -1;\n// }\n// protected getColumnByIndex(\n// cache: IRichTextFrame,\n// index: number\n// ): {\n// lineInfo: IRichTextLine;\n// columnInfo: IRichTextParagraph | IRichTextIcon;\n// } | null {\n// // TODO 认为都是单个字符拆分的\n// let inputIndex = -1;\n// for (let i = 0; i < cache.lines.length; i++) {\n// const lineInfo = cache.lines[i];\n// for (let j = 0; j < lineInfo.paragraphs.length; j++) {\n// const columnInfo = lineInfo.paragraphs[j];\n// inputIndex++;\n// if (inputIndex === index) {\n// return {\n// lineInfo,\n// columnInfo\n// };\n// }\n// }\n// }\n// return null;\n// }\n\n// protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText) {\n// this.editLine.setAttributes({\n// points: [\n// { x, y: y1 },\n// { x, y: y2 }\n// ]\n// });\n// const out = { x: 0, y: 0 };\n// rt.globalTransMatrix.getInverse().transformPoint({ x, y: y1 }, out);\n// // TODO 考虑stage变换\n// const { left, top } = this.pluginService.stage.window.getBoundingClientRect();\n// out.x += left;\n// out.y += top;\n\n// this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);\n// }\n// protected setCursor(x: number, y1: number, y2: number) {\n// this.editLine.setAttributes({\n// points: [\n// { x, y: y1 },\n// { x, y: y2 }\n// ]\n// });\n// }\n\n// applyUpdate() {\n// this.pluginService.stage.renderNextFrame();\n// }\n// deFocus(e: PointerEvent) {\n// const target = this.currRt as IRichText;\n// if (!target) {\n// return;\n// }\n// target.detachShadow();\n// this.currRt = null;\n// if (this.editLine) {\n// this.editLine.parent.removeChild(this.editLine);\n// this.editLine.release();\n// this.editLine = null;\n\n// this.editBg.parent.removeChild(this.editBg);\n// this.editBg.release();\n// this.editBg = null;\n// }\n// }\n\n// static splitText(text: string) {\n// // 😁这种emoji长度算两个,所以得处理一下\n// return Array.from(text);\n// }\n\n// static tryUpdateRichtext(richtext: IRichText) {\n// const cache = richtext.getFrameCache();\n// if (\n// !cache.lines.every(line =>\n// line.paragraphs.every(\n// item => !(item.text && isString(item.text) && RichTextEditPlugin.splitText(item.text).length > 1)\n// )\n// )\n// ) {\n// const tc: IRichTextCharacter[] = [];\n// richtext.attribute.textConfig.forEach((item: IRichTextParagraphCharacter) => {\n// const textList = RichTextEditPlugin.splitText(item.text.toString());\n// if (isString(item.text) && textList.length > 1) {\n// // 拆分\n// for (let i = 0; i < textList.length; i++) {\n// const t = textList[i];\n// tc.push({ ...item, text: t });\n// }\n// } else {\n// tc.push(item);\n// }\n// });\n// richtext.setAttributes({ textConfig: tc });\n// richtext.doUpdateFrameCache(tc);\n// }\n// }\n\n// onSelect() {\n// return;\n// }\n\n// deactivate(context: IPluginService): void {\n// // context.stage.off('pointerdown', this.handleClick);\n// context.stage.off('pointermove', this.handleMove);\n// context.stage.off('pointerdown', this.handlePointerDown);\n// context.stage.off('pointerup', this.handlePointerUp);\n// context.stage.off('pointerleave', this.handlePointerUp);\n// }\n\n// release() {\n// this.editModule.release();\n// }\n// }\n"]}
@@ -1,19 +1,21 @@
1
1
  import type { IPointLike } from '@visactor/vutils';
2
- import type { IGroup, ILine, IPlugin, IPluginService, IRichText, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph } from '../../interface';
2
+ import type { IGroup, ILine, IPlugin, IPluginService, IRect, IRichText, IRichTextCharacter, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
3
3
  import { EditModule } from './edit-module';
4
- type UpdateType = 'input' | 'change' | 'onfocus' | 'defocus' | 'selection' | 'dispatch';
4
+ type UpdateType = 'input' | 'change' | 'onfocus' | 'beforeOnfocus' | 'defocus' | 'beforeDefocus' | 'selection' | 'dispatch';
5
5
  declare class Selection {
6
- cacheSelectionStartCursorIdx: number;
7
- cacheCurCursorIdx: number;
8
6
  selectionStartCursorIdx: number;
9
7
  curCursorIdx: number;
10
8
  rt: IRichText;
11
- constructor(cacheSelectionStartCursorIdx: number, cacheCurCursorIdx: number, selectionStartCursorIdx: number, curCursorIdx: number, rt: IRichText);
9
+ constructor(selectionStartCursorIdx: number, curCursorIdx: number, rt: IRichText);
10
+ isEmpty(): boolean;
11
+ getSelectionPureText(): string;
12
12
  hasFormat(key: string): boolean;
13
+ _getFormat(key: string, cursorIdx: number): any;
13
14
  getFormat(key: string): any;
14
15
  getAllFormat(key: string): any;
15
16
  }
16
17
  export declare const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
18
+ export declare const FORMAT_ALL_TEXT_COMMAND = "FORMAT_ALL_TEXT_COMMAND";
17
19
  export declare const FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
18
20
  export declare class RichTextEditPlugin implements IPlugin {
19
21
  name: 'RichTextEditPlugin';
@@ -22,55 +24,112 @@ export declare class RichTextEditPlugin implements IPlugin {
22
24
  _uid: number;
23
25
  key: string;
24
26
  editing: boolean;
27
+ focusing: boolean;
28
+ pointerDown: boolean;
25
29
  editLine: ILine;
26
30
  editBg: IGroup;
27
- pointerDown: boolean;
28
- lastPoint?: IPointLike;
29
- editModule: EditModule;
31
+ shadowPlaceHolder: IRichText;
32
+ shadowBounds: IRect;
33
+ ticker: ITicker;
34
+ timeline: ITimeline;
30
35
  currRt: IRichText;
31
36
  curCursorIdx: number;
32
37
  selectionStartCursorIdx: number;
33
- commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;
34
- updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;
38
+ startCursorPos?: IPointLike;
39
+ editModule: EditModule;
40
+ protected commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;
41
+ protected updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin, params?: any) => void>;
42
+ protected deltaX: number;
43
+ protected deltaY: number;
44
+ static tryUpdateRichtext(richtext: IRichText): void;
45
+ static CreateSelection(rt: IRichText): Selection;
35
46
  constructor();
36
- getSelection(): Selection;
37
- formatTextCommandCb(payload: string, p: RichTextEditPlugin): void;
47
+ formatTextCommandCb: (payload: string, p: RichTextEditPlugin) => void;
48
+ formatAllTextCommandCb: (payload: string, p: RichTextEditPlugin) => void;
49
+ _formatTextCommand(payload: string, config: IRichTextCharacter[], rt: IRichText): void;
38
50
  dispatchCommand(command: string, payload: any): void;
39
51
  registerCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void): void;
52
+ removeCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void): void;
40
53
  registerUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void): void;
54
+ removeUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void): void;
41
55
  activate(context: IPluginService): void;
42
- handleInput: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => void;
43
- handleChange: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText, orient: 'left' | 'right') => void;
56
+ copyToClipboard(e: KeyboardEvent): boolean;
57
+ selectionRange(startIdx: number, endIdx: number): void;
58
+ selectionRangeByCursorIdx(startCursorIdx: number, endCursorIdx: number, cache: IRichTextFrame): void;
59
+ fullSelection(e: KeyboardEvent): boolean;
60
+ directKey(e: KeyboardEvent): boolean;
61
+ handleKeyDown: (e: KeyboardEvent) => void;
62
+ handleInput: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
63
+ handleChange: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
64
+ tryShowShadowPlaceholder(): void;
65
+ tryShowInputBounds(): void;
66
+ trySyncPlaceholderToTextConfig(): void;
67
+ handleFocusIn: () => never;
68
+ handleFocusOut: () => never;
69
+ deactivate(context: IPluginService): void;
44
70
  handleMove: (e: PointerEvent) => void;
45
- showSelection(e: PointerEvent): void;
46
- hideSelection(): void;
71
+ handleEnter: () => void;
72
+ handleLeave: () => void;
47
73
  handlePointerDown: (e: PointerEvent) => void;
48
74
  handlePointerUp: (e: PointerEvent) => void;
49
- handleEnter: (e: PointerEvent) => void;
50
- handleLeave: (e: PointerEvent) => void;
51
- isRichtext(e: PointerEvent): boolean;
52
- protected getEventPosition(e: PointerEvent): IPointLike;
53
- protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine;
54
- protected getColumnByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): IRichTextParagraph | IRichTextIcon;
55
- onFocus(e: PointerEvent): void;
56
- protected getPointByColumnIdx(idx: number, rt: IRichText, orient: 'left' | 'right'): {
75
+ handleDBLClick: (e: PointerEvent) => void;
76
+ onFocus(e: PointerEvent, data?: any): void;
77
+ protected offsetLineBgAndShadowBounds(): void;
78
+ protected deFocus(trulyDeFocus?: boolean): void;
79
+ protected addAnimateToLine(line: ILine): void;
80
+ tryShowSelection(e: PointerEvent, dblclick: boolean): void;
81
+ _tryShowSelection(currCursorData: {
57
82
  x: any;
58
83
  y1: number;
59
84
  y2: number;
85
+ }, cache: IRichTextFrame): void;
86
+ hideSelection(): void;
87
+ protected getShadow(rt: IRichText): import("../../interface").IShadowRoot;
88
+ protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine;
89
+ protected getColumnAndIndexByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): {
90
+ columnInfo: IRichTextParagraph | IRichTextIcon;
91
+ delta: number;
60
92
  };
61
93
  protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
94
+ protected isRichtext(e: PointerEvent): boolean;
95
+ protected isEditableRichtext(e: PointerEvent): boolean;
96
+ protected triggerRender(): void;
97
+ protected computeGlobalDelta(cache: IRichTextFrame): void;
98
+ protected getEventPosition(e: PointerEvent): IPointLike;
99
+ protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText): void;
100
+ protected computedCursorPosByEvent(e: PointerEvent, cache: IRichTextFrame): {
101
+ x: any;
102
+ y1: number;
103
+ y2: number;
104
+ cursorIndex: number;
105
+ lineInfo: IRichTextLine;
106
+ columnInfo: IRichTextParagraph | IRichTextIcon;
107
+ };
108
+ protected computedCursorPosByCursorIdx(cursorIdx: number, rt: IRichText): {
109
+ x: number;
110
+ y1: number;
111
+ y2: any;
112
+ lineInfo?: undefined;
113
+ columnInfo?: undefined;
114
+ } | {
115
+ x: any;
116
+ y1: number;
117
+ y2: number;
118
+ lineInfo: IRichTextLine;
119
+ columnInfo: IRichTextParagraph | IRichTextIcon;
120
+ };
62
121
  protected getColumnByIndex(cache: IRichTextFrame, index: number): {
63
122
  lineInfo: IRichTextLine;
64
123
  columnInfo: IRichTextParagraph | IRichTextIcon;
65
124
  } | null;
66
- protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText): void;
67
- protected setCursor(x: number, y1: number, y2: number): void;
68
- applyUpdate(): void;
69
- deFocus(e: PointerEvent): void;
70
- splitText(text: string): string[];
71
- tryUpdateRichtext(richtext: IRichText): void;
72
- onSelect(): void;
73
- deactivate(context: IPluginService): void;
74
125
  release(): void;
126
+ getSelection(defaultAll?: boolean): Selection;
127
+ forceFocus(params: {
128
+ e?: PointerEvent;
129
+ target: IRichText | null;
130
+ cursorIndex?: number;
131
+ }): void;
132
+ protected _forceFocusByEvent(e: PointerEvent): void;
133
+ protected _forceFocusByCursorIndex(cursorIndex: number): void;
75
134
  }
76
135
  export {};