@tscircuit/core 0.0.110 → 0.0.112

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
@@ -1,4 +1,4 @@
1
- import React, { ReactElement } from 'react';
1
+ import React, { ReactElement, ComponentProps } from 'react';
2
2
  import * as zod from 'zod';
3
3
  import { ZodType, z } from 'zod';
4
4
  import { SchSymbol, BaseSymbolName } from 'schematic-symbols';
@@ -4803,6 +4803,8 @@ declare const useRenderedCircuit: (reactElements: React.ReactElement) => {
4803
4803
  circuitJson?: AnyCircuitElement[];
4804
4804
  };
4805
4805
 
4806
+ declare const createUseComponent: <C extends React.ComponentType<any>, PiD extends string>(Component: C, pins: readonly PiD[]) => <T extends Omit<ComponentProps<C>, "name"> | undefined = undefined>(name: string, props?: T) => React.ComponentType<(T extends undefined ? Omit<ComponentProps<C>, "name"> : Omit<Partial<ComponentProps<C>>, "name">) & { [key in (typeof pins)[number]]?: string; }> & { [key in (typeof pins)[number]]: string; };
4807
+
4806
4808
  declare global {
4807
4809
  namespace JSX {
4808
4810
  interface IntrinsicElements {
@@ -4849,4 +4851,4 @@ declare global {
4849
4851
  }
4850
4852
  }
4851
4853
 
4852
- export { Board, Capacitor, Chip, Circuit, Constraint, Diode, FabricationNotePath, FabricationNoteText, Footprint, Group, Hole, type IRenderable, Jumper, Keepout, Led, Net, NormalComponent, PlatedHole, Port, PrimitiveComponent, Project, Renderable, Resistor, SilkscreenCircle, SilkscreenPath, SilkscreenRect, SilkscreenText, SmtPad, Trace, TraceHint, Via, useRenderedCircuit };
4854
+ export { Board, Capacitor, Chip, Circuit, Constraint, Diode, FabricationNotePath, FabricationNoteText, Footprint, Group, Hole, type IRenderable, Jumper, Keepout, Led, Net, NormalComponent, PlatedHole, Port, PrimitiveComponent, Project, Renderable, Resistor, SilkscreenCircle, SilkscreenPath, SilkscreenRect, SilkscreenText, SmtPad, Trace, TraceHint, Via, createUseComponent, useRenderedCircuit };
package/dist/index.js CHANGED
@@ -1268,6 +1268,59 @@ var Keepout = class extends PrimitiveComponent {
1268
1268
  }
1269
1269
  };
1270
1270
 
1271
+ // lib/components/primitive-components/Hole.ts
1272
+ import { holeProps } from "@tscircuit/props";
1273
+ var Hole = class extends PrimitiveComponent {
1274
+ pcb_hole_id = null;
1275
+ isPcbPrimitive = true;
1276
+ get config() {
1277
+ return {
1278
+ componentName: "Hole",
1279
+ zodProps: holeProps
1280
+ };
1281
+ }
1282
+ getPcbSize() {
1283
+ const { _parsedProps: props } = this;
1284
+ return { width: props.diameter, height: props.diameter };
1285
+ }
1286
+ doInitialPcbPrimitiveRender() {
1287
+ const { db } = this.root;
1288
+ const { _parsedProps: props } = this;
1289
+ const position = this._getGlobalPcbPositionBeforeLayout();
1290
+ const inserted_hole = db.pcb_hole.insert({
1291
+ hole_shape: "circle",
1292
+ // @ts-ignore
1293
+ hole_diameter: props.diameter,
1294
+ x: position.x,
1295
+ y: position.y
1296
+ });
1297
+ this.pcb_hole_id = inserted_hole.pcb_hole_id;
1298
+ }
1299
+ _getPcbCircuitJsonBounds() {
1300
+ const { db } = this.root;
1301
+ const hole = db.pcb_hole.get(this.pcb_hole_id);
1302
+ const size = this.getPcbSize();
1303
+ return {
1304
+ center: { x: hole.x, y: hole.y },
1305
+ bounds: {
1306
+ left: hole.x - size.width / 2,
1307
+ top: hole.y - size.height / 2,
1308
+ right: hole.x + size.width / 2,
1309
+ bottom: hole.y + size.height / 2
1310
+ },
1311
+ width: size.width,
1312
+ height: size.height
1313
+ };
1314
+ }
1315
+ _setPositionFromLayout(newCenter) {
1316
+ const { db } = this.root;
1317
+ db.pcb_hole.update(this.pcb_hole_id, {
1318
+ x: newCenter.x,
1319
+ y: newCenter.y
1320
+ });
1321
+ }
1322
+ };
1323
+
1271
1324
  // lib/utils/createComponentsFromSoup.ts
1272
1325
  var createComponentsFromSoup = (soup) => {
1273
1326
  const components = [];
@@ -1335,6 +1388,14 @@ var createComponentsFromSoup = (soup) => {
1335
1388
  height: elm.height
1336
1389
  })
1337
1390
  );
