@inweb/viewer-visualize 27.1.4 → 27.1.6

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.
@@ -3442,22 +3442,7 @@
3442
3442
  }
3443
3443
  }
3444
3444
 
3445
- class RenderLoopComponent {
3446
- constructor(viewer) {
3447
- this.animate = (time) => {
3448
- this.requestId = requestAnimationFrame(this.animate);
3449
- this.viewer.render(time);
3450
- this.viewer.emitEvent({ type: "animate", time });
3451
- };
3452
- this.viewer = viewer;
3453
- this.requestId = requestAnimationFrame(this.animate);
3454
- }
3455
- dispose() {
3456
- cancelAnimationFrame(this.requestId);
3457
- }
3458
- }
3459
-
3460
- class ResizeCanvasComponent {
3445
+ class CanvasResizeComponent {
3461
3446
  constructor(viewer) {
3462
3447
  this.resizeViewer = (entries) => {
3463
3448
  const { width, height } = entries[0].contentRect;
@@ -3474,6 +3459,46 @@
3474
3459
  }
3475
3460
  }
3476
3461
 
3462
+ class CanvasRemoveComponent {
3463
+ constructor(viewer) {
3464
+ this.cleanupViewer = (mutations) => {
3465
+ for (const mutation of mutations) {
3466
+ if (mutation.type === "childList" && mutation.removedNodes.length > 0) {
3467
+ for (const node of mutation.removedNodes) {
3468
+ if (node === this.viewer.canvas || node.contains(this.viewer.canvas)) {
3469
+ this.viewer.emitEvent({ type: "canvasremoved" });
3470
+ this.viewer.dispose();
3471
+ return;
3472
+ }
3473
+ }
3474
+ }
3475
+ }
3476
+ };
3477
+ this.viewer = viewer;
3478
+ this.mutationObserver = new MutationObserver(this.cleanupViewer);
3479
+ this.mutationObserver.observe(document, { childList: true, subtree: true });
3480
+ }
3481
+ dispose() {
3482
+ this.mutationObserver.disconnect();
3483
+ this.mutationObserver = undefined;
3484
+ }
3485
+ }
3486
+
3487
+ class RenderLoopComponent {
3488
+ constructor(viewer) {
3489
+ this.animate = (time) => {
3490
+ this.requestId = requestAnimationFrame(this.animate);
3491
+ this.viewer.render(time);
3492
+ this.viewer.emitEvent({ type: "animate", time });
3493
+ };
3494
+ this.viewer = viewer;
3495
+ this.requestId = requestAnimationFrame(this.animate);
3496
+ }
3497
+ dispose() {
3498
+ cancelAnimationFrame(this.requestId);
3499
+ }
3500
+ }
3501
+
3477
3502
  class ZoomWheelComponent {
3478
3503
  constructor(viewer) {
3479
3504
  this.viewer = viewer;
@@ -3728,7 +3753,8 @@
3728
3753
  const components = componentsRegistry("visualizejs");
3729
3754
  components.registerComponent("CameraComponent", (viewer) => new CameraComponent(viewer));
3730
3755
  components.registerComponent("InfoComponent", (viewer) => new InfoComponent(viewer));
3731
- components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
3756
+ components.registerComponent("CanvasResizeComponent", (viewer) => new CanvasResizeComponent(viewer));
3757
+ components.registerComponent("CanvasRemoveComponent", (viewer) => new CanvasRemoveComponent(viewer));
3732
3758
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
3733
3759
  components.registerComponent("ZoomWheelComponent", (viewer) => new ZoomWheelComponent(viewer));
3734
3760
  components.registerComponent("GestureManagerComponent", (viewer) => new GestureManagerComponent(viewer));
@@ -4325,7 +4351,7 @@
4325
4351
  : {};
4326
4352
  const Konva$2 = {
4327
4353
  _global: glob,
4328
- version: '10.0.12',
4354
+ version: '10.2.0',
4329
4355
  isBrowser: detectBrowser(),
4330
4356
  isUnminified: /param/.test(function (param) { }.toString()),
4331
4357
  dblClickWindow: 400,
@@ -4697,7 +4723,7 @@ js: import "konva/skia-backend";
4697
4723
  let _isCanvasFarblingActive = null;
4698
4724
  const req = (typeof requestAnimationFrame !== 'undefined' && requestAnimationFrame) ||
4699
4725
  function (f) {
4700
- setTimeout(f, 60);
4726
+ setTimeout(f, 16);
4701
4727
  };
4702
4728
  const Util = {
4703
4729
  _isElement(obj) {
@@ -6494,8 +6520,8 @@ js: import "konva/skia-backend";
6494
6520
  }
6495
6521
  clearCache() {
6496
6522
  if (this._cache.has(CANVAS)) {
6497
- const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
6498
- Util.releaseCanvas(scene, filter, hit, buffer);
6523
+ const { scene, filter, hit } = this._cache.get(CANVAS);
6524
+ Util.releaseCanvas(scene._canvas, filter._canvas, hit._canvas);
6499
6525
  this._cache.delete(CANVAS);
6500
6526
  }
6501
6527
  this._clearSelfAndDescendantCache();
@@ -6578,11 +6604,11 @@ js: import "konva/skia-backend";
6578
6604
  sceneContext.stroke();
6579
6605
  sceneContext.restore();
6580
6606
  }
6607
+ Util.releaseCanvas(bufferCanvas._canvas);
6581
6608
  this._cache.set(CANVAS, {
6582
6609
  scene: cachedSceneCanvas,
6583
6610
  filter: cachedFilterCanvas,
6584
6611
  hit: cachedHitCanvas,
6585
- buffer: bufferCanvas,
6586
6612
  x: x,
6587
6613
  y: y,
6588
6614
  });
@@ -7607,19 +7633,20 @@ js: import "konva/skia-backend";
7607
7633
  }
7608
7634
  }
7609
7635
  _getProtoListeners(eventType) {
7610
- var _a, _b, _c;
7611
- const allListeners = (_a = this._cache.get(ALL_LISTENERS)) !== null && _a !== void 0 ? _a : {};
7636
+ var _a, _b;
7637
+ const { nodeType } = this;
7638
+ const allListeners = Node.protoListenerMap.get(nodeType) || {};
7612
7639
  let events = allListeners === null || allListeners === void 0 ? void 0 : allListeners[eventType];
7613
7640
  if (events === undefined) {
7614
7641
  events = [];
7615
7642
  let obj = Object.getPrototypeOf(this);
7616
7643
  while (obj) {
7617
- const hierarchyEvents = (_c = (_b = obj.eventListeners) === null || _b === void 0 ? void 0 : _b[eventType]) !== null && _c !== void 0 ? _c : [];
7644
+ const hierarchyEvents = (_b = (_a = obj.eventListeners) === null || _a === void 0 ? void 0 : _a[eventType]) !== null && _b !== void 0 ? _b : [];
7618
7645
  events.push(...hierarchyEvents);
7619
7646
  obj = Object.getPrototypeOf(obj);
7620
7647
  }
7621
7648
  allListeners[eventType] = events;
7622
- this._cache.set(ALL_LISTENERS, allListeners);
7649
+ Node.protoListenerMap.set(nodeType, allListeners);
7623
7650
  }
7624
7651
  return events;
7625
7652
  }
@@ -7809,6 +7836,7 @@ js: import "konva/skia-backend";
7809
7836
  return no;
7810
7837
  }
7811
7838
  }
7839
+ Node.protoListenerMap = new Map();
7812
7840
  Node.prototype.nodeType = 'Node';
7813
7841
  Node.prototype._attrsAffectingSize = [];
7814
7842
  Node.prototype.eventListeners = {};
@@ -9266,7 +9294,15 @@ js: import "konva/skia-backend";
9266
9294
  stage = this.getStage();
9267
9295
  const bc = bufferCanvas || stage.bufferCanvas;
9268
9296
  const bufferContext = bc.getContext();
9269
- bufferContext.clear();
9297
+ if (bufferCanvas) {
9298
+ bufferContext.save();
9299
+ bufferContext.setTransform(1, 0, 0, 1, 0, 0);
9300
+ bufferContext.clearRect(0, 0, bc.width, bc.height);
9301
+ bufferContext.restore();
9302
+ }
9303
+ else {
9304
+ bufferContext.clear();
9305
+ }
9270
9306
  bufferContext.save();
9271
9307
  bufferContext._applyLineJoin(this);
9272
9308
  bufferContext._applyMiterLimit(this);
@@ -10559,6 +10595,35 @@ js: import "konva/skia-backend";
10559
10595
  }
10560
10596
  return allPoints;
10561
10597
  }
