@visactor/vrender-core 0.22.0-vstory.11 → 0.22.0-vstory.14

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 (154) hide show
  1. package/cjs/animate/animate.js +1 -1
  2. package/cjs/animate/animate.js.map +1 -1
  3. package/cjs/animate/custom-animate.js +2 -1
  4. package/cjs/animate/custom-animate.js.map +1 -1
  5. package/cjs/common/inversify/annotation/optional.d.ts +2 -0
  6. package/cjs/common/inversify/annotation/optional.js +14 -0
  7. package/cjs/common/inversify/annotation/optional.js.map +1 -0
  8. package/cjs/common/inversify/container.js +9 -6
  9. package/cjs/common/inversify/container.js.map +1 -1
  10. package/cjs/common/render-area.d.ts +0 -4
  11. package/cjs/common/render-area.js +16 -76
  12. package/cjs/common/render-area.js.map +1 -1
  13. package/cjs/common/render-curve.d.ts +1 -1
  14. package/cjs/common/render-curve.js.map +1 -1
  15. package/cjs/common/segment/step.js +1 -1
  16. package/cjs/common/segment/step.js.map +1 -1
  17. package/cjs/core/contributions/textMeasure/AtextMeasure.js +10 -0
  18. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  19. package/cjs/core/global.d.ts +3 -0
  20. package/cjs/core/global.js +7 -1
  21. package/cjs/core/global.js.map +1 -1
  22. package/cjs/graphic/bounds.d.ts +2 -2
  23. package/cjs/graphic/bounds.js.map +1 -1
  24. package/cjs/graphic/config.js +2 -0
  25. package/cjs/graphic/config.js.map +1 -1
  26. package/cjs/graphic/graphic.js +4 -4
  27. package/cjs/graphic/graphic.js.map +1 -1
  28. package/cjs/graphic/group.d.ts +0 -1
  29. package/cjs/graphic/group.js +0 -5
  30. package/cjs/graphic/group.js.map +1 -1
  31. package/cjs/graphic/line.js +2 -2
  32. package/cjs/graphic/line.js.map +1 -1
  33. package/cjs/graphic/richtext/line.js +3 -13
  34. package/cjs/graphic/richtext/line.js.map +1 -1
  35. package/cjs/graphic/richtext/paragraph.d.ts +3 -9
  36. package/cjs/graphic/richtext/paragraph.js +33 -20
  37. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  38. package/cjs/graphic/richtext/utils.d.ts +1 -1
  39. package/cjs/graphic/richtext/utils.js +6 -7
  40. package/cjs/graphic/richtext/utils.js.map +1 -1
  41. package/cjs/graphic/richtext.d.ts +0 -1
  42. package/cjs/graphic/richtext.js +25 -14
  43. package/cjs/graphic/richtext.js.map +1 -1
  44. package/cjs/interface/color.js.map +1 -1
  45. package/cjs/interface/global.d.ts +1 -0
  46. package/cjs/interface/global.js.map +1 -1
  47. package/cjs/interface/graphic/richText.d.ts +2 -1
  48. package/cjs/interface/graphic/richText.js.map +1 -1
  49. package/cjs/interface/graphic.d.ts +3 -2
  50. package/cjs/interface/graphic.js.map +1 -1
  51. package/cjs/plugins/builtin-plugin/edit-module.js +10 -5
  52. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  53. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +10 -7
  54. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +190 -159
  55. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  56. package/cjs/render/contributions/render/area-render.d.ts +1 -1
  57. package/cjs/render/contributions/render/area-render.js +16 -36
  58. package/cjs/render/contributions/render/area-render.js.map +1 -1
  59. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  60. package/cjs/render/contributions/render/contributions/base-contribution-render.js +7 -3
  61. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  62. package/cjs/render/contributions/render/contributions/group-contribution-render.js +2 -1
  63. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  64. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  65. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  66. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  67. package/cjs/render/contributions/render/contributions/text-contribution-render.js +3 -2
  68. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  69. package/cjs/render/contributions/render/draw-contribution.js +1 -0
  70. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  71. package/cjs/render/contributions/render/image-render.js.map +1 -1
  72. package/cjs/render/contributions/render/line-render.js +9 -31
  73. package/cjs/render/contributions/render/line-render.js.map +1 -1
  74. package/cjs/resource-loader/loader.d.ts +2 -2
  75. package/cjs/resource-loader/loader.js +1 -1
  76. package/cjs/resource-loader/loader.js.map +1 -1
  77. package/dist/index.es.js +328 -501
  78. package/es/animate/animate.js +4 -3
  79. package/es/animate/animate.js.map +1 -1
  80. package/es/animate/custom-animate.js +2 -1
  81. package/es/animate/custom-animate.js.map +1 -1
  82. package/es/common/inversify/annotation/optional.d.ts +2 -0
  83. package/es/common/inversify/annotation/optional.js +12 -0
  84. package/es/common/inversify/annotation/optional.js.map +1 -0
  85. package/es/common/inversify/container.js +9 -6
  86. package/es/common/inversify/container.js.map +1 -1
  87. package/es/common/render-area.d.ts +0 -4
  88. package/es/common/render-area.js +16 -76
  89. package/es/common/render-area.js.map +1 -1
  90. package/es/common/render-curve.d.ts +1 -1
  91. package/es/common/render-curve.js.map +1 -1
  92. package/es/common/segment/step.js +1 -1
  93. package/es/common/segment/step.js.map +1 -1
  94. package/es/core/contributions/textMeasure/AtextMeasure.js +10 -0
  95. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  96. package/es/core/global.d.ts +3 -0
  97. package/es/core/global.js +8 -1
  98. package/es/core/global.js.map +1 -1
  99. package/es/graphic/bounds.d.ts +2 -2
  100. package/es/graphic/bounds.js.map +1 -1
  101. package/es/graphic/config.js +2 -0
  102. package/es/graphic/config.js.map +1 -1
  103. package/es/graphic/graphic.js +5 -5
  104. package/es/graphic/graphic.js.map +1 -1
  105. package/es/graphic/group.d.ts +0 -1
  106. package/es/graphic/group.js +0 -5
  107. package/es/graphic/group.js.map +1 -1
  108. package/es/graphic/line.js +2 -2
  109. package/es/graphic/line.js.map +1 -1
  110. package/es/graphic/richtext/line.js +3 -13
  111. package/es/graphic/richtext/line.js.map +1 -1
  112. package/es/graphic/richtext/paragraph.d.ts +3 -9
  113. package/es/graphic/richtext/paragraph.js +33 -20
  114. package/es/graphic/richtext/paragraph.js.map +1 -1
  115. package/es/graphic/richtext/utils.d.ts +1 -1
  116. package/es/graphic/richtext/utils.js +6 -7
  117. package/es/graphic/richtext/utils.js.map +1 -1
  118. package/es/graphic/richtext.d.ts +0 -1
  119. package/es/graphic/richtext.js +22 -13
  120. package/es/graphic/richtext.js.map +1 -1
  121. package/es/interface/color.js.map +1 -1
  122. package/es/interface/global.d.ts +1 -0
  123. package/es/interface/global.js.map +1 -1
  124. package/es/interface/graphic/richText.d.ts +2 -1
  125. package/es/interface/graphic/richText.js.map +1 -1
  126. package/es/interface/graphic.d.ts +3 -2
  127. package/es/interface/graphic.js.map +1 -1
  128. package/es/plugins/builtin-plugin/edit-module.js +10 -5
  129. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  130. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +10 -7
  131. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +190 -159
  132. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  133. package/es/render/contributions/render/area-render.d.ts +1 -1
  134. package/es/render/contributions/render/area-render.js +16 -36
  135. package/es/render/contributions/render/area-render.js.map +1 -1
  136. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  137. package/es/render/contributions/render/contributions/base-contribution-render.js +7 -3
  138. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  139. package/es/render/contributions/render/contributions/group-contribution-render.js +2 -1
  140. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  141. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  142. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  143. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  144. package/es/render/contributions/render/contributions/text-contribution-render.js +3 -2
  145. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  146. package/es/render/contributions/render/draw-contribution.js +3 -2
  147. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  148. package/es/render/contributions/render/image-render.js.map +1 -1
  149. package/es/render/contributions/render/line-render.js +9 -31
  150. package/es/render/contributions/render/line-render.js.map +1 -1
  151. package/es/resource-loader/loader.d.ts +2 -2
  152. package/es/resource-loader/loader.js +1 -1
  153. package/es/resource-loader/loader.js.map +1 -1
  154. package/package.json +1 -1
