@tscircuit/core 0.0.402 → 0.0.403

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +157 -157
  2. package/dist/index.js +449 -400
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -292,253 +292,7 @@ var extendCatalogue = (objects) => {
292
292
  };
293
293
 
294
294
  // lib/fiber/create-instance-from-react-element.ts
295
- import { identity } from "transformation-matrix";
296
- function prepare(object, state) {
297
- const instance = object;
298
- instance.__tsci = {
299
- ...state
300
- };
301
- return object;
302
- }
303
- var hostConfig = {
304
- supportsMutation: true,
305
- createInstance(type, props) {
306
- const target = catalogue[type];
307
- if (!target) {
308
- if (Object.keys(catalogue).length === 0) {
309
- throw new Error(
310
- "No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"
311
- );
312
- }
313
- throw new Error(
314
- `Unsupported component type (not registered in @tscircuit/core catalogue): "${type}" See CREATING_NEW_COMPONENTS.md`
315
- );
316
- }
317
- const instance = prepare(new target(props), {});
318
- return instance;
319
- },
320
- createTextInstance() {
321
- return {};
322
- },
323
- appendInitialChild(parentInstance, child) {
324
- parentInstance.add(child);
325
- },
326
- appendChild(parentInstance, child) {
327
- parentInstance.add(child);
328
- },
329
- appendChildToContainer(container, child) {
330
- container.add(child);
331
- },
332
- finalizeInitialChildren() {
333
- return false;
334
- },
335
- prepareUpdate() {
336
- return null;
337
- },
338
- shouldSetTextContent() {
339
- return false;
340
- },
341
- getRootHostContext() {
342
- return {};
343
- },
344
- getChildHostContext() {
345
- return {};
346
- },
347
- prepareForCommit() {
348
- return null;
349
- },
350
- resetAfterCommit() {
351
- },
352
- commitMount() {
353
- },
354
- commitUpdate() {
355
- },
356
- removeChild() {
357
- },
358
- clearContainer() {
359
- },
360
- supportsPersistence: false,
361
- getPublicInstance(instance) {
362
- return instance;
363
- },
364
- preparePortalMount(containerInfo) {
365
- throw new Error("Function not implemented.");
366
- },
367
- scheduleTimeout(fn, delay) {
368
- throw new Error("Function not implemented.");
369
- },
370
- cancelTimeout(id) {
371
- throw new Error("Function not implemented.");
372
- },
373
- noTimeout: void 0,
374
- isPrimaryRenderer: false,
375
- getInstanceFromNode(node) {
376
- throw new Error("Function not implemented.");
377
- },
378
- beforeActiveInstanceBlur() {
379
- throw new Error("Function not implemented.");
380
- },
381
- afterActiveInstanceBlur() {
382
- throw new Error("Function not implemented.");
383
- },
384
- prepareScopeUpdate: (scopeInstance, instance) => {
385
- throw new Error("Function not implemented.");
386
- },
387
- getInstanceFromScope: (scopeInstance) => {
388
- throw new Error("Function not implemented.");
389
- },
390
- detachDeletedInstance: (node) => {
391
- throw new Error("Function not implemented.");
392
- },
393
- // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
394
- getCurrentEventPriority: () => DefaultEventPriority,
395
- // @ts-expect-error
396
- // https://github.com/diegomura/react-pdf/blob/fabecc56727dfb6d590a3fa1e11f50250ecbbea1/packages/reconciler/src/reconciler-31.js#L57
397
- getCurrentUpdatePriority: () => DefaultEventPriority,
398
- resolveUpdatePriority: () => DefaultEventPriority,
399
- setCurrentUpdatePriority: () => {
400
- },
401
- maySuspendCommit: () => false,
402
- supportsHydration: false
403
- };
404
- var reconciler;
405
- if (React.version.startsWith("19.")) {
406
- reconciler = ReactReconciler(hostConfig);
407
- } else {
408
- reconciler = ReactReconciler18(hostConfig);
409
- }
410
- var createInstanceFromReactElement = (reactElm) => {
411
- const rootContainer = {
412
- children: [],
413
- props: {
414
- name: "$root"
415
- },
416
- add(instance) {
417
- instance.parent = this;
418
- this.children.push(instance);
419
- },
420
- computePcbGlobalTransform() {
421
- return identity();
422
- }
423
- };
424
- const containerErrors = [];
425
- const container = reconciler.createContainer(
426
- // TODO Replace with store like react-three-fiber
427
- // https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
428
- // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts#L168
429
- rootContainer,
430
- 0,
431
- null,
432
- false,
433
- null,
434
- "tsci",
435
- (error) => {
436
- console.log("Error in createContainer");
437
- console.error(error);
438
- containerErrors.push(error);
439
- },
440
- null
441
- );
442
- if (React.version.startsWith("19.")) {
443
- reconciler.updateContainerSync(reactElm, container, null, () => {
444
- });
445
- reconciler.flushSyncWork();
446
- } else {
447
- reconciler.updateContainer(reactElm, container, null, () => {
448
- });
449
- }
450
- if (containerErrors.length > 0) {
451
- throw containerErrors[0];
452
- }
453
- const rootInstance = reconciler.getPublicRootInstance(
454
- container
455
- );
456
- if (rootInstance) return rootInstance;
457
- return rootContainer.children[0];
458
- };
459
-
460
- // lib/soup/underscorifyPinStyles.ts
461
- import "circuit-json";
462
- import "zod";
463
-
464
- // lib/utils/schematic/parsePinNumberFromLabelsOrThrow.ts
465
- var parsePinNumberFromLabelsOrThrow = (pinNumberOrLabel, pinLabels) => {
466
- if (typeof pinNumberOrLabel === "number") {
467
- return pinNumberOrLabel;
468
- }
469
- if (pinNumberOrLabel.startsWith("pin")) {
470
- const pinNumber = Number(pinNumberOrLabel.slice(3));
471
- return pinNumber;
472
- }
473
- if (!pinLabels) {
474
- throw new Error(
475
- `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
476
- );
477
- }
478
- for (const pinNumberKey in pinLabels) {
479
- const aliases = Array.isArray(pinLabels[pinNumberKey]) ? pinLabels[pinNumberKey] : [pinLabels[pinNumberKey]];
480
- if (aliases.includes(pinNumberOrLabel)) {
481
- return Number(pinNumberKey.replace("pin", ""));
482
- }
483
- }
484
- throw new Error(
485
- `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
486
- );
487
- };
488
-
489
- // lib/soup/underscorifyPinStyles.ts
490
- var underscorifyPinStyles = (pinStyles, pinLabels) => {
491
- if (!pinStyles) return void 0;
492
- const underscorePinStyles = {};
493
- const mergedStyles = {};
494
- for (const [pinNameOrLabel, pinStyle] of Object.entries(pinStyles)) {
495
- const pinNumber = parsePinNumberFromLabelsOrThrow(pinNameOrLabel, pinLabels);
496
- mergedStyles[pinNumber] = {
497
- ...mergedStyles[pinNumber],
498
- ...pinStyle
499
- };
500
- }
501
- for (const [pinNumber, pinStyle] of Object.entries(mergedStyles)) {
502
- const pinKey = `pin${pinNumber}`;
503
- underscorePinStyles[pinKey] = {
504
- bottom_margin: pinStyle.bottomMargin,
505
- left_margin: pinStyle.leftMargin,
506
- right_margin: pinStyle.rightMargin,
507
- top_margin: pinStyle.topMargin
508
- };
509
- }
510
- return underscorePinStyles;
511
- };
512
-
513
- // lib/soup/underscorifyPortArrangement.ts
514
- var underscorifyPortArrangement = (portArrangement) => {
515
- if (!portArrangement) return void 0;
516
- if ("leftSide" in portArrangement || "rightSide" in portArrangement || "topSide" in portArrangement || "bottomSide" in portArrangement) {
517
- return {
518
- left_side: portArrangement.leftSide,
519
- right_side: portArrangement.rightSide,
520
- top_side: portArrangement.topSide,
521
- bottom_side: portArrangement.bottomSide
522
- };
523
- }
524
- if ("leftPinCount" in portArrangement || "rightPinCount" in portArrangement || "topPinCount" in portArrangement || "bottomPinCount" in portArrangement) {
525
- return {
526
- left_size: portArrangement.leftPinCount,
527
- right_size: portArrangement.rightPinCount,
528
- top_size: portArrangement.topPinCount,
529
- bottom_size: portArrangement.bottomPinCount
530
- };
531
- }
532
- if ("leftSize" in portArrangement || "rightSize" in portArrangement || "topSize" in portArrangement || "bottomSize" in portArrangement) {
533
- return {
534
- left_size: portArrangement.leftSize,
535
- right_size: portArrangement.rightSize,
536
- top_size: portArrangement.topSize,
537
- bottom_size: portArrangement.bottomSize
538
- };
539
- }
540
- return void 0;
541
- };
295
+ import { identity as identity2 } from "transformation-matrix";
542
296
 
543
297
  // lib/components/base-components/PrimitiveComponent/PrimitiveComponent.ts
544
298
  import "debug";
@@ -605,11 +359,11 @@ import {
605
359
  applyToPoint,
606
360
  compose,
607
361
  flipY,
608
- identity as identity2,
362
+ identity,
609
363
  rotate,
610
364
  translate
611
365
  } from "transformation-matrix";
612
- import { z as z2 } from "zod";
366
+ import { z } from "zod";
613
367
  import { selectOne, selectAll } from "css-select";
614
368
 
615
369
  // lib/components/base-components/PrimitiveComponent/cssSelectPrimitiveComponentAdapter.ts
@@ -733,7 +487,7 @@ var PrimitiveComponent2 = class extends Renderable {
733
487
  get config() {
734
488
  return {
735
489
  componentName: "",
736
- zodProps: z2.object({}).passthrough()
490
+ zodProps: z.object({}).passthrough()
737
491
  };
738
492
  }
739
493
  props;
@@ -843,7 +597,7 @@ var PrimitiveComponent2 = class extends Renderable {
843
597
  const manualPlacement = this.getSubcircuit()._getPcbManualPlacementForComponent(this);
844
598
  if (manualPlacement && this.props.pcbX === void 0 && this.props.pcbY === void 0) {
845
599
  return compose(
846
- this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity2(),
600
+ this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity(),
847
601
  compose(
848
602
  translate(manualPlacement.x, manualPlacement.y),
849
603
  rotate((props.pcbRotation ?? 0) * Math.PI / 180)
@@ -862,7 +616,7 @@ var PrimitiveComponent2 = class extends Renderable {
862
616
  translate(-containerCenter.x, -containerCenter.y)
863
617
  );
864
618
  return compose(
865
- this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity2(),
619
+ this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity(),
866
620
  flipY(),
867
621
  this.computePcbPropsTransform()
868
622
  );
@@ -870,7 +624,7 @@ var PrimitiveComponent2 = class extends Renderable {
870
624
  }
871
625
  }
872
626
  return compose(
873
- this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity2(),
627
+ this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity(),
874
628
  this.computePcbPropsTransform()
875
629
  );
876
630
  }
@@ -935,7 +689,7 @@ var PrimitiveComponent2 = class extends Renderable {
935
689
  const manualPlacementTransform = this._getSchematicGlobalManualPlacementTransform(this);
936
690
  if (manualPlacementTransform) return manualPlacementTransform;
937
691
  return compose(
938
- this.parent?.computeSchematicGlobalTransform?.() ?? identity2(),
692
+ this.parent?.computeSchematicGlobalTransform?.() ?? identity(),
939
693
  this.computeSchematicPropsTransform()
940
694
  );
941
695
  }
@@ -1044,7 +798,7 @@ var PrimitiveComponent2 = class extends Renderable {
1044
798
  if (isMatchingSelector(component, position.selector) || component.props.name === position.selector) {
1045
799
  if (position.relative_to === "group_center") {
1046
800
  return compose(
1047
- this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity2(),
801
+ this.parent?._computePcbGlobalTransformBeforeLayout() ?? identity(),
1048
802
  translate(position.center.x, position.center.y)
1049
803
  );
1050
804
  }
@@ -1194,152 +948,447 @@ var PrimitiveComponent2 = class extends Renderable {
1194
948
  this._cachedSelectAllQueries.set(selectorRaw, result);
1195
949
  return result;
1196
950
  }
1197
- const [firstpart, ...rest] = selector.split(" ");
1198
- const subcircuit = selectOne(firstpart, this, {
1199
- adapter: cssSelectPrimitiveComponentAdapterOnlySubcircuits
951
+ const [firstpart, ...rest] = selector.split(" ");
952
+ const subcircuit = selectOne(firstpart, this, {
953
+ adapter: cssSelectPrimitiveComponentAdapterOnlySubcircuits
954
+ });
955
+ if (!subcircuit) return [];
956
+ const result2 = subcircuit.selectAll(rest.join(" "));
957
+ this._cachedSelectAllQueries.set(selectorRaw, result2);
958
+ return result2;
959
+ }
960
+ _cachedSelectOneQueries = /* @__PURE__ */ new Map();
961
+ selectOne(selectorRaw, options) {
962
+ if (this._cachedSelectOneQueries.has(selectorRaw)) {
963
+ return this._cachedSelectOneQueries.get(selectorRaw);
964
+ }
965
+ const selector = preprocessSelector(selectorRaw);
966
+ if (options?.port) {
967
+ options.type = "port";
968
+ }
969
+ let result = null;
970
+ if (options?.type) {
971
+ const allMatching = selectAll(
972
+ selector,
973
+ this,
974
+ cssSelectOptionsInsideSubcircuit
975
+ );
976
+ result = allMatching.find(
977
+ (n) => n.lowercaseComponentName === options.type
978
+ );
979
+ }
980
+ result ??= selectOne(
981
+ selector,
982
+ this,
983
+ cssSelectOptionsInsideSubcircuit
984
+ );
985
+ if (result) {
986
+ this._cachedSelectOneQueries.set(selectorRaw, result);
987
+ return result;
988
+ }
989
+ const [firstpart, ...rest] = selector.split(" ");
990
+ const subcircuit = selectOne(firstpart, this, {
991
+ adapter: cssSelectPrimitiveComponentAdapterOnlySubcircuits
992
+ });
993
+ if (!subcircuit) return null;
994
+ result = subcircuit.selectOne(rest.join(" "), options);
995
+ this._cachedSelectOneQueries.set(selectorRaw, result);
996
+ return result;
997
+ }
998
+ getAvailablePcbLayers() {
999
+ if (this.isPcbPrimitive) {
1000
+ const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
1001
+ if ("layer" in this._parsedProps || this.componentName === "SmtPad") {
1002
+ const layer = maybeFlipLayer(this._parsedProps.layer ?? "top");
1003
+ return [layer];
1004
+ }
1005
+ if ("layers" in this._parsedProps) {
1006
+ return this._parsedProps.layers;
1007
+ }
1008
+ if (this.componentName === "PlatedHole") {
1009
+ return this.root?._getBoard()?.allLayers ?? ["top", "bottom"];
1010
+ }
1011
+ return [];
1012
+ }
1013
+ return [];
1014
+ }
1015
+ /**
1016
+ * Returns all descendants
1017
+ *
1018
+ * NOTE: This crosses subcircuit boundaries, you may want to use
1019
+ * getSelectableDescendants instead
1020
+ */
1021
+ getDescendants() {
1022
+ const descendants = [];
1023
+ for (const child of this.children) {
1024
+ descendants.push(child);
1025
+ descendants.push(...child.getDescendants());
1026
+ }
1027
+ return descendants;
1028
+ }
1029
+ /**
1030
+ * Returns all descendants that are accessible without crossing a subcircuit
1031
+ * boundary
1032
+ */
1033
+ getSelectableDescendants() {
1034
+ const descendants = [];
1035
+ for (const child of this.children) {
1036
+ if (child.isSubcircuit) {
1037
+ descendants.push(child);
1038
+ } else {
1039
+ descendants.push(child);
1040
+ descendants.push(...child.getSelectableDescendants());
1041
+ }
1042
+ }
1043
+ return descendants;
1044
+ }
1045
+ /**
1046
+ * Return the number of pins in this component, this is important for
1047
+ * NormalComponents
1048
+ */
1049
+ _getPinCount() {
1050
+ return 0;
1051
+ }
1052
+ /**
1053
+ * If this component represents a SchematicBox (like a Chip), return the
1054
+ * dimensions of the box, which allows computing the position of ports etc.
1055
+ */
1056
+ _getSchematicBoxDimensions() {
1057
+ return null;
1058
+ }
1059
+ // TODO we shouldn't need to override this, errors can be rendered and handled
1060
+ // by the Renderable class, however, the Renderable class currently doesn't
1061
+ // have access to the database or cleanup
1062
+ renderError(message) {
1063
+ if (typeof message === "string") {
1064
+ return super.renderError(message);
1065
+ }
1066
+ this.root?.db.pcb_placement_error.insert(message);
1067
+ }
1068
+ getString() {
1069
+ const { lowercaseComponentName: cname, _parsedProps: props, parent } = this;
1070
+ if (props?.pinNumber !== void 0 && parent?.props?.name && props?.name) {
1071
+ return `<${cname}#${this._renderId}(pin:${props.pinNumber} .${parent?.props.name}>.${props.name}) />`;
1072
+ }
1073
+ if (parent?.props?.name && props?.name) {
1074
+ return `<${cname}#${this._renderId}(.${parent?.props.name}>.${props?.name}) />`;
1075
+ }
1076
+ if (props?.from && props?.to) {
1077
+ return `<${cname}#${this._renderId}(from:${props.from} to:${props?.to}) />`;
1078
+ }
1079
+ if (props?.name) {
1080
+ return `<${cname}#${this._renderId} name=".${props?.name}" />`;
1081
+ }
1082
+ if (props?.portHints) {
1083
+ return `<${cname}#${this._renderId}(${props.portHints.map((ph) => `.${ph}`).join(", ")}) />`;
1084
+ }
1085
+ return `<${cname}#${this._renderId} />`;
1086
+ }
1087
+ get [Symbol.toStringTag]() {
1088
+ return this.getString();
1089
+ }
1090
+ [Symbol.for("nodejs.util.inspect.custom")]() {
1091
+ return this.getString();
1092
+ }
1093
+ };
1094
+
1095
+ // lib/components/primitive-components/ErrorPlaceholder.ts
1096
+ import { z as z2 } from "zod";
1097
+ var ErrorPlaceholderComponent = class extends PrimitiveComponent2 {
1098
+ constructor(props, error) {
1099
+ super(props);
1100
+ this._parsedProps = {
1101
+ ...props,
1102
+ error,
1103
+ type: props.type || "unknown",
1104
+ component_name: props.name,
1105
+ error_type: "source_failed_to_create_component_error",
1106
+ message: error instanceof Error ? error.message : String(error),
1107
+ pcb_center: {
1108
+ x: props.pcbX || 0,
1109
+ y: props.pcbY || 0
1110
+ },
1111
+ schematic_center: {
1112
+ x: props.schX || 0,
1113
+ y: props.schY || 0
1114
+ }
1115
+ };
1116
+ }
1117
+ get config() {
1118
+ return {
1119
+ componentName: "ErrorPlaceholder",
1120
+ zodProps: z2.object({}).passthrough()
1121
+ };
1122
+ }
1123
+ doInitialSourceRender() {
1124
+ if (this.root?.db) {
1125
+ this.root.db.source_failed_to_create_component_error.insert({
1126
+ component_name: this._parsedProps.component_name,
1127
+ message: this._parsedProps.message,
1128
+ pcb_center: this._parsedProps.pcb_center,
1129
+ schematic_center: this._parsedProps.schematic_center
1130
+ });
1131
+ }
1132
+ }
1133
+ };
1134
+ function createErrorPlaceholderComponent(props, error) {
1135
+ return new ErrorPlaceholderComponent(props, error);
1136
+ }
1137
+
1138
+ // lib/fiber/create-instance-from-react-element.ts
1139
+ function prepare(object, state) {
1140
+ const instance = object;
1141
+ instance.__tsci = {
1142
+ ...state
1143
+ };
1144
+ return object;
1145
+ }
1146
+ var hostConfig = {
1147
+ supportsMutation: true,
1148
+ createInstance(type, props) {
1149
+ const target = catalogue[type];
1150
+ if (!target) {
1151
+ if (Object.keys(catalogue).length === 0) {
1152
+ throw new Error(
1153
+ "No components registered in catalogue, did you forget to import lib/register-catalogue in your test file?"
1154
+ );
1155
+ }
1156
+ throw new Error(
1157
+ `Unsupported component type (not registered in @tscircuit/core catalogue): "${type}" See CREATING_NEW_COMPONENTS.md`
1158
+ );
1159
+ }
1160
+ try {
1161
+ const instance = prepare(new target(props), {});
1162
+ return instance;
1163
+ } catch (error) {
1164
+ return createErrorPlaceholderComponent(props, error);
1165
+ }
1166
+ },
1167
+ createTextInstance() {
1168
+ return {};
1169
+ },
1170
+ appendInitialChild(parentInstance, child) {
1171
+ parentInstance.add(child);
1172
+ },
1173
+ appendChild(parentInstance, child) {
1174
+ parentInstance.add(child);
1175
+ },
1176
+ appendChildToContainer(container, child) {
1177
+ container.add(child);
1178
+ },
1179
+ finalizeInitialChildren() {
1180
+ return false;
1181
+ },
1182
+ prepareUpdate() {
1183
+ return null;
1184
+ },
1185
+ shouldSetTextContent() {
1186
+ return false;
1187
+ },
1188
+ getRootHostContext() {
1189
+ return {};
1190
+ },
1191
+ getChildHostContext() {
1192
+ return {};
1193
+ },
1194
+ prepareForCommit() {
1195
+ return null;
1196
+ },
1197
+ resetAfterCommit() {
1198
+ },
1199
+ commitMount() {
1200
+ },
1201
+ commitUpdate() {
1202
+ },
1203
+ removeChild() {
1204
+ },
1205
+ clearContainer() {
1206
+ },
1207
+ supportsPersistence: false,
1208
+ getPublicInstance(instance) {
1209
+ return instance;
1210
+ },
1211
+ preparePortalMount(containerInfo) {
1212
+ throw new Error("Function not implemented.");
1213
+ },
1214
+ scheduleTimeout(fn, delay) {
1215
+ throw new Error("Function not implemented.");
1216
+ },
1217
+ cancelTimeout(id) {
1218
+ throw new Error("Function not implemented.");
1219
+ },
1220
+ noTimeout: void 0,
1221
+ isPrimaryRenderer: false,
1222
+ getInstanceFromNode(node) {
1223
+ throw new Error("Function not implemented.");
1224
+ },
1225
+ beforeActiveInstanceBlur() {
1226
+ throw new Error("Function not implemented.");
1227
+ },
1228
+ afterActiveInstanceBlur() {
1229
+ throw new Error("Function not implemented.");
1230
+ },
1231
+ prepareScopeUpdate: (scopeInstance, instance) => {
1232
+ throw new Error("Function not implemented.");
1233
+ },
1234
+ getInstanceFromScope: (scopeInstance) => {
1235
+ throw new Error("Function not implemented.");
1236
+ },
1237
+ detachDeletedInstance: (node) => {
1238
+ throw new Error("Function not implemented.");
1239
+ },
1240
+ // https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
1241
+ getCurrentEventPriority: () => DefaultEventPriority,
1242
+ // @ts-expect-error
1243
+ // https://github.com/diegomura/react-pdf/blob/fabecc56727dfb6d590a3fa1e11f50250ecbbea1/packages/reconciler/src/reconciler-31.js#L57
1244
+ getCurrentUpdatePriority: () => DefaultEventPriority,
1245
+ resolveUpdatePriority: () => DefaultEventPriority,
1246
+ setCurrentUpdatePriority: () => {
1247
+ },
1248
+ maySuspendCommit: () => false,
1249
+ supportsHydration: false
1250
+ };
1251
+ var reconciler;
1252
+ if (React.version.startsWith("19.")) {
1253
+ reconciler = ReactReconciler(hostConfig);
1254
+ } else {
1255
+ reconciler = ReactReconciler18(hostConfig);
1256
+ }
1257
+ var createInstanceFromReactElement = (reactElm) => {
1258
+ const rootContainer = {
1259
+ children: [],
1260
+ props: {
1261
+ name: "$root"
1262
+ },
1263
+ add(instance) {
1264
+ instance.parent = this;
1265
+ this.children.push(instance);
1266
+ },
1267
+ computePcbGlobalTransform() {
1268
+ return identity2();
1269
+ }
1270
+ };
1271
+ const containerErrors = [];
1272
+ const container = reconciler.createContainer(
1273
+ // TODO Replace with store like react-three-fiber
1274
+ // https://github.com/pmndrs/react-three-fiber/blob/a457290856f57741bf8beef4f6ff9dbf4879c0a5/packages/fiber/src/core/index.tsx#L172
1275
+ // https://github.com/pmndrs/react-three-fiber/blob/master/packages/fiber/src/core/store.ts#L168
1276
+ rootContainer,
1277
+ 0,
1278
+ null,
1279
+ false,
1280
+ null,
1281
+ "tsci",
1282
+ (error) => {
1283
+ console.log("Error in createContainer");
1284
+ console.error(error);
1285
+ containerErrors.push(error);
1286
+ },
1287
+ null
1288
+ );
1289
+ if (React.version.startsWith("19.")) {
1290
+ reconciler.updateContainerSync(reactElm, container, null, () => {
1200
1291
  });
1201
- if (!subcircuit) return [];
1202
- const result2 = subcircuit.selectAll(rest.join(" "));
1203
- this._cachedSelectAllQueries.set(selectorRaw, result2);
1204
- return result2;
1205
- }
1206
- _cachedSelectOneQueries = /* @__PURE__ */ new Map();
1207
- selectOne(selectorRaw, options) {
1208
- if (this._cachedSelectOneQueries.has(selectorRaw)) {
1209
- return this._cachedSelectOneQueries.get(selectorRaw);
1210
- }
1211
- const selector = preprocessSelector(selectorRaw);
1212
- if (options?.port) {
1213
- options.type = "port";
1214
- }
1215
- let result = null;
1216
- if (options?.type) {
1217
- const allMatching = selectAll(
1218
- selector,
1219
- this,
1220
- cssSelectOptionsInsideSubcircuit
1221
- );
1222
- result = allMatching.find(
1223
- (n) => n.lowercaseComponentName === options.type
1224
- );
1225
- }
1226
- result ??= selectOne(
1227
- selector,
1228
- this,
1229
- cssSelectOptionsInsideSubcircuit
1230
- );
1231
- if (result) {
1232
- this._cachedSelectOneQueries.set(selectorRaw, result);
1233
- return result;
1234
- }
1235
- const [firstpart, ...rest] = selector.split(" ");
1236
- const subcircuit = selectOne(firstpart, this, {
1237
- adapter: cssSelectPrimitiveComponentAdapterOnlySubcircuits
1292
+ reconciler.flushSyncWork();
1293
+ } else {
1294
+ reconciler.updateContainer(reactElm, container, null, () => {
1238
1295
  });
1239
- if (!subcircuit) return null;
1240
- result = subcircuit.selectOne(rest.join(" "), options);
1241
- this._cachedSelectOneQueries.set(selectorRaw, result);
1242
- return result;
1243
- }
1244
- getAvailablePcbLayers() {
1245
- if (this.isPcbPrimitive) {
1246
- const { maybeFlipLayer } = this._getPcbPrimitiveFlippedHelpers();
1247
- if ("layer" in this._parsedProps || this.componentName === "SmtPad") {
1248
- const layer = maybeFlipLayer(this._parsedProps.layer ?? "top");
1249
- return [layer];
1250
- }
1251
- if ("layers" in this._parsedProps) {
1252
- return this._parsedProps.layers;
1253
- }
1254
- if (this.componentName === "PlatedHole") {
1255
- return this.root?._getBoard()?.allLayers ?? ["top", "bottom"];
1256
- }
1257
- return [];
1258
- }
1259
- return [];
1260
1296
  }
1261
- /**
1262
- * Returns all descendants
1263
- *
1264
- * NOTE: This crosses subcircuit boundaries, you may want to use
1265
- * getSelectableDescendants instead
1266
- */
1267
- getDescendants() {
1268
- const descendants = [];
1269
- for (const child of this.children) {
1270
- descendants.push(child);
1271
- descendants.push(...child.getDescendants());
1272
- }
1273
- return descendants;
1297
+ if (containerErrors.length > 0) {
1298
+ throw containerErrors[0];
1274
1299
  }
1275
- /**
1276
- * Returns all descendants that are accessible without crossing a subcircuit
1277
- * boundary
1278
- */
1279
- getSelectableDescendants() {
1280
- const descendants = [];
1281
- for (const child of this.children) {
1282
- if (child.isSubcircuit) {
1283
- descendants.push(child);
1284
- } else {
1285
- descendants.push(child);
1286
- descendants.push(...child.getSelectableDescendants());
1287
- }
1288
- }
1289
- return descendants;
1300
+ const rootInstance = reconciler.getPublicRootInstance(
1301
+ container
1302
+ );
1303
+ if (rootInstance) return rootInstance;
1304
+ return rootContainer.children[0];
1305
+ };
1306
+
1307
+ // lib/soup/underscorifyPinStyles.ts
1308
+ import "circuit-json";
1309
+ import "zod";
1310
+
1311
+ // lib/utils/schematic/parsePinNumberFromLabelsOrThrow.ts
1312
+ var parsePinNumberFromLabelsOrThrow = (pinNumberOrLabel, pinLabels) => {
1313
+ if (typeof pinNumberOrLabel === "number") {
1314
+ return pinNumberOrLabel;
1290
1315
  }
1291
- /**
1292
- * Return the number of pins in this component, this is important for
1293
- * NormalComponents
1294
- */
1295
- _getPinCount() {
1296
- return 0;
1316
+ if (pinNumberOrLabel.startsWith("pin")) {
1317
+ const pinNumber = Number(pinNumberOrLabel.slice(3));
1318
+ return pinNumber;
1297
1319
  }
1298
- /**
1299
- * If this component represents a SchematicBox (like a Chip), return the
1300
- * dimensions of the box, which allows computing the position of ports etc.
1301
- */
1302
- _getSchematicBoxDimensions() {
1303
- return null;
1320
+ if (!pinLabels) {
1321
+ throw new Error(
1322
+ `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
1323
+ );
1304
1324
  }
1305
- // TODO we shouldn't need to override this, errors can be rendered and handled
1306
- // by the Renderable class, however, the Renderable class currently doesn't
1307
- // have access to the database or cleanup
1308
- renderError(message) {
1309
- if (typeof message === "string") {
1310
- return super.renderError(message);
1325
+ for (const pinNumberKey in pinLabels) {
1326
+ const aliases = Array.isArray(pinLabels[pinNumberKey]) ? pinLabels[pinNumberKey] : [pinLabels[pinNumberKey]];
1327
+ if (aliases.includes(pinNumberOrLabel)) {
1328
+ return Number(pinNumberKey.replace("pin", ""));
1311
1329
  }
1312
- this.root?.db.pcb_placement_error.insert(message);
1313
1330
  }
1314
- getString() {
1315
- const { lowercaseComponentName: cname, _parsedProps: props, parent } = this;
1316
- if (props?.pinNumber !== void 0 && parent?.props?.name && props?.name) {
1317
- return `<${cname}#${this._renderId}(pin:${props.pinNumber} .${parent?.props.name}>.${props.name}) />`;
1318
- }
1319
- if (parent?.props?.name && props?.name) {
1320
- return `<${cname}#${this._renderId}(.${parent?.props.name}>.${props?.name}) />`;
1321
- }
1322
- if (props?.from && props?.to) {
1323
- return `<${cname}#${this._renderId}(from:${props.from} to:${props?.to}) />`;
1324
- }
1325
- if (props?.name) {
1326
- return `<${cname}#${this._renderId} name=".${props?.name}" />`;
1327
- }
1328
- if (props?.portHints) {
1329
- return `<${cname}#${this._renderId}(${props.portHints.map((ph) => `.${ph}`).join(", ")}) />`;
1330
- }
1331
- return `<${cname}#${this._renderId} />`;
1331
+ throw new Error(
1332
+ `No pin labels provided and pin number or label is not a number: "${pinNumberOrLabel}"`
1333
+ );
1334
+ };
1335
+
1336
+ // lib/soup/underscorifyPinStyles.ts
1337
+ var underscorifyPinStyles = (pinStyles, pinLabels) => {
1338
+ if (!pinStyles) return void 0;
1339
+ const underscorePinStyles = {};
1340
+ const mergedStyles = {};
1341
+ for (const [pinNameOrLabel, pinStyle] of Object.entries(pinStyles)) {
1342
+ const pinNumber = parsePinNumberFromLabelsOrThrow(pinNameOrLabel, pinLabels);
1343
+ mergedStyles[pinNumber] = {
1344
+ ...mergedStyles[pinNumber],
1345
+ ...pinStyle
1346
+ };
1332
1347
  }
1333
- get [Symbol.toStringTag]() {
1334
- return this.getString();
1348
+ for (const [pinNumber, pinStyle] of Object.entries(mergedStyles)) {
1349
+ const pinKey = `pin${pinNumber}`;
1350
+ underscorePinStyles[pinKey] = {
1351
+ bottom_margin: pinStyle.bottomMargin,
1352
+ left_margin: pinStyle.leftMargin,
1353
+ right_margin: pinStyle.rightMargin,
1354
+ top_margin: pinStyle.topMargin
1355
+ };
1335
1356
  }
1336
- [Symbol.for("nodejs.util.inspect.custom")]() {
1337
- return this.getString();
1357
+ return underscorePinStyles;
1358
+ };
1359
+
1360
+ // lib/soup/underscorifyPortArrangement.ts
1361
+ var underscorifyPortArrangement = (portArrangement) => {
1362
+ if (!portArrangement) return void 0;
1363
+ if ("leftSide" in portArrangement || "rightSide" in portArrangement || "topSide" in portArrangement || "bottomSide" in portArrangement) {
1364
+ return {
1365
+ left_side: portArrangement.leftSide,
1366
+ right_side: portArrangement.rightSide,
1367
+ top_side: portArrangement.topSide,
1368
+ bottom_side: portArrangement.bottomSide
1369
+ };
1370
+ }
1371
+ if ("leftPinCount" in portArrangement || "rightPinCount" in portArrangement || "topPinCount" in portArrangement || "bottomPinCount" in portArrangement) {
1372
+ return {
1373
+ left_size: portArrangement.leftPinCount,
1374
+ right_size: portArrangement.rightPinCount,
1375
+ top_size: portArrangement.topPinCount,
1376
+ bottom_size: portArrangement.bottomPinCount
1377
+ };
1378
+ }
1379
+ if ("leftSize" in portArrangement || "rightSize" in portArrangement || "topSize" in portArrangement || "bottomSize" in portArrangement) {
1380
+ return {
1381
+ left_size: portArrangement.leftSize,
1382
+ right_size: portArrangement.rightSize,
1383
+ top_size: portArrangement.topSize,
1384
+ bottom_size: portArrangement.bottomSize
1385
+ };
1338
1386
  }
1387
+ return void 0;
1339
1388
  };
1340
1389
 
1341
1390
  // lib/components/primitive-components/Net.ts
1342
- import { z as z3 } from "zod";
1391
+ import { z as z4 } from "zod";
1343
1392
 
1344
1393
  // lib/utils/pairs.ts
1345
1394
  function pairs(arr) {
@@ -1352,8 +1401,8 @@ function pairs(arr) {
1352
1401
 
1353
1402
  // lib/components/primitive-components/Net.ts
1354
1403
  import { autoroute } from "@tscircuit/infgrid-ijump-astar";
1355
- var netProps = z3.object({
1356
- name: z3.string()
1404
+ var netProps = z4.object({
1405
+ name: z4.string()
1357
1406
  });
1358
1407
  var Net = class extends PrimitiveComponent2 {
1359
1408
  source_net_id;
@@ -1826,14 +1875,14 @@ var SilkscreenPath = class extends PrimitiveComponent2 {
1826
1875
  };
1827
1876
 
1828
1877
  // lib/components/primitive-components/PcbTrace.ts
1829
- import { z as z4 } from "zod";
1878
+ import { z as z5 } from "zod";
1830
1879
  import { pcb_trace_route_point } from "circuit-json";
1831
1880
  import { applyToPoint as applyToPoint3 } from "transformation-matrix";
1832
- var pcbTraceProps = z4.object({
1833
- route: z4.array(pcb_trace_route_point),
1881
+ var pcbTraceProps = z5.object({
1882
+ route: z5.array(pcb_trace_route_point),
1834
1883
  // If this primitive PcbTrace needs to be associated with a source_trace_id
1835
1884
  // it can be added as a prop here. For footprints, it's often not needed.
1836
- source_trace_id: z4.string().optional()
1885
+ source_trace_id: z5.string().optional()
1837
1886
  });
1838
1887
  var PcbTrace = class extends PrimitiveComponent2 {
1839
1888
  pcb_trace_id = null;
@@ -2403,7 +2452,7 @@ function getRelativeDirection(pointA, pointB) {
2403
2452
  // lib/components/primitive-components/Port/Port.ts
2404
2453
  import "schematic-symbols";
2405
2454
  import { applyToPoint as applyToPoint4, compose as compose3, translate as translate3 } from "transformation-matrix";
2406
- import { z as z5 } from "zod";
2455
+ import { z as z6 } from "zod";
2407
2456
 
2408
2457
  // lib/components/primitive-components/Port/areAllPcbPrimitivesOverlapping.ts
2409
2458
  var areAllPcbPrimitivesOverlapping = (pcbPrimitives) => {
@@ -2453,10 +2502,10 @@ var getCenterOfPcbPrimitives = (pcbPrimitives) => {
2453
2502
  };
2454
2503
 
2455
2504
  // lib/components/primitive-components/Port/Port.ts
2456
- var portProps = z5.object({
2457
- name: z5.string().optional(),
2458
- pinNumber: z5.number().optional(),
2459
- aliases: z5.array(z5.string()).optional()
2505
+ var portProps = z6.object({
2506
+ name: z6.string().optional(),
2507
+ pinNumber: z6.number().optional(),
2508
+ aliases: z6.array(z6.string()).optional()
2460
2509
  });
2461
2510
  var Port = class extends PrimitiveComponent2 {
2462
2511
  source_port_id = null;
@@ -3104,7 +3153,7 @@ import {
3104
3153
  isValidElement
3105
3154
  } from "react";
3106
3155
  import { symbols as symbols2 } from "schematic-symbols";
3107
- import { z as z7 } from "zod";
3156
+ import { z as z8 } from "zod";
3108
3157
 
3109
3158
  // lib/components/primitive-components/Footprint.ts
3110
3159
  import { footprintProps } from "@tscircuit/props";
@@ -4927,7 +4976,7 @@ searched component ${targetComponent.getString()}, which has ports: ${targetComp
4927
4976
 
4928
4977
  // lib/components/base-components/NormalComponent/NormalComponent.ts
4929
4978
  var debug3 = Debug4("tscircuit:core");
4930
- var rotation3 = z7.object({
4979
+ var rotation3 = z8.object({
4931
4980
  x: rotation,
4932
4981
  y: rotation,
4933
4982
  z: rotation
@@ -8174,7 +8223,7 @@ import { identity as identity4 } from "transformation-matrix";
8174
8223
  var package_default = {
8175
8224
  name: "@tscircuit/core",
8176
8225
  type: "module",
8177
- version: "0.0.401",
8226
+ version: "0.0.402",
8178
8227
  types: "dist/index.d.ts",
8179
8228
  main: "dist/index.js",
8180
8229
  module: "dist/index.js",