@tscircuit/pcb-viewer 1.11.274 → 1.11.276

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.275",
13296
13309
  main: "dist/index.js",
13297
13310
  type: "module",
13298
13311
  repository: "tscircuit/pcb-viewer",
@@ -14429,96 +14442,104 @@ var PCBViewer = ({
14429
14442
  }),
14430
14443
  [initialState, disablePcbGroups]
14431
14444
  );
14432
- return /* @__PURE__ */ jsxs14("div", { ref: transformRef, style: { position: "relative" }, children: [
14433
- /* @__PURE__ */ jsx18("div", { ref, children: /* @__PURE__ */ jsxs14(
14434
- ContextProviders,
14435
- {
14436
- initialState: mergedInitialState,
14437
- disablePcbGroups,
14438
- children: [
14439
- /* @__PURE__ */ jsx18(
14440
- CanvasElementsRenderer,
14441
- {
14442
- transform,
14443
- height,
14444
- width: refDimensions.width,
14445
- allowEditing,
14446
- focusOnHover,
14447
- cancelPanDrag,
14448
- onCreateEditEvent,
14449
- onModifyEditEvent,
14450
- grid: {
14451
- spacing: 1,
14452
- view_window: {
14453
- left: 0,
14454
- right: refDimensions.width || 500,
14455
- top: height,
14456
- bottom: 0
14457
- }
14458
- },
14459
- elements,
14460
- debugGraphics
14461
- },
14462
- refDimensions.width
14463
- ),
14464
- /* @__PURE__ */ jsx18(ToastContainer, {})
14465
- ]
14466
- }
14467
- ) }),
14468
- clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx18(
14469
- "div",
14470
- {
14471
- onClick: () => {
14472
- setIsInteractionEnabled(true);
14473
- resetTransform();
14474
- },
14475
- onTouchStart: (e) => {
14476
- const touch = e.touches[0];
14477
- touchStartRef.current = {
14478
- x: touch.clientX,
14479
- y: touch.clientY
14480
- };
14481
- },
14482
- onTouchEnd: (e) => {
14483
- const touch = e.changedTouches[0];
14484
- const start = touchStartRef.current;
14485
- if (!start) return;
14486
- const deltaX = Math.abs(touch.clientX - start.x);
14487
- const deltaY = Math.abs(touch.clientY - start.y);
14488
- if (deltaX < 10 && deltaY < 10) {
14489
- e.preventDefault();
14490
- setIsInteractionEnabled(true);
14491
- resetTransform();
14492
- }
14493
- touchStartRef.current = null;
14494
- },
14495
- style: {
14496
- position: "absolute",
14497
- inset: 0,
14498
- cursor: "pointer",
14499
- zIndex: zIndexMap.clickToInteractOverlay,
14500
- display: "flex",
14501
- alignItems: "center",
14502
- justifyContent: "center",
14503
- touchAction: "pan-x pan-y pinch-zoom"
14504
- },
14505
- children: /* @__PURE__ */ jsx18(
14445
+ return /* @__PURE__ */ jsxs14(
14446
+ "div",
14447
+ {
14448
+ ref: transformRef,
14449
+ style: { position: "relative" },
14450
+ onContextMenu: (event) => event.preventDefault(),
14451
+ children: [
14452
+ /* @__PURE__ */ jsx18("div", { ref, children: /* @__PURE__ */ jsxs14(
14453
+ ContextProviders,
14454
+ {
14455
+ initialState: mergedInitialState,
14456
+ disablePcbGroups,
14457
+ children: [
14458
+ /* @__PURE__ */ jsx18(
14459
+ CanvasElementsRenderer,
14460
+ {
14461
+ transform,
14462
+ height,
14463
+ width: refDimensions.width,
14464
+ allowEditing,
14465
+ focusOnHover,
14466
+ cancelPanDrag,
14467
+ onCreateEditEvent,
14468
+ onModifyEditEvent,
14469
+ grid: {
14470
+ spacing: 1,
14471
+ view_window: {
14472
+ left: 0,
14473
+ right: refDimensions.width || 500,
14474
+ top: height,
14475
+ bottom: 0
14476
+ }
14477
+ },
14478
+ elements,
14479
+ debugGraphics
14480
+ },
14481
+ refDimensions.width
14482
+ ),
14483
+ /* @__PURE__ */ jsx18(ToastContainer, {})
14484
+ ]
14485
+ }
14486
+ ) }),
14487
+ clickToInteractEnabled && !isInteractionEnabled && /* @__PURE__ */ jsx18(
14506
14488
  "div",
14507
14489
  {
14490
+ onClick: () => {
14491
+ setIsInteractionEnabled(true);
14492
+ resetTransform();
14493
+ },
14494
+ onTouchStart: (e) => {
14495
+ const touch = e.touches[0];
14496
+ touchStartRef.current = {
14497
+ x: touch.clientX,
14498
+ y: touch.clientY
14499
+ };
14500
+ },
14501
+ onTouchEnd: (e) => {
14502
+ const touch = e.changedTouches[0];
14503
+ const start = touchStartRef.current;
14504
+ if (!start) return;
14505
+ const deltaX = Math.abs(touch.clientX - start.x);
14506
+ const deltaY = Math.abs(touch.clientY - start.y);
14507
+ if (deltaX < 10 && deltaY < 10) {
14508
+ e.preventDefault();
14509
+ setIsInteractionEnabled(true);
14510
+ resetTransform();
14511
+ }
14512
+ touchStartRef.current = null;
14513
+ },
14508
14514
  style: {
14509
- backgroundColor: "rgba(0, 0, 0, 0.8)",
14510
- color: "white",
14511
- padding: "12px 24px",
14512
- borderRadius: "8px",
14513
- fontSize: "16px",
14514
- pointerEvents: "none"
14515
+ position: "absolute",
14516
+ inset: 0,
14517
+ cursor: "pointer",
14518
+ zIndex: zIndexMap.clickToInteractOverlay,
14519
+ display: "flex",
14520
+ alignItems: "center",
14521
+ justifyContent: "center",
14522
+ touchAction: "pan-x pan-y pinch-zoom"
14515
14523
  },
14516
- children: typeof window !== "undefined" && ("ontouchstart" in window || navigator.maxTouchPoints > 0) ? "Touch to Interact" : "Click to Interact"
14524
+ children: /* @__PURE__ */ jsx18(
14525
+ "div",
14526
+ {
14527
+ style: {
14528
+ backgroundColor: "rgba(0, 0, 0, 0.8)",
14529
+ color: "white",
14530
+ padding: "12px 24px",
14531
+ borderRadius: "8px",
14532
+ fontSize: "16px",
14533
+ pointerEvents: "none"
14534
+ },
14535
+ children: typeof window !== "undefined" && ("ontouchstart" in window || navigator.maxTouchPoints > 0) ? "Touch to Interact" : "Click to Interact"
14536
+ }
14537
+ )
14517
14538
  }
14518
14539
  )
14519
- }
14520
- )
14521
- ] });
14540
+ ]
14541
+ }
14542
+ );
14522
14543
  };
14523
14544
  export {
14524
14545
  CanvasElementsRenderer,