@tscircuit/circuit-json-util 0.0.114 → 0.0.116
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/README.md +3 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +99 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,14 +116,14 @@ const source_traces = su(circuitJson).source_trace.list({
|
|
|
116
116
|
For large circuit json, the library provides an optimized version with indexing for faster lookups:
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
|
-
import {
|
|
119
|
+
import { cjuIndexed } from "@tscircuit/circuit-json-util"
|
|
120
120
|
|
|
121
121
|
const circuitJson = [
|
|
122
122
|
/* large soup with many elements */
|
|
123
123
|
]
|
|
124
124
|
|
|
125
125
|
// Configure the indexes you want to use
|
|
126
|
-
const indexedSu =
|
|
126
|
+
const indexedSu = cjuIndexed(circuitJson, {
|
|
127
127
|
indexConfig: {
|
|
128
128
|
byId: true, // Index by element ID for fast .get() operations
|
|
129
129
|
byType: true, // Index by element type for fast .list() operations
|
|
@@ -142,7 +142,7 @@ const subcircuitElements = indexedSu.source_component.list({
|
|
|
142
142
|
})
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
The indexed version
|
|
145
|
+
The indexed version supports root-level `insert`, `insertAll`, and `subtree` as well as table operations. Root inserts assign IDs, including when an input supplies an ID, just like `cju`. Subtrees preserve the indexing and validation options and have their own collection; existing element objects are shared with the parent. `list()` returns a new array, so sorting or splicing it cannot modify the store's type index. The elements in that array remain live objects.
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
## Categorize DRC Errors and Warnings
|
package/dist/index.d.ts
CHANGED
|
@@ -19309,6 +19309,9 @@ interface BoardBounds {
|
|
|
19309
19309
|
}
|
|
19310
19310
|
declare const getBoardBounds: (board: PcbBoard) => BoardBounds;
|
|
19311
19311
|
|
|
19312
|
+
type AnyCircuitJsonId = string;
|
|
19313
|
+
declare function createBoardOwnerMap(circuitJson: AnyCircuitElement[]): Map<AnyCircuitJsonId, PcbBoard | undefined>;
|
|
19314
|
+
|
|
19312
19315
|
type SchematicElementWithBounds = SchematicComponent | SchematicNetLabel | SchematicTrace;
|
|
19313
19316
|
interface SchematicElementBounds {
|
|
19314
19317
|
minX: number;
|
|
@@ -19496,4 +19499,4 @@ declare const getTraceSegmentPolygon: (start: Point$2, end: Point$2, startWidth:
|
|
|
19496
19499
|
*/
|
|
19497
19500
|
declare const copperPolygonsTouch: (a: Polygon$1, b: Polygon$1, tolerance?: number) => boolean;
|
|
19498
19501
|
|
|
19499
|
-
export { type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, copperPolygonsTouch, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
|
|
19502
|
+
export { type AnyCircuitJsonId, type BoardBounds, type CircuitJsonInputUtilObjects, type CircuitJsonOps, type CircuitJsonTreeNode, type CircuitJsonUtilObjects, type CircuitJsonUtilOptions, type DrcCategory, type GetCircuitJsonUtilFn, type GetIndexedCircuitJsonUtilFn, type IndexedCircuitJsonUtilOptions, type PcbBounds, type PcbPin1LocationElement, type SchematicElementBounds, type SchematicElementWithBounds, type Size, type SubtreeOptions, analyzePcbPin1Location, applySelector, applySelectorAST, buildSubtree, categorizeErrorOrWarning, circlePolygon, cju, cjuIndexed, computeClearanceBetweenElements, computeGapBetweenCopper, copperPolygonsTouch, createBoardOwnerMap, directionToVec, distanceBetweenCircleAndCircle, distanceBetweenCircleAndPolygon, distanceBetweenPolygonAndPolygon, distanceBetweenShapes, findBoundsAndCenter, getBoardBounds, getBoundsOfPcbElements, getCircuitJsonTree, getElementById, getElementId, getElementRenderLayers, getMinimumFlexContainer, getPcbElementBounds, getPcbElementsWithinBounds, getPlatedHolePolygon, getPourPolygon, getPrimaryId, getReadableNameForElement, getReadableNameForPcbPort, getReadableNameForPcbSmtpad, getReadableNameForPcbTrace, getSchematicElementBounds, getSmtPadPolygon, getStringFromCircuitJsonTree, getTraceSegmentPolygon, getViaPolygon, oppositeDirection, oppositeSide, placePolygon, repositionPcbComponentTo, repositionPcbGroupTo, repositionSchematicComponentTo, repositionSchematicGroupTo, rotateClockwise, rotateCounterClockwise, rotateDirection, roundedRectangle, su, transformInsertionDirection, transformPCBElement, transformPCBElements, transformPCBElement as transformPcbElement, transformPCBElements as transformPcbElements, transformSchematicElement, transformSchematicElements, vecToDirection };
|
package/dist/index.js
CHANGED
|
@@ -401,6 +401,20 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
401
401
|
if (prop === "editCount") {
|
|
402
402
|
return internalStore.editCount;
|
|
403
403
|
}
|
|
404
|
+
if (prop === "insert") {
|
|
405
|
+
return (elm) => {
|
|
406
|
+
const { type, ...props } = elm;
|
|
407
|
+
if (!type) throw new Error("insert requires an element with a type");
|
|
408
|
+
delete props[`${type}_id`];
|
|
409
|
+
return suIndexed[type].insert(props);
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
if (prop === "insertAll") {
|
|
413
|
+
return (elms) => elms.map((elm) => suIndexed.insert(elm));
|
|
414
|
+
}
|
|
415
|
+
if (prop === "subtree") {
|
|
416
|
+
return (opts) => cjuIndexed(buildSubtree(soup, opts), options);
|
|
417
|
+
}
|
|
404
418
|
const component_type = prop;
|
|
405
419
|
return {
|
|
406
420
|
get: (id) => {
|
|
@@ -496,7 +510,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
496
510
|
const indexConfig = options.indexConfig || {};
|
|
497
511
|
const keys = !where ? [] : Object.keys(where);
|
|
498
512
|
if (keys.length === 0 && indexConfig.byType && internalStore.indexes.byType) {
|
|
499
|
-
return internalStore.indexes.byType.get(component_type) || [];
|
|
513
|
+
return (internalStore.indexes.byType.get(component_type) || []).slice();
|
|
500
514
|
}
|
|
501
515
|
if (keys.length === 1 && keys[0] === "subcircuit_id" && indexConfig.bySubcircuit && internalStore.indexes.bySubcircuit) {
|
|
502
516
|
const subcircuitId = where.subcircuit_id;
|
|
@@ -516,7 +530,7 @@ var cjuIndexed = ((soup, options = {}) => {
|
|
|
516
530
|
(e) => keys.every((key) => e[key] === where[key])
|
|
517
531
|
);
|
|
518
532
|
}
|
|
519
|
-
return elementsToFilter;
|
|
533
|
+
return elementsToFilter.slice();
|
|
520
534
|
},
|
|
521
535
|
insert: (elm) => {
|
|
522
536
|
internalStore.counts[component_type] ??= -1;
|
|
@@ -1582,6 +1596,88 @@ var getBoardBounds = (board) => {
|
|
|
1582
1596
|
};
|
|
1583
1597
|
};
|
|
1584
1598
|
|
|
1599
|
+
// lib/create-board-owner-map.ts
|
|
1600
|
+
function createBoardOwnerMap(circuitJson) {
|
|
1601
|
+
const boardOwnerMap = /* @__PURE__ */ new Map();
|
|
1602
|
+
const parentById = /* @__PURE__ */ new Map();
|
|
1603
|
+
const boardsById = /* @__PURE__ */ new Map();
|
|
1604
|
+
for (const element of circuitJson) {
|
|
1605
|
+
switch (element.type) {
|
|
1606
|
+
case "pcb_board":
|
|
1607
|
+
boardsById.set(element.pcb_board_id, element);
|
|
1608
|
+
break;
|
|
1609
|
+
case "source_group": {
|
|
1610
|
+
const parentGroupId = element.parent_subcircuit_id ?? element.parent_source_group_id;
|
|
1611
|
+
parentById.set(
|
|
1612
|
+
element.source_group_id,
|
|
1613
|
+
element.subcircuit_id ?? parentGroupId
|
|
1614
|
+
);
|
|
1615
|
+
if (element.is_subcircuit && element.subcircuit_id) {
|
|
1616
|
+
parentById.set(element.subcircuit_id, parentGroupId);
|
|
1617
|
+
}
|
|
1618
|
+
break;
|
|
1619
|
+
}
|
|
1620
|
+
case "pcb_group":
|
|
1621
|
+
parentById.set(
|
|
1622
|
+
element.pcb_group_id,
|
|
1623
|
+
element.subcircuit_id ?? element.source_group_id
|
|
1624
|
+
);
|
|
1625
|
+
break;
|
|
1626
|
+
case "pcb_component":
|
|
1627
|
+
parentById.set(
|
|
1628
|
+
element.pcb_component_id,
|
|
1629
|
+
element.subcircuit_id ?? element.pcb_group_id
|
|
1630
|
+
);
|
|
1631
|
+
break;
|
|
1632
|
+
case "pcb_trace":
|
|
1633
|
+
parentById.set(
|
|
1634
|
+
element.pcb_trace_id,
|
|
1635
|
+
element.subcircuit_id ?? element.pcb_group_id ?? element.pcb_component_id
|
|
1636
|
+
);
|
|
1637
|
+
break;
|
|
1638
|
+
case "pcb_via":
|
|
1639
|
+
parentById.set(
|
|
1640
|
+
element.pcb_via_id,
|
|
1641
|
+
element.subcircuit_id ?? element.pcb_group_id ?? element.pcb_trace_id
|
|
1642
|
+
);
|
|
1643
|
+
break;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
const boards = [...boardsById.values()];
|
|
1647
|
+
for (const board of boards) {
|
|
1648
|
+
boardOwnerMap.set(board.pcb_board_id, board);
|
|
1649
|
+
if (board.subcircuit_id) {
|
|
1650
|
+
boardOwnerMap.set(board.subcircuit_id, board);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
const singleBoard = boards.length === 1 ? boards[0] : void 0;
|
|
1654
|
+
const resolvingIds = /* @__PURE__ */ new Set();
|
|
1655
|
+
function resolveBoard(id) {
|
|
1656
|
+
if (boardOwnerMap.has(id)) {
|
|
1657
|
+
return boardOwnerMap.get(id);
|
|
1658
|
+
}
|
|
1659
|
+
if (!parentById.has(id)) {
|
|
1660
|
+
return void 0;
|
|
1661
|
+
}
|
|
1662
|
+
if (resolvingIds.has(id)) {
|
|
1663
|
+
return void 0;
|
|
1664
|
+
}
|
|
1665
|
+
resolvingIds.add(id);
|
|
1666
|
+
const parentId = parentById.get(id);
|
|
1667
|
+
let board = singleBoard;
|
|
1668
|
+
if (parentId) {
|
|
1669
|
+
board = resolveBoard(parentId);
|
|
1670
|
+
}
|
|
1671
|
+
resolvingIds.delete(id);
|
|
1672
|
+
boardOwnerMap.set(id, board);
|
|
1673
|
+
return board;
|
|
1674
|
+
}
|
|
1675
|
+
for (const id of parentById.keys()) {
|
|
1676
|
+
resolveBoard(id);
|
|
1677
|
+
}
|
|
1678
|
+
return boardOwnerMap;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1585
1681
|
// lib/get-schematic-element-bounds.ts
|
|
1586
1682
|
var SCHEMATIC_TRACE_WIDTH = 0.1;
|
|
1587
1683
|
var SCHEMATIC_NET_LABEL_FONT_SIZE = 0.18;
|
|
@@ -2982,6 +3078,7 @@ export {
|
|
|
2982
3078
|
computeClearanceBetweenElements,
|
|
2983
3079
|
computeGapBetweenCopper,
|
|
2984
3080
|
copperPolygonsTouch,
|
|
3081
|
+
createBoardOwnerMap,
|
|
2985
3082
|
directionToVec,
|
|
2986
3083
|
distanceBetweenCircleAndCircle,
|
|
2987
3084
|
distanceBetweenCircleAndPolygon,
|