@visactor/vrender-core 0.21.0-vstory.1 → 0.21.0-vstory.3

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 (160) hide show
  1. package/cjs/animate/Ticker/default-ticker.d.ts +2 -1
  2. package/cjs/animate/Ticker/default-ticker.js +6 -3
  3. package/cjs/animate/Ticker/default-ticker.js.map +1 -1
  4. package/cjs/animate/custom-animate.d.ts +2 -0
  5. package/cjs/animate/custom-animate.js +11 -2
  6. package/cjs/animate/custom-animate.js.map +1 -1
  7. package/cjs/animate/easing.d.ts +1 -0
  8. package/cjs/animate/easing.js +3 -0
  9. package/cjs/animate/easing.js.map +1 -1
  10. package/cjs/animate/index.d.ts +1 -0
  11. package/cjs/animate/index.js +1 -1
  12. package/cjs/animate/index.js.map +1 -1
  13. package/cjs/canvas/util.js +1 -2
  14. package/cjs/color-string/store.js +2 -1
  15. package/cjs/common/color-utils.js +2 -2
  16. package/cjs/common/color-utils.js.map +1 -1
  17. package/cjs/common/utils.d.ts +1 -0
  18. package/cjs/common/utils.js +9 -2
  19. package/cjs/common/utils.js.map +1 -1
  20. package/cjs/core/contributions/textMeasure/AtextMeasure.d.ts +56 -4
  21. package/cjs/core/contributions/textMeasure/AtextMeasure.js +119 -18
  22. package/cjs/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  23. package/cjs/core/contributions/textMeasure/layout.d.ts +8 -3
  24. package/cjs/core/contributions/textMeasure/layout.js +55 -44
  25. package/cjs/core/contributions/textMeasure/layout.js.map +1 -1
  26. package/cjs/core/stage.d.ts +5 -0
  27. package/cjs/core/stage.js +20 -7
  28. package/cjs/core/stage.js.map +1 -1
  29. package/cjs/event/event-manager.d.ts +1 -0
  30. package/cjs/event/event-manager.js +1 -1
  31. package/cjs/event/event-manager.js.map +1 -1
  32. package/cjs/event/event-system.js +2 -1
  33. package/cjs/event/event-system.js.map +1 -1
  34. package/cjs/graphic/config.d.ts +1 -1
  35. package/cjs/graphic/config.js +7 -3
  36. package/cjs/graphic/config.js.map +1 -1
  37. package/cjs/graphic/node-tree.js +3 -3
  38. package/cjs/graphic/node-tree.js.map +1 -1
  39. package/cjs/graphic/richtext/line.js +9 -2
  40. package/cjs/graphic/richtext/line.js.map +1 -1
  41. package/cjs/graphic/richtext/paragraph.js +4 -3
  42. package/cjs/graphic/richtext/paragraph.js.map +1 -1
  43. package/cjs/graphic/richtext/utils.d.ts +2 -1
  44. package/cjs/graphic/richtext/utils.js +5 -3
  45. package/cjs/graphic/richtext/utils.js.map +1 -1
  46. package/cjs/graphic/text.d.ts +11 -11
  47. package/cjs/graphic/text.js +102 -168
  48. package/cjs/graphic/text.js.map +1 -1
  49. package/cjs/graphic/wrap-text.js +16 -4
  50. package/cjs/graphic/wrap-text.js.map +1 -1
  51. package/cjs/interface/animate.d.ts +1 -38
  52. package/cjs/interface/animate.js.map +1 -1
  53. package/cjs/interface/context.d.ts +1 -0
  54. package/cjs/interface/context.js.map +1 -1
  55. package/cjs/interface/graphic/text.d.ts +11 -3
  56. package/cjs/interface/graphic/text.js +6 -1
  57. package/cjs/interface/graphic/text.js.map +1 -1
  58. package/cjs/interface/graphic.d.ts +1 -0
  59. package/cjs/interface/graphic.js.map +1 -1
  60. package/cjs/interface/stage.d.ts +2 -0
  61. package/cjs/interface/stage.js.map +1 -1
  62. package/cjs/interface/text.d.ts +9 -1
  63. package/cjs/interface/text.js.map +1 -1
  64. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.d.ts +16 -0
  65. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js +48 -0
  66. package/cjs/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -0
  67. package/cjs/render/contributions/render/contributions/arc-contribution-render.js +2 -2
  68. package/cjs/render/contributions/render/contributions/arc-contribution-render.js.map +1 -1
  69. package/cjs/render/contributions/render/contributions/circle-contribution-render.js +2 -2
  70. package/cjs/render/contributions/render/contributions/circle-contribution-render.js.map +1 -1
  71. package/cjs/render/contributions/render/contributions/rect-contribution-render.js +2 -2
  72. package/cjs/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  73. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js +2 -2
  74. package/cjs/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  75. package/cjs/render/contributions/render/draw-interceptor.js +3 -2
  76. package/cjs/render/contributions/render/draw-interceptor.js.map +1 -1
  77. package/cjs/render/contributions/render/text-render.d.ts +1 -1
  78. package/cjs/render/contributions/render/text-render.js +24 -46
  79. package/cjs/render/contributions/render/text-render.js.map +1 -1
  80. package/dist/index.es.js +8876 -8751
  81. package/es/animate/Ticker/default-ticker.d.ts +2 -1
  82. package/es/animate/Ticker/default-ticker.js +6 -3
  83. package/es/animate/Ticker/default-ticker.js.map +1 -1
  84. package/es/animate/custom-animate.d.ts +2 -0
  85. package/es/animate/custom-animate.js +11 -2
  86. package/es/animate/custom-animate.js.map +1 -1
  87. package/es/animate/easing.d.ts +1 -0
  88. package/es/animate/easing.js +3 -0
  89. package/es/animate/easing.js.map +1 -1
  90. package/es/animate/index.d.ts +1 -0
  91. package/es/animate/index.js +2 -0
  92. package/es/animate/index.js.map +1 -1
  93. package/es/canvas/util.js +1 -2
  94. package/es/color-string/store.js +2 -1
  95. package/es/common/color-utils.js +2 -2
  96. package/es/common/color-utils.js.map +1 -1
  97. package/es/common/utils.d.ts +1 -0
  98. package/es/common/utils.js +6 -1
  99. package/es/common/utils.js.map +1 -1
  100. package/es/core/contributions/textMeasure/AtextMeasure.d.ts +56 -4
  101. package/es/core/contributions/textMeasure/AtextMeasure.js +122 -17
  102. package/es/core/contributions/textMeasure/AtextMeasure.js.map +1 -1
  103. package/es/core/contributions/textMeasure/layout.d.ts +8 -3
  104. package/es/core/contributions/textMeasure/layout.js +55 -44
  105. package/es/core/contributions/textMeasure/layout.js.map +1 -1
  106. package/es/core/stage.d.ts +5 -0
  107. package/es/core/stage.js +21 -6
  108. package/es/core/stage.js.map +1 -1
  109. package/es/event/event-manager.d.ts +1 -0
  110. package/es/event/event-manager.js +1 -1
  111. package/es/event/event-manager.js.map +1 -1
  112. package/es/event/event-system.js +2 -1
  113. package/es/event/event-system.js.map +1 -1
  114. package/es/graphic/config.d.ts +1 -1
  115. package/es/graphic/config.js +8 -2
  116. package/es/graphic/config.js.map +1 -1
  117. package/es/graphic/node-tree.js +3 -3
  118. package/es/graphic/node-tree.js.map +1 -1
  119. package/es/graphic/richtext/line.js +10 -3
  120. package/es/graphic/richtext/line.js.map +1 -1
  121. package/es/graphic/richtext/paragraph.js +4 -3
  122. package/es/graphic/richtext/paragraph.js.map +1 -1
  123. package/es/graphic/richtext/utils.d.ts +2 -1
  124. package/es/graphic/richtext/utils.js +6 -2
  125. package/es/graphic/richtext/utils.js.map +1 -1
  126. package/es/graphic/text.d.ts +11 -11
  127. package/es/graphic/text.js +101 -163
  128. package/es/graphic/text.js.map +1 -1
  129. package/es/graphic/wrap-text.js +16 -4
  130. package/es/graphic/wrap-text.js.map +1 -1
  131. package/es/interface/animate.d.ts +1 -38
  132. package/es/interface/animate.js.map +1 -1
  133. package/es/interface/context.d.ts +1 -0
  134. package/es/interface/context.js.map +1 -1
  135. package/es/interface/graphic/text.d.ts +11 -3
  136. package/es/interface/graphic/text.js +6 -1
  137. package/es/interface/graphic/text.js.map +1 -1
  138. package/es/interface/graphic.d.ts +1 -0
  139. package/es/interface/graphic.js.map +1 -1
  140. package/es/interface/stage.d.ts +2 -0
  141. package/es/interface/stage.js.map +1 -1
  142. package/es/interface/text.d.ts +9 -1
  143. package/es/interface/text.js.map +1 -1
  144. package/es/plugins/builtin-plugin/auto-refresh-plugin.d.ts +16 -0
  145. package/es/plugins/builtin-plugin/auto-refresh-plugin.js +41 -0
  146. package/es/plugins/builtin-plugin/auto-refresh-plugin.js.map +1 -0
  147. package/es/render/contributions/render/contributions/arc-contribution-render.js +2 -2
  148. package/es/render/contributions/render/contributions/arc-contribution-render.js.map +1 -1
  149. package/es/render/contributions/render/contributions/circle-contribution-render.js +2 -2
  150. package/es/render/contributions/render/contributions/circle-contribution-render.js.map +1 -1
  151. package/es/render/contributions/render/contributions/rect-contribution-render.js +2 -2
  152. package/es/render/contributions/render/contributions/rect-contribution-render.js.map +1 -1
  153. package/es/render/contributions/render/contributions/symbol-contribution-render.js +2 -2
  154. package/es/render/contributions/render/contributions/symbol-contribution-render.js.map +1 -1
  155. package/es/render/contributions/render/draw-interceptor.js +3 -2
  156. package/es/render/contributions/render/draw-interceptor.js.map +1 -1
  157. package/es/render/contributions/render/text-render.d.ts +1 -1
  158. package/es/render/contributions/render/text-render.js +23 -45
  159. package/es/render/contributions/render/text-render.js.map +1 -1
  160. package/package.json +4 -3
