@tscircuit/3d-viewer 0.0.413 → 0.0.415
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 +533 -196
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14228,15 +14228,15 @@ var require_browser = __commonJS({
|
|
|
14228
14228
|
});
|
|
14229
14229
|
|
|
14230
14230
|
// src/CadViewer.tsx
|
|
14231
|
-
import { useState as
|
|
14231
|
+
import { useState as useState18, useCallback as useCallback9, useRef as useRef9, useEffect as useEffect24 } from "react";
|
|
14232
14232
|
|
|
14233
14233
|
// src/CadViewerJscad.tsx
|
|
14234
14234
|
import { su as su4 } from "@tscircuit/circuit-json-util";
|
|
14235
|
-
import { forwardRef as forwardRef3, useMemo as
|
|
14235
|
+
import { forwardRef as forwardRef3, useMemo as useMemo18 } from "react";
|
|
14236
14236
|
|
|
14237
14237
|
// src/AnyCadComponent.tsx
|
|
14238
14238
|
import { su } from "@tscircuit/circuit-json-util";
|
|
14239
|
-
import { useMemo as
|
|
14239
|
+
import { useMemo as useMemo7, useState as useState6, useCallback as useCallback3 } from "react";
|
|
14240
14240
|
|
|
14241
14241
|
// src/ContainerWithTooltip.tsx
|
|
14242
14242
|
import { useEffect as useEffect2 } from "react";
|
|
@@ -26440,15 +26440,87 @@ var Html = ({ children, position, style }) => {
|
|
|
26440
26440
|
return portal;
|
|
26441
26441
|
};
|
|
26442
26442
|
|
|
26443
|
+
// src/contexts/LayerVisibilityContext.tsx
|
|
26444
|
+
import {
|
|
26445
|
+
createContext as createContext3,
|
|
26446
|
+
useContext as useContext3,
|
|
26447
|
+
useState as useState5,
|
|
26448
|
+
useCallback as useCallback2,
|
|
26449
|
+
useMemo as useMemo6
|
|
26450
|
+
} from "react";
|
|
26451
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
26452
|
+
var defaultVisibility = {
|
|
26453
|
+
boardBody: true,
|
|
26454
|
+
topCopper: true,
|
|
26455
|
+
bottomCopper: true,
|
|
26456
|
+
adhesive: false,
|
|
26457
|
+
solderPaste: false,
|
|
26458
|
+
topSilkscreen: true,
|
|
26459
|
+
bottomSilkscreen: true,
|
|
26460
|
+
topMask: true,
|
|
26461
|
+
bottomMask: true,
|
|
26462
|
+
throughHoleModels: true,
|
|
26463
|
+
smtModels: true,
|
|
26464
|
+
virtualModels: false,
|
|
26465
|
+
modelsNotInPosFile: false,
|
|
26466
|
+
modelsMarkedDNP: false,
|
|
26467
|
+
modelBoundingBoxes: false,
|
|
26468
|
+
threedAxis: false,
|
|
26469
|
+
backgroundStart: true,
|
|
26470
|
+
backgroundEnd: true
|
|
26471
|
+
};
|
|
26472
|
+
var LayerVisibilityContext = createContext3(void 0);
|
|
26473
|
+
var LayerVisibilityProvider = ({ children }) => {
|
|
26474
|
+
const [visibility, setVisibility] = useState5(defaultVisibility);
|
|
26475
|
+
const toggleLayer = useCallback2((layer) => {
|
|
26476
|
+
setVisibility((prev) => ({
|
|
26477
|
+
...prev,
|
|
26478
|
+
[layer]: !prev[layer]
|
|
26479
|
+
}));
|
|
26480
|
+
}, []);
|
|
26481
|
+
const setLayerVisibility = useCallback2(
|
|
26482
|
+
(layer, visible) => {
|
|
26483
|
+
setVisibility((prev) => ({
|
|
26484
|
+
...prev,
|
|
26485
|
+
[layer]: visible
|
|
26486
|
+
}));
|
|
26487
|
+
},
|
|
26488
|
+
[]
|
|
26489
|
+
);
|
|
26490
|
+
const resetToDefaults = useCallback2(() => {
|
|
26491
|
+
setVisibility(defaultVisibility);
|
|
26492
|
+
}, []);
|
|
26493
|
+
const value = useMemo6(
|
|
26494
|
+
() => ({
|
|
26495
|
+
visibility,
|
|
26496
|
+
toggleLayer,
|
|
26497
|
+
setLayerVisibility,
|
|
26498
|
+
resetToDefaults
|
|
26499
|
+
}),
|
|
26500
|
+
[visibility, toggleLayer, setLayerVisibility, resetToDefaults]
|
|
26501
|
+
);
|
|
26502
|
+
return /* @__PURE__ */ jsx8(LayerVisibilityContext.Provider, { value, children });
|
|
26503
|
+
};
|
|
26504
|
+
var useLayerVisibility = () => {
|
|
26505
|
+
const context = useContext3(LayerVisibilityContext);
|
|
26506
|
+
if (!context) {
|
|
26507
|
+
throw new Error(
|
|
26508
|
+
"useLayerVisibility must be used within a LayerVisibilityProvider"
|
|
26509
|
+
);
|
|
26510
|
+
}
|
|
26511
|
+
return context;
|
|
26512
|
+
};
|
|
26513
|
+
|
|
26443
26514
|
// src/AnyCadComponent.tsx
|
|
26444
|
-
import { Fragment as Fragment3, jsx as
|
|
26515
|
+
import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
26445
26516
|
var AnyCadComponent = ({
|
|
26446
26517
|
cad_component: cad_component2,
|
|
26447
26518
|
circuitJson
|
|
26448
26519
|
}) => {
|
|
26449
|
-
const [isHovered, setIsHovered] =
|
|
26450
|
-
const
|
|
26451
|
-
const
|
|
26520
|
+
const [isHovered, setIsHovered] = useState6(false);
|
|
26521
|
+
const { visibility } = useLayerVisibility();
|
|
26522
|
+
const [hoverPosition, setHoverPosition] = useState6(null);
|
|
26523
|
+
const handleHover = useCallback3((e) => {
|
|
26452
26524
|
if (e?.mousePosition) {
|
|
26453
26525
|
setIsHovered(true);
|
|
26454
26526
|
setHoverPosition(e.mousePosition);
|
|
@@ -26457,11 +26529,11 @@ var AnyCadComponent = ({
|
|
|
26457
26529
|
setHoverPosition(null);
|
|
26458
26530
|
}
|
|
26459
26531
|
}, []);
|
|
26460
|
-
const handleUnhover =
|
|
26532
|
+
const handleUnhover = useCallback3(() => {
|
|
26461
26533
|
setIsHovered(false);
|
|
26462
26534
|
setHoverPosition(null);
|
|
26463
26535
|
}, []);
|
|
26464
|
-
const componentName =
|
|
26536
|
+
const componentName = useMemo7(() => {
|
|
26465
26537
|
return su(circuitJson).source_component.getUsing({
|
|
26466
26538
|
source_component_id: cad_component2.source_component_id
|
|
26467
26539
|
})?.name;
|
|
@@ -26475,7 +26547,7 @@ var AnyCadComponent = ({
|
|
|
26475
26547
|
) : void 0;
|
|
26476
26548
|
let modelComponent = null;
|
|
26477
26549
|
if (url) {
|
|
26478
|
-
modelComponent = /* @__PURE__ */
|
|
26550
|
+
modelComponent = /* @__PURE__ */ jsx9(
|
|
26479
26551
|
MixedStlModel,
|
|
26480
26552
|
{
|
|
26481
26553
|
url,
|
|
@@ -26493,7 +26565,7 @@ var AnyCadComponent = ({
|
|
|
26493
26565
|
cad_component2.cad_component_id
|
|
26494
26566
|
);
|
|
26495
26567
|
} else if (gltfUrl) {
|
|
26496
|
-
modelComponent = /* @__PURE__ */
|
|
26568
|
+
modelComponent = /* @__PURE__ */ jsx9(
|
|
26497
26569
|
GltfModel,
|
|
26498
26570
|
{
|
|
26499
26571
|
gltfUrl,
|
|
@@ -26511,7 +26583,7 @@ var AnyCadComponent = ({
|
|
|
26511
26583
|
cad_component2.cad_component_id
|
|
26512
26584
|
);
|
|
26513
26585
|
} else if (cad_component2.model_jscad) {
|
|
26514
|
-
modelComponent = /* @__PURE__ */
|
|
26586
|
+
modelComponent = /* @__PURE__ */ jsx9(
|
|
26515
26587
|
JscadModel,
|
|
26516
26588
|
{
|
|
26517
26589
|
jscadPlan: cad_component2.model_jscad,
|
|
@@ -26524,7 +26596,7 @@ var AnyCadComponent = ({
|
|
|
26524
26596
|
cad_component2.cad_component_id
|
|
26525
26597
|
);
|
|
26526
26598
|
} else if (cad_component2.footprinter_string) {
|
|
26527
|
-
modelComponent = /* @__PURE__ */
|
|
26599
|
+
modelComponent = /* @__PURE__ */ jsx9(
|
|
26528
26600
|
FootprinterModel,
|
|
26529
26601
|
{
|
|
26530
26602
|
positionOffset: cad_component2.position ? [
|
|
@@ -26541,9 +26613,12 @@ var AnyCadComponent = ({
|
|
|
26541
26613
|
}
|
|
26542
26614
|
);
|
|
26543
26615
|
}
|
|
26616
|
+
if (!visibility.smtModels) {
|
|
26617
|
+
return null;
|
|
26618
|
+
}
|
|
26544
26619
|
return /* @__PURE__ */ jsxs2(Fragment3, { children: [
|
|
26545
26620
|
modelComponent,
|
|
26546
|
-
isHovered && hoverPosition ? /* @__PURE__ */
|
|
26621
|
+
isHovered && hoverPosition ? /* @__PURE__ */ jsx9(
|
|
26547
26622
|
Html,
|
|
26548
26623
|
{
|
|
26549
26624
|
position: hoverPosition,
|
|
@@ -26568,15 +26643,15 @@ var AnyCadComponent = ({
|
|
|
26568
26643
|
// src/CadViewerContainer.tsx
|
|
26569
26644
|
import {
|
|
26570
26645
|
forwardRef as forwardRef2,
|
|
26571
|
-
useMemo as
|
|
26572
|
-
useState as
|
|
26646
|
+
useMemo as useMemo14,
|
|
26647
|
+
useState as useState8
|
|
26573
26648
|
} from "react";
|
|
26574
26649
|
import * as THREE13 from "three";
|
|
26575
26650
|
|
|
26576
26651
|
// package.json
|
|
26577
26652
|
var package_default = {
|
|
26578
26653
|
name: "@tscircuit/3d-viewer",
|
|
26579
|
-
version: "0.0.
|
|
26654
|
+
version: "0.0.414",
|
|
26580
26655
|
main: "./dist/index.js",
|
|
26581
26656
|
module: "./dist/index.js",
|
|
26582
26657
|
type: "module",
|
|
@@ -26655,11 +26730,11 @@ var package_default = {
|
|
|
26655
26730
|
};
|
|
26656
26731
|
|
|
26657
26732
|
// src/three-components/cube-with-labeled-sides.tsx
|
|
26658
|
-
import { useEffect as
|
|
26733
|
+
import { useEffect as useEffect11, useMemo as useMemo9 } from "react";
|
|
26659
26734
|
import * as THREE8 from "three";
|
|
26660
26735
|
|
|
26661
26736
|
// src/react-three/Text.tsx
|
|
26662
|
-
import { useEffect as
|
|
26737
|
+
import { useEffect as useEffect10, useMemo as useMemo8 } from "react";
|
|
26663
26738
|
import { Text as TroikaText } from "troika-three-text";
|
|
26664
26739
|
var Text = ({
|
|
26665
26740
|
children,
|
|
@@ -26674,7 +26749,7 @@ var Text = ({
|
|
|
26674
26749
|
depthOffset
|
|
26675
26750
|
}) => {
|
|
26676
26751
|
const { rootObject } = useThree();
|
|
26677
|
-
const mesh =
|
|
26752
|
+
const mesh = useMemo8(() => {
|
|
26678
26753
|
const textMesh = new TroikaText();
|
|
26679
26754
|
textMesh.text = children;
|
|
26680
26755
|
if (position) textMesh.position.fromArray(position);
|
|
@@ -26699,7 +26774,7 @@ var Text = ({
|
|
|
26699
26774
|
anchorY,
|
|
26700
26775
|
depthOffset
|
|
26701
26776
|
]);
|
|
26702
|
-
|
|
26777
|
+
useEffect10(() => {
|
|
26703
26778
|
const parentObject = parent || rootObject;
|
|
26704
26779
|
if (!parentObject || !mesh) return;
|
|
26705
26780
|
parentObject.add(mesh);
|
|
@@ -26712,7 +26787,7 @@ var Text = ({
|
|
|
26712
26787
|
};
|
|
26713
26788
|
|
|
26714
26789
|
// src/three-components/cube-with-labeled-sides.tsx
|
|
26715
|
-
import { Fragment as Fragment4, jsx as
|
|
26790
|
+
import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
26716
26791
|
if (typeof window !== "undefined") {
|
|
26717
26792
|
window.TSCI_MAIN_CAMERA_ROTATION = new THREE8.Euler(0, 0, 0);
|
|
26718
26793
|
}
|
|
@@ -26727,7 +26802,7 @@ function computePointInFront(rotationVector, distance2) {
|
|
|
26727
26802
|
}
|
|
26728
26803
|
var CubeWithLabeledSides = ({}) => {
|
|
26729
26804
|
const { camera, scene } = useThree();
|
|
26730
|
-
|
|
26805
|
+
useEffect11(() => {
|
|
26731
26806
|
if (!scene) return;
|
|
26732
26807
|
const ambientLight = new THREE8.AmbientLight(16777215, Math.PI / 2);
|
|
26733
26808
|
scene.add(ambientLight);
|
|
@@ -26742,7 +26817,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26742
26817
|
camera.position.copy(cameraPosition);
|
|
26743
26818
|
camera.lookAt(0, 0, 0);
|
|
26744
26819
|
});
|
|
26745
|
-
const group =
|
|
26820
|
+
const group = useMemo9(() => {
|
|
26746
26821
|
const g = new THREE8.Group();
|
|
26747
26822
|
g.rotation.fromArray([Math.PI / 2, 0, 0]);
|
|
26748
26823
|
const box = new THREE8.Mesh(
|
|
@@ -26757,7 +26832,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26757
26832
|
g.add(edges);
|
|
26758
26833
|
return g;
|
|
26759
26834
|
}, []);
|
|
26760
|
-
|
|
26835
|
+
useEffect11(() => {
|
|
26761
26836
|
if (!scene) return;
|
|
26762
26837
|
scene.add(group);
|
|
26763
26838
|
return () => {
|
|
@@ -26765,7 +26840,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26765
26840
|
};
|
|
26766
26841
|
}, [scene, group]);
|
|
26767
26842
|
return /* @__PURE__ */ jsxs3(Fragment4, { children: [
|
|
26768
|
-
/* @__PURE__ */
|
|
26843
|
+
/* @__PURE__ */ jsx10(
|
|
26769
26844
|
Text,
|
|
26770
26845
|
{
|
|
26771
26846
|
parent: group,
|
|
@@ -26775,7 +26850,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26775
26850
|
children: "Front"
|
|
26776
26851
|
}
|
|
26777
26852
|
),
|
|
26778
|
-
/* @__PURE__ */
|
|
26853
|
+
/* @__PURE__ */ jsx10(
|
|
26779
26854
|
Text,
|
|
26780
26855
|
{
|
|
26781
26856
|
parent: group,
|
|
@@ -26786,7 +26861,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26786
26861
|
children: "Back"
|
|
26787
26862
|
}
|
|
26788
26863
|
),
|
|
26789
|
-
/* @__PURE__ */
|
|
26864
|
+
/* @__PURE__ */ jsx10(
|
|
26790
26865
|
Text,
|
|
26791
26866
|
{
|
|
26792
26867
|
parent: group,
|
|
@@ -26797,7 +26872,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26797
26872
|
children: "Right"
|
|
26798
26873
|
}
|
|
26799
26874
|
),
|
|
26800
|
-
/* @__PURE__ */
|
|
26875
|
+
/* @__PURE__ */ jsx10(
|
|
26801
26876
|
Text,
|
|
26802
26877
|
{
|
|
26803
26878
|
parent: group,
|
|
@@ -26808,7 +26883,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26808
26883
|
children: "Left"
|
|
26809
26884
|
}
|
|
26810
26885
|
),
|
|
26811
|
-
/* @__PURE__ */
|
|
26886
|
+
/* @__PURE__ */ jsx10(
|
|
26812
26887
|
Text,
|
|
26813
26888
|
{
|
|
26814
26889
|
parent: group,
|
|
@@ -26819,7 +26894,7 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26819
26894
|
children: "Top"
|
|
26820
26895
|
}
|
|
26821
26896
|
),
|
|
26822
|
-
/* @__PURE__ */
|
|
26897
|
+
/* @__PURE__ */ jsx10(
|
|
26823
26898
|
Text,
|
|
26824
26899
|
{
|
|
26825
26900
|
parent: group,
|
|
@@ -26836,12 +26911,12 @@ var CubeWithLabeledSides = ({}) => {
|
|
|
26836
26911
|
// src/react-three/Canvas.tsx
|
|
26837
26912
|
import {
|
|
26838
26913
|
useRef as useRef4,
|
|
26839
|
-
useEffect as
|
|
26840
|
-
useState as
|
|
26841
|
-
useCallback as
|
|
26914
|
+
useEffect as useEffect12,
|
|
26915
|
+
useState as useState7,
|
|
26916
|
+
useCallback as useCallback4,
|
|
26842
26917
|
forwardRef,
|
|
26843
26918
|
useImperativeHandle,
|
|
26844
|
-
useMemo as
|
|
26919
|
+
useMemo as useMemo10
|
|
26845
26920
|
} from "react";
|
|
26846
26921
|
import * as THREE10 from "three";
|
|
26847
26922
|
|
|
@@ -26859,23 +26934,23 @@ var configureRenderer = (renderer) => {
|
|
|
26859
26934
|
};
|
|
26860
26935
|
|
|
26861
26936
|
// src/react-three/Canvas.tsx
|
|
26862
|
-
import { jsx as
|
|
26937
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
26863
26938
|
var Canvas = forwardRef(
|
|
26864
26939
|
({ children, scene: sceneProps, camera: cameraProps, style }, ref) => {
|
|
26865
26940
|
const mountRef = useRef4(null);
|
|
26866
|
-
const [contextState, setContextState] =
|
|
26941
|
+
const [contextState, setContextState] = useState7(
|
|
26867
26942
|
null
|
|
26868
26943
|
);
|
|
26869
26944
|
const frameListeners = useRef4(
|
|
26870
26945
|
[]
|
|
26871
26946
|
);
|
|
26872
|
-
const addFrameListener =
|
|
26947
|
+
const addFrameListener = useCallback4(
|
|
26873
26948
|
(listener) => {
|
|
26874
26949
|
frameListeners.current.push(listener);
|
|
26875
26950
|
},
|
|
26876
26951
|
[]
|
|
26877
26952
|
);
|
|
26878
|
-
const removeFrameListener =
|
|
26953
|
+
const removeFrameListener = useCallback4(
|
|
26879
26954
|
(listener) => {
|
|
26880
26955
|
frameListeners.current = frameListeners.current.filter(
|
|
26881
26956
|
(l) => l !== listener
|
|
@@ -26883,13 +26958,13 @@ var Canvas = forwardRef(
|
|
|
26883
26958
|
},
|
|
26884
26959
|
[]
|
|
26885
26960
|
);
|
|
26886
|
-
const scene =
|
|
26961
|
+
const scene = useMemo10(() => new THREE10.Scene(), []);
|
|
26887
26962
|
if (sceneProps?.up) {
|
|
26888
26963
|
scene.up.set(sceneProps.up.x, sceneProps.up.y, sceneProps.up.z);
|
|
26889
26964
|
}
|
|
26890
26965
|
const rootObject = useRef4(new THREE10.Object3D());
|
|
26891
26966
|
useImperativeHandle(ref, () => rootObject.current);
|
|
26892
|
-
|
|
26967
|
+
useEffect12(() => {
|
|
26893
26968
|
if (!mountRef.current) return;
|
|
26894
26969
|
removeExistingCanvases(mountRef.current);
|
|
26895
26970
|
const renderer = new THREE10.WebGLRenderer({ antialias: true, alpha: true });
|
|
@@ -26961,12 +27036,12 @@ var Canvas = forwardRef(
|
|
|
26961
27036
|
}
|
|
26962
27037
|
};
|
|
26963
27038
|
}, [scene, addFrameListener, removeFrameListener]);
|
|
26964
|
-
return /* @__PURE__ */
|
|
27039
|
+
return /* @__PURE__ */ jsx11("div", { ref: mountRef, style: { width: "100%", height: "100%", ...style }, children: contextState && /* @__PURE__ */ jsx11(ThreeContext.Provider, { value: contextState, children: /* @__PURE__ */ jsx11(HoverProvider, { children }) }) });
|
|
26965
27040
|
}
|
|
26966
27041
|
);
|
|
26967
27042
|
|
|
26968
27043
|
// src/react-three/OrbitControls.tsx
|
|
26969
|
-
import { useEffect as
|
|
27044
|
+
import { useEffect as useEffect13, useMemo as useMemo11 } from "react";
|
|
26970
27045
|
import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
26971
27046
|
var OrbitControls = ({
|
|
26972
27047
|
autoRotate,
|
|
@@ -26980,11 +27055,11 @@ var OrbitControls = ({
|
|
|
26980
27055
|
target
|
|
26981
27056
|
}) => {
|
|
26982
27057
|
const { camera, renderer } = useThree();
|
|
26983
|
-
const controls =
|
|
27058
|
+
const controls = useMemo11(() => {
|
|
26984
27059
|
if (!camera || !renderer) return null;
|
|
26985
27060
|
return new ThreeOrbitControls(camera, renderer.domElement);
|
|
26986
27061
|
}, [camera, renderer]);
|
|
26987
|
-
|
|
27062
|
+
useEffect13(() => {
|
|
26988
27063
|
if (!controls) return;
|
|
26989
27064
|
controls.autoRotate = autoRotate || false;
|
|
26990
27065
|
controls.autoRotateSpeed = autoRotateSpeed || 1;
|
|
@@ -27009,14 +27084,14 @@ var OrbitControls = ({
|
|
|
27009
27084
|
dampingFactor,
|
|
27010
27085
|
target
|
|
27011
27086
|
]);
|
|
27012
|
-
|
|
27087
|
+
useEffect13(() => {
|
|
27013
27088
|
if (!controls || !onStart) return;
|
|
27014
27089
|
controls.addEventListener("start", onStart);
|
|
27015
27090
|
return () => {
|
|
27016
27091
|
controls.removeEventListener("start", onStart);
|
|
27017
27092
|
};
|
|
27018
27093
|
}, [controls, onStart]);
|
|
27019
|
-
|
|
27094
|
+
useEffect13(() => {
|
|
27020
27095
|
if (!controls) return;
|
|
27021
27096
|
return () => {
|
|
27022
27097
|
controls.dispose();
|
|
@@ -27029,7 +27104,7 @@ var OrbitControls = ({
|
|
|
27029
27104
|
};
|
|
27030
27105
|
|
|
27031
27106
|
// src/react-three/Grid.tsx
|
|
27032
|
-
import { useEffect as
|
|
27107
|
+
import { useEffect as useEffect14, useMemo as useMemo12 } from "react";
|
|
27033
27108
|
import * as THREE11 from "three";
|
|
27034
27109
|
var vertexShader = `
|
|
27035
27110
|
varying vec3 worldPosition;
|
|
@@ -27075,7 +27150,7 @@ var Grid = ({
|
|
|
27075
27150
|
}) => {
|
|
27076
27151
|
const { scene, camera } = useThree();
|
|
27077
27152
|
const size2 = 1e3;
|
|
27078
|
-
const gridMesh =
|
|
27153
|
+
const gridMesh = useMemo12(() => {
|
|
27079
27154
|
const geometry = new THREE11.PlaneGeometry(size2, size2);
|
|
27080
27155
|
geometry.rotateX(-Math.PI / 2);
|
|
27081
27156
|
const material = new THREE11.ShaderMaterial({
|
|
@@ -27104,7 +27179,7 @@ var Grid = ({
|
|
|
27104
27179
|
gridMesh.position.set(camera.position.x, camera.position.y, 0);
|
|
27105
27180
|
}
|
|
27106
27181
|
});
|
|
27107
|
-
|
|
27182
|
+
useEffect14(() => {
|
|
27108
27183
|
if (!scene || !gridMesh) return;
|
|
27109
27184
|
scene.add(gridMesh);
|
|
27110
27185
|
return () => {
|
|
@@ -27121,21 +27196,21 @@ var Grid = ({
|
|
|
27121
27196
|
};
|
|
27122
27197
|
|
|
27123
27198
|
// src/react-three/Lights.tsx
|
|
27124
|
-
import { useEffect as
|
|
27199
|
+
import { useEffect as useEffect15, useMemo as useMemo13 } from "react";
|
|
27125
27200
|
import * as THREE12 from "three";
|
|
27126
27201
|
var Lights = () => {
|
|
27127
27202
|
const { scene } = useThree();
|
|
27128
|
-
const ambientLight =
|
|
27203
|
+
const ambientLight = useMemo13(
|
|
27129
27204
|
() => new THREE12.AmbientLight(16777215, Math.PI / 2),
|
|
27130
27205
|
[]
|
|
27131
27206
|
);
|
|
27132
|
-
const pointLight =
|
|
27207
|
+
const pointLight = useMemo13(() => {
|
|
27133
27208
|
const light = new THREE12.PointLight(16777215, Math.PI / 4);
|
|
27134
27209
|
light.position.set(-10, -10, 10);
|
|
27135
27210
|
light.decay = 0;
|
|
27136
27211
|
return light;
|
|
27137
27212
|
}, []);
|
|
27138
|
-
|
|
27213
|
+
useEffect15(() => {
|
|
27139
27214
|
if (!scene) return;
|
|
27140
27215
|
scene.add(ambientLight);
|
|
27141
27216
|
scene.add(pointLight);
|
|
@@ -27148,7 +27223,7 @@ var Lights = () => {
|
|
|
27148
27223
|
};
|
|
27149
27224
|
|
|
27150
27225
|
// src/CadViewerContainer.tsx
|
|
27151
|
-
import { jsx as
|
|
27226
|
+
import { jsx as jsx12, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
27152
27227
|
var RotationTracker = () => {
|
|
27153
27228
|
const { camera } = useThree();
|
|
27154
27229
|
useFrame(() => {
|
|
@@ -27168,10 +27243,10 @@ var CadViewerContainer = forwardRef2(
|
|
|
27168
27243
|
boardCenter,
|
|
27169
27244
|
onUserInteraction
|
|
27170
27245
|
}, ref) => {
|
|
27171
|
-
const [isInteractionEnabled, setIsInteractionEnabled] =
|
|
27246
|
+
const [isInteractionEnabled, setIsInteractionEnabled] = useState8(
|
|
27172
27247
|
!clickToInteractEnabled
|
|
27173
27248
|
);
|
|
27174
|
-
const gridSectionSize =
|
|
27249
|
+
const gridSectionSize = useMemo14(() => {
|
|
27175
27250
|
if (!boardDimensions) return 10;
|
|
27176
27251
|
const width10 = boardDimensions.width ?? 0;
|
|
27177
27252
|
const height10 = boardDimensions.height ?? 0;
|
|
@@ -27179,12 +27254,12 @@ var CadViewerContainer = forwardRef2(
|
|
|
27179
27254
|
const desired = largest * 1.5;
|
|
27180
27255
|
return desired > 10 ? desired : 10;
|
|
27181
27256
|
}, [boardDimensions]);
|
|
27182
|
-
const orbitTarget =
|
|
27257
|
+
const orbitTarget = useMemo14(() => {
|
|
27183
27258
|
if (!boardCenter) return void 0;
|
|
27184
27259
|
return [boardCenter.x, boardCenter.y, 0];
|
|
27185
27260
|
}, [boardCenter]);
|
|
27186
27261
|
return /* @__PURE__ */ jsxs4("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
|
|
27187
|
-
/* @__PURE__ */
|
|
27262
|
+
/* @__PURE__ */ jsx12(
|
|
27188
27263
|
"div",
|
|
27189
27264
|
{
|
|
27190
27265
|
style: {
|
|
@@ -27194,7 +27269,7 @@ var CadViewerContainer = forwardRef2(
|
|
|
27194
27269
|
width: 120,
|
|
27195
27270
|
height: 120
|
|
27196
27271
|
},
|
|
27197
|
-
children: /* @__PURE__ */
|
|
27272
|
+
children: /* @__PURE__ */ jsx12(
|
|
27198
27273
|
Canvas,
|
|
27199
27274
|
{
|
|
27200
27275
|
camera: {
|
|
@@ -27202,7 +27277,7 @@ var CadViewerContainer = forwardRef2(
|
|
|
27202
27277
|
position: [1, 1, 1]
|
|
27203
27278
|
},
|
|
27204
27279
|
style: { zIndex: 10 },
|
|
27205
|
-
children: /* @__PURE__ */
|
|
27280
|
+
children: /* @__PURE__ */ jsx12(CubeWithLabeledSides, {})
|
|
27206
27281
|
}
|
|
27207
27282
|
)
|
|
27208
27283
|
}
|
|
@@ -27214,8 +27289,8 @@ var CadViewerContainer = forwardRef2(
|
|
|
27214
27289
|
scene: { up: new THREE13.Vector3(0, 0, 1) },
|
|
27215
27290
|
camera: { up: [0, 0, 1], position: initialCameraPosition },
|
|
27216
27291
|
children: [
|
|
27217
|
-
/* @__PURE__ */
|
|
27218
|
-
isInteractionEnabled && /* @__PURE__ */
|
|
27292
|
+
/* @__PURE__ */ jsx12(RotationTracker, {}),
|
|
27293
|
+
isInteractionEnabled && /* @__PURE__ */ jsx12(
|
|
27219
27294
|
OrbitControls,
|
|
27220
27295
|
{
|
|
27221
27296
|
autoRotate: !autoRotateDisabled,
|
|
@@ -27229,8 +27304,8 @@ var CadViewerContainer = forwardRef2(
|
|
|
27229
27304
|
target: orbitTarget
|
|
27230
27305
|
}
|
|
27231
27306
|
),
|
|
27232
|
-
/* @__PURE__ */
|
|
27233
|
-
/* @__PURE__ */
|
|
27307
|
+
/* @__PURE__ */ jsx12(Lights, {}),
|
|
27308
|
+
/* @__PURE__ */ jsx12(
|
|
27234
27309
|
Grid,
|
|
27235
27310
|
{
|
|
27236
27311
|
rotation: [Math.PI / 2, 0, 0],
|
|
@@ -27262,7 +27337,7 @@ var CadViewerContainer = forwardRef2(
|
|
|
27262
27337
|
]
|
|
27263
27338
|
}
|
|
27264
27339
|
),
|
|
27265
|
-
clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */
|
|
27340
|
+
clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx12(
|
|
27266
27341
|
"button",
|
|
27267
27342
|
{
|
|
27268
27343
|
type: "button",
|
|
@@ -27281,7 +27356,7 @@ var CadViewerContainer = forwardRef2(
|
|
|
27281
27356
|
alignItems: "center",
|
|
27282
27357
|
justifyContent: "center"
|
|
27283
27358
|
},
|
|
27284
|
-
children: /* @__PURE__ */
|
|
27359
|
+
children: /* @__PURE__ */ jsx12(
|
|
27285
27360
|
"div",
|
|
27286
27361
|
{
|
|
27287
27362
|
style: {
|
|
@@ -27304,9 +27379,9 @@ var CadViewerContainer = forwardRef2(
|
|
|
27304
27379
|
|
|
27305
27380
|
// src/hooks/use-convert-children-to-soup.ts
|
|
27306
27381
|
import { Circuit } from "@tscircuit/core";
|
|
27307
|
-
import { useMemo as
|
|
27382
|
+
import { useMemo as useMemo15 } from "react";
|
|
27308
27383
|
var useConvertChildrenToCircuitJson = (children) => {
|
|
27309
|
-
return
|
|
27384
|
+
return useMemo15(() => {
|
|
27310
27385
|
if (!children) return [];
|
|
27311
27386
|
const circuit = new Circuit();
|
|
27312
27387
|
circuit.add(children);
|
|
@@ -27316,21 +27391,23 @@ var useConvertChildrenToCircuitJson = (children) => {
|
|
|
27316
27391
|
};
|
|
27317
27392
|
|
|
27318
27393
|
// src/hooks/use-stls-from-geom.ts
|
|
27319
|
-
import { useState as
|
|
27394
|
+
import { useState as useState9, useEffect as useEffect17 } from "react";
|
|
27320
27395
|
import stlSerializer from "@jscad/stl-serializer";
|
|
27321
27396
|
var useStlsFromGeom = (geom) => {
|
|
27322
|
-
const [stls, setStls] =
|
|
27323
|
-
const [loading, setLoading] =
|
|
27324
|
-
|
|
27397
|
+
const [stls, setStls] = useState9([]);
|
|
27398
|
+
const [loading, setLoading] = useState9(true);
|
|
27399
|
+
useEffect17(() => {
|
|
27325
27400
|
if (!geom) return;
|
|
27326
27401
|
const generateStls = async () => {
|
|
27327
27402
|
setLoading(true);
|
|
27328
27403
|
const geometries = Array.isArray(geom) ? geom : [geom];
|
|
27329
|
-
const stlPromises = geometries.map(async (g) => {
|
|
27404
|
+
const stlPromises = geometries.map(async (g, index) => {
|
|
27330
27405
|
const rawParts = stlSerializer.serialize({ binary: true }, [g]);
|
|
27331
27406
|
const blob = new Blob(rawParts);
|
|
27332
27407
|
const stlData = await blob.arrayBuffer();
|
|
27333
|
-
|
|
27408
|
+
const layerType = g.layerType;
|
|
27409
|
+
const inferredLayerType = layerType || (index === 0 ? "board" : void 0);
|
|
27410
|
+
return { stlData, color: g.color, layerType: inferredLayerType };
|
|
27334
27411
|
});
|
|
27335
27412
|
try {
|
|
27336
27413
|
const generatedStls = await Promise.all(stlPromises);
|
|
@@ -27348,7 +27425,7 @@ var useStlsFromGeom = (geom) => {
|
|
|
27348
27425
|
};
|
|
27349
27426
|
|
|
27350
27427
|
// src/hooks/useBoardGeomBuilder.ts
|
|
27351
|
-
import { useState as
|
|
27428
|
+
import { useState as useState10, useEffect as useEffect18, useRef as useRef6 } from "react";
|
|
27352
27429
|
|
|
27353
27430
|
// src/soup-to-3d/index.ts
|
|
27354
27431
|
var import_primitives2 = __toESM(require_primitives(), 1);
|
|
@@ -28555,7 +28632,11 @@ var BoardGeomBuilder = class {
|
|
|
28555
28632
|
let cyGeom = null;
|
|
28556
28633
|
if (ph.shape === "circular_hole_with_rect_pad") {
|
|
28557
28634
|
cyGeom = (0, import_primitives6.cylinder)({
|
|
28558
|
-
center: [
|
|
28635
|
+
center: [
|
|
28636
|
+
ph.x + (ph.hole_offset_x || 0),
|
|
28637
|
+
ph.y + (ph.hole_offset_y || 0),
|
|
28638
|
+
0
|
|
28639
|
+
],
|
|
28559
28640
|
radius: ph.hole_diameter / 2 + M,
|
|
28560
28641
|
// Add margin for subtraction
|
|
28561
28642
|
height: this.ctx.pcbThickness * 1.5
|
|
@@ -28590,17 +28671,21 @@ var BoardGeomBuilder = class {
|
|
|
28590
28671
|
if (ph.shape === "pill_hole_with_rect_pad") {
|
|
28591
28672
|
pillHole = (0, import_booleans3.union)(
|
|
28592
28673
|
(0, import_primitives6.cuboid)({
|
|
28593
|
-
center: [
|
|
28674
|
+
center: [
|
|
28675
|
+
ph.x + (ph.hole_offset_x || 0),
|
|
28676
|
+
ph.y + (ph.hole_offset_y || 0),
|
|
28677
|
+
0
|
|
28678
|
+
],
|
|
28594
28679
|
size: shouldRotate ? [holeHeight, rectLength, this.ctx.pcbThickness * 1.5] : [rectLength, holeHeight, this.ctx.pcbThickness * 1.5]
|
|
28595
28680
|
}),
|
|
28596
28681
|
(0, import_primitives6.cylinder)({
|
|
28597
28682
|
center: shouldRotate ? [
|
|
28598
|
-
ph.x + ph.hole_offset_x,
|
|
28599
|
-
ph.y + ph.hole_offset_y - rectLength / 2,
|
|
28683
|
+
ph.x + (ph.hole_offset_x || 0),
|
|
28684
|
+
ph.y + (ph.hole_offset_y || 0) - rectLength / 2,
|
|
28600
28685
|
0
|
|
28601
28686
|
] : [
|
|
28602
|
-
ph.x + ph.hole_offset_x - rectLength / 2,
|
|
28603
|
-
ph.y + ph.hole_offset_y,
|
|
28687
|
+
ph.x + (ph.hole_offset_x || 0) - rectLength / 2,
|
|
28688
|
+
ph.y + (ph.hole_offset_y || 0),
|
|
28604
28689
|
0
|
|
28605
28690
|
],
|
|
28606
28691
|
radius: holeRadius,
|
|
@@ -28608,12 +28693,12 @@ var BoardGeomBuilder = class {
|
|
|
28608
28693
|
}),
|
|
28609
28694
|
(0, import_primitives6.cylinder)({
|
|
28610
28695
|
center: shouldRotate ? [
|
|
28611
|
-
ph.x + ph.hole_offset_x,
|
|
28612
|
-
ph.y + ph.hole_offset_y + rectLength / 2,
|
|
28696
|
+
ph.x + (ph.hole_offset_x || 0),
|
|
28697
|
+
ph.y + (ph.hole_offset_y || 0) + rectLength / 2,
|
|
28613
28698
|
0
|
|
28614
28699
|
] : [
|
|
28615
|
-
ph.x + ph.hole_offset_x + rectLength / 2,
|
|
28616
|
-
ph.y + ph.hole_offset_y,
|
|
28700
|
+
ph.x + (ph.hole_offset_x || 0) + rectLength / 2,
|
|
28701
|
+
ph.y + (ph.hole_offset_y || 0),
|
|
28617
28702
|
0
|
|
28618
28703
|
],
|
|
28619
28704
|
radius: holeRadius,
|
|
@@ -28978,9 +29063,9 @@ var BoardGeomBuilder = class {
|
|
|
28978
29063
|
|
|
28979
29064
|
// src/hooks/useBoardGeomBuilder.ts
|
|
28980
29065
|
var useBoardGeomBuilder = (circuitJson) => {
|
|
28981
|
-
const [boardGeom, setBoardGeom] =
|
|
29066
|
+
const [boardGeom, setBoardGeom] = useState10(null);
|
|
28982
29067
|
const isProcessingRef = useRef6(false);
|
|
28983
|
-
|
|
29068
|
+
useEffect18(() => {
|
|
28984
29069
|
let isCancelled = false;
|
|
28985
29070
|
if (!circuitJson) {
|
|
28986
29071
|
setBoardGeom(null);
|
|
@@ -29023,17 +29108,17 @@ var useBoardGeomBuilder = (circuitJson) => {
|
|
|
29023
29108
|
};
|
|
29024
29109
|
|
|
29025
29110
|
// src/three-components/Error3d.tsx
|
|
29026
|
-
import { useState as
|
|
29111
|
+
import { useState as useState11, useCallback as useCallback5, useEffect as useEffect19, useMemo as useMemo16 } from "react";
|
|
29027
29112
|
import * as THREE14 from "three";
|
|
29028
|
-
import { Fragment as Fragment5, jsx as
|
|
29113
|
+
import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
29029
29114
|
var Error3d = ({
|
|
29030
29115
|
error,
|
|
29031
29116
|
cad_component: cad_component2
|
|
29032
29117
|
}) => {
|
|
29033
29118
|
const { rootObject } = useThree();
|
|
29034
|
-
const [isHovered, setIsHovered] =
|
|
29035
|
-
const [hoverPosition, setHoverPosition] =
|
|
29036
|
-
const handleHover =
|
|
29119
|
+
const [isHovered, setIsHovered] = useState11(false);
|
|
29120
|
+
const [hoverPosition, setHoverPosition] = useState11(null);
|
|
29121
|
+
const handleHover = useCallback5((e) => {
|
|
29037
29122
|
if (e?.mousePosition) {
|
|
29038
29123
|
setIsHovered(true);
|
|
29039
29124
|
setHoverPosition(e.mousePosition);
|
|
@@ -29042,11 +29127,11 @@ var Error3d = ({
|
|
|
29042
29127
|
setHoverPosition(null);
|
|
29043
29128
|
}
|
|
29044
29129
|
}, []);
|
|
29045
|
-
const handleUnhover =
|
|
29130
|
+
const handleUnhover = useCallback5(() => {
|
|
29046
29131
|
setIsHovered(false);
|
|
29047
29132
|
setHoverPosition(null);
|
|
29048
29133
|
}, []);
|
|
29049
|
-
const position =
|
|
29134
|
+
const position = useMemo16(() => {
|
|
29050
29135
|
if (cad_component2?.position) {
|
|
29051
29136
|
const p = [
|
|
29052
29137
|
cad_component2.position.x,
|
|
@@ -29057,12 +29142,12 @@ var Error3d = ({
|
|
|
29057
29142
|
}
|
|
29058
29143
|
return [0, 0, 0];
|
|
29059
29144
|
}, [cad_component2]);
|
|
29060
|
-
const group =
|
|
29145
|
+
const group = useMemo16(() => {
|
|
29061
29146
|
const g = new THREE14.Group();
|
|
29062
29147
|
g.position.fromArray(position);
|
|
29063
29148
|
return g;
|
|
29064
29149
|
}, [position]);
|
|
29065
|
-
|
|
29150
|
+
useEffect19(() => {
|
|
29066
29151
|
if (!rootObject) return;
|
|
29067
29152
|
rootObject.add(group);
|
|
29068
29153
|
return () => {
|
|
@@ -29078,8 +29163,8 @@ var Error3d = ({
|
|
|
29078
29163
|
onUnhover: handleUnhover,
|
|
29079
29164
|
object: group,
|
|
29080
29165
|
children: [
|
|
29081
|
-
/* @__PURE__ */
|
|
29082
|
-
/* @__PURE__ */
|
|
29166
|
+
/* @__PURE__ */ jsx13(ErrorBox, { parent: group }),
|
|
29167
|
+
/* @__PURE__ */ jsx13(
|
|
29083
29168
|
Text,
|
|
29084
29169
|
{
|
|
29085
29170
|
parent: group,
|
|
@@ -29094,7 +29179,7 @@ var Error3d = ({
|
|
|
29094
29179
|
]
|
|
29095
29180
|
}
|
|
29096
29181
|
),
|
|
29097
|
-
isHovered && hoverPosition ? /* @__PURE__ */
|
|
29182
|
+
isHovered && hoverPosition ? /* @__PURE__ */ jsx13(
|
|
29098
29183
|
Html,
|
|
29099
29184
|
{
|
|
29100
29185
|
position: hoverPosition,
|
|
@@ -29117,7 +29202,7 @@ var Error3d = ({
|
|
|
29117
29202
|
] });
|
|
29118
29203
|
};
|
|
29119
29204
|
var ErrorBox = ({ parent }) => {
|
|
29120
|
-
const mesh =
|
|
29205
|
+
const mesh = useMemo16(() => {
|
|
29121
29206
|
const m = new THREE14.Mesh(
|
|
29122
29207
|
new THREE14.BoxGeometry(0.5, 0.5, 0.5),
|
|
29123
29208
|
new THREE14.MeshStandardMaterial({
|
|
@@ -29131,7 +29216,7 @@ var ErrorBox = ({ parent }) => {
|
|
|
29131
29216
|
m.rotation.fromArray([Math.PI / 4, Math.PI / 4, 0]);
|
|
29132
29217
|
return m;
|
|
29133
29218
|
}, []);
|
|
29134
|
-
|
|
29219
|
+
useEffect19(() => {
|
|
29135
29220
|
parent.add(mesh);
|
|
29136
29221
|
return () => {
|
|
29137
29222
|
parent.remove(mesh);
|
|
@@ -29141,7 +29226,7 @@ var ErrorBox = ({ parent }) => {
|
|
|
29141
29226
|
};
|
|
29142
29227
|
|
|
29143
29228
|
// src/three-components/STLModel.tsx
|
|
29144
|
-
import { useState as
|
|
29229
|
+
import { useState as useState12, useEffect as useEffect20, useMemo as useMemo17 } from "react";
|
|
29145
29230
|
import * as THREE15 from "three";
|
|
29146
29231
|
import { STLLoader } from "three-stdlib";
|
|
29147
29232
|
function STLModel({
|
|
@@ -29152,8 +29237,8 @@ function STLModel({
|
|
|
29152
29237
|
opacity = 1
|
|
29153
29238
|
}) {
|
|
29154
29239
|
const { rootObject } = useThree();
|
|
29155
|
-
const [geom, setGeom] =
|
|
29156
|
-
|
|
29240
|
+
const [geom, setGeom] = useState12(null);
|
|
29241
|
+
useEffect20(() => {
|
|
29157
29242
|
const loader = new STLLoader();
|
|
29158
29243
|
if (stlData) {
|
|
29159
29244
|
try {
|
|
@@ -29171,7 +29256,7 @@ function STLModel({
|
|
|
29171
29256
|
});
|
|
29172
29257
|
}
|
|
29173
29258
|
}, [stlUrl, stlData]);
|
|
29174
|
-
const mesh =
|
|
29259
|
+
const mesh = useMemo17(() => {
|
|
29175
29260
|
if (!geom) return null;
|
|
29176
29261
|
const material = new THREE15.MeshStandardMaterial({
|
|
29177
29262
|
color: Array.isArray(color) ? new THREE15.Color(color[0], color[1], color[2]) : color,
|
|
@@ -29180,7 +29265,7 @@ function STLModel({
|
|
|
29180
29265
|
});
|
|
29181
29266
|
return new THREE15.Mesh(geom, material);
|
|
29182
29267
|
}, [geom, color, opacity]);
|
|
29183
|
-
|
|
29268
|
+
useEffect20(() => {
|
|
29184
29269
|
if (!rootObject || !mesh) return;
|
|
29185
29270
|
rootObject.add(mesh);
|
|
29186
29271
|
return () => {
|
|
@@ -29196,9 +29281,36 @@ function STLModel({
|
|
|
29196
29281
|
return null;
|
|
29197
29282
|
}
|
|
29198
29283
|
|
|
29284
|
+
// src/three-components/VisibleSTLModel.tsx
|
|
29285
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
29286
|
+
function VisibleSTLModel({
|
|
29287
|
+
stlData,
|
|
29288
|
+
color,
|
|
29289
|
+
opacity = 1,
|
|
29290
|
+
layerType
|
|
29291
|
+
}) {
|
|
29292
|
+
const { visibility } = useLayerVisibility();
|
|
29293
|
+
let shouldShow = true;
|
|
29294
|
+
if (layerType === "board") {
|
|
29295
|
+
shouldShow = visibility.boardBody;
|
|
29296
|
+
} else if (layerType === "top-copper") {
|
|
29297
|
+
shouldShow = visibility.topCopper;
|
|
29298
|
+
} else if (layerType === "bottom-copper") {
|
|
29299
|
+
shouldShow = visibility.bottomCopper;
|
|
29300
|
+
} else if (layerType === "top-silkscreen") {
|
|
29301
|
+
shouldShow = visibility.topSilkscreen;
|
|
29302
|
+
} else if (layerType === "bottom-silkscreen") {
|
|
29303
|
+
shouldShow = visibility.bottomSilkscreen;
|
|
29304
|
+
}
|
|
29305
|
+
if (!shouldShow) {
|
|
29306
|
+
return null;
|
|
29307
|
+
}
|
|
29308
|
+
return /* @__PURE__ */ jsx14(STLModel, { stlData, color, opacity });
|
|
29309
|
+
}
|
|
29310
|
+
|
|
29199
29311
|
// src/three-components/ThreeErrorBoundary.tsx
|
|
29200
|
-
import
|
|
29201
|
-
var ThreeErrorBoundary = class extends
|
|
29312
|
+
import React11 from "react";
|
|
29313
|
+
var ThreeErrorBoundary = class extends React11.Component {
|
|
29202
29314
|
constructor(props) {
|
|
29203
29315
|
super(props);
|
|
29204
29316
|
this.state = { hasError: false, error: null };
|
|
@@ -29215,7 +29327,7 @@ var ThreeErrorBoundary = class extends React10.Component {
|
|
|
29215
29327
|
};
|
|
29216
29328
|
|
|
29217
29329
|
// src/CadViewerJscad.tsx
|
|
29218
|
-
import { jsx as
|
|
29330
|
+
import { jsx as jsx15, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
29219
29331
|
var CadViewerJscad = forwardRef3(
|
|
29220
29332
|
({
|
|
29221
29333
|
soup,
|
|
@@ -29226,12 +29338,12 @@ var CadViewerJscad = forwardRef3(
|
|
|
29226
29338
|
onUserInteraction
|
|
29227
29339
|
}, ref) => {
|
|
29228
29340
|
const childrenSoup = useConvertChildrenToCircuitJson(children);
|
|
29229
|
-
const internalCircuitJson =
|
|
29341
|
+
const internalCircuitJson = useMemo18(() => {
|
|
29230
29342
|
const cj = soup ?? circuitJson;
|
|
29231
29343
|
return cj ?? childrenSoup;
|
|
29232
29344
|
}, [soup, circuitJson, childrenSoup]);
|
|
29233
29345
|
const boardGeom = useBoardGeomBuilder(internalCircuitJson);
|
|
29234
|
-
const initialCameraPosition =
|
|
29346
|
+
const initialCameraPosition = useMemo18(() => {
|
|
29235
29347
|
if (!internalCircuitJson) return [5, 5, 5];
|
|
29236
29348
|
try {
|
|
29237
29349
|
const board = su4(internalCircuitJson).pcb_board.list()[0];
|
|
@@ -29250,7 +29362,7 @@ var CadViewerJscad = forwardRef3(
|
|
|
29250
29362
|
return [5, 5, 5];
|
|
29251
29363
|
}
|
|
29252
29364
|
}, [internalCircuitJson]);
|
|
29253
|
-
const boardDimensions =
|
|
29365
|
+
const boardDimensions = useMemo18(() => {
|
|
29254
29366
|
if (!internalCircuitJson) return void 0;
|
|
29255
29367
|
try {
|
|
29256
29368
|
const board = su4(internalCircuitJson).pcb_board.list()[0];
|
|
@@ -29261,7 +29373,7 @@ var CadViewerJscad = forwardRef3(
|
|
|
29261
29373
|
return void 0;
|
|
29262
29374
|
}
|
|
29263
29375
|
}, [internalCircuitJson]);
|
|
29264
|
-
const boardCenter =
|
|
29376
|
+
const boardCenter = useMemo18(() => {
|
|
29265
29377
|
if (!internalCircuitJson) return void 0;
|
|
29266
29378
|
try {
|
|
29267
29379
|
const board = su4(internalCircuitJson).pcb_board.list()[0];
|
|
@@ -29285,20 +29397,21 @@ var CadViewerJscad = forwardRef3(
|
|
|
29285
29397
|
boardCenter,
|
|
29286
29398
|
onUserInteraction,
|
|
29287
29399
|
children: [
|
|
29288
|
-
boardStls.map(({ stlData, color }, index) => /* @__PURE__ */
|
|
29289
|
-
|
|
29400
|
+
boardStls.map(({ stlData, color, layerType }, index) => /* @__PURE__ */ jsx15(
|
|
29401
|
+
VisibleSTLModel,
|
|
29290
29402
|
{
|
|
29291
29403
|
stlData,
|
|
29292
29404
|
color,
|
|
29293
|
-
opacity: index === 0 ? 0.95 : 1
|
|
29405
|
+
opacity: index === 0 ? 0.95 : 1,
|
|
29406
|
+
layerType
|
|
29294
29407
|
},
|
|
29295
|
-
`board-${index
|
|
29408
|
+
`board-${index}`
|
|
29296
29409
|
)),
|
|
29297
|
-
cad_components.map((cad_component2) => /* @__PURE__ */
|
|
29410
|
+
cad_components.map((cad_component2) => /* @__PURE__ */ jsx15(
|
|
29298
29411
|
ThreeErrorBoundary,
|
|
29299
29412
|
{
|
|
29300
|
-
fallback: ({ error }) => /* @__PURE__ */
|
|
29301
|
-
children: /* @__PURE__ */
|
|
29413
|
+
fallback: ({ error }) => /* @__PURE__ */ jsx15(Error3d, { cad_component: cad_component2, error }),
|
|
29414
|
+
children: /* @__PURE__ */ jsx15(
|
|
29302
29415
|
AnyCadComponent,
|
|
29303
29416
|
{
|
|
29304
29417
|
cad_component: cad_component2,
|
|
@@ -29317,10 +29430,10 @@ var CadViewerJscad = forwardRef3(
|
|
|
29317
29430
|
|
|
29318
29431
|
// src/CadViewerManifold.tsx
|
|
29319
29432
|
import { su as su13 } from "@tscircuit/circuit-json-util";
|
|
29320
|
-
import { useEffect as
|
|
29433
|
+
import { useEffect as useEffect22, useMemo as useMemo20, useState as useState15 } from "react";
|
|
29321
29434
|
|
|
29322
29435
|
// src/hooks/useManifoldBoardBuilder.ts
|
|
29323
|
-
import { useState as
|
|
29436
|
+
import { useState as useState14, useEffect as useEffect21, useMemo as useMemo19, useRef as useRef7 } from "react";
|
|
29324
29437
|
import { su as su12 } from "@tscircuit/circuit-json-util";
|
|
29325
29438
|
import * as THREE23 from "three";
|
|
29326
29439
|
|
|
@@ -30174,7 +30287,7 @@ function processSmtPadsForManifold(Manifold, circuitJson, pcbThickness, manifold
|
|
|
30174
30287
|
}
|
|
30175
30288
|
const threeGeom = manifoldMeshToThreeGeometry(finalPadOp.getMesh());
|
|
30176
30289
|
smtPadGeoms.push({
|
|
30177
|
-
key: `
|
|
30290
|
+
key: `smt_pad-${pad2.layer || "top"}-${pad2.pcb_smtpad_id || index}`,
|
|
30178
30291
|
geometry: threeGeom,
|
|
30179
30292
|
color: COPPER_COLOR3
|
|
30180
30293
|
});
|
|
@@ -30513,20 +30626,20 @@ function processCutoutsForManifold(Manifold, CrossSection, circuitJson, pcbThick
|
|
|
30513
30626
|
|
|
30514
30627
|
// src/hooks/useManifoldBoardBuilder.ts
|
|
30515
30628
|
var useManifoldBoardBuilder = (manifoldJSModule, circuitJson) => {
|
|
30516
|
-
const [geoms, setGeoms] =
|
|
30517
|
-
const [textures, setTextures] =
|
|
30518
|
-
const [pcbThickness, setPcbThickness] =
|
|
30519
|
-
const [error, setError] =
|
|
30520
|
-
const [isLoading, setIsLoading] =
|
|
30629
|
+
const [geoms, setGeoms] = useState14(null);
|
|
30630
|
+
const [textures, setTextures] = useState14(null);
|
|
30631
|
+
const [pcbThickness, setPcbThickness] = useState14(null);
|
|
30632
|
+
const [error, setError] = useState14(null);
|
|
30633
|
+
const [isLoading, setIsLoading] = useState14(true);
|
|
30521
30634
|
const manifoldInstancesForCleanup = useRef7([]);
|
|
30522
|
-
const boardData =
|
|
30635
|
+
const boardData = useMemo19(() => {
|
|
30523
30636
|
const boards = su12(circuitJson).pcb_board.list();
|
|
30524
30637
|
if (boards.length === 0) {
|
|
30525
30638
|
return null;
|
|
30526
30639
|
}
|
|
30527
30640
|
return boards[0];
|
|
30528
30641
|
}, [circuitJson]);
|
|
30529
|
-
|
|
30642
|
+
useEffect21(() => {
|
|
30530
30643
|
if (!manifoldJSModule || !boardData) {
|
|
30531
30644
|
setGeoms(null);
|
|
30532
30645
|
setTextures(null);
|
|
@@ -30872,21 +30985,64 @@ function createTextureMeshes(textures, boardData, pcbThickness) {
|
|
|
30872
30985
|
}
|
|
30873
30986
|
|
|
30874
30987
|
// src/CadViewerManifold.tsx
|
|
30875
|
-
import { jsx as
|
|
30988
|
+
import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
30876
30989
|
var BoardMeshes = ({
|
|
30877
30990
|
geometryMeshes,
|
|
30878
30991
|
textureMeshes
|
|
30879
30992
|
}) => {
|
|
30880
30993
|
const { rootObject } = useThree();
|
|
30881
|
-
|
|
30994
|
+
const { visibility } = useLayerVisibility();
|
|
30995
|
+
useEffect22(() => {
|
|
30882
30996
|
if (!rootObject) return;
|
|
30883
|
-
geometryMeshes.forEach((mesh) =>
|
|
30884
|
-
|
|
30997
|
+
geometryMeshes.forEach((mesh) => {
|
|
30998
|
+
let shouldShow = true;
|
|
30999
|
+
if (mesh.name === "board-geom") {
|
|
31000
|
+
shouldShow = visibility.boardBody;
|
|
31001
|
+
} else if (mesh.name.includes("smt_pad")) {
|
|
31002
|
+
if (mesh.name.includes("smt_pad-top")) {
|
|
31003
|
+
shouldShow = visibility.topCopper;
|
|
31004
|
+
} else if (mesh.name.includes("smt_pad-bottom")) {
|
|
31005
|
+
shouldShow = visibility.bottomCopper;
|
|
31006
|
+
} else {
|
|
31007
|
+
shouldShow = visibility.topCopper || visibility.bottomCopper;
|
|
31008
|
+
}
|
|
31009
|
+
} else if (mesh.name.includes("plated_hole") || mesh.name.includes("via")) {
|
|
31010
|
+
shouldShow = visibility.topCopper || visibility.bottomCopper;
|
|
31011
|
+
} else if (mesh.name.includes("copper_pour")) {
|
|
31012
|
+
shouldShow = visibility.topCopper || visibility.bottomCopper;
|
|
31013
|
+
}
|
|
31014
|
+
if (shouldShow) {
|
|
31015
|
+
rootObject.add(mesh);
|
|
31016
|
+
}
|
|
31017
|
+
});
|
|
31018
|
+
textureMeshes.forEach((mesh) => {
|
|
31019
|
+
let shouldShow = true;
|
|
31020
|
+
if (mesh.name.includes("top-trace")) {
|
|
31021
|
+
shouldShow = visibility.topCopper;
|
|
31022
|
+
} else if (mesh.name.includes("bottom-trace")) {
|
|
31023
|
+
shouldShow = visibility.bottomCopper;
|
|
31024
|
+
} else if (mesh.name.includes("top-silkscreen")) {
|
|
31025
|
+
shouldShow = visibility.topSilkscreen;
|
|
31026
|
+
} else if (mesh.name.includes("bottom-silkscreen")) {
|
|
31027
|
+
shouldShow = visibility.bottomSilkscreen;
|
|
31028
|
+
}
|
|
31029
|
+
if (shouldShow) {
|
|
31030
|
+
rootObject.add(mesh);
|
|
31031
|
+
}
|
|
31032
|
+
});
|
|
30885
31033
|
return () => {
|
|
30886
|
-
geometryMeshes.forEach((mesh) =>
|
|
30887
|
-
|
|
31034
|
+
geometryMeshes.forEach((mesh) => {
|
|
31035
|
+
if (mesh.parent === rootObject) {
|
|
31036
|
+
rootObject.remove(mesh);
|
|
31037
|
+
}
|
|
31038
|
+
});
|
|
31039
|
+
textureMeshes.forEach((mesh) => {
|
|
31040
|
+
if (mesh.parent === rootObject) {
|
|
31041
|
+
rootObject.remove(mesh);
|
|
31042
|
+
}
|
|
31043
|
+
});
|
|
30888
31044
|
};
|
|
30889
|
-
}, [rootObject, geometryMeshes, textureMeshes]);
|
|
31045
|
+
}, [rootObject, geometryMeshes, textureMeshes, visibility]);
|
|
30890
31046
|
return null;
|
|
30891
31047
|
};
|
|
30892
31048
|
var MANIFOLD_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1";
|
|
@@ -30898,12 +31054,12 @@ var CadViewerManifold = ({
|
|
|
30898
31054
|
children
|
|
30899
31055
|
}) => {
|
|
30900
31056
|
const childrenCircuitJson = useConvertChildrenToCircuitJson(children);
|
|
30901
|
-
const circuitJson =
|
|
31057
|
+
const circuitJson = useMemo20(() => {
|
|
30902
31058
|
return circuitJsonProp ?? childrenCircuitJson;
|
|
30903
31059
|
}, [circuitJsonProp, childrenCircuitJson]);
|
|
30904
|
-
const [manifoldJSModule, setManifoldJSModule] =
|
|
30905
|
-
const [manifoldLoadingError, setManifoldLoadingError] =
|
|
30906
|
-
|
|
31060
|
+
const [manifoldJSModule, setManifoldJSModule] = useState15(null);
|
|
31061
|
+
const [manifoldLoadingError, setManifoldLoadingError] = useState15(null);
|
|
31062
|
+
useEffect22(() => {
|
|
30907
31063
|
if (window.ManifoldModule && typeof window.ManifoldModule === "object" && window.ManifoldModule.setup) {
|
|
30908
31064
|
setManifoldJSModule(window.ManifoldModule);
|
|
30909
31065
|
return;
|
|
@@ -30973,27 +31129,27 @@ try {
|
|
|
30973
31129
|
isLoading: builderIsLoading,
|
|
30974
31130
|
boardData
|
|
30975
31131
|
} = useManifoldBoardBuilder(manifoldJSModule, circuitJson);
|
|
30976
|
-
const geometryMeshes =
|
|
30977
|
-
const textureMeshes =
|
|
31132
|
+
const geometryMeshes = useMemo20(() => createGeometryMeshes(geoms), [geoms]);
|
|
31133
|
+
const textureMeshes = useMemo20(
|
|
30978
31134
|
() => createTextureMeshes(textures, boardData, pcbThickness),
|
|
30979
31135
|
[textures, boardData, pcbThickness]
|
|
30980
31136
|
);
|
|
30981
|
-
const cadComponents =
|
|
31137
|
+
const cadComponents = useMemo20(
|
|
30982
31138
|
() => su13(circuitJson).cad_component.list(),
|
|
30983
31139
|
[circuitJson]
|
|
30984
31140
|
);
|
|
30985
|
-
const boardDimensions =
|
|
31141
|
+
const boardDimensions = useMemo20(() => {
|
|
30986
31142
|
if (!boardData) return void 0;
|
|
30987
31143
|
const { width: width10 = 0, height: height10 = 0 } = boardData;
|
|
30988
31144
|
return { width: width10, height: height10 };
|
|
30989
31145
|
}, [boardData]);
|
|
30990
|
-
const boardCenter =
|
|
31146
|
+
const boardCenter = useMemo20(() => {
|
|
30991
31147
|
if (!boardData) return void 0;
|
|
30992
31148
|
const { center } = boardData;
|
|
30993
31149
|
if (!center) return void 0;
|
|
30994
31150
|
return { x: center.x, y: center.y };
|
|
30995
31151
|
}, [boardData]);
|
|
30996
|
-
const initialCameraPosition =
|
|
31152
|
+
const initialCameraPosition = useMemo20(() => {
|
|
30997
31153
|
if (!boardData) return [5, 5, 5];
|
|
30998
31154
|
const { width: width10 = 0, height: height10 = 0 } = boardData;
|
|
30999
31155
|
const safeWidth = Math.max(width10, 1);
|
|
@@ -31019,7 +31175,7 @@ try {
|
|
|
31019
31175
|
);
|
|
31020
31176
|
}
|
|
31021
31177
|
if (!manifoldJSModule) {
|
|
31022
|
-
return /* @__PURE__ */
|
|
31178
|
+
return /* @__PURE__ */ jsx16("div", { style: { padding: "1em" }, children: "Loading Manifold module..." });
|
|
31023
31179
|
}
|
|
31024
31180
|
if (builderError) {
|
|
31025
31181
|
return /* @__PURE__ */ jsxs7(
|
|
@@ -31039,7 +31195,7 @@ try {
|
|
|
31039
31195
|
);
|
|
31040
31196
|
}
|
|
31041
31197
|
if (builderIsLoading) {
|
|
31042
|
-
return /* @__PURE__ */
|
|
31198
|
+
return /* @__PURE__ */ jsx16("div", { style: { padding: "1em" }, children: "Processing board geometry..." });
|
|
31043
31199
|
}
|
|
31044
31200
|
return /* @__PURE__ */ jsxs7(
|
|
31045
31201
|
CadViewerContainer,
|
|
@@ -31051,18 +31207,18 @@ try {
|
|
|
31051
31207
|
boardCenter,
|
|
31052
31208
|
onUserInteraction,
|
|
31053
31209
|
children: [
|
|
31054
|
-
/* @__PURE__ */
|
|
31210
|
+
/* @__PURE__ */ jsx16(
|
|
31055
31211
|
BoardMeshes,
|
|
31056
31212
|
{
|
|
31057
31213
|
geometryMeshes,
|
|
31058
31214
|
textureMeshes
|
|
31059
31215
|
}
|
|
31060
31216
|
),
|
|
31061
|
-
cadComponents.map((cad_component2) => /* @__PURE__ */
|
|
31217
|
+
cadComponents.map((cad_component2) => /* @__PURE__ */ jsx16(
|
|
31062
31218
|
ThreeErrorBoundary,
|
|
31063
31219
|
{
|
|
31064
|
-
fallback: ({ error }) => /* @__PURE__ */
|
|
31065
|
-
children: /* @__PURE__ */
|
|
31220
|
+
fallback: ({ error }) => /* @__PURE__ */ jsx16(Error3d, { cad_component: cad_component2, error }),
|
|
31221
|
+
children: /* @__PURE__ */ jsx16(
|
|
31066
31222
|
AnyCadComponent,
|
|
31067
31223
|
{
|
|
31068
31224
|
cad_component: cad_component2,
|
|
@@ -31079,10 +31235,10 @@ try {
|
|
|
31079
31235
|
var CadViewerManifold_default = CadViewerManifold;
|
|
31080
31236
|
|
|
31081
31237
|
// src/hooks/useContextMenu.ts
|
|
31082
|
-
import { useState as
|
|
31238
|
+
import { useState as useState16, useCallback as useCallback7, useRef as useRef8, useEffect as useEffect23 } from "react";
|
|
31083
31239
|
var useContextMenu = ({ containerRef }) => {
|
|
31084
|
-
const [menuVisible, setMenuVisible] =
|
|
31085
|
-
const [menuPos, setMenuPos] =
|
|
31240
|
+
const [menuVisible, setMenuVisible] = useState16(false);
|
|
31241
|
+
const [menuPos, setMenuPos] = useState16({
|
|
31086
31242
|
x: 0,
|
|
31087
31243
|
y: 0
|
|
31088
31244
|
});
|
|
@@ -31096,7 +31252,7 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31096
31252
|
longPressTimeoutRef.current = null;
|
|
31097
31253
|
}
|
|
31098
31254
|
};
|
|
31099
|
-
const handleContextMenu =
|
|
31255
|
+
const handleContextMenu = useCallback7(
|
|
31100
31256
|
(e) => {
|
|
31101
31257
|
e.preventDefault();
|
|
31102
31258
|
const eventX = typeof e.clientX === "number" ? e.clientX : 0;
|
|
@@ -31122,7 +31278,7 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31122
31278
|
},
|
|
31123
31279
|
[setMenuPos, setMenuVisible]
|
|
31124
31280
|
);
|
|
31125
|
-
const handleTouchStart =
|
|
31281
|
+
const handleTouchStart = useCallback7(
|
|
31126
31282
|
(e) => {
|
|
31127
31283
|
if (e.touches.length === 1) {
|
|
31128
31284
|
const touch = e.touches[0];
|
|
@@ -31155,7 +31311,7 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31155
31311
|
},
|
|
31156
31312
|
[containerRef]
|
|
31157
31313
|
);
|
|
31158
|
-
const handleTouchMove =
|
|
31314
|
+
const handleTouchMove = useCallback7((e) => {
|
|
31159
31315
|
if (!interactionOriginPosRef.current || e.touches.length !== 1) {
|
|
31160
31316
|
return;
|
|
31161
31317
|
}
|
|
@@ -31173,7 +31329,7 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31173
31329
|
clearLongPressTimeout();
|
|
31174
31330
|
}
|
|
31175
31331
|
}, []);
|
|
31176
|
-
const handleTouchEnd =
|
|
31332
|
+
const handleTouchEnd = useCallback7(() => {
|
|
31177
31333
|
clearLongPressTimeout();
|
|
31178
31334
|
setTimeout(() => {
|
|
31179
31335
|
if (interactionOriginPosRef.current) {
|
|
@@ -31181,13 +31337,13 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31181
31337
|
}
|
|
31182
31338
|
}, 0);
|
|
31183
31339
|
}, []);
|
|
31184
|
-
const handleClickAway =
|
|
31340
|
+
const handleClickAway = useCallback7((e) => {
|
|
31185
31341
|
const target = e.target;
|
|
31186
31342
|
if (menuRef.current && !menuRef.current.contains(target)) {
|
|
31187
31343
|
setMenuVisible(false);
|
|
31188
31344
|
}
|
|
31189
31345
|
}, []);
|
|
31190
|
-
|
|
31346
|
+
useEffect23(() => {
|
|
31191
31347
|
if (menuVisible) {
|
|
31192
31348
|
document.addEventListener("mousedown", handleClickAway);
|
|
31193
31349
|
document.addEventListener("touchstart", handleClickAway);
|
|
@@ -31221,10 +31377,10 @@ var useContextMenu = ({ containerRef }) => {
|
|
|
31221
31377
|
};
|
|
31222
31378
|
|
|
31223
31379
|
// src/hooks/useGlobalDownloadGltf.ts
|
|
31224
|
-
import { useCallback as
|
|
31380
|
+
import { useCallback as useCallback8 } from "react";
|
|
31225
31381
|
import { GLTFExporter } from "three-stdlib";
|
|
31226
31382
|
var useGlobalDownloadGltf = () => {
|
|
31227
|
-
return
|
|
31383
|
+
return useCallback8(() => {
|
|
31228
31384
|
const root = window.__TSCIRCUIT_THREE_OBJECT;
|
|
31229
31385
|
if (!root) return;
|
|
31230
31386
|
const exporter = new GLTFExporter();
|
|
@@ -31249,13 +31405,190 @@ var useGlobalDownloadGltf = () => {
|
|
|
31249
31405
|
}, []);
|
|
31250
31406
|
};
|
|
31251
31407
|
|
|
31408
|
+
// src/components/AppearanceMenu.tsx
|
|
31409
|
+
import { useState as useState17 } from "react";
|
|
31410
|
+
import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
31411
|
+
var menuItemStyle = {
|
|
31412
|
+
padding: "8px 18px",
|
|
31413
|
+
cursor: "pointer",
|
|
31414
|
+
display: "flex",
|
|
31415
|
+
alignItems: "center",
|
|
31416
|
+
gap: 10,
|
|
31417
|
+
color: "#f5f6fa",
|
|
31418
|
+
fontWeight: 400,
|
|
31419
|
+
fontSize: 14,
|
|
31420
|
+
transition: "background 0.1s"
|
|
31421
|
+
};
|
|
31422
|
+
var checkmarkStyle = {
|
|
31423
|
+
width: 20
|
|
31424
|
+
};
|
|
31425
|
+
var handleMouseOver = (e) => {
|
|
31426
|
+
e.currentTarget.style.background = "#2d313a";
|
|
31427
|
+
};
|
|
31428
|
+
var handleMouseOut = (e) => {
|
|
31429
|
+
e.currentTarget.style.background = "transparent";
|
|
31430
|
+
};
|
|
31431
|
+
var AppearanceMenu = () => {
|
|
31432
|
+
const { visibility, toggleLayer } = useLayerVisibility();
|
|
31433
|
+
const [showSubmenu, setShowSubmenu] = useState17(false);
|
|
31434
|
+
return /* @__PURE__ */ jsxs8(Fragment6, { children: [
|
|
31435
|
+
/* @__PURE__ */ jsx17(
|
|
31436
|
+
"div",
|
|
31437
|
+
{
|
|
31438
|
+
style: {
|
|
31439
|
+
borderTop: "1px solid rgba(255, 255, 255, 0.1)",
|
|
31440
|
+
margin: "8px 0"
|
|
31441
|
+
}
|
|
31442
|
+
}
|
|
31443
|
+
),
|
|
31444
|
+
/* @__PURE__ */ jsxs8(
|
|
31445
|
+
"div",
|
|
31446
|
+
{
|
|
31447
|
+
style: {
|
|
31448
|
+
padding: "8px 18px",
|
|
31449
|
+
fontSize: 14,
|
|
31450
|
+
color: "#f5f6fa",
|
|
31451
|
+
fontWeight: 400,
|
|
31452
|
+
cursor: "pointer",
|
|
31453
|
+
display: "flex",
|
|
31454
|
+
alignItems: "center",
|
|
31455
|
+
justifyContent: "space-between",
|
|
31456
|
+
transition: "background 0.1s",
|
|
31457
|
+
position: "relative"
|
|
31458
|
+
},
|
|
31459
|
+
onMouseEnter: () => setShowSubmenu(true),
|
|
31460
|
+
onMouseLeave: () => setShowSubmenu(false),
|
|
31461
|
+
onMouseOver: handleMouseOver,
|
|
31462
|
+
onMouseOut: handleMouseOut,
|
|
31463
|
+
children: [
|
|
31464
|
+
/* @__PURE__ */ jsx17("span", { children: "Appearance" }),
|
|
31465
|
+
/* @__PURE__ */ jsx17(
|
|
31466
|
+
"span",
|
|
31467
|
+
{
|
|
31468
|
+
style: {
|
|
31469
|
+
fontSize: 10,
|
|
31470
|
+
transform: showSubmenu ? "rotate(90deg)" : "rotate(0deg)",
|
|
31471
|
+
transition: "transform 0.2s",
|
|
31472
|
+
display: "inline-block"
|
|
31473
|
+
},
|
|
31474
|
+
children: "\u25B6"
|
|
31475
|
+
}
|
|
31476
|
+
),
|
|
31477
|
+
showSubmenu && /* @__PURE__ */ jsxs8(
|
|
31478
|
+
"div",
|
|
31479
|
+
{
|
|
31480
|
+
style: {
|
|
31481
|
+
position: "absolute",
|
|
31482
|
+
left: "100%",
|
|
31483
|
+
top: 0,
|
|
31484
|
+
minWidth: 200,
|
|
31485
|
+
background: "#23272f",
|
|
31486
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
31487
|
+
borderRadius: 6,
|
|
31488
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.4)",
|
|
31489
|
+
zIndex: 1e3,
|
|
31490
|
+
marginTop: 8,
|
|
31491
|
+
marginBottom: 8
|
|
31492
|
+
},
|
|
31493
|
+
onMouseEnter: () => setShowSubmenu(true),
|
|
31494
|
+
onMouseLeave: () => setShowSubmenu(false),
|
|
31495
|
+
onClick: (e) => e.stopPropagation(),
|
|
31496
|
+
children: [
|
|
31497
|
+
/* @__PURE__ */ jsxs8(
|
|
31498
|
+
"div",
|
|
31499
|
+
{
|
|
31500
|
+
style: menuItemStyle,
|
|
31501
|
+
onClick: () => toggleLayer("boardBody"),
|
|
31502
|
+
onMouseOver: handleMouseOver,
|
|
31503
|
+
onMouseOut: handleMouseOut,
|
|
31504
|
+
children: [
|
|
31505
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.boardBody ? "\u2714" : "" }),
|
|
31506
|
+
"Board Body"
|
|
31507
|
+
]
|
|
31508
|
+
}
|
|
31509
|
+
),
|
|
31510
|
+
/* @__PURE__ */ jsxs8(
|
|
31511
|
+
"div",
|
|
31512
|
+
{
|
|
31513
|
+
style: menuItemStyle,
|
|
31514
|
+
onClick: () => toggleLayer("topCopper"),
|
|
31515
|
+
onMouseOver: handleMouseOver,
|
|
31516
|
+
onMouseOut: handleMouseOut,
|
|
31517
|
+
children: [
|
|
31518
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.topCopper ? "\u2714" : "" }),
|
|
31519
|
+
"Top Copper"
|
|
31520
|
+
]
|
|
31521
|
+
}
|
|
31522
|
+
),
|
|
31523
|
+
/* @__PURE__ */ jsxs8(
|
|
31524
|
+
"div",
|
|
31525
|
+
{
|
|
31526
|
+
style: menuItemStyle,
|
|
31527
|
+
onClick: () => toggleLayer("bottomCopper"),
|
|
31528
|
+
onMouseOver: handleMouseOver,
|
|
31529
|
+
onMouseOut: handleMouseOut,
|
|
31530
|
+
children: [
|
|
31531
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.bottomCopper ? "\u2714" : "" }),
|
|
31532
|
+
"Bottom Copper"
|
|
31533
|
+
]
|
|
31534
|
+
}
|
|
31535
|
+
),
|
|
31536
|
+
/* @__PURE__ */ jsxs8(
|
|
31537
|
+
"div",
|
|
31538
|
+
{
|
|
31539
|
+
style: menuItemStyle,
|
|
31540
|
+
onClick: () => toggleLayer("topSilkscreen"),
|
|
31541
|
+
onMouseOver: handleMouseOver,
|
|
31542
|
+
onMouseOut: handleMouseOut,
|
|
31543
|
+
children: [
|
|
31544
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.topSilkscreen ? "\u2714" : "" }),
|
|
31545
|
+
"Top Silkscreen"
|
|
31546
|
+
]
|
|
31547
|
+
}
|
|
31548
|
+
),
|
|
31549
|
+
/* @__PURE__ */ jsxs8(
|
|
31550
|
+
"div",
|
|
31551
|
+
{
|
|
31552
|
+
style: menuItemStyle,
|
|
31553
|
+
onClick: () => toggleLayer("bottomSilkscreen"),
|
|
31554
|
+
onMouseOver: handleMouseOver,
|
|
31555
|
+
onMouseOut: handleMouseOut,
|
|
31556
|
+
children: [
|
|
31557
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.bottomSilkscreen ? "\u2714" : "" }),
|
|
31558
|
+
"Bottom Silkscreen"
|
|
31559
|
+
]
|
|
31560
|
+
}
|
|
31561
|
+
),
|
|
31562
|
+
/* @__PURE__ */ jsxs8(
|
|
31563
|
+
"div",
|
|
31564
|
+
{
|
|
31565
|
+
style: menuItemStyle,
|
|
31566
|
+
onClick: () => toggleLayer("smtModels"),
|
|
31567
|
+
onMouseOver: handleMouseOver,
|
|
31568
|
+
onMouseOut: handleMouseOut,
|
|
31569
|
+
children: [
|
|
31570
|
+
/* @__PURE__ */ jsx17("span", { style: checkmarkStyle, children: visibility.smtModels ? "\u2714" : "" }),
|
|
31571
|
+
"CAD Models"
|
|
31572
|
+
]
|
|
31573
|
+
}
|
|
31574
|
+
)
|
|
31575
|
+
]
|
|
31576
|
+
}
|
|
31577
|
+
)
|
|
31578
|
+
]
|
|
31579
|
+
}
|
|
31580
|
+
)
|
|
31581
|
+
] });
|
|
31582
|
+
};
|
|
31583
|
+
|
|
31252
31584
|
// src/CadViewer.tsx
|
|
31253
|
-
import { jsx as
|
|
31254
|
-
var
|
|
31255
|
-
const [engine, setEngine] =
|
|
31585
|
+
import { jsx as jsx18, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
31586
|
+
var CadViewerInner = (props) => {
|
|
31587
|
+
const [engine, setEngine] = useState18("manifold");
|
|
31256
31588
|
const containerRef = useRef9(null);
|
|
31257
|
-
const [autoRotate, setAutoRotate] =
|
|
31258
|
-
const [autoRotateUserToggled, setAutoRotateUserToggled] =
|
|
31589
|
+
const [autoRotate, setAutoRotate] = useState18(true);
|
|
31590
|
+
const [autoRotateUserToggled, setAutoRotateUserToggled] = useState18(false);
|
|
31591
|
+
const { visibility, toggleLayer } = useLayerVisibility();
|
|
31259
31592
|
const {
|
|
31260
31593
|
menuVisible,
|
|
31261
31594
|
menuPos,
|
|
@@ -31265,12 +31598,12 @@ var CadViewer = (props) => {
|
|
|
31265
31598
|
} = useContextMenu({ containerRef });
|
|
31266
31599
|
const autoRotateUserToggledRef = useRef9(autoRotateUserToggled);
|
|
31267
31600
|
autoRotateUserToggledRef.current = autoRotateUserToggled;
|
|
31268
|
-
const handleUserInteraction =
|
|
31601
|
+
const handleUserInteraction = useCallback9(() => {
|
|
31269
31602
|
if (!autoRotateUserToggledRef.current) {
|
|
31270
31603
|
setAutoRotate(false);
|
|
31271
31604
|
}
|
|
31272
31605
|
}, []);
|
|
31273
|
-
const toggleAutoRotate =
|
|
31606
|
+
const toggleAutoRotate = useCallback9(() => {
|
|
31274
31607
|
setAutoRotate((prev) => !prev);
|
|
31275
31608
|
setAutoRotateUserToggled(true);
|
|
31276
31609
|
}, []);
|
|
@@ -31279,17 +31612,17 @@ var CadViewer = (props) => {
|
|
|
31279
31612
|
setEngine(newEngine);
|
|
31280
31613
|
setMenuVisible(false);
|
|
31281
31614
|
};
|
|
31282
|
-
|
|
31615
|
+
useEffect24(() => {
|
|
31283
31616
|
const stored = window.localStorage.getItem("cadViewerEngine");
|
|
31284
31617
|
if (stored === "jscad" || stored === "manifold") {
|
|
31285
31618
|
setEngine(stored);
|
|
31286
31619
|
}
|
|
31287
31620
|
}, []);
|
|
31288
|
-
|
|
31621
|
+
useEffect24(() => {
|
|
31289
31622
|
window.localStorage.setItem("cadViewerEngine", engine);
|
|
31290
31623
|
}, [engine]);
|
|
31291
31624
|
const viewerKey = props.circuitJson ? JSON.stringify(props.circuitJson) : void 0;
|
|
31292
|
-
return /* @__PURE__ */
|
|
31625
|
+
return /* @__PURE__ */ jsxs9(
|
|
31293
31626
|
"div",
|
|
31294
31627
|
{
|
|
31295
31628
|
ref: containerRef,
|
|
@@ -31305,14 +31638,14 @@ var CadViewer = (props) => {
|
|
|
31305
31638
|
},
|
|
31306
31639
|
...contextMenuEventHandlers,
|
|
31307
31640
|
children: [
|
|
31308
|
-
engine === "jscad" ? /* @__PURE__ */
|
|
31641
|
+
engine === "jscad" ? /* @__PURE__ */ jsx18(
|
|
31309
31642
|
CadViewerJscad,
|
|
31310
31643
|
{
|
|
31311
31644
|
...props,
|
|
31312
31645
|
autoRotateDisabled: props.autoRotateDisabled || !autoRotate,
|
|
31313
31646
|
onUserInteraction: handleUserInteraction
|
|
31314
31647
|
}
|
|
31315
|
-
) : /* @__PURE__ */
|
|
31648
|
+
) : /* @__PURE__ */ jsx18(
|
|
31316
31649
|
CadViewerManifold_default,
|
|
31317
31650
|
{
|
|
31318
31651
|
...props,
|
|
@@ -31320,7 +31653,7 @@ var CadViewer = (props) => {
|
|
|
31320
31653
|
onUserInteraction: handleUserInteraction
|
|
31321
31654
|
}
|
|
31322
31655
|
),
|
|
31323
|
-
/* @__PURE__ */
|
|
31656
|
+
/* @__PURE__ */ jsxs9(
|
|
31324
31657
|
"div",
|
|
31325
31658
|
{
|
|
31326
31659
|
style: {
|
|
@@ -31337,11 +31670,11 @@ var CadViewer = (props) => {
|
|
|
31337
31670
|
},
|
|
31338
31671
|
children: [
|
|
31339
31672
|
"Engine: ",
|
|
31340
|
-
/* @__PURE__ */
|
|
31673
|
+
/* @__PURE__ */ jsx18("b", { children: engine === "jscad" ? "JSCAD" : "Manifold" })
|
|
31341
31674
|
]
|
|
31342
31675
|
}
|
|
31343
31676
|
),
|
|
31344
|
-
menuVisible && /* @__PURE__ */
|
|
31677
|
+
menuVisible && /* @__PURE__ */ jsxs9(
|
|
31345
31678
|
"div",
|
|
31346
31679
|
{
|
|
31347
31680
|
ref: menuRef,
|
|
@@ -31362,7 +31695,7 @@ var CadViewer = (props) => {
|
|
|
31362
31695
|
transition: "opacity 0.1s"
|
|
31363
31696
|
},
|
|
31364
31697
|
children: [
|
|
31365
|
-
/* @__PURE__ */
|
|
31698
|
+
/* @__PURE__ */ jsxs9(
|
|
31366
31699
|
"div",
|
|
31367
31700
|
{
|
|
31368
31701
|
style: {
|
|
@@ -31383,7 +31716,7 @@ var CadViewer = (props) => {
|
|
|
31383
31716
|
"Switch to ",
|
|
31384
31717
|
engine === "jscad" ? "Manifold" : "JSCAD",
|
|
31385
31718
|
" Engine",
|
|
31386
|
-
/* @__PURE__ */
|
|
31719
|
+
/* @__PURE__ */ jsx18(
|
|
31387
31720
|
"span",
|
|
31388
31721
|
{
|
|
31389
31722
|
style: {
|
|
@@ -31398,7 +31731,7 @@ var CadViewer = (props) => {
|
|
|
31398
31731
|
]
|
|
31399
31732
|
}
|
|
31400
31733
|
),
|
|
31401
|
-
/* @__PURE__ */
|
|
31734
|
+
/* @__PURE__ */ jsxs9(
|
|
31402
31735
|
"div",
|
|
31403
31736
|
{
|
|
31404
31737
|
style: {
|
|
@@ -31419,12 +31752,12 @@ var CadViewer = (props) => {
|
|
|
31419
31752
|
onMouseOver: (e) => e.currentTarget.style.background = "#2d313a",
|
|
31420
31753
|
onMouseOut: (e) => e.currentTarget.style.background = "transparent",
|
|
31421
31754
|
children: [
|
|
31422
|
-
/* @__PURE__ */
|
|
31755
|
+
/* @__PURE__ */ jsx18("span", { style: { marginRight: 8 }, children: autoRotate ? "\u2714" : "" }),
|
|
31423
31756
|
"Auto rotate"
|
|
31424
31757
|
]
|
|
31425
31758
|
}
|
|
31426
31759
|
),
|
|
31427
|
-
/* @__PURE__ */
|
|
31760
|
+
/* @__PURE__ */ jsx18(
|
|
31428
31761
|
"div",
|
|
31429
31762
|
{
|
|
31430
31763
|
style: {
|
|
@@ -31447,7 +31780,8 @@ var CadViewer = (props) => {
|
|
|
31447
31780
|
children: "Download GLTF"
|
|
31448
31781
|
}
|
|
31449
31782
|
),
|
|
31450
|
-
/* @__PURE__ */
|
|
31783
|
+
/* @__PURE__ */ jsx18(AppearanceMenu, {}),
|
|
31784
|
+
/* @__PURE__ */ jsx18(
|
|
31451
31785
|
"div",
|
|
31452
31786
|
{
|
|
31453
31787
|
style: {
|
|
@@ -31457,7 +31791,7 @@ var CadViewer = (props) => {
|
|
|
31457
31791
|
borderTop: "1px solid rgba(255, 255, 255, 0.1)",
|
|
31458
31792
|
marginTop: "8px"
|
|
31459
31793
|
},
|
|
31460
|
-
children: /* @__PURE__ */
|
|
31794
|
+
children: /* @__PURE__ */ jsxs9(
|
|
31461
31795
|
"span",
|
|
31462
31796
|
{
|
|
31463
31797
|
style: {
|
|
@@ -31482,6 +31816,9 @@ var CadViewer = (props) => {
|
|
|
31482
31816
|
viewerKey
|
|
31483
31817
|
);
|
|
31484
31818
|
};
|
|
31819
|
+
var CadViewer = (props) => {
|
|
31820
|
+
return /* @__PURE__ */ jsx18(LayerVisibilityProvider, { children: /* @__PURE__ */ jsx18(CadViewerInner, { ...props }) });
|
|
31821
|
+
};
|
|
31485
31822
|
|
|
31486
31823
|
// src/convert-circuit-json-to-3d-svg.ts
|
|
31487
31824
|
var import_debug = __toESM(require_browser(), 1);
|
|
@@ -31762,10 +32099,10 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
|
|
|
31762
32099
|
|
|
31763
32100
|
// src/hooks/exporter/gltf.ts
|
|
31764
32101
|
import { GLTFExporter as GLTFExporter2 } from "three-stdlib";
|
|
31765
|
-
import { useEffect as
|
|
32102
|
+
import { useEffect as useEffect25, useState as useState19, useMemo as useMemo21, useCallback as useCallback10 } from "react";
|
|
31766
32103
|
function useSaveGltfAs(options = {}) {
|
|
31767
32104
|
const parse = useParser(options);
|
|
31768
|
-
const link =
|
|
32105
|
+
const link = useMemo21(() => document.createElement("a"), []);
|
|
31769
32106
|
const saveAs = async (filename) => {
|
|
31770
32107
|
const name = filename ?? options.filename ?? "";
|
|
31771
32108
|
if (options.binary == null) options.binary = name.endsWith(".glb");
|
|
@@ -31775,7 +32112,7 @@ function useSaveGltfAs(options = {}) {
|
|
|
31775
32112
|
link.dispatchEvent(new MouseEvent("click"));
|
|
31776
32113
|
URL.revokeObjectURL(url);
|
|
31777
32114
|
};
|
|
31778
|
-
|
|
32115
|
+
useEffect25(
|
|
31779
32116
|
() => () => {
|
|
31780
32117
|
link.remove();
|
|
31781
32118
|
instance = null;
|
|
@@ -31783,24 +32120,24 @@ function useSaveGltfAs(options = {}) {
|
|
|
31783
32120
|
[]
|
|
31784
32121
|
);
|
|
31785
32122
|
let instance;
|
|
31786
|
-
const ref =
|
|
32123
|
+
const ref = useCallback10((obj3D) => {
|
|
31787
32124
|
instance = obj3D;
|
|
31788
32125
|
}, []);
|
|
31789
32126
|
return [ref, saveAs];
|
|
31790
32127
|
}
|
|
31791
32128
|
function useExportGltfUrl(options = {}) {
|
|
31792
32129
|
const parse = useParser(options);
|
|
31793
|
-
const [url, setUrl] =
|
|
31794
|
-
const [error, setError] =
|
|
31795
|
-
const ref =
|
|
32130
|
+
const [url, setUrl] = useState19();
|
|
32131
|
+
const [error, setError] = useState19();
|
|
32132
|
+
const ref = useCallback10(
|
|
31796
32133
|
(instance) => parse(instance).then(setUrl).catch(setError),
|
|
31797
32134
|
[]
|
|
31798
32135
|
);
|
|
31799
|
-
|
|
32136
|
+
useEffect25(() => () => URL.revokeObjectURL(url), [url]);
|
|
31800
32137
|
return [ref, url, error];
|
|
31801
32138
|
}
|
|
31802
32139
|
function useParser(options = {}) {
|
|
31803
|
-
const exporter =
|
|
32140
|
+
const exporter = useMemo21(() => new GLTFExporter2(), []);
|
|
31804
32141
|
return (instance) => {
|
|
31805
32142
|
const { promise, resolve, reject } = Promise.withResolvers();
|
|
31806
32143
|
exporter.parse(
|