@visactor/vrender-core 0.21.1-alpha.1 → 0.21.2-vstory.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/cjs/animate/Ticker/default-ticker.d.ts +2 -0
  2. package/cjs/animate/Ticker/default-ticker.js +7 -1
  3. package/cjs/animate/Ticker/default-ticker.js.map +1 -1
  4. package/cjs/animate/animate.js +1 -1
  5. package/cjs/animate/animate.js.map +1 -1
  6. package/cjs/animate/easing-func.d.ts +1 -0
  7. package/cjs/animate/easing-func.js +16 -0
  8. package/cjs/animate/easing-func.js.map +1 -0
  9. package/cjs/animate/easing.d.ts +4 -0
  10. package/cjs/animate/easing.js +12 -1
  11. package/cjs/animate/easing.js.map +1 -1
  12. package/cjs/animate/index.d.ts +1 -0
  13. package/cjs/animate/index.js +1 -1
  14. package/cjs/animate/index.js.map +1 -1
  15. package/cjs/color-string/store.js +1 -2
  16. package/cjs/common/3d-interceptor.js +2 -1
  17. package/cjs/common/bezier-utils.d.ts +3 -0
  18. package/cjs/common/bezier-utils.js +17 -2
  19. package/cjs/common/bezier-utils.js.map +1 -1
  20. package/cjs/common/custom-path2d.d.ts +4 -0
  21. package/cjs/common/custom-path2d.js +43 -11
  22. package/cjs/common/custom-path2d.js.map +1 -1
  23. package/cjs/common/render-area.js +0 -1
  24. package/cjs/common/render-command-list.js +2 -1
  25. package/cjs/common/render-curve.js +1 -1
  26. package/cjs/common/render-curve.js.map +1 -1
  27. package/cjs/common/segment/curve/arc.d.ts +4 -1
  28. package/cjs/common/segment/curve/arc.js +10 -1
  29. package/cjs/common/segment/curve/arc.js.map +1 -1
  30. package/cjs/common/segment/curve/base.d.ts +4 -1
  31. package/cjs/common/segment/curve/base.js.map +1 -1
  32. package/cjs/common/segment/curve/cubic-bezier.d.ts +5 -1
  33. package/cjs/common/segment/curve/cubic-bezier.js +24 -3
  34. package/cjs/common/segment/curve/cubic-bezier.js.map +1 -1
  35. package/cjs/common/segment/curve/curve-context.js +5 -4
  36. package/cjs/common/segment/curve/curve-context.js.map +1 -1
  37. package/cjs/common/segment/curve/ellipse.d.ts +4 -1
  38. package/cjs/common/segment/curve/ellipse.js +9 -0
  39. package/cjs/common/segment/curve/ellipse.js.map +1 -1
  40. package/cjs/common/segment/curve/line.d.ts +4 -1
  41. package/cjs/common/segment/curve/line.js +18 -0
  42. package/cjs/common/segment/curve/line.js.map +1 -1
  43. package/cjs/common/segment/curve/move.d.ts +4 -1
  44. package/cjs/common/segment/curve/move.js +9 -0
  45. package/cjs/common/segment/curve/move.js.map +1 -1
  46. package/cjs/common/segment/curve/path.d.ts +2 -1
  47. package/cjs/common/segment/curve/path.js +5 -2
  48. package/cjs/common/segment/curve/path.js.map +1 -1
  49. package/cjs/common/segment/curve/quadratic-bezier.d.ts +6 -2
  50. package/cjs/common/segment/curve/quadratic-bezier.js +23 -5
  51. package/cjs/common/segment/curve/quadratic-bezier.js.map +1 -1
  52. package/cjs/common/store.js +1 -1
  53. package/cjs/constants.d.ts +1 -0
  54. package/cjs/constants.js +3 -2
  55. package/cjs/constants.js.map +1 -1
  56. package/cjs/graphic/builtin-symbol/rect.d.ts +2 -1
  57. package/cjs/graphic/builtin-symbol/rect.js +28 -0
  58. package/cjs/graphic/builtin-symbol/rect.js.map +1 -1
  59. package/cjs/graphic/builtin-symbol/utils.d.ts +2 -1
  60. package/cjs/graphic/builtin-symbol/utils.js +5 -0
  61. package/cjs/graphic/builtin-symbol/utils.js.map +1 -1
  62. package/cjs/graphic/config.js +6 -1
  63. package/cjs/graphic/config.js.map +1 -1
  64. package/cjs/graphic/graphic.js +2 -1
  65. package/cjs/graphic/graphic.js.map +1 -1
  66. package/cjs/graphic/group.js +10 -5
  67. package/cjs/graphic/group.js.map +1 -1
  68. package/cjs/graphic/node-tree.js +3 -3
  69. package/cjs/graphic/node-tree.js.map +1 -1
  70. package/cjs/graphic/richtext/utils.js +3 -3
  71. package/cjs/graphic/richtext/utils.js.map +1 -1
  72. package/cjs/graphic/richtext/wrapper.d.ts +1 -0
  73. package/cjs/graphic/richtext/wrapper.js +1 -1
  74. package/cjs/graphic/richtext/wrapper.js.map +1 -1
  75. package/cjs/graphic/richtext.js +3 -2
  76. package/cjs/graphic/richtext.js.map +1 -1
  77. package/cjs/index.d.ts +1 -0
  78. package/cjs/index.js +1 -1
  79. package/cjs/index.js.map +1 -1
  80. package/cjs/interface/animate.d.ts +5 -39
  81. package/cjs/interface/animate.js.map +1 -1
  82. package/cjs/interface/graphic/path.d.ts +1 -0
  83. package/cjs/interface/graphic/path.js.map +1 -1
  84. package/cjs/interface/graphic/symbol.d.ts +2 -0
  85. package/cjs/interface/graphic/symbol.js.map +1 -1
  86. package/cjs/interface/graphic.d.ts +6 -2
  87. package/cjs/interface/graphic.js.map +1 -1
  88. package/cjs/interface/path.d.ts +5 -0
  89. package/cjs/interface/path.js.map +1 -1
  90. package/cjs/interface/picker.d.ts +13 -0
  91. package/cjs/interface/picker.js.map +1 -1
  92. package/cjs/picker/constants.d.ts +2 -0
  93. package/cjs/picker/constants.js +3 -2
  94. package/cjs/picker/constants.js.map +1 -1
  95. package/cjs/picker/pick-interceptor.d.ts +7 -2
  96. package/cjs/picker/pick-interceptor.js +19 -2
  97. package/cjs/picker/pick-interceptor.js.map +1 -1
  98. package/cjs/picker/pick-modules.js +7 -4
  99. package/cjs/picker/pick-modules.js.map +1 -1
  100. package/cjs/picker/picker-service.d.ts +4 -2
  101. package/cjs/picker/picker-service.js +13 -12
  102. package/cjs/picker/picker-service.js.map +1 -1
  103. package/cjs/plugins/builtin-plugin/edit-module.d.ts +6 -5
  104. package/cjs/plugins/builtin-plugin/edit-module.js +84 -28
  105. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  106. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  107. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  108. package/cjs/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  109. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +49 -30
  110. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +280 -217
  111. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  112. package/cjs/render/contributions/render/arc3d-render.js.map +1 -1
  113. package/cjs/render/contributions/render/base-render.d.ts +1 -0
  114. package/cjs/render/contributions/render/base-render.js +20 -2
  115. package/cjs/render/contributions/render/base-render.js.map +1 -1
  116. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  117. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  118. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  119. package/cjs/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  120. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +30 -2
  121. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  122. package/cjs/render/contributions/render/draw-contribution.d.ts +1 -0
  123. package/cjs/render/contributions/render/draw-contribution.js +15 -7
  124. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  125. package/cjs/render/contributions/render/path-render.js.map +1 -1
  126. package/cjs/render/contributions/render/polygon-render.js.map +1 -1
  127. package/cjs/render/contributions/render/symbol-render.js +15 -12
  128. package/cjs/render/contributions/render/symbol-render.js.map +1 -1
  129. package/cjs/render/contributions/render/utils.d.ts +1 -2
  130. package/cjs/render/contributions/render/utils.js +4 -20
  131. package/cjs/render/contributions/render/utils.js.map +1 -1
  132. package/dist/index.es.js +8282 -7662
  133. package/es/animate/Ticker/default-ticker.d.ts +2 -0
  134. package/es/animate/Ticker/default-ticker.js +7 -1
  135. package/es/animate/Ticker/default-ticker.js.map +1 -1
  136. package/es/animate/animate.js +1 -1
  137. package/es/animate/animate.js.map +1 -1
  138. package/es/animate/easing-func.d.ts +1 -0
  139. package/es/animate/easing-func.js +10 -0
  140. package/es/animate/easing-func.js.map +1 -0
  141. package/es/animate/easing.d.ts +4 -0
  142. package/es/animate/easing.js +12 -1
  143. package/es/animate/easing.js.map +1 -1
  144. package/es/animate/index.d.ts +1 -0
  145. package/es/animate/index.js +2 -0
  146. package/es/animate/index.js.map +1 -1
  147. package/es/color-string/store.js +1 -2
  148. package/es/common/3d-interceptor.js +2 -1
  149. package/es/common/bezier-utils.d.ts +3 -0
  150. package/es/common/bezier-utils.js +14 -0
  151. package/es/common/bezier-utils.js.map +1 -1
  152. package/es/common/custom-path2d.d.ts +4 -0
  153. package/es/common/custom-path2d.js +44 -12
  154. package/es/common/custom-path2d.js.map +1 -1
  155. package/es/common/render-area.js +1 -2
  156. package/es/common/render-command-list.js +2 -1
  157. package/es/common/render-curve.js +1 -1
  158. package/es/common/render-curve.js.map +1 -1
  159. package/es/common/segment/curve/arc.d.ts +4 -1
  160. package/es/common/segment/curve/arc.js +10 -1
  161. package/es/common/segment/curve/arc.js.map +1 -1
  162. package/es/common/segment/curve/base.d.ts +4 -1
  163. package/es/common/segment/curve/base.js.map +1 -1
  164. package/es/common/segment/curve/cubic-bezier.d.ts +5 -1
  165. package/es/common/segment/curve/cubic-bezier.js +22 -1
  166. package/es/common/segment/curve/cubic-bezier.js.map +1 -1
  167. package/es/common/segment/curve/curve-context.js +6 -3
  168. package/es/common/segment/curve/curve-context.js.map +1 -1
  169. package/es/common/segment/curve/ellipse.d.ts +4 -1
  170. package/es/common/segment/curve/ellipse.js +9 -0
  171. package/es/common/segment/curve/ellipse.js.map +1 -1
  172. package/es/common/segment/curve/line.d.ts +4 -1
  173. package/es/common/segment/curve/line.js +18 -0
  174. package/es/common/segment/curve/line.js.map +1 -1
  175. package/es/common/segment/curve/move.d.ts +4 -1
  176. package/es/common/segment/curve/move.js +9 -0
  177. package/es/common/segment/curve/move.js.map +1 -1
  178. package/es/common/segment/curve/path.d.ts +2 -1
  179. package/es/common/segment/curve/path.js +5 -2
  180. package/es/common/segment/curve/path.js.map +1 -1
  181. package/es/common/segment/curve/quadratic-bezier.d.ts +6 -2
  182. package/es/common/segment/curve/quadratic-bezier.js +28 -5
  183. package/es/common/segment/curve/quadratic-bezier.js.map +1 -1
  184. package/es/common/store.js +1 -1
  185. package/es/constants.d.ts +1 -0
  186. package/es/constants.js +2 -0
  187. package/es/constants.js.map +1 -1
  188. package/es/graphic/builtin-symbol/rect.d.ts +2 -1
  189. package/es/graphic/builtin-symbol/rect.js +28 -0
  190. package/es/graphic/builtin-symbol/rect.js.map +1 -1
  191. package/es/graphic/builtin-symbol/utils.d.ts +2 -1
  192. package/es/graphic/builtin-symbol/utils.js +5 -0
  193. package/es/graphic/builtin-symbol/utils.js.map +1 -1
  194. package/es/graphic/config.js +6 -1
  195. package/es/graphic/config.js.map +1 -1
  196. package/es/graphic/graphic.js +2 -1
  197. package/es/graphic/graphic.js.map +1 -1
  198. package/es/graphic/group.js +10 -5
  199. package/es/graphic/group.js.map +1 -1
  200. package/es/graphic/node-tree.js +3 -3
  201. package/es/graphic/node-tree.js.map +1 -1
  202. package/es/graphic/richtext/utils.js +4 -2
  203. package/es/graphic/richtext/utils.js.map +1 -1
  204. package/es/graphic/richtext/wrapper.d.ts +1 -0
  205. package/es/graphic/richtext/wrapper.js +1 -1
  206. package/es/graphic/richtext/wrapper.js.map +1 -1
  207. package/es/graphic/richtext.js +3 -2
  208. package/es/graphic/richtext.js.map +1 -1
  209. package/es/index.d.ts +1 -0
  210. package/es/index.js +2 -0
  211. package/es/index.js.map +1 -1
  212. package/es/interface/animate.d.ts +5 -39
  213. package/es/interface/animate.js.map +1 -1
  214. package/es/interface/graphic/path.d.ts +1 -0
  215. package/es/interface/graphic/path.js.map +1 -1
  216. package/es/interface/graphic/symbol.d.ts +2 -0
  217. package/es/interface/graphic/symbol.js.map +1 -1
  218. package/es/interface/graphic.d.ts +6 -2
  219. package/es/interface/graphic.js.map +1 -1
  220. package/es/interface/path.d.ts +5 -0
  221. package/es/interface/path.js.map +1 -1
  222. package/es/interface/picker.d.ts +13 -0
  223. package/es/interface/picker.js.map +1 -1
  224. package/es/picker/constants.d.ts +2 -0
  225. package/es/picker/constants.js +4 -0
  226. package/es/picker/constants.js.map +1 -1
  227. package/es/picker/pick-interceptor.d.ts +7 -2
  228. package/es/picker/pick-interceptor.js +19 -1
  229. package/es/picker/pick-interceptor.js.map +1 -1
  230. package/es/picker/pick-modules.js +5 -3
  231. package/es/picker/pick-modules.js.map +1 -1
  232. package/es/picker/picker-service.d.ts +4 -2
  233. package/es/picker/picker-service.js +13 -13
  234. package/es/picker/picker-service.js.map +1 -1
  235. package/es/plugins/builtin-plugin/edit-module.d.ts +6 -5
  236. package/es/plugins/builtin-plugin/edit-module.js +79 -25
  237. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  238. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.d.ts +1 -0
  239. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js +3 -0
  240. package/es/plugins/builtin-plugin/richtext-edit-plugin-old.js.map +1 -0
  241. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +49 -30
  242. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +283 -214
  243. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  244. package/es/render/contributions/render/arc3d-render.js.map +1 -1
  245. package/es/render/contributions/render/base-render.d.ts +1 -0
  246. package/es/render/contributions/render/base-render.js +21 -2
  247. package/es/render/contributions/render/base-render.js.map +1 -1
  248. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  249. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +29 -2
  250. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  251. package/es/render/contributions/render/contributions/symbol-contribution-render.d.ts +8 -1
  252. package/es/render/contributions/render/contributions/symbol-contribution-render.js +26 -0
  253. package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  254. package/es/render/contributions/render/draw-contribution.d.ts +1 -0
  255. package/es/render/contributions/render/draw-contribution.js +15 -7
  256. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  257. package/es/render/contributions/render/path-render.js.map +1 -1
  258. package/es/render/contributions/render/polygon-render.js.map +1 -1
  259. package/es/render/contributions/render/symbol-render.js +16 -13
  260. package/es/render/contributions/render/symbol-render.js.map +1 -1
  261. package/es/render/contributions/render/utils.d.ts +1 -2
  262. package/es/render/contributions/render/utils.js +0 -18
  263. package/es/render/contributions/render/utils.js.map +1 -1
  264. package/package.json +4 -4