@@ -40,15 +40,16 @@ 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, includeUndefined) {
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
- (includeUndefined || void 0 !== val) && valSet.add(val);
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);
52
+ val && valSet.add(val);
52
53
  }
53
54
  return Array.from(valSet.values());
54
55
  }
@@ -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))));
@@ -106,15 +107,16 @@ export class RichTextEditPlugin {
106
107
  }, this.handleFocusOut = () => {
107
108
  throw new Error("不会走到这里 handleFocusOut");
108
109
  }, this.handleMove = e => {
109
- 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
- }, this.handleEnter = () => {
110
+ this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave, {
111
+ capture: !0
112
+ }), this.tryShowSelection(e, !1));
113
+ }, this.handleEnter = e => {
112
114
  this.editing = !0, this.pluginService.stage.setCursor("text");
113
- }, this.handleLeave = () => {
115
+ }, this.handleLeave = e => {
114
116
  this.editing = !1, this.pluginService.stage.setCursor("default");
115
117
  }, this.handlePointerDown = e => {
116
- this.editing && this.isEditableRichtext(e) ? this.onFocus(e) : this.deFocus(!0),
117
- this.triggerRender(), this.pointerDown = !0, this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
118
+ this.editing ? this.onFocus(e) : this.deFocus(!0), this.triggerRender(), this.pointerDown = !0,
119
+ this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
118
120
  }, this.handlePointerUp = e => {
119
121
  this.pointerDown = !1;
120
122
  }, this.handleDBLClick = e => {
@@ -150,10 +152,17 @@ export class RichTextEditPlugin {
150
152
  idx > -1 && cbs.splice(idx, 1);
151
153
  }
152
154
  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),
