@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
@@ -35,15 +35,16 @@ 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, includeUndefined) {
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
- (includeUndefined || void 0 !== val) && valSet.add(val);
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);
47
+ val && valSet.add(val);
47
48
  }
48
49
  return Array.from(valSet.values());
49
50
  }
@@ -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,15 +101,16 @@ class RichTextEditPlugin {
100
101
  }, this.handleFocusOut = () => {
101
102
  throw new Error("不会走到这里 handleFocusOut");
102
103
  }, this.handleMove = e => {
103
- this.currRt && !this.currRt.attribute.editable && this.deFocus(!0), this.isEditableRichtext(e) ? (this.handleEnter(),
104
- e.target.once("pointerleave", this.handleLeave), this.tryShowSelection(e, !1)) : this.handleLeave();
105
- }, this.handleEnter = () => {
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));
107
+ }, this.handleEnter = e => {
106
108
  this.editing = !0, this.pluginService.stage.setCursor("text");
107
- }, this.handleLeave = () => {
109
+ }, this.handleLeave = e => {
108
110
  this.editing = !1, this.pluginService.stage.setCursor("default");
109
111
  }, this.handlePointerDown = e => {
110
- this.editing && this.isEditableRichtext(e) ? this.onFocus(e) : this.deFocus(!0),
111
- this.triggerRender(), this.pointerDown = !0, this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
112
+ this.editing ? this.onFocus(e) : this.deFocus(!0), this.triggerRender(), this.pointerDown = !0,
113
+ this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
112
114
  }, this.handlePointerUp = e => {
113
115
  this.pointerDown = !1;
114
116
  }, this.handleDBLClick = 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;
@@ -202,8 +211,7 @@ class RichTextEditPlugin {
202
211
  const {lineInfo: lineInfo, columnInfo: columnInfo} = this.getColumnByIndex(cache, Math.round(this.curCursorIdx)), {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
203
212
  if (x) {
204
213
  x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 2] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + .2 : x > 0 && columnInfo === lineInfo.paragraphs[lineInfo.paragraphs.length - 1] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx + 1 - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx > Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - .2 : x < 0 && columnInfo === lineInfo.paragraphs[0] && this.curCursorIdx < Math.round(this.curCursorIdx) ? this.curCursorIdx = this.curCursorIdx - 1 + .2 : this.curCursorIdx += x,
205
- this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1),
206
- this.selectionStartCursorIdx = this.curCursorIdx;
214
+ this.curCursorIdx < -.1 ? this.curCursorIdx = -.1 : this.curCursorIdx > totalCursorCount + .1 && (this.curCursorIdx = totalCursorCount + .1);
207
215
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
208
216
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this.hideSelection();
209
217
  }
@@ -234,7 +242,7 @@ class RichTextEditPlugin {
234
242
  const placeholder = shadowRoot.getElementsByType("richtext")[0];
235
243
  placeholder && shadowRoot.removeChild(placeholder);
236
244
  }
237
- const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
245
+ const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
238
246
  if (textConfig && textConfig.length) return;
239
247
  if (!editOptions || !editOptions.placeholder) return;
240
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,
@@ -246,41 +254,44 @@ class RichTextEditPlugin {
246
254
  graphic_1.createRichText)(Object.assign(Object.assign({}, this.currRt.attribute), {
247
255
  x: 0,
248
256
  y: 0,
249
- pickable: !1,
250
- editable: !1,
251
- editOptions: null,
257
+ dx: -this.deltaX,
258
+ dy: -this.deltaY,
252
259
  angle: 0,
253
- _debug_bounds: !1,
254
260
  textConfig: [ textConfigItem ]
255
261
  })), shadow.add(this.shadowPlaceHolder);
256
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
+ }
257
272
  tryShowInputBounds() {
258
273
  if (!this.currRt || !this.focusing) return;
259
274
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
260
275
  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 = (0, graphic_1.getRichTextBounds)(Object.assign({}, this.shadowPlaceHolder.attribute));
266
- }
276
+ const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
267
277
  this.shadowBounds = this.shadowBounds || (0, graphic_1.createRect)({}), this.shadowBounds.setAttributes({
268
278
  x: 0,
269
279
  y: 0,
270
- width: b.width(),
271
- height: h,
280
+ width: width,
281
+ height: height,
272
282
  fill: !1,
273
283
  stroke: boundsStrokeWhenInput,
274
284
  lineWidth: 1,
275
285
  zIndex: -1
276
286
  });
277
- this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
287
+ this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds(),
288
+ this.offsetShadowRoot();
278
289
  }
279
290
  trySyncPlaceholderToTextConfig() {
280
291
  if (!this.currRt) return;
281
292
  const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
282
293
  if (textConfig && textConfig.length) return;
283
- if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) return;
294
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
284
295
  const {placeholder: placeholder} = editOptions;
285
296
  this.currRt.setAttributes({
286
297
  textConfig: [ Object.assign({
@@ -289,9 +300,20 @@ class RichTextEditPlugin {
289
300
  });
290
301
  }
291
302
  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_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();
295
317
  }
296
318
  onFocus(e, data) {
297
319
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
@@ -300,48 +322,59 @@ class RichTextEditPlugin {
300
322
  if (!target || "richtext" !== target.type) return;
301
323
  this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
302
324
  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 = (0, graphic_1.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 = (0, graphic_1.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 = (0, graphic_1.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();
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);
344
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);
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
+ }));
345
378
  }
346
379
  offsetLineBgAndShadowBounds() {
347
380
  const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
@@ -360,11 +393,15 @@ class RichTextEditPlugin {
360
393
  });
361
394
  }
