@visactor/vrender 0.21.0-alpha.3 → 0.21.0-alpha.4

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.
package/dist/index.es.js CHANGED
@@ -3913,7 +3913,6 @@ const DefaultStrokeStyle = Object.assign({
3913
3913
  const DefaultTextStyle = {
3914
3914
  text: "",
3915
3915
  maxLineWidth: 1 / 0,
3916
- maxWidth: 1 / 0,
3917
3916
  textAlign: "left",
3918
3917
  textBaseline: "alphabetic",
3919
3918
  fontSize: 16,
@@ -4266,32 +4265,10 @@ let ATextMeasure = class {
4266
4265
  configure(service, env) {
4267
4266
  this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
4268
4267
  }
4269
- _measureTextWithoutAlignBaseline(text, options, compatible) {
4268
+ measureTextWidth(text, options) {
4269
+ if (!this.context) return this.estimate(text, options).width;
4270
4270
  this.context.setTextStyleWithoutAlignBaseline(options);
4271
- const metrics = this.context.measureText(text);
4272
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
4273
- }
4274
- _measureTextWithAlignBaseline(text, options, compatible) {
4275
- this.context.setTextStyle(options);
4276
- const metrics = this.context.measureText(text);
4277
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
4278
- }
4279
- compatibleMetrics(metrics, options) {
4280
- if (null == metrics.actualBoundingBoxAscent || null == metrics.actualBoundingBoxDescent || null == metrics.fontBoundingBoxAscent || null == metrics.fontBoundingBoxDescent) {
4281
- const {
4282
- ascent: ascent,
4283
- descent: descent
4284
- } = this.measureTextBoundADscentEstimate(options);
4285
- metrics.actualBoundingBoxAscent = ascent, metrics.actualBoundingBoxDescent = descent, metrics.fontBoundingBoxAscent = ascent, metrics.fontBoundingBoxDescent = descent;
4286
- }
4287
- if (null == metrics.actualBoundingBoxLeft || null == metrics.actualBoundingBoxRight) {
4288
- const {
4289
- left: left,
4290
- right: right
4291
- } = this.measureTextBoundLeftRightEstimate(options);
4292
- metrics.actualBoundingBoxLeft = left, metrics.actualBoundingBoxRight = right;
4293
- }
4294
- return metrics;
4271
+ return this.context.measureText(text).width;
4295
4272
  }
4296
4273
  estimate(text, _ref) {
4297
4274
  let {
@@ -4305,85 +4282,19 @@ let ATextMeasure = class {
4305
4282
  height: fontSize
4306
4283
  };
4307
4284
  }
4308
- measureTextWidth(text, options, textMeasure) {
4309
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
4310
- }
4311
- measureTextBoundsWidth(text, options, textMeasure) {
4312
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
4313
- }
4314
- measureTextBoundsLeftRight(text, options, textMeasure) {
4315
- return this.context ? {
4316
- left: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxLeft,
4317
- right: textMeasure.actualBoundingBoxRight
4318
- } : this.measureTextBoundLeftRightEstimate(options);
4319
- }
4320
- measureTextPixelHeight(text, options, textMeasure) {
4285
+ measureTextPixelHeight(text, options) {
4321
4286
  var _a;
4322
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, !0), Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent)) : null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4323
- }
4324
- measureTextPixelADscent(text, options, textMeasure) {
4325
- return this.context ? {
4326
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxAscent,
4327
- descent: textMeasure.actualBoundingBoxDescent
4328
- } : this.measureTextBoundADscentEstimate(options);
4329
- }
4330
- measureTextBoundHieght(text, options, textMeasure) {
4331
- var _a;
4332
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options, !0), Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent)) : null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4333
- }
4334
- measureTextBoundADscent(text, options, textMeasure) {
4335
- return this.context ? {
4336
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).fontBoundingBoxAscent,
4337
- descent: textMeasure.fontBoundingBoxDescent
4338
- } : this.measureTextBoundADscentEstimate(options);
4339
- }
4340
- measureTextBoundADscentEstimate(options) {
4341
- var _a;
4342
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
4343
- {
4344
- textBaseline: textBaseline
4345
- } = options;
4346
- return "bottom" === textBaseline ? {
4347
- ascent: fontSize,
4348
- descent: 0
4349
- } : "middle" === textBaseline ? {
4350
- ascent: fontSize / 2,
4351
- descent: fontSize / 2
4352
- } : "alphabetic" === textBaseline ? {
4353
- ascent: .79 * fontSize,
4354
- descent: .21 * fontSize
4355
- } : {
4356
- ascent: 0,
4357
- descent: fontSize
4358
- };
4287
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4288
+ this.context.setTextStyleWithoutAlignBaseline(options);
4289
+ const textMeasure = this.context.measureText(text);
4290
+ return Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent);
4359
4291
  }
