@tscircuit/3d-viewer 0.0.414 → 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.
Files changed (2) hide show
  1. package/dist/index.js +515 -186
  2. 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 useState16, useCallback as useCallback8, useRef as useRef9, useEffect as useEffect23 } from "react";
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 useMemo17 } from "react";
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 useMemo6, useState as useState5, useCallback as useCallback2 } from "react";
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 jsx8, jsxs as jsxs2 } from "react/jsx-runtime";
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] = useState5(false);
26450
- const [hoverPosition, setHoverPosition] = useState5(null);
26451
- const handleHover = useCallback2((e) => {
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 = useCallback2(() => {
26532
+ const handleUnhover = useCallback3(() => {
26461
26533
  setIsHovered(false);
26462
26534
  setHoverPosition(null);
26463
26535
  }, []);
26464
- const componentName = useMemo6(() => {
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__ */ jsx8(
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__ */ jsx8(
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__ */ jsx8(
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__ */ jsx8(
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__ */ jsx8(
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 useMemo13,
26572
- useState as useState7
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.413",
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 useEffect10, useMemo as useMemo8 } from "react";
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 useEffect9, useMemo as useMemo7 } from "react";
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 = useMemo7(() => {
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
- useEffect9(() => {
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 jsx9, jsxs as jsxs3 } from "react/jsx-runtime";
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
- useEffect10(() => {
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 = useMemo8(() => {
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
- useEffect10(() => {
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__ */ jsx9(
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__ */ jsx9(
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__ */ jsx9(
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__ */ jsx9(
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__ */ jsx9(
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__ */ jsx9(
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 useEffect11,
26840
- useState as useState6,
26841
- useCallback as useCallback3,
26914
+ useEffect as useEffect12,
26915
+ useState as useState7,
26916
+ useCallback as useCallback4,
26842
26917
  forwardRef,
26843
26918
  useImperativeHandle,
26844
- useMemo as useMemo9
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 jsx10 } from "react/jsx-runtime";
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] = useState6(
26941
+ const [contextState, setContextState] = useState7(
26867
26942
  null
26868
26943
  );
26869
26944
  const frameListeners = useRef4(
26870
26945
  []
26871
26946
  );
26872
- const addFrameListener = useCallback3(
26947
+ const addFrameListener = useCallback4(
26873
26948
  (listener) => {
26874
26949
  frameListeners.current.push(listener);
26875
26950
  },
26876
26951
  []
26877
26952
  );
26878
- const removeFrameListener = useCallback3(
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 = useMemo9(() => new THREE10.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
- useEffect11(() => {
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__ */ jsx10("div", { ref: mountRef, style: { width: "100%", height: "100%", ...style }, children: contextState && /* @__PURE__ */ jsx10(ThreeContext.Provider, { value: contextState, children: /* @__PURE__ */ jsx10(HoverProvider, { children }) }) });
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 useEffect12, useMemo as useMemo10 } from "react";
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 = useMemo10(() => {
27058
+ const controls = useMemo11(() => {
26984
27059
  if (!camera || !renderer) return null;
26985
27060
  return new ThreeOrbitControls(camera, renderer.domElement);
26986
27061
  }, [camera, renderer]);
26987
- useEffect12(() => {
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
- useEffect12(() => {
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
- useEffect12(() => {
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 useEffect13, useMemo as useMemo11 } from "react";
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 = useMemo11(() => {
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
- useEffect13(() => {
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 useEffect14, useMemo as useMemo12 } from "react";
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 = useMemo12(
27203
+ const ambientLight = useMemo13(
27129
27204
  () => new THREE12.AmbientLight(16777215, Math.PI / 2),
27130
27205
  []
27131
27206
  );
27132
- const pointLight = useMemo12(() => {
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
- useEffect14(() => {
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 jsx11, jsxs as jsxs4 } from "react/jsx-runtime";
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] = useState7(
27246
+ const [isInteractionEnabled, setIsInteractionEnabled] = useState8(
27172
27247
  !clickToInteractEnabled
27173
27248
  );
27174
- const gridSectionSize = useMemo13(() => {
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 = useMemo13(() => {
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__ */ jsx11(
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__ */ jsx11(
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__ */ jsx11(CubeWithLabeledSides, {})
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__ */ jsx11(RotationTracker, {}),
27218
- isInteractionEnabled && /* @__PURE__ */ jsx11(
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__ */ jsx11(Lights, {}),
27233
- /* @__PURE__ */ jsx11(
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__ */ jsx11(
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__ */ jsx11(
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 useMemo14 } from "react";
27382
+ import { useMemo as useMemo15 } from "react";
27308
27383
  var useConvertChildrenToCircuitJson = (children) => {
27309
- return useMemo14(() => {
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 useState8, useEffect as useEffect16 } from "react";
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] = useState8([]);
27323
- const [loading, setLoading] = useState8(true);
27324
- useEffect16(() => {
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
- return { stlData, color: g.color };
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 useState9, useEffect as useEffect17, useRef as useRef6 } from "react";
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);
@@ -28986,9 +29063,9 @@ var BoardGeomBuilder = class {
28986
29063
 
28987
29064
  // src/hooks/useBoardGeomBuilder.ts
28988
29065
  var useBoardGeomBuilder = (circuitJson) => {
28989
- const [boardGeom, setBoardGeom] = useState9(null);
29066
+ const [boardGeom, setBoardGeom] = useState10(null);
28990
29067
  const isProcessingRef = useRef6(false);
28991
- useEffect17(() => {
29068
+ useEffect18(() => {
28992
29069
  let isCancelled = false;
28993
29070
  if (!circuitJson) {
28994
29071
  setBoardGeom(null);
@@ -29031,17 +29108,17 @@ var useBoardGeomBuilder = (circuitJson) => {
29031
29108
  };
29032
29109
 
29033
29110
  // src/three-components/Error3d.tsx
29034
- import { useState as useState10, useCallback as useCallback4, useEffect as useEffect18, useMemo as useMemo15 } from "react";
29111
+ import { useState as useState11, useCallback as useCallback5, useEffect as useEffect19, useMemo as useMemo16 } from "react";
29035
29112
  import * as THREE14 from "three";
29036
- import { Fragment as Fragment5, jsx as jsx12, jsxs as jsxs5 } from "react/jsx-runtime";
29113
+ import { Fragment as Fragment5, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
29037
29114
  var Error3d = ({
29038
29115
  error,
29039
29116
  cad_component: cad_component2
29040
29117
  }) => {
29041
29118
  const { rootObject } = useThree();
29042
- const [isHovered, setIsHovered] = useState10(false);
29043
- const [hoverPosition, setHoverPosition] = useState10(null);
29044
- const handleHover = useCallback4((e) => {
29119
+ const [isHovered, setIsHovered] = useState11(false);
29120
+ const [hoverPosition, setHoverPosition] = useState11(null);
29121
+ const handleHover = useCallback5((e) => {
29045
29122
  if (e?.mousePosition) {
29046
29123
  setIsHovered(true);
29047
29124
  setHoverPosition(e.mousePosition);
@@ -29050,11 +29127,11 @@ var Error3d = ({
29050
29127
  setHoverPosition(null);
29051
29128
  }
29052
29129
  }, []);
29053
- const handleUnhover = useCallback4(() => {
29130
+ const handleUnhover = useCallback5(() => {
29054
29131
  setIsHovered(false);
29055
29132
  setHoverPosition(null);
29056
29133
  }, []);
29057
- const position = useMemo15(() => {
29134
+ const position = useMemo16(() => {
29058
29135
  if (cad_component2?.position) {
29059
29136
  const p = [
29060
29137
  cad_component2.position.x,
@@ -29065,12 +29142,12 @@ var Error3d = ({
29065
29142
  }
29066
29143
  return [0, 0, 0];
29067
29144
  }, [cad_component2]);
29068
- const group = useMemo15(() => {
29145
+ const group = useMemo16(() => {
29069
29146
  const g = new THREE14.Group();
29070
29147
  g.position.fromArray(position);
29071
29148
  return g;
29072
29149
  }, [position]);
29073
- useEffect18(() => {
29150
+ useEffect19(() => {
29074
29151
  if (!rootObject) return;
29075
29152
  rootObject.add(group);
29076
29153
  return () => {
@@ -29086,8 +29163,8 @@ var Error3d = ({
29086
29163
  onUnhover: handleUnhover,
29087
29164
  object: group,
29088
29165
  children: [
29089
- /* @__PURE__ */ jsx12(ErrorBox, { parent: group }),
29090
- /* @__PURE__ */ jsx12(
29166
+ /* @__PURE__ */ jsx13(ErrorBox, { parent: group }),
29167
+ /* @__PURE__ */ jsx13(
29091
29168
  Text,
29092
29169
  {
29093
29170
  parent: group,
@@ -29102,7 +29179,7 @@ var Error3d = ({
29102
29179
  ]
29103
29180
  }
29104
29181
  ),
29105
- isHovered && hoverPosition ? /* @__PURE__ */ jsx12(
29182
+ isHovered && hoverPosition ? /* @__PURE__ */ jsx13(
29106
29183
  Html,
29107
29184
  {
29108
29185
  position: hoverPosition,
@@ -29125,7 +29202,7 @@ var Error3d = ({
29125
29202
  ] });
29126
29203
  };
29127
29204
  var ErrorBox = ({ parent }) => {
29128
- const mesh = useMemo15(() => {
29205
+ const mesh = useMemo16(() => {
29129
29206
  const m = new THREE14.Mesh(
29130
29207
  new THREE14.BoxGeometry(0.5, 0.5, 0.5),
29131
29208
  new THREE14.MeshStandardMaterial({
@@ -29139,7 +29216,7 @@ var ErrorBox = ({ parent }) => {
29139
29216
  m.rotation.fromArray([Math.PI / 4, Math.PI / 4, 0]);
29140
29217
  return m;
29141
29218
  }, []);
29142
- useEffect18(() => {
29219
+ useEffect19(() => {
29143
29220
  parent.add(mesh);
29144
29221
  return () => {
29145
29222
  parent.remove(mesh);
@@ -29149,7 +29226,7 @@ var ErrorBox = ({ parent }) => {
29149
29226
  };
29150
29227
 
29151
29228
  // src/three-components/STLModel.tsx
29152
- import { useState as useState11, useEffect as useEffect19, useMemo as useMemo16 } from "react";
29229
+ import { useState as useState12, useEffect as useEffect20, useMemo as useMemo17 } from "react";
29153
29230
  import * as THREE15 from "three";
29154
29231
  import { STLLoader } from "three-stdlib";
29155
29232
  function STLModel({
@@ -29160,8 +29237,8 @@ function STLModel({
29160
29237
  opacity = 1
29161
29238
  }) {
29162
29239
  const { rootObject } = useThree();
29163
- const [geom, setGeom] = useState11(null);
29164
- useEffect19(() => {
29240
+ const [geom, setGeom] = useState12(null);
29241
+ useEffect20(() => {
29165
29242
  const loader = new STLLoader();
29166
29243
  if (stlData) {
29167
29244
  try {
@@ -29179,7 +29256,7 @@ function STLModel({
29179
29256
  });
29180
29257
  }
29181
29258
  }, [stlUrl, stlData]);
29182
- const mesh = useMemo16(() => {
29259
+ const mesh = useMemo17(() => {
29183
29260
  if (!geom) return null;
29184
29261
  const material = new THREE15.MeshStandardMaterial({
29185
29262
  color: Array.isArray(color) ? new THREE15.Color(color[0], color[1], color[2]) : color,
@@ -29188,7 +29265,7 @@ function STLModel({
29188
29265
  });
29189
29266
  return new THREE15.Mesh(geom, material);
29190
29267
  }, [geom, color, opacity]);
29191
- useEffect19(() => {
29268
+ useEffect20(() => {
29192
29269
  if (!rootObject || !mesh) return;
29193
29270
  rootObject.add(mesh);
29194
29271
  return () => {
@@ -29204,9 +29281,36 @@ function STLModel({
29204
29281
  return null;
29205
29282
  }
29206
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
+
29207
29311
  // src/three-components/ThreeErrorBoundary.tsx
29208
- import React10 from "react";
29209
- var ThreeErrorBoundary = class extends React10.Component {
29312
+ import React11 from "react";
29313
+ var ThreeErrorBoundary = class extends React11.Component {
29210
29314
  constructor(props) {
29211
29315
  super(props);
29212
29316
  this.state = { hasError: false, error: null };
@@ -29223,7 +29327,7 @@ var ThreeErrorBoundary = class extends React10.Component {
29223
29327
  };
29224
29328
 
29225
29329
  // src/CadViewerJscad.tsx
29226
- import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
29330
+ import { jsx as jsx15, jsxs as jsxs6 } from "react/jsx-runtime";
29227
29331
  var CadViewerJscad = forwardRef3(
29228
29332
  ({
29229
29333
  soup,
@@ -29234,12 +29338,12 @@ var CadViewerJscad = forwardRef3(
29234
29338
  onUserInteraction
29235
29339
  }, ref) => {
29236
29340
  const childrenSoup = useConvertChildrenToCircuitJson(children);
29237
- const internalCircuitJson = useMemo17(() => {
29341
+ const internalCircuitJson = useMemo18(() => {
29238
29342
  const cj = soup ?? circuitJson;
29239
29343
  return cj ?? childrenSoup;
29240
29344
  }, [soup, circuitJson, childrenSoup]);
29241
29345
  const boardGeom = useBoardGeomBuilder(internalCircuitJson);
29242
- const initialCameraPosition = useMemo17(() => {
29346
+ const initialCameraPosition = useMemo18(() => {
29243
29347
  if (!internalCircuitJson) return [5, 5, 5];
29244
29348
  try {
29245
29349
  const board = su4(internalCircuitJson).pcb_board.list()[0];
@@ -29258,7 +29362,7 @@ var CadViewerJscad = forwardRef3(
29258
29362
  return [5, 5, 5];
29259
29363
  }
29260
29364
  }, [internalCircuitJson]);
29261
- const boardDimensions = useMemo17(() => {
29365
+ const boardDimensions = useMemo18(() => {
29262
29366
  if (!internalCircuitJson) return void 0;
29263
29367
  try {
29264
29368
  const board = su4(internalCircuitJson).pcb_board.list()[0];
@@ -29269,7 +29373,7 @@ var CadViewerJscad = forwardRef3(
29269
29373
  return void 0;
29270
29374
  }
29271
29375
  }, [internalCircuitJson]);
29272
- const boardCenter = useMemo17(() => {
29376
+ const boardCenter = useMemo18(() => {
29273
29377
  if (!internalCircuitJson) return void 0;
29274
29378
  try {
29275
29379
  const board = su4(internalCircuitJson).pcb_board.list()[0];
@@ -29293,20 +29397,21 @@ var CadViewerJscad = forwardRef3(
29293
29397
  boardCenter,
29294
29398
  onUserInteraction,
29295
29399
  children: [
29296
- boardStls.map(({ stlData, color }, index) => /* @__PURE__ */ jsx13(
29297
- STLModel,
29400
+ boardStls.map(({ stlData, color, layerType }, index) => /* @__PURE__ */ jsx15(
29401
+ VisibleSTLModel,
29298
29402
  {
29299
29403
  stlData,
29300
29404
  color,
29301
- opacity: index === 0 ? 0.95 : 1
29405
+ opacity: index === 0 ? 0.95 : 1,
29406
+ layerType
29302
29407
  },
29303
- `board-${index - boardStls.length}`
29408
+ `board-${index}`
29304
29409
  )),
29305
- cad_components.map((cad_component2) => /* @__PURE__ */ jsx13(
29410
+ cad_components.map((cad_component2) => /* @__PURE__ */ jsx15(
29306
29411
  ThreeErrorBoundary,
29307
29412
  {
29308
- fallback: ({ error }) => /* @__PURE__ */ jsx13(Error3d, { cad_component: cad_component2, error }),
29309
- children: /* @__PURE__ */ jsx13(
29413
+ fallback: ({ error }) => /* @__PURE__ */ jsx15(Error3d, { cad_component: cad_component2, error }),
29414
+ children: /* @__PURE__ */ jsx15(
29310
29415
  AnyCadComponent,
29311
29416
  {
29312
29417
  cad_component: cad_component2,
@@ -29325,10 +29430,10 @@ var CadViewerJscad = forwardRef3(
29325
29430
 
29326
29431
  // src/CadViewerManifold.tsx
29327
29432
  import { su as su13 } from "@tscircuit/circuit-json-util";
29328
- import { useEffect as useEffect21, useMemo as useMemo19, useState as useState14 } from "react";
29433
+ import { useEffect as useEffect22, useMemo as useMemo20, useState as useState15 } from "react";
29329
29434
 
29330
29435
  // src/hooks/useManifoldBoardBuilder.ts
29331
- import { useState as useState13, useEffect as useEffect20, useMemo as useMemo18, useRef as useRef7 } from "react";
29436
+ import { useState as useState14, useEffect as useEffect21, useMemo as useMemo19, useRef as useRef7 } from "react";
29332
29437
  import { su as su12 } from "@tscircuit/circuit-json-util";
29333
29438
  import * as THREE23 from "three";
29334
29439
 
@@ -30182,7 +30287,7 @@ function processSmtPadsForManifold(Manifold, circuitJson, pcbThickness, manifold
30182
30287
  }
30183
30288
  const threeGeom = manifoldMeshToThreeGeometry(finalPadOp.getMesh());
30184
30289
  smtPadGeoms.push({
30185
- key: `pad-${pad2.pcb_smtpad_id || index}`,
30290
+ key: `smt_pad-${pad2.layer || "top"}-${pad2.pcb_smtpad_id || index}`,
30186
30291
  geometry: threeGeom,
30187
30292
  color: COPPER_COLOR3
30188
30293
  });
@@ -30521,20 +30626,20 @@ function processCutoutsForManifold(Manifold, CrossSection, circuitJson, pcbThick
30521
30626
 
30522
30627
  // src/hooks/useManifoldBoardBuilder.ts
30523
30628
  var useManifoldBoardBuilder = (manifoldJSModule, circuitJson) => {
30524
- const [geoms, setGeoms] = useState13(null);
30525
- const [textures, setTextures] = useState13(null);
30526
- const [pcbThickness, setPcbThickness] = useState13(null);
30527
- const [error, setError] = useState13(null);
30528
- const [isLoading, setIsLoading] = useState13(true);
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);
30529
30634
  const manifoldInstancesForCleanup = useRef7([]);
30530
- const boardData = useMemo18(() => {
30635
+ const boardData = useMemo19(() => {
30531
30636
  const boards = su12(circuitJson).pcb_board.list();
30532
30637
  if (boards.length === 0) {
30533
30638
  return null;
30534
30639
  }
30535
30640
  return boards[0];
30536
30641
  }, [circuitJson]);
30537
- useEffect20(() => {
30642
+ useEffect21(() => {
30538
30643
  if (!manifoldJSModule || !boardData) {
30539
30644
  setGeoms(null);
30540
30645
  setTextures(null);
@@ -30880,21 +30985,64 @@ function createTextureMeshes(textures, boardData, pcbThickness) {
30880
30985
  }
30881
30986
 
30882
30987
  // src/CadViewerManifold.tsx
30883
- import { jsx as jsx14, jsxs as jsxs7 } from "react/jsx-runtime";
30988
+ import { jsx as jsx16, jsxs as jsxs7 } from "react/jsx-runtime";
30884
30989
  var BoardMeshes = ({
30885
30990
  geometryMeshes,
30886
30991
  textureMeshes
30887
30992
  }) => {
30888
30993
  const { rootObject } = useThree();
30889
- useEffect21(() => {
30994
+ const { visibility } = useLayerVisibility();
30995
+ useEffect22(() => {
30890
30996
  if (!rootObject) return;
30891
- geometryMeshes.forEach((mesh) => rootObject.add(mesh));
30892
- textureMeshes.forEach((mesh) => rootObject.add(mesh));
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
+ });
30893
31033
  return () => {
30894
- geometryMeshes.forEach((mesh) => rootObject.remove(mesh));
30895
- textureMeshes.forEach((mesh) => rootObject.remove(mesh));
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
+ });
30896
31044
  };
30897
- }, [rootObject, geometryMeshes, textureMeshes]);
31045
+ }, [rootObject, geometryMeshes, textureMeshes, visibility]);
30898
31046
  return null;
30899
31047
  };
30900
31048
  var MANIFOLD_CDN_BASE_URL = "https://cdn.jsdelivr.net/npm/manifold-3d@3.2.1";
@@ -30906,12 +31054,12 @@ var CadViewerManifold = ({
30906
31054
  children
30907
31055
  }) => {
30908
31056
  const childrenCircuitJson = useConvertChildrenToCircuitJson(children);
30909
- const circuitJson = useMemo19(() => {
31057
+ const circuitJson = useMemo20(() => {
30910
31058
  return circuitJsonProp ?? childrenCircuitJson;
30911
31059
  }, [circuitJsonProp, childrenCircuitJson]);
30912
- const [manifoldJSModule, setManifoldJSModule] = useState14(null);
30913
- const [manifoldLoadingError, setManifoldLoadingError] = useState14(null);
30914
- useEffect21(() => {
31060
+ const [manifoldJSModule, setManifoldJSModule] = useState15(null);
31061
+ const [manifoldLoadingError, setManifoldLoadingError] = useState15(null);
31062
+ useEffect22(() => {
30915
31063
  if (window.ManifoldModule && typeof window.ManifoldModule === "object" && window.ManifoldModule.setup) {
30916
31064
  setManifoldJSModule(window.ManifoldModule);
30917
31065
  return;
@@ -30981,27 +31129,27 @@ try {
30981
31129
  isLoading: builderIsLoading,
30982
31130
  boardData
30983
31131
  } = useManifoldBoardBuilder(manifoldJSModule, circuitJson);
30984
- const geometryMeshes = useMemo19(() => createGeometryMeshes(geoms), [geoms]);
30985
- const textureMeshes = useMemo19(
31132
+ const geometryMeshes = useMemo20(() => createGeometryMeshes(geoms), [geoms]);
31133
+ const textureMeshes = useMemo20(
30986
31134
  () => createTextureMeshes(textures, boardData, pcbThickness),
30987
31135
  [textures, boardData, pcbThickness]
30988
31136
  );
30989
- const cadComponents = useMemo19(
31137
+ const cadComponents = useMemo20(
30990
31138
  () => su13(circuitJson).cad_component.list(),
30991
31139
  [circuitJson]
30992
31140
  );
30993
- const boardDimensions = useMemo19(() => {
31141
+ const boardDimensions = useMemo20(() => {
30994
31142
  if (!boardData) return void 0;
30995
31143
  const { width: width10 = 0, height: height10 = 0 } = boardData;
30996
31144
  return { width: width10, height: height10 };
30997
31145
  }, [boardData]);
30998
- const boardCenter = useMemo19(() => {
31146
+ const boardCenter = useMemo20(() => {
30999
31147
  if (!boardData) return void 0;
31000
31148
  const { center } = boardData;
31001
31149
  if (!center) return void 0;
31002
31150
  return { x: center.x, y: center.y };
31003
31151
  }, [boardData]);
31004
- const initialCameraPosition = useMemo19(() => {
31152
+ const initialCameraPosition = useMemo20(() => {
31005
31153
  if (!boardData) return [5, 5, 5];
31006
31154
  const { width: width10 = 0, height: height10 = 0 } = boardData;
31007
31155
  const safeWidth = Math.max(width10, 1);
@@ -31027,7 +31175,7 @@ try {
31027
31175
  );
31028
31176
  }
31029
31177
  if (!manifoldJSModule) {
31030
- return /* @__PURE__ */ jsx14("div", { style: { padding: "1em" }, children: "Loading Manifold module..." });
31178
+ return /* @__PURE__ */ jsx16("div", { style: { padding: "1em" }, children: "Loading Manifold module..." });
31031
31179
  }
31032
31180
  if (builderError) {
31033
31181
  return /* @__PURE__ */ jsxs7(
@@ -31047,7 +31195,7 @@ try {
31047
31195
  );
31048
31196
  }
31049
31197
  if (builderIsLoading) {
31050
- return /* @__PURE__ */ jsx14("div", { style: { padding: "1em" }, children: "Processing board geometry..." });
31198
+ return /* @__PURE__ */ jsx16("div", { style: { padding: "1em" }, children: "Processing board geometry..." });
31051
31199
  }
31052
31200
  return /* @__PURE__ */ jsxs7(
31053
31201
  CadViewerContainer,
@@ -31059,18 +31207,18 @@ try {
31059
31207
  boardCenter,
31060
31208
  onUserInteraction,
31061
31209
  children: [
31062
- /* @__PURE__ */ jsx14(
31210
+ /* @__PURE__ */ jsx16(
31063
31211
  BoardMeshes,
31064
31212
  {
31065
31213
  geometryMeshes,
31066
31214
  textureMeshes
31067
31215
  }
31068
31216
  ),
31069
- cadComponents.map((cad_component2) => /* @__PURE__ */ jsx14(
31217
+ cadComponents.map((cad_component2) => /* @__PURE__ */ jsx16(
31070
31218
  ThreeErrorBoundary,
31071
31219
  {
31072
- fallback: ({ error }) => /* @__PURE__ */ jsx14(Error3d, { cad_component: cad_component2, error }),
31073
- children: /* @__PURE__ */ jsx14(
31220
+ fallback: ({ error }) => /* @__PURE__ */ jsx16(Error3d, { cad_component: cad_component2, error }),
31221
+ children: /* @__PURE__ */ jsx16(
31074
31222
  AnyCadComponent,
31075
31223
  {
31076
31224
  cad_component: cad_component2,
@@ -31087,10 +31235,10 @@ try {
31087
31235
  var CadViewerManifold_default = CadViewerManifold;
31088
31236
 
31089
31237
  // src/hooks/useContextMenu.ts
31090
- import { useState as useState15, useCallback as useCallback6, useRef as useRef8, useEffect as useEffect22 } from "react";
31238
+ import { useState as useState16, useCallback as useCallback7, useRef as useRef8, useEffect as useEffect23 } from "react";
31091
31239
  var useContextMenu = ({ containerRef }) => {
31092
- const [menuVisible, setMenuVisible] = useState15(false);
31093
- const [menuPos, setMenuPos] = useState15({
31240
+ const [menuVisible, setMenuVisible] = useState16(false);
31241
+ const [menuPos, setMenuPos] = useState16({
31094
31242
  x: 0,
31095
31243
  y: 0
31096
31244
  });
@@ -31104,7 +31252,7 @@ var useContextMenu = ({ containerRef }) => {
31104
31252
  longPressTimeoutRef.current = null;
31105
31253
  }
31106
31254
  };
31107
- const handleContextMenu = useCallback6(
31255
+ const handleContextMenu = useCallback7(
31108
31256
  (e) => {
31109
31257
  e.preventDefault();
31110
31258
  const eventX = typeof e.clientX === "number" ? e.clientX : 0;
@@ -31130,7 +31278,7 @@ var useContextMenu = ({ containerRef }) => {
31130
31278
  },
31131
31279
  [setMenuPos, setMenuVisible]
31132
31280
  );
31133
- const handleTouchStart = useCallback6(
31281
+ const handleTouchStart = useCallback7(
31134
31282
  (e) => {
31135
31283
  if (e.touches.length === 1) {
31136
31284
  const touch = e.touches[0];
@@ -31163,7 +31311,7 @@ var useContextMenu = ({ containerRef }) => {
31163
31311
  },
31164
31312
  [containerRef]
31165
31313
  );
31166
- const handleTouchMove = useCallback6((e) => {
31314
+ const handleTouchMove = useCallback7((e) => {
31167
31315
  if (!interactionOriginPosRef.current || e.touches.length !== 1) {
31168
31316
  return;
31169
31317
  }
@@ -31181,7 +31329,7 @@ var useContextMenu = ({ containerRef }) => {
31181
31329
  clearLongPressTimeout();
31182
31330
  }
31183
31331
  }, []);
31184
- const handleTouchEnd = useCallback6(() => {
31332
+ const handleTouchEnd = useCallback7(() => {
31185
31333
  clearLongPressTimeout();
31186
31334
  setTimeout(() => {
31187
31335
  if (interactionOriginPosRef.current) {
@@ -31189,13 +31337,13 @@ var useContextMenu = ({ containerRef }) => {
31189
31337
  }
31190
31338
  }, 0);
31191
31339
  }, []);
31192
- const handleClickAway = useCallback6((e) => {
31340
+ const handleClickAway = useCallback7((e) => {
31193
31341
  const target = e.target;
31194
31342
  if (menuRef.current && !menuRef.current.contains(target)) {
31195
31343
  setMenuVisible(false);
31196
31344
  }
31197
31345
  }, []);
31198
- useEffect22(() => {
31346
+ useEffect23(() => {
31199
31347
  if (menuVisible) {
31200
31348
  document.addEventListener("mousedown", handleClickAway);
31201
31349
  document.addEventListener("touchstart", handleClickAway);
@@ -31229,10 +31377,10 @@ var useContextMenu = ({ containerRef }) => {
31229
31377
  };
31230
31378
 
31231
31379
  // src/hooks/useGlobalDownloadGltf.ts
31232
- import { useCallback as useCallback7 } from "react";
31380
+ import { useCallback as useCallback8 } from "react";
31233
31381
  import { GLTFExporter } from "three-stdlib";
31234
31382
  var useGlobalDownloadGltf = () => {
31235
- return useCallback7(() => {
31383
+ return useCallback8(() => {
31236
31384
  const root = window.__TSCIRCUIT_THREE_OBJECT;
31237
31385
  if (!root) return;
31238
31386
  const exporter = new GLTFExporter();
@@ -31257,13 +31405,190 @@ var useGlobalDownloadGltf = () => {
31257
31405
  }, []);
31258
31406
  };
31259
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
+
31260
31584
  // src/CadViewer.tsx
31261
- import { jsx as jsx15, jsxs as jsxs8 } from "react/jsx-runtime";
31262
- var CadViewer = (props) => {
31263
- const [engine, setEngine] = useState16("manifold");
31585
+ import { jsx as jsx18, jsxs as jsxs9 } from "react/jsx-runtime";
31586
+ var CadViewerInner = (props) => {
31587
+ const [engine, setEngine] = useState18("manifold");
31264
31588
  const containerRef = useRef9(null);
31265
- const [autoRotate, setAutoRotate] = useState16(true);
31266
- const [autoRotateUserToggled, setAutoRotateUserToggled] = useState16(false);
31589
+ const [autoRotate, setAutoRotate] = useState18(true);
31590
+ const [autoRotateUserToggled, setAutoRotateUserToggled] = useState18(false);
31591
+ const { visibility, toggleLayer } = useLayerVisibility();
31267
31592
  const {
31268
31593
  menuVisible,
31269
31594
  menuPos,
@@ -31273,12 +31598,12 @@ var CadViewer = (props) => {
31273
31598
  } = useContextMenu({ containerRef });
31274
31599
  const autoRotateUserToggledRef = useRef9(autoRotateUserToggled);
31275
31600
  autoRotateUserToggledRef.current = autoRotateUserToggled;
31276
- const handleUserInteraction = useCallback8(() => {
31601
+ const handleUserInteraction = useCallback9(() => {
31277
31602
  if (!autoRotateUserToggledRef.current) {
31278
31603
  setAutoRotate(false);
31279
31604
  }
31280
31605
  }, []);
31281
- const toggleAutoRotate = useCallback8(() => {
31606
+ const toggleAutoRotate = useCallback9(() => {
31282
31607
  setAutoRotate((prev) => !prev);
31283
31608
  setAutoRotateUserToggled(true);
31284
31609
  }, []);
@@ -31287,17 +31612,17 @@ var CadViewer = (props) => {
31287
31612
  setEngine(newEngine);
31288
31613
  setMenuVisible(false);
31289
31614
  };
31290
- useEffect23(() => {
31615
+ useEffect24(() => {
31291
31616
  const stored = window.localStorage.getItem("cadViewerEngine");
31292
31617
  if (stored === "jscad" || stored === "manifold") {
31293
31618
  setEngine(stored);
31294
31619
  }
31295
31620
  }, []);
31296
- useEffect23(() => {
31621
+ useEffect24(() => {
31297
31622
  window.localStorage.setItem("cadViewerEngine", engine);
31298
31623
  }, [engine]);
31299
31624
  const viewerKey = props.circuitJson ? JSON.stringify(props.circuitJson) : void 0;
31300
- return /* @__PURE__ */ jsxs8(
31625
+ return /* @__PURE__ */ jsxs9(
31301
31626
  "div",
31302
31627
  {
31303
31628
  ref: containerRef,
@@ -31313,14 +31638,14 @@ var CadViewer = (props) => {
31313
31638
  },
31314
31639
  ...contextMenuEventHandlers,
31315
31640
  children: [
31316
- engine === "jscad" ? /* @__PURE__ */ jsx15(
31641
+ engine === "jscad" ? /* @__PURE__ */ jsx18(
31317
31642
  CadViewerJscad,
31318
31643
  {
31319
31644
  ...props,
31320
31645
  autoRotateDisabled: props.autoRotateDisabled || !autoRotate,
31321
31646
  onUserInteraction: handleUserInteraction
31322
31647
  }
31323
- ) : /* @__PURE__ */ jsx15(
31648
+ ) : /* @__PURE__ */ jsx18(
31324
31649
  CadViewerManifold_default,
31325
31650
  {
31326
31651
  ...props,
@@ -31328,7 +31653,7 @@ var CadViewer = (props) => {
31328
31653
  onUserInteraction: handleUserInteraction
31329
31654
  }
31330
31655
  ),
31331
- /* @__PURE__ */ jsxs8(
31656
+ /* @__PURE__ */ jsxs9(
31332
31657
  "div",
31333
31658
  {
31334
31659
  style: {
@@ -31345,11 +31670,11 @@ var CadViewer = (props) => {
31345
31670
  },
31346
31671
  children: [
31347
31672
  "Engine: ",
31348
- /* @__PURE__ */ jsx15("b", { children: engine === "jscad" ? "JSCAD" : "Manifold" })
31673
+ /* @__PURE__ */ jsx18("b", { children: engine === "jscad" ? "JSCAD" : "Manifold" })
31349
31674
  ]
31350
31675
  }
31351
31676
  ),
31352
- menuVisible && /* @__PURE__ */ jsxs8(
31677
+ menuVisible && /* @__PURE__ */ jsxs9(
31353
31678
  "div",
31354
31679
  {
31355
31680
  ref: menuRef,
@@ -31370,7 +31695,7 @@ var CadViewer = (props) => {
31370
31695
  transition: "opacity 0.1s"
31371
31696
  },
31372
31697
  children: [
31373
- /* @__PURE__ */ jsxs8(
31698
+ /* @__PURE__ */ jsxs9(
31374
31699
  "div",
31375
31700
  {
31376
31701
  style: {
@@ -31391,7 +31716,7 @@ var CadViewer = (props) => {
31391
31716
  "Switch to ",
31392
31717
  engine === "jscad" ? "Manifold" : "JSCAD",
31393
31718
  " Engine",
31394
- /* @__PURE__ */ jsx15(
31719
+ /* @__PURE__ */ jsx18(
31395
31720
  "span",
31396
31721
  {
31397
31722
  style: {
@@ -31406,7 +31731,7 @@ var CadViewer = (props) => {
31406
31731
  ]
31407
31732
  }
31408
31733
  ),
31409
- /* @__PURE__ */ jsxs8(
31734
+ /* @__PURE__ */ jsxs9(
31410
31735
  "div",
31411
31736
  {
31412
31737
  style: {
@@ -31427,12 +31752,12 @@ var CadViewer = (props) => {
31427
31752
  onMouseOver: (e) => e.currentTarget.style.background = "#2d313a",
31428
31753
  onMouseOut: (e) => e.currentTarget.style.background = "transparent",
31429
31754
  children: [
31430
- /* @__PURE__ */ jsx15("span", { style: { marginRight: 8 }, children: autoRotate ? "\u2714" : "" }),
31755
+ /* @__PURE__ */ jsx18("span", { style: { marginRight: 8 }, children: autoRotate ? "\u2714" : "" }),
31431
31756
  "Auto rotate"
31432
31757
  ]
31433
31758
  }
31434
31759
  ),
31435
- /* @__PURE__ */ jsx15(
31760
+ /* @__PURE__ */ jsx18(
31436
31761
  "div",
31437
31762
  {
31438
31763
  style: {
@@ -31455,7 +31780,8 @@ var CadViewer = (props) => {
31455
31780
  children: "Download GLTF"
31456
31781
  }
31457
31782
  ),
31458
- /* @__PURE__ */ jsx15(
31783
+ /* @__PURE__ */ jsx18(AppearanceMenu, {}),
31784
+ /* @__PURE__ */ jsx18(
31459
31785
  "div",
31460
31786
  {
31461
31787
  style: {
@@ -31465,7 +31791,7 @@ var CadViewer = (props) => {
31465
31791
  borderTop: "1px solid rgba(255, 255, 255, 0.1)",
31466
31792
  marginTop: "8px"
31467
31793
  },
31468
- children: /* @__PURE__ */ jsxs8(
31794
+ children: /* @__PURE__ */ jsxs9(
31469
31795
  "span",
31470
31796
  {
31471
31797
  style: {
@@ -31490,6 +31816,9 @@ var CadViewer = (props) => {
31490
31816
  viewerKey
31491
31817
  );
31492
31818
  };
31819
+ var CadViewer = (props) => {
31820
+ return /* @__PURE__ */ jsx18(LayerVisibilityProvider, { children: /* @__PURE__ */ jsx18(CadViewerInner, { ...props }) });
31821
+ };
31493
31822
 
31494
31823
  // src/convert-circuit-json-to-3d-svg.ts
31495
31824
  var import_debug = __toESM(require_browser(), 1);
@@ -31770,10 +32099,10 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
31770
32099
 
31771
32100
  // src/hooks/exporter/gltf.ts
31772
32101
  import { GLTFExporter as GLTFExporter2 } from "three-stdlib";
31773
- import { useEffect as useEffect24, useState as useState17, useMemo as useMemo20, useCallback as useCallback9 } from "react";
32102
+ import { useEffect as useEffect25, useState as useState19, useMemo as useMemo21, useCallback as useCallback10 } from "react";
31774
32103
  function useSaveGltfAs(options = {}) {
31775
32104
  const parse = useParser(options);
31776
- const link = useMemo20(() => document.createElement("a"), []);
32105
+ const link = useMemo21(() => document.createElement("a"), []);
31777
32106
  const saveAs = async (filename) => {
31778
32107
  const name = filename ?? options.filename ?? "";
31779
32108
  if (options.binary == null) options.binary = name.endsWith(".glb");
@@ -31783,7 +32112,7 @@ function useSaveGltfAs(options = {}) {
31783
32112
  link.dispatchEvent(new MouseEvent("click"));
31784
32113
  URL.revokeObjectURL(url);
31785
32114
  };
31786
- useEffect24(
32115
+ useEffect25(
31787
32116
  () => () => {
31788
32117
  link.remove();
31789
32118
  instance = null;
@@ -31791,24 +32120,24 @@ function useSaveGltfAs(options = {}) {
31791
32120
  []
31792
32121
  );
31793
32122
  let instance;
31794
- const ref = useCallback9((obj3D) => {
32123
+ const ref = useCallback10((obj3D) => {
31795
32124
  instance = obj3D;
31796
32125
  }, []);
31797
32126
  return [ref, saveAs];
31798
32127
  }
31799
32128
  function useExportGltfUrl(options = {}) {
31800
32129
  const parse = useParser(options);
31801
- const [url, setUrl] = useState17();
31802
- const [error, setError] = useState17();
31803
- const ref = useCallback9(
32130
+ const [url, setUrl] = useState19();
32131
+ const [error, setError] = useState19();
32132
+ const ref = useCallback10(
31804
32133
  (instance) => parse(instance).then(setUrl).catch(setError),
31805
32134
  []
31806
32135
  );
31807
- useEffect24(() => () => URL.revokeObjectURL(url), [url]);
32136
+ useEffect25(() => () => URL.revokeObjectURL(url), [url]);
31808
32137
  return [ref, url, error];
31809
32138
  }
31810
32139
  function useParser(options = {}) {
31811
- const exporter = useMemo20(() => new GLTFExporter2(), []);
32140
+ const exporter = useMemo21(() => new GLTFExporter2(), []);
31812
32141
  return (instance) => {
31813
32142
  const { promise, resolve, reject } = Promise.withResolvers();
31814
32143
  exporter.parse(