@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.umd.js CHANGED
@@ -12500,6 +12500,7 @@
12500
12500
  PropertySyntax["OFFSET_PATH"] = "<offset-path>";
12501
12501
  PropertySyntax["OFFSET_DISTANCE"] = "<offset-distance>";
12502
12502
  PropertySyntax["CLIP_PATH"] = "<clip-path>";
12503
+ PropertySyntax["TEXT_PATH"] = "<text-path>";
12503
12504
  PropertySyntax["MARKER"] = "<marker>";
12504
12505
  PropertySyntax["TRANSFORM"] = "<transform>";
12505
12506
  PropertySyntax["TRANSFORM_ORIGIN"] = "<transform-origin>";
@@ -17881,13 +17882,19 @@
17881
17882
  var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
17882
17883
  var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
17883
17884
  var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
17885
+ /**
17886
+ * Borrow from pixi/packages/text/src/TextMetrics.ts
17887
+ */
17884
17888
 
17885
17889
  exports.TextService = /*#__PURE__*/function () {
17890
+ /**
17891
+ * font metrics cache
17892
+ */
17886
17893
  function TextService(offscreenCanvas) {
17887
17894
  var _this = this;
17888
17895
 
17889
17896
  this.offscreenCanvas = void 0;
17890
- this.cache = {};
17897
+ this.fontMetricsCache = {};
17891
17898
 
17892
17899
  this.shouldBreakByKinsokuShorui = function (char, nextChar) {
17893
17900
  if (_this.isBreakingSpace(nextChar)) return false;
@@ -17918,13 +17925,17 @@
17918
17925
 
17919
17926
  this.offscreenCanvas = offscreenCanvas;
17920
17927
  }
17928
+ /**
17929
+ * Calculates the ascent, descent and fontSize of a given font-style.
17930
+ */
17931
+
17921
17932
 
17922
17933
  var _proto = TextService.prototype;
17923
17934
 
17924
17935
  _proto.measureFont = function measureFont(font, offscreenCanvas) {
17925
17936
  // as this method is used for preparing assets, don't recalculate things if we don't need to
17926
- if (this.cache[font]) {
17927
- return this.cache[font];
17937
+ if (this.fontMetricsCache[font]) {
17938
+ return this.fontMetricsCache[font];
17928
17939
  }
17929
17940
 
17930
17941
  var properties = {
@@ -17993,7 +18004,7 @@
17993
18004
 
17994
18005
  properties.descent = i - baseline;
17995
18006
  properties.fontSize = properties.ascent + properties.descent;
17996
- this.cache[font] = properties;
18007
+ this.fontMetricsCache[font] = properties;
17997
18008
  return properties;
17998
18009
  };
17999
18010
 
@@ -18005,6 +18016,9 @@
18005
18016
  textBaseline = parsedStyle.textBaseline,
18006
18017
  textAlign = parsedStyle.textAlign,
18007
18018
  letterSpacing = parsedStyle.letterSpacing,
18019
+ textPath = parsedStyle.textPath,
18020
+ textPathSide = parsedStyle.textPathSide,
18021
+ textPathStartOffset = parsedStyle.textPathStartOffset,
18008
18022
  _parsedStyle$leading = parsedStyle.leading,
18009
18023
  leading = _parsedStyle$leading === void 0 ? 0 : _parsedStyle$leading;
18010
18024
  var font = toFontString(parsedStyle);
@@ -18023,59 +18037,92 @@
18023
18037
  var outputText = wordWrap ? this.wordWrap(text, parsedStyle, offscreenCanvas) : text;
18024
18038
  var lines = outputText.split(/(?:\r\n|\r|\n)/);
18025
18039
  var lineWidths = new Array(lines.length);
18026
- var maxLineWidth = 0;
18040
+ var maxLineWidth = 0; // account for textPath
18027
18041
 
18028
- for (var i = 0; i < lines.length; i++) {
18029
- var _lineWidth = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
18042
+ if (textPath) {
18043
+ var totalPathLength = textPath.getTotalLength(); // eslint-disable-next-line @typescript-eslint/no-unused-vars
18030
18044
 
18031
- lineWidths[i] = _lineWidth;
18032
- maxLineWidth = Math.max(maxLineWidth, _lineWidth);
18033
- }
18045
+ var startingPoint = textPath.getPoint(0);
18034
18046
 
18035
- var width = maxLineWidth + lineWidth; // if (dropShadow) {
18036
- // width += dropShadowDistance;
18037
- // }
18047
+ for (var i = 0; i < lines.length; i++) {
18048
+ var width = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
18049
+ // let i = reverse ? lines[0].length - 1 : 0;
18050
+ // reverse ? i >= 0 : i < lines[0].length;
18051
+ // reverse ? i-- : i++
18052
+ // ) {
18053
+ // graphemeInfo = lineBounds[i];
18054
+ // if (positionInPath > totalPathLength) {
18055
+ // positionInPath %= totalPathLength;
18056
+ // } else if (positionInPath < 0) {
18057
+ // positionInPath += totalPathLength;
18058
+ // }
18059
+ // // it would probably much faster to send all the grapheme position for a line
18060
+ // // and calculate path position/angle at once.
18061
+ // this.setGraphemeOnPath(
18062
+ // positionInPath,
18063
+ // graphemeInfo,
18064
+ // startingPoint
18065
+ // );
18066
+ // positionInPath += graphemeInfo.kernedWidth;
18067
+ // }
18068
+ }
18069
+ } else {
18070
+ for (var _i = 0; _i < lines.length; _i++) {
18071
+ // char width + letterSpacing
18072
+ var _lineWidth = context.measureText(lines[_i]).width + (lines[_i].length - 1) * letterSpacing;
18038
18073
 
18039
- var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
18040
- var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading); // if (dropShadow) {
18041
- // height += dropShadowDistance;
18042
- // }
18074
+ lineWidths[_i] = _lineWidth;
18075
+ maxLineWidth = Math.max(maxLineWidth, _lineWidth);
18076
+ }
18043
18077
 
18044
- lineHeight += leading; // handle vertical text baseline
18078
+ var _width = maxLineWidth + lineWidth; // if (dropShadow) {
18079
+ // width += dropShadowDistance;
18080
+ // }
18045
18081
 
18046
- var offsetY = 0;
18047
18082
 
18048
- if (textBaseline === 'middle') {
18049
- offsetY = -height / 2;
18050
- } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
18051
- offsetY = -height;
18052
- } else if (textBaseline === 'top' || textBaseline === 'hanging') {
18053
- offsetY = 0;
18054
- }
18083
+ var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
18084
+ var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading); // if (dropShadow) {
18085
+ // height += dropShadowDistance;
18086
+ // }
18055
18087
 
18056
- return {
18057
- font: font,
18058
- width: width,
18059
- height: height,
18060
- lines: lines,
18061
- lineWidths: lineWidths,
18062
- lineHeight: lineHeight,
18063
- maxLineWidth: maxLineWidth,
18064
- fontProperties: fontProperties,
18065
- lineMetrics: lineWidths.map(function (width, i) {
18066
- var offsetX = 0; // handle horizontal text align
18067
-
18068
- if (textAlign === 'center') {
18069
- offsetX -= width / 2;
18070
- } else if (textAlign === 'right' || textAlign === 'end') {
18071
- offsetX -= width;
18072
- }
18073
-
18074
- return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
18075
- })
18076
- };
18088
+ lineHeight += leading; // handle vertical text baseline
18089
+
18090
+ var offsetY = 0;
18091
+
18092
+ if (textBaseline === 'middle') {
18093
+ offsetY = -height / 2;
18094
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
18095
+ offsetY = -height;
18096
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
18097
+ offsetY = 0;
18098
+ }
18099
+
18100
+ return {
18101
+ font: font,
18102
+ width: _width,
18103
+ height: height,
18104
+ lines: lines,
18105
+ lineWidths: lineWidths,
18106
+ lineHeight: lineHeight,
18107
+ maxLineWidth: maxLineWidth,
18108
+ fontProperties: fontProperties,
18109
+ lineMetrics: lineWidths.map(function (width, i) {
18110
+ var offsetX = 0; // handle horizontal text align
18111
+
18112
+ if (textAlign === 'center') {
18113
+ offsetX -= width / 2;
18114
+ } else if (textAlign === 'right' || textAlign === 'end') {
18115
+ offsetX -= width;
18116
+ }
18117
+
18118
+ return new Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
18119
+ })
18120
+ };
18121
+ }
18077
18122
  };
