@visactor/vrender-core 0.21.2-vstory.3 → 0.21.2

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