circuit-to-svg 0.0.298 → 0.0.299

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
@@ -4128,10 +4128,28 @@ function formatOffsetLabel(axis, offsetMm, displayOffset) {
4128
4128
  return `${axis}: ${valueStr}${unitSuffix}`;
4129
4129
  }
4130
4130
 
4131
+ // lib/utils/get-point-from-elm.ts
4132
+ function getPointFromElm(elm) {
4133
+ const candidate = elm?.anchor_position ?? elm?.center;
4134
+ if (candidate && typeof candidate.x === "number" && typeof candidate.y === "number") {
4135
+ return { x: candidate.x, y: candidate.y };
4136
+ }
4137
+ return void 0;
4138
+ }
4139
+
4131
4140
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-board.ts
4132
4141
  function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
4133
4142
  const { transform, colorMap: colorMap2, showSolderMask, circuitJson } = ctx;
4134
- const { width, height, center, outline } = pcbBoard;
4143
+ const {
4144
+ width,
4145
+ height,
4146
+ center,
4147
+ outline,
4148
+ position_mode,
4149
+ anchor_position: boardAnchorPosition,
4150
+ display_offset_x,
4151
+ display_offset_y
4152
+ } = pcbBoard;
4135
4153
  let path;
4136
4154
  if (outline && Array.isArray(outline) && outline.length >= 3) {
4137
4155
  path = outline.map((point, index) => {
@@ -4195,21 +4213,25 @@ function createSvgObjectsFromPcbBoard(pcbBoard, ctx) {
4195
4213
  "data-pcb-layer": "board"
4196
4214
  }
4197
4215
  });
4198
- if (ctx.showAnchorOffsets && circuitJson) {
4216
+ if (ctx.showAnchorOffsets && circuitJson && position_mode === "relative_to_panel_anchor") {
4199
4217
  const panel = circuitJson.find(
4200
4218
  (elm) => elm.type === "pcb_panel"
4201
4219
  );
4202
4220
  if (panel) {
4203
- const panelCenter = panel.center ?? { x: 0, y: 0 };
4204
- svgObjects.push(
4205
- ...createAnchorOffsetIndicators({
4206
- groupAnchorPosition: panelCenter,
4207
- componentPosition: center,
4208
- transform,
4209
- componentWidth: width,
4210
- componentHeight: height
4211
- })
4212
- );
4221
+ const panelAnchorPosition = getPointFromElm(panel);
4222
+ if (panelAnchorPosition) {
4223
+ svgObjects.push(
4224
+ ...createAnchorOffsetIndicators({
4225
+ groupAnchorPosition: panelAnchorPosition,
4226
+ componentPosition: boardAnchorPosition ?? center,
4227
+ transform,
4228
+ componentWidth: width,
4229
+ componentHeight: height,
4230
+ displayXOffset: display_offset_x,
4231
+ displayYOffset: display_offset_y
4232
+ })
4233
+ );
4234
+ }
4213
4235
  }
4214
4236
  }
4215
4237
  return svgObjects;
@@ -5407,17 +5429,6 @@ function createMajorGridPatternChildren(cellSize, majorCellSize, lineColor, majo
5407
5429
 
5408
5430
  // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-component.ts
5409
5431
  import { applyToPoint as applyToPoint31 } from "transformation-matrix";
5410
-
5411
- // lib/utils/get-point-from-elm.ts
5412
- function getPointFromElm(elm) {
5413
- const candidate = elm?.anchor_position ?? elm?.center;
5414
- if (candidate && typeof candidate.x === "number" && typeof candidate.y === "number") {
5415
- return { x: candidate.x, y: candidate.y };
5416
- }
5417
- return void 0;
5418
- }
5419
-
5420
- // lib/pcb/svg-object-fns/create-svg-objects-from-pcb-component.ts
5421
5432
  function createSvgObjectsFromPcbComponent(component, ctx) {
5422
5433
  const { transform, circuitJson } = ctx;
5423
5434
  const { center, width, height, rotation = 0 } = component;
@@ -5427,11 +5438,11 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
5427
5438
  const transformStr = `translate(${x}, ${y}) rotate(${-rotation}) scale(1, -1)`;
5428
5439
  const svgObjects = [];
5429
5440
  if (ctx.showAnchorOffsets && circuitJson && component.position_mode === "relative_to_group_anchor" && (component.positioned_relative_to_pcb_group_id || component.positioned_relative_to_pcb_board_id)) {
5430
- const anchorPosition = getAnchorPosition(component, circuitJson);
5431
- if (anchorPosition) {
5441
+ const parentAnchorPosition = getParentAnchorPosition(component, circuitJson);
5442
+ if (parentAnchorPosition) {
5432
5443
  svgObjects.push(
5433
5444
  ...createAnchorOffsetIndicators({
5434
- groupAnchorPosition: anchorPosition,
5445
+ groupAnchorPosition: parentAnchorPosition,
5435
5446
  componentPosition: center,
5436
5447
  transform,
5437
5448
  componentWidth: width,
@@ -5474,7 +5485,7 @@ function createSvgObjectsFromPcbComponent(component, ctx) {
5474
5485
  });
5475
5486
  return svgObjects;
5476
5487
  }
5477
- function getAnchorPosition(component, circuitJson) {
5488
+ function getParentAnchorPosition(component, circuitJson) {
5478
5489
  if (component.positioned_relative_to_pcb_group_id) {
5479
5490
  const pcbGroup = circuitJson.find(
5480
5491
  (elm) => elm.type === "pcb_group" && elm.pcb_group_id === component.positioned_relative_to_pcb_group_id
@@ -5501,11 +5512,11 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
5501
5512
  const { center, width, height } = pcbGroup;
5502
5513
  const svgObjects = [];
5503
5514
  if (ctx.showAnchorOffsets && pcbGroup.position_mode === "relative_to_group_anchor" && circuitJson) {
5504
- const anchorPosition = getAnchorPosition2(pcbGroup, circuitJson);
5505
- if (anchorPosition) {
5515
+ const parentAnchorPosition = getParentAnchorPosition2(pcbGroup, circuitJson);
5516
+ if (parentAnchorPosition) {
5506
5517
  svgObjects.push(
5507
5518
  ...createAnchorOffsetIndicators({
5508
- groupAnchorPosition: anchorPosition,
5519
+ groupAnchorPosition: parentAnchorPosition,
5509
5520
  componentPosition: pcbGroup.anchor_position ?? pcbGroup.center,
5510
5521
  transform,
5511
5522
  componentWidth: pcbGroup.width,
@@ -5586,7 +5597,7 @@ function createSvgObjectsFromPcbGroup(pcbGroup, ctx) {
5586
5597
  svgObjects.push(svgObject);
5587
5598
  return svgObjects;
5588
5599
  }
5589
- function getAnchorPosition2(group, circuitJson) {
5600
+ function getParentAnchorPosition2(group, circuitJson) {
5590
5601
  if (group.positioned_relative_to_pcb_group_id) {
5591
5602
  const pcbGroup = circuitJson.find(
5592
5603
  (elm) => elm.type === "pcb_group" && elm.pcb_group_id === group.positioned_relative_to_pcb_group_id
@@ -5616,7 +5627,7 @@ function getSoftwareUsedString(circuitJson) {
5616
5627
  var package_default = {
5617
5628
  name: "circuit-to-svg",
5618
5629
  type: "module",
5619
- version: "0.0.297",
5630
+ version: "0.0.298",
5620
5631
  description: "Convert Circuit JSON to SVG",
5621
5632
  main: "dist/index.js",
5622
5633
  files: [
@@ -5639,7 +5650,7 @@ var package_default = {
5639
5650
  "@vitejs/plugin-react": "5.0.0",
5640
5651
  biome: "^0.3.3",
5641
5652
  "bun-match-svg": "^0.0.12",
5642
- "circuit-json": "^0.0.335",
5653
+ "circuit-json": "^0.0.342",
5643
5654
  esbuild: "^0.20.2",
5644
5655
  "performance-now": "^2.1.0",
5645
5656
  react: "19.1.0",