@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;
@@ -40,14 +40,15 @@ class Selection {
40
40
  for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
41
41
  return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
42
42
  }
43
- getFormat(key) {
44
- return this.getAllFormat(key)[0];
43
+ getFormat(key, supportOutAttr = !1) {
44
+ return this.getAllFormat(key, supportOutAttr)[0];
45
45
  }
46
- getAllFormat(key) {
46
+ getAllFormat(key, supportOutAttr = !1) {
47
+ var _a, _b, _c, _d;
47
48
  const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
48
- if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
49
+ 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) ];
49
50
  for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
50
- const val = this._getFormat(key, i);
51
+ 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);
51
52
  val && valSet.add(val);
52
53
  }
53
54
  return Array.from(valSet.values());
@@ -91,7 +92,7 @@ export class RichTextEditPlugin {
91
92
  const config = rt.attribute.textConfig;
92
93
  this._formatTextCommand(payload, config, rt);
93
94
  }, this.handleKeyDown = e => {
94
- this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
95
+ this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelectionKeyHandler(e) || this.directKeyHandler(e));
95
96
  }, this.handleInput = (text, isComposing, cursorIdx, rt) => {
96
97
  this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
97
98
  this.updateCbs.forEach((cb => cb("input", this))));
@@ -107,7 +108,9 @@ export class RichTextEditPlugin {
107
108
  throw new Error("不会走到这里 handleFocusOut");
108
109
  }, this.handleMove = e => {
109
110
  this.currRt && !this.currRt.attribute.editable && this.deFocus(!0), this.isEditableRichtext(e) ? (this.handleEnter(),
110
- e.target.once("pointerleave", this.handleLeave), this.tryShowSelection(e, !1)) : this.handleLeave();
111
+ e.target.once("pointerleave", this.handleLeave, {
112
+ capture: !0
113
+ }), this.tryShowSelection(e, !1)) : this.handleLeave();
111
114
  }, this.handleEnter = () => {
112
115
  this.editing = !0, this.pluginService.stage.setCursor("text");
113
116
  }, this.handleLeave = () => {
@@ -150,10 +153,17 @@ export class RichTextEditPlugin {
150
153
  idx > -1 && cbs.splice(idx, 1);
151
154
  }
152
155
  activate(context) {
153
- this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove),
154
- context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
155
- context.stage.on("pointerleave", this.handlePointerUp), context.stage.on("dblclick", this.handleDBLClick),
156
- application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
156
+ this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove, {
157
+ capture: !0
158
+ }), context.stage.on("pointerdown", this.handlePointerDown, {
159
+ capture: !0
160
+ }), context.stage.on("pointerup", this.handlePointerUp, {
161
+ capture: !0
162
+ }), context.stage.on("pointerleave", this.handlePointerUp, {
163
+ capture: !0
164
+ }), context.stage.on("dblclick", this.handleDBLClick, {
165
+ capture: !0
166
+ }), application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
157
167
  this.editModule.onChange(this.handleChange), this.editModule.onFocusOut(this.handleFocusOut);
158
168
  }
