@tscircuit/schematic-viewer 2.0.103 → 2.0.105

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
@@ -2,6 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { CircuitJson } from 'circuit-json';
4
4
  import { ColorOverrides, AcSweepView } from 'circuit-to-svg';
5
+ import { PlatformConfig } from '@tscircuit/props';
5
6
 
6
7
  interface SchematicViewerController {
7
8
  /** @internal Pending command, consumed after the viewer focuses the component. */
@@ -34,6 +35,8 @@ interface ViewPcbComponentEvent {
34
35
 
35
36
  interface Props$1 {
36
37
  circuitJson: CircuitJson;
38
+ /** Platform providers used for supplier availability and requests. */
39
+ platformConfig?: PlatformConfig;
37
40
  containerStyle?: React.CSSProperties;
38
41
  debugGrid?: boolean;
39
42
  debug?: boolean;
@@ -62,7 +65,7 @@ interface Props$1 {
62
65
  /** Omit when the host has no enabled PCB view. */
63
66
  onViewPcbComponent?: (event: ViewPcbComponentEvent) => void;
64
67
  }
65
- declare const SchematicViewer: ({ circuitJson, containerStyle, debugGrid, debug, clickToInteractEnabled, colorOverrides, disableGroups, netHoverHighlightEnabled, onSchematicComponentClicked, showSchematicPorts, onSchematicPortClicked, onSchematicSheetChange, searchEnabled, controller, onViewPcbComponent, css, className, }: Props$1) => react.JSX.Element;
68
+ declare const SchematicViewer: ({ circuitJson, platformConfig, containerStyle, debugGrid, debug, clickToInteractEnabled, colorOverrides, disableGroups, netHoverHighlightEnabled, onSchematicComponentClicked, showSchematicPorts, onSchematicPortClicked, onSchematicSheetChange, searchEnabled, controller, onViewPcbComponent, css, className, }: Props$1) => react.JSX.Element;
66
69
 
67
70
  interface BoundingBoxBounds {
68
71
  minX: number;
package/dist/index.js CHANGED
@@ -175,13 +175,11 @@ function getNetLocations(circuitJson, key) {
175
175
  import * as Dialog from "@radix-ui/react-dialog";
176
176
 
177
177
  // lib/utils/load-style-analyzer.ts
178
- var STYLE_ANALYZER_URL = "https://jscdn.tscircuit.com/@tscircuit/circuit-json-schematic-placement-analysis/latest/dist/browser.js";
178
+ import importer from "@tscircuit/internal-dynamic-import";
179
179
  var styleAnalyzerLoader = {
180
180
  async load() {
181
- const analyzer = await import(
182
- /* @vite-ignore */
183
- /* webpackIgnore: true */
184
- STYLE_ANALYZER_URL
181
+ const analyzer = await importer(
182
+ "@tscircuit/circuit-json-schematic-placement-analysis"
185
183
  );
186
184
  if (typeof analyzer.createSchematicPlacementIssueArtifacts !== "function") {
187
185
  throw new Error(
@@ -199,7 +197,7 @@ import { useEffect, useState } from "react";
199
197
  var zIndexMap = {
200
198
  contextMenu: 110,
201
199
  styleAnalysis: 120,
202
- viewMenu: 55,
200
+ viewMenu: 110,
203
201
  viewMenuIcon: 48,
204
202
  clickToInteractOverlay: 100,
205
203
  schematicComponentDetailsTooltip: 105,
@@ -217,6 +215,7 @@ var StyleAnalysisDialog = ({
217
215
  const [state, setState] = useState({ status: "loading" });
218
216
  useEffect(() => {
219
217
  let cancelled = false;
218
+ setState({ status: "loading" });
220
219
  const timer = window.setTimeout(async () => {
221
220
  try {
222
221
  const { createSchematicPlacementIssueArtifacts } = await styleAnalyzerLoader.load();
@@ -1431,7 +1430,7 @@ import {
1431
1430
  getPcbElementBounds,
1432
1431
  getPcbElementsWithinBounds
1433
1432
  } from "@tscircuit/circuit-json-util";
1434
- import { gzipSync, strToU8 } from "fflate";
1433
+ import { convertCircuitJsonToPcbSvg } from "circuit-to-svg";
1435
1434
  var getComponentWarnings = (circuitJson, schematicComponent, pcbComponent) => circuitJson.filter((element) => {
1436
1435
  if (!element.type.endsWith("_warning")) return false;
1437
1436
  const warning = element;
@@ -1581,27 +1580,15 @@ var getPcbComponentPreview = (circuitJson, pcbComponentId) => {
1581
1580
  viewBox
1582
1581
  };
1583
1582
  };
1584
- var bytesToBase64 = (bytes) => {
1585
- let binary = "";
1586
- const chunkSize = 8192;
1587
- for (let index = 0; index < bytes.length; index += chunkSize) {
1588
- binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));
1589
- }
1590
- return btoa(binary);
1591
- };
1592
1583
  var getFootprintPreviewUrl = (footprintPreviewCircuitJson, viewBox) => {
1593
- const encodedCircuitJson = bytesToBase64(
1594
- gzipSync(strToU8(JSON.stringify(footprintPreviewCircuitJson)))
1595
- );
1596
- const url = new URL("https://svg.tscircuit.com/");
1597
- url.searchParams.set("svg_type", "pcb");
1598
- url.searchParams.set("circuit_json", encodedCircuitJson);
1599
- url.searchParams.set(
1600
- "viewbox",
1601
- [viewBox.minX, viewBox.minY, viewBox.maxX, viewBox.maxY].join(",")
1602
- );
1603
- url.searchParams.set("background_color", "#f8fafc");
1604
- return url.toString();
1584
+ const svg = convertCircuitJsonToPcbSvg(footprintPreviewCircuitJson, {
1585
+ width: 320,
1586
+ height: 240,
1587
+ viewport: viewBox,
1588
+ backgroundColor: "#f8fafc",
1589
+ includeVersion: false
1590
+ });
1591
+ return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
1605
1592
  };
1606
1593
 
1607
1594
  // lib/utils/get-pcb-component-at-element.ts
@@ -1856,8 +1843,8 @@ var getPrice = (value) => {
1856
1843
  }
1857
1844
  return null;
1858
1845
  };
1859
- var fetchJlcPartAvailability = async (partNumber, signal) => {
1860
- const response = await fetch(
1846
+ var fetchJlcPartAvailability = async (partNumber, signal, platformFetch = fetch) => {
1847
+ const response = await platformFetch(
1861
1848
  `https://jlcsearch.tscircuit.com/api/search?q=${encodeURIComponent(partNumber)}&limit=1`,
1862
1849
  { signal, cache: "no-store" }
1863
1850
  );
@@ -1876,9 +1863,26 @@ var fetchJlcPartAvailability = async (partNumber, signal) => {
1876
1863
 
1877
1864
  // lib/components/JlcPartAvailability.tsx
1878
1865
  import { Fragment as Fragment3, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
1879
- var JlcPartAvailability = ({ partNumber }) => {
1866
+ var formatPrice = (availability) => {
1867
+ if (availability?.price == null) return "Price unavailable";
1868
+ const options = { minimumFractionDigits: 2, maximumFractionDigits: 6 };
1869
+ if (availability.currency === null) {
1870
+ return availability.price.toLocaleString("en-US", options);
1871
+ }
1872
+ return availability.price.toLocaleString("en-US", {
1873
+ ...options,
1874
+ style: "currency",
1875
+ currency: availability.currency ?? "USD"
1876
+ });
1877
+ };
1878
+ var JlcPartAvailability = ({
1879
+ partNumber,
1880
+ platformConfig
1881
+ }) => {
1880
1882
  const [result, setResult] = useState5(null);
1881
1883
  const [loading, setLoading] = useState5(true);
1884
+ const partsEngine = platformConfig?.partsEngine;
1885
+ const platformFetch = platformConfig?.platformFetch;
1882
1886
  useEffect8(() => {
1883
1887
  const controller = new AbortController();
1884
1888
  let active = true;
@@ -1888,7 +1892,21 @@ var JlcPartAvailability = ({ partNumber }) => {
1888
1892
  controller.abort();
1889
1893
  if (active) setLoading(false);
1890
1894
  }, 1e4);
1891
- fetchJlcPartAvailability(partNumber, controller.signal).then((availability) => {
1895
+ Promise.resolve().then(async () => {
1896
+ if (partsEngine?.fetchPartAvailability) {
1897
+ return await partsEngine.fetchPartAvailability({
1898
+ supplierName: "jlcpcb",
1899
+ supplierPartNumber: partNumber,
1900
+ signal: controller.signal,
1901
+ platformFetch
1902
+ }) ?? null;
1903
+ }
1904
+ return fetchJlcPartAvailability(
1905
+ partNumber,
1906
+ controller.signal,
1907
+ platformFetch
1908
+ );
1909
+ }).then((availability) => {
1892
1910
  if (active) setResult(availability);
1893
1911
  }).catch(() => {
1894
1912
  }).finally(() => {
@@ -1900,7 +1918,7 @@ var JlcPartAvailability = ({ partNumber }) => {
1900
1918
  clearTimeout(timeout);
1901
1919
  controller.abort();
1902
1920
  };
1903
- }, [partNumber]);
1921
+ }, [partNumber, partsEngine, platformFetch]);
1904
1922
  return /* @__PURE__ */ jsx3(
1905
1923
  "span",
1906
1924
  {
@@ -1934,7 +1952,7 @@ var JlcPartAvailability = ({ partNumber }) => {
1934
1952
  ) }),
1935
1953
  "Loading price and stock\u2026"
1936
1954
  ] }) : /* @__PURE__ */ jsxs2(Fragment3, { children: [
1937
- /* @__PURE__ */ jsx3("span", { style: { display: "block" }, children: result?.price != null ? `$${result.price.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 6 })}` : "Price unavailable" }),
1955
+ /* @__PURE__ */ jsx3("span", { style: { display: "block" }, children: formatPrice(result) }),
1938
1956
  /* @__PURE__ */ jsx3("span", { style: { display: "block" }, children: result?.stock != null ? `${result.stock.toLocaleString("en-US")} in stock` : "Stock unavailable" })
1939
1957
  ] })
1940
1958
  }
@@ -1950,6 +1968,7 @@ var detailLabelStyle = {
1950
1968
  lineHeight: 1.45
1951
1969
  };
1952
1970
  var SchematicComponentDetailsTooltip = ({
1971
+ platformConfig,
1953
1972
  sourceComponent,
1954
1973
  warnings = [],
1955
1974
  footprinterString,
@@ -2071,7 +2090,8 @@ var SchematicComponentDetailsTooltip = ({
2071
2090
  entry.label === "jlcpcb" && /* @__PURE__ */ jsx4(
2072
2091
  JlcPartAvailability,
2073
2092
  {
2074
- partNumber: link.partNumber
2093
+ partNumber: link.partNumber,
2094
+ platformConfig
2075
2095
  },
2076
2096
  `${sourceComponent.source_component_id}-${link.partNumber}`
2077
2097
  )
@@ -3284,17 +3304,24 @@ import { useMemo as useMemo5 } from "react";
3284
3304
  // package.json
3285
3305
  var package_default = {
3286
3306
  name: "@tscircuit/schematic-viewer",
3287
- version: "2.0.102",
3307
+ version: "2.0.104",
3288
3308
  repository: {
3289
3309
  type: "git",
3290
3310
  url: "https://github.com/tscircuit/schematic-viewer"
3291
3311
  },
3292
3312
  main: "dist/index.js",
3313
+ exports: {
3314
+ ".": {
3315
+ types: "./dist/index.d.ts",
3316
+ default: "./dist/index.js"
3317
+ }
3318
+ },
3293
3319
  type: "module",
3294
3320
  scripts: {
3295
3321
  start: "cosmos",
3296
3322
  build: "tsup-node ./lib/index.ts --dts --format esm --sourcemap",
3297
3323
  "build:site": "cosmos-export",
3324
+ "test:package": "bun run build && bun run scripts/test-package.ts",
3298
3325
  "vercel-build": "bun run build:site",
3299
3326
  format: "biome format --write .",
3300
3327
  "format:check": "biome format ."
@@ -3330,11 +3357,14 @@ var package_default = {
3330
3357
  "@radix-ui/react-dialog": "^1.1.23",
3331
3358
  "@radix-ui/react-dropdown-menu": "^2.1.16",
3332
3359
  "@tscircuit/circuit-json-util": "^0.0.108",
3360
+ "@tscircuit/internal-dynamic-import": "^0.0.17",
3361
+ "@tscircuit/props": "^0.0.697",
3362
+ "@tscircuit/soup-util": "^0.0.41",
3333
3363
  "circuit-json": "^0.0.479",
3334
3364
  "circuit-to-svg": "^0.0.432",
3335
3365
  debug: "^4.4.0",
3336
- fflate: "^0.8.3",
3337
3366
  "performance-now": "^2.1.0",
3367
+ "transformation-matrix": "^2.16.1",
3338
3368
  "use-mouse-matrix-transform": "^1.2.2"
3339
3369
  }
3340
3370
  };
@@ -3642,6 +3672,7 @@ var ViewMenu = ({
3642
3672
  import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
3643
3673
  var SchematicViewer = ({
3644
3674
  circuitJson,
3675
+ platformConfig,
3645
3676
  containerStyle,
3646
3677
  debugGrid = false,
3647
3678
  debug: debug2 = false,
@@ -4198,6 +4229,7 @@ var SchematicViewer = ({
4198
4229
  selectedComponentDetails && componentTooltipLayout && /* @__PURE__ */ jsx12(
4199
4230
  SchematicComponentDetailsTooltip,
4200
4231
  {
4232
+ platformConfig,
4201
4233
  sourceComponent: selectedComponentDetails.sourceComponent,
4202
4234
  warnings: selectedComponentDetails.warnings,
4203
4235
  footprinterString: selectedComponentDetails.footprinterString,