@tscircuit/3d-viewer 0.0.427 → 0.0.429
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.
- package/dist/index.js +86 -24
- 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 useState33, useCallback as
|
|
14231
|
+
import { useState as useState33, useCallback as useCallback20, useRef as useRef22, useEffect as useEffect39 } from "react";
|
|
14232
14232
|
|
|
14233
14233
|
// src/CadViewerJscad.tsx
|
|
14234
14234
|
import { su as su4 } from "@tscircuit/circuit-json-util";
|
|
@@ -26789,7 +26789,7 @@ import * as THREE14 from "three";
|
|
|
26789
26789
|
// package.json
|
|
26790
26790
|
var package_default = {
|
|
26791
26791
|
name: "@tscircuit/3d-viewer",
|
|
26792
|
-
version: "0.0.
|
|
26792
|
+
version: "0.0.428",
|
|
26793
26793
|
main: "./dist/index.js",
|
|
26794
26794
|
module: "./dist/index.js",
|
|
26795
26795
|
type: "module",
|
|
@@ -29942,7 +29942,14 @@ var CadViewerJscad = forwardRef3(
|
|
|
29942
29942
|
const adjustedBoardWidth = Math.max(width10, minCameraDistance);
|
|
29943
29943
|
const adjustedBoardHeight = Math.max(height10, minCameraDistance);
|
|
29944
29944
|
const largestDim = Math.max(adjustedBoardWidth, adjustedBoardHeight);
|
|
29945
|
-
return [
|
|
29945
|
+
return [
|
|
29946
|
+
largestDim * 0.4,
|
|
29947
|
+
// Move right
|
|
29948
|
+
-largestDim * 0.7,
|
|
29949
|
+
// Move back (negative Y)
|
|
29950
|
+
largestDim * 0.9
|
|
29951
|
+
// Keep height but slightly lower than top-down
|
|
29952
|
+
];
|
|
29946
29953
|
} catch (e) {
|
|
29947
29954
|
console.error(e);
|
|
29948
29955
|
return [5, -5, 5];
|
|
@@ -31889,7 +31896,14 @@ try {
|
|
|
31889
31896
|
const safeWidth = Math.max(width10, 1);
|
|
31890
31897
|
const safeHeight = Math.max(height10, 1);
|
|
31891
31898
|
const largestDim = Math.max(safeWidth, safeHeight, 5);
|
|
31892
|
-
return [
|
|
31899
|
+
return [
|
|
31900
|
+
largestDim * 0.4,
|
|
31901
|
+
// Move right
|
|
31902
|
+
-largestDim * 0.7,
|
|
31903
|
+
// Move back (negative Y)
|
|
31904
|
+
largestDim * 0.9
|
|
31905
|
+
// Keep height but slightly lower than top-down
|
|
31906
|
+
];
|
|
31893
31907
|
}, [boardData]);
|
|
31894
31908
|
if (manifoldLoadingError) {
|
|
31895
31909
|
return /* @__PURE__ */ jsxs7(
|
|
@@ -32111,11 +32125,51 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
32111
32125
|
};
|
|
32112
32126
|
};
|
|
32113
32127
|
|
|
32114
|
-
// src/hooks/
|
|
32128
|
+
// src/hooks/useCameraPreset.ts
|
|
32115
32129
|
import { useCallback as useCallback9 } from "react";
|
|
32130
|
+
function useCameraPreset({
|
|
32131
|
+
setAutoRotate,
|
|
32132
|
+
setAutoRotateUserToggled,
|
|
32133
|
+
setCameraPreset,
|
|
32134
|
+
closeMenu,
|
|
32135
|
+
cameraControllerRef,
|
|
32136
|
+
isAnimatingRef,
|
|
32137
|
+
lastPresetSelectTime
|
|
32138
|
+
}) {
|
|
32139
|
+
const handleCameraPresetSelect = useCallback9(
|
|
32140
|
+
(preset) => {
|
|
32141
|
+
setAutoRotate(false);
|
|
32142
|
+
setAutoRotateUserToggled(true);
|
|
32143
|
+
setCameraPreset(preset);
|
|
32144
|
+
closeMenu();
|
|
32145
|
+
lastPresetSelectTime.current = Date.now();
|
|
32146
|
+
if (preset === "Custom") return;
|
|
32147
|
+
isAnimatingRef.current = true;
|
|
32148
|
+
cameraControllerRef.current?.animateToPreset(preset);
|
|
32149
|
+
setTimeout(() => {
|
|
32150
|
+
isAnimatingRef.current = false;
|
|
32151
|
+
}, 600);
|
|
32152
|
+
},
|
|
32153
|
+
[
|
|
32154
|
+
setAutoRotate,
|
|
32155
|
+
setAutoRotateUserToggled,
|
|
32156
|
+
setCameraPreset,
|
|
32157
|
+
closeMenu,
|
|
32158
|
+
cameraControllerRef,
|
|
32159
|
+
isAnimatingRef,
|
|
32160
|
+
lastPresetSelectTime
|
|
32161
|
+
]
|
|
32162
|
+
);
|
|
32163
|
+
return {
|
|
32164
|
+
handleCameraPresetSelect
|
|
32165
|
+
};
|
|
32166
|
+
}
|
|
32167
|
+
|
|
32168
|
+
// src/hooks/useGlobalDownloadGltf.ts
|
|
32169
|
+
import { useCallback as useCallback10 } from "react";
|
|
32116
32170
|
import { GLTFExporter } from "three-stdlib";
|
|
32117
32171
|
var useGlobalDownloadGltf = () => {
|
|
32118
|
-
return
|
|
32172
|
+
return useCallback10(() => {
|
|
32119
32173
|
const root = window.__TSCIRCUIT_THREE_OBJECT;
|
|
32120
32174
|
if (!root) return;
|
|
32121
32175
|
const exporter = new GLTFExporter();
|
|
@@ -38076,21 +38130,29 @@ var CadViewerInner = (props) => {
|
|
|
38076
38130
|
} = useContextMenu({ containerRef });
|
|
38077
38131
|
const autoRotateUserToggledRef = useRef22(autoRotateUserToggled);
|
|
38078
38132
|
autoRotateUserToggledRef.current = autoRotateUserToggled;
|
|
38079
|
-
const
|
|
38133
|
+
const isAnimatingRef = useRef22(false);
|
|
38134
|
+
const lastPresetSelectTime = useRef22(0);
|
|
38135
|
+
const PRESET_COOLDOWN = 1e3;
|
|
38136
|
+
const handleUserInteraction = useCallback20(() => {
|
|
38137
|
+
if (isAnimatingRef.current || Date.now() - lastPresetSelectTime.current < PRESET_COOLDOWN) {
|
|
38138
|
+
return;
|
|
38139
|
+
}
|
|
38080
38140
|
if (!autoRotateUserToggledRef.current) {
|
|
38081
38141
|
setAutoRotate(false);
|
|
38082
38142
|
}
|
|
38083
|
-
|
|
38084
|
-
|
|
38085
|
-
|
|
38143
|
+
if (!menuVisible) {
|
|
38144
|
+
setCameraPreset("Custom");
|
|
38145
|
+
}
|
|
38146
|
+
}, [menuVisible]);
|
|
38147
|
+
const toggleAutoRotate = useCallback20(() => {
|
|
38086
38148
|
setAutoRotate((prev) => !prev);
|
|
38087
38149
|
setAutoRotateUserToggled(true);
|
|
38088
38150
|
}, []);
|
|
38089
38151
|
const downloadGltf = useGlobalDownloadGltf();
|
|
38090
|
-
const closeMenu =
|
|
38152
|
+
const closeMenu = useCallback20(() => {
|
|
38091
38153
|
setMenuVisible(false);
|
|
38092
38154
|
}, [setMenuVisible]);
|
|
38093
|
-
const handleCameraControllerReady =
|
|
38155
|
+
const handleCameraControllerReady = useCallback20(
|
|
38094
38156
|
(controller) => {
|
|
38095
38157
|
cameraControllerRef.current = controller;
|
|
38096
38158
|
externalCameraControllerReady?.(controller);
|
|
@@ -38100,15 +38162,15 @@ var CadViewerInner = (props) => {
|
|
|
38100
38162
|
},
|
|
38101
38163
|
[cameraPreset, externalCameraControllerReady]
|
|
38102
38164
|
);
|
|
38103
|
-
const handleCameraPresetSelect =
|
|
38104
|
-
|
|
38105
|
-
|
|
38106
|
-
|
|
38107
|
-
|
|
38108
|
-
|
|
38109
|
-
|
|
38110
|
-
|
|
38111
|
-
);
|
|
38165
|
+
const { handleCameraPresetSelect } = useCameraPreset({
|
|
38166
|
+
setAutoRotate,
|
|
38167
|
+
setAutoRotateUserToggled,
|
|
38168
|
+
setCameraPreset,
|
|
38169
|
+
closeMenu,
|
|
38170
|
+
cameraControllerRef,
|
|
38171
|
+
isAnimatingRef,
|
|
38172
|
+
lastPresetSelectTime
|
|
38173
|
+
});
|
|
38112
38174
|
useEffect39(() => {
|
|
38113
38175
|
const stored = window.localStorage.getItem("cadViewerEngine");
|
|
38114
38176
|
if (stored === "jscad" || stored === "manifold") {
|
|
@@ -38493,7 +38555,7 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
|
|
|
38493
38555
|
|
|
38494
38556
|
// src/hooks/exporter/gltf.ts
|
|
38495
38557
|
import { GLTFExporter as GLTFExporter2 } from "three-stdlib";
|
|
38496
|
-
import { useEffect as useEffect40, useState as useState34, useMemo as useMemo27, useCallback as
|
|
38558
|
+
import { useEffect as useEffect40, useState as useState34, useMemo as useMemo27, useCallback as useCallback21 } from "react";
|
|
38497
38559
|
function useSaveGltfAs(options = {}) {
|
|
38498
38560
|
const parse2 = useParser(options);
|
|
38499
38561
|
const link = useMemo27(() => document.createElement("a"), []);
|
|
@@ -38514,7 +38576,7 @@ function useSaveGltfAs(options = {}) {
|
|
|
38514
38576
|
[]
|
|
38515
38577
|
);
|
|
38516
38578
|
let instance;
|
|
38517
|
-
const ref =
|
|
38579
|
+
const ref = useCallback21((obj3D) => {
|
|
38518
38580
|
instance = obj3D;
|
|
38519
38581
|
}, []);
|
|
38520
38582
|
return [ref, saveAs];
|
|
@@ -38523,7 +38585,7 @@ function useExportGltfUrl(options = {}) {
|
|
|
38523
38585
|
const parse2 = useParser(options);
|
|
38524
38586
|
const [url, setUrl] = useState34();
|
|
38525
38587
|
const [error, setError] = useState34();
|
|
38526
|
-
const ref =
|
|
38588
|
+
const ref = useCallback21(
|
|
38527
38589
|
(instance) => parse2(instance).then(setUrl).catch(setError),
|
|
38528
38590
|
[]
|
|
38529
38591
|
);
|