159
169
  copyToClipboard(e) {
@@ -182,21 +192,21 @@ export class RichTextEditPlugin {
182
192
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
183
193
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
184
194
  }
185
- fullSelection(e) {
186
- if (application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) {
187
- const currRt = this.currRt;
188
- if (!currRt) return;
189
- const cache = currRt.getFrameCache();
190
- if (!cache) return;
191
- const {lines: lines} = cache;
192
- if (0 === lines.length) return;
193
- if (!lines[0].paragraphs || 0 === lines[0].paragraphs.length) return;
194
- const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
195
- return this.selectionRange(-.1, totalCursorCount + .1), e.preventDefault(), !0;
196
- }
197
- return !1;
195
+ fullSelection() {
196
+ const currRt = this.currRt;
197
+ if (!currRt) return;
198
+ const cache = currRt.getFrameCache();
199
+ if (!cache) return;
200
+ const {lines: lines} = cache;
201
+ if (!lines.length || !lines[0].paragraphs.length) return;
202
+ const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
203
+ this.selectionRange(-.1, totalCursorCount + .1);
204
+ }
205
+ fullSelectionKeyHandler(e) {
206
+ return !!(application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) && (this.fullSelection(),
207
+ e.preventDefault(), !0);
198
208
  }
199
- directKey(e) {
209
+ directKeyHandler(e) {
200
210
  if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
201
211
  const cache = this.currRt.getFrameCache();
202
212
  if (!cache) return !1;
@@ -205,7 +215,8 @@ export class RichTextEditPlugin {
205
215
  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;
206
216
  if (x) {
207
217
  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,
208
- this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
218
+ this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1),
219
+ this.selectionStartCursorIdx = this.curCursorIdx;
209
220
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
210
221
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
211
222
  }
@@ -236,7 +247,7 @@ export class RichTextEditPlugin {
236
247
  const placeholder = shadowRoot.getElementsByType("richtext")[0];
237
248
  placeholder && shadowRoot.removeChild(placeholder);
238
249
  }
239
- const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
250
+ const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
240
251
  if (textConfig && textConfig.length) return;
241
252
  if (!editOptions || !editOptions.placeholder) return;
242
253
  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({}, getDefaultCharacterConfig(this.currRt.attribute)), {
@@ -246,41 +257,45 @@ export class RichTextEditPlugin {
246
257
  placeholderFontSize && (textConfigItem.fontSize = placeholderFontSize), this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), {
247
258
  x: 0,
248
259
  y: 0,
249
- pickable: !1,
250
- editable: !1,
251
- editOptions: null,
260
+ dx: -this.deltaX,
261
+ dy: -this.deltaY,
252
262
  angle: 0,
253
- _debug_bounds: !1,
254
263
  textConfig: [ textConfigItem ]
255
264
  })), shadow.add(this.shadowPlaceHolder);
256
265
  }
266
+ getRichTextAABBBounds(rt) {
267
+ const {attribute: attribute} = rt;
268
+ return attribute.textConfig.length ? rt.AABBBounds : getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), {
269
+ x: attribute.x,
270
+ y: attribute.y,
271
+ textAlign: attribute.textAlign,
272
+ boundsMode: "accurate"
273
+ }));
274
+ }
257
275
  tryShowInputBounds() {
258
276
  if (!this.currRt || !this.focusing) return;
259
277
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
260
278
  if (!editOptions || !boundsStrokeWhenInput) return;
261
- const {attribute: attribute} = this.currRt;
262
- let b = this.currRt.AABBBounds, h = b.height();
263
- if (!attribute.textConfig.length && this.editLine) {
264
- const {points: points} = this.editLine.attribute;
265
- h = points[1].y - points[0].y, b = getRichTextBounds(Object.assign({}, this.shadowPlaceHolder.attribute));
266
- }
279
+ const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
267
280
  this.shadowBounds = this.shadowBounds || createRect({}), this.shadowBounds.setAttributes({
268
281
  x: 0,
269
282
  y: 0,
270
- width: b.width(),
271
- height: h,
283
+ width: width,
284
+ height: height,
272
285
  fill: !1,
273
286
  stroke: boundsStrokeWhenInput,
274
287
  lineWidth: 1,
275
288
  zIndex: -1
276
289
  });
277
- this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
290
+ const shadow = this.getShadow(this.currRt);
291
+ this.addEditLineOrBgOrBounds(this.shadowBounds, shadow), this.offsetLineBgAndShadowBounds(),
292
+ this.offsetShadowRoot();
278
293
  }
279
294
  trySyncPlaceholderToTextConfig() {
280
295
  if (!this.currRt) return;
281
296
  const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
282
297
  if (textConfig && textConfig.length) return;
283
- if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) return;
298
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
284
299
  const {placeholder: placeholder} = editOptions;
