@tscircuit/pcb-viewer 1.11.272 → 1.11.274

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,52 +9386,84 @@ 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 getTextWidth = (text) => {
9390
- if (text.text.length === 0) return 0;
9389
+ var getTextGeometry = (text) => {
9391
9390
  const target_height = text.size * 0.7;
9392
9391
  const target_width_char = target_height * LETTER_HEIGHT_TO_WIDTH_RATIO;
9393
9392
  const space_between_chars = target_height * LETTER_HEIGHT_TO_SPACE_RATIO;
9394
- return text.text.length * target_width_char + (text.text.length - 1) * space_between_chars;
9393
+ const space_between_lines = target_height * LETTER_HEIGHT_TO_SPACE_RATIO;
9394
+ const text_lines = text.text.split(/\r?\n/);
9395
+ const has_text = text.text.length > 0 && target_height > 0;
9396
+ const line_count = has_text ? text_lines.length : 0;
9397
+ const line_widths = has_text ? text_lines.map((line) => {
9398
+ if (line.length === 0) return 0;
9399
+ return line.length * target_width_char + (line.length - 1) * space_between_chars;
9400
+ }) : [];
9401
+ 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;
9403
+ return {
9404
+ text_lines,
9405
+ line_count,
9406
+ target_height,
9407
+ target_width_char,
9408
+ space_between_chars,
9409
+ space_between_lines,
9410
+ width,
9411
+ height
9412
+ };
9413
+ };
9414
+ var getTextMetrics = (text) => {
9415
+ const geometry = getTextGeometry(text);
9416
+ return {
9417
+ width: geometry.width,
9418
+ height: geometry.height,
9419
+ lineHeight: geometry.target_height,
9420
+ lineSpacing: geometry.space_between_lines,
9421
+ lineCount: geometry.line_count
9422
+ };
9395
9423
  };
9396
9424
  var convertTextToLines = (text) => {
9397
- const target_height = text.size * 0.7;
9398
- if (target_height <= 0 || text.text.length === 0) return [];
9425
+ const {
9426
+ text_lines,
9427
+ line_count,
9428
+ target_height,
9429
+ target_width_char,
9430
+ space_between_chars,
9431
+ space_between_lines
9432
+ } = getTextGeometry(text);
9433
+ if (target_height <= 0 || line_count === 0) return [];
9399
9434
  const strokeWidth = target_height / 12;
9400
- const centerline_span_y = Math.max(0, target_height - strokeWidth);
9401
- const y_baseline_offset = strokeWidth / 2;
9402
- const target_width_char = target_height * LETTER_HEIGHT_TO_WIDTH_RATIO;
9403
- const centerline_span_x = Math.max(0, target_width_char - strokeWidth);
9404
- const x_char_start_offset = strokeWidth / 2;
9405
- const space_between_chars = target_height * LETTER_HEIGHT_TO_SPACE_RATIO;
9406
9435
  const lines = [];
9407
- let current_x_origin_for_char_box = text.x;
9408
- for (let letterIndex = 0; letterIndex < text.text.length; letterIndex++) {
9409
- const letter = text.text[letterIndex];
9410
- const letterLines = lineAlphabet[letter] ?? lineAlphabet[letter.toUpperCase()];
9411
- if (!letterLines) {
9436
+ for (let lineIndex = 0; lineIndex < line_count; lineIndex++) {
9437
+ const lineYOffset = lineIndex * (target_height + space_between_lines);
9438
+ let current_x_origin_for_char_box = text.x;
9439
+ for (let letterIndex = 0; letterIndex < text_lines[lineIndex].length; letterIndex++) {
9440
+ const letter = text_lines[lineIndex][letterIndex];
9441
+ const letterLines = lineAlphabet[letter] ?? lineAlphabet[letter.toUpperCase()];
9442
+ if (!letterLines) {
9443
+ current_x_origin_for_char_box += target_width_char + space_between_chars;
9444
+ continue;
9445
+ }
9446
+ for (const {
9447
+ x1: norm_x1,
9448
+ y1: norm_y1,
9449
+ x2: norm_x2,
9450
+ y2: norm_y2
9451
+ } of letterLines) {
9452
+ lines.push({
9453
+ _pcb_drawing_object_id: getNewPcbDrawingObjectId("line"),
9454
+ pcb_drawing_type: "line",
9455
+ x1: current_x_origin_for_char_box + target_width_char * norm_x1,
9456
+ y1: text.y + lineYOffset + target_height * norm_y1,
9457
+ x2: current_x_origin_for_char_box + target_width_char * norm_x2,
9458
+ y2: text.y + lineYOffset + target_height * norm_y2,
9459
+ width: strokeWidth,
9460
+ layer: text.layer,
9461
+ unit: text.unit,
9462
+ color: text.color
9463
+ });
9464
+ }
9412
9465
  current_x_origin_for_char_box += target_width_char + space_between_chars;
9413
- continue;
9414
- }
9415
- for (const {
9416
- x1: norm_x1,
9417
- y1: norm_y1,
9418
- x2: norm_x2,
9419
- y2: norm_y2
9420
- } of letterLines) {
9421
- lines.push({
9422
- _pcb_drawing_object_id: getNewPcbDrawingObjectId("line"),
9423
- pcb_drawing_type: "line",
9424
- x1: current_x_origin_for_char_box + x_char_start_offset + centerline_span_x * norm_x1,
9425
- y1: text.y + y_baseline_offset + centerline_span_y * norm_y1,
9426
- x2: current_x_origin_for_char_box + x_char_start_offset + centerline_span_x * norm_x2,
9427
- y2: text.y + y_baseline_offset + centerline_span_y * norm_y2,
9428
- width: strokeWidth,
9429
- layer: text.layer,
9430
- unit: text.unit,
9431
- color: text.color
9432
- });
9433
9466
  }
9434
- current_x_origin_for_char_box += target_width_char + space_between_chars;
9435
9467
  }
9436
9468
  return lines;
9437
9469
  };
@@ -9467,8 +9499,7 @@ var drawText = (drawer, text) => {
9467
9499
  layer: text.layer
9468
9500
  });
9469
9501
  let alignOffset = { x: 0, y: 0 };
9470
- const textWidth = getTextWidth(text);
9471
- const textHeight = text.size;
9502
+ const { width: textWidth, height: textHeight } = getTextMetrics(text);
9472
9503
  switch (text.align) {
9473
9504
  case "top_left":
9474
9505
  alignOffset.x = 0;
@@ -13261,7 +13292,7 @@ import { css as css3 } from "@emotion/css";
13261
13292
  // package.json
13262
13293
  var package_default = {
13263
13294
  name: "@tscircuit/pcb-viewer",
13264
- version: "1.11.271",
13295
+ version: "1.11.273",
13265
13296
  main: "dist/index.js",
13266
13297
  type: "module",
13267
13298
  repository: "tscircuit/pcb-viewer",
@@ -13780,6 +13811,8 @@ var ToolbarOverlay = ({ children, elements }) => {
13780
13811
  zIndex: 1e3,
13781
13812
  minWidth: isSmallScreen ? "280px" : "400px",
13782
13813
  maxWidth: isSmallScreen ? "90vw" : "600px",
13814
+ maxHeight: "400px",
13815
+ overflow: "auto",
13783
13816
  boxShadow: "0 4px 12px rgba(0, 0, 0, 0.3)"
13784
13817
  },
13785
13818
  children: errorElements.map((e, i) => {