@visactor/vrender-core 0.22.0-vstory.1 → 0.22.0-vstory.2

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 (72) hide show
  1. package/cjs/core/global.d.ts +0 -3
  2. package/cjs/core/global.js +1 -7
  3. package/cjs/core/global.js.map +1 -1
  4. package/cjs/graphic/config.js +1 -0
  5. package/cjs/graphic/config.js.map +1 -1
  6. package/cjs/graphic/graphic.d.ts +1 -1
  7. package/cjs/graphic/graphic.js +5 -5
  8. package/cjs/graphic/graphic.js.map +1 -1
  9. package/cjs/graphic/richtext/line.js +1 -1
  10. package/cjs/graphic/richtext/line.js.map +1 -1
  11. package/cjs/graphic/richtext/paragraph.d.ts +1 -1
  12. package/cjs/graphic/richtext/paragraph.js +32 -7
  13. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  14. package/cjs/graphic/richtext.js +4 -1
  15. package/cjs/graphic/richtext.js.map +1 -1
  16. package/cjs/interface/global.d.ts +0 -1
  17. package/cjs/interface/global.js.map +1 -1
  18. package/cjs/interface/graphic/richText.d.ts +10 -0
  19. package/cjs/interface/graphic/richText.js.map +1 -1
  20. package/cjs/interface/graphic.d.ts +1 -1
  21. package/cjs/interface/graphic.js.map +1 -1
  22. package/cjs/plugins/builtin-plugin/edit-module.d.ts +2 -1
  23. package/cjs/plugins/builtin-plugin/edit-module.js +18 -13
  24. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  25. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -6
  26. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +248 -74
  27. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  28. package/cjs/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  29. package/cjs/render/contributions/render/contributions/image-contribution-render.js +2 -2
  30. package/cjs/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  31. package/cjs/render/contributions/render/draw-contribution.js +2 -1
  32. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  33. package/cjs/render/contributions/render/image-render.js.map +1 -1
  34. package/cjs/resource-loader/loader.js +1 -1
  35. package/cjs/resource-loader/loader.js.map +1 -1
  36. package/dist/index.es.js +376 -82
  37. package/es/core/global.d.ts +0 -3
  38. package/es/core/global.js +1 -8
  39. package/es/core/global.js.map +1 -1
  40. package/es/graphic/config.js +1 -0
  41. package/es/graphic/config.js.map +1 -1
  42. package/es/graphic/graphic.d.ts +1 -1
  43. package/es/graphic/graphic.js +5 -5
  44. package/es/graphic/graphic.js.map +1 -1
  45. package/es/graphic/richtext/line.js +1 -1
  46. package/es/graphic/richtext/line.js.map +1 -1
  47. package/es/graphic/richtext/paragraph.d.ts +1 -1
  48. package/es/graphic/richtext/paragraph.js +32 -7
  49. package/es/graphic/richtext/paragraph.js.map +1 -1
  50. package/es/graphic/richtext.js +4 -1
  51. package/es/graphic/richtext.js.map +1 -1
  52. package/es/interface/global.d.ts +0 -1
  53. package/es/interface/global.js.map +1 -1
  54. package/es/interface/graphic/richText.d.ts +10 -0
  55. package/es/interface/graphic/richText.js.map +1 -1
  56. package/es/interface/graphic.d.ts +1 -1
  57. package/es/interface/graphic.js.map +1 -1
  58. package/es/plugins/builtin-plugin/edit-module.d.ts +2 -1
  59. package/es/plugins/builtin-plugin/edit-module.js +15 -11
  60. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  61. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +30 -6
  62. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +248 -73
  63. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  64. package/es/render/contributions/render/contributions/image-contribution-render.d.ts +1 -1
  65. package/es/render/contributions/render/contributions/image-contribution-render.js +2 -2
  66. package/es/render/contributions/render/contributions/image-contribution-render.js.map +1 -1
  67. package/es/render/contributions/render/draw-contribution.js +1 -1
  68. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  69. package/es/render/contributions/render/image-render.js.map +1 -1
  70. package/es/resource-loader/loader.js +1 -1
  71. package/es/resource-loader/loader.js.map +1 -1
  72. package/package.json +3 -3
