@tscircuit/core 0.0.5 → 0.0.7
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.cjs → index.js} +837 -379
- package/package.json +3 -3
|
@@ -1,53 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
1
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
2
|
var __export = (target, all) => {
|
|
9
3
|
for (var name in all)
|
|
10
4
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
5
|
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// index.ts
|
|
31
|
-
var core_exports = {};
|
|
32
|
-
__export(core_exports, {
|
|
33
|
-
Board: () => Board,
|
|
34
|
-
Capacitor: () => Capacitor,
|
|
35
|
-
Chip: () => Chip,
|
|
36
|
-
Footprint: () => Footprint,
|
|
37
|
-
Group: () => Group,
|
|
38
|
-
Led: () => Led,
|
|
39
|
-
Net: () => Net,
|
|
40
|
-
NormalComponent: () => NormalComponent,
|
|
41
|
-
Port: () => Port,
|
|
42
|
-
PrimitiveComponent: () => PrimitiveComponent,
|
|
43
|
-
Project: () => Project,
|
|
44
|
-
Renderable: () => Renderable,
|
|
45
|
-
Resistor: () => Resistor,
|
|
46
|
-
SmtPad: () => SmtPad,
|
|
47
|
-
Trace: () => Trace,
|
|
48
|
-
TraceHint: () => TraceHint
|
|
49
|
-
});
|
|
50
|
-
module.exports = __toCommonJS(core_exports);
|
|
51
6
|
|
|
52
7
|
// lib/components/index.ts
|
|
53
8
|
var components_exports = {};
|
|
@@ -70,12 +25,12 @@ __export(components_exports, {
|
|
|
70
25
|
});
|
|
71
26
|
|
|
72
27
|
// lib/components/base-components/PrimitiveComponent.ts
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
import { symbols } from "schematic-symbols";
|
|
30
|
+
import "react";
|
|
76
31
|
|
|
77
32
|
// lib/components/base-components/Renderable.ts
|
|
78
|
-
|
|
33
|
+
import "react";
|
|
79
34
|
var orderedRenderPhases = [
|
|
80
35
|
"ReactSubtreesRender",
|
|
81
36
|
// probably going to be removed b/c subtrees should render instantly
|
|
@@ -161,15 +116,49 @@ var Renderable = class {
|
|
|
161
116
|
};
|
|
162
117
|
|
|
163
118
|
// lib/components/base-components/PrimitiveComponent.ts
|
|
164
|
-
|
|
165
|
-
|
|
119
|
+
import {
|
|
120
|
+
applyToPoint,
|
|
121
|
+
compose,
|
|
122
|
+
identity,
|
|
123
|
+
translate
|
|
124
|
+
} from "transformation-matrix";
|
|
125
|
+
|
|
126
|
+
// lib/utils/selector-matching/index.ts
|
|
127
|
+
function isMatchingSelector(component, selector) {
|
|
128
|
+
const idMatch = selector.match(/^#(\w+)/);
|
|
129
|
+
if (idMatch) {
|
|
130
|
+
return component.props.id === idMatch[1];
|
|
131
|
+
}
|
|
132
|
+
const classMatch = selector.match(/^\.(\w+)/);
|
|
133
|
+
if (classMatch) {
|
|
134
|
+
return component.isMatchingNameOrAlias(classMatch[1]);
|
|
135
|
+
}
|
|
136
|
+
const [type, ...conditions] = selector.split(/(?=[#.[])/);
|
|
137
|
+
if (type && type !== "*" && component.lowercaseComponentName !== type.toLowerCase()) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
return conditions.every((condition) => {
|
|
141
|
+
if (condition.startsWith("#")) {
|
|
142
|
+
return component.props.id === condition.slice(1);
|
|
143
|
+
}
|
|
144
|
+
if (condition.startsWith(".")) {
|
|
145
|
+
return component.isMatchingNameOrAlias(condition.slice(1));
|
|
146
|
+
}
|
|
147
|
+
const match = condition.match(/\[(\w+)=['"]?(.+?)['"]?\]/);
|
|
148
|
+
if (!match) return true;
|
|
149
|
+
const [, prop, value] = match;
|
|
150
|
+
return component.props[prop].toString() === value;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// lib/components/base-components/PrimitiveComponent.ts
|
|
166
155
|
var PrimitiveComponent = class extends Renderable {
|
|
167
156
|
parent = null;
|
|
168
157
|
children;
|
|
169
158
|
childrenPendingRemoval;
|
|
170
159
|
get config() {
|
|
171
160
|
return {
|
|
172
|
-
zodProps:
|
|
161
|
+
zodProps: z.object({}).passthrough()
|
|
173
162
|
};
|
|
174
163
|
}
|
|
175
164
|
project = null;
|
|
@@ -221,15 +210,15 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
221
210
|
* components
|
|
222
211
|
*/
|
|
223
212
|
computePcbPropsTransform() {
|
|
224
|
-
return
|
|
213
|
+
return compose(translate(this.props.pcbX ?? 0, this.props.pcbY ?? 0));
|
|
225
214
|
}
|
|
226
215
|
/**
|
|
227
216
|
* Compute a transformation matrix combining all parent transforms for PCB
|
|
228
217
|
* components
|
|
229
218
|
*/
|
|
230
219
|
computePcbGlobalTransform() {
|
|
231
|
-
return
|
|
232
|
-
this.parent?.computePcbGlobalTransform() ??
|
|
220
|
+
return compose(
|
|
221
|
+
this.parent?.computePcbGlobalTransform() ?? identity(),
|
|
233
222
|
this.computePcbPropsTransform()
|
|
234
223
|
);
|
|
235
224
|
}
|
|
@@ -238,15 +227,15 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
238
227
|
* schematic components
|
|
239
228
|
*/
|
|
240
229
|
computeSchematicPropsTransform() {
|
|
241
|
-
return
|
|
230
|
+
return compose(translate(this.props.schX ?? 0, this.props.schY ?? 0));
|
|
242
231
|
}
|
|
243
232
|
/**
|
|
244
233
|
* Compute a transformation matrix combining all parent transforms for this
|
|
245
234
|
* component
|
|
246
235
|
*/
|
|
247
236
|
computeSchematicGlobalTransform() {
|
|
248
|
-
return
|
|
249
|
-
this.parent?.computeSchematicGlobalTransform?.() ??
|
|
237
|
+
return compose(
|
|
238
|
+
this.parent?.computeSchematicGlobalTransform?.() ?? identity(),
|
|
250
239
|
this.computeSchematicPropsTransform()
|
|
251
240
|
);
|
|
252
241
|
}
|
|
@@ -258,13 +247,13 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
258
247
|
}
|
|
259
248
|
const { config } = this;
|
|
260
249
|
if (!config.schematicSymbolName) return null;
|
|
261
|
-
return
|
|
250
|
+
return symbols[`${config.schematicSymbolName}_${variant}`];
|
|
262
251
|
}
|
|
263
252
|
getGlobalPcbPosition() {
|
|
264
|
-
return
|
|
253
|
+
return applyToPoint(this.computePcbGlobalTransform(), { x: 0, y: 0 });
|
|
265
254
|
}
|
|
266
255
|
getGlobalSchematicPosition() {
|
|
267
|
-
return
|
|
256
|
+
return applyToPoint(this.computeSchematicGlobalTransform(), { x: 0, y: 0 });
|
|
268
257
|
}
|
|
269
258
|
onAddToParent(parent) {
|
|
270
259
|
this.parent = parent;
|
|
@@ -330,7 +319,7 @@ var PrimitiveComponent = class extends Renderable {
|
|
|
330
319
|
onlyDirectChildren = true;
|
|
331
320
|
} else {
|
|
332
321
|
results = results.flatMap((component) => {
|
|
333
|
-
return (onlyDirectChildren ? component.children : component.getDescendants()).filter((descendant) =>
|
|
322
|
+
return (onlyDirectChildren ? component.children : component.getDescendants()).filter((descendant) => isMatchingSelector(descendant, part));
|
|
334
323
|
});
|
|
335
324
|
onlyDirectChildren = false;
|
|
336
325
|
}
|
|
@@ -397,17 +386,28 @@ var Footprint = class extends PrimitiveComponent {
|
|
|
397
386
|
};
|
|
398
387
|
|
|
399
388
|
// lib/components/base-components/NormalComponent.ts
|
|
400
|
-
|
|
389
|
+
import "zod";
|
|
390
|
+
|
|
391
|
+
// lib/components/primitive-components/Port.ts
|
|
392
|
+
import { z as z2 } from "zod";
|
|
393
|
+
|
|
394
|
+
// lib/utils/get-relative-direction.ts
|
|
395
|
+
function getRelativeDirection(pointA, pointB) {
|
|
396
|
+
const dx = pointB.x - pointA.x;
|
|
397
|
+
const dy = pointB.y - pointA.y;
|
|
398
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
399
|
+
return dx > 0 ? "right" : "left";
|
|
400
|
+
}
|
|
401
|
+
return dy > 0 ? "down" : "up";
|
|
402
|
+
}
|
|
401
403
|
|
|
402
404
|
// lib/components/primitive-components/Port.ts
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
var
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
pinNumber: import_zod2.z.number().optional(),
|
|
410
|
-
aliases: import_zod2.z.array(import_zod2.z.string()).optional()
|
|
405
|
+
import "schematic-symbols";
|
|
406
|
+
import { applyToPoint as applyToPoint2, compose as compose2, translate as translate2 } from "transformation-matrix";
|
|
407
|
+
var portProps = z2.object({
|
|
408
|
+
name: z2.string().optional(),
|
|
409
|
+
pinNumber: z2.number().optional(),
|
|
410
|
+
aliases: z2.array(z2.string()).optional()
|
|
411
411
|
});
|
|
412
412
|
var Port = class extends PrimitiveComponent {
|
|
413
413
|
source_port_id = null;
|
|
@@ -435,7 +435,7 @@ var Port = class extends PrimitiveComponent {
|
|
|
435
435
|
}
|
|
436
436
|
getGlobalSchematicPosition() {
|
|
437
437
|
if (!this.schematicSymbolPortDef) {
|
|
438
|
-
return (
|
|
438
|
+
return applyToPoint2(this.parent.computeSchematicGlobalTransform(), {
|
|
439
439
|
x: 0,
|
|
440
440
|
y: 0
|
|
441
441
|
});
|
|
@@ -445,11 +445,11 @@ var Port = class extends PrimitiveComponent {
|
|
|
445
445
|
}
|
|
446
446
|
const symbol = this.parent?.getSchematicSymbol();
|
|
447
447
|
if (!symbol) throw new Error(`Could not find parent symbol for ${this}`);
|
|
448
|
-
const transform = (
|
|
448
|
+
const transform = compose2(
|
|
449
449
|
this.parent.computeSchematicGlobalTransform(),
|
|
450
|
-
(
|
|
450
|
+
translate2(-symbol.center.x, -symbol.center.y)
|
|
451
451
|
);
|
|
452
|
-
return (
|
|
452
|
+
return applyToPoint2(transform, this.schematicSymbolPortDef);
|
|
453
453
|
}
|
|
454
454
|
/**
|
|
455
455
|
* Smtpads and platedholes call this method to register themselves as a match
|
|
@@ -545,7 +545,7 @@ var Port = class extends PrimitiveComponent {
|
|
|
545
545
|
if (!this.parent) return;
|
|
546
546
|
const center = this.getGlobalSchematicPosition();
|
|
547
547
|
const parentCenter = this.parent?.getGlobalSchematicPosition();
|
|
548
|
-
this.facingDirection =
|
|
548
|
+
this.facingDirection = getRelativeDirection(parentCenter, center);
|
|
549
549
|
const schematic_port = db.schematic_port.insert({
|
|
550
550
|
schematic_component_id: this.parent?.schematic_component_id,
|
|
551
551
|
center,
|
|
@@ -557,12 +557,266 @@ var Port = class extends PrimitiveComponent {
|
|
|
557
557
|
};
|
|
558
558
|
|
|
559
559
|
// lib/components/base-components/NormalComponent.ts
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
560
|
+
import { symbols as symbols3 } from "schematic-symbols";
|
|
561
|
+
import { fp } from "footprinter";
|
|
562
|
+
import {
|
|
563
|
+
isValidElement as isReactElement2,
|
|
564
|
+
isValidElement
|
|
565
|
+
} from "react";
|
|
566
|
+
|
|
567
|
+
// lib/fiber/create-instance-from-react-element.ts
|
|
568
|
+
import ReactReconciler from "react-reconciler";
|
|
569
|
+
|
|
570
|
+
// lib/fiber/catalogue.ts
|
|
571
|
+
var catalogue = {};
|
|
572
|
+
var extendCatalogue = (objects) => {
|
|
573
|
+
const altKeys = Object.fromEntries(
|
|
574
|
+
Object.entries(objects).map(([key, v]) => [key.toLowerCase(), v])
|
|
575
|
+
);
|
|
576
|
+
Object.assign(catalogue, objects);
|
|
577
|
+
Object.assign(catalogue, altKeys);
|
|
578
|
+
};
|
|
579
|
+
|
|
580
|
+
// lib/fiber/create-instance-from-react-element.ts
|
|
581
|
+
function prepare(object, state) {
|
|
582
|
+
const instance = object;
|
|
583
|
+
instance.__tsci = {
|
|
584
|
+
...state
|
|
585
|
+
};
|
|
586
|
+
return object;
|
|
587
|
+
}
|
|
588
|
+
var hostConfig = {
|
|
589
|
+
supportsMutation: true,
|
|
590
|
+
createInstance(type, props) {
|
|
591
|
+
const target = catalogue[type];
|
|
592
|
+
if (!target) {
|
|
593
|
+
if (Object.keys(catalogue).length === 0) {
|
|
594
|
+
throw new Error(
|
|
595
|
+
"No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
throw new Error(
|
|
599
|
+
`Unsupported component type (not registered in @tscircuit/core catalogue): ${type}`
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
const instance = prepare(new target(props), {});
|
|
603
|
+
return instance;
|
|
604
|
+
},
|
|
605
|
+
createTextInstance() {
|
|
606
|
+
return {};
|
|
607
|
+
},
|
|
608
|
+
appendInitialChild(parentInstance, child) {
|
|
609
|
+
parentInstance.add(child);
|
|
610
|
+
},
|
|
611
|
+
appendChild(parentInstance, child) {
|
|
612
|
+
parentInstance.add(child);
|
|
613
|
+
},
|
|
614
|
+
appendChildToContainer(container, child) {
|
|
615
|
+
container.add(child);
|
|
616
|
+
},
|
|
617
|
+
finalizeInitialChildren() {
|
|
618
|
+
return false;
|
|
619
|
+
},
|
|
620
|
+
prepareUpdate() {
|
|
621
|
+
return null;
|
|
622
|
+
},
|
|
623
|
+
shouldSetTextContent() {
|
|
624
|
+
return false;
|
|
625
|
+
},
|
|
626
|
+
getRootHostContext() {
|
|
627
|
+
return {};
|
|
628
|
+
},
|
|
629
|
+
getChildHostContext() {
|
|
630
|
+
return {};
|
|
631
|
+
},
|
|
632
|
+
prepareForCommit() {
|
|
633
|
+
return null;
|
|
634
|
+
},
|
|
635
|
+
resetAfterCommit() {
|
|
636
|
+
},
|
|
637
|
+
commitMount() {
|
|
638
|
+
},
|
|
639
|
+
commitUpdate() {
|
|
640
|
+
},
|
|
641
|
+
removeChild() {
|
|
642
|
+
},
|
|
643
|
+
clearContainer() {
|
|
644
|
+
},
|
|
645
|
+
supportsPersistence: false,
|
|
646
|
+
getPublicInstance(instance) {
|
|
647
|
+
return instance;
|
|
648
|
+
},
|
|
649
|
+
preparePortalMount(containerInfo) {
|
|
650
|
+
throw new Error("Function not implemented.");
|
|
651
|
+
},
|
|
652
|
+
scheduleTimeout(fn, delay) {
|
|
653
|
+
throw new Error("Function not implemented.");
|
|
654
|
+
},
|
|
655
|
+
cancelTimeout(id) {
|
|
656
|
+
throw new Error("Function not implemented.");
|
|
657
|
+
},
|
|
658
|
+
noTimeout: void 0,
|
|
659
|
+
isPrimaryRenderer: false,
|
|
660
|
+
getCurrentEventPriority() {
|
|
661
|
+
throw new Error("Function not implemented.");
|
|
662
|
+
},
|
|
663
|
+
getInstanceFromNode(node) {
|
|
664
|
+
throw new Error("Function not implemented.");
|
|
665
|
+
},
|
|
666
|
+
beforeActiveInstanceBlur() {
|
|
667
|
+
throw new Error("Function not implemented.");
|
|
668
|
+
},
|
|
669
|
+
afterActiveInstanceBlur() {
|
|
670
|
+
throw new Error("Function not implemented.");
|
|
671
|
+
},
|
|
672
|
+
prepareScopeUpdate: (scopeInstance, instance) => {
|
|
673
|
+
throw new Error("Function not implemented.");
|
|
674
|
+
},
|
|
675
|
+
getInstanceFromScope: (scopeInstance) => {
|
|
676
|
+
throw new Error("Function not implemented.");
|
|
677
|
+
},
|
|
678
|
+
detachDeletedInstance: (node) => {
|
|
679
|
+
throw new Error("Function not implemented.");
|
|
680
|
+
},
|
|
681
|
+
supportsHydration: false
|
|
682
|
+
};
|
|
683
|
+
var reconciler = ReactReconciler(hostConfig);
|
|
684
|
+
var createInstanceFromReactElement = (reactElm) => {
|
|
685
|
+
const container = reconciler.createContainer(
|
|
686
|
+
// TODO Replace with store like react-three-fiber
|
|
687
|
+
// https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
|
|
688
|
+
// 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
|
+
},
|
|
697
|
+
0,
|
|
698
|
+
null,
|
|
699
|
+
false,
|
|
700
|
+
null,
|
|
701
|
+
"tsci",
|
|
702
|
+
(error) => {
|
|
703
|
+
console.log("Error in createContainer");
|
|
704
|
+
console.error(error);
|
|
705
|
+
},
|
|
706
|
+
null
|
|
707
|
+
);
|
|
708
|
+
reconciler.updateContainer(reactElm, container, null, () => {
|
|
709
|
+
});
|
|
710
|
+
return reconciler.getPublicRootInstance(container);
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
// lib/utils/getPortFromHints.ts
|
|
714
|
+
function getPortFromHints(hints) {
|
|
715
|
+
const pinNumber = hints.find((p) => /^(pin)?\d+$/.test(p));
|
|
716
|
+
if (!pinNumber) return null;
|
|
717
|
+
return new Port({
|
|
718
|
+
pinNumber: Number.parseInt(pinNumber.replace(/^pin/, "")),
|
|
719
|
+
aliases: hints.filter((p) => p !== pinNumber)
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// lib/components/primitive-components/SmtPad.ts
|
|
724
|
+
import { smtPadProps } from "@tscircuit/props";
|
|
725
|
+
var SmtPad = class extends PrimitiveComponent {
|
|
726
|
+
pcb_smtpad_id = null;
|
|
727
|
+
matchedPort = null;
|
|
728
|
+
isPcbPrimitive = true;
|
|
729
|
+
get config() {
|
|
730
|
+
return {
|
|
731
|
+
zodProps: smtPadProps
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
doInitialPortMatching() {
|
|
735
|
+
const parentPorts = (this.parent?.children ?? []).filter(
|
|
736
|
+
(c) => c.componentName === "Port"
|
|
737
|
+
);
|
|
738
|
+
if (!this.props.portHints) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
for (const port of parentPorts) {
|
|
742
|
+
if (port.isMatchingAnyOf(this.props.portHints)) {
|
|
743
|
+
this.matchedPort = port;
|
|
744
|
+
port.registerMatch(this);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
doInitialPcbPrimitiveRender() {
|
|
750
|
+
const { db } = this.project;
|
|
751
|
+
const { _parsedProps: props } = this;
|
|
752
|
+
if (!props.portHints) return;
|
|
753
|
+
const position = this.getGlobalPcbPosition();
|
|
754
|
+
let pcb_smtpad = null;
|
|
755
|
+
if (props.shape === "circle") {
|
|
756
|
+
pcb_smtpad = db.pcb_smtpad.insert({
|
|
757
|
+
pcb_component_id: this.parent?.pcb_component_id,
|
|
758
|
+
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
759
|
+
layer: props.layer ?? "top",
|
|
760
|
+
shape: "circle",
|
|
761
|
+
// @ts-ignore: no idea why this is triggering
|
|
762
|
+
radius: props.radius,
|
|
763
|
+
port_hints: props.portHints.map((ph) => ph.toString()),
|
|
764
|
+
x: position.x,
|
|
765
|
+
y: position.y
|
|
766
|
+
});
|
|
767
|
+
} else if (props.shape === "rect") {
|
|
768
|
+
pcb_smtpad = db.pcb_smtpad.insert({
|
|
769
|
+
pcb_component_id: this.parent?.pcb_component_id,
|
|
770
|
+
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
771
|
+
layer: props.layer ?? "top",
|
|
772
|
+
shape: "rect",
|
|
773
|
+
// @ts-ignore: no idea why this is triggering
|
|
774
|
+
width: props.width,
|
|
775
|
+
height: props.height,
|
|
776
|
+
port_hints: props.portHints.map((ph) => ph.toString()),
|
|
777
|
+
x: position.x,
|
|
778
|
+
y: position.y
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
if (pcb_smtpad) {
|
|
782
|
+
this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// lib/utils/createComponentsFromSoup.ts
|
|
788
|
+
var createComponentsFromSoup = (soup) => {
|
|
789
|
+
const components = [];
|
|
790
|
+
for (const elm of soup) {
|
|
791
|
+
if (elm.type === "pcb_smtpad" && elm.shape === "rect") {
|
|
792
|
+
components.push(
|
|
793
|
+
new SmtPad({
|
|
794
|
+
pcbX: elm.x,
|
|
795
|
+
pcbY: elm.y,
|
|
796
|
+
layer: elm.layer,
|
|
797
|
+
shape: "rect",
|
|
798
|
+
height: elm.height,
|
|
799
|
+
width: elm.width,
|
|
800
|
+
portHints: elm.port_hints
|
|
801
|
+
})
|
|
802
|
+
);
|
|
803
|
+
} else if (elm.type === "pcb_smtpad" && elm.shape === "circle") {
|
|
804
|
+
components.push(
|
|
805
|
+
new SmtPad({
|
|
806
|
+
pcbX: elm.x,
|
|
807
|
+
pcbY: elm.y,
|
|
808
|
+
layer: elm.layer,
|
|
809
|
+
shape: "circle",
|
|
810
|
+
radius: elm.radius,
|
|
811
|
+
portHints: elm.port_hints
|
|
812
|
+
})
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return components;
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
// lib/components/base-components/NormalComponent.ts
|
|
566
820
|
var NormalComponent = class extends PrimitiveComponent {
|
|
567
821
|
reactSubtrees = [];
|
|
568
822
|
constructor(props) {
|
|
@@ -587,10 +841,10 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
587
841
|
initPorts() {
|
|
588
842
|
const { config } = this;
|
|
589
843
|
if (config.schematicSymbolName) {
|
|
590
|
-
const sym =
|
|
844
|
+
const sym = symbols3[`${config.schematicSymbolName}_horz`];
|
|
591
845
|
if (!sym) return;
|
|
592
846
|
for (const symPort of sym.ports) {
|
|
593
|
-
const port =
|
|
847
|
+
const port = getPortFromHints(symPort.labels);
|
|
594
848
|
if (port) {
|
|
595
849
|
port.schematicSymbolPortDef = symPort;
|
|
596
850
|
this.add(port);
|
|
@@ -605,8 +859,8 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
605
859
|
const { footprint } = this.props;
|
|
606
860
|
if (!footprint) return;
|
|
607
861
|
if (typeof footprint === "string") {
|
|
608
|
-
const fpSoup =
|
|
609
|
-
const fpComponents =
|
|
862
|
+
const fpSoup = fp.string(footprint).soup();
|
|
863
|
+
const fpComponents = createComponentsFromSoup(fpSoup);
|
|
610
864
|
this.addAll(fpComponents);
|
|
611
865
|
}
|
|
612
866
|
}
|
|
@@ -658,11 +912,11 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
658
912
|
const { schematicSymbolName } = this.config;
|
|
659
913
|
if (!schematicSymbolName) return;
|
|
660
914
|
const symbol_name = `${this.config.schematicSymbolName}_horz`;
|
|
661
|
-
const symbol =
|
|
915
|
+
const symbol = symbols3[symbol_name];
|
|
662
916
|
if (!symbol) {
|
|
663
917
|
throw new Error(`Could not find schematic-symbol "${symbol_name}"`);
|
|
664
918
|
}
|
|
665
|
-
const
|
|
919
|
+
const schematic_component2 = db.schematic_component.insert({
|
|
666
920
|
center: { x: this.props.schX ?? 0, y: this.props.schY ?? 0 },
|
|
667
921
|
rotation: this.props.schRotation ?? 0,
|
|
668
922
|
size: symbol.size,
|
|
@@ -670,7 +924,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
670
924
|
// @ts-ignore
|
|
671
925
|
symbol_name
|
|
672
926
|
});
|
|
673
|
-
this.schematic_component_id =
|
|
927
|
+
this.schematic_component_id = schematic_component2.schematic_component_id;
|
|
674
928
|
}
|
|
675
929
|
doInitialPcbComponentRender() {
|
|
676
930
|
const { db } = this.project;
|
|
@@ -693,11 +947,11 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
693
947
|
_renderReactSubtree(element) {
|
|
694
948
|
return {
|
|
695
949
|
element,
|
|
696
|
-
component:
|
|
950
|
+
component: createInstanceFromReactElement(element)
|
|
697
951
|
};
|
|
698
952
|
}
|
|
699
953
|
doInitialReactSubtreesRender() {
|
|
700
|
-
if ((
|
|
954
|
+
if (isReactElement2(this.props.footprint)) {
|
|
701
955
|
if (this.reactSubtrees.some((rs) => rs.element === this.props.footprint))
|
|
702
956
|
return;
|
|
703
957
|
const subtree = this._renderReactSubtree(this.props.footprint);
|
|
@@ -707,7 +961,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
707
961
|
}
|
|
708
962
|
add(componentOrElm) {
|
|
709
963
|
let component;
|
|
710
|
-
if ((
|
|
964
|
+
if (isReactElement2(componentOrElm)) {
|
|
711
965
|
const subtree = this._renderReactSubtree(componentOrElm);
|
|
712
966
|
this.reactSubtrees.push(subtree);
|
|
713
967
|
component = subtree.component;
|
|
@@ -718,26 +972,26 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
718
972
|
}
|
|
719
973
|
getPortsFromFootprint() {
|
|
720
974
|
let { footprint } = this.props;
|
|
721
|
-
if (!footprint ||
|
|
975
|
+
if (!footprint || isValidElement(footprint)) {
|
|
722
976
|
footprint = this.children.find((c) => c.componentName === "Footprint");
|
|
723
977
|
}
|
|
724
978
|
if (typeof footprint === "string") {
|
|
725
|
-
const fpSoup =
|
|
979
|
+
const fpSoup = fp.string(footprint).soup();
|
|
726
980
|
const newPorts2 = [];
|
|
727
981
|
for (const elm of fpSoup) {
|
|
728
982
|
if ("port_hints" in elm && elm.port_hints) {
|
|
729
|
-
const newPort =
|
|
983
|
+
const newPort = getPortFromHints(elm.port_hints);
|
|
730
984
|
if (!newPort) continue;
|
|
731
985
|
newPorts2.push(newPort);
|
|
732
986
|
}
|
|
733
987
|
}
|
|
734
988
|
return newPorts2;
|
|
735
989
|
}
|
|
736
|
-
if (!
|
|
990
|
+
if (!isValidElement(footprint) && footprint && footprint.componentName === "Footprint") {
|
|
737
991
|
const fp2 = footprint;
|
|
738
992
|
const newPorts2 = [];
|
|
739
993
|
for (const fpChild of fp2.children) {
|
|
740
|
-
const newPort =
|
|
994
|
+
const newPort = getPortFromHints(fpChild.props.portHints ?? []);
|
|
741
995
|
if (!newPort) continue;
|
|
742
996
|
newPorts2.push(newPort);
|
|
743
997
|
}
|
|
@@ -747,7 +1001,7 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
747
1001
|
if (!footprint) {
|
|
748
1002
|
for (const child of this.children) {
|
|
749
1003
|
if (child.props.portHints && child.isPcbPrimitive) {
|
|
750
|
-
const port =
|
|
1004
|
+
const port = getPortFromHints(child.props.portHints);
|
|
751
1005
|
if (port) newPorts.push(port);
|
|
752
1006
|
}
|
|
753
1007
|
}
|
|
@@ -757,11 +1011,11 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
757
1011
|
getPortsFromSchematicSymbol() {
|
|
758
1012
|
const { config } = this;
|
|
759
1013
|
if (!config.schematicSymbolName) return [];
|
|
760
|
-
const symbol =
|
|
1014
|
+
const symbol = symbols3[config.schematicSymbolName];
|
|
761
1015
|
if (!symbol) return [];
|
|
762
1016
|
const newPorts = [];
|
|
763
1017
|
for (const symbolPort of symbol.ports) {
|
|
764
|
-
const port =
|
|
1018
|
+
const port = getPortFromHints(symbolPort.labels);
|
|
765
1019
|
if (port) {
|
|
766
1020
|
port.schematicSymbolPortDef = symbolPort;
|
|
767
1021
|
newPorts.push(port);
|
|
@@ -803,13 +1057,13 @@ var NormalComponent = class extends PrimitiveComponent {
|
|
|
803
1057
|
};
|
|
804
1058
|
|
|
805
1059
|
// lib/components/normal-components/Board.ts
|
|
806
|
-
|
|
807
|
-
|
|
1060
|
+
import { boardProps } from "@tscircuit/props";
|
|
1061
|
+
import { identity as identity2 } from "transformation-matrix";
|
|
808
1062
|
var Board = class extends NormalComponent {
|
|
809
1063
|
pcb_board_id = null;
|
|
810
1064
|
get config() {
|
|
811
1065
|
return {
|
|
812
|
-
zodProps:
|
|
1066
|
+
zodProps: boardProps
|
|
813
1067
|
};
|
|
814
1068
|
}
|
|
815
1069
|
doInitialPcbComponentRender() {
|
|
@@ -829,81 +1083,17 @@ var Board = class extends NormalComponent {
|
|
|
829
1083
|
this.pcb_board_id = null;
|
|
830
1084
|
}
|
|
831
1085
|
computePcbGlobalTransform() {
|
|
832
|
-
return (
|
|
1086
|
+
return identity2();
|
|
833
1087
|
}
|
|
834
1088
|
};
|
|
835
1089
|
|
|
836
|
-
// lib/components/
|
|
837
|
-
|
|
838
|
-
var
|
|
839
|
-
pcb_smtpad_id = null;
|
|
840
|
-
matchedPort = null;
|
|
841
|
-
isPcbPrimitive = true;
|
|
842
|
-
get config() {
|
|
843
|
-
return {
|
|
844
|
-
zodProps: import_props2.smtPadProps
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
doInitialPortMatching() {
|
|
848
|
-
const parentPorts = (this.parent?.children ?? []).filter(
|
|
849
|
-
(c) => c.componentName === "Port"
|
|
850
|
-
);
|
|
851
|
-
if (!this.props.portHints) {
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
for (const port of parentPorts) {
|
|
855
|
-
if (port.isMatchingAnyOf(this.props.portHints)) {
|
|
856
|
-
this.matchedPort = port;
|
|
857
|
-
port.registerMatch(this);
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
doInitialPcbPrimitiveRender() {
|
|
863
|
-
const { db } = this.project;
|
|
864
|
-
const { _parsedProps: props } = this;
|
|
865
|
-
if (!props.portHints) return;
|
|
866
|
-
const position = this.getGlobalPcbPosition();
|
|
867
|
-
let pcb_smtpad = null;
|
|
868
|
-
if (props.shape === "circle") {
|
|
869
|
-
pcb_smtpad = db.pcb_smtpad.insert({
|
|
870
|
-
pcb_component_id: this.parent?.pcb_component_id,
|
|
871
|
-
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
872
|
-
layer: props.layer ?? "top",
|
|
873
|
-
shape: "circle",
|
|
874
|
-
// @ts-ignore: no idea why this is triggering
|
|
875
|
-
radius: props.radius,
|
|
876
|
-
port_hints: props.portHints.map((ph) => ph.toString()),
|
|
877
|
-
x: position.x,
|
|
878
|
-
y: position.y
|
|
879
|
-
});
|
|
880
|
-
} else if (props.shape === "rect") {
|
|
881
|
-
pcb_smtpad = db.pcb_smtpad.insert({
|
|
882
|
-
pcb_component_id: this.parent?.pcb_component_id,
|
|
883
|
-
pcb_port_id: this.matchedPort?.pcb_port_id,
|
|
884
|
-
layer: props.layer ?? "top",
|
|
885
|
-
shape: "rect",
|
|
886
|
-
// @ts-ignore: no idea why this is triggering
|
|
887
|
-
width: props.width,
|
|
888
|
-
height: props.height,
|
|
889
|
-
port_hints: props.portHints.map((ph) => ph.toString()),
|
|
890
|
-
x: position.x,
|
|
891
|
-
y: position.y
|
|
892
|
-
});
|
|
893
|
-
}
|
|
894
|
-
if (pcb_smtpad) {
|
|
895
|
-
this.pcb_smtpad_id = pcb_smtpad.pcb_smtpad_id;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
|
|
900
|
-
// lib/components/normal-components/Resistor.ts
|
|
901
|
-
var import_props3 = require("@tscircuit/props");
|
|
902
|
-
var Resistor = class extends NormalComponent {
|
|
1090
|
+
// lib/components/normal-components/Resistor.ts
|
|
1091
|
+
import { resistorProps } from "@tscircuit/props";
|
|
1092
|
+
var Resistor = class extends NormalComponent {
|
|
903
1093
|
get config() {
|
|
904
1094
|
return {
|
|
905
1095
|
schematicSymbolName: "boxresistor",
|
|
906
|
-
zodProps:
|
|
1096
|
+
zodProps: resistorProps,
|
|
907
1097
|
sourceFtype: "simple_resistor"
|
|
908
1098
|
};
|
|
909
1099
|
}
|
|
@@ -912,12 +1102,12 @@ var Resistor = class extends NormalComponent {
|
|
|
912
1102
|
};
|
|
913
1103
|
|
|
914
1104
|
// lib/components/normal-components/Led.ts
|
|
915
|
-
|
|
1105
|
+
import { ledProps } from "@tscircuit/props";
|
|
916
1106
|
var Led = class extends NormalComponent {
|
|
917
1107
|
get config() {
|
|
918
1108
|
return {
|
|
919
1109
|
schematicSymbolName: "led",
|
|
920
|
-
zodProps:
|
|
1110
|
+
zodProps: ledProps,
|
|
921
1111
|
sourceFtype: "simple_diode"
|
|
922
1112
|
};
|
|
923
1113
|
}
|
|
@@ -930,22 +1120,32 @@ var Led = class extends NormalComponent {
|
|
|
930
1120
|
};
|
|
931
1121
|
|
|
932
1122
|
// lib/components/normal-components/Capacitor.ts
|
|
933
|
-
|
|
934
|
-
|
|
1123
|
+
import { ledProps as ledProps2 } from "@tscircuit/props";
|
|
1124
|
+
|
|
1125
|
+
// lib/utils/constants.ts
|
|
1126
|
+
var stringProxy = new Proxy(
|
|
1127
|
+
{},
|
|
1128
|
+
{
|
|
1129
|
+
get: (target, prop) => prop
|
|
1130
|
+
}
|
|
1131
|
+
);
|
|
1132
|
+
var FTYPE = stringProxy;
|
|
1133
|
+
|
|
1134
|
+
// lib/components/normal-components/Capacitor.ts
|
|
935
1135
|
var Capacitor = class extends PrimitiveComponent {
|
|
936
1136
|
get config() {
|
|
937
1137
|
return {
|
|
938
1138
|
// schematicSymbolName: BASE_SYMBOLS.capacitor,
|
|
939
|
-
zodProps:
|
|
940
|
-
sourceFtype:
|
|
1139
|
+
zodProps: ledProps2,
|
|
1140
|
+
sourceFtype: FTYPE.simple_capacitor
|
|
941
1141
|
};
|
|
942
1142
|
}
|
|
943
1143
|
};
|
|
944
1144
|
|
|
945
1145
|
// lib/components/primitive-components/Net.ts
|
|
946
|
-
|
|
947
|
-
var netProps =
|
|
948
|
-
name:
|
|
1146
|
+
import { z as z4 } from "zod";
|
|
1147
|
+
var netProps = z4.object({
|
|
1148
|
+
name: z4.string()
|
|
949
1149
|
});
|
|
950
1150
|
var Net = class extends PrimitiveComponent {
|
|
951
1151
|
getPortSelector() {
|
|
@@ -954,13 +1154,145 @@ var Net = class extends PrimitiveComponent {
|
|
|
954
1154
|
};
|
|
955
1155
|
|
|
956
1156
|
// lib/components/primitive-components/Trace.ts
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
1157
|
+
import { traceProps } from "@tscircuit/props";
|
|
1158
|
+
import {
|
|
1159
|
+
IJumpAutorouter,
|
|
1160
|
+
autoroute,
|
|
1161
|
+
getObstaclesFromSoup,
|
|
1162
|
+
markObstaclesAsConnected
|
|
1163
|
+
} from "@tscircuit/infgrid-ijump-astar";
|
|
1164
|
+
|
|
1165
|
+
// lib/utils/autorouting/computeObstacleBounds.ts
|
|
1166
|
+
var computeObstacleBounds = (obstacles) => {
|
|
1167
|
+
const minX = Math.min(...obstacles.map((o) => o.center.x));
|
|
1168
|
+
const maxX = Math.max(...obstacles.map((o) => o.center.x));
|
|
1169
|
+
const minY = Math.min(...obstacles.map((o) => o.center.y));
|
|
1170
|
+
const maxY = Math.max(...obstacles.map((o) => o.center.y));
|
|
1171
|
+
return { minX, maxX, minY, maxY };
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
// lib/utils/projectPointInDirection.ts
|
|
1175
|
+
var projectPointInDirection = (point, direction, distance) => {
|
|
1176
|
+
switch (direction) {
|
|
1177
|
+
case "up":
|
|
1178
|
+
return { x: point.x, y: point.y - distance };
|
|
1179
|
+
case "down":
|
|
1180
|
+
return { x: point.x, y: point.y + distance };
|
|
1181
|
+
case "left":
|
|
1182
|
+
return { x: point.x - distance, y: point.y };
|
|
1183
|
+
case "right":
|
|
1184
|
+
return { x: point.x + distance, y: point.y };
|
|
1185
|
+
default:
|
|
1186
|
+
throw new Error(`Unknown direction "${direction}"`);
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1190
|
+
// lib/utils/autorouting/findPossibleTraceLayerCombinations.ts
|
|
1191
|
+
var LAYER_SELECTION_PREFERENCE = ["top", "bottom", "inner1", "inner2"];
|
|
1192
|
+
var findPossibleTraceLayerCombinations = (hints, layer_path = []) => {
|
|
1193
|
+
const candidates = [];
|
|
1194
|
+
if (layer_path.length === 0) {
|
|
1195
|
+
const starting_layers = hints[0].layers;
|
|
1196
|
+
for (const layer of starting_layers) {
|
|
1197
|
+
candidates.push(
|
|
1198
|
+
...findPossibleTraceLayerCombinations(hints.slice(1), [layer])
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
return candidates;
|
|
1202
|
+
}
|
|
1203
|
+
if (hints.length === 0) return [];
|
|
1204
|
+
const current_hint = hints[0];
|
|
1205
|
+
const is_possibly_via = current_hint.via || current_hint.optional_via;
|
|
1206
|
+
const last_layer = layer_path[layer_path.length - 1];
|
|
1207
|
+
if (hints.length === 1) {
|
|
1208
|
+
const last_hint = current_hint;
|
|
1209
|
+
if (last_hint.layers && is_possibly_via) {
|
|
1210
|
+
return last_hint.layers.map((layer) => ({
|
|
1211
|
+
layer_path: [...layer_path, layer]
|
|
1212
|
+
}));
|
|
1213
|
+
}
|
|
1214
|
+
if (last_hint.layers?.includes(last_layer)) {
|
|
1215
|
+
return [{ layer_path: [...layer_path, last_layer] }];
|
|
1216
|
+
}
|
|
1217
|
+
return [];
|
|
1218
|
+
}
|
|
1219
|
+
if (!is_possibly_via) {
|
|
1220
|
+
if (current_hint.layers) {
|
|
1221
|
+
if (!current_hint.layers.includes(last_layer)) {
|
|
1222
|
+
return [];
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return findPossibleTraceLayerCombinations(
|
|
1226
|
+
hints.slice(1),
|
|
1227
|
+
layer_path.concat([last_layer])
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
const candidate_next_layers = (current_hint.optional_via ? LAYER_SELECTION_PREFERENCE : LAYER_SELECTION_PREFERENCE.filter((layer) => layer !== last_layer)).filter(
|
|
1231
|
+
(layer) => !current_hint.layers || current_hint.layers?.includes(layer)
|
|
1232
|
+
);
|
|
1233
|
+
for (const candidate_next_layer of candidate_next_layers) {
|
|
1234
|
+
candidates.push(
|
|
1235
|
+
...findPossibleTraceLayerCombinations(
|
|
1236
|
+
hints.slice(1),
|
|
1237
|
+
layer_path.concat(candidate_next_layer)
|
|
1238
|
+
)
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
return candidates;
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
// lib/utils/pairs.ts
|
|
1245
|
+
function pairs(arr) {
|
|
1246
|
+
const result = [];
|
|
1247
|
+
for (let i = 0; i < arr.length - 1; i++) {
|
|
1248
|
+
result.push([arr[i], arr[i + 1]]);
|
|
1249
|
+
}
|
|
1250
|
+
return result;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// lib/utils/autorouting/mergeRoutes.ts
|
|
1254
|
+
function pdist(a, b) {
|
|
1255
|
+
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
1256
|
+
}
|
|
1257
|
+
var mergeRoutes = (routes) => {
|
|
1258
|
+
if (routes.some((r) => r.length === 0)) {
|
|
1259
|
+
throw new Error("Cannot merge routes with zero length");
|
|
1260
|
+
}
|
|
1261
|
+
const merged = [];
|
|
1262
|
+
const first_route_fp = routes[0][0];
|
|
1263
|
+
const first_route_lp = routes[0][routes[0].length - 1];
|
|
1264
|
+
const second_route_fp = routes[1][0];
|
|
1265
|
+
const second_route_lp = routes[1][routes[1].length - 1];
|
|
1266
|
+
const best_reverse_dist = Math.min(
|
|
1267
|
+
pdist(first_route_fp, second_route_fp),
|
|
1268
|
+
pdist(first_route_fp, second_route_lp)
|
|
1269
|
+
);
|
|
1270
|
+
const best_normal_dist = Math.min(
|
|
1271
|
+
pdist(first_route_lp, second_route_fp),
|
|
1272
|
+
pdist(first_route_lp, second_route_lp)
|
|
1273
|
+
);
|
|
1274
|
+
if (best_reverse_dist < best_normal_dist) {
|
|
1275
|
+
merged.push(...routes[0].reverse());
|
|
1276
|
+
} else {
|
|
1277
|
+
merged.push(...routes[0]);
|
|
1278
|
+
}
|
|
1279
|
+
for (let i = 1; i < routes.length; i++) {
|
|
1280
|
+
const last_merged_point = merged[merged.length - 1];
|
|
1281
|
+
const next_route = routes[i];
|
|
1282
|
+
const next_first_point = next_route[0];
|
|
1283
|
+
const next_last_point = next_route[next_route.length - 1];
|
|
1284
|
+
const distance_to_first = pdist(last_merged_point, next_first_point);
|
|
1285
|
+
const distance_to_last = pdist(last_merged_point, next_last_point);
|
|
1286
|
+
if (distance_to_first < distance_to_last) {
|
|
1287
|
+
merged.push(...next_route);
|
|
1288
|
+
} else {
|
|
1289
|
+
merged.push(...next_route.reverse());
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
return merged;
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
// lib/components/primitive-components/Trace.ts
|
|
964
1296
|
var portToObjective = (port) => {
|
|
965
1297
|
const portPosition = port.getGlobalPcbPosition();
|
|
966
1298
|
return {
|
|
@@ -974,7 +1306,7 @@ var Trace = class extends PrimitiveComponent {
|
|
|
974
1306
|
schematic_trace_id = null;
|
|
975
1307
|
get config() {
|
|
976
1308
|
return {
|
|
977
|
-
zodProps:
|
|
1309
|
+
zodProps: traceProps
|
|
978
1310
|
};
|
|
979
1311
|
}
|
|
980
1312
|
getTracePortPathSelectors() {
|
|
@@ -1059,7 +1391,7 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1059
1391
|
return;
|
|
1060
1392
|
}
|
|
1061
1393
|
if (pcbRouteHints.length === 0) {
|
|
1062
|
-
const { solution } =
|
|
1394
|
+
const { solution } = autoroute(pcbElements.concat([source_trace]));
|
|
1063
1395
|
const pcb_trace2 = solution[0];
|
|
1064
1396
|
db.pcb_trace.insert(pcb_trace2);
|
|
1065
1397
|
this.pcb_trace_id = pcb_trace2.pcb_trace_id;
|
|
@@ -1070,7 +1402,7 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1070
1402
|
...pcbRouteHints,
|
|
1071
1403
|
portToObjective(ports[1].port)
|
|
1072
1404
|
];
|
|
1073
|
-
const candidateLayerCombinations =
|
|
1405
|
+
const candidateLayerCombinations = findPossibleTraceLayerCombinations(
|
|
1074
1406
|
orderedRouteObjectives
|
|
1075
1407
|
);
|
|
1076
1408
|
if (candidateLayerCombinations.length === 0) {
|
|
@@ -1078,8 +1410,8 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1078
1410
|
`Could not find a common layer (using hints) for trace ${this.getString()}`
|
|
1079
1411
|
);
|
|
1080
1412
|
}
|
|
1081
|
-
const obstacles =
|
|
1082
|
-
|
|
1413
|
+
const obstacles = getObstaclesFromSoup(this.project.db.toArray());
|
|
1414
|
+
markObstaclesAsConnected(
|
|
1083
1415
|
obstacles,
|
|
1084
1416
|
orderedRouteObjectives,
|
|
1085
1417
|
this.source_trace_id
|
|
@@ -1095,9 +1427,9 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1095
1427
|
return { ...t, layers: [candidateLayerSelections[idx]] };
|
|
1096
1428
|
});
|
|
1097
1429
|
const routes = [];
|
|
1098
|
-
for (const [a, b] of
|
|
1430
|
+
for (const [a, b] of pairs(orderedRoutePoints)) {
|
|
1099
1431
|
const BOUNDS_MARGIN = 2;
|
|
1100
|
-
const ijump = new
|
|
1432
|
+
const ijump = new IJumpAutorouter({
|
|
1101
1433
|
input: {
|
|
1102
1434
|
obstacles,
|
|
1103
1435
|
connections: [
|
|
@@ -1126,7 +1458,7 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1126
1458
|
routes.push(trace.route);
|
|
1127
1459
|
}
|
|
1128
1460
|
const pcb_trace = db.pcb_trace.insert({
|
|
1129
|
-
route:
|
|
1461
|
+
route: mergeRoutes(routes),
|
|
1130
1462
|
source_trace_id: this.source_trace_id
|
|
1131
1463
|
});
|
|
1132
1464
|
this.pcb_trace_id = pcb_trace.pcb_trace_id;
|
|
@@ -1155,21 +1487,21 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1155
1487
|
}
|
|
1156
1488
|
for (const { port } of ports) {
|
|
1157
1489
|
connection.pointsToConnect.push(
|
|
1158
|
-
|
|
1490
|
+
projectPointInDirection(
|
|
1159
1491
|
port.getGlobalSchematicPosition(),
|
|
1160
1492
|
port.facingDirection,
|
|
1161
1493
|
0.1501
|
|
1162
1494
|
)
|
|
1163
1495
|
);
|
|
1164
1496
|
}
|
|
1165
|
-
const bounds =
|
|
1497
|
+
const bounds = computeObstacleBounds(obstacles);
|
|
1166
1498
|
const simpleRouteJsonInput = {
|
|
1167
1499
|
obstacles,
|
|
1168
1500
|
connections: [connection],
|
|
1169
1501
|
bounds,
|
|
1170
1502
|
layerCount: 1
|
|
1171
1503
|
};
|
|
1172
|
-
const autorouter = new
|
|
1504
|
+
const autorouter = new IJumpAutorouter({
|
|
1173
1505
|
input: simpleRouteJsonInput
|
|
1174
1506
|
});
|
|
1175
1507
|
const results = autorouter.solve();
|
|
@@ -1196,10 +1528,9 @@ searched component ${targetComponent.getString()}, which has ports:${targetCompo
|
|
|
1196
1528
|
};
|
|
1197
1529
|
|
|
1198
1530
|
// lib/components/primitive-components/TraceHint.ts
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
var
|
|
1202
|
-
var TraceHint = class extends import_PrimitiveComponent8.PrimitiveComponent {
|
|
1531
|
+
import "@tscircuit/props";
|
|
1532
|
+
import { applyToPoint as applyToPoint3 } from "transformation-matrix";
|
|
1533
|
+
var TraceHint = class extends PrimitiveComponent {
|
|
1203
1534
|
matchedPort = null;
|
|
1204
1535
|
doInitialPortMatching() {
|
|
1205
1536
|
const { db } = this.project;
|
|
@@ -1232,7 +1563,7 @@ var TraceHint = class extends import_PrimitiveComponent8.PrimitiveComponent {
|
|
|
1232
1563
|
const globalTransform = this.computePcbGlobalTransform();
|
|
1233
1564
|
return offsets.map(
|
|
1234
1565
|
(offset) => ({
|
|
1235
|
-
...(
|
|
1566
|
+
...applyToPoint3(globalTransform, offset),
|
|
1236
1567
|
via: offset.via,
|
|
1237
1568
|
to_layer: offset.to_layer,
|
|
1238
1569
|
trace_width: offset.trace_width
|
|
@@ -1242,26 +1573,304 @@ var TraceHint = class extends import_PrimitiveComponent8.PrimitiveComponent {
|
|
|
1242
1573
|
};
|
|
1243
1574
|
|
|
1244
1575
|
// lib/components/primitive-components/Group.ts
|
|
1245
|
-
|
|
1576
|
+
import { groupProps } from "@tscircuit/props";
|
|
1246
1577
|
var Group = class extends PrimitiveComponent {
|
|
1247
1578
|
get config() {
|
|
1248
1579
|
return {
|
|
1249
|
-
zodProps:
|
|
1580
|
+
zodProps: groupProps
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
// lib/components/normal-components/Chip.ts
|
|
1586
|
+
import { chipProps } from "@tscircuit/props";
|
|
1587
|
+
|
|
1588
|
+
// lib/utils/schematic/getAllDimensionsForSchematicBox.ts
|
|
1589
|
+
import "@tscircuit/soup";
|
|
1590
|
+
|
|
1591
|
+
// lib/utils/schematic/getSizeOfSidesFromPortArrangement.ts
|
|
1592
|
+
var hasExplicitPinMapping = (pa) => {
|
|
1593
|
+
for (const side of [
|
|
1594
|
+
"leftSide",
|
|
1595
|
+
"rightSide",
|
|
1596
|
+
"topSide",
|
|
1597
|
+
"bottomSide"
|
|
1598
|
+
]) {
|
|
1599
|
+
if (side in pa && typeof pa[side] === "number") {
|
|
1600
|
+
throw new Error(
|
|
1601
|
+
`A number was specified for "${side}", you probably meant to use "size" not "side"`
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
return "leftSide" in pa || "rightSide" in pa || "topSide" in pa || "bottomSide" in pa;
|
|
1606
|
+
};
|
|
1607
|
+
var getSizeOfSidesFromPortArrangement = (pa) => {
|
|
1608
|
+
if (hasExplicitPinMapping(pa)) {
|
|
1609
|
+
return {
|
|
1610
|
+
leftSize: pa.leftSide?.pins.length ?? 0,
|
|
1611
|
+
rightSize: pa.rightSide?.pins.length ?? 0,
|
|
1612
|
+
topSize: pa.topSide?.pins.length ?? 0,
|
|
1613
|
+
bottomSize: pa.bottomSide?.pins.length ?? 0
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
const { leftSize = 0, rightSize = 0, topSize = 0, bottomSize = 0 } = pa;
|
|
1617
|
+
return { leftSize, rightSize, topSize, bottomSize };
|
|
1618
|
+
};
|
|
1619
|
+
|
|
1620
|
+
// lib/utils/schematic/getAllDimensionsForSchematicBox.ts
|
|
1621
|
+
import "@tscircuit/props";
|
|
1622
|
+
import "zod";
|
|
1623
|
+
var getAllDimensionsForSchematicBox = (params) => {
|
|
1624
|
+
const portDistanceFromEdge = params.portDistanceFromEdge ?? params.schPinSpacing * 2;
|
|
1625
|
+
let sidePinCounts = params.schPortArrangement ? getSizeOfSidesFromPortArrangement(params.schPortArrangement) : null;
|
|
1626
|
+
const sideLengths = {
|
|
1627
|
+
left: 0,
|
|
1628
|
+
right: 0,
|
|
1629
|
+
top: 0,
|
|
1630
|
+
bottom: 0
|
|
1631
|
+
};
|
|
1632
|
+
let pinCount = params.pinCount ?? null;
|
|
1633
|
+
if (pinCount === null) {
|
|
1634
|
+
if (sidePinCounts) {
|
|
1635
|
+
pinCount = sidePinCounts.leftSize + sidePinCounts.rightSize + sidePinCounts.topSize;
|
|
1636
|
+
} else {
|
|
1637
|
+
throw new Error("Could not determine pin count for the schematic box");
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if (pinCount && !sidePinCounts) {
|
|
1641
|
+
const rightSize = Math.floor(pinCount / 2);
|
|
1642
|
+
sidePinCounts = {
|
|
1643
|
+
leftSize: pinCount - rightSize,
|
|
1644
|
+
rightSize,
|
|
1645
|
+
topSize: 0,
|
|
1646
|
+
bottomSize: 0
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
if (!sidePinCounts) {
|
|
1650
|
+
throw new Error("Could not determine side sizes for the schematic box");
|
|
1651
|
+
}
|
|
1652
|
+
const orderedTruePorts = [];
|
|
1653
|
+
let currentDistanceFromEdge = 0;
|
|
1654
|
+
let truePinIndex = 0;
|
|
1655
|
+
for (let sideIndex = 0; sideIndex < sidePinCounts.leftSize; sideIndex++) {
|
|
1656
|
+
const pinNumber = truePinIndex + 1;
|
|
1657
|
+
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
1658
|
+
if (pinStyle?.topMargin) {
|
|
1659
|
+
currentDistanceFromEdge += pinStyle.topMargin;
|
|
1660
|
+
}
|
|
1661
|
+
orderedTruePorts.push({
|
|
1662
|
+
trueIndex: truePinIndex,
|
|
1663
|
+
pinNumber,
|
|
1664
|
+
side: "left",
|
|
1665
|
+
distanceFromEdge: currentDistanceFromEdge
|
|
1666
|
+
});
|
|
1667
|
+
if (pinStyle?.bottomMargin) {
|
|
1668
|
+
currentDistanceFromEdge += pinStyle.bottomMargin;
|
|
1669
|
+
}
|
|
1670
|
+
const isLastPinOnSide = sideIndex === sidePinCounts.leftSize - 1;
|
|
1671
|
+
if (!isLastPinOnSide) {
|
|
1672
|
+
currentDistanceFromEdge += params.schPinSpacing;
|
|
1673
|
+
} else {
|
|
1674
|
+
sideLengths.left = currentDistanceFromEdge;
|
|
1675
|
+
}
|
|
1676
|
+
truePinIndex++;
|
|
1677
|
+
}
|
|
1678
|
+
currentDistanceFromEdge = 0;
|
|
1679
|
+
for (let sideIndex = 0; sideIndex < sidePinCounts.bottomSize; sideIndex++) {
|
|
1680
|
+
const pinNumber = truePinIndex + 1;
|
|
1681
|
+
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
1682
|
+
if (pinStyle?.leftMargin) {
|
|
1683
|
+
currentDistanceFromEdge += pinStyle.leftMargin;
|
|
1684
|
+
}
|
|
1685
|
+
orderedTruePorts.push({
|
|
1686
|
+
trueIndex: truePinIndex,
|
|
1687
|
+
pinNumber,
|
|
1688
|
+
side: "bottom",
|
|
1689
|
+
distanceFromEdge: currentDistanceFromEdge
|
|
1690
|
+
});
|
|
1691
|
+
if (pinStyle?.rightMargin) {
|
|
1692
|
+
currentDistanceFromEdge += pinStyle.rightMargin;
|
|
1693
|
+
}
|
|
1694
|
+
const isLastPinOnSide = sideIndex === sidePinCounts.bottomSize - 1;
|
|
1695
|
+
if (!isLastPinOnSide) {
|
|
1696
|
+
currentDistanceFromEdge += params.schPinSpacing;
|
|
1697
|
+
} else {
|
|
1698
|
+
sideLengths.bottom = currentDistanceFromEdge;
|
|
1699
|
+
}
|
|
1700
|
+
truePinIndex++;
|
|
1701
|
+
}
|
|
1702
|
+
currentDistanceFromEdge = 0;
|
|
1703
|
+
for (let sideIndex = 0; sideIndex < sidePinCounts.rightSize; sideIndex++) {
|
|
1704
|
+
const pinNumber = truePinIndex + 1;
|
|
1705
|
+
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
1706
|
+
if (pinStyle?.bottomMargin) {
|
|
1707
|
+
currentDistanceFromEdge += pinStyle.bottomMargin;
|
|
1708
|
+
}
|
|
1709
|
+
orderedTruePorts.push({
|
|
1710
|
+
trueIndex: truePinIndex,
|
|
1711
|
+
pinNumber,
|
|
1712
|
+
side: "right",
|
|
1713
|
+
distanceFromEdge: currentDistanceFromEdge
|
|
1714
|
+
});
|
|
1715
|
+
if (pinStyle?.topMargin) {
|
|
1716
|
+
currentDistanceFromEdge += pinStyle.topMargin;
|
|
1717
|
+
}
|
|
1718
|
+
const isLastPinOnSide = sideIndex === sidePinCounts.rightSize - 1;
|
|
1719
|
+
if (!isLastPinOnSide) {
|
|
1720
|
+
currentDistanceFromEdge += params.schPinSpacing;
|
|
1721
|
+
} else {
|
|
1722
|
+
sideLengths.right = currentDistanceFromEdge;
|
|
1723
|
+
}
|
|
1724
|
+
truePinIndex++;
|
|
1725
|
+
}
|
|
1726
|
+
currentDistanceFromEdge = 0;
|
|
1727
|
+
for (let sideIndex = 0; sideIndex < sidePinCounts.topSize; sideIndex++) {
|
|
1728
|
+
const pinNumber = truePinIndex + 1;
|
|
1729
|
+
const pinStyle = params.schPinStyle?.[`pin${pinNumber}`] ?? params.schPinStyle?.[pinNumber];
|
|
1730
|
+
if (pinStyle?.rightMargin) {
|
|
1731
|
+
currentDistanceFromEdge += pinStyle.rightMargin;
|
|
1732
|
+
}
|
|
1733
|
+
orderedTruePorts.push({
|
|
1734
|
+
trueIndex: truePinIndex,
|
|
1735
|
+
pinNumber,
|
|
1736
|
+
side: "top",
|
|
1737
|
+
distanceFromEdge: currentDistanceFromEdge
|
|
1738
|
+
});
|
|
1739
|
+
if (pinStyle?.leftMargin) {
|
|
1740
|
+
currentDistanceFromEdge += pinStyle.leftMargin;
|
|
1741
|
+
}
|
|
1742
|
+
const isLastPinOnSide = sideIndex === sidePinCounts.topSize - 1;
|
|
1743
|
+
if (!isLastPinOnSide) {
|
|
1744
|
+
currentDistanceFromEdge += params.schPinSpacing;
|
|
1745
|
+
} else {
|
|
1746
|
+
sideLengths.top = currentDistanceFromEdge;
|
|
1747
|
+
}
|
|
1748
|
+
truePinIndex++;
|
|
1749
|
+
}
|
|
1750
|
+
let schWidth = params.schWidth;
|
|
1751
|
+
if (!schWidth) {
|
|
1752
|
+
schWidth = Math.max(
|
|
1753
|
+
sideLengths.top + params.schPinSpacing * 2,
|
|
1754
|
+
sideLengths.bottom + params.schPinSpacing * 2
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
let schHeight = params.schHeight;
|
|
1758
|
+
if (!schHeight) {
|
|
1759
|
+
schHeight = Math.max(
|
|
1760
|
+
sideLengths.left + params.schPinSpacing * 2,
|
|
1761
|
+
sideLengths.right + params.schPinSpacing * 2
|
|
1762
|
+
);
|
|
1763
|
+
}
|
|
1764
|
+
const trueEdgePositions = {
|
|
1765
|
+
// Top left corner
|
|
1766
|
+
left: {
|
|
1767
|
+
x: -schWidth / 2 - portDistanceFromEdge,
|
|
1768
|
+
y: sideLengths.left / 2
|
|
1769
|
+
},
|
|
1770
|
+
// bottom left corner
|
|
1771
|
+
bottom: {
|
|
1772
|
+
x: -sideLengths.bottom / 2,
|
|
1773
|
+
y: -schHeight / 2 - portDistanceFromEdge
|
|
1774
|
+
},
|
|
1775
|
+
// bottom right corner
|
|
1776
|
+
right: {
|
|
1777
|
+
x: schWidth / 2 + portDistanceFromEdge,
|
|
1778
|
+
y: -sideLengths.right / 2
|
|
1779
|
+
},
|
|
1780
|
+
// top right corner
|
|
1781
|
+
top: {
|
|
1782
|
+
x: sideLengths.top / 2,
|
|
1783
|
+
y: schHeight / 2 + portDistanceFromEdge
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
const trueEdgeTraversalDirections = {
|
|
1787
|
+
left: { x: 0, y: -1 },
|
|
1788
|
+
right: { x: 0, y: 1 },
|
|
1789
|
+
top: { x: -1, y: 0 },
|
|
1790
|
+
bottom: { x: 1, y: 0 }
|
|
1791
|
+
};
|
|
1792
|
+
const truePortsWithPositions = orderedTruePorts.map((p) => {
|
|
1793
|
+
const { distanceFromEdge, side } = p;
|
|
1794
|
+
const edgePos = trueEdgePositions[side];
|
|
1795
|
+
const edgeDir = trueEdgeTraversalDirections[side];
|
|
1796
|
+
return {
|
|
1797
|
+
x: edgePos.x + distanceFromEdge * edgeDir.x,
|
|
1798
|
+
y: edgePos.y + distanceFromEdge * edgeDir.y,
|
|
1799
|
+
...p
|
|
1800
|
+
};
|
|
1801
|
+
});
|
|
1802
|
+
return {
|
|
1803
|
+
getPortPositionByPinNumber(pinNumber) {
|
|
1804
|
+
const port = truePortsWithPositions.find(
|
|
1805
|
+
(p) => p.pinNumber.toString() === pinNumber.toString()
|
|
1806
|
+
);
|
|
1807
|
+
if (!port) {
|
|
1808
|
+
throw new Error(
|
|
1809
|
+
`Could not find port for pin number ${pinNumber}, available pins: ${truePortsWithPositions.map((tp) => tp.pinNumber).join(", ")}`
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
return port;
|
|
1813
|
+
},
|
|
1814
|
+
getSize() {
|
|
1815
|
+
return { width: schWidth, height: schHeight };
|
|
1816
|
+
},
|
|
1817
|
+
pinCount
|
|
1818
|
+
};
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
// lib/soup/underscorifyPortArrangement.ts
|
|
1822
|
+
var underscorifyPortArrangement = (portArrangement) => {
|
|
1823
|
+
if (!portArrangement) return void 0;
|
|
1824
|
+
if ("leftSide" in portArrangement || "rightSide" in portArrangement || "topSide" in portArrangement || "bottomSide" in portArrangement) {
|
|
1825
|
+
return {
|
|
1826
|
+
left_side: portArrangement.leftSide,
|
|
1827
|
+
right_side: portArrangement.rightSide,
|
|
1828
|
+
top_side: portArrangement.topSide,
|
|
1829
|
+
bottom_side: portArrangement.bottomSide
|
|
1250
1830
|
};
|
|
1251
1831
|
}
|
|
1832
|
+
if ("leftPinCount" in portArrangement || "rightPinCount" in portArrangement || "topPinCount" in portArrangement || "bottomPinCount" in portArrangement) {
|
|
1833
|
+
return {
|
|
1834
|
+
left_size: portArrangement.leftPinCount,
|
|
1835
|
+
right_size: portArrangement.rightPinCount,
|
|
1836
|
+
top_size: portArrangement.topPinCount,
|
|
1837
|
+
bottom_size: portArrangement.bottomPinCount
|
|
1838
|
+
};
|
|
1839
|
+
}
|
|
1840
|
+
if ("leftSize" in portArrangement || "rightSize" in portArrangement || "topSize" in portArrangement || "bottomSize" in portArrangement) {
|
|
1841
|
+
return {
|
|
1842
|
+
left_size: portArrangement.leftSize,
|
|
1843
|
+
right_size: portArrangement.rightSize,
|
|
1844
|
+
top_size: portArrangement.topSize,
|
|
1845
|
+
bottom_size: portArrangement.bottomSize
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
return void 0;
|
|
1849
|
+
};
|
|
1850
|
+
|
|
1851
|
+
// lib/soup/underscorifyPinStyles.ts
|
|
1852
|
+
import "@tscircuit/soup";
|
|
1853
|
+
import "zod";
|
|
1854
|
+
var underscorifyPinStyles = (pinStyles) => {
|
|
1855
|
+
if (!pinStyles) return void 0;
|
|
1856
|
+
const underscorePinStyles = {};
|
|
1857
|
+
for (const [pinName, pinStyle] of Object.entries(pinStyles)) {
|
|
1858
|
+
underscorePinStyles[pinName] = {
|
|
1859
|
+
bottom_margin: pinStyle.bottomMargin,
|
|
1860
|
+
left_margin: pinStyle.leftMargin,
|
|
1861
|
+
right_margin: pinStyle.rightMargin,
|
|
1862
|
+
top_margin: pinStyle.topMargin
|
|
1863
|
+
};
|
|
1864
|
+
}
|
|
1865
|
+
return underscorePinStyles;
|
|
1252
1866
|
};
|
|
1253
1867
|
|
|
1254
1868
|
// lib/components/normal-components/Chip.ts
|
|
1255
|
-
var
|
|
1256
|
-
var import_props9 = require("@tscircuit/props");
|
|
1257
|
-
var import_getAllDimensionsForSchematicBox = require("lib/utils/schematic/getAllDimensionsForSchematicBox");
|
|
1258
|
-
var import_underscorifyPortArrangement = require("lib/soup/underscorifyPortArrangement");
|
|
1259
|
-
var import_underscorifyPinStyles = require("lib/soup/underscorifyPinStyles");
|
|
1260
|
-
var Chip = class extends import_NormalComponent4.NormalComponent {
|
|
1869
|
+
var Chip = class extends NormalComponent {
|
|
1261
1870
|
schematicDimensions = null;
|
|
1262
1871
|
get config() {
|
|
1263
1872
|
return {
|
|
1264
|
-
zodProps:
|
|
1873
|
+
zodProps: chipProps
|
|
1265
1874
|
};
|
|
1266
1875
|
}
|
|
1267
1876
|
initPorts() {
|
|
@@ -1295,7 +1904,7 @@ var Chip = class extends import_NormalComponent4.NormalComponent {
|
|
|
1295
1904
|
const { db } = this.project;
|
|
1296
1905
|
const { _parsedProps: props } = this;
|
|
1297
1906
|
const pinSpacing = props.schPinSpacing ?? 0.2;
|
|
1298
|
-
const dimensions =
|
|
1907
|
+
const dimensions = getAllDimensionsForSchematicBox({
|
|
1299
1908
|
schWidth: props.schWidth,
|
|
1300
1909
|
schHeight: props.schHeight,
|
|
1301
1910
|
schPinSpacing: pinSpacing,
|
|
@@ -1306,20 +1915,20 @@ var Chip = class extends import_NormalComponent4.NormalComponent {
|
|
|
1306
1915
|
schPortArrangement: props.schPortArrangement
|
|
1307
1916
|
});
|
|
1308
1917
|
this.schematicDimensions = dimensions;
|
|
1309
|
-
const
|
|
1918
|
+
const schematic_component2 = db.schematic_component.insert({
|
|
1310
1919
|
center: { x: props.schX ?? 0, y: props.schY ?? 0 },
|
|
1311
1920
|
rotation: props.schRotation ?? 0,
|
|
1312
1921
|
size: dimensions.getSize(),
|
|
1313
|
-
port_arrangement:
|
|
1922
|
+
port_arrangement: underscorifyPortArrangement(
|
|
1314
1923
|
props.schPortArrangement
|
|
1315
1924
|
),
|
|
1316
1925
|
pin_spacing: pinSpacing,
|
|
1317
1926
|
// @ts-ignore soup needs to support distance for pin_styles
|
|
1318
|
-
pin_styles:
|
|
1927
|
+
pin_styles: underscorifyPinStyles(props.schPinStyle),
|
|
1319
1928
|
port_labels: props.pinLabels,
|
|
1320
1929
|
source_component_id: this.source_component_id
|
|
1321
1930
|
});
|
|
1322
|
-
this.schematic_component_id =
|
|
1931
|
+
this.schematic_component_id = schematic_component2.schematic_component_id;
|
|
1323
1932
|
}
|
|
1324
1933
|
doInitialPcbComponentRender() {
|
|
1325
1934
|
const { db } = this.project;
|
|
@@ -1339,171 +1948,21 @@ var Chip = class extends import_NormalComponent4.NormalComponent {
|
|
|
1339
1948
|
};
|
|
1340
1949
|
|
|
1341
1950
|
// lib/Project.ts
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
// lib/fiber/create-instance-from-react-element.ts
|
|
1346
|
-
var import_react_reconciler = __toESM(require("react-reconciler"), 1);
|
|
1347
|
-
var import_Renderable3 = require("lib/components/base-components/Renderable");
|
|
1348
|
-
var import_NormalComponent6 = require("lib/components/base-components/NormalComponent");
|
|
1349
|
-
|
|
1350
|
-
// lib/fiber/catalogue.ts
|
|
1351
|
-
var catalogue = {};
|
|
1352
|
-
var extendCatalogue = (objects) => {
|
|
1353
|
-
const altKeys = Object.fromEntries(
|
|
1354
|
-
Object.entries(objects).map(([key, v]) => [key.toLowerCase(), v])
|
|
1355
|
-
);
|
|
1356
|
-
Object.assign(catalogue, objects);
|
|
1357
|
-
Object.assign(catalogue, altKeys);
|
|
1358
|
-
};
|
|
1359
|
-
|
|
1360
|
-
// lib/fiber/create-instance-from-react-element.ts
|
|
1361
|
-
function prepare(object, state) {
|
|
1362
|
-
const instance = object;
|
|
1363
|
-
instance.__tsci = {
|
|
1364
|
-
...state
|
|
1365
|
-
};
|
|
1366
|
-
return object;
|
|
1367
|
-
}
|
|
1368
|
-
var hostConfig = {
|
|
1369
|
-
supportsMutation: true,
|
|
1370
|
-
createInstance(type, props) {
|
|
1371
|
-
const target = catalogue[type];
|
|
1372
|
-
if (!target) {
|
|
1373
|
-
if (Object.keys(catalogue).length === 0) {
|
|
1374
|
-
throw new Error(
|
|
1375
|
-
"No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"
|
|
1376
|
-
);
|
|
1377
|
-
}
|
|
1378
|
-
throw new Error(
|
|
1379
|
-
`Unsupported component type (not registered in @tscircuit/core catalogue): ${type}`
|
|
1380
|
-
);
|
|
1381
|
-
}
|
|
1382
|
-
const instance = prepare(new target(props), {});
|
|
1383
|
-
return instance;
|
|
1384
|
-
},
|
|
1385
|
-
createTextInstance() {
|
|
1386
|
-
return {};
|
|
1387
|
-
},
|
|
1388
|
-
appendInitialChild(parentInstance, child) {
|
|
1389
|
-
parentInstance.add(child);
|
|
1390
|
-
},
|
|
1391
|
-
appendChild(parentInstance, child) {
|
|
1392
|
-
parentInstance.add(child);
|
|
1393
|
-
},
|
|
1394
|
-
appendChildToContainer(container, child) {
|
|
1395
|
-
container.add(child);
|
|
1396
|
-
},
|
|
1397
|
-
finalizeInitialChildren() {
|
|
1398
|
-
return false;
|
|
1399
|
-
},
|
|
1400
|
-
prepareUpdate() {
|
|
1401
|
-
return null;
|
|
1402
|
-
},
|
|
1403
|
-
shouldSetTextContent() {
|
|
1404
|
-
return false;
|
|
1405
|
-
},
|
|
1406
|
-
getRootHostContext() {
|
|
1407
|
-
return {};
|
|
1408
|
-
},
|
|
1409
|
-
getChildHostContext() {
|
|
1410
|
-
return {};
|
|
1411
|
-
},
|
|
1412
|
-
prepareForCommit() {
|
|
1413
|
-
return null;
|
|
1414
|
-
},
|
|
1415
|
-
resetAfterCommit() {
|
|
1416
|
-
},
|
|
1417
|
-
commitMount() {
|
|
1418
|
-
},
|
|
1419
|
-
commitUpdate() {
|
|
1420
|
-
},
|
|
1421
|
-
removeChild() {
|
|
1422
|
-
},
|
|
1423
|
-
clearContainer() {
|
|
1424
|
-
},
|
|
1425
|
-
supportsPersistence: false,
|
|
1426
|
-
getPublicInstance(instance) {
|
|
1427
|
-
return instance;
|
|
1428
|
-
},
|
|
1429
|
-
preparePortalMount(containerInfo) {
|
|
1430
|
-
throw new Error("Function not implemented.");
|
|
1431
|
-
},
|
|
1432
|
-
scheduleTimeout(fn, delay) {
|
|
1433
|
-
throw new Error("Function not implemented.");
|
|
1434
|
-
},
|
|
1435
|
-
cancelTimeout(id) {
|
|
1436
|
-
throw new Error("Function not implemented.");
|
|
1437
|
-
},
|
|
1438
|
-
noTimeout: void 0,
|
|
1439
|
-
isPrimaryRenderer: false,
|
|
1440
|
-
getCurrentEventPriority() {
|
|
1441
|
-
throw new Error("Function not implemented.");
|
|
1442
|
-
},
|
|
1443
|
-
getInstanceFromNode(node) {
|
|
1444
|
-
throw new Error("Function not implemented.");
|
|
1445
|
-
},
|
|
1446
|
-
beforeActiveInstanceBlur() {
|
|
1447
|
-
throw new Error("Function not implemented.");
|
|
1448
|
-
},
|
|
1449
|
-
afterActiveInstanceBlur() {
|
|
1450
|
-
throw new Error("Function not implemented.");
|
|
1451
|
-
},
|
|
1452
|
-
prepareScopeUpdate: (scopeInstance, instance) => {
|
|
1453
|
-
throw new Error("Function not implemented.");
|
|
1454
|
-
},
|
|
1455
|
-
getInstanceFromScope: (scopeInstance) => {
|
|
1456
|
-
throw new Error("Function not implemented.");
|
|
1457
|
-
},
|
|
1458
|
-
detachDeletedInstance: (node) => {
|
|
1459
|
-
throw new Error("Function not implemented.");
|
|
1460
|
-
},
|
|
1461
|
-
supportsHydration: false
|
|
1462
|
-
};
|
|
1463
|
-
var reconciler = (0, import_react_reconciler.default)(hostConfig);
|
|
1464
|
-
var createInstanceFromReactElement2 = (reactElm) => {
|
|
1465
|
-
const container = reconciler.createContainer(
|
|
1466
|
-
// TODO Replace with store like react-three-fiber
|
|
1467
|
-
// https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
|
|
1468
|
-
// https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts#L168
|
|
1469
|
-
{
|
|
1470
|
-
props: {
|
|
1471
|
-
name: "$root"
|
|
1472
|
-
},
|
|
1473
|
-
add(instance) {
|
|
1474
|
-
instance.parent = this;
|
|
1475
|
-
}
|
|
1476
|
-
},
|
|
1477
|
-
0,
|
|
1478
|
-
null,
|
|
1479
|
-
false,
|
|
1480
|
-
null,
|
|
1481
|
-
"tsci",
|
|
1482
|
-
(error) => {
|
|
1483
|
-
console.log("Error in createContainer");
|
|
1484
|
-
console.error(error);
|
|
1485
|
-
},
|
|
1486
|
-
null
|
|
1487
|
-
);
|
|
1488
|
-
reconciler.updateContainer(reactElm, container, null, () => {
|
|
1489
|
-
});
|
|
1490
|
-
return reconciler.getPublicRootInstance(container);
|
|
1491
|
-
};
|
|
1492
|
-
|
|
1493
|
-
// lib/Project.ts
|
|
1494
|
-
var import_transformation_matrix5 = require("transformation-matrix");
|
|
1951
|
+
import { su } from "@tscircuit/soup-util";
|
|
1952
|
+
import { isValidElement as isValidElement2 } from "react";
|
|
1953
|
+
import { identity as identity3 } from "transformation-matrix";
|
|
1495
1954
|
var Project = class {
|
|
1496
1955
|
rootComponent = null;
|
|
1497
1956
|
children;
|
|
1498
1957
|
db;
|
|
1499
1958
|
constructor() {
|
|
1500
1959
|
this.children = [];
|
|
1501
|
-
this.db =
|
|
1960
|
+
this.db = su([]);
|
|
1502
1961
|
}
|
|
1503
1962
|
add(componentOrElm) {
|
|
1504
1963
|
let component;
|
|
1505
|
-
if ((
|
|
1506
|
-
component =
|
|
1964
|
+
if (isValidElement2(componentOrElm)) {
|
|
1965
|
+
component = createInstanceFromReactElement(componentOrElm);
|
|
1507
1966
|
} else {
|
|
1508
1967
|
component = componentOrElm;
|
|
1509
1968
|
}
|
|
@@ -1547,10 +2006,10 @@ var Project = class {
|
|
|
1547
2006
|
return this.getSoup();
|
|
1548
2007
|
}
|
|
1549
2008
|
computeGlobalSchematicTransform() {
|
|
1550
|
-
return (
|
|
2009
|
+
return identity3();
|
|
1551
2010
|
}
|
|
1552
2011
|
computeGlobalPcbTransform() {
|
|
1553
|
-
return (
|
|
2012
|
+
return identity3();
|
|
1554
2013
|
}
|
|
1555
2014
|
selectAll(selector) {
|
|
1556
2015
|
return this.rootComponent?.selectAll(selector) ?? [];
|
|
@@ -1562,8 +2021,7 @@ var Project = class {
|
|
|
1562
2021
|
|
|
1563
2022
|
// lib/register-catalogue.ts
|
|
1564
2023
|
extendCatalogue(components_exports);
|
|
1565
|
-
|
|
1566
|
-
0 && (module.exports = {
|
|
2024
|
+
export {
|
|
1567
2025
|
Board,
|
|
1568
2026
|
Capacitor,
|
|
1569
2027
|
Chip,
|
|
@@ -1580,4 +2038,4 @@ extendCatalogue(components_exports);
|
|
|
1580
2038
|
SmtPad,
|
|
1581
2039
|
Trace,
|
|
1582
2040
|
TraceHint
|
|
1583
|
-
}
|
|
2041
|
+
};
|