@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.js CHANGED
@@ -3919,7 +3919,6 @@
3919
3919
  const DefaultTextStyle = {
3920
3920
  text: "",
3921
3921
  maxLineWidth: 1 / 0,
3922
- maxWidth: 1 / 0,
3923
3922
  textAlign: "left",
3924
3923
  textBaseline: "alphabetic",
3925
3924
  fontSize: 16,
@@ -4272,32 +4271,10 @@
4272
4271
  configure(service, env) {
4273
4272
  this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
4274
4273
  }
4275
- _measureTextWithoutAlignBaseline(text, options, compatible) {
4274
+ measureTextWidth(text, options) {
4275
+ if (!this.context) return this.estimate(text, options).width;
4276
4276
  this.context.setTextStyleWithoutAlignBaseline(options);
4277
- const metrics = this.context.measureText(text);
4278
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
4279
- }
4280
- _measureTextWithAlignBaseline(text, options, compatible) {
4281
- this.context.setTextStyle(options);
4282
- const metrics = this.context.measureText(text);
4283
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
4284
- }
4285
- compatibleMetrics(metrics, options) {
4286
- if (null == metrics.actualBoundingBoxAscent || null == metrics.actualBoundingBoxDescent || null == metrics.fontBoundingBoxAscent || null == metrics.fontBoundingBoxDescent) {
4287
- const {
4288
- ascent: ascent,
4289
- descent: descent
4290
- } = this.measureTextBoundADscentEstimate(options);
4291
- metrics.actualBoundingBoxAscent = ascent, metrics.actualBoundingBoxDescent = descent, metrics.fontBoundingBoxAscent = ascent, metrics.fontBoundingBoxDescent = descent;
4292
- }
4293
- if (null == metrics.actualBoundingBoxLeft || null == metrics.actualBoundingBoxRight) {
4294
- const {
4295
- left: left,
4296
- right: right
4297
- } = this.measureTextBoundLeftRightEstimate(options);
4298
- metrics.actualBoundingBoxLeft = left, metrics.actualBoundingBoxRight = right;
4299
- }
4300
- return metrics;
4277
+ return this.context.measureText(text).width;
4301
4278
  }
4302
4279
  estimate(text, _ref) {
4303
4280
  let {
@@ -4311,85 +4288,19 @@
4311
4288
  height: fontSize
4312
4289
  };
4313
4290
  }
4314
- measureTextWidth(text, options, textMeasure) {
4315
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
4316
- }
4317
- measureTextBoundsWidth(text, options, textMeasure) {
4318
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
4319
- }
4320
- measureTextBoundsLeftRight(text, options, textMeasure) {
4321
- return this.context ? {
4322
- left: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxLeft,
4323
- right: textMeasure.actualBoundingBoxRight
4324
- } : this.measureTextBoundLeftRightEstimate(options);
4325
- }
4326
- measureTextPixelHeight(text, options, textMeasure) {
4291
+ measureTextPixelHeight(text, options) {
4327
4292
  var _a;
4328
- 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;
4329
- }
4330
- measureTextPixelADscent(text, options, textMeasure) {
4331
- return this.context ? {
4332
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxAscent,
4333
- descent: textMeasure.actualBoundingBoxDescent
4334
- } : this.measureTextBoundADscentEstimate(options);
4335
- }
4336
- measureTextBoundHieght(text, options, textMeasure) {
4337
- var _a;
4338
- 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;
4339
- }
4340
- measureTextBoundADscent(text, options, textMeasure) {
4341
- return this.context ? {
4342
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).fontBoundingBoxAscent,
4343
- descent: textMeasure.fontBoundingBoxDescent
4344
- } : this.measureTextBoundADscentEstimate(options);
4345
- }
4346
- measureTextBoundADscentEstimate(options) {
4347
- var _a;
4348
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
4349
- {
4350
- textBaseline: textBaseline
4351
- } = options;
4352
- return "bottom" === textBaseline ? {
4353
- ascent: fontSize,
4354
- descent: 0
4355
- } : "middle" === textBaseline ? {
4356
- ascent: fontSize / 2,
4357
- descent: fontSize / 2
4358
- } : "alphabetic" === textBaseline ? {
4359
- ascent: .79 * fontSize,
4360
- descent: .21 * fontSize
4361
- } : {
4362
- ascent: 0,
4363
- descent: fontSize
4364
- };
4293
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4294
+ this.context.setTextStyleWithoutAlignBaseline(options);
4295
+ const textMeasure = this.context.measureText(text);
4296
+ return Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent);
4365
4297
  }
4366
- measureTextBoundLeftRightEstimate(options) {
4298
+ measureTextBoundHieght(text, options) {
4367
4299
  var _a;
4368
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
4369
- {
4370
- textAlign: textAlign
4371
- } = options;
4372
- return "center" === textAlign ? {
4373
- left: fontSize / 2,
4374
- right: fontSize / 2
4375
- } : "right" === textAlign || "end" === textAlign ? {
4376
- left: fontSize,
4377
- right: 0
4378
- } : {
4379
- left: 0,
4380
- right: fontSize
4381
- };
4382
- }
4383
- measureTextPixelADscentAndWidth(text, options) {
4384
- if (!this.context) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
4385
- width: this.estimate(text, options).width
4386
- });
4387
- const out = this._measureTextWithoutAlignBaseline(text, options, !0);
4388
- return {
4389
- ascent: out.actualBoundingBoxAscent,
4390
- descent: out.actualBoundingBoxDescent,
4391
- width: out.width
4392
- };
4300
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
4301
+ this.context.setTextStyleWithoutAlignBaseline(options);
4302
+ const textMeasure = this.context.measureText(text);
4303
+ return Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent);
4393
4304
  }
