circuit-to-svg 0.0.300 → 0.0.301
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 +48 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -622,6 +622,9 @@ function normalize(vector) {
|
|
|
622
622
|
const length = Math.hypot(vector.x, vector.y) || 1;
|
|
623
623
|
return { x: vector.x / length, y: vector.y / length };
|
|
624
624
|
}
|
|
625
|
+
var TEXT_OFFSET_MULTIPLIER = 1.5;
|
|
626
|
+
var CHARACTER_WIDTH_MULTIPLIER = 0.6;
|
|
627
|
+
var TEXT_INTERSECTION_PADDING_MULTIPLIER = 0.3;
|
|
625
628
|
function toPath(points) {
|
|
626
629
|
return points.map(
|
|
627
630
|
(point, index) => index === 0 ? `M ${point.x} ${point.y}` : `L ${point.x} ${point.y}`
|
|
@@ -640,7 +643,8 @@ function createSvgObjectsFromPcbFabricationNoteDimension(dimension, ctx) {
|
|
|
640
643
|
pcb_component_id,
|
|
641
644
|
pcb_fabrication_note_dimension_id,
|
|
642
645
|
offset_distance,
|
|
643
|
-
offset_direction
|
|
646
|
+
offset_direction,
|
|
647
|
+
text_ccw_rotation
|
|
644
648
|
} = dimension;
|
|
645
649
|
if (layerFilter && layer && layer !== layerFilter) return [];
|
|
646
650
|
if (!from || !to || typeof from !== "object" || typeof to !== "object") {
|
|
@@ -751,12 +755,6 @@ function createSvgObjectsFromPcbFabricationNoteDimension(dimension, ctx) {
|
|
|
751
755
|
x: (from.x + to.x) / 2 + offsetVector.x,
|
|
752
756
|
y: (from.y + to.y) / 2 + offsetVector.y
|
|
753
757
|
};
|
|
754
|
-
const textOffset = arrowSize * 1.5;
|
|
755
|
-
const textPoint = {
|
|
756
|
-
x: midPoint.x + perpendicular.x * textOffset,
|
|
757
|
-
y: midPoint.y + perpendicular.y * textOffset
|
|
758
|
-
};
|
|
759
|
-
const [textX, textY] = applyToPoint6(transform, [textPoint.x, textPoint.y]);
|
|
760
758
|
const [screenFromX, screenFromY] = applyToPoint6(transform, [
|
|
761
759
|
fromOffset.x,
|
|
762
760
|
fromOffset.y
|
|
@@ -773,6 +771,25 @@ function createSvgObjectsFromPcbFabricationNoteDimension(dimension, ctx) {
|
|
|
773
771
|
if (textAngle > 90 || textAngle < -90) {
|
|
774
772
|
textAngle += 180;
|
|
775
773
|
}
|
|
774
|
+
const finalTextAngle = typeof text_ccw_rotation === "number" && Number.isFinite(text_ccw_rotation) ? textAngle - text_ccw_rotation : textAngle;
|
|
775
|
+
let additionalOffset = 0;
|
|
776
|
+
if (text && typeof text_ccw_rotation === "number" && Number.isFinite(text_ccw_rotation)) {
|
|
777
|
+
const textWidth = text.length * font_size * CHARACTER_WIDTH_MULTIPLIER;
|
|
778
|
+
const textHeight = font_size;
|
|
779
|
+
const rotationRad = text_ccw_rotation * Math.PI / 180;
|
|
780
|
+
const sinRot = Math.abs(Math.sin(rotationRad));
|
|
781
|
+
const cosRot = Math.abs(Math.cos(rotationRad));
|
|
782
|
+
const halfWidth = textWidth / 2;
|
|
783
|
+
const halfHeight = textHeight / 2;
|
|
784
|
+
const maxExtension = halfWidth * sinRot + halfHeight * cosRot;
|
|
785
|
+
additionalOffset = maxExtension + font_size * TEXT_INTERSECTION_PADDING_MULTIPLIER;
|
|
786
|
+
}
|
|
787
|
+
const textOffset = arrowSize * TEXT_OFFSET_MULTIPLIER + additionalOffset;
|
|
788
|
+
const textPoint = {
|
|
789
|
+
x: midPoint.x + perpendicular.x * textOffset,
|
|
790
|
+
y: midPoint.y + perpendicular.y * textOffset
|
|
791
|
+
};
|
|
792
|
+
const [textX, textY] = applyToPoint6(transform, [textPoint.x, textPoint.y]);
|
|
776
793
|
const transformedFontSize = font_size * Math.abs(transform.a);
|
|
777
794
|
const children = [
|
|
778
795
|
...extensionSegments,
|
|
@@ -827,7 +844,7 @@ function createSvgObjectsFromPcbFabricationNoteDimension(dimension, ctx) {
|
|
|
827
844
|
"text-anchor": "middle",
|
|
828
845
|
"dominant-baseline": "central",
|
|
829
846
|
class: "pcb-fabrication-note-dimension-text",
|
|
830
|
-
transform: `rotate(${
|
|
847
|
+
transform: `rotate(${finalTextAngle} ${textX} ${textY})`
|
|
831
848
|
},
|
|
832
849
|
children: [
|
|
833
850
|
{
|
|
@@ -1126,7 +1143,8 @@ function createSvgObjectsFromPcbNoteDimension(dimension, ctx) {
|
|
|
1126
1143
|
color,
|
|
1127
1144
|
arrow_size,
|
|
1128
1145
|
offset_distance,
|
|
1129
|
-
offset_direction
|
|
1146
|
+
offset_direction,
|
|
1147
|
+
text_ccw_rotation
|
|
1130
1148
|
} = dimension;
|
|
1131
1149
|
if (!from || !to) {
|
|
1132
1150
|
console.error("Invalid pcb_note_dimension endpoints", { from, to });
|
|
@@ -1221,12 +1239,6 @@ function createSvgObjectsFromPcbNoteDimension(dimension, ctx) {
|
|
|
1221
1239
|
x: (from.x + to.x) / 2 + offsetVector.x,
|
|
1222
1240
|
y: (from.y + to.y) / 2 + offsetVector.y
|
|
1223
1241
|
};
|
|
1224
|
-
const textOffset = arrow_size * 1.5;
|
|
1225
|
-
const textPoint = {
|
|
1226
|
-
x: midPoint.x + perpendicular.x * textOffset,
|
|
1227
|
-
y: midPoint.y + perpendicular.y * textOffset
|
|
1228
|
-
};
|
|
1229
|
-
const [textX, textY] = applyToPoint7(transform, [textPoint.x, textPoint.y]);
|
|
1230
1242
|
const [screenFromX, screenFromY] = applyToPoint7(transform, [
|
|
1231
1243
|
fromOffset.x,
|
|
1232
1244
|
fromOffset.y
|
|
@@ -1243,6 +1255,25 @@ function createSvgObjectsFromPcbNoteDimension(dimension, ctx) {
|
|
|
1243
1255
|
if (textAngle > 90 || textAngle < -90) {
|
|
1244
1256
|
textAngle += 180;
|
|
1245
1257
|
}
|
|
1258
|
+
const finalTextAngle = typeof text_ccw_rotation === "number" && Number.isFinite(text_ccw_rotation) ? textAngle - text_ccw_rotation : textAngle;
|
|
1259
|
+
let additionalOffset = 0;
|
|
1260
|
+
if (text && typeof text_ccw_rotation === "number" && Number.isFinite(text_ccw_rotation)) {
|
|
1261
|
+
const textWidth = text.length * font_size * 0.6;
|
|
1262
|
+
const textHeight = font_size;
|
|
1263
|
+
const rotationRad = text_ccw_rotation * Math.PI / 180;
|
|
1264
|
+
const sinRot = Math.abs(Math.sin(rotationRad));
|
|
1265
|
+
const cosRot = Math.abs(Math.cos(rotationRad));
|
|
1266
|
+
const halfWidth = textWidth / 2;
|
|
1267
|
+
const halfHeight = textHeight / 2;
|
|
1268
|
+
const maxExtension = halfWidth * sinRot + halfHeight * cosRot;
|
|
1269
|
+
additionalOffset = maxExtension + font_size * 0.3;
|
|
1270
|
+
}
|
|
1271
|
+
const textOffset = arrow_size * 1.5 + additionalOffset;
|
|
1272
|
+
const textPoint = {
|
|
1273
|
+
x: midPoint.x + perpendicular.x * textOffset,
|
|
1274
|
+
y: midPoint.y + perpendicular.y * textOffset
|
|
1275
|
+
};
|
|
1276
|
+
const [textX, textY] = applyToPoint7(transform, [textPoint.x, textPoint.y]);
|
|
1246
1277
|
const transformedFontSize = font_size * Math.abs(transform.a);
|
|
1247
1278
|
const children = [
|
|
1248
1279
|
...extensionSegments,
|
|
@@ -1297,7 +1328,7 @@ function createSvgObjectsFromPcbNoteDimension(dimension, ctx) {
|
|
|
1297
1328
|
"text-anchor": "middle",
|
|
1298
1329
|
"dominant-baseline": "central",
|
|
1299
1330
|
class: "pcb-note-dimension-text",
|
|
1300
|
-
transform: `rotate(${
|
|
1331
|
+
transform: `rotate(${finalTextAngle} ${textX} ${textY})`
|
|
1301
1332
|
},
|
|
1302
1333
|
children: [
|
|
1303
1334
|
{
|
|
@@ -5674,7 +5705,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5674
5705
|
var package_default = {
|
|
5675
5706
|
name: "circuit-to-svg",
|
|
5676
5707
|
type: "module",
|
|
5677
|
-
version: "0.0.
|
|
5708
|
+
version: "0.0.300",
|
|
5678
5709
|
description: "Convert Circuit JSON to SVG",
|
|
5679
5710
|
main: "dist/index.js",
|
|
5680
5711
|
files: [
|