@visactor/vrender-core 0.22.0-vstory.12 → 0.22.0-vstory.15

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 (70) hide show
  1. package/cjs/common/inversify/annotation/optional.d.ts +2 -0
  2. package/cjs/common/inversify/annotation/optional.js +14 -0
  3. package/cjs/common/inversify/annotation/optional.js.map +1 -0
  4. package/cjs/common/inversify/container.js +9 -6
  5. package/cjs/common/inversify/container.js.map +1 -1
  6. package/cjs/core/contributions/textMeasure/AtextMeasure.js +10 -0
  7. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  8. package/cjs/graphic/bounds.d.ts +2 -2
  9. package/cjs/graphic/bounds.js.map +1 -1
  10. package/cjs/graphic/config.js +1 -0
  11. package/cjs/graphic/config.js.map +1 -1
  12. package/cjs/graphic/richtext.d.ts +1 -1
  13. package/cjs/graphic/richtext.js +23 -6
  14. package/cjs/graphic/richtext.js.map +1 -1
  15. package/cjs/interface/graphic/richText.d.ts +1 -0
  16. package/cjs/interface/graphic/richText.js.map +1 -1
  17. package/cjs/interface/graphic.d.ts +1 -0
  18. package/cjs/interface/graphic.js.map +1 -1
  19. package/cjs/plugins/builtin-plugin/edit-module.js +2 -1
  20. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  21. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +8 -4
  22. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +124 -81
  23. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  24. package/cjs/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  25. package/cjs/render/contributions/render/contributions/base-contribution-render.js +7 -3
  26. package/cjs/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  27. package/cjs/render/contributions/render/contributions/group-contribution-render.js +2 -1
  28. package/cjs/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  29. package/cjs/render/contributions/render/contributions/text-contribution-render.js +3 -2
  30. package/cjs/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  31. package/cjs/render/contributions/render/draw-contribution.js +1 -0
  32. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  33. package/cjs/resource-loader/loader.d.ts +2 -2
  34. package/cjs/resource-loader/loader.js.map +1 -1
  35. package/dist/index.es.js +153 -65
  36. package/es/common/inversify/annotation/optional.d.ts +2 -0
  37. package/es/common/inversify/annotation/optional.js +12 -0
  38. package/es/common/inversify/annotation/optional.js.map +1 -0
  39. package/es/common/inversify/container.js +9 -6
  40. package/es/common/inversify/container.js.map +1 -1
  41. package/es/core/contributions/textMeasure/AtextMeasure.js +10 -0
  42. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  43. package/es/graphic/bounds.d.ts +2 -2
  44. package/es/graphic/bounds.js.map +1 -1
  45. package/es/graphic/config.js +1 -0
  46. package/es/graphic/config.js.map +1 -1
  47. package/es/graphic/richtext.d.ts +1 -1
  48. package/es/graphic/richtext.js +20 -5
  49. package/es/graphic/richtext.js.map +1 -1
  50. package/es/interface/graphic/richText.d.ts +1 -0
  51. package/es/interface/graphic/richText.js.map +1 -1
  52. package/es/interface/graphic.d.ts +1 -0
  53. package/es/interface/graphic.js.map +1 -1
  54. package/es/plugins/builtin-plugin/edit-module.js +2 -1
  55. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  56. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +8 -4
  57. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +124 -81
  58. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  59. package/es/render/contributions/render/contributions/base-contribution-render.d.ts +1 -0
  60. package/es/render/contributions/render/contributions/base-contribution-render.js +7 -3
  61. package/es/render/contributions/render/contributions/base-contribution-render.js.map +1 -1
  62. package/es/render/contributions/render/contributions/group-contribution-render.js +2 -1
  63. package/es/render/contributions/render/contributions/group-contribution-render.js.map +1 -1
  64. package/es/render/contributions/render/contributions/text-contribution-render.js +3 -2
  65. package/es/render/contributions/render/contributions/text-contribution-render.js.map +1 -1
  66. package/es/render/contributions/render/draw-contribution.js +3 -2
  67. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  68. package/es/resource-loader/loader.d.ts +2 -2
  69. package/es/resource-loader/loader.js.map +1 -1
  70. package/package.json +2 -2
@@ -40,14 +40,15 @@ class Selection {
40
40
  for (let i = 0; i < config.length; i++) if ("\n" !== config[i].text && (idx--, idx < 0)) return config[i][key];
41
41
  return null !== (_a = config[Math.min(idx, config.length - 1)][key]) && void 0 !== _a ? _a : this.rt.attribute[key];
42
42
  }