4394
4305
  measureText(text, options) {
4395
4306
  return this.context ? (this.context.setTextStyleWithoutAlignBaseline(options), this.context.measureText(text)) : this.estimate(text, options);
@@ -9189,7 +9100,7 @@
9189
9100
  }
9190
9101
  static GetFile(url, type) {
9191
9102
  let data = ResourceLoader.cache.get(url);
9192
- return data ? "init" === data.loadState || "fail" === data.loadState ? Promise.reject() : "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
9103
+ return data ? "fail" === data.loadState ? Promise.reject() : "init" === data.loadState || "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
9193
9104
  type: type,
9194
9105
  loadState: "init"
9195
9106
  }, 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));
@@ -12453,8 +12364,9 @@
12453
12364
  constructor() {
12454
12365
  super(...arguments), this.time = exports.BaseRenderContributionTime.afterFillStroke, this.useStyle = !0, this.order = 0;
12455
12366
  }
12456
- drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
12457
- return super.drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
12367
+ drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
12368
+ if (!(image.isGifImage && image.renderFrame && image.playing)) return super.drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
12369
+ image.renderFrame(context, x, y);
12458
12370
  }
12459
12371
  }
12460
12372
  const defaultImageRenderContribution = new DefaultImageRenderContribution();
@@ -13796,50 +13708,77 @@
13796
13708
  }
13797
13709
  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());
13798
13710
  };
13799
- if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
13800
- const {
13801
- multilineLayout: multilineLayout
13802
- } = text;
13803
- if (!multilineLayout) return void context.highPerformanceRestore();
13804
- const {
13805
- xOffset: xOffset,
13806
- yOffset: yOffset
13807
- } = multilineLayout.bbox;
13808
- doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13809
- context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
13810
- }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13811
- 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, {
13812
- width: line.width
13711
+ if (text.isMultiLine) {
13712
+ if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
13713
+ const {
13714
+ multilineLayout: multilineLayout
13715
+ } = text;
13716
+ if (!multilineLayout) return void context.highPerformanceRestore();
13717
+ const {
13718
+ xOffset: xOffset,
13719
+ yOffset: yOffset
13720
+ } = multilineLayout.bbox;
13721
+ doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13722
+ context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
13723
+ }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
13724
+ 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, {
13725
+ width: line.width
13726
+ });
13727
+ })));
13728
+ } else {
13729
+ text.tryUpdateAABBBounds();
13730
+ const cache = text.cache,
13731
+ {
13732
+ verticalList: verticalList
13733
+ } = cache;
13734
+ context.textAlign = "left", context.textBaseline = "top";
13735
+ const totalHeight = lineHeight * verticalList.length;
13736
+ let totalW = 0;
13737
+ verticalList.forEach(verticalData => {
13738
+ const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
13739
+ totalW = max(_w, totalW);
13740
+ });
13741
+ let offsetY = 0,
13742
+ offsetX = 0;
13743
+ "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
13744
+ const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
13745
+ dw = totalW - currentW;
13746
+ let currentOffsetY = offsetY;
13747
+ "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
13748
+ const {
13749
+ text: text,
13750
+ width: width,
13751
+ direction: direction
13752
+ } = item;
13753
+ drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
13754
+ });
13813
13755
  });
