@visactor/vrender 0.11.0-alpha.2 → 0.11.0

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.
Files changed (42) hide show
  1. package/cjs/common/segment/index.d.ts +1 -0
  2. package/cjs/common/segment/index.js +2 -1
  3. package/cjs/common/segment/index.js.map +1 -1
  4. package/cjs/common/text.d.ts +1 -1
  5. package/cjs/common/text.js +3 -2
  6. package/cjs/common/text.js.map +1 -1
  7. package/cjs/core/contributions/textMeasure/layout.js +2 -1
  8. package/cjs/core/contributions/textMeasure/layout.js.map +1 -1
  9. package/cjs/graphic/config.js +1 -1
  10. package/cjs/graphic/config.js.map +1 -1
  11. package/cjs/graphic/text.js +2 -2
  12. package/cjs/graphic/text.js.map +1 -1
  13. package/cjs/index.d.ts +1 -1
  14. package/cjs/index.js +18 -18
  15. package/cjs/index.js.map +1 -1
  16. package/cjs/picker/contributions/canvas-picker/text-picker.js +2 -2
  17. package/cjs/picker/contributions/canvas-picker/text-picker.js.map +1 -1
  18. package/cjs/render/contributions/render/text-render.js +8 -5
  19. package/cjs/render/contributions/render/text-render.js.map +1 -1
  20. package/dist/index.js +86 -17
  21. package/dist/index.min.js +1 -1
  22. package/es/common/segment/index.d.ts +1 -0
  23. package/es/common/segment/index.js +2 -0
  24. package/es/common/segment/index.js.map +1 -1
  25. package/es/common/text.d.ts +1 -1
  26. package/es/common/text.js +3 -2
  27. package/es/common/text.js.map +1 -1
  28. package/es/core/contributions/textMeasure/layout.js +2 -1
  29. package/es/core/contributions/textMeasure/layout.js.map +1 -1
  30. package/es/graphic/config.js +1 -1
  31. package/es/graphic/config.js.map +1 -1
  32. package/es/graphic/text.js +2 -2
  33. package/es/graphic/text.js.map +1 -1
  34. package/es/index.d.ts +1 -1
  35. package/es/index.js +1 -1
  36. package/es/index.js.map +1 -1
  37. package/es/picker/contributions/canvas-picker/text-picker.js +1 -1
  38. package/es/picker/contributions/canvas-picker/text-picker.js.map +1 -1
  39. package/es/render/contributions/render/text-render.js +8 -5
  40. package/es/render/contributions/render/text-render.js.map +1 -1
  41. package/es/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -6938,6 +6938,59 @@
6938
6938
  return genCurveSegments(path, points, 1);
6939
6939
  }
6940
6940
 
6941
+ class CurveContext {
6942
+ _lastX;
6943
+ _lastY;
6944
+ _startX;
6945
+ _startY;
6946
+ constructor(path) {
6947
+ this.path = path;
6948
+ this._lastX = this._lastY = this._startX = this._startY = 0;
6949
+ }
6950
+ moveTo(x, y) {
6951
+ this._lastX = this._startX = x;
6952
+ this._lastY = this._startY = y;
6953
+ return this;
6954
+ }
6955
+ lineTo(x, y) {
6956
+ const curve = this.addLinearCurve(x, y);
6957
+ this.path.curves.push(curve);
6958
+ this._lastX = x;
6959
+ this._lastY = y;
6960
+ }
6961
+ addLinearCurve(x, y) {
6962
+ const curve = new LineCurve(new Point(this._lastX, this._lastY), new Point(x, y));
6963
+ return curve;
6964
+ }
6965
+ quadraticCurveTo(aCPx, aCPy, aX, aY) {
6966
+ throw new Error('CurveContext不支持调用quadraticCurveTo');
6967
+ }
6968
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
6969
+ const curve = new CubicBezierCurve(new Point(this._lastX, this._lastY), new Point(cp1x, cp1y), new Point(cp2x, cp2y), new Point(x, y));
6970
+ this.path.curves.push(curve);
6971
+ this._lastX = x;
6972
+ this._lastY = y;
6973
+ }
6974
+ arcTo(aX1, aY1, aX2, aY2, aRadius) {
6975
+ throw new Error('CurveContext不支持调用arcTo');
6976
+ }
6977
+ ellipse(aX, aY, xRadius, yRadius, aRotation, aStartAngle, aEndAngle, aClockwise) {
6978
+ throw new Error('CurveContext不支持调用ellipse');
6979
+ }
6980
+ rect(x, y, w, h) {
6981
+ throw new Error('CurveContext不支持调用rect');
6982
+ }
6983
+ arc(x, y, radius, startAngle, endAngle, counterclockwise) {
6984
+ throw new Error('CurveContext不支持调用arc');
6985
+ }
6986
+ closePath() {
6987
+ if (this.path.curves.length < 2) {
6988
+ return;
6989
+ }
6990
+ this.lineTo(this._startX, this._startY);
6991
+ }
6992
+ }
6993
+
6941
6994
  function calcLineCache$1(points, curveType, params) {
6942
6995
  switch (curveType) {
6943
6996
  case 'linear':
@@ -7500,7 +7553,7 @@
7500
7553
  ellipsis: '…',
7501
7554
  fontVariant: '',
7502
7555
  fontStyle: '',
7503
- lineHeight: 16,
7556
+ lineHeight: undefined,
7504
7557
  underline: 0,
7505
7558
  lineThrough: 0
7506
7559
  };
@@ -17336,18 +17389,21 @@
17336
17389
  }
