@tscircuit/pcb-viewer 1.11.274 → 1.11.275

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
@@ -9386,6 +9386,14 @@ import { lineAlphabet, svgAlphabet } from "@tscircuit/alphabet";
9386
9386
  // src/lib/convert-text-to-lines.ts
9387
9387
  var LETTER_HEIGHT_TO_WIDTH_RATIO = 0.6;
9388
9388
  var LETTER_HEIGHT_TO_SPACE_RATIO = 0.2;
9389
+ var LOWERCASE_BASELINE_OFFSET = (() => {
9390
+ const referenceLetters = ["a", "c", "e", "m", "n", "o", "r", "s", "u", "x"];
9391
+ const offsets = referenceLetters.map((letter) => lineAlphabet[letter]).filter((lines) => lines && lines.length > 0).map(
9392
+ (lines) => Math.min(...lines.map((line) => Math.min(line.y1, line.y2)))
9393
+ );
9394
+ return offsets.length > 0 ? Math.min(...offsets) : 0;
9395
+ })();
9396
+ var getBaselineOffsetForLetter = (letter) => letter >= "a" && letter <= "z" ? LOWERCASE_BASELINE_OFFSET : 0;
9389
9397
  var getTextGeometry = (text) => {
9390
9398
  const target_height = text.size * 0.7;
9391
9399
  const target_width_char = target_height * LETTER_HEIGHT_TO_WIDTH_RATIO;
@@ -9399,7 +9407,9 @@ var getTextGeometry = (text) => {
9399
9407
  return line.length * target_width_char + (line.length - 1) * space_between_chars;
9400
9408
  }) : [];
9401
9409
  const width = line_widths.length > 0 ? Math.max(...line_widths) : 0;
9402
- const height = line_count > 0 ? line_count * target_height + (line_count - 1) * space_between_lines : 0;
9410
+ const hasLowercase = /[a-z]/.test(text.text);
9411
+ const baselineOffset = hasLowercase ? LOWERCASE_BASELINE_OFFSET * target_height : 0;
9412
+ const height = line_count > 0 ? line_count * target_height + (line_count - 1) * space_between_lines + baselineOffset : 0;
9403
9413
  return {
9404
9414
  text_lines,
9405
9415
  line_count,
@@ -9439,6 +9449,7 @@ var convertTextToLines = (text) => {
9439
9449
  for (let letterIndex = 0; letterIndex < text_lines[lineIndex].length; letterIndex++) {
9440
9450
  const letter = text_lines[lineIndex][letterIndex];
9441
9451
  const letterLines = lineAlphabet[letter] ?? lineAlphabet[letter.toUpperCase()];
9452
+ const baselineOffset = getBaselineOffsetForLetter(letter);
9442
9453
  if (!letterLines) {
9443
9454
  current_x_origin_for_char_box += target_width_char + space_between_chars;
9444
9455
  continue;
@@ -9449,13 +9460,15 @@ var convertTextToLines = (text) => {
9449
9460
  x2: norm_x2,
9450
9461
  y2: norm_y2
9451
9462
  } of letterLines) {
9463
+ const adjusted_y1 = norm_y1 - baselineOffset;
9464
+ const adjusted_y2 = norm_y2 - baselineOffset;
9452
9465
  lines.push({
9453
9466
  _pcb_drawing_object_id: getNewPcbDrawingObjectId("line"),
9454
9467
  pcb_drawing_type: "line",
9455
9468
  x1: current_x_origin_for_char_box + target_width_char * norm_x1,
9456
- y1: text.y + lineYOffset + target_height * norm_y1,
9469
+ y1: text.y + lineYOffset + target_height * adjusted_y1,
9457
9470
  x2: current_x_origin_for_char_box + target_width_char * norm_x2,
9458
- y2: text.y + lineYOffset + target_height * norm_y2,
9471
+ y2: text.y + lineYOffset + target_height * adjusted_y2,
9459
9472
  width: strokeWidth,
9460
9473
  layer: text.layer,
9461
9474
  unit: text.unit,
@@ -13292,7 +13305,7 @@ import { css as css3 } from "@emotion/css";
13292
13305
  // package.json
13293
13306
  var package_default = {
13294
13307
  name: "@tscircuit/pcb-viewer",
13295
- version: "1.11.273",
13308
+ version: "1.11.274",
13296
13309
  main: "dist/index.js",
13297
13310
  type: "module",
13298
13311
  repository: "tscircuit/pcb-viewer",