@antv/g-lite 1.0.3 → 1.0.5

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
@@ -7720,7 +7720,9 @@ exports.TextService = /*#__PURE__*/function () {
7720
7720
  }
7721
7721
 
7722
7722
  var context = this.offscreenCanvas.getOrCreateContext(offscreenCanvas);
7723
- context.font = font;
7723
+ context.font = font; // no overflowing by default
7724
+
7725
+ parsedStyle.isOverflowing = false;
7724
7726
  var outputText = wordWrap ? this.wordWrap(text, parsedStyle, offscreenCanvas) : text;
7725
7727
  var lines = outputText.split(/(?:\r\n|\r|\n)/);
7726
7728
  var lineWidths = new Array(lines.length);
@@ -7777,14 +7779,25 @@ exports.TextService = /*#__PURE__*/function () {
7777
7779
  };
7778
7780
  };
7779
7781
 
7780
- _proto.wordWrap = function wordWrap(text, _ref, offscreenCanvas) {
7782
+ _proto.wordWrap = function wordWrap(text, parsedStyle, offscreenCanvas) {
7781
7783
  var _this2 = this;
7782
7784
 
7783
- var _ref$wordWrapWidth = _ref.wordWrapWidth,
7784
- wordWrapWidth = _ref$wordWrapWidth === void 0 ? 0 : _ref$wordWrapWidth,
7785
- letterSpacing = _ref.letterSpacing;
7785
+ var _parsedStyle$wordWrap = parsedStyle.wordWrapWidth,
7786
+ wordWrapWidth = _parsedStyle$wordWrap === void 0 ? 0 : _parsedStyle$wordWrap,
7787
+ letterSpacing = parsedStyle.letterSpacing,
7788
+ _parsedStyle$maxLines = parsedStyle.maxLines,
7789
+ maxLines = _parsedStyle$maxLines === void 0 ? Infinity : _parsedStyle$maxLines,
7790
+ textOverflow = parsedStyle.textOverflow;
7786
7791
  var context = this.offscreenCanvas.getOrCreateContext(offscreenCanvas);
7787
7792
  var maxWidth = wordWrapWidth + letterSpacing;
7793
+ var ellipsis = '';
7794
+
7795
+ if (textOverflow === 'ellipsis') {
7796
+ ellipsis = '...';
7797
+ } else if (textOverflow && textOverflow !== 'clip') {
7798
+ ellipsis = textOverflow;
7799
+ }
7800
+
7788
7801
  var lines = [];
7789
7802
  var currentIndex = 0;
7790
7803
  var currentWidth = 0;
@@ -7794,41 +7807,74 @@ exports.TextService = /*#__PURE__*/function () {
7794
7807
  return _this2.getFromCache(char, letterSpacing, cache, context);
7795
7808
  };
7796
7809
 
7797
- Array.from(text).forEach(function (char, i) {
7810
+ var ellipsisWidth = Array.from(ellipsis).reduce(function (prev, cur) {
7811
+ return prev + calcWidth(cur);
7812
+ }, 0);
7813
+ var chars = Array.from(text);
7814
+
7815
+ for (var i = 0; i < chars.length; i++) {
7816
+ var char = chars[i];
7798
7817
  var prevChar = text[i - 1];
7799
7818
  var nextChar = text[i + 1];
7800
7819
  var width = calcWidth(char);
7801
7820
 
7802
- if (_this2.isNewline(char)) {
7821
+ if (this.isNewline(char)) {
7803
7822
  currentIndex++;
7804
7823
  currentWidth = 0;
7805
7824
  lines[currentIndex] = '';
7806
- return;
7825
+ continue;
7807
7826
  }
7808
7827
 
7809
7828
  if (currentWidth > 0 && currentWidth + width > maxWidth) {
7829
+ if (currentIndex + 1 >= maxLines) {
7830
+ parsedStyle.isOverflowing = true; // If there is not enough space to display the string itself, it is clipped.
7831
+ // @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
7832
+
7833
+ if (ellipsisWidth > 0 && ellipsisWidth <= maxWidth) {
7834
+ // Backspace from line's end.
7835
+ var lastLineWidth = 0;
7836
+ var lastLineIndex = 0;
7837
+
7838
+ for (var _i = 0; _i < lines[currentIndex].length; _i++) {
7839
+ var _width = calcWidth(lines[currentIndex][_i]);
7840
+
7841
+ if (lastLineWidth + _width + ellipsisWidth > maxWidth) {
7842
+ lastLineIndex = _i;
7843
+ break;
7844
+ }
7845
+
7846
+ lastLineWidth += _width;
7847
+ }
7848
+
7849
+ lines[currentIndex] = (lines[currentIndex] || '').slice(0, lastLineIndex) + ellipsis;
7850
+ }
7851
+
7852
+ break;
7853
+ }
7854
+
7810
7855
  currentIndex++;
7811
7856
  currentWidth = 0;
7812
7857
  lines[currentIndex] = '';
7813
7858
 
7814
- if (_this2.isBreakingSpace(char)) {
7815
- return;
7859
+ if (this.isBreakingSpace(char)) {
7860
+ continue;
7816
7861
  }
7817
7862
 
7818
- if (!_this2.canBreakInLastChar(char)) {
7819
- lines = _this2.trimToBreakable(lines);
7820
- currentWidth = _this2.sumTextWidthByCache(lines[currentIndex] || '', cache);
7863
+ if (!this.canBreakInLastChar(char)) {
7864
+ lines = this.trimToBreakable(lines);
7865
+ currentWidth = this.sumTextWidthByCache(lines[currentIndex] || '', cache);
7821
7866
  }
7822
7867
 
7823
- if (_this2.shouldBreakByKinsokuShorui(char, nextChar)) {
7824
- lines = _this2.trimByKinsokuShorui(lines);
7868
+ if (this.shouldBreakByKinsokuShorui(char, nextChar)) {
7869
+ lines = this.trimByKinsokuShorui(lines);
7825
7870
  currentWidth += calcWidth(prevChar || '');
7826
7871
  }
7827
7872
  }
7828
7873
 
7829
7874
  currentWidth += width;
7830
7875
  lines[currentIndex] = (lines[currentIndex] || '') + char;
7831
- });
7876
+ }
7877
+
7832
7878
  return lines.join('\n');
7833
7879
  };
7834
7880
 
@@ -8882,6 +8928,47 @@ var Document = /*#__PURE__*/function (_Node) {
8882
8928
  return b.sortable.renderOrder - a.sortable.renderOrder;
8883
8929
  });
8884
8930
  return hitTestList;
8931
+ };
8932
+
8933
+ _proto.elementFromPointSync = function elementFromPointSync(x, y) {
8934
+ var _this$defaultView$can = this.defaultView.canvas2Viewport({
8935
+ x: x,
8936
+ y: y
8937
+ }),
8938
+ viewportX = _this$defaultView$can.x,
8939
+ viewportY = _this$defaultView$can.y;
8940
+
8941
+ var _this$defaultView$get = this.defaultView.getConfig(),
8942
+ width = _this$defaultView$get.width,
8943
+ height = _this$defaultView$get.height; // outside canvas' viewport
8944
+
8945
+
8946
+ if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
8947
+ return null;
8948
+ }
8949
+
8950
+ var _this$defaultView$vie = this.defaultView.viewport2Client({
8951
+ x: viewportX,
8952
+ y: viewportY
8953
+ }),
8954
+ clientX = _this$defaultView$vie.x,
8955
+ clientY = _this$defaultView$vie.y;
8956
+
8957
+ var _this$defaultView$get2 = this.defaultView.getRenderingService().hooks.pickSync.call({
8958
+ topmost: true,
8959
+ position: {
8960
+ x: x,
8961
+ y: y,
8962
+ viewportX: viewportX,
8963
+ viewportY: viewportY,
8964
+ clientX: clientX,
8965
+ clientY: clientY
8966
+ },
8967
+ picked: []
8968
+ }),
8969
+ picked = _this$defaultView$get2.picked;
8970
+
8971
+ return picked && picked[0] || this.documentElement;
8885
8972
  }
8886
8973
  /**
8887
8974
  * Do picking with API instead of triggering interactive events.
@@ -8894,17 +8981,17 @@ var Document = /*#__PURE__*/function (_Node) {
8894
8981
  /*#__PURE__*/
8895
8982
  function () {
8896
8983
  var _elementFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(x, y) {
8897
- var _this$defaultView$can, viewportX, viewportY, _this$defaultView$get, width, height, _this$defaultView$vie, clientX, clientY, _yield$this$defaultVi, picked;
8984
+ var _this$defaultView$can2, viewportX, viewportY, _this$defaultView$get3, width, height, _this$defaultView$vie2, clientX, clientY, _yield$this$defaultVi, picked;
8898
8985
 
8899
8986
  return _regeneratorRuntime().wrap(function _callee$(_context) {
8900
8987
  while (1) {
8901
8988
  switch (_context.prev = _context.next) {
8902
8989
  case 0:
8903
- _this$defaultView$can = this.defaultView.canvas2Viewport({
8990
+ _this$defaultView$can2 = this.defaultView.canvas2Viewport({
8904
8991
  x: x,
8905
8992
  y: y
8906
- }), viewportX = _this$defaultView$can.x, viewportY = _this$defaultView$can.y;
8907
- _this$defaultView$get = this.defaultView.getConfig(), width = _this$defaultView$get.width, height = _this$defaultView$get.height; // outside canvas' viewport
8993
+ }), viewportX = _this$defaultView$can2.x, viewportY = _this$defaultView$can2.y;
8994
+ _this$defaultView$get3 = this.defaultView.getConfig(), width = _this$defaultView$get3.width, height = _this$defaultView$get3.height; // outside canvas' viewport
8908
8995
 
8909
8996
  if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
8910
8997
  _context.next = 4;
@@ -8914,10 +9001,10 @@ var Document = /*#__PURE__*/function (_Node) {
8914
9001
  return _context.abrupt("return", null);
8915
9002
 
8916
9003
  case 4:
8917
- _this$defaultView$vie = this.defaultView.viewport2Client({
9004
+ _this$defaultView$vie2 = this.defaultView.viewport2Client({
8918
9005
  x: viewportX,
8919
9006
  y: viewportY
8920
- }), clientX = _this$defaultView$vie.x, clientY = _this$defaultView$vie.y;
9007
+ }), clientX = _this$defaultView$vie2.x, clientY = _this$defaultView$vie2.y;
8921
9008
  _context.next = 7;
8922
9009
  return this.defaultView.getRenderingService().hooks.pick.promise({
8923
9010
  topmost: true,
@@ -8950,7 +9037,52 @@ var Document = /*#__PURE__*/function (_Node) {
8950
9037
  }
8951
9038
 
8952
9039
  return elementFromPoint;
8953
- }()
9040
+ }();
9041
+
9042
+ _proto.elementsFromPointSync = function elementsFromPointSync(x, y) {
9043
+ var _this$defaultView$can3 = this.defaultView.canvas2Viewport({
9044
+ x: x,
9045
+ y: y
9046
+ }),
9047
+ viewportX = _this$defaultView$can3.x,
9048
+ viewportY = _this$defaultView$can3.y;
9049
+
9050
+ var _this$defaultView$get4 = this.defaultView.getConfig(),
9051
+ width = _this$defaultView$get4.width,
9052
+ height = _this$defaultView$get4.height; // outside canvas' viewport
9053
+
9054
+
9055
+ if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
9056
+ return [];
9057
+ }
9058
+
9059
+ var _this$defaultView$vie3 = this.defaultView.viewport2Client({
9060
+ x: viewportX,
9061
+ y: viewportY
9062
+ }),
9063
+ clientX = _this$defaultView$vie3.x,
9064
+ clientY = _this$defaultView$vie3.y;
9065
+
9066
+ var _this$defaultView$get5 = this.defaultView.getRenderingService().hooks.pickSync.call({
9067
+ topmost: false,
9068
+ position: {
9069
+ x: x,
9070
+ y: y,
9071
+ viewportX: viewportX,
9072
+ viewportY: viewportY,
9073
+ clientX: clientX,
9074
+ clientY: clientY
9075
+ },
9076
+ picked: []
9077
+ }),
9078
+ picked = _this$defaultView$get5.picked;
9079
+
9080
+ if (picked[picked.length - 1] !== this.documentElement) {
9081
+ picked.push(this.documentElement);
9082
+ }
9083
+
9084
+ return picked;
9085
+ }
8954
9086
  /**
8955
9087
  * Do picking with API instead of triggering interactive events.
8956
9088
  *
@@ -8962,17 +9094,17 @@ var Document = /*#__PURE__*/function (_Node) {
8962
9094
  /*#__PURE__*/
8963
9095
  function () {
8964
9096
  var _elementsFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(x, y) {
8965
- var _this$defaultView$can2, viewportX, viewportY, _this$defaultView$get2, width, height, _this$defaultView$vie2, clientX, clientY, _yield$this$defaultVi2, picked;
9097
+ var _this$defaultView$can4, viewportX, viewportY, _this$defaultView$get6, width, height, _this$defaultView$vie4, clientX, clientY, _yield$this$defaultVi2, picked;
8966
9098
 
8967
9099
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
8968
9100
  while (1) {
8969
9101
  switch (_context2.prev = _context2.next) {
8970
9102
  case 0:
8971
- _this$defaultView$can2 = this.defaultView.canvas2Viewport({
9103
+ _this$defaultView$can4 = this.defaultView.canvas2Viewport({
8972
9104
  x: x,
8973
9105
  y: y
8974
- }), viewportX = _this$defaultView$can2.x, viewportY = _this$defaultView$can2.y;
8975
- _this$defaultView$get2 = this.defaultView.getConfig(), width = _this$defaultView$get2.width, height = _this$defaultView$get2.height; // outside canvas' viewport
9106
+ }), viewportX = _this$defaultView$can4.x, viewportY = _this$defaultView$can4.y;
9107
+ _this$defaultView$get6 = this.defaultView.getConfig(), width = _this$defaultView$get6.width, height = _this$defaultView$get6.height; // outside canvas' viewport
8976
9108
 
8977
9109
  if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
8978
9110
  _context2.next = 4;
@@ -8982,10 +9114,10 @@ var Document = /*#__PURE__*/function (_Node) {
8982
9114
  return _context2.abrupt("return", []);
8983
9115
 
8984
9116
  case 4:
8985
- _this$defaultView$vie2 = this.defaultView.viewport2Client({
9117
+ _this$defaultView$vie4 = this.defaultView.viewport2Client({
8986
9118
  x: viewportX,
8987
9119
  y: viewportY
8988
- }), clientX = _this$defaultView$vie2.x, clientY = _this$defaultView$vie2.y;
9120
+ }), clientX = _this$defaultView$vie4.x, clientY = _this$defaultView$vie4.y;
8989
9121
  _context2.next = 7;
8990
9122
  return this.defaultView.getRenderingService().hooks.pick.promise({
8991
9123
  topmost: false,
@@ -11981,6 +12113,10 @@ var Text = /*#__PURE__*/function (_DisplayObject) {
11981
12113
  return ((_this$parsedStyle$met2 = this.parsedStyle.metrics) === null || _this$parsedStyle$met2 === void 0 ? void 0 : _this$parsedStyle$met2.lineMetrics) || [];
11982
12114
  };
11983
12115
 
12116
+ _proto.isOverflowing = function isOverflowing() {
12117
+ return !!this.parsedStyle.isOverflowing;
12118
+ };
12119
+
11984
12120
  return Text;
11985
12121
  }(DisplayObject);
11986
12122
 
@@ -14086,6 +14222,11 @@ exports.RenderingService = /*#__PURE__*/function () {
14086
14222
  */
14087
14223
  pick: new AsyncSeriesWaterfallHook(['result']),
14088
14224
 
14225
+ /**
14226
+ * Unsafe but sync version of pick.
14227
+ */
14228
+ pickSync: new SyncWaterfallHook(['result']),
14229
+
14089
14230
  /**
14090
14231
  * used in event system
14091
14232
  */
@@ -15096,24 +15237,27 @@ exports.DefaultSceneGraphService = /*#__PURE__*/function () {
15096
15237
  aabb.add(childBounds);
15097
15238
  }
15098
15239
  }
15099
- }); // account for clip path
15240
+ });
15100
15241
 
15101
- var clipped = findClosestClipPathTarget(element);
15242
+ if (render) {
15243
+ // account for clip path
15244
+ var clipped = findClosestClipPathTarget(element);
15102
15245
 
15103
- if (clipped) {
15104
- var clipPathBounds = this.getTransformedGeometryBounds(clipped.style.clipPath, true);
15105
- var transformParentBounds;
15246
+ if (clipped) {
15247
+ var clipPathBounds = this.getTransformedGeometryBounds(clipped.style.clipPath, true);
15248
+ var transformParentBounds;
15106
15249
 
15107
- if (clipPathBounds) {
15108
- transformParentBounds = new AABB(); // intersect with original geometry
15250
+ if (clipPathBounds) {
15251
+ transformParentBounds = new AABB(); // intersect with original geometry
15109
15252
 
15110
- transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(clipped));
15111
- }
15253
+ transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(clipped));
15254
+ }
15112
15255
 
15113
- if (!aabb) {
15114
- aabb = transformParentBounds;
15115
- } else if (transformParentBounds) {
15116
- aabb = transformParentBounds.intersection(aabb);
15256
+ if (!aabb) {
15257
+ aabb = transformParentBounds;
15258
+ } else if (transformParentBounds) {
15259
+ aabb = transformParentBounds.intersection(aabb);
15260
+ }
15117
15261
  }
15118
15262
  }
15119
15263
 
@@ -16666,6 +16810,13 @@ var BUILT_IN_PROPERTIES = [{
16666
16810
  }, {
16667
16811
  n: 'wordWrapWidth',
16668
16812
  l: true
16813
+ }, {
16814
+ n: 'maxLines',
16815
+ l: true
16816
+ }, {
16817
+ n: 'textOverflow',
16818
+ l: true,
16819
+ d: 'clip'
16669
16820
  }, {
16670
16821
  n: 'leading',
16671
16822
  l: true
@@ -18837,6 +18988,7 @@ exports.computeLinearGradient = computeLinearGradient;
18837
18988
  exports.computeRadialGradient = computeRadialGradient;
18838
18989
  exports.convertToPath = convertToPath;
18839
18990
  exports.createVec3 = createVec3;
18991
+ exports.decompose = decompose;
18840
18992
  exports.definedProps = definedProps;
18841
18993
  exports.deg2rad = deg2rad;
18842
18994
  exports.deg2turn = deg2turn;