13814
- })));
13756
+ }
13757
+ } else if ("horizontal" === direction) {
13758
+ context.setTextStyle(text.attribute, textAttribute, z);
13759
+ const t = text.clipedText;
13760
+ let dy = 0;
13761
+ lineHeight !== fontSize && ("top" === textBaseline ? dy = (lineHeight - fontSize) / 2 : "middle" === textBaseline || "bottom" === textBaseline && (dy = -(lineHeight - fontSize) / 2)), drawText(t, 0, dy, 0);
13815
13762
  } else {
13816
13763
  text.tryUpdateAABBBounds();
13817
- const cache = text.cache,
13818
- {
13764
+ const cache = text.cache;
13765
+ if (cache) {
13766
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
13767
+ const {
13819
13768
  verticalList: verticalList
13820
13769
  } = cache;
13821
- context.textAlign = "left", context.textBaseline = "top";
13822
- const totalHeight = lineHeight * verticalList.length;
13823
- let totalW = 0;
13824
- verticalList.forEach(verticalData => {
13825
- const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
13826
- totalW = max(_w, totalW);
13827
- });
13828
- let offsetY = 0,
13829
- offsetX = 0;
13830
- "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
13831
- const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
13832
- dw = totalW - currentW;
13833
- let currentOffsetY = offsetY;
13834
- "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
13770
+ let offsetY = 0;
13771
+ const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
13772
+ let offsetX = 0;
13773
+ "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 => {
13835
13774
  const {
13836
13775
  text: text,
13837
13776
  width: width,
13838
13777
  direction: direction
13839
13778
  } = item;
13840
- drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
13779
+ drawText(text, offsetX, offsetY, direction), offsetY += width;
13841
13780
  });
13842
- });
13781
+ }
13843
13782
  }
13844
13783
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context), this.afterRenderStep(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb);
13845
13784
  }
@@ -14177,10 +14116,12 @@
14177
14116
  const {
14178
14117
  image: url
14179
14118
  } = image.attribute;
14180
- if (!url || !image.resources) return;
14181
- const res = image.resources.get(url);
14182
- if ("loading" === res.state && isString$1(url)) return void ResourceLoader.improveImageLoading(url);
14183
- if ("success" !== res.state) return;
14119
+ if (!image.isGifImage) {
14120
+ if (!url || !image.resources) return;
14121
+ const res = image.resources.get(url);
14122
+ if ("loading" === res.state && isString$1(url)) return void ResourceLoader.improveImageLoading(url);
14123
+ if ("success" !== res.state) return;
14124
+ }
14184
14125
  const {
14185
14126
  context: context
14186
14127
  } = renderService.drawParams;
@@ -14572,6 +14513,28 @@
14572
14513
  }
14573
14514
  return bbox.yOffset = "top" === textBaseline ? 0 : "middle" === textBaseline ? bbox.height / -2 : "alphabetic" === textBaseline ? -.79 * bbox.height : -bbox.height, bbox;
14574
14515
  }
14516
+ GetLayout(str, width, height, textAlign, textBaseline, lineHeight, suffix, wordBreak, suffixPosition) {
14517
+ const linesLayout = [],
14518
+ bboxWH = [width, height],
14519
+ bboxOffset = [0, 0];
14520
+ for (; str.length > 0;) {
14521
+ const {
14522
+ str: clipText
14523
+ } = this.textMeasure.clipTextWithSuffix(str, this.textOptions, width, suffix, wordBreak, suffixPosition);
14524
+ linesLayout.push({
14525
+ str: clipText,
14526
+ width: this.textMeasure.measureTextWidth(clipText, this.textOptions)
14527
+ }), str = str.substring(clipText.length);
14528
+ }
14529
+ "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]));
14530
+ const bbox = {
14531
+ xOffset: bboxOffset[0],
14532
+ yOffset: bboxOffset[1],
14533
+ width: bboxWH[0],
14534
+ height: bboxWH[1]
14535
+ };
14536
+ return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
14537
+ }
14575
14538
  GetLayoutByLines(lines, textAlign, textBaseline, lineHeight) {
14576
14539
  let suffix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
14577
14540
  let wordBreak = arguments.length > 5 ? arguments[5] : undefined;
@@ -14582,29 +14545,18 @@
14582
14545
  bboxWH = [0, 0];
14583
14546
  if ("number" == typeof lineWidth && lineWidth !== 1 / 0) {
14584
14547
  let width;
14585
- for (let i = 0, len = lines.length; i < len; i++) {
14586
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
14587
- width = Math.min(metrics.width, lineWidth), linesLayout.push({
14588
- str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
14589
- width: width,
14590
- ascent: metrics.ascent,
14591
- descent: metrics.descent
14592
- });
14593
- }
14548
+ for (let i = 0, len = lines.length; i < len; i++) width = Math.min(this.textMeasure.measureTextWidth(lines[i], this.textOptions), lineWidth), linesLayout.push({
14549
+ str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
14550
+ width: width
14551
+ });
14594
14552
  bboxWH[0] = lineWidth;
14595
14553
  } else {
14596
14554
  let width, text;
14597
14555
  lineWidth = 0;
14598
- for (let i = 0, len = lines.length; i < len; i++) {
14599
- text = lines[i];
14600
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
14601
- width = metrics.width, lineWidth = Math.max(lineWidth, width), linesLayout.push({
14602
- str: text,
14603
- width: width,
14604
- ascent: metrics.ascent,
14605
- descent: metrics.descent
14606
- });
14607
- }
14556
+ 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({
14557
+ str: text,
14558
+ width: width
14559
+ });
14608
14560
  bboxWH[0] = lineWidth;
14609
14561
  }
14610
14562
  bboxWH[1] = linesLayout.length * lineHeight, bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);
