@tscircuit/core 0.0.368 → 0.0.369

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
@@ -11548,6 +11548,14 @@ declare const applySchematicEditEventsToManualEditsFile: ({ circuitJson, editEve
11548
11548
  manualEditsFile: z.infer<typeof manual_edits_file>;
11549
11549
  }) => z.infer<typeof manual_edits_file>;
11550
11550
 
11551
+ /**
11552
+ * Applies edit events directly to a CircuitJson object
11553
+ */
11554
+ declare const applyEditEvents: ({ circuitJson, editEvents, }: {
11555
+ circuitJson: CircuitJson;
11556
+ editEvents: ManualEditEvent[];
11557
+ }) => CircuitJson;
11558
+
11551
11559
  interface TscircuitElements {
11552
11560
  resistor: _tscircuit_props.ResistorProps;
11553
11561
  capacitor: _tscircuit_props.CapacitorProps;
@@ -11613,4 +11621,4 @@ declare module "react/jsx-runtime" {
11613
11621
  }
11614
11622
  }
11615
11623
 
11616
- export { type AsyncEffect, type AutorouterCompleteEvent, type AutorouterErrorEvent, type AutorouterEvent, type AutorouterProgressEvent, type AutoroutingEndEvent, type AutoroutingErrorEvent, type AutoroutingProgressEvent, type AutoroutingStartEvent, Battery, Board, Capacitor, Chip, Circuit, type ComponentWithPins, Constraint, Crystal, Diode, FabricationNotePath, FabricationNoteText, Footprint, type GenericConnectionsAndSelectorsSel, type GenericLocalAutorouter, Group, Hole, type IRenderable, Inductor, Jumper, Keepout, Led, Mosfet, Net, NetAlias, NormalComponent, type Obstacle, PinHeader, type PinLabelSpec, PlatedHole, Port, Potentiometer, PowerSource, PrimitiveComponent, Project, PushButton, type RenderPhase, type RenderPhaseFn, type RenderPhaseFunctions, type RenderPhaseStates, Renderable, Resistor, Resonator, RootCircuit, type RootCircuitEventName, type Sel, SilkscreenCircle, SilkscreenLine, SilkscreenPath, SilkscreenRect, SilkscreenText, type SimpleRouteConnection, type SimpleRouteJson, type SimplifiedPcbTrace, SmtPad, Subcircuit, Switch, Trace, TraceHint, Transistor, Via, applyEditEventsToManualEditsFile, applyPcbEditEventsToManualEditsFile, applySchematicEditEventsToManualEditsFile, createUseComponent, getPhaseTimingsFromRenderEvents, getSimpleRouteJsonFromCircuitJson, orderedRenderPhases, sel, useCapacitor, useChip, useDiode, useLed, useRenderedCircuit, useResistor };
11624
+ export { type AsyncEffect, type AutorouterCompleteEvent, type AutorouterErrorEvent, type AutorouterEvent, type AutorouterProgressEvent, type AutoroutingEndEvent, type AutoroutingErrorEvent, type AutoroutingProgressEvent, type AutoroutingStartEvent, Battery, Board, Capacitor, Chip, Circuit, type ComponentWithPins, Constraint, Crystal, Diode, FabricationNotePath, FabricationNoteText, Footprint, type GenericConnectionsAndSelectorsSel, type GenericLocalAutorouter, Group, Hole, type IRenderable, Inductor, Jumper, Keepout, Led, Mosfet, Net, NetAlias, NormalComponent, type Obstacle, PinHeader, type PinLabelSpec, PlatedHole, Port, Potentiometer, PowerSource, PrimitiveComponent, Project, PushButton, type RenderPhase, type RenderPhaseFn, type RenderPhaseFunctions, type RenderPhaseStates, Renderable, Resistor, Resonator, RootCircuit, type RootCircuitEventName, type Sel, SilkscreenCircle, SilkscreenLine, SilkscreenPath, SilkscreenRect, SilkscreenText, type SimpleRouteConnection, type SimpleRouteJson, type SimplifiedPcbTrace, SmtPad, Subcircuit, Switch, Trace, TraceHint, Transistor, Via, applyEditEvents, applyEditEventsToManualEditsFile, applyPcbEditEventsToManualEditsFile, applySchematicEditEventsToManualEditsFile, createUseComponent, getPhaseTimingsFromRenderEvents, getSimpleRouteJsonFromCircuitJson, orderedRenderPhases, sel, useCapacitor, useChip, useDiode, useLed, useRenderedCircuit, useResistor };
package/dist/index.js CHANGED
@@ -7441,7 +7441,7 @@ import { identity as identity4 } from "transformation-matrix";
7441
7441
  var package_default = {
7442
7442
  name: "@tscircuit/core",
7443
7443
  type: "module",
7444
- version: "0.0.367",
7444
+ version: "0.0.368",
7445
7445
  types: "dist/index.d.ts",
7446
7446
  main: "dist/index.js",
7447
7447
  module: "dist/index.js",
@@ -7861,6 +7861,78 @@ var sel = new Proxy(
7861
7861
  }
7862
7862
  );