4360
- measureTextBoundLeftRightEstimate(options) {
4292
+ measureTextBoundHieght(text, options) {
4361
4293
  var _a;
4362
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
4363
- {
4364
- textAlign: textAlign
4365
- } = options;
4366
- return "center" === textAlign ? {
4367
- left: fontSize / 2,
4368
- right: fontSize / 2
4369
- } : "right" === textAlign || "end" === textAlign ? {
4370
- left: fontSize,
4371
- right: 0
4372
- } : {
4373
- left: 0,
4374
- right: fontSize
4375
- };
4376
- }
4377
- measureTextPixelADscentAndWidth(text, options) {
4378
- if (!this.context) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
4379
- width: this.estimate(text, options).width
4380
- });
4381
- const out = this._measureTextWithoutAlignBaseline(text, options, !0);
4382
- return {
4383
- ascent: out.actualBoundingBoxAscent,
4384
- descent: out.actualBoundingBoxDescent,
4385
- width: out.width
4386
- };
4294
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4295
+ this.context.setTextStyleWithoutAlignBaseline(options);
4296
+ const textMeasure = this.context.measureText(text);
4297
+ return Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent);
4387
4298
  }
4388
4299
  measureText(text, options) {
4389
4300
  return this.context ? (this.context.setTextStyleWithoutAlignBaseline(options), this.context.measureText(text)) : this.estimate(text, options);
@@ -9183,7 +9094,7 @@ class ResourceLoader {
9183
9094
  }
9184
9095
  static GetFile(url, type) {
9185
9096
  let data = ResourceLoader.cache.get(url);
9186
- return data ? "init" === data.loadState || "fail" === data.loadState ? Promise.reject() : "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
9097
+ return data ? "fail" === data.loadState ? Promise.reject() : "init" === data.loadState || "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
9187
9098
  type: type,
9188
9099
  loadState: "init"
9189
9100
  }, ResourceLoader.cache.set(url, data), "arrayBuffer" === type ? data.dataPromise = application.global.loadArrayBuffer(url) : "blob" === type ? data.dataPromise = application.global.loadBlob(url) : "json" === type && (data.dataPromise = application.global.loadJson(url)), data.dataPromise.then(data => data.data));
@@ -12447,8 +12358,9 @@ class DefaultImageRenderContribution extends DefaultRectRenderContribution {
12447
12358
  constructor() {
12448
12359
  super(...arguments), this.time = BaseRenderContributionTime.afterFillStroke, this.useStyle = !0, this.order = 0;
12449
12360
  }
12450
- drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
12451
- return super.drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
12361
+ drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
12362
+ if (!(image.isGifImage && image.renderFrame && image.playing)) return super.drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
12363
+ image.renderFrame(context, x, y);
12452
12364
  }
12453
12365
  }
12454
12366
  const defaultImageRenderContribution = new DefaultImageRenderContribution();
@@ -13790,50 +13702,77 @@ let DefaultCanvasTextRender = class extends BaseRender {
13790
13702
  }
13791
13703
  doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.strokeText(t, _x, _y, z))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), context.fillText(t, _x, _y, z), this.drawUnderLine(underline, lineThrough, text, _x, _y, z, textAttribute, context))), direction && (context.highPerformanceRestore(), context.setTransformForCurrent());
13792
13704
  };
13793
- if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
13794
- const {
13795
- multilineLayout: multilineLayout
13796
- } = text;
13797
- if (!multilineLayout) return void context.highPerformanceRestore();
13798
- const {
13799
- xOffset: xOffset,
13800
- yOffset: yOffset
13801
- } = multilineLayout.bbox;
13802
- doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13803
- context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
13804
- }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13805
- context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z), this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y - textDrawOffsetY("bottom", fontSize) - .05 * fontSize, z, textAttribute, context, {
13806
- width: line.width
13705
+ if (text.isMultiLine) {
13706
+ if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
13707
+ const {
13708
+ multilineLayout: multilineLayout
13709
+ } = text;
13710
+ if (!multilineLayout) return void context.highPerformanceRestore();
13711
+ const {
13712
+ xOffset: xOffset,
13713
+ yOffset: yOffset
13714
+ } = multilineLayout.bbox;
13715
+ doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13716
+ context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
13717
+ }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13718
+ context.fillText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z), this.drawUnderLine(underline, lineThrough, text, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y - textDrawOffsetY("bottom", fontSize) - .05 * fontSize, z, textAttribute, context, {
13719
+ width: line.width
13720
+ });
13721
+ })));
13722
+ } else {
13723
+ text.tryUpdateAABBBounds();
13724
+ const cache = text.cache,
13725
+ {
13726
+ verticalList: verticalList
13727
+ } = cache;
13728
+ context.textAlign = "left", context.textBaseline = "top";
13729
+ const totalHeight = lineHeight * verticalList.length;
13730
+ let totalW = 0;
13731
+ verticalList.forEach(verticalData => {
13732
+ const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
13733
+ totalW = max(_w, totalW);
13734
+ });
13735
+ let offsetY = 0,
13736
+ offsetX = 0;
13737
+ "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
13738
+ const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
13739
+ dw = totalW - currentW;
13740
+ let currentOffsetY = offsetY;
13741
+ "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
13742
+ const {
13743
+ text: text,
13744
+ width: width,
13745
+ direction: direction
13746
+ } = item;
13747
+ drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
13748
+ });
13807
13749
  });
