@visactor/vrender-components 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
@@ -2009,7 +2009,6 @@ const DefaultStrokeStyle = Object.assign({
2009
2009
  const DefaultTextStyle = {
2010
2010
  text: "",
2011
2011
  maxLineWidth: 1 / 0,
2012
- maxWidth: 1 / 0,
2013
2012
  textAlign: "left",
2014
2013
  textBaseline: "alphabetic",
2015
2014
  fontSize: 16,
@@ -2354,32 +2353,10 @@ let ATextMeasure = class {
2354
2353
  configure(service, env) {
2355
2354
  this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
2356
2355
  }
2357
- _measureTextWithoutAlignBaseline(text, options, compatible) {
2356
+ measureTextWidth(text, options) {
2357
+ if (!this.context) return this.estimate(text, options).width;
2358
2358
  this.context.setTextStyleWithoutAlignBaseline(options);
2359
- const metrics = this.context.measureText(text);
2360
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
2361
- }
2362
- _measureTextWithAlignBaseline(text, options, compatible) {
2363
- this.context.setTextStyle(options);
2364
- const metrics = this.context.measureText(text);
2365
- return compatible ? this.compatibleMetrics(metrics, options) : metrics;
2366
- }
2367
- compatibleMetrics(metrics, options) {
2368
- if (null == metrics.actualBoundingBoxAscent || null == metrics.actualBoundingBoxDescent || null == metrics.fontBoundingBoxAscent || null == metrics.fontBoundingBoxDescent) {
2369
- const {
2370
- ascent: ascent,
2371
- descent: descent
2372
- } = this.measureTextBoundADscentEstimate(options);
2373
- metrics.actualBoundingBoxAscent = ascent, metrics.actualBoundingBoxDescent = descent, metrics.fontBoundingBoxAscent = ascent, metrics.fontBoundingBoxDescent = descent;
2374
- }
2375
- if (null == metrics.actualBoundingBoxLeft || null == metrics.actualBoundingBoxRight) {
2376
- const {
2377
- left: left,
2378
- right: right
2379
- } = this.measureTextBoundLeftRightEstimate(options);
2380
- metrics.actualBoundingBoxLeft = left, metrics.actualBoundingBoxRight = right;
2381
- }
2382
- return metrics;
2359
+ return this.context.measureText(text).width;
2383
2360
  }
2384
2361
  estimate(text, _ref) {
2385
2362
  let {
@@ -2393,85 +2370,19 @@ let ATextMeasure = class {
2393
2370
  height: fontSize
2394
2371
  };
2395
2372
  }
2396
- measureTextWidth(text, options, textMeasure) {
2397
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
2398
- }
2399
- measureTextBoundsWidth(text, options, textMeasure) {
2400
- return this.context ? (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithoutAlignBaseline(text, options)).width : this.estimate(text, options).width;
2401
- }
2402
- measureTextBoundsLeftRight(text, options, textMeasure) {
2403
- return this.context ? {
2404
- left: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxLeft,
2405
- right: textMeasure.actualBoundingBoxRight
2406
- } : this.measureTextBoundLeftRightEstimate(options);
2407
- }
2408
- measureTextPixelHeight(text, options, textMeasure) {
2373
+ measureTextPixelHeight(text, options) {
2409
2374
  var _a;
2410
- 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;
2411
- }
2412
- measureTextPixelADscent(text, options, textMeasure) {
2413
- return this.context ? {
2414
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).actualBoundingBoxAscent,
2415
- descent: textMeasure.actualBoundingBoxDescent
2416
- } : this.measureTextBoundADscentEstimate(options);
2417
- }
2418
- measureTextBoundHieght(text, options, textMeasure) {
2419
- var _a;
2420
- 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;
2421
- }
2422
- measureTextBoundADscent(text, options, textMeasure) {
2423
- return this.context ? {
2424
- ascent: (textMeasure = null != textMeasure ? textMeasure : this._measureTextWithAlignBaseline(text, options, !0)).fontBoundingBoxAscent,
2425
- descent: textMeasure.fontBoundingBoxDescent
2426
- } : this.measureTextBoundADscentEstimate(options);
2427
- }
2428
- measureTextBoundADscentEstimate(options) {
2429
- var _a;
2430
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
2431
- {
2432
- textBaseline: textBaseline
2433
- } = options;
2434
- return "bottom" === textBaseline ? {
2435
- ascent: fontSize,
2436
- descent: 0
2437
- } : "middle" === textBaseline ? {
2438
- ascent: fontSize / 2,
2439
- descent: fontSize / 2
2440
- } : "alphabetic" === textBaseline ? {
2441
- ascent: .79 * fontSize,
2442
- descent: .21 * fontSize
2443
- } : {
2444
- ascent: 0,
2445
- descent: fontSize
2446
- };
2375
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2376
+ this.context.setTextStyleWithoutAlignBaseline(options);
2377
+ const textMeasure = this.context.measureText(text);
2378
+ return Math.abs(textMeasure.actualBoundingBoxAscent - textMeasure.actualBoundingBoxDescent);
2447
2379
  }
2448
- measureTextBoundLeftRightEstimate(options) {
2380
+ measureTextBoundHieght(text, options) {
2449
2381
  var _a;
2450
- const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize,
2451
- {
2452
- textAlign: textAlign
2453
- } = options;
2454
- return "center" === textAlign ? {
2455
- left: fontSize / 2,
2456
- right: fontSize / 2
2457
- } : "right" === textAlign || "end" === textAlign ? {
2458
- left: fontSize,
2459
- right: 0
2460
- } : {
2461
- left: 0,
2462
- right: fontSize
2463
- };
2464
- }
2465
- measureTextPixelADscentAndWidth(text, options) {
2466
- if (!this.context) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
2467
- width: this.estimate(text, options).width
2468
- });
2469
- const out = this._measureTextWithoutAlignBaseline(text, options, !0);
2470
- return {
2471
- ascent: out.actualBoundingBoxAscent,
2472
- descent: out.actualBoundingBoxDescent,
2473
- width: out.width
2474
- };
2382
+ if (!this.context) return null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
2383
+ this.context.setTextStyleWithoutAlignBaseline(options);
2384
+ const textMeasure = this.context.measureText(text);
2385
+ return Math.abs(textMeasure.fontBoundingBoxAscent - textMeasure.fontBoundingBoxDescent);
2475
2386
  }
2476
2387
  measureText(text, options) {
2477
2388
  return this.context ? (this.context.setTextStyleWithoutAlignBaseline(options), this.context.measureText(text)) : this.estimate(text, options);
@@ -4461,7 +4372,7 @@ class ResourceLoader {
4461
4372
  }
4462
4373
  static GetFile(url, type) {
4463
4374
  let data = ResourceLoader.cache.get(url);
4464
- return data ? "init" === data.loadState || "fail" === data.loadState ? Promise.reject() : "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
4375
+ return data ? "fail" === data.loadState ? Promise.reject() : "init" === data.loadState || "loading" === data.loadState ? data.dataPromise.then(data => data.data) : Promise.resolve(data.data) : (data = {
4465
4376
  type: type,
4466
4377
  loadState: "init"
4467
4378
  }, 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));
@@ -6606,7 +6517,7 @@ class BaseRender {
6606
6517
  }
6607
6518
  }
6608
6519
 
6609
- const parse = function () {
6520
+ const parse$1 = function () {
6610
6521
  const tokens = {
6611
6522
  linearGradient: /^(linear\-gradient)/i,
6612
6523
  radialGradient: /^(radial\-gradient)/i,
@@ -6759,7 +6670,7 @@ class GradientParser {
6759
6670
  }
6760
6671
  static Parse(c) {
6761
6672
  if (GradientParser.IsGradientStr(c)) try {
6762
- const datum = parse(c)[0];
6673
+ const datum = parse$1(c)[0];
6763
6674
  if (datum) {
6764
6675
  if ("linear" === datum.type) return GradientParser.ParseLinear(datum);
6765
6676
  if ("radial" === datum.type) return GradientParser.ParseRadial(datum);
@@ -7442,8 +7353,9 @@ class DefaultImageRenderContribution extends DefaultRectRenderContribution {
7442
7353
  constructor() {
7443
7354
  super(...arguments), this.time = BaseRenderContributionTime.afterFillStroke, this.useStyle = !0, this.order = 0;
7444
7355
  }
7445
- drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
7446
- return super.drawShape(rect, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
7356
+ drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb) {
7357
+ if (!(image.isGifImage && image.renderFrame && image.playing)) return super.drawShape(image, context, x, y, doFill, doStroke, fVisible, sVisible, rectAttribute, drawContext, fillCb, strokeCb);
7358
+ image.renderFrame(context, x, y);
7447
7359
  }
7448
7360
  }
7449
7361
  const defaultImageRenderContribution = new DefaultImageRenderContribution();
@@ -8783,50 +8695,77 @@ let DefaultCanvasTextRender = class extends BaseRender {
8783
8695
  }
8784
8696
  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());
8785
8697
  };
8786
- if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
8787
- const {
8788
- multilineLayout: multilineLayout
8789
- } = text;
8790
- if (!multilineLayout) return void context.highPerformanceRestore();
8791
- const {
8792
- xOffset: xOffset,
8793
- yOffset: yOffset
8794
- } = multilineLayout.bbox;
8795
- doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8796
- context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
8797
- }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8798
- 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, {
8799
- width: line.width
8698
+ if (text.isMultiLine) {
8699
+ if (context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z), "horizontal" === direction) {
8700
+ const {
8701
+ multilineLayout: multilineLayout
8702
+ } = text;
8703
+ if (!multilineLayout) return void context.highPerformanceRestore();
8704
+ const {
8705
+ xOffset: xOffset,
8706
+ yOffset: yOffset
8707
+ } = multilineLayout.bbox;
8708
+ doStroke && (strokeCb ? strokeCb(context, text.attribute, textAttribute) : sVisible && (context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8709
+ context.strokeText(line.str, (line.leftOffset || 0) + xOffset + x, (line.topOffset || 0) + yOffset + y, z);
8710
+ }))), doFill && (fillCb ? fillCb(context, text.attribute, textAttribute) : fVisible && (context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute), multilineLayout.lines.forEach(line => {
8711
+ 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, {
8712
+ width: line.width
8713
+ });
8714
+ })));
8715
+ } else {
8716
+ text.tryUpdateAABBBounds();
8717
+ const cache = text.cache,
8718
+ {
8719
+ verticalList: verticalList
8720
+ } = cache;
8721
+ context.textAlign = "left", context.textBaseline = "top";
8722
+ const totalHeight = lineHeight * verticalList.length;
8723
+ let totalW = 0;
8724
+ verticalList.forEach(verticalData => {
8725
+ const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
8726
+ totalW = max(_w, totalW);
8800
8727
  });
8801
- })));
8728
+ let offsetY = 0,
8729
+ offsetX = 0;
8730
+ "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
8731
+ const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
8732
+ dw = totalW - currentW;
8733
+ let currentOffsetY = offsetY;
8734
+ "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
8735
+ const {
8736
+ text: text,
8737
+ width: width,
8738
+ direction: direction
8739
+ } = item;
8740
+ drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
8741
+ });
8742
+ });
8743
+ }
8744
+ } else if ("horizontal" === direction) {
8745
+ context.setTextStyle(text.attribute, textAttribute, z);
8746
+ const t = text.clipedText;
8747
+ let dy = 0;
8748
+ lineHeight !== fontSize && ("top" === textBaseline ? dy = (lineHeight - fontSize) / 2 : "middle" === textBaseline || "bottom" === textBaseline && (dy = -(lineHeight - fontSize) / 2)), drawText(t, 0, dy, 0);
8802
8749
  } else {
8803
8750
  text.tryUpdateAABBBounds();
8804
- const cache = text.cache,
8805
- {
8751
+ const cache = text.cache;
8752
+ if (cache) {
8753
+ context.setTextStyleWithoutAlignBaseline(text.attribute, textAttribute, z);
8754
+ const {
8806
8755
  verticalList: verticalList
8807
8756
  } = cache;
8808
- context.textAlign = "left", context.textBaseline = "top";
8809
- const totalHeight = lineHeight * verticalList.length;
8810
- let totalW = 0;
8811
- verticalList.forEach(verticalData => {
8812
- const _w = verticalData.reduce((a, b) => a + (b.width || 0), 0);
8813
- totalW = max(_w, totalW);
8814
- });
8815
- let offsetY = 0,
8816
- offsetX = 0;
8817
- "bottom" === textBaseline ? offsetX = -totalHeight : "middle" === textBaseline && (offsetX = -totalHeight / 2), "center" === textAlign ? offsetY -= totalW / 2 : "right" === textAlign && (offsetY -= totalW), verticalList.forEach((verticalData, i) => {
8818
- const currentW = verticalData.reduce((a, b) => a + (b.width || 0), 0),
8819
- dw = totalW - currentW;
8820
- let currentOffsetY = offsetY;
8821
- "center" === textAlign ? currentOffsetY += dw / 2 : "right" === textAlign && (currentOffsetY += dw), verticalData.forEach(item => {
8757
+ let offsetY = 0;
8758
+ const totalW = verticalList[0].reduce((a, b) => a + (b.width || 0), 0);
8759
+ let offsetX = 0;
8760
+ "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 => {
8822
8761
  const {
8823
8762
  text: text,
8824
8763
  width: width,
8825
8764
  direction: direction
8826
8765
  } = item;
8827
- drawText(text, totalHeight - (i + 1) * lineHeight + offsetX, currentOffsetY, direction), currentOffsetY += width;
8766
+ drawText(text, offsetX, offsetY, direction), offsetY += width;
8828
8767
  });
8829
- });
8768
+ }
8830
8769
  }
8831
8770
  transform3dMatrixToContextMatrix && this.restoreTransformUseContext2d(text, textAttribute, z, context), this.afterRenderStep(text, context, x, y, doFill, doStroke, fVisible, sVisible, textAttribute, drawContext, fillCb, strokeCb);
8832
8771
  }
