easyeda 0.0.329 → 0.0.331
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/browser/index.js +502 -472
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +502 -472
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +503 -473
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -11919,6 +11919,351 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
|
|
|
11919
11919
|
return placementPromise;
|
|
11920
11920
|
};
|
|
11921
11921
|
|
|
11922
|
+
// lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
|
|
11923
|
+
var round = (value) => Number(value.toFixed(6));
|
|
11924
|
+
var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
|
|
11925
|
+
var toSchematicUnits = (value) => round(value * EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT);
|
|
11926
|
+
var getPointTransformer = (origin) => (point2) => ({
|
|
11927
|
+
x: toSchematicUnits(point2.x - origin.x),
|
|
11928
|
+
y: toSchematicUnits(origin.y - point2.y)
|
|
11929
|
+
});
|
|
11930
|
+
var formatNumber = (value) => String(round(value));
|
|
11931
|
+
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
11932
|
+
A: 7,
|
|
11933
|
+
C: 6,
|
|
11934
|
+
H: 1,
|
|
11935
|
+
L: 2,
|
|
11936
|
+
M: 2,
|
|
11937
|
+
Q: 4,
|
|
11938
|
+
S: 4,
|
|
11939
|
+
T: 2,
|
|
11940
|
+
V: 1,
|
|
11941
|
+
Z: 0
|
|
11942
|
+
};
|
|
11943
|
+
var transformSvgPath = (pathData, origin) => {
|
|
11944
|
+
const tokens = pathData.match(
|
|
11945
|
+
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
11946
|
+
) ?? [];
|
|
11947
|
+
const output = [];
|
|
11948
|
+
let command = "";
|
|
11949
|
+
let tokenIndex = 0;
|
|
11950
|
+
let currentX = 0;
|
|
11951
|
+
let currentY = 0;
|
|
11952
|
+
let subpathStartX = 0;
|
|
11953
|
+
let subpathStartY = 0;
|
|
11954
|
+
const transformPoint = getPointTransformer(origin);
|
|
11955
|
+
const getOriginalPoint = (x, y, isRelative) => ({
|
|
11956
|
+
x: isRelative ? currentX + x : x,
|
|
11957
|
+
y: isRelative ? currentY + y : y
|
|
11958
|
+
});
|
|
11959
|
+
while (tokenIndex < tokens.length) {
|
|
11960
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
11961
|
+
command = tokens[tokenIndex];
|
|
11962
|
+
tokenIndex += 1;
|
|
11963
|
+
}
|
|
11964
|
+
if (!command) break;
|
|
11965
|
+
const upperCommand = command.toUpperCase();
|
|
11966
|
+
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
11967
|
+
if (parameterCount === void 0) break;
|
|
11968
|
+
if (upperCommand === "Z") {
|
|
11969
|
+
output.push("Z");
|
|
11970
|
+
currentX = subpathStartX;
|
|
11971
|
+
currentY = subpathStartY;
|
|
11972
|
+
command = "";
|
|
11973
|
+
continue;
|
|
11974
|
+
}
|
|
11975
|
+
if (tokenIndex + parameterCount > tokens.length) break;
|
|
11976
|
+
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
11977
|
+
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
11978
|
+
tokenIndex += parameterCount;
|
|
11979
|
+
const isRelative = command === command.toLowerCase();
|
|
11980
|
+
if (upperCommand === "H" || upperCommand === "V") {
|
|
11981
|
+
const point2 = getOriginalPoint(
|
|
11982
|
+
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
11983
|
+
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
11984
|
+
isRelative
|
|
11985
|
+
);
|
|
11986
|
+
const transformed = transformPoint(point2);
|
|
11987
|
+
output.push(
|
|
11988
|
+
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11989
|
+
);
|
|
11990
|
+
currentX = point2.x;
|
|
11991
|
+
currentY = point2.y;
|
|
11992
|
+
continue;
|
|
11993
|
+
}
|
|
11994
|
+
if (["M", "L", "T"].includes(upperCommand)) {
|
|
11995
|
+
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
11996
|
+
const transformed = transformPoint(point2);
|
|
11997
|
+
output.push(
|
|
11998
|
+
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
11999
|
+
);
|
|
12000
|
+
currentX = point2.x;
|
|
12001
|
+
currentY = point2.y;
|
|
12002
|
+
if (upperCommand === "M") {
|
|
12003
|
+
subpathStartX = point2.x;
|
|
12004
|
+
subpathStartY = point2.y;
|
|
12005
|
+
command = isRelative ? "l" : "L";
|
|
12006
|
+
}
|
|
12007
|
+
continue;
|
|
12008
|
+
}
|
|
12009
|
+
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
12010
|
+
const transformedValues = [];
|
|
12011
|
+
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
12012
|
+
const point2 = getOriginalPoint(
|
|
12013
|
+
values[valueIndex],
|
|
12014
|
+
values[valueIndex + 1],
|
|
12015
|
+
isRelative
|
|
12016
|
+
);
|
|
12017
|
+
const transformed = transformPoint(point2);
|
|
12018
|
+
transformedValues.push(transformed.x, transformed.y);
|
|
12019
|
+
}
|
|
12020
|
+
output.push(
|
|
12021
|
+
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
12022
|
+
);
|
|
12023
|
+
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
12024
|
+
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
12025
|
+
continue;
|
|
12026
|
+
}
|
|
12027
|
+
if (upperCommand === "A") {
|
|
12028
|
+
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
12029
|
+
const transformedEndpoint = transformPoint(endpoint);
|
|
12030
|
+
output.push(
|
|
12031
|
+
[
|
|
12032
|
+
"A",
|
|
12033
|
+
formatNumber(toSchematicUnits(Math.abs(values[0]))),
|
|
12034
|
+
formatNumber(toSchematicUnits(Math.abs(values[1]))),
|
|
12035
|
+
formatNumber(-values[2]),
|
|
12036
|
+
String(values[3]),
|
|
12037
|
+
String(values[4] === 0 ? 1 : 0),
|
|
12038
|
+
formatNumber(transformedEndpoint.x),
|
|
12039
|
+
formatNumber(transformedEndpoint.y)
|
|
12040
|
+
].join(" ")
|
|
12041
|
+
);
|
|
12042
|
+
currentX = endpoint.x;
|
|
12043
|
+
currentY = endpoint.y;
|
|
12044
|
+
}
|
|
12045
|
+
}
|
|
12046
|
+
return output.join(" ");
|
|
12047
|
+
};
|
|
12048
|
+
var getPinDirection = (rotation2) => {
|
|
12049
|
+
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
12050
|
+
if (normalizedRotation === 90) return "up";
|
|
12051
|
+
if (normalizedRotation === 180) return "left";
|
|
12052
|
+
if (normalizedRotation === 270) return "down";
|
|
12053
|
+
return "right";
|
|
12054
|
+
};
|
|
12055
|
+
var getPinStemLength = (path) => {
|
|
12056
|
+
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
12057
|
+
if (!segment) return void 0;
|
|
12058
|
+
return toSchematicUnits(Math.abs(Number(segment[1])));
|
|
12059
|
+
};
|
|
12060
|
+
var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
|
|
12061
|
+
if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
|
|
12062
|
+
const first = shape.points[0];
|
|
12063
|
+
const last = shape.points[shape.points.length - 1];
|
|
12064
|
+
if (first.x === last.x && first.y === last.y) return [];
|
|
12065
|
+
return [transformPoint(first), transformPoint(last)];
|
|
12066
|
+
});
|
|
12067
|
+
var alignPortToDrawing = ({
|
|
12068
|
+
position: position2,
|
|
12069
|
+
direction,
|
|
12070
|
+
stemLength,
|
|
12071
|
+
drawingEndpoints
|
|
12072
|
+
}) => {
|
|
12073
|
+
if (stemLength === void 0) return position2;
|
|
12074
|
+
const outwardDirection = getUnitVectorFromDirection(direction);
|
|
12075
|
+
const expectedBodyConnection = {
|
|
12076
|
+
x: position2.x - outwardDirection.x * stemLength,
|
|
12077
|
+
y: position2.y - outwardDirection.y * stemLength
|
|
12078
|
+
};
|
|
12079
|
+
const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
|
|
12080
|
+
const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
|
|
12081
|
+
endpoint,
|
|
12082
|
+
distance: distance2(endpoint, expectedBodyConnection)
|
|
12083
|
+
})).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
|
|
12084
|
+
if (!nearestEndpoint) return position2;
|
|
12085
|
+
return {
|
|
12086
|
+
x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
|
|
12087
|
+
y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
|
|
12088
|
+
};
|
|
12089
|
+
};
|
|
12090
|
+
var getTextFontSize = (fontSize) => {
|
|
12091
|
+
const numericFontSize = Number.parseFloat(fontSize);
|
|
12092
|
+
if (!Number.isFinite(numericFontSize)) return 0.2;
|
|
12093
|
+
return toSchematicUnits(numericFontSize);
|
|
12094
|
+
};
|
|
12095
|
+
var getTextAnchor = (alignment) => {
|
|
12096
|
+
if (alignment === "L") return "left";
|
|
12097
|
+
if (alignment === "R") return "right";
|
|
12098
|
+
return "center";
|
|
12099
|
+
};
|
|
12100
|
+
var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
|
|
12101
|
+
const pins = easyEdaJson.dataStr.shape.filter(
|
|
12102
|
+
(shape) => shape.type === "PIN"
|
|
12103
|
+
);
|
|
12104
|
+
const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
|
|
12105
|
+
(shape) => shape.type === "PAD"
|
|
12106
|
+
);
|
|
12107
|
+
const sourcePorts = circuitJson.filter(
|
|
12108
|
+
(element) => element.type === "source_port"
|
|
12109
|
+
);
|
|
12110
|
+
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
12111
|
+
pads.forEach((pad, padIndex) => {
|
|
12112
|
+
const sourcePort = sourcePorts.find(
|
|
12113
|
+
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
12114
|
+
);
|
|
12115
|
+
if (!sourcePort) return;
|
|
12116
|
+
const padNumber = String(pad.number);
|
|
12117
|
+
sourcePortNamesByPadNumber.set(padNumber, [
|
|
12118
|
+
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
12119
|
+
sourcePort.name
|
|
12120
|
+
]);
|
|
12121
|
+
});
|
|
12122
|
+
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
12123
|
+
const usedPortNames = /* @__PURE__ */ new Set();
|
|
12124
|
+
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
12125
|
+
pins.forEach((pin, pinIndex) => {
|
|
12126
|
+
const pinNumberKey = String(pin.pinNumber);
|
|
12127
|
+
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
12128
|
+
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
12129
|
+
let portName = matchingPortNames[matchingPortIndex];
|
|
12130
|
+
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
12131
|
+
if (!portName && pin.label) {
|
|
12132
|
+
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
12133
|
+
portName = sourcePorts.find(
|
|
12134
|
+
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
12135
|
+
)?.name;
|
|
12136
|
+
}
|
|
12137
|
+
const numericPinNumber = Number(pin.pinNumber);
|
|
12138
|
+
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
12139
|
+
const numericPortName = `pin${numericPinNumber}`;
|
|
12140
|
+
if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
|
|
12141
|
+
portName = numericPortName;
|
|
12142
|
+
}
|
|
12143
|
+
}
|
|
12144
|
+
portName ??= sourcePorts.find((port) => !usedPortNames.has(port.name))?.name;
|
|
12145
|
+
portName ??= `pin${pinIndex + 1}`;
|
|
12146
|
+
usedPortNames.add(portName);
|
|
12147
|
+
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
12148
|
+
metadataByShapeId.set(pin.id, {
|
|
12149
|
+
name: portName,
|
|
12150
|
+
pinNumber: sourcePort?.pin_number,
|
|
12151
|
+
aliases: [
|
|
12152
|
+
...sourcePort?.port_hints ?? [],
|
|
12153
|
+
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
12154
|
+
].filter(
|
|
12155
|
+
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
12156
|
+
)
|
|
12157
|
+
});
|
|
12158
|
+
});
|
|
12159
|
+
return metadataByShapeId;
|
|
12160
|
+
};
|
|
12161
|
+
var generateShapeTsx = ({
|
|
12162
|
+
shape,
|
|
12163
|
+
origin,
|
|
12164
|
+
portMetadata,
|
|
12165
|
+
drawingEndpoints = []
|
|
12166
|
+
}) => {
|
|
12167
|
+
const transformPoint = getPointTransformer(origin);
|
|
12168
|
+
if (shape.type === "RECTANGLE") {
|
|
12169
|
+
const center = transformPoint({
|
|
12170
|
+
x: shape.position.x + shape.width / 2,
|
|
12171
|
+
y: shape.position.y + shape.height / 2
|
|
12172
|
+
});
|
|
12173
|
+
return `<schematicrect schX={${center.x}} schY={${center.y}} width={${toSchematicUnits(shape.width)}} height={${toSchematicUnits(shape.height)}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12174
|
+
}
|
|
12175
|
+
if (shape.type === "ELLIPSE") {
|
|
12176
|
+
const center = transformPoint(shape.center);
|
|
12177
|
+
return `<schematiccircle center={{ x: ${center.x}, y: ${center.y} }} radius={${toSchematicUnits(Math.max(shape.radiusX, shape.radiusY))}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12178
|
+
}
|
|
12179
|
+
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
12180
|
+
const isPolygon = shape.type === "POLYGON";
|
|
12181
|
+
const points = shape.points.map(transformPoint);
|
|
12182
|
+
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
12183
|
+
return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12184
|
+
}
|
|
12185
|
+
if (shape.type === "PATH") {
|
|
12186
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
12187
|
+
if (!transformedPath) return void 0;
|
|
12188
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12189
|
+
}
|
|
12190
|
+
if (shape.type === "ARC") {
|
|
12191
|
+
const transformedPath = transformSvgPath(shape.pathData, origin);
|
|
12192
|
+
if (!transformedPath) return void 0;
|
|
12193
|
+
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
12194
|
+
}
|
|
12195
|
+
if (shape.type === "TEXT") {
|
|
12196
|
+
if (shape.visibility !== "1") return void 0;
|
|
12197
|
+
const position2 = transformPoint({ x: shape.x, y: shape.y });
|
|
12198
|
+
return `<schematictext schX={${position2.x}} schY={${position2.y}} text=${JSON.stringify(shape.content)} fontSize={${getTextFontSize(shape.fontSize)}} anchor=${JSON.stringify(getTextAnchor(shape.alignment))} color=${JSON.stringify(shape.fontColor)} schRotation={${round(-shape.rotation)}} />`;
|
|
12199
|
+
}
|
|
12200
|
+
if (shape.type === "PIN" && portMetadata) {
|
|
12201
|
+
if (shape.visibility !== "show") return void 0;
|
|
12202
|
+
const direction = getPinDirection(shape.rotation);
|
|
12203
|
+
const stemLength = getPinStemLength(shape.path);
|
|
12204
|
+
const position2 = alignPortToDrawing({
|
|
12205
|
+
position: transformPoint({ x: shape.x, y: shape.y }),
|
|
12206
|
+
direction,
|
|
12207
|
+
stemLength,
|
|
12208
|
+
drawingEndpoints
|
|
12209
|
+
});
|
|
12210
|
+
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
12211
|
+
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
12212
|
+
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
12213
|
+
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
12214
|
+
}
|
|
12215
|
+
if (shape.type === "IGNORED") return void 0;
|
|
12216
|
+
return void 0;
|
|
12217
|
+
};
|
|
12218
|
+
var generateSymbolTsx = (easyEdaJson, circuitJson, {
|
|
12219
|
+
includePorts = true,
|
|
12220
|
+
alignPortsToDrawing = false
|
|
12221
|
+
} = {}) => {
|
|
12222
|
+
const shapes = easyEdaJson.dataStr.shape;
|
|
12223
|
+
if (shapes.length === 0) return void 0;
|
|
12224
|
+
const headOrigin = {
|
|
12225
|
+
x: easyEdaJson.dataStr.head.x,
|
|
12226
|
+
y: easyEdaJson.dataStr.head.y
|
|
12227
|
+
};
|
|
12228
|
+
const bounds = easyEdaJson.dataStr.BBox;
|
|
12229
|
+
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
12230
|
+
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
12231
|
+
x: bounds.x + bounds.width / 2,
|
|
12232
|
+
y: bounds.y + bounds.height / 2
|
|
12233
|
+
};
|
|
12234
|
+
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
12235
|
+
easyEdaJson,
|
|
12236
|
+
circuitJson
|
|
12237
|
+
);
|
|
12238
|
+
const transformPoint = getPointTransformer(origin);
|
|
12239
|
+
const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
|
|
12240
|
+
const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
|
|
12241
|
+
(shape) => generateShapeTsx({
|
|
12242
|
+
shape,
|
|
12243
|
+
origin,
|
|
12244
|
+
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
|
|
12245
|
+
drawingEndpoints
|
|
12246
|
+
})
|
|
12247
|
+
).filter((tsx) => Boolean(tsx));
|
|
12248
|
+
if (shapeTsx.length === 0) return void 0;
|
|
12249
|
+
return `<symbol>
|
|
12250
|
+
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
12251
|
+
</symbol>`;
|
|
12252
|
+
};
|
|
12253
|
+
var hasNonBoxSchematicSymbol = (easyEdaJson) => {
|
|
12254
|
+
const drawableShapes = easyEdaJson.dataStr.shape.filter(
|
|
12255
|
+
(shape) => shape.type !== "PIN" && shape.type !== "TEXT" && shape.type !== "IGNORED"
|
|
12256
|
+
);
|
|
12257
|
+
if (drawableShapes.length === 0) return false;
|
|
12258
|
+
const rectangles = drawableShapes.filter(
|
|
12259
|
+
(shape) => shape.type === "RECTANGLE"
|
|
12260
|
+
);
|
|
12261
|
+
const onlyBoxPrimitives = drawableShapes.every(
|
|
12262
|
+
(shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
|
|
12263
|
+
);
|
|
12264
|
+
return rectangles.length !== 1 || !onlyBoxPrimitives;
|
|
12265
|
+
};
|
|
12266
|
+
|
|
11922
12267
|
// lib/websafe/generate-footprint-tsx.ts
|
|
11923
12268
|
var mapPortHints = (portHints, portHintsMap) => {
|
|
11924
12269
|
if (!portHintsMap || !portHints) return portHints;
|
|
@@ -12140,7 +12485,8 @@ var generateTypescriptComponent = ({
|
|
|
12140
12485
|
inductance: inductance2,
|
|
12141
12486
|
crystalFrequency,
|
|
12142
12487
|
crystalPinVariant,
|
|
12143
|
-
symbolTsx
|
|
12488
|
+
symbolTsx,
|
|
12489
|
+
schPinArrangement
|
|
12144
12490
|
}) => {
|
|
12145
12491
|
const safePinLabels = pinLabels ?? {};
|
|
12146
12492
|
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
@@ -12185,6 +12531,8 @@ ${polarizedPinLabelsString}
|
|
|
12185
12531
|
const symbolProp = symbolTsx ? ` symbol={
|
|
12186
12532
|
${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
|
|
12187
12533
|
}
|
|
12534
|
+
` : "";
|
|
12535
|
+
const schPinArrangementProp = schPinArrangement ? ` schPinArrangement={${JSON.stringify(schPinArrangement)}}
|
|
12188
12536
|
` : "";
|
|
12189
12537
|
const cadModelLines = [
|
|
12190
12538
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
@@ -12429,7 +12777,7 @@ ${pinAttributesBlock}export const ${componentName} = (props: ChipProps<typeof pi
|
|
|
12429
12777
|
return (
|
|
12430
12778
|
<chip
|
|
12431
12779
|
pinLabels={pinLabels}
|
|
12432
|
-
${pinAttributesProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
12780
|
+
${pinAttributesProp}${symbolProp}${schPinArrangementProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
12433
12781
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
12434
12782
|
footprint={${footprintTsx}}
|
|
12435
12783
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -12437,495 +12785,151 @@ ${cadModelLines}
|
|
|
12437
12785
|
}}` : ""}
|
|
12438
12786
|
{...props}
|
|
12439
12787
|
/>
|
|
12440
|
-
)
|
|
12441
|
-
}
|
|
12442
|
-
`.trim();
|
|
12443
|
-
};
|
|
12444
|
-
|
|
12445
|
-
// lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
|
|
12446
|
-
var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
|
|
12447
|
-
var normalizeCapacitanceValue = (value) => {
|
|
12448
|
-
if (typeof value !== "string") return void 0;
|
|
12449
|
-
const trimmedValue = value.trim();
|
|
12450
|
-
if (!capacitancePattern.test(trimmedValue)) return void 0;
|
|
12451
|
-
return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
|
|
12452
|
-
};
|
|
12453
|
-
var isCapacitorComponent = (betterEasy) => {
|
|
12454
|
-
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12455
|
-
const prefix = componentParameters.pre;
|
|
12456
|
-
const value = componentParameters.Value;
|
|
12457
|
-
return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
|
|
12458
|
-
};
|
|
12459
|
-
|
|
12460
|
-
// lib/websafe/convert-to-typescript-component/is-crystal-component.ts
|
|
12461
|
-
var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
|
|
12462
|
-
var isCrystalComponent = (betterEasy) => {
|
|
12463
|
-
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12464
|
-
const packageName = componentParameters.package;
|
|
12465
|
-
const value = componentParameters.Value;
|
|
12466
|
-
return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
|
|
12467
|
-
};
|
|
12468
|
-
|
|
12469
|
-
// lib/websafe/convert-to-typescript-component/is-inductor-component.ts
|
|
12470
|
-
var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
|
|
12471
|
-
var isInductorComponent = (betterEasy) => {
|
|
12472
|
-
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12473
|
-
const packageName = componentParameters.package;
|
|
12474
|
-
const value = componentParameters.Value;
|
|
12475
|
-
return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
|
|
12476
|
-
};
|
|
12477
|
-
|
|
12478
|
-
// lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
|
|
12479
|
-
var isMicroUsbConnectorComponent = (betterEasy) => {
|
|
12480
|
-
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12481
|
-
return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
|
|
12482
|
-
};
|
|
12483
|
-
|
|
12484
|
-
// lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
|
|
12485
|
-
var categoryValueContainsPushbutton = (value) => {
|
|
12486
|
-
if (typeof value === "string") {
|
|
12487
|
-
const normalized = value.toLowerCase();
|
|
12488
|
-
if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
|
|
12489
|
-
return false;
|
|
12490
|
-
}
|
|
12491
|
-
return /push\s*buttons?/.test(normalized) || /pushbuttons?/.test(normalized) || /tact(?:ile)?\s+switch(?:es)?/.test(normalized) || /keyboard\s+(?:switch(?:es)?|shaft)/.test(normalized) || /mechanical\s+keyboard\s+shaft/.test(normalized) || /\bkey[-_\s]+(?:th|smd)(?:\b|[_-])/.test(normalized);
|
|
12492
|
-
}
|
|
12493
|
-
if (Array.isArray(value)) {
|
|
12494
|
-
return value.some(categoryValueContainsPushbutton);
|
|
12495
|
-
}
|
|
12496
|
-
if (value && typeof value === "object") {
|
|
12497
|
-
return Object.values(value).some(categoryValueContainsPushbutton);
|
|
12498
|
-
}
|
|
12499
|
-
return false;
|
|
12500
|
-
};
|
|
12501
|
-
|
|
12502
|
-
// lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
|
|
12503
|
-
var isPushbuttonCategoryComponent = (betterEasy) => {
|
|
12504
|
-
const cPara = betterEasy.dataStr.head.c_para;
|
|
12505
|
-
return [
|
|
12506
|
-
betterEasy.tags,
|
|
12507
|
-
betterEasy.title,
|
|
12508
|
-
betterEasy.description,
|
|
12509
|
-
cPara.category,
|
|
12510
|
-
cPara.Category,
|
|
12511
|
-
cPara["LCSC Category"],
|
|
12512
|
-
cPara["JLCPCB Category"],
|
|
12513
|
-
cPara.package,
|
|
12514
|
-
cPara.pre,
|
|
12515
|
-
betterEasy.category
|
|
12516
|
-
].some(categoryValueContainsPushbutton);
|
|
12517
|
-
};
|
|
12518
|
-
|
|
12519
|
-
// lib/websafe/convert-to-typescript-component/is-resistor-component.ts
|
|
12520
|
-
var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
|
|
12521
|
-
var normalizeExplicitScale = (scale2) => {
|
|
12522
|
-
if (scale2 === "k" || scale2 === "K") return "k";
|
|
12523
|
-
if (scale2 === "m") return "m";
|
|
12524
|
-
if (scale2 === "M") return "M";
|
|
12525
|
-
if (scale2 === "g" || scale2 === "G") return "G";
|
|
12526
|
-
return "";
|
|
12788
|
+
)
|
|
12789
|
+
}
|
|
12790
|
+
`.trim();
|
|
12527
12791
|
};
|
|
12528
|
-
|
|
12792
|
+
|
|
12793
|
+
// lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
|
|
12794
|
+
var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
|
|
12795
|
+
var normalizeCapacitanceValue = (value) => {
|
|
12529
12796
|
if (typeof value !== "string") return void 0;
|
|
12530
|
-
const
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
);
|
|
12534
|
-
if (explicitUnitMatch) {
|
|
12535
|
-
const [, magnitude, scale2] = explicitUnitMatch;
|
|
12536
|
-
if (Number(magnitude) === 0) return "0ohm";
|
|
12537
|
-
return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
|
|
12538
|
-
}
|
|
12539
|
-
const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
|
|
12540
|
-
if (resistorCodeMatch) {
|
|
12541
|
-
const [, whole, multiplier, fraction] = resistorCodeMatch;
|
|
12542
|
-
const magnitude = fraction ? `${whole}.${fraction}` : whole;
|
|
12543
|
-
if (Number(magnitude) === 0) return "0ohm";
|
|
12544
|
-
const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
|
|
12545
|
-
return `${magnitude}${scale2}ohm`;
|
|
12546
|
-
}
|
|
12547
|
-
if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
|
|
12548
|
-
return void 0;
|
|
12797
|
+
const trimmedValue = value.trim();
|
|
12798
|
+
if (!capacitancePattern.test(trimmedValue)) return void 0;
|
|
12799
|
+
return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
|
|
12549
12800
|
};
|
|
12550
|
-
var
|
|
12801
|
+
var isCapacitorComponent = (betterEasy) => {
|
|
12551
12802
|
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12552
|
-
const
|
|
12553
|
-
|
|
12803
|
+
const prefix = componentParameters.pre;
|
|
12804
|
+
const value = componentParameters.Value;
|
|
12805
|
+
return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
|
|
12554
12806
|
};
|
|
12555
12807
|
|
|
12556
|
-
// lib/websafe/convert-to-typescript-component/
|
|
12557
|
-
var
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
|
|
12564
|
-
}
|
|
12565
|
-
if (Array.isArray(value)) {
|
|
12566
|
-
return value.some(categoryValueContainsSwitch);
|
|
12567
|
-
}
|
|
12568
|
-
if (value && typeof value === "object") {
|
|
12569
|
-
return Object.values(value).some(categoryValueContainsSwitch);
|
|
12570
|
-
}
|
|
12571
|
-
return false;
|
|
12808
|
+
// lib/websafe/convert-to-typescript-component/is-crystal-component.ts
|
|
12809
|
+
var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
|
|
12810
|
+
var isCrystalComponent = (betterEasy) => {
|
|
12811
|
+
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12812
|
+
const packageName = componentParameters.package;
|
|
12813
|
+
const value = componentParameters.Value;
|
|
12814
|
+
return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
|
|
12572
12815
|
};
|
|
12573
12816
|
|
|
12574
|
-
// lib/websafe/convert-to-typescript-component/is-
|
|
12575
|
-
var
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
cPara["LCSC Category"],
|
|
12582
|
-
cPara["JLCPCB Category"],
|
|
12583
|
-
betterEasy.category
|
|
12584
|
-
].some(categoryValueContainsSwitch);
|
|
12817
|
+
// lib/websafe/convert-to-typescript-component/is-inductor-component.ts
|
|
12818
|
+
var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
|
|
12819
|
+
var isInductorComponent = (betterEasy) => {
|
|
12820
|
+
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12821
|
+
const packageName = componentParameters.package;
|
|
12822
|
+
const value = componentParameters.Value;
|
|
12823
|
+
return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
|
|
12585
12824
|
};
|
|
12586
12825
|
|
|
12587
|
-
// lib/websafe/convert-to-typescript-component/
|
|
12588
|
-
var
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
var getPointTransformer = (origin) => (point2) => ({
|
|
12592
|
-
x: toSchematicUnits(point2.x - origin.x),
|
|
12593
|
-
y: toSchematicUnits(origin.y - point2.y)
|
|
12594
|
-
});
|
|
12595
|
-
var formatNumber = (value) => String(round(value));
|
|
12596
|
-
var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
|
|
12597
|
-
A: 7,
|
|
12598
|
-
C: 6,
|
|
12599
|
-
H: 1,
|
|
12600
|
-
L: 2,
|
|
12601
|
-
M: 2,
|
|
12602
|
-
Q: 4,
|
|
12603
|
-
S: 4,
|
|
12604
|
-
T: 2,
|
|
12605
|
-
V: 1,
|
|
12606
|
-
Z: 0
|
|
12607
|
-
};
|
|
12608
|
-
var transformSvgPath = (pathData, origin) => {
|
|
12609
|
-
const tokens = pathData.match(
|
|
12610
|
-
/[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
|
|
12611
|
-
) ?? [];
|
|
12612
|
-
const output = [];
|
|
12613
|
-
let command = "";
|
|
12614
|
-
let tokenIndex = 0;
|
|
12615
|
-
let currentX = 0;
|
|
12616
|
-
let currentY = 0;
|
|
12617
|
-
let subpathStartX = 0;
|
|
12618
|
-
let subpathStartY = 0;
|
|
12619
|
-
const transformPoint = getPointTransformer(origin);
|
|
12620
|
-
const getOriginalPoint = (x, y, isRelative) => ({
|
|
12621
|
-
x: isRelative ? currentX + x : x,
|
|
12622
|
-
y: isRelative ? currentY + y : y
|
|
12623
|
-
});
|
|
12624
|
-
while (tokenIndex < tokens.length) {
|
|
12625
|
-
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
|
|
12626
|
-
command = tokens[tokenIndex];
|
|
12627
|
-
tokenIndex += 1;
|
|
12628
|
-
}
|
|
12629
|
-
if (!command) break;
|
|
12630
|
-
const upperCommand = command.toUpperCase();
|
|
12631
|
-
const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
|
|
12632
|
-
if (parameterCount === void 0) break;
|
|
12633
|
-
if (upperCommand === "Z") {
|
|
12634
|
-
output.push("Z");
|
|
12635
|
-
currentX = subpathStartX;
|
|
12636
|
-
currentY = subpathStartY;
|
|
12637
|
-
command = "";
|
|
12638
|
-
continue;
|
|
12639
|
-
}
|
|
12640
|
-
if (tokenIndex + parameterCount > tokens.length) break;
|
|
12641
|
-
if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
|
|
12642
|
-
const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
|
|
12643
|
-
tokenIndex += parameterCount;
|
|
12644
|
-
const isRelative = command === command.toLowerCase();
|
|
12645
|
-
if (upperCommand === "H" || upperCommand === "V") {
|
|
12646
|
-
const point2 = getOriginalPoint(
|
|
12647
|
-
upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
|
|
12648
|
-
upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
|
|
12649
|
-
isRelative
|
|
12650
|
-
);
|
|
12651
|
-
const transformed = transformPoint(point2);
|
|
12652
|
-
output.push(
|
|
12653
|
-
`L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
12654
|
-
);
|
|
12655
|
-
currentX = point2.x;
|
|
12656
|
-
currentY = point2.y;
|
|
12657
|
-
continue;
|
|
12658
|
-
}
|
|
12659
|
-
if (["M", "L", "T"].includes(upperCommand)) {
|
|
12660
|
-
const point2 = getOriginalPoint(values[0], values[1], isRelative);
|
|
12661
|
-
const transformed = transformPoint(point2);
|
|
12662
|
-
output.push(
|
|
12663
|
-
`${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
|
|
12664
|
-
);
|
|
12665
|
-
currentX = point2.x;
|
|
12666
|
-
currentY = point2.y;
|
|
12667
|
-
if (upperCommand === "M") {
|
|
12668
|
-
subpathStartX = point2.x;
|
|
12669
|
-
subpathStartY = point2.y;
|
|
12670
|
-
command = isRelative ? "l" : "L";
|
|
12671
|
-
}
|
|
12672
|
-
continue;
|
|
12673
|
-
}
|
|
12674
|
-
if (["C", "S", "Q"].includes(upperCommand)) {
|
|
12675
|
-
const transformedValues = [];
|
|
12676
|
-
for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
|
|
12677
|
-
const point2 = getOriginalPoint(
|
|
12678
|
-
values[valueIndex],
|
|
12679
|
-
values[valueIndex + 1],
|
|
12680
|
-
isRelative
|
|
12681
|
-
);
|
|
12682
|
-
const transformed = transformPoint(point2);
|
|
12683
|
-
transformedValues.push(transformed.x, transformed.y);
|
|
12684
|
-
}
|
|
12685
|
-
output.push(
|
|
12686
|
-
`${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
|
|
12687
|
-
);
|
|
12688
|
-
currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
|
|
12689
|
-
currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
|
|
12690
|
-
continue;
|
|
12691
|
-
}
|
|
12692
|
-
if (upperCommand === "A") {
|
|
12693
|
-
const endpoint = getOriginalPoint(values[5], values[6], isRelative);
|
|
12694
|
-
const transformedEndpoint = transformPoint(endpoint);
|
|
12695
|
-
output.push(
|
|
12696
|
-
[
|
|
12697
|
-
"A",
|
|
12698
|
-
formatNumber(toSchematicUnits(Math.abs(values[0]))),
|
|
12699
|
-
formatNumber(toSchematicUnits(Math.abs(values[1]))),
|
|
12700
|
-
formatNumber(-values[2]),
|
|
12701
|
-
String(values[3]),
|
|
12702
|
-
String(values[4] === 0 ? 1 : 0),
|
|
12703
|
-
formatNumber(transformedEndpoint.x),
|
|
12704
|
-
formatNumber(transformedEndpoint.y)
|
|
12705
|
-
].join(" ")
|
|
12706
|
-
);
|
|
12707
|
-
currentX = endpoint.x;
|
|
12708
|
-
currentY = endpoint.y;
|
|
12709
|
-
}
|
|
12710
|
-
}
|
|
12711
|
-
return output.join(" ");
|
|
12712
|
-
};
|
|
12713
|
-
var getPinDirection = (rotation2) => {
|
|
12714
|
-
const normalizedRotation = (rotation2 % 360 + 360) % 360;
|
|
12715
|
-
if (normalizedRotation === 90) return "up";
|
|
12716
|
-
if (normalizedRotation === 180) return "left";
|
|
12717
|
-
if (normalizedRotation === 270) return "down";
|
|
12718
|
-
return "right";
|
|
12719
|
-
};
|
|
12720
|
-
var getPinStemLength = (path) => {
|
|
12721
|
-
const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
|
|
12722
|
-
if (!segment) return void 0;
|
|
12723
|
-
return toSchematicUnits(Math.abs(Number(segment[1])));
|
|
12724
|
-
};
|
|
12725
|
-
var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
|
|
12726
|
-
if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
|
|
12727
|
-
const first = shape.points[0];
|
|
12728
|
-
const last = shape.points[shape.points.length - 1];
|
|
12729
|
-
if (first.x === last.x && first.y === last.y) return [];
|
|
12730
|
-
return [transformPoint(first), transformPoint(last)];
|
|
12731
|
-
});
|
|
12732
|
-
var alignPortToDrawing = ({
|
|
12733
|
-
position: position2,
|
|
12734
|
-
direction,
|
|
12735
|
-
stemLength,
|
|
12736
|
-
drawingEndpoints
|
|
12737
|
-
}) => {
|
|
12738
|
-
if (stemLength === void 0) return position2;
|
|
12739
|
-
const outwardDirection = getUnitVectorFromDirection(direction);
|
|
12740
|
-
const expectedBodyConnection = {
|
|
12741
|
-
x: position2.x - outwardDirection.x * stemLength,
|
|
12742
|
-
y: position2.y - outwardDirection.y * stemLength
|
|
12743
|
-
};
|
|
12744
|
-
const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
|
|
12745
|
-
const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
|
|
12746
|
-
endpoint,
|
|
12747
|
-
distance: distance2(endpoint, expectedBodyConnection)
|
|
12748
|
-
})).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
|
|
12749
|
-
if (!nearestEndpoint) return position2;
|
|
12750
|
-
return {
|
|
12751
|
-
x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
|
|
12752
|
-
y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
|
|
12753
|
-
};
|
|
12754
|
-
};
|
|
12755
|
-
var getTextFontSize = (fontSize) => {
|
|
12756
|
-
const numericFontSize = Number.parseFloat(fontSize);
|
|
12757
|
-
if (!Number.isFinite(numericFontSize)) return 0.2;
|
|
12758
|
-
return toSchematicUnits(numericFontSize);
|
|
12759
|
-
};
|
|
12760
|
-
var getTextAnchor = (alignment) => {
|
|
12761
|
-
if (alignment === "L") return "left";
|
|
12762
|
-
if (alignment === "R") return "right";
|
|
12763
|
-
return "center";
|
|
12826
|
+
// lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
|
|
12827
|
+
var isMicroUsbConnectorComponent = (betterEasy) => {
|
|
12828
|
+
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12829
|
+
return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
|
|
12764
12830
|
};
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
)
|
|
12769
|
-
|
|
12770
|
-
(
|
|
12771
|
-
|
|
12772
|
-
const sourcePorts = circuitJson.filter(
|
|
12773
|
-
(element) => element.type === "source_port"
|
|
12774
|
-
);
|
|
12775
|
-
const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
12776
|
-
pads.forEach((pad, padIndex) => {
|
|
12777
|
-
const sourcePort = sourcePorts.find(
|
|
12778
|
-
(port) => port.source_port_id === `source_port_${padIndex + 1}`
|
|
12779
|
-
);
|
|
12780
|
-
if (!sourcePort) return;
|
|
12781
|
-
const padNumber = String(pad.number);
|
|
12782
|
-
sourcePortNamesByPadNumber.set(padNumber, [
|
|
12783
|
-
...sourcePortNamesByPadNumber.get(padNumber) ?? [],
|
|
12784
|
-
sourcePort.name
|
|
12785
|
-
]);
|
|
12786
|
-
});
|
|
12787
|
-
const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
|
|
12788
|
-
const usedPortNames = /* @__PURE__ */ new Set();
|
|
12789
|
-
const metadataByShapeId = /* @__PURE__ */ new Map();
|
|
12790
|
-
pins.forEach((pin, pinIndex) => {
|
|
12791
|
-
const pinNumberKey = String(pin.pinNumber);
|
|
12792
|
-
const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
|
|
12793
|
-
const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
|
|
12794
|
-
let portName = matchingPortNames[matchingPortIndex];
|
|
12795
|
-
usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
|
|
12796
|
-
if (!portName && pin.label) {
|
|
12797
|
-
const normalizedLabel = normalizeSymbolName(pin.label);
|
|
12798
|
-
portName = sourcePorts.find(
|
|
12799
|
-
(port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
|
|
12800
|
-
)?.name;
|
|
12801
|
-
}
|
|
12802
|
-
const numericPinNumber = Number(pin.pinNumber);
|
|
12803
|
-
if (!portName && Number.isInteger(numericPinNumber)) {
|
|
12804
|
-
const numericPortName = `pin${numericPinNumber}`;
|
|
12805
|
-
if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
|
|
12806
|
-
portName = numericPortName;
|
|
12807
|
-
}
|
|
12831
|
+
|
|
12832
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
|
|
12833
|
+
var categoryValueContainsPushbutton = (value) => {
|
|
12834
|
+
if (typeof value === "string") {
|
|
12835
|
+
const normalized = value.toLowerCase();
|
|
12836
|
+
if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
|
|
12837
|
+
return false;
|
|
12808
12838
|
}
|
|
12809
|
-
|
|
12810
|
-
portName ??= `pin${pinIndex + 1}`;
|
|
12811
|
-
usedPortNames.add(portName);
|
|
12812
|
-
const sourcePort = sourcePorts.find((port) => port.name === portName);
|
|
12813
|
-
metadataByShapeId.set(pin.id, {
|
|
12814
|
-
name: portName,
|
|
12815
|
-
pinNumber: sourcePort?.pin_number,
|
|
12816
|
-
aliases: [
|
|
12817
|
-
...sourcePort?.port_hints ?? [],
|
|
12818
|
-
...pin.label ? [normalizeSymbolName(pin.label)] : []
|
|
12819
|
-
].filter(
|
|
12820
|
-
(alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
|
|
12821
|
-
)
|
|
12822
|
-
});
|
|
12823
|
-
});
|
|
12824
|
-
return metadataByShapeId;
|
|
12825
|
-
};
|
|
12826
|
-
var generateShapeTsx = ({
|
|
12827
|
-
shape,
|
|
12828
|
-
origin,
|
|
12829
|
-
portMetadata,
|
|
12830
|
-
drawingEndpoints = []
|
|
12831
|
-
}) => {
|
|
12832
|
-
const transformPoint = getPointTransformer(origin);
|
|
12833
|
-
if (shape.type === "RECTANGLE") {
|
|
12834
|
-
const center = transformPoint({
|
|
12835
|
-
x: shape.position.x + shape.width / 2,
|
|
12836
|
-
y: shape.position.y + shape.height / 2
|
|
12837
|
-
});
|
|
12838
|
-
return `<schematicrect schX={${center.x}} schY={${center.y}} width={${toSchematicUnits(shape.width)}} height={${toSchematicUnits(shape.height)}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12839
|
-
}
|
|
12840
|
-
if (shape.type === "ELLIPSE") {
|
|
12841
|
-
const center = transformPoint(shape.center);
|
|
12842
|
-
return `<schematiccircle center={{ x: ${center.x}, y: ${center.y} }} radius={${toSchematicUnits(Math.max(shape.radiusX, shape.radiusY))}} color=${JSON.stringify(shape.color)}${shape.fillColor && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12843
|
-
}
|
|
12844
|
-
if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
|
|
12845
|
-
const isPolygon = shape.type === "POLYGON";
|
|
12846
|
-
const points = shape.points.map(transformPoint);
|
|
12847
|
-
if (isPolygon && points.length > 0) points.push(points[0]);
|
|
12848
|
-
return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12839
|
+
return /push\s*buttons?/.test(normalized) || /pushbuttons?/.test(normalized) || /tact(?:ile)?\s+switch(?:es)?/.test(normalized) || /keyboard\s+(?:switch(?:es)?|shaft)/.test(normalized) || /mechanical\s+keyboard\s+shaft/.test(normalized) || /\bkey[-_\s]+(?:th|smd)(?:\b|[_-])/.test(normalized);
|
|
12849
12840
|
}
|
|
12850
|
-
if (
|
|
12851
|
-
|
|
12852
|
-
if (!transformedPath) return void 0;
|
|
12853
|
-
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
|
|
12841
|
+
if (Array.isArray(value)) {
|
|
12842
|
+
return value.some(categoryValueContainsPushbutton);
|
|
12854
12843
|
}
|
|
12855
|
-
if (
|
|
12856
|
-
|
|
12857
|
-
if (!transformedPath) return void 0;
|
|
12858
|
-
return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
|
|
12844
|
+
if (value && typeof value === "object") {
|
|
12845
|
+
return Object.values(value).some(categoryValueContainsPushbutton);
|
|
12859
12846
|
}
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12847
|
+
return false;
|
|
12848
|
+
};
|
|
12849
|
+
|
|
12850
|
+
// lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
|
|
12851
|
+
var isPushbuttonCategoryComponent = (betterEasy) => {
|
|
12852
|
+
const cPara = betterEasy.dataStr.head.c_para;
|
|
12853
|
+
return [
|
|
12854
|
+
betterEasy.tags,
|
|
12855
|
+
betterEasy.title,
|
|
12856
|
+
betterEasy.description,
|
|
12857
|
+
cPara.category,
|
|
12858
|
+
cPara.Category,
|
|
12859
|
+
cPara["LCSC Category"],
|
|
12860
|
+
cPara["JLCPCB Category"],
|
|
12861
|
+
cPara.package,
|
|
12862
|
+
cPara.pre,
|
|
12863
|
+
betterEasy.category
|
|
12864
|
+
].some(categoryValueContainsPushbutton);
|
|
12865
|
+
};
|
|
12866
|
+
|
|
12867
|
+
// lib/websafe/convert-to-typescript-component/is-resistor-component.ts
|
|
12868
|
+
var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
|
|
12869
|
+
var normalizeExplicitScale = (scale2) => {
|
|
12870
|
+
if (scale2 === "k" || scale2 === "K") return "k";
|
|
12871
|
+
if (scale2 === "m") return "m";
|
|
12872
|
+
if (scale2 === "M") return "M";
|
|
12873
|
+
if (scale2 === "g" || scale2 === "G") return "G";
|
|
12874
|
+
return "";
|
|
12875
|
+
};
|
|
12876
|
+
var normalizeResistorValue = (value) => {
|
|
12877
|
+
if (typeof value !== "string") return void 0;
|
|
12878
|
+
const compactValue = value.trim().replace(/\s+/g, "");
|
|
12879
|
+
const explicitUnitMatch = compactValue.match(
|
|
12880
|
+
/^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
|
|
12881
|
+
);
|
|
12882
|
+
if (explicitUnitMatch) {
|
|
12883
|
+
const [, magnitude, scale2] = explicitUnitMatch;
|
|
12884
|
+
if (Number(magnitude) === 0) return "0ohm";
|
|
12885
|
+
return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
|
|
12864
12886
|
}
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
const
|
|
12868
|
-
const
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
drawingEndpoints
|
|
12873
|
-
});
|
|
12874
|
-
const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
|
|
12875
|
-
const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
|
|
12876
|
-
const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
|
|
12877
|
-
return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
|
|
12887
|
+
const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
|
|
12888
|
+
if (resistorCodeMatch) {
|
|
12889
|
+
const [, whole, multiplier, fraction] = resistorCodeMatch;
|
|
12890
|
+
const magnitude = fraction ? `${whole}.${fraction}` : whole;
|
|
12891
|
+
if (Number(magnitude) === 0) return "0ohm";
|
|
12892
|
+
const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
|
|
12893
|
+
return `${magnitude}${scale2}ohm`;
|
|
12878
12894
|
}
|
|
12879
|
-
if (
|
|
12895
|
+
if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
|
|
12880
12896
|
return void 0;
|
|
12881
12897
|
};
|
|
12882
|
-
var
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
12886
|
-
const shapes = easyEdaJson.dataStr.shape;
|
|
12887
|
-
if (shapes.length === 0) return void 0;
|
|
12888
|
-
const headOrigin = {
|
|
12889
|
-
x: easyEdaJson.dataStr.head.x,
|
|
12890
|
-
y: easyEdaJson.dataStr.head.y
|
|
12891
|
-
};
|
|
12892
|
-
const bounds = easyEdaJson.dataStr.BBox;
|
|
12893
|
-
const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
|
|
12894
|
-
const origin = isHeadOriginInsideBounds ? headOrigin : {
|
|
12895
|
-
x: bounds.x + bounds.width / 2,
|
|
12896
|
-
y: bounds.y + bounds.height / 2
|
|
12897
|
-
};
|
|
12898
|
-
const portMetadataByShapeId = getPortMetadataByShapeId(
|
|
12899
|
-
easyEdaJson,
|
|
12900
|
-
circuitJson
|
|
12901
|
-
);
|
|
12902
|
-
const transformPoint = getPointTransformer(origin);
|
|
12903
|
-
const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
|
|
12904
|
-
const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
|
|
12905
|
-
(shape) => generateShapeTsx({
|
|
12906
|
-
shape,
|
|
12907
|
-
origin,
|
|
12908
|
-
portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
|
|
12909
|
-
drawingEndpoints
|
|
12910
|
-
})
|
|
12911
|
-
).filter((tsx) => Boolean(tsx));
|
|
12912
|
-
if (shapeTsx.length === 0) return void 0;
|
|
12913
|
-
return `<symbol>
|
|
12914
|
-
${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
|
|
12915
|
-
</symbol>`;
|
|
12898
|
+
var isResistorComponent = (betterEasy) => {
|
|
12899
|
+
const componentParameters = betterEasy.dataStr.head.c_para;
|
|
12900
|
+
const packageName = componentParameters.package;
|
|
12901
|
+
return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
|
|
12916
12902
|
};
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
)
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
)
|
|
12928
|
-
|
|
12903
|
+
|
|
12904
|
+
// lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
|
|
12905
|
+
var categoryValueContainsSwitch = (value) => {
|
|
12906
|
+
if (typeof value === "string") {
|
|
12907
|
+
const normalized = value.toLowerCase();
|
|
12908
|
+
if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
|
|
12909
|
+
return false;
|
|
12910
|
+
}
|
|
12911
|
+
return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
|
|
12912
|
+
}
|
|
12913
|
+
if (Array.isArray(value)) {
|
|
12914
|
+
return value.some(categoryValueContainsSwitch);
|
|
12915
|
+
}
|
|
12916
|
+
if (value && typeof value === "object") {
|
|
12917
|
+
return Object.values(value).some(categoryValueContainsSwitch);
|
|
12918
|
+
}
|
|
12919
|
+
return false;
|
|
12920
|
+
};
|
|
12921
|
+
|
|
12922
|
+
// lib/websafe/convert-to-typescript-component/is-switch-category-component.ts
|
|
12923
|
+
var isSwitchCategoryComponent = (betterEasy) => {
|
|
12924
|
+
const cPara = betterEasy.dataStr.head.c_para;
|
|
12925
|
+
return [
|
|
12926
|
+
betterEasy.tags,
|
|
12927
|
+
cPara.category,
|
|
12928
|
+
cPara.Category,
|
|
12929
|
+
cPara["LCSC Category"],
|
|
12930
|
+
cPara["JLCPCB Category"],
|
|
12931
|
+
betterEasy.category
|
|
12932
|
+
].some(categoryValueContainsSwitch);
|
|
12929
12933
|
};
|
|
12930
12934
|
|
|
12931
12935
|
// lib/websafe/convert-to-typescript-component/index.tsx
|
|
@@ -12941,6 +12945,24 @@ var getGeneratedComponentType = (betterEasy, pinCount) => {
|
|
|
12941
12945
|
if (isMicroUsbConnectorComponent(betterEasy)) return "connector";
|
|
12942
12946
|
return "chip";
|
|
12943
12947
|
};
|
|
12948
|
+
var getVisibleSchematicPinArrangement = (betterEasy) => {
|
|
12949
|
+
const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN");
|
|
12950
|
+
if (!pins.some((pin) => pin.visibility !== "show")) return void 0;
|
|
12951
|
+
const arrangement = {
|
|
12952
|
+
leftSide: [],
|
|
12953
|
+
rightSide: [],
|
|
12954
|
+
topSide: [],
|
|
12955
|
+
bottomSide: []
|
|
12956
|
+
};
|
|
12957
|
+
for (const pin of pins.filter((pin2) => pin2.visibility === "show")) {
|
|
12958
|
+
const rotation2 = (pin.rotation % 360 + 360) % 360;
|
|
12959
|
+
const side = rotation2 === 90 ? "topSide" : rotation2 === 180 ? "leftSide" : rotation2 === 270 ? "bottomSide" : "rightSide";
|
|
12960
|
+
arrangement[side].push(pin.pinNumber);
|
|
12961
|
+
}
|
|
12962
|
+
return Object.fromEntries(
|
|
12963
|
+
Object.entries(arrangement).filter(([, pins2]) => pins2.length > 0)
|
|
12964
|
+
);
|
|
12965
|
+
};
|
|
12944
12966
|
var convertRawEasyToTsx = async ({ rawEasy }) => {
|
|
12945
12967
|
const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
|
|
12946
12968
|
const result = await convertBetterEasyToTsx({
|
|
@@ -12974,6 +12996,11 @@ var convertBetterEasyToTsx = async ({
|
|
|
12974
12996
|
}
|
|
12975
12997
|
const componentName = normalizeManufacturerPartNumber(manufacturerPartNumber);
|
|
12976
12998
|
const sourcePorts = su(circuitJson).source_port.list();
|
|
12999
|
+
const hiddenSchematicPinNumbers = new Set(
|
|
13000
|
+
betterEasy.dataStr.shape.flatMap(
|
|
13001
|
+
(shape) => shape.type === "PIN" && shape.visibility !== "show" ? [String(shape.pinNumber)] : []
|
|
13002
|
+
)
|
|
13003
|
+
);
|
|
12977
13004
|
const pinLabels = {};
|
|
12978
13005
|
const sortedPorts = sourcePorts.sort((a, b) => {
|
|
12979
13006
|
const aNum = Number.parseInt(a.name.replace("pin", ""));
|
|
@@ -12981,6 +13008,7 @@ var convertBetterEasyToTsx = async ({
|
|
|
12981
13008
|
return aNum - bNum;
|
|
12982
13009
|
});
|
|
12983
13010
|
for (const sourcePort of sortedPorts) {
|
|
13011
|
+
if (hiddenSchematicPinNumbers.has(String(sourcePort.pin_number))) continue;
|
|
12984
13012
|
pinLabels[sourcePort.name] = [
|
|
12985
13013
|
sourcePort.name,
|
|
12986
13014
|
...sourcePort.port_hints ?? []
|
|
@@ -13018,6 +13046,7 @@ var convertBetterEasyToTsx = async ({
|
|
|
13018
13046
|
const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && !isMultiPinInductor && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
|
|
13019
13047
|
alignPortsToDrawing: isPassiveWithCustomSymbol
|
|
13020
13048
|
}) : void 0;
|
|
13049
|
+
const schPinArrangement = symbolTsx ? void 0 : getVisibleSchematicPinArrangement(betterEasy);
|
|
13021
13050
|
return generateTypescriptComponent({
|
|
13022
13051
|
componentName,
|
|
13023
13052
|
manufacturerPartNumber,
|
|
@@ -13032,7 +13061,8 @@ var convertBetterEasyToTsx = async ({
|
|
|
13032
13061
|
inductance: inductance2,
|
|
13033
13062
|
crystalFrequency,
|
|
13034
13063
|
crystalPinVariant,
|
|
13035
|
-
symbolTsx
|
|
13064
|
+
symbolTsx,
|
|
13065
|
+
schPinArrangement
|
|
13036
13066
|
});
|
|
13037
13067
|
};
|
|
13038
13068
|
var checkModelObjUrlValidity = async (url) => {
|