@tscircuit/core 0.0.7 → 0.0.9
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 +32 -15
- package/lib/components/base-components/PrimitiveComponent.ts +1 -1
- package/lib/components/normal-components/Chip.ts +4 -0
- package/lib/components/primitive-components/Group.ts +1 -0
- package/lib/fiber/create-instance-from-react-element.ts +20 -9
- package/lib/register-catalogue.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -210,7 +210,7 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
210
210
|
* components
|
|
211
211
|
*/
|
|
212
212
|
computePcbPropsTransform() {
|
|
213
|
-
return
|
|
213
|
+
return translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Compute a transformation matrix combining all parent transforms for PCB
|
|
@@ -578,6 +578,7 @@ var extendCatalogue = (objects) => {
|
|
|
578
578
|
};
|
|
579
579
|
|
|
580
580
|
// lib/fiber/create-instance-from-react-element.ts
|
|
581
|
+
import { identity as identity2 } from "transformation-matrix";
|
|
581
582
|
function prepare(object, state) {
|
|
582
583
|
const instance = object;
|
|
583
584
|
instance.__tsci = {
|
|
@@ -682,18 +683,24 @@ var hostConfig = {
|
|
|
682
683
|
};
|
|
683
684
|
var reconciler = ReactReconciler(hostConfig);
|
|
684
685
|
var createInstanceFromReactElement = (reactElm) => {
|
|
686
|
+
const rootContainer = {
|
|
687
|
+
children: [],
|
|
688
|
+
props: {
|
|
689
|
+
name: "$root"
|
|
690
|
+
},
|
|
691
|
+
add(instance) {
|
|
692
|
+
instance.parent = this;
|
|
693
|
+
this.children.push(instance);
|
|
694
|
+
},
|
|
695
|
+
computePcbGlobalTransform() {
|
|
696
|
+
return identity2();
|
|
697
|
+
}
|
|
698
|
+
};
|
|
685
699
|
const container = reconciler.createContainer(
|
|
686
700
|
// TODO Replace with store like react-three-fiber
|
|
687
701
|
// https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
|
|
688
702
|
// 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
|
-
},
|
|
703
|
+
rootContainer,
|
|
697
704
|
0,
|
|
698
705
|
null,
|
|
699
706
|
false,
|
|
@@ -707,7 +714,11 @@ var createInstanceFromReactElement = (reactElm) => {
|
|
|
707
714
|
);
|
|
708
715
|
reconciler.updateContainer(reactElm, container, null, () => {
|
|
709
716
|
});
|
|
710
|
-
|
|
717
|
+
const rootInstance = reconciler.getPublicRootInstance(
|
|
718
|
+
container
|
|
719
|
+
);
|
|
720
|
+
if (rootInstance) return rootInstance;
|
|
721
|
+
return rootContainer.children[0];
|
|
711
722
|
};
|
|
712
723
|
|
|
713
724
|
// lib/utils/getPortFromHints.ts
|
|
@@ -1058,7 +1069,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
1058
1069
|
|
|
1059
1070
|
// lib/components/normal-components/Board.ts
|
|
1060
1071
|
import { boardProps } from "@tscircuit/props";
|
|
1061
|
-
import { identity as
|
|
1072
|
+
import { identity as identity3 } from "transformation-matrix";
|
|
1062
1073
|
var Board = class extends NormalComponent {
|
|
1063
1074
|
pcb_board_id = null;
|
|
1064
1075
|
get config() {
|
|
@@ -1083,7 +1094,7 @@ var Board = class extends NormalComponent {
|
|
|
1083
1094
|
this.pcb_board_id = null;
|
|
1084
1095
|
}
|
|
1085
1096
|
computePcbGlobalTransform() {
|
|
1086
|
-
return
|
|
1097
|
+
return identity3();
|
|
1087
1098
|
}
|
|
1088
1099
|
};
|
|
1089
1100
|
|
|
@@ -1574,6 +1585,7 @@ var TraceHint = class extends PrimitiveComponent {
|
|
|
1574
1585
|
|
|
1575
1586
|
// lib/components/primitive-components/Group.ts
|
|
1576
1587
|
import { groupProps } from "@tscircuit/props";
|
|
1588
|
+
import "transformation-matrix";
|
|
1577
1589
|
var Group = class extends PrimitiveComponent {
|
|
1578
1590
|
get config() {
|
|
1579
1591
|
return {
|
|
@@ -1903,12 +1915,14 @@ var Chip = class extends NormalComponent {
|
|
|
1903
1915
|
doInitialSchematicComponentRender() {
|
|
1904
1916
|
const { db } = this.project;
|
|
1905
1917
|
const { _parsedProps: props } = this;
|
|
1918
|
+
const ports = this.children.filter((child) => child instanceof Port);
|
|
1906
1919
|
const pinSpacing = props.schPinSpacing ?? 0.2;
|
|
1907
1920
|
const dimensions = getAllDimensionsForSchematicBox({
|
|
1908
1921
|
schWidth: props.schWidth,
|
|
1909
1922
|
schHeight: props.schHeight,
|
|
1910
1923
|
schPinSpacing: pinSpacing,
|
|
1911
1924
|
schPinStyle: props.schPinStyle,
|
|
1925
|
+
pinCount: ports.length,
|
|
1912
1926
|
// @ts-ignore there's a subtley in the definition difference with
|
|
1913
1927
|
// leftSide/rightSide/topSide/bottomSide in how the direction is defined
|
|
1914
1928
|
// that doesn't really matter
|
|
@@ -1950,7 +1964,7 @@ var Chip = class extends NormalComponent {
|
|
|
1950
1964
|
// lib/Project.ts
|
|
1951
1965
|
import { su } from "@tscircuit/soup-util";
|
|
1952
1966
|
import { isValidElement as isValidElement2 } from "react";
|
|
1953
|
-
import { identity as
|
|
1967
|
+
import { identity as identity5 } from "transformation-matrix";
|
|
1954
1968
|
var Project = class {
|
|
1955
1969
|
rootComponent = null;
|
|
1956
1970
|
children;
|
|
@@ -2006,10 +2020,10 @@ var Project = class {
|
|
|
2006
2020
|
return this.getSoup();
|
|
2007
2021
|
}
|
|
2008
2022
|
computeGlobalSchematicTransform() {
|
|
2009
|
-
return
|
|
2023
|
+
return identity5();
|
|
2010
2024
|
}
|
|
2011
2025
|
computeGlobalPcbTransform() {
|
|
2012
|
-
return
|
|
2026
|
+
return identity5();
|
|
2013
2027
|
}
|
|
2014
2028
|
selectAll(selector) {
|
|
2015
2029
|
return this.rootComponent?.selectAll(selector) ?? [];
|
|
@@ -2021,6 +2035,9 @@ var Project = class {
|
|
|
2021
2035
|
|
|
2022
2036
|
// lib/register-catalogue.ts
|
|
2023
2037
|
extendCatalogue(components_exports);
|
|
2038
|
+
extendCatalogue({
|
|
2039
|
+
Bug: Chip
|
|
2040
|
+
});
|
|
2024
2041
|
export {
|
|
2025
2042
|
Board,
|
|
2026
2043
|
Capacitor,
|
|
@@ -95,7 +95,7 @@ export abstract class PrimitiveComponent<
|
|
|
95
95
|
*/
|
|
96
96
|
computePcbPropsTransform(): Matrix {
|
|
97
97
|
// TODO rotations
|
|
98
|
-
return
|
|
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
|
-
|
|
174
|
+
const rootInstance = reconciler.getPublicRootInstance(
|
|
175
|
+
container,
|
|
176
|
+
) as NormalComponent
|
|
177
|
+
if (rootInstance) return rootInstance
|
|
178
|
+
return rootContainer.children[0] as NormalComponent
|
|
168
179
|
}
|