@@ -9154,10 +9093,12 @@ let DefaultCanvasImageRender = class extends BaseRender {
9154
9093
  const {
9155
9094
  image: url
9156
9095
  } = image.attribute;
9157
- if (!url || !image.resources) return;
9158
- const res = image.resources.get(url);
9159
- if ("loading" === res.state && isString(url)) return void ResourceLoader.improveImageLoading(url);
9160
- if ("success" !== res.state) return;
9096
+ if (!image.isGifImage) {
9097
+ if (!url || !image.resources) return;
9098
+ const res = image.resources.get(url);
9099
+ if ("loading" === res.state && isString(url)) return void ResourceLoader.improveImageLoading(url);
9100
+ if ("success" !== res.state) return;
9101
+ }
9161
9102
  const {
9162
9103
  context: context
9163
9104
  } = renderService.drawParams;
@@ -9541,6 +9482,28 @@ class CanvasTextLayout {
9541
9482
  }
9542
9483
  return bbox.yOffset = "top" === textBaseline ? 0 : "middle" === textBaseline ? bbox.height / -2 : "alphabetic" === textBaseline ? -.79 * bbox.height : -bbox.height, bbox;
9543
9484
  }
9485
+ GetLayout(str, width, height, textAlign, textBaseline, lineHeight, suffix, wordBreak, suffixPosition) {
9486
+ const linesLayout = [],
9487
+ bboxWH = [width, height],
9488
+ bboxOffset = [0, 0];
9489
+ for (; str.length > 0;) {
9490
+ const {
9491
+ str: clipText
9492
+ } = this.textMeasure.clipTextWithSuffix(str, this.textOptions, width, suffix, wordBreak, suffixPosition);
9493
+ linesLayout.push({
9494
+ str: clipText,
9495
+ width: this.textMeasure.measureTextWidth(clipText, this.textOptions)
9496
+ }), str = str.substring(clipText.length);
9497
+ }
9498
+ "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]));
9499
+ const bbox = {
9500
+ xOffset: bboxOffset[0],
9501
+ yOffset: bboxOffset[1],
9502
+ width: bboxWH[0],
9503
+ height: bboxWH[1]
9504
+ };
9505
+ return this.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9506
+ }
9544
9507
  GetLayoutByLines(lines, textAlign, textBaseline, lineHeight) {
9545
9508
  let suffix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
9546
9509
  let wordBreak = arguments.length > 5 ? arguments[5] : undefined;
@@ -9551,29 +9514,18 @@ class CanvasTextLayout {
9551
9514
  bboxWH = [0, 0];
9552
9515
  if ("number" == typeof lineWidth && lineWidth !== 1 / 0) {
9553
9516
  let width;
9554
- for (let i = 0, len = lines.length; i < len; i++) {
9555
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
9556
- width = Math.min(metrics.width, lineWidth), linesLayout.push({
9557
- str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
9558
- width: width,
9559
- ascent: metrics.ascent,
9560
- descent: metrics.descent
9561
- });
9562
- }
9517
+ for (let i = 0, len = lines.length; i < len; i++) width = Math.min(this.textMeasure.measureTextWidth(lines[i], this.textOptions), lineWidth), linesLayout.push({
9518
+ str: this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
9519
+ width: width
9520
+ });
9563
9521
  bboxWH[0] = lineWidth;
9564
9522
  } else {
9565
9523
  let width, text;
9566
9524
  lineWidth = 0;
9567
- for (let i = 0, len = lines.length; i < len; i++) {
9568
- text = lines[i];
9569
- const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
9570
- width = metrics.width, lineWidth = Math.max(lineWidth, width), linesLayout.push({
9571
- str: text,
9572
- width: width,
9573
- ascent: metrics.ascent,
9574
- descent: metrics.descent
9575
- });
9576
- }
9525
+ 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({
9526
+ str: text,
9527
+ width: width
9528
+ });
9577
9529
  bboxWH[0] = lineWidth;
9578
9530
  }
9579
9531
  bboxWH[1] = linesLayout.length * lineHeight, bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);
@@ -9602,11 +9554,11 @@ class CanvasTextLayout {
9602
9554
  };
9603
9555
  }
9604
9556
  lineOffset(bbox, line, textAlign, textBaseline, lineHeight, origin) {
9605
- 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;
9557
+ 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;
9606
9558
  }
9607
9559
  }
9608
9560
 
