@tscircuit/3d-viewer 0.0.320 → 0.0.321
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 +68 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15804,7 +15804,7 @@ var require_browser = __commonJS({
|
|
|
15804
15804
|
});
|
|
15805
15805
|
|
|
15806
15806
|
// src/CadViewer.tsx
|
|
15807
|
-
import { useState as useState16, useCallback as useCallback7, useRef as
|
|
15807
|
+
import { useState as useState16, useCallback as useCallback7, useRef as useRef9, useEffect as useEffect22 } from "react";
|
|
15808
15808
|
|
|
15809
15809
|
// src/CadViewerJscad.tsx
|
|
15810
15810
|
import { su as su4 } from "@tscircuit/circuit-json-util";
|
|
@@ -15824,7 +15824,8 @@ import {
|
|
|
15824
15824
|
useState,
|
|
15825
15825
|
useCallback,
|
|
15826
15826
|
useMemo,
|
|
15827
|
-
useEffect
|
|
15827
|
+
useEffect,
|
|
15828
|
+
useRef
|
|
15828
15829
|
} from "react";
|
|
15829
15830
|
import * as THREE from "three";
|
|
15830
15831
|
|
|
@@ -15859,26 +15860,43 @@ var useHover = () => {
|
|
|
15859
15860
|
var HoverProvider = ({ children }) => {
|
|
15860
15861
|
const { camera, renderer } = useThree();
|
|
15861
15862
|
const [hoverables, setHoverables] = useState([]);
|
|
15862
|
-
const [hoveredObject, setHoveredObject] = useState(
|
|
15863
|
-
null
|
|
15864
|
-
);
|
|
15865
15863
|
const raycaster = useMemo(() => new THREE.Raycaster(), []);
|
|
15866
15864
|
const mouse = useMemo(() => new THREE.Vector2(), []);
|
|
15865
|
+
const hoverablesRef = useRef(hoverables);
|
|
15866
|
+
hoverablesRef.current = hoverables;
|
|
15867
|
+
const hoveredObjectRef = useRef(null);
|
|
15867
15868
|
const addHoverable = useCallback((hoverable) => {
|
|
15868
15869
|
setHoverables((prev) => [...prev, hoverable]);
|
|
15869
15870
|
}, []);
|
|
15870
15871
|
const removeHoverable = useCallback((object) => {
|
|
15872
|
+
if (hoveredObjectRef.current) {
|
|
15873
|
+
let isAncestor = false;
|
|
15874
|
+
let current2 = hoveredObjectRef.current.object;
|
|
15875
|
+
while (current2) {
|
|
15876
|
+
if (current2 === object) {
|
|
15877
|
+
isAncestor = true;
|
|
15878
|
+
break;
|
|
15879
|
+
}
|
|
15880
|
+
current2 = current2.parent;
|
|
15881
|
+
}
|
|
15882
|
+
if (isAncestor) {
|
|
15883
|
+
hoveredObjectRef.current = null;
|
|
15884
|
+
}
|
|
15885
|
+
}
|
|
15871
15886
|
setHoverables((prev) => prev.filter((h) => h.object !== object));
|
|
15872
15887
|
}, []);
|
|
15873
|
-
const findHoverable = (
|
|
15874
|
-
|
|
15875
|
-
|
|
15876
|
-
|
|
15877
|
-
|
|
15878
|
-
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15888
|
+
const findHoverable = useCallback(
|
|
15889
|
+
(object) => {
|
|
15890
|
+
let current2 = object;
|
|
15891
|
+
while (current2) {
|
|
15892
|
+
const found = hoverablesRef.current.find((h) => h.object === current2);
|
|
15893
|
+
if (found) return found;
|
|
15894
|
+
current2 = current2.parent;
|
|
15895
|
+
}
|
|
15896
|
+
return void 0;
|
|
15897
|
+
},
|
|
15898
|
+
[]
|
|
15899
|
+
);
|
|
15882
15900
|
const onMouseMove2 = useCallback(
|
|
15883
15901
|
(event) => {
|
|
15884
15902
|
if (!renderer.domElement) return;
|
|
@@ -15886,8 +15904,14 @@ var HoverProvider = ({ children }) => {
|
|
|
15886
15904
|
mouse.x = (event.clientX - rect.left) / rect.width * 2 - 1;
|
|
15887
15905
|
mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
|
|
15888
15906
|
raycaster.setFromCamera(mouse, camera);
|
|
15889
|
-
const objectsToIntersect =
|
|
15890
|
-
if (objectsToIntersect.length === 0)
|
|
15907
|
+
const objectsToIntersect = hoverablesRef.current.map((h) => h.object);
|
|
15908
|
+
if (objectsToIntersect.length === 0) {
|
|
15909
|
+
if (hoveredObjectRef.current) {
|
|
15910
|
+
hoveredObjectRef.current.onUnhover();
|
|
15911
|
+
hoveredObjectRef.current = null;
|
|
15912
|
+
}
|
|
15913
|
+
return;
|
|
15914
|
+
}
|
|
15891
15915
|
const intersects = raycaster.intersectObjects(objectsToIntersect, true);
|
|
15892
15916
|
if (intersects.length > 0) {
|
|
15893
15917
|
const firstIntersect = intersects[0];
|
|
@@ -15900,27 +15924,27 @@ var HoverProvider = ({ children }) => {
|
|
|
15900
15924
|
firstIntersect.point.z
|
|
15901
15925
|
]
|
|
15902
15926
|
};
|
|
15903
|
-
if (
|
|
15904
|
-
|
|
15927
|
+
if (hoveredObjectRef.current !== newHovered) {
|
|
15928
|
+
hoveredObjectRef.current?.onUnhover();
|
|
15905
15929
|
newHovered.onHover(eventPayload);
|
|
15906
|
-
|
|
15930
|
+
hoveredObjectRef.current = newHovered;
|
|
15907
15931
|
} else {
|
|
15908
15932
|
newHovered.onHover(eventPayload);
|
|
15909
15933
|
}
|
|
15910
15934
|
} else {
|
|
15911
|
-
if (
|
|
15912
|
-
|
|
15913
|
-
|
|
15935
|
+
if (hoveredObjectRef.current) {
|
|
15936
|
+
hoveredObjectRef.current.onUnhover();
|
|
15937
|
+
hoveredObjectRef.current = null;
|
|
15914
15938
|
}
|
|
15915
15939
|
}
|
|
15916
15940
|
} else {
|
|
15917
|
-
if (
|
|
15918
|
-
|
|
15919
|
-
|
|
15941
|
+
if (hoveredObjectRef.current) {
|
|
15942
|
+
hoveredObjectRef.current.onUnhover();
|
|
15943
|
+
hoveredObjectRef.current = null;
|
|
15920
15944
|
}
|
|
15921
15945
|
}
|
|
15922
15946
|
},
|
|
15923
|
-
[camera, renderer, raycaster, mouse,
|
|
15947
|
+
[camera, renderer, raycaster, mouse, findHoverable]
|
|
15924
15948
|
);
|
|
15925
15949
|
useEffect(() => {
|
|
15926
15950
|
const domElement = renderer.domElement;
|
|
@@ -23600,7 +23624,7 @@ var require_react_development = __commonJS2({
|
|
|
23600
23624
|
var dispatcher = resolveDispatcher();
|
|
23601
23625
|
return dispatcher.useReducer(reducer, initialArg, init);
|
|
23602
23626
|
}
|
|
23603
|
-
function
|
|
23627
|
+
function useRef10(initialValue) {
|
|
23604
23628
|
var dispatcher = resolveDispatcher();
|
|
23605
23629
|
return dispatcher.useRef(initialValue);
|
|
23606
23630
|
}
|
|
@@ -24394,7 +24418,7 @@ var require_react_development = __commonJS2({
|
|
|
24394
24418
|
exports.useLayoutEffect = useLayoutEffect;
|
|
24395
24419
|
exports.useMemo = useMemo22;
|
|
24396
24420
|
exports.useReducer = useReducer;
|
|
24397
|
-
exports.useRef =
|
|
24421
|
+
exports.useRef = useRef10;
|
|
24398
24422
|
exports.useState = useState18;
|
|
24399
24423
|
exports.useSyncExternalStore = useSyncExternalStore;
|
|
24400
24424
|
exports.useTransition = useTransition;
|
|
@@ -101537,12 +101561,12 @@ var FootprinterModel = ({
|
|
|
101537
101561
|
var tuple = (...args) => args;
|
|
101538
101562
|
|
|
101539
101563
|
// src/react-three/Html.tsx
|
|
101540
|
-
import { useRef, useEffect as useEffect7, useState as useState4 } from "react";
|
|
101564
|
+
import { useRef as useRef2, useEffect as useEffect7, useState as useState4 } from "react";
|
|
101541
101565
|
import ReactDOM from "react-dom";
|
|
101542
101566
|
import * as THREE5 from "three";
|
|
101543
101567
|
var Html = ({ children, position, style }) => {
|
|
101544
101568
|
const { camera, renderer } = useThree();
|
|
101545
|
-
const el =
|
|
101569
|
+
const el = useRef2(document.createElement("div"));
|
|
101546
101570
|
const [portal, setPortal] = useState4(null);
|
|
101547
101571
|
useEffect7(() => {
|
|
101548
101572
|
const rendererNode = renderer?.domElement.parentNode;
|
|
@@ -101686,7 +101710,7 @@ import * as THREE10 from "three";
|
|
|
101686
101710
|
// package.json
|
|
101687
101711
|
var package_default = {
|
|
101688
101712
|
name: "@tscircuit/3d-viewer",
|
|
101689
|
-
version: "0.0.
|
|
101713
|
+
version: "0.0.320",
|
|
101690
101714
|
main: "./dist/index.js",
|
|
101691
101715
|
module: "./dist/index.js",
|
|
101692
101716
|
type: "module",
|
|
@@ -101950,7 +101974,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
101950
101974
|
|
|
101951
101975
|
// src/react-three/Canvas.tsx
|
|
101952
101976
|
import {
|
|
101953
|
-
useRef as
|
|
101977
|
+
useRef as useRef4,
|
|
101954
101978
|
useEffect as useEffect10,
|
|
101955
101979
|
useState as useState6,
|
|
101956
101980
|
useCallback as useCallback3,
|
|
@@ -101962,11 +101986,11 @@ import * as THREE7 from "three";
|
|
|
101962
101986
|
import { jsx as jsx37 } from "react/jsx-runtime";
|
|
101963
101987
|
var Canvas = forwardRef(
|
|
101964
101988
|
({ children, scene: sceneProps, camera: cameraProps, style }, ref) => {
|
|
101965
|
-
const mountRef =
|
|
101989
|
+
const mountRef = useRef4(null);
|
|
101966
101990
|
const [contextState, setContextState] = useState6(
|
|
101967
101991
|
null
|
|
101968
101992
|
);
|
|
101969
|
-
const frameListeners =
|
|
101993
|
+
const frameListeners = useRef4(
|
|
101970
101994
|
[]
|
|
101971
101995
|
);
|
|
101972
101996
|
const addFrameListener = useCallback3(
|
|
@@ -101987,7 +102011,7 @@ var Canvas = forwardRef(
|
|
|
101987
102011
|
if (sceneProps?.up) {
|
|
101988
102012
|
scene.up.set(sceneProps.up.x, sceneProps.up.y, sceneProps.up.z);
|
|
101989
102013
|
}
|
|
101990
|
-
const rootObject =
|
|
102014
|
+
const rootObject = useRef4(new THREE7.Object3D());
|
|
101991
102015
|
useImperativeHandle(ref, () => rootObject.current);
|
|
101992
102016
|
useEffect10(() => {
|
|
101993
102017
|
if (!mountRef.current) return;
|
|
@@ -102439,7 +102463,7 @@ var useStlsFromGeom = (geom) => {
|
|
|
102439
102463
|
};
|
|
102440
102464
|
|
|
102441
102465
|
// src/hooks/useBoardGeomBuilder.ts
|
|
102442
|
-
import { useState as useState9, useEffect as useEffect16, useRef as
|
|
102466
|
+
import { useState as useState9, useEffect as useEffect16, useRef as useRef6 } from "react";
|
|
102443
102467
|
|
|
102444
102468
|
// src/soup-to-3d/index.ts
|
|
102445
102469
|
var import_primitives2 = __toESM(require_primitives(), 1);
|
|
@@ -103554,7 +103578,7 @@ var BoardGeomBuilder = class {
|
|
|
103554
103578
|
// src/hooks/useBoardGeomBuilder.ts
|
|
103555
103579
|
var useBoardGeomBuilder = (circuitJson) => {
|
|
103556
103580
|
const [boardGeom, setBoardGeom] = useState9(null);
|
|
103557
|
-
const isProcessingRef =
|
|
103581
|
+
const isProcessingRef = useRef6(false);
|
|
103558
103582
|
useEffect16(() => {
|
|
103559
103583
|
let isCancelled = false;
|
|
103560
103584
|
if (!circuitJson) {
|
|
@@ -103869,7 +103893,7 @@ import ManifoldModule from "manifold-3d";
|
|
|
103869
103893
|
import { useEffect as useEffect20, useMemo as useMemo19, useState as useState14 } from "react";
|
|
103870
103894
|
|
|
103871
103895
|
// src/hooks/useManifoldBoardBuilder.ts
|
|
103872
|
-
import { useState as useState13, useEffect as useEffect19, useMemo as useMemo18, useRef as
|
|
103896
|
+
import { useState as useState13, useEffect as useEffect19, useMemo as useMemo18, useRef as useRef7 } from "react";
|
|
103873
103897
|
import { su as su12 } from "@tscircuit/circuit-json-util";
|
|
103874
103898
|
import * as THREE19 from "three";
|
|
103875
103899
|
|
|
@@ -104629,7 +104653,7 @@ var useManifoldBoardBuilder = (manifoldJSModule, circuitJson) => {
|
|
|
104629
104653
|
const [pcbThickness, setPcbThickness] = useState13(null);
|
|
104630
104654
|
const [error, setError] = useState13(null);
|
|
104631
104655
|
const [isLoading, setIsLoading] = useState13(true);
|
|
104632
|
-
const manifoldInstancesForCleanup =
|
|
104656
|
+
const manifoldInstancesForCleanup = useRef7([]);
|
|
104633
104657
|
const boardData = useMemo18(() => {
|
|
104634
104658
|
const boards = su12(circuitJson).pcb_board.list();
|
|
104635
104659
|
if (boards.length === 0) {
|
|
@@ -105056,15 +105080,15 @@ var CadViewerManifold = ({
|
|
|
105056
105080
|
var CadViewerManifold_default = CadViewerManifold;
|
|
105057
105081
|
|
|
105058
105082
|
// src/hooks/useContextMenu.ts
|
|
105059
|
-
import { useState as useState15, useCallback as useCallback6, useRef as
|
|
105083
|
+
import { useState as useState15, useCallback as useCallback6, useRef as useRef8, useEffect as useEffect21 } from "react";
|
|
105060
105084
|
var useContextMenu = ({ containerRef }) => {
|
|
105061
105085
|
const [menuVisible, setMenuVisible] = useState15(false);
|
|
105062
105086
|
const [menuPos, setMenuPos] = useState15({
|
|
105063
105087
|
x: 0,
|
|
105064
105088
|
y: 0
|
|
105065
105089
|
});
|
|
105066
|
-
const menuRef =
|
|
105067
|
-
const interactionOriginPosRef =
|
|
105090
|
+
const menuRef = useRef8(null);
|
|
105091
|
+
const interactionOriginPosRef = useRef8(null);
|
|
105068
105092
|
const handleContextMenu = useCallback6(
|
|
105069
105093
|
(e) => {
|
|
105070
105094
|
e.preventDefault();
|
|
@@ -105161,7 +105185,7 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
105161
105185
|
import { jsx as jsx43, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
105162
105186
|
var CadViewer = (props) => {
|
|
105163
105187
|
const [engine, setEngine] = useState16("manifold");
|
|
105164
|
-
const containerRef =
|
|
105188
|
+
const containerRef = useRef9(null);
|
|
105165
105189
|
const [autoRotate, setAutoRotate] = useState16(true);
|
|
105166
105190
|
const [autoRotateUserToggled, setAutoRotateUserToggled] = useState16(false);
|
|
105167
105191
|
const {
|
|
@@ -105171,7 +105195,7 @@ var CadViewer = (props) => {
|
|
|
105171
105195
|
contextMenuEventHandlers,
|
|
105172
105196
|
setMenuVisible
|
|
105173
105197
|
} = useContextMenu({ containerRef });
|
|
105174
|
-
const autoRotateUserToggledRef =
|
|
105198
|
+
const autoRotateUserToggledRef = useRef9(autoRotateUserToggled);
|
|
105175
105199
|
autoRotateUserToggledRef.current = autoRotateUserToggled;
|
|
105176
105200
|
const handleUserInteraction = useCallback7(() => {
|
|
105177
105201
|
if (!autoRotateUserToggledRef.current) {
|