155
+ this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove, {
156
+ capture: !0
157
+ }), context.stage.on("pointerdown", this.handlePointerDown, {
158
+ capture: !0
159
+ }), context.stage.on("pointerup", this.handlePointerUp, {
160
+ capture: !0
161
+ }), context.stage.on("pointerleave", this.handlePointerUp, {
162
+ capture: !0
163
+ }), context.stage.on("dblclick", this.handleDBLClick, {
164
+ capture: !0
165
+ }), application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
157
166
  this.editModule.onChange(this.handleChange), this.editModule.onFocusOut(this.handleFocusOut);
158
167
  }
159
168
  copyToClipboard(e) {
@@ -182,21 +191,21 @@ export class RichTextEditPlugin {
182
191
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
183
192
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
184
193
  }
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;
194
+ fullSelection() {
195
+ const currRt = this.currRt;
196
+ if (!currRt) return;
197
+ const cache = currRt.getFrameCache();
198
+ if (!cache) return;
199
+ const {lines: lines} = cache;
200
+ if (!lines.length || !lines[0].paragraphs.length) return;
201
+ const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
202
+ this.selectionRange(-.1, totalCursorCount + .1);
203
+ }
204
+ fullSelectionKeyHandler(e) {
205
+ return !!(application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) && (this.fullSelection(),
206
+ e.preventDefault(), !0);
198
207
  }
199
- directKey(e) {
208
+ directKeyHandler(e) {
200
209
  if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
201
210
  const cache = this.currRt.getFrameCache();
202
211
  if (!cache) return !1;
@@ -205,8 +214,7 @@ export class RichTextEditPlugin {
205
214
  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
215
  if (x) {
207
216
  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),
209
- this.selectionStartCursorIdx = this.curCursorIdx;
217
+ this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
210
218
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
211
219
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
212
220
  }
@@ -237,7 +245,7 @@ export class RichTextEditPlugin {
237
245
  const placeholder = shadowRoot.getElementsByType("richtext")[0];
238
246
  placeholder && shadowRoot.removeChild(placeholder);
239
247
  }
240
- const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
248
+ const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
241
249
  if (textConfig && textConfig.length) return;
242
250
  if (!editOptions || !editOptions.placeholder) return;
243
251
  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)), {
@@ -247,41 +255,44 @@ export class RichTextEditPlugin {
247
255
  placeholderFontSize && (textConfigItem.fontSize = placeholderFontSize), this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), {
248
256
  x: 0,
249
257
  y: 0,
250
- pickable: !1,
251
- editable: !1,
252
- editOptions: null,
258
+ dx: -this.deltaX,
259
+ dy: -this.deltaY,
253
260
  angle: 0,
254
- _debug_bounds: !1,
255
261
  textConfig: [ textConfigItem ]
256
262
  })), shadow.add(this.shadowPlaceHolder);