285
300
  this.currRt.setAttributes({
286
301
  textConfig: [ Object.assign({
@@ -289,59 +304,95 @@ export class RichTextEditPlugin {
289
304
  });
290
305
  }
291
306
  deactivate(context) {
292
- context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
293
- context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
294
- context.stage.off("dblclick", this.handleDBLClick), application.global.addEventListener("keydown", this.handleKeyDown);
307
+ context.stage.off("pointermove", this.handleMove, {
308
+ capture: !0
309
+ }), context.stage.off("pointerdown", this.handlePointerDown, {
310
+ capture: !0
311
+ }), context.stage.off("pointerup", this.handlePointerUp, {
312
+ capture: !0
313
+ }), context.stage.off("pointerleave", this.handlePointerUp, {
314
+ capture: !0
315
+ }), context.stage.off("dblclick", this.handleDBLClick, {
316
+ capture: !0
317
+ }), application.global.addEventListener("keydown", this.handleKeyDown);
318
+ }
319
+ stopPropagation(e) {
320
+ e.stopPropagation();
321
+ }
322
+ addEditLineOrBgOrBounds(graphic, shadowRoot) {
323
+ let group = shadowRoot.getElementById("emptyBoundsContainer");
324
+ group || (group = createGroup({
325
+ x: 0,
326
+ y: 0,
327
+ width: 0,
328
+ height: 0,
329
+ boundsMode: "empty"
330
+ }), group.id = "emptyBoundsContainer", shadowRoot.add(group)), group.add(graphic);
331
+ }
332
+ removeEditLineOrBgOrBounds(graphic, shadowRoot) {
333
+ const group = shadowRoot.getElementById("emptyBoundsContainer");
334
+ group && group.removeChild(graphic);
295
335
  }
296
336
  onFocus(e, data) {
297
337
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
298
- this.focusing = !0;
338
+ this.focusing = !0, this.editing = !0;
299
339
  const target = e.target;
300
340
  if (!target || "richtext" !== target.type) return;
301
341
  this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
302
342
  const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
303
- if (cache) {
304
- if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
305
- shadowRootIdx: 1,
306
- pickable: !1,
307
- x: this.deltaX,
308
- y: this.deltaY
309
- }), !this.editLine) {
310
- const line = createLine({
311
- x: 0,
312
- y: 0,
313
- lineWidth: 1,
314
- stroke: "black"
315
- });
316
- this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
317
- const g = createGroup({
318
- x: 0,
319
- y: 0,
320
- width: 0,
321
- height: 0
322
- });
323
- this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
324
- }
325
- if (data = data || this.computedCursorPosByEvent(e, cache)) {
326
- const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
327
- this.startCursorPos = {
328
- x: x,
329
- y: (y1 + y2) / 2
330
- }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
331
- this.setCursorAndTextArea(x, y1, y2, target);
332
- } else {
333
- const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
334
- textConfig: [ {
335
- text: "a"
336
- } ]
337
- })).height();
338
- this.startCursorPos = {
339
- x: x,
340
- y: (y1 + y2) / 2
341
- }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
342
- }
343
- this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
343
+ if (!cache) return;
344
+ const {editOptions: editOptions = {}} = this.currRt.attribute;
345
+ if (editOptions.stopPropagation && target.addEventListener("*", this.stopPropagation),
346
+ this.offsetShadowRoot(target), !this.editLine) {
347
+ const line = createLine({
348
+ x: 0,
349
+ y: 0,
350
+ lineWidth: 1,
351
+ stroke: "black"
352
+ });
353
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
354
+ const g = createGroup({
355
+ x: 0,
356
+ y: 0,
357
+ width: 0,
358
+ height: 0
359
+ });
360
+ this.editBg = g, this.addEditLineOrBgOrBounds(this.editLine, shadowRoot), this.addEditLineOrBgOrBounds(this.editBg, shadowRoot);
344
361
  }
