@visactor/vtable-plugins 1.19.9 → 1.19.10-alpha.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.
@@ -742,7 +742,15 @@
742
742
  const EnvContribution = Symbol.for("EnvContribution");
743
743
  const VGlobal = Symbol.for("VGlobal");
744
744
 
745
- class Application {}
745
+ const container = new Container();
746
+
747
+ const RenderService = Symbol.for("RenderService");
748
+
749
+ class Application {
750
+ get renderService() {
751
+ return this._renderService || (this._renderService = container.get(RenderService)), this._renderService;
752
+ }
753
+ }
746
754
  const application = new Application();
747
755
 
748
756
  let idx = 0;
@@ -4084,7 +4092,8 @@
4084
4092
  y1: 0,
4085
4093
  strokeBoundsBuffer: 0,
4086
4094
  cornerRadius: 0,
4087
- cornerType: "round"
4095
+ cornerType: "round",
4096
+ drawStrokeWhenZeroWH: !1
4088
4097
  });
4089
4098
  Object.assign(Object.assign({}, DefaultAttribute), {
4090
4099
  width: 0,
@@ -4093,7 +4102,8 @@
4093
4102
  y1: 0,
4094
4103
  cornerRadius: 0,
4095
4104
  length: 0,
4096
- cornerType: "round"
4105
+ cornerType: "round",
4106
+ drawStrokeWhenZeroWH: !1
4097
4107
  });
4098
4108
  const DefaultSymbolAttribute = Object.assign(Object.assign({}, DefaultAttribute), {
4099
4109
  symbolType: "circle",
@@ -4320,6 +4330,34 @@
4320
4330
  }
4321
4331
  return c;
4322
4332
  }
4333
+ static processColorStops(colorStops) {
4334
+ if (!colorStops || 0 === colorStops.length) return [];
4335
+ if (colorStops.some(item => item.length)) {
4336
+ const stops = colorStops.map(item => ({
4337
+ color: item.value,
4338
+ offset: item.length ? parseFloat(item.length.value) / 100 : -1
4339
+ }));
4340
+ stops[0].offset < 0 && (stops[0].offset = 0), stops[stops.length - 1].offset < 0 && (stops[stops.length - 1].offset = 1);
4341
+ for (let i = 1; i < stops.length - 1; i++) if (stops[i].offset < 0) {
4342
+ const prevWithOffsetIdx = i - 1;
4343
+ let nextWithOffsetIdx = i + 1;
4344
+ for (; nextWithOffsetIdx < stops.length && stops[nextWithOffsetIdx].offset < 0;) nextWithOffsetIdx++;
4345
+ const startOffset = stops[prevWithOffsetIdx].offset,
4346
+ endOffset = stops[nextWithOffsetIdx].offset,
4347
+ unspecCount = nextWithOffsetIdx - prevWithOffsetIdx;
4348
+ for (let j = 1; j < unspecCount; j++) stops[prevWithOffsetIdx + j].offset = startOffset + (endOffset - startOffset) * j / unspecCount;
4349
+ i = nextWithOffsetIdx - 1;
4350
+ }
4351
+ return stops;
4352
+ }
4353
+ return colorStops.map((item, index) => {
4354
+ const offset = colorStops.length > 1 ? index / (colorStops.length - 1) : 0;
4355
+ return {
4356
+ color: item.value,
4357
+ offset: offset
4358
+ };
4359
+ });
4360
+ }
4323
4361
  static ParseConic(datum) {
4324
4362
  const {
4325
4363
  orientation: orientation,
@@ -4333,10 +4371,7 @@
4333
4371
  y: .5,
4334
4372
  startAngle: sa,
4335
4373
  endAngle: sa + pi2,
4336
- stops: colorStops.map(item => ({
4337
- color: item.value,
4338
- offset: parseFloat(item.length.value) / 100
4339
- }))
4374
+ stops: GradientParser.processColorStops(colorStops)
4340
4375
  };
4341
4376
  }
4342
4377
  static ParseRadial(datum) {
@@ -4351,10 +4386,7 @@
4351
4386
  y1: .5,
4352
4387
  r0: 0,
4353
4388
  r1: 1,
4354
- stops: colorStops.map(item => ({
4355
- color: item.value,
4356
- offset: parseFloat(item.length.value) / 100
4357
- }))
4389
+ stops: GradientParser.processColorStops(colorStops)
4358
4390
  };
4359
4391
  }