257
263
  }
264
+ getRichTextAABBBounds(rt) {
265
+ const {attribute: attribute} = rt;
266
+ return attribute.textConfig.length ? rt.AABBBounds : getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), {
267
+ x: attribute.x,
268
+ y: attribute.y,
269
+ textAlign: attribute.textAlign,
270
+ boundsMode: "accurate"
271
+ }));
272
+ }
258
273
  tryShowInputBounds() {
259
274
  if (!this.currRt || !this.focusing) return;
260
275
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
261
276
  if (!editOptions || !boundsStrokeWhenInput) return;
262
- const {attribute: attribute} = this.currRt;
263
- let b = this.currRt.AABBBounds, h = b.height();
264
- if (!attribute.textConfig.length && this.editLine) {
265
- const {points: points} = this.editLine.attribute;
266
- h = points[1].y - points[0].y, b = getRichTextBounds(Object.assign({}, this.shadowPlaceHolder.attribute));
267
- }
277
+ const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
268
278
  this.shadowBounds = this.shadowBounds || createRect({}), this.shadowBounds.setAttributes({
269
279
  x: 0,
270
280
  y: 0,
271
- width: b.width(),
272
- height: h,
281
+ width: width,
282
+ height: height,
273
283
  fill: !1,
274
284
  stroke: boundsStrokeWhenInput,
275
285
  lineWidth: 1,
276
286
  zIndex: -1
277
287
  });
278
- this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
288
+ this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds(),
289
+ this.offsetShadowRoot();
279
290
  }
280
291
  trySyncPlaceholderToTextConfig() {
281
292
  if (!this.currRt) return;
282
293
  const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
283
294
  if (textConfig && textConfig.length) return;
284
- if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) return;
295
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
285
296
  const {placeholder: placeholder} = editOptions;
286
297
  this.currRt.setAttributes({
287
298
  textConfig: [ Object.assign({
@@ -290,9 +301,20 @@ export class RichTextEditPlugin {
290
301
  });
291
302
  }
292
303
  deactivate(context) {
293
- context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
294
- context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
295
- context.stage.off("dblclick", this.handleDBLClick), application.global.addEventListener("keydown", this.handleKeyDown);
304
+ context.stage.off("pointermove", this.handleMove, {
305
+ capture: !0
306
+ }), context.stage.off("pointerdown", this.handlePointerDown, {
307
+ capture: !0
308
+ }), context.stage.off("pointerup", this.handlePointerUp, {
309
+ capture: !0
310
+ }), context.stage.off("pointerleave", this.handlePointerUp, {
311
+ capture: !0
312
+ }), context.stage.off("dblclick", this.handleDBLClick, {
313
+ capture: !0
314
+ }), application.global.addEventListener("keydown", this.handleKeyDown);
315
+ }
316
+ stopPropagation(e) {
317
+ e.stopPropagation();
296
318
  }
297
319
  onFocus(e, data) {
298
320
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
@@ -301,48 +323,59 @@ export class RichTextEditPlugin {
301
323
  if (!target || "richtext" !== target.type) return;
302
324
  this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
303
325
  const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
304
- if (cache) {
305
- if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
306
- shadowRootIdx: 1,
307
- pickable: !1,
308
- x: this.deltaX,
309
- y: this.deltaY
310
- }), !this.editLine) {
311
- const line = createLine({
312
- x: 0,
313
- y: 0,
314
- lineWidth: 1,
315
- stroke: "black"
316
- });
317
- this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
318
- const g = createGroup({
319
- x: 0,
320
- y: 0,
321
- width: 0,
322
- height: 0
323
- });
324
- this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
325
- }
326
- if (data = data || this.computedCursorPosByEvent(e, cache)) {
327
- const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
328
- this.startCursorPos = {
329
- x: x,
330
- y: (y1 + y2) / 2
331
- }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
332
- this.setCursorAndTextArea(x, y1, y2, target);
333
- } else {
334
- const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
335
- textConfig: [ {
336
- text: "a"
337
- } ]
338
- })).height();
339
- this.startCursorPos = {
340
- x: x,
341
- y: (y1 + y2) / 2
342
- }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
343
- }
344
- this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
326
+ if (!cache) return;
327
+ const {editOptions: editOptions = {}} = this.currRt.attribute;
328
+ if (editOptions.stopPropagation && target.addEventListener("*", this.stopPropagation),
329
+ this.offsetShadowRoot(target), !this.editLine) {
330
+ const line = createLine({
331
+ x: 0,
332
+ y: 0,
333
+ lineWidth: 1,
334
+ stroke: "black"
335
+ });
336
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
337
+ const g = createGroup({
338
+ x: 0,
339
+ y: 0,
340
+ width: 0,
341
+ height: 0
342
+ });
343
+ this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
345
344
  }
