three-cad-viewer 3.0.2 → 3.0.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.
@@ -57632,6 +57632,13 @@ class Display {
57632
57632
  this.cadView.appendChild(cadView);
57633
57633
  }
57634
57634
 
57635
+ /**
57636
+ * Get the DOM canvas element
57637
+ */
57638
+ getCanvas() {
57639
+ return this.cadView.children[this.cadView.children.length - 1];
57640
+ }
57641
+
57635
57642
  /**
57636
57643
  * Clear the Cad tree
57637
57644
  */
@@ -63190,7 +63197,7 @@ class Camera {
63190
63197
  }
63191
63198
  }
63192
63199
 
63193
- const version = "3.0.2";
63200
+ const version = "3.0.3";
63194
63201
 
63195
63202
  class Viewer {
63196
63203
  /**
@@ -65650,35 +65657,56 @@ class Viewer {
65650
65657
  * Note: Only the canvas will be shown, no tools and orientation marker
65651
65658
  */
65652
65659
  pinAsPng = () => {
65653
- const children = this.display.cadView.children;
65654
- const canvas = children[children.length - 1];
65655
- this.renderer.setViewport(0, 0, this.cadWidth, this.height);
65656
- this.renderer.render(this.scene, this.camera.getCamera());
65657
- canvas.toBlob((blob) => {
65658
- let reader = new FileReader();
65659
- const scope = this;
65660
- reader.addEventListener(
65661
- "load",
65662
- function () {
65663
- var image = document.createElement("img");
65664
- image.width = scope.cadWidth;
65665
- image.height = scope.height;
65666
- image.src = reader.result;
65667
- if (scope.pinAsPngCallback == null) {
65668
- // default, replace the elements of the container with the image
65669
- for (var c of scope.display.container.children) {
65670
- scope.display.container.removeChild(c);
65660
+ const screenshot = this.getImage("screenshot");
65661
+ screenshot.then((data) => {
65662
+ var image = document.createElement("img");
65663
+ image.width = this.cadWidth;
65664
+ image.height = this.height;
65665
+ image.src = data.dataUrl;
65666
+ if (this.pinAsPngCallback == null) {
65667
+ // default, replace the elements of the container with the image
65668
+ for (var c of this.display.container.children) {
65669
+ this.display.container.removeChild(c);
65670
+ }
65671
+ this.display.container.appendChild(image);
65672
+ }
65673
+ });
65674
+ };
65675
+
65676
+ /**
65677
+ * Get the current canvas as png data.
65678
+ * @function
65679
+ * @param {string} taksId - and id to identify the screenshot
65680
+ * Note: Only the canvas will be shown, no tools and orientation marker
65681
+ */
65682
+ getImage = (taskId) => {
65683
+ // canvas.toBlob can be very slow when anmation loop is off!
65684
+ const animationLoop = this.hasAnimationLoop;
65685
+ if (!animationLoop) {
65686
+ this.toggleAnimationLoop(true);
65687
+ }
65688
+ let result = new Promise((resolve, reject) => {
65689
+ const canvas = this.display.getCanvas();
65690
+ this.renderer.setViewport(0, 0, this.cadWidth, this.height);
65691
+ this.renderer.render(this.scene, this.camera.getCamera());
65692
+ canvas.toBlob((blob) => {
65693
+ let reader = new FileReader();
65694
+ reader.addEventListener(
65695
+ "load",
65696
+ () => {
65697
+ resolve({ task: taskId, dataUrl: reader.result });
65698
+ // set animation loop back to the stored value
65699
+ if (!animationLoop) {
65700
+ this.toggleAnimationLoop(false);
65671
65701
  }
65672
- scope.display.container.appendChild(image);
65673
- } else {
65674
- // let callbackl handle the image placement
65675
- scope.pinAsPngCallback(image);
65676
- }
65677
- },
65678
- false,
65679
- );
65680
- reader.readAsDataURL(blob);
65702
+ },
65703
+ false,
65704
+ );
65705
+ reader.readAsDataURL(blob);
65706
+ });
65681
65707
  });
65708
+
65709
+ return result;
65682
65710
  };
65683
65711
 
65684
65712
  /**