circuit-to-svg 0.0.179 → 0.0.181

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1495,7 +1495,7 @@ function getSoftwareUsedString(circuitJson) {
1495
1495
  var package_default = {
1496
1496
  name: "circuit-to-svg",
1497
1497
  type: "module",
1498
- version: "0.0.178",
1498
+ version: "0.0.180",
1499
1499
  description: "Convert Circuit JSON to SVG",
1500
1500
  main: "dist/index.js",
1501
1501
  files: [
@@ -1522,7 +1522,7 @@ var package_default = {
1522
1522
  react: "19.1.0",
1523
1523
  "react-cosmos": "7.0.0",
1524
1524
  "react-cosmos-plugin-vite": "7.0.0",
1525
- tscircuit: "^0.0.606",
1525
+ tscircuit: "^0.0.609",
1526
1526
  tsup: "^8.0.2",
1527
1527
  typescript: "^5.4.5",
1528
1528
  "vite-tsconfig-paths": "^5.0.1"
@@ -4570,6 +4570,29 @@ import "@tscircuit/circuit-json-util";
4570
4570
  import { applyToPoint as applyToPoint30 } from "transformation-matrix";
4571
4571
  import { su as su5 } from "@tscircuit/circuit-json-util";
4572
4572
  var PIN_CIRCLE_RADIUS_MM = 0.02;
4573
+ var createArrow = (tip, angle, size, color, strokeWidth) => {
4574
+ const arrowAngle = Math.PI / 6;
4575
+ const p1 = {
4576
+ x: tip.x - size * Math.cos(angle - arrowAngle),
4577
+ y: tip.y - size * Math.sin(angle - arrowAngle)
4578
+ };
4579
+ const p2 = {
4580
+ x: tip.x - size * Math.cos(angle + arrowAngle),
4581
+ y: tip.y - size * Math.sin(angle + arrowAngle)
4582
+ };
4583
+ return {
4584
+ name: "polygon",
4585
+ type: "element",
4586
+ attributes: {
4587
+ points: `${tip.x},${tip.y} ${p1.x},${p1.y} ${p2.x},${p2.y}`,
4588
+ fill: "white",
4589
+ stroke: color,
4590
+ "stroke-width": `${strokeWidth}px`
4591
+ },
4592
+ value: "",
4593
+ children: []
4594
+ };
4595
+ };
4573
4596
  var createSvgObjectsForSchPortBoxLine = ({
4574
4597
  schPort,
4575
4598
  schComponent,
@@ -4669,6 +4692,69 @@ var createSvgObjectsForSchPortBoxLine = ({
4669
4692
  },
4670
4693
  children: pinChildren
4671
4694
  });
4695
+ const { has_input_arrow, has_output_arrow } = schPort;
4696
+ if ((has_input_arrow || has_output_arrow) && schPort.side_of_component) {
4697
+ const arrowSize = Math.abs(transform.a) * 0.15;
4698
+ const arrowColor = colorMap.schematic.component_outline;
4699
+ const arrowAxialLength = arrowSize * Math.cos(Math.PI / 6);
4700
+ const strokeWidth = getSchStrokeSize(transform) / 2;
4701
+ let inputAngleRads = 0;
4702
+ let outputAngleRads = 0;
4703
+ if (schPort.side_of_component === "left") {
4704
+ inputAngleRads = 0;
4705
+ outputAngleRads = Math.PI;
4706
+ } else if (schPort.side_of_component === "right") {
4707
+ inputAngleRads = Math.PI;
4708
+ outputAngleRads = 0;
4709
+ } else if (schPort.side_of_component === "top") {
4710
+ inputAngleRads = Math.PI / 2;
4711
+ outputAngleRads = -Math.PI / 2;
4712
+ } else if (schPort.side_of_component === "bottom") {
4713
+ inputAngleRads = -Math.PI / 2;
4714
+ outputAngleRads = Math.PI / 2;
4715
+ }
4716
+ const both = has_input_arrow && has_output_arrow;
4717
+ let inputArrowTip = { ...screenRealEdgePos };
4718
+ let outputArrowBase = { ...screenRealEdgePos };
4719
+ if (both) {
4720
+ const offset = arrowAxialLength;
4721
+ if (schPort.side_of_component === "left") {
4722
+ outputArrowBase.x -= offset;
4723
+ } else if (schPort.side_of_component === "right") {
4724
+ outputArrowBase.x += offset;
4725
+ } else if (schPort.side_of_component === "top") {
4726
+ outputArrowBase.y -= offset;
4727
+ } else if (schPort.side_of_component === "bottom") {
4728
+ outputArrowBase.y += offset;
4729
+ }
4730
+ }
4731
+ if (has_input_arrow) {
4732
+ svgObjects.push(
4733
+ createArrow(
4734
+ inputArrowTip,
4735
+ inputAngleRads,
4736
+ arrowSize,
4737
+ arrowColor,
4738
+ strokeWidth
4739
+ )
4740
+ );
4741
+ }
4742
+ if (has_output_arrow) {
4743
+ const outputArrowTip = {
4744
+ x: outputArrowBase.x + arrowSize * Math.cos(outputAngleRads),
4745
+ y: outputArrowBase.y + arrowSize * Math.sin(outputAngleRads)
4746
+ };
4747
+ svgObjects.push(
4748
+ createArrow(
4749
+ outputArrowTip,
4750
+ outputAngleRads,
4751
+ arrowSize,
4752
+ arrowColor,
4753
+ strokeWidth
4754
+ )
4755
+ );
4756
+ }
4757
+ }
4672
4758
  return svgObjects;
4673
4759
  };
4674
4760
 
@@ -5154,7 +5240,8 @@ function createSchematicTrace({
5154
5240
  }) {
5155
5241
  const edges = trace.edges;
5156
5242
  if (edges.length === 0) return [];
5157
- const svgObjects = [];
5243
+ const baseObjects = [];
5244
+ const overlayObjects = [];
5158
5245
  let path = "";
5159
5246
  for (let edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {
5160
5247
  const edge = edges[edgeIndex];
@@ -5173,6 +5260,38 @@ function createSchematicTrace({
5173
5260
  path += ` L ${screenToX} ${screenToY}`;
5174
5261
  }
5175
5262
  }
5263
+ if (path) {
5264
+ baseObjects.push({
5265
+ name: "path",
5266
+ type: "element",
5267
+ attributes: {
5268
+ d: path,
5269
+ class: "trace-invisible-hover-outline",
5270
+ stroke: colorMap2.schematic.wire,
5271
+ fill: "none",
5272
+ "stroke-width": `${getSchStrokeSize(transform) * 8}px`,
5273
+ "stroke-linecap": "round",
5274
+ opacity: "0",
5275
+ "stroke-linejoin": "round"
5276
+ },
5277
+ value: "",
5278
+ children: []
5279
+ });
5280
+ baseObjects.push({
5281
+ name: "path",
5282
+ type: "element",
5283
+ attributes: {
5284
+ d: path,
5285
+ stroke: colorMap2.schematic.wire,
5286
+ fill: "none",
5287
+ "stroke-width": `${getSchStrokeSize(transform)}px`,
5288
+ "stroke-linecap": "round",
5289
+ "stroke-linejoin": "round"
5290
+ },
5291
+ value: "",
5292
+ children: []
5293
+ });
5294
+ }
5176
5295
  for (const edge of edges) {
5177
5296
  if (!edge.is_crossing) continue;
5178
5297
  const [screenFromX, screenFromY] = applyToPoint38(transform, [
@@ -5193,7 +5312,7 @@ function createSchematicTrace({
5193
5312
  const perpY = dx / len * hopHeight;
5194
5313
  const controlX = midX + perpX;
5195
5314
  const controlY = midY - Math.abs(perpY);
5196
- svgObjects.push({
5315
+ overlayObjects.push({
5197
5316
  name: "path",
5198
5317
  type: "element",
5199
5318
  attributes: {
@@ -5202,12 +5321,12 @@ function createSchematicTrace({
5202
5321
  stroke: colorMap2.schematic.background,
5203
5322
  fill: "none",
5204
5323
  "stroke-width": `${getSchStrokeSize(transform) * 1.5}px`,
5205
- "stroke-linecap": "round"
5324
+ "stroke-linecap": "butt"
5206
5325
  },
5207
5326
  value: "",
5208
5327
  children: []
5209
5328
  });
5210
- svgObjects.push({
5329
+ overlayObjects.push({
5211
5330
  name: "path",
5212
5331
  type: "element",
5213
5332
  attributes: {
@@ -5221,45 +5340,13 @@ function createSchematicTrace({
5221
5340
  children: []
5222
5341
  });
5223
5342
  }
5224
- if (path) {
5225
- svgObjects.push({
5226
- name: "path",
5227
- type: "element",
5228
- attributes: {
5229
- d: path,
5230
- class: "trace-invisible-hover-outline",
5231
- stroke: colorMap2.schematic.wire,
5232
- fill: "none",
5233
- "stroke-width": `${getSchStrokeSize(transform) * 8}px`,
5234
- "stroke-linecap": "round",
5235
- opacity: "0",
5236
- "stroke-linejoin": "round"
5237
- },
5238
- value: "",
5239
- children: []
5240
- });
5241
- svgObjects.push({
5242
- name: "path",
5243
- type: "element",
5244
- attributes: {
5245
- d: path,
5246
- stroke: colorMap2.schematic.wire,
5247
- fill: "none",
5248
- "stroke-width": `${getSchStrokeSize(transform)}px`,
5249
- "stroke-linecap": "round",
5250
- "stroke-linejoin": "round"
5251
- },
5252
- value: "",
5253
- children: []
5254
- });
5255
- }
5256
5343
  if (trace.junctions) {
5257
5344
  for (const junction of trace.junctions) {
5258
5345
  const [screenX, screenY] = applyToPoint38(transform, [
5259
5346
  junction.x,
5260
5347
  junction.y
5261
5348
  ]);
5262
- svgObjects.push({
5349
+ overlayObjects.push({
5263
5350
  name: "circle",
5264
5351
  type: "element",
5265
5352
  attributes: {
@@ -5281,10 +5368,23 @@ function createSchematicTrace({
5281
5368
  value: "",
5282
5369
  attributes: {
5283
5370
  class: "trace",
5371
+ "data-layer": "base",
5372
+ "data-circuit-json-type": "schematic_trace",
5373
+ "data-schematic-trace-id": trace.schematic_trace_id
5374
+ },
5375
+ children: baseObjects
5376
+ },
5377
+ {
5378
+ name: "g",
5379
+ type: "element",
5380
+ value: "",
5381
+ attributes: {
5382
+ class: "trace-overlays",
5383
+ "data-layer": "overlay",
5284
5384
  "data-circuit-json-type": "schematic_trace",
5285
5385
  "data-schematic-trace-id": trace.schematic_trace_id
5286
5386
  },
5287
- children: svgObjects
5387
+ children: overlayObjects
5288
5388
  }
5289
5389
  ];
5290
5390
  }
@@ -6113,9 +6213,16 @@ function convertCircuitJsonToSchematicSvg(circuitJson, options) {
6113
6213
  );
6114
6214
  }
6115
6215
  }
6216
+ const schTraceBaseSvgs = schTraceSvgs.filter(
6217
+ (o) => o.attributes?.["data-layer"] !== "overlay"
6218
+ );
6219
+ const schTraceOverlaySvgs = schTraceSvgs.filter(
6220
+ (o) => o.attributes?.["data-layer"] === "overlay"
6221
+ );
6116
6222
  svgChildren.push(
6117
6223
  ...schDebugObjectSvgs,
6118
- ...schTraceSvgs,
6224
+ ...schTraceBaseSvgs,
6225
+ ...schTraceOverlaySvgs,
6119
6226
  ...schComponentSvgs,
6120
6227
  ...schPortHoverSvgs,
6121
6228
  ...schNetLabel,