@@ -48,7 +48,6 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
48
48
  get clipedWidth(): number | undefined;
49
49
  get cliped(): boolean | undefined;
50
50
  get multilineLayout(): LayoutType | undefined;
51
- private isSimplify;
52
51
  get isMultiLine(): boolean;
53
52
  constructor(params?: ITextGraphicAttribute);
54
53
  isValid(): boolean;
@@ -56,10 +55,18 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
56
55
  getGraphicTheme(): Required<ITextGraphicAttribute>;
57
56
  protected doUpdateOBBBounds(): IOBBBounds;
58
57
  protected updateAABBBounds(attribute: ITextGraphicAttribute, textTheme: Required<ITextGraphicAttribute>, aabbBounds: IAABBBounds): import("@visactor/vutils").IBounds;
59
- updateWrapAABBBounds(text: (number | string) | (number | string)[]): import("@visactor/vutils").IBounds;
60
58
  updateSingallineAABBBounds(text: number | string): IAABBBounds;
61
- updateMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
62
- updateHorizontalSinglelineAABBBounds(text: number | string): IAABBBounds;
59
+ protected updateMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
60
+ guessLineHeightBuf(fontSize: number): number;
61
+ updateHorizontalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
62
+ updateWrapAABBBounds(text: (number | string) | (number | string)[]): import("@visactor/vutils").IBounds;
63
+ updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
64
+ protected getMaxWidth(theme: ITextGraphicAttribute): number;
65
+ protected getLineHeight(attribute: ITextGraphicAttribute, textTheme: ITextGraphicAttribute, buf: number): number;
66
+ protected needUpdateTags(keys: string[], k?: string[]): boolean;
67
+ protected needUpdateTag(key: string, k?: string[]): boolean;
68
+ clone(): Text;
69
+ getNoWorkAnimateAttr(): Record<string, number>;
63
70
  getBaselineMapAlign(): Record<string, string>;
