@visactor/vrender-core 0.22.0-vstory.8 → 0.22.0

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