@inweb/viewer-visualize 27.1.4 → 27.1.5

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));