@tscircuit/pcb-viewer 1.8.1 → 1.9.0

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
@@ -10108,7 +10108,7 @@ var require_dist = __commonJS({
10108
10108
  route_thickness_mode: import_zod39.z.enum([
10109
10109
  "constant",
10110
10110
  "interpolated"
10111
- ]).default("interpolated").optional(),
10111
+ ]).default("constant").optional(),
10112
10112
  should_round_corners: import_zod39.z.boolean().optional(),
10113
10113
  route: import_zod39.z.array(import_zod39.z.union([
10114
10114
  import_zod39.z.object({
@@ -10118,7 +10118,7 @@ var require_dist = __commonJS({
10118
10118
  width: distance,
10119
10119
  start_pcb_port_id: import_zod39.z.string().optional(),
10120
10120
  end_pcb_port_id: import_zod39.z.string().optional(),
10121
- layer: import_zod39.z.string()
10121
+ layer: layer_ref
10122
10122
  }),
10123
10123
  import_zod39.z.object({
10124
10124
  route_type: import_zod39.z.literal("via"),
@@ -10286,21 +10286,25 @@ var require_dist = __commonJS({
10286
10286
  var import_zod54 = require_lib2();
10287
10287
  var pcb_keepout = import_zod54.z.object({
10288
10288
  type: import_zod54.z.literal("pcb_keepout"),
10289
- pcb_keepout_id: import_zod54.z.string(),
10290
- layer: import_zod54.z.array(import_zod54.z.string()).optional(),
10291
- // Specify layers where the keepout applies
10292
- description: import_zod54.z.string().optional()
10293
- }).and(import_zod54.z.object({
10294
10289
  shape: import_zod54.z.literal("rect"),
10295
10290
  x: distance,
10296
10291
  y: distance,
10297
10292
  width: distance,
10298
- height: distance
10293
+ height: distance,
10294
+ pcb_keepout_id: import_zod54.z.string(),
10295
+ layer: import_zod54.z.array(import_zod54.z.string()).optional(),
10296
+ // Specify layers where the keepout applies
10297
+ description: import_zod54.z.string().optional()
10299
10298
  }).or(import_zod54.z.object({
10299
+ type: import_zod54.z.literal("pcb_keepout"),
10300
10300
  shape: import_zod54.z.literal("circle"),
10301
10301
  center: point,
10302
- radius: distance
10303
- })));
10302
+ radius: distance,
10303
+ pcb_keepout_id: import_zod54.z.string(),
10304
+ layer: import_zod54.z.array(import_zod54.z.string()).optional(),
10305
+ // Specify layers where the keepout applies
10306
+ description: import_zod54.z.string().optional()
10307
+ }));
10304
10308
  var import_zod55 = require_lib2();
10305
10309
  var cad_component = import_zod55.z.object({
10306
10310
  type: import_zod55.z.literal("cad_component"),
@@ -10335,6 +10339,7 @@ var require_dist = __commonJS({
10335
10339
  pcb_component,
10336
10340
  pcb_hole,
10337
10341
  pcb_plated_hole,
10342
+ pcb_keepout,
10338
10343
  pcb_port,
10339
10344
  pcb_text,
10340
10345
  pcb_trace,
@@ -11781,16 +11786,13 @@ var drawRect = function(drawer, rect) {
11781
11786
  drawer.equip({
11782
11787
  color: rect.layer
11783
11788
  });
11784
- if (rect.align && rect.align !== "center") {
11785
- console.warn("Unhandled rect align", rect.align);
11786
- }
11787
- drawer.rect(rect.x, rect.y, rect.w, rect.h);
11789
+ drawer.rect(rect.x, rect.y, rect.w, rect.h, rect.mesh_fill);
11788
11790
  };
11789
11791
  var drawCircle = function(drawer, circle) {
11790
11792
  drawer.equip({
11791
11793
  color: circle.layer
11792
11794
  });
11793
- drawer.circle(circle.x, circle.y, circle.r);
11795
+ drawer.circle(circle.x, circle.y, circle.r, circle.mesh_fill);
11794
11796
  };
11795
11797
  var drawOval = function(drawer, oval) {
11796
11798
  drawer.equip({
@@ -11841,12 +11843,6 @@ var drawPrimitives = function(drawer, primitives) {
11841
11843
  return drawPrimitive(drawer, primitive);
11842
11844
  });
11843
11845
  };
11844
- // src/lib/util/scale-only.ts
11845
- var scaleOnly = function(mat) {
11846
- var value = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
11847
- if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
11848
- return value * Math.abs(mat.a);
11849
- };
11850
11846
  // src/lib/Drawer.ts
11851
11847
  var import_transformation_matrix = require("transformation-matrix");
11852
11848
  // src/lib/colors.ts
@@ -12080,6 +12076,12 @@ var colors_default = {
12080
12076
  worksheet: "rgb(192, 0, 0)"
12081
12077
  }
12082
12078
  };
12079
+ // src/lib/util/scale-only.ts
12080
+ var scaleOnly = function(mat) {
12081
+ var value = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
12082
+ if (Math.abs(mat.a) !== Math.abs(mat.d)) throw new Error("Cannot scale non-uniformly");
12083
+ return value * Math.abs(mat.a);
12084
+ };
12083
12085
  // src/lib/Drawer.ts
12084
12086
  var LAYER_NAME_TO_COLOR = _object_spread({
12085
12087
  // Standard colors, you shouldn't use these except for testing
@@ -12181,9 +12183,40 @@ var Drawer = /*#__PURE__*/ function() {
12181
12183
  }, aperture);
12182
12184
  }
12183
12185
  },
12186
+ {
12187
+ key: "drawMeshPattern",
12188
+ value: function drawMeshPattern(x, y, width, height, spacing) {
12189
+ var angle = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : 45;
12190
+ var ctx = this.getLayerCtx();
12191
+ var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
12192
+ x,
12193
+ y
12194
+ ]), 2), x1 = _ref[0], y1 = _ref[1];
12195
+ var _ref1 = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
12196
+ x + width,
12197
+ y + height
12198
+ ]), 2), x2 = _ref1[0], y2 = _ref1[1];
12199
+ var spacing$ = scaleOnly(this.transform, spacing);
12200
+ ctx.lineWidth = 1;
12201
+ ctx.strokeStyle = this.aperture.color;
12202
+ var drawLines = function(angle2) {
12203
+ var sin = Math.sin(angle2);
12204
+ var cos = Math.cos(angle2);
12205
+ var diag = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
12206
+ for(var i = -diag; i <= diag; i += spacing$){
12207
+ ctx.beginPath();
12208
+ ctx.moveTo(x1 + i * cos - diag * sin, y1 + i * sin + diag * cos);
12209
+ ctx.lineTo(x1 + i * cos + diag * sin, y1 + i * sin - diag * cos);
12210
+ ctx.stroke();
12211
+ }
12212
+ };
12213
+ drawLines(angle * Math.PI / 180);
12214
+ drawLines((angle + 90) * Math.PI / 180);
12215
+ }
12216
+ },
12184
12217
  {
12185
12218
  key: "rect",
12186
- value: function rect(x, y, w, h) {
12219
+ value: function rect(x, y, w, h, mesh_fill) {
12187
12220
  var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
12188
12221
  x - w / 2,
12189
12222
  y - h / 2
@@ -12194,12 +12227,22 @@ var Drawer = /*#__PURE__*/ function() {
12194
12227
  ]), 2), x2$ = _ref1[0], y2$ = _ref1[1];
12195
12228
  this.applyAperture();
12196
12229
  var ctx = this.getLayerCtx();
12197
- ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12230
+ if (mesh_fill) {
12231
+ ctx.save();
12232
+ ctx.beginPath();
12233
+ ctx.rect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12234
+ ctx.clip();
12235
+ this.drawMeshPattern(x - w / 2, y - h / 2, w, h, 0.15);
12236
+ ctx.restore();
12237
+ ctx.strokeRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12238
+ } else {
12239
+ ctx.fillRect(x1$, y1$, x2$ - x1$, y2$ - y1$);
12240
+ }
12198
12241
  }
12199
12242
  },
12200
12243
  {
12201
12244
  key: "circle",
12202
- value: function circle(x, y, r) {
12245
+ value: function circle(x, y, r, mesh_fill) {
12203
12246
  var r$ = scaleOnly(this.transform, r);
12204
12247
  var _ref = _sliced_to_array((0, import_transformation_matrix.applyToPoint)(this.transform, [
12205
12248
  x,
@@ -12207,10 +12250,21 @@ var Drawer = /*#__PURE__*/ function() {
12207
12250
  ]), 2), x$ = _ref[0], y$ = _ref[1];
12208
12251
  this.applyAperture();
12209
12252
  var ctx = this.getLayerCtx();
12210
- ctx.beginPath();
12211
- ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12212
- ctx.fill();
12213
- ctx.closePath();
12253
+ if (mesh_fill) {
12254
+ ctx.save();
12255
+ ctx.beginPath();
12256
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12257
+ ctx.clip();
12258
+ this.drawMeshPattern(x - r, y - r, r * 2, r * 2, 0.15);
12259
+ ctx.restore();
12260
+ ctx.beginPath();
12261
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12262
+ ctx.stroke();
12263
+ } else {
12264
+ ctx.beginPath();
12265
+ ctx.arc(x$, y$, r$, 0, 2 * Math.PI);
12266
+ ctx.fill();
12267
+ }
12214
12268
  }
12215
12269
  },
12216
12270
  {
@@ -12839,48 +12893,45 @@ var convertElementToPrimitives = function(element, allElements) {
12839
12893
  return [];
12840
12894
  }
12841
12895
  }
12842
- case "pcb_trace":
12896
+ case "pcb_keepout":
12843
12897
  {
12844
- var primitives = [];
12845
- if (element.route_thickness_mode === "constant") {
12846
- var prevX = null;
12847
- var prevY = null;
12848
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12849
- try {
12850
- for(var _iterator = element.route[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12851
- var route = _step.value;
12852
- if (route.route_type === "wire") {
12853
- if (prevX !== null && prevY !== null) {
12854
- primitives.push({
12855
- pcb_drawing_type: "line",
12856
- x1: prevX,
12857
- y1: prevY,
12858
- x2: route.x,
12859
- y2: route.y,
12860
- width: route.width,
12861
- squareCap: false,
12862
- layer: route.layer
12863
- });
12864
- }
12865
- prevX = route.x;
12866
- prevY = route.y;
12867
- }
12898
+ if (element.shape === "circle") {
12899
+ var center1 = element.center, radius1 = element.radius;
12900
+ return [
12901
+ {
12902
+ pcb_drawing_type: "circle",
12903
+ x: center1.x,
12904
+ y: center1.y,
12905
+ r: radius1,
12906
+ layer: "top",
12907
+ _element: element,
12908
+ _parent_pcb_component: _parent_pcb_component,
12909
+ _parent_source_component: _parent_source_component,
12910
+ mesh_fill: true
12868
12911
  }
12869
- } catch (err) {
12870
- _didIteratorError = true;
12871
- _iteratorError = err;
12872
- } finally{
12873
- try {
12874
- if (!_iteratorNormalCompletion && _iterator.return != null) {
12875
- _iterator.return();
12876
- }
12877
- } finally{
12878
- if (_didIteratorError) {
12879
- throw _iteratorError;
12880
- }
12912
+ ];
12913
+ } else if (element.shape === "rect") {
12914
+ var x6 = element.x, y6 = element.y, width2 = element.width, height2 = element.height;
12915
+ return [
12916
+ {
12917
+ pcb_drawing_type: "rect",
12918
+ x: x6,
12919
+ y: y6,
12920
+ w: width2,
12921
+ h: height2,
12922
+ layer: "drill",
12923
+ _element: element,
12924
+ _parent_pcb_component: _parent_pcb_component,
12925
+ _parent_source_component: _parent_source_component,
12926
+ mesh_fill: true
12881
12927
  }
12882
- }
12883
- } else if (element.route_thickness_mode === "interpolated") {
12928
+ ];
12929
+ }
12930
+ }
12931
+ case "pcb_trace":
12932
+ {
12933
+ var primitives = [];
12934
+ if (element.route_thickness_mode === "interpolated") {
12884
12935
  var strokeInput = element.route.map(function(r) {
12885
12936
  return {
12886
12937
  x: r.x,
@@ -12906,17 +12957,55 @@ var convertElementToPrimitives = function(element, allElements) {
12906
12957
  });
12907
12958
  }
12908
12959
  });
12960
+ return primitives;
12961
+ }
12962
+ var prevX = null;
12963
+ var prevY = null;
12964
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
12965
+ try {
12966
+ for(var _iterator = element.route[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
12967
+ var route = _step.value;
12968
+ if (route.route_type === "wire") {
12969
+ if (prevX !== null && prevY !== null) {
12970
+ primitives.push({
12971
+ pcb_drawing_type: "line",
12972
+ x1: prevX,
12973
+ y1: prevY,
12974
+ x2: route.x,
12975
+ y2: route.y,
12976
+ width: route.width,
12977
+ squareCap: false,
12978
+ layer: route.layer
12979
+ });
12980
+ }
12981
+ prevX = route.x;
12982
+ prevY = route.y;
12983
+ }
12984
+ }
12985
+ } catch (err) {
12986
+ _didIteratorError = true;
12987
+ _iteratorError = err;
12988
+ } finally{
12989
+ try {
12990
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
12991
+ _iterator.return();
12992
+ }
12993
+ } finally{
12994
+ if (_didIteratorError) {
12995
+ throw _iteratorError;
12996
+ }
12997
+ }
12909
12998
  }
12910
12999
  return primitives;
12911
13000
  }
12912
13001
  case "pcb_via":
12913
13002
  {
12914
- var x6 = element.x, y6 = element.y, outer_diameter1 = element.outer_diameter, hole_diameter2 = element.hole_diameter, from_layer = element.from_layer, to_layer = element.to_layer;
13003
+ var x7 = element.x, y7 = element.y, outer_diameter1 = element.outer_diameter, hole_diameter2 = element.hole_diameter, from_layer = element.from_layer, to_layer = element.to_layer;
12915
13004
  return [
12916
13005
  {
12917
13006
  pcb_drawing_type: "circle",
12918
- x: x6,
12919
- y: y6,
13007
+ x: x7,
13008
+ y: y7,
12920
13009
  r: outer_diameter1 / 2,
12921
13010
  layer: from_layer,
12922
13011
  _element: element,
@@ -12925,8 +13014,8 @@ var convertElementToPrimitives = function(element, allElements) {
12925
13014
  },
12926
13015
  {
12927
13016
  pcb_drawing_type: "circle",
12928
- x: x6,
12929
- y: y6,
13017
+ x: x7,
13018
+ y: y7,
12930
13019
  r: hole_diameter2 / 2,
12931
13020
  layer: "drill",
12932
13021
  _element: element,
@@ -12935,8 +13024,8 @@ var convertElementToPrimitives = function(element, allElements) {
12935
13024
  },
12936
13025
  {
12937
13026
  pcb_drawing_type: "circle",
12938
- x: x6,
12939
- y: y6,
13027
+ x: x7,
13028
+ y: y7,
12940
13029
  r: outer_diameter1 / 2,
12941
13030
  layer: to_layer,
12942
13031
  _element: element,
@@ -13567,7 +13656,7 @@ var import_soup2 = __toESM(require_dist());
13567
13656
  // package.json
13568
13657
  var package_default = {
13569
13658
  name: "@tscircuit/pcb-viewer",
13570
- version: "1.8.0",
13659
+ version: "1.8.2",
13571
13660
  main: "dist/index.js",
13572
13661
  repository: "tscircuit/pcb-viewer",
13573
13662
  license: "MIT",
@@ -13594,7 +13683,7 @@ var package_default = {
13594
13683
  "@tscircuit/eagle-xml-converter": "^0.0.6",
13595
13684
  "@tscircuit/props": "^0.0.46",
13596
13685
  "@tscircuit/react-fiber": "^1.1.25",
13597
- "@tscircuit/soup": "^0.0.58",
13686
+ "@tscircuit/soup": "^0.0.61",
13598
13687
  "@tscircuit/soup-util": "^0.0.13",
13599
13688
  "@types/node": "18.7.23",
13600
13689
  "@types/react": "^18.3.3",