@antv/g-lite 1.2.20 → 1.2.22

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.esm.js CHANGED
@@ -641,7 +641,7 @@ var AbstractRenderer = /** @class */ (function () {
641
641
  /**
642
642
  * enable dirty rectangle rendering by default
643
643
  */
644
- enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false }, config);
644
+ enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false, enableSizeAttenuation: true }, config);
645
645
  }
646
646
  AbstractRenderer.prototype.registerPlugin = function (plugin) {
647
647
  var index = this.plugins.findIndex(function (p) { return p === plugin; });
@@ -3955,29 +3955,25 @@ function parseDimension(unitRegExp, string) {
3955
3955
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length
3956
3956
  * length with only absolute unit, eg. 1px
3957
3957
  */
3958
- var parseLength = memoize(function (css) {
3958
+ var parseLengthUnmemoize = function (css) {
3959
3959
  return parseDimension(new RegExp('px', 'g'), css);
3960
- });
3960
+ };
3961
+ var parseLength = memoize(parseLengthUnmemoize);
3961
3962
  /**
3962
3963
  * <percentage>
3963
3964
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/percentage
3964
3965
  */
3965
- memoize(function (css) {
3966
+ var parserPercentageUnmemoize = function (css) {
3966
3967
  return parseDimension(new RegExp('%', 'g'), css);
3967
- });
3968
+ };
3969
+ memoize(parserPercentageUnmemoize);
3968
3970
  /**
3969
3971
  * length with absolute or relative unit,
3970
3972
  * eg. 1px, 0.7em, 50%, calc(100% - 200px);
3971
3973
  *
3972
3974
  * @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/length-percentage
3973
3975
  */
3974
- // export const parseLengthOrPercentage = memoize((css: string): CSSUnitValue => {
3975
- // if (isNumber(css) || isFinite(Number(css))) {
3976
- // return getOrCreateUnitValue(Number(css), 'px');
3977
- // }
3978
- // return parseDimension(new RegExp('px|%|em|rem', 'g'), css) as CSSUnitValue;
3979
- // });
3980
- var parseLengthOrPercentage = function (css) {
3976
+ var parseLengthOrPercentageUnmemoize = function (css) {
3981
3977
  if (isNumber(css) || isFinite(Number(css))) {
3982
3978
  // Number(css) is NaN
3983
3979
  return getOrCreateUnitValue(Number(css) || 0, 'px');
@@ -3985,9 +3981,11 @@ var parseLengthOrPercentage = function (css) {
3985
3981
  }
3986
3982
  return parseDimension(new RegExp('px|%|em|rem', 'g'), css);
3987
3983
  };
3988
- var parseAngle = memoize(function (css) {
3984
+ var parseLengthOrPercentage = memoize(parseLengthOrPercentageUnmemoize);
3985
+ var parseAngleUnmemoize = function (css) {
3989
3986
  return parseDimension(new RegExp('deg|rad|grad|turn', 'g'), css);
3990
- });
3987
+ };
3988
+ var parseAngle = memoize(parseAngleUnmemoize);
3991
3989
  /**
3992
3990
  * merge CSSUnitValue
3993
3991
  *
@@ -4180,7 +4178,7 @@ function numberToString(x) {
4180
4178
  * * 0 -> CSSUnitValue(0)
4181
4179
  * * '2' -> CSSUnitValue(2)
4182
4180
  */
4183
- var parseNumber = memoize(function (string) {
4181
+ var parseNumberUnmemoize = function (string) {
4184
4182
  if (typeof string === 'number') {
4185
4183
  return getOrCreateUnitValue(string);
4186
4184
  }
@@ -4190,12 +4188,8 @@ var parseNumber = memoize(function (string) {
4190
4188
  else {
4191
4189
  return getOrCreateUnitValue(0);
4192
4190
  }
4193
- });
4194
- /**
4195
- * separate string to array
4196
- * eg.
4197
- * * [0.5, 0.5] -> [CSSUnitValue, CSSUnitValue]
4198
- */
4191
+ };
4192
+ var parseNumber = memoize(parseNumberUnmemoize);
4199
4193
  memoize(function (string) {
4200
4194
  if (isString(string)) {
4201
4195
  return string.split(' ').map(parseNumber);
@@ -5255,6 +5249,68 @@ function parseTransform(string) {
5255
5249
  }
5256
5250
  return [];
5257
5251
  }
5252
+ function parseTransformUnmemoize(string) {
5253
+ string = (string || 'none').toLowerCase().trim();
5254
+ if (string === 'none') {
5255
+ return [];
5256
+ }
5257
+ var transformRegExp = /\s*(\w+)\(([^)]*)\)/g;
5258
+ var result = [];
5259
+ var match;
5260
+ var prevLastIndex = 0;
5261
+ while ((match = transformRegExp.exec(string))) {
5262
+ if (match.index !== prevLastIndex) {
5263
+ return [];
5264
+ }
5265
+ prevLastIndex = match.index + match[0].length;
5266
+ var functionName = match[1]; // scale
5267
+ var functionData = transformFunctions[functionName]; // scale(1, 2)
5268
+ if (!functionData) {
5269
+ // invalid, eg. scale()
5270
+ return [];
5271
+ }
5272
+ var args = match[2].split(','); // 1,2
5273
+ var argTypes = functionData[0]; // Nn
5274
+ if (argTypes.length < args.length) {
5275
+ // scale(N, n)
5276
+ return [];
5277
+ }
5278
+ var parsedArgs = [];
5279
+ for (var i = 0; i < argTypes.length; i++) {
5280
+ var arg = args[i];
5281
+ var type = argTypes[i];
5282
+ var parsedArg = void 0;
5283
+ if (!arg) {
5284
+ // @ts-ignore
5285
+ parsedArg = {
5286
+ a: Odeg,
5287
+ n: parsedArgs[0],
5288
+ t: Opx,
5289
+ }[type];
5290
+ }
5291
+ else {
5292
+ // @ts-ignore
5293
+ parsedArg = {
5294
+ A: function (s) {
5295
+ return s.trim() === '0' ? Odeg : parseAngleUnmemoize(s);
5296
+ },
5297
+ N: parseNumberUnmemoize,
5298
+ T: parseLengthOrPercentageUnmemoize,
5299
+ L: parseLengthUnmemoize,
5300
+ }[type.toUpperCase()](arg);
5301
+ }
5302
+ if (parsedArg === undefined) {
5303
+ return [];
5304
+ }
5305
+ parsedArgs.push(parsedArg);
5306
+ }
5307
+ result.push({ t: functionName, d: parsedArgs }); // { t: scale, d: [1, 2] }
5308
+ if (transformRegExp.lastIndex === string.length) {
5309
+ return result;
5310
+ }
5311
+ }
5312
+ return [];
5313
+ }
5258
5314
  function convertItemToMatrix(item) {
5259
5315
  var x;
5260
5316
  var y;
@@ -5870,6 +5926,39 @@ var parseTransformOrigin = memoize(function (value) {
5870
5926
  ];
5871
5927
  }
5872
5928
  });
5929
+ var parseTransformOriginUnmemoize = function (value) {
5930
+ if (isString(value)) {
5931
+ if (value === 'text-anchor') {
5932
+ return [getOrCreateUnitValue(0, 'px'), getOrCreateUnitValue(0, 'px')];
5933
+ }
5934
+ var values = value.split(' ');
5935
+ if (values.length === 1) {
5936
+ if (values[0] === 'top' || values[0] === 'bottom') {
5937
+ // 'top' -> 'center top'
5938
+ values[1] = values[0];
5939
+ values[0] = 'center';
5940
+ }
5941
+ else {
5942
+ // '50px' -> '50px center'
5943
+ values[1] = 'center';
5944
+ }
5945
+ }
5946
+ if (values.length !== 2) {
5947
+ return null;
5948
+ }
5949
+ // eg. center bottom
5950
+ return [
5951
+ parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[0])),
5952
+ parseLengthOrPercentageUnmemoize(convertKeyword2Percent(values[1])),
5953
+ ];
5954
+ }
5955
+ else {
5956
+ return [
5957
+ getOrCreateUnitValue(value[0] || 0, 'px'),
5958
+ getOrCreateUnitValue(value[1] || 0, 'px'),
5959
+ ];
5960
+ }
5961
+ };
5873
5962
  function convertKeyword2Percent(keyword) {
5874
5963
  if (keyword === 'center') {
5875
5964
  return '50%';
@@ -6522,6 +6611,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6522
6611
  skipParse: false,
6523
6612
  forceUpdateGeometry: false,
6524
6613
  usedAttributes: [],
6614
+ memoize: true,
6525
6615
  }; }
6526
6616
  if (!this.runtime.enableCSSParsing) {
6527
6617
  Object.assign(object.attributes, attributes);
@@ -6685,7 +6775,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6685
6775
  }
6686
6776
  return;
6687
6777
  }
6688
- var skipUpdateAttribute = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes;
6778
+ var skipUpdateAttribute = options.skipUpdateAttribute, skipParse = options.skipParse, forceUpdateGeometry = options.forceUpdateGeometry, usedAttributes = options.usedAttributes, memoize = options.memoize;
6689
6779
  var needUpdateGeometry = forceUpdateGeometry;
6690
6780
  var attributeNames = Object.keys(attributes);
6691
6781
  attributeNames.forEach(function (attributeName) {
@@ -6699,7 +6789,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6699
6789
  });
6700
6790
  if (!skipParse) {
6701
6791
  attributeNames.forEach(function (name) {
6702
- object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object);
6792
+ object.computedStyle[name] = _this.parseProperty(name, object.attributes[name], object, memoize);
6703
6793
  });
6704
6794
  }
6705
6795
  // let hasUnresolvedProperties = false;
@@ -6733,7 +6823,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6733
6823
  attributeNames.forEach(function (name) {
6734
6824
  // some style props maybe deleted after parsing such as `anchor` in Text
6735
6825
  if (name in object.computedStyle) {
6736
- object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object);
6826
+ object.parsedStyle[name] = _this.computeProperty(name, object.computedStyle[name], object, memoize);
6737
6827
  }
6738
6828
  });
6739
6829
  // if (hasUnresolvedProperties) {
@@ -6768,7 +6858,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6768
6858
  /**
6769
6859
  * string -> parsed value
6770
6860
  */
6771
- DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object) {
6861
+ DefaultStyleValueRegistry.prototype.parseProperty = function (name, value, object, memoized) {
6772
6862
  var metadata = propertyMetadataCache[name];
6773
6863
  var computed = value;
6774
6864
  if (value === '' || isNil(value)) {
@@ -6787,9 +6877,14 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6787
6877
  // computed = new CSSKeywordValue(value);
6788
6878
  computed = getOrCreateKeyword(value);
6789
6879
  }
6790
- else if (handler && handler.parser) {
6791
- // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
6792
- computed = handler.parser(value, object);
6880
+ else if (handler) {
6881
+ if (!memoized && handler.parserUnmemoize) {
6882
+ computed = handler.parserUnmemoize(value, object);
6883
+ }
6884
+ else if (handler.parser) {
6885
+ // try to parse it to CSSStyleValue, eg. '10px' -> CSS.px(10)
6886
+ computed = handler.parser(value, object);
6887
+ }
6793
6888
  }
6794
6889
  }
6795
6890
  }
@@ -6798,7 +6893,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6798
6893
  /**
6799
6894
  * computed value -> used value
6800
6895
  */
6801
- DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object) {
6896
+ DefaultStyleValueRegistry.prototype.computeProperty = function (name, computed, object, memoized) {
6802
6897
  var metadata = propertyMetadataCache[name];
6803
6898
  var isDocumentElement = object.id === 'g-root';
6804
6899
  // let used: CSSStyleValue = computed instanceof CSSStyleValue ? computed.clone() : computed;
@@ -6823,7 +6918,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
6823
6918
  if (!isNil(defaultValue)) {
6824
6919
  computed = this.parseProperty(name, isFunction(defaultValue)
6825
6920
  ? defaultValue(object.nodeName)
6826
- : defaultValue, object);
6921
+ : defaultValue, object, memoized);
6827
6922
  }
6828
6923
  }