4360
4392
  static ParseLinear(datum) {
@@ -4376,10 +4408,7 @@
4376
4408
  y0: y0,
4377
4409
  x1: x1,
4378
4410
  y1: y1,
4379
- stops: colorStops.map(item => ({
4380
- color: item.value,
4381
- offset: parseFloat(item.length.value) / 100
4382
- }))
4411
+ stops: GradientParser.processColorStops(colorStops)
4383
4412
  };
4384
4413
  }
4385
4414
  }
@@ -4463,6 +4492,9 @@
4463
4492
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4464
4493
  };
4465
4494
  let ATextMeasure = class {
4495
+ constructor() {
4496
+ this.id = "ATextMeasure";
4497
+ }
4466
4498
  configure(service, env) {
4467
4499
  this.canvas = service.canvas, this.context = service.context, service.bindTextMeasure(this);
4468
4500
  }
@@ -4855,11 +4887,13 @@
4855
4887
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4856
4888
  };
4857
4889
  const TextMeasureContribution = Symbol.for("TextMeasureContribution");
4858
- let DefaultTextMeasureContribution = class extends ATextMeasure {};
4890
+ let DefaultTextMeasureContribution = class extends ATextMeasure {
4891
+ constructor() {
4892
+ super(...arguments), this.id = "DefaultTextMeasureContribution";
4893
+ }
4894
+ };
4859
4895
  DefaultTextMeasureContribution = __decorate$t([injectable()], DefaultTextMeasureContribution);
4860
4896
 
4861
- const container = new Container();
4862
-
4863
4897
  const CanvasFactory = Symbol.for("CanvasFactory");
4864
4898
 
4865
4899
  function wrapCanvas(params) {
@@ -5438,13 +5472,17 @@
5438
5472
  return this.tryInitCanvas(), this._context;
5439
5473
  }
