@tscircuit/pcb-viewer 1.11.41 → 1.11.43

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
@@ -66,8 +66,10 @@ type Props = {
66
66
  initialState?: Partial<StateProps>;
67
67
  onEditEventsChanged?: (editEvents: EditEvent[]) => void;
68
68
  focusOnHover?: boolean;
69
+ clickToInteractEnabled?: boolean;
70
+ disableAutoFocus?: boolean;
69
71
  };
70
- declare const PCBViewer: ({ children, soup, circuitJson, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, focusOnHover, }: Props) => react_jsx_runtime.JSX.Element;
72
+ declare const PCBViewer: ({ children, soup, circuitJson, height, initialState, allowEditing, editEvents: editEventsProp, onEditEventsChanged, focusOnHover, clickToInteractEnabled, disableAutoFocus, }: Props) => react_jsx_runtime.JSX.Element;
71
73
 
72
74
  declare const applyEditEvents: (soup: AnyCircuitElement[], edit_events: EditEvent[]) => AnyCircuitElement[];
73
75
 
package/dist/index.js CHANGED
@@ -7874,7 +7874,11 @@ var MouseElementTracker = ({
7874
7874
  import { useEffect as useEffect6, useRef as useRef3, useState as useState5 } from "react";
7875
7875
  import { applyToPoint as applyToPoint6, identity as identity3, inverse as inverse3 } from "transformation-matrix";
7876
7876
  import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
7877
- var DimensionOverlay = ({ children, transform, focusOnHover = false }) => {
7877
+ var DimensionOverlay = ({
7878
+ children,
7879
+ transform,
7880
+ focusOnHover = false
7881
+ }) => {
7878
7882
  if (!transform) transform = identity3();
7879
7883
  const [dimensionToolVisible, setDimensionToolVisible] = useState5(false);
7880
7884
  const [dimensionToolStretching, setDimensionToolStretching] = useState5(false);
@@ -8139,7 +8143,7 @@ import { css } from "@emotion/css";
8139
8143
  // package.json
8140
8144
  var package_default = {
8141
8145
  name: "@tscircuit/pcb-viewer",
8142
- version: "1.11.40",
8146
+ version: "1.11.42",
8143
8147
  main: "dist/index.js",
8144
8148
  type: "module",
8145
8149
  repository: "tscircuit/pcb-viewer",
@@ -8167,7 +8171,7 @@ var package_default = {
8167
8171
  "@swc/core": "^1.4.12",
8168
8172
  "@tscircuit/core": "0.0.274",
8169
8173
  "@tscircuit/eagle-xml-converter": "^1.0.0",
8170
- "@tscircuit/props": "^0.0.142",
8174
+ "@tscircuit/props": "^0.0.143",
8171
8175
  "@tscircuit/soup-util": "^0.0.41",
8172
8176
  "@types/color": "^3.0.6",
8173
8177
  "@types/node": "18.7.23",
@@ -9456,16 +9460,23 @@ var CanvasElementsRenderer = (props) => {
9456
9460
  cancelPanDrag: props.cancelPanDrag,
9457
9461
  onCreateEditEvent: props.onCreateEditEvent,
9458
9462
  onModifyEditEvent: props.onModifyEditEvent,
9459
- children: /* @__PURE__ */ jsx13(DimensionOverlay, { transform, focusOnHover: props.focusOnHover, children: /* @__PURE__ */ jsx13(ToolbarOverlay, { elements, children: /* @__PURE__ */ jsx13(ErrorOverlay, { transform, elements, children: /* @__PURE__ */ jsx13(RatsNestOverlay, { transform, soup: elements, children: /* @__PURE__ */ jsx13(
9460
- CanvasPrimitiveRenderer,
9463
+ children: /* @__PURE__ */ jsx13(
9464
+ DimensionOverlay,
9461
9465
  {
9462
9466
  transform,
9463
- primitives,
9464
- width: props.width,
9465
- height: props.height,
9466
- grid: props.grid
9467
+ focusOnHover: props.focusOnHover,
9468
+ children: /* @__PURE__ */ jsx13(ToolbarOverlay, { elements, children: /* @__PURE__ */ jsx13(ErrorOverlay, { transform, elements, children: /* @__PURE__ */ jsx13(RatsNestOverlay, { transform, soup: elements, children: /* @__PURE__ */ jsx13(
9469
+ CanvasPrimitiveRenderer,
9470
+ {
9471
+ transform,
9472
+ primitives,
9473
+ width: props.width,
9474
+ height: props.height,
9475
+ grid: props.grid
9476
+ }
9477
+ ) }) }) })
9467
9478
  }
9468
- ) }) }) }) })
9479
+ )
9469
9480
  }
9470
9481
  )
9471
9482
  }
@@ -9486,7 +9497,9 @@ var PCBViewer = ({
9486
9497
  allowEditing = true,
9487
9498
  editEvents: editEventsProp,
9488
9499
  onEditEventsChanged,
9489
- focusOnHover = false
9500
+ focusOnHover = false,
9501
+ clickToInteractEnabled = false,
9502
+ disableAutoFocus = false
9490
9503
  }) => {
9491
9504
  circuitJson ??= soup;
9492
9505
  const {
@@ -9495,6 +9508,7 @@ var PCBViewer = ({
9495
9508
  isLoading
9496
9509
  } = useRenderedCircuit(children);
9497
9510
  circuitJson ??= circuitJsonFromChildren ?? [];
9511
+ const [isInteractionEnabled, setIsInteractionEnabled] = useState10(!clickToInteractEnabled);
9498
9512
  const [ref, refDimensions] = useMeasure_default();
9499
9513
  const [transform, setTransformInternal] = useState10(defaultTransform);
9500
9514
  const {
@@ -9503,11 +9517,12 @@ var PCBViewer = ({
9503
9517
  cancelDrag: cancelPanDrag
9504
9518
  } = src_default({
9505
9519
  transform,
9506
- onSetTransform: setTransformInternal
9520
+ onSetTransform: setTransformInternal,
9521
+ enabled: isInteractionEnabled
9507
9522
  });
9508
9523
  let [editEvents, setEditEvents] = useState10([]);
9509
9524
  editEvents = editEventsProp ?? editEvents;
9510
- const resetTransform = () => {
9525
+ const resetTransform = (shouldAnimate = false) => {
9511
9526
  const elmBounds = refDimensions?.width > 0 ? refDimensions : { width: 500, height: 500 };
9512
9527
  const { center, width, height: height2 } = elements.some(
9513
9528
  (e) => e.type.startsWith("pcb_")
@@ -9519,19 +9534,42 @@ var PCBViewer = ({
9519
9534
  (elmBounds.height ?? 0) / height2,
9520
9535
  100
9521
9536
  ) * 0.75;
9522
- setTransform(
9523
- compose4(
9524
- translate5((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
9525
- scale2(scaleFactor, -scaleFactor, 0, 0),
9526
- translate5(-center.x, -center.y)
9527
- )
9537
+ const targetTransform = compose4(
9538
+ translate5((elmBounds.width ?? 0) / 2, (elmBounds.height ?? 0) / 2),
9539
+ scale2(scaleFactor, -scaleFactor, 0, 0),
9540
+ translate5(-center.x, -center.y)
9528
9541
  );
9542
+ if (!shouldAnimate) {
9543
+ setTransform(targetTransform);
9544
+ return;
9545
+ }
9546
+ const startTransform = { ...transform };
9547
+ const startTime = Date.now();
9548
+ const duration = 1e3;
9549
+ const animateTransform = () => {
9550
+ const elapsed = Date.now() - startTime;
9551
+ const progress = Math.min(elapsed / duration, 1);
9552
+ const easeProgress = 1 - Math.pow(1 - progress, 3);
9553
+ const newTransform = {
9554
+ a: startTransform.a + (targetTransform.a - startTransform.a) * easeProgress,
9555
+ b: startTransform.b + (targetTransform.b - startTransform.b) * easeProgress,
9556
+ c: startTransform.c + (targetTransform.c - startTransform.c) * easeProgress,
9557
+ d: startTransform.d + (targetTransform.d - startTransform.d) * easeProgress,
9558
+ e: startTransform.e + (targetTransform.e - startTransform.e) * easeProgress,
9559
+ f: startTransform.f + (targetTransform.f - startTransform.f) * easeProgress
9560
+ };
9561
+ setTransform(newTransform);
9562
+ if (progress < 1) {
9563
+ requestAnimationFrame(animateTransform);
9564
+ }
9565
+ };
9566
+ requestAnimationFrame(animateTransform);
9529
9567
  };
9530
9568
  useEffect12(() => {
9531
- if (refDimensions && refDimensions.width !== 0 && (children || soup)) {
9532
- resetTransform();
9569
+ if (!disableAutoFocus && refDimensions && refDimensions.width !== 0 && (children || soup) && (!clickToInteractEnabled || isInteractionEnabled)) {
9570
+ resetTransform(false);
9533
9571
  }
9534
- }, [children, refDimensions]);
9572
+ }, [children, refDimensions, clickToInteractEnabled, isInteractionEnabled, disableAutoFocus]);
9535
9573
  const pcbElmsPreEdit = useMemo6(
9536
9574
  () => circuitJson.filter(
9537
9575
  (e) => e.type.startsWith("pcb_") || e.type.startsWith("source_")
@@ -9552,33 +9590,67 @@ var PCBViewer = ({
9552
9590
  setEditEvents(newEditEvents);
9553
9591
  onEditEventsChanged?.(newEditEvents);
9554
9592
  };
9555
- return /* @__PURE__ */ jsx14("div", { ref: transformRef, children: /* @__PURE__ */ jsx14("div", { ref, children: /* @__PURE__ */ jsxs10(ContextProviders, { initialState, children: [
9556
- /* @__PURE__ */ jsx14(
9557
- CanvasElementsRenderer,
9593
+ return /* @__PURE__ */ jsxs10("div", { ref: transformRef, style: { position: "relative" }, children: [
9594
+ /* @__PURE__ */ jsx14("div", { ref, children: /* @__PURE__ */ jsxs10(ContextProviders, { initialState, children: [
9595
+ /* @__PURE__ */ jsx14(
9596
+ CanvasElementsRenderer,
9597
+ {
9598
+ transform,
9599
+ height,
9600
+ width: refDimensions.width,
9601
+ allowEditing,
9602
+ focusOnHover,
9603
+ cancelPanDrag,
9604
+ onCreateEditEvent,
9605
+ onModifyEditEvent,
9606
+ grid: {
9607
+ spacing: 1,
9608
+ view_window: {
9609
+ left: 0,
9610
+ right: refDimensions.width || 500,
9611
+ top: height,
9612
+ bottom: 0
9613
+ }
9614
+ },
9615
+ elements
9616
+ },
9617
+ refDimensions.width
9618
+ ),
9619
+ /* @__PURE__ */ jsx14(ToastContainer, {})
9620
+ ] }) }),
9621
+ clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx14(
9622
+ "div",
9558
9623
  {
9559
- transform,
9560
- height,
9561
- width: refDimensions.width,
9562
- allowEditing,
9563
- focusOnHover,
9564
- cancelPanDrag,
9565
- onCreateEditEvent,
9566
- onModifyEditEvent,
9567
- grid: {
9568
- spacing: 1,
9569
- view_window: {
9570
- left: 0,
9571
- right: refDimensions.width || 500,
9572
- top: height,
9573
- bottom: 0
9574
- }
9624
+ onClick: () => {
9625
+ setIsInteractionEnabled(true);
9626
+ resetTransform(true);
9575
9627
  },
9576
- elements
9577
- },
9578
- refDimensions.width
9579
- ),
9580
- /* @__PURE__ */ jsx14(ToastContainer, {})
9581
- ] }) }) });
9628
+ style: {
9629
+ position: "absolute",
9630
+ inset: 0,
9631
+ cursor: "pointer",
9632
+ zIndex: 10,
9633
+ display: "flex",
9634
+ alignItems: "center",
9635
+ justifyContent: "center"
9636
+ },
9637
+ children: /* @__PURE__ */ jsx14(
9638
+ "div",
9639
+ {
9640
+ style: {
9641
+ backgroundColor: "rgba(0, 0, 0, 0.8)",
9642
+ color: "white",
9643
+ padding: "12px 24px",
9644
+ borderRadius: "8px",
9645
+ fontSize: "16px",
9646
+ pointerEvents: "none"
9647
+ },
9648
+ children: "Click to Interact"
9649
+ }
9650
+ )
9651
+ }
9652
+ )
9653
+ ] });
9582
9654
  };
9583
9655
  export {
9584
9656
  CanvasElementsRenderer,