7863
7863
 
7864
+ // lib/utils/edit-events/apply-edit-events-to-circuit-json.ts
7865
+ import { transformPCBElement } from "@tscircuit/soup-util";
7866
+ import { translate as translate3 } from "transformation-matrix";
7867
+
7868
+ // lib/utils/edit-events/apply-trace-hint-edit-event.ts
7869
+ import { su as su5 } from "@tscircuit/soup-util";
7870
+ var applyTraceHintEditEvent = (circuitJson, edit_event) => {
7871
+ const existingTraceHint = su5(circuitJson).pcb_trace_hint.get(
7872
+ edit_event.pcb_trace_hint_id
7873
+ );
7874
+ if (existingTraceHint) {
7875
+ circuitJson = circuitJson.map(
7876
+ (e) => e.pcb_trace_hint_id === edit_event.pcb_trace_hint_id ? {
7877
+ ...e,
7878
+ route: edit_event.route
7879
+ } : e
7880
+ );
7881
+ } else {
7882
+ const pcbPort = su5(circuitJson).pcb_port.get(edit_event.pcb_port_id);
7883
+ circuitJson = circuitJson.filter(
7884
+ (e) => !(e.type === "pcb_trace_hint" && e.pcb_port_id === edit_event.pcb_port_id)
7885
+ ).concat([
7886
+ {
7887
+ type: "pcb_trace_hint",
7888
+ pcb_trace_hint_id: edit_event.pcb_trace_hint_id,
7889
+ route: edit_event.route,
7890
+ pcb_port_id: edit_event.pcb_port_id,
7891
+ pcb_component_id: pcbPort?.pcb_component_id
7892
+ }
7893
+ ]);
7894
+ }
7895
+ return circuitJson;
7896
+ };
7897
+
7898
+ // lib/utils/edit-events/apply-edit-events-to-circuit-json.ts
7899
+ var applyEditEvents = ({
7900
+ circuitJson,
7901
+ editEvents
7902
+ }) => {
7903
+ circuitJson = JSON.parse(JSON.stringify(circuitJson));
7904
+ for (const editEvent of editEvents) {
7905
+ if (editEvent.edit_event_type === "edit_pcb_component_location") {
7906
+ const component = circuitJson.find(
7907
+ (e) => e.type === "pcb_component" && e.pcb_component_id === editEvent.pcb_component_id
7908
+ );
7909
+ const needsMovement = !component || component.center.x !== editEvent.new_center.x || component.center.y !== editEvent.new_center.y;
7910
+ if (needsMovement && editEvent.original_center) {
7911
+ const mat = translate3(
7912
+ editEvent.new_center.x - editEvent.original_center.x,
7913
+ editEvent.new_center.y - editEvent.original_center.y
7914
+ );
7915
+ circuitJson = circuitJson.map(
7916
+ (e) => e.pcb_component_id !== editEvent.pcb_component_id ? e : transformPCBElement(e, mat)
7917
+ );
7918
+ }
7919
+ } else if (editEvent.edit_event_type === "edit_schematic_component_location") {
7920
+ circuitJson = circuitJson.map((e) => {
7921
+ if (e.type === "schematic_component" && e.schematic_component_id === editEvent.schematic_component_id) {
7922
+ return {
7923
+ ...e,
7924
+ center: editEvent.new_center
7925
+ };
7926
+ }
7927
+ return e;
7928
+ });
7929
+ } else if (editEvent.edit_event_type === "edit_pcb_trace_hint") {
7930
+ circuitJson = applyTraceHintEditEvent(circuitJson, editEvent);
7931
+ }
7932
+ }
7933
+ return circuitJson;
7934
+ };
7935
+
7864
7936
  // lib/index.ts
7865
7937
  import { createElement } from "react";
7866
7938
 
@@ -7915,6 +7987,7 @@ export {
7915
7987
  TraceHint,
7916
7988
  Transistor,
7917
7989
  Via,
7990
+ applyEditEvents,
7918
7991
  applyEditEventsToManualEditsFile,
7919
7992
  applyPcbEditEventsToManualEditsFile,
7920
7993
  applySchematicEditEventsToManualEditsFile,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.368",
4
+ "version": "0.0.369",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",