@visactor/vrender-core 0.22.0-vstory.9 → 0.22.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 (220) hide show
  1. package/cjs/allocator/bounds-allocate.js +1 -1
  2. package/cjs/allocator/canvas-allocate.js +1 -1
  3. package/cjs/allocator/constants.js +1 -1
  4. package/cjs/allocator/graphic-allocate.js +1 -1
  5. package/cjs/allocator/matrix-allocate.js +1 -1
  6. package/cjs/animate/animate.js +1 -1
  7. package/cjs/animate/animate.js.map +1 -1
  8. package/cjs/animate/custom-animate.js +4 -2
  9. package/cjs/animate/custom-animate.js.map +1 -1
  10. package/cjs/animate/index.js +1 -2
  11. package/cjs/color-string/store.js +2 -1
  12. package/cjs/common/custom-path2d.js +8 -6
  13. package/cjs/common/custom-path2d.js.map +1 -1
  14. package/cjs/common/enums.js +1 -2
  15. package/cjs/common/inversify/annotation/optional.d.ts +2 -0
  16. package/cjs/common/inversify/annotation/optional.js +14 -0
  17. package/cjs/common/inversify/annotation/optional.js.map +1 -0
  18. package/cjs/common/inversify/container.js +9 -6
  19. package/cjs/common/inversify/container.js.map +1 -1
  20. package/cjs/common/render-area.d.ts +0 -4
  21. package/cjs/common/render-area.js +17 -76
  22. package/cjs/common/render-area.js.map +1 -1
  23. package/cjs/common/render-curve.d.ts +1 -1
  24. package/cjs/common/render-curve.js.map +1 -1
  25. package/cjs/common/segment/step.js +1 -1
  26. package/cjs/common/segment/step.js.map +1 -1
  27. package/cjs/common/store.js +1 -1
  28. package/cjs/common/text.js +1 -2
  29. package/cjs/common/utils.js +1 -1
  30. package/cjs/core/application.js +1 -1
  31. package/cjs/core/camera.js +1 -1
  32. package/cjs/core/contributions/textMeasure/AtextMeasure.js +10 -0
  33. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  34. package/cjs/core/global.d.ts +3 -0
  35. package/cjs/core/global.js +7 -1
  36. package/cjs/core/global.js.map +1 -1
  37. package/cjs/graphic/bounds.d.ts +2 -2
  38. package/cjs/graphic/bounds.js.map +1 -1
  39. package/cjs/graphic/config.js +4 -1
  40. package/cjs/graphic/config.js.map +1 -1
  41. package/cjs/graphic/graphic.d.ts +1 -1
  42. package/cjs/graphic/graphic.js +7 -7
  43. package/cjs/graphic/graphic.js.map +1 -1
  44. package/cjs/graphic/group.d.ts +1 -0
  45. package/cjs/graphic/group.js +5 -0
  46. package/cjs/graphic/group.js.map +1 -1
  47. package/cjs/graphic/line.js +2 -2
  48. package/cjs/graphic/line.js.map +1 -1
  49. package/cjs/graphic/richtext/line.js +2 -2
  50. package/cjs/graphic/richtext/line.js.map +1 -1
  51. package/cjs/graphic/richtext/paragraph.d.ts +2 -1
  52. package/cjs/graphic/richtext/paragraph.js +19 -17
  53. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  54. package/cjs/graphic/richtext/utils.d.ts +1 -1
  55. package/cjs/graphic/richtext/utils.js +6 -7
  56. package/cjs/graphic/richtext/utils.js.map +1 -1
  57. package/cjs/graphic/richtext.d.ts +0 -1
  58. package/cjs/graphic/richtext.js +34 -19
  59. package/cjs/graphic/richtext.js.map +1 -1
  60. package/cjs/graphic/symbol.d.ts +1 -0
  61. package/cjs/graphic/symbol.js +11 -0
  62. package/cjs/graphic/symbol.js.map +1 -1
  63. package/cjs/interface/color.js.map +1 -1
  64. package/cjs/interface/global.d.ts +1 -0
  65. package/cjs/interface/global.js.map +1 -1
  66. package/cjs/interface/graphic/arc.js.map +1 -1
  67. package/cjs/interface/graphic/area.js.map +1 -1
  68. package/cjs/interface/graphic/circle.js.map +1 -1
  69. package/cjs/interface/graphic/group.js.map +1 -1
  70. package/cjs/interface/graphic/image.js.map +1 -1
  71. package/cjs/interface/graphic/line.js.map +1 -1
  72. package/cjs/interface/graphic/polygon.js.map +1 -1
  73. package/cjs/interface/graphic/rect.js.map +1 -1
  74. package/cjs/interface/graphic/richText.d.ts +6 -1
  75. package/cjs/interface/graphic/richText.js.map +1 -1
  76. package/cjs/interface/graphic/symbol.d.ts +1 -0
  77. package/cjs/interface/graphic/symbol.js.map +1 -1
  78. package/cjs/interface/graphic/text.js.map +1 -1
  79. package/cjs/interface/graphic.d.ts +3 -2
  80. package/cjs/interface/graphic.js.map +1 -1
  81. package/cjs/plugins/builtin-plugin/edit-module.js +13 -7
  82. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  83. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +11 -5
  84. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +209 -158
  85. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  86. package/cjs/render/contributions/render/area-render.d.ts +1 -1
  87. package/cjs/render/contributions/render/area-render.js +16 -36
  88. package/cjs/render/contributions/render/area-render.js.map +1 -1
  89. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  90. package/cjs/render/contributions/render/contributions/base-contribution-render.js +7 -3
  91. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  92. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  93. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js +20 -3
  94. package/cjs/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  95. package/cjs/render/contributions/render/contributions/group-contribution-render.js +2 -1
  96. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  97. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  98. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  99. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  100. package/cjs/render/contributions/render/contributions/text-contribution-render.js +3 -2
  101. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  102. package/cjs/render/contributions/render/draw-contribution.js +1 -0
  103. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  104. package/cjs/render/contributions/render/image-render.js.map +1 -1
  105. package/cjs/render/contributions/render/line-render.js +9 -31
  106. package/cjs/render/contributions/render/line-render.js.map +1 -1
  107. package/cjs/resource-loader/loader.d.ts +2 -2
  108. package/cjs/resource-loader/loader.js +1 -1
  109. package/cjs/resource-loader/loader.js.map +1 -1
  110. package/dist/index.es.js +445 -476
  111. package/es/allocator/bounds-allocate.js +1 -1
  112. package/es/allocator/canvas-allocate.js +1 -1
  113. package/es/allocator/constants.js +1 -1
  114. package/es/allocator/graphic-allocate.js +1 -1
  115. package/es/allocator/matrix-allocate.js +1 -1
  116. package/es/animate/animate.js +4 -3
  117. package/es/animate/animate.js.map +1 -1
  118. package/es/animate/custom-animate.js +4 -2
  119. package/es/animate/custom-animate.js.map +1 -1
  120. package/es/animate/index.js +1 -2
  121. package/es/color-string/store.js +2 -1
  122. package/es/common/custom-path2d.js +8 -6
  123. package/es/common/custom-path2d.js.map +1 -1
  124. package/es/common/enums.js +1 -2
  125. package/es/common/inversify/annotation/optional.d.ts +2 -0
  126. package/es/common/inversify/annotation/optional.js +12 -0
  127. package/es/common/inversify/annotation/optional.js.map +1 -0
  128. package/es/common/inversify/container.js +9 -6
  129. package/es/common/inversify/container.js.map +1 -1
  130. package/es/common/render-area.d.ts +0 -4
  131. package/es/common/render-area.js +18 -77
  132. package/es/common/render-area.js.map +1 -1
  133. package/es/common/render-curve.d.ts +1 -1
  134. package/es/common/render-curve.js.map +1 -1
  135. package/es/common/segment/step.js +1 -1
  136. package/es/common/segment/step.js.map +1 -1
  137. package/es/common/store.js +1 -1
  138. package/es/common/text.js +1 -2
  139. package/es/common/utils.js +1 -1
  140. package/es/core/application.js +1 -1
  141. package/es/core/camera.js +1 -1
  142. package/es/core/contributions/textMeasure/AtextMeasure.js +10 -0
  143. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  144. package/es/core/global.d.ts +3 -0
  145. package/es/core/global.js +8 -1
  146. package/es/core/global.js.map +1 -1
  147. package/es/graphic/bounds.d.ts +2 -2
  148. package/es/graphic/bounds.js.map +1 -1
  149. package/es/graphic/config.js +4 -1
  150. package/es/graphic/config.js.map +1 -1
  151. package/es/graphic/graphic.d.ts +1 -1
  152. package/es/graphic/graphic.js +9 -9
  153. package/es/graphic/graphic.js.map +1 -1
  154. package/es/graphic/group.d.ts +1 -0
  155. package/es/graphic/group.js +5 -0
  156. package/es/graphic/group.js.map +1 -1
  157. package/es/graphic/line.js +2 -2
  158. package/es/graphic/line.js.map +1 -1
  159. package/es/graphic/richtext/line.js +2 -2
  160. package/es/graphic/richtext/line.js.map +1 -1
  161. package/es/graphic/richtext/paragraph.d.ts +2 -1
  162. package/es/graphic/richtext/paragraph.js +19 -17
  163. package/es/graphic/richtext/paragraph.js.map +1 -1
  164. package/es/graphic/richtext/utils.d.ts +1 -1
  165. package/es/graphic/richtext/utils.js +6 -7
  166. package/es/graphic/richtext/utils.js.map +1 -1
  167. package/es/graphic/richtext.d.ts +0 -1
  168. package/es/graphic/richtext.js +31 -18
  169. package/es/graphic/richtext.js.map +1 -1
  170. package/es/graphic/symbol.d.ts +1 -0
  171. package/es/graphic/symbol.js +11 -0
  172. package/es/graphic/symbol.js.map +1 -1
  173. package/es/interface/color.js.map +1 -1
  174. package/es/interface/global.d.ts +1 -0
  175. package/es/interface/global.js.map +1 -1
  176. package/es/interface/graphic/arc.js.map +1 -1
  177. package/es/interface/graphic/area.js.map +1 -1
  178. package/es/interface/graphic/circle.js.map +1 -1
  179. package/es/interface/graphic/group.js.map +1 -1
  180. package/es/interface/graphic/image.js.map +1 -1
  181. package/es/interface/graphic/line.js.map +1 -1
  182. package/es/interface/graphic/polygon.js.map +1 -1
  183. package/es/interface/graphic/rect.js.map +1 -1
  184. package/es/interface/graphic/richText.d.ts +6 -1
  185. package/es/interface/graphic/richText.js.map +1 -1
  186. package/es/interface/graphic/symbol.d.ts +1 -0
  187. package/es/interface/graphic/symbol.js.map +1 -1
  188. package/es/interface/graphic/text.js.map +1 -1
  189. package/es/interface/graphic.d.ts +3 -2
  190. package/es/interface/graphic.js.map +1 -1
  191. package/es/plugins/builtin-plugin/edit-module.js +13 -7
  192. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  193. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +11 -5
  194. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +209 -158
  195. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  196. package/es/render/contributions/render/area-render.d.ts +1 -1
  197. package/es/render/contributions/render/area-render.js +16 -36
  198. package/es/render/contributions/render/area-render.js.map +1 -1
  199. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  200. package/es/render/contributions/render/contributions/base-contribution-render.js +7 -3
  201. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  202. package/es/render/contributions/render/contributions/base-texture-contribution-render.d.ts +2 -1
  203. package/es/render/contributions/render/contributions/base-texture-contribution-render.js +22 -2
  204. package/es/render/contributions/render/contributions/base-texture-contribution-render.js.map +1 -1
  205. package/es/render/contributions/render/contributions/group-contribution-render.js +2 -1
  206. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  207. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  208. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  209. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  210. package/es/render/contributions/render/contributions/text-contribution-render.js +3 -2
  211. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  212. package/es/render/contributions/render/draw-contribution.js +3 -2
  213. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  214. package/es/render/contributions/render/image-render.js.map +1 -1
  215. package/es/render/contributions/render/line-render.js +9 -31
  216. package/es/render/contributions/render/line-render.js.map +1 -1
  217. package/es/resource-loader/loader.d.ts +2 -2
  218. package/es/resource-loader/loader.js +1 -1
  219. package/es/resource-loader/loader.js.map +1 -1
  220. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
