@inweb/viewer-three 27.1.3 → 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.
@@ -251,6 +251,8 @@
251
251
  rulerUnit: "Default",
252
252
  rulerPrecision: 2,
253
253
  cameraMode: "perspective",
254
+ snapshotMimeType: "image/jpeg",
255
+ snapshotQuality: 0.25,
254
256
  };
255
257
  }
256
258
  class Options {
@@ -35796,9 +35798,15 @@ void main() {
35796
35798
  viewer.clearSlices();
35797
35799
  }
35798
35800
 
35799
- function createPreview(viewer, type = "image/jpeg", quality = 0.25) {
35801
+ function getSnapshot(viewer, type, quality) {
35802
+ var _a, _b;
35800
35803
  viewer.update(true);
35801
- return viewer.canvas.toDataURL(type, quality);
35804
+ const mimeType = (_a = type !== null && type !== void 0 ? type : viewer.options.snapshotMimeType) !== null && _a !== void 0 ? _a : "image/jpeg";
35805
+ const imageQuality = (_b = quality !== null && quality !== void 0 ? quality : viewer.options.snapshotQuality) !== null && _b !== void 0 ? _b : 0.25;
35806
+ if (viewer.markup) {
35807
+ return viewer.markup.getSnapshot(mimeType, imageQuality);
35808
+ }
35809
+ return viewer.canvas.toDataURL(mimeType, imageQuality);
35802
35810
  }
35803
35811
 
35804
35812
  function explode(viewer, index = 0) {
@@ -36007,7 +36015,7 @@ void main() {
36007
36015
  commands.registerCommand("clearSelected", clearSelected);
36008
36016
  commands.registerCommand("clearSlices", clearSlices);
36009
36017
  commands.registerCommand("collect", collect);
36010
- commands.registerCommand("createPreview", createPreview);
36018
+ commands.registerCommand("getSnapshot", getSnapshot);
36011
36019
  commands.registerCommand("explode", explode);
36012
36020
  commands.registerCommand("getDefaultViewPositions", getDefaultViewPositions);
36013
36021
  commands.registerCommand("getModels", getModels);
@@ -36039,6 +36047,7 @@ void main() {
36039
36047
  commands.registerCommand("nw", (viewer) => setDefaultViewPosition(viewer, "nw"));
36040
36048
  commands.registerCommandAlias("clearMarkup", "clearOverlay");
36041
36049
  commands.registerCommandAlias("clearSelected", "unselect");
36050
+ commands.registerCommandAlias("getSnapshot", "createPreview");
36042
36051
  commands.registerCommandAlias("zoomToExtents", "zoomExtents");
36043
36052
  commands.registerCommandAlias("top", "k3DViewTop");
36044
36053
  commands.registerCommandAlias("bottom", "k3DViewBottom");
@@ -36125,7 +36134,7 @@ void main() {
36125
36134
  if (camera.isOrthographicCamera) {
36126
36135
  camera.left = camera.bottom * aspectRatio;
36127
36136
  camera.right = camera.top * aspectRatio;
36128
- camera.near = 0;
36137
+ camera.near = -extentsSize * 1000;
36129
36138
  camera.far = extentsSize * 1000;
36130
36139
  }
36131
36140
  camera.updateProjectionMatrix();
@@ -36391,22 +36400,7 @@ void main() {
36391
36400
  }
36392
36401
  }
36393
36402
 
36394
- class RenderLoopComponent {
36395
- constructor(viewer) {
36396
- this.animate = (time) => {
36397
- this.requestId = requestAnimationFrame(this.animate);
36398
- this.viewer.render(time);
36399
- this.viewer.emitEvent({ type: "animate", time });
36400
- };
36401
- this.viewer = viewer;
36402
- this.requestId = requestAnimationFrame(this.animate);
36403
- }
36404
- dispose() {
36405
- cancelAnimationFrame(this.requestId);
36406
- }
36407
- }
36408
-
36409
- class ResizeCanvasComponent {
36403
+ class CanvasResizeComponent {
36410
36404
  constructor(viewer) {
36411
36405
  this.resizeViewer = (entries) => {
36412
36406
  const { width, height } = entries[0].contentRect;
@@ -36423,6 +36417,46 @@ void main() {
36423
36417
  }
36424
36418
  }
36425
36419
 
36420
+ class CanvasRemoveComponent {
36421
+ constructor(viewer) {
36422
+ this.cleanupViewer = (mutations) => {
36423
+ for (const mutation of mutations) {
36424
+ if (mutation.type === "childList" && mutation.removedNodes.length > 0) {
36425
+ for (const node of mutation.removedNodes) {
36426
+ if (node === this.viewer.canvas || node.contains(this.viewer.canvas)) {
36427
+ this.viewer.emitEvent({ type: "canvasremoved" });
36428
+ this.viewer.dispose();
36429
+ return;
36430
+ }
36431
+ }
36432
+ }
36433
+ }
36434
+ };
36435
+ this.viewer = viewer;
36436
+ this.mutationObserver = new MutationObserver(this.cleanupViewer);
36437
+ this.mutationObserver.observe(document, { childList: true, subtree: true });
36438
+ }
36439
+ dispose() {
36440
+ this.mutationObserver.disconnect();
36441
+ this.mutationObserver = undefined;
36442
+ }
36443
+ }
36444
+
36445
+ class RenderLoopComponent {
36446
+ constructor(viewer) {
36447
+ this.animate = (time) => {
36448
+ this.requestId = requestAnimationFrame(this.animate);
36449
+ this.viewer.render(time);
36450
+ this.viewer.emitEvent({ type: "animate", time });
36451
+ };
36452
+ this.viewer = viewer;
36453
+ this.requestId = requestAnimationFrame(this.animate);
36454
+ }
36455
+ dispose() {
36456
+ cancelAnimationFrame(this.requestId);
36457
+ }
36458
+ }
36459
+
36426
36460
  const _box = new Box3();
36427
36461
  const _vector = new Vector3();
36428
36462
  class LineSegmentsGeometry extends InstancedBufferGeometry {
@@ -37518,7 +37552,8 @@ void main() {
37518
37552
  components.registerComponent("BackgroundComponent", (viewer) => new BackgroundComponent(viewer));
37519
37553
  components.registerComponent("LightComponent", (viewer) => new LightComponent(viewer));
37520
37554
  components.registerComponent("InfoComponent", (viewer) => new InfoComponent(viewer));
37521
- components.registerComponent("ResizeCanvasComponent", (viewer) => new ResizeCanvasComponent(viewer));
37555
+ components.registerComponent("CanvasResizeComponent", (viewer) => new CanvasResizeComponent(viewer));
37556
+ components.registerComponent("CanvasRemoveComponent", (viewer) => new CanvasRemoveComponent(viewer));
37522
37557
  components.registerComponent("RenderLoopComponent", (viewer) => new RenderLoopComponent(viewer));
37523
37558
  components.registerComponent("HighlighterComponent", (viewer) => new HighlighterComponent(viewer));
37524
37559
  components.registerComponent("SelectionComponent", (viewer) => new SelectionComponent(viewer));
@@ -56591,10 +56626,22 @@ js: import "konva/skia-backend";
56591
56626
  viewpoint.ellipses = this.getMarkupEllipses();
56592
56627
  viewpoint.images = this.getMarkupImages();
56593
56628
  viewpoint.rectangles = this.getMarkupRectangles();
56594
- viewpoint.snapshot = { data: this.combineMarkupWithDrawing() };
56595
56629
  viewpoint.custom_fields.markup_color = this.getMarkupColor();
56596
56630
  return viewpoint;
56597
56631
  }
56632
+ getSnapshot(type = "image/jpeg", quality = 0.25) {
56633
+ this.clearSelected();
56634
+ const tempCanvas = document.createElement("canvas");
56635
+ if (this._konvaStage) {
56636
+ tempCanvas.width = this._konvaStage.width();
56637
+ tempCanvas.height = this._konvaStage.height();
56638
+ const ctx = tempCanvas.getContext("2d");
56639
+ if (this._container instanceof HTMLCanvasElement)
56640
+ ctx.drawImage(this._container, 0, 0);
56641
+ ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
56642
+ }
56643
+ return tempCanvas.toDataURL(type, quality);
56644
+ }
56598
56645
  enableEditMode(mode) {
56599
56646
  if (!mode || !MarkupMode2Konva[mode]) {
56600
56647
  this.clearSelected();
@@ -57031,19 +57078,6 @@ js: import "konva/skia-backend";
57031
57078
  });
57032
57079
  return clouds;
57033
57080
  }
57034
- combineMarkupWithDrawing() {
57035
- this.clearSelected();
57036
- const tempCanvas = document.createElement("canvas");
57037
- if (this._konvaStage) {
57038
- tempCanvas.width = this._konvaStage.width();
57039
- tempCanvas.height = this._konvaStage.height();
57040
- const ctx = tempCanvas.getContext("2d");
57041
- if (this._container instanceof HTMLCanvasElement)
57042
- ctx.drawImage(this._container, 0, 0);
57043
- ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
57044
- }
57045
- return tempCanvas.toDataURL("image/jpeg", 0.25);
57046
- }
57047
57081
  addLine(linePoints, color, type, width, id) {
57048
57082
  if (!linePoints || linePoints.length === 0)
57049
57083
  return;
@@ -57644,7 +57678,7 @@ js: import "konva/skia-backend";
57644
57678
  camera.bottom = -orthogonal_camera.field_height / 2;
57645
57679
  camera.left = camera.bottom * aspectRatio;
57646
57680
  camera.right = camera.top * aspectRatio;
57647
- camera.near = 0;
57681
+ camera.near = -extentsSize * 1000;
57648
57682
  camera.far = extentsSize * 1000;
57649
57683
  camera.zoom = orthogonal_camera.view_to_world_scale;
57650
57684
  camera.updateProjectionMatrix();
@@ -57765,12 +57799,16 @@ js: import "konva/skia-backend";
57765
57799
  viewpoint.clipping_planes = getClippingPlanes();
57766
57800
  viewpoint.selection = getSelection();
57767
57801
  viewpoint.description = new Date().toDateString();
57802
+ viewpoint.snapshot = { data: this.getSnapshot() };
57768
57803
  this._markup.getViewpoint(viewpoint);
57769
57804
  viewpoint.custom_fields.camera_target = getPoint3dFromVector3(this.target);
57770
57805
  viewpoint.custom_fields.selection2 = getSelection2();
57771
57806
  this.emitEvent({ type: "createviewpoint", data: viewpoint });
57772
57807
  return viewpoint;
57773
57808
  }
57809
+ getSnapshot(type, quality) {
57810
+ return this.executeCommand("getSnapshot", type, quality);
57811
+ }
57774
57812
  screenToWorld(position) {
57775
57813
  if (!this.renderer)
57776
57814
  return { x: position.x, y: position.y, z: 0 };