@tscircuit/schematic-viewer 1.2.5 → 1.2.7

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
@@ -1113,6 +1113,14 @@ function scale(sx, sy = void 0, cx = void 0, cy = void 0) {
1113
1113
  // node_modules/transformation-matrix/src/skew.js
1114
1114
  var { tan } = Math;
1115
1115
 
1116
+ // node_modules/transformation-matrix/src/toString.js
1117
+ function toSVG(matrix) {
1118
+ return toString(matrix);
1119
+ }
1120
+ function toString(matrix) {
1121
+ return `matrix(${matrix.a},${matrix.b},${matrix.c},${matrix.d},${matrix.e},${matrix.f})`;
1122
+ }
1123
+
1116
1124
  // node_modules/transformation-matrix/src/fromTransformAttribute.autogenerated.js
1117
1125
  function peg$subclass(child, parent) {
1118
1126
  function C() {
@@ -1280,8 +1288,6 @@ var SVGPathComponent = ({
1280
1288
  const badRatio = Math.abs(pathBounds.width / pathBounds.height - size.width / size.height) > 0.01;
1281
1289
  if (badRatio) {
1282
1290
  }
1283
- pathBounds.height = Math.max(pathBounds.height, 0.01);
1284
- pathBounds.width = Math.max(pathBounds.width, 0.01);
1285
1291
  const absoluteCenter = applyToPoint(ct, center);
1286
1292
  const actualAbsWidth = size.width * ct.a;
1287
1293
  const actualAbsHeight = size.height * Math.abs(ct.d);
@@ -1289,11 +1295,19 @@ var SVGPathComponent = ({
1289
1295
  width: Math.max(1, actualAbsWidth),
1290
1296
  height: Math.max(1, actualAbsHeight)
1291
1297
  };
1292
- console.log(absoluteSize, pathBounds);
1293
1298
  const [hovering, setHovering] = (0, import_react2.useState)(false);
1294
1299
  const svgLeft = absoluteCenter.x - absoluteSize.width / 2;
1295
1300
  const svgTop = absoluteCenter.y - absoluteSize.height / 2;
1296
1301
  const viewBox = `${pathBounds.minX} ${pathBounds.minY} ${pathBounds.width} ${pathBounds.height}`;
1302
+ const svgToScreen = compose(
1303
+ // translate(0, 0)
1304
+ scale(
1305
+ actualAbsWidth / pathBounds.width,
1306
+ actualAbsHeight / pathBounds.height
1307
+ ),
1308
+ translate(-pathBounds.minX, -pathBounds.minY)
1309
+ // translate(center.x, center.y)
1310
+ );
1297
1311
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1298
1312
  hovering && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
1299
1313
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -1301,11 +1315,11 @@ var SVGPathComponent = ({
1301
1315
  {
1302
1316
  style: {
1303
1317
  position: "absolute",
1304
- left: svgLeft - 4,
1305
- top: svgTop - 4,
1318
+ left: svgLeft - 6,
1319
+ top: svgTop - 6,
1306
1320
  pointerEvents: "none",
1307
- width: actualAbsWidth + 8,
1308
- height: actualAbsHeight + 8,
1321
+ width: actualAbsWidth + 12,
1322
+ height: actualAbsHeight + 12,
1309
1323
  border: "1px red solid",
1310
1324
  mixBlendMode: "difference",
1311
1325
  zIndex: 1e3
@@ -1348,18 +1362,20 @@ var SVGPathComponent = ({
1348
1362
  ].join(" "),
1349
1363
  left: svgLeft,
1350
1364
  top: svgTop
1351
- // backgroundColor: badRatio ? "rgba(255, 0, 0, 0.5)" : "transparent",
1365
+ // overflow: "hidden",
1366
+ // backgroundColor: badRatio ? "rgba(255, 0, 0, 0.1)" : "transparent",
1367
+ // backgroundColor: "rgba(255, 0, 0, 0.1)",
1352
1368
  },
1353
1369
  overflow: "visible",
1354
1370
  width: absoluteSize.width,
1355
1371
  height: absoluteSize.height,
1356
- viewBox,
1357
1372
  children: paths.map((p, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1358
1373
  "path",
1359
1374
  {
1375
+ transform: toSVG(svgToScreen),
1360
1376
  fill: p.fill ?? "none",
1361
1377
  strokeLinecap: "round",
1362
- strokeWidth: 2 * (p.strokeWidth || 1),
1378
+ strokeWidth: 1.5 * (p.strokeWidth || 1),
1363
1379
  stroke: p.stroke || "red",
1364
1380
  d: p.d
1365
1381
  },
@@ -1404,8 +1420,8 @@ var SimpleCapacitor = ({
1404
1420
  size: schematic.size,
1405
1421
  paths: [
1406
1422
  { stroke: "red", strokeWidth: 1, d: "M 0 15 l 12 0" },
1407
- { stroke: "red", strokeWidth: 2, d: "M 12 0 l 0 30" },
1408
- { stroke: "red", strokeWidth: 2, d: "M 18 0 l 0 30" },
1423
+ { stroke: "red", strokeWidth: 1, d: "M 12 0 l 0 30" },
1424
+ { stroke: "red", strokeWidth: 1, d: "M 18 0 l 0 30" },
1409
1425
  { stroke: "red", strokeWidth: 1, d: "M 18 15 l 12 0" }
1410
1426
  ]
1411
1427
  }
@@ -1439,6 +1455,7 @@ var SchematicPort = ({
1439
1455
  port: { source_port, source_component, schematic }
1440
1456
  }) => {
1441
1457
  const hoverName = source_component?.name ? `.${source_component.name} > .${source_port?.name ?? source_port?.pin_number}` : `.${source_port?.name ?? source_port?.pin_number}`;
1458
+ const vec = directionToVec(schematic.facing_direction);
1442
1459
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1443
1460
  SVGPathComponent,
1444
1461
  {
@@ -1449,7 +1466,10 @@ var SchematicPort = ({
1449
1466
  source_port?.pin_number && `Pin ${source_port.pin_number}`
1450
1467
  ] }),
1451
1468
  center: schematic.center,
1452
- size: { width: 0.2, height: 0.2 },
1469
+ size: {
1470
+ width: 0.2 + Math.abs(vec.x) * 0.04,
1471
+ height: 0.2 + Math.abs(vec.y) * 0.04
1472
+ },
1453
1473
  zIndex: 10,
1454
1474
  paths: [
1455
1475
  {
@@ -1460,7 +1480,7 @@ var SchematicPort = ({
1460
1480
  schematic.facing_direction ? {
1461
1481
  stroke: "blue",
1462
1482
  strokeWidth: 0.5,
1463
- d: `M 5 5 l ${directionToVec(schematic.facing_direction).x * 7} ${directionToVec(schematic.facing_direction).y * 7}`
1483
+ d: `M 5 5 l ${vec.x * 7} ${vec.y * 7}`
1464
1484
  } : null
1465
1485
  ].filter(Boolean)
1466
1486
  }