1
  import type { IPointLike } from '@visactor/vutils';
2
- import type { IGroup, ILine, IPlugin, IPluginService, IRect, IRichText, IRichTextCharacter, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
2
+ import type { IGraphic, IGroup, ILine, IPlugin, IPluginService, IRect, IRichText, IRichTextCharacter, IRichTextFrame, IRichTextIcon, IRichTextLine, IRichTextParagraph, ITicker, ITimeline } from '../../interface';
3
3
  import { EditModule } from './edit-module';
4
4
  type UpdateType = 'input' | 'change' | 'onfocus' | 'beforeOnfocus' | 'defocus' | 'beforeDefocus' | 'selection' | 'dispatch';
5
5
  declare class Selection {
@@ -11,8 +11,8 @@ declare class Selection {
11
11
  getSelectionPureText(): string;
12
12
  hasFormat(key: string): boolean;
13
13
  _getFormat(key: string, cursorIdx: number): any;
14
- getFormat(key: string): any;
15
- getAllFormat(key: string): any;
14
+ getFormat(key: string, supportOutAttr?: boolean): any;
15
+ getAllFormat(key: string, supportOutAttr?: boolean): any;
16
16
  }
17
17
  export declare const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
18
18
  export declare const FORMAT_ALL_TEXT_COMMAND = "FORMAT_ALL_TEXT_COMMAND";
@@ -56,12 +56,14 @@ export declare class RichTextEditPlugin implements IPlugin {
56
56
  copyToClipboard(e: KeyboardEvent): boolean;
57
57
  selectionRange(startIdx: number, endIdx: number): void;
58
58
  selectionRangeByCursorIdx(startCursorIdx: number, endCursorIdx: number, cache: IRichTextFrame): void;
59
- fullSelection(e: KeyboardEvent): boolean;
60
- directKey(e: KeyboardEvent): boolean;
59
+ fullSelection(): void;
60
+ protected fullSelectionKeyHandler(e: KeyboardEvent): boolean;
61
+ directKeyHandler(e: KeyboardEvent): boolean;
61
62
  handleKeyDown: (e: KeyboardEvent) => void;
62
63
  handleInput: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
63
64
  handleChange: (text: string, isComposing: boolean, cursorIdx: number, rt: IRichText) => void;
64
65
  tryShowShadowPlaceholder(): void;
66
+ getRichTextAABBBounds(rt: IRichText): any;
65
67
  tryShowInputBounds(): void;
66
68
  trySyncPlaceholderToTextConfig(): void;
67
69
  handleFocusIn: () => never;
@@ -73,7 +75,11 @@ export declare class RichTextEditPlugin implements IPlugin {
73
75
  handlePointerDown: (e: PointerEvent) => void;
74
76
  handlePointerUp: (e: PointerEvent) => void;
75
77
  handleDBLClick: (e: PointerEvent) => void;
78
+ protected stopPropagation(e: Event): void;
79
+ addEditLineOrBgOrBounds(graphic: IGraphic, shadowRoot: IGroup): void;
80
+ removeEditLineOrBgOrBounds(graphic: IGraphic, shadowRoot: IGroup): void;
76
81
  onFocus(e: PointerEvent, data?: any): void;
82
+ offsetShadowRoot(rt?: IRichText): void;
77
83
  protected offsetLineBgAndShadowBounds(): void;
78
84
  protected deFocus(trulyDeFocus?: boolean): void;
79
85
  protected addAnimateToLine(line: ILine): void;
@@ -35,14 +35,15 @@ class Selection {
35
35
  for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
36
36
  return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
37
37
  }
38
- getFormat(key) {
39
- return this.getAllFormat(key)[0];
38
+ getFormat(key, supportOutAttr = !1) {
39
+ return this.getAllFormat(key, supportOutAttr)[0];
40
40
  }
41
- getAllFormat(key) {
41
+ getAllFormat(key, supportOutAttr = !1) {
42
+ var _a, _b, _c, _d;
42
43
  const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
43
- if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
44
+ if (minCursorIdx === maxCursorIdx) return supportOutAttr ? [ null !== (_a = this._getFormat(key, minCursorIdx)) && void 0 !== _a ? _a : (null === (_b = this.rt) || void 0 === _b ? void 0 : _b.attribute)[key] ] : [ this._getFormat(key, minCursorIdx) ];
44
45
  for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
45
- const val = this._getFormat(key, i);
46
+ const val = supportOutAttr ? null !== (_c = this._getFormat(key, i)) && void 0 !== _c ? _c : (null === (_d = this.rt) || void 0 === _d ? void 0 : _d.attribute)[key] : this._getFormat(key, i);
46
47
  val && valSet.add(val);
47
48
  }
48
49
  return Array.from(valSet.values());
@@ -85,7 +86,7 @@ class RichTextEditPlugin {
85
86
  const config = rt.attribute.textConfig;
86
87
  this._formatTextCommand(payload, config, rt);
87
88
  }, this.handleKeyDown = e => {
88
- this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
89
+ this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelectionKeyHandler(e) || this.directKeyHandler(e));
89
90
  }, this.handleInput = (text, isComposing, cursorIdx, rt) => {
90
91
  this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
91
92
  this.updateCbs.forEach((cb => cb("input", this))));
@@ -101,7 +102,9 @@ class RichTextEditPlugin {
101
102
  throw new Error("不会走到这里 handleFocusOut");
102
103
  }, this.handleMove = e => {
103
104
  this.currRt && !this.currRt.attribute.editable && this.deFocus(!0), this.isEditableRichtext(e) ? (this.handleEnter(),
104
- e.target.once("pointerleave", this.handleLeave), this.tryShowSelection(e, !1)) : this.handleLeave();
105
+ e.target.once("pointerleave", this.handleLeave, {
106
+ capture: !0
107
+ }), this.tryShowSelection(e, !1)) : this.handleLeave();
105
108
  }, this.handleEnter = () => {
106
109
  this.editing = !0, this.pluginService.stage.setCursor("text");
107
110
  }, this.handleLeave = () => {
@@ -145,10 +148,17 @@ class RichTextEditPlugin {
145
148
  idx > -1 && cbs.splice(idx, 1);
146
149
  }
147
150
  activate(context) {
148
- this.pluginService = context, this.editModule = new edit_module_1.EditModule, context.stage.on("pointermove", this.handleMove),
149
- context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
150
- context.stage.on("pointerleave", this.handlePointerUp), context.stage.on("dblclick", this.handleDBLClick),
151
- application_1.application.global.addEventListener("keydown", this.handleKeyDown),
151
+ this.pluginService = context, this.editModule = new edit_module_1.EditModule, context.stage.on("pointermove", this.handleMove, {
152
+ capture: !0
153
+ }), context.stage.on("pointerdown", this.handlePointerDown, {
154
+ capture: !0
155
+ }), context.stage.on("pointerup", this.handlePointerUp, {
156
+ capture: !0
157
+ }), context.stage.on("pointerleave", this.handlePointerUp, {
158
+ capture: !0
159
+ }), context.stage.on("dblclick", this.handleDBLClick, {
160
+ capture: !0
161
+ }), application_1.application.global.addEventListener("keydown", this.handleKeyDown),
152
162
  this.editModule.onInput(this.handleInput), this.editModule.onChange(this.handleChange),
153
163
  this.editModule.onFocusOut(this.handleFocusOut);
154
164
  }
@@ -179,21 +189,21 @@ class RichTextEditPlugin {
179
189
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
180
190
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
181
191
  }
182
- fullSelection(e) {
183
- if (application_1.application.global.isMacOS() && e.metaKey && "a" === e.key || !application_1.application.global.isMacOS() && e.ctrlKey && "a" === e.key) {
184
- const currRt = this.currRt;
185
- if (!currRt) return;
186
- const cache = currRt.getFrameCache();
187
- if (!cache) return;
188
- const {lines: lines} = cache;
189
- if (0 === lines.length) return;
190
- if (!lines[0].paragraphs || 0 === lines[0].paragraphs.length) return;
191
- const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
192
- return this.selectionRange(-.1, totalCursorCount + .1), e.preventDefault(), !0;
193
- }
194
- return !1;
192
+ fullSelection() {
193
+ const currRt = this.currRt;
194
+ if (!currRt) return;
195
+ const cache = currRt.getFrameCache();
196
+ if (!cache) return;
197
+ const {lines: lines} = cache;
198
+ if (!lines.length || !lines[0].paragraphs.length) return;
199
+ const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
200
+ this.selectionRange(-.1, totalCursorCount + .1);
201
+ }
202
+ fullSelectionKeyHandler(e) {
203
+ return !!(application_1.application.global.isMacOS() && e.metaKey && "a" === e.key || !application_1.application.global.isMacOS() && e.ctrlKey && "a" === e.key) && (this.fullSelection(),
204
+ e.preventDefault(), !0);
195
205
  }
196
- directKey(e) {
206
+ directKeyHandler(e) {
197
207
  if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
198
208
  const cache = this.currRt.getFrameCache();
199
209
  if (!cache) return !1;
@@ -202,7 +212,8 @@ class RichTextEditPlugin {
202
212
  const {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, Math.round(this.curCursorIdx)), {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
203
213
  if (x) {
204
214
  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,
205
- this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
215
+ this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1),
216
+ this.selectionStartCursorIdx = this.curCursorIdx;
206
217
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
207
218
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
208
219
  }
@@ -233,7 +244,7 @@ class RichTextEditPlugin {
233
244
  const placeholder = shadowRoot.getElementsByType("richtext")[0];
234
245
  placeholder && shadowRoot.removeChild(placeholder);
235
246
  }
236
- const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
247
+ const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
237
248
  if (textConfig && textConfig.length) return;
238
249
  if (!editOptions || !editOptions.placeholder) return;
239
250
  const {placeholder: placeholder, placeholderColor: placeholderColor = "rgba(0, 0, 0, 0.6)", placeholderFontFamily: placeholderFontFamily, placeholderFontSize: placeholderFontSize} = editOptions, shadow = this.getShadow(this.currRt), textConfigItem = Object.assign(Object.assign({}, (0,
@@ -245,41 +256,45 @@ class RichTextEditPlugin {
245
256
  graphic_1.createRichText)(Object.assign(Object.assign({}, this.currRt.attribute), {
246
257
  x: 0,
247
258
  y: 0,
248
- pickable: !1,
249
- editable: !1,
250
- editOptions: null,
259
+ dx: -this.deltaX,
260
+ dy: -this.deltaY,
251
261
  angle: 0,
252
- _debug_bounds: !1,
253
262
  textConfig: [ textConfigItem ]
254
263
  })), shadow.add(this.shadowPlaceHolder);
255
264
  }
265
+ getRichTextAABBBounds(rt) {
266
+ const {attribute: attribute} = rt;
267
+ return attribute.textConfig.length ? rt.AABBBounds : (0, graphic_1.getRichTextBounds)(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), {
268
+ x: attribute.x,
269
+ y: attribute.y,
270
+ textAlign: attribute.textAlign,
271
+ boundsMode: "accurate"
272
+ }));
273
+ }
256
274
  tryShowInputBounds() {
257
275
  if (!this.currRt || !this.focusing) return;
258
276
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
259
277
  if (!editOptions || !boundsStrokeWhenInput) return;
260
- const {attribute: attribute} = this.currRt;
261
- let b = this.currRt.AABBBounds, h = b.height();
262
- if (!attribute.textConfig.length && this.editLine) {
263
- const {points: points} = this.editLine.attribute;
264
- h = points[1].y - points[0].y, b = (0, graphic_1.getRichTextBounds)(Object.assign({}, this.shadowPlaceHolder.attribute));
265
- }
278
+ const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
266
279
  this.shadowBounds = this.shadowBounds || (0, graphic_1.createRect)({}), this.shadowBounds.setAttributes({
267
280
  x: 0,
268
281
  y: 0,
269
- width: b.width(),
270
- height: h,
282
+ width: width,
283
+ height: height,
271
284
  fill: !1,
272
285
  stroke: boundsStrokeWhenInput,
273
286
  lineWidth: 1,
274
287
  zIndex: -1
275
288
  });
276
- this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
289
+ const shadow = this.getShadow(this.currRt);
290
+ this.addEditLineOrBgOrBounds(this.shadowBounds, shadow), this.offsetLineBgAndShadowBounds(),
291
+ this.offsetShadowRoot();
277
292
  }
278
293
  trySyncPlaceholderToTextConfig() {
279
294
  if (!this.currRt) return;
280
295
  const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
281
296
  if (textConfig && textConfig.length) return;
282
- if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) return;
297
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
283
298
  const {placeholder: placeholder} = editOptions;
284
299
  this.currRt.setAttributes({
285
300
  textConfig: [ Object.assign({
@@ -288,59 +303,95 @@ class RichTextEditPlugin {
288
303
  });
289
304
  }
290
305
  deactivate(context) {
291
- context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
292
- context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
293
- context.stage.off("dblclick", this.handleDBLClick), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
306
+ context.stage.off("pointermove", this.handleMove, {
307
+ capture: !0
308
+ }), context.stage.off("pointerdown", this.handlePointerDown, {
309
+ capture: !0
310
+ }), context.stage.off("pointerup", this.handlePointerUp, {
311
+ capture: !0
312
+ }), context.stage.off("pointerleave", this.handlePointerUp, {
313
+ capture: !0
314
+ }), context.stage.off("dblclick", this.handleDBLClick, {
315
+ capture: !0
316
+ }), application_1.application.global.addEventListener("keydown", this.handleKeyDown);
317
+ }
318
+ stopPropagation(e) {
319
+ e.stopPropagation();
320
+ }
321
+ addEditLineOrBgOrBounds(graphic, shadowRoot) {
322
+ let group = shadowRoot.getElementById("emptyBoundsContainer");
323
+ group || (group = (0, graphic_1.createGroup)({
324
+ x: 0,
325
+ y: 0,
326
+ width: 0,
327
+ height: 0,
328
+ boundsMode: "empty"
329
+ }), group.id = "emptyBoundsContainer", shadowRoot.add(group)), group.add(graphic);
330
+ }
331
+ removeEditLineOrBgOrBounds(graphic, shadowRoot) {
332
+ const group = shadowRoot.getElementById("emptyBoundsContainer");
333
+ group && group.removeChild(graphic);
294
334
  }
295
335
  onFocus(e, data) {
296
336
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
297
- this.focusing = !0;
337
+ this.focusing = !0, this.editing = !0;
298
338
  const target = e.target;
299
339
  if (!target || "richtext" !== target.type) return;
300
340
  this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
301
341
  const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
302
- if (cache) {
303
- if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
304
- shadowRootIdx: 1,
305
- pickable: !1,
306
- x: this.deltaX,
307
- y: this.deltaY
308
- }), !this.editLine) {
309
- const line = (0, graphic_1.createLine)({
310
- x: 0,
311
- y: 0,
312
- lineWidth: 1,
313
- stroke: "black"
314
- });
315
- this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
316
- const g = (0, graphic_1.createGroup)({
317
- x: 0,
318
- y: 0,
319
- width: 0,
320
- height: 0
321
- });
322
- this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
323
- }
324
- if (data = data || this.computedCursorPosByEvent(e, cache)) {
325
- const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
326
- this.startCursorPos = {
327
- x: x,
328
- y: (y1 + y2) / 2
329
- }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
330
- this.setCursorAndTextArea(x, y1, y2, target);
331
- } else {
332
- const x = 0, y1 = 0, y2 = (0, graphic_1.getRichTextBounds)(Object.assign(Object.assign({}, target.attribute), {
333
- textConfig: [ {
334
- text: "a"
335
- } ]
336
- })).height();
337
- this.startCursorPos = {
338
- x: x,
339
- y: (y1 + y2) / 2
340
- }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
341
- }
342
- this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
342
+ if (!cache) return;
343
+ const {editOptions: editOptions = {}} = this.currRt.attribute;
344
+ if (editOptions.stopPropagation && target.addEventListener("*", this.stopPropagation),
345
+ this.offsetShadowRoot(target), !this.editLine) {
346
+ const line = (0, graphic_1.createLine)({
347
+ x: 0,
348
+ y: 0,
349
+ lineWidth: 1,
350
+ stroke: "black"
351
+ });
352
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
353
+ const g = (0, graphic_1.createGroup)({
354
+ x: 0,
355
+ y: 0,
356
+ width: 0,
357
+ height: 0
358
+ });
359
+ this.editBg = g, this.addEditLineOrBgOrBounds(this.editLine, shadowRoot), this.addEditLineOrBgOrBounds(this.editBg, shadowRoot);
343
360
  }
361
+ if (data = data || this.computedCursorPosByEvent(e, cache)) {
362
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
363
+ this.startCursorPos = {
364
+ x: x,
365
+ y: (y1 + y2) / 2
366
+ }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
367
+ this.setCursorAndTextArea(x, y1, y2, target);
368
+ } else {
369
+ const x = 0, y1 = 0, y2 = (0, graphic_1.getRichTextBounds)(Object.assign(Object.assign({}, target.attribute), {
370
+ textConfig: [ {
371
+ text: "a"
372
+ } ]
373
+ })).height();
374
+ this.startCursorPos = {
375
+ x: x,
376
+ y: (y1 + y2) / 2
377
+ }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
378
+ }
379
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
380
+ }
381
+ offsetShadowRoot(rt) {
382
+ if (!(rt = rt || this.currRt)) return;
383
+ const shadowRoot = this.getShadow(rt);
384
+ if (!shadowRoot) return;
385
+ const cache = rt.getFrameCache();
386
+ cache && (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
387
+ shadowRootIdx: 1,
388
+ pickable: !1,
389
+ x: this.deltaX,
390
+ y: this.deltaY
391
+ }), this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({
392
+ dx: -this.deltaX,
393
+ dy: -this.deltaY
394
+ }));
344
395
  }
345
396
  offsetLineBgAndShadowBounds() {
346
397
  const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
@@ -359,27 +410,27 @@ class RichTextEditPlugin {
359
410
  });
360
411
  }
361
412
  deFocus(trulyDeFocus = !1) {
362
- const target = this.currRt;
363
- if (!target) return;
364
- this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
413
+ this.editing = !1, this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
365
414
  trulyDeFocus: trulyDeFocus
366
- }))), trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
415
+ })));
367
416
  const currRt = this.currRt;