1391
+ } else if (elm.type === "pcb_hole" && elm.hole_shape === "circle") {
1392
+ components.push(
1393
+ new Hole({
1394
+ pcbX: elm.x,
1395
+ pcbY: elm.y,
1396
+ diameter: elm.hole_diameter
1397
+ })
1398
+ );
1338
1399
  }
1339
1400
  }
1340
1401
  return components;
@@ -3705,59 +3766,6 @@ var FabricationNoteText = class extends PrimitiveComponent {
3705
3766
  }
3706
3767
  };
3707
3768
 
3708
- // lib/components/primitive-components/Hole.ts
3709
- import { holeProps } from "@tscircuit/props";
3710
- var Hole = class extends PrimitiveComponent {
3711
- pcb_hole_id = null;
3712
- isPcbPrimitive = true;
3713
- get config() {
3714
- return {
3715
- componentName: "Hole",
3716
- zodProps: holeProps
3717
- };
3718
- }
3719
- getPcbSize() {
3720
- const { _parsedProps: props } = this;
3721
- return { width: props.diameter, height: props.diameter };
3722
- }
3723
- doInitialPcbPrimitiveRender() {
3724
- const { db } = this.root;
3725
- const { _parsedProps: props } = this;
3726
- const position = this._getGlobalPcbPositionBeforeLayout();
3727
- const inserted_hole = db.pcb_hole.insert({
3728
- hole_shape: "circle",
3729
- // @ts-ignore
3730
- hole_diameter: props.diameter,
3731
- x: position.x,
3732
- y: position.y
3733
- });
3734
- this.pcb_hole_id = inserted_hole.pcb_hole_id;
3735
- }
3736
- _getPcbCircuitJsonBounds() {
3737
- const { db } = this.root;
3738
- const hole = db.pcb_hole.get(this.pcb_hole_id);
3739
- const size = this.getPcbSize();
3740
- return {
3741
- center: { x: hole.x, y: hole.y },
3742
- bounds: {
3743
- left: hole.x - size.width / 2,
3744
- top: hole.y - size.height / 2,
3745
- right: hole.x + size.width / 2,
3746
- bottom: hole.y + size.height / 2
3747
- },
3748
- width: size.width,
3749
- height: size.height
3750
- };
3751
- }
3752
- _setPositionFromLayout(newCenter) {
3753
- const { db } = this.root;
3754
- db.pcb_hole.update(this.pcb_hole_id, {
3755
- x: newCenter.x,
3756
- y: newCenter.y
3757
- });
3758
- }
3759
- };
3760
-
3761
3769
  // lib/components/primitive-components/SilkscreenCircle.ts
3762
3770
  import { silkscreenCircleProps } from "@tscircuit/props";
3763
3771
  var SilkscreenCircle = class extends PrimitiveComponent {
@@ -4053,6 +4061,39 @@ var useRenderedCircuit = (reactElements) => {
4053
4061
  return { isLoading, error, circuit, circuitJson };
4054
4062
  };
4055
4063
 
4064
+ // lib/hooks/create-use-component.tsx
4065
+ import "react";
4066
+ import "zod";
4067
+ import "@tscircuit/props";
4068
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4069
+ var createUseComponent = (Component2, pins) => {
4070
+ return (name, props) => {
4071
+ const R = (props2) => {
4072
+ const combinedProps = { ...props, ...props2, name };
4073
+ const tracesToCreate = [];
4074
+ for (const portLabel of pins) {
4075
+ if (combinedProps[portLabel]) {
4076
+ const from = `.${name} > .${portLabel}`;
4077
+ const to = combinedProps[portLabel];
4078
+ tracesToCreate.push({ from, to });
4079
+ delete combinedProps[portLabel];
4080
+ }
4081
+ }
4082
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4083
+ /* @__PURE__ */ jsx(Component2, { ...combinedProps }),
4084
+ tracesToCreate.map((trace, i) => (
4085
+ // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
4086
+ /* @__PURE__ */ jsx("trace", { ...trace }, i)
4087
+ ))
4088
+ ] });
4089
+ };
4090
+ for (const port of pins) {
4091
+ R[port] = `.${name} > .${port}`;
4092
+ }
4093
+ return R;
4094
+ };
4095
+ };
4096
+
4056
4097
  // lib/register-catalogue.ts
4057
4098
  extendCatalogue(components_exports);
4058
4099
  extendCatalogue({
@@ -4089,5 +4130,6 @@ export {
4089
4130
  Trace,
4090
4131
  TraceHint,
4091
4132
  Via,
4133
+ createUseComponent,
4092
4134
  useRenderedCircuit
4093
4135
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.110",
4
+ "version": "0.0.112",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",