@antv/g-lite 1.0.9 → 1.0.10

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
@@ -2974,6 +2974,7 @@ var CSSRGB = /*#__PURE__*/function (_CSSColorValue) {
2974
2974
  PropertySyntax["OFFSET_PATH"] = "<offset-path>";
2975
2975
  PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
2976
2976
  PropertySyntax["CLIP_PATH"] = "<clip-path>";
2977
+ PropertySyntax["TEXT_PATH"] = "<text-path>";
2977
2978
  PropertySyntax["MARKER"] = "<marker>";
2978
2979
  PropertySyntax["TRANSFORM"] = "<transform>";
2979
2980
  PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
@@ -7641,13 +7642,19 @@ var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%
7641
7642
  var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
7642
7643
  var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
7643
7644
  var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
7645
+ /**
7646
+ * Borrow from pixi/packages/text/src/TextMetrics.ts
7647
+ */
7644
7648
 
7645
7649
  exports.TextService = /*#__PURE__*/function () {
7650
+ /**
7651
+ * font metrics cache
7652
+ */
7646
7653
  function TextService(offscreenCanvas) {
7647
7654
  var _this = this;
7648
7655
 
7649
7656
  this.offscreenCanvas = void 0;
7650
- this.cache = {};
7657
+ this.fontMetricsCache = {};
7651
7658
 
7652
7659
  this.shouldBreakByKinsokuShorui = function (char, nextChar) {
7653
7660
  if (_this.isBreakingSpace(nextChar)) return false;
@@ -7678,13 +7685,17 @@ exports.TextService = /*#__PURE__*/function () {
7678
7685
 
7679
7686
  this.offscreenCanvas = offscreenCanvas;
7680
7687
  }
7688
+ /**
7689
+ * Calculates the ascent, descent and fontSize of a given font-style.
7690
+ */
7691
+
7681
7692
 
7682
7693
  var _proto = TextService.prototype;
7683
7694
 
7684
7695
  _proto.measureFont = function measureFont(font, offscreenCanvas) {
7685
7696
  // as this method is used for preparing assets, don't recalculate things if we don't need to
7686
- if (this.cache[font]) {
7687
- return this.cache[font];
7697
+ if (this.fontMetricsCache[font]) {
7698
+ return this.fontMetricsCache[font];
7688
7699
  }
7689
7700
 
7690
7701
  var properties = {
@@ -7753,7 +7764,7 @@ exports.TextService = /*#__PURE__*/function () {
7753
7764
 
7754
7765
  properties.descent = i - baseline;
7755
7766
  properties.fontSize = properties.ascent + properties.descent;
7756
- this.cache[font] = properties;
7767
+ this.fontMetricsCache[font] = properties;
7757
7768
  return properties;
7758
7769
  };
7759
7770
 
@@ -7765,6 +7776,9 @@ exports.TextService = /*#__PURE__*/function () {
7765
7776
  textBaseline = parsedStyle.textBaseline,
7766
7777
  textAlign = parsedStyle.textAlign,
7767
7778
  letterSpacing = parsedStyle.letterSpacing,
7779
+ textPath = parsedStyle.textPath,
7780
+ textPathSide = parsedStyle.textPathSide,
7781
+ textPathStartOffset = parsedStyle.textPathStartOffset,
7768
7782
  _parsedStyle$leading = parsedStyle.leading,
7769
7783
  leading = _parsedStyle$leading === void 0 ? 0 : _parsedStyle$leading;
7770
7784
  var font = toFontString(parsedStyle);
@@ -7783,59 +7797,92 @@ exports.TextService = /*#__PURE__*/function () {
7783
7797
  var outputText = wordWrap ? this.wordWrap(text, parsedStyle, offscreenCanvas) : text;
7784
7798
  var lines = outputText.split(/(?:\r\n|\r|\n)/);
7785
7799
  var lineWidths = new Array(lines.length);
7786
- var maxLineWidth = 0;
7800
+ var maxLineWidth = 0; // account for textPath
7787
7801
 
7788
- for (var i = 0; i < lines.length; i++) {
7789
- var _lineWidth = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
7802
+ if (textPath) {
7803
+ var totalPathLength = textPath.getTotalLength(); // eslint-disable-next-line @typescript-eslint/no-unused-vars
7790
7804
 
7791
- lineWidths[i] = _lineWidth;
7792
- maxLineWidth = Math.max(maxLineWidth, _lineWidth);
7793
- }
7805
+ var startingPoint = textPath.getPoint(0);
7794
7806
 
7795
- var width = maxLineWidth + lineWidth; // if (dropShadow) {
7796
- // width += dropShadowDistance;
7797
- // }
7807
+ for (var i = 0; i < lines.length; i++) {
7808
+ var width = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
7809
+ // let i = reverse ? lines[0].length - 1 : 0;
7810
+ // reverse ? i >= 0 : i < lines[0].length;
7811
+ // reverse ? i-- : i++
7812
+ // ) {
7813
+ // graphemeInfo = lineBounds[i];
7814
+ // if (positionInPath > totalPathLength) {
7815
+ // positionInPath %= totalPathLength;
7816
+ // } else if (positionInPath < 0) {
7817
+ // positionInPath += totalPathLength;
7818
+ // }
7819
+ // // it would probably much faster to send all the grapheme position for a line
7820
+ // // and calculate path position/angle at once.
7821
+ // this.setGraphemeOnPath(
7822
+ // positionInPath,
7823
+ // graphemeInfo,
7824
+ // startingPoint
7825
+ // );
7826
+ // positionInPath += graphemeInfo.kernedWidth;
7827
+ // }
7828
+ }
7829
+ } else {
7830
+ for (var _i = 0; _i < lines.length; _i++) {
7831
+ // char width + letterSpacing
7832
+ var _lineWidth = context.measureText(lines[_i]).width + (lines[_i].length - 1) * letterSpacing;
7798
7833
 
7799
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
7800
- var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading); // if (dropShadow) {
7801
- // height += dropShadowDistance;
7802
- // }
7834
+ lineWidths[_i] = _lineWidth;
7835
+ maxLineWidth = Math.max(maxLineWidth, _lineWidth);
7836
+ }
7803
7837
 
7804
- lineHeight += leading; // handle vertical text baseline
7838
+ var _width = maxLineWidth + lineWidth; // if (dropShadow) {
7839
+ // width += dropShadowDistance;
7840
+ // }
7805
7841
 
7806
- var offsetY = 0;
7807
7842
 
7808
- if (textBaseline === 'middle') {
7809
- offsetY = -height / 2;
7810
- } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
7811
- offsetY = -height;
7812
- } else if (textBaseline === 'top' || textBaseline === 'hanging') {
7813
- offsetY = 0;
7814
- }
7843
+ var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
7844
+ var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading); // if (dropShadow) {
7845
+ // height += dropShadowDistance;
7846
+ // }
7815
7847
 
7816
- return {
7817
- font: font,
7818
- width: width,
7819
- height: height,
7820
- lines: lines,
7821
- lineWidths: lineWidths,
7822
- lineHeight: lineHeight,
7823
- maxLineWidth: maxLineWidth,
7824
- fontProperties: fontProperties,
7825
- lineMetrics: lineWidths.map(function (width, i) {
7826
- var offsetX = 0; // handle horizontal text align
7827
-
7828
- if (textAlign === 'center') {
7829
- offsetX -= width / 2;
7830
- } else if (textAlign === 'right' || textAlign === 'end') {
7831
- offsetX -= width;
7832
- }
7848
+ lineHeight += leading; // handle vertical text baseline
7833
7849
 
7834
- return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
7835
- })
7836
- };
7850
+ var offsetY = 0;
7851
+
7852
+ if (textBaseline === 'middle') {
7853
+ offsetY = -height / 2;
7854
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
7855
+ offsetY = -height;
7856
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
7857
+ offsetY = 0;
7858
+ }
7859
+
7860
+ return {
7861
+ font: font,
7862
+ width: _width,
7863
+ height: height,
7864
+ lines: lines,
7865
+ lineWidths: lineWidths,
7866
+ lineHeight: lineHeight,
7867
+ maxLineWidth: maxLineWidth,
7868
+ fontProperties: fontProperties,
7869
+ lineMetrics: lineWidths.map(function (width, i) {
7870
+ var offsetX = 0; // handle horizontal text align
7871
+
7872
+ if (textAlign === 'center') {
7873
+ offsetX -= width / 2;
7874
+ } else if (textAlign === 'right' || textAlign === 'end') {
7875
+ offsetX -= width;
7876
+ }
7877
+
7878
+ return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
7879
+ })
7880
+ };
7881
+ }
7837
7882
  };
7838
7883
 
7884
+ _proto.setGraphemeOnPath = function setGraphemeOnPath() {};
7885
+
7839
7886
  _proto.wordWrap = function wordWrap(text, parsedStyle, offscreenCanvas) {
7840
7887
  var _this2 = this;
7841
7888
 
@@ -7892,15 +7939,15 @@ exports.TextService = /*#__PURE__*/function () {
7892
7939
  var lastLineWidth = 0;
7893
7940
  var lastLineIndex = 0;
7894
7941
 
7895
- for (var _i = 0; _i < lines[currentIndex].length; _i++) {
7896
- var _width = calcWidth(lines[currentIndex][_i]);
7942
+ for (var _i2 = 0; _i2 < lines[currentIndex].length; _i2++) {
7943
+ var _width2 = calcWidth(lines[currentIndex][_i2]);
7897
7944
 
7898
- if (lastLineWidth + _width + ellipsisWidth > maxWidth) {
7899
- lastLineIndex = _i;
7945
+ if (lastLineWidth + _width2 + ellipsisWidth > maxWidth) {
7946
+ lastLineIndex = _i2;
7900
7947
  break;
7901
7948
  }
7902
7949
 
7903
- lastLineWidth += _width;
7950
+ lastLineWidth += _width2;
7904
7951
  }
7905
7952
 
7906
7953
  lines[currentIndex] = (lines[currentIndex] || '').slice(0, lastLineIndex) + ellipsis;
@@ -8036,7 +8083,6 @@ exports.TextUpdater = /*#__PURE__*/function () {
8036
8083
  offscreenCanvas = _ref.offscreenCanvas;
8037
8084
 
8038
8085
  if (!this.isReadyToMeasure(parsedStyle, object)) {
8039
- // if (!text || !textAlign || !textBaseline ||) {
8040
8086
  parsedStyle.metrics = {
8041
8087
  font: '',
8042
8088
  width: 0,
@@ -10599,20 +10645,23 @@ var DisplayObject = /*#__PURE__*/function (_Element) {
10599
10645
  var oldParsedValue = this.parsedStyle[name];
10600
10646
  this.styleValueRegistry.processProperties(this, (_this$styleValueRegis = {}, _this$styleValueRegis[name] = value, _this$styleValueRegis), parseOptions); // inform clip path targets
10601
10647
 
10602
- if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
10603
- this.parsedStyle.clipPathTargets.forEach(function (target) {
10604
- _this2.sceneGraphService.dirtifyToRoot(target);
10648
+ ['clipPathTargets', 'textPathTargets'].forEach(function (pathTargetsName, i) {
10649
+ if (_this2.parsedStyle[pathTargetsName] && _this2.parsedStyle[pathTargetsName].length) {
10650
+ var modifiedName = i === 0 ? 'clipPath' : 'textPath';
10605
10651
 
10606
- target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, 'clipPath', MutationEvent.MODIFICATION, _this2, _this2));
10652
+ _this2.parsedStyle[pathTargetsName].forEach(function (target) {
10653
+ _this2.sceneGraphService.dirtifyToRoot(target);
10607
10654
 
10608
- if (target.isCustomElement && target.isConnected) {
10609
- if (target.attributeChangedCallback) {
10610
- target.attributeChangedCallback('clipPath', _this2, _this2);
10611
- }
10612
- }
10613
- });
10614
- } // redraw at next frame
10655
+ target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, modifiedName, MutationEvent.MODIFICATION, _this2, _this2));
10615
10656
 
10657
+ if (target.isCustomElement && target.isConnected) {
10658
+ if (target.attributeChangedCallback) {
10659
+ target.attributeChangedCallback(modifiedName, _this2, _this2);
10660
+ }
10661
+ }
10662
+ });
10663
+ }
10664
+ }); // redraw at next frame
10616
10665
 
10617
10666
  renderable.dirty = true; // trigger later
10618
10667
  // this.sceneGraphService.pendingEvents.push([ElementEvent.ATTR_MODIFIED, { affectChildren }]);
@@ -15541,20 +15590,21 @@ var CSSPropertyClipPath = /*#__PURE__*/function () {
15541
15590
  // unset
15542
15591
  if (newClipPath instanceof CSSKeywordValue) {
15543
15592
  newClipPath = null;
15544
- } // clear ref to old clip path
15593
+ }
15545
15594
 
15595
+ var pathTargetsName = name === 'clipPath' ? 'clipPathTargets' : 'textPathTargets'; // clear ref to old clip path
15546
15596
 
15547
- if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle.clipPathTargets) {
15548
- var index = oldClipPath.parsedStyle.clipPathTargets.indexOf(object);
15549
- oldClipPath.parsedStyle.clipPathTargets.splice(index, 1);
15597
+ if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle[pathTargetsName]) {
15598
+ var index = oldClipPath.parsedStyle[pathTargetsName].indexOf(object);
15599
+ oldClipPath.parsedStyle[pathTargetsName].splice(index, 1);
15550
15600
  }
15551
15601
 
15552
15602
  if (newClipPath) {
15553
- if (!newClipPath.parsedStyle.clipPathTargets) {
15554
- newClipPath.parsedStyle.clipPathTargets = [];
15603
+ if (!newClipPath.parsedStyle[pathTargetsName]) {
15604
+ newClipPath.parsedStyle[pathTargetsName] = [];
15555
15605
  }
15556
15606
 
15557
- newClipPath.parsedStyle.clipPathTargets.push(object);
15607
+ newClipPath.parsedStyle[pathTargetsName].push(object);
15558
15608
  } // should affect children
15559
15609
 
15560
15610
 
@@ -15570,10 +15620,13 @@ var CSSPropertyClipPath = /*#__PURE__*/function () {
15570
15620
  }();
15571
15621
 
15572
15622
  CSSPropertyClipPath = tslib.__decorate([manaSyringe.singleton({
15573
- token: {
15623
+ token: [{
15574
15624
  token: CSSProperty,
15575
15625
  named: exports.PropertySyntax.CLIP_PATH
15576
- }
15626
+ }, {
15627
+ token: CSSProperty,
15628
+ named: exports.PropertySyntax.TEXT_PATH
15629
+ }]
15577
15630
  }), tslib.__param(0, manaSyringe.inject(SceneGraphService))], CSSPropertyClipPath);
15578
15631
 
15579
15632
  var CSSPropertyColor = /*#__PURE__*/function () {
@@ -16520,6 +16573,10 @@ var BUILT_IN_PROPERTIES = [{
16520
16573
  k: ['none'],
16521
16574
  d: 'none',
16522
16575
  syntax: exports.PropertySyntax.PAINT
16576
+ }, {
16577
+ n: 'fillRule',
16578
+ k: ['nonzero', 'evenodd'],
16579
+ d: 'nonzero'
16523
16580
  },
16524
16581
  /**
16525
16582
  * default to none
@@ -16657,6 +16714,18 @@ var BUILT_IN_PROPERTIES = [{
16657
16714
  }, {
16658
16715
  n: 'clipPath',
16659
16716
  syntax: exports.PropertySyntax.CLIP_PATH
16717
+ }, {
16718
+ n: 'textPath',
16719
+ syntax: exports.PropertySyntax.TEXT_PATH
16720
+ }, {
16721
+ n: 'textPathSide',
16722
+ k: ['left', 'right'],
16723
+ d: 'left'
16724
+ }, {
16725
+ n: 'textPathStartOffset',
16726
+ l: true,
16727
+ d: '0',
16728
+ syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
16660
16729
  }, {
16661
16730
  n: 'transform',
16662
16731
  p: 100,