@tscircuit/3d-viewer 0.0.352 → 0.0.353

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.
Files changed (2) hide show
  1. package/dist/index.js +66 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14228,7 +14228,7 @@ var require_browser = __commonJS({
14228
14228
  });
14229
14229
 
14230
14230
  // src/CadViewer.tsx
14231
- import { useState as useState15, useCallback as useCallback7, useRef as useRef9, useEffect as useEffect22 } from "react";
14231
+ import { useState as useState15, useCallback as useCallback8, useRef as useRef9, useEffect as useEffect22 } from "react";
14232
14232
 
14233
14233
  // src/CadViewerJscad.tsx
14234
14234
  import { su as su4 } from "@tscircuit/circuit-json-util";
@@ -25583,7 +25583,7 @@ import * as THREE10 from "three";
25583
25583
  // package.json
25584
25584
  var package_default = {
25585
25585
  name: "@tscircuit/3d-viewer",
25586
- version: "0.0.351",
25586
+ version: "0.0.352",
25587
25587
  main: "./dist/index.js",
25588
25588
  module: "./dist/index.js",
25589
25589
  type: "module",
@@ -25912,6 +25912,7 @@ var Canvas = forwardRef(
25912
25912
  }
25913
25913
  camera.lookAt(0, 0, 0);
25914
25914
  scene.add(rootObject.current);
25915
+ window.__TSCIRCUIT_THREE_OBJECT = rootObject.current;
25915
25916
  setContextState({
25916
25917
  scene,
25917
25918
  camera,
@@ -25949,6 +25950,9 @@ var Canvas = forwardRef(
25949
25950
  }
25950
25951
  renderer.dispose();
25951
25952
  scene.remove(rootObject.current);
25953
+ if (window.__TSCIRCUIT_THREE_OBJECT === rootObject.current) {
25954
+ window.__TSCIRCUIT_THREE_OBJECT = void 0;
25955
+ }
25952
25956
  };
25953
25957
  }, [scene, addFrameListener, removeFrameListener]);
25954
25958
  return /* @__PURE__ */ jsx9("div", { ref: mountRef, style: { width: "100%", height: "100%", ...style }, children: contextState && /* @__PURE__ */ jsx9(ThreeContext.Provider, { value: contextState, children: /* @__PURE__ */ jsx9(HoverProvider, { children }) }) });
@@ -29147,6 +29151,35 @@ var useContextMenu = ({ containerRef }) => {
29147
29151
  };
29148
29152
  };
29149
29153
 
29154
+ // src/hooks/useGlobalDownloadGltf.ts
29155
+ import { useCallback as useCallback7 } from "react";
29156
+ import { GLTFExporter } from "three-stdlib";
29157
+ var useGlobalDownloadGltf = () => {
29158
+ return useCallback7(() => {
29159
+ const root = window.__TSCIRCUIT_THREE_OBJECT;
29160
+ if (!root) return;
29161
+ const exporter = new GLTFExporter();
29162
+ exporter.parse(
29163
+ root,
29164
+ (gltf) => {
29165
+ const blob = new Blob(
29166
+ [gltf instanceof ArrayBuffer ? gltf : JSON.stringify(gltf)],
29167
+ { type: "model/gltf+json" }
29168
+ );
29169
+ const url = URL.createObjectURL(blob);
29170
+ const link = document.createElement("a");
29171
+ link.href = url;
29172
+ link.download = "scene.gltf";
29173
+ link.click();
29174
+ URL.revokeObjectURL(url);
29175
+ },
29176
+ (err) => {
29177
+ console.error("Failed to export GLTF", err);
29178
+ }
29179
+ );
29180
+ }, []);
29181
+ };
29182
+
29150
29183
  // src/CadViewer.tsx
29151
29184
  import { jsx as jsx14, jsxs as jsxs8 } from "react/jsx-runtime";