345
+ if (data = data || this.computedCursorPosByEvent(e, cache)) {
346
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
347
+ this.startCursorPos = {
348
+ x: x,
349
+ y: (y1 + y2) / 2
350
+ }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
351
+ this.setCursorAndTextArea(x, y1, y2, target);
352
+ } else {
353
+ const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
354
+ textConfig: [ {
355
+ text: "a"
356
+ } ]
357
+ })).height();
358
+ this.startCursorPos = {
359
+ x: x,
360
+ y: (y1 + y2) / 2
361
+ }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
362
+ }
363
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
364
+ }
365
+ offsetShadowRoot(rt) {
366
+ if (!(rt = rt || this.currRt)) return;
367
+ const shadowRoot = this.getShadow(rt);
368
+ if (!shadowRoot) return;
369
+ const cache = rt.getFrameCache();
370
+ cache && (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
371
+ shadowRootIdx: 1,
372
+ pickable: !1,
373
+ x: this.deltaX,
374
+ y: this.deltaY
375
+ }), this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({
376
+ dx: -this.deltaX,
377
+ dy: -this.deltaY
378
+ }));
346
379
  }
347
380
  offsetLineBgAndShadowBounds() {
348
381
  const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
@@ -361,11 +394,15 @@ export class RichTextEditPlugin {
361
394
  });
362
395
  }
363
396
  deFocus(trulyDeFocus = !1) {
364
- const currRt = this.currRt;
365
- if (!currRt) return;
366
397
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
367
398
  trulyDeFocus: trulyDeFocus
368
- }))), trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), currRt.detachShadow()),
399
+ })));
400
+ const target = this.currRt;
401
+ if (!target) return;
402
+ const {editOptions: editOptions = {}} = target.attribute;
403
+ editOptions.stopPropagation && target.removeEventListener("*", this.stopPropagation),
404
+ trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
405
+ const currRt = this.currRt;
369
406
  this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
370
407
  this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
371
408
  this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
@@ -377,12 +414,10 @@ export class RichTextEditPlugin {
377
414
  cleared = !0;
378
415
  cleared && currRt.setAttributes({
379
416
  textConfig: textConfig
380
- }), currRt.removeEventListener("pointerleave", this.handleLeave);
417
+ });
381
418
  }
