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

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 (40) hide show
  1. package/cjs/graphic/group.js +1 -1
  2. package/cjs/graphic/group.js.map +1 -1
  3. package/cjs/graphic/richtext/line.js +11 -1
  4. package/cjs/graphic/richtext/line.js.map +1 -1
  5. package/cjs/graphic/richtext/paragraph.d.ts +8 -1
  6. package/cjs/graphic/richtext/paragraph.js +8 -20
  7. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  8. package/cjs/graphic/richtext.d.ts +2 -1
  9. package/cjs/graphic/richtext.js +6 -0
  10. package/cjs/graphic/richtext.js.map +1 -1
  11. package/cjs/interface/graphic/richText.d.ts +1 -0
  12. package/cjs/interface/graphic/richText.js.map +1 -1
  13. package/cjs/plugins/builtin-plugin/edit-module.js +2 -2
  14. package/cjs/plugins/builtin-plugin/edit-module.js.map +1 -1
  15. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
  16. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js +87 -73
  17. package/cjs/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  18. package/cjs/render/contributions/render/draw-contribution.js +1 -1
  19. package/cjs/render/contributions/render/draw-contribution.js.map +1 -1
  20. package/dist/index.es.js +81 -47
  21. package/es/graphic/group.js +1 -1
  22. package/es/graphic/group.js.map +1 -1
  23. package/es/graphic/richtext/line.js +11 -1
  24. package/es/graphic/richtext/line.js.map +1 -1
  25. package/es/graphic/richtext/paragraph.d.ts +8 -1
  26. package/es/graphic/richtext/paragraph.js +8 -20
  27. package/es/graphic/richtext/paragraph.js.map +1 -1
  28. package/es/graphic/richtext.d.ts +2 -1
  29. package/es/graphic/richtext.js +6 -0
  30. package/es/graphic/richtext.js.map +1 -1
  31. package/es/interface/graphic/richText.d.ts +1 -0
  32. package/es/interface/graphic/richText.js.map +1 -1
  33. package/es/plugins/builtin-plugin/edit-module.js +2 -2
  34. package/es/plugins/builtin-plugin/edit-module.js.map +1 -1
  35. package/es/plugins/builtin-plugin/richtext-edit-plugin.d.ts +3 -2
  36. package/es/plugins/builtin-plugin/richtext-edit-plugin.js +85 -73
  37. package/es/plugins/builtin-plugin/richtext-edit-plugin.js.map +1 -1
  38. package/es/render/contributions/render/draw-contribution.js +1 -1
  39. package/es/render/contributions/render/draw-contribution.js.map +1 -1
  40. package/package.json +3 -3
package/dist/index.es.js CHANGED
@@ -13587,6 +13587,9 @@ class Group extends Graphic {
13587
13587
  const bounds = this.doUpdateAABBBounds();
13588
13588
  this.addUpdateLayoutTag();
13589
13589
  application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);
13590
+ if (this.attribute.boundsMode === 'empty') {
13591
+ bounds.clear();
13592
+ }
13590
13593
  return bounds;
13591
13594
  }
13592
13595
  doUpdateLocalMatrix() {
@@ -17841,15 +17844,11 @@ function getFixedLRTB(left, right, top, bottom) {
17841
17844
  const topInt = Math.round(top);
17842
17845
  const rightInt = Math.round(right);
17843
17846
  const bottomInt = Math.round(bottom);
17844
- const _left = left > leftInt ? leftInt : leftInt - 0.5;
17845
- const _top = top > topInt ? topInt : topInt - 0.5;
17846
- const _right = rightInt > right ? rightInt : rightInt + 0.5;
17847
- const _bottom = bottomInt > bottom ? bottomInt : bottomInt + 0.5;
17848
17847
  return {
17849
- left: _left,
17850
- top: _top,
17851
- right: _right,
17852
- bottom: _bottom
17848
+ left: leftInt,
17849
+ top: topInt,
17850
+ right: rightInt,
17851
+ bottom: bottomInt
17853
17852
  };
17854
17853
  }
17855
17854
  class Paragraph {
@@ -17953,34 +17952,10 @@ class Paragraph {
17953
17952
  }
17954
17953
  }
17955
17954
  }
17956
- switch (this.character.script) {
17957
- case 'super':
17958
- baseline -= this.ascent * (1 / 3);
17959
- break;
17960
- case 'sub':
17961
- baseline += this.descent / 2;
17962
- break;
17963
- }
17964
- if (direction === 'vertical') {
17965
- ctx.save();
17966
- ctx.rotateAbout(Math.PI / 2, left, baseline);
17967
- ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2);
17968
- ctx.translate(left, baseline);
17969
- left = 0;
17970
- baseline = 0;
17971
- }
17972
- const fillStyle = ctx.fillStyle;
17973
- const globalAlpha = ctx.globalAlpha;
17974
- ctx.fillStyle = this.character.background;
17975
- if (this.character.backgroundOpacity !== void 0) {
17976
- ctx.globalAlpha = this.character.backgroundOpacity;
17977
- }
17978
17955
  const right = left + (this.widthOrigin || this.width);
17979
17956
  const bottom = top + lineHeight;
17980
17957
  const lrtb = getFixedLRTB(left, right, top, bottom);
17981
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top);
17982
- ctx.fillStyle = fillStyle;
17983
- ctx.globalAlpha = globalAlpha;
17958
+ return Object.assign(Object.assign({}, lrtb), { fillStyle: this.character.background, globalAlpha: this.character.backgroundOpacity });
17984
17959
  }
17985
17960
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
17986
17961
  let baseline = top + ascent;
@@ -18405,11 +18380,35 @@ class Line {
18405
18380
  }
18406
18381
  }
18407
18382
  }