29152
29185
  var CadViewer = (props) => {
@@ -29163,15 +29196,16 @@ var CadViewer = (props) => {
29163
29196
  } = useContextMenu({ containerRef });
29164
29197
  const autoRotateUserToggledRef = useRef9(autoRotateUserToggled);
29165
29198
  autoRotateUserToggledRef.current = autoRotateUserToggled;
29166
- const handleUserInteraction = useCallback7(() => {
29199
+ const handleUserInteraction = useCallback8(() => {
29167
29200
  if (!autoRotateUserToggledRef.current) {
29168
29201
  setAutoRotate(false);
29169
29202
  }
29170
29203
  }, []);
29171
- const toggleAutoRotate = useCallback7(() => {
29204
+ const toggleAutoRotate = useCallback8(() => {
29172
29205
  setAutoRotate((prev) => !prev);
29173
29206
  setAutoRotateUserToggled(true);
29174
29207
  }, []);
29208
+ const downloadGltf = useGlobalDownloadGltf();
29175
29209
  const handleMenuClick = (newEngine) => {
29176
29210
  setEngine(newEngine);
29177
29211
  setMenuVisible(false);
@@ -29312,6 +29346,29 @@ var CadViewer = (props) => {
29312
29346
  ]
29313
29347
  }
29314
29348
  ),
29349
+ /* @__PURE__ */ jsx14(
29350
+ "div",
29351
+ {
29352
+ style: {
29353
+ padding: "12px 18px",
29354
+ cursor: "pointer",
29355
+ display: "flex",
29356
+ alignItems: "center",
29357
+ gap: 10,
29358
+ color: "#f5f6fa",
29359
+ fontWeight: 500,
29360
+ borderRadius: 6,
29361
+ transition: "background 0.1s"
29362
+ },
29363
+ onClick: () => {
29364
+ downloadGltf();
29365
+ setMenuVisible(false);
29366
+ },
29367
+ onMouseOver: (e) => e.currentTarget.style.background = "#2d313a",
29368
+ onMouseOut: (e) => e.currentTarget.style.background = "transparent",
29369
+ children: "Download GLTF"
29370
+ }
29371
+ ),
29315
29372
  /* @__PURE__ */ jsx14(
29316
29373
  "div",
29317
29374
  {
@@ -29616,8 +29673,8 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
29616
29673
  }
29617
29674
 
29618
29675
  // src/hooks/exporter/gltf.ts
29619
- import { GLTFExporter } from "three-stdlib";
29620
- import { useEffect as useEffect23, useState as useState16, useMemo as useMemo19, useCallback as useCallback8 } from "react";
29676
+ import { GLTFExporter as GLTFExporter2 } from "three-stdlib";
29677
+ import { useEffect as useEffect23, useState as useState16, useMemo as useMemo19, useCallback as useCallback9 } from "react";
29621
29678
  function useSaveGltfAs(options = {}) {
29622
29679
  const parse = useParser(options);
29623
29680
  const link = useMemo19(() => document.createElement("a"), []);
@@ -29638,7 +29695,7 @@ function useSaveGltfAs(options = {}) {
29638
29695
  []
29639
29696
  );
29640
29697
  let instance;
29641
- const ref = useCallback8((obj3D) => {
29698
+ const ref = useCallback9((obj3D) => {
29642
29699
  instance = obj3D;
29643
29700
  }, []);
29644
29701
  return [ref, saveAs];
@@ -29647,7 +29704,7 @@ function useExportGltfUrl(options = {}) {
29647
29704
  const parse = useParser(options);
29648
29705
  const [url, setUrl] = useState16();
29649
29706
  const [error, setError] = useState16();
29650
- const ref = useCallback8(
29707
+ const ref = useCallback9(
29651
29708
  (instance) => parse(instance).then(setUrl).catch(setError),
29652
29709
  []
29653
29710
  );
@@ -29655,7 +29712,7 @@ function useExportGltfUrl(options = {}) {
29655
29712
  return [ref, url, error];
29656
29713
  }
29657
29714
  function useParser(options = {}) {
29658
- const exporter = useMemo19(() => new GLTFExporter(), []);
29715
+ const exporter = useMemo19(() => new GLTFExporter2(), []);
29659
29716
  return (instance) => {
29660
29717
  const { promise, resolve, reject } = Promise.withResolvers();
29661
29718
  exporter.parse(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.352",
3
+ "version": "0.0.353",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",