17337
17390
  return 0;
17338
17391
  }
17339
- function textLayoutOffsetY(baseline, h) {
17392
+ function textLayoutOffsetY(baseline, lineHeight, fontSize) {
17340
17393
  if (baseline === 'middle') {
17341
- return -h / 2;
17394
+ return -lineHeight / 2;
17342
17395
  }
17343
17396
  if (baseline === 'top') {
17344
17397
  return 0;
17345
17398
  }
17346
17399
  if (baseline === 'bottom') {
17347
- return -h;
17400
+ return -lineHeight;
17348
17401
  }
17349
17402
  if (!baseline || baseline === 'alphabetic') {
17350
- return -0.79 * h;
17403
+ if (!fontSize) {
17404
+ fontSize = lineHeight;
17405
+ }
17406
+ return -(lineHeight - fontSize) / 2 - 0.79 * fontSize;
17351
17407
  }
17352
17408
  return 0;
17353
17409
  }
@@ -17493,7 +17549,7 @@
17493
17549
  else if (textAlign === 'right' || textAlign === 'end') {
17494
17550
  line.leftOffset = bbox.width - line.width;
17495
17551
  }
17496
- line.topOffset = lineHeight * 0.79 + origin[1];
17552
+ line.topOffset = (lineHeight - this.textOptions.fontSize) / 2 + this.textOptions.fontSize * 0.79 + origin[1];
17497
17553
  origin[1] += lineHeight;
17498
17554
  return line;
17499
17555
  }
@@ -17596,7 +17652,7 @@
17596
17652
  if (!this.shouldUpdateShape() && this.cache) {
17597
17653
  width = this.cache.clipedWidth;
17598
17654
  const dx = textDrawOffsetX(textAlign, width);
17599
- const dy = textLayoutOffsetY(textBaseline, lineHeight);
17655
+ const dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
17600
17656
  this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight);
17601
17657
  if (stroke) {
17602
17658
  this._AABBBounds.expand(lineWidth / 2);
@@ -17625,7 +17681,7 @@
17625
17681
  }
17626
17682
  this.clearUpdateShapeTag();
17627
17683
  const dx = textDrawOffsetX(textAlign, width);
17628
- const dy = textLayoutOffsetY(textBaseline, lineHeight);
17684
+ const dy = textLayoutOffsetY(textBaseline, lineHeight, fontSize);
17629
17685
  this._AABBBounds.set(dx, dy, dx + width, dy + lineHeight);