@@ -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,15 +1,15 @@
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, IRichText, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
3
3
  import { EditModule } from './edit-module';
4
4
  type UpdateType = 'input' | 'change' | 'onfocus' | 'defocus' | '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;
12
11
  hasFormat(key: string): boolean;
12
+ _getFormat(key: string, cursorIdx: number): any;
13
13
  getFormat(key: string): any;
14
14
  getAllFormat(key: string): any;
15
15
  }
@@ -22,55 +22,74 @@ export declare class RichTextEditPlugin implements IPlugin {
22
22
  _uid: number;
23
23
  key: string;
24
24
  editing: boolean;
25
+ pointerDown: boolean;
25
26
  editLine: ILine;
26
27
  editBg: IGroup;
27
- pointerDown: boolean;
28
- lastPoint?: IPointLike;
29
- editModule: EditModule;
28
+ ticker: ITicker;
29
+ timeline: ITimeline;
30
30
  currRt: IRichText;
31
31
  curCursorIdx: number;
32
32
  selectionStartCursorIdx: number;
33
- commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;
34
- updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;
33
+ startCursorPos?: IPointLike;
34
+ editModule: EditModule;
35
+ protected commandCbs: Map<string, Array<(payload: any, p: RichTextEditPlugin) => void>>;
36
+ protected updateCbs: Array<(type: UpdateType, p: RichTextEditPlugin) => void>;
37
+ protected deltaX: number;
38
+ protected deltaY: number;
39
+ static splitText(text: string): string[];
40
+ static tryUpdateRichtext(richtext: IRichText): void;
41
+ static CreateSelection(rt: IRichText): Selection;
35
42
  constructor();
36
- getSelection(): Selection;
37
43
  formatTextCommandCb(payload: string, p: RichTextEditPlugin): void;
38
44
  dispatchCommand(command: string, payload: any): void;
39
45
  registerCommand(command: string, cb: (payload: any, p: RichTextEditPlugin) => void): void;
40
46
  registerUpdateListener(cb: (type: UpdateType, p: RichTextEditPlugin) => void): void;
41
47
  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;
48
+ handleKeyDown: (e: KeyboardEvent) => void;
49
+ handleInput: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
50
+ handleChange: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
51
+ deactivate(context: IPluginService): void;
44
52
  handleMove: (e: PointerEvent) => void;
45
- showSelection(e: PointerEvent): void;
46
- hideSelection(): void;
47
- handlePointerDown: (e: PointerEvent) => void;
48
- handlePointerUp: (e: PointerEvent) => void;
49
53
  handleEnter: (e: PointerEvent) => void;
50
54
  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
+ handlePointerDown: (e: PointerEvent) => void;
56
+ handlePointerUp: (e: PointerEvent) => void;
55
57
  onFocus(e: PointerEvent): void;
56
- protected getPointByColumnIdx(idx: number, rt: IRichText, orient: 'left' | 'right'): {
58
+ protected deFocus(e: PointerEvent): void;
59
+ protected addAnimateToLine(line: ILine): void;
60
+ tryShowSelection(e: PointerEvent): void;
61
+ hideSelection(): void;
62
+ protected getLineByPoint(cache: IRichTextFrame, p1: IPointLike): IRichTextLine;
63
+ protected getColumnAndIndexByLinePoint(lineInfo: IRichTextLine, p1: IPointLike): {
64
+ columnInfo: IRichTextParagraph | IRichTextIcon;
65
+ delta: number;
66
+ };
67
+ protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
68
+ protected isRichtext(e: PointerEvent): boolean;
69
+ protected triggerRender(): void;
70
+ protected computeGlobalDelta(cache: IRichTextFrame): void;
71
+ protected getEventPosition(e: PointerEvent): IPointLike;
72
+ protected setCursorAndTextArea(x: number, y1: number, y2: number, rt: IRichText): void;
73
+ protected computedCursorPosByEvent(e: PointerEvent, cache: IRichTextFrame): {
74
+ x: any;
75
+ y1: number;
76
+ y2: number;
77
+ cursorIndex: number;
78
+ };
79
+ protected computedCursorPosByCursorIdx(cursorIdx: number, rt: IRichText): {
80
+ x: number;
81
+ y1: number;
82
+ y2: any;
83
+ } | {
57
84
  x: any;
58
85
  y1: number;
59
86
  y2: number;
60
87
  };
61
- protected getColumnIndex(cache: IRichTextFrame, cInfo: IRichTextParagraph | IRichTextIcon): number;
62
88
  protected getColumnByIndex(cache: IRichTextFrame, index: number): {
63
89
  lineInfo: IRichTextLine;
64
90
  columnInfo: IRichTextParagraph | IRichTextIcon;
65
91
  } | 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
92
  release(): void;
93
+ getSelection(defaultAll?: boolean): Selection;
75
94
  }
76
95
  export {};