@@ -14633,11 +14585,11 @@
14633
14585
  };
14634
14586
  }
14635
14587
  lineOffset(bbox, line, textAlign, textBaseline, lineHeight, origin) {
14636
- 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;
14588
+ 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;
14637
14589
  }
14638
14590
  }
14639
14591
 
14640
- 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];
14592
+ const TEXT_UPDATE_TAG_KEY = ["text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY];
14641
14593
  class Text extends Graphic {
14642
14594
  get font() {
14643
14595
  const textTheme = this.getGraphicTheme();
@@ -14646,22 +14598,26 @@
14646
14598
  get clipedText() {
14647
14599
  var _a;
14648
14600
  const attribute = this.attribute,
14649
- textTheme = this.getGraphicTheme(),
14650
- maxWidth = this.getMaxWidth(textTheme);
14651
- return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
14601
+ textTheme = this.getGraphicTheme();
14602
+ if (!this.isSimplify()) return;
14603
+ const {
14604
+ maxLineWidth = textTheme.maxLineWidth
14605
+ } = attribute;
14606
+ return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
14652
14607
  }
14653
14608
  get clipedWidth() {
14654
- return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
14609
+ if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
14655
14610
  }
14656
14611
  get cliped() {
14657
14612
  var _a, _b;
14658
14613
  const textTheme = this.getGraphicTheme(),
14659
14614
  attribute = this.attribute,
14660
- maxWidth = this.getMaxWidth(textTheme);
14661
- if (!Number.isFinite(maxWidth)) return !1;
14662
- const {
14663
- text: text
14664
- } = this.attribute;
14615
+ {
14616
+ maxLineWidth = textTheme.maxLineWidth,
14617
+ text: text,
14618
+ whiteSpace = textTheme.whiteSpace
14619
+ } = attribute;
14620
+ if (!Number.isFinite(maxLineWidth)) return !1;
14665
14621
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
14666
14622
  let mergedText = "";
14667
14623
  this.cache.layoutData.lines.forEach(item => {
@@ -14672,7 +14628,10 @@
14672
14628
  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();
14673
14629
  }
14674
14630
  get multilineLayout() {
14675
- return this.tryUpdateAABBBounds(), this.cache.layoutData;
14631
+ if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
14632
+ }
14633
+ isSimplify() {
14634
+ return !this.isMultiLine && "vertical" !== this.attribute.direction;
14676
14635
  }
14677
14636
  get isMultiLine() {
14678
14637
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -14745,63 +14704,8 @@
14745
14704
  }
14746
14705
  return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds), transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
14747
14706
  }
14748
- updateSingallineAABBBounds(text) {
14749
- this.updateMultilineAABBBounds([text]);
14750
- const layoutData = this.cache.layoutData;
14751
- if (layoutData) {
14752
- const line = layoutData.lines[0];
14753
- this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
14754
- }
14755
- return this._AABBBounds;
14756
- }
14757
- updateMultilineAABBBounds(text) {
14758
- const textTheme = this.getGraphicTheme(),
14759
- {
14760
- direction = textTheme.direction,
14761
- underlineOffset = textTheme.underlineOffset
14762
- } = this.attribute,
14763
- b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
14764
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14765
- }
14766
- updateHorizontalMultilineAABBBounds(text) {
14767
- var _a;
14768
- const textTheme = this.getGraphicTheme(),
14769
- attribute = this.attribute,
14770
- {
14771
- fontFamily = textTheme.fontFamily,
14772
- textAlign = textTheme.textAlign,
14773
- textBaseline = textTheme.textBaseline,
14774
- fontSize = textTheme.fontSize,
14775
- fontWeight = textTheme.fontWeight,
14776
- ellipsis = textTheme.ellipsis,
14777
- maxLineWidth: maxLineWidth,
14778
- stroke = textTheme.stroke,
14779
- wrap = textTheme.wrap,
14780
- ignoreBuf = textTheme.ignoreBuf,
14781
- lineWidth = textTheme.lineWidth,
14782
- whiteSpace = textTheme.whiteSpace,
14783
- suffixPosition = textTheme.suffixPosition
14784
- } = attribute,
14785
- buf = ignoreBuf ? 0 : 2,
14786
- lineHeight = this.getLineHeight(attribute, textTheme) + buf;
14787
- if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
14788
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
14789
- const bbox = this.cache.layoutData.bbox;
14790
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14791
- }
14792
- const textMeasure = application.graphicUtil.textMeasure,
14793
- layoutData = new CanvasTextLayout(fontFamily, {
14794
- fontSize: fontSize,
14795
- fontWeight: fontWeight,
14796
- fontFamily: fontFamily
14797
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
14798
- {
14799
- bbox: bbox
14800
- } = layoutData;
14801
- 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;
14802
- }
14803
14707
  updateWrapAABBBounds(text) {
14804
- var _a, _b, _c;
14708
+ var _a, _b, _c, _d;
14805
14709
  const textTheme = this.getGraphicTheme(),
14806
14710
  {
14807
14711
  fontFamily = textTheme.fontFamily,
@@ -14819,19 +14723,18 @@
14819
14723
  heightLimit = 0,
14820
14724
  lineClamp: lineClamp
14821
14725
  } = this.attribute,
14822
- buf = ignoreBuf ? 0 : 2,
14823
- lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
14824
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
14726
+ lineHeight = null !== (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize,
14727
+ buf = ignoreBuf ? 0 : 2;
14728
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
14825
14729
  const bbox = this.cache.layoutData.bbox;
14826
14730
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14827
14731
  }
14828
14732
  const textMeasure = application.graphicUtil.textMeasure,
14829
- textOptions = {
14733
+ layoutObj = new CanvasTextLayout(fontFamily, {
14830
14734
  fontSize: fontSize,
14831
14735
  fontWeight: fontWeight,
14832
14736
  fontFamily: fontFamily
14833
- },
14834
- layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure),
14737
+ }, textMeasure),
14835
14738
  lines = isArray$1(text) ? text.map(l => l.toString()) : [text.toString()],
14836
14739
  linesLayout = [],
14837
14740
  bboxWH = [0, 0];
@@ -14841,33 +14744,29 @@
14841
14744
  const str = lines[i];
14842
14745
  let needCut = !0;
14843
14746
  if (i === lineCountLimit - 1) {
14844
- const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1),
14845
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14747
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
14846
14748
  linesLayout.push({
14847
14749
  str: clip.str,
14848
- width: clip.width,
14849
- ascent: matrics.ascent,
14850
- descent: matrics.descent
14750
+ width: clip.width
14851
14751
  });
14852
14752
  break;
14853
14753
  }
14854
- const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-word" === wordBreak);
14855
- if ("" !== str && "" === clip.str) {
14754
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
14755
+ if ("" !== str && "" === clip.str || clip.wordBreaked) {
14856
14756
  if (ellipsis) {
14857
- const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14858
- clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
14757
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14758
+ clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
14859
14759
  } else clip.str = "", clip.width = 0;
14860
14760
  needCut = !1;
14861
14761
  }
14862
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14863
- if (linesLayout.push({
14762
+ linesLayout.push({
14864
14763
  str: clip.str,
14865
- width: clip.width,
14866
- ascent: matrics.ascent,
14867
- descent: matrics.descent
14868
- }), clip.str.length === str.length) ;else if (needCut) {
14869
- const newStr = str.substring(clip.str.length);
14870
- lines.splice(i + 1, 0, newStr);
14764
+ width: clip.width
14765
+ });
14766
+ let cutLength = clip.str.length;
14767
+ if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked), clip.str.length === str.length) ;else if (needCut) {
14768
+ let newStr = str.substring(cutLength);
14769
+ "keep-all" === wordBreak && (newStr = newStr.replace(/^\s+/g, "")), lines.splice(i + 1, 0, newStr);
14871
14770
  }
14872
14771
  }
14873
14772
  let maxWidth = 0;
@@ -14880,28 +14779,21 @@
14880
14779
  lineWidth = 0;
14881
14780
  for (let i = 0, len = lines.length; i < len; i++) {
14882
14781
  if (i === lineCountLimit - 1) {
14883
- const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition),
14884
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
14782
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
14885
14783
  linesLayout.push({
14886
14784
  str: clip.str,
14887
- width: clip.width,
14888
- ascent: matrics.ascent,
14889
- descent: matrics.descent
14785
+ width: clip.width
14890
14786
  }), lineWidth = Math.max(lineWidth, clip.width);
14891
14787
  break;
14892
14788
  }
14893
- text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
14894
- const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions);
14895
- linesLayout.push({
14789
+ text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
14896
14790
  str: text,
14897
- width: width,
14898
- ascent: matrics.ascent,
14899
- descent: matrics.descent
14791
+ width: width
14900
14792
  });
14901
14793
  }