17630
17686
  if (stroke) {
17631
17687
  this._AABBBounds.expand(lineWidth / 2);
@@ -24311,7 +24367,8 @@
24311
24367
  z;
24312
24368
  drawShape(text, context, x, y, drawContext, params, fillCb, strokeCb) {
24313
24369
  const textAttribute = getTheme(text, params?.theme).text;
24314
- const { text: str, fill = textAttribute.fill, stroke = textAttribute.stroke, fillOpacity = textAttribute.fillOpacity, strokeOpacity = textAttribute.strokeOpacity, opacity = textAttribute.opacity, lineWidth = textAttribute.lineWidth, visible = textAttribute.visible, underline = textAttribute.underline, lineThrough = textAttribute.lineThrough, keepDirIn3d = textAttribute.keepDirIn3d, x: originX = textAttribute.x, y: originY = textAttribute.y } = text.attribute;
24370
+ const { text: str, fill = textAttribute.fill, stroke = textAttribute.stroke, fillOpacity = textAttribute.fillOpacity, strokeOpacity = textAttribute.strokeOpacity, opacity = textAttribute.opacity, lineWidth = textAttribute.lineWidth, visible = textAttribute.visible, underline = textAttribute.underline, lineThrough = textAttribute.lineThrough, keepDirIn3d = textAttribute.keepDirIn3d, fontSize = textAttribute.fontSize, textBaseline = textAttribute.textBaseline, x: originX = textAttribute.x, y: originY = textAttribute.y } = text.attribute;
24371
+ const lineHeight = text.attribute.lineHeight ?? fontSize;
24315
24372
  const fVisible = fillVisible(opacity, fillOpacity);
24316
24373
  const sVisible = strokeVisible(opacity, strokeOpacity);
24317
24374
  const doFill = runFill(fill);
@@ -24362,13 +24419,24 @@
24362
24419
  else {
24363
24420
  context.setTextStyle(text.attribute, textAttribute, z);
24364
24421
  const t = text.clipedText;
24422
+ let dy = 0;
24423
+ if (lineHeight !== fontSize) {
24424
+ if (textBaseline === 'top') {
24425
+ dy = (lineHeight - fontSize) / 2;
24426
+ }
24427
+ else if (textBaseline === 'middle') ;
24428
+ else if (textBaseline === 'bottom') {
24429
+ dy = -(lineHeight - fontSize) / 2;
24430
+ }
24431
+ else ;
24432
+ }
24365
24433
  if (doStroke) {
24366
24434
  if (strokeCb) {
24367
24435
  strokeCb(context, text.attribute, textAttribute);
24368
24436
  }
24369
24437
  else if (sVisible) {
24370
24438
  context.setStrokeStyle(text, text.attribute, originX - x, originY - y, textAttribute);
24371
- context.strokeText(t, x, y, z);
24439
+ context.strokeText(t, x, y + dy, z);
24372
24440
  }
24373
24441
  }
24374
24442
  if (doFill) {
@@ -24377,8 +24445,8 @@
24377
24445
  }
24378
24446
  else if (fVisible) {
24379
24447
  context.setCommonStyle(text, text.attribute, originX - x, originY - y, textAttribute);
24380
- context.fillText(t, x, y, z);
24381
- this.drawUnderLine(underline, lineThrough, text, x, y, z, textAttribute, context);
24448
+ context.fillText(t, x, y + dy, z);
24449
+ this.drawUnderLine(underline, lineThrough, text, x, y + dy, z, textAttribute, context);
24382
24450
  }
24383
24451
  }
24384
24452
  }
@@ -24408,7 +24476,7 @@
24408
24476
  const { textAlign = textAttribute.textAlign, textBaseline = textAttribute.textBaseline, fontSize = textAttribute.fontSize, fill = textAttribute.fill, opacity = textAttribute.opacity, fillOpacity = textAttribute.fillOpacity } = text.attribute;
24409
24477
  const w = text.clipedWidth;
24410
24478
  const offsetX = textDrawOffsetX(textAlign, w);
24411
- const offsetY = textLayoutOffsetY(textBaseline, fontSize);
24479
+ const offsetY = textLayoutOffsetY(textBaseline, fontSize, fontSize);
24412
24480
  const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };
24413
24481
  if (underline) {
24414
24482
  attribute.lineWidth = underline;
@@ -24435,7 +24503,7 @@
24435
24503
  }
24436
24504
  const { textAlign = textAttribute.textAlign, fontSize = textAttribute.fontSize, fill = textAttribute.fill, opacity = textAttribute.opacity, fillOpacity = textAttribute.fillOpacity } = text.attribute;
24437
24505
  const offsetX = textDrawOffsetX(textAlign, w);
24438
- const offsetY = textLayoutOffsetY('alphabetic', fontSize);
24506
+ const offsetY = textLayoutOffsetY('alphabetic', fontSize, fontSize);
24439
24507
  const attribute = { lineWidth: 0, stroke: fill, opacity, strokeOpacity: fillOpacity };
24440
24508
  let deltaY = -3;
24441
24509
  if (underline) {
@@ -31744,11 +31812,11 @@
31744
31812
  if (picked) {
31745
31813
  return true;
31746
31814
  }
31747
- const { textBaseline = textAttribute.textBaseline, textAlign = textAttribute.textAlign } = text.attribute;
31815
+ const { fontSize = textAttribute.fontSize, textBaseline = textAttribute.textBaseline, textAlign = textAttribute.textAlign } = text.attribute;
31748
31816
  const bounds = text.AABBBounds;
31749
31817
  const height = bounds.height();
31750
31818
  const width = bounds.width();
31751
- const offsetY = textLayoutOffsetY(textBaseline, height);
31819
+ const offsetY = textLayoutOffsetY(textBaseline, height, fontSize);
31752
31820
  const offsetX = textDrawOffsetX(textAlign, width);
31753
31821
  context.rect(offsetX + x, offsetY + y, width, height, z);
31754
31822
  picked = context.isPointInPath(pickPoint.x, pickPoint.y);
@@ -33566,7 +33634,7 @@
33566
33634
  return new Stage(params);
33567
33635
  }
33568
33636
 
33569
- const version = "0.11.0-alpha.2";
33637
+ const version = "0.11.0";
33570
33638
 
33571
33639
  exports.ACustomAnimate = ACustomAnimate;
33572
33640
  exports.ARC3D_NUMBER_TYPE = ARC3D_NUMBER_TYPE;
@@ -33601,6 +33669,7 @@
33601
33669
  exports.ColorInterpolate = ColorInterpolate;
33602
33670
  exports.Context2dFactory = Context2dFactory;
33603
33671
  exports.ContributionProvider = ContributionProvider;
33672
+ exports.CurveContext = CurveContext;
33604
33673
  exports.CustomEvent = CustomEvent;
33605
33674
  exports.CustomPath2D = CustomPath2D;
33606
33675
  exports.CustomSymbolClass = CustomSymbolClass;