@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.umd.js CHANGED
@@ -17960,7 +17960,9 @@
17960
17960
  }
17961
17961
 
17962
17962
  var context = this.offscreenCanvas.getOrCreateContext(offscreenCanvas);
17963
- context.font = font;
17963
+ context.font = font; // no overflowing by default
17964
+
17965
+ parsedStyle.isOverflowing = false;
17964
17966
  var outputText = wordWrap ? this.wordWrap(text, parsedStyle, offscreenCanvas) : text;
17965
17967
  var lines = outputText.split(/(?:\r\n|\r|\n)/);
17966
17968
  var lineWidths = new Array(lines.length);
@@ -18017,14 +18019,25 @@
18017
18019
  };
18018
18020
  };
18019
18021
 
18020
- _proto.wordWrap = function wordWrap(text, _ref, offscreenCanvas) {
18022
+ _proto.wordWrap = function wordWrap(text, parsedStyle, offscreenCanvas) {
18021
18023
  var _this2 = this;
18022
18024
 
18023
- var _ref$wordWrapWidth = _ref.wordWrapWidth,
18024
- wordWrapWidth = _ref$wordWrapWidth === void 0 ? 0 : _ref$wordWrapWidth,
18025
- letterSpacing = _ref.letterSpacing;
18025
+ var _parsedStyle$wordWrap = parsedStyle.wordWrapWidth,
18026
+ wordWrapWidth = _parsedStyle$wordWrap === void 0 ? 0 : _parsedStyle$wordWrap,
18027
+ letterSpacing = parsedStyle.letterSpacing,
18028
+ _parsedStyle$maxLines = parsedStyle.maxLines,
18029
+ maxLines = _parsedStyle$maxLines === void 0 ? Infinity : _parsedStyle$maxLines,
18030
+ textOverflow = parsedStyle.textOverflow;
18026
18031
  var context = this.offscreenCanvas.getOrCreateContext(offscreenCanvas);
18027
18032
  var maxWidth = wordWrapWidth + letterSpacing;
18033
+ var ellipsis = '';
18034
+
18035
+ if (textOverflow === 'ellipsis') {
18036
+ ellipsis = '...';
18037
+ } else if (textOverflow && textOverflow !== 'clip') {
18038
+ ellipsis = textOverflow;
18039
+ }
18040
+
18028
18041
  var lines = [];
18029
18042
  var currentIndex = 0;
18030
18043
  var currentWidth = 0;
@@ -18034,41 +18047,74 @@
18034
18047
  return _this2.getFromCache(char, letterSpacing, cache, context);
18035
18048
  };
18036
18049
 
18037
- Array.from(text).forEach(function (char, i) {
18050
+ var ellipsisWidth = Array.from(ellipsis).reduce(function (prev, cur) {
18051
+ return prev + calcWidth(cur);
18052
+ }, 0);
18053
+ var chars = Array.from(text);
18054
+
18055
+ for (var i = 0; i < chars.length; i++) {
18056
+ var char = chars[i];
18038
18057
  var prevChar = text[i - 1];
18039
18058
  var nextChar = text[i + 1];
18040
18059
  var width = calcWidth(char);
18041
18060
 
18042
- if (_this2.isNewline(char)) {
18061
+ if (this.isNewline(char)) {
18043
18062
  currentIndex++;
18044
18063
  currentWidth = 0;
18045
18064
  lines[currentIndex] = '';
18046
- return;
18065
+ continue;
18047
18066
  }
18048
18067
 
18049
18068
  if (currentWidth > 0 && currentWidth + width > maxWidth) {
18069
+ if (currentIndex + 1 >= maxLines) {
18070
+ parsedStyle.isOverflowing = true; // If there is not enough space to display the string itself, it is clipped.
18071
+ // @see https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow#values
18072
+
18073
+ if (ellipsisWidth > 0 && ellipsisWidth <= maxWidth) {
18074
+ // Backspace from line's end.
18075
+ var lastLineWidth = 0;
18076
+ var lastLineIndex = 0;
18077
+
18078
+ for (var _i = 0; _i < lines[currentIndex].length; _i++) {
18079
+ var _width = calcWidth(lines[currentIndex][_i]);
18080
+
18081
+ if (lastLineWidth + _width + ellipsisWidth > maxWidth) {
18082
+ lastLineIndex = _i;
18083
+ break;
18084
+ }
18085
+
18086
+ lastLineWidth += _width;
18087
+ }
18088
+
18089
+ lines[currentIndex] = (lines[currentIndex] || '').slice(0, lastLineIndex) + ellipsis;
18090
+ }
18091
+
18092
+ break;
18093
+ }
18094
+
18050
18095
  currentIndex++;
18051
18096
  currentWidth = 0;
18052
18097
  lines[currentIndex] = '';
18053
18098
 
18054
- if (_this2.isBreakingSpace(char)) {
18055
- return;
18099
+ if (this.isBreakingSpace(char)) {
18100
+ continue;
18056
18101
  }
18057
18102
 
18058
- if (!_this2.canBreakInLastChar(char)) {
18059
- lines = _this2.trimToBreakable(lines);
18060
- currentWidth = _this2.sumTextWidthByCache(lines[currentIndex] || '', cache);
18103
+ if (!this.canBreakInLastChar(char)) {
18104
+ lines = this.trimToBreakable(lines);
18105
+ currentWidth = this.sumTextWidthByCache(lines[currentIndex] || '', cache);
18061
18106
  }
18062
18107
 
18063
- if (_this2.shouldBreakByKinsokuShorui(char, nextChar)) {
18064
- lines = _this2.trimByKinsokuShorui(lines);
18108
+ if (this.shouldBreakByKinsokuShorui(char, nextChar)) {
18109
+ lines = this.trimByKinsokuShorui(lines);
18065
18110
  currentWidth += calcWidth(prevChar || '');
18066
18111
  }
18067
18112
  }
18068
18113
 
18069
18114
  currentWidth += width;
18070
18115
  lines[currentIndex] = (lines[currentIndex] || '') + char;
18071
- });
18116
+ }
18117
+
18072
18118
  return lines.join('\n');
18073
18119
  };
18074
18120
 
@@ -19460,6 +19506,47 @@
19460
19506
  return b.sortable.renderOrder - a.sortable.renderOrder;
19461
19507
  });
19462
19508
  return hitTestList;
19509
+ };
19510
+
19511
+ _proto.elementFromPointSync = function elementFromPointSync(x, y) {
19512
+ var _this$defaultView$can = this.defaultView.canvas2Viewport({
19513
+ x: x,
19514
+ y: y
19515
+ }),
19516
+ viewportX = _this$defaultView$can.x,
19517
+ viewportY = _this$defaultView$can.y;
19518
+
19519
+ var _this$defaultView$get = this.defaultView.getConfig(),
19520
+ width = _this$defaultView$get.width,
19521
+ height = _this$defaultView$get.height; // outside canvas' viewport
19522
+
19523
+
19524
+ if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
19525
+ return null;
19526
+ }
19527
+
19528
+ var _this$defaultView$vie = this.defaultView.viewport2Client({
19529
+ x: viewportX,
19530
+ y: viewportY
19531
+ }),
19532
+ clientX = _this$defaultView$vie.x,
19533
+ clientY = _this$defaultView$vie.y;
19534
+
19535
+ var _this$defaultView$get2 = this.defaultView.getRenderingService().hooks.pickSync.call({
19536
+ topmost: true,
19537
+ position: {
19538
+ x: x,
19539
+ y: y,
19540
+ viewportX: viewportX,
19541
+ viewportY: viewportY,
19542
+ clientX: clientX,
19543
+ clientY: clientY
19544
+ },
19545
+ picked: []
19546
+ }),
19547
+ picked = _this$defaultView$get2.picked;
19548
+
19549
+ return picked && picked[0] || this.documentElement;
19463
19550
  }