14902
14794
  bboxWH[0] = lineWidth;
14903
14795
  }
14904
- bboxWH[1] = linesLayout.length * lineHeight;
14796
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
14905
14797
  const bbox = {
14906
14798
  xOffset: 0,
14907
14799
  yOffset: 0,
@@ -14912,12 +14804,210 @@
14912
14804
  const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
14913
14805
  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;
14914
14806
  }
14915
- updateVerticalMultilineAABBBounds(text) {
14807
+ updateSingallineAABBBounds(text) {
14808
+ const textTheme = this.getGraphicTheme(),
14809
+ {
14810
+ direction = textTheme.direction,
14811
+ underlineOffset = textTheme.underlineOffset
14812
+ } = this.attribute,
14813
+ b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
14814
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14815
+ }
14816
+ updateMultilineAABBBounds(text) {
14817
+ const textTheme = this.getGraphicTheme(),
14818
+ {
14819
+ direction = textTheme.direction,
14820
+ underlineOffset = textTheme.underlineOffset
14821
+ } = this.attribute,
14822
+ b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
14823
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
14824
+ }
14825
+ updateHorizontalSinglelineAABBBounds(text) {
14826
+ var _a, _b;
14827
+ const textTheme = this.getGraphicTheme(),
14828
+ {
14829
+ wrap = textTheme.wrap
14830
+ } = this.attribute;
14831
+ if (wrap) return this.updateWrapAABBBounds([text]);
14832
+ const textMeasure = application.graphicUtil.textMeasure;
14833
+ let width, str;
14834
+ const attribute = this.attribute,
14835
+ {
14836
+ maxLineWidth = textTheme.maxLineWidth,
14837
+ ellipsis = textTheme.ellipsis,
14838
+ textAlign = textTheme.textAlign,
14839
+ textBaseline = textTheme.textBaseline,
14840
+ fontFamily = textTheme.fontFamily,
14841
+ fontSize = textTheme.fontSize,
14842
+ fontWeight = textTheme.fontWeight,
14843
+ stroke = textTheme.stroke,
14844
+ lineWidth = textTheme.lineWidth,
14845
+ ignoreBuf = textTheme.ignoreBuf,
14846
+ whiteSpace = textTheme.whiteSpace,
14847
+ suffixPosition = textTheme.suffixPosition
14848
+ } = attribute;
14849
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
14850
+ const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize),
14851
+ textFontSize = attribute.fontSize || textTheme.fontSize,
14852
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
14853
+ if (!this.shouldUpdateShape() && this.cache) {
14854
+ width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
14855
+ const dx = textDrawOffsetX(textAlign, width),
14856
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14857
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14858
+ }
14859
+ if (Number.isFinite(maxLineWidth)) {
14860
+ if (ellipsis) {
14861
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
14862
+ data = textMeasure.clipTextWithSuffix(text.toString(), {
14863
+ fontSize: fontSize,
14864
+ fontWeight: fontWeight,
14865
+ fontFamily: fontFamily
14866
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
14867
+ str = data.str, width = data.width;
14868
+ } else {
14869
+ const data = textMeasure.clipText(text.toString(), {
14870
+ fontSize: fontSize,
14871
+ fontWeight: fontWeight,
14872
+ fontFamily: fontFamily
14873
+ }, maxLineWidth, !1);
14874
+ str = data.str, width = data.width;
14875
+ }
14876
+ this.cache.clipedText = str, this.cache.clipedWidth = width;
14877
+ } else width = textMeasure.measureTextWidth(text.toString(), {
14878
+ fontSize: fontSize,
14879
+ fontWeight: fontWeight,
14880
+ fontFamily: fontFamily
14881
+ }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
14882
+ this.clearUpdateShapeTag();
14883
+ const dx = textDrawOffsetX(textAlign, width);
14884
+ let lh = lineHeight;
14885
+ application.global && application.global.isSafari() && (lh += .2 * fontSize);
14886
+ const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
14887
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14888
+ }
14889
+ getBaselineMapAlign() {
14890
+ return Text.baselineMapAlign;
14891
+ }
14892
+ getAlignMapBaseline() {
14893
+ return Text.alignMapBaseline;
14894
+ }
14895
+ updateVerticalSinglelineAABBBounds(text) {
14896
+ var _a, _b, _c;
14897
+ const textTheme = this.getGraphicTheme(),
14898
+ textMeasure = application.graphicUtil.textMeasure;
14899
+ let width;
14900
+ const attribute = this.attribute,
14901
+ {
14902
+ ignoreBuf = textTheme.ignoreBuf
14903
+ } = attribute,
14904
+ buf = ignoreBuf ? 0 : 2,
14905
+ {
14906
+ maxLineWidth = textTheme.maxLineWidth,
14907
+ ellipsis = textTheme.ellipsis,
14908
+ fontSize = textTheme.fontSize,
14909
+ fontWeight = textTheme.fontWeight,
14910
+ fontFamily = textTheme.fontFamily,
14911
+ stroke = textTheme.stroke,
14912
+ lineWidth = textTheme.lineWidth,
14913
+ verticalMode = textTheme.verticalMode,
14914
+ suffixPosition = textTheme.suffixPosition
14915
+ } = attribute,
14916
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14917
+ let {
14918
+ textAlign = textTheme.textAlign,
14919
+ textBaseline = textTheme.textBaseline
14920
+ } = attribute;
14921
+ if (!verticalMode) {
14922
+ const t = textAlign;
14923
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
14924
+ }
14925
+ if (!this.shouldUpdateShape() && this.cache) {
14926
+ width = this.cache.clipedWidth;
14927
+ const dx = textDrawOffsetX(textAlign, width),
14928
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14929
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14930
+ }
14931
+ let verticalList = [verticalLayout(text.toString())];
14932
+ if (Number.isFinite(maxLineWidth)) {
14933
+ if (ellipsis) {
14934
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
14935
+ data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
14936
+ fontSize: fontSize,
14937
+ fontWeight: fontWeight,
14938
+ fontFamily: fontFamily
14939
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
14940
+ verticalList = [data.verticalList], width = data.width;
14941
+ } else {
14942
+ const data = textMeasure.clipTextVertical(verticalList[0], {
14943
+ fontSize: fontSize,
14944
+ fontWeight: fontWeight,
14945
+ fontFamily: fontFamily
14946
+ }, maxLineWidth, !1);
14947
+ verticalList = [data.verticalList], width = data.width;
14948
+ }
14949
+ this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
14950
+ } else width = 0, verticalList[0].forEach(t => {
14951
+ const w = t.direction === exports.TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
14952
+ fontSize: fontSize,
14953
+ fontWeight: fontWeight,
14954
+ fontFamily: fontFamily
14955
+ });
14956
+ width += w, t.width = w;
14957
+ }), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
14958
+ this.clearUpdateShapeTag();
14959
+ const dx = textDrawOffsetX(textAlign, width),
14960
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
14961
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14962
+ }
14963
+ updateHorizontalMultilineAABBBounds(text) {
14916
14964
  var _a, _b;
14965
+ const textTheme = this.getGraphicTheme(),
14966
+ {
14967
+ wrap = textTheme.wrap
14968
+ } = this.attribute;
14969
+ if (wrap) return this.updateWrapAABBBounds(text);
14970
+ const attribute = this.attribute,
14971
+ {
14972
+ fontFamily = textTheme.fontFamily,
14973
+ textAlign = textTheme.textAlign,
14974
+ textBaseline = textTheme.textBaseline,
14975
+ fontSize = textTheme.fontSize,
14976
+ fontWeight = textTheme.fontWeight,
14977
+ ellipsis = textTheme.ellipsis,
14978
+ maxLineWidth: maxLineWidth,
14979
+ stroke = textTheme.stroke,
14980
+ lineWidth = textTheme.lineWidth,
14981
+ whiteSpace = textTheme.whiteSpace,
14982
+ suffixPosition = textTheme.suffixPosition
14983
+ } = attribute,
14984
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
14985
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
14986
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
14987
+ const bbox = this.cache.layoutData.bbox;
14988
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14989
+ }
14990
+ const textMeasure = application.graphicUtil.textMeasure,
14991
+ layoutData = new CanvasTextLayout(fontFamily, {
14992
+ fontSize: fontSize,
14993
+ fontWeight: fontWeight,
14994
+ fontFamily: fontFamily
14995
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
14996
+ {
14997
+ bbox: bbox
14998
+ } = layoutData;
14999
+ 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;
15000
+ }
15001
+ updateVerticalMultilineAABBBounds(text) {
15002
+ var _a, _b, _c;
14917
15003
  const textTheme = this.getGraphicTheme(),
14918
15004
  textMeasure = application.graphicUtil.textMeasure;
14919
15005
  let width;
14920
15006
  const attribute = this.attribute,
15007
+ {
15008
+ ignoreBuf = textTheme.ignoreBuf
15009
+ } = attribute,
15010
+ buf = ignoreBuf ? 0 : 2,
14921
15011
  {
14922
15012
  maxLineWidth = textTheme.maxLineWidth,
14923
15013
  ellipsis = textTheme.ellipsis,
@@ -14929,14 +15019,14 @@
14929
15019
  verticalMode = textTheme.verticalMode,
14930
15020
  suffixPosition = textTheme.suffixPosition
14931
15021
  } = attribute,
14932
- lineHeight = this.getLineHeight(attribute, textTheme);
15022
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
14933
15023
  let {
14934
15024
  textAlign = textTheme.textAlign,
14935
15025
  textBaseline = textTheme.textBaseline
14936
15026
  } = attribute;
14937
15027
  if (!verticalMode) {
14938
15028
  const t = textAlign;
14939
- textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
15029
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
14940
15030
  }
14941
15031
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
14942
15032
  this.cache.verticalList.forEach(item => {
@@ -14984,15 +15074,6 @@
14984
15074
  dy = textLayoutOffsetY(textBaseline, height, fontSize);
14985
15075
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
14986
15076
  }
14987
- getMaxWidth(theme) {
14988
- var _a, _b;
14989
- const attribute = this.attribute;
14990
- return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
14991
- }
14992
- getLineHeight(attribute, textTheme) {
14993
- var _a;
14994
- return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
14995
- }
14996
15077
  needUpdateTags(keys) {
14997
15078
  let k = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TEXT_UPDATE_TAG_KEY;
14998
15079
  return super.needUpdateTags(keys, k);
@@ -15007,12 +15088,6 @@
15007
15088
  getNoWorkAnimateAttr() {
15008
15089
  return Text.NOWORK_ANIMATE_ATTR;
15009
15090
  }
15010
- getBaselineMapAlign() {
15011
- return Text.baselineMapAlign;
15012
- }
15013
- getAlignMapBaseline() {
15014
- return Text.alignMapBaseline;
15015
- }
15016
15091
  }
15017
15092
  Text.NOWORK_ANIMATE_ATTR = Object.assign({
15018
15093
  ellipsis: 1,
@@ -15091,9 +15166,7 @@
15091
15166
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
15092
15167
  linesLayout.push({
15093
15168
  str: clip.str,
15094
- width: clip.width,
15095
- ascent: 0,
15096
- descent: 0
15169
+ width: clip.width
15097
15170
  });
15098
15171
  break;
15099
15172
  }
@@ -15107,9 +15180,7 @@
15107
15180
  }
15108
15181
  if (linesLayout.push({
15109
15182
  str: clip.str,
15110
- width: clip.width,
15111
- ascent: 0,
15112
- descent: 0
15183
+ width: clip.width
15113
15184
  }), clip.str.length === str.length) ;else if (needCut) {
15114
15185
  const newStr = str.substring(clip.str.length);
15115
15186
  lines.splice(i + 1, 0, newStr);
@@ -15128,17 +15199,13 @@
15128
15199
  const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
15129
15200
  linesLayout.push({
15130
15201
  str: clip.str,
15131
- width: clip.width,
15132
- ascent: 0,
15133
- descent: 0
15202
+ width: clip.width
15134
15203
  }), lineWidth = Math.max(lineWidth, clip.width);
15135
15204
  break;
15136
15205
  }
15137
15206
  text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
15138
15207
  str: text,
15139
- width: width,
15140
- ascent: 0,
15141
- descent: 0
15208
+ width: width
15142
15209
  });
15143
15210
  }
15144
15211
  bboxWH[0] = lineWidth;
@@ -23585,9 +23652,11 @@
23585
23652
  name: name,
23586
23653
  id: id,
23587
23654
  attribute: attribute,
23588
- stateProxy: stateProxy
23655
+ stateProxy: stateProxy,
23656
+ animation: animation,
23657
+ timeline: timeline
23589
23658
  } = _a,