43
- getFormat(key) {
44
- return this.getAllFormat(key)[0];
43
+ getFormat(key, supportOutAttr = !1) {
44
+ return this.getAllFormat(key, supportOutAttr)[0];
45
45
  }
46
- getAllFormat(key) {
46
+ getAllFormat(key, supportOutAttr = !1) {
47
+ var _a, _b, _c, _d;
47
48
  const valSet = new Set, minCursorIdx = Math.min(this.selectionStartCursorIdx, this.curCursorIdx), maxCursorIdx = Math.max(this.selectionStartCursorIdx, this.curCursorIdx);
48
- if (minCursorIdx === maxCursorIdx) return [ this._getFormat(key, minCursorIdx) ];
49
+ if (minCursorIdx === maxCursorIdx) return supportOutAttr ? [ null !== (_a = this._getFormat(key, minCursorIdx)) && void 0 !== _a ? _a : (null === (_b = this.rt) || void 0 === _b ? void 0 : _b.attribute)[key] ] : [ this._getFormat(key, minCursorIdx) ];
49
50
  for (let i = Math.ceil(minCursorIdx); i <= Math.floor(maxCursorIdx); i++) {
50
- const val = this._getFormat(key, i);
51
+ const val = supportOutAttr ? null !== (_c = this._getFormat(key, i)) && void 0 !== _c ? _c : (null === (_d = this.rt) || void 0 === _d ? void 0 : _d.attribute)[key] : this._getFormat(key, i);
51
52
  val && valSet.add(val);
52
53
  }
53
54
  return Array.from(valSet.values());
@@ -91,7 +92,7 @@ export class RichTextEditPlugin {
91
92
  const config = rt.attribute.textConfig;
92
93
  this._formatTextCommand(payload, config, rt);
93
94
  }, this.handleKeyDown = e => {
94
- this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelection(e) || this.directKey(e));
95
+ this.currRt && this.editing && (this.copyToClipboard(e) || this.fullSelectionKeyHandler(e) || this.directKeyHandler(e));
95
96
  }, this.handleInput = (text, isComposing, cursorIdx, rt) => {
96
97
  this.currRt && (this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.hideSelection(),
97
98
  this.updateCbs.forEach((cb => cb("input", this))));
@@ -106,8 +107,9 @@ export class RichTextEditPlugin {
106
107
  }, this.handleFocusOut = () => {
107
108
  throw new Error("不会走到这里 handleFocusOut");
108
109
  }, this.handleMove = e => {
109
- this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave),
110
- this.tryShowSelection(e, !1));
110
+ this.isRichtext(e) && (this.currRt = e.target, this.handleEnter(e), e.target.once("pointerleave", this.handleLeave, {
111
+ capture: !0
112
+ }), this.tryShowSelection(e, !1));
111
113
  }, this.handleEnter = e => {
112
114
  this.editing = !0, this.pluginService.stage.setCursor("text");
113
115
  }, this.handleLeave = e => {
@@ -150,10 +152,17 @@ export class RichTextEditPlugin {
150
152
  idx > -1 && cbs.splice(idx, 1);
151
153
  }
152
154
  activate(context) {
153
- this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove),
154
- context.stage.on("pointerdown", this.handlePointerDown), context.stage.on("pointerup", this.handlePointerUp),
155
- context.stage.on("pointerleave", this.handlePointerUp), context.stage.on("dblclick", this.handleDBLClick),
156
- application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
155
+ this.pluginService = context, this.editModule = new EditModule, context.stage.on("pointermove", this.handleMove, {
156
+ capture: !0
157
+ }), context.stage.on("pointerdown", this.handlePointerDown, {
158
+ capture: !0
159
+ }), context.stage.on("pointerup", this.handlePointerUp, {
160
+ capture: !0
161
+ }), context.stage.on("pointerleave", this.handlePointerUp, {
162
+ capture: !0
163
+ }), context.stage.on("dblclick", this.handleDBLClick, {
164
+ capture: !0
165
+ }), application.global.addEventListener("keydown", this.handleKeyDown), this.editModule.onInput(this.handleInput),
157
166
  this.editModule.onChange(this.handleChange), this.editModule.onFocusOut(this.handleFocusOut);
158
167
  }
159
168
  copyToClipboard(e) {
@@ -182,18 +191,21 @@ export class RichTextEditPlugin {
182
191
  const pos = this.computedCursorPosByCursorIdx(this.curCursorIdx, this.currRt);
183
192
  this.setCursorAndTextArea(pos.x, pos.y1, pos.y2, this.currRt), this._tryShowSelection(pos, cache);
184
193
  }
185
- fullSelection(e) {
186
- if (application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) {
187
- const currRt = this.currRt;
188
- if (!currRt) return;
189
- const cache = currRt.getFrameCache();
190
- if (!cache) return;
191
- const {lines: lines} = cache, 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;
194
+ fullSelection() {
195
+ const currRt = this.currRt;
196
+ if (!currRt) return;
197
+ const cache = currRt.getFrameCache();
198
+ if (!cache) return;
199
+ const {lines: lines} = cache;
200
+ if (!lines.length || !lines[0].paragraphs.length) return;
201
+ const totalCursorCount = lines.reduce(((total, line) => total + line.paragraphs.length), 0) - 1;
202
+ this.selectionRange(-.1, totalCursorCount + .1);
195
203
  }
196
- directKey(e) {
204
+ fullSelectionKeyHandler(e) {
205
+ return !!(application.global.isMacOS() && e.metaKey && "a" === e.key || !application.global.isMacOS() && e.ctrlKey && "a" === e.key) && (this.fullSelection(),
206
+ e.preventDefault(), !0);
207
+ }
208
+ directKeyHandler(e) {
197
209
  if ("ArrowUp" !== e.key && "ArrowDown" !== e.key && "ArrowLeft" !== e.key && "ArrowRight" !== e.key) return !1;
198
210
  const cache = this.currRt.getFrameCache();
199
211
  if (!cache) return !1;
@@ -233,7 +245,7 @@ export class RichTextEditPlugin {
233
245
  const placeholder = shadowRoot.getElementsByType("richtext")[0];
234
246
  placeholder && shadowRoot.removeChild(placeholder);
235
247
  }
236
- const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
248
+ const {textConfig: textConfig, editOptions: editOptions = {}} = this.currRt.attribute;
237
249
  if (textConfig && textConfig.length) return;
238
250
  if (!editOptions || !editOptions.placeholder) return;
239
251
  const {placeholder: placeholder, placeholderColor: placeholderColor = "rgba(0, 0, 0, 0.6)", placeholderFontFamily: placeholderFontFamily, placeholderFontSize: placeholderFontSize} = editOptions, shadow = this.getShadow(this.currRt), textConfigItem = Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), {
@@ -243,38 +255,44 @@ export class RichTextEditPlugin {
243
255
  placeholderFontSize && (textConfigItem.fontSize = placeholderFontSize), this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), {
244
256
  x: 0,
245
257
  y: 0,
258
+ dx: -this.deltaX,
259
+ dy: -this.deltaY,
246
260
  angle: 0,
247
- _debug_bounds: !1,
248
261
  textConfig: [ textConfigItem ]
249
262
  })), shadow.add(this.shadowPlaceHolder);
250
263
  }
264
+ getRichTextAABBBounds(rt) {
265
+ const {attribute: attribute} = rt;
266
+ return attribute.textConfig.length ? rt.AABBBounds : getRichTextBounds(Object.assign(Object.assign({}, this.shadowPlaceHolder.attribute), {
267
+ x: attribute.x,
268
+ y: attribute.y,
269
+ textAlign: attribute.textAlign,
270
+ boundsMode: "accurate"
271
+ }));
272
+ }
251
273
  tryShowInputBounds() {
252
274
  if (!this.currRt || !this.focusing) return;
253
275
  const {editOptions: editOptions = {}} = this.currRt.attribute, {boundsStrokeWhenInput: boundsStrokeWhenInput} = editOptions;
254
276
  if (!editOptions || !boundsStrokeWhenInput) return;
255
- const {attribute: attribute} = this.currRt, b = this.currRt.AABBBounds;
256
- let h = b.height();
257
- if (!attribute.textConfig.length && this.editLine) {
258
- const {points: points} = this.editLine.attribute;
259
- h = points[1].y - points[0].y;
260
- }
277
+ const b = this.getRichTextAABBBounds(this.currRt), height = b.height(), width = b.width();
261
278
  this.shadowBounds = this.shadowBounds || createRect({}), this.shadowBounds.setAttributes({
262
279
  x: 0,
263
280
  y: 0,
264
- width: b.width(),
265
- height: h,
281
+ width: width,
282
+ height: height,
266
283
  fill: !1,
267
284
  stroke: boundsStrokeWhenInput,
268
285
  lineWidth: 1,
269
286
  zIndex: -1
270
287
  });
271
- this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds();
288
+ this.getShadow(this.currRt).add(this.shadowBounds), this.offsetLineBgAndShadowBounds(),
289
+ this.offsetShadowRoot();
272
290
  }
273
291
  trySyncPlaceholderToTextConfig() {
274
292
  if (!this.currRt) return;
275
293
  const {textConfig: textConfig, editOptions: editOptions} = this.currRt.attribute;
276
294
  if (textConfig && textConfig.length) return;
277
- if (!editOptions || !editOptions.placeholder) return;
295
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceholderToTextConfig)) return;
278
296
  const {placeholder: placeholder} = editOptions;
279
297
  this.currRt.setAttributes({
280
298
  textConfig: [ Object.assign({
@@ -283,9 +301,20 @@ export class RichTextEditPlugin {
283
301
  });
284
302
  }
285
303
  deactivate(context) {
286
- context.stage.off("pointermove", this.handleMove), context.stage.off("pointerdown", this.handlePointerDown),
287
- context.stage.off("pointerup", this.handlePointerUp), context.stage.off("pointerleave", this.handlePointerUp),
288
- context.stage.off("dblclick", this.handleDBLClick), application.global.addEventListener("keydown", this.handleKeyDown);
304
+ context.stage.off("pointermove", this.handleMove, {
305
+ capture: !0
306
+ }), context.stage.off("pointerdown", this.handlePointerDown, {
307
+ capture: !0
308
+ }), context.stage.off("pointerup", this.handlePointerUp, {
309
+ capture: !0
310
+ }), context.stage.off("pointerleave", this.handlePointerUp, {
311
+ capture: !0
312
+ }), context.stage.off("dblclick", this.handleDBLClick, {
313
+ capture: !0
314
+ }), application.global.addEventListener("keydown", this.handleKeyDown);
315
+ }
316
+ stopPropagation(e) {
317
+ e.stopPropagation();
289
318
  }
290
319
  onFocus(e, data) {
291
320
  this.updateCbs && this.updateCbs.forEach((cb => cb("beforeOnfocus", this))), this.deFocus(!1),
@@ -294,48 +323,59 @@ export class RichTextEditPlugin {
294
323
  if (!target || "richtext" !== target.type) return;
295
324
  this.currRt = target, RichTextEditPlugin.tryUpdateRichtext(target);
296
325
  const shadowRoot = this.getShadow(target), cache = target.getFrameCache();
297
- if (cache) {
298
- if (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
299
- shadowRootIdx: 1,
300
- pickable: !1,
301
- x: this.deltaX,
302
- y: this.deltaY
303
- }), !this.editLine) {
304
- const line = createLine({
305
- x: 0,
306
- y: 0,
307
- lineWidth: 1,
308
- stroke: "black"
309
- });
310
- this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
311
- const g = createGroup({
312
- x: 0,
313
- y: 0,
314
- width: 0,
315
- height: 0
316
- });
317
- this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
318
- }
319
- if (data = data || this.computedCursorPosByEvent(e, cache)) {
320
- const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
321
- this.startCursorPos = {
322
- x: x,
323
- y: (y1 + y2) / 2
324
- }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
325
- this.setCursorAndTextArea(x, y1, y2, target);
326
- } else {
327
- const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
328
- textConfig: [ {
329
- text: "a"
330
- } ]
331
- })).height();
332
- this.startCursorPos = {
333
- x: x,
334
- y: (y1 + y2) / 2
335
- }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
336
- }
337
- this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
326
+ if (!cache) return;
327
+ const {editOptions: editOptions = {}} = this.currRt.attribute;
328
+ if (editOptions.stopPropagation && target.addEventListener("*", this.stopPropagation),
329
+ this.offsetShadowRoot(target), !this.editLine) {
330
+ const line = createLine({
331
+ x: 0,
332
+ y: 0,
333
+ lineWidth: 1,
334
+ stroke: "black"
335
+ });
336
+ this.addAnimateToLine(line), this.editLine = line, this.ticker.start(!0);
337
+ const g = createGroup({
338
+ x: 0,
339
+ y: 0,
340
+ width: 0,
341
+ height: 0
342
+ });
343
+ this.editBg = g, shadowRoot.add(this.editLine), shadowRoot.add(this.editBg);
338
344
  }
345
+ if (data = data || this.computedCursorPosByEvent(e, cache)) {
346
+ const {x: x, y1: y1, y2: y2, cursorIndex: cursorIndex} = data;
347
+ this.startCursorPos = {
348
+ x: x,
349
+ y: (y1 + y2) / 2
350
+ }, this.curCursorIdx = cursorIndex, this.selectionStartCursorIdx = cursorIndex,
351
+ this.setCursorAndTextArea(x, y1, y2, target);
352
+ } else {
353
+ const x = 0, y1 = 0, y2 = getRichTextBounds(Object.assign(Object.assign({}, target.attribute), {
354
+ textConfig: [ {
355
+ text: "a"
356
+ } ]
357
+ })).height();
358
+ this.startCursorPos = {
359
+ x: x,
360
+ y: (y1 + y2) / 2
361
+ }, this.curCursorIdx = -.1, this.selectionStartCursorIdx = -.1, this.setCursorAndTextArea(x, y1, y2, target);
362
+ }
363
+ this.tryShowShadowPlaceholder(), this.tryShowInputBounds(), this.currRt.addUpdateBoundTag();
364
+ }
365
+ offsetShadowRoot(rt) {
366
+ if (!(rt = rt || this.currRt)) return;
367
+ const shadowRoot = this.getShadow(rt);
368
+ if (!shadowRoot) return;
369
+ const cache = rt.getFrameCache();
370
+ cache && (this.computeGlobalDelta(cache), shadowRoot.setAttributes({
371
+ shadowRootIdx: 1,
372
+ pickable: !1,
373
+ x: this.deltaX,
374
+ y: this.deltaY
375
+ }), this.shadowPlaceHolder && this.shadowPlaceHolder.setAttributes({
376
+ dx: -this.deltaX,
377
+ dy: -this.deltaY
378
+ }));
339
379
  }
340
380
  offsetLineBgAndShadowBounds() {
341
381
  const rt = this.currRt, {textBaseline: textBaseline} = rt.attribute;
@@ -359,6 +399,8 @@ export class RichTextEditPlugin {
359
399
  })));
