@antv/g-lite 1.2.20 → 1.2.21
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/css/CSSProperty.d.ts +7 -0
- package/dist/css/StyleValueRegistry.d.ts +2 -2
- package/dist/css/interfaces.d.ts +3 -2
- package/dist/css/parser/dimension.d.ts +9 -1
- package/dist/css/parser/numeric.d.ts +3 -0
- package/dist/css/parser/transform-origin.d.ts +2 -0
- package/dist/css/parser/transform.d.ts +1 -0
- package/dist/css/properties/CSSPropertyAngle.d.ts +1 -0
- package/dist/css/properties/CSSPropertyLengthOrPercentage.d.ts +5 -1
- package/dist/css/properties/CSSPropertyNumber.d.ts +1 -0
- package/dist/css/properties/CSSPropertyOffsetDistance.d.ts +1 -0
- package/dist/css/properties/CSSPropertyOpacity.d.ts +1 -0
- package/dist/css/properties/CSSPropertyTransform.d.ts +3 -2
- package/dist/css/properties/CSSPropertyTransformOrigin.d.ts +1 -0
- package/dist/css/properties/CSSPropertyZIndex.d.ts +1 -0
- package/dist/display-objects/DisplayObject.d.ts +1 -1
- package/dist/index.esm.js +136 -32
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +136 -32
- package/dist/index.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3976,29 +3976,25 @@ function parseDimension(unitRegExp, string) {
|
|
|
3976
3976
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length
|
|
3977
3977
|
* length with only absolute unit, eg. 1px
|
|
3978
3978
|
*/
|
|
3979
|
-
var
|
|
3979
|
+
var parseLengthUnmemoize = function (css) {
|
|
3980
3980
|
return parseDimension(new RegExp('px', 'g'), css);
|
|
3981
|
-
}
|
|
3981
|
+
};
|
|
3982
|
+
var parseLength = memoize(parseLengthUnmemoize);
|
|
3982
3983
|
/**
|
|
3983
3984
|
* <percentage>
|
|
3984
3985
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/percentage
|
|
3985
3986
|
*/
|
|
3986
|
-
|
|
3987
|
+
var parserPercentageUnmemoize = function (css) {
|
|
3987
3988
|
return parseDimension(new RegExp('%', 'g'), css);
|
|
3988
|
-
}
|
|
3989
|
+
};
|
|
3990
|
+
memoize(parserPercentageUnmemoize);
|
|
3989
3991
|
/**
|
|
3990
3992
|
* length with absolute or relative unit,
|
|
3991
3993
|
* eg. 1px, 0.7em, 50%, calc(100% - 200px);
|
|
3992
3994
|
*
|
|
3993
3995
|
* @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length-percentage
|
|
3994
3996
|
*/
|
|
3995
|
-
|
|
3996
|
-
// if (isNumber(css) || isFinite(Number(css))) {
|
|
3997
|
-
// return getOrCreateUnitValue(Number(css), 'px');
|
|
3998
|
-
// }
|
|
3999
|
-
// return parseDimension(new RegExp('px|%|em|rem', 'g'), css) as CSSUnitValue;
|
|
4000
|
-
// });
|
|
4001
|
-
var parseLengthOrPercentage = function (css) {
|
|
3997
|
+
var parseLengthOrPercentageUnmemoize = function (css) {
|
|
4002
3998
|
if (util.isNumber(css) || isFinite(Number(css))) {
|
|
4003
3999
|
// Number(css) is NaN
|
|
4004
4000
|
return getOrCreateUnitValue(Number(css) || 0, 'px');
|
|
@@ -4006,9 +4002,11 @@ var parseLengthOrPercentage = function (css) {
|
|
|
4006
4002
|
}
|
|
4007
4003
|
return parseDimension(new RegExp('px|%|em|rem', 'g'), css);
|
|
4008
4004
|
};
|
|
4009
|
-
var
|
|
4005
|
+
var parseLengthOrPercentage = memoize(parseLengthOrPercentageUnmemoize);
|
|
4006
|
+
var parseAngleUnmemoize = function (css) {
|
|
4010
4007
|
return parseDimension(new RegExp('deg|rad|grad|turn', 'g'), css);
|
|
4011
|
-
}
|
|
4008
|
+
};
|
|
4009
|
+
var parseAngle = memoize(parseAngleUnmemoize);
|
|
4012
4010
|
/**
|
|
4013
4011
|
* merge CSSUnitValue
|
|
4014
4012
|
*
|
|
@@ -4201,7 +4199,7 @@ function numberToString(x) {
|
|
|
4201
4199
|
* * 0 -> CSSUnitValue(0)
|
|
4202
4200
|
* * '2' -> CSSUnitValue(2)
|
|
4203
4201
|
*/
|
|
4204
|
-
var
|
|
4202
|
+
var parseNumberUnmemoize = function (string) {
|
|
4205
4203
|
if (typeof string === 'number') {
|
|
4206
4204
|
return getOrCreateUnitValue(string);
|
|
4207
4205
|
}
|
|
@@ -4211,12 +4209,8 @@ var parseNumber = memoize(function (string) {
|
|
|
4211
4209
|
else {
|
|
4212
4210
|
return getOrCreateUnitValue(0);
|
|
4213
4211
|
}
|
|
4214
|
-
}
|
|
4215
|
-
|
|
4216
|
-
* separate string to array
|
|
4217
|
-
* eg.
|
|
4218
|
-
* * [0.5, 0.5] -> [CSSUnitValue, CSSUnitValue]
|
|
4219
|
-
*/
|
|
4212
|
+
};
|
|
4213
|
+
var parseNumber = memoize(parseNumberUnmemoize);
|
|
4220
4214
|
memoize(function (string) {
|
|
4221
4215
|
if (util.isString(string)) {
|
|
4222
4216
|
return string.split(' ').map(parseNumber);
|
|
@@ -5276,6 +5270,68 @@ function parseTransform(string) {
|
|
|
5276
5270
|
}
|
|
5277
5271
|
return [];
|
|
5278
5272
|
}
|
|
5273
|
+
function parseTransformUnmemoize(string) {
|
|
5274
|
+
string = (string || 'none').toLowerCase().trim();
|
|
5275
|
+
if (string === 'none') {
|
|
5276
|
+
return [];
|
|
5277
|
+
}
|
|
5278
|
+
var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
|
|
5279
|
+
var result = [];
|
|
5280
|
+
var match;
|
|
5281
|
+
var prevLastIndex = 0;
|
|
5282
|
+
while ((match = transformRegExp.exec(string))) {
|
|
5283
|
+
if (match.index !== prevLastIndex) {
|
|
5284
|
+
return [];
|
|
5285
|
+
}
|
|
5286
|
+
prevLastIndex = match.index + match[0].length;
|
|
5287
|
+
var functionName = match[1]; // scale
|
|
5288
|
+
var functionData = transformFunctions[functionName]; // scale(1, 2)
|
|
5289
|
+
if (!functionData) {
|
|
5290
|
+
// invalid, eg. scale()
|
|
5291
|
+
return [];
|
|
5292
|
+
}
|
|
5293
|
+
var args = match[2].split(','); // 1,2
|
|
5294
|
+
var argTypes = functionData[0]; // Nn
|
|
5295
|
+
if (argTypes.length < args.length) {
|
|
5296
|
+
// scale(N, n)
|
|
5297
|
+
return [];
|
|
5298
|
+
}
|
|
5299
|
+
var parsedArgs = [];
|
|
5300
|
+
for (var i = 0; i < argTypes.length; i++) {
|
|
5301
|
+
var arg = args[i];
|
|
5302
|
+
var type = argTypes[i];
|
|
5303
|
+
var parsedArg = void 0;
|
|
5304
|
+
if (!arg) {
|
|
5305
|
+
// @ts-ignore
|
|
5306
|
+
parsedArg = {
|
|
5307
|
+
a: Odeg,
|
|
5308
|
+
n: parsedArgs[0],
|
|
5309
|
+
t: Opx,
|
|
5310
|
+
}[type];
|
|
5311
|
+
}
|
|
5312
|
+
else {
|
|
5313
|
+
// @ts-ignore
|
|
5314
|
+
parsedArg = {
|
|
5315
|
+
A: function (s) {
|
|
5316
|
+
return s.trim() === '0' ? Odeg : parseAngleUnmemoize(s);
|
|
5317
|
+
},
|
|
5318
|
+
N: parseNumberUnmemoize,
|
|
5319
|
+
T: parseLengthOrPercentageUnmemoize,
|
|
5320
|
+
L: parseLengthUnmemoize,
|
|
5321
|
+
}[type.toUpperCase()](arg);
|
|
5322
|
+
}
|
|
5323
|
+
if (parsedArg === undefined) {
|
|
5324
|
+
return [];
|
|
5325
|
+
}
|
|
5326
|
+
parsedArgs.push(parsedArg);
|
|
5327
|
+
}
|
|
5328
|
+
result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
|
|
5329
|
+
if (transformRegExp.lastIndex === string.length) {
|
|
5330
|
+
return result;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
return [];
|
|
5334
|
+
}
|
|
5279
5335
|
function convertItemToMatrix(item) {
|
|
5280
5336
|
var x;
|
|
5281
5337
|
var y;
|
|
@@ -5891,6 +5947,39 @@ var parseTransformOrigin = memoize(function (value) {
|
|
|
5891
5947
|
];
|
|
5892
5948
|
}
|
|
5893
5949
|
});
|
|
5950
|
+
var parseTransformOriginUnmemoize = function (value) {
|
|
5951
|
+
if (util.isString(value)) {
|
|
5952
|
+
if (value === 'text-anchor') {
|
|
5953
|
+
return [getOrCreateUnitValue(0, 'px'), getOrCreateUnitValue(0, 'px')];
|
|
5954
|
+
}
|
|
5955
|
+
var values = value.split(' ');
|
|
5956
|
+
if (values.length === 1) {
|
|
5957
|
+
if (values[0] === 'top' || values[0] === 'bottom') {
|
|
5958
|
+
// 'top' -> 'center top'
|
|
5959
|
+
values[1] = values[0];
|
|
5960
|
+
values[0] = 'center';
|
|
5961
|
+
}
|
|
5962
|
+
else {
|
|
5963
|
+
// '50px' -> '50px center'
|
|
5964
|
+
values[1] = 'center';
|
|
5965
|
+
}
|
|
5966
|
+
}
|
|
5967
|
+
if (values.length !== 2) {
|
|
5968
|
+
return null;
|
|
5969
|
+
}
|
|
5970
|
+
// eg. center bottom
|
|
5971
|
+
return [
|
|
5972
|
+
parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[0])),
|
|
5973
|
+
parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[1])),
|
|
5974
|
+
];
|
|
5975
|
+
}
|
|
5976
|
+
else {
|
|
5977
|
+
return [
|
|
5978
|
+
getOrCreateUnitValue(value[0] || 0, 'px'),
|
|
5979
|
+
getOrCreateUnitValue(value[1] || 0, 'px'),
|
|
5980
|
+
];
|
|
5981
|
+
}
|
|
5982
|
+
};
|
|
5894
5983
|
function convertKeyword2Percent(keyword) {
|
|
5895
5984
|
if (keyword === 'center') {
|
|
5896
5985
|
return '50%';
|
|
@@ -6543,6 +6632,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6543
6632
|
skipParse: false,
|
|
6544
6633
|
forceUpdateGeometry: false,
|
|
6545
6634
|
usedAttributes: [],
|
|
6635
|
+
memoize: true,
|
|
6546
6636
|
}; }
|
|
6547
6637
|
if (!this.runtime.enableCSSParsing) {
|
|
6548
6638
|
Object.assign(object.attributes, attributes);
|
|
@@ -6706,7 +6796,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6706
6796
|
}
|
|
6707
6797
|
return;
|
|
6708
6798
|
}
|
|
6709
|
-
var skipUpdateAttribute = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes;
|
|
6799
|
+
var skipUpdateAttribute = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize = options.memoize;
|
|
6710
6800
|
var needUpdateGeometry = forceUpdateGeometry;
|
|
6711
6801
|
var attributeNames = Object.keys(attributes);
|
|
6712
6802
|
attributeNames.forEach(function (attributeName) {
|
|
@@ -6720,7 +6810,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6720
6810
|
});
|
|
6721
6811
|
if (!skipParse) {
|
|
6722
6812
|
attributeNames.forEach(function (name) {
|
|
6723
|
-
object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object);
|
|
6813
|
+
object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize);
|
|
6724
6814
|
});
|
|
6725
6815
|
}
|
|
6726
6816
|
// let hasUnresolvedProperties = false;
|
|
@@ -6754,7 +6844,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6754
6844
|
attributeNames.forEach(function (name) {
|
|
6755
6845
|
// some style props maybe deleted after parsing such as `anchor` in Text
|
|
6756
6846
|
if (name in object.computedStyle) {
|
|
6757
|
-
object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object);
|
|
6847
|
+
object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize);
|
|
6758
6848
|
}
|
|
6759
6849
|
});
|
|
6760
6850
|
// if (hasUnresolvedProperties) {
|
|
@@ -6789,7 +6879,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6789
6879
|
/**
|
|
6790
6880
|
* string -> parsed value
|
|
6791
6881
|
*/
|
|
6792
|
-
DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object) {
|
|
6882
|
+
DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object, memoized) {
|
|
6793
6883
|
var metadata = propertyMetadataCache[name];
|
|
6794
6884
|
var computed = value;
|
|
6795
6885
|
if (value === '' || util.isNil(value)) {
|
|
@@ -6808,9 +6898,14 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6808
6898
|
// computed = new CSSKeywordValue(value);
|
|
6809
6899
|
computed = getOrCreateKeyword(value);
|
|
6810
6900
|
}
|
|
6811
|
-
else if (handler
|
|
6812
|
-
|
|
6813
|
-
|
|
6901
|
+
else if (handler) {
|
|
6902
|
+
if (!memoized && handler.parserUnmemoize) {
|
|
6903
|
+
computed = handler.parserUnmemoize(value, object);
|
|
6904
|
+
}
|
|
6905
|
+
else if (handler.parser) {
|
|
6906
|
+
// try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
|
|
6907
|
+
computed = handler.parser(value, object);
|
|
6908
|
+
}
|
|
6814
6909
|
}
|
|
6815
6910
|
}
|
|
6816
6911
|
}
|
|
@@ -6819,7 +6914,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6819
6914
|
/**
|
|
6820
6915
|
* computed value -> used value
|
|
6821
6916
|
*/
|
|
6822
|
-
DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object) {
|
|
6917
|
+
DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object, memoized) {
|
|
6823
6918
|
var metadata = propertyMetadataCache[name];
|
|
6824
6919
|
var isDocumentElement = object.id === 'g-root';
|
|
6825
6920
|
// let used: CSSStyleValue = computed instanceof CSSStyleValue ? computed.clone() : computed;
|
|
@@ -6844,7 +6939,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
6844
6939
|
if (!util.isNil(defaultValue)) {
|
|
6845
6940
|
computed = this.parseProperty(name, isFunction(defaultValue)
|
|
6846
6941
|
? defaultValue(object.nodeName)
|
|
6847
|
-
: defaultValue, object);
|
|
6942
|
+
: defaultValue, object, memoized);
|
|
6848
6943
|
}
|
|
6849
6944
|
}
|
|
6850
6945
|
else if (value === 'inherit') {
|
|
@@ -7112,6 +7207,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
|
|
|
7112
7207
|
var CSSPropertyAngle = /** @class */ (function () {
|
|
7113
7208
|
function CSSPropertyAngle() {
|
|
7114
7209
|
this.parser = parseAngle;
|
|
7210
|
+
this.parserUnmemoize = parseAngleUnmemoize;
|
|
7115
7211
|
this.parserWithCSSDisabled = null;
|
|
7116
7212
|
this.mixer = mergeNumbers;
|
|
7117
7213
|
}
|
|
@@ -7186,6 +7282,7 @@ function getFontSize(object) {
|
|
|
7186
7282
|
var CSSPropertyLengthOrPercentage = /** @class */ (function () {
|
|
7187
7283
|
function CSSPropertyLengthOrPercentage() {
|
|
7188
7284
|
this.parser = parseLengthOrPercentage;
|
|
7285
|
+
this.parserUnmemoize = parseLengthOrPercentageUnmemoize;
|
|
7189
7286
|
this.parserWithCSSDisabled = null;
|
|
7190
7287
|
this.mixer = mergeNumbers;
|
|
7191
7288
|
}
|
|
@@ -7507,6 +7604,7 @@ var CSSPropertyNumber = /** @class */ (function () {
|
|
|
7507
7604
|
function CSSPropertyNumber() {
|
|
7508
7605
|
this.mixer = mergeNumbers;
|
|
7509
7606
|
this.parser = parseNumber;
|
|
7607
|
+
this.parserUnmemoize = parseNumberUnmemoize;
|
|
7510
7608
|
this.parserWithCSSDisabled = null;
|
|
7511
7609
|
}
|
|
7512
7610
|
CSSPropertyNumber.prototype.calculator = function (name, oldParsed, computed) {
|
|
@@ -7518,6 +7616,7 @@ var CSSPropertyNumber = /** @class */ (function () {
|
|
|
7518
7616
|
var CSSPropertyOffsetDistance = /** @class */ (function () {
|
|
7519
7617
|
function CSSPropertyOffsetDistance() {
|
|
7520
7618
|
this.parser = parseNumber;
|
|
7619
|
+
this.parserUnmemoize = parseNumberUnmemoize;
|
|
7521
7620
|
this.parserWithCSSDisabled = null;
|
|
7522
7621
|
this.mixer = clampedMergeNumbers(0, 1);
|
|
7523
7622
|
}
|
|
@@ -7551,6 +7650,7 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
|
|
|
7551
7650
|
var CSSPropertyOpacity = /** @class */ (function () {
|
|
7552
7651
|
function CSSPropertyOpacity() {
|
|
7553
7652
|
this.parser = parseNumber;
|
|
7653
|
+
this.parserUnmemoize = parseNumberUnmemoize;
|
|
7554
7654
|
this.parserWithCSSDisabled = null;
|
|
7555
7655
|
this.mixer = clampedMergeNumbers(0, 1);
|
|
7556
7656
|
}
|
|
@@ -8057,7 +8157,8 @@ function toFontString(attributes) {
|
|
|
8057
8157
|
var CSSPropertyTransform = /** @class */ (function () {
|
|
8058
8158
|
function CSSPropertyTransform() {
|
|
8059
8159
|
this.parser = parseTransform;
|
|
8060
|
-
this.
|
|
8160
|
+
this.parserUnmemoize = parseTransformUnmemoize;
|
|
8161
|
+
this.parserWithCSSDisabled = parseTransformUnmemoize;
|
|
8061
8162
|
this.mixer = mergeTransforms;
|
|
8062
8163
|
}
|
|
8063
8164
|
CSSPropertyTransform.prototype.calculator = function (name, oldParsed, parsed, object) {
|
|
@@ -8082,6 +8183,7 @@ var CSSPropertyTransform = /** @class */ (function () {
|
|
|
8082
8183
|
var CSSPropertyTransformOrigin = /** @class */ (function () {
|
|
8083
8184
|
function CSSPropertyTransformOrigin() {
|
|
8084
8185
|
this.parser = parseTransformOrigin;
|
|
8186
|
+
this.parserUnmemoize = parseTransformOriginUnmemoize;
|
|
8085
8187
|
// calculator(
|
|
8086
8188
|
// name: string,
|
|
8087
8189
|
// oldParsed: [CSSUnitValue, CSSUnitValue],
|
|
@@ -8099,6 +8201,7 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
|
|
|
8099
8201
|
var CSSPropertyZIndex = /** @class */ (function () {
|
|
8100
8202
|
function CSSPropertyZIndex() {
|
|
8101
8203
|
this.parser = parseNumber;
|
|
8204
|
+
this.parserUnmemoize = parseNumberUnmemoize;
|
|
8102
8205
|
}
|
|
8103
8206
|
CSSPropertyZIndex.prototype.calculator = function (name, oldParsed, computed, object) {
|
|
8104
8207
|
return computed.value;
|
|
@@ -12507,15 +12610,16 @@ var DisplayObject = /** @class */ (function (_super) {
|
|
|
12507
12610
|
// redraw at next frame
|
|
12508
12611
|
renderable.dirty = true;
|
|
12509
12612
|
};
|
|
12510
|
-
DisplayObject.prototype.setAttribute = function (name, value, force) {
|
|
12613
|
+
DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
|
|
12511
12614
|
if (force === void 0) { force = false; }
|
|
12615
|
+
if (memoize === void 0) { memoize = true; }
|
|
12512
12616
|
var attributeName = formatAttributeName(name);
|
|
12513
12617
|
// ignore undefined value
|
|
12514
12618
|
if (util.isUndefined(value)) {
|
|
12515
12619
|
return;
|
|
12516
12620
|
}
|
|
12517
12621
|
if (force || value !== this.attributes[attributeName]) {
|
|
12518
|
-
this.internalSetAttribute(attributeName, value);
|
|
12622
|
+
this.internalSetAttribute(attributeName, value, { memoize: memoize });
|
|
12519
12623
|
_super.prototype.setAttribute.call(this, attributeName, value);
|
|
12520
12624
|
}
|
|
12521
12625
|
};
|