@tscircuit/schematic-viewer 2.0.94 → 2.0.95

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 CHANGED
@@ -606,8 +606,116 @@ function buildNetRegistry(circuitJson) {
606
606
  return { componentIdToKeys, netLabelIdToKey };
607
607
  }
608
608
 
609
+ // lib/hooks/useSchematicWarnings.ts
610
+ import { useLayoutEffect, useRef } from "react";
611
+ var SVG_NS = "http://www.w3.org/2000/svg";
612
+ var useSchematicWarnings = ({
613
+ svgDivRef,
614
+ svgContent,
615
+ circuitJsonKey
616
+ }) => {
617
+ const minimizedIds = useRef(/* @__PURE__ */ new Set());
618
+ useLayoutEffect(() => {
619
+ minimizedIds.current.clear();
620
+ }, [circuitJsonKey]);
621
+ useLayoutEffect(() => {
622
+ const cleanups = [];
623
+ for (const warning of svgDivRef.current?.querySelectorAll(
624
+ ".schematic-warning"
625
+ ) ?? []) {
626
+ const id = warning.getAttribute("data-warning-id");
627
+ const callout = warning.querySelector(
628
+ '[data-warning-reference="callout"]'
629
+ );
630
+ if (!id || !callout) continue;
631
+ const content = Array.from(warning.children);
632
+ const originalDisplays = content.map((child) => child.style.display);
633
+ const originalRole = warning.getAttribute("role");
634
+ const message = warning.getAttribute("aria-label") ?? "Warning";
635
+ const icon = document.createElementNS(SVG_NS, "g");
636
+ icon.setAttribute("data-warning-icon", "");
637
+ icon.setAttribute("aria-hidden", "true");
638
+ icon.setAttribute(
639
+ "transform",
640
+ `translate(${callout.getAttribute("x")} ${callout.getAttribute("y")})`
641
+ );
642
+ const badge = document.createElementNS(SVG_NS, "rect");
643
+ badge.setAttribute("width", "24");
644
+ badge.setAttribute("height", "24");
645
+ badge.setAttribute("fill", callout.getAttribute("fill") ?? "#fffaeb");
646
+ badge.setAttribute("stroke", callout.getAttribute("stroke") ?? "#d99a00");
647
+ badge.setAttribute("stroke-width", "1");
648
+ const mark = document.createElementNS(SVG_NS, "text");
649
+ mark.setAttribute("x", "12");
650
+ mark.setAttribute("y", "12");
651
+ mark.setAttribute("dominant-baseline", "central");
652
+ mark.setAttribute("text-anchor", "middle");
653
+ mark.setAttribute("font-size", "16");
654
+ mark.setAttribute("font-family", "sans-serif");
655
+ mark.setAttribute("font-weight", "bold");
656
+ mark.setAttribute("fill", "#5c4300");
657
+ mark.textContent = "!";
658
+ icon.append(badge, mark);
659
+ warning.append(icon);
660
+ warning.setAttribute("role", "button");
661
+ warning.setAttribute("tabindex", "0");
662
+ warning.style.cursor = "pointer";
663
+ warning.style.outline = "none";
664
+ const update = () => {
665
+ const minimized = minimizedIds.current.has(id);
666
+ content.forEach((child, index) => {
667
+ child.style.display = minimized ? "none" : originalDisplays[index];
668
+ });
669
+ icon.style.display = minimized ? "" : "none";
670
+ warning.setAttribute("aria-expanded", String(!minimized));
671
+ warning.setAttribute(
672
+ "aria-label",
673
+ `${minimized ? "Expand" : "Minimize"} warning: ${message}`
674
+ );
675
+ };
676
+ const toggle = (event) => {
677
+ event.preventDefault();
678
+ event.stopPropagation();
679
+ if (minimizedIds.current.has(id)) minimizedIds.current.delete(id);
680
+ else minimizedIds.current.add(id);
681
+ update();
682
+ };
683
+ const onKeyDown = (event) => {
684
+ if (event.key === "Enter" || event.key === " ") {
685
+ if (!event.repeat) toggle(event);
686
+ else event.preventDefault();
687
+ }
688
+ };
689
+ const stopPropagation = (event) => event.stopPropagation();
690
+ warning.addEventListener("click", toggle);
691
+ warning.addEventListener("keydown", onKeyDown);
692
+ warning.addEventListener("mousedown", stopPropagation);
693
+ warning.addEventListener("touchstart", stopPropagation);
694
+ update();
695
+ cleanups.push(() => {
696
+ warning.removeEventListener("click", toggle);
697
+ warning.removeEventListener("keydown", onKeyDown);
698
+ warning.removeEventListener("mousedown", stopPropagation);
699
+ warning.removeEventListener("touchstart", stopPropagation);
700
+ icon.remove();
701
+ content.forEach((child, index) => {
702
+ child.style.display = originalDisplays[index];
703
+ });
704
+ if (originalRole) warning.setAttribute("role", originalRole);
705
+ else warning.removeAttribute("role");
706
+ warning.setAttribute("aria-label", message);
707
+ warning.removeAttribute("aria-expanded");
708
+ warning.removeAttribute("tabindex");
709
+ warning.style.removeProperty("cursor");
710
+ warning.style.removeProperty("outline");
711
+ });
712
+ }
713
+ return () => cleanups.forEach((cleanup) => cleanup());
714
+ }, [svgDivRef, svgContent, circuitJsonKey]);
715
+ };
716
+
609
717
  // lib/hooks/useSchematicSearch.ts
