@visactor/vrender 0.21.0-alpha.5 → 0.21.0-alpha.7
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/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.es.js +92 -43
- package/dist/index.js +91 -42
- package/dist/index.min.js +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -748,6 +748,13 @@
|
|
|
748
748
|
};
|
|
749
749
|
exports.DefaultGlobal = __decorate$1H([injectable(), __param$T(0, inject(ContributionProvider)), __param$T(0, named(EnvContribution)), __metadata$1h("design:paramtypes", [Object])], exports.DefaultGlobal);
|
|
750
750
|
|
|
751
|
+
exports.MeasureModeEnum = void 0;
|
|
752
|
+
!function (MeasureModeEnum) {
|
|
753
|
+
MeasureModeEnum[MeasureModeEnum.estimate = 0] = "estimate", MeasureModeEnum[MeasureModeEnum.actualBounding = 1] = "actualBounding", MeasureModeEnum[MeasureModeEnum.fontBounding = 2] = "fontBounding";
|
|
754
|
+
}(exports.MeasureModeEnum || (exports.MeasureModeEnum = {}));
|
|
755
|
+
|
|
756
|
+
const strCommandMap = ["arc", "arcTo", "bezierCurveTo", "closePath", "ellipse", "lineTo", "moveTo", "quadraticCurveTo", "rect"];
|
|
757
|
+
|
|
751
758
|
function getDefaultExportFromCjs (x) {
|
|
752
759
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
753
760
|
}
|
|
@@ -1702,7 +1709,9 @@
|
|
|
1702
1709
|
} = this.textSpec;
|
|
1703
1710
|
return {
|
|
1704
1711
|
width: metrics.width,
|
|
1705
|
-
height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize
|
|
1712
|
+
height: null !== (_a = lineHeight) && void 0 !== _a ? _a : fontSize,
|
|
1713
|
+
fontBoundingBoxAscent: metrics.fontBoundingBoxAscent,
|
|
1714
|
+
fontBoundingBoxDescent: metrics.fontBoundingBoxDescent
|
|
1706
1715
|
};
|
|
1707
1716
|
}
|
|
1708
1717
|
quickMeasure(text) {
|
|
@@ -1716,7 +1725,7 @@
|
|
|
1716
1725
|
for (let i = 0; i < text.length; i++) {
|
|
1717
1726
|
const char = text[i];
|
|
1718
1727
|
let size = this._measureSpecialChar(char);
|
|
1719
|
-
isNil$1(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char) && (size = this._measureNumberChar()), isNil$1(size) && ["F", "W"].includes(eastAsianCharacterInfo(char)) && (size = this._measureFullSizeChar()), isNil$1(size) && (size = this._measureLetterChar()), totalSize.width += size.width, totalSize.height = Math.max(totalSize.height, size.height);
|
|
1728
|
+
isNil$1(size) && TextMeasure.NUMBERS_CHAR_SET.includes(char) && (size = this._measureNumberChar()), isNil$1(size) && ["F", "W"].includes(eastAsianCharacterInfo(char)) && (size = this._measureFullSizeChar()), isNil$1(size) && (size = this._measureLetterChar()), totalSize.width += size.width, totalSize.height = Math.max(totalSize.height, size.height), !isNil$1(size.fontBoundingBoxAscent) && (totalSize.fontBoundingBoxAscent = size.fontBoundingBoxAscent), !isNil$1(size.fontBoundingBoxDescent) && (totalSize.fontBoundingBoxDescent = size.fontBoundingBoxDescent);
|
|
1720
1729
|
}
|
|
1721
1730
|
return totalSize;
|
|
1722
1731
|
}
|
|
@@ -1765,7 +1774,9 @@
|
|
|
1765
1774
|
const numberBounds = this._standardMethod(TextMeasure.NUMBERS_CHAR_SET);
|
|
1766
1775
|
this._numberCharSize = {
|
|
1767
1776
|
width: numberBounds.width / TextMeasure.NUMBERS_CHAR_SET.length,
|
|
1768
|
-
height: numberBounds.height
|
|
1777
|
+
height: numberBounds.height,
|
|
1778
|
+
fontBoundingBoxAscent: numberBounds.fontBoundingBoxAscent,
|
|
1779
|
+
fontBoundingBoxDescent: numberBounds.fontBoundingBoxDescent
|
|
1769
1780
|
};
|
|
1770
1781
|
}
|
|
1771
1782
|
return this._numberCharSize;
|
|
@@ -1778,7 +1789,9 @@
|
|
|
1778
1789
|
const alphabetBounds = this._standardMethod(TextMeasure.ALPHABET_CHAR_SET);
|
|
1779
1790
|
this._letterCharSize = {
|
|
1780
1791
|
width: alphabetBounds.width / TextMeasure.ALPHABET_CHAR_SET.length,
|
|
1781
|
-
height: alphabetBounds.height
|
|
1792
|
+
height: alphabetBounds.height,
|
|
1793
|
+
fontBoundingBoxAscent: alphabetBounds.fontBoundingBoxAscent,
|
|
1794
|
+
fontBoundingBoxDescent: alphabetBounds.fontBoundingBoxDescent
|
|
1782
1795
|
};
|
|
1783
1796
|
}
|
|
1784
1797
|
return this._letterCharSize;
|
|
@@ -3943,7 +3956,8 @@
|
|
|
3943
3956
|
suffixPosition: "end",
|
|
3944
3957
|
underlineDash: [],
|
|
3945
3958
|
underlineOffset: 0,
|
|
3946
|
-
disableAutoClipedPoptip: void 0
|
|
3959
|
+
disableAutoClipedPoptip: void 0,
|
|
3960
|
+
measureMode: exports.MeasureModeEnum.fontBounding
|
|
3947
3961
|
};
|
|
3948
3962
|
const DefaultPickStyle = {
|
|
3949
3963
|
pickStrokeBuffer: 0
|
|
@@ -4346,22 +4360,10 @@
|
|
|
4346
4360
|
}
|
|
4347
4361
|
measureTextBoundADscentEstimate(options) {
|
|
4348
4362
|
var _a;
|
|
4349
|
-
const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize
|
|
4350
|
-
|
|
4351
|
-
textBaseline: textBaseline
|
|
4352
|
-
} = options;
|
|
4353
|
-
return "bottom" === textBaseline ? {
|
|
4354
|
-
ascent: fontSize,
|
|
4355
|
-
descent: 0
|
|
4356
|
-
} : "middle" === textBaseline ? {
|
|
4357
|
-
ascent: fontSize / 2,
|
|
4358
|
-
descent: fontSize / 2
|
|
4359
|
-
} : "alphabetic" === textBaseline ? {
|
|
4363
|
+
const fontSize = null !== (_a = options.fontSize) && void 0 !== _a ? _a : DefaultTextStyle.fontSize;
|
|
4364
|
+
return {
|
|
4360
4365
|
ascent: .79 * fontSize,
|
|
4361
4366
|
descent: .21 * fontSize
|
|
4362
|
-
} : {
|
|
4363
|
-
ascent: 0,
|
|
4364
|
-
descent: fontSize
|
|
4365
4367
|
};
|
|
4366
4368
|
}
|
|
4367
4369
|
measureTextBoundLeftRightEstimate(options) {
|
|
@@ -4381,11 +4383,42 @@
|
|
|
4381
4383
|
right: fontSize
|
|
4382
4384
|
};
|
|
4383
4385
|
}
|
|
4384
|
-
measureTextPixelADscentAndWidth(text, options) {
|
|
4386
|
+
measureTextPixelADscentAndWidth(text, options, mode) {
|
|
4385
4387
|
if (!this.context) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
|
|
4386
4388
|
width: this.estimate(text, options).width
|
|
4387
4389
|
});
|
|
4388
4390
|
const out = this._measureTextWithoutAlignBaseline(text, options, !0);
|
|
4391
|
+
if (mode === exports.MeasureModeEnum.actualBounding) return {
|
|
4392
|
+
ascent: out.actualBoundingBoxAscent,
|
|
4393
|
+
descent: out.actualBoundingBoxDescent,
|
|
4394
|
+
width: out.width
|
|
4395
|
+
};
|
|
4396
|
+
if (mode === exports.MeasureModeEnum.estimate) return Object.assign(Object.assign({}, this.measureTextBoundADscentEstimate(options)), {
|
|
4397
|
+
width: out.width
|
|
4398
|
+
});
|
|
4399
|
+
if (mode === exports.MeasureModeEnum.fontBounding) {
|
|
4400
|
+
const {
|
|
4401
|
+
lineHeight = options.fontSize
|
|
4402
|
+
} = options;
|
|
4403
|
+
let ratio = 1;
|
|
4404
|
+
if (lineHeight) {
|
|
4405
|
+
ratio = lineHeight / (out.fontBoundingBoxAscent + out.fontBoundingBoxDescent);
|
|
4406
|
+
}
|
|
4407
|
+
let ascent = out.fontBoundingBoxAscent * ratio,
|
|
4408
|
+
descent = out.fontBoundingBoxDescent * ratio;
|
|
4409
|
+
if (out.actualBoundingBoxDescent && descent < out.actualBoundingBoxDescent) {
|
|
4410
|
+
const delta = out.actualBoundingBoxDescent - descent;
|
|
4411
|
+
descent += delta, ascent -= delta;
|
|
4412
|
+
} else if (out.actualBoundingBoxAscent && ascent < out.actualBoundingBoxAscent) {
|
|
4413
|
+
const delta = out.actualBoundingBoxAscent - ascent;
|
|
4414
|
+
ascent += delta, descent -= delta;
|
|
4415
|
+
}
|
|
4416
|
+
return {
|
|
4417
|
+
ascent: ascent,
|
|
4418
|
+
descent: descent,
|
|
4419
|
+
width: out.width
|
|
4420
|
+
};
|
|
4421
|
+
}
|
|
4389
4422
|
return {
|
|
4390
4423
|
ascent: out.actualBoundingBoxAscent,
|
|
4391
4424
|
descent: out.actualBoundingBoxDescent,
|
|
@@ -14587,15 +14620,19 @@
|
|
|
14587
14620
|
GetLayoutByLines(lines, textAlign, textBaseline, lineHeight) {
|
|
14588
14621
|
let suffix = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
|
|
14589
14622
|
let wordBreak = arguments.length > 5 ? arguments[5] : undefined;
|
|
14590
|
-
let
|
|
14591
|
-
|
|
14623
|
+
let params = arguments.length > 6 ? arguments[6] : undefined;
|
|
14624
|
+
const {
|
|
14625
|
+
lineWidth: lineWidth,
|
|
14626
|
+
suffixPosition = "end",
|
|
14627
|
+
measureMode = exports.MeasureModeEnum.actualBounding
|
|
14628
|
+
} = null != params ? params : {};
|
|
14592
14629
|
lines = lines.map(l => l.toString());
|
|
14593
14630
|
const linesLayout = [],
|
|
14594
14631
|
bboxWH = [0, 0];
|
|
14595
14632
|
if ("number" == typeof lineWidth && lineWidth !== 1 / 0) {
|
|
14596
14633
|
let width;
|
|
14597
14634
|
for (let i = 0, len = lines.length; i < len; i++) {
|
|
14598
|
-
const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
|
|
14635
|
+
const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions, measureMode);
|
|
14599
14636
|
width = Math.min(metrics.width, lineWidth), linesLayout.push({
|
|
14600
14637
|
str: metrics.width <= lineWidth ? lines[i].toString() : this.textMeasure.clipTextWithSuffix(lines[i], this.textOptions, width, suffix, wordBreak, suffixPosition).str,
|
|
14601
14638
|
width: width,
|
|
@@ -14605,19 +14642,20 @@
|
|
|
14605
14642
|
}
|
|
14606
14643
|
bboxWH[0] = lineWidth;
|
|
14607
14644
|
} else {
|
|
14608
|
-
let width,
|
|
14609
|
-
|
|
14645
|
+
let width,
|
|
14646
|
+
text,
|
|
14647
|
+
_lineWidth = 0;
|
|
14610
14648
|
for (let i = 0, len = lines.length; i < len; i++) {
|
|
14611
14649
|
text = lines[i];
|
|
14612
|
-
const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions);
|
|
14613
|
-
width = metrics.width,
|
|
14650
|
+
const metrics = this.textMeasure.measureTextPixelADscentAndWidth(lines[i], this.textOptions, measureMode);
|
|
14651
|
+
width = metrics.width, _lineWidth = Math.max(_lineWidth, width), linesLayout.push({
|
|
14614
14652
|
str: text,
|
|
14615
14653
|
width: width,
|
|
14616
14654
|
ascent: metrics.ascent,
|
|
14617
14655
|
descent: metrics.descent
|
|
14618
14656
|
});
|
|
14619
14657
|
}
|
|
14620
|
-
bboxWH[0] =
|
|
14658
|
+
bboxWH[0] = _lineWidth;
|
|
14621
14659
|
}
|
|
14622
14660
|
bboxWH[1] = linesLayout.length * lineHeight, bboxWH[0] = linesLayout.reduce((a, b) => Math.max(a, b.width), 0);
|
|
14623
14661
|
const bbox = {
|
|
@@ -14775,6 +14813,9 @@
|
|
|
14775
14813
|
b = "horizontal" === direction ? this.updateHorizontalMultilineAABBBounds(text) : this.updateVerticalMultilineAABBBounds(text);
|
|
14776
14814
|
return "horizontal" === direction && underlineOffset && this._AABBBounds.add(this._AABBBounds.x1, this._AABBBounds.y2 + underlineOffset), b;
|
|
14777
14815
|
}
|
|
14816
|
+
guessLineHeightBuf(fontSize) {
|
|
14817
|
+
return fontSize ? .1 * fontSize : 0;
|
|
14818
|
+
}
|
|
14778
14819
|
updateHorizontalMultilineAABBBounds(text) {
|
|
14779
14820
|
var _a;
|
|
14780
14821
|
const textTheme = this.getGraphicTheme(),
|
|
@@ -14789,12 +14830,14 @@
|
|
|
14789
14830
|
maxLineWidth: maxLineWidth,
|
|
14790
14831
|
stroke = textTheme.stroke,
|
|
14791
14832
|
wrap = textTheme.wrap,
|
|
14792
|
-
|
|
14833
|
+
measureMode = textTheme.measureMode,
|
|
14793
14834
|
lineWidth = textTheme.lineWidth,
|
|
14794
14835
|
whiteSpace = textTheme.whiteSpace,
|
|
14795
|
-
suffixPosition = textTheme.suffixPosition
|
|
14836
|
+
suffixPosition = textTheme.suffixPosition,
|
|
14837
|
+
ignoreBuf = textTheme.ignoreBuf
|
|
14796
14838
|
} = attribute,
|
|
14797
|
-
|
|
14839
|
+
buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize),
|
|
14840
|
+
lineHeight = this.getLineHeight(attribute, textTheme) + buf;
|
|
14798
14841
|
if ("normal" === whiteSpace || wrap) return this.updateWrapAABBBounds(text);
|
|
14799
14842
|
if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
|
|
14800
14843
|
const bbox = this.cache.layoutData.bbox;
|
|
@@ -14804,8 +14847,13 @@
|
|
|
14804
14847
|
layoutData = new CanvasTextLayout(fontFamily, {
|
|
14805
14848
|
fontSize: fontSize,
|
|
14806
14849
|
fontWeight: fontWeight,
|
|
14807
|
-
fontFamily: fontFamily
|
|
14808
|
-
|
|
14850
|
+
fontFamily: fontFamily,
|
|
14851
|
+
lineHeight: lineHeight
|
|
14852
|
+
}, textMeasure).GetLayoutByLines(text, textAlign, textBaseline, lineHeight, !0 === ellipsis ? textTheme.ellipsis : ellipsis || void 0, !1, {
|
|
14853
|
+
lineWidth: maxLineWidth,
|
|
14854
|
+
suffixPosition: suffixPosition,
|
|
14855
|
+
measureMode: measureMode
|
|
14856
|
+
}),
|
|
14809
14857
|
{
|
|
14810
14858
|
bbox: bbox
|
|
14811
14859
|
} = layoutData;
|
|
@@ -14826,11 +14874,13 @@
|
|
|
14826
14874
|
wordBreak = textTheme.wordBreak,
|
|
14827
14875
|
fontWeight = textTheme.fontWeight,
|
|
14828
14876
|
ignoreBuf = textTheme.ignoreBuf,
|
|
14877
|
+
measureMode = textTheme.measureMode,
|
|
14829
14878
|
suffixPosition = textTheme.suffixPosition,
|
|
14830
14879
|
heightLimit = 0,
|
|
14831
14880
|
lineClamp: lineClamp
|
|
14832
14881
|
} = this.attribute,
|
|
14833
|
-
|
|
14882
|
+
buf = ignoreBuf ? 0 : this.guessLineHeightBuf(fontSize),
|
|
14883
|
+
lineHeight = this.getLineHeight(this.attribute, textTheme) + buf;
|
|
14834
14884
|
if (!this.shouldUpdateShape() && (null === (_a = this.cache) || void 0 === _a ? void 0 : _a.layoutData)) {
|
|
14835
14885
|
const bbox = this.cache.layoutData.bbox;
|
|
14836
14886
|
return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
|
|
@@ -14839,7 +14889,8 @@
|
|
|
14839
14889
|
textOptions = {
|
|
14840
14890
|
fontSize: fontSize,
|
|
14841
14891
|
fontWeight: fontWeight,
|
|
14842
|
-
fontFamily: fontFamily
|
|
14892
|
+
fontFamily: fontFamily,
|
|
14893
|
+
lineHeight: lineHeight
|
|
14843
14894
|
},
|
|
14844
14895
|
layoutObj = new CanvasTextLayout(fontFamily, textOptions, textMeasure),
|
|
14845
14896
|
lines = isArray$1(text) ? text.map(l => l.toString()) : [text.toString()],
|
|
@@ -14852,7 +14903,7 @@
|
|
|
14852
14903
|
let needCut = !0;
|
|
14853
14904
|
if (i === lineCountLimit - 1) {
|
|
14854
14905
|
const clip = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition, i !== lines.length - 1),
|
|
14855
|
-
matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
|
|
14906
|
+
matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
|
|
14856
14907
|
linesLayout.push({
|
|
14857
14908
|
str: clip.str,
|
|
14858
14909
|
width: clip.width,
|
|
@@ -14869,7 +14920,7 @@
|
|
|
14869
14920
|
} else clip.str = "", clip.width = 0;
|
|
14870
14921
|
needCut = !1;
|
|
14871
14922
|
}
|
|
14872
|
-
const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
|
|
14923
|
+
const matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
|
|
14873
14924
|
linesLayout.push({
|
|
14874
14925
|
str: clip.str,
|
|
14875
14926
|
width: clip.width,
|
|
@@ -14893,7 +14944,7 @@
|
|
|
14893
14944
|
for (let i = 0, len = lines.length; i < len; i++) {
|
|
14894
14945
|
if (i === lineCountLimit - 1) {
|
|
14895
14946
|
const clip = textMeasure.clipTextWithSuffix(lines[i], textOptions, maxLineWidth, ellipsis, !1, suffixPosition),
|
|
14896
|
-
matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions);
|
|
14947
|
+
matrics = textMeasure.measureTextPixelADscentAndWidth(clip.str, textOptions, measureMode);
|
|
14897
14948
|
linesLayout.push({
|
|
14898
14949
|
str: clip.str,
|
|
14899
14950
|
width: clip.width,
|
|
@@ -14903,7 +14954,7 @@
|
|
|
14903
14954
|
break;
|
|
14904
14955
|
}
|
|
14905
14956
|
text = lines[i], width = textMeasure.measureTextWidth(text, textOptions), lineWidth = Math.max(lineWidth, width);
|
|
14906
|
-
const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions);
|
|
14957
|
+
const matrics = textMeasure.measureTextPixelADscentAndWidth(text, textOptions, measureMode);
|
|
14907
14958
|
linesLayout.push({
|
|
14908
14959
|
str: text,
|
|
14909
14960
|
width: width,
|
|
@@ -18988,8 +19039,6 @@
|
|
|
18988
19039
|
return new Stage(params);
|
|
18989
19040
|
}
|
|
18990
19041
|
|
|
18991
|
-
const strCommandMap = ["arc", "arcTo", "bezierCurveTo", "closePath", "ellipse", "lineTo", "moveTo", "quadraticCurveTo", "rect"];
|
|
18992
|
-
|
|
18993
19042
|
var __decorate$1d = undefined && undefined.__decorate || function (decorators, target, key, desc) {
|
|
18994
19043
|
var d,
|
|
18995
19044
|
c = arguments.length,
|
|
@@ -28575,7 +28624,7 @@
|
|
|
28575
28624
|
|
|
28576
28625
|
const roughModule = _roughModule;
|
|
28577
28626
|
|
|
28578
|
-
const version = "0.21.0-alpha.
|
|
28627
|
+
const version = "0.21.0-alpha.7";
|
|
28579
28628
|
preLoadAllModule();
|
|
28580
28629
|
if (isBrowserEnv()) {
|
|
28581
28630
|
loadBrowserEnv(container);
|