easyeda 0.0.330 → 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/main.cjs CHANGED
@@ -1026,7 +1026,7 @@ var import_promises = __toESM(require("fs/promises"), 1);
1026
1026
  var package_default = {
1027
1027
  name: "easyeda",
1028
1028
  type: "module",
1029
- version: "0.0.329",
1029
+ version: "0.0.330",
1030
1030
  files: [
1031
1031
  "dist"
1032
1032
  ],
@@ -9139,6 +9139,351 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
9139
9139
  return placementPromise;
9140
9140
  };
9141
9141
 
9142
+ // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
9143
+ var round = (value) => Number(value.toFixed(6));
9144
+ var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
9145
+ var toSchematicUnits = (value) => round(value * EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT);
9146
+ var getPointTransformer = (origin) => (point2) => ({
9147
+ x: toSchematicUnits(point2.x - origin.x),
9148
+ y: toSchematicUnits(origin.y - point2.y)
9149
+ });
9150
+ var formatNumber = (value) => String(round(value));
9151
+ var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
9152
+ A: 7,
9153
+ C: 6,
9154
+ H: 1,
9155
+ L: 2,
9156
+ M: 2,
9157
+ Q: 4,
9158
+ S: 4,
9159
+ T: 2,
9160
+ V: 1,
9161
+ Z: 0
9162
+ };
9163
+ var transformSvgPath = (pathData, origin) => {
9164
+ const tokens = pathData.match(
9165
+ /[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
9166
+ ) ?? [];
9167
+ const output = [];
9168
+ let command = "";
9169
+ let tokenIndex = 0;
9170
+ let currentX = 0;
9171
+ let currentY = 0;
9172
+ let subpathStartX = 0;
9173
+ let subpathStartY = 0;
9174
+ const transformPoint = getPointTransformer(origin);
9175
+ const getOriginalPoint = (x, y, isRelative) => ({
9176
+ x: isRelative ? currentX + x : x,
9177
+ y: isRelative ? currentY + y : y
9178
+ });
9179
+ while (tokenIndex < tokens.length) {
9180
+ if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
9181
+ command = tokens[tokenIndex];
9182
+ tokenIndex += 1;
9183
+ }
9184
+ if (!command) break;
9185
+ const upperCommand = command.toUpperCase();
9186
+ const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
9187
+ if (parameterCount === void 0) break;
9188
+ if (upperCommand === "Z") {
9189
+ output.push("Z");
9190
+ currentX = subpathStartX;
9191
+ currentY = subpathStartY;
9192
+ command = "";
9193
+ continue;
9194
+ }
9195
+ if (tokenIndex + parameterCount > tokens.length) break;
9196
+ if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
9197
+ const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
9198
+ tokenIndex += parameterCount;
9199
+ const isRelative = command === command.toLowerCase();
9200
+ if (upperCommand === "H" || upperCommand === "V") {
9201
+ const point2 = getOriginalPoint(
9202
+ upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
9203
+ upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
9204
+ isRelative
9205
+ );
9206
+ const transformed = transformPoint(point2);
9207
+ output.push(
9208
+ `L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
9209
+ );
9210
+ currentX = point2.x;
9211
+ currentY = point2.y;
9212
+ continue;
9213
+ }
9214
+ if (["M", "L", "T"].includes(upperCommand)) {
9215
+ const point2 = getOriginalPoint(values[0], values[1], isRelative);
9216
+ const transformed = transformPoint(point2);
9217
+ output.push(
9218
+ `${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
9219
+ );
9220
+ currentX = point2.x;
9221
+ currentY = point2.y;
9222
+ if (upperCommand === "M") {
9223
+ subpathStartX = point2.x;
9224
+ subpathStartY = point2.y;
9225
+ command = isRelative ? "l" : "L";
9226
+ }
9227
+ continue;
9228
+ }
9229
+ if (["C", "S", "Q"].includes(upperCommand)) {
9230
+ const transformedValues = [];
9231
+ for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
9232
+ const point2 = getOriginalPoint(
9233
+ values[valueIndex],
9234
+ values[valueIndex + 1],
9235
+ isRelative
9236
+ );
9237
+ const transformed = transformPoint(point2);
9238
+ transformedValues.push(transformed.x, transformed.y);
9239
+ }
9240
+ output.push(
9241
+ `${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
9242
+ );
9243
+ currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
9244
+ currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
9245
+ continue;
9246
+ }
9247
+ if (upperCommand === "A") {
9248
+ const endpoint = getOriginalPoint(values[5], values[6], isRelative);
9249
+ const transformedEndpoint = transformPoint(endpoint);
9250
+ output.push(
9251
+ [
9252
+ "A",
9253
+ formatNumber(toSchematicUnits(Math.abs(values[0]))),
9254
+ formatNumber(toSchematicUnits(Math.abs(values[1]))),
9255
+ formatNumber(-values[2]),
9256
+ String(values[3]),
9257
+ String(values[4] === 0 ? 1 : 0),
9258
+ formatNumber(transformedEndpoint.x),
9259
+ formatNumber(transformedEndpoint.y)
9260
+ ].join(" ")
9261
+ );
9262
+ currentX = endpoint.x;
9263
+ currentY = endpoint.y;
9264
+ }
9265
+ }
9266
+ return output.join(" ");
9267
+ };
9268
+ var getPinDirection = (rotation2) => {
9269
+ const normalizedRotation = (rotation2 % 360 + 360) % 360;
9270
+ if (normalizedRotation === 90) return "up";
9271
+ if (normalizedRotation === 180) return "left";
9272
+ if (normalizedRotation === 270) return "down";
9273
+ return "right";
9274
+ };
9275
+ var getPinStemLength = (path) => {
9276
+ const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
9277
+ if (!segment) return void 0;
9278
+ return toSchematicUnits(Math.abs(Number(segment[1])));
9279
+ };
9280
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
9281
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
9282
+ const first = shape.points[0];
9283
+ const last = shape.points[shape.points.length - 1];
9284
+ if (first.x === last.x && first.y === last.y) return [];
9285
+ return [transformPoint(first), transformPoint(last)];
9286
+ });
9287
+ var alignPortToDrawing = ({
9288
+ position: position2,
9289
+ direction,
9290
+ stemLength,
9291
+ drawingEndpoints
9292
+ }) => {
9293
+ if (stemLength === void 0) return position2;
9294
+ const outwardDirection = getUnitVectorFromDirection(direction);
9295
+ const expectedBodyConnection = {
9296
+ x: position2.x - outwardDirection.x * stemLength,
9297
+ y: position2.y - outwardDirection.y * stemLength
9298
+ };
9299
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
9300
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
9301
+ endpoint,
9302
+ distance: distance2(endpoint, expectedBodyConnection)
9303
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
9304
+ if (!nearestEndpoint) return position2;
9305
+ return {
9306
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
9307
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
9308
+ };
9309
+ };
9310
+ var getTextFontSize = (fontSize) => {
9311
+ const numericFontSize = Number.parseFloat(fontSize);
9312
+ if (!Number.isFinite(numericFontSize)) return 0.2;
9313
+ return toSchematicUnits(numericFontSize);
9314
+ };
9315
+ var getTextAnchor = (alignment) => {
9316
+ if (alignment === "L") return "left";
9317
+ if (alignment === "R") return "right";
9318
+ return "center";
9319
+ };
9320
+ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
9321
+ const pins = easyEdaJson.dataStr.shape.filter(
9322
+ (shape) => shape.type === "PIN"
9323
+ );
9324
+ const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
9325
+ (shape) => shape.type === "PAD"
9326
+ );
9327
+ const sourcePorts = circuitJson.filter(
9328
+ (element) => element.type === "source_port"
9329
+ );
9330
+ const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
9331
+ pads.forEach((pad, padIndex) => {
9332
+ const sourcePort = sourcePorts.find(
9333
+ (port) => port.source_port_id === `source_port_${padIndex + 1}`
9334
+ );
9335
+ if (!sourcePort) return;
9336
+ const padNumber = String(pad.number);
9337
+ sourcePortNamesByPadNumber.set(padNumber, [
9338
+ ...sourcePortNamesByPadNumber.get(padNumber) ?? [],
9339
+ sourcePort.name
9340
+ ]);
9341
+ });
9342
+ const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
9343
+ const usedPortNames = /* @__PURE__ */ new Set();
9344
+ const metadataByShapeId = /* @__PURE__ */ new Map();
9345
+ pins.forEach((pin, pinIndex) => {
9346
+ const pinNumberKey = String(pin.pinNumber);
9347
+ const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
9348
+ const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
9349
+ let portName = matchingPortNames[matchingPortIndex];
9350
+ usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
9351
+ if (!portName && pin.label) {
9352
+ const normalizedLabel = normalizeSymbolName(pin.label);
9353
+ portName = sourcePorts.find(
9354
+ (port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
9355
+ )?.name;
9356
+ }
9357
+ const numericPinNumber = Number(pin.pinNumber);
9358
+ if (!portName && Number.isInteger(numericPinNumber)) {
9359
+ const numericPortName = `pin${numericPinNumber}`;
9360
+ if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
9361
+ portName = numericPortName;
9362
+ }
9363
+ }
9364
+ portName ??= sourcePorts.find((port) => !usedPortNames.has(port.name))?.name;
9365
+ portName ??= `pin${pinIndex + 1}`;
9366
+ usedPortNames.add(portName);
9367
+ const sourcePort = sourcePorts.find((port) => port.name === portName);
9368
+ metadataByShapeId.set(pin.id, {
9369
+ name: portName,
9370
+ pinNumber: sourcePort?.pin_number,
9371
+ aliases: [
9372
+ ...sourcePort?.port_hints ?? [],
9373
+ ...pin.label ? [normalizeSymbolName(pin.label)] : []
9374
+ ].filter(
9375
+ (alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
9376
+ )
9377
+ });
9378
+ });
9379
+ return metadataByShapeId;
9380
+ };
9381
+ var generateShapeTsx = ({
9382
+ shape,
9383
+ origin,
9384
+ portMetadata,
9385
+ drawingEndpoints = []
9386
+ }) => {
9387
+ const transformPoint = getPointTransformer(origin);
9388
+ if (shape.type === "RECTANGLE") {
9389
+ const center = transformPoint({
9390
+ x: shape.position.x + shape.width / 2,
9391
+ y: shape.position.y + shape.height / 2
9392
+ });
9393
+ 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)}` : ""} />`;
9394
+ }
9395
+ if (shape.type === "ELLIPSE") {
9396
+ const center = transformPoint(shape.center);
9397
+ 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)}` : ""} />`;
9398
+ }
9399
+ if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
9400
+ const isPolygon = shape.type === "POLYGON";
9401
+ const points = shape.points.map(transformPoint);
9402
+ if (isPolygon && points.length > 0) points.push(points[0]);
9403
+ return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
9404
+ }
9405
+ if (shape.type === "PATH") {
9406
+ const transformedPath = transformSvgPath(shape.pathData, origin);
9407
+ if (!transformedPath) return void 0;
9408
+ return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
9409
+ }
9410
+ if (shape.type === "ARC") {
9411
+ const transformedPath = transformSvgPath(shape.pathData, origin);
9412
+ if (!transformedPath) return void 0;
9413
+ return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
9414
+ }
9415
+ if (shape.type === "TEXT") {
9416
+ if (shape.visibility !== "1") return void 0;
9417
+ const position2 = transformPoint({ x: shape.x, y: shape.y });
9418
+ 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)}} />`;
9419
+ }
9420
+ if (shape.type === "PIN" && portMetadata) {
9421
+ if (shape.visibility !== "show") return void 0;
9422
+ const direction = getPinDirection(shape.rotation);
9423
+ const stemLength = getPinStemLength(shape.path);
9424
+ const position2 = alignPortToDrawing({
9425
+ position: transformPoint({ x: shape.x, y: shape.y }),
9426
+ direction,
9427
+ stemLength,
9428
+ drawingEndpoints
9429
+ });
9430
+ const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
9431
+ const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
9432
+ const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
9433
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
9434
+ }
9435
+ if (shape.type === "IGNORED") return void 0;
9436
+ return void 0;
9437
+ };
9438
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
9439
+ includePorts = true,
9440
+ alignPortsToDrawing = false
9441
+ } = {}) => {
9442
+ const shapes = easyEdaJson.dataStr.shape;
9443
+ if (shapes.length === 0) return void 0;
9444
+ const headOrigin = {
9445
+ x: easyEdaJson.dataStr.head.x,
9446
+ y: easyEdaJson.dataStr.head.y
9447
+ };
9448
+ const bounds = easyEdaJson.dataStr.BBox;
9449
+ const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
9450
+ const origin = isHeadOriginInsideBounds ? headOrigin : {
9451
+ x: bounds.x + bounds.width / 2,
9452
+ y: bounds.y + bounds.height / 2
9453
+ };
9454
+ const portMetadataByShapeId = getPortMetadataByShapeId(
9455
+ easyEdaJson,
9456
+ circuitJson
9457
+ );
9458
+ const transformPoint = getPointTransformer(origin);
9459
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
9460
+ const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
9461
+ (shape) => generateShapeTsx({
9462
+ shape,
9463
+ origin,
9464
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
9465
+ drawingEndpoints
9466
+ })
9467
+ ).filter((tsx) => Boolean(tsx));
9468
+ if (shapeTsx.length === 0) return void 0;
9469
+ return `<symbol>
9470
+ ${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
9471
+ </symbol>`;
9472
+ };
9473
+ var hasNonBoxSchematicSymbol = (easyEdaJson) => {
9474
+ const drawableShapes = easyEdaJson.dataStr.shape.filter(
9475
+ (shape) => shape.type !== "PIN" && shape.type !== "TEXT" && shape.type !== "IGNORED"
9476
+ );
9477
+ if (drawableShapes.length === 0) return false;
9478
+ const rectangles = drawableShapes.filter(
9479
+ (shape) => shape.type === "RECTANGLE"
9480
+ );
9481
+ const onlyBoxPrimitives = drawableShapes.every(
9482
+ (shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
9483
+ );
9484
+ return rectangles.length !== 1 || !onlyBoxPrimitives;
9485
+ };
9486
+
9142
9487
  // lib/websafe/generate-footprint-tsx.ts
9143
9488
  var mapPortHints = (portHints, portHintsMap) => {
9144
9489
  if (!portHintsMap || !portHints) return portHints;
@@ -9360,7 +9705,8 @@ var generateTypescriptComponent = ({
9360
9705
  inductance: inductance2,
9361
9706
  crystalFrequency,
9362
9707
  crystalPinVariant,
9363
- symbolTsx
9708
+ symbolTsx,
9709
+ schPinArrangement
9364
9710
  }) => {
9365
9711
  const safePinLabels = pinLabels ?? {};
9366
9712
  const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
@@ -9405,6 +9751,8 @@ ${polarizedPinLabelsString}
9405
9751
  const symbolProp = symbolTsx ? ` symbol={
9406
9752
  ${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
9407
9753
  }
9754
+ ` : "";
9755
+ const schPinArrangementProp = schPinArrangement ? ` schPinArrangement={${JSON.stringify(schPinArrangement)}}
9408
9756
  ` : "";
9409
9757
  const cadModelLines = [
9410
9758
  objUrl ? `objUrl: "${objUrl}",` : "",
@@ -9649,7 +9997,7 @@ ${pinAttributesBlock}export const ${componentName} = (props: ChipProps<typeof pi
9649
9997
  return (
9650
9998
  <chip
9651
9999
  pinLabels={pinLabels}
9652
- ${pinAttributesProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
10000
+ ${pinAttributesProp}${symbolProp}${schPinArrangementProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
9653
10001
  manufacturerPartNumber="${manufacturerPartNumber}"
9654
10002
  footprint={${footprintTsx}}
9655
10003
  ${objUrl || stepUrl ? `cadModel={{
@@ -9657,495 +10005,151 @@ ${cadModelLines}
9657
10005
  }}` : ""}
9658
10006
  {...props}
9659
10007
  />
9660
- )
9661
- }
9662
- `.trim();
9663
- };
9664
-
9665
- // lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
9666
- var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
9667
- var normalizeCapacitanceValue = (value) => {
9668
- if (typeof value !== "string") return void 0;
9669
- const trimmedValue = value.trim();
9670
- if (!capacitancePattern.test(trimmedValue)) return void 0;
9671
- return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
9672
- };
9673
- var isCapacitorComponent = (betterEasy) => {
9674
- const componentParameters = betterEasy.dataStr.head.c_para;
9675
- const prefix = componentParameters.pre;
9676
- const value = componentParameters.Value;
9677
- return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
9678
- };
9679
-
9680
- // lib/websafe/convert-to-typescript-component/is-crystal-component.ts
9681
- var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
9682
- var isCrystalComponent = (betterEasy) => {
9683
- const componentParameters = betterEasy.dataStr.head.c_para;
9684
- const packageName = componentParameters.package;
9685
- const value = componentParameters.Value;
9686
- return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
9687
- };
9688
-
9689
- // lib/websafe/convert-to-typescript-component/is-inductor-component.ts
9690
- var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
9691
- var isInductorComponent = (betterEasy) => {
9692
- const componentParameters = betterEasy.dataStr.head.c_para;
9693
- const packageName = componentParameters.package;
9694
- const value = componentParameters.Value;
9695
- return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
9696
- };
9697
-
9698
- // lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
9699
- var isMicroUsbConnectorComponent = (betterEasy) => {
9700
- const componentParameters = betterEasy.dataStr.head.c_para;
9701
- return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
9702
- };
9703
-
9704
- // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
9705
- var categoryValueContainsPushbutton = (value) => {
9706
- if (typeof value === "string") {
9707
- const normalized = value.toLowerCase();
9708
- if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
9709
- return false;
9710
- }
9711
- 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);
9712
- }
9713
- if (Array.isArray(value)) {
9714
- return value.some(categoryValueContainsPushbutton);
9715
- }
9716
- if (value && typeof value === "object") {
9717
- return Object.values(value).some(categoryValueContainsPushbutton);
9718
- }
9719
- return false;
9720
- };
9721
-
9722
- // lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
9723
- var isPushbuttonCategoryComponent = (betterEasy) => {
9724
- const cPara = betterEasy.dataStr.head.c_para;
9725
- return [
9726
- betterEasy.tags,
9727
- betterEasy.title,
9728
- betterEasy.description,
9729
- cPara.category,
9730
- cPara.Category,
9731
- cPara["LCSC Category"],
9732
- cPara["JLCPCB Category"],
9733
- cPara.package,
9734
- cPara.pre,
9735
- betterEasy.category
9736
- ].some(categoryValueContainsPushbutton);
9737
- };
9738
-
9739
- // lib/websafe/convert-to-typescript-component/is-resistor-component.ts
9740
- var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
9741
- var normalizeExplicitScale = (scale2) => {
9742
- if (scale2 === "k" || scale2 === "K") return "k";
9743
- if (scale2 === "m") return "m";
9744
- if (scale2 === "M") return "M";
9745
- if (scale2 === "g" || scale2 === "G") return "G";
9746
- return "";
10008
+ )
10009
+ }
10010
+ `.trim();
9747
10011
  };
9748
- var normalizeResistorValue = (value) => {
10012
+
10013
+ // lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
10014
+ var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
10015
+ var normalizeCapacitanceValue = (value) => {
9749
10016
  if (typeof value !== "string") return void 0;
9750
- const compactValue = value.trim().replace(/\s+/g, "");
9751
- const explicitUnitMatch = compactValue.match(
9752
- /^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
9753
- );
9754
- if (explicitUnitMatch) {
9755
- const [, magnitude, scale2] = explicitUnitMatch;
9756
- if (Number(magnitude) === 0) return "0ohm";
9757
- return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
9758
- }
9759
- const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
9760
- if (resistorCodeMatch) {
9761
- const [, whole, multiplier, fraction] = resistorCodeMatch;
9762
- const magnitude = fraction ? `${whole}.${fraction}` : whole;
9763
- if (Number(magnitude) === 0) return "0ohm";
9764
- const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
9765
- return `${magnitude}${scale2}ohm`;
9766
- }
9767
- if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
9768
- return void 0;
10017
+ const trimmedValue = value.trim();
10018
+ if (!capacitancePattern.test(trimmedValue)) return void 0;
10019
+ return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
9769
10020
  };
9770
- var isResistorComponent = (betterEasy) => {
10021
+ var isCapacitorComponent = (betterEasy) => {
9771
10022
  const componentParameters = betterEasy.dataStr.head.c_para;
9772
- const packageName = componentParameters.package;
9773
- return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
10023
+ const prefix = componentParameters.pre;
10024
+ const value = componentParameters.Value;
10025
+ return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
9774
10026
  };
9775
10027
 
9776
- // lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
9777
- var categoryValueContainsSwitch = (value) => {
9778
- if (typeof value === "string") {
9779
- const normalized = value.toLowerCase();
9780
- if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
9781
- return false;
9782
- }
9783
- return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
9784
- }
9785
- if (Array.isArray(value)) {
9786
- return value.some(categoryValueContainsSwitch);
9787
- }
9788
- if (value && typeof value === "object") {
9789
- return Object.values(value).some(categoryValueContainsSwitch);
9790
- }
9791
- return false;
10028
+ // lib/websafe/convert-to-typescript-component/is-crystal-component.ts
10029
+ var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
10030
+ var isCrystalComponent = (betterEasy) => {
10031
+ const componentParameters = betterEasy.dataStr.head.c_para;
10032
+ const packageName = componentParameters.package;
10033
+ const value = componentParameters.Value;
10034
+ return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
9792
10035
  };
9793
10036
 
9794
- // lib/websafe/convert-to-typescript-component/is-switch-category-component.ts
9795
- var isSwitchCategoryComponent = (betterEasy) => {
9796
- const cPara = betterEasy.dataStr.head.c_para;
9797
- return [
9798
- betterEasy.tags,
9799
- cPara.category,
9800
- cPara.Category,
9801
- cPara["LCSC Category"],
9802
- cPara["JLCPCB Category"],
9803
- betterEasy.category
9804
- ].some(categoryValueContainsSwitch);
10037
+ // lib/websafe/convert-to-typescript-component/is-inductor-component.ts
10038
+ var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
10039
+ var isInductorComponent = (betterEasy) => {
10040
+ const componentParameters = betterEasy.dataStr.head.c_para;
10041
+ const packageName = componentParameters.package;
10042
+ const value = componentParameters.Value;
10043
+ return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
9805
10044
  };
9806
10045
 
9807
- // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
9808
- var round = (value) => Number(value.toFixed(6));
9809
- var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
9810
- var toSchematicUnits = (value) => round(value * EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT);
9811
- var getPointTransformer = (origin) => (point2) => ({
9812
- x: toSchematicUnits(point2.x - origin.x),
9813
- y: toSchematicUnits(origin.y - point2.y)
9814
- });
9815
- var formatNumber = (value) => String(round(value));
9816
- var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
9817
- A: 7,
9818
- C: 6,
9819
- H: 1,
9820
- L: 2,
9821
- M: 2,
9822
- Q: 4,
9823
- S: 4,
9824
- T: 2,
9825
- V: 1,
9826
- Z: 0
9827
- };
9828
- var transformSvgPath = (pathData, origin) => {
9829
- const tokens = pathData.match(
9830
- /[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
9831
- ) ?? [];
9832
- const output = [];
9833
- let command = "";
9834
- let tokenIndex = 0;
9835
- let currentX = 0;
9836
- let currentY = 0;
9837
- let subpathStartX = 0;
9838
- let subpathStartY = 0;
9839
- const transformPoint = getPointTransformer(origin);
9840
- const getOriginalPoint = (x, y, isRelative) => ({
9841
- x: isRelative ? currentX + x : x,
9842
- y: isRelative ? currentY + y : y
9843
- });
9844
- while (tokenIndex < tokens.length) {
9845
- if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
9846
- command = tokens[tokenIndex];
9847
- tokenIndex += 1;
9848
- }
9849
- if (!command) break;
9850
- const upperCommand = command.toUpperCase();
9851
- const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
9852
- if (parameterCount === void 0) break;
9853
- if (upperCommand === "Z") {
9854
- output.push("Z");
9855
- currentX = subpathStartX;
9856
- currentY = subpathStartY;
9857
- command = "";
9858
- continue;
9859
- }
9860
- if (tokenIndex + parameterCount > tokens.length) break;
9861
- if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
9862
- const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
9863
- tokenIndex += parameterCount;
9864
- const isRelative = command === command.toLowerCase();
9865
- if (upperCommand === "H" || upperCommand === "V") {
9866
- const point2 = getOriginalPoint(
9867
- upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
9868
- upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
9869
- isRelative
9870
- );
9871
- const transformed = transformPoint(point2);
9872
- output.push(
9873
- `L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
9874
- );
9875
- currentX = point2.x;
9876
- currentY = point2.y;
9877
- continue;
9878
- }
9879
- if (["M", "L", "T"].includes(upperCommand)) {
9880
- const point2 = getOriginalPoint(values[0], values[1], isRelative);
9881
- const transformed = transformPoint(point2);
9882
- output.push(
9883
- `${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
9884
- );
9885
- currentX = point2.x;
9886
- currentY = point2.y;
9887
- if (upperCommand === "M") {
9888
- subpathStartX = point2.x;
9889
- subpathStartY = point2.y;
9890
- command = isRelative ? "l" : "L";
9891
- }
9892
- continue;
9893
- }
9894
- if (["C", "S", "Q"].includes(upperCommand)) {
9895
- const transformedValues = [];
9896
- for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
9897
- const point2 = getOriginalPoint(
9898
- values[valueIndex],
9899
- values[valueIndex + 1],
9900
- isRelative
9901
- );
9902
- const transformed = transformPoint(point2);
9903
- transformedValues.push(transformed.x, transformed.y);
9904
- }
9905
- output.push(
9906
- `${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
9907
- );
9908
- currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
9909
- currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
9910
- continue;
9911
- }
9912
- if (upperCommand === "A") {
9913
- const endpoint = getOriginalPoint(values[5], values[6], isRelative);
9914
- const transformedEndpoint = transformPoint(endpoint);
9915
- output.push(
9916
- [
9917
- "A",
9918
- formatNumber(toSchematicUnits(Math.abs(values[0]))),
9919
- formatNumber(toSchematicUnits(Math.abs(values[1]))),
9920
- formatNumber(-values[2]),
9921
- String(values[3]),
9922
- String(values[4] === 0 ? 1 : 0),
9923
- formatNumber(transformedEndpoint.x),
9924
- formatNumber(transformedEndpoint.y)
9925
- ].join(" ")
9926
- );
9927
- currentX = endpoint.x;
9928
- currentY = endpoint.y;
9929
- }
9930
- }
9931
- return output.join(" ");
9932
- };
9933
- var getPinDirection = (rotation2) => {
9934
- const normalizedRotation = (rotation2 % 360 + 360) % 360;
9935
- if (normalizedRotation === 90) return "up";
9936
- if (normalizedRotation === 180) return "left";
9937
- if (normalizedRotation === 270) return "down";
9938
- return "right";
9939
- };
9940
- var getPinStemLength = (path) => {
9941
- const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
9942
- if (!segment) return void 0;
9943
- return toSchematicUnits(Math.abs(Number(segment[1])));
9944
- };
9945
- var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
9946
- if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
9947
- const first = shape.points[0];
9948
- const last = shape.points[shape.points.length - 1];
9949
- if (first.x === last.x && first.y === last.y) return [];
9950
- return [transformPoint(first), transformPoint(last)];
9951
- });
9952
- var alignPortToDrawing = ({
9953
- position: position2,
9954
- direction,
9955
- stemLength,
9956
- drawingEndpoints
9957
- }) => {
9958
- if (stemLength === void 0) return position2;
9959
- const outwardDirection = getUnitVectorFromDirection(direction);
9960
- const expectedBodyConnection = {
9961
- x: position2.x - outwardDirection.x * stemLength,
9962
- y: position2.y - outwardDirection.y * stemLength
9963
- };
9964
- const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
9965
- const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
9966
- endpoint,
9967
- distance: distance2(endpoint, expectedBodyConnection)
9968
- })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
9969
- if (!nearestEndpoint) return position2;
9970
- return {
9971
- x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
9972
- y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
9973
- };
9974
- };
9975
- var getTextFontSize = (fontSize) => {
9976
- const numericFontSize = Number.parseFloat(fontSize);
9977
- if (!Number.isFinite(numericFontSize)) return 0.2;
9978
- return toSchematicUnits(numericFontSize);
9979
- };
9980
- var getTextAnchor = (alignment) => {
9981
- if (alignment === "L") return "left";
9982
- if (alignment === "R") return "right";
9983
- return "center";
10046
+ // lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
10047
+ var isMicroUsbConnectorComponent = (betterEasy) => {
10048
+ const componentParameters = betterEasy.dataStr.head.c_para;
10049
+ return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
9984
10050
  };
9985
- var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
9986
- const pins = easyEdaJson.dataStr.shape.filter(
9987
- (shape) => shape.type === "PIN"
9988
- );
9989
- const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
9990
- (shape) => shape.type === "PAD"
9991
- );
9992
- const sourcePorts = circuitJson.filter(
9993
- (element) => element.type === "source_port"
9994
- );
9995
- const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
9996
- pads.forEach((pad, padIndex) => {
9997
- const sourcePort = sourcePorts.find(
9998
- (port) => port.source_port_id === `source_port_${padIndex + 1}`
9999
- );
10000
- if (!sourcePort) return;
10001
- const padNumber = String(pad.number);
10002
- sourcePortNamesByPadNumber.set(padNumber, [
10003
- ...sourcePortNamesByPadNumber.get(padNumber) ?? [],
10004
- sourcePort.name
10005
- ]);
10006
- });
10007
- const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
10008
- const usedPortNames = /* @__PURE__ */ new Set();
10009
- const metadataByShapeId = /* @__PURE__ */ new Map();
10010
- pins.forEach((pin, pinIndex) => {
10011
- const pinNumberKey = String(pin.pinNumber);
10012
- const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
10013
- const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
10014
- let portName = matchingPortNames[matchingPortIndex];
10015
- usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
10016
- if (!portName && pin.label) {
10017
- const normalizedLabel = normalizeSymbolName(pin.label);
10018
- portName = sourcePorts.find(
10019
- (port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
10020
- )?.name;
10021
- }
10022
- const numericPinNumber = Number(pin.pinNumber);
10023
- if (!portName && Number.isInteger(numericPinNumber)) {
10024
- const numericPortName = `pin${numericPinNumber}`;
10025
- if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
10026
- portName = numericPortName;
10027
- }
10051
+
10052
+ // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
10053
+ var categoryValueContainsPushbutton = (value) => {
10054
+ if (typeof value === "string") {
10055
+ const normalized = value.toLowerCase();
10056
+ if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
10057
+ return false;
10028
10058
  }
10029
- portName ??= sourcePorts.find((port) => !usedPortNames.has(port.name))?.name;
10030
- portName ??= `pin${pinIndex + 1}`;
10031
- usedPortNames.add(portName);
10032
- const sourcePort = sourcePorts.find((port) => port.name === portName);
10033
- metadataByShapeId.set(pin.id, {
10034
- name: portName,
10035
- pinNumber: sourcePort?.pin_number,
10036
- aliases: [
10037
- ...sourcePort?.port_hints ?? [],
10038
- ...pin.label ? [normalizeSymbolName(pin.label)] : []
10039
- ].filter(
10040
- (alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
10041
- )
10042
- });
10043
- });
10044
- return metadataByShapeId;
10045
- };
10046
- var generateShapeTsx = ({
10047
- shape,
10048
- origin,
10049
- portMetadata,
10050
- drawingEndpoints = []
10051
- }) => {
10052
- const transformPoint = getPointTransformer(origin);
10053
- if (shape.type === "RECTANGLE") {
10054
- const center = transformPoint({
10055
- x: shape.position.x + shape.width / 2,
10056
- y: shape.position.y + shape.height / 2
10057
- });
10058
- 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)}` : ""} />`;
10059
- }
10060
- if (shape.type === "ELLIPSE") {
10061
- const center = transformPoint(shape.center);
10062
- 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)}` : ""} />`;
10063
- }
10064
- if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
10065
- const isPolygon = shape.type === "POLYGON";
10066
- const points = shape.points.map(transformPoint);
10067
- if (isPolygon && points.length > 0) points.push(points[0]);
10068
- return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
10059
+ 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);
10069
10060
  }
10070
- if (shape.type === "PATH") {
10071
- const transformedPath = transformSvgPath(shape.pathData, origin);
10072
- if (!transformedPath) return void 0;
10073
- return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
10061
+ if (Array.isArray(value)) {
10062
+ return value.some(categoryValueContainsPushbutton);
10074
10063
  }
10075
- if (shape.type === "ARC") {
10076
- const transformedPath = transformSvgPath(shape.pathData, origin);
10077
- if (!transformedPath) return void 0;
10078
- return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
10064
+ if (value && typeof value === "object") {
10065
+ return Object.values(value).some(categoryValueContainsPushbutton);
10079
10066
  }
10080
- if (shape.type === "TEXT") {
10081
- if (shape.visibility !== "1") return void 0;
10082
- const position2 = transformPoint({ x: shape.x, y: shape.y });
10083
- 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)}} />`;
10067
+ return false;
10068
+ };
10069
+
10070
+ // lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
10071
+ var isPushbuttonCategoryComponent = (betterEasy) => {
10072
+ const cPara = betterEasy.dataStr.head.c_para;
10073
+ return [
10074
+ betterEasy.tags,
10075
+ betterEasy.title,
10076
+ betterEasy.description,
10077
+ cPara.category,
10078
+ cPara.Category,
10079
+ cPara["LCSC Category"],
10080
+ cPara["JLCPCB Category"],
10081
+ cPara.package,
10082
+ cPara.pre,
10083
+ betterEasy.category
10084
+ ].some(categoryValueContainsPushbutton);
10085
+ };
10086
+
10087
+ // lib/websafe/convert-to-typescript-component/is-resistor-component.ts
10088
+ var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
10089
+ var normalizeExplicitScale = (scale2) => {
10090
+ if (scale2 === "k" || scale2 === "K") return "k";
10091
+ if (scale2 === "m") return "m";
10092
+ if (scale2 === "M") return "M";
10093
+ if (scale2 === "g" || scale2 === "G") return "G";
10094
+ return "";
10095
+ };
10096
+ var normalizeResistorValue = (value) => {
10097
+ if (typeof value !== "string") return void 0;
10098
+ const compactValue = value.trim().replace(/\s+/g, "");
10099
+ const explicitUnitMatch = compactValue.match(
10100
+ /^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
10101
+ );
10102
+ if (explicitUnitMatch) {
10103
+ const [, magnitude, scale2] = explicitUnitMatch;
10104
+ if (Number(magnitude) === 0) return "0ohm";
10105
+ return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
10084
10106
  }
10085
- if (shape.type === "PIN" && portMetadata) {
10086
- const direction = getPinDirection(shape.rotation);
10087
- const stemLength = getPinStemLength(shape.path);
10088
- const position2 = alignPortToDrawing({
10089
- position: transformPoint({ x: shape.x, y: shape.y }),
10090
- direction,
10091
- stemLength,
10092
- drawingEndpoints
10093
- });
10094
- const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
10095
- const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
10096
- const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
10097
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
10107
+ const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
10108
+ if (resistorCodeMatch) {
10109
+ const [, whole, multiplier, fraction] = resistorCodeMatch;
10110
+ const magnitude = fraction ? `${whole}.${fraction}` : whole;
10111
+ if (Number(magnitude) === 0) return "0ohm";
10112
+ const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
10113
+ return `${magnitude}${scale2}ohm`;
10098
10114
  }
10099
- if (shape.type === "IGNORED") return void 0;
10115
+ if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
10100
10116
  return void 0;
10101
10117
  };
10102
- var generateSymbolTsx = (easyEdaJson, circuitJson, {
10103
- includePorts = true,
10104
- alignPortsToDrawing = false
10105
- } = {}) => {
10106
- const shapes = easyEdaJson.dataStr.shape;
10107
- if (shapes.length === 0) return void 0;
10108
- const headOrigin = {
10109
- x: easyEdaJson.dataStr.head.x,
10110
- y: easyEdaJson.dataStr.head.y
10111
- };
10112
- const bounds = easyEdaJson.dataStr.BBox;
10113
- const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
10114
- const origin = isHeadOriginInsideBounds ? headOrigin : {
10115
- x: bounds.x + bounds.width / 2,
10116
- y: bounds.y + bounds.height / 2
10117
- };
10118
- const portMetadataByShapeId = getPortMetadataByShapeId(
10119
- easyEdaJson,
10120
- circuitJson
10121
- );
10122
- const transformPoint = getPointTransformer(origin);
10123
- const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
10124
- const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
10125
- (shape) => generateShapeTsx({
10126
- shape,
10127
- origin,
10128
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
10129
- drawingEndpoints
10130
- })
10131
- ).filter((tsx) => Boolean(tsx));
10132
- if (shapeTsx.length === 0) return void 0;
10133
- return `<symbol>
10134
- ${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
10135
- </symbol>`;
10118
+ var isResistorComponent = (betterEasy) => {
10119
+ const componentParameters = betterEasy.dataStr.head.c_para;
10120
+ const packageName = componentParameters.package;
10121
+ return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
10136
10122
  };
10137
- var hasNonBoxSchematicSymbol = (easyEdaJson) => {
10138
- const drawableShapes = easyEdaJson.dataStr.shape.filter(
10139
- (shape) => shape.type !== "PIN" && shape.type !== "TEXT" && shape.type !== "IGNORED"
10140
- );
10141
- if (drawableShapes.length === 0) return false;
10142
- const rectangles = drawableShapes.filter(
10143
- (shape) => shape.type === "RECTANGLE"
10144
- );
10145
- const onlyBoxPrimitives = drawableShapes.every(
10146
- (shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
10147
- );
10148
- return rectangles.length !== 1 || !onlyBoxPrimitives;
10123
+
10124
+ // lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
10125
+ var categoryValueContainsSwitch = (value) => {
10126
+ if (typeof value === "string") {
10127
+ const normalized = value.toLowerCase();
10128
+ if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
10129
+ return false;
10130
+ }
10131
+ return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
10132
+ }
10133
+ if (Array.isArray(value)) {
10134
+ return value.some(categoryValueContainsSwitch);
10135
+ }
10136
+ if (value && typeof value === "object") {
10137
+ return Object.values(value).some(categoryValueContainsSwitch);
10138
+ }
10139
+ return false;
10140
+ };
10141
+
10142
+ // lib/websafe/convert-to-typescript-component/is-switch-category-component.ts
10143
+ var isSwitchCategoryComponent = (betterEasy) => {
10144
+ const cPara = betterEasy.dataStr.head.c_para;
10145
+ return [
10146
+ betterEasy.tags,
10147
+ cPara.category,
10148
+ cPara.Category,
10149
+ cPara["LCSC Category"],
10150
+ cPara["JLCPCB Category"],
10151
+ betterEasy.category
10152
+ ].some(categoryValueContainsSwitch);
10149
10153
  };
10150
10154
 
10151
10155
  // lib/websafe/convert-to-typescript-component/index.tsx
@@ -10161,6 +10165,24 @@ var getGeneratedComponentType = (betterEasy, pinCount) => {
10161
10165
  if (isMicroUsbConnectorComponent(betterEasy)) return "connector";
10162
10166
  return "chip";
10163
10167
  };
10168
+ var getVisibleSchematicPinArrangement = (betterEasy) => {
10169
+ const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN");
10170
+ if (!pins.some((pin) => pin.visibility !== "show")) return void 0;
10171
+ const arrangement = {
10172
+ leftSide: [],
10173
+ rightSide: [],
10174
+ topSide: [],
10175
+ bottomSide: []
10176
+ };
10177
+ for (const pin of pins.filter((pin2) => pin2.visibility === "show")) {
10178
+ const rotation2 = (pin.rotation % 360 + 360) % 360;
10179
+ const side = rotation2 === 90 ? "topSide" : rotation2 === 180 ? "leftSide" : rotation2 === 270 ? "bottomSide" : "rightSide";
10180
+ arrangement[side].push(pin.pinNumber);
10181
+ }
10182
+ return Object.fromEntries(
10183
+ Object.entries(arrangement).filter(([, pins2]) => pins2.length > 0)
10184
+ );
10185
+ };
10164
10186
  var convertRawEasyToTsx = async ({ rawEasy }) => {
10165
10187
  const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
10166
10188
  const result = await convertBetterEasyToTsx({
@@ -10194,6 +10216,11 @@ var convertBetterEasyToTsx = async ({
10194
10216
  }
10195
10217
  const componentName = normalizeManufacturerPartNumber(manufacturerPartNumber);
10196
10218
  const sourcePorts = su(circuitJson).source_port.list();
10219
+ const hiddenSchematicPinNumbers = new Set(
10220
+ betterEasy.dataStr.shape.flatMap(
10221
+ (shape) => shape.type === "PIN" && shape.visibility !== "show" ? [String(shape.pinNumber)] : []
10222
+ )
10223
+ );
10197
10224
  const pinLabels = {};
10198
10225
  const sortedPorts = sourcePorts.sort((a, b) => {
10199
10226
  const aNum = Number.parseInt(a.name.replace("pin", ""));
@@ -10201,6 +10228,7 @@ var convertBetterEasyToTsx = async ({
10201
10228
  return aNum - bNum;
10202
10229
  });
10203
10230
  for (const sourcePort of sortedPorts) {
10231
+ if (hiddenSchematicPinNumbers.has(String(sourcePort.pin_number))) continue;
10204
10232
  pinLabels[sourcePort.name] = [
10205
10233
  sourcePort.name,
10206
10234
  ...sourcePort.port_hints ?? []
@@ -10238,6 +10266,7 @@ var convertBetterEasyToTsx = async ({
10238
10266
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && !isMultiPinInductor && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
10239
10267
  alignPortsToDrawing: isPassiveWithCustomSymbol
10240
10268
  }) : void 0;
10269
+ const schPinArrangement = symbolTsx ? void 0 : getVisibleSchematicPinArrangement(betterEasy);
10241
10270
  return generateTypescriptComponent({
10242
10271
  componentName,
10243
10272
  manufacturerPartNumber,
@@ -10252,7 +10281,8 @@ var convertBetterEasyToTsx = async ({
10252
10281
  inductance: inductance2,
10253
10282
  crystalFrequency,
10254
10283
  crystalPinVariant,
10255
- symbolTsx
10284
+ symbolTsx,
10285
+ schPinArrangement
10256
10286
  });
10257
10287
  };
10258
10288
  var checkModelObjUrlValidity = async (url) => {