9609
- 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];
9561
+ const TEXT_UPDATE_TAG_KEY = ["text", "maxLineWidth", "textAlign", "textBaseline", "heightLimit", "lineClamp", "fontSize", "fontFamily", "fontWeight", "ellipsis", "lineHeight", "direction", "wordBreak", "heightLimit", "lineClamp", ...GRAPHIC_UPDATE_TAG_KEY];
9610
9562
  class Text extends Graphic {
9611
9563
  get font() {
9612
9564
  const textTheme = this.getGraphicTheme();
@@ -9615,22 +9567,26 @@ class Text extends Graphic {
9615
9567
  get clipedText() {
9616
9568
  var _a;
9617
9569
  const attribute = this.attribute,
9618
- textTheme = this.getGraphicTheme(),
9619
- maxWidth = this.getMaxWidth(textTheme);
9620
- return Number.isFinite(maxWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
9570
+ textTheme = this.getGraphicTheme();
9571
+ if (!this.isSimplify()) return;
9572
+ const {
9573
+ maxLineWidth = textTheme.maxLineWidth
9574
+ } = attribute;
9575
+ return Number.isFinite(maxLineWidth) ? (this.tryUpdateAABBBounds(), this.cache.clipedText) : (null !== (_a = attribute.text) && void 0 !== _a ? _a : textTheme.text).toString();
9621
9576
  }
9622
9577
  get clipedWidth() {
9623
- return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
9578
+ if (this.isSimplify()) return this.tryUpdateAABBBounds(), this.cache.clipedWidth;
9624
9579
  }
9625
9580
  get cliped() {
9626
9581
  var _a, _b;
9627
9582
  const textTheme = this.getGraphicTheme(),
9628
9583
  attribute = this.attribute,
9629
- maxWidth = this.getMaxWidth(textTheme);
9630
- if (!Number.isFinite(maxWidth)) return !1;
9631
- const {
9632
- text: text
9633
- } = this.attribute;
9584
+ {
9585
+ maxLineWidth = textTheme.maxLineWidth,
9586
+ text: text,
9587
+ whiteSpace = textTheme.whiteSpace
9588
+ } = attribute;
9589
+ if (!Number.isFinite(maxLineWidth)) return !1;
9634
9590
  if (this.tryUpdateAABBBounds(), null === (_b = null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData) || void 0 === _b ? void 0 : _b.lines) {
9635
9591
  let mergedText = "";
9636
9592
  this.cache.layoutData.lines.forEach(item => {
@@ -9641,7 +9597,10 @@ class Text extends Graphic {
9641
9597
  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();
9642
9598
  }
9643
9599
  get multilineLayout() {
9644
- return this.tryUpdateAABBBounds(), this.cache.layoutData;
9600
+ if (this.isMultiLine) return this.tryUpdateAABBBounds(), this.cache.layoutData;
9601
+ }
9602
+ isSimplify() {
9603
+ return !this.isMultiLine && "vertical" !== this.attribute.direction;
9645
9604
  }
9646
9605
  get isMultiLine() {
9647
9606
  return Array.isArray(this.attribute.text) || "normal" === this.attribute.whiteSpace;
@@ -9714,63 +9673,8 @@ class Text extends Graphic {
9714
9673
  }
9715
9674
  return application.graphicService.combindShadowAABBBounds(aabbBounds, this), null == attribute.forceBoundsHeight && null == attribute.forceBoundsWidth || application.graphicService.updateHTMLTextAABBBounds(attribute, textTheme, aabbBounds), transformBoundsWithMatrix(aabbBounds, aabbBounds, this.transMatrix), aabbBounds;
9716
9675
  }
9717
- updateSingallineAABBBounds(text) {
9718
- this.updateMultilineAABBBounds([text]);
9719
- const layoutData = this.cache.layoutData;
9720
- if (layoutData) {
9721
- const line = layoutData.lines[0];
9722
- this.cache.clipedText = line.str, this.cache.clipedWidth = line.width;
9723
- }
9724
- return this._AABBBounds;
9725
- }
9726
- updateMultilineAABBBounds(text) {
9727
- const textTheme = this.getGraphicTheme(),
9728
- {
9729
- direction = textTheme.direction,
9730
- underlineOffset = textTheme.underlineOffset
9731
- } = this.attribute,
9732
- b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
9733
- return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9734
- }
9735
- updateHorizontalMultilineAABBBounds(text) {
9736
- var _a;
9737
- const textTheme = this.getGraphicTheme(),
9738
- attribute = this.attribute,
9739
- {
9740
- fontFamily = textTheme.fontFamily,
9741
- textAlign = textTheme.textAlign,
9742
- textBaseline = textTheme.textBaseline,
9743
- fontSize = textTheme.fontSize,
9744
- fontWeight = textTheme.fontWeight,
9745
- ellipsis = textTheme.ellipsis,
9746
- maxLineWidth: maxLineWidth,
9747
- stroke = textTheme.stroke,
9748
- wrap = textTheme.wrap,
9749
- ignoreBuf = textTheme.ignoreBuf,
9750
- lineWidth = textTheme.lineWidth,
9751
- whiteSpace = textTheme.whiteSpace,
9752
- suffixPosition = textTheme.suffixPosition
9753
- } = attribute,
9754
- buf = ignoreBuf ? 0 : 2,
9755
- lineHeight = this.getLineHeight(attribute, textTheme) + buf;
9756
- if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
9757
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
9758
- const bbox = this.cache.layoutData.bbox;
9759
- return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9760
- }
9761
- const textMeasure = application.graphicUtil.textMeasure,
9762
- layoutData = new CanvasTextLayout(fontFamily, {
9763
- fontSize: fontSize,
9764
- fontWeight: fontWeight,
9765
- fontFamily: fontFamily
9766
- }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
9767
- {
9768
- bbox: bbox
9769
- } = layoutData;
9770
- 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;
9771
- }
9772
9676
  updateWrapAABBBounds(text) {
9773
- var _a, _b, _c;
9677
+ var _a, _b, _c, _d;
9774
9678
  const textTheme = this.getGraphicTheme(),
9775
9679
  {
9776
9680
  fontFamily = textTheme.fontFamily,
@@ -9788,19 +9692,18 @@ class Text extends Graphic {
9788
9692
  heightLimit = 0,
9789
9693
  lineClamp: lineClamp
9790
9694
  } = this.attribute,
9791
- buf = ignoreBuf ? 0 : 2,
9792
- lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
9793
- if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
9695
+ lineHeight = null !== (_a = calculateLineHeight(this.attribute.lineHeight, this.attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : this.attribute.fontSize || textTheme.fontSize,
9696
+ buf = ignoreBuf ? 0 : 2;
9697
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
9794
9698
  const bbox = this.cache.layoutData.bbox;
9795
9699
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9796
9700
  }
9797
9701
  const textMeasure = application.graphicUtil.textMeasure,
9798
- textOptions = {
9702
+ layoutObj = new CanvasTextLayout(fontFamily, {
9799
9703
  fontSize: fontSize,
9800
9704
  fontWeight: fontWeight,
9801
9705
  fontFamily: fontFamily
9802
- },
9803
- layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure),
9706
+ }, textMeasure),
9804
9707
  lines = isArray(text) ? text.map(l => l.toString()) : [text.toString()],
9805
9708
  linesLayout = [],
9806
9709
  bboxWH = [0, 0];
@@ -9810,33 +9713,29 @@ class Text extends Graphic {
9810
9713
  const str = lines[i];
9811
9714
  let needCut = !0;
9812
9715
  if (i === lineCountLimit - 1) {
9813
- const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1),
9814
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
9716
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1);
9815
9717
  linesLayout.push({
9816
9718
  str: clip.str,
9817
- width: clip.width,
9818
- ascent: matrics.ascent,
9819
- descent: matrics.descent
9719
+ width: clip.width
9820
9720
  });
9821
9721
  break;
9822
9722
  }
9823
- const clip = textMeasure.clipText(str, textOptions, maxLineWidth, "break-word" === wordBreak);
9824
- if ("" !== str && "" === clip.str) {
9723
+ const clip = layoutObj.textMeasure.clipText(str, layoutObj.textOptions, maxLineWidth, "break-all" !== wordBreak, "keep-all" === wordBreak);
9724
+ if ("" !== str && "" === clip.str || clip.wordBreaked) {
9825
9725
  if (ellipsis) {
9826
- const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9827
- clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
9726
+ const clipEllipsis = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9727
+ clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
9828
9728
  } else clip.str = "", clip.width = 0;
9829
9729
  needCut = !1;
9830
9730
  }
9831
- const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
9832
- if (linesLayout.push({
9731
+ linesLayout.push({
9833
9732
  str: clip.str,
9834
- width: clip.width,
9835
- ascent: matrics.ascent,
9836
- descent: matrics.descent
9837
- }), clip.str.length === str.length) ;else if (needCut) {
9838
- const newStr = str.substring(clip.str.length);
9839
- lines.splice(i + 1, 0, newStr);
9733
+ width: clip.width
9734
+ });
9735
+ let cutLength = clip.str.length;
9736
+ if (!clip.wordBreaked || "" !== str && "" === clip.str || (needCut = !0, cutLength = clip.wordBreaked), clip.str.length === str.length) ;else if (needCut) {
9737
+ let newStr = str.substring(cutLength);
9738
+ "keep-all" === wordBreak && (newStr = newStr.replace(/^\s+/g, "")), lines.splice(i + 1, 0, newStr);
9840
9739
  }
9841
9740
  }
9842
9741
  let maxWidth = 0;
@@ -9849,28 +9748,21 @@ class Text extends Graphic {
9849
9748
  lineWidth = 0;
9850
9749
  for (let i = 0, len = lines.length; i < len; i++) {
9851
9750
  if (i === lineCountLimit - 1) {
9852
- const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition),
9853
- matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
9751
+ const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9854
9752
  linesLayout.push({
9855
9753
  str: clip.str,
9856
- width: clip.width,
9857
- ascent: matrics.ascent,
9858
- descent: matrics.descent
9754
+ width: clip.width
9859
9755
  }), lineWidth = Math.max(lineWidth, clip.width);
9860
9756
  break;
9861
9757
  }
9862
- text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
9863
- const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions);
9864
- linesLayout.push({
9758
+ text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
9865
9759
  str: text,
9866
- width: width,
9867
- ascent: matrics.ascent,
9868
- descent: matrics.descent
9760
+ width: width
9869
9761
  });
9870
9762
  }
9871
9763
  bboxWH[0] = lineWidth;
9872
9764
  }
9873
- bboxWH[1] = linesLayout.length * lineHeight;
9765
+ bboxWH[1] = linesLayout.length * (lineHeight + buf);
9874
9766
  const bbox = {
9875
9767
  xOffset: 0,
9876
9768
  yOffset: 0,
@@ -9881,12 +9773,210 @@ class Text extends Graphic {
9881
9773
  const layoutData = layoutObj.layoutWithBBox(bbox, linesLayout, textAlign, textBaseline, lineHeight);
9882
9774
  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;
9883
9775
  }
9884
- updateVerticalMultilineAABBBounds(text) {
9776
+ updateSingallineAABBBounds(text) {
9777
+ const textTheme = this.getGraphicTheme(),
9778
+ {
9779
+ direction = textTheme.direction,
9780
+ underlineOffset = textTheme.underlineOffset
9781
+ } = this.attribute,
9782
+ b = "horizontal" === direction ? this.updateHorizontalSinglelineAABBBounds(text) : this.updateVerticalSinglelineAABBBounds(text);
9783
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9784
+ }
9785
+ updateMultilineAABBBounds(text) {
9786
+ const textTheme = this.getGraphicTheme(),
9787
+ {
9788
+ direction = textTheme.direction,
9789
+ underlineOffset = textTheme.underlineOffset
9790
+ } = this.attribute,
9791
+ b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
9792
+ return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
9793
+ }
9794
+ updateHorizontalSinglelineAABBBounds(text) {
9795
+ var _a, _b;
9796
+ const textTheme = this.getGraphicTheme(),
9797
+ {
9798
+ wrap = textTheme.wrap
9799
+ } = this.attribute;
9800
+ if (wrap) return this.updateWrapAABBBounds([text]);
9801
+ const textMeasure = application.graphicUtil.textMeasure;
9802
+ let width, str;
9803
+ const attribute = this.attribute,
9804
+ {
9805
+ maxLineWidth = textTheme.maxLineWidth,
9806
+ ellipsis = textTheme.ellipsis,
9807
+ textAlign = textTheme.textAlign,
9808
+ textBaseline = textTheme.textBaseline,
9809
+ fontFamily = textTheme.fontFamily,
9810
+ fontSize = textTheme.fontSize,
9811
+ fontWeight = textTheme.fontWeight,
9812
+ stroke = textTheme.stroke,
9813
+ lineWidth = textTheme.lineWidth,
9814
+ ignoreBuf = textTheme.ignoreBuf,
9815
+ whiteSpace = textTheme.whiteSpace,
9816
+ suffixPosition = textTheme.suffixPosition
9817
+ } = attribute;
9818
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
9819
+ const buf = ignoreBuf ? 0 : Math.max(2, .075 * fontSize),
9820
+ textFontSize = attribute.fontSize || textTheme.fontSize,
9821
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, textFontSize)) && void 0 !== _a ? _a : textFontSize + buf;
9822
+ if (!this.shouldUpdateShape() && this.cache) {
9823
+ width = null !== (_b = this.cache.clipedWidth) && void 0 !== _b ? _b : 0;
9824
+ const dx = textDrawOffsetX(textAlign, width),
9825
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9826
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9827
+ }
9828
+ if (Number.isFinite(maxLineWidth)) {
9829
+ if (ellipsis) {
9830
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
9831
+ data = textMeasure.clipTextWithSuffix(text.toString(), {
9832
+ fontSize: fontSize,
9833
+ fontWeight: fontWeight,
9834
+ fontFamily: fontFamily
9835
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
9836
+ str = data.str, width = data.width;
9837
+ } else {
9838
+ const data = textMeasure.clipText(text.toString(), {
9839
+ fontSize: fontSize,
9840
+ fontWeight: fontWeight,
9841
+ fontFamily: fontFamily
9842
+ }, maxLineWidth, !1);
9843
+ str = data.str, width = data.width;
9844
+ }
9845
+ this.cache.clipedText = str, this.cache.clipedWidth = width;
9846
+ } else width = textMeasure.measureTextWidth(text.toString(), {
9847
+ fontSize: fontSize,
9848
+ fontWeight: fontWeight,
9849
+ fontFamily: fontFamily
9850
+ }), this.cache.clipedText = text.toString(), this.cache.clipedWidth = width;
9851
+ this.clearUpdateShapeTag();
9852
+ const dx = textDrawOffsetX(textAlign, width);
9853
+ let lh = lineHeight;
9854
+ application.global && application.global.isSafari() && (lh += .2 * fontSize);
9855
+ const dy = textLayoutOffsetY(textBaseline, lh, fontSize, buf);
9856
+ return this._AABBBounds.set(dx, dy, dx + width, dy + lh), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9857
+ }
9858
+ getBaselineMapAlign() {
9859
+ return Text.baselineMapAlign;
9860
+ }
9861
+ getAlignMapBaseline() {
9862
+ return Text.alignMapBaseline;
9863
+ }
9864
+ updateVerticalSinglelineAABBBounds(text) {
9865
+ var _a, _b, _c;
9866
+ const textTheme = this.getGraphicTheme(),
9867
+ textMeasure = application.graphicUtil.textMeasure;
9868
+ let width;
9869
+ const attribute = this.attribute,
9870
+ {
9871
+ ignoreBuf = textTheme.ignoreBuf
9872
+ } = attribute,
9873
+ buf = ignoreBuf ? 0 : 2,
9874
+ {
9875
+ maxLineWidth = textTheme.maxLineWidth,
9876
+ ellipsis = textTheme.ellipsis,
9877
+ fontSize = textTheme.fontSize,
9878
+ fontWeight = textTheme.fontWeight,
9879
+ fontFamily = textTheme.fontFamily,
9880
+ stroke = textTheme.stroke,
9881
+ lineWidth = textTheme.lineWidth,
9882
+ verticalMode = textTheme.verticalMode,
9883
+ suffixPosition = textTheme.suffixPosition
9884
+ } = attribute,
9885
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
9886
+ let {
9887
+ textAlign = textTheme.textAlign,
9888
+ textBaseline = textTheme.textBaseline
9889
+ } = attribute;
9890
+ if (!verticalMode) {
9891
+ const t = textAlign;
9892
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
9893
+ }
9894
+ if (!this.shouldUpdateShape() && this.cache) {
9895
+ width = this.cache.clipedWidth;
9896
+ const dx = textDrawOffsetX(textAlign, width),
9897
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9898
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9899
+ }
9900
+ let verticalList = [verticalLayout(text.toString())];
9901
+ if (Number.isFinite(maxLineWidth)) {
9902
+ if (ellipsis) {
9903
+ const strEllipsis = !0 === ellipsis ? textTheme.ellipsis : ellipsis,
9904
+ data = textMeasure.clipTextWithSuffixVertical(verticalList[0], {
9905
+ fontSize: fontSize,
9906
+ fontWeight: fontWeight,
9907
+ fontFamily: fontFamily
9908
+ }, maxLineWidth, strEllipsis, !1, suffixPosition);
9909
+ verticalList = [data.verticalList], width = data.width;
9910
+ } else {
9911
+ const data = textMeasure.clipTextVertical(verticalList[0], {
9912
+ fontSize: fontSize,
9913
+ fontWeight: fontWeight,
9914
+ fontFamily: fontFamily
9915
+ }, maxLineWidth, !1);
9916
+ verticalList = [data.verticalList], width = data.width;
9917
+ }
9918
+ this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
9919
+ } else width = 0, verticalList[0].forEach(t => {
9920
+ const w = t.direction === TextDirection.HORIZONTAL ? fontSize : textMeasure.measureTextWidth(t.text, {
9921
+ fontSize: fontSize,
9922
+ fontWeight: fontWeight,
9923
+ fontFamily: fontFamily
9924
+ });
9925
+ width += w, t.width = w;
9926
+ }), this.cache.verticalList = verticalList, this.cache.clipedWidth = width;
9927
+ this.clearUpdateShapeTag();
9928
+ const dx = textDrawOffsetX(textAlign, width),
9929
+ dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
9930
+ return this._AABBBounds.set(dy, dx, dy + lineHeight, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9931
+ }
9932
+ updateHorizontalMultilineAABBBounds(text) {
9885
9933
  var _a, _b;
9934
+ const textTheme = this.getGraphicTheme(),
9935
+ {
9936
+ wrap = textTheme.wrap
9937
+ } = this.attribute;
9938
+ if (wrap) return this.updateWrapAABBBounds(text);
9939
+ const attribute = this.attribute,
9940
+ {
9941
+ fontFamily = textTheme.fontFamily,
9942
+ textAlign = textTheme.textAlign,
9943
+ textBaseline = textTheme.textBaseline,
9944
+ fontSize = textTheme.fontSize,
9945
+ fontWeight = textTheme.fontWeight,
9946
+ ellipsis = textTheme.ellipsis,
9947
+ maxLineWidth: maxLineWidth,
9948
+ stroke = textTheme.stroke,
9949
+ lineWidth = textTheme.lineWidth,
9950
+ whiteSpace = textTheme.whiteSpace,
9951
+ suffixPosition = textTheme.suffixPosition
9952
+ } = attribute,
9953
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
9954
+ if ("normal" === whiteSpace) return this.updateWrapAABBBounds(text);
9955
+ if (!this.shouldUpdateShape() && (null === (_b = this.cache) || void 0 === _b ? void 0 : _b.layoutData)) {
9956
+ const bbox = this.cache.layoutData.bbox;
9957
+ return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9958
+ }
9959
+ const textMeasure = application.graphicUtil.textMeasure,
9960
+ layoutData = new CanvasTextLayout(fontFamily, {
9961
+ fontSize: fontSize,
9962
+ fontWeight: fontWeight,
9963
+ fontFamily: fontFamily
9964
+ }, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, maxLineWidth, suffixPosition),
9965
+ {
9966
+ bbox: bbox
9967
+ } = layoutData;
9968
+ 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;
9969
+ }
9970
+ updateVerticalMultilineAABBBounds(text) {
9971
+ var _a, _b, _c;
9886
9972
  const textTheme = this.getGraphicTheme(),
9887
9973
  textMeasure = application.graphicUtil.textMeasure;
9888
9974
  let width;
9889
9975
  const attribute = this.attribute,
9976
+ {
9977
+ ignoreBuf = textTheme.ignoreBuf
9978
+ } = attribute,
9979
+ buf = ignoreBuf ? 0 : 2,
9890
9980
  {
9891
9981
  maxLineWidth = textTheme.maxLineWidth,
9892
9982
  ellipsis = textTheme.ellipsis,
@@ -9898,14 +9988,14 @@ class Text extends Graphic {
9898
9988
  verticalMode = textTheme.verticalMode,
9899
9989
  suffixPosition = textTheme.suffixPosition
9900
9990
  } = attribute,
9901
- lineHeight = this.getLineHeight(attribute, textTheme);
9991
+ lineHeight = null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : (attribute.fontSize || textTheme.fontSize) + buf;
9902
9992
  let {
9903
9993
  textAlign = textTheme.textAlign,
9904
9994
  textBaseline = textTheme.textBaseline
9905
9995
  } = attribute;
9906
9996
  if (!verticalMode) {
9907
9997
  const t = textAlign;
9908
- textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
9998
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
9909
9999
  }
9910
10000
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
9911
10001
  this.cache.verticalList.forEach(item => {
@@ -9953,15 +10043,6 @@ class Text extends Graphic {
9953
10043
  dy = textLayoutOffsetY(textBaseline, height, fontSize);
9954
10044
  return this._AABBBounds.set(dy, dx, dy + height, dx + width), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9955
10045
  }
9956
- getMaxWidth(theme) {
9957
- var _a, _b;
9958
- const attribute = this.attribute;
9959
- return null !== (_b = null !== (_a = attribute.maxLineWidth) && void 0 !== _a ? _a : attribute.maxWidth) && void 0 !== _b ? _b : theme.maxWidth;
9960
- }
9961
- getLineHeight(attribute, textTheme) {
9962
- var _a;
9963
- return null !== (_a = calculateLineHeight(attribute.lineHeight, attribute.fontSize || textTheme.fontSize)) && void 0 !== _a ? _a : attribute.fontSize || textTheme.fontSize;
9964
- }
9965
10046
  needUpdateTags(keys) {
9966
10047
  let k = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TEXT_UPDATE_TAG_KEY;
9967
10048
  return super.needUpdateTags(keys, k);
@@ -9976,12 +10057,6 @@ class Text extends Graphic {
9976
10057
  getNoWorkAnimateAttr() {
9977
10058
  return Text.NOWORK_ANIMATE_ATTR;
9978
10059
  }
9979
- getBaselineMapAlign() {
9980
- return Text.baselineMapAlign;
9981
- }
9982
- getAlignMapBaseline() {
9983
- return Text.alignMapBaseline;
9984
- }
9985
10060
  }
9986
10061
  Text.NOWORK_ANIMATE_ATTR = Object.assign({
9987
10062
  ellipsis: 1,
@@ -10060,9 +10135,7 @@ class WrapText extends Text {
10060
10135
  const clip = layoutObj.textMeasure.clipTextWithSuffix(str, layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
10061
10136
  linesLayout.push({
10062
10137
  str: clip.str,
10063
- width: clip.width,
10064
- ascent: 0,
10065
- descent: 0
10138
+ width: clip.width
10066
10139
  });
10067
10140
  break;
10068
10141
  }
@@ -10076,9 +10149,7 @@ class WrapText extends Text {
10076
10149
  }
10077
10150
  if (linesLayout.push({
10078
10151
  str: clip.str,
10079
- width: clip.width,
10080
- ascent: 0,
10081
- descent: 0
10152
+ width: clip.width
10082
10153
  }), clip.str.length === str.length) ;else if (needCut) {
10083
10154
  const newStr = str.substring(clip.str.length);
10084
10155
  lines.splice(i + 1, 0, newStr);
@@ -10097,17 +10168,13 @@ class WrapText extends Text {
10097
10168
  const clip = layoutObj.textMeasure.clipTextWithSuffix(lines[i], layoutObj.textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
10098
10169
  linesLayout.push({
10099
10170
  str: clip.str,
10100
- width: clip.width,
10101
- ascent: 0,
10102
- descent: 0
10171
+ width: clip.width
10103
10172
  }), lineWidth = Math.max(lineWidth, clip.width);
10104
10173
  break;
10105
10174
  }
10106
10175
  text = lines[i], width = layoutObj.textMeasure.measureTextWidth(text, layoutObj.textOptions, "break-word" === wordBreak), lineWidth = Math.max(lineWidth, width), linesLayout.push({
10107
10176
  str: text,
10108
- width: width,
10109
- ascent: 0,
10110
- descent: 0
10177
+ width: width
10111
10178
  });
10112
10179
  }
10113
10180
  bboxWH[0] = lineWidth;
@@ -13916,8 +13983,10 @@ let DefaultCanvasTextPicker = class extends Base3dPicker {
13916
13983
  } = text.attribute,
13917
13984
  bounds = text.AABBBounds,
13918
13985
  height = bounds.height(),
13919
- width = bounds.width();
13920
- return context.rect(bounds.x1, bounds.y1, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
13986
+ width = bounds.width(),
13987
+ offsetY = textLayoutOffsetY(textBaseline, height, fontSize),
13988
+ offsetX = textDrawOffsetX(textAlign, width);
13989
+ return context.rect(offsetX + x, offsetY + y, width, height, z), picked = context.isPointInPath(pickPoint.x, pickPoint.y), picked;
13921
13990
  }, (context, symbolAttribute, themeAttribute) => picked), this.canvasRenderer.z = 0, pickContext.modelMatrix !== lastModelMatrix && mat4Allocate.free(pickContext.modelMatrix), pickContext.modelMatrix = lastModelMatrix, pickContext.highPerformanceRestore(), picked;
13922
13991
  }
13923
13992
  };
@@ -29483,6 +29552,690 @@ EmptyTip.defaultAttributes = {
29483
29552
  }
29484
29553
  };
29485
29554
 
29486
- const version = "0.21.0-alpha.3";
29555
+ var lib$1 = {};
29556
+
29557
+ var gif = {};
29558
+
29559
+ var lib = {};
29560
+
29561
+ Object.defineProperty(lib, "__esModule", {
29562
+ value: true
29563
+ });
29564
+ lib.loop = lib.conditional = lib.parse = void 0;
29565
+ var parse = function parse(stream, schema) {
29566
+ var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
29567
+ var parent = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : result;
29568
+ if (Array.isArray(schema)) {
29569
+ schema.forEach(function (partSchema) {
29570
+ return parse(stream, partSchema, result, parent);
29571
+ });
29572
+ } else if (typeof schema === 'function') {
29573
+ schema(stream, result, parent, parse);
29574
+ } else {
29575
+ var key = Object.keys(schema)[0];
29576
+ if (Array.isArray(schema[key])) {
29577
+ parent[key] = {};
29578
+ parse(stream, schema[key], result, parent[key]);
29579
+ } else {
29580
+ parent[key] = schema[key](stream, result, parent, parse);
29581
+ }
29582
+ }
29583
+ return result;
29584
+ };
29585
+ lib.parse = parse;
29586
+ var conditional = function conditional(schema, conditionFunc) {
29587
+ return function (stream, result, parent, parse) {
29588
+ if (conditionFunc(stream, result, parent)) {
29589
+ parse(stream, schema, result, parent);
29590
+ }
29591
+ };
29592
+ };
29593
+ lib.conditional = conditional;
29594
+ var loop = function loop(schema, continueFunc) {
29595
+ return function (stream, result, parent, parse) {
29596
+ var arr = [];
29597
+ var lastStreamPos = stream.pos;
29598
+ while (continueFunc(stream, result, parent)) {
29599
+ var newParent = {};
29600
+ parse(stream, schema, result, newParent); // cases when whole file is parsed but no termination is there and stream position is not getting updated as well
29601
+ // it falls into infinite recursion, null check to avoid the same
29602
+
29603
+ if (stream.pos === lastStreamPos) {
29604
+ break;
29605
+ }
29606
+ lastStreamPos = stream.pos;
29607
+ arr.push(newParent);
29608
+ }
29609
+ return arr;
29610
+ };
29611
+ };
29612
+ lib.loop = loop;
29613
+
29614
+ var uint8 = {};
29615
+
29616
+ Object.defineProperty(uint8, "__esModule", {
29617
+ value: true
29618
+ });
29619
+ uint8.readBits = uint8.readArray = uint8.readUnsigned = uint8.readString = uint8.peekBytes = uint8.readBytes = uint8.peekByte = uint8.readByte = uint8.buildStream = void 0;
29620
+
29621
+ // Default stream and parsers for Uint8TypedArray data type
29622
+ var buildStream = function buildStream(uint8Data) {
29623
+ return {
29624
+ data: uint8Data,
29625
+ pos: 0
29626
+ };
29627
+ };
29628
+ uint8.buildStream = buildStream;
29629
+ var readByte = function readByte() {
29630
+ return function (stream) {
29631
+ return stream.data[stream.pos++];
29632
+ };
29633
+ };
29634
+ uint8.readByte = readByte;
29635
+ var peekByte = function peekByte() {
29636
+ var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
29637
+ return function (stream) {
29638
+ return stream.data[stream.pos + offset];
29639
+ };
29640
+ };
29641
+ uint8.peekByte = peekByte;
29642
+ var readBytes = function readBytes(length) {
29643
+ return function (stream) {
29644
+ return stream.data.subarray(stream.pos, stream.pos += length);
29645
+ };
29646
+ };
29647
+ uint8.readBytes = readBytes;
29648
+ var peekBytes = function peekBytes(length) {
29649
+ return function (stream) {
29650
+ return stream.data.subarray(stream.pos, stream.pos + length);
29651
+ };
29652
+ };
29653
+ uint8.peekBytes = peekBytes;
29654
+ var readString = function readString(length) {
29655
+ return function (stream) {
29656
+ return Array.from(readBytes(length)(stream)).map(function (value) {
29657
+ return String.fromCharCode(value);
29658
+ }).join('');
29659
+ };
29660
+ };
29661
+ uint8.readString = readString;
29662
+ var readUnsigned = function readUnsigned(littleEndian) {
29663
+ return function (stream) {
29664
+ var bytes = readBytes(2)(stream);
29665
+ return littleEndian ? (bytes[1] << 8) + bytes[0] : (bytes[0] << 8) + bytes[1];
29666
+ };
29667
+ };
29668
+ uint8.readUnsigned = readUnsigned;
29669
+ var readArray = function readArray(byteSize, totalOrFunc) {
29670
+ return function (stream, result, parent) {
29671
+ var total = typeof totalOrFunc === 'function' ? totalOrFunc(stream, result, parent) : totalOrFunc;
29672
+ var parser = readBytes(byteSize);
29673
+ var arr = new Array(total);
29674
+ for (var i = 0; i < total; i++) {
29675
+ arr[i] = parser(stream);
29676
+ }
29677
+ return arr;
29678
+ };
29679
+ };
29680
+ uint8.readArray = readArray;
29681
+ var subBitsTotal = function subBitsTotal(bits, startIndex, length) {
29682
+ var result = 0;
29683
+ for (var i = 0; i < length; i++) {
29684
+ result += bits[startIndex + i] && Math.pow(2, length - i - 1);
29685
+ }
29686
+ return result;
29687
+ };
29688
+ var readBits = function readBits(schema) {
29689
+ return function (stream) {
29690
+ var _byte = readByte()(stream); // convert the byte to bit array
29691
+
29692
+ var bits = new Array(8);
29693
+ for (var i = 0; i < 8; i++) {
29694
+ bits[7 - i] = !!(_byte & 1 << i);
29695
+ } // convert the bit array to values based on the schema
29696
+
29697
+ return Object.keys(schema).reduce(function (res, key) {
29698
+ var def = schema[key];
29699
+ if (def.length) {
29700
+ res[key] = subBitsTotal(bits, def.index, def.length);
29701
+ } else {
29702
+ res[key] = bits[def.index];
29703
+ }
29704
+ return res;
29705
+ }, {});
29706
+ };
29707
+ };
29708
+ uint8.readBits = readBits;
29709
+
29710
+ (function (exports) {
29711
+
29712
+ Object.defineProperty(exports, "__esModule", {
29713
+ value: true
29714
+ });
29715
+ exports["default"] = void 0;
29716
+ var _ = lib;
29717
+ var _uint = uint8;
29718
+
29719
+ // a set of 0x00 terminated subblocks
29720
+ var subBlocksSchema = {
29721
+ blocks: function blocks(stream) {
29722
+ var terminator = 0x00;
29723
+ var chunks = [];
29724
+ var streamSize = stream.data.length;
29725
+ var total = 0;
29726
+ for (var size = (0, _uint.readByte)()(stream); size !== terminator; size = (0, _uint.readByte)()(stream)) {
29727
+ // size becomes undefined for some case when file is corrupted and terminator is not proper
29728
+ // null check to avoid recursion
29729
+ if (!size) break; // catch corrupted files with no terminator
29730
+
29731
+ if (stream.pos + size >= streamSize) {
29732
+ var availableSize = streamSize - stream.pos;
29733
+ chunks.push((0, _uint.readBytes)(availableSize)(stream));
29734
+ total += availableSize;
29735
+ break;
29736
+ }
29737
+ chunks.push((0, _uint.readBytes)(size)(stream));
29738
+ total += size;
29739
+ }
29740
+ var result = new Uint8Array(total);
29741
+ var offset = 0;
29742
+ for (var i = 0; i < chunks.length; i++) {
29743
+ result.set(chunks[i], offset);
29744
+ offset += chunks[i].length;
29745
+ }
29746
+ return result;
29747
+ }
29748
+ }; // global control extension
29749
+
29750
+ var gceSchema = (0, _.conditional)({
29751
+ gce: [{
29752
+ codes: (0, _uint.readBytes)(2)
29753
+ }, {
29754
+ byteSize: (0, _uint.readByte)()
29755
+ }, {
29756
+ extras: (0, _uint.readBits)({
29757
+ future: {
29758
+ index: 0,
29759
+ length: 3
29760
+ },
29761
+ disposal: {
29762
+ index: 3,
29763
+ length: 3
29764
+ },
29765
+ userInput: {
29766
+ index: 6
29767
+ },
29768
+ transparentColorGiven: {
29769
+ index: 7
29770
+ }
29771
+ })
29772
+ }, {
29773
+ delay: (0, _uint.readUnsigned)(true)
29774
+ }, {
29775
+ transparentColorIndex: (0, _uint.readByte)()
29776
+ }, {
29777
+ terminator: (0, _uint.readByte)()
29778
+ }]
29779
+ }, function (stream) {
29780
+ var codes = (0, _uint.peekBytes)(2)(stream);
29781
+ return codes[0] === 0x21 && codes[1] === 0xf9;
29782
+ }); // image pipeline block
29783
+
29784
+ var imageSchema = (0, _.conditional)({
29785
+ image: [{
29786
+ code: (0, _uint.readByte)()
29787
+ }, {
29788
+ descriptor: [{
29789
+ left: (0, _uint.readUnsigned)(true)
29790
+ }, {
29791
+ top: (0, _uint.readUnsigned)(true)
29792
+ }, {
29793
+ width: (0, _uint.readUnsigned)(true)
29794
+ }, {
29795
+ height: (0, _uint.readUnsigned)(true)
29796
+ }, {
29797
+ lct: (0, _uint.readBits)({
29798
+ exists: {
29799
+ index: 0
29800
+ },
29801
+ interlaced: {
29802
+ index: 1
29803
+ },
29804
+ sort: {
29805
+ index: 2
29806
+ },
29807
+ future: {
29808
+ index: 3,
29809
+ length: 2
29810
+ },
29811
+ size: {
29812
+ index: 5,
29813
+ length: 3
29814
+ }
29815
+ })
29816
+ }]
29817
+ }, (0, _.conditional)({
29818
+ lct: (0, _uint.readArray)(3, function (stream, result, parent) {
29819
+ return Math.pow(2, parent.descriptor.lct.size + 1);
29820
+ })
29821
+ }, function (stream, result, parent) {
29822
+ return parent.descriptor.lct.exists;
29823
+ }), {
29824
+ data: [{
29825
+ minCodeSize: (0, _uint.readByte)()
29826
+ }, subBlocksSchema]
29827
+ }]
29828
+ }, function (stream) {
29829
+ return (0, _uint.peekByte)()(stream) === 0x2c;
29830
+ }); // plain text block
29831
+
29832
+ var textSchema = (0, _.conditional)({
29833
+ text: [{
29834
+ codes: (0, _uint.readBytes)(2)
29835
+ }, {
29836
+ blockSize: (0, _uint.readByte)()
29837
+ }, {
29838
+ preData: function preData(stream, result, parent) {
29839
+ return (0, _uint.readBytes)(parent.text.blockSize)(stream);
29840
+ }
29841
+ }, subBlocksSchema]
29842
+ }, function (stream) {
29843
+ var codes = (0, _uint.peekBytes)(2)(stream);
29844
+ return codes[0] === 0x21 && codes[1] === 0x01;
29845
+ }); // application block
29846
+
29847
+ var applicationSchema = (0, _.conditional)({
29848
+ application: [{
29849
+ codes: (0, _uint.readBytes)(2)
29850
+ }, {
29851
+ blockSize: (0, _uint.readByte)()
29852
+ }, {
29853
+ id: function id(stream, result, parent) {
29854
+ return (0, _uint.readString)(parent.blockSize)(stream);
29855
+ }
29856
+ }, subBlocksSchema]
29857
+ }, function (stream) {
29858
+ var codes = (0, _uint.peekBytes)(2)(stream);
29859
+ return codes[0] === 0x21 && codes[1] === 0xff;
29860
+ }); // comment block
29861
+
29862
+ var commentSchema = (0, _.conditional)({
29863
+ comment: [{
29864
+ codes: (0, _uint.readBytes)(2)
29865
+ }, subBlocksSchema]
29866
+ }, function (stream) {
29867
+ var codes = (0, _uint.peekBytes)(2)(stream);
29868
+ return codes[0] === 0x21 && codes[1] === 0xfe;
29869
+ });
29870
+ var schema = [{
29871
+ header: [{
29872
+ signature: (0, _uint.readString)(3)
29873
+ }, {
29874
+ version: (0, _uint.readString)(3)
29875
+ }]
29876
+ }, {
29877
+ lsd: [{
29878
+ width: (0, _uint.readUnsigned)(true)
29879
+ }, {
29880
+ height: (0, _uint.readUnsigned)(true)
29881
+ }, {
29882
+ gct: (0, _uint.readBits)({
29883
+ exists: {
29884
+ index: 0
29885
+ },
29886
+ resolution: {
29887
+ index: 1,
29888
+ length: 3
29889
+ },
29890
+ sort: {
29891
+ index: 4
29892
+ },
29893
+ size: {
29894
+ index: 5,
29895
+ length: 3
29896
+ }
29897
+ })
29898
+ }, {
29899
+ backgroundColorIndex: (0, _uint.readByte)()
29900
+ }, {
29901
+ pixelAspectRatio: (0, _uint.readByte)()
29902
+ }]
29903
+ }, (0, _.conditional)({
29904
+ gct: (0, _uint.readArray)(3, function (stream, result) {
29905
+ return Math.pow(2, result.lsd.gct.size + 1);
29906
+ })
29907
+ }, function (stream, result) {
29908
+ return result.lsd.gct.exists;
29909
+ }),
29910
+ // content frames
29911
+ {
29912
+ frames: (0, _.loop)([gceSchema, applicationSchema, commentSchema, imageSchema, textSchema], function (stream) {
29913
+ var nextCode = (0, _uint.peekByte)()(stream); // rather than check for a terminator, we should check for the existence
29914
+ // of an ext or image block to avoid infinite loops
29915
+ //var terminator = 0x3B;
29916
+ //return nextCode !== terminator;
29917
+
29918
+ return nextCode === 0x21 || nextCode === 0x2c;
29919
+ })
29920
+ }];
29921
+ var _default = schema;
29922
+ exports["default"] = _default;
29923
+ })(gif);
29924
+
29925
+ var deinterlace$1 = {};
29926
+
29927
+ Object.defineProperty(deinterlace$1, "__esModule", {
29928
+ value: true
29929
+ });
29930
+ deinterlace$1.deinterlace = void 0;
29931
+
29932
+ /**
29933
+ * Deinterlace function from https://github.com/shachaf/jsgif
29934
+ */
29935
+ var deinterlace = function deinterlace(pixels, width) {
29936
+ var newPixels = new Array(pixels.length);
29937
+ var rows = pixels.length / width;
29938
+ var cpRow = function cpRow(toRow, fromRow) {
29939
+ var fromPixels = pixels.slice(fromRow * width, (fromRow + 1) * width);
29940
+ newPixels.splice.apply(newPixels, [toRow * width, width].concat(fromPixels));
29941
+ }; // See appendix E.
29942
+
29943
+ var offsets = [0, 4, 2, 1];
29944
+ var steps = [8, 8, 4, 2];
29945
+ var fromRow = 0;
29946
+ for (var pass = 0; pass < 4; pass++) {
29947
+ for (var toRow = offsets[pass]; toRow < rows; toRow += steps[pass]) {
29948
+ cpRow(toRow, fromRow);
29949
+ fromRow++;
29950
+ }
29951
+ }
29952
+ return newPixels;
29953
+ };
29954
+ deinterlace$1.deinterlace = deinterlace;
29955
+
29956
+ var lzw$1 = {};
29957
+
29958
+ Object.defineProperty(lzw$1, "__esModule", {
29959
+ value: true
29960
+ });
29961
+ lzw$1.lzw = void 0;
29962
+
29963
+ /**
29964
+ * javascript port of java LZW decompression
29965
+ * Original java author url: https://gist.github.com/devunwired/4479231
29966
+ */
29967
+ var lzw = function lzw(minCodeSize, data, pixelCount) {
29968
+ var MAX_STACK_SIZE = 4096;
29969
+ var nullCode = -1;
29970
+ var npix = pixelCount;
29971
+ var available, clear, code_mask, code_size, end_of_information, in_code, old_code, bits, code, i, datum, data_size, first, top, bi, pi;
29972
+ var dstPixels = new Array(pixelCount);
29973
+ var prefix = new Array(MAX_STACK_SIZE);
29974
+ var suffix = new Array(MAX_STACK_SIZE);
29975
+ var pixelStack = new Array(MAX_STACK_SIZE + 1); // Initialize GIF data stream decoder.
29976
+
29977
+ data_size = minCodeSize;
29978
+ clear = 1 << data_size;
29979
+ end_of_information = clear + 1;
29980
+ available = clear + 2;
29981
+ old_code = nullCode;
29982
+ code_size = data_size + 1;
29983
+ code_mask = (1 << code_size) - 1;
29984
+ for (code = 0; code < clear; code++) {
29985
+ prefix[code] = 0;
29986
+ suffix[code] = code;
29987
+ } // Decode GIF pixel stream.
29988
+
29989
+ var datum, bits, first, top, pi, bi;
29990
+ datum = bits = first = top = pi = bi = 0;
29991
+ for (i = 0; i < npix;) {
29992
+ if (top === 0) {
29993
+ if (bits < code_size) {
29994
+ // get the next byte
29995
+ datum += data[bi] << bits;
29996
+ bits += 8;
29997
+ bi++;
29998
+ continue;
29999
+ } // Get the next code.
30000
+
30001
+ code = datum & code_mask;
30002
+ datum >>= code_size;
30003
+ bits -= code_size; // Interpret the code
30004
+
30005
+ if (code > available || code == end_of_information) {
30006
+ break;
30007
+ }
30008
+ if (code == clear) {
30009
+ // Reset decoder.
30010
+ code_size = data_size + 1;
30011
+ code_mask = (1 << code_size) - 1;
30012
+ available = clear + 2;
30013
+ old_code = nullCode;
30014
+ continue;
30015
+ }
30016
+ if (old_code == nullCode) {
30017
+ pixelStack[top++] = suffix[code];
30018
+ old_code = code;
30019
+ first = code;
30020
+ continue;
30021
+ }
30022
+ in_code = code;
30023
+ if (code == available) {
30024
+ pixelStack[top++] = first;
30025
+ code = old_code;
30026
+ }
30027
+ while (code > clear) {
30028
+ pixelStack[top++] = suffix[code];
30029
+ code = prefix[code];
30030
+ }
30031
+ first = suffix[code] & 0xff;
30032
+ pixelStack[top++] = first; // add a new string to the table, but only if space is available
30033
+ // if not, just continue with current table until a clear code is found
30034
+ // (deferred clear code implementation as per GIF spec)
30035
+
30036
+ if (available < MAX_STACK_SIZE) {
30037
+ prefix[available] = old_code;
30038
+ suffix[available] = first;
30039
+ available++;
30040
+ if ((available & code_mask) === 0 && available < MAX_STACK_SIZE) {
30041
+ code_size++;
30042
+ code_mask += available;
30043
+ }
30044
+ }
30045
+ old_code = in_code;
30046
+ } // Pop a pixel off the pixel stack.
30047
+
30048
+ top--;
30049
+ dstPixels[pi++] = pixelStack[top];
30050
+ i++;
30051
+ }
30052
+ for (i = pi; i < npix; i++) {
30053
+ dstPixels[i] = 0; // clear missing pixels
30054
+ }
30055
+
30056
+ return dstPixels;
30057
+ };
30058
+ lzw$1.lzw = lzw;
30059
+
30060
+ Object.defineProperty(lib$1, "__esModule", {
30061
+ value: true
30062
+ });
30063
+ var decompressFrames_1 = lib$1.decompressFrames = lib$1.decompressFrame = parseGIF_1 = lib$1.parseGIF = void 0;
30064
+ var _gif = _interopRequireDefault(gif);
30065
+ var _jsBinarySchemaParser = lib;
30066
+ var _uint = uint8;
30067
+ var _deinterlace = deinterlace$1;
30068
+ var _lzw = lzw$1;
30069
+ function _interopRequireDefault(obj) {
30070
+ return obj && obj.__esModule ? obj : {
30071
+ "default": obj
30072
+ };
30073
+ }
30074
+ var parseGIF = function parseGIF(arrayBuffer) {
30075
+ var byteData = new Uint8Array(arrayBuffer);
30076
+ return (0, _jsBinarySchemaParser.parse)((0, _uint.buildStream)(byteData), _gif["default"]);
30077
+ };
30078
+ var parseGIF_1 = lib$1.parseGIF = parseGIF;
30079
+ var generatePatch = function generatePatch(image) {
30080
+ var totalPixels = image.pixels.length;
30081
+ var patchData = new Uint8ClampedArray(totalPixels * 4);
30082
+ for (var i = 0; i < totalPixels; i++) {
30083
+ var pos = i * 4;
30084
+ var colorIndex = image.pixels[i];
30085
+ var color = image.colorTable[colorIndex] || [0, 0, 0];
30086
+ patchData[pos] = color[0];
30087
+ patchData[pos + 1] = color[1];
30088
+ patchData[pos + 2] = color[2];
30089
+ patchData[pos + 3] = colorIndex !== image.transparentIndex ? 255 : 0;
30090
+ }
30091
+ return patchData;
30092
+ };
30093
+ var decompressFrame = function decompressFrame(frame, gct, buildImagePatch) {
30094
+ if (!frame.image) {
30095
+ console.warn('gif frame does not have associated image.');
30096
+ return;
30097
+ }
30098
+ var image = frame.image; // get the number of pixels
30099
+
30100
+ var totalPixels = image.descriptor.width * image.descriptor.height; // do lzw decompression
30101
+
30102
+ var pixels = (0, _lzw.lzw)(image.data.minCodeSize, image.data.blocks, totalPixels); // deal with interlacing if necessary
30103
+
30104
+ if (image.descriptor.lct.interlaced) {
30105
+ pixels = (0, _deinterlace.deinterlace)(pixels, image.descriptor.width);
30106
+ }
30107
+ var resultImage = {
30108
+ pixels: pixels,
30109
+ dims: {
30110
+ top: frame.image.descriptor.top,
30111
+ left: frame.image.descriptor.left,
30112
+ width: frame.image.descriptor.width,
30113
+ height: frame.image.descriptor.height
30114
+ }
30115
+ }; // color table
30116
+
30117
+ if (image.descriptor.lct && image.descriptor.lct.exists) {
30118
+ resultImage.colorTable = image.lct;
30119
+ } else {
30120
+ resultImage.colorTable = gct;
30121
+ } // add per frame relevant gce information
30122
+
30123
+ if (frame.gce) {
30124
+ resultImage.delay = (frame.gce.delay || 10) * 10; // convert to ms
30125
+
30126
+ resultImage.disposalType = frame.gce.extras.disposal; // transparency
30127
+
30128
+ if (frame.gce.extras.transparentColorGiven) {
30129
+ resultImage.transparentIndex = frame.gce.transparentColorIndex;
30130
+ }
30131
+ } // create canvas usable imagedata if desired
30132
+
30133
+ if (buildImagePatch) {
30134
+ resultImage.patch = generatePatch(resultImage);
30135
+ }
30136
+ return resultImage;
30137
+ };
30138
+ lib$1.decompressFrame = decompressFrame;
30139
+ var decompressFrames = function decompressFrames(parsedGif, buildImagePatches) {
30140
+ return parsedGif.frames.filter(function (f) {
30141
+ return f.image;
30142
+ }).map(function (f) {
30143
+ return decompressFrame(f, parsedGif.gct, buildImagePatches);
30144
+ });
30145
+ };
30146
+ decompressFrames_1 = lib$1.decompressFrames = decompressFrames;
30147
+
30148
+ class GifImage extends Image {
30149
+ constructor(params) {
30150
+ super(params);
30151
+ this.isGifImage = true;
30152
+ this.loadGif();
30153
+ }
30154
+ loadGif() {
30155
+ if (isString(this.attribute.gifImage)) {
30156
+ ResourceLoader.GetFile(this.attribute.gifImage, 'arrayBuffer')
30157
+ .then((res) => {
30158
+ const gif = parseGIF_1(res);
30159
+ const frames = decompressFrames_1(gif, true);
30160
+ this.renderGIF(frames);
30161
+ })
30162
+ .catch(e => {
30163
+ console.error('Gif load error: ', e);
30164
+ });
30165
+ }
30166
+ else if (this.attribute.gifImage instanceof ArrayBuffer) {
30167
+ const gif = parseGIF_1(this.attribute.gifImage);
30168
+ const frames = decompressFrames_1(gif, true);
30169
+ this.renderGIF(frames);
30170
+ }
30171
+ }
30172
+ renderGIF(frames) {
30173
+ this.loadedFrames = frames;
30174
+ this.frameIndex = 0;
30175
+ if (!this.tempCanvas) {
30176
+ this.tempCanvas = application.global.createCanvas({});
30177
+ this.tempCtx = this.tempCanvas.getContext('2d');
30178
+ }
30179
+ if (!this.gifCanvas) {
30180
+ this.gifCanvas = application.global.createCanvas({});
30181
+ this.gifCtx = this.gifCanvas.getContext('2d');
30182
+ }
30183
+ this.gifCanvas.width = frames[0].dims.width;
30184
+ this.gifCanvas.height = frames[0].dims.height;
30185
+ this.playing = true;
30186
+ this.lastTime = new Date().getTime();
30187
+ const animation = this.animate();
30188
+ if (this.attribute.timeline) {
30189
+ animation.setTimeline(this.attribute.timeline);
30190
+ }
30191
+ animation.to({}, 1000, 'linear').loop(Infinity);
30192
+ }
30193
+ renderFrame(context, x, y) {
30194
+ const frame = this.loadedFrames[this.frameIndex || 0];
30195
+ if (frame.disposalType === 2) {
30196
+ this.gifCtx.clearRect(0, 0, this.gifCanvas.width, this.gifCanvas.height);
30197
+ }
30198
+ this.drawPatch(frame);
30199
+ this.manipulate(context, x, y);
30200
+ const diff = new Date().getTime() - this.lastTime;
30201
+ if (frame.delay < diff) {
30202
+ this.frameIndex++;
30203
+ this.lastTime = new Date().getTime();
30204
+ }
30205
+ if (this.frameIndex >= this.loadedFrames.length) {
30206
+ this.frameIndex = 0;
30207
+ }
30208
+ }
30209
+ drawPatch(frame) {
30210
+ const dims = frame.dims;
30211
+ if (!this.frameImageData ||
30212
+ dims.width !== this.frameImageData.width ||
30213
+ dims.height !== this.frameImageData.height) {
30214
+ this.tempCanvas.width = dims.width;
30215
+ this.tempCanvas.height = dims.height;
30216
+ this.frameImageData = this.tempCtx.createImageData(dims.width, dims.height);
30217
+ }
30218
+ this.frameImageData.data.set(frame.patch);
30219
+ this.tempCtx.putImageData(this.frameImageData, 0, 0);
30220
+ this.gifCtx.drawImage(this.tempCanvas, dims.left, dims.top);
30221
+ }
30222
+ manipulate(context, x, y) {
30223
+ context.drawImage(this.gifCanvas, 0, 0, this.gifCanvas.width, this.gifCanvas.height, x, y, this.attribute.width, this.attribute.height);
30224
+ }
30225
+ setAttribute(key, value, forceUpdateTag, context) {
30226
+ super.setAttribute(key, value, forceUpdateTag, context);
30227
+ if (key === 'gifImage') {
30228
+ this.loadGif();
30229
+ }
30230
+ }
30231
+ setAttributes(params, forceUpdateTag, context) {
30232
+ super.setAttributes(params, forceUpdateTag, context);
30233
+ if (params.gifImage) {
30234
+ this.loadGif();
30235
+ }
30236
+ }
30237
+ }
30238
+
30239
+ const version = "0.21.0-alpha.4";
29487
30240
 
29488
- export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GroupTransition, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SizeContinuousLegend, Slider, SymbolLabel, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };
30241
+ export { AXIS_ELEMENT_NAME, AbstractComponent, ArcInfo, ArcLabel, ArcSegment, AxisStateValue, BasePlayer, Brush, CheckBox, CircleAxis, CircleAxisGrid, CircleCrosshair, ColorContinuousLegend, ContinuousPlayer, DEFAULT_ITEM_SPACE_COL, DEFAULT_ITEM_SPACE_ROW, DEFAULT_LABEL_SPACE, DEFAULT_PAGER_SPACE, DEFAULT_SHAPE_SIZE, DEFAULT_SHAPE_SPACE, DEFAULT_STATES$1 as DEFAULT_STATES, DEFAULT_TITLE_SPACE, DEFAULT_VALUE_SPACE, DataLabel, DataZoom, DataZoomActiveTag, DirectionEnum, DiscreteLegend, DiscretePlayer, EmptyTip, GifImage, GroupTransition, IMarkAreaLabelPosition, IMarkCommonArcLabelPosition, IMarkLineLabelPosition, IMarkPointItemPosition, IOperateType, Indicator, LEGEND_ELEMENT_NAME, LabelBase, LegendEvent, LegendStateValue, LineAxis, LineAxisGrid, LineCrosshair, LineLabel, LinkPath, MarkArcArea, MarkArcLine, MarkArea, MarkLine, MarkPoint, Pager, PlayerEventEnum, PolygonCrosshair, PopTip, Radio, RectCrosshair, RectLabel, SLIDER_ELEMENT_NAME, ScrollBar, SectorCrosshair, Segment, SizeContinuousLegend, Slider, SymbolLabel, Tag, Timeline, Title, Tooltip, TopZIndex, VTag, alignTextInLine, angle, angleLabelOrientAttribute, angleTo, cartesianTicks, clampRadian, computeOffsetForlimit, continuousTicks, contrastAccessibilityChecker, convertDomainToTickData, createTextGraphicByType, deltaXYToAngle, fuzzyEqualNumber, getAxisBreakSymbolAttrs, getCircleLabelPosition, getCirclePoints, getCircleVerticalVector, getElMap, getHorizontalPath, getMarksByName, getNoneGroupMarksByName, getPolarAngleLabelPosition, getPolygonPath, getSizeHandlerPath, getTextAlignAttrOfVerticalDir, getTextType, getVerticalCoord, getVerticalPath, hasOverlap, htmlAttributeTransform, initTextMeasure, isInRange, isPostiveXAxis, isRichText, isVisible, labelSmartInvert, length, limitShapeInBounds, linearDiscreteTicks, loadPoptip, measureTextSize, normalize, polarAngleAxisDiscreteTicks, polarTicks, reactAttributeTransform, registerArcDataLabel, registerLineDataLabel, registerMarkArcAreaAnimate, registerMarkArcLineAnimate, registerMarkAreaAnimate, registerMarkLineAnimate, registerMarkPointAnimate, registerRectDataLabel, registerSymbolDataLabel, removeRepeatPoint, richTextAttributeTransform, scale, setPoptipTheme, smartInvertStrategy, tan2AngleToAngle, textIntersect, ticks, traverseGroup, version };