@antv/g-lite 1.0.8 → 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/camera/Camera.d.ts +4 -0
- package/dist/camera/Camera.d.ts.map +1 -1
- package/dist/camera/interfaces.d.ts +1 -0
- package/dist/camera/interfaces.d.ts.map +1 -1
- package/dist/css/StyleValueRegistry.d.ts.map +1 -1
- package/dist/css/interfaces.d.ts +1 -0
- package/dist/css/interfaces.d.ts.map +1 -1
- package/dist/css/properties/CSSPropertyClipPath.d.ts.map +1 -1
- package/dist/display-objects/DisplayObject.d.ts.map +1 -1
- package/dist/display-objects/Text.d.ts +35 -2
- package/dist/display-objects/Text.d.ts.map +1 -1
- package/dist/index.esm.js +168 -72
- package/dist/index.js +168 -72
- package/dist/index.umd.js +169 -73
- package/dist/index.umd.min.js +2 -2
- package/dist/services/TextService.d.ts +11 -1
- package/dist/services/TextService.d.ts.map +1 -1
- package/dist/services/aabb/TextUpdater.d.ts.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
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.
|
|
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.
|
|
7687
|
-
return this.
|
|
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.
|
|
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
|
-
|
|
7789
|
-
var
|
|
7802
|
+
if (textPath) {
|
|
7803
|
+
var totalPathLength = textPath.getTotalLength(); // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
7790
7804
|
|
|
7791
|
-
|
|
7792
|
-
maxLineWidth = Math.max(maxLineWidth, _lineWidth);
|
|
7793
|
-
}
|
|
7805
|
+
var startingPoint = textPath.getPoint(0);
|
|
7794
7806
|
|
|
7795
|
-
|
|
7796
|
-
|
|
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
|
-
|
|
7800
|
-
|
|
7801
|
-
|
|
7802
|
-
// }
|
|
7834
|
+
lineWidths[_i] = _lineWidth;
|
|
7835
|
+
maxLineWidth = Math.max(maxLineWidth, _lineWidth);
|
|
7836
|
+
}
|
|
7803
7837
|
|
|
7804
|
-
|
|
7838
|
+
var _width = maxLineWidth + lineWidth; // if (dropShadow) {
|
|
7839
|
+
// width += dropShadowDistance;
|
|
7840
|
+
// }
|
|
7805
7841
|
|
|
7806
|
-
var offsetY = 0;
|
|
7807
7842
|
|
|
7808
|
-
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
7896
|
-
var
|
|
7942
|
+
for (var _i2 = 0; _i2 < lines[currentIndex].length; _i2++) {
|
|
7943
|
+
var _width2 = calcWidth(lines[currentIndex][_i2]);
|
|
7897
7944
|
|
|
7898
|
-
if (lastLineWidth +
|
|
7899
|
-
lastLineIndex =
|
|
7945
|
+
if (lastLineWidth + _width2 + ellipsisWidth > maxWidth) {
|
|
7946
|
+
lastLineIndex = _i2;
|
|
7900
7947
|
break;
|
|
7901
7948
|
}
|
|
7902
7949
|
|
|
7903
|
-
lastLineWidth +=
|
|
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
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
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
|
-
|
|
10652
|
+
_this2.parsedStyle[pathTargetsName].forEach(function (target) {
|
|
10653
|
+
_this2.sceneGraphService.dirtifyToRoot(target);
|
|
10607
10654
|
|
|
10608
|
-
|
|
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 }]);
|
|
@@ -13757,6 +13806,33 @@ exports.Camera = /*#__PURE__*/function () {
|
|
|
13757
13806
|
this.setPerspective(this.near, this.far, this.fov, this.aspect);
|
|
13758
13807
|
}
|
|
13759
13808
|
|
|
13809
|
+
return this;
|
|
13810
|
+
}
|
|
13811
|
+
/**
|
|
13812
|
+
* Zoom by specified point in viewport coordinates.
|
|
13813
|
+
*/
|
|
13814
|
+
;
|
|
13815
|
+
|
|
13816
|
+
_proto.setZoomByViewportPoint = function setZoomByViewportPoint(zoom, viewportPoint) {
|
|
13817
|
+
var _this$canvas$viewport = this.canvas.viewport2Canvas({
|
|
13818
|
+
x: viewportPoint[0],
|
|
13819
|
+
y: viewportPoint[1]
|
|
13820
|
+
}),
|
|
13821
|
+
ox = _this$canvas$viewport.x,
|
|
13822
|
+
oy = _this$canvas$viewport.y;
|
|
13823
|
+
|
|
13824
|
+
this.setPosition(ox, oy);
|
|
13825
|
+
this.setFocalPoint(ox, oy);
|
|
13826
|
+
this.setZoom(zoom);
|
|
13827
|
+
|
|
13828
|
+
var _this$canvas$viewport2 = this.canvas.viewport2Canvas({
|
|
13829
|
+
x: viewportPoint[0],
|
|
13830
|
+
y: viewportPoint[1]
|
|
13831
|
+
}),
|
|
13832
|
+
cx = _this$canvas$viewport2.x,
|
|
13833
|
+
cy = _this$canvas$viewport2.y;
|
|
13834
|
+
|
|
13835
|
+
this.pan(ox - cx, oy - cy);
|
|
13760
13836
|
return this;
|
|
13761
13837
|
};
|
|
13762
13838
|
|
|
@@ -15514,20 +15590,21 @@ var CSSPropertyClipPath = /*#__PURE__*/function () {
|
|
|
15514
15590
|
// unset
|
|
15515
15591
|
if (newClipPath instanceof CSSKeywordValue) {
|
|
15516
15592
|
newClipPath = null;
|
|
15517
|
-
}
|
|
15593
|
+
}
|
|
15518
15594
|
|
|
15595
|
+
var pathTargetsName = name === 'clipPath' ? 'clipPathTargets' : 'textPathTargets'; // clear ref to old clip path
|
|
15519
15596
|
|
|
15520
|
-
if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle
|
|
15521
|
-
var index = oldClipPath.parsedStyle.
|
|
15522
|
-
oldClipPath.parsedStyle.
|
|
15597
|
+
if (oldClipPath && oldClipPath !== newClipPath && oldClipPath.parsedStyle[pathTargetsName]) {
|
|
15598
|
+
var index = oldClipPath.parsedStyle[pathTargetsName].indexOf(object);
|
|
15599
|
+
oldClipPath.parsedStyle[pathTargetsName].splice(index, 1);
|
|
15523
15600
|
}
|
|
15524
15601
|
|
|
15525
15602
|
if (newClipPath) {
|
|
15526
|
-
if (!newClipPath.parsedStyle
|
|
15527
|
-
newClipPath.parsedStyle
|
|
15603
|
+
if (!newClipPath.parsedStyle[pathTargetsName]) {
|
|
15604
|
+
newClipPath.parsedStyle[pathTargetsName] = [];
|
|
15528
15605
|
}
|
|
15529
15606
|
|
|
15530
|
-
newClipPath.parsedStyle.
|
|
15607
|
+
newClipPath.parsedStyle[pathTargetsName].push(object);
|
|
15531
15608
|
} // should affect children
|
|
15532
15609
|
|
|
15533
15610
|
|
|
@@ -15543,10 +15620,13 @@ var CSSPropertyClipPath = /*#__PURE__*/function () {
|
|
|
15543
15620
|
}();
|
|
15544
15621
|
|
|
15545
15622
|
CSSPropertyClipPath = tslib.__decorate([manaSyringe.singleton({
|
|
15546
|
-
token: {
|
|
15623
|
+
token: [{
|
|
15547
15624
|
token: CSSProperty,
|
|
15548
15625
|
named: exports.PropertySyntax.CLIP_PATH
|
|
15549
|
-
}
|
|
15626
|
+
}, {
|
|
15627
|
+
token: CSSProperty,
|
|
15628
|
+
named: exports.PropertySyntax.TEXT_PATH
|
|
15629
|
+
}]
|
|
15550
15630
|
}), tslib.__param(0, manaSyringe.inject(SceneGraphService))], CSSPropertyClipPath);
|
|
15551
15631
|
|
|
15552
15632
|
var CSSPropertyColor = /*#__PURE__*/function () {
|
|
@@ -16493,6 +16573,10 @@ var BUILT_IN_PROPERTIES = [{
|
|
|
16493
16573
|
k: ['none'],
|
|
16494
16574
|
d: 'none',
|
|
16495
16575
|
syntax: exports.PropertySyntax.PAINT
|
|
16576
|
+
}, {
|
|
16577
|
+
n: 'fillRule',
|
|
16578
|
+
k: ['nonzero', 'evenodd'],
|
|
16579
|
+
d: 'nonzero'
|
|
16496
16580
|
},
|
|
16497
16581
|
/**
|
|
16498
16582
|
* default to none
|
|
@@ -16630,6 +16714,18 @@ var BUILT_IN_PROPERTIES = [{
|
|
|
16630
16714
|
}, {
|
|
16631
16715
|
n: 'clipPath',
|
|
16632
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
|
|
16633
16729
|
}, {
|
|
16634
16730
|
n: 'transform',
|
|
16635
16731
|
p: 100,
|