23590
- props = __rest(_a, ["key", "name", "id", "attribute", "stateProxy"]);
23659
+ props = __rest(_a, ["key", "name", "id", "attribute", "stateProxy", "animation", "timeline"]);
23591
23660
  let c = type;
23592
23661
  isString$1(type) && (c = graphicCreator[type]);
23593
23662
  const childrenList = [];
@@ -23596,7 +23665,13 @@
23596
23665
  }
23597
23666
  children.length && flatten(1 === children.length ? children[0] : children, childrenList);
23598
23667
  const g = "Group" === c.name ? new c(attribute) : c(config);
23599
- return parseToGraphic$1(g, childrenList, props), stateProxy && (g.stateProxy = stateProxy), g;
23668
+ if (parseToGraphic$1(g, childrenList, props), stateProxy && (g.stateProxy = stateProxy), name && (g.name = name), isArray$1(animation)) {
23669
+ const animate = g.animate();
23670
+ timeline && animate.setTimeline(timeline), animation.forEach(item => {
23671
+ animate[item[0]](...item.slice(1));
23672
+ });
23673
+ }
23674
+ return g;
23600
23675
  }
23601
23676
  function parseToGraphic$1(g, childrenList, props) {
23602
23677
  let out,
@@ -28199,8 +28274,10 @@
28199
28274
  } = text.attribute,
28200
28275
  bounds = text.AABBBounds,
28201
28276
  height = bounds.height(),
28202
- width = bounds.width();
28203
- return context.rect(bounds.x1, bounds.y1, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
28277
+ width = bounds.width(),
28278
+ offsetY = textLayoutOffsetY(textBaseline, height, fontSize),
28279
+ offsetX = textDrawOffsetX(textAlign, width);
28280
+ return context.rect(offsetX + x, offsetY + y, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
28204
28281
  }, (context, symbolAttribute, themeAttribute) => picked), this.canvasRenderer.z = 0, pickContext.modelMatrix !== lastModelMatrix && mat4Allocate.free(pickContext.modelMatrix), pickContext.modelMatrix = lastModelMatrix, pickContext.highPerformanceRestore(), picked;
28205
28282
  }
28206
28283
  };
@@ -28540,7 +28617,7 @@
28540
28617
 
28541
28618
  const roughModule = _roughModule;
28542
28619
 
28543
- const version = "0.21.0-alpha.3";
28620
+ const version = "0.21.0-alpha.4";
28544
28621
  preLoadAllModule();
28545
28622
  if (isBrowserEnv()) {
28546
28623
  loadBrowserEnv(container);