18078
18123
 
18124
+ _proto.setGraphemeOnPath = function setGraphemeOnPath() {};
18125
+
18079
18126
  _proto.wordWrap = function wordWrap(text, parsedStyle, offscreenCanvas) {
18080
18127
  var _this2 = this;
18081
18128
 
@@ -18132,15 +18179,15 @@
18132
18179
  var lastLineWidth = 0;
18133
18180
  var lastLineIndex = 0;
18134
18181
 
18135
- for (var _i = 0; _i < lines[currentIndex].length; _i++) {
18136
- var _width = calcWidth(lines[currentIndex][_i]);
18182
+ for (var _i2 = 0; _i2 < lines[currentIndex].length; _i2++) {
18183
+ var _width2 = calcWidth(lines[currentIndex][_i2]);
18137
18184
 
18138
- if (lastLineWidth + _width + ellipsisWidth > maxWidth) {
18139
- lastLineIndex = _i;
18185
+ if (lastLineWidth + _width2 + ellipsisWidth > maxWidth) {
18186
+ lastLineIndex = _i2;
18140
18187
  break;
18141
18188
  }
18142
18189
 
18143
- lastLineWidth += _width;
18190
+ lastLineWidth += _width2;
18144
18191
  }
18145
18192
 
18146
18193
  lines[currentIndex] = (lines[currentIndex] || '').slice(0, lastLineIndex) + ellipsis;
@@ -18276,7 +18323,6 @@
18276
18323
  offscreenCanvas = _ref.offscreenCanvas;
18277
18324
 
18278
18325
  if (!this.isReadyToMeasure(parsedStyle, object)) {
18279
- // if (!text || !textAlign || !textBaseline ||) {
18280
18326
  parsedStyle.metrics = {
18281
18327
  font: '',
18282
18328
  width: 0,
@@ -21177,20 +21223,23 @@
21177
21223
  var oldParsedValue = this.parsedStyle[name];
21178
21224
  this.styleValueRegistry.processProperties(this, (_this$styleValueRegis = {}, _this$styleValueRegis[name] = value, _this$styleValueRegis), parseOptions); // inform clip path targets
21179
21225
 
21180
- if (this.parsedStyle.clipPathTargets && this.parsedStyle.clipPathTargets.length) {
21181
- this.parsedStyle.clipPathTargets.forEach(function (target) {
21182
- _this2.sceneGraphService.dirtifyToRoot(target);
21226
+ ['clipPathTargets', 'textPathTargets'].forEach(function (pathTargetsName, i) {
21227
+ if (_this2.parsedStyle[pathTargetsName] && _this2.parsedStyle[pathTargetsName].length) {
21228
+ var modifiedName = i === 0 ? 'clipPath' : 'textPath';
21183
21229
 
21184
- target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, 'clipPath', MutationEvent.MODIFICATION, _this2, _this2));
21230
+ _this2.parsedStyle[pathTargetsName].forEach(function (target) {
21231
+ _this2.sceneGraphService.dirtifyToRoot(target);
21185
21232
 
21186
- if (target.isCustomElement && target.isConnected) {
21187
- if (target.attributeChangedCallback) {
21188
- target.attributeChangedCallback('clipPath', _this2, _this2);
21189
- }
21190
- }
21191
- });
21192
- } // redraw at next frame
21233
+ target.dispatchEvent(new MutationEvent(exports.ElementEvent.ATTR_MODIFIED, target, _this2, _this2, modifiedName, MutationEvent.MODIFICATION, _this2, _this2));
21193
21234
 
21235
+ if (target.isCustomElement && target.isConnected) {
21236
+ if (target.attributeChangedCallback) {
21237
+ target.attributeChangedCallback(modifiedName, _this2, _this2);
21238
+ }
21239
+ }
21240
+ });
21241
+ }
21242
+ }); // redraw at next frame
21194
21243
 
21195
21244
  renderable.dirty = true; // trigger later
21196
21245
  // this.sceneGraphService.pendingEvents.push([ElementEvent.ATTR_MODIFIED, { affectChildren }]);
@@ -26119,20 +26168,21 @@
26119
26168
  // unset
26120
26169
  if (newClipPath instanceof CSSKeywordValue) {
26121
26170
  newClipPath = null;
26122
- } // clear ref to old clip path
26171
+ }
26123
26172
 
26173
+ var pathTargetsName = name === 'clipPath' ? 'clipPathTargets' : 'textPathTargets'; // clear ref to old clip path
26124
26174
 
26125
- if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle.clipPathTargets) {
26126
- var index = oldClipPath.parsedStyle.clipPathTargets.indexOf(object);
26127
- oldClipPath.parsedStyle.clipPathTargets.splice(index, 1);
26175
+ if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle[pathTargetsName]) {
26176
+ var index = oldClipPath.parsedStyle[pathTargetsName].indexOf(object);
26177
+ oldClipPath.parsedStyle[pathTargetsName].splice(index, 1);
26128
26178
  }
26129
26179
 
26130
26180
  if (newClipPath) {
26131
- if (!newClipPath.parsedStyle.clipPathTargets) {
26132
- newClipPath.parsedStyle.clipPathTargets = [];
26181
+ if (!newClipPath.parsedStyle[pathTargetsName]) {
26182
+ newClipPath.parsedStyle[pathTargetsName] = [];
26133
26183
  }
26134
26184
 
26135
- newClipPath.parsedStyle.clipPathTargets.push(object);
26185
+ newClipPath.parsedStyle[pathTargetsName].push(object);
26136
26186
  } // should affect children
26137
26187
 
26138
26188
 
@@ -26148,10 +26198,13 @@
26148
26198
  }();
26149
26199
 
26150
26200
  CSSPropertyClipPath = __decorate([singleton({
26151
- token: {
26201
+ token: [{
26152
26202
  token: CSSProperty,
26153
26203
  named: exports.PropertySyntax.CLIP_PATH
26154
- }
26204
+ }, {
26205
+ token: CSSProperty,
26206
+ named: exports.PropertySyntax.TEXT_PATH
26207
+ }]
26155
26208
  }), __param(0, inject(SceneGraphService))], CSSPropertyClipPath);
26156
26209
 
26157
26210
  var CSSPropertyColor = /*#__PURE__*/function () {
@@ -27098,6 +27151,10 @@
27098
27151
  k: ['none'],
27099
27152
  d: 'none',
27100
27153
  syntax: exports.PropertySyntax.PAINT
27154
+ }, {
27155
+ n: 'fillRule',
27156
+ k: ['nonzero', 'evenodd'],
27157
+ d: 'nonzero'
27101
27158
  },
27102
27159
  /**
27103
27160
  * default to none
@@ -27235,6 +27292,18 @@
27235
27292
  }, {
27236
27293
  n: 'clipPath',
27237
27294
  syntax: exports.PropertySyntax.CLIP_PATH
27295
+ }, {
27296
+ n: 'textPath',
27297
+ syntax: exports.PropertySyntax.TEXT_PATH
27298
+ }, {
27299
+ n: 'textPathSide',
27300
+ k: ['left', 'right'],
27301
+ d: 'left'
27302
+ }, {
27303
+ n: 'textPathStartOffset',
27304
+ l: true,
27305
+ d: '0',
27306
+ syntax: exports.PropertySyntax.LENGTH_PERCENTAGE
27238
27307
  }, {
27239
27308
  n: 'transform',
27240
27309
  p: 100,