@tscircuit/3d-viewer 0.0.185 → 0.0.186

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.d.ts CHANGED
@@ -11,6 +11,7 @@ interface Props {
11
11
  soup?: AnyCircuitElement[];
12
12
  circuitJson?: AnyCircuitElement[];
13
13
  autoRotateDisabled?: boolean;
14
+ clickToInteractEnabled?: boolean;
14
15
  }
15
16
  declare const CadViewer: React.ForwardRefExoticComponent<Props & {
16
17
  children?: React.ReactNode | undefined;
package/dist/index.js CHANGED
@@ -13994,7 +13994,7 @@ var useConvertChildrenToSoup = (children, defaultSoup) => {
13994
13994
 
13995
13995
  // src/CadViewer.tsx
13996
13996
  import { su as su2 } from "@tscircuit/soup-util";
13997
- import { useMemo as useMemo4, useState as useState3, forwardRef as forwardRef2 } from "react";
13997
+ import { useMemo as useMemo4, useState as useState4, forwardRef as forwardRef2 } from "react";
13998
13998
 
13999
13999
  // src/soup-to-3d/index.ts
14000
14000
  var import_transforms2 = __toESM(require_transforms(), 1);
@@ -17411,7 +17411,7 @@ import { Canvas, useFrame as useFrame2 } from "@react-three/fiber";
17411
17411
  // package.json
17412
17412
  var package_default = {
17413
17413
  name: "@tscircuit/3d-viewer",
17414
- version: "0.0.184",
17414
+ version: "0.0.185",
17415
17415
  main: "./dist/index.js",
17416
17416
  module: "./dist/index.js",
17417
17417
  type: "module",
@@ -17585,7 +17585,7 @@ var CubeWithLabeledSides = ({}) => {
17585
17585
  };
17586
17586
 
17587
17587
  // src/CadViewerContainer.tsx
17588
- import { forwardRef } from "react";
17588
+ import { forwardRef, useState as useState2 } from "react";
17589
17589
  import { Html } from "@react-three/drei";
17590
17590
  import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
17591
17591
  var RotationTracker = () => {
@@ -17599,8 +17599,12 @@ var CadViewerContainer = forwardRef(
17599
17599
  children,
17600
17600
  hoveredComponent,
17601
17601
  initialCameraPosition = [5, 5, 5],
17602
- autoRotateDisabled
17602
+ autoRotateDisabled,
17603
+ clickToInteractEnabled = false
17603
17604
  }, ref) => {
17605
+ const [isInteractionEnabled, setIsInteractionEnabled] = useState2(
17606
+ !clickToInteractEnabled
17607
+ );
17604
17608
  return /* @__PURE__ */ jsxs3("div", { style: { position: "relative", width: "100%", height: "100%" }, children: [
17605
17609
  /* @__PURE__ */ jsx3(
17606
17610
  "div",
@@ -17635,7 +17639,13 @@ var CadViewerContainer = forwardRef(
17635
17639
  camera: { up: [0, 0, 1], position: initialCameraPosition },
17636
17640
  children: [
17637
17641
  /* @__PURE__ */ jsx3(RotationTracker, {}),
17638
- /* @__PURE__ */ jsx3(OrbitControls, { autoRotate: !autoRotateDisabled, autoRotateSpeed: 1 }),
17642
+ isInteractionEnabled && /* @__PURE__ */ jsx3(
17643
+ OrbitControls,
17644
+ {
17645
+ autoRotate: !autoRotateDisabled,
17646
+ autoRotateSpeed: 1
17647
+ }
17648
+ ),
17639
17649
  /* @__PURE__ */ jsx3("ambientLight", { intensity: Math.PI / 2 }),
17640
17650
  /* @__PURE__ */ jsx3(
17641
17651
  "pointLight",
@@ -17694,6 +17704,36 @@ var CadViewerContainer = forwardRef(
17694
17704
  package_default.version
17695
17705
  ]
17696
17706
  }
17707
+ ),
17708
+ clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx3(
17709
+ "div",
17710
+ {
17711
+ onClick: () => setIsInteractionEnabled(true),
17712
+ style: {
17713
+ position: "absolute",
17714
+ inset: 0,
17715
+ cursor: "pointer",
17716
+ zIndex: 10,
17717
+ display: "flex",
17718
+ alignItems: "center",
17719
+ justifyContent: "center"
17720
+ },
17721
+ children: /* @__PURE__ */ jsx3(
17722
+ "div",
17723
+ {
17724
+ style: {
17725
+ backgroundColor: "rgba(0, 0, 0, 0.8)",
17726
+ color: "white",
17727
+ padding: "12px 24px",
17728
+ borderRadius: "8px",
17729
+ fontSize: "16px",
17730
+ fontFamily: "sans-serif",
17731
+ pointerEvents: "none"
17732
+ },
17733
+ children: "Click to Interact"
17734
+ }
17735
+ )
17736
+ }
17697
17737
  )
17698
17738
  ] });
17699
17739
  }
@@ -17750,12 +17790,12 @@ var ContainerWithTooltip = ({
17750
17790
  var ContainerWithTooltip_default = ContainerWithTooltip;
17751
17791
 
17752
17792
  // src/hooks/use-global-obj-loader.ts
17753
- import { useState as useState2, useEffect as useEffect3 } from "react";
17793
+ import { useState as useState3, useEffect as useEffect3 } from "react";
17754
17794
  if (typeof window !== "undefined" && !window.TSCIRCUIT_OBJ_LOADER_CACHE) {
17755
17795
  window.TSCIRCUIT_OBJ_LOADER_CACHE = /* @__PURE__ */ new Map();
17756
17796
  }
17757
17797
  function useGlobalObjLoader(url) {
17758
- const [obj, setObj] = useState2(null);
17798
+ const [obj, setObj] = useState3(null);
17759
17799
  useEffect3(() => {
17760
17800
  if (!url) return;
17761
17801
  const cache = window.TSCIRCUIT_OBJ_LOADER_CACHE;
@@ -18078,89 +18118,92 @@ var Error3d = ({
18078
18118
 
18079
18119
  // src/CadViewer.tsx
18080
18120
  import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
18081
- var CadViewer = forwardRef2(({ soup, circuitJson, children, autoRotateDisabled }, ref) => {
18082
- circuitJson ??= soup;
18083
- const [hoveredComponent, setHoveredComponent] = useState3(null);
18084
- circuitJson ??= useConvertChildrenToSoup(children, circuitJson);
18085
- const initialCameraPosition = useMemo4(() => {
18086
- if (!circuitJson) return [5, 5, 5];
18087
- try {
18088
- const board = su2(circuitJson).pcb_board.list()[0];
18089
- if (!board) return [5, 5, 5];
18090
- const { width, height } = board;
18091
- if (!width && !height) {
18121
+ var CadViewer = forwardRef2(
18122
+ ({ soup, circuitJson, children, autoRotateDisabled, clickToInteractEnabled }, ref) => {
18123
+ circuitJson ??= soup;
18124
+ const [hoveredComponent, setHoveredComponent] = useState4(null);
18125
+ circuitJson ??= useConvertChildrenToSoup(children, circuitJson);
18126
+ const initialCameraPosition = useMemo4(() => {
18127
+ if (!circuitJson) return [5, 5, 5];
18128
+ try {
18129
+ const board = su2(circuitJson).pcb_board.list()[0];
18130
+ if (!board) return [5, 5, 5];
18131
+ const { width, height } = board;
18132
+ if (!width && !height) {
18133
+ return [5, 5, 5];
18134
+ }
18135
+ const minCameraDistance = 5;
18136
+ const adjustedBoardWidth = Math.max(width, minCameraDistance);
18137
+ const adjustedBoardHeight = Math.max(height, minCameraDistance);
18138
+ const largestDim = Math.max(adjustedBoardWidth, adjustedBoardHeight);
18139
+ return [largestDim / 2, largestDim / 2, largestDim];
18140
+ } catch (e) {
18141
+ console.error(e);
18092
18142
  return [5, 5, 5];
18093
18143
  }
18094
- const minCameraDistance = 5;
18095
- const adjustedBoardWidth = Math.max(width, minCameraDistance);
18096
- const adjustedBoardHeight = Math.max(height, minCameraDistance);
18097
- const largestDim = Math.max(adjustedBoardWidth, adjustedBoardHeight);
18098
- return [largestDim / 2, largestDim / 2, largestDim];
18099
- } catch (e) {
18100
- console.error(e);
18101
- return [5, 5, 5];
18102
- }
18103
- }, [circuitJson]);
18104
- const boardGeom = useMemo4(() => {
18144
+ }, [circuitJson]);
18145
+ const boardGeom = useMemo4(() => {
18146
+ if (!circuitJson) return null;
18147
+ if (!circuitJson.some((e) => e.type === "pcb_board")) return null;
18148
+ return createBoardGeomFromSoup(circuitJson);
18149
+ }, [circuitJson]);
18150
+ const { stls: boardStls, loading } = useStlsFromGeom(boardGeom);
18105
18151
  if (!circuitJson) return null;
18106
- if (!circuitJson.some((e) => e.type === "pcb_board")) return null;
18107
- return createBoardGeomFromSoup(circuitJson);
18108
- }, [circuitJson]);
18109
- const { stls: boardStls, loading } = useStlsFromGeom(boardGeom);
18110
- if (!circuitJson) return null;
18111
- const cad_components = su2(circuitJson).cad_component.list();
18112
- return /* @__PURE__ */ jsxs6(
18113
- CadViewerContainer,
18114
- {
18115
- ref,
18116
- hoveredComponent,
18117
- autoRotateDisabled,
18118
- initialCameraPosition,
18119
- children: [
18120
- boardStls.map(({ stlUrl, color }, index) => /* @__PURE__ */ jsx10(
18121
- STLModel,
18122
- {
18123
- stlUrl,
18124
- color,
18125
- opacity: index === 0 ? 0.95 : 1
18126
- },
18127
- stlUrl
18128
- )),
18129
- cad_components.map((cad_component) => /* @__PURE__ */ jsx10(
18130
- ThreeErrorBoundary,
18131
- {
18132
- fallback: ({ error }) => /* @__PURE__ */ jsx10(Error3d, { cad_component, error }),
18133
- children: /* @__PURE__ */ jsx10(
18134
- AnyCadComponent,
18135
- {
18136
- onHover: (e) => {
18137
- if (!e) {
18138
- setHoveredComponent(null);
18139
- }
18140
- if (!e.mousePosition) return;
18141
- const componentName = su2(
18142
- circuitJson
18143
- ).source_component.getUsing({
18144
- source_component_id: cad_component.source_component_id
18145
- })?.name;
18146
- setHoveredComponent({
18147
- cad_component_id: cad_component.cad_component_id,
18148
- name: componentName ?? "<unknown>",
18149
- mousePosition: e.mousePosition
18150
- });
18152
+ const cad_components = su2(circuitJson).cad_component.list();
18153
+ return /* @__PURE__ */ jsxs6(
18154
+ CadViewerContainer,
18155
+ {
18156
+ ref,
18157
+ hoveredComponent,
18158
+ autoRotateDisabled,
18159
+ initialCameraPosition,
18160
+ clickToInteractEnabled,
18161
+ children: [
18162
+ boardStls.map(({ stlUrl, color }, index) => /* @__PURE__ */ jsx10(
18163
+ STLModel,
18164
+ {
18165
+ stlUrl,
18166
+ color,
18167
+ opacity: index === 0 ? 0.95 : 1
18168
+ },
18169
+ stlUrl
18170
+ )),
18171
+ cad_components.map((cad_component) => /* @__PURE__ */ jsx10(
18172
+ ThreeErrorBoundary,
18173
+ {
18174
+ fallback: ({ error }) => /* @__PURE__ */ jsx10(Error3d, { cad_component, error }),
18175
+ children: /* @__PURE__ */ jsx10(
18176
+ AnyCadComponent,
18177
+ {
18178
+ onHover: (e) => {
18179
+ if (!e) {
18180
+ setHoveredComponent(null);
18181
+ }
18182
+ if (!e.mousePosition) return;
18183
+ const componentName = su2(
18184
+ circuitJson
18185
+ ).source_component.getUsing({
18186
+ source_component_id: cad_component.source_component_id
18187
+ })?.name;
18188
+ setHoveredComponent({
18189
+ cad_component_id: cad_component.cad_component_id,
18190
+ name: componentName ?? "<unknown>",
18191
+ mousePosition: e.mousePosition
18192
+ });
18193
+ },
18194
+ cad_component,
18195
+ isHovered: hoveredComponent?.cad_component_id === cad_component.cad_component_id
18151
18196
  },
18152
- cad_component,
18153
- isHovered: hoveredComponent?.cad_component_id === cad_component.cad_component_id
18154
- },
18155
- cad_component.cad_component_id
18156
- )
18157
- },
18158
- cad_component.cad_component_id
18159
- ))
18160
- ]
18161
- }
18162
- );
18163
- });
18197
+ cad_component.cad_component_id
18198
+ )
18199
+ },
18200
+ cad_component.cad_component_id
18201
+ ))
18202
+ ]
18203
+ }
18204
+ );
18205
+ }
18206
+ );
18164
18207
 
18165
18208
  // src/convert-circuit-json-to-3d-svg.ts
18166
18209
  var import_debug = __toESM(require_browser(), 1);
@@ -18425,7 +18468,7 @@ async function convertCircuitJsonTo3dSvg(circuitJson, options = {}) {
18425
18468
  }
18426
18469
 
18427
18470
  // src/hooks/exporter/gltf.ts
18428
- import { useEffect as useEffect5, useState as useState4, useMemo as useMemo5, useCallback as useCallback2 } from "react";
18471
+ import { useEffect as useEffect5, useState as useState5, useMemo as useMemo5, useCallback as useCallback2 } from "react";
18429
18472
  function useSaveGltfAs(options = {}) {
18430
18473
  const parse = useParser(options);
18431
18474
  const link = useMemo5(() => document.createElement("a"), []);
@@ -18453,8 +18496,8 @@ function useSaveGltfAs(options = {}) {
18453
18496
  }
18454
18497
  function useExportGltfUrl(options = {}) {
18455
18498
  const parse = useParser(options);
18456
- const [url, setUrl] = useState4();
18457
- const [error, setError] = useState4();
18499
+ const [url, setUrl] = useState5();
18500
+ const [error, setError] = useState5();
18458
18501
  const ref = useCallback2(
18459
18502
  (instance) => parse(instance).then(setUrl).catch(setError),
18460
18503
  []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/3d-viewer",
3
- "version": "0.0.185",
3
+ "version": "0.0.186",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "type": "module",