10598
+ function getBezierExtremaPoints(points) {
10599
+ const axisPoints = [
10600
+ [points[0], points[2], points[4], points[6]],
10601
+ [points[1], points[3], points[5], points[7]],
10602
+ ];
10603
+ const extremaTs = [];
10604
+ for (const axis of axisPoints) {
10605
+ const a = -3 * axis[0] + 9 * axis[1] - 9 * axis[2] + 3 * axis[3];
10606
+ if (a !== 0) {
10607
+ const b = 6 * axis[0] - 12 * axis[1] + 6 * axis[2];
10608
+ const c = -3 * axis[0] + 3 * axis[1];
10609
+ const discriminant = b * b - 4 * a * c;
10610
+ if (discriminant >= 0) {
10611
+ const d = Math.sqrt(discriminant);
10612
+ extremaTs.push((-b + d) / (2 * a));
10613
+ extremaTs.push((-b - d) / (2 * a));
10614
+ }
10615
+ }
10616
+ }
10617
+ return extremaTs
10618
+ .filter((t) => t > 0 && t < 1)
10619
+ .flatMap((t) => axisPoints.map((axis) => {
10620
+ const mt = 1 - t;
10621
+ return (mt * mt * mt * axis[0] +
10622
+ 3 * mt * mt * t * axis[1] +
10623
+ 3 * mt * t * t * axis[2] +
10624
+ t * t * t * axis[3]);
10625
+ }));
10626
+ }
10562
10627
  class Line extends Shape {
10563
10628
  constructor(config) {
10564
10629
  super(config);
@@ -10660,6 +10725,15 @@ js: import "konva/skia-backend";
10660
10725
  points[points.length - 1],
10661
10726
  ];
10662
10727
  }