13808
- })));
13750
+ }
13751
+ } else if ("horizontal" === direction) {
13752
+ context.setTextStyle(text.attribute, textAttribute, z);
13753
+ const t = text.clipedText;
13754
+ let dy = 0;
13755
+ lineHeight !== fontSize && ("top" === textBaseline ? dy = (lineHeight - fontSize) / 2 : "middle" === textBaseline || "bottom" === textBaseline && (dy = -(lineHeight - fontSize) / 2)), drawText(t, 0, dy, 0);
13809
13756
  } else {
13810
13757
  text.tryUpdateAABBBounds();
13811
- const cache = text.cache,
13812
- {
13758
+ const cache = text.cache;
13759
+ if (cache) {
13760
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
13761
+ const {
13813
13762
  verticalList: verticalList
13814
13763
  } = cache;
13815
- context.textAlign = "left", context.textBaseline = "top";
13816
- const totalHeight = lineHeight * verticalList.length;
13817
- let totalW = 0;
13818
- verticalList.forEach(verticalData => {
13819
- const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
13820
- totalW = max(_w, totalW);
13821
- });
13822
- let offsetY = 0,
13823
- offsetX = 0;
13824
- "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
13825
- const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
13826
- dw = totalW - currentW;
13827
- let currentOffsetY = offsetY;
13828
- "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
13764
+ let offsetY = 0;
13765
+ const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
13766
+ let offsetX = 0;
13767
+ "bottom" === textBaseline ? offsetX = -lineHeight : "middle" === textBaseline && (offsetX = -lineHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), context.textAlign = "left", context.textBaseline = "top", verticalList[0].forEach(item => {
13829
13768
  const {
13830
13769
  text: text,
13831
13770
  width: width,
13832
13771
  direction: direction
13833
13772
  } = item;
13834
- drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
13773
+ drawText(text, offsetX, offsetY, direction), offsetY += width;
13835
13774
  });
13836
- });
13775
+ }
13837
13776
  }
13838
13777
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context), this.afterRenderStep(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb);
13839
13778
  }
@@ -14171,10 +14110,12 @@ let DefaultCanvasImageRender = class extends BaseRender {
14171
14110
  const {
14172
14111
  image: url
14173
14112
  } = image.attribute;
14174
- if (!url || !image.resources) return;
14175
- const res = image.resources.get(url);
14176
- if ("loading" === res.state && isString$1(url)) return void ResourceLoader.improveImageLoading(url);
14177
- if ("success" !== res.state) return;
14113
+ if (!image.isGifImage) {
14114
+ if (!url || !image.resources) return;
14115
+ const res = image.resources.get(url);
14116
+ if ("loading" === res.state && isString$1(url)) return void ResourceLoader.improveImageLoading(url);
14117
+ if ("success" !== res.state) return;
14118
+ }
14178
14119
  const {
14179
14120
  context: context
14180
14121
  } = renderService.drawParams;
@@ -14566,6 +14507,28 @@ class CanvasTextLayout {
14566
14507
  }
14567
14508
  return bbox.yOffset = "top" === textBaseline ? 0 : "middle" === textBaseline ? bbox.height / -2 : "alphabetic" === textBaseline ? -.79 * bbox.height : -bbox.height, bbox;
14568
14509
  }
14510
+ GetLayout(str, width, height, textAlign, textBaseline, lineHeight, suffix, wordBreak, suffixPosition) {
14511
+ const linesLayout = [],
14512
+ bboxWH = [width, height],
14513
+ bboxOffset = [0, 0];
14514
+ for (; str.length > 0;) {
14515
+ const {
14516
+ str: clipText
14517
+ } = this.textMeasure.clipTextWithSuffix(str, this.textOptions, width, suffix, wordBreak, suffixPosition);
14518
+ linesLayout.push({
14519
+ str: clipText,
14520
+ width: this.textMeasure.measureTextWidth(clipText, this.textOptions)
14521
+ }), str = str.substring(clipText.length);
14522
+ }
14523
+ "left" === textAlign || "start" === textAlign || ("center" === textAlign ? bboxOffset[0] = bboxWH[0] / -2 : "right" !== textAlign && "end" !== textAlign || (bboxOffset[0] = -bboxWH[0])), "top" === textBaseline || ("middle" === textBaseline ? bboxOffset[1] = bboxWH[1] / -2 : "bottom" === textBaseline && (bboxOffset[1] = -bboxWH[1]));
14524
+ const bbox = {
14525
+ xOffset: bboxOffset[0],
14526
+ yOffset: bboxOffset[1],
14527
+ width: bboxWH[0],
14528
+ height: bboxWH[1]
14529
+ };
14530
+ return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
14531
+ }
14569
14532
  GetLayoutByLines(lines, textAlign, textBaseline, lineHeight) {
14570
14533
  let suffix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
14571
14534
  let wordBreak = arguments.length > 5 ? arguments[5] : undefined;
@@ -14576,29 +14539,18 @@ class CanvasTextLayout {
14576
14539
  bboxWH = [0, 0];
14577
14540
  if ("number" == typeof lineWidth && lineWidth !== 1 / 0) {
14578
14541
  let width;
14579
- for (let i = 0, len = lines.length; i < len; i++) {
14580
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
14581
- width = Math.min(metrics.width, lineWidth), linesLayout.push({
14582
- str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
14583
- width: width,
14584
- ascent: metrics.ascent,
14585
- descent: metrics.descent
14586
- });
14587
- }
14542
+ for (let i = 0, len = lines.length; i < len; i++) width = Math.min(this.textMeasure.measureTextWidth(lines[i], this.textOptions), lineWidth), linesLayout.push({
14543
+ str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
14544
+ width: width
14545
+ });
14588
14546
  bboxWH[0] = lineWidth;
14589
14547
  } else {
14590
14548
  let width, text;
14591
14549
  lineWidth = 0;
14592
- for (let i = 0, len = lines.length; i < len; i++) {
14593
- text = lines[i];
14594
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
14595
- width = metrics.width, lineWidth = Math.max(lineWidth, width), linesLayout.push({
14596
- str: text,
14597
- width: width,
14598
- ascent: metrics.ascent,
14599
- descent: metrics.descent
14600
- });
14601
- }
14550
+ for (let i = 0, len = lines.length; i < len; i++) text = lines[i], width = this.textMeasure.measureTextWidth(text, this.textOptions), lineWidth = Math.max(lineWidth, width), linesLayout.push({
14551
+ str: text,
14552
+ width: width
14553
+ });
14602
14554
  bboxWH[0] = lineWidth;
14603
14555
  }
14604
14556
  bboxWH[1] = linesLayout.length * lineHeight, bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);
@@ -14627,11 +14579,11 @@ class CanvasTextLayout {
14627
14579
  };
14628
14580
  }
