@tscircuit/3d-viewer 0.0.426 → 0.0.428
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 +93 -31
- 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.427",
|
|
26793
26793
|
main: "./dist/index.js",
|
|
26794
26794
|
module: "./dist/index.js",
|
|
26795
26795
|
type: "module",
|
|
@@ -27501,7 +27501,7 @@ var useCameraController = ({
|
|
|
27501
27501
|
}) => {
|
|
27502
27502
|
const controlsRef = useRef5(null);
|
|
27503
27503
|
const baseDistance = useMemo14(() => {
|
|
27504
|
-
const [x, y, z133] = initialCameraPosition ?? [5, 5, 5];
|
|
27504
|
+
const [x, y, z133] = initialCameraPosition ?? [5, -5, 5];
|
|
27505
27505
|
const distance2 = Math.hypot(
|
|
27506
27506
|
x - defaultTarget.x,
|
|
27507
27507
|
y - defaultTarget.y,
|
|
@@ -27649,7 +27649,7 @@ var RotationTracker = () => {
|
|
|
27649
27649
|
var CadViewerContainer = forwardRef2(
|
|
27650
27650
|
({
|
|
27651
27651
|
children,
|
|
27652
|
-
initialCameraPosition = [5, 5, 5],
|
|
27652
|
+
initialCameraPosition = [5, -5, 5],
|
|
27653
27653
|
autoRotateDisabled,
|
|
27654
27654
|
clickToInteractEnabled = false,
|
|
27655
27655
|
boardDimensions,
|
|
@@ -29930,22 +29930,29 @@ var CadViewerJscad = forwardRef3(
|
|
|
29930
29930
|
}, [soup, circuitJson, childrenSoup]);
|
|
29931
29931
|
const boardGeom = useBoardGeomBuilder(internalCircuitJson);
|
|
29932
29932
|
const initialCameraPosition = useMemo19(() => {
|
|
29933
|
-
if (!internalCircuitJson) return [5, 5, 5];
|
|
29933
|
+
if (!internalCircuitJson) return [5, -5, 5];
|
|
29934
29934
|
try {
|
|
29935
29935
|
const board = su4(internalCircuitJson).pcb_board.list()[0];
|
|
29936
|
-
if (!board) return [5, 5, 5];
|
|
29936
|
+
if (!board) return [5, -5, 5];
|
|
29937
29937
|
const { width: width10, height: height10 } = board;
|
|
29938
29938
|
if (!width10 && !height10) {
|
|
29939
|
-
return [5, 5, 5];
|
|
29939
|
+
return [5, -5, 5];
|
|
29940
29940
|
}
|
|
29941
29941
|
const minCameraDistance = 5;
|
|
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
|
-
return [5, 5, 5];
|
|
29955
|
+
return [5, -5, 5];
|
|
29949
29956
|
}
|
|
29950
29957
|
}, [internalCircuitJson]);
|
|
29951
29958
|
const boardDimensions = useMemo19(() => {
|
|
@@ -31884,12 +31891,19 @@ try {
|
|
|
31884
31891
|
return { x: center.x, y: center.y };
|
|
31885
31892
|
}, [boardData]);
|
|
31886
31893
|
const initialCameraPosition = useMemo21(() => {
|
|
31887
|
-
if (!boardData) return [5, 5, 5];
|
|
31894
|
+
if (!boardData) return [5, -5, 5];
|
|
31888
31895
|
const { width: width10 = 0, height: height10 = 0 } = boardData;
|
|
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
|
);
|