10728
+ else if (this.bezier()) {
10729
+ points = [
10730
+ points[0],
10731
+ points[1],
10732
+ ...getBezierExtremaPoints(this.points()),
10733
+ points[points.length - 2],
10734
+ points[points.length - 1],
10735
+ ];
10736
+ }
10663
10737
  else {
10664
10738
  points = this.points();
10665
10739
  }
@@ -12949,7 +13023,7 @@ js: import "konva/skia-backend";
12949
13023
  if (!this.text()) {
12950
13024
  return;
12951
13025
  }
12952
- let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
13026
+ let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), underlineOffset = this.underlineOffset(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
12953
13027
  direction = direction === INHERIT ? context.direction : direction;
12954
13028
  let translateY = lineHeightPx / 2;
12955
13029
  let baseline = MIDDLE;
@@ -12987,9 +13061,9 @@ js: import "konva/skia-backend";
12987
13061
  if (shouldUnderline) {
12988
13062
  context.save();
12989
13063
  context.beginPath();
12990
- const yOffset = !Konva$2.legacyTextRendering
13064
+ const yOffset = underlineOffset !== null && underlineOffset !== void 0 ? underlineOffset : (!Konva$2.legacyTextRendering
12991
13065
  ? Math.round(fontSize / 4)
12992
- : Math.round(fontSize / 2);
13066
+ : Math.round(fontSize / 2));
12993
13067
  const x = lineTranslateX;
12994
13068
  const y = translateY + lineTranslateY + yOffset;
12995
13069
  context.moveTo(x, y);
@@ -13308,6 +13382,7 @@ js: import "konva/skia-backend";
13308
13382
  Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
13309
13383
  Factory.addGetterSetter(Text, 'text', '', getStringValidator());
13310
13384
  Factory.addGetterSetter(Text, 'textDecoration', '');
13385
+ Factory.addGetterSetter(Text, 'underlineOffset', undefined, getNumberValidator());
13311
13386
  Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
13312
13387
 
13313
13388
  const EMPTY_STRING = '', NORMAL = 'normal';
@@ -13576,6 +13651,7 @@ js: import "konva/skia-backend";
13576
13651
  const ATTR_CHANGE_LIST = [
13577
13652
  'resizeEnabledChange',
13578
13653
  'rotateAnchorOffsetChange',
13654
+ 'rotateAnchorAngleChange',
13579
13655
  'rotateEnabledChange',
13580
13656
  'enabledAnchorsChange',
13581
13657
  'anchorSizeChange',
@@ -13973,11 +14049,38 @@ js: import "konva/skia-backend";
13973
14049
  sceneFunc(ctx, shape) {
13974
14050
  const tr = shape.getParent();
13975
14051
  const padding = tr.padding();
14052
+ const width = shape.width();
14053
+ const height = shape.height();
13976
14054
  ctx.beginPath();
13977
- ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
13978
- ctx.moveTo(shape.width() / 2, -padding);
14055
+ ctx.rect(-padding, -padding, width + padding * 2, height + padding * 2);
13979
14056
  if (tr.rotateEnabled() && tr.rotateLineVisible()) {
13980
- ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util._sign(shape.height()) - padding);
14057
+ const rotateAnchorAngle = tr.rotateAnchorAngle();
14058
+ const rotateAnchorOffset = tr.rotateAnchorOffset();
14059
+ const rad = Util.degToRad(rotateAnchorAngle);
14060
+ const dirX = Math.sin(rad);
14061
+ const dirY = -Math.cos(rad);
14062
+ const cx = width / 2;
14063
+ const cy = height / 2;
14064
+ let t = Infinity;
14065
+ if (dirY < 0) {
14066
+ t = Math.min(t, -cy / dirY);
14067
+ }
14068
+ else if (dirY > 0) {
14069
+ t = Math.min(t, (height - cy) / dirY);
14070
+ }
14071
+ if (dirX < 0) {
14072
+ t = Math.min(t, -cx / dirX);
14073
+ }
14074
+ else if (dirX > 0) {
14075
+ t = Math.min(t, (width - cx) / dirX);
14076
+ }
14077
+ const edgeX = cx + dirX * t;
14078
+ const edgeY = cy + dirY * t;
14079
+ const sign = Util._sign(height);
14080
+ const endX = edgeX + dirX * rotateAnchorOffset * sign;
14081
+ const endY = edgeY + dirY * rotateAnchorOffset * sign;
14082
+ ctx.moveTo(edgeX, edgeY);
14083
+ ctx.lineTo(endX, endY);
13981
14084
  }
13982
14085
  ctx.fillStrokeShape(shape);
13983
14086
  },
@@ -14059,7 +14162,8 @@ js: import "konva/skia-backend";
14059
14162
  const attrs = this._getNodeRect();
14060
14163
  x = anchorNode.x() - attrs.width / 2;
14061
14164
  y = -anchorNode.y() + attrs.height / 2;
14062
- let delta = Math.atan2(-y, x) + Math.PI / 2;
14165
+ const rotateAnchorAngleRad = Konva$2.getAngle(this.rotateAnchorAngle());
14166
+ let delta = Math.atan2(-y, x) + Math.PI / 2 - rotateAnchorAngleRad;
14063
14167
  if (attrs.height < 0) {
14064
14168
  delta -= Math.PI;
14065
14169
  }
@@ -14454,9 +14558,32 @@ js: import "konva/skia-backend";
14454
14558
  offsetY: anchorSize / 2 - padding,
14455
14559
  visible: resizeEnabled && enabledAnchors.indexOf('bottom-right') >= 0,
14456
14560
  });
