@tscircuit/core 0.0.1965 → 0.0.1967

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
+ _hasRenderLifecycleListeners?: boolean;
361
362
  hasEventListener?(event: RootCircuitEventName): boolean;
362
363
  emit(event: RootCircuitEventName, ...args: any[]): void;
363
364
  on(event: RootCircuitEventName, listener: (...args: any[]) => void): void;
@@ -395,7 +396,10 @@ type IRenderable = RenderPhaseFunctions & {
395
396
  runRenderCycle(): void;
396
397
  };
397
398
  declare abstract class Renderable implements IRenderable {
398
- renderPhaseStates: RenderPhaseStates;
399
+ private _phaseStatesByName?;
400
+ private readonly _phaseStatesByIndex;
401
+ get renderPhaseStates(): RenderPhaseStates;
402
+ set renderPhaseStates(states: RenderPhaseStates);
399
403
  shouldBeRemoved: boolean;
400
404
  children: IRenderable[];
401
405
  /** PCB-only SMTPads, PlatedHoles, Holes, Silkscreen elements etc. */
@@ -595,6 +599,7 @@ declare class IsolatedCircuit {
595
599
  selectOne(selector: string, opts?: {
596
600
  type?: "component" | "port";
597
601
  }): PrimitiveComponent | null;
602
+ _hasRenderLifecycleListeners: boolean;
598
603
  _eventListeners: Record<RootCircuitEventName, Array<(...args: any[]) => void>>;
599
604
  emit(event: RootCircuitEventName, ...args: any[]): void;
600
605
  hasEventListener(event: RootCircuitEventName): boolean;
package/dist/index.js CHANGED
@@ -389,6 +389,17 @@ var mergeRoutes = (routes) => {
389
389
  // lib/components/primitive-components/Net.ts
390
390
  import { netProps } from "@tscircuit/props";
391
391
 
392
+ // lib/components/base-components/PrimitiveComponent/get-construction-props-schema.ts
393
+ var constructionSchemas = /* @__PURE__ */ new WeakMap();
394
+ var getConstructionPropsSchema = (schema) => {
395
+ let constructionSchema = constructionSchemas.get(schema);
396
+ if (!constructionSchema) {
397
+ constructionSchema = "partial" in schema ? schema.partial({ name: true }) : schema;
398
+ constructionSchemas.set(schema, constructionSchema);
399
+ }
400
+ return constructionSchema;
401
+ };
402
+
392
403
  // lib/components/base-components/PrimitiveComponent/select-net-by-literal-selector.ts
393
404
  var netsBySelectorByNets = /* @__PURE__ */ new WeakMap();
394
405
  var selectNetByLiteralSelector = (nets, selector) => {
@@ -611,7 +622,21 @@ var asyncPhaseDependencies = {
611
622
  var globalRenderCounter = 0;
612
623
  var globalAsyncEffectCounter = 0;
613
624
  var Renderable = class _Renderable {
614
- renderPhaseStates;
625
+ _phaseStatesByName;
626
+ _phaseStatesByIndex;
627
+ // Build the named map once, sharing the state objects used by the render loop.
628
+ // Once exposed, use the map so callers can also replace individual entries.
629
+ get renderPhaseStates() {
630
+ return this._phaseStatesByName ??= Object.fromEntries(
631
+ orderedRenderPhases.map((phase, index) => [
632
+ phase,
633
+ this._phaseStatesByIndex[index]
634
+ ])
635
+ );
636
+ }
637
+ set renderPhaseStates(states) {
638
+ this._phaseStatesByName = states;
639
+ }
615
640
  shouldBeRemoved = false;
616
641
  children;
617
642
  /** PCB-only SMTPads, PlatedHoles, Holes, Silkscreen elements etc. */
@@ -626,19 +651,19 @@ var Renderable = class _Renderable {
626
651
  constructor(props) {
627
652
  this._renderId = `${globalRenderCounter++}`;
628
653
  this.children = [];
629
- this.renderPhaseStates = {};
630
- for (const phase of orderedRenderPhases) {
631
- this.renderPhaseStates[phase] = {
654
+ this._phaseStatesByIndex = Array.from(
655
+ { length: orderedRenderPhases.length },
656
+ () => ({
632
657
  initialized: false,
633
658
  dirty: false
634
- };
635
- }
659
+ })
660
+ );
636
661
  }
637
662
  _markDirty(phase) {
638
- this.renderPhaseStates[phase].dirty = true;
639
663
  const phaseIndex = renderPhaseIndexMap.get(phase);
640
- for (let i = phaseIndex + 1; i < orderedRenderPhases.length; i++) {
641
- this.renderPhaseStates[orderedRenderPhases[i]].dirty = true;
664
+ for (let i = phaseIndex; i < orderedRenderPhases.length; i++) {
665
+ const state = this._phaseStatesByName?.[orderedRenderPhases[i]] ?? this._phaseStatesByIndex[i];
666
+ state.dirty = true;
642
667
  }
643
668
  if (this.parent?._markDirty) {
644
669
  this.parent._markDirty(phase);
@@ -694,8 +719,9 @@ ${error.stack}`
694
719
  });
695
720
  }
696
721
  _emitRenderLifecycleEvent(phase, startOrEnd) {
697
- const granular_event_type = `renderable:renderLifecycle:${phase}:${startOrEnd}`;
698
722
  const root = this._getRootCircuit();
723
+ if (root?._hasRenderLifecycleListeners === false && !debug.enabled) return;
724
+ const granular_event_type = `renderable:renderLifecycle:${phase}:${startOrEnd}`;
699
725
  const hasListeners = root && (!root.hasEventListener || root.hasEventListener(granular_event_type) || root.hasEventListener("renderable:renderLifecycle:anyEvent"));
700
726
  if (!debug.enabled && !hasListeners) return;
701
727
  const componentDisplayName = this.getString();
@@ -775,9 +801,9 @@ ${error.stack}`
775
801
  */
776
802
  runRenderPhase(phase) {
777
803
  this._currentRenderPhase = phase;
778
- const phaseState = this.renderPhaseStates[phase];
779
- const isInitialized = phaseState.initialized;
780
- const isDirty = phaseState.dirty;
804
+ const phaseIndex = renderPhaseIndexMap.get(phase);
805
+ const phaseState = this._phaseStatesByName?.[phase] ?? this._phaseStatesByIndex[phaseIndex];
806
+ const { initialized: isInitialized, dirty: isDirty } = phaseState;
781
807
  if (!isInitialized && this.shouldBeRemoved) return;
782
808
  if (this.shouldBeRemoved && isInitialized) {
783
809
  this._emitRenderLifecycleEvent(phase, "start");
@@ -787,10 +813,12 @@ ${error.stack}`
787
813
  this._emitRenderLifecycleEvent(phase, "end");
788
814
  return;
789
815
  }
790
- const prevPhaseIndex = renderPhaseIndexMap.get(phase) - 1;
791
- if (prevPhaseIndex >= 0) {
816
+ const prevPhaseIndex = phaseIndex - 1;
817
+ if (this._asyncEffects.length > 0 && prevPhaseIndex >= 0) {
792
818
  const prevPhase = orderedRenderPhases[prevPhaseIndex];
793
- const hasIncompleteEffects = this._asyncEffects.filter((e) => e.phase === prevPhase).some((e) => !e.complete);
819
+ const hasIncompleteEffects = this._asyncEffects.some(
820
+ (e) => e.phase === prevPhase && !e.complete
821
+ );
794
822
  if (hasIncompleteEffects) return;
795
823
  }
796
824
  const deps = asyncPhaseDependencies[phase] || [];
@@ -818,7 +846,7 @@ ${error.stack}`
818
846
  }
819
847
  runRenderPhaseForChildren(phase) {
820
848
  for (const child of this.children) {
821
- if ("_isIsolatedSubcircuit" in this && this._isIsolatedSubcircuit && "doInitialRenderIsolatedSubcircuits" in this && phase === "RenderIsolatedSubcircuits") {
849
+ if (phase === "RenderIsolatedSubcircuits" && "_isIsolatedSubcircuit" in this && this._isIsolatedSubcircuit && "doInitialRenderIsolatedSubcircuits" in this) {
822
850
  continue;
823
851
  }
824
852
  child.runRenderPhaseForChildren(phase);
@@ -1575,9 +1603,7 @@ var PrimitiveComponent2 = class extends Renderable {
1575
1603
  this.childrenPendingRemoval = [];
1576
1604
  this.props = props ?? {};
1577
1605
  this.externallyAddedAliases = [];
1578
- const zodProps = "partial" in this.config.zodProps ? this.config.zodProps.partial({
1579
- name: true
1580
- }) : this.config.zodProps;
1606
+ const zodProps = getConstructionPropsSchema(this.config.zodProps);
1581
1607
  const parsePropsResult = zodProps.safeParse(props ?? {});
1582
1608
  if (parsePropsResult.success) {
1583
1609
  this._parsedProps = parsePropsResult.data;
@@ -63774,7 +63800,7 @@ function Group_getRoutingPhasePlans(group) {
63774
63800
  var package_default = {
63775
63801
  name: "@tscircuit/core",
63776
63802
  type: "module",
63777
- version: "0.0.1964",
63803
+ version: "0.0.1966",
63778
63804
  types: "dist/index.d.ts",
63779
63805
  main: "dist/index.js",
63780
63806
  module: "dist/index.js",
@@ -68640,6 +68666,7 @@ var IsolatedCircuit = class {
68640
68666
  this._guessRootComponent();
68641
68667
  return this.firstChild?.selectOne(selector, opts) ?? null;
68642
68668
  }
68669
+ _hasRenderLifecycleListeners = false;
68643
68670
  _eventListeners = {};
68644
68671
  emit(event, ...args) {
68645
68672
  if (event === "asyncEffect:start") {
@@ -68660,12 +68687,22 @@ var IsolatedCircuit = class {
68660
68687
  this._eventListeners[event] = [];
68661
68688
  }
68662
68689
  this._eventListeners[event].push(listener);
68690
+ if (event.startsWith("renderable:renderLifecycle:")) {
68691
+ this._hasRenderLifecycleListeners = true;
68692
+ }
68663
68693
  }
68664
68694
  removeListener(event, listener) {
68665
68695
  if (!this._eventListeners[event]) return;
68666
68696
  this._eventListeners[event] = this._eventListeners[event].filter(
68667
68697
  (l) => l !== listener
68668
68698
  );
68699
+ if (event.startsWith("renderable:renderLifecycle:")) {
68700
+ this._hasRenderLifecycleListeners = Object.entries(
68701
+ this._eventListeners
68702
+ ).some(
68703
+ ([eventName, listeners]) => eventName.startsWith("renderable:renderLifecycle:") && listeners.length > 0
68704
+ );
68705
+ }
68669
68706
  }
68670
68707
  enableDebug(debug13) {
68671
68708
  if (typeof debug13 === "string") {
@@ -69444,6 +69481,7 @@ var findFloatingCopper = (circuitJson, generatedStitchingViaIds = /* @__PURE__ *
69444
69481
  var Board_doInitialPcbCopperPourCleanup = (board) => {
69445
69482
  if (!board.root || board.root.pcbDisabled) return;
69446
69483
  const { db } = board.root;
69484
+ if (db.pcb_copper_pour.list().length === 0) return;
69447
69485
  const circuitJson = db.subtree({ subcircuit_id: board.subcircuit_id }).toArray();
69448
69486
  if (db.pcb_autorouting_error.list().length > 0) return;
69449
69487
  if (!circuitJson.some((element) => element.type === "pcb_copper_pour")) return;
@@ -70087,6 +70125,10 @@ var Board = class extends Group5 {
70087
70125
  const pcbDisabled = this.root?.pcbDisabled;
70088
70126
  const schematicDisabled = this.root?.schematicDisabled;
70089
70127
  const drcChecksDisabled = this.root?.platform?.drcChecksDisabled ?? this.getInheritedProperty("drcChecksDisabled");
70128
+ if (drcChecksDisabled) {
70129
+ this._drcChecksComplete = true;
70130
+ return;
70131
+ }
70090
70132
  const netlistDrcChecksDisabled = this.root?.platform?.netlistDrcChecksDisabled ?? this.getInheritedProperty("netlistDrcChecksDisabled");
70091
70133
  const pinSpecificationDrcChecksDisabled = this.getInheritedProperty(
70092
70134
  "pinSpecificationDrcChecksDisabled"
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.1965",
4
+ "version": "0.0.1967",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",