5440
5474
  constructor(contributions) {
5441
- this.contributions = contributions, this.configured = !1, this.global = application.global, this.global.hooks.onSetEnv.tap("graphic-util", (lastEnv, env, global) => {
5475
+ this.contributions = contributions, this.configured = !1, this.global = application.global, this._textMeasureMap = new Map(), this.global.hooks.onSetEnv.tap("graphic-util", (lastEnv, env, global) => {
5442
5476
  this.configured = !1, this.configure(global, env);
5443
5477
  });
5444
5478
  }
5445
5479
  get textMeasure() {
5446
5480
  return this._textMeasure || this.configure(this.global, this.global.env), this._textMeasure;
5447
5481
  }
5482
+ getTextMeasureInstance(textMeasureId) {
5483
+ if (!textMeasureId) return this.textMeasure;
5484
+ return this._textMeasureMap.get(textMeasureId) || this.textMeasure;
5485
+ }
5448
5486
  configure(global, env) {
5449
5487
  this.configured || (this.contributions.getContributions().forEach(contribution => {
5450
5488
  contribution.configure(this, env);
@@ -5457,7 +5495,7 @@
5457
5495
  }
5458
5496
  }
5459
5497
  bindTextMeasure(tm) {
5460
- this._textMeasure = tm;
5498
+ this._textMeasure && "DefaultTextMeasureContribution" !== tm.id || (this._textMeasure = tm), this._textMeasureMap.has(tm.id) || this._textMeasureMap.set(tm.id, tm);
5461
5499
  }
5462
5500
  measureText(text, tc, method = "native") {
5463
5501
  var _a;
@@ -8241,7 +8279,7 @@
8241
8279
  });
8242
8280
  }
8243
8281
  setAttributes(params, forceUpdateTag = !1, context) {
8244
- (params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params).background ? this.loadImage(params.background, !0) : params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._setAttributes(params, forceUpdateTag, context);
8282
+ params && ((params = this.onBeforeAttributeUpdate && this.onBeforeAttributeUpdate(params, this.attribute, null, context) || params).background ? this.loadImage(params.background, !0) : params.shadowGraphic && this.setShadowGraphic(params.shadowGraphic), this._setAttributes(params, forceUpdateTag, context));
8245
8283
  }
8246
8284
  _setAttributes(params, forceUpdateTag = !1, context) {
8247
8285
  const keys = Object.keys(params);
@@ -9066,8 +9104,8 @@
9066
9104
  function strokeVisible(opacity, strokeOpacity) {
9067
9105
  return opacity * strokeOpacity > 0;
9068
9106
  }
9069
- function rectStrokeVisible(opacity, strokeOpacity, width, height) {
9070
- return opacity * strokeOpacity > 0 && 0 !== width && 0 !== height;
9107
+ function rectStrokeVisible(opacity, strokeOpacity, width, height, drawStrokeWhenZeroWH) {
9108
+ return drawStrokeWhenZeroWH ? opacity * strokeOpacity > 0 : opacity * strokeOpacity > 0 && 0 !== width && 0 !== height;
9071
9109
  }
9072
9110
 
9073
9111
  const AreaRenderContribution = Symbol.for("AreaRenderContribution");
@@ -9488,7 +9526,7 @@
9488
9526
  this.cache.layoutData.lines.forEach(item => {
9489
9527
  mergedText += item.str;
9490
9528
  });
9491
- return (Array.isArray(text) ? text.join("") : text) !== mergedText;
9529
+ return (Array.isArray(text) ? text.join("") : text).toString() !== mergedText;
9492
9530
  }
9493
9531
  return "vertical" === attribute.direction && this.cache.verticalList && this.cache.verticalList[0] ? this.cache.verticalList[0].map(item => item.text).join("") !== attribute.text.toString() : null != this.clipedText && this.clipedText !== attribute.text.toString();
9494
9532
  }
@@ -9587,7 +9625,7 @@
9587
9625
  return fontSize ? .1 * fontSize : 0;
9588
9626
  }
9589
9627
  updateHorizontalMultilineAABBBounds(text) {
9590
- var _a;
9628
+ var _a, _b;
9591
9629
  const textTheme = this.getGraphicTheme(),
9592
9630
  attribute = this.attribute,
9593
9631
  {
@@ -9614,7 +9652,7 @@
9614
9652
  const bbox = this.cache.layoutData.bbox;
9615
9653
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9616
9654
  }
9617
- const textMeasure = application.graphicUtil.textMeasure,
9655
+ const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || (null === (_b = this.stage) || void 0 === _b ? void 0 : _b.textMeasureId)),
9618
9656
  layoutData = new CanvasTextLayout(fontFamily, {
9619
9657
  fontSize: fontSize,
9620
9658
  fontWeight: fontWeight,
@@ -9632,7 +9670,7 @@
9632
9670
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9633
9671
  }
9634
9672
  updateWrapAABBBounds(text) {
9635
- var _a, _b, _c;
9673
+ var _a, _b, _c, _d;
9636
9674
  const textTheme = this.getGraphicTheme(),
9637
9675
  {
9638
9676
  fontFamily = textTheme.fontFamily,
@@ -9658,7 +9696,7 @@
9658
9696
  const bbox = this.cache.layoutData.bbox;
9659
9697
  return this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9660
9698
  }
9661
- const textMeasure = application.graphicUtil.textMeasure,
9699
+ const textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || (null === (_b = this.stage) || void 0 === _b ? void 0 : _b.textMeasureId)),
9662
9700
  textOptions = {
9663
9701
  fontSize: fontSize,
9664
9702
  fontWeight: fontWeight,
@@ -9690,7 +9728,7 @@
9690
9728
  if ("" !== str && "" === clip.str || clip.wordBreaked) {
9691
9729
  if (ellipsis) {
9692
9730
  const clipEllipsis = textMeasure.clipTextWithSuffix(str, textOptions, maxLineWidth, ellipsis, !1, suffixPosition);
9693
- clip.str = null !== (_b = clipEllipsis.str) && void 0 !== _b ? _b : "", clip.width = null !== (_c = clipEllipsis.width) && void 0 !== _c ? _c : 0;
9731
+ clip.str = null !== (_c = clipEllipsis.str) && void 0 !== _c ? _c : "", clip.width = null !== (_d = clipEllipsis.width) && void 0 !== _d ? _d : 0;
9694
9732
  } else clip.str = "", clip.width = 0;
9695
9733
  needCut = !1;
9696
9734
  }
@@ -9753,9 +9791,9 @@
9753
9791
  return this.cache.layoutData = layoutData, this.clearUpdateShapeTag(), this._AABBBounds.set(bbox.xOffset, bbox.yOffset, bbox.xOffset + bbox.width, bbox.yOffset + bbox.height), stroke && this._AABBBounds.expand(lineWidth / 2), this._AABBBounds;
9754
9792
  }
9755
9793
  updateVerticalMultilineAABBBounds(text) {
9756
- var _a, _b;
9794
+ var _a, _b, _c;
9757
9795
  const textTheme = this.getGraphicTheme(),
9758
- textMeasure = application.graphicUtil.textMeasure;
9796
+ textMeasure = application.graphicUtil.getTextMeasureInstance(this.textMeasureId || (null === (_a = this.stage) || void 0 === _a ? void 0 : _a.textMeasureId));
9759
9797
  let width;
9760
9798
  const attribute = this.attribute,
9761
9799
  {
@@ -9776,7 +9814,7 @@
9776
9814
  } = attribute;
9777
9815
  if (!verticalMode) {
9778
9816
  const t = textAlign;
9779
- textAlign = null !== (_a = Text.baselineMapAlign[textBaseline]) && void 0 !== _a ? _a : "left", textBaseline = null !== (_b = Text.alignMapBaseline[t]) && void 0 !== _b ? _b : "top";
9817
+ textAlign = null !== (_b = Text.baselineMapAlign[textBaseline]) && void 0 !== _b ? _b : "left", textBaseline = null !== (_c = Text.alignMapBaseline[t]) && void 0 !== _c ? _c : "top";
9780
9818
  }
9781
9819
  if (width = 0, !this.shouldUpdateShape() && this.cache) {
9782
9820
  this.cache.verticalList.forEach(item => {
@@ -11761,7 +11799,8 @@
11761
11799
  y1: y1,
11762
11800
  x: originX = rectAttribute.x,
11763
11801
  y: originY = rectAttribute.y,
11764
- fillStrokeOrder = rectAttribute.fillStrokeOrder
11802
+ fillStrokeOrder = rectAttribute.fillStrokeOrder,
11803
+ drawStrokeWhenZeroWH = rectAttribute.drawStrokeWhenZeroWH
11765
11804
  } = rect.attribute;
11766
11805
  let {
11767
11806
  width: width,
@@ -11769,7 +11808,7 @@
11769
11808
  } = rect.attribute;
11770
11809
  width = (null != width ? width : x1 - originX) || 0, height = (null != height ? height : y1 - originY) || 0;
11771
11810
  const fVisible = rectFillVisible(opacity, fillOpacity, width, height, fill),
11772
- sVisible = rectStrokeVisible(opacity, strokeOpacity, width, height),
11811
+ sVisible = rectStrokeVisible(opacity, strokeOpacity, width, height, drawStrokeWhenZeroWH),
11773
11812
  doFill = runFill(fill, background),
11774
11813
  doStroke = runStroke(stroke, lineWidth);
11775
11814
  if (!rect.valid || !visible) return;
@@ -12491,7 +12530,6 @@
12491
12530
  decorator(target, key, paramIndex);
12492
12531
  };
12493
12532
  };
12494
- const RenderService = Symbol.for("RenderService");
12495
12533
  let DefaultRenderService = class {
12496
12534
  constructor(drawContribution) {
12497
12535
  this.drawContribution = drawContribution;
@@ -13380,8 +13418,6 @@
13380
13418
  application.transformUtil = transformUtil;
13381
13419
  const graphicService = container.get(GraphicService);
13382
13420
  application.graphicService = graphicService;
13383
- const renderService = container.get(RenderService);
13384
- application.renderService = renderService;
13385
13421
  const layerService = container.get(LayerService);
13386
13422
  application.layerService = layerService;
13387
13423
 
@@ -13629,13 +13665,13 @@
13629
13665
  this._skipRender > 1 && this.renderNextFrame(), this._skipRender = 0;
13630
13666
  } else this._skipRender = 1;
13631
13667
  }, this.beforeRender = stage => {
13632
- this._beforeRender && this._beforeRender(stage);
13668
+ this._beforeRenderList.forEach(cb => cb(stage));
13633
13669
  }, this.afterClearScreen = drawParams => {
13634
13670
  this._afterClearScreen && this._afterClearScreen(drawParams);
13635
13671
  }, this.afterClearRect = drawParams => {
13636
13672
  this._afterClearRect && this._afterClearRect(drawParams);
13637
13673
  }, this.afterRender = stage => {
13638
- this.renderCount++, this._afterRender && this._afterRender(stage), this._afterNextRenderCbs && this._afterNextRenderCbs.forEach(cb => cb(stage)), this._afterNextRenderCbs = null, this.tickedBeforeRender = !1;
13674
+ this.renderCount++, this._afterRenderList.forEach(cb => cb(stage)), this._afterNextRenderCbs && this._afterNextRenderCbs.forEach(cb => cb(stage)), this._afterNextRenderCbs = null, this.tickedBeforeRender = !1;
13639
13675
  }, this.afterTickCb = () => {
13640
13676
  this.tickedBeforeRender = !0, "rendering" !== this.state && this.renderNextFrame();
13641
13677
  }, this.params = params, this.theme = new Theme(), this.hooks = {
@@ -13643,7 +13679,7 @@
13643
13679
  afterRender: new SyncHook(["stage"]),
13644
13680
  afterClearScreen: new SyncHook(["stage"]),
13645
13681
  afterClearRect: new SyncHook(["stage"])
13646
- }, this.global = application.global, !this.global.env && isBrowserEnv() && this.global.setEnv("browser"), this.window = container.get(VWindow), this.renderService = container.get(RenderService), this.pluginService = container.get(PluginService), this.layerService = container.get(LayerService), this.graphicService = container.get(GraphicService), this.pluginService.active(this, params), this.window.create({
13682
+ }, this.global = application.global, !this.global.env && isBrowserEnv() && this.global.setEnv("browser"), this.window = container.get(VWindow), this.renderService = container.get(RenderService), this.pluginService = container.get(PluginService), this.layerService = container.get(LayerService), this.graphicService = container.get(GraphicService), this.pluginService.active(this, params), this._beforeRenderList = [], this._afterRenderList = [], this.window.create({
13647
13683
  width: params.width,
13648
13684
  height: params.height,
13649
13685
  viewBox: params.viewBox,
@@ -13654,7 +13690,7 @@
13654
13690
  canvas: params.canvas
13655
13691
  }), this.state = "normal", this.renderCount = 0, this.tryInitEventSystem(), this._background = null !== (_a = params.background) && void 0 !== _a ? _a : DefaultConfig.BACKGROUND, this.appendChild(this.layerService.createLayer(this, {
13656
13692
  main: !0
13657
- })), this.nextFrameRenderLayerSet = new Set(), this.willNextFrameRender = !1, this.stage = this, this.renderStyle = params.renderStyle, params.autoRender && this.enableAutoRender(), params.autoRefresh && this.enableAutoRefresh(), !1 === params.disableDirtyBounds && this.enableDirtyBounds(), params.enableHtmlAttribute && this.enableHtmlAttribute(params.enableHtmlAttribute), params.ReactDOM && this.enableReactAttribute(params.ReactDOM), params.enableLayout && this.enableLayout(), this.hooks.beforeRender.tap("constructor", this.beforeRender), this.hooks.afterRender.tap("constructor", this.afterRender), this.hooks.afterClearScreen.tap("constructor", this.afterClearScreen), this.hooks.afterClearRect.tap("constructor", this.afterClearRect), this._beforeRender = params.beforeRender, this._afterRender = params.afterRender, this._afterClearScreen = params.afterClearScreen, this._afterClearRect = params.afterClearRect, this.supportInteractiveLayer = !1 !== params.interactiveLayer, params.optimize || (params.optimize = {
13693
+ })), this.nextFrameRenderLayerSet = new Set(), this.willNextFrameRender = !1, this.stage = this, this.renderStyle = params.renderStyle, params.autoRender && this.enableAutoRender(), params.autoRefresh && this.enableAutoRefresh(), !1 === params.disableDirtyBounds && this.enableDirtyBounds(), params.enableHtmlAttribute && this.enableHtmlAttribute(params.enableHtmlAttribute), params.ReactDOM && this.enableReactAttribute(params.ReactDOM), params.enableLayout && this.enableLayout(), this.hooks.beforeRender.tap("constructor", this.beforeRender), this.hooks.afterRender.tap("constructor", this.afterRender), params.beforeRender && this._beforeRenderList.push(params.beforeRender), params.afterRender && this._afterRenderList.push(params.afterRender), this.hooks.afterClearScreen.tap("constructor", this.afterClearScreen), this.hooks.afterClearRect.tap("constructor", this.afterClearRect), this._afterClearScreen = params.afterClearScreen, this._afterClearRect = params.afterClearRect, this.supportInteractiveLayer = !1 !== params.interactiveLayer, params.optimize || (params.optimize = {
13658
13694
  tickRenderMode: "effect"
13659
13695
  }), this.optmize(params.optimize), params.background && isString$3(this._background) && this._background.includes("/") && this.setAttributes({
13660
13696
  background: this._background
@@ -13769,10 +13805,16 @@
13769
13805
  options.enableView3dTransform && this.enableView3dTransform();
13770
13806
  }
13771
13807
  setBeforeRender(cb) {
13772
- this._beforeRender = cb;
13808
+ this._beforeRenderList.push(cb);
13809
+ }
13810
+ removeBeforeRender(cb) {
13811
+ this._beforeRenderList = this._beforeRenderList.filter(c => c !== cb);
13773
13812
  }
13774
13813
  setAfterRender(cb) {
13775
- this._afterRender = cb;
13814
+ this._afterRenderList.push(cb);
13815
+ }
13816
+ removeAfterRender(cb) {
13817
+ this._afterRenderList = this._afterRenderList.filter(c => c !== cb);
13776
13818
  }
13777
13819
  afterNextRender(cb) {
13778
13820
  this._afterNextRenderCbs || (this._afterNextRenderCbs = []), this._afterNextRenderCbs.push(cb);