@@ -2,11 +2,11 @@ import { isObject, merge } from "@visactor/vutils";
2
2
 
3
3
  import { Generator } from "../../common/generator";
4
4
 
5
- import { createGroup, createLine, createRect, RichText } from "../../graphic";
5
+ import { createGroup, createLine, createRect, createRichText, getRichTextBounds, RichText } from "../../graphic";
6
6
 
7
7
  import { DefaultTicker, DefaultTimeline } from "../../animate";
8
8
 
9
- import { EditModule, findConfigIndexByCursorIdx } from "./edit-module";
9
+ import { EditModule, findConfigIndexByCursorIdx, getDefaultCharacterConfig } from "./edit-module";
10
10
 
11
11
  import { application } from "../../application";
12
12
 
@@ -36,6 +36,7 @@ class Selection {
36
36
  if (!this.rt) return null;
37
37
  let idx = Math.round(cursorIdx);
38
38
  const config = this.rt.attribute.textConfig;
39
+ if (!config.length) return null;
39
40
  for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
40
41
  return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
41
42
  }
@@ -55,6 +56,8 @@ class Selection {
55
56
 
56
57
  export const FORMAT_TEXT_COMMAND = "FORMAT_TEXT_COMMAND";
57
58
 
59
+ export const FORMAT_ALL_TEXT_COMMAND = "FORMAT_ALL_TEXT_COMMAND";
60
+
58
61
  export const FORMAT_ELEMENT_COMMAND = "FORMAT_ELEMENT_COMMAND";
59
62
 
60
63
  export class RichTextEditPlugin {
@@ -74,17 +77,34 @@ export class RichTextEditPlugin {
74
77
  }
75
78
  constructor() {
76
79
  this.name = "RichTextEditPlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(),
77
- this.key = this.name + this._uid, this.editing = !1, this.pointerDown = !1, this.handleKeyDown = e => {
80
+ this.key = this.name + this._uid, this.editing = !1, this.focusing = !1, this.pointerDown = !1,
81
+ this.formatTextCommandCb = (payload, p) => {
82
+ const rt = p.currRt;
83
+ if (!rt) return;
84
+ const selectionData = p.getSelection();
85
+ if (!selectionData) return;
86
+ const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
87
+ this._formatTextCommand(payload, config, rt);
88
+ }, this.formatAllTextCommandCb = (payload, p) => {
89
+ const rt = p.currRt;
90
+ if (!rt) return;
91
+ const config = rt.attribute.textConfig;
92
+ this._formatTextCommand(payload, config, rt);
93
+ }, this.handleKeyDown = e => {
78
94
  this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
79
95
  }, this.handleInput = (text, isComposing, cursorIdx, rt) => {
80
- this.hideSelection(), this.updateCbs.forEach((cb => cb("input", this)));
96
+ this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
97
+ this.updateCbs.forEach((cb => cb("input", this))));
81
98
  }, this.handleChange = (text, isComposing, cursorIdx, rt) => {
82
- this.curCursorIdx = cursorIdx, this.selectionStartCursorIdx = cursorIdx;
99
+ if (!this.currRt) return;
100
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.curCursorIdx = cursorIdx,
101
+ this.selectionStartCursorIdx = cursorIdx;
83
102
  const p = this.computedCursorPosByCursorIdx(cursorIdx, rt);
84
103
  this.setCursorAndTextArea(p.x, p.y1, p.y2, rt), this.hideSelection(), this.updateCbs.forEach((cb => cb("change", this)));
85
- }, this.handleFocusIn = () => {}, this.handleFocusOut = () => {
86
- this.editing = !1, this.deFocus(), this.pointerDown = !1, this.triggerRender(),
87
- this.updateCbs.forEach((cb => cb("defocus", this)));
104
+ }, this.handleFocusIn = () => {
105
+ throw new Error("不会走到这里 handleFocusIn");
106
+ }, this.handleFocusOut = () => {
107
+ throw new Error("不会走到这里 handleFocusOut");
88
108
  }, this.handleMove = e => {
89
109
  this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave),
90
110
  this.tryShowSelection(e, !1));
@@ -93,24 +113,23 @@ export class RichTextEditPlugin {
93
113
  }, this.handleLeave = e => {
94
114
  this.editing = !1, this.pluginService.stage.setCursor("default");
95
115
  }, this.handlePointerDown = e => {
96
- this.editing ? this.onFocus(e) : this.deFocus(), this.triggerRender(), this.pointerDown = !0,
116
+ this.editing ? this.onFocus(e) : this.deFocus(!0), this.triggerRender(), this.pointerDown = !0,
97
117
  this.updateCbs.forEach((cb => cb(this.editing ? "onfocus" : "defocus", this)));
98
118
  }, this.handlePointerUp = e => {
99
119
  this.pointerDown = !1;
100
120
  }, this.handleDBLClick = e => {
101
121
  this.editing && this.tryShowSelection(e, !0);
102
122
  }, this.commandCbs = new Map, this.commandCbs.set(FORMAT_TEXT_COMMAND, [ this.formatTextCommandCb ]),
103
- this.updateCbs = [], this.timeline = new DefaultTimeline, this.ticker = new DefaultTicker([ this.timeline ]),
123
+ this.commandCbs.set(FORMAT_ALL_TEXT_COMMAND, [ this.formatAllTextCommandCb ]), this.updateCbs = [],
124
+ this.timeline = new DefaultTimeline, this.ticker = new DefaultTicker([ this.timeline ]),
104
125
  this.deltaX = 0, this.deltaY = 0;
105
126
  }
106
- formatTextCommandCb(payload, p) {
107
- const rt = p.currRt;
108
- if (!rt) return;
109
- const selectionData = p.getSelection();
110
- if (!selectionData) return;
111
- const {selectionStartCursorIdx: selectionStartCursorIdx, curCursorIdx: curCursorIdx} = selectionData, minCursorIdx = Math.min(selectionStartCursorIdx, curCursorIdx), maxCursorIdx = Math.max(selectionStartCursorIdx, curCursorIdx), minConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, minCursorIdx), maxConfigIdx = findConfigIndexByCursorIdx(rt.attribute.textConfig, maxCursorIdx), config = rt.attribute.textConfig.slice(minConfigIdx, maxConfigIdx);
127
+ _formatTextCommand(payload, config, rt) {
112
128
  "bold" === payload ? config.forEach((item => item.fontWeight = "bold")) : "italic" === payload ? config.forEach((item => item.fontStyle = "italic")) : "underline" === payload ? config.forEach((item => item.underline = !0)) : "lineThrough" === payload ? config.forEach((item => item.lineThrough = !0)) : isObject(payload) && config.forEach((item => merge(item, payload))),
113
129
  rt.setAttributes(rt.attribute);
130
+ const cache = rt.getFrameCache();
131
+ cache && (this.selectionRangeByCursorIdx(this.selectionStartCursorIdx, this.curCursorIdx, cache),
132
+ this.tryShowInputBounds());
114
133
  }
115
134
  dispatchCommand(command, payload) {
116
135
  const cbs = this.commandCbs.get(command);
@@ -119,9 +138,17 @@ export class RichTextEditPlugin {
119
138
  registerCommand(command, cb) {
120
139
  (this.commandCbs.get(command) || []).push(cb);
121
140
  }
141
+ removeCommand(command, cb) {
142
+ const cbs = this.commandCbs.get(command) || [], idx = cbs.indexOf(cb);
143
+ idx > -1 && cbs.splice(idx, 1);
144
+ }
122
145
  registerUpdateListener(cb) {
123
146
  (this.updateCbs || []).push(cb);
124
147
  }
148
+ removeUpdateListener(cb) {
149
+ const cbs = this.updateCbs || [], idx = cbs.indexOf(cb);
150
+ idx > -1 && cbs.splice(idx, 1);
151
+ }
125
152
  activate(context) {
126
153
  this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove),
127
154
  context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
@@ -143,8 +170,10 @@ export class RichTextEditPlugin {
143
170
  if (!cache) return;
144
171
  const {lines: lines} = cache, totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
145
172
  startIdx > endIdx && ([startIdx, endIdx] = [ endIdx, startIdx ]), startIdx = Math.min(Math.max(startIdx, -.1), totalCursorCount + .1),
146
- endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.curCursorIdx = endIdx,
147
- this.selectionStartCursorIdx = startIdx;
173
+ endIdx = Math.min(Math.max(endIdx, -.1), totalCursorCount + .1), this.selectionRangeByCursorIdx(startIdx, endIdx, cache);
174
+ }
175
+ selectionRangeByCursorIdx(startCursorIdx, endCursorIdx, cache) {
176
+ this.curCursorIdx = endCursorIdx, this.selectionStartCursorIdx = startCursorIdx;
148
177
  const {x: x, y1: y1, y2: y2} = this.computedCursorPosByCursorIdx(this.selectionStartCursorIdx, this.currRt);
149
178
  this.startCursorPos = {
150
179
  x: x,
@@ -197,60 +226,162 @@ export class RichTextEditPlugin {
197
226
  }
198
227
  return !0;
199
228
  }
229
+ tryShowShadowPlaceholder() {
230
+ if (!this.currRt) return;
231
+ const shadowRoot = this.currRt.shadowRoot;
232
+ if (shadowRoot) {
233
+ const placeholder = shadowRoot.getElementsByType("richtext")[0];
234
+ placeholder && shadowRoot.removeChild(placeholder);
235
+ }
236
+ const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
237
+ if (textConfig && textConfig.length) return;
238
+ if (!editOptions || !editOptions.placeholder) return;
239
+ const {placeholder: placeholder, placeholderColor: placeholderColor = "rgba(0, 0, 0, 0.6)", placeholderFontFamily: placeholderFontFamily, placeholderFontSize: placeholderFontSize} = editOptions, shadow = this.currRt.shadowRoot || this.currRt.attachShadow();
240
+ this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), {
241
+ x: 0,
242
+ y: 0,
243
+ angle: 0,
244
+ _debug_bounds: !1,
245
+ textConfig: [ {
246
+ text: placeholder,
247
+ fill: placeholderColor,
248
+ fontFamily: placeholderFontFamily,
249
+ fontSize: placeholderFontSize
250
+ } ]
251
+ })), shadow.add(this.shadowPlaceHolder);
252
+ }
253
+ tryShowInputBounds() {
254
+ if (!this.currRt || !this.focusing) return;
255
+ const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
256
+ if (!editOptions || !boundsStrokeWhenInput) return;
257
+ const {attribute: attribute} = this.currRt, b = this.currRt.AABBBounds;
258
+ let h = b.height();
259
+ if (!attribute.textConfig.length && this.editLine) {
260
+ const {points: points} = this.editLine.attribute;
261
+ h = points[1].y - points[0].y;
262
+ }
263
+ this.shadowBounds = this.shadowBounds || createRect({}), this.shadowBounds.setAttributes({
264
+ x: 0,
265
+ y: 0,
266
+ width: b.width(),
267
+ height: h,
268
+ fill: !1,
269
+ stroke: boundsStrokeWhenInput,
270
+ lineWidth: 1,
271
+ boundsMode: "empty",
272
+ zIndex: -1
273
+ });
274
+ (this.currRt.shadowRoot || this.currRt.attachShadow()).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
275
+ }
276
+ trySyncPlaceholderToTextConfig() {
277
+ if (!this.currRt) return;
278
+ const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
279
+ if (textConfig && textConfig.length) return;
280
+ if (!editOptions || !editOptions.placeholder) return;
281
+ const {placeholder: placeholder} = editOptions;
282
+ this.currRt.setAttributes({
283
+ textConfig: [ Object.assign({
284
+ text: placeholder
285
+ }, getDefaultCharacterConfig(this.currRt.attribute)) ]
286
+ });
287
+ }
200
288
  deactivate(context) {
201
289
  context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
202
290
  context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
203
291
  context.stage.off("dblclick", this.handleDBLClick), application.global.addEventListener("keydown", this.handleKeyDown);
204
292
  }
205
- onFocus(e) {
206
- this.deFocus(), this.currRt = e.target;
293
+ onFocus(e, data) {
294
+ this.deFocus(!1), this.focusing = !0;
207
295
  const target = e.target;
208
- RichTextEditPlugin.tryUpdateRichtext(target);
209
- const shadowRoot = target.attachShadow(), cache = target.getFrameCache();
210
- if (!cache) return;
211
- if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
212
- shadowRootIdx: 1,
213
- pickable: !1,
214
- x: this.deltaX,
215
- y: this.deltaY
216
- }), !this.editLine) {
217
- const line = createLine({
218
- x: 0,
219
- y: 0,
220
- lineWidth: 1,
221
- stroke: "black"
222
- });
223
- this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
224
- const g = createGroup({
225
- x: 0,
226
- y: 0,
227
- width: 0,
228
- height: 0
229
- });
230
- this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
231
- }
232
- const data = this.computedCursorPosByEvent(e, cache);
233
- if (data) {
234
- const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
235
- this.startCursorPos = {
236
- x: x,
237
- y: (y1 + y2) / 2
238
- }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
239
- this.setCursorAndTextArea(x, y1, y2, target);
296
+ if (!target || "richtext" !== target.type) return;
297
+ this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
298
+ const shadowRoot = target.shadowRoot || target.attachShadow(), cache = target.getFrameCache();
299
+ if (cache) {
300
+ if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
301
+ shadowRootIdx: 1,
302
+ pickable: !1,
303
+ x: this.deltaX,
304
+ y: this.deltaY
305
+ }), !this.editLine) {
306
+ const line = createLine({
307
+ x: 0,
308
+ y: 0,
309
+ lineWidth: 1,
310
+ stroke: "black",
311
+ boundsMode: "empty"
312
+ });
313
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
314
+ const g = createGroup({
315
+ x: 0,
316
+ y: 0,
317
+ width: 0,
318
+ height: 0,
319
+ boundsMode: "empty"
320
+ });
321
+ this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
322
+ }
323
+ if (data = data || this.computedCursorPosByEvent(e, cache)) {
324
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
325
+ this.startCursorPos = {
326
+ x: x,
327
+ y: (y1 + y2) / 2
328
+ }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
329
+ this.setCursorAndTextArea(x, y1, y2, target);
330
+ } else {
331
+ const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
332
+ textConfig: [ {
333
+ text: "a"
334
+ } ]
335
+ })).height();
336
+ this.startCursorPos = {
337
+ x: x,
338
+ y: (y1 + y2) / 2
339
+ }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
340
+ }
341
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
240
342
  }
