@visactor/vrender 0.21.2 → 0.21.3

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.js CHANGED
@@ -591,6 +591,31 @@
591
591
  return function (target, key) {
592
592
  decorator(target, key, paramIndex);
593
593
  };
594
+ },
595
+ __awaiter$8 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
596
+ return new (P || (P = Promise))(function (resolve, reject) {
597
+ function fulfilled(value) {
598
+ try {
599
+ step(generator.next(value));
600
+ } catch (e) {
601
+ reject(e);
602
+ }
603
+ }
604
+ function rejected(value) {
605
+ try {
606
+ step(generator.throw(value));
607
+ } catch (e) {
608
+ reject(e);
609
+ }
610
+ }
611
+ function step(result) {
612
+ var value;
613
+ result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P(function (resolve) {
614
+ resolve(value);
615
+ })).then(fulfilled, rejected);
616
+ }
617
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
618
+ });
594
619
  };
595
620
  exports.DefaultGlobal = class DefaultGlobal {
596
621
  get env() {
@@ -716,6 +741,11 @@
716
741
  loadBlob(url) {
717
742
  return this._env || this.setEnv("browser"), this.envContribution.loadBlob(url);
718
743
  }
744
+ loadFont(name, source, descriptors) {
745
+ return __awaiter$8(this, void 0, void 0, function* () {
746
+ return this._env || this.setEnv("browser"), this.envContribution.loadFont(name, source, descriptors);
747
+ });
748
+ }
719
749
  isChrome() {
720
750
  return null != this._isChrome || (this._env || this.setEnv("browser"), this._isChrome = "browser" === this._env && navigator.userAgent.indexOf("Chrome") > -1), this._isChrome;
721
751
  }
@@ -5795,7 +5825,7 @@
5795
5825
  return null;
5796
5826
  }
5797
5827
 
5798
- var __awaiter$5 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
5828
+ var __awaiter$7 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
5799
5829
  return new (P || (P = Promise))(function (resolve, reject) {
5800
5830
  function fulfilled(value) {
5801
5831
  try {
@@ -5865,7 +5895,7 @@
5865
5895
  }
5866
5896
  forEachChildrenAsync(cb) {
5867
5897
  let reverse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
5868
- return __awaiter$5(this, void 0, void 0, function* () {
5898
+ return __awaiter$7(this, void 0, void 0, function* () {
5869
5899
  if (reverse) {
5870
5900
  let child = this._lastChild,
5871
5901
  i = 0;
@@ -10473,7 +10503,7 @@
10473
10503
  return str.startsWith("<");
10474
10504
  }
10475
10505
 
10476
- var __awaiter$4 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
10506
+ var __awaiter$6 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
10477
10507
  return new (P || (P = Promise))(function (resolve, reject) {
10478
10508
  function fulfilled(value) {
10479
10509
  try {
@@ -10502,7 +10532,7 @@
10502
10532
  group.incrementalAppendChild(graphic);
10503
10533
  }
10504
10534
  function waitForAllSubLayers(stage) {
10505
- return __awaiter$4(this, void 0, void 0, function* () {
10535
+ return __awaiter$6(this, void 0, void 0, function* () {
10506
10536
  const promiseList = [],
10507
10537
  layers = stage.getChildren();
10508
10538
  yield new Promise(resolve => {
@@ -12451,7 +12481,9 @@
12451
12481
  const {
12452
12482
  background: background,
12453
12483
  backgroundMode = graphicAttribute.backgroundMode,
12454
- backgroundFit = graphicAttribute.backgroundFit
12484
+ backgroundFit = graphicAttribute.backgroundFit,
12485
+ width: width,
12486
+ height: height
12455
12487
  } = graphic.attribute;
12456
12488
  if (background) if (graphic.backgroundImg) {
12457
12489
  const res = graphic.resources.get(background);
@@ -12484,11 +12516,7 @@
12484
12516
  height: height
12485
12517
  } = getActualPosition(graphic);
12486
12518
  cornerRadius ? createRectPath(context, x - expandX, y - expandY, width + 2 * expandX, height + 2 * expandY, cornerRadius) : context.rect(x - expandX, y - expandY, width + 2 * expandX, height + 2 * expandY), context.globalAlpha = 1, fill && (context.fillStyle = fill, context.fill()), stroke && lineWidth > 0 && (context.lineWidth = lineWidth, context.strokeStyle = stroke, context.stroke());
12487
- } else {
12488
- context.beginPath();
12489
- const b = graphic.AABBBounds;
12490
- context.rect(x, y, b.width(), b.height()), context.fillStyle = background, context.globalAlpha = 1, context.fill();
12491
- }
12519
+ } else context.beginPath(), context.rect(x, y, width || 0, height || 0), context.fillStyle = background, context.globalAlpha = 1, context.fill();
12492
12520
  }
12493
12521
  }
12494
12522
  function getActualPosition(graphic) {
@@ -14205,7 +14233,7 @@
14205
14233
  doFill: doFill,
14206
14234
  doStroke: doStroke
14207
14235
  } = data;
14208
- context.setShadowBlendStyle && context.setShadowBlendStyle(image, imageAttribute), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
14236
+ context.setShadowBlendStyle && context.setShadowBlendStyle(image, image.attribute, imageAttribute), this.beforeRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
14209
14237
  const _runFill = () => {
14210
14238
  if (doFill) if (fillCb) fillCb(context, image.attribute, imageAttribute);else if (fVisible) {
14211
14239
  if (!url || !image.resources) return;
@@ -14222,7 +14250,7 @@
14222
14250
  }
14223
14251
  },
14224
14252
  _runStroke = () => {
14225
- doStroke && (strokeCb ? strokeCb(context, image.attribute, imageAttribute) : sVisible && (context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute), context.stroke()));
14253
+ doStroke && (strokeCb ? strokeCb(context, image.attribute, imageAttribute) : sVisible && (context.setStrokeStyle(image, image.attribute, originX - x, originY - y, imageAttribute), context.strokeRect(x, y, width, height)));
14226
14254
  };
14227
14255
  fillStrokeOrder ? (_runStroke(), _runFill()) : (_runFill(), _runStroke()), this.afterRenderStep(image, context, x, y, doFill, !1, fVisible, !1, imageAttribute, drawContext, fillCb);
14228
14256
  }
@@ -17841,7 +17869,7 @@
17841
17869
  container.load(envModules), container.load(textMeasureModules), container.load(layerHandlerModules);
17842
17870
  }
17843
17871
 
17844
- var __awaiter$3 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
17872
+ var __awaiter$5 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
17845
17873
  return new (P || (P = Promise))(function (resolve, reject) {
17846
17874
  function fulfilled(value) {
17847
17875
  try {
@@ -17914,7 +17942,7 @@
17914
17942
  }
17915
17943
  function foreachAsync(graphic, defaultZIndex, cb) {
17916
17944
  let reverse = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : !1;
17917
- return __awaiter$3(this, void 0, void 0, function* () {
17945
+ return __awaiter$5(this, void 0, void 0, function* () {
17918
17946
  yield graphic.forEachChildrenAsync(cb, reverse);
17919
17947
  });
17920
17948
  }
@@ -18275,7 +18303,7 @@
18275
18303
  decorator(target, key, paramIndex);
18276
18304
  };
18277
18305
  },
18278
- __awaiter$2 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
18306
+ __awaiter$4 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
18279
18307
  return new (P || (P = Promise))(function (resolve, reject) {
18280
18308
  function fulfilled(value) {
18281
18309
  try {
@@ -18310,7 +18338,7 @@
18310
18338
  }, this.defaultRenderMap.set(this.lineRender.numberType, this.lineRender), this.defaultRenderMap.set(this.areaRender.numberType, this.areaRender);
18311
18339
  }
18312
18340
  draw(renderService, drawContext) {
18313
- return __awaiter$2(this, void 0, void 0, function* () {
18341
+ return __awaiter$4(this, void 0, void 0, function* () {
18314
18342
  if (this.checkingForDrawPromise) return;
18315
18343
  this.lastRenderService = renderService, this.lastDrawContext = drawContext, this.checkingForDrawPromise = this.checkForDraw(drawContext);
18316
18344
  const skipDraw = yield this.checkingForDrawPromise;
@@ -18331,15 +18359,15 @@
18331
18359
  });
18332
18360
  }
18333
18361
  _increaseRender(group, drawContext) {
18334
- return __awaiter$2(this, void 0, void 0, function* () {
18362
+ return __awaiter$4(this, void 0, void 0, function* () {
18335
18363
  this.rendering = !0, yield this._renderIncrementalGroup(group, drawContext);
18336
18364
  });
18337
18365
  }
18338
18366
  _renderIncrementalGroup(group, drawContext) {
18339
- return __awaiter$2(this, void 0, void 0, function* () {
18367
+ return __awaiter$4(this, void 0, void 0, function* () {
18340
18368
  this.count = group.count, yield new Promise(resolve => {
18341
18369
  this.renderItem(group, drawContext, {
18342
- drawingCb: () => __awaiter$2(this, void 0, void 0, function* () {
18370
+ drawingCb: () => __awaiter$4(this, void 0, void 0, function* () {
18343
18371
  if (2 !== group.count) yield foreachAsync(group, DefaultAttribute.zIndex, (item, i) => {
18344
18372
  if (this.status === STATUS.STOP) return !0;
18345
18373
  if (item.isContainer) return !1;
@@ -18360,7 +18388,7 @@
18360
18388
  });
18361
18389
  }
18362
18390
  waitToNextFrame() {
18363
- return __awaiter$2(this, void 0, void 0, function* () {
18391
+ return __awaiter$4(this, void 0, void 0, function* () {
18364
18392
  return new Promise(resolve => {
18365
18393
  this.global.getRequestAnimationFrame()(() => {
18366
18394
  resolve(!1);
@@ -18369,13 +18397,13 @@
18369
18397
  });
18370
18398
  }
18371
18399
  checkForDraw(drawContext) {
18372
- return __awaiter$2(this, void 0, void 0, function* () {
18400
+ return __awaiter$4(this, void 0, void 0, function* () {
18373
18401
  let skip = this.rendering;
18374
18402
  return drawContext.restartIncremental && (skip = !1, yield this.forceStop(), this.resetToInit()), skip;
18375
18403
  });
18376
18404
  }
18377
18405
  forceStop() {
18378
- return __awaiter$2(this, void 0, void 0, function* () {
18406
+ return __awaiter$4(this, void 0, void 0, function* () {
18379
18407
  this.rendering && (this.status = STATUS.STOP, yield new Promise(resolve => {
18380
18408
  this.hooks.completeDraw.tap("stopCb", () => {
18381
18409
  this.status = STATUS.NORMAL, this.hooks.completeDraw.taps = this.hooks.completeDraw.taps.filter(item => "stopCb" !== item.name), resolve(!1);
@@ -18387,11 +18415,11 @@
18387
18415
  this.currFrameStartAt = 0, this.currentIdx = 0;
18388
18416
  }
18389
18417
  renderGroup(group, drawContext) {
18390
- return __awaiter$2(this, void 0, void 0, function* () {
18418
+ return __awaiter$4(this, void 0, void 0, function* () {
18391
18419
  if (!drawContext.break && !1 !== group.attribute.visibleAll) return group.incremental && drawContext.startAtId === group._uid ? (yield this._increaseRender(group, drawContext), void (drawContext.break = !0)) : void (yield new Promise(resolve => {
18392
18420
  this.renderItem(group, drawContext, {
18393
- drawingCb: () => __awaiter$2(this, void 0, void 0, function* () {
18394
- yield foreachAsync(group, DefaultAttribute.zIndex, item => __awaiter$2(this, void 0, void 0, function* () {
18421
+ drawingCb: () => __awaiter$4(this, void 0, void 0, function* () {
18422
+ yield foreachAsync(group, DefaultAttribute.zIndex, item => __awaiter$4(this, void 0, void 0, function* () {
18395
18423
  drawContext.break || item.isContainer && (yield this.renderGroup(item, drawContext));
18396
18424
  })), resolve(!1);
18397
18425
  })
@@ -19413,12 +19441,37 @@
19413
19441
  BaseCanvas.env = "browser";
19414
19442
 
19415
19443
  var __decorate$1c = undefined && undefined.__decorate || function (decorators, target, key, desc) {
19416
- var d,
19417
- c = arguments.length,
19418
- r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
19419
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
19420
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19421
- };
19444
+ var d,
19445
+ c = arguments.length,
19446
+ r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;
19447
+ if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) (d = decorators[i]) && (r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r);
19448
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
19449
+ },
19450
+ __awaiter$3 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
19451
+ return new (P || (P = Promise))(function (resolve, reject) {
19452
+ function fulfilled(value) {
19453
+ try {
19454
+ step(generator.next(value));
19455
+ } catch (e) {
19456
+ reject(e);
19457
+ }
19458
+ }
19459
+ function rejected(value) {
19460
+ try {
19461
+ step(generator.throw(value));
19462
+ } catch (e) {
19463
+ reject(e);
19464
+ }
19465
+ }
19466
+ function step(result) {
19467
+ var value;
19468
+ result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P(function (resolve) {
19469
+ resolve(value);
19470
+ })).then(fulfilled, rejected);
19471
+ }
19472
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19473
+ });
19474
+ };
19422
19475
  exports.BaseEnvContribution = class BaseEnvContribution {
19423
19476
  configure(service) {
19424
19477
  service.env === this.type && service.setActiveEnvContribution(this);
@@ -19487,6 +19540,13 @@
19487
19540
  left: 0
19488
19541
  };
19489
19542
  }
19543
+ loadFont(font, source, descriptors) {
19544
+ return __awaiter$3(this, void 0, void 0, function* () {
19545
+ return {
19546
+ loadState: "fail"
19547
+ };
19548
+ });
19549
+ }
19490
19550
  };
19491
19551
  exports.BaseEnvContribution = __decorate$1c([injectable()], exports.BaseEnvContribution);
19492
19552
 
@@ -20497,7 +20557,7 @@
20497
20557
  const fVisible = fillVisible(opacity, fillOpacity, !0),
20498
20558
  sVisible = fillVisible(opacity, strokeOpacity, !0);
20499
20559
  if (!fVisible) return;
20500
- context.translate(x, y), this.beforeRenderStep(richtext, context, x, y, fVisible, sVisible, fVisible, sVisible, richtextAttribute, drawContext);
20560
+ context.setShadowBlendStyle && context.setShadowBlendStyle(richtext, richtext.attribute, richtextAttribute), context.translate(x, y), this.beforeRenderStep(richtext, context, x, y, fVisible, sVisible, fVisible, sVisible, richtextAttribute, drawContext);
20501
20561
  richtext.getFrameCache().draw(context, this.drawIcon), this.afterRenderStep(richtext, context, x, y, fVisible, sVisible, fVisible, sVisible, richtextAttribute, drawContext);
20502
20562
  }
20503
20563
  drawIcon(icon, context, x, y, baseline) {
@@ -20931,11 +20991,18 @@
20931
20991
 
20932
20992
  class HtmlAttributePlugin {
20933
20993
  constructor() {
20934
- this.name = "HtmlAttributePlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(), this.key = this.name + this._uid, this.htmlMap = {}, this.renderId = 0;
20994
+ this.name = "HtmlAttributePlugin", this.activeEvent = "onRegister", this._uid = Generator.GenAutoIncrementId(), this.key = this.name + this._uid, this.htmlMap = {}, this.renderId = 0, this.onWheel = ev => {
20995
+ try {
20996
+ const newEvent = new ev.constructor(ev.type, ev);
20997
+ this.pluginService.stage.window.getContext().getCanvas().nativeCanvas.dispatchEvent(newEvent);
20998
+ } catch (err) {
20999
+ return;
21000
+ }
21001
+ };
20935
21002
  }
20936
21003
  activate(context) {
20937
21004
  this.pluginService = context, context.stage.hooks.afterRender.tap(this.key, stage => {
20938
- stage && stage === this.pluginService.stage && this.drawHTML(context.stage.renderService);
21005
+ stage && stage === this.pluginService.stage && this.drawHTML([...context.stage.getChildren()]);
20939
21006
  });
20940
21007
  }
20941
21008
  deactivate(context) {
@@ -20997,10 +21064,13 @@
20997
21064
  }
20998
21065
  updateStyleOfWrapContainer(graphic, stage, wrapContainer, nativeContainer, options) {
20999
21066
  const {
21000
- pointerEvents: pointerEvents
21067
+ pointerEvents: pointerEvents,
21068
+ penetrateEventList = []
21001
21069
  } = options;
21002
21070
  let calculateStyle = this.parseDefaultStyleFromGraphic(graphic);
21003
- calculateStyle.display = !1 !== graphic.attribute.visible ? "block" : "none", calculateStyle.pointerEvents = !0 === pointerEvents ? "all" : pointerEvents || "none", wrapContainer.style.position || (wrapContainer.style.position = "absolute", nativeContainer.style.position = "relative");
21071
+ calculateStyle.display = !1 !== graphic.attribute.visible ? "block" : "none", calculateStyle.pointerEvents = !0 === pointerEvents ? "all" : pointerEvents || "none", "none" !== calculateStyle.pointerEvents && (this.removeWrapContainerEventListener(wrapContainer), penetrateEventList.forEach(event => {
21072
+ "wheel" === event && wrapContainer.addEventListener("wheel", this.onWheel);
21073
+ })), wrapContainer.style.position || (wrapContainer.style.position = "absolute", nativeContainer.style.position = "relative");
21004
21074
  let left = 0,
21005
21075
  top = 0;
21006
21076
  const b = graphic.globalAABBBounds;
@@ -21037,8 +21107,8 @@
21037
21107
  this.htmlMap[key] && this.htmlMap[key].renderId !== this.renderId && this.removeElement(key);
21038
21108
  }), this.renderId += 1;
21039
21109
  }
21040
- drawHTML(renderService) {
21041
- "browser" === application.global.env && (renderService.renderTreeRoots.sort((a, b) => {
21110
+ drawHTML(layers) {
21111
+ "browser" === application.global.env && (layers.sort((a, b) => {
21042
21112
  var _a, _b;
21043
21113
  return (null !== (_a = a.attribute.zIndex) && void 0 !== _a ? _a : DefaultAttribute.zIndex) - (null !== (_b = b.attribute.zIndex) && void 0 !== _b ? _b : DefaultAttribute.zIndex);
21044
21114
  }).forEach(group => {
@@ -21057,6 +21127,9 @@
21057
21127
  } = this.htmlMap[id];
21058
21128
  wrapContainer && application.global.removeDom(wrapContainer), this.htmlMap[id] = null;
21059
21129
  }
21130
+ removeWrapContainerEventListener(wrapContainer) {
21131
+ wrapContainer.removeEventListener("wheel", this.onWheel);
21132
+ }
21060
21133
  renderGraphicHTML(graphic) {
21061
21134
  var _a;
21062
21135
  const {
@@ -24927,6 +25000,31 @@
24927
25000
  },
24928
25001
  __metadata$J = undefined && undefined.__metadata || function (k, v) {
24929
25002
  if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
25003
+ },
25004
+ __awaiter$2 = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
25005
+ return new (P || (P = Promise))(function (resolve, reject) {
25006
+ function fulfilled(value) {
25007
+ try {
25008
+ step(generator.next(value));
25009
+ } catch (e) {
25010
+ reject(e);
25011
+ }
25012
+ }
25013
+ function rejected(value) {
25014
+ try {
25015
+ step(generator.throw(value));
25016
+ } catch (e) {
25017
+ reject(e);
25018
+ }
25019
+ }
25020
+ function step(result) {
25021
+ var value;
25022
+ result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P(function (resolve) {
25023
+ resolve(value);
25024
+ })).then(fulfilled, rejected);
25025
+ }
25026
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25027
+ });
24930
25028
  };
24931
25029
  class DynamicB {
24932
25030
  get x1() {
@@ -25122,6 +25220,19 @@
25122
25220
  left: actualLeft
25123
25221
  };
25124
25222
  }
25223
+ loadFont(font, source, descriptors) {
25224
+ return __awaiter$2(this, void 0, void 0, function* () {
25225
+ return new FontFace(font, isString$1(source) ? `url(${source})` : source, descriptors).load().then(function (loadedFont) {
25226
+ return document.fonts.add(loadedFont), {
25227
+ loadState: "success"
25228
+ };
25229
+ }).catch(function (error) {
25230
+ return console.error("Failed to load font:", error), {
25231
+ loadState: "fail"
25232
+ };
25233
+ });
25234
+ });
25235
+ }
25125
25236
  };
25126
25237
  exports.BrowserEnvContribution = __decorate$T([injectable(), __metadata$J("design:paramtypes", [])], exports.BrowserEnvContribution);
25127
25238
 
@@ -28681,7 +28792,7 @@
28681
28792
 
28682
28793
  const roughModule = _roughModule;
28683
28794
 
28684
- const version = "0.21.2";
28795
+ const version = "0.21.3";
28685
28796
  preLoadAllModule();
28686
28797
  if (isBrowserEnv()) {
28687
28798
  loadBrowserEnv(container);