360
400
  const target = this.currRt;
361
401
  if (!target) return;
402
+ const {editOptions: editOptions = {}} = target.attribute;
403
+ editOptions.stopPropagation && target.removeEventListener("*", this.stopPropagation),
362
404
  trulyDeFocus && (this.trySyncPlaceholderToTextConfig(), target.detachShadow());
363
405
  const currRt = this.currRt;
364
406
  this.currRt = null, this.editLine && (this.editLine.parent && this.editLine.parent.removeChild(this.editLine),
@@ -517,7 +559,7 @@ export class RichTextEditPlugin {
517
559
  this.pluginService.stage.renderNextFrame();
518
560
  }
519
561
  computeGlobalDelta(cache) {
520
- this.deltaX = 0, this.deltaY = 0;
562
+ this.deltaX = 0, this.deltaY = 0, 0 === cache.lines.length && this.shadowPlaceHolder && (cache = this.shadowPlaceHolder.getFrameCache());
521
563
  const height = cache.height, actualHeight = cache.actualHeight, width = cache.lines.reduce(((w, item) => Math.max(w, item.actualWidth)), 0);
522
564
  "center" === cache.globalAlign ? this.deltaX = -width / 2 : "right" === cache.globalAlign && (this.deltaX = -width),
523
565
  "middle" === cache.verticalDirection ? this.deltaY = height / 2 - actualHeight / 2 : "bottom" === cache.verticalDirection && (this.deltaY = height - actualHeight);
@@ -556,7 +598,8 @@ export class RichTextEditPlugin {
556
598
  y: y1
557
599
  }, out);
558
600
  const {left: left, top: top} = this.pluginService.stage.window.getBoundingClientRect();
559
- out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
601
+ out.x += left, out.y += top, this.offsetLineBgAndShadowBounds(), this.offsetShadowRoot(),
602
+ this.editModule.moveTo(out.x, out.y, rt, this.curCursorIdx, this.selectionStartCursorIdx);
560
603
  }
561
604
  computedCursorPosByEvent(e, cache) {
562
605
  const p1 = this.getEventPosition(e), lineInfo = this.getLineByPoint(cache, p1);