circuit-to-svg 0.0.237 → 0.0.239

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.d.ts CHANGED
@@ -112,6 +112,8 @@ interface PinoutSvgContext {
112
112
  };
113
113
  styleScale: number;
114
114
  label_positions: Map<string, LabelPosition>;
115
+ svgWidth: number;
116
+ svgHeight: number;
115
117
  }
116
118
  declare function convertCircuitJsonToPinoutSvg(soup: AnyCircuitElement[], options?: Options$2): string;
117
119
 
package/dist/index.js CHANGED
@@ -2346,8 +2346,18 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
2346
2346
  if (hole.hole_shape === "pill") {
2347
2347
  const scaledWidth = hole.hole_width * Math.abs(transform.a);
2348
2348
  const scaledHeight = hole.hole_height * Math.abs(transform.a);
2349
- const radiusX = scaledWidth / 2;
2350
- const straightLength = scaledHeight - scaledWidth;
2349
+ const isHorizontal = scaledWidth > scaledHeight;
2350
+ const radius = Math.min(scaledWidth, scaledHeight) / 2;
2351
+ const straightLength = Math.abs(
2352
+ isHorizontal ? scaledWidth - scaledHeight : scaledHeight - scaledWidth
2353
+ );
2354
+ const pathD = isHorizontal ? (
2355
+ // Horizontal pill (wider than tall)
2356
+ `M${x - straightLength / 2},${y - radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`
2357
+ ) : (
2358
+ // Vertical pill (taller than wide)
2359
+ `M${x - radius},${y - straightLength / 2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`
2360
+ );
2351
2361
  return [
2352
2362
  {
2353
2363
  name: "path",
@@ -2355,7 +2365,7 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
2355
2365
  attributes: {
2356
2366
  class: "pcb-hole",
2357
2367
  fill: colorMap2.drill,
2358
- d: `M${x - radiusX},${y - straightLength / 2} v${straightLength} a${radiusX},${radiusX} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radiusX},${radiusX} 0 0 0 -${scaledWidth},0 z`,
2368
+ d: pathD,
2359
2369
  "data-type": "pcb_hole",
2360
2370
  "data-pcb-layer": "drill"
2361
2371
  },
@@ -2367,9 +2377,19 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
2367
2377
  if (hole.hole_shape === "rotated_pill") {
2368
2378
  const scaledWidth = hole.hole_width * Math.abs(transform.a);
2369
2379
  const scaledHeight = hole.hole_height * Math.abs(transform.a);
2370
- const radiusX = scaledWidth / 2;
2371
- const straightLength = scaledHeight - scaledWidth;
2372
2380
  const rotation = "ccw_rotation" in hole ? hole.ccw_rotation ?? 0 : 0;
2381
+ const isHorizontal = scaledWidth > scaledHeight;
2382
+ const radius = Math.min(scaledWidth, scaledHeight) / 2;
2383
+ const straightLength = Math.abs(
2384
+ isHorizontal ? scaledWidth - scaledHeight : scaledHeight - scaledWidth
2385
+ );
2386
+ const pathD = isHorizontal ? (
2387
+ // Horizontal pill (wider than tall)
2388
+ `M${-straightLength / 2},${-radius} h${straightLength} a${radius},${radius} 0 0 1 0,${scaledHeight} h-${straightLength} a${radius},${radius} 0 0 1 0,-${scaledHeight} z`
2389
+ ) : (
2390
+ // Vertical pill (taller than wide)
2391
+ `M${-radius},${-straightLength / 2} v${straightLength} a${radius},${radius} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radius},${radius} 0 0 0 -${scaledWidth},0 z`
2392
+ );
2373
2393
  return [
2374
2394
  {
2375
2395
  name: "path",
@@ -2377,7 +2397,7 @@ function createSvgObjectsFromPcbHole(hole, ctx) {
2377
2397
  attributes: {
2378
2398
  class: "pcb-hole",
2379
2399
  fill: colorMap2.drill,
2380
- d: `M${-radiusX},${-straightLength / 2} v${straightLength} a${radiusX},${radiusX} 0 0 0 ${scaledWidth},0 v-${straightLength} a${radiusX},${radiusX} 0 0 0 -${scaledWidth},0 z`,
2400
+ d: pathD,
2381
2401
  transform: `translate(${x} ${y}) rotate(${-rotation})`,
2382
2402
  "data-type": "pcb_hole",
2383
2403
  "data-pcb-layer": "drill"
@@ -2913,7 +2933,7 @@ function getSoftwareUsedString(circuitJson) {
2913
2933
  var package_default = {
2914
2934
  name: "circuit-to-svg",
2915
2935
  type: "module",
2916
- version: "0.0.236",
2936
+ version: "0.0.238",
2917
2937
  description: "Convert Circuit JSON to SVG",
2918
2938
  main: "dist/index.js",
2919
2939
  files: [
@@ -4339,6 +4359,10 @@ var BOARD_STROKE_COLOR = "rgba(0,0,0,0.9)";
4339
4359
  function createSvgObjectsFromPinoutBoard(pcbBoard, ctx) {
4340
4360
  const { transform, soup } = ctx;
4341
4361
  const { width, height, center, outline } = pcbBoard;
4362
+ const sourceBoard = soup.find(
4363
+ (elm) => elm.type === "source_board" && elm.title
4364
+ );
4365
+ const title = sourceBoard?.title;
4342
4366
  let path;
4343
4367
  if (outline && Array.isArray(outline) && outline.length >= 3) {
4344
4368
  path = outline.map((point, index) => {
@@ -4387,7 +4411,7 @@ function createSvgObjectsFromPinoutBoard(pcbBoard, ctx) {
4387
4411
  } else if (cutout.shape === "circle") {
4388
4412
  }
4389
4413
  }
4390
- return [
4414
+ const svgObjects = [
4391
4415
  {
4392
4416
  name: "path",
4393
4417
  type: "element",
@@ -4404,6 +4428,29 @@ function createSvgObjectsFromPinoutBoard(pcbBoard, ctx) {
4404
4428
  }
4405
4429
  }
4406
4430
  ];
4431
+ if (title) {
4432
+ const titleX = ctx.svgWidth / 2;
4433
+ const titleY = 30;
4434
+ svgObjects.push({
4435
+ name: "text",
4436
+ type: "element",
4437
+ value: "",
4438
+ children: [
4439
+ { name: "", type: "text", value: title, attributes: {}, children: [] }
4440
+ ],
4441
+ attributes: {
4442
+ x: titleX.toString(),
4443
+ y: titleY.toString(),
4444
+ "text-anchor": "middle",
4445
+ "font-size": "18px",
4446
+ "font-weight": "bold",
4447
+ "font-family": "Arial, sans-serif",
4448
+ fill: "black",
4449
+ class: "pinout-board-title"
4450
+ }
4451
+ });
4452
+ }
4453
+ return svgObjects;
4407
4454
  }
4408
4455
 
4409
4456
  // lib/pinout/svg-object-fns/create-svg-objects-from-pinout-component.ts
@@ -5398,6 +5445,9 @@ function convertCircuitJsonToPinoutSvg(soup, options) {
5398
5445
  const paddingMm = 2;
5399
5446
  let svgWidth = options?.width ?? 1200;
5400
5447
  let svgHeight = options?.height ?? 768;
5448
+ const boardTitle = soup.find(
5449
+ (e) => e.type === "source_board" && !!e.title
5450
+ )?.title;
5401
5451
  const board_bounds = { minX, minY, maxX, maxY };
5402
5452
  const pinout_ports = soup.filter(
5403
5453
  (elm) => elm.type === "pcb_port" && elm.is_board_pinout
@@ -5519,7 +5569,9 @@ function convertCircuitJsonToPinoutSvg(soup, options) {
5519
5569
  soup,
5520
5570
  board_bounds,
5521
5571
  styleScale,
5522
- label_positions
5572
+ label_positions,
5573
+ svgWidth,
5574
+ svgHeight
5523
5575
  };
5524
5576
  const svgObjects = soup.sort(
5525
5577
  (a, b) => (OBJECT_ORDER2.indexOf(a.type) ?? 9999) - (OBJECT_ORDER2.indexOf(b.type) ?? 9999)