18383
+ let fillStyle = '';
18384
+ let globalAlpha = -1;
18385
+ let currBgList = [];
18386
+ const bgList = [currBgList];
18408
18387
  this.paragraphs.forEach((paragraph, index) => {
18409
18388
  if (paragraph instanceof RichTextIcon) {
18410
18389
  return;
18411
18390
  }
18412
- paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);
18391
+ const data = paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);
18392
+ if (!data) {
18393
+ return;
18394
+ }
18395
+ if (!(fillStyle === data.fillStyle && globalAlpha === data.globalAlpha)) {
18396
+ currBgList = [];
18397
+ bgList.push(currBgList);
18398
+ fillStyle = data.fillStyle;
18399
+ globalAlpha = data.globalAlpha;
18400
+ }
18401
+ currBgList.push(data);
18402
+ });
18403
+ bgList.forEach(bg => {
18404
+ if (bg.length === 0) {
18405
+ return;
18406
+ }
18407
+ const data = bg[0];
18408
+ const end = bg[bg.length - 1];
18409
+ ctx.fillStyle = data.fillStyle;
18410
+ ctx.globalAlpha = data.globalAlpha;
18411
+ ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);
18413
18412
  });
18414
18413
  this.paragraphs.forEach((paragraph, index) => {
18415
18414
  if (paragraph instanceof RichTextIcon) {
@@ -18758,7 +18757,16 @@ class RichText extends Graphic {
18758
18757
  return tc.every(item => item.isComposing ||
18759
18758
  !(item.text && isString(item.text) && RichText.splitText(item.text).length > 1));
18760
18759
  }
18760
+ static splitEmoji(text) {
18761
+ return [...new Intl.Segmenter().segment(text)].map(x => x.segment);
18762
+ }
18761
18763
  static splitText(text) {
18764
+ try {
18765
+ const arr = this.splitEmoji(text);
18766
+ return arr;
18767
+ }
18768
+ catch (e) {
18769
+ }
18762
18770
  return Array.from(text);
18763
18771
  }
18764
18772
  static TransformTextConfig2SingleCharacter(textConfig) {
@@ -24414,7 +24422,9 @@ let DefaultDrawContribution = class DefaultDrawContribution {
24414
24422
  this._increaseRender(group, drawContext);
24415
24423
  return;
24416
24424
  }
24417
- if (this.useDirtyBounds && !isRectIntersect(group.AABBBounds, this.dirtyBounds, false)) {
24425
+ if (this.useDirtyBounds &&
24426
+ !isRectIntersect(group.AABBBounds, this.dirtyBounds, false) &&
24427
+ group.attribute.boundsMode !== 'empty') {
24418
24428
  return;
24419
24429
  }
24420
24430
  let nextM = parentMatrix;
@@ -27258,7 +27268,7 @@ class EditModule {
27258
27268
  const text = lastConfig.text;
27259
27269
  const textList = text ? Array.from(text.toString()) : [];
27260
27270
  for (let i = 0; i < textList.length; i++) {
27261
- textConfig.splice(i + configIdx, 0, Object.assign(Object.assign({ fill: 'black' }, lastConfig), { isComposing: false, text: textList[i] }));
27271
+ textConfig.splice(i + configIdx, 0, Object.assign(Object.assign(Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), { fill: 'black' }), lastConfig), { isComposing: false, text: textList[i] }));
27262
27272
  }
27263
27273
  this.currRt.setAttributes({ textConfig });
27264
27274
  const nextConfigIdx = configIdx + textList.length;
@@ -27604,6 +27614,12 @@ class RichTextEditPlugin {
27604
27614
  return;
27605
27615
  }
27606
27616
  const { lines } = cache;
27617
+ if (lines.length === 0) {
27618
+ return;
27619
+ }
27620
+ if (!lines[0].paragraphs || lines[0].paragraphs.length === 0) {
27621
+ return;
27622
+ }
27607
27623
  const totalCursorCount = lines.reduce((total, line) => total + line.paragraphs.length, 0) - 1;
27608
27624
  this.selectionRange(-0.1, totalCursorCount + 0.1);
27609
27625
  e.preventDefault();
@@ -27717,10 +27733,18 @@ class RichTextEditPlugin {
27717
27733
  return;
27718
27734
  }
27719
27735
  const { placeholder, placeholderColor = 'rgba(0, 0, 0, 0.6)', placeholderFontFamily, placeholderFontSize } = editOptions;
27720
- const shadow = this.currRt.shadowRoot || this.currRt.attachShadow();
27721
- this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, angle: 0, _debug_bounds: false, textConfig: [
27722
- { text: placeholder, fill: placeholderColor, fontFamily: placeholderFontFamily, fontSize: placeholderFontSize }
27723
- ] }));
27736
+ const shadow = this.getShadow(this.currRt);
27737
+ const textConfigItem = Object.assign(Object.assign({}, getDefaultCharacterConfig(this.currRt.attribute)), { text: placeholder });
27738
+ if (placeholderColor) {
27739
+ textConfigItem.fill = placeholderColor;
27740
+ }
27741
+ if (placeholderFontFamily) {
27742
+ textConfigItem.fontFamily = placeholderFontFamily;
27743
+ }
27744
+ if (placeholderFontSize) {
27745
+ textConfigItem.fontSize = placeholderFontSize;
27746
+ }
27747
+ this.shadowPlaceHolder = createRichText(Object.assign(Object.assign({}, this.currRt.attribute), { x: 0, y: 0, pickable: false, editable: false, editOptions: null, angle: 0, _debug_bounds: false, textConfig: [textConfigItem] }));
27724
27748
  shadow.add(this.shadowPlaceHolder);
27725
27749
  }