610
- import { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef, useState as useState2 } from "react";
718
+ import { useCallback as useCallback2, useEffect as useEffect4, useMemo, useRef as useRef2, useState as useState2 } from "react";
611
719
  import { fromString } from "transformation-matrix";
612
720
 
613
721
  // lib/utils/get-schematic-search-results.ts
@@ -815,7 +923,7 @@ var useSchematicSearch = ({
815
923
  }) => {
816
924
  const [searchQuery, setSearchQuery] = useState2("");
817
925
  const [pendingSearchResult, setPendingSearchResult] = useState2(null);
818
- const searchAnimationTimerRef = useRef(
926
+ const searchAnimationTimerRef = useRef2(
819
927
  null
820
928
  );
821
929
  const searchResults = useMemo(
@@ -947,7 +1055,7 @@ var enableDebug = () => {
947
1055
  };
948
1056
 
949
1057
  // lib/components/SchematicViewer.tsx
950
- import { useCallback as useCallback7, useEffect as useEffect12, useMemo as useMemo6, useRef as useRef8, useState as useState9 } from "react";
1058
+ import { useCallback as useCallback7, useEffect as useEffect12, useMemo as useMemo6, useRef as useRef9, useState as useState9 } from "react";
951
1059
  import { toString as transformToString } from "transformation-matrix";
952
1060
  import { useMouseMatrixTransform } from "use-mouse-matrix-transform";
953
1061
 
@@ -976,16 +1084,16 @@ var useResizeHandling = (containerRef) => {
976
1084
  };
977
1085
 
978
1086
  // lib/hooks/useContextMenu.ts
979
- import { useCallback as useCallback3, useEffect as useEffect6, useRef as useRef2, useState as useState4 } from "react";
1087
+ import { useCallback as useCallback3, useEffect as useEffect6, useRef as useRef3, useState as useState4 } from "react";
980
1088
  var LONG_PRESS_DURATION_MS = 600;
981
1089
  var MOVEMENT_THRESHOLD_PX = 10;
982
1090
  var useContextMenu = ({ containerRef }) => {
983
1091
  const [menuVisible, setMenuVisible] = useState4(false);
984
1092
  const [menuPos, setMenuPos] = useState4({ x: 0, y: 0 });
985
- const menuRef = useRef2(null);
986
- const interactionOriginRef = useRef2(null);
987
- const longPressTimeoutRef = useRef2(null);
988
- const ignoreContextMenuUntilRef = useRef2(0);
1093
+ const menuRef = useRef3(null);
1094
+ const interactionOriginRef = useRef3(null);
1095
+ const longPressTimeoutRef = useRef3(null);
1096
+ const ignoreContextMenuUntilRef = useRef3(0);
989
1097
  const clearLongPressTimeout = useCallback3(() => {
990
1098
  if (longPressTimeoutRef.current === null) return;
991
1099
  window.clearTimeout(longPressTimeoutRef.current);
@@ -1269,7 +1377,7 @@ import {
1269
1377
  useContext,
1270
1378
  useEffect as useEffect7,
1271
1379
  useMemo as useMemo2,
1272
- useRef as useRef3
1380
+ useRef as useRef4
1273
1381
  } from "react";
1274
1382
  import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
1275
1383
  var MouseTrackerContext = createContext(null);
@@ -1287,7 +1395,7 @@ var MouseTracker = ({ children }) => {
1287
1395
  return /* @__PURE__ */ jsx2(MouseTrackerProvider, { children });
1288
1396
  };
1289
1397
  var MouseTrackerProvider = ({ children }) => {
1290
- const storeRef = useRef3({
1398
+ const storeRef = useRef4({
1291
1399
  pointer: null,
1292
1400
  boundingBoxes: /* @__PURE__ */ new Map(),
1293
1401
  hoveringIds: /* @__PURE__ */ new Set(),
@@ -1645,7 +1753,7 @@ var SchematicComponentDetailsTooltip = ({
1645
1753
  };
1646
1754
 
1647
1755
  // lib/components/SchematicComponentMouseTarget.tsx
1648
- import { useCallback as useCallback5, useEffect as useEffect9, useRef as useRef5, useState as useState5 } from "react";
1756
+ import { useCallback as useCallback5, useEffect as useEffect9, useRef as useRef6, useState as useState5 } from "react";
1649
1757
 
1650
1758
  // lib/hooks/useMouseEventsOverBoundingBox.ts
1651
1759
  import {
@@ -1653,7 +1761,7 @@ import {
1653
1761
  useEffect as useEffect8,
1654
1762
  useId,
1655
1763
  useMemo as useMemo4,
1656
- useRef as useRef4,
1764
+ useRef as useRef5,
1657
1765
  useSyncExternalStore
1658
1766
  } from "react";
1659
1767
  var useMouseEventsOverBoundingBox = (options) => {
@@ -1664,7 +1772,7 @@ var useMouseEventsOverBoundingBox = (options) => {
1664
1772
  );
1665
1773
  }
1666
1774
  const id = useId();
1667
- const latestOptionsRef = useRef4(options);
1775
+ const latestOptionsRef = useRef5(options);
1668
1776
  latestOptionsRef.current = options;
1669
1777
  const handleClick = useMemo4(
1670
1778
  () => (event) => {
@@ -1721,7 +1829,7 @@ var SchematicComponentMouseTarget = ({
1721
1829
  circuitJsonKey
1722
1830
  }) => {
1723
1831
  const [measurement, setMeasurement] = useState5(null);
1724
- const frameRef = useRef5(null);
1832
+ const frameRef = useRef6(null);
1725
1833
  const measure = useCallback5(() => {
1726
1834
  frameRef.current = null;
1727
1835
  const svgDiv = svgDivRef.current;
@@ -1836,7 +1944,7 @@ var SchematicComponentMouseTarget = ({
1836
1944
  };
1837
1945
 
1838
1946
  // lib/components/SchematicPortMouseTarget.tsx
1839
- import { useCallback as useCallback6, useEffect as useEffect10, useRef as useRef6, useState as useState6 } from "react";
1947
+ import { useCallback as useCallback6, useEffect as useEffect10, useRef as useRef7, useState as useState6 } from "react";
1840
1948
  import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1841
1949
  var areMeasurementsEqual2 = (a, b) => {
1842
1950
  if (!a && !b) return true;
@@ -1854,7 +1962,7 @@ var SchematicPortMouseTarget = ({
1854
1962
  circuitJsonKey
1855
1963
  }) => {
1856
1964
  const [measurement, setMeasurement] = useState6(null);
1857
- const frameRef = useRef6(null);
1965
+ const frameRef = useRef7(null);
1858
1966
  const measure = useCallback6(() => {
1859
1967
  frameRef.current = null;
1860
1968
  const svgDiv = svgDivRef.current;
@@ -1996,7 +2104,7 @@ var SchematicPortMouseTarget = ({
1996
2104
  };
1997
2105
 
1998
2106
  // lib/components/SchematicSearch.tsx
1999
- import { useEffect as useEffect11, useRef as useRef7, useState as useState7 } from "react";
2107
+ import { useEffect as useEffect11, useRef as useRef8, useState as useState7 } from "react";
2000
2108
 
2001
2109
  // lib/components/SchematicSearchIcons.tsx
2002
2110
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
@@ -2084,8 +2192,8 @@ var SchematicSearch = ({
2084
2192
  const [isOpen, setIsOpen] = useState7(false);
2085
2193
  const [activeResultId, setActiveResultId] = useState7(null);
2086
2194
  const [hoveredResultId, setHoveredResultId] = useState7(null);
2087
- const inputRef = useRef7(null);
2088
- const resultsListRef = useRef7(null);
2195
+ const inputRef = useRef8(null);
2196
+ const resultsListRef = useRef8(null);
2089
2197
  const shortcutLabel = getShortcutLabel();
2090
2198
  useEffect11(() => {
2091
2199
  setActiveResultId((currentId) => {
@@ -2744,7 +2852,7 @@ var SchematicWarningsButton = ({
2744
2852
  viewBox: "0 0 24 24",
2745
2853
  fill: "none",
2746
2854
  stroke: "currentColor",
2747
- strokeWidth: "2",
2855
+ strokeWidth: "1",
2748
2856
  strokeLinecap: "round",
2749
2857
  strokeLinejoin: "round",
2750
2858
  "aria-hidden": "true",
@@ -2768,7 +2876,7 @@ import { useMemo as useMemo5 } from "react";
2768
2876
  // package.json
2769
2877
  var package_default = {
2770
2878
  name: "@tscircuit/schematic-viewer",
2771
- version: "2.0.93",
2879
+ version: "2.0.94",
2772
2880
  repository: {
2773
2881
  type: "git",
2774
2882
  url: "https://github.com/tscircuit/schematic-viewer"
@@ -2815,7 +2923,7 @@ var package_default = {
2815
2923
  "@radix-ui/react-dropdown-menu": "^2.1.16",
2816
2924
  "@tscircuit/circuit-json-util": "^0.0.108",
2817
2925
  "circuit-json": "^0.0.479",
2818
- "circuit-to-svg": "^0.0.416",
2926
+ "circuit-to-svg": "^0.0.421",
2819
2927
  debug: "^4.4.0",
2820
2928
  fflate: "^0.8.3",
2821
2929
  "performance-now": "^2.1.0",
@@ -3151,7 +3259,7 @@ var SchematicViewer = ({
3151
3259
  }
3152
3260
  }, [showSchematicPorts]);
3153
3261
  const [isHoveringClickableComponent, setIsHoveringClickableComponent] = useState9(false);
3154
- const hoveringComponentsRef = useRef8(/* @__PURE__ */ new Set());
3262
+ const hoveringComponentsRef = useRef9(/* @__PURE__ */ new Set());
3155
3263
  const [selectedSchematicComponent, setSelectedSchematicComponent] = useState9(null);
3156
3264
  const handleComponentHoverChange = useCallback7(
3157
3265
  (componentId, isHovering) => {
@@ -3165,7 +3273,7 @@ var SchematicViewer = ({
3165
3273
  []
3166
3274
  );
3167
3275
  const [isHoveringClickablePort, setIsHoveringClickablePort] = useState9(false);
3168
- const hoveringPortsRef = useRef8(/* @__PURE__ */ new Set());
3276
+ const hoveringPortsRef = useRef9(/* @__PURE__ */ new Set());
3169
3277
  const handlePortHoverChange = useCallback7(
3170
3278
  (portId, isHovering) => {
3171
3279
  if (isHovering) {
@@ -3177,9 +3285,9 @@ var SchematicViewer = ({
3177
3285
  },
3178
3286
  []
3179
3287
  );
3180
- const svgDivRef = useRef8(null);
3181
- const touchStartRef = useRef8(null);
3182
- const zoomScaleRef = useRef8({ x: 1, y: 1 });
3288
+ const svgDivRef = useRef9(null);
3289
+ const touchStartRef = useRef9(null);
3290
+ const zoomScaleRef = useRef9({ x: 1, y: 1 });
3183
3291
  const schematicComponentIds = useMemo6(() => {
3184
3292
  try {
3185
3293
  const components = su4(circuitJson).schematic_component?.list() ?? [];
@@ -3234,7 +3342,7 @@ var SchematicViewer = ({
3234
3342
  const shouldPanSchematic = useCallback7(
3235
3343
  (event) => {
3236
3344
  if (event.target instanceof Element && event.target.closest(
3237
- "[data-schematic-search], [data-schematic-warnings]"
3345
+ "[data-schematic-search], [data-schematic-warnings], .schematic-warning"
3238
3346
  )) {
3239
3347
  return false;
3240
3348
  }
@@ -3416,6 +3524,7 @@ var SchematicViewer = ({
3416
3524
  ),
3417
3525
  [svgString, isInteractionEnabled, clickToInteractEnabled]
3418
3526
  );
3527
+ useSchematicWarnings({ svgDivRef, svgContent: svgDiv, circuitJsonKey });
3419
3528
  return /* @__PURE__ */ jsxs9(MouseTracker, { children: [
3420
3529
  netHoverHighlightEnabled && /* @__PURE__ */ jsx11("style", { children: `.sch-net-faded { opacity: 0.35; }
3421
3530
  svg :is(g.trace, g.trace-overlays, g[data-schematic-component-id], [data-schematic-net-label-id]) { transition: opacity 0.12s ease-in-out; }` }),
@@ -3647,7 +3756,7 @@ import {
3647
3756
  convertCircuitJsonToSchematicSimulationSvg,
3648
3757
  convertCircuitJsonToSimulationGraphSvg
3649
3758
  } from "circuit-to-svg";
3650
- import { useEffect as useEffect13, useMemo as useMemo7, useRef as useRef9, useState as useState11 } from "react";
3759
+ import { useEffect as useEffect13, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
3651
3760
  import { toString as transformToString2 } from "transformation-matrix";
3652
3761
  import { useMouseMatrixTransform as useMouseMatrixTransform2 } from "use-mouse-matrix-transform";
3653
3762
 
@@ -3862,8 +3971,8 @@ var AnalogSimulationViewer = ({
3862
3971
  const [isLoading, setIsLoading] = useState11(true);
3863
3972
  const [error, setError] = useState11(null);
3864
3973
  const [svgObjectUrl, setSvgObjectUrl] = useState11(null);
3865
- const containerRef = useRef9(null);
3866
- const imgRef = useRef9(null);
3974
+ const containerRef = useRef10(null);
3975
+ const imgRef = useRef10(null);
3867
3976
  const { containerWidth } = useResizeHandling(
3868
3977
  containerRef
3869
3978
  );