382
419
  addAnimateToLine(line) {
383
- line.setAttributes({
384
- opacity: 1
385
- }), line.animates && line.animates.forEach((animate => {
420
+ line.animates && line.animates.forEach((animate => {
386
421
  animate.stop(), animate.release();
387
422
  }));
388
423
  line.animate({
@@ -420,63 +455,61 @@ export class RichTextEditPlugin {
420
455
  x: currCursorData.x,
421
456
  y: (currCursorData.y1 + currCursorData.y2) / 2
422
457
  }, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
423
- if (line0Info && line1Info) {
424
- if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
425
- [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
426
- x: startCursorPos.x,
458
+ if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
459
+ [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
460
+ x: startCursorPos.x,
461
+ y: line0Info.top,
462
+ width: endCursorPos.x - startCursorPos.x,
463
+ height: line0Info.height,
464
+ fill: "#336df4",
465
+ fillOpacity: .2
466
+ }); else {
467
+ this.editBg.setAttributes({
468
+ x: 0,
427
469
  y: line0Info.top,
428
- width: endCursorPos.x - startCursorPos.x,
429
- height: line0Info.height,
430
- fill: "#336df4",
431
- fillOpacity: .2
432
- }); else {
433
- this.editBg.setAttributes({
434
- x: 0,
435
- y: line0Info.top,
436
- width: 0,
437
- height: 0
438
- });
439
- const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
440
- let y = 0;
441
- for (let i = startIdx; i <= endIdx; i++) {
442
- const line = cache.lines[i];
443
- if (i === startIdx) {
444
- const p = line.paragraphs[line.paragraphs.length - 1];
445
- this.editBg.add(createRect({
446
- x: startCursorPos.x,
447
- y: y,
448
- width: p.left + p.width - startCursorPos.x,
449
- height: line.height,
450
- fill: "#336df4",
451
- fillOpacity: .2
452
- }));
453
- } else if (i === endIdx) {
454
- const p = line.paragraphs[0];
455
- this.editBg.add(createRect({
456
- x: p.left,
457
- y: y,
458
- width: endCursorPos.x - p.left,
459
- height: line.height,
460
- fill: "#336df4",
461
- fillOpacity: .2
462
- }));
463
- } else {
464
- const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
465
- this.editBg.add(createRect({
466
- x: p0.left,
467
- y: y,
468
- width: p1.left + p1.width - p0.left,
469
- height: line.height,
470
- fill: "#336df4",
471
- fillOpacity: .2
472
- }));
473
- }
474
- y += line.height;
470
+ width: 0,
471
+ height: 0
472
+ });
473
+ const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
474
+ let y = 0;
475
+ for (let i = startIdx; i <= endIdx; i++) {
476
+ const line = cache.lines[i];
477
+ if (i === startIdx) {
478
+ const p = line.paragraphs[line.paragraphs.length - 1];
479
+ this.editBg.add(createRect({
480
+ x: startCursorPos.x,
481
+ y: y,
482
+ width: p.left + p.width - startCursorPos.x,
483
+ height: line.height,
484
+ fill: "#336df4",
485
+ fillOpacity: .2
486
+ }));
487
+ } else if (i === endIdx) {
488
+ const p = line.paragraphs[0];
489
+ this.editBg.add(createRect({
490
+ x: p.left,
491
+ y: y,
492
+ width: endCursorPos.x - p.left,
493
+ height: line.height,
494
+ fill: "#336df4",
495
+ fillOpacity: .2
496
+ }));
497
+ } else {
498
+ const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
499
+ this.editBg.add(createRect({
500
+ x: p0.left,
501
+ y: y,
502
+ width: p1.left + p1.width - p0.left,
503
+ height: line.height,
504
+ fill: "#336df4",
505
+ fillOpacity: .2
506
+ }));
475
507
  }
508
+ y += line.height;
476
509
  }
477
- this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
478
- this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
479
510
  }
511
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
512
+ this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
480
513
  }
481
514
  hideSelection() {
482
515
  this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
@@ -520,16 +553,13 @@ export class RichTextEditPlugin {
520
553
  return -1;
521
554
  }
522
555
  isRichtext(e) {
523
- return !(!e.target || "richtext" !== e.target.type);
524
- }
525
- isEditableRichtext(e) {
526
- return this.isRichtext(e) && !!e.target.attribute.editable;
556
+ return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
527
557
  }
528
558
  triggerRender() {
529
559
  this.pluginService.stage.renderNextFrame();
530
560
  }
531
561
  computeGlobalDelta(cache) {
532
- this.deltaX = 0, this.deltaY = 0;
562
+ this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
533
563
  const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
534
564
  "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
535
565
  "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
@@ -568,7 +598,8 @@ export class RichTextEditPlugin {
568
598
  y: y1
569
599
  }, out);
570
600
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
571
- out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
601
+ out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.offsetShadowRoot(),
602
+ this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
572
603
  }
573
604
  computedCursorPosByEvent(e, cache) {
574
605
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
@@ -642,7 +673,7 @@ export class RichTextEditPlugin {
642
673
  target && (this.currRt = target, e ? this._forceFocusByEvent(e) : this._forceFocusByCursorIndex(null != cursorIndex ? cursorIndex : -.1));
643
674
  }
644
675
  _forceFocusByEvent(e) {
645
- this.handleEnter(), this.handlePointerDown(e), this.handlePointerUp(e);
676
+ this.handleEnter(e), this.handlePointerDown(e), this.handlePointerUp(e);
646
677
  }
647
678
  _forceFocusByCursorIndex(cursorIndex) {
648
679
  const richtext = this.currRt;