368
- this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
369
- this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
370
- this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
417
+ if (!currRt) return;
418
+ const {editOptions: editOptions = {}} = currRt.attribute;
419
+ editOptions.stopPropagation && currRt.removeEventListener("*", this.stopPropagation),
420
+ trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), currRt.detachShadow()),
421
+ this.currRt = null;
422
+ const shadowRoot = this.getShadow(currRt);
423
+ this.editLine && (this.removeEditLineOrBgOrBounds(this.editLine, shadowRoot), this.editLine.release(),
424
+ this.editLine = null, this.removeEditLineOrBgOrBounds(this.editBg, shadowRoot),
425
+ this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.removeEditLineOrBgOrBounds(this.shadowBounds, shadowRoot),
371
426
  this.shadowBounds.release(), this.shadowBounds = null), this.shadowPlaceHolder && (this.shadowPlaceHolder.parent && this.shadowPlaceHolder.parent.removeChild(this.shadowPlaceHolder),
372
- this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1;
373
- const textConfig = currRt.attribute.textConfig;
374
- let lastConfig = textConfig[textConfig.length - 1], cleared = !1;
375
- for (;lastConfig && "\n" === lastConfig.text; ) textConfig.pop(), lastConfig = textConfig[textConfig.length - 1],
376
- cleared = !0;
377
- cleared && currRt.setAttributes({
378
- textConfig: textConfig
379
- }), currRt.removeEventListener("pointerleave", this.handleLeave);
427
+ this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1,
428
+ currRt.removeEventListener("pointerleave", this.handleLeave);
380
429
  }
