@tscircuit/core 0.0.339 → 0.0.341

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
@@ -135,13 +135,13 @@ declare class RootCircuit {
135
135
  render(): void;
136
136
  renderUntilSettled(): Promise<void>;
137
137
  private _hasIncompleteAsyncEffects;
138
- getSoup(): AnyCircuitElement[];
139
138
  getCircuitJson(): AnyCircuitElement[];
140
139
  toJson(): AnyCircuitElement[];
141
140
  getSvg(options: {
142
141
  view: "pcb";
143
142
  layer?: string;
144
143
  }): Promise<string>;
144
+ getCoreVersion(): string;
145
145
  preview(previewNameOrOpts: string | {
146
146
  previewName: string;
147
147
  tscircuitApiKey?: string;
@@ -155,6 +155,7 @@ declare class RootCircuit {
155
155
  _eventListeners: Record<RootCircuitEventName, Array<(...args: any[]) => void>>;
156
156
  emit(event: RootCircuitEventName, ...args: any[]): void;
157
157
  on(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
158
+ removeListener(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
158
159
  getClientOrigin(): string;
159
160
  }
160
161
  /**
@@ -180,11 +181,19 @@ interface IGroup extends PrimitiveComponent {
180
181
  pcb_group_id: string | null;
181
182
  }
182
183
 
184
+ type Ftype = Extract<AnySourceComponent, {
185
+ ftype: string;
186
+ }>["ftype"];
187
+ type TwoPinPorts = "pin1" | "pin2";
188
+ type PassivePorts = TwoPinPorts;
189
+ type PolarizedPassivePorts = PassivePorts | "anode" | "cathode" | "pos" | "neg";
190
+ type TransistorPorts = "pin1" | "pin2" | "pin3" | "emitter" | "collector" | "base";
191
+
183
192
  interface BaseComponentConfig {
184
193
  componentName: string;
185
194
  schematicSymbolName?: string | null;
186
195
  zodProps: ZodType;
187
- sourceFtype?: AnySourceComponent["ftype"] | null;
196
+ sourceFtype?: Ftype | null;
188
197
  shouldRenderAsSchematicBox?: boolean;
189
198
  }
190
199
  /**
@@ -1629,12 +1638,6 @@ declare class Board extends Group<typeof boardProps> {
1629
1638
  _computePcbGlobalTransformBeforeLayout(): Matrix;
1630
1639
  }
1631
1640
 
1632
- type Ftype = AnySourceComponent["ftype"];
1633
- type TwoPinPorts = "pin1" | "pin2";
1634
- type PassivePorts = TwoPinPorts;
1635
- type PolarizedPassivePorts = PassivePorts | "anode" | "cathode" | "pos" | "neg";
1636
- type TransistorPorts = "pin1" | "pin2" | "pin3" | "emitter" | "collector" | "base";
1637
-
1638
1641
  declare class Capacitor extends NormalComponent<typeof capacitorProps, PassivePorts> {
1639
1642
  get config(): {
1640
1643
  componentName: string;
package/dist/index.js CHANGED
@@ -3656,7 +3656,18 @@ var pushEdgesOfSchematicTraceToPreventOverlap = ({
3656
3656
  var isRouteOutsideBoard = (mergedRoute, { db }) => {
3657
3657
  const pcbBoard = db.pcb_board.list()[0];
3658
3658
  if (pcbBoard.outline) {
3659
- return true;
3659
+ const boardOutline = pcbBoard.outline;
3660
+ const isInsidePolygon = (point, polygon) => {
3661
+ let inside = false;
3662
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
3663
+ const xi = polygon[i].x, yi = polygon[i].y;
3664
+ const xj = polygon[j].x, yj = polygon[j].y;
3665
+ const intersect = yi > point.y !== yj > point.y && point.x < (xj - xi) * (point.y - yi) / (yj - yi) + xi;
3666
+ if (intersect) inside = !inside;
3667
+ }
3668
+ return inside;
3669
+ };
3670
+ return mergedRoute.some((point) => !isInsidePolygon(point, boardOutline));
3660
3671
  }
3661
3672
  const boardWidth = pcbBoard.width;
3662
3673
  const boardHeight = pcbBoard.height;
@@ -5710,6 +5721,9 @@ var Group = class extends NormalComponent {
5710
5721
  const serverMode = autorouterConfig.serverMode;
5711
5722
  const fetchWithDebug = (url, options) => {
5712
5723
  debug4("fetching", url);
5724
+ if (options.headers) {
5725
+ options.headers["Tscircuit-Core-Version"] = this.root?.getCoreVersion();
5726
+ }
5713
5727
  return fetch(url, options);
5714
5728
  };
5715
5729
  const pcbAndSourceCircuitJson = this.root.db.toArray().filter(
@@ -5731,7 +5745,9 @@ var Group = class extends NormalComponent {
5731
5745
  }).simpleRouteJson,
5732
5746
  subcircuit_id: this.subcircuit_id
5733
5747
  }),
5734
- headers: { "Content-Type": "application/json" }
5748
+ headers: {
5749
+ "Content-Type": "application/json"
5750
+ }
5735
5751
  }
5736
5752
  ).then((r) => r.json());
5737
5753
  this._asyncAutoroutingResult = autorouting_result2;
@@ -5746,7 +5762,9 @@ var Group = class extends NormalComponent {
5746
5762
  input_circuit_json: pcbAndSourceCircuitJson,
5747
5763
  subcircuit_id: this.subcircuit_id
5748
5764
  }),
5749
- headers: { "Content-Type": "application/json" }
5765
+ headers: {
5766
+ "Content-Type": "application/json"
5767
+ }
5750
5768
  }
5751
5769
  ).then((r) => r.json());
5752
5770
  this._asyncAutoroutingResult = autorouting_result;
@@ -5765,7 +5783,9 @@ var Group = class extends NormalComponent {
5765
5783
  subcircuit_id: this.subcircuit_id,
5766
5784
  server_cache_enabled: autorouterConfig.serverCacheEnabled
5767
5785
  }),
5768
- headers: { "Content-Type": "application/json" }
5786
+ headers: {
5787
+ "Content-Type": "application/json"
5788
+ }
5769
5789
  }
5770
5790
  ).then((r) => r.json());
5771
5791
  while (true) {
@@ -6039,7 +6059,7 @@ var Group = class extends NormalComponent {
6039
6059
  };
6040
6060
  return {
6041
6061
  local: true,
6042
- groupMode: "sequential-trace"
6062
+ groupMode: "subcircuit"
6043
6063
  };
6044
6064
  }
6045
6065
  /**
@@ -7220,6 +7240,83 @@ var Switch = class extends NormalComponent {
7220
7240
  import { su as su3 } from "@tscircuit/soup-util";
7221
7241
  import { isValidElement as isValidElement2 } from "react";
7222
7242
  import { identity as identity4 } from "transformation-matrix";
7243
+
7244
+ // package.json
7245
+ var package_default = {
7246
+ name: "@tscircuit/core",
7247
+ type: "module",
7248
+ version: "0.0.340",
7249
+ types: "dist/index.d.ts",
7250
+ main: "dist/index.js",
7251
+ module: "dist/index.js",
7252
+ files: [
7253
+ "dist"
7254
+ ],
7255
+ repository: {
7256
+ type: "git",
7257
+ url: "https://github.com/tscircuit/core"
7258
+ },
7259
+ scripts: {
7260
+ build: "tsup-node index.ts --format esm --dts",
7261
+ format: "biome format . --write",
7262
+ "measure-bundle": "howfat -r table .",
7263
+ "pkg-pr-new-release": "bunx pkg-pr-new publish --comment=off --peerDeps",
7264
+ "build:benchmarking": "bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist",
7265
+ "build:benchmarking:watch": `chokidar "./{benchmarking,lib}/**/*.{ts,tsx}" -c 'bun build --experimental-html ./benchmarking/website/index.html --outdir ./benchmarking-dist'`,
7266
+ "start:benchmarking": 'concurrently "bun run build:benchmarking:watch" "live-server ./benchmarking-dist"'
7267
+ },
7268
+ devDependencies: {
7269
+ "@biomejs/biome": "^1.8.3",
7270
+ "@tscircuit/footprinter": "^0.0.140",
7271
+ "@tscircuit/import-snippet": "^0.0.4",
7272
+ "@tscircuit/layout": "^0.0.28",
7273
+ "@tscircuit/log-soup": "^1.0.2",
7274
+ "@types/bun": "latest",
7275
+ "@types/debug": "^4.1.12",
7276
+ "@types/react": "^19.0.1",
7277
+ "@types/react-dom": "^19.0.2",
7278
+ "@types/react-reconciler": "^0.28.9",
7279
+ "bun-match-svg": "0.0.8",
7280
+ "chokidar-cli": "^3.0.0",
7281
+ "circuit-to-svg": "^0.0.99",
7282
+ concurrently: "^9.1.2",
7283
+ debug: "^4.3.6",
7284
+ "graphics-debug": "^0.0.4",
7285
+ howfat: "^0.3.8",
7286
+ "live-server": "^1.2.2",
7287
+ "looks-same": "^9.0.1",
7288
+ "pkg-pr-new": "^0.0.37",
7289
+ react: "^19.0.0",
7290
+ "react-dom": "^19.0.0",
7291
+ "ts-expect": "^1.3.0",
7292
+ tsup: "^8.2.4"
7293
+ },
7294
+ peerDependencies: {
7295
+ typescript: "^5.0.0",
7296
+ "@tscircuit/footprinter": "*"
7297
+ },
7298
+ dependencies: {
7299
+ "@lume/kiwi": "^0.4.3",
7300
+ "@tscircuit/capacity-autorouter": "^0.0.13",
7301
+ "@tscircuit/infgrid-ijump-astar": "^0.0.33",
7302
+ "@tscircuit/math-utils": "^0.0.9",
7303
+ "@tscircuit/props": "^0.0.159",
7304
+ "@tscircuit/schematic-autolayout": "^0.0.6",
7305
+ "@tscircuit/soup-util": "^0.0.41",
7306
+ "circuit-json": "^0.0.151",
7307
+ "circuit-json-to-connectivity-map": "^0.0.17",
7308
+ "format-si-unit": "^0.0.3",
7309
+ nanoid: "^5.0.7",
7310
+ "performance-now": "^2.1.0",
7311
+ "react-reconciler": "^0.31.0",
7312
+ "react-reconciler-18": "npm:react-reconciler@0.29.2",
7313
+ "schematic-symbols": "^0.0.121",
7314
+ "transformation-matrix": "^2.16.1",
7315
+ zod: "^3.23.8"
7316
+ }
7317
+ };
7318
+
7319
+ // lib/RootCircuit.ts
7223
7320
  var RootCircuit = class {
7224
7321
  firstChild = null;
7225
7322
  children;
@@ -7291,6 +7388,11 @@ var RootCircuit = class {
7291
7388
  this._hasRenderedAtleastOnce = true;
7292
7389
  }
7293
7390
  async renderUntilSettled() {
7391
+ if (!this.db.source_project_metadata.list()?.[0]) {
7392
+ this.db.source_project_metadata.insert({
7393
+ software_used_string: `@tscircuit/core@${this.getCoreVersion()}`
7394
+ });
7395
+ }
7294
7396
  this.render();
7295
7397
  while (this._hasIncompleteAsyncEffects()) {
7296
7398
  await new Promise((resolve) => setTimeout(resolve, 100));
@@ -7306,26 +7408,27 @@ var RootCircuit = class {
7306
7408
  );
7307
7409
  });
7308
7410
  }
7309
- getSoup() {
7411
+ getCircuitJson() {
7310
7412
  if (!this._hasRenderedAtleastOnce) this.render();
7311
7413
  return this.db.toArray();
7312
7414
  }
7313
- getCircuitJson() {
7314
- return this.getSoup();
7315
- }
7316
7415
  toJson() {
7317
- return this.getSoup();
7416
+ return this.getCircuitJson();
7318
7417
  }
7319
7418
  async getSvg(options) {
7320
7419
  const circuitToSvg = await import("circuit-to-svg").catch((e) => {
7321
7420
  throw new Error(
7322
- `To use project.getSvg, you must install the "circuit-to-svg" package.
7421
+ `To use circuit.getSvg, you must install the "circuit-to-svg" package.
7323
7422
 
7324
7423
  "${e.message}"`
7325
7424
  );
7326
7425
  });
7327
7426
  return circuitToSvg.convertCircuitJsonToPcbSvg(this.getCircuitJson());
7328
7427
  }
7428
+ getCoreVersion() {
7429
+ const [major, minor, patch] = package_default.version.split(".").map(Number);
7430
+ return `${major}.${minor}.${patch + 1}`;
7431
+ }
7329
7432
  async preview(previewNameOrOpts) {
7330
7433
  const previewOpts = typeof previewNameOrOpts === "object" ? previewNameOrOpts : { previewName: previewNameOrOpts };
7331
7434
  throw new Error("project.preview is not yet implemented");
@@ -7357,6 +7460,12 @@ var RootCircuit = class {
7357
7460
  }
7358
7461
  this._eventListeners[event].push(listener);
7359
7462
  }
7463
+ removeListener(event, listener) {
7464
+ if (!this._eventListeners[event]) return;
7465
+ this._eventListeners[event] = this._eventListeners[event].filter(
7466
+ (l) => l !== listener
7467
+ );
7468
+ }
7360
7469
  getClientOrigin() {
7361
7470
  if (typeof window !== "undefined") {
7362
7471
  return window.location.origin;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.339",
4
+ "version": "0.0.341",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -59,7 +59,7 @@
59
59
  "@tscircuit/props": "^0.0.159",
60
60
  "@tscircuit/schematic-autolayout": "^0.0.6",
61
61
  "@tscircuit/soup-util": "^0.0.41",
62
- "circuit-json": "^0.0.149",
62
+ "circuit-json": "^0.0.151",
63
63
  "circuit-json-to-connectivity-map": "^0.0.17",
64
64
  "format-si-unit": "^0.0.3",
65
65
  "nanoid": "^5.0.7",