circuit-to-svg 0.0.306 → 0.0.307
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 +95 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5884,7 +5884,7 @@ function getSoftwareUsedString(circuitJson) {
|
|
|
5884
5884
|
var package_default = {
|
|
5885
5885
|
name: "circuit-to-svg",
|
|
5886
5886
|
type: "module",
|
|
5887
|
-
version: "0.0.
|
|
5887
|
+
version: "0.0.306",
|
|
5888
5888
|
description: "Convert Circuit JSON to SVG",
|
|
5889
5889
|
main: "dist/index.js",
|
|
5890
5890
|
files: [
|
|
@@ -6139,6 +6139,100 @@ function getPcbBoundsFromCircuitJson(circuitJson) {
|
|
|
6139
6139
|
width: circuitJsonElm.width,
|
|
6140
6140
|
height: circuitJsonElm.height
|
|
6141
6141
|
});
|
|
6142
|
+
} else if (circuitJsonElm.type === "pcb_note_dimension" || circuitJsonElm.type === "pcb_fabrication_note_dimension") {
|
|
6143
|
+
const dimension = circuitJsonElm;
|
|
6144
|
+
const {
|
|
6145
|
+
from,
|
|
6146
|
+
to,
|
|
6147
|
+
text,
|
|
6148
|
+
font_size = 1,
|
|
6149
|
+
arrow_size,
|
|
6150
|
+
offset_distance,
|
|
6151
|
+
offset_direction
|
|
6152
|
+
} = dimension;
|
|
6153
|
+
if (!from || !to || !arrow_size) continue;
|
|
6154
|
+
updateBounds({ center: from, width: 0, height: 0 });
|
|
6155
|
+
updateBounds({ center: to, width: 0, height: 0 });
|
|
6156
|
+
const normalize3 = (v) => {
|
|
6157
|
+
const l = Math.hypot(v.x, v.y) || 1;
|
|
6158
|
+
return { x: v.x / l, y: v.y / l };
|
|
6159
|
+
};
|
|
6160
|
+
const direction = normalize3({ x: to.x - from.x, y: to.y - from.y });
|
|
6161
|
+
if (Number.isNaN(direction.x) || Number.isNaN(direction.y)) continue;
|
|
6162
|
+
const perpendicular = { x: -direction.y, y: direction.x };
|
|
6163
|
+
const hasOffsetDirection = offset_direction && typeof offset_direction.x === "number" && typeof offset_direction.y === "number";
|
|
6164
|
+
const normalizedOffsetDirection = hasOffsetDirection ? normalize3(offset_direction) : { x: 0, y: 0 };
|
|
6165
|
+
const offsetMagnitude = typeof offset_distance === "number" ? offset_distance : 0;
|
|
6166
|
+
const offsetVector = {
|
|
6167
|
+
x: normalizedOffsetDirection.x * offsetMagnitude,
|
|
6168
|
+
y: normalizedOffsetDirection.y * offsetMagnitude
|
|
6169
|
+
};
|
|
6170
|
+
const fromOffset = {
|
|
6171
|
+
x: from.x + offsetVector.x,
|
|
6172
|
+
y: from.y + offsetVector.y
|
|
6173
|
+
};
|
|
6174
|
+
const toOffset = { x: to.x + offsetVector.x, y: to.y + offsetVector.y };
|
|
6175
|
+
updateBounds({ center: fromOffset, width: 0, height: 0 });
|
|
6176
|
+
updateBounds({ center: toOffset, width: 0, height: 0 });
|
|
6177
|
+
const extensionDirection = hasOffsetDirection && (Math.abs(normalizedOffsetDirection.x) > Number.EPSILON || Math.abs(normalizedOffsetDirection.y) > Number.EPSILON) ? normalizedOffsetDirection : perpendicular;
|
|
6178
|
+
const extensionLength = offsetMagnitude + arrow_size;
|
|
6179
|
+
const fromExtEnd = {
|
|
6180
|
+
x: from.x + extensionDirection.x * extensionLength,
|
|
6181
|
+
y: from.y + extensionDirection.y * extensionLength
|
|
6182
|
+
};
|
|
6183
|
+
const toExtEnd = {
|
|
6184
|
+
x: to.x + extensionDirection.x * extensionLength,
|
|
6185
|
+
y: to.y + extensionDirection.y * extensionLength
|
|
6186
|
+
};
|
|
6187
|
+
updateBounds({ center: fromExtEnd, width: 0, height: 0 });
|
|
6188
|
+
updateBounds({ center: toExtEnd, width: 0, height: 0 });
|
|
6189
|
+
const arrowHalfWidth = arrow_size / 2;
|
|
6190
|
+
const fromBase = {
|
|
6191
|
+
x: fromOffset.x + direction.x * arrow_size,
|
|
6192
|
+
y: fromOffset.y + direction.y * arrow_size
|
|
6193
|
+
};
|
|
6194
|
+
const toBase = {
|
|
6195
|
+
x: toOffset.x - direction.x * arrow_size,
|
|
6196
|
+
y: toOffset.y - direction.y * arrow_size
|
|
6197
|
+
};
|
|
6198
|
+
const fromArrowP2 = {
|
|
6199
|
+
x: fromBase.x + perpendicular.x * arrowHalfWidth,
|
|
6200
|
+
y: fromBase.y + perpendicular.y * arrowHalfWidth
|
|
6201
|
+
};
|
|
6202
|
+
const fromArrowP3 = {
|
|
6203
|
+
x: fromBase.x - perpendicular.x * arrowHalfWidth,
|
|
6204
|
+
y: fromBase.y - perpendicular.y * arrowHalfWidth
|
|
6205
|
+
};
|
|
6206
|
+
updateBounds({ center: fromArrowP2, width: 0, height: 0 });
|
|
6207
|
+
updateBounds({ center: fromArrowP3, width: 0, height: 0 });
|
|
6208
|
+
const toArrowP2 = {
|
|
6209
|
+
x: toBase.x + perpendicular.x * arrowHalfWidth,
|
|
6210
|
+
y: toBase.y + perpendicular.y * arrowHalfWidth
|
|
6211
|
+
};
|
|
6212
|
+
const toArrowP3 = {
|
|
6213
|
+
x: toBase.x - perpendicular.x * arrowHalfWidth,
|
|
6214
|
+
y: toBase.y - perpendicular.y * arrowHalfWidth
|
|
6215
|
+
};
|
|
6216
|
+
updateBounds({ center: toArrowP2, width: 0, height: 0 });
|
|
6217
|
+
updateBounds({ center: toArrowP3, width: 0, height: 0 });
|
|
6218
|
+
if (text) {
|
|
6219
|
+
const midPoint = {
|
|
6220
|
+
x: (from.x + to.x) / 2 + offsetVector.x,
|
|
6221
|
+
y: (from.y + to.y) / 2 + offsetVector.y
|
|
6222
|
+
};
|
|
6223
|
+
const textOffset = arrow_size * 1.5;
|
|
6224
|
+
const textPoint = {
|
|
6225
|
+
x: midPoint.x + perpendicular.x * textOffset,
|
|
6226
|
+
y: midPoint.y + perpendicular.y * textOffset
|
|
6227
|
+
};
|
|
6228
|
+
const textWidth = text.length * font_size * 0.6;
|
|
6229
|
+
const textHeight = font_size;
|
|
6230
|
+
updateBounds({
|
|
6231
|
+
center: textPoint,
|
|
6232
|
+
width: textWidth,
|
|
6233
|
+
height: textHeight
|
|
6234
|
+
});
|
|
6235
|
+
}
|
|
6142
6236
|
} else if (circuitJsonElm.type === "pcb_cutout") {
|
|
6143
6237
|
const cutout = circuitJsonElm;
|
|
6144
6238
|
if (cutout.shape === "rect") {
|