@tscircuit/core 0.0.1956 → 0.0.1958

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
@@ -358,6 +358,7 @@ interface DebugLogOutputEvent {
358
358
  }
359
359
 
360
360
  interface IIsolatedCircuit {
361
+ hasEventListener?(event: RootCircuitEventName): boolean;
361
362
  emit(event: RootCircuitEventName, ...args: any[]): void;
362
363
  on(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
363
364
  isDoneRendering(): boolean;
@@ -596,6 +597,7 @@ declare class IsolatedCircuit {
596
597
  }): PrimitiveComponent | null;
597
598
  _eventListeners: Record<RootCircuitEventName, Array<(...args: any[]) => void>>;
598
599
  emit(event: RootCircuitEventName, ...args: any[]): void;
600
+ hasEventListener(event: RootCircuitEventName): boolean;
599
601
  on(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
600
602
  removeListener(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
601
603
  enableDebug(debug: string | null | false): void;
@@ -1698,6 +1700,7 @@ interface BaseComponentConfig {
1698
1700
  }
1699
1701
  declare abstract class PrimitiveComponent<ZodProps extends ZodType = any> extends Renderable {
1700
1702
  parent: PrimitiveComponent | null;
1703
+ protected _childrenVersion: number;
1701
1704
  children: PrimitiveComponent[];
1702
1705
  childrenPendingRemoval: PrimitiveComponent[];
1703
1706
  get config(): BaseComponentConfig;
@@ -2470,6 +2473,7 @@ declare class NormalComponent<ZodProps extends z.ZodType = any, PortNames extend
2470
2473
  doInitialInitializePortsFromChildren(): void;
2471
2474
  updateInitializePortsFromChildren(): void;
2472
2475
  protected getGlobalTransformRotation(): number;
2476
+ private _footprintChildCache?;
2473
2477
  private _getFootprintMetadataForPcbComponent;
2474
2478
  protected _getPcbComponentLayer(): LayerRef;
2475
2479
  _getFootprintOriginalLayer(): LayerRef | undefined;
package/dist/index.js CHANGED
@@ -673,21 +673,23 @@ ${error.stack}`
673
673
  });
674
674
  }
675
675
  _emitRenderLifecycleEvent(phase, startOrEnd) {
676
- debug(`${phase}:${startOrEnd} ${this.getString()}`);
677
676
  const granular_event_type = `renderable:renderLifecycle:${phase}:${startOrEnd}`;
677
+ const root = this._getRootCircuit();
678
+ const hasListeners = root && (!root.hasEventListener || root.hasEventListener(granular_event_type) || root.hasEventListener("renderable:renderLifecycle:anyEvent"));
679
+ if (!debug.enabled && !hasListeners) return;
680
+ const componentDisplayName = this.getString();
681
+ if (debug.enabled) debug(`${phase}:${startOrEnd} ${componentDisplayName}`);
682
+ if (!hasListeners) return;
678
683
  const eventPayload = {
679
684
  renderId: this._renderId,
680
- componentDisplayName: this.getString(),
685
+ componentDisplayName,
681
686
  type: granular_event_type
682
687
  };
683
- const root = this._getRootCircuit();
684
- if (root) {
685
- root.emit(granular_event_type, eventPayload);
686
- root.emit("renderable:renderLifecycle:anyEvent", {
687
- ...eventPayload,
688
- type: granular_event_type
689
- });
690
- }
688
+ root.emit(granular_event_type, eventPayload);
689
+ root.emit("renderable:renderLifecycle:anyEvent", {
690
+ ...eventPayload,
691
+ type: granular_event_type
692
+ });
691
693
  }
692
694
  getString() {
693
695
  return this.constructor.name;
@@ -1453,6 +1455,7 @@ var basePrimitiveComponentConfig = {
1453
1455
  };
1454
1456
  var PrimitiveComponent2 = class extends Renderable {
1455
1457
  parent = null;
1458
+ _childrenVersion = 0;
1456
1459
  children;
1457
1460
  childrenPendingRemoval;
1458
1461
  get config() {
@@ -2181,6 +2184,7 @@ var PrimitiveComponent2 = class extends Renderable {
2181
2184
  component.onAddToParent(this);
2182
2185
  component.parent = this;
2183
2186
  this.children.push(component);
2187
+ this._childrenVersion++;
2184
2188
  this._clearSelectorCachesUpTree();
2185
2189
  }
2186
2190
  addAll(components) {
@@ -2190,6 +2194,7 @@ var PrimitiveComponent2 = class extends Renderable {
2190
2194
  }
2191
2195
  remove(component) {
2192
2196
  this.children = this.children.filter((c) => c !== component);
2197
+ this._childrenVersion++;
2193
2198
  this.childrenPendingRemoval.push(component);
2194
2199
  component.shouldBeRemoved = true;
2195
2200
  this._clearSelectorCachesUpTree();
@@ -2336,7 +2341,10 @@ var PrimitiveComponent2 = class extends Renderable {
2336
2341
  const subcircuit = selectOne(firstpart, this, {
2337
2342
  adapter: cssSelectPrimitiveComponentAdapterOnlySubcircuits
2338
2343
  });
2339
- if (!subcircuit) return [];
2344
+ if (!subcircuit) {
2345
+ this._cachedSelectAllQueries.set(selectorRaw, result);
2346
+ return result;
2347
+ }
2340
2348
  const result2 = subcircuit.selectAll(rest.join(" "));
2341
2349
  this._cachedSelectAllQueries.set(selectorRaw, result2);
2342
2350
  return result2;
@@ -16068,10 +16076,19 @@ var NormalComponent = class extends PrimitiveComponent2 {
16068
16076
  const decomposedTransform = decomposeTSR9(globalTransform);
16069
16077
  return decomposedTransform.rotation.angle * 180 / Math.PI;
16070
16078
  }
16079
+ _footprintChildCache;
16071
16080
  _getFootprintMetadataForPcbComponent() {
16072
- const footprintChild = this.children.find(
16073
- (c) => c.componentName === "Footprint"
16074
- );
16081
+ if (!this._footprintChildCache || this._footprintChildCache.children !== this.children || this._footprintChildCache.childrenVersion !== this._childrenVersion || this._footprintChildCache.childCount !== this.children.length) {
16082
+ this._footprintChildCache = {
16083
+ children: this.children,
16084
+ childrenVersion: this._childrenVersion,
16085
+ childCount: this.children.length,
16086
+ footprintChild: this.children.find(
16087
+ (c) => c.componentName === "Footprint"
16088
+ )
16089
+ };
16090
+ }
16091
+ const { footprintChild } = this._footprintChildCache;
16075
16092
  if (footprintChild) {
16076
16093
  return {
16077
16094
  insertionDirection: footprintChild._parsedProps.insertionDirection,
@@ -55792,6 +55809,7 @@ function Group_doInitialPcbCalcPlacementResolution(group) {
55792
55809
  const { db } = group.root;
55793
55810
  const normalComponentNameMap = group.getNormalComponentNameMap?.() ?? /* @__PURE__ */ new Map();
55794
55811
  const allNormalComponents = collectNormalComponentsInSubcircuit(group);
55812
+ if (!allNormalComponents.some(shouldResolvePlacementInCalcPhase)) return;
55795
55813
  const namedComponentVars = {};
55796
55814
  for (const component of allNormalComponents) {
55797
55815
  updateVarsForNamedComponent(component, namedComponentVars);
@@ -63726,7 +63744,7 @@ function Group_getRoutingPhasePlans(group) {
63726
63744
  var package_default = {
63727
63745
  name: "@tscircuit/core",
63728
63746
  type: "module",
63729
- version: "0.0.1955",
63747
+ version: "0.0.1957",
63730
63748
  types: "dist/index.d.ts",
63731
63749
  main: "dist/index.js",
63732
63750
  module: "dist/index.js",
@@ -63763,7 +63781,7 @@ var package_default = {
63763
63781
  "@tscircuit/bus-lanes-solver": "github:tscircuit/bus-lanes-solver#0bc8d071241b18a3e7465a878881abe4998f6384",
63764
63782
  "@tscircuit/capacity-autorouter": "^0.0.919",
63765
63783
  "@tscircuit/checks": "^0.0.208",
63766
- "@tscircuit/circuit-json-util": "^0.0.114",
63784
+ "@tscircuit/circuit-json-util": "^0.0.115",
63767
63785
  "@tscircuit/common": "^0.0.20",
63768
63786
  "@tscircuit/copper-pour-solver": "^0.0.56",
63769
63787
  "@tscircuit/create-fdm-enclosure": "0.0.4",
@@ -63782,7 +63800,7 @@ var package_default = {
63782
63800
  "@tscircuit/ngspice-spice-engine": "^0.0.20",
63783
63801
  "@tscircuit/props": "^0.0.664",
63784
63802
  "@tscircuit/schematic-match-adapt": "^0.0.18",
63785
- "@tscircuit/schematic-trace-solver": "^0.0.201",
63803
+ "@tscircuit/schematic-trace-solver": "^0.0.203",
63786
63804
  "@tscircuit/solver-utils": "^0.0.16",
63787
63805
  "@tscircuit/soup-util": "^0.0.41",
63788
63806
  "@tscircuit/via-stitch-solver": "github:tscircuit/via-stitch-solver#64f2ac7781b795bdc0d74ba411988e60767fa653",
@@ -63858,7 +63876,7 @@ var package_default = {
63858
63876
  zod: "^3.25.67"
63859
63877
  },
63860
63878
  overrides: {
63861
- "@tscircuit/circuit-json-util": "^0.0.114",
63879
+ "@tscircuit/circuit-json-util": "^0.0.115",
63862
63880
  "@tscircuit/props": "^0.0.664",
63863
63881
  "circuit-json": "^0.0.497"
63864
63882
  }
@@ -68346,8 +68364,21 @@ var DrcCheck = class extends PrimitiveComponent2 {
68346
68364
  }
68347
68365
  };
68348
68366
 
68367
+ // lib/utils/circuit-json/create-circuit-json-database.ts
68368
+ import * as circuitJsonUtil from "@tscircuit/circuit-json-util";
68369
+ function createCircuitJsonDatabase() {
68370
+ if (typeof circuitJsonUtil.cjuIndexed !== "function")
68371
+ return circuitJsonUtil.cju([]);
68372
+ const indexed = circuitJsonUtil.cjuIndexed([], {
68373
+ indexConfig: { byId: true, byType: true }
68374
+ });
68375
+ if (typeof indexed.insert !== "function" || typeof indexed.insertAll !== "function" || typeof indexed.subtree !== "function") {
68376
+ return circuitJsonUtil.cju([]);
68377
+ }
68378
+ return indexed;
68379
+ }
68380
+
68349
68381
  // lib/IsolatedCircuit.ts
68350
- import { su as su5 } from "@tscircuit/circuit-json-util";
68351
68382
  import Debug16 from "debug";
68352
68383
  import { isValidElement as isValidElement3 } from "react";
68353
68384
  import { identity as identity8 } from "transformation-matrix";
@@ -68412,7 +68443,7 @@ var IsolatedCircuit = class {
68412
68443
  pendingSubcircuitRenders
68413
68444
  } = {}) {
68414
68445
  this.children = [];
68415
- this.db = su5([]);
68446
+ this.db = createCircuitJsonDatabase();
68416
68447
  this.platform = platform;
68417
68448
  this.projectUrl = projectUrl;
68418
68449
  this.pcbDisabled = platform?.pcbDisabled ?? false;
@@ -68587,6 +68618,9 @@ var IsolatedCircuit = class {
68587
68618
  listener(...args);
68588
68619
  }
68589
68620
  }
68621
+ hasEventListener(event) {
68622
+ return (this._eventListeners[event]?.length ?? 0) > 0;
68623
+ }
68590
68624
  on(event, listener) {
68591
68625
  if (!this._eventListeners[event]) {
68592
68626
  this._eventListeners[event] = [];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1956",
4
+ "version": "0.0.1958",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "@tscircuit/bus-lanes-solver": "github:tscircuit/bus-lanes-solver#0bc8d071241b18a3e7465a878881abe4998f6384",
39
39
  "@tscircuit/capacity-autorouter": "^0.0.919",
40
40
  "@tscircuit/checks": "^0.0.208",
41
- "@tscircuit/circuit-json-util": "^0.0.114",
41
+ "@tscircuit/circuit-json-util": "^0.0.115",
42
42
  "@tscircuit/common": "^0.0.20",
43
43
  "@tscircuit/copper-pour-solver": "^0.0.56",
44
44
  "@tscircuit/create-fdm-enclosure": "0.0.4",
@@ -57,7 +57,7 @@
57
57
  "@tscircuit/ngspice-spice-engine": "^0.0.20",
58
58
  "@tscircuit/props": "^0.0.664",
59
59
  "@tscircuit/schematic-match-adapt": "^0.0.18",
60
- "@tscircuit/schematic-trace-solver": "^0.0.201",
60
+ "@tscircuit/schematic-trace-solver": "^0.0.203",
61
61
  "@tscircuit/solver-utils": "^0.0.16",
62
62
  "@tscircuit/soup-util": "^0.0.41",
63
63
  "@tscircuit/via-stitch-solver": "github:tscircuit/via-stitch-solver#64f2ac7781b795bdc0d74ba411988e60767fa653",
@@ -133,7 +133,7 @@
133
133
  "zod": "^3.25.67"
134
134
  },
135
135
  "overrides": {
136
- "@tscircuit/circuit-json-util": "^0.0.114",
136
+ "@tscircuit/circuit-json-util": "^0.0.115",
137
137
  "@tscircuit/props": "^0.0.664",
138
138
  "circuit-json": "^0.0.497"
139
139
  }