362
+ if (data = data || this.computedCursorPosByEvent(e, cache)) {
363
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
364
+ this.startCursorPos = {
365
+ x: x,
366
+ y: (y1 + y2) / 2
367
+ }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
368
+ this.setCursorAndTextArea(x, y1, y2, target);
369
+ } else {
370
+ const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
371
+ textConfig: [ {
372
+ text: "a"
373
+ } ]
374
+ })).height();
375
+ this.startCursorPos = {
376
+ x: x,
377
+ y: (y1 + y2) / 2
378
+ }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
379
+ }
380
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
381
+ }
382
+ offsetShadowRoot(rt) {
383
+ if (!(rt = rt || this.currRt)) return;
384
+ const shadowRoot = this.getShadow(rt);
385
+ if (!shadowRoot) return;
386
+ const cache = rt.getFrameCache();
387
+ cache && (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
388
+ shadowRootIdx: 1,
389
+ pickable: !1,
390
+ x: this.deltaX,
391
+ y: this.deltaY
392
+ }), this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({
393
+ dx: -this.deltaX,
394
+ dy: -this.deltaY
395
+ }));
345
396
  }
346
397
  offsetLineBgAndShadowBounds() {
347
398
  const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
@@ -360,27 +411,27 @@ export class RichTextEditPlugin {
360
411
  });
361
412
  }
362
413
  deFocus(trulyDeFocus = !1) {
363
- const target = this.currRt;
364
- if (!target) return;
365
- this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
414
+ this.editing = !1, this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
366
415
  trulyDeFocus: trulyDeFocus
367
- }))), trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
416
+ })));
368
417
  const currRt = this.currRt;
369
- this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
370
- this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
371
- this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
418
+ if (!currRt) return;
419
+ const {editOptions: editOptions = {}} = currRt.attribute;
420
+ editOptions.stopPropagation && currRt.removeEventListener("*", this.stopPropagation),
421
+ trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), currRt.detachShadow()),
422
+ this.currRt = null;
423
+ const shadowRoot = this.getShadow(currRt);
424
+ this.editLine && (this.removeEditLineOrBgOrBounds(this.editLine, shadowRoot), this.editLine.release(),
425
+ this.editLine = null, this.removeEditLineOrBgOrBounds(this.editBg, shadowRoot),
426
+ this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.removeEditLineOrBgOrBounds(this.shadowBounds, shadowRoot),
372
427
  this.shadowBounds.release(), this.shadowBounds = null), this.shadowPlaceHolder && (this.shadowPlaceHolder.parent && this.shadowPlaceHolder.parent.removeChild(this.shadowPlaceHolder),
373
- this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1;
374
- const textConfig = currRt.attribute.textConfig;
375
- let lastConfig = textConfig[textConfig.length - 1], cleared = !1;
376
- for (;lastConfig && "\n" === lastConfig.text; ) textConfig.pop(), lastConfig = textConfig[textConfig.length - 1],
377
- cleared = !0;
378
- cleared && currRt.setAttributes({
379
- textConfig: textConfig
380
- }), currRt.removeEventListener("pointerleave", this.handleLeave);
428
+ this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1,
429
+ currRt.removeEventListener("pointerleave", this.handleLeave);
381
430
  }