381
430
  addAnimateToLine(line) {
382
- line.animates && line.animates.forEach((animate => {
431
+ line.setAttributes({
432
+ opacity: 1
433
+ }), line.animates && line.animates.forEach((animate => {
383
434
  animate.stop(), animate.release();
384
435
  }));
385
436
  line.animate({
@@ -417,63 +468,61 @@ class RichTextEditPlugin {
417
468
  x: currCursorData.x,
418
469
  y: (currCursorData.y1 + currCursorData.y2) / 2
419
470
  }, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
420
- if (line0Info && line1Info) {
421
- if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
422
- [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
423
- x: startCursorPos.x,
471
+ if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
472
+ [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
473
+ x: startCursorPos.x,
474
+ y: line0Info.top,
475
+ width: endCursorPos.x - startCursorPos.x,
476
+ height: line0Info.height,
477
+ fill: "#336df4",
478
+ fillOpacity: .2
479
+ }); else {
480
+ this.editBg.setAttributes({
481
+ x: 0,
424
482
  y: line0Info.top,
425
- width: endCursorPos.x - startCursorPos.x,
426
- height: line0Info.height,
427
- fill: "#336df4",
428
- fillOpacity: .2
429
- }); else {
430
- this.editBg.setAttributes({
431
- x: 0,
432
- y: line0Info.top,
433
- width: 0,
434
- height: 0
435
- });
436
- const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
437
- let y = 0;
438
- for (let i = startIdx; i <= endIdx; i++) {
439
- const line = cache.lines[i];
440
- if (i === startIdx) {
441
- const p = line.paragraphs[line.paragraphs.length - 1];
442
- this.editBg.add((0, graphic_1.createRect)({
443
- x: startCursorPos.x,
444
- y: y,
445
- width: p.left + p.width - startCursorPos.x,
446
- height: line.height,
447
- fill: "#336df4",
448
- fillOpacity: .2
449
- }));
450
- } else if (i === endIdx) {
451
- const p = line.paragraphs[0];
452
- this.editBg.add((0, graphic_1.createRect)({
453
- x: p.left,
454
- y: y,
455
- width: endCursorPos.x - p.left,
456
- height: line.height,
457
- fill: "#336df4",
458
- fillOpacity: .2
459
- }));
460
- } else {
461
- const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
462
- this.editBg.add((0, graphic_1.createRect)({
463
- x: p0.left,
464
- y: y,
465
- width: p1.left + p1.width - p0.left,
466
- height: line.height,
467
- fill: "#336df4",
468
- fillOpacity: .2
469
- }));
470
- }
471
- y += line.height;
483
+ width: 0,
484
+ height: 0
485
+ });
486
+ const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
487
+ let y = 0;
488
+ for (let i = startIdx; i <= endIdx; i++) {
489
+ const line = cache.lines[i];
490
+ if (i === startIdx) {
491
+ const p = line.paragraphs[line.paragraphs.length - 1];
492
+ this.editBg.add((0, graphic_1.createRect)({
493
+ x: startCursorPos.x,
494
+ y: y,
495
+ width: p.left + p.width - startCursorPos.x,
496
+ height: line.height,
497
+ fill: "#336df4",
498
+ fillOpacity: .2
499
+ }));
500
+ } else if (i === endIdx) {
501
+ const p = line.paragraphs[0];
502
+ this.editBg.add((0, graphic_1.createRect)({
503
+ x: p.left,
504
+ y: y,
505
+ width: endCursorPos.x - p.left,
506
+ height: line.height,
507
+ fill: "#336df4",
508
+ fillOpacity: .2
509
+ }));
510
+ } else {
511
+ const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
512
+ this.editBg.add((0, graphic_1.createRect)({
513
+ x: p0.left,
514
+ y: y,
515
+ width: p1.left + p1.width - p0.left,
516
+ height: line.height,
517
+ fill: "#336df4",
518
+ fillOpacity: .2
519
+ }));
472
520
  }
521
+ y += line.height;
473
522
  }
474
- this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
475
- this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
476
523
  }
524
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
525
+ this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
477
526
  }
478
527
  hideSelection() {
479
528
  this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
@@ -483,7 +532,8 @@ class RichTextEditPlugin {
483
532
  getShadow(rt) {
484
533
  const sr = rt.shadowRoot || rt.attachShadow();
485
534
  return sr.setAttributes({
486
- boundsMode: "empty"
535
+ width: 1,
536
+ height: 1
487
537
  }), sr;
488
538
  }
489
539
  getLineByPoint(cache, p1) {
@@ -526,7 +576,7 @@ class RichTextEditPlugin {
526
576
  this.pluginService.stage.renderNextFrame();
527
577
  }
528
578
  computeGlobalDelta(cache) {
529
- this.deltaX = 0, this.deltaY = 0;
579
+ this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
530
580
  const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
531
581
  "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
532
582
  "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
@@ -565,7 +615,8 @@ class RichTextEditPlugin {
565
615
  y: y1
566
616
  }, out);
567
617
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
568
- out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
618
+ out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.offsetShadowRoot(),
619
+ this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
569
620
  }
570
621
  computedCursorPosByEvent(e, cache) {
571
622
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);