64
71
  getAlignMapBaseline(): Record<string, string>;
65
72
  static baselineMapAlign: {
@@ -72,12 +79,5 @@ export declare class Text extends Graphic<ITextGraphicAttribute> implements ITex
72
79
  right: string;
73
80
  center: string;
74
81
  };
75
- updateVerticalSinglelineAABBBounds(text: number | string): IAABBBounds;
76
- updateHorizontalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
77
- updateVerticalMultilineAABBBounds(text: (number | string)[]): IAABBBounds;
78
- protected needUpdateTags(keys: string[], k?: string[]): boolean;
79
- protected needUpdateTag(key: string, k?: string[]): boolean;
80
- clone(): Text;
81
- getNoWorkAnimateAttr(): Record<string, number>;
82
82
  }
83
83
  export declare function createText(attributes: ITextGraphicAttribute): IText;
@@ -16,7 +16,7 @@ import { TEXT_NUMBER_TYPE } from "./constants";
16
16
 
17
17
  import { boundStroke, TextDirection, verticalLayout } from "./tools";
18
18
 
19
- const TEXT_UPDATE_TAG_KEY = [ "text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY ];
19
+ const TEXT_UPDATE_TAG_KEY = [ "text", "maxLineWidth", "maxWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY ];
20
20
 
21
21
  export class Text extends Graphic {
22
22
  get font() {
@@ -25,18 +25,17 @@ export class Text extends Graphic {
25
25
  }
26
26
  get clipedText() {
27
27
  var _a;
28
- const attribute = this.attribute, textTheme = this.getGraphicTheme();
29
- if (!this.isSimplify()) return;
30
- const {maxLineWidth: maxLineWidth = textTheme.maxLineWidth} = attribute;
31
- return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
28
+ const attribute = this.attribute, textTheme = this.getGraphicTheme(), maxWidth = this.getMaxWidth(textTheme);
29
+ return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
32
30
  }
33
31
  get clipedWidth() {
34
- if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
32
+ return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
35
33
  }
36
34
  get cliped() {
37
35
  var _a, _b;
38
- const textTheme = this.getGraphicTheme(), attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, text: text, whiteSpace: whiteSpace = textTheme.whiteSpace} = attribute;
39
- if (!Number.isFinite(maxLineWidth)) return !1;
36
+ const textTheme = this.getGraphicTheme(), attribute = this.attribute, maxWidth = this.getMaxWidth(textTheme);
37
+ if (!Number.isFinite(maxWidth)) return !1;
38
+ const {text: text} = this.attribute;
40
39
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
41
40
  let mergedText = "";
42
41
  this.cache.layoutData.lines.forEach((item => {
@@ -47,10 +46,7 @@ export class Text extends Graphic {
47
46
  return "vertical" === attribute.direction && this.cache.verticalList && this.cache.verticalList[0] ? this.cache.verticalList[0].map((item => item.text)).join("") !== attribute.text.toString() : null != this.clipedText && this.clipedText !== attribute.text.toString();
48
47
  }
49
48
  get multilineLayout() {
50
- if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
51
- }
52
- isSimplify() {
53
- return !this.isMultiLine && "vertical" !== this.attribute.direction;
49
+ return this.tryUpdateAABBBounds(), this.cache.layoutData;
54
50
  }
55
51
  get isMultiLine() {
56
52
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -103,19 +99,60 @@ export class Text extends Graphic {
103
99
  return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds),
104
100
  transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
105
101
  }
102
+ updateSingallineAABBBounds(text) {
103
+ this.updateMultilineAABBBounds([ text ]);
104
+ const layoutData = this.cache.layoutData;
105
+ if (layoutData && layoutData.lines && layoutData.lines.length) {
106
+ const line = layoutData.lines[0];
107
+ this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
108
+ }
109
+ return this._AABBBounds;
110
+ }
111
+ updateMultilineAABBBounds(text) {
112
+ const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
113
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
114
+ b;
115
+ }
116
+ guessLineHeightBuf(fontSize) {
117
+ return fontSize ? .1 * fontSize : 0;
118
+ }
119
+ updateHorizontalMultilineAABBBounds(text) {
120
+ var _a;
121
+ const textTheme = this.getGraphicTheme(), attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, wrap: wrap = textTheme.wrap, measureMode: measureMode = textTheme.measureMode, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(attribute, textTheme, buf);
122
+ if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
123
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
124
+ const bbox = this.cache.layoutData.bbox;
125
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
126
+ stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
127
+ }
128
+ const textMeasure = application.graphicUtil.textMeasure, layoutData = new CanvasTextLayout(fontFamily, {
129
+ fontSize: fontSize,
130
+ fontWeight: fontWeight,
131
+ fontFamily: fontFamily,
132
+ lineHeight: lineHeight
133
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, {
134
+ lineWidth: maxLineWidth,
135
+ suffixPosition: suffixPosition,
136
+ measureMode: measureMode,
137
+ keepCenterInLine: keepCenterInLine
138
+ }), {bbox: bbox} = layoutData;
139
+ return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
140
+ stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
141
+ }
106
142
  updateWrapAABBBounds(text) {
107
- var _a, _b, _c, _d;
108
- const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp} = this.attribute, lineHeight = null !== (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize, buf = ignoreBuf ? 0 : 2;
109
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
143
+ var _a, _b, _c;
144
+ const textTheme = this.getGraphicTheme(), {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, wordBreak: wordBreak = textTheme.wordBreak, fontWeight: fontWeight = textTheme.fontWeight, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, measureMode: measureMode = textTheme.measureMode, suffixPosition: suffixPosition = textTheme.suffixPosition, heightLimit: heightLimit = 0, lineClamp: lineClamp, keepCenterInLine: keepCenterInLine = textTheme.keepCenterInLine} = this.attribute, buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize), lineHeight = this.getLineHeight(this.attribute, textTheme, buf);
145
+ if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
110
146
  const bbox = this.cache.layoutData.bbox;
111
147
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
112
148
  stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
113
149
  }
114
- const textMeasure = application.graphicUtil.textMeasure, layoutObj = new CanvasTextLayout(fontFamily, {
150
+ const textMeasure = application.graphicUtil.textMeasure, textOptions = {
115
151
  fontSize: fontSize,
116
152
  fontWeight: fontWeight,
117
- fontFamily: fontFamily
118
- }, textMeasure), lines = isArray(text) ? text.map((l => l.toString())) : [ text.toString() ], linesLayout = [], bboxWH = [ 0, 0 ];
153
+ fontFamily: fontFamily,
154
+ lineHeight: lineHeight
155
+ }, layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure), lines = isArray(text) ? text.map((l => l.toString())) : [ text.toString() ], linesLayout = [], bboxWH = [ 0, 0 ];
119
156
  let lineCountLimit = 1 / 0;
120
157
  if (heightLimit > 0 && (lineCountLimit = Math.max(Math.floor(heightLimit / lineHeight), 1)),
121
158
  lineClamp && (lineCountLimit = Math.min(lineCountLimit, lineClamp)), "number" == typeof maxLineWidth && maxLineWidth !== 1 / 0) {
@@ -123,24 +160,31 @@ export class Text extends Graphic {
123
160
  const str = lines[i];
124
161
  let needCut = !0;
125
162
  if (i === lineCountLimit - 1) {
126
- const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
163
+ const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1), matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
127
164
  linesLayout.push({
128
165
  str: clip.str,
129
- width: clip.width
166
+ width: clip.width,
167
+ ascent: matrics.ascent,
168
+ descent: matrics.descent,
169
+ keepCenterInLine: keepCenterInLine
130
170
  });
131
171
  break;
132
172
  }
133
- const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
173
+ const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
134
174
  if ("" !== str && "" === clip.str || clip.wordBreaked) {
135
175
  if (ellipsis) {
136
- const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
137
- clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
176
+ const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
177
+ clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
138
178
  } else clip.str = "", clip.width = 0;
139
179
  needCut = !1;
140
180
  }
181
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
141
182
  linesLayout.push({
142
183
  str: clip.str,
143
- width: clip.width
184
+ width: clip.width,
185
+ ascent: matrics.ascent,
186
+ descent: matrics.descent,
187
+ keepCenterInLine: keepCenterInLine
144
188
  });
145
189
  let cutLength = clip.str.length;
146
190
  if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked),
@@ -157,171 +201,50 @@ export class Text extends Graphic {
157
201
  let width, text, lineWidth = 0;
158
202
  for (let i = 0, len = lines.length; i < len; i++) {
159
203
  if (i === lineCountLimit - 1) {
160
- const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
204
+ const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition), matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
161
205
  linesLayout.push({
162
206
  str: clip.str,
163
- width: clip.width
207
+ width: clip.width,
208
+ ascent: matrics.ascent,
209
+ descent: matrics.descent,
210
+ keepCenterInLine: keepCenterInLine
164
211
  }), lineWidth = Math.max(lineWidth, clip.width);
165
212
  break;
166
213
  }
167
- text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak),
168
- lineWidth = Math.max(lineWidth, width), linesLayout.push({
214
+ text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
215
+ const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions, measureMode);
216
+ linesLayout.push({
169
217
  str: text,
170
- width: width
218
+ width: width,
219
+ ascent: matrics.ascent,
220
+ descent: matrics.descent,
221
+ keepCenterInLine: keepCenterInLine
171
222
  });
172
223
  }
173
224
  bboxWH[0] = lineWidth;
174
225
  }
175
- bboxWH[1] = linesLayout.length * (lineHeight + buf);
226
+ bboxWH[1] = linesLayout.length * lineHeight;
176
227
  const bbox = {
177
228
  xOffset: 0,
178
229
  yOffset: 0,
179
230
  width: bboxWH[0],
180
231
  height: bboxWH[1]
181
232
  };
182
- layoutObj.LayoutBBox(bbox, textAlign, textBaseline);
233
+ layoutObj.LayoutBBox(bbox, textAlign, textBaseline, linesLayout);
183
234
  const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
184
235
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
185
236
  stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
186
237
  }
187
- updateSingallineAABBBounds(text) {
188
- const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
189
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
190
- b;
191
- }
192
- updateMultilineAABBBounds(text) {
193
- const textTheme = this.getGraphicTheme(), {direction: direction = textTheme.direction, underlineOffset: underlineOffset = textTheme.underlineOffset} = this.attribute, b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
194
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset),
195
- b;
196
- }
197
- updateHorizontalSinglelineAABBBounds(text) {
198
- var _a, _b;
199
- const textTheme = this.getGraphicTheme(), {wrap: wrap = textTheme.wrap} = this.attribute;
200
- if (wrap) return this.updateWrapAABBBounds([ text ]);
201
- const textMeasure = application.graphicUtil.textMeasure;
202
- let width, str;
203
- const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, ignoreBuf: ignoreBuf = textTheme.ignoreBuf, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute;
204
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
205
- const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize), textFontSize = attribute.fontSize || textTheme.fontSize, lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
206
- if (!this.shouldUpdateShape() && this.cache) {
207
- width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
208
- const dx = textDrawOffsetX(textAlign, width), dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
209
- return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2),
210
- this._AABBBounds;
211
- }
212
- if (Number.isFinite(maxLineWidth)) {
213
- if (ellipsis) {
214
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis, data = textMeasure.clipTextWithSuffix(text.toString(), {
215
- fontSize: fontSize,
216
- fontWeight: fontWeight,
217
- fontFamily: fontFamily
218
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
219
- str = data.str, width = data.width;
220
- } else {
221
- const data = textMeasure.clipText(text.toString(), {
222
- fontSize: fontSize,
223
- fontWeight: fontWeight,
224
- fontFamily: fontFamily
225
- }, maxLineWidth, !1);
226
- str = data.str, width = data.width;
227
- }
228
- this.cache.clipedText = str, this.cache.clipedWidth = width;
229
- } else width = textMeasure.measureTextWidth(text.toString(), {
230
- fontSize: fontSize,
231
- fontWeight: fontWeight,
232
- fontFamily: fontFamily
233
- }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
234
- this.clearUpdateShapeTag();
235
- const dx = textDrawOffsetX(textAlign, width);
236
- let lh = lineHeight;
237
- application.global && application.global.isSafari() && (lh += .2 * fontSize);
238
- const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
239
- return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2),
240
- this._AABBBounds;
241
- }
242
- getBaselineMapAlign() {
243
- return Text.baselineMapAlign;
244
- }
245
- getAlignMapBaseline() {
246
- return Text.alignMapBaseline;
247
- }
248
- updateVerticalSinglelineAABBBounds(text) {
249
- var _a, _b, _c;
250
- const textTheme = this.getGraphicTheme(), textMeasure = application.graphicUtil.textMeasure;
251
- let width;
252
- const attribute = this.attribute, {ignoreBuf: ignoreBuf = textTheme.ignoreBuf} = attribute, buf = ignoreBuf ? 0 : 2, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, fontFamily: fontFamily = textTheme.fontFamily, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
253
- let {textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline} = attribute;
254
- if (!verticalMode) {
255
- const t = textAlign;
256
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left",
257
- textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
258
- }
259
- if (!this.shouldUpdateShape() && this.cache) {
260
- width = this.cache.clipedWidth;
261
- const dx = textDrawOffsetX(textAlign, width), dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
262
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
263
- this._AABBBounds;
264
- }
265
- let verticalList = [ verticalLayout(text.toString()) ];
266
- if (Number.isFinite(maxLineWidth)) {
267
- if (ellipsis) {
268
- const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis, data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
269
- fontSize: fontSize,
270
- fontWeight: fontWeight,
271
- fontFamily: fontFamily
272
- }, maxLineWidth, strEllipsis, !1, suffixPosition);
273
- verticalList = [ data.verticalList ], width = data.width;
274
- } else {
275
- const data = textMeasure.clipTextVertical(verticalList[0], {
276
- fontSize: fontSize,
277
- fontWeight: fontWeight,
278
- fontFamily: fontFamily
279
- }, maxLineWidth, !1);
280
- verticalList = [ data.verticalList ], width = data.width;
281
- }
282
- this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
283
- } else width = 0, verticalList[0].forEach((t => {
284
- const w = t.direction === TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
285
- fontSize: fontSize,
286
- fontWeight: fontWeight,
287
- fontFamily: fontFamily
288
- });
289
- width += w, t.width = w;
290
- })), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
291
- this.clearUpdateShapeTag();
292
- const dx = textDrawOffsetX(textAlign, width), dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
293
- return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
294
- this._AABBBounds;
295
- }
296
- updateHorizontalMultilineAABBBounds(text) {
297
- var _a, _b;
298
- const textTheme = this.getGraphicTheme(), {wrap: wrap = textTheme.wrap} = this.attribute;
299
- if (wrap) return this.updateWrapAABBBounds(text);
300
- const attribute = this.attribute, {fontFamily: fontFamily = textTheme.fontFamily, textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, ellipsis: ellipsis = textTheme.ellipsis, maxLineWidth: maxLineWidth, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, whiteSpace: whiteSpace = textTheme.whiteSpace, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
301
- if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
302
- if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
303
- const bbox = this.cache.layoutData.bbox;
304
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
305
- stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
306
- }
307
- const textMeasure = application.graphicUtil.textMeasure, layoutData = new CanvasTextLayout(fontFamily, {
308
- fontSize: fontSize,
309
- fontWeight: fontWeight,
310
- fontFamily: fontFamily
311
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition), {bbox: bbox} = layoutData;
312
- return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height),
313
- stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
314
- }
315
238
  updateVerticalMultilineAABBBounds(text) {
316
- var _a, _b, _c;
239
+ var _a, _b;
317
240
  const textTheme = this.getGraphicTheme(), textMeasure = application.graphicUtil.textMeasure;
318
241
  let width;
319
- const attribute = this.attribute, {ignoreBuf: ignoreBuf = textTheme.ignoreBuf} = attribute, buf = ignoreBuf ? 0 : 2, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
242
+ const attribute = this.attribute, {maxLineWidth: maxLineWidth = textTheme.maxLineWidth, ellipsis: ellipsis = textTheme.ellipsis, fontFamily: fontFamily = textTheme.fontFamily, fontSize: fontSize = textTheme.fontSize, fontWeight: fontWeight = textTheme.fontWeight, stroke: stroke = textTheme.stroke, lineWidth: lineWidth = textTheme.lineWidth, verticalMode: verticalMode = textTheme.verticalMode, suffixPosition: suffixPosition = textTheme.suffixPosition} = attribute, lineHeight = this.getLineHeight(attribute, textTheme, 0);
320
243
  let {textAlign: textAlign = textTheme.textAlign, textBaseline: textBaseline = textTheme.textBaseline} = attribute;
321
244
  if (!verticalMode) {
322
245
  const t = textAlign;
323
- textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left",
324
- textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
246
+ textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left",
247
+ textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
325
248
  }
326
249
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
327
250
  this.cache.verticalList.forEach((item => {
@@ -364,6 +287,15 @@ export class Text extends Graphic {
364
287
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2),
365
288
  this._AABBBounds;
366
289
  }
290
+ getMaxWidth(theme) {
291
+ var _a, _b;
292
+ const attribute = this.attribute;
293
+ return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
294
+ }
295
+ getLineHeight(attribute, textTheme, buf) {
296
+ var _a;
297
+ return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
298
+ }
367
299
  needUpdateTags(keys, k = TEXT_UPDATE_TAG_KEY) {
368
300
  return super.needUpdateTags(keys, k);
369
301
  }
@@ -376,6 +308,12 @@ export class Text extends Graphic {
376
308
  getNoWorkAnimateAttr() {
377
309
  return Text.NOWORK_ANIMATE_ATTR;
378
310
  }
311
+ getBaselineMapAlign() {
312
+ return Text.baselineMapAlign;
313
+ }
314
+ getAlignMapBaseline() {
315
+ return Text.alignMapBaseline;
316
+ }
379
317
  }
380
318
 
381
319
  Text.NOWORK_ANIMATE_ATTR = Object.assign({