382
431
  addAnimateToLine(line) {
383
- line.animates && line.animates.forEach((animate => {
432
+ line.setAttributes({
433
+ opacity: 1
434
+ }), line.animates && line.animates.forEach((animate => {
384
435
  animate.stop(), animate.release();
385
436
  }));
386
437
  line.animate({
@@ -418,63 +469,61 @@ export class RichTextEditPlugin {
418
469
  x: currCursorData.x,
419
470
  y: (currCursorData.y1 + currCursorData.y2) / 2
420
471
  }, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
421
- if (line0Info && line1Info) {
422
- if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
423
- [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
424
- x: startCursorPos.x,
472
+ if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
473
+ [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
474
+ x: startCursorPos.x,
475
+ y: line0Info.top,
476
+ width: endCursorPos.x - startCursorPos.x,
477
+ height: line0Info.height,
478
+ fill: "#336df4",
479
+ fillOpacity: .2
480
+ }); else {
481
+ this.editBg.setAttributes({
482
+ x: 0,
425
483
  y: line0Info.top,
426
- width: endCursorPos.x - startCursorPos.x,
427
- height: line0Info.height,
428
- fill: "#336df4",
429
- fillOpacity: .2
430
- }); else {
431
- this.editBg.setAttributes({
432
- x: 0,
433
- y: line0Info.top,
434
- width: 0,
435
- height: 0
436
- });
437
- const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
438
- let y = 0;
439
- for (let i = startIdx; i <= endIdx; i++) {
440
- const line = cache.lines[i];
441
- if (i === startIdx) {
442
- const p = line.paragraphs[line.paragraphs.length - 1];
443
- this.editBg.add(createRect({
444
- x: startCursorPos.x,
445
- y: y,
446
- width: p.left + p.width - startCursorPos.x,
447
- height: line.height,
448
- fill: "#336df4",
449
- fillOpacity: .2
450
- }));
451
- } else if (i === endIdx) {
452
- const p = line.paragraphs[0];
453
- this.editBg.add(createRect({
454
- x: p.left,
455
- y: y,
456
- width: endCursorPos.x - p.left,
457
- height: line.height,
458
- fill: "#336df4",
459
- fillOpacity: .2
460
- }));
461
- } else {
462
- const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
463
- this.editBg.add(createRect({
464
- x: p0.left,
465
- y: y,
466
- width: p1.left + p1.width - p0.left,
467
- height: line.height,
468
- fill: "#336df4",
469
- fillOpacity: .2
470
- }));
471
- }
472
- y += line.height;
484
+ width: 0,
485
+ height: 0
486
+ });
487
+ const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
488
+ let y = 0;
489
+ for (let i = startIdx; i <= endIdx; i++) {
490
+ const line = cache.lines[i];
491
+ if (i === startIdx) {
492
+ const p = line.paragraphs[line.paragraphs.length - 1];
493
+ this.editBg.add(createRect({
494
+ x: startCursorPos.x,
495
+ y: y,
496
+ width: p.left + p.width - startCursorPos.x,
497
+ height: line.height,
498
+ fill: "#336df4",
499
+ fillOpacity: .2
500
+ }));
501
+ } else if (i === endIdx) {
502
+ const p = line.paragraphs[0];
503
+ this.editBg.add(createRect({
504
+ x: p.left,
505
+ y: y,
506
+ width: endCursorPos.x - p.left,
507
+ height: line.height,
508
+ fill: "#336df4",
509
+ fillOpacity: .2
510
+ }));
511
+ } else {
512
+ const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
513
+ this.editBg.add(createRect({
514
+ x: p0.left,
515
+ y: y,
516
+ width: p1.left + p1.width - p0.left,
517
+ height: line.height,
518
+ fill: "#336df4",
519
+ fillOpacity: .2
520
+ }));
473
521
  }
522
+ y += line.height;
474
523
  }
475
- this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
476
- this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
477
524
  }
525
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
526
+ this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
478
527
  }
479
528
  hideSelection() {
480
529
  this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
@@ -484,7 +533,8 @@ export class RichTextEditPlugin {
484
533
  getShadow(rt) {
485
534
  const sr = rt.shadowRoot || rt.attachShadow();
486
535
  return sr.setAttributes({
487
- boundsMode: "empty"
536
+ width: 1,
537
+ height: 1
488
538
  }), sr;
489
539
  }
490
540
  getLineByPoint(cache, p1) {
@@ -527,7 +577,7 @@ export class RichTextEditPlugin {
527
577
  this.pluginService.stage.renderNextFrame();
528
578
  }
529
579
  computeGlobalDelta(cache) {
530
- this.deltaX = 0, this.deltaY = 0;
580
+ this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
531
581
  const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
532
582
  "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
533
583
  "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
@@ -566,7 +616,8 @@ export class RichTextEditPlugin {
566
616
  y: y1
567
617
  }, out);
568
618
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
569
- out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
619
+ out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.offsetShadowRoot(),
620
+ this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
570
621
  }
571
622
  computedCursorPosByEvent(e, cache) {
572
623
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);