6829
6924
  else if (value === 'inherit') {
@@ -7078,6 +7173,32 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7078
7173
  this.runtime.sceneGraphService.dirtifyToRoot(object);
7079
7174
  }
7080
7175
  };
7176
+ DefaultStyleValueRegistry.prototype.updateSizeAttenuation = function (node, zoom) {
7177
+ if (node.style.isSizeAttenuation) {
7178
+ if (!node.style.rawLineWidth) {
7179
+ node.style.rawLineWidth = node.style.lineWidth;
7180
+ }
7181
+ node.style.lineWidth = node.style.rawLineWidth / zoom;
7182
+ if (node.nodeName === Shape.CIRCLE) {
7183
+ if (!node.style.rawR) {
7184
+ node.style.rawR = node.style.r;
7185
+ }
7186
+ node.style.r = node.style.rawR / zoom;
7187
+ }
7188
+ }
7189
+ else {
7190
+ if (node.style.rawLineWidth) {
7191
+ node.style.lineWidth = node.style.rawLineWidth;
7192
+ delete node.style.rawLineWidth;
7193
+ }
7194
+ if (node.nodeName === Shape.CIRCLE) {
7195
+ if (node.style.rawR) {
7196
+ node.style.r = node.style.rawR;
7197
+ delete node.style.rawR;
7198
+ }
7199
+ }
7200
+ }
7201
+ };
7081
7202
  DefaultStyleValueRegistry.prototype.isPropertyInheritable = function (name) {
7082
7203
  var metadata = propertyMetadataCache[name];
7083
7204
  if (!metadata) {
@@ -7091,6 +7212,7 @@ var DefaultStyleValueRegistry = /** @class */ (function () {
7091
7212
  var CSSPropertyAngle = /** @class */ (function () {
7092
7213
  function CSSPropertyAngle() {
7093
7214
  this.parser = parseAngle;
7215
+ this.parserUnmemoize = parseAngleUnmemoize;
7094
7216
  this.parserWithCSSDisabled = null;
7095
7217
  this.mixer = mergeNumbers;
7096
7218
  }
@@ -7165,6 +7287,7 @@ function getFontSize(object) {
7165
7287
  var CSSPropertyLengthOrPercentage = /** @class */ (function () {
7166
7288
  function CSSPropertyLengthOrPercentage() {
7167
7289
  this.parser = parseLengthOrPercentage;
7290
+ this.parserUnmemoize = parseLengthOrPercentageUnmemoize;
7168
7291
  this.parserWithCSSDisabled = null;
7169
7292
  this.mixer = mergeNumbers;
7170
7293
  }
@@ -7486,6 +7609,7 @@ var CSSPropertyNumber = /** @class */ (function () {
7486
7609
  function CSSPropertyNumber() {
7487
7610
  this.mixer = mergeNumbers;
7488
7611
  this.parser = parseNumber;
7612
+ this.parserUnmemoize = parseNumberUnmemoize;
7489
7613
  this.parserWithCSSDisabled = null;
7490
7614
  }
7491
7615
  CSSPropertyNumber.prototype.calculator = function (name, oldParsed, computed) {
@@ -7497,6 +7621,7 @@ var CSSPropertyNumber = /** @class */ (function () {
7497
7621
  var CSSPropertyOffsetDistance = /** @class */ (function () {
7498
7622
  function CSSPropertyOffsetDistance() {
7499
7623
  this.parser = parseNumber;
7624
+ this.parserUnmemoize = parseNumberUnmemoize;
7500
7625
  this.parserWithCSSDisabled = null;
7501
7626
  this.mixer = clampedMergeNumbers(0, 1);
7502
7627
  }
@@ -7530,6 +7655,7 @@ var CSSPropertyOffsetDistance = /** @class */ (function () {
7530
7655
  var CSSPropertyOpacity = /** @class */ (function () {
7531
7656
  function CSSPropertyOpacity() {
7532
7657
  this.parser = parseNumber;
7658
+ this.parserUnmemoize = parseNumberUnmemoize;
7533
7659
  this.parserWithCSSDisabled = null;
7534
7660
  this.mixer = clampedMergeNumbers(0, 1);
7535
7661
  }
@@ -8036,7 +8162,8 @@ function toFontString(attributes) {
8036
8162
  var CSSPropertyTransform = /** @class */ (function () {
8037
8163
  function CSSPropertyTransform() {
8038
8164
  this.parser = parseTransform;
8039
- this.parserWithCSSDisabled = parseTransform;
8165
+ this.parserUnmemoize = parseTransformUnmemoize;
8166
+ this.parserWithCSSDisabled = parseTransformUnmemoize;
8040
8167
  this.mixer = mergeTransforms;
8041
8168
  }
8042
8169
  CSSPropertyTransform.prototype.calculator = function (name, oldParsed, parsed, object) {
@@ -8061,6 +8188,7 @@ var CSSPropertyTransform = /** @class */ (function () {
8061
8188
  var CSSPropertyTransformOrigin = /** @class */ (function () {
8062
8189
  function CSSPropertyTransformOrigin() {
8063
8190
  this.parser = parseTransformOrigin;
8191
+ this.parserUnmemoize = parseTransformOriginUnmemoize;
8064
8192
  // calculator(
8065
8193
  // name: string,
8066
8194
  // oldParsed: [CSSUnitValue, CSSUnitValue],
@@ -8078,6 +8206,7 @@ var CSSPropertyTransformOrigin = /** @class */ (function () {
8078
8206
  var CSSPropertyZIndex = /** @class */ (function () {
8079
8207
  function CSSPropertyZIndex() {
8080
8208
  this.parser = parseNumber;
8209
+ this.parserUnmemoize = parseNumberUnmemoize;
8081
8210
  }
8082
8211
  CSSPropertyZIndex.prototype.calculator = function (name, oldParsed, computed, object) {
8083
8212
  return computed.value;
@@ -11631,6 +11760,7 @@ runtime.globalThis = getGlobalThis();
11631
11760
  runtime.enableCSSParsing = true;
11632
11761
  runtime.enableDataset = false;
11633
11762
  runtime.enableStyleSyntax = true;
11763
+ runtime.enableSizeAttenuation = false;
11634
11764
 
11635
11765
  var entityCounter = 0;
11636
11766
  function resetEntityCounter() {
@@ -12486,15 +12616,16 @@ var DisplayObject = /** @class */ (function (_super) {
12486
12616
  // redraw at next frame
12487
12617
  renderable.dirty = true;
12488
12618
  };
12489
- DisplayObject.prototype.setAttribute = function (name, value, force) {
12619
+ DisplayObject.prototype.setAttribute = function (name, value, force, memoize) {
12490
12620
  if (force === void 0) { force = false; }
12621
+ if (memoize === void 0) { memoize = true; }
12491
12622
  var attributeName = formatAttributeName(name);
12492
12623
  // ignore undefined value
12493
12624
  if (isUndefined(value)) {
12494
12625
  return;
12495
12626
  }
12496
12627
  if (force || value !== this.attributes[attributeName]) {
12497
- this.internalSetAttribute(attributeName, value);
12628
+ this.internalSetAttribute(attributeName, value, { memoize: memoize });
12498
12629
  _super.prototype.setAttribute.call(this, attributeName, value);
12499
12630
  }
12500
12631
  };
@@ -14769,6 +14900,9 @@ var PrepareRendererPlugin = /** @class */ (function () {
14769
14900
  };
14770
14901
  var handleMounted = function (e) {
14771
14902
  var object = e.target;
14903
+ if (runtime.enableSizeAttenuation) {
14904
+ runtime.styleValueRegistry.updateSizeAttenuation(object, canvas.getCamera().getZoom());
14905
+ }
14772
14906
  if (runtime.enableCSSParsing) {
14773
14907
  // recalc style values
14774
14908
  runtime.styleValueRegistry.recalc(object);
@@ -15011,10 +15145,20 @@ var Canvas = /** @class */ (function (_super) {
15011
15145
  // redraw when camera changed
15012
15146
  camera.eventEmitter.on(CameraEvent.UPDATED, function () {
15013
15147
  _this.context.renderingContext.renderReasons.add(RenderReason.CAMERA_CHANGED);
15148
+ if (runtime.enableSizeAttenuation &&
15149
+ _this.getConfig().renderer.getConfig().enableSizeAttenuation) {
15150
+ _this.updateSizeAttenuation();
15151
+ }
15014
15152
  });
15015
15153
  // bind camera
15016
15154
  this.context.camera = camera;
15017
15155
  };
15156
+ Canvas.prototype.updateSizeAttenuation = function () {
15157
+ var zoom = this.getCamera().getZoom();
15158
+ this.document.documentElement.forEach(function (node) {
15159
+ runtime.styleValueRegistry.updateSizeAttenuation(node, zoom);
15160
+ });
15161
+ };
15018
15162
  Canvas.prototype.getConfig = function () {
15019
15163
  return this.context.config;
15020
15164
  };