27726
27750
  tryShowInputBounds() {
@@ -27733,11 +27757,12 @@ class RichTextEditPlugin {
27733
27757
  return;
27734
27758
  }
27735
27759
  const { attribute } = this.currRt;
27736
- const b = this.currRt.AABBBounds;
27760
+ let b = this.currRt.AABBBounds;
27737
27761
  let h = b.height();
27738
27762
  if (!attribute.textConfig.length && this.editLine) {
27739
27763
  const { points } = this.editLine.attribute;
27740
27764
  h = points[1].y - points[0].y;
27765
+ b = getRichTextBounds(Object.assign({}, this.shadowPlaceHolder.attribute));
27741
27766
  }
27742
27767
  this.shadowBounds = this.shadowBounds || createRect({});
27743
27768
  this.shadowBounds.setAttributes({
@@ -27748,10 +27773,9 @@ class RichTextEditPlugin {
27748
27773
  fill: false,
27749
27774
  stroke: boundsStrokeWhenInput,
27750
27775
  lineWidth: 1,
27751
- boundsMode: 'empty',
27752
27776
  zIndex: -1
27753
27777
  });
27754
- const shadow = this.currRt.shadowRoot || this.currRt.attachShadow();
27778
+ const shadow = this.getShadow(this.currRt);
27755
27779
  shadow.add(this.shadowBounds);
27756
27780
  this.offsetLineBgAndShadowBounds();
27757
27781
  }
@@ -27763,7 +27787,7 @@ class RichTextEditPlugin {
27763
27787
  if (textConfig && textConfig.length) {
27764
27788
  return;
27765
27789
  }
27766
- if (!(editOptions && editOptions.placeholder)) {
27790
+ if (!(editOptions && editOptions.placeholder && editOptions.syncPlaceHolderToTextConfig)) {
27767
27791
  return;
27768
27792
  }
27769
27793
  const { placeholder } = editOptions;
@@ -27782,6 +27806,7 @@ class RichTextEditPlugin {
27782
27806
  application.global.addEventListener('keydown', this.handleKeyDown);
27783
27807
  }
27784
27808
  onFocus(e, data) {
27809
+ this.updateCbs && this.updateCbs.forEach(cb => cb('beforeOnfocus', this));
27785
27810
  this.deFocus(false);
27786
27811
  this.focusing = true;
27787
27812
  const target = e.target;
@@ -27790,7 +27815,7 @@ class RichTextEditPlugin {
27790
27815
  }
27791
27816
  this.currRt = target;
27792
27817
  RichTextEditPlugin.tryUpdateRichtext(target);
27793
- const shadowRoot = target.shadowRoot || target.attachShadow();
27818
+ const shadowRoot = this.getShadow(target);
27794
27819
  const cache = target.getFrameCache();
27795
27820
  if (!cache) {
27796
27821
  return;
@@ -27798,11 +27823,11 @@ class RichTextEditPlugin {
27798
27823
  this.computeGlobalDelta(cache);
27799
27824
  shadowRoot.setAttributes({ shadowRootIdx: 1, pickable: false, x: this.deltaX, y: this.deltaY });
27800
27825
  if (!this.editLine) {
27801
- const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black', boundsMode: 'empty' });
27826
+ const line = createLine({ x: 0, y: 0, lineWidth: 1, stroke: 'black' });
27802
27827
  this.addAnimateToLine(line);
27803
27828
  this.editLine = line;
27804
27829
  this.ticker.start(true);
27805
- const g = createGroup({ x: 0, y: 0, width: 0, height: 0, boundsMode: 'empty' });
27830
+ const g = createGroup({ x: 0, y: 0, width: 0, height: 0 });
27806
27831
  this.editBg = g;
27807
27832
  shadowRoot.add(this.editLine);
27808
27833
  shadowRoot.add(this.editBg);
@@ -27857,6 +27882,7 @@ class RichTextEditPlugin {
27857
27882
  if (!target) {
27858
27883
  return;
27859
27884
  }
27885
+ this.updateCbs && this.updateCbs.forEach(cb => cb('beforeDefocus', this, { trulyDeFocus }));
27860
27886
  if (trulyDeFocus) {
27861
27887
  this.trySyncPlaceholderToTextConfig();
27862
27888
  target.detachShadow();
@@ -27953,6 +27979,9 @@ class RichTextEditPlugin {
27953
27979
  };
27954
27980
  let line0Info = this.getLineByPoint(cache, startCursorPos);
27955
27981
  let line1Info = this.getLineByPoint(cache, endCursorPos);
27982
+ if (!line0Info || !line1Info) {
27983
+ return;
27984
+ }
27956
27985
  if (startCursorPos.y > endCursorPos.y ||
27957
27986
  (startCursorPos.y === endCursorPos.y && startCursorPos.x > endCursorPos.x)) {
27958
27987
  [startCursorPos, endCursorPos] = [endCursorPos, startCursorPos];
@@ -28023,6 +28052,11 @@ class RichTextEditPlugin {
28023
28052
  this.editBg.setAttributes({ fill: 'transparent' });
28024
28053
  }
28025
28054
  }
28055
+ getShadow(rt) {
28056
+ const sr = rt.shadowRoot || rt.attachShadow();
28057
+ sr.setAttributes({ boundsMode: 'empty' });
28058
+ return sr;
28059
+ }
28026
28060
  getLineByPoint(cache, p1) {
28027
28061
  let lineInfo = cache.lines[0];
28028
28062
  for (let i = 0; i < cache.lines.length; i++) {
@@ -66,7 +66,7 @@ export class Group extends Graphic {
66
66
  application.graphicService.beforeUpdateAABBBounds(this, this.stage, !0, this._AABBBounds);
67
67
  const selfChange = this.shouldSelfChangeUpdateAABBBounds(), bounds = this.doUpdateAABBBounds();
68
68
  return this.addUpdateLayoutTag(), application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange),
69
- bounds;
69
+ "empty" === this.attribute.boundsMode && bounds.clear(), bounds;
70
70
  }
71
71
  doUpdateLocalMatrix() {
72
72
  const {x: x = DefaultTransform.x, y: y = DefaultTransform.y, dx: dx = DefaultTransform.dx, dy: dy = DefaultTransform.dy, scaleX: scaleX = DefaultTransform.scaleX, scaleY: scaleY = DefaultTransform.scaleY, angle: angle = DefaultTransform.angle, postMatrix: postMatrix} = this.attribute;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,CAAN,IAAY,yBAKX;AALD,W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C,oBAAoB,CAAC,CAAC;QAC1E,OAAO,YAAY,CAAC;IACtB,CAAC;IAEO,eAAe,CAA0B,IAAY,EAAE,IAAc;QAC3E,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;IASD,mBAAmB,CACjB,WAAmB,EACnB,UAAkC,EAClC,WAAc;QAEd,IAAI,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,WAAW,CAAa,CAAC;QAC5D,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;SACnC;aAAM;YACL,OAAO,GAAG,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,UAAiB,CAAC,CAAC;YAC7E,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACnB;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AArXM,yBAAmB,GAAG,mBAAmB,CAAC;AAwXnD,MAAM,UAAU,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"group.js","sourcesContent":["import type { IAABBBounds, Matrix } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/group.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAG5C,MAAM,CAAN,IAAY,yBAKX;AALD,WAAY,yBAAyB;IAEnC,qFAAc,CAAA;IAEd,qFAAc,CAAA;AAChB,CAAC,EALW,yBAAyB,KAAzB,yBAAyB,QAKpC;AAED,MAAM,OAAO,KAAM,SAAQ,OAA+B;IAWxD,YAAY,MAA8B;QACxC,KAAK,CAAC,MAAM,CAAC,CAAC;QAXhB,SAAI,GAAgB,OAAO,CAAC;QAC5B,WAAM,GAAQ,IAAI,CAAC;QACnB,gBAAW,GAAY,IAAI,CAAC;QAU1B,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC,aAAa,CAAC;IAEjD,CAAC;IAED,OAAO,CAAC,IAAiB;QACvB,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,S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AM;YACL,OAAO,GAAG,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,UAAiB,CAAC,CAAC;YAC7E,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC;YAC3B,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SACnB;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,OAAO,IAAI,KAAK,mBAAM,IAAI,CAAC,SAAS,EAAG,CAAC;IAC1C,CAAC;IAED,oBAAoB;QAClB,OAAO,KAAK,CAAC,mBAAmB,CAAC;IACnC,CAAC;;AAzXM,yBAAmB,GAAG,mBAAmB,CAAC;AA4XnD,MAAM,UAAU,WAAW,CAAC,UAAkC;IAC5D,OAAO,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","file":"group.js","sourcesContent":["import type { IAABBBounds, Matrix } from '@visactor/vutils';\n// eslint-disable-next-line no-duplicate-imports\nimport { Point } from '@visactor/vutils';\nimport { application } from '../application';\nimport type {\n IStage,\n GraphicAttributeMap,\n INode,\n IGraphic,\n ITheme,\n IThemeSpec,\n ILayer,\n GraphicType\n} from '../interface';\nimport type { IGroup, IGroupGraphicAttribute } from '../interface/graphic/group';\nimport { Graphic, NOWORK_ANIMATE_ATTR } from './graphic';\nimport { getTheme, Theme } from './theme';\nimport { UpdateTag, IContainPointMode } from '../common/enums';\nimport { GROUP_NUMBER_TYPE } from './constants';\nimport { DefaultTransform } from './config';\n\n// Group更新AABBBounds的策略\nexport enum GroupUpdateAABBBoundsMode {\n // Group较少的情况,不会批量设置所有父层的tag,而是每次都查找\n LESS_GROUP = 0,\n // Group较多的情况,每次都会设置tag到最顶层\n MORE_GROUP = 1\n}\n\nexport class Group extends Graphic<IGroupGraphicAttribute> implements IGroup {\n type: GraphicType = 'group';\n parent: any = null;\n isContainer: boolean = true;\n // 子元素的更新标记\n declare _childUpdateTag: number;\n\n declare theme?: ITheme;\n\n static NOWORK_ANIMATE_ATTR = NOWORK_ANIMATE_ATTR;\n\n constructor(params: IGroupGraphicAttribute) {\n super(params);\n this.numberType = GROUP_NUMBER_TYPE;\n this._childUpdateTag = UpdateTag.UPDATE_BOUNDS;\n // this.theme = new Theme();\n }\n\n setMode(mode: '2d' | '3d') {\n mode === '3d' ? this.set3dMode() : this.set2dMode();\n }\n\n set3dMode() {\n this.in3dMode = true;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('3d');\n // });\n }\n set2dMode() {\n this.in3dMode = false;\n // this.forEachChildren((c: IGraphic) => {\n // c.setMode('2d');\n // });\n }\n\n setTheme(t: IThemeSpec) {\n if (!this.theme) {\n this.theme = new Theme();\n }\n return this.theme.setTheme(t, this);\n }\n\n createTheme() {\n if (!this.theme) {\n this.theme = new Theme();\n }\n }\n\n visibleAll(visible: boolean) {\n this.setAttribute('visible', visible);\n this.forEachChildren((item: IGraphic) => {\n if (item.isContainer && (item as any).visibleAll) {\n (item as any).visibleAll(visible);\n } else {\n item.setAttribute('visible', visible);\n }\n });\n }\n\n hideAll() {\n this.visibleAll(false);\n }\n\n showAll() {\n this.visibleAll(true);\n }\n\n /**\n * 是否包含某个点(点需要是全局坐标系)\n * group containsPoint 只需要判断bounds\n * TODO: group的shape判断\n * @param x\n * @param y\n * @param mode\n * @returns\n */\n containsPoint(x: number, y: number, mode: IContainPointMode): boolean {\n if (mode === IContainPointMode.GLOBAL) {\n // 转换x,y更精准\n const point = new Point(x, y);\n if (this.parent) {\n this.parent.globalTransMatrix.transformPoint(point, point);\n }\n return this.AABBBounds.contains(point.x, point.y);\n }\n return this.AABBBounds.contains(x, y);\n }\n\n shouldUpdateAABBBounds(): boolean {\n // 检索自己是否需要更新\n if (super.shouldUpdateAABBBounds()) {\n return true;\n }\n // 检索叶子节点是否有更新(如果children是叶子节点的话)\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return true;\n }\n return false;\n // // 检索是否子group需要更新\n // let needUpdate = false;\n // this.forEachChildren((node: IGraphic) => {\n // // 只查找group层级\n // if (node.isContainer && (node as Group).shouldUpdateAABBBounds()) {\n // needUpdate = true;\n // return true;\n // }\n // return false;\n // });\n // return needUpdate;\n }\n\n protected tryUpdateAABBBounds(): IAABBBounds {\n if (!this.shouldUpdateAABBBounds()) {\n return this._AABBBounds;\n }\n application.graphicService.beforeUpdateAABBBounds(this, this.stage, true, this._AABBBounds);\n const selfChange = this.shouldSelfChangeUpdateAABBBounds();\n const bounds = this.doUpdateAABBBounds();\n this.addUpdateLayoutTag();\n application.graphicService.afterUpdateAABBBounds(this, this.stage, this._AABBBounds, this, selfChange);\n // 直接返回空Bounds,但是前面的流程还是要走\n if (this.attribute.boundsMode === 'empty') {\n bounds.clear();\n }\n return bounds;\n }\n\n /**\n * 大部分group不需要更新matrix,这里特殊优化一下\n * 更新局部matrix的具体函数\n */\n protected doUpdateLocalMatrix() {\n const {\n x = DefaultTransform.x,\n y = DefaultTransform.y,\n dx = DefaultTransform.dx,\n dy = DefaultTransform.dy,\n scaleX = DefaultTransform.scaleX,\n scaleY = DefaultTransform.scaleY,\n angle = DefaultTransform.angle,\n postMatrix\n } = this.attribute;\n if (x === 0 && y === 0 && dx === 0 && dy === 0 && scaleX === 1 && scaleY === 1 && angle === 0 && !postMatrix) {\n this._transMatrix.reset();\n return;\n }\n return super.doUpdateLocalMatrix();\n }\n\n getGraphicTheme(): Required<IGroupGraphicAttribute> {\n return getTheme(this).group;\n }\n\n protected updateAABBBounds(\n attribute: IGroupGraphicAttribute,\n groupTheme: Required<IGroupGraphicAttribute>,\n aabbBounds: IAABBBounds\n ) {\n const originalAABBBounds = aabbBounds; // fix aabbbounds update error in flex layout\n aabbBounds = aabbBounds.clone();\n\n const { width, height, path, clip = groupTheme.clip } = attribute;\n // 添加自身的fill或者clip\n if (path && path.length) {\n path.forEach(g => {\n aabbBounds.union(g.AABBBounds);\n });\n } else if (width != null && height != null) {\n aabbBounds.set(0, 0, Math.max(0, width), Math.max(0, height)); // fix bounds set when auto size in vtable\n }\n if (!clip) {\n // 添加子节点\n this.forEachChildren((node: IGraphic) => {\n aabbBounds.union(node.AABBBounds);\n });\n // 如果没有clip的话,还需要加一下scroll\n const { scrollX = 0, scrollY = 0 } = attribute;\n aabbBounds.translate(scrollX, scrollY);\n }\n application.graphicService.updateTempAABBBounds(aabbBounds);\n\n application.graphicService.transformAABBBounds(attribute, aabbBounds, groupTheme, false, this);\n\n originalAABBBounds.copy(aabbBounds);\n return originalAABBBounds;\n }\n\n protected doUpdateAABBBounds(): IAABBBounds {\n this.updateAABBBoundsStamp++;\n const bounds = super.doUpdateAABBBounds();\n\n // 更新bounds之后需要设置父节点,否则tag丢失\n this.parent && this.parent.addChildUpdateBoundTag();\n this._emitCustomEvent('AAABBBoundsChange');\n\n return bounds;\n }\n\n protected clearUpdateBoundTag() {\n this._updateTag &= UpdateTag.CLEAR_BOUNDS;\n this._childUpdateTag &= UpdateTag.CLEAR_BOUNDS;\n }\n\n addUpdateBoundTag() {\n this._updateTag |= UpdateTag.UPDATE_BOUNDS; // for bounds\n if (this.parent) {\n this.parent.addChildUpdateBoundTag();\n }\n }\n\n addChildUpdateBoundTag() {\n // 如果已经设置过updateTag,那就不需要设置了\n if (this._childUpdateTag & UpdateTag.UPDATE_BOUNDS) {\n return;\n }\n // 如果没有设置过,那么继续向上设置\n this._childUpdateTag |= UpdateTag.UPDATE_BOUNDS;\n this.parent && this.parent.addChildUpdateBoundTag();\n }\n\n getTheme() {\n return this.theme.getTheme(this);\n }\n\n /* 场景树结构 */\n incrementalAppendChild(node: INode): INode | null {\n const data = super.appendChild(node);\n if (this.stage && data) {\n (data as unknown as this).stage = this.stage;\n (data as unknown as this).layer = this.layer;\n }\n this.addUpdateBoundTag();\n application.graphicService.onAddIncremental(node as unknown as IGraphic, this, this.stage);\n return data;\n }\n incrementalClearChild(): void {\n super.removeAllChild();\n this.addUpdateBoundTag();\n application.graphicService.onClearIncremental(this, this.stage);\n return;\n }\n\n protected _updateChildToStage(child: IGraphic) {\n if (this.stage && child) {\n child.setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return child;\n }\n // TODO 代码优化\n appendChild(node: INode, addStage: boolean = true): INode | null {\n const data = super.appendChild(node);\n if (addStage && this.stage && data) {\n (data as unknown as this).setStage(this.stage, this.layer);\n }\n this.addUpdateBoundTag();\n return data;\n }\n insertBefore(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertBefore(newNode, referenceNode) as undefined as IGraphic);\n }\n insertAfter(newNode: INode, referenceNode: INode): INode | null {\n return this._updateChildToStage(super.insertAfter(newNode, referenceNode) as undefined as IGraphic);\n }\n insertInto(newNode: INode, idx: number): INode | null {\n return this._updateChildToStage(super.insertInto(newNode, idx) as undefined as IGraphic);\n }\n\n removeChild(child: IGraphic): IGraphic {\n const data = super.removeChild(child);\n child.stage = null;\n application.graphicService.onRemove(child);\n this.addUpdateBoundTag();\n return data as IGraphic;\n }\n\n removeAllChild(deep: boolean = false): void {\n this.forEachChildren((child: IGraphic) => {\n application.graphicService.onRemove(child);\n if (deep && child.isContainer) {\n child.removeAllChild(deep);\n }\n });\n super.removeAllChild();\n this.addUpdateBoundTag();\n }\n\n setStage(stage?: IStage, layer?: ILayer) {\n if (this.stage !== stage) {\n this.stage = stage;\n this.layer = layer;\n this.setStageToShadowRoot(stage, layer);\n this._onSetStage && this._onSetStage(this, stage, layer);\n application.graphicService.onSetStage(this, stage);\n this.forEachChildren(item => {\n (item as any).setStage(stage, this.layer);\n });\n }\n }\n /**\n * 更新位置tag,包括全局tag和局部tag\n */\n addUpdatePositionTag() {\n super.addUpdatePositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * 更新全局位置tag\n */\n addUpdateGlobalPositionTag() {\n super.addUpdateGlobalPositionTag();\n // 批量设置底层group的global tag\n this.forEachChildren((g: Group) => {\n if (g.isContainer) {\n g.addUpdateGlobalPositionTag();\n }\n });\n }\n /**\n * group更新全局的transMatrix\n * @param clearTag\n * @returns\n */\n protected tryUpdateGlobalTransMatrix(clearTag: boolean = true): Matrix {\n if (this.shouldUpdateGlobalMatrix()) {\n if (!this._globalTransMatrix) {\n this._globalTransMatrix = this.parent\n ? (this.parent as IGroup).globalTransMatrix.clone()\n : this.transMatrix.clone();\n } else if (this.parent) {\n const m = (this.parent as IGroup).globalTransMatrix;\n this._globalTransMatrix.setValue(m.a, m.b, m.c, m.d, m.e, m.f);\n }\n this.doUpdateGlobalMatrix();\n clearTag && this.clearUpdateGlobalPositionTag();\n }\n return this._globalTransMatrix;\n }\n /**\n * 查找自身更新global的tag,如果存在,就更新\n * @returns\n */\n shouldUpdateGlobalMatrix(): boolean {\n const shouldUpdate = !!(this._updateTag & UpdateTag.UPDATE_GLOBAL_MATRIX);\n return shouldUpdate;\n }\n\n private _getChildByName<T extends INode = INode>(name: string, deep?: boolean): T | null {\n return this.find(node => node.name === name, deep);\n }\n\n /**\n * if graphic exist then update attributes, otherwise create a new instance\n * @param graphicName the name of graphic\n * @param attributes the attributes of graphic\n * @param graphicType the type of graphic\n * @returns the graphic instance\n */\n createOrUpdateChild<T extends keyof GraphicAttributeMap>(\n graphicName: string,\n attributes: GraphicAttributeMap[T],\n graphicType: T\n ): INode {\n let graphic = this._getChildByName(graphicName) as IGraphic;\n if (graphic) {\n graphic.setAttributes(attributes);\n } else {\n graphic = application.graphicService.creator[graphicType](attributes as any);\n graphic.name = graphicName;\n this.add(graphic);\n }\n\n return graphic;\n }\n\n clone() {\n return new Group({ ...this.attribute });\n }\n\n getNoWorkAnimateAttr(): Record<string, number> {\n return Group.NOWORK_ANIMATE_ATTR;\n }\n}\n\nexport function createGroup(attributes: IGroupGraphicAttribute): IGroup {\n return new Group(attributes);\n}\n"]}
@@ -67,8 +67,18 @@ export default class Line {
67
67
  paragraph.ellipsis = "hide", otherParagraphWidth += paragraph.width;
68
68
  }
69
69
  }
70
+ let fillStyle = "", globalAlpha = -1, currBgList = [];
71
+ const bgList = [ currBgList ];
70
72
  this.paragraphs.forEach(((paragraph, index) => {
71
- paragraph instanceof RichTextIcon || paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
73
+ if (paragraph instanceof RichTextIcon) return;
74
+ const data = paragraph.drawBackground(ctx, y, this.ascent, x, 0 === index, this.textAlign, this.height);
75
+ data && (fillStyle === data.fillStyle && globalAlpha === data.globalAlpha || (currBgList = [],
76
+ bgList.push(currBgList), fillStyle = data.fillStyle, globalAlpha = data.globalAlpha),
77
+ currBgList.push(data));
78
+ })), bgList.forEach((bg => {
79
+ if (0 === bg.length) return;
80
+ const data = bg[0], end = bg[bg.length - 1];
81
+ ctx.fillStyle = data.fillStyle, ctx.globalAlpha = data.globalAlpha, ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);
72
82
  })), this.paragraphs.forEach(((paragraph, index) => {
73
83
  if (paragraph instanceof RichTextIcon) return paragraph.setAttributes({
74
84
  x: x + paragraph._x,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B5G,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EACd,OAAe,EACf,UAAwC,EACxC,SAAoC,EACpC,UAAmB;QAEnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,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,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,YAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/graphic/richtext/line.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AA8B5G,MAAM,CAAC,OAAO,OAAO,IAAI;IAevB,YACE,IAAY,EACZ,KAAa,EACb,QAAgB,EAChB,MAAc,EAC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S,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,MAAM;aACP;iBAAM,IAAI,aAAa,IAAI,IAAI,CAAC,UAAU,GAAG,mBAAmB,GAAG,SAAS,CAAC,KAAK,EAAE;gBAEnF,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC/B,SAAS,CAAC,aAAa,GAAG,aAAa,CAAC;gBACxC,SAAS,CAAC,2BAA2B,GAAG,IAAI,CAAC,UAAU,GAAG,mBAAmB,CAAC;gBAE9E,MAAM;aACP;iBAAM;gBAEL,SAAS,CAAC,QAAQ,GAAG,MAAM,CAAC;gBAC5B,mBAAmB,IAAI,SAAS,CAAC,KAAK,CAAC;aACxC;SACF;QAED,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE;YAC3C,IAAI,SAAS,YAAY,YAAY,EAAE;gBACrC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC;aAC1B;iBAAM;gBACL,KAAK,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACvD;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","file":"line.js","sourcesContent":["// import { IContext2d } from '../../IContext';\nimport type { IContext2d, IRichTextIcon } from '../../interface';\nimport { RichTextIcon } from './icon';\nimport Paragraph from './paragraph';\nimport { applyFillStyle, applyStrokeStyle, DIRECTION_KEY, measureTextCanvas, regFirstSpace } from './utils';\n\n/**\n * 部分代码参考 https://github.com/danielearwicker/carota/\n * The MIT License (MIT)\n\n \"Carota\" - Copyright (c) 2013 Daniel Earwicker\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n */\n\n// 行\n// 参考carota\n// https://github.com/danielearwicker/carota/blob/master/src/line.js\nexport default class Line {\n left: number;\n top: number;\n width: number;\n height: number;\n baseline: number;\n ascent: number;\n descent: number;\n paragraphs: (Paragraph | RichTextIcon)[];\n actualWidth: number;\n blankWidth: number;\n textAlign: string;\n direction: 'horizontal' | 'vertical';\n directionKey: { width: string; height: string; left: string; x: string; y: string };\n\n constructor(\n left: number,\n width: number,\n baseline: number,\n ascent: number,\n descent: number,\n lineBuffer: (Paragraph | RichTextIcon)[],\n direction: 'horizontal' | 'vertical',\n isWidthMax: boolean\n ) {\n this.left = left;\n this.width = width;\n this.baseline = baseline;\n this.ascent = ascent;\n this.descent = descent;\n // this.height = ascent + descent;\n this.top = baseline - ascent;\n this.paragraphs = lineBuffer.map(p => p);\n this.textAlign =\n (this.paragraphs[0] instanceof RichTextIcon\n ? this.paragraphs[0].attribute.textAlign\n : this.paragraphs[0].character.textAlign) || 'left'; // 对齐方式选择第一个paragraph属性\n this.direction = direction;\n this.directionKey = DIRECTION_KEY[this.direction];\n\n this.actualWidth = 0;\n let maxHeight = 0;\n this.paragraphs.forEach((word, index) => {\n // 每行中第一个字符不能是空格\n if (index === 0 && word instanceof Paragraph) {\n const result = regFirstSpace.exec(word.text);\n if (result?.index !== 0) {\n word.text = word.text.slice(result?.index);\n word.updateWidth();\n }\n }\n this.actualWidth += word[this.directionKey.width];\n maxHeight = Math.max(word[this.directionKey.height], maxHeight);\n });\n this.height = maxHeight;\n\n this.blankWidth = !isWidthMax ? this.width - this.actualWidth : 0;\n\n this.calcOffset(width, isWidthMax);\n }\n\n calcOffset(width: number, isWidthMax: boolean) {\n // 处理对齐方式,计算左侧偏移距离和字符之间间距\n const directionKey = this.directionKey;\n const maxHeight = this.height;\n let x = this.left;\n let spacing = 0;\n if (this.actualWidth < width && !isWidthMax) {\n if (this.textAlign === 'right' || this.textAlign === 'end') {\n x = width - this.actualWidth;\n } else if (this.textAlign === 'center') {\n x = (width - this.actualWidth) / 2;\n } else if (this.textAlign === 'justify') {\n if (this.paragraphs.length < 2) {\n // 只有一个paragraph两端对齐居中显示\n x = (width - this.actualWidth) / 2;\n } else {\n spacing = (width - this.actualWidth) / (this.paragraphs.length - 1);\n }\n }\n }\n\n this.paragraphs.map(function (paragraph) {\n if (paragraph instanceof RichTextIcon) {\n // paragraph.setAttribute(directionKey.x, x);\n paragraph['_' + directionKey.x] = x;\n x += paragraph[directionKey.width] + spacing;\n // 处理纵向对齐\n paragraph['_' + directionKey.y] =\n paragraph.attribute.textBaseline === 'top'\n ? 0\n : paragraph.attribute.textBaseline === 'bottom'\n ? maxHeight - paragraph.height\n : (maxHeight - paragraph.height) / 2;\n } else {\n paragraph[directionKey.left] = x;\n x += paragraph[directionKey.width] + spacing;\n }\n });\n }\n\n draw(\n ctx: IContext2d,\n lastLine: boolean,\n x: number,\n y: number,\n drawEllipsis: boolean | string,\n drawIcon: (icon: IRichTextIcon, context: IContext2d, x: number, y: number, baseline: number) => void\n ) {\n if (drawEllipsis && (lastLine || this.paragraphs.some(p => (p as Paragraph).overflow))) {\n // 检测是否需要省略号,因为会有多行同时省略的情况\n let emptyOverflow = true;\n let skipEllipsis = false;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n emptyOverflow = emptyOverflow && (paragraph as Paragraph).text === '';\n } else {\n if (emptyOverflow) {\n skipEllipsis = true;\n break;\n }\n }\n }\n\n // 处理省略号\n let otherParagraphWidth = 0;\n if (!skipEllipsis) {\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if ((paragraph as Paragraph).overflow) {\n if ((paragraph as Paragraph).text === '') {\n break;\n }\n continue;\n }\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n if (this.direction === 'vertical' && paragraph.direction !== 'vertical') {\n paragraph.verticalEllipsis = true;\n break;\n }\n const ellipsis = drawEllipsis === true ? '...' : drawEllipsis || '';\n paragraph.ellipsisStr = ellipsis;\n // const { width } = measureText('...', paragraph.style);\n const { width } = measureTextCanvas(ellipsis, paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n lastLine && (paragraph.ellipsis = 'add');\n\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n }\n }\n\n // 绘制背景\n // 属性相同的背景,合并绘制\n let fillStyle = '';\n let globalAlpha = -1;\n let currBgList: {\n fillStyle: string;\n globalAlpha: number;\n left: number;\n top: number;\n right: number;\n bottom: number;\n }[] = [];\n const bgList = [currBgList];\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n return;\n }\n const data = paragraph.drawBackground(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n if (!data) {\n return;\n }\n if (!(fillStyle === data.fillStyle && globalAlpha === data.globalAlpha)) {\n currBgList = [];\n bgList.push(currBgList);\n fillStyle = data.fillStyle;\n globalAlpha = data.globalAlpha;\n }\n currBgList.push(data);\n });\n // 绘制背景\n bgList.forEach(bg => {\n if (bg.length === 0) {\n return;\n }\n const data = bg[0];\n const end = bg[bg.length - 1];\n ctx.fillStyle = data.fillStyle;\n ctx.globalAlpha = data.globalAlpha;\n ctx.fillRect(data.left, data.top, end.right - data.left, end.bottom - data.top);\n });\n\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n // 更新icon位置\n paragraph.setAttributes({\n x: x + paragraph._x,\n y: y + paragraph._y\n });\n\n // 绘制icon\n drawIcon(paragraph, ctx, x + paragraph._x, y + paragraph._y, this.ascent);\n return;\n }\n const b = {\n x1: this.left,\n y1: this.top,\n x2: this.left + this.actualWidth,\n y2: this.top + this.height\n };\n applyStrokeStyle(ctx, paragraph.character);\n // 下面绘制underline和line-through时需要设置FillStyle\n applyFillStyle(ctx, paragraph.character, b);\n paragraph.draw(ctx, y, this.ascent, x, index === 0, this.textAlign, this.height);\n });\n }\n\n getWidthWithEllips(ellipsis: string) {\n // 处理省略号\n let otherParagraphWidth = 0;\n for (let i = this.paragraphs.length - 1; i >= 0; i--) {\n const paragraph = this.paragraphs[i];\n if (paragraph instanceof RichTextIcon) {\n break; // todo: 处理最后为图标,显示省略号的情况\n }\n\n const { width } = measureTextCanvas(ellipsis, paragraph.character);\n const ellipsisWidth = width || 0;\n if (ellipsisWidth <= this.blankWidth + otherParagraphWidth) {\n // 省略号可以直接接在后面paragraph\n paragraph.ellipsis = 'add';\n paragraph.ellipsisWidth = ellipsisWidth;\n break;\n } else if (ellipsisWidth <= this.blankWidth + otherParagraphWidth + paragraph.width) {\n // 省略号需要替换paragraph中的字符\n paragraph.ellipsis = 'replace';\n paragraph.ellipsisWidth = ellipsisWidth;\n paragraph.ellipsisOtherParagraphWidth = this.blankWidth + otherParagraphWidth;\n\n break;\n } else {\n // 省略号需要的width大于paragraph的width,隐藏paragraph,向前搜索\n paragraph.ellipsis = 'hide';\n otherParagraphWidth += paragraph.width;\n }\n }\n\n let width = 0;\n // 正常绘制\n this.paragraphs.forEach((paragraph, index) => {\n if (paragraph instanceof RichTextIcon) {\n width += paragraph.width; // todo: 处理direction\n } else {\n width += paragraph.getWidthWithEllips(this.direction);\n }\n });\n\n return width;\n }\n}\n"]}
@@ -24,7 +24,14 @@ export default class Paragraph {
24
24
  overflow?: boolean;
25
25
  constructor(text: string, newLine: boolean, character: IRichTextParagraphCharacter);
26
26
  updateWidth(): void;
27
- drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
27
+ drawBackground(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): {
28
+ fillStyle: string;
29
+ globalAlpha: number;
30
+ left: number;
31
+ top: number;
32
+ right: number;
33
+ bottom: number;
34
+ };
28
35
  draw(ctx: IContext2d, top: number, ascent: number, deltaLeft: number, isLineFirst: boolean, textAlign: string, lineHeight: number): void;
29
36
  getWidthWithEllips(direction: string): number;
30
37
  }
@@ -3,12 +3,11 @@ import { calculateLineHeight } from "../../common/utils";
3
3
  import { measureTextCanvas, getStrByWithCanvas } from "./utils";
4
4
 
5
5
  function getFixedLRTB(left, right, top, bottom) {
6
- const leftInt = Math.round(left), topInt = Math.round(top), rightInt = Math.round(right), bottomInt = Math.round(bottom);
7
6
  return {
8
- left: left > leftInt ? leftInt : leftInt - .5,
9
- top: top > topInt ? topInt : topInt - .5,
10
- right: rightInt > right ? rightInt : rightInt + .5,
11
- bottom: bottomInt > bottom ? bottomInt : bottomInt + .5
7
+ left: Math.round(left),
8
+ top: Math.round(top),
9
+ right: Math.round(right),
10
+ bottom: Math.round(bottom)
12
11
  };
13
12
  }
14
13
 
@@ -51,22 +50,11 @@ export default class Paragraph {
51
50
  }
52
51
  }
53
52
  }
54
- switch (this.character.script) {
55
- case "super":
56
- baseline -= this.ascent * (1 / 3);
57
- break;
58
-
59
- case "sub":
60
- baseline += this.descent / 2;
61
- }
62
- "vertical" === direction && (ctx.save(), ctx.rotateAbout(Math.PI / 2, left, baseline),
63
- ctx.translate(-this.heightOrigin || -this.lineHeight / 2, -this.descent / 2), ctx.translate(left, baseline),
64
- left = 0, baseline = 0);
65
- const fillStyle = ctx.fillStyle, globalAlpha = ctx.globalAlpha;
66
- ctx.fillStyle = this.character.background, void 0 !== this.character.backgroundOpacity && (ctx.globalAlpha = this.character.backgroundOpacity);
67
53
  const lrtb = getFixedLRTB(left, left + (this.widthOrigin || this.width), top, top + lineHeight);
68
- ctx.fillRect(lrtb.left, lrtb.top, lrtb.right - lrtb.left, lrtb.bottom - lrtb.top),
69
- ctx.fillStyle = fillStyle, ctx.globalAlpha = globalAlpha;
54
+ return Object.assign(Object.assign({}, lrtb), {
55
+ fillStyle: this.character.background,
56
+ globalAlpha: this.character.backgroundOpacity
57
+ });
70
58
  }
71
59
  draw(ctx, top, ascent, deltaLeft, isLineFirst, textAlign, lineHeight) {
72
60
  let baseline = top + ascent, text = this.text, left = this.left + deltaLeft;