@tscircuit/core 0.0.8 → 0.0.10

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.js CHANGED
@@ -133,7 +133,8 @@ function isMatchingSelector(component, selector) {
133
133
  if (classMatch) {
134
134
  return component.isMatchingNameOrAlias(classMatch[1]);
135
135
  }
136
- const [type, ...conditions] = selector.split(/(?=[#.[])/);
136
+ let [type, ...conditions] = selector.split(/(?=[#.[])/);
137
+ if (type === "pin") type = "port";
137
138
  if (type && type !== "*" && component.lowercaseComponentName !== type.toLowerCase()) {
138
139
  return false;
139
140
  }
@@ -210,7 +211,7 @@ var PrimitiveComponent = class extends Renderable {
210
211
  * components
211
212
  */
212
213
  computePcbPropsTransform() {
213
- return compose(translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0));
214
+ return translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0);
214
215
  }
215
216
  /**
216
217
  * Compute a transformation matrix combining all parent transforms for PCB
@@ -578,6 +579,7 @@ var extendCatalogue = (objects) => {
578
579
  };
579
580
 
580
581
  // lib/fiber/create-instance-from-react-element.ts
582
+ import { identity as identity2 } from "transformation-matrix";
581
583
  function prepare(object, state) {
582
584
  const instance = object;
583
585
  instance.__tsci = {
@@ -682,18 +684,24 @@ var hostConfig = {
682
684
  };
683
685
  var reconciler = ReactReconciler(hostConfig);
684
686
  var createInstanceFromReactElement = (reactElm) => {
687
+ const rootContainer = {
688
+ children: [],
689
+ props: {
690
+ name: "$root"
691
+ },
692
+ add(instance) {
693
+ instance.parent = this;
694
+ this.children.push(instance);
695
+ },
696
+ computePcbGlobalTransform() {
697
+ return identity2();
698
+ }
699
+ };
685
700
  const container = reconciler.createContainer(
686
701
  // TODO Replace with store like react-three-fiber
687
702
  // https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
688
703
  // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts#L168
689
- {
690
- props: {
691
- name: "$root"
692
- },
693
- add(instance) {
694
- instance.parent = this;
695
- }
696
- },
704
+ rootContainer,
697
705
  0,
698
706
  null,
699
707
  false,
@@ -707,7 +715,11 @@ var createInstanceFromReactElement = (reactElm) => {
707
715
  );
708
716
  reconciler.updateContainer(reactElm, container, null, () => {
709
717
  });
710
- return reconciler.getPublicRootInstance(container);
718
+ const rootInstance = reconciler.getPublicRootInstance(
719
+ container
720
+ );
721
+ if (rootInstance) return rootInstance;
722
+ return rootContainer.children[0];
711
723
  };
712
724
 
713
725
  // lib/utils/getPortFromHints.ts
@@ -1058,7 +1070,7 @@ var NormalComponent = class extends PrimitiveComponent {
1058
1070
 
1059
1071
  // lib/components/normal-components/Board.ts
1060
1072
  import { boardProps } from "@tscircuit/props";
1061
- import { identity as identity2 } from "transformation-matrix";
1073
+ import { identity as identity3 } from "transformation-matrix";
1062
1074
  var Board = class extends NormalComponent {
1063
1075
  pcb_board_id = null;
1064
1076
  get config() {
@@ -1083,7 +1095,7 @@ var Board = class extends NormalComponent {
1083
1095
  this.pcb_board_id = null;
1084
1096
  }
1085
1097
  computePcbGlobalTransform() {
1086
- return identity2();
1098
+ return identity3();
1087
1099
  }
1088
1100
  };
1089
1101
 
@@ -1574,6 +1586,7 @@ var TraceHint = class extends PrimitiveComponent {
1574
1586
 
1575
1587
  // lib/components/primitive-components/Group.ts
1576
1588
  import { groupProps } from "@tscircuit/props";
1589
+ import "transformation-matrix";
1577
1590
  var Group = class extends PrimitiveComponent {
1578
1591
  get config() {
1579
1592
  return {
@@ -1903,12 +1916,14 @@ var Chip = class extends NormalComponent {
1903
1916
  doInitialSchematicComponentRender() {
1904
1917
  const { db } = this.project;
1905
1918
  const { _parsedProps: props } = this;
1919
+ const ports = this.children.filter((child) => child instanceof Port);
1906
1920
  const pinSpacing = props.schPinSpacing ?? 0.2;
1907
1921
  const dimensions = getAllDimensionsForSchematicBox({
1908
1922
  schWidth: props.schWidth,
1909
1923
  schHeight: props.schHeight,
1910
1924
  schPinSpacing: pinSpacing,
1911
1925
  schPinStyle: props.schPinStyle,
1926
+ pinCount: ports.length,
1912
1927
  // @ts-ignore there's a subtley in the definition difference with
1913
1928
  // leftSide/rightSide/topSide/bottomSide in how the direction is defined
1914
1929
  // that doesn't really matter
@@ -1950,7 +1965,7 @@ var Chip = class extends NormalComponent {
1950
1965
  // lib/Project.ts
1951
1966
  import { su } from "@tscircuit/soup-util";
1952
1967
  import { isValidElement as isValidElement2 } from "react";
1953
- import { identity as identity3 } from "transformation-matrix";
1968
+ import { identity as identity5 } from "transformation-matrix";
1954
1969
  var Project = class {
1955
1970
  rootComponent = null;
1956
1971
  children;
@@ -2006,10 +2021,10 @@ var Project = class {
2006
2021
  return this.getSoup();
2007
2022
  }
2008
2023
  computeGlobalSchematicTransform() {
2009
- return identity3();
2024
+ return identity5();
2010
2025
  }
2011
2026
  computeGlobalPcbTransform() {
2012
- return identity3();
2027
+ return identity5();
2013
2028
  }
2014
2029
  selectAll(selector) {
2015
2030
  return this.rootComponent?.selectAll(selector) ?? [];
@@ -95,7 +95,7 @@ export abstract class PrimitiveComponent<
95
95
  */
96
96
  computePcbPropsTransform(): Matrix {
97
97
  // TODO rotations
98
- return compose(translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0))
98
+ return translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0)
99
99
  }
100
100
 
101
101
  /**
@@ -58,6 +58,8 @@ export class Chip<PinLabels extends string = never> extends NormalComponent<
58
58
  const { db } = this.project!
59
59
  const { _parsedProps: props } = this
60
60
 
61
+ const ports = this.children.filter((child) => child instanceof Port)
62
+
61
63
  const pinSpacing = props.schPinSpacing ?? 0.2
62
64
 
63
65
  const dimensions = getAllDimensionsForSchematicBox({
@@ -66,6 +68,8 @@ export class Chip<PinLabels extends string = never> extends NormalComponent<
66
68
  schPinSpacing: pinSpacing,
67
69
  schPinStyle: props.schPinStyle,
68
70
 
71
+ pinCount: ports.length,
72
+
69
73
  // @ts-ignore there's a subtley in the definition difference with
70
74
  // leftSide/rightSide/topSide/bottomSide in how the direction is defined
71
75
  // that doesn't really matter
@@ -1,5 +1,6 @@
1
1
  import { groupProps } from "@tscircuit/props"
2
2
  import { PrimitiveComponent } from "../base-components/PrimitiveComponent"
3
+ import { compose, identity } from "transformation-matrix"
3
4
 
4
5
  export class Group extends PrimitiveComponent<typeof groupProps> {
5
6
  get config() {
@@ -4,6 +4,7 @@ import { type Renderable } from "lib/components/base-components/Renderable"
4
4
  import { type NormalComponent } from "lib/components/base-components/NormalComponent"
5
5
  import type { ReactElement, ReactNode } from "react"
6
6
  import { catalogue, type Instance } from "./catalogue"
7
+ import { identity } from "transformation-matrix"
7
8
 
8
9
  export type ReactSubtree = {
9
10
  element: ReactElement // TODO rename to "reactElement"
@@ -140,18 +141,24 @@ const reconciler = ReactReconciler(hostConfig as any)
140
141
  export const createInstanceFromReactElement = (
141
142
  reactElm: React.ReactElement,
142
143
  ): NormalComponent => {
144
+ const rootContainer = {
145
+ children: [] as any[],
146
+ props: {
147
+ name: "$root",
148
+ },
149
+ add(instance: any) {
150
+ instance.parent = this
151
+ this.children.push(instance)
152
+ },
153
+ computePcbGlobalTransform() {
154
+ return identity()
155
+ },
156
+ }
143
157
  const container = reconciler.createContainer(
144
158
  // TODO Replace with store like react-three-fiber
145
159
  // https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
146
160
  // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts#L168
147
- {
148
- props: {
149
- name: "$root",
150
- },
151
- add(instance: any) {
152
- instance.parent = this
153
- },
154
- },
161
+ rootContainer,
155
162
  0,
156
163
  null,
157
164
  false,
@@ -164,5 +171,9 @@ export const createInstanceFromReactElement = (
164
171
  null,
165
172
  )
166
173
  reconciler.updateContainer(reactElm, container, null, () => {})
167
- return reconciler.getPublicRootInstance(container) as NormalComponent
174
+ const rootInstance = reconciler.getPublicRootInstance(
175
+ container,
176
+ ) as NormalComponent
177
+ if (rootInstance) return rootInstance
178
+ return rootContainer.children[0] as NormalComponent
168
179
  }
@@ -0,0 +1,12 @@
1
+ export const extendAliases = (
2
+ aliases: string[],
3
+ additionalAliases: Record<string, string[]>,
4
+ ): string[] => {
5
+ return Array.from(
6
+ new Set(
7
+ aliases.flatMap((alias) => {
8
+ return [alias, ...(additionalAliases[alias] || [])]
9
+ }),
10
+ ),
11
+ )
12
+ }
@@ -33,7 +33,9 @@ export function isMatchingSelector(
33
33
  }
34
34
 
35
35
  // Split the selector into type and conditions
36
- const [type, ...conditions] = selector.split(/(?=[#.[])/)
36
+ let [type, ...conditions] = selector.split(/(?=[#.[])/)
37
+
38
+ if (type === "pin") type = "port"
37
39
 
38
40
  // Check if the component type matches
39
41
  if (
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
5
  "types": "index.ts",
6
- "version": "0.0.8",
6
+ "version": "0.0.10",
7
7
  "main": "dist/index.js",
8
8
  "files": [
9
9
  "index.ts",