19464
19551
  /**
19465
19552
  * Do picking with API instead of triggering interactive events.
@@ -19472,17 +19559,17 @@
19472
19559
  /*#__PURE__*/
19473
19560
  function () {
19474
19561
  var _elementFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(x, y) {
19475
- var _this$defaultView$can, viewportX, viewportY, _this$defaultView$get, width, height, _this$defaultView$vie, clientX, clientY, _yield$this$defaultVi, picked;
19562
+ var _this$defaultView$can2, viewportX, viewportY, _this$defaultView$get3, width, height, _this$defaultView$vie2, clientX, clientY, _yield$this$defaultVi, picked;
19476
19563
 
19477
19564
  return _regeneratorRuntime().wrap(function _callee$(_context) {
19478
19565
  while (1) {
19479
19566
  switch (_context.prev = _context.next) {
19480
19567
  case 0:
19481
- _this$defaultView$can = this.defaultView.canvas2Viewport({
19568
+ _this$defaultView$can2 = this.defaultView.canvas2Viewport({
19482
19569
  x: x,
19483
19570
  y: y
19484
- }), viewportX = _this$defaultView$can.x, viewportY = _this$defaultView$can.y;
19485
- _this$defaultView$get = this.defaultView.getConfig(), width = _this$defaultView$get.width, height = _this$defaultView$get.height; // outside canvas' viewport
19571
+ }), viewportX = _this$defaultView$can2.x, viewportY = _this$defaultView$can2.y;
19572
+ _this$defaultView$get3 = this.defaultView.getConfig(), width = _this$defaultView$get3.width, height = _this$defaultView$get3.height; // outside canvas' viewport
19486
19573
 
19487
19574
  if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
19488
19575
  _context.next = 4;
@@ -19492,10 +19579,10 @@
19492
19579
  return _context.abrupt("return", null);
19493
19580
 
19494
19581
  case 4:
19495
- _this$defaultView$vie = this.defaultView.viewport2Client({
19582
+ _this$defaultView$vie2 = this.defaultView.viewport2Client({
19496
19583
  x: viewportX,
19497
19584
  y: viewportY
19498
- }), clientX = _this$defaultView$vie.x, clientY = _this$defaultView$vie.y;
19585
+ }), clientX = _this$defaultView$vie2.x, clientY = _this$defaultView$vie2.y;
19499
19586
  _context.next = 7;
19500
19587
  return this.defaultView.getRenderingService().hooks.pick.promise({
19501
19588
  topmost: true,
@@ -19528,7 +19615,52 @@
19528
19615
  }
19529
19616
 
19530
19617
  return elementFromPoint;
19531
- }()
19618
+ }();
19619
+
19620
+ _proto.elementsFromPointSync = function elementsFromPointSync(x, y) {
19621
+ var _this$defaultView$can3 = this.defaultView.canvas2Viewport({
19622
+ x: x,
19623
+ y: y
19624
+ }),
19625
+ viewportX = _this$defaultView$can3.x,
19626
+ viewportY = _this$defaultView$can3.y;
19627
+
19628
+ var _this$defaultView$get4 = this.defaultView.getConfig(),
19629
+ width = _this$defaultView$get4.width,
19630
+ height = _this$defaultView$get4.height; // outside canvas' viewport
19631
+
19632
+
19633
+ if (viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height) {
19634
+ return [];
19635
+ }
19636
+
19637
+ var _this$defaultView$vie3 = this.defaultView.viewport2Client({
19638
+ x: viewportX,
19639
+ y: viewportY
19640
+ }),
19641
+ clientX = _this$defaultView$vie3.x,
19642
+ clientY = _this$defaultView$vie3.y;
19643
+
19644
+ var _this$defaultView$get5 = this.defaultView.getRenderingService().hooks.pickSync.call({
19645
+ topmost: false,
19646
+ position: {
19647
+ x: x,
19648
+ y: y,
19649
+ viewportX: viewportX,
19650
+ viewportY: viewportY,
19651
+ clientX: clientX,
19652
+ clientY: clientY
19653
+ },
19654
+ picked: []
19655
+ }),
19656
+ picked = _this$defaultView$get5.picked;
19657
+
19658
+ if (picked[picked.length - 1] !== this.documentElement) {
19659
+ picked.push(this.documentElement);
19660
+ }
19661
+
19662
+ return picked;
19663
+ }
19532
19664
  /**
19533
19665
  * Do picking with API instead of triggering interactive events.
19534
19666
  *
@@ -19540,17 +19672,17 @@
19540
19672
  /*#__PURE__*/
19541
19673
  function () {
19542
19674
  var _elementsFromPoint = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(x, y) {
19543
- var _this$defaultView$can2, viewportX, viewportY, _this$defaultView$get2, width, height, _this$defaultView$vie2, clientX, clientY, _yield$this$defaultVi2, picked;
19675
+ var _this$defaultView$can4, viewportX, viewportY, _this$defaultView$get6, width, height, _this$defaultView$vie4, clientX, clientY, _yield$this$defaultVi2, picked;
19544
19676
 
19545
19677
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
19546
19678
  while (1) {
19547
19679
  switch (_context2.prev = _context2.next) {
19548
19680
  case 0:
19549
- _this$defaultView$can2 = this.defaultView.canvas2Viewport({
19681
+ _this$defaultView$can4 = this.defaultView.canvas2Viewport({
19550
19682
  x: x,
19551
19683
  y: y
19552
- }), viewportX = _this$defaultView$can2.x, viewportY = _this$defaultView$can2.y;
19553
- _this$defaultView$get2 = this.defaultView.getConfig(), width = _this$defaultView$get2.width, height = _this$defaultView$get2.height; // outside canvas' viewport
19684
+ }), viewportX = _this$defaultView$can4.x, viewportY = _this$defaultView$can4.y;
19685
+ _this$defaultView$get6 = this.defaultView.getConfig(), width = _this$defaultView$get6.width, height = _this$defaultView$get6.height; // outside canvas' viewport
19554
19686
 
19555
19687
  if (!(viewportX < 0 || viewportY < 0 || viewportX > width || viewportY > height)) {
19556
19688
  _context2.next = 4;
@@ -19560,10 +19692,10 @@
19560
19692
  return _context2.abrupt("return", []);
19561
19693
 
19562
19694
  case 4:
19563
- _this$defaultView$vie2 = this.defaultView.viewport2Client({
19695
+ _this$defaultView$vie4 = this.defaultView.viewport2Client({
19564
19696
  x: viewportX,
19565
19697
  y: viewportY
19566
- }), clientX = _this$defaultView$vie2.x, clientY = _this$defaultView$vie2.y;
19698
+ }), clientX = _this$defaultView$vie4.x, clientY = _this$defaultView$vie4.y;
19567
19699
  _context2.next = 7;
19568
19700
  return this.defaultView.getRenderingService().hooks.pick.promise({
19569
19701
  topmost: false,
@@ -22559,6 +22691,10 @@
22559
22691
  return ((_this$parsedStyle$met2 = this.parsedStyle.metrics) === null || _this$parsedStyle$met2 === void 0 ? void 0 : _this$parsedStyle$met2.lineMetrics) || [];
22560
22692
  };
22561
22693
 
22694
+ _proto.isOverflowing = function isOverflowing() {
22695
+ return !!this.parsedStyle.isOverflowing;
22696
+ };
22697
+
22562
22698
  return Text;
22563
22699
  }(DisplayObject);
22564
22700
 
@@ -24664,6 +24800,11 @@
24664
24800
  */
24665
24801
  pick: new AsyncSeriesWaterfallHook(['result']),
24666
24802
 
24803
+ /**
24804
+ * Unsafe but sync version of pick.
24805
+ */
24806
+ pickSync: new SyncWaterfallHook(['result']),
24807
+
24667
24808
  /**
24668
24809
  * used in event system
24669
24810
  */
@@ -25674,24 +25815,27 @@
25674
25815
  aabb.add(childBounds);
25675
25816
  }
25676
25817
  }
25677
- }); // account for clip path
25818
+ });
25678
25819
 
25679
- var clipped = findClosestClipPathTarget(element);
25820
+ if (render) {
25821
+ // account for clip path
25822
+ var clipped = findClosestClipPathTarget(element);
25680
25823
 
25681
- if (clipped) {
25682
- var clipPathBounds = this.getTransformedGeometryBounds(clipped.style.clipPath, true);
25683
- var transformParentBounds;
25824
+ if (clipped) {
25825
+ var clipPathBounds = this.getTransformedGeometryBounds(clipped.style.clipPath, true);
25826
+ var transformParentBounds;
25684
25827
 
25685
- if (clipPathBounds) {
25686
- transformParentBounds = new AABB(); // intersect with original geometry
25828
+ if (clipPathBounds) {
25829
+ transformParentBounds = new AABB(); // intersect with original geometry
25687
25830
 
25688
- transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(clipped));
25689
- }
25831
+ transformParentBounds.setFromTransformedAABB(clipPathBounds, this.getWorldTransform(clipped));
25832
+ }
25690
25833
 
25691
- if (!aabb) {
25692
- aabb = transformParentBounds;
25693
- } else if (transformParentBounds) {
25694
- aabb = transformParentBounds.intersection(aabb);
25834
+ if (!aabb) {
25835
+ aabb = transformParentBounds;
25836
+ } else if (transformParentBounds) {
25837
+ aabb = transformParentBounds.intersection(aabb);
25838
+ }
25695
25839
  }
25696
25840
  }
25697
25841
 
@@ -27244,6 +27388,13 @@
27244
27388
  }, {
27245
27389
  n: 'wordWrapWidth',
27246
27390
  l: true
27391
+ }, {
27392
+ n: 'maxLines',
27393
+ l: true
27394
+ }, {
27395
+ n: 'textOverflow',
27396
+ l: true,
27397
+ d: 'clip'
27247
27398
  }, {
27248
27399
  n: 'leading',
27249
27400
  l: true
@@ -29378,6 +29529,7 @@
29378
29529
  exports.computeRadialGradient = computeRadialGradient;
29379
29530
  exports.convertToPath = convertToPath;
29380
29531
  exports.createVec3 = createVec3;
29532
+ exports.decompose = decompose;
29381
29533
  exports.definedProps = definedProps;
29382
29534
  exports.deg2rad = deg2rad;
29383
29535
  exports.deg2turn = deg2turn;