241
343
  }
242
- deFocus() {
344
+ offsetLineBgAndShadowBounds() {
345
+ const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
346
+ let b, dy = 0, attr = rt.attribute;
347
+ "middle" !== textBaseline && "bottom" !== textBaseline || (attr.textConfig.length || (attr = Object.assign(Object.assign({}, attr), {
348
+ textConfig: [ {
349
+ text: "a"
350
+ } ]
351
+ })), b = getRichTextBounds(attr)), "middle" === textBaseline ? dy = -b.height() / 2 : "bottom" === textBaseline && (dy = -b.height()),
352
+ this.editLine && this.editLine.setAttributes({
353
+ dy: dy
354
+ }), this.editBg && this.editBg.setAttributes({
355
+ dy: dy
356
+ }), this.shadowBounds && this.shadowBounds.setAttributes({
357
+ dy: dy
358
+ });
359
+ }
360
+ deFocus(trulyDeFocus = !1) {
243
361
  const target = this.currRt;
244
- target && (target.detachShadow(), this.currRt = null, this.editLine && (this.editLine.parent.removeChild(this.editLine),
245
- this.editLine.release(), this.editLine = null, this.editBg.parent.removeChild(this.editBg),
246
- this.editBg.release(), this.editBg = null));
362
+ if (!target) return;
363
+ trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
364
+ const currRt = this.currRt;
365
+ this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
366
+ this.editLine.release(), this.editLine = null, this.editBg.parent && this.editBg.parent.removeChild(this.editBg),
367
+ this.editBg.release(), this.editBg = null), trulyDeFocus && (this.shadowBounds && (this.shadowBounds.parent && this.shadowBounds.parent.removeChild(this.shadowBounds),
368
+ this.shadowBounds.release(), this.shadowBounds = null), this.shadowPlaceHolder && (this.shadowPlaceHolder.parent && this.shadowPlaceHolder.parent.removeChild(this.shadowPlaceHolder),
369
+ this.shadowPlaceHolder.release(), this.shadowPlaceHolder = null)), this.focusing = !1;
370
+ const textConfig = currRt.attribute.textConfig;
371
+ let lastConfig = textConfig[textConfig.length - 1], cleared = !1;
372
+ for (;lastConfig && "\n" === lastConfig.text; ) textConfig.pop(), lastConfig = textConfig[textConfig.length - 1],
373
+ cleared = !0;
374
+ cleared && currRt.setAttributes({
375
+ textConfig: textConfig
376
+ });
247
377
  }
