@tscircuit/pcb-viewer 1.11.151 → 1.11.152

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
@@ -4526,6 +4526,12 @@ var source_simple_power_source = source_component_base.extend({
4526
4526
  voltage
4527
4527
  });
4528
4528
  expectTypesMatch(true);
4529
+ var source_simple_fuse = source_component_base.extend({
4530
+ ftype: z.literal("simple_fuse"),
4531
+ current_rating_amps: z.number().describe("Nominal current in amps the fuse is rated for"),
4532
+ voltage_rating_volts: z.number().describe("Voltage rating in volts, e.g. \xB15V would be 5")
4533
+ });
4534
+ expectTypesMatch(true);
4529
4535
  var source_simple_battery = source_component_base.extend({
4530
4536
  ftype: z.literal("simple_battery"),
4531
4537
  capacity: battery_capacity
@@ -4634,6 +4640,7 @@ var any_source_component = z.union([
4634
4640
  source_simple_switch,
4635
4641
  source_simple_transistor,
4636
4642
  source_simple_mosfet,
4643
+ source_simple_fuse,
4637
4644
  source_project_metadata,
4638
4645
  source_missing_property_error,
4639
4646
  source_failed_to_create_component_error
@@ -4816,7 +4823,7 @@ var schematic_text = z.object({
4816
4823
  schematic_component_id: z.string().optional(),
4817
4824
  schematic_text_id: z.string(),
4818
4825
  text: z.string(),
4819
- font_size: z.number().default(1),
4826
+ font_size: z.number().default(0.18),
4820
4827
  position: z.object({
4821
4828
  x: distance,
4822
4829
  y: distance
@@ -7836,30 +7843,50 @@ for (const letter in svgAlphabet) {
7836
7843
  var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
7837
7844
  var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
7838
7845
  var getTextWidth = (text) => {
7839
- return text.text.length * text.size * LETTER_HEIGHT_TO_WIDTH_RATIO + (text.text.length - 1) * text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
7846
+ if (text.text.length === 0) return 0;
7847
+ const target_height = text.size * 0.7;
7848
+ const target_width_char = target_height * LETTER_HEIGHT_TO_WIDTH_RATIO;
7849
+ const space_between_chars = target_height * LETTER_HEIGHT_TO_SPACE_RATIO;
7850
+ return text.text.length * target_width_char + (text.text.length - 1) * space_between_chars;
7840
7851
  };
7841
7852
  var convertTextToLines = (text) => {
7842
- const strokeWidth = text.size / 8;
7843
- const letterWidth = text.size * LETTER_HEIGHT_TO_WIDTH_RATIO;
7844
- const letterSpace = text.size * LETTER_HEIGHT_TO_SPACE_RATIO;
7853
+ const target_height = text.size * 0.7;
7854
+ if (target_height <= 0 || text.text.length === 0) return [];
7855
+ const strokeWidth = target_height / 12;
7856
+ const centerline_span_y = Math.max(0, target_height - strokeWidth);
7857
+ const y_baseline_offset = strokeWidth / 2;
7858
+ const target_width_char = target_height * LETTER_HEIGHT_TO_WIDTH_RATIO;
7859
+ const centerline_span_x = Math.max(0, target_width_char - strokeWidth);
7860
+ const x_char_start_offset = strokeWidth / 2;
7861
+ const space_between_chars = target_height * LETTER_HEIGHT_TO_SPACE_RATIO;
7845
7862
  const lines = [];
7863
+ let current_x_origin_for_char_box = text.x;
7846
7864
  for (let letterIndex = 0; letterIndex < text.text.length; letterIndex++) {
7847
7865
  const letter = text.text[letterIndex];
7848
7866
  const letterLines = lineAlphabet[letter.toUpperCase()];
7849
- if (!letterLines) continue;
7850
- for (const { x1, y1, x2, y2 } of letterLines) {
7867
+ if (!letterLines) {
7868
+ current_x_origin_for_char_box += target_width_char + space_between_chars;
7869
+ continue;
7870
+ }
7871
+ for (const {
7872
+ x1: norm_x1,
7873
+ y1: norm_y1,
7874
+ x2: norm_x2,
7875
+ y2: norm_y2
7876
+ } of letterLines) {
7851
7877
  lines.push({
7852
7878
  _pcb_drawing_object_id: getNewPcbDrawingObjectId("line"),
7853
7879
  pcb_drawing_type: "line",
7854
- x1: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x1,
7855
- y1: text.y + text.size * y1,
7856
- x2: text.x + (letterWidth + letterSpace) * letterIndex + letterWidth * x2,
7857
- y2: text.y + text.size * y2,
7880
+ x1: current_x_origin_for_char_box + x_char_start_offset + centerline_span_x * norm_x1,
7881
+ y1: text.y + y_baseline_offset + centerline_span_y * norm_y1,
7882
+ x2: current_x_origin_for_char_box + x_char_start_offset + centerline_span_x * norm_x2,
7883
+ y2: text.y + y_baseline_offset + centerline_span_y * norm_y2,
7858
7884
  width: strokeWidth,
7859
7885
  layer: text.layer,
7860
7886
  unit: text.unit
7861
7887
  });
7862
7888
  }
7889
+ current_x_origin_for_char_box += target_width_char + space_between_chars;
7863
7890
  }
7864
7891
  return lines;
7865
7892
  };
@@ -7887,21 +7914,53 @@ var drawLine = (drawer, line) => {
7887
7914
  var drawText = (drawer, text) => {
7888
7915
  drawer.equip({
7889
7916
  fontSize: text.size,
7890
- color: text.layer
7917
+ color: getColor(text),
7918
+ layer: text.layer
7891
7919
  });
7892
7920
  let alignOffset = { x: 0, y: 0 };
7893
7921
  const textWidth = getTextWidth(text);
7894
7922
  const textHeight = text.size;
7895
- if (text.align === "top_left") {
7896
- alignOffset.y = -textHeight;
7897
- } else if (text.align === "bottom_right") {
7898
- alignOffset.x = -textWidth;
7899
- } else if (text.align === "top_right") {
7900
- alignOffset.x = -textWidth;
7901
- alignOffset.y = -textHeight;
7902
- } else if (text.align === "center") {
7903
- alignOffset.x = -textWidth / 2;
7904
- alignOffset.y = -textHeight / 2;
7923
+ switch (text.align) {
7924
+ case "top_left":
7925
+ alignOffset.x = 0;
7926
+ alignOffset.y = -textHeight;
7927
+ break;
7928
+ case "top_center":
7929
+ alignOffset.x = -textWidth / 2;
7930
+ alignOffset.y = -textHeight;
7931
+ break;
7932
+ case "top_right":
7933
+ alignOffset.x = -textWidth;
7934
+ alignOffset.y = -textHeight;
7935
+ break;
7936
+ case "center_left":
7937
+ alignOffset.x = 0;
7938
+ alignOffset.y = -textHeight / 2;
7939
+ break;
7940
+ case "center":
7941
+ alignOffset.x = -textWidth / 2;
7942
+ alignOffset.y = -textHeight / 2;
7943
+ break;
7944
+ case "center_right":
7945
+ alignOffset.x = -textWidth;
7946
+ alignOffset.y = -textHeight / 2;
7947
+ break;
7948
+ case "bottom_left":
7949
+ alignOffset.x = 0;
7950
+ alignOffset.y = 0;
7951
+ break;
7952
+ case "bottom_center":
7953
+ alignOffset.x = -textWidth / 2;
7954
+ alignOffset.y = 0;
7955
+ break;
7956
+ case "bottom_right":
7957
+ alignOffset.x = -textWidth;
7958
+ alignOffset.y = 0;
7959
+ break;
7960
+ default:
7961
+ alignOffset.x = 0;
7962
+ alignOffset.y = 0;
7963
+ break;
7905
7964
  }
7906
7965
  text.x ??= 0;
7907
7966
  text.y ??= 0;
@@ -9793,7 +9852,7 @@ import { css as css3 } from "@emotion/css";
9793
9852
  // package.json
9794
9853
  var package_default = {
9795
9854
  name: "@tscircuit/pcb-viewer",
9796
- version: "1.11.150",
9855
+ version: "1.11.151",
9797
9856
  main: "dist/index.js",
9798
9857
  type: "module",
9799
9858
  repository: "tscircuit/pcb-viewer",
@@ -9820,12 +9879,12 @@ var package_default = {
9820
9879
  "@storybook/react": "^8.0.6",
9821
9880
  "@swc/core": "^1.4.12",
9822
9881
  "@tscircuit/eagle-xml-converter": "^1.0.0",
9823
- "@tscircuit/props": "^0.0.187",
9882
+ "@tscircuit/props": "^0.0.192",
9824
9883
  "@tscircuit/soup-util": "^0.0.41",
9825
9884
  "@types/color": "^3.0.6",
9826
9885
  "@types/node": "18.7.23",
9827
9886
  "@types/react": "^18.3.3",
9828
- "circuit-json": "^0.0.186",
9887
+ "circuit-json": "^0.0.190",
9829
9888
  next: "^14.1.4",
9830
9889
  "pixi.js": "^8.6.6",
9831
9890
  react: "^18.2.0",
@@ -9843,7 +9902,7 @@ var package_default = {
9843
9902
  },
9844
9903
  dependencies: {
9845
9904
  "@emotion/css": "^11.11.2",
9846
- "@tscircuit/core": "^0.0.417",
9905
+ "@tscircuit/core": "^0.0.422",
9847
9906
  "@tscircuit/math-utils": "^0.0.18",
9848
9907
  "circuit-json-to-connectivity-map": "^0.0.22",
9849
9908
  "circuit-to-svg": "^0.0.130",