14561
+ const rotateAnchorAngle = this.rotateAnchorAngle();
14562
+ const rotateAnchorOffset = this.rotateAnchorOffset();
14563
+ const rad = Util.degToRad(rotateAnchorAngle);
14564
+ const dirX = Math.sin(rad);
14565
+ const dirY = -Math.cos(rad);
14566
+ const cx = width / 2;
14567
+ const cy = height / 2;
14568
+ let t = Infinity;
14569
+ if (dirY < 0) {
14570
+ t = Math.min(t, -cy / dirY);
14571
+ }
14572
+ else if (dirY > 0) {
14573
+ t = Math.min(t, (height - cy) / dirY);
14574
+ }
14575
+ if (dirX < 0) {
14576
+ t = Math.min(t, -cx / dirX);
14577
+ }
14578
+ else if (dirX > 0) {
14579
+ t = Math.min(t, (width - cx) / dirX);
14580
+ }
14581
+ const edgeX = cx + dirX * t;
14582
+ const edgeY = cy + dirY * t;
14583
+ const sign = Util._sign(height);
14457
14584
  this._batchChangeChild('.rotater', {
14458
- x: width / 2,
14459
- y: -this.rotateAnchorOffset() * Util._sign(height) - padding,
14585
+ x: edgeX + dirX * rotateAnchorOffset * sign,
14586
+ y: edgeY + dirY * rotateAnchorOffset * sign - padding * dirY,
14460
14587
  visible: this.rotateEnabled(),
14461
14588
  });
14462
14589
  this._batchChangeChild('.back', {
@@ -14544,6 +14671,7 @@ js: import "konva/skia-backend";
14544
14671
  Factory.addGetterSetter(Transformer, 'rotateLineVisible', true);
14545
14672
  Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
14546
14673
  Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, getNumberValidator());
14674
+ Factory.addGetterSetter(Transformer, 'rotateAnchorAngle', 0, getNumberValidator());
14547
14675
  Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
14548
14676
  Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, getNumberValidator());
14549
14677
  Factory.addGetterSetter(Transformer, 'borderEnabled', true);