248
378
  addAnimateToLine(line) {
249
379
  line.animates && line.animates.forEach((animate => {
250
380
  animate.stop(), animate.release();
251
381
  }));
252
- const animate = line.animate();
253
- animate.setTimeline(this.timeline), animate.to({
382
+ line.animate({
383
+ timeline: this.timeline
384
+ }).to({
254
385
  opacity: 1
255
386
  }, 10, "linear").wait(700).to({
256
387
  opacity: 0
@@ -336,7 +467,7 @@ export class RichTextEditPlugin {
336
467
  y += line.height;
337
468
  }
338
469
  }
339
- this.setCursorAndTextArea(currCursorData.x, currCursorData.y1 + 2, currCursorData.y2 - 2, this.currRt),
470
+ this.setCursorAndTextArea(currCursorData.x, currCursorData.y1, currCursorData.y2, this.currRt),
340
471
  this.triggerRender(), this.updateCbs.forEach((cb => cb("selection", this)));
341
472
  }
342
473
  hideSelection() {
@@ -391,8 +522,15 @@ export class RichTextEditPlugin {
391
522
  x: 0,
392
523
  y: 0
393
524
  };
394
- return e.target.globalTransMatrix.transformPoint(p, p1), p1.x -= this.deltaX, p1.y -= this.deltaY,
395
- p1;
525
+ e.target.globalTransMatrix.transformPoint(p, p1), p1.x -= this.deltaX, p1.y -= this.deltaY;
526
+ const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
527
+ let dy = 0;
528
+ if ("middle" === textBaseline) {
529
+ dy = getRichTextBounds(rt.attribute).height() / 2;
530
+ } else if ("bottom" === textBaseline) {
531
+ dy = getRichTextBounds(rt.attribute).height();
532
+ }
533
+ return p1.y += dy, p1;
396
534
  }
397
535
  setCursorAndTextArea(x, y1, y2, rt) {
398
536
  this.editLine.setAttributes({
@@ -413,15 +551,14 @@ export class RichTextEditPlugin {
413
551
  y: y1
414
552
  }, out);
415
553
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
416
- out.x += left, out.y += top, this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
554
+ out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
417
555
  }
418
556
  computedCursorPosByEvent(e, cache) {
419
557
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);
420
558
  if (!lineInfo) return;
421
559
  const {columnInfo: columnInfo, delta: delta} = this.getColumnAndIndexByLinePoint(lineInfo, p1);
422
560
  if (!columnInfo) return;
423
- let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
424
- y1 += 2, y2 -= 2;
561
+ const y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
425
562
  let cursorIndex = this.getColumnIndex(cache, columnInfo);
426
563
  cursorIndex += delta;
427
564
  return {
@@ -436,17 +573,31 @@ export class RichTextEditPlugin {
436
573
  computedCursorPosByCursorIdx(cursorIdx, rt) {
437
574
  var _a, _b, _c;
438
575
  const idx = Math.round(cursorIdx), leftRight = cursorIdx - idx, cache = rt.getFrameCache(), column = this.getColumnByIndex(cache, idx), height = null !== (_a = rt.attribute.fontSize) && void 0 !== _a ? _a : null === (_c = null === (_b = rt.attribute.textConfig) || void 0 === _b ? void 0 : _b[0]) || void 0 === _c ? void 0 : _c.fontSize;
439
- if (!column) return {
440
- x: 0,
441
- y1: 0,
442
- y2: height
443
- };
444
- const {lineInfo: lineInfo, columnInfo: columnInfo} = column;
445
- let y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
446
- return y1 += 2, y2 -= 2, {
576
+ if (!column) {
577
+ if (!cache.lines.length) {
578
+ return {
579
+ x: 0,
580
+ y1: 0,
581
+ y2: getRichTextBounds(Object.assign(Object.assign({}, rt.attribute), {
582
+ textConfig: [ {
583
+ text: "a"
584
+ } ]
585
+ })).height()
586
+ };
587
+ }
588
+ return {
589
+ x: 0,
590
+ y1: 0,
591
+ y2: height
592
+ };
593
+ }
594
+ const {lineInfo: lineInfo, columnInfo: columnInfo} = column, y1 = lineInfo.top, y2 = lineInfo.top + lineInfo.height;
595
+ return {
447
596
  x: columnInfo.left + (leftRight < 0 ? 0 : columnInfo.width),
448
597
  y1: y1,
449
- y2: y2
598
+ y2: y2,
599
+ lineInfo: lineInfo,
600
+ columnInfo: columnInfo
450
601
  };
451
602
  }
452
603
  getColumnByIndex(cache, index) {
@@ -469,5 +620,29 @@ export class RichTextEditPlugin {
469
620
  getSelection(defaultAll = !1) {
470
621
  return this.currRt ? null != this.selectionStartCursorIdx && null != this.curCursorIdx ? new Selection(this.selectionStartCursorIdx, this.curCursorIdx, this.currRt) : defaultAll ? RichTextEditPlugin.CreateSelection(this.currRt) : null : null;
471
622
  }
623
+ forceFocus(params) {
624
+ const {target: target, e: e, cursorIndex: cursorIndex} = params;
625
+ target && (this.currRt = target, e ? this._forceFocusByEvent(e) : this._forceFocusByCursorIndex(null != cursorIndex ? cursorIndex : -.1));
626
+ }
627
+ _forceFocusByEvent(e) {
628
+ this.handleEnter(e), this.handlePointerDown(e), this.handlePointerUp(e);
629
+ }
630
+ _forceFocusByCursorIndex(cursorIndex) {
631
+ const richtext = this.currRt;
632
+ if (!richtext) return;
633
+ let x = 0, y1 = 0, y2 = 2, lineInfo = null, columnInfo = null;
634
+ const data = this.computedCursorPosByCursorIdx(cursorIndex, richtext);
635
+ x = data.x, y1 = data.y1, y2 = data.y2, lineInfo = data.lineInfo, columnInfo = data.columnInfo,
636
+ this.onFocus({
637
+ target: this.currRt
638
+ }, {
639
+ x: x,
640
+ y1: y1,
641
+ y2: y2,
642
+ cursorIndex: cursorIndex,
643
+ lineInfo: lineInfo,
644
+ columnInfo: columnInfo
645
+ });
646
+ }
472
647
  }
473
648
  //# sourceMappingURL=richtext-edit-plugin.js.map