362
395
  deFocus(trulyDeFocus = !1) {
363
- const currRt = this.currRt;
364
- if (!currRt) return;
365
396
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeDefocus", this, {
366
397
  trulyDeFocus: trulyDeFocus
367
- }))), trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), currRt.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());
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),
370
407
  this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
@@ -376,12 +413,10 @@ class RichTextEditPlugin {
376
413
  cleared = !0;
377
414
  cleared && currRt.setAttributes({
378
415
  textConfig: textConfig
379
- }), currRt.removeEventListener("pointerleave", this.handleLeave);
416
+ });
380
417
  }
381
418
  addAnimateToLine(line) {
382
- line.setAttributes({
383
- opacity: 1
384
- }), line.animates && line.animates.forEach((animate => {
419
+ line.animates && line.animates.forEach((animate => {
385
420
  animate.stop(), animate.release();
386
421
  }));
387
422
  line.animate({
@@ -419,63 +454,61 @@ class RichTextEditPlugin {
419
454
  x: currCursorData.x,
420
455
  y: (currCursorData.y1 + currCursorData.y2) / 2
421
456
  }, line0Info = this.getLineByPoint(cache, startCursorPos), line1Info = this.getLineByPoint(cache, endCursorPos);
422
- if (line0Info && line1Info) {
423
- if ((startCursorPos.y > endCursorPos.y || startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x) && ([startCursorPos, endCursorPos] = [ endCursorPos, startCursorPos ],
424
- [line1Info, line0Info] = [ line0Info, line1Info ]), this.hideSelection(), line0Info === line1Info) this.editBg.setAttributes({
425
- 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,
426
468
  y: line0Info.top,
427
- width: endCursorPos.x - startCursorPos.x,
428
- height: line0Info.height,
429
- fill: "#336df4",
430
- fillOpacity: .2
431
- }); else {
432
- this.editBg.setAttributes({
433
- x: 0,
434
- y: line0Info.top,
435
- width: 0,
436
- height: 0
437
- });
438
- const startIdx = cache.lines.findIndex((item => item === line0Info)), endIdx = cache.lines.findIndex((item => item === line1Info));
439
- let y = 0;
440
- for (let i = startIdx; i <= endIdx; i++) {
441
- const line = cache.lines[i];
442
- if (i === startIdx) {
443
- const p = line.paragraphs[line.paragraphs.length - 1];
444
- this.editBg.add((0, graphic_1.createRect)({
445
- x: startCursorPos.x,
446
- y: y,
447
- width: p.left + p.width - startCursorPos.x,
448
- height: line.height,
449
- fill: "#336df4",
450
- fillOpacity: .2
451
- }));
452
- } else if (i === endIdx) {
453
- const p = line.paragraphs[0];
454
- this.editBg.add((0, graphic_1.createRect)({
455
- x: p.left,
456
- y: y,
457
- width: endCursorPos.x - p.left,
458
- height: line.height,
459
- fill: "#336df4",
460
- fillOpacity: .2
461
- }));
462
- } else {
463
- const p0 = line.paragraphs[0], p1 = line.paragraphs[line.paragraphs.length - 1];
464
- this.editBg.add((0, graphic_1.createRect)({
465
- x: p0.left,
466
- y: y,
467
- width: p1.left + p1.width - p0.left,
468
- height: line.height,
469
- fill: "#336df4",
470
- fillOpacity: .2
471
- }));
472
- }
473
- 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
+ }));
474
506
  }
507
+ y += line.height;
475
508
  }
476
- this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
477
- this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
478
509
  }
510
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
511
+ this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
479
512
  }
480
513
  hideSelection() {
481
514
  this.editBg && (this.editBg.removeAllChild(), this.editBg.setAttributes({
@@ -519,16 +552,13 @@ class RichTextEditPlugin {
519
552
  return -1;
520
553
  }
521
554
  isRichtext(e) {
522
- return !(!e.target || "richtext" !== e.target.type);
523
- }
524
- isEditableRichtext(e) {
525
- return this.isRichtext(e) && !!e.target.attribute.editable;
555
+ return !(!e.target || "richtext" !== e.target.type || !e.target.attribute.editable);
526
556
  }
527
557
  triggerRender() {
528
558
  this.pluginService.stage.renderNextFrame();
529
559
  }
530
560
  computeGlobalDelta(cache) {
531
- this.deltaX = 0, this.deltaY = 0;
561
+ this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
532
562
  const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
533
563
  "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
534
564
  "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
@@ -567,7 +597,8 @@ class RichTextEditPlugin {
567
597
  y: y1
568
598
  }, out);
569
599
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
570
- 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);
571
602
  }
572
603
  computedCursorPosByEvent(e, cache) {
573
604
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
@@ -641,7 +672,7 @@ class RichTextEditPlugin {
641
672
  target && (this.currRt = target, e ? this._forceFocusByEvent(e) : this._forceFocusByCursorIndex(null != cursorIndex ? cursorIndex : -.1));
642
673
  }
643
674
  _forceFocusByEvent(e) {
644
- this.handleEnter(), this.handlePointerDown(e), this.handlePointerUp(e);
675
+ this.handleEnter(e), this.handlePointerDown(e), this.handlePointerUp(e);
645
676
  }
646
677
  _forceFocusByCursorIndex(cursorIndex) {
647
678
  const richtext = this.currRt;