14629
14581
  lineOffset(bbox, line, textAlign, textBaseline, lineHeight, origin) {
14630
- return "left" === textAlign || "start" === textAlign ? line.leftOffset = 0 : "center" === textAlign ? line.leftOffset = (bbox.width - line.width) / 2 : "right" !== textAlign && "end" !== textAlign || (line.leftOffset = bbox.width - line.width), line.topOffset = lineHeight / 2 + (line.ascent - line.descent) / 2 + origin[1], origin[1] += lineHeight, line;
14582
+ return "left" === textAlign || "start" === textAlign ? line.leftOffset = 0 : "center" === textAlign ? line.leftOffset = (bbox.width - line.width) / 2 : "right" !== textAlign && "end" !== textAlign || (line.leftOffset = bbox.width - line.width), line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + .79 * this.textOptions.fontSize + origin[1], origin[1] += lineHeight, line;
14631
14583
  }
14632
14584
  }
14633
14585
 
14634
- 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];
14586
+ const TEXT_UPDATE_TAG_KEY = ["text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY];
14635
14587
  class Text extends Graphic {
14636
14588
  get font() {
14637
14589
  const textTheme = this.getGraphicTheme();
@@ -14640,22 +14592,26 @@ class Text extends Graphic {
14640
14592
  get clipedText() {
14641
14593
  var _a;
14642
14594
  const attribute = this.attribute,
14643
- textTheme = this.getGraphicTheme(),
14644
- maxWidth = this.getMaxWidth(textTheme);
14645
- return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
14595
+ textTheme = this.getGraphicTheme();
14596
+ if (!this.isSimplify()) return;
14597
+ const {
14598
+ maxLineWidth = textTheme.maxLineWidth
14599
+ } = attribute;
14600
+ return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
14646
14601
  }
14647
14602
  get clipedWidth() {
14648
- return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
14603
+ if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
14649
14604
  }
14650
14605
  get cliped() {
14651
14606
  var _a, _b;
14652
14607
  const textTheme = this.getGraphicTheme(),
14653
14608
  attribute = this.attribute,
14654
- maxWidth = this.getMaxWidth(textTheme);
14655
- if (!Number.isFinite(maxWidth)) return !1;
14656
- const {
14657
- text: text
14658
- } = this.attribute;
14609
+ {
14610
+ maxLineWidth = textTheme.maxLineWidth,
14611
+ text: text,
14612
+ whiteSpace = textTheme.whiteSpace
14613
+ } = attribute;
14614
+ if (!Number.isFinite(maxLineWidth)) return !1;
14659
14615
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
14660
14616
  let mergedText = "";
14661
14617
  this.cache.layoutData.lines.forEach(item => {
@@ -14666,7 +14622,10 @@ class Text extends Graphic {
14666
14622
  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();
14667
14623
  }
14668
14624
  get multilineLayout() {
14669
- return this.tryUpdateAABBBounds(), this.cache.layoutData;
14625
+ if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
14626
+ }
14627
+ isSimplify() {
14628
+ return !this.isMultiLine && "vertical" !== this.attribute.direction;
14670
14629
  }
14671
14630
  get isMultiLine() {
14672
14631
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -14739,63 +14698,8 @@ class Text extends Graphic {
14739
14698
  }
14740
14699
  return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds), transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
14741
14700
  }
14742
- updateSingallineAABBBounds(text) {
14743
- this.updateMultilineAABBBounds([text]);
14744
- const layoutData = this.cache.layoutData;
14745
- if (layoutData) {
14746
- const line = layoutData.lines[0];
14747
- this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
14748
- }
14749
- return this._AABBBounds;
14750
- }
14751
- updateMultilineAABBBounds(text) {
14752
- const textTheme = this.getGraphicTheme(),
14753
- {
14754
- direction = textTheme.direction,
14755
- underlineOffset = textTheme.underlineOffset
14756
- } = this.attribute,
14757
- b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
14758
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14759
- }
14760
- updateHorizontalMultilineAABBBounds(text) {
14761
- var _a;
14762
- const textTheme = this.getGraphicTheme(),
14763
- attribute = this.attribute,
14764
- {
14765
- fontFamily = textTheme.fontFamily,
14766
- textAlign = textTheme.textAlign,
14767
- textBaseline = textTheme.textBaseline,
14768
- fontSize = textTheme.fontSize,
14769
- fontWeight = textTheme.fontWeight,
14770
- ellipsis = textTheme.ellipsis,
14771
- maxLineWidth: maxLineWidth,
14772
- stroke = textTheme.stroke,
14773
- wrap = textTheme.wrap,
14774
- ignoreBuf = textTheme.ignoreBuf,
14775
- lineWidth = textTheme.lineWidth,
14776
- whiteSpace = textTheme.whiteSpace,
14777
- suffixPosition = textTheme.suffixPosition
14778
- } = attribute,
14779
- buf = ignoreBuf ? 0 : 2,
14780
- lineHeight = this.getLineHeight(attribute, textTheme) + buf;
14781
- if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
14782
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
14783
- const bbox = this.cache.layoutData.bbox;
14784
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14785
- }
14786
- const textMeasure = application.graphicUtil.textMeasure,
14787
- layoutData = new CanvasTextLayout(fontFamily, {
14788
- fontSize: fontSize,
14789
- fontWeight: fontWeight,
14790
- fontFamily: fontFamily
14791
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
14792
- {
14793
- bbox: bbox
14794
- } = layoutData;
14795
- return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14796
- }
14797
14701
  updateWrapAABBBounds(text) {
14798
- var _a, _b, _c;
14702
+ var _a, _b, _c, _d;
14799
14703
  const textTheme = this.getGraphicTheme(),
14800
14704
  {
14801
14705
  fontFamily = textTheme.fontFamily,
@@ -14813,19 +14717,18 @@ class Text extends Graphic {
14813
14717
  heightLimit = 0,
14814
14718
  lineClamp: lineClamp
14815
14719
  } = this.attribute,
14816
- buf = ignoreBuf ? 0 : 2,
14817
- lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
14818
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
14720
+ lineHeight = null !== (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize,
14721
+ buf = ignoreBuf ? 0 : 2;
14722
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
14819
14723
  const bbox = this.cache.layoutData.bbox;
14820
14724
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14821
14725
  }
14822
14726
  const textMeasure = application.graphicUtil.textMeasure,
14823
- textOptions = {
14727
+ layoutObj = new CanvasTextLayout(fontFamily, {
14824
14728
  fontSize: fontSize,
14825
14729
  fontWeight: fontWeight,
14826
14730
  fontFamily: fontFamily
14827
- },
14828
- layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure),
14731
+ }, textMeasure),
14829
14732
  lines = isArray$1(text) ? text.map(l => l.toString()) : [text.toString()],
14830
14733
  linesLayout = [],
14831
14734
  bboxWH = [0, 0];
@@ -14835,33 +14738,29 @@ class Text extends Graphic {
14835
14738
  const str = lines[i];
14836
14739
  let needCut = !0;
14837
14740
  if (i === lineCountLimit - 1) {
14838
- const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1),
14839
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14741
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
14840
14742
  linesLayout.push({
14841
14743
  str: clip.str,
14842
- width: clip.width,
14843
- ascent: matrics.ascent,
14844
- descent: matrics.descent
14744
+ width: clip.width
14845
14745
  });
14846
14746
  break;
14847
14747
  }
14848
- const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-word" === wordBreak);
14849
- if ("" !== str && "" === clip.str) {
14748
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
14749
+ if ("" !== str && "" === clip.str || clip.wordBreaked) {
14850
14750
  if (ellipsis) {
14851
- const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14852
- clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
14751
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14752
+ clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
14853
14753
  } else clip.str = "", clip.width = 0;
14854
14754
  needCut = !1;
14855
14755
  }
14856
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14857
- if (linesLayout.push({
14756
+ linesLayout.push({
14858
14757
  str: clip.str,
14859
- width: clip.width,
14860
- ascent: matrics.ascent,
14861
- descent: matrics.descent
14862
- }), clip.str.length === str.length) ;else if (needCut) {
14863
- const newStr = str.substring(clip.str.length);
14864
- lines.splice(i + 1, 0, newStr);
14758
+ width: clip.width
14759
+ });
14760
+ let cutLength = clip.str.length;
14761
+ if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked), clip.str.length === str.length) ;else if (needCut) {
14762
+ let newStr = str.substring(cutLength);
14763
+ "keep-all" === wordBreak && (newStr = newStr.replace(/^\s+/g, "")), lines.splice(i + 1, 0, newStr);
14865
14764
  }
14866
14765
  }
14867
14766
  let maxWidth = 0;
@@ -14874,28 +14773,21 @@ class Text extends Graphic {
14874
14773
  lineWidth = 0;
14875
14774
  for (let i = 0, len = lines.length; i < len; i++) {
14876
14775
  if (i === lineCountLimit - 1) {
14877
- const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition),
14878
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14776
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14879
14777
  linesLayout.push({
14880
14778
  str: clip.str,
14881
- width: clip.width,
14882
- ascent: matrics.ascent,
14883
- descent: matrics.descent
14779
+ width: clip.width
14884
14780
  }), lineWidth = Math.max(lineWidth, clip.width);
14885
14781
  break;
14886
14782
  }
14887
- text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
14888
- const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions);
14889
- linesLayout.push({
14783
+ text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
14890
14784
  str: text,
14891
- width: width,
14892
- ascent: matrics.ascent,
14893
- descent: matrics.descent
14785
+ width: width
14894
14786
  });
14895
14787
  }
14896
14788
  bboxWH[0] = lineWidth;
14897
14789
  }
14898
- bboxWH[1] = linesLayout.length * lineHeight;
14790
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
14899
14791
  const bbox = {
14900
14792
  xOffset: 0,
14901
14793
  yOffset: 0,
@@ -14906,12 +14798,210 @@ class Text extends Graphic {
14906
14798
  const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
14907
14799
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14908
14800
  }
14909
- updateVerticalMultilineAABBBounds(text) {
14801
+ updateSingallineAABBBounds(text) {
14802
+ const textTheme = this.getGraphicTheme(),
14803
+ {
14804
+ direction = textTheme.direction,
14805
+ underlineOffset = textTheme.underlineOffset
14806
+ } = this.attribute,
14807
+ b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
14808
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14809
+ }
14810
+ updateMultilineAABBBounds(text) {
14811
+ const textTheme = this.getGraphicTheme(),
14812
+ {
14813
+ direction = textTheme.direction,
14814
+ underlineOffset = textTheme.underlineOffset
14815
+ } = this.attribute,
14816
+ b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
14817
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14818
+ }
14819
+ updateHorizontalSinglelineAABBBounds(text) {
14820
+ var _a, _b;
14821
+ const textTheme = this.getGraphicTheme(),
14822
+ {
14823
+ wrap = textTheme.wrap
14824
+ } = this.attribute;
14825
+ if (wrap) return this.updateWrapAABBBounds([text]);
14826
+ const textMeasure = application.graphicUtil.textMeasure;
14827
+ let width, str;
14828
+ const attribute = this.attribute,
14829
+ {
14830
+ maxLineWidth = textTheme.maxLineWidth,
14831
+ ellipsis = textTheme.ellipsis,
14832
+ textAlign = textTheme.textAlign,
14833
+ textBaseline = textTheme.textBaseline,
14834
+ fontFamily = textTheme.fontFamily,
14835
+ fontSize = textTheme.fontSize,
14836
+ fontWeight = textTheme.fontWeight,
14837
+ stroke = textTheme.stroke,
14838
+ lineWidth = textTheme.lineWidth,
14839
+ ignoreBuf = textTheme.ignoreBuf,
14840
+ whiteSpace = textTheme.whiteSpace,
14841
+ suffixPosition = textTheme.suffixPosition
14842
+ } = attribute;
14843
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
14844
+ const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize),
14845
+ textFontSize = attribute.fontSize || textTheme.fontSize,
14846
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
14847
+ if (!this.shouldUpdateShape() && this.cache) {
14848
+ width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
14849
+ const dx = textDrawOffsetX(textAlign, width),
14850
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14851
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14852
+ }
14853
+ if (Number.isFinite(maxLineWidth)) {
14854
+ if (ellipsis) {
14855
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
14856
+ data = textMeasure.clipTextWithSuffix(text.toString(), {
14857
+ fontSize: fontSize,
14858
+ fontWeight: fontWeight,
14859
+ fontFamily: fontFamily
14860
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
14861
+ str = data.str, width = data.width;
14862
+ } else {
14863
+ const data = textMeasure.clipText(text.toString(), {
14864
+ fontSize: fontSize,
14865
+ fontWeight: fontWeight,
14866
+ fontFamily: fontFamily
14867
+ }, maxLineWidth, !1);
14868
+ str = data.str, width = data.width;
14869
+ }
14870
+ this.cache.clipedText = str, this.cache.clipedWidth = width;
14871
+ } else width = textMeasure.measureTextWidth(text.toString(), {
14872
+ fontSize: fontSize,
14873
+ fontWeight: fontWeight,
14874
+ fontFamily: fontFamily
14875
+ }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
14876
+ this.clearUpdateShapeTag();
14877
+ const dx = textDrawOffsetX(textAlign, width);
14878
+ let lh = lineHeight;
14879
+ application.global && application.global.isSafari() && (lh += .2 * fontSize);
14880
+ const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
14881
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14882
+ }
14883
+ getBaselineMapAlign() {
14884
+ return Text.baselineMapAlign;
14885
+ }
14886
+ getAlignMapBaseline() {
14887
+ return Text.alignMapBaseline;
14888
+ }
14889
+ updateVerticalSinglelineAABBBounds(text) {
14890
+ var _a, _b, _c;
14891
+ const textTheme = this.getGraphicTheme(),
14892
+ textMeasure = application.graphicUtil.textMeasure;
14893
+ let width;
14894
+ const attribute = this.attribute,
14895
+ {
14896
+ ignoreBuf = textTheme.ignoreBuf
14897
+ } = attribute,
14898
+ buf = ignoreBuf ? 0 : 2,
14899
+ {
14900
+ maxLineWidth = textTheme.maxLineWidth,
14901
+ ellipsis = textTheme.ellipsis,
14902
+ fontSize = textTheme.fontSize,
14903
+ fontWeight = textTheme.fontWeight,
14904
+ fontFamily = textTheme.fontFamily,
14905
+ stroke = textTheme.stroke,
14906
+ lineWidth = textTheme.lineWidth,
14907
+ verticalMode = textTheme.verticalMode,
14908
+ suffixPosition = textTheme.suffixPosition
14909
+ } = attribute,
14910
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14911
+ let {
14912
+ textAlign = textTheme.textAlign,
14913
+ textBaseline = textTheme.textBaseline
14914
+ } = attribute;
14915
+ if (!verticalMode) {
14916
+ const t = textAlign;
14917
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
14918
+ }
14919
+ if (!this.shouldUpdateShape() && this.cache) {
14920
+ width = this.cache.clipedWidth;
14921
+ const dx = textDrawOffsetX(textAlign, width),
14922
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14923
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14924
+ }
14925
+ let verticalList = [verticalLayout(text.toString())];
14926
+ if (Number.isFinite(maxLineWidth)) {
14927
+ if (ellipsis) {
14928
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
14929
+ data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
14930
+ fontSize: fontSize,
14931
+ fontWeight: fontWeight,
14932
+ fontFamily: fontFamily
14933
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
14934
+ verticalList = [data.verticalList], width = data.width;
14935
+ } else {
14936
+ const data = textMeasure.clipTextVertical(verticalList[0], {
14937
+ fontSize: fontSize,
14938
+ fontWeight: fontWeight,
14939
+ fontFamily: fontFamily
14940
+ }, maxLineWidth, !1);
14941
+ verticalList = [data.verticalList], width = data.width;
14942
+ }
14943
+ this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
14944
+ } else width = 0, verticalList[0].forEach(t => {
14945
+ const w = t.direction === TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
14946
+ fontSize: fontSize,
14947
+ fontWeight: fontWeight,
14948
+ fontFamily: fontFamily
14949
+ });
14950
+ width += w, t.width = w;
14951
+ }), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
14952
+ this.clearUpdateShapeTag();
14953
+ const dx = textDrawOffsetX(textAlign, width),
14954
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14955
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14956
+ }
14957
+ updateHorizontalMultilineAABBBounds(text) {
14910
14958
  var _a, _b;
14959
+ const textTheme = this.getGraphicTheme(),
14960
+ {
14961
+ wrap = textTheme.wrap
14962
+ } = this.attribute;
14963
+ if (wrap) return this.updateWrapAABBBounds(text);
14964
+ const attribute = this.attribute,
14965
+ {
14966
+ fontFamily = textTheme.fontFamily,
14967
+ textAlign = textTheme.textAlign,
14968
+ textBaseline = textTheme.textBaseline,
14969
+ fontSize = textTheme.fontSize,
14970
+ fontWeight = textTheme.fontWeight,
14971
+ ellipsis = textTheme.ellipsis,
14972
+ maxLineWidth: maxLineWidth,
14973
+ stroke = textTheme.stroke,
14974
+ lineWidth = textTheme.lineWidth,
14975
+ whiteSpace = textTheme.whiteSpace,
14976
+ suffixPosition = textTheme.suffixPosition
14977
+ } = attribute,
14978
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
14979
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
14980
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
14981
+ const bbox = this.cache.layoutData.bbox;
14982
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14983
+ }
14984
+ const textMeasure = application.graphicUtil.textMeasure,
14985
+ layoutData = new CanvasTextLayout(fontFamily, {
14986
+ fontSize: fontSize,
14987
+ fontWeight: fontWeight,
14988
+ fontFamily: fontFamily
14989
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
14990
+ {
14991
+ bbox: bbox
14992
+ } = layoutData;
14993
+ return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14994
+ }
14995
+ updateVerticalMultilineAABBBounds(text) {
14996
+ var _a, _b, _c;
14911
14997
  const textTheme = this.getGraphicTheme(),
14912
14998
  textMeasure = application.graphicUtil.textMeasure;
14913
14999
  let width;
14914
15000
  const attribute = this.attribute,
15001
+ {
15002
+ ignoreBuf = textTheme.ignoreBuf
15003
+ } = attribute,
15004
+ buf = ignoreBuf ? 0 : 2,
14915
15005
  {
14916
15006
  maxLineWidth = textTheme.maxLineWidth,
14917
15007
  ellipsis = textTheme.ellipsis,
@@ -14923,14 +15013,14 @@ class Text extends Graphic {
14923
15013
  verticalMode = textTheme.verticalMode,
14924
15014
  suffixPosition = textTheme.suffixPosition
14925
15015
  } = attribute,
14926
- lineHeight = this.getLineHeight(attribute, textTheme);
15016
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14927
15017
  let {
14928
15018
  textAlign = textTheme.textAlign,
14929
15019
  textBaseline = textTheme.textBaseline
14930
15020
  } = attribute;
14931
15021
  if (!verticalMode) {
14932
15022
  const t = textAlign;
14933
- textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
15023
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
14934
15024
  }
14935
15025
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
14936
15026
  this.cache.verticalList.forEach(item => {
@@ -14978,15 +15068,6 @@ class Text extends Graphic {
14978
15068
  dy = textLayoutOffsetY(textBaseline, height, fontSize);
14979
15069
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14980
15070
  }
14981
- getMaxWidth(theme) {
14982
- var _a, _b;
14983
- const attribute = this.attribute;
14984
- return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
14985
- }
14986
- getLineHeight(attribute, textTheme) {
14987
- var _a;
14988
- return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
14989
- }
14990
15071
  needUpdateTags(keys) {
14991
15072
  let k = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TEXT_UPDATE_TAG_KEY;
14992
15073
  return super.needUpdateTags(keys, k);
@@ -15001,12 +15082,6 @@ class Text extends Graphic {
15001
15082
  getNoWorkAnimateAttr() {
15002
15083
  return Text.NOWORK_ANIMATE_ATTR;
15003
15084
  }
15004
- getBaselineMapAlign() {
15005
- return Text.baselineMapAlign;
15006
- }
15007
- getAlignMapBaseline() {
15008
- return Text.alignMapBaseline;
15009
- }
15010
15085
  }
15011
15086
  Text.NOWORK_ANIMATE_ATTR = Object.assign({
15012
15087
  ellipsis: 1,
@@ -15085,9 +15160,7 @@ class WrapText extends Text {
15085
15160
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
15086
15161
  linesLayout.push({
15087
15162
  str: clip.str,
15088
- width: clip.width,
15089
- ascent: 0,
15090
- descent: 0
15163
+ width: clip.width
15091
15164
  });
15092
15165
  break;
15093
15166
  }
@@ -15101,9 +15174,7 @@ class WrapText extends Text {
15101
15174
  }
15102
15175
  if (linesLayout.push({
15103
15176
  str: clip.str,
15104
- width: clip.width,
15105
- ascent: 0,
15106
- descent: 0
15177
+ width: clip.width
15107
15178
  }), clip.str.length === str.length) ;else if (needCut) {
15108
15179
  const newStr = str.substring(clip.str.length);
15109
15180
  lines.splice(i + 1, 0, newStr);
@@ -15122,17 +15193,13 @@ class WrapText extends Text {
15122
15193
  const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
15123
15194
  linesLayout.push({
15124
15195
  str: clip.str,
15125
- width: clip.width,
15126
- ascent: 0,
15127
- descent: 0
15196
+ width: clip.width
15128
15197
  }), lineWidth = Math.max(lineWidth, clip.width);
15129
15198
  break;
15130
15199
  }
15131
15200
  text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
15132
15201
  str: text,
15133
- width: width,
15134
- ascent: 0,
15135
- descent: 0
15202
+ width: width
15136
15203
  });
15137
15204
  }
15138
15205
  bboxWH[0] = lineWidth;
@@ -23579,9 +23646,11 @@ function jsx(type, config) {
23579
23646
  name: name,
23580
23647
  id: id,
23581
23648
  attribute: attribute,
23582
- stateProxy: stateProxy
23649
+ stateProxy: stateProxy,
23650
+ animation: animation,
23651
+ timeline: timeline
23583
23652
  } = _a,
23584
- props = __rest(_a, ["key", "name", "id", "attribute", "stateProxy"]);
23653
+ props = __rest(_a, ["key", "name", "id", "attribute", "stateProxy", "animation", "timeline"]);
23585
23654
  let c = type;
23586
23655
  isString$1(type) && (c = graphicCreator[type]);
23587
23656
  const childrenList = [];
@@ -23590,7 +23659,13 @@ function jsx(type, config) {
23590
23659
  }
23591
23660
  children.length && flatten(1 === children.length ? children[0] : children, childrenList);
23592
23661
  const g = "Group" === c.name ? new c(attribute) : c(config);
23593
- return parseToGraphic$1(g, childrenList, props), stateProxy && (g.stateProxy = stateProxy), g;
23662
+ if (parseToGraphic$1(g, childrenList, props), stateProxy && (g.stateProxy = stateProxy), name && (g.name = name), isArray$1(animation)) {
23663
+ const animate = g.animate();
23664
+ timeline && animate.setTimeline(timeline), animation.forEach(item => {
23665
+ animate[item[0]](...item.slice(1));
23666
+ });
23667
+ }
23668
+ return g;
23594
23669
  }
23595
23670
  function parseToGraphic$1(g, childrenList, props) {
23596
23671
  let out,
@@ -28193,8 +28268,10 @@ let DefaultCanvasTextPicker = class extends Base3dPicker {
28193
28268
  } = text.attribute,
28194
28269
  bounds = text.AABBBounds,
28195
28270
  height = bounds.height(),
28196
- width = bounds.width();
28197
- return context.rect(bounds.x1, bounds.y1, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
28271
+ width = bounds.width(),
28272
+ offsetY = textLayoutOffsetY(textBaseline, height, fontSize),
28273
+ offsetX = textDrawOffsetX(textAlign, width);
28274
+ return context.rect(offsetX + x, offsetY + y, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
28198
28275
  }, (context, symbolAttribute, themeAttribute) => picked), this.canvasRenderer.z = 0, pickContext.modelMatrix !== lastModelMatrix && mat4Allocate.free(pickContext.modelMatrix), pickContext.modelMatrix = lastModelMatrix, pickContext.highPerformanceRestore(), picked;
28199
28276
  }
28200
28277
  };
@@ -28534,7 +28611,7 @@ const registerWrapText = _registerWrapText;
28534
28611
 
28535
28612
  const roughModule = _roughModule;
28536
28613
 
28537
- const version = "0.21.0-alpha.3";
28614
+ const version = "0.21.0-alpha.4";
28538
28615
  preLoadAllModule();
28539
28616
  if (isBrowserEnv()) {
28540
28617
  loadBrowserEnv(container);