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/index.js CHANGED
@@ -8234,6 +8234,351 @@ var getEasyEdaCadModelPlacement = async (easyEdaJson, { fetch: fetch2 = globalTh
8234
8234
  return placementPromise;
8235
8235
  };
8236
8236
 
8237
+ // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
8238
+ var round = (value) => Number(value.toFixed(6));
8239
+ var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
8240
+ var toSchematicUnits = (value) => round(value * EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT);
8241
+ var getPointTransformer = (origin) => (point2) => ({
8242
+ x: toSchematicUnits(point2.x - origin.x),
8243
+ y: toSchematicUnits(origin.y - point2.y)
8244
+ });
8245
+ var formatNumber = (value) => String(round(value));
8246
+ var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
8247
+ A: 7,
8248
+ C: 6,
8249
+ H: 1,
8250
+ L: 2,
8251
+ M: 2,
8252
+ Q: 4,
8253
+ S: 4,
8254
+ T: 2,
8255
+ V: 1,
8256
+ Z: 0
8257
+ };
8258
+ var transformSvgPath = (pathData, origin) => {
8259
+ const tokens = pathData.match(
8260
+ /[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
8261
+ ) ?? [];
8262
+ const output = [];
8263
+ let command = "";
8264
+ let tokenIndex = 0;
8265
+ let currentX = 0;
8266
+ let currentY = 0;
8267
+ let subpathStartX = 0;
8268
+ let subpathStartY = 0;
8269
+ const transformPoint = getPointTransformer(origin);
8270
+ const getOriginalPoint = (x, y, isRelative) => ({
8271
+ x: isRelative ? currentX + x : x,
8272
+ y: isRelative ? currentY + y : y
8273
+ });
8274
+ while (tokenIndex < tokens.length) {
8275
+ if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
8276
+ command = tokens[tokenIndex];
8277
+ tokenIndex += 1;
8278
+ }
8279
+ if (!command) break;
8280
+ const upperCommand = command.toUpperCase();
8281
+ const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
8282
+ if (parameterCount === void 0) break;
8283
+ if (upperCommand === "Z") {
8284
+ output.push("Z");
8285
+ currentX = subpathStartX;
8286
+ currentY = subpathStartY;
8287
+ command = "";
8288
+ continue;
8289
+ }
8290
+ if (tokenIndex + parameterCount > tokens.length) break;
8291
+ if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
8292
+ const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
8293
+ tokenIndex += parameterCount;
8294
+ const isRelative = command === command.toLowerCase();
8295
+ if (upperCommand === "H" || upperCommand === "V") {
8296
+ const point2 = getOriginalPoint(
8297
+ upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
8298
+ upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
8299
+ isRelative
8300
+ );
8301
+ const transformed = transformPoint(point2);
8302
+ output.push(
8303
+ `L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
8304
+ );
8305
+ currentX = point2.x;
8306
+ currentY = point2.y;
8307
+ continue;
8308
+ }
8309
+ if (["M", "L", "T"].includes(upperCommand)) {
8310
+ const point2 = getOriginalPoint(values[0], values[1], isRelative);
8311
+ const transformed = transformPoint(point2);
8312
+ output.push(
8313
+ `${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
8314
+ );
8315
+ currentX = point2.x;
8316
+ currentY = point2.y;
8317
+ if (upperCommand === "M") {
8318
+ subpathStartX = point2.x;
8319
+ subpathStartY = point2.y;
8320
+ command = isRelative ? "l" : "L";
8321
+ }
8322
+ continue;
8323
+ }
8324
+ if (["C", "S", "Q"].includes(upperCommand)) {
8325
+ const transformedValues = [];
8326
+ for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
8327
+ const point2 = getOriginalPoint(
8328
+ values[valueIndex],
8329
+ values[valueIndex + 1],
8330
+ isRelative
8331
+ );
8332
+ const transformed = transformPoint(point2);
8333
+ transformedValues.push(transformed.x, transformed.y);
8334
+ }
8335
+ output.push(
8336
+ `${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
8337
+ );
8338
+ currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
8339
+ currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
8340
+ continue;
8341
+ }
8342
+ if (upperCommand === "A") {
8343
+ const endpoint = getOriginalPoint(values[5], values[6], isRelative);
8344
+ const transformedEndpoint = transformPoint(endpoint);
8345
+ output.push(
8346
+ [
8347
+ "A",
8348
+ formatNumber(toSchematicUnits(Math.abs(values[0]))),
8349
+ formatNumber(toSchematicUnits(Math.abs(values[1]))),
8350
+ formatNumber(-values[2]),
8351
+ String(values[3]),
8352
+ String(values[4] === 0 ? 1 : 0),
8353
+ formatNumber(transformedEndpoint.x),
8354
+ formatNumber(transformedEndpoint.y)
8355
+ ].join(" ")
8356
+ );
8357
+ currentX = endpoint.x;
8358
+ currentY = endpoint.y;
8359
+ }
8360
+ }
8361
+ return output.join(" ");
8362
+ };
8363
+ var getPinDirection = (rotation2) => {
8364
+ const normalizedRotation = (rotation2 % 360 + 360) % 360;
8365
+ if (normalizedRotation === 90) return "up";
8366
+ if (normalizedRotation === 180) return "left";
8367
+ if (normalizedRotation === 270) return "down";
8368
+ return "right";
8369
+ };
8370
+ var getPinStemLength = (path) => {
8371
+ const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
8372
+ if (!segment) return void 0;
8373
+ return toSchematicUnits(Math.abs(Number(segment[1])));
8374
+ };
8375
+ var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
8376
+ if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
8377
+ const first = shape.points[0];
8378
+ const last = shape.points[shape.points.length - 1];
8379
+ if (first.x === last.x && first.y === last.y) return [];
8380
+ return [transformPoint(first), transformPoint(last)];
8381
+ });
8382
+ var alignPortToDrawing = ({
8383
+ position: position2,
8384
+ direction,
8385
+ stemLength,
8386
+ drawingEndpoints
8387
+ }) => {
8388
+ if (stemLength === void 0) return position2;
8389
+ const outwardDirection = getUnitVectorFromDirection(direction);
8390
+ const expectedBodyConnection = {
8391
+ x: position2.x - outwardDirection.x * stemLength,
8392
+ y: position2.y - outwardDirection.y * stemLength
8393
+ };
8394
+ const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
8395
+ const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
8396
+ endpoint,
8397
+ distance: distance2(endpoint, expectedBodyConnection)
8398
+ })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
8399
+ if (!nearestEndpoint) return position2;
8400
+ return {
8401
+ x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
8402
+ y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
8403
+ };
8404
+ };
8405
+ var getTextFontSize = (fontSize) => {
8406
+ const numericFontSize = Number.parseFloat(fontSize);
8407
+ if (!Number.isFinite(numericFontSize)) return 0.2;
8408
+ return toSchematicUnits(numericFontSize);
8409
+ };
8410
+ var getTextAnchor = (alignment) => {
8411
+ if (alignment === "L") return "left";
8412
+ if (alignment === "R") return "right";
8413
+ return "center";
8414
+ };
8415
+ var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
8416
+ const pins = easyEdaJson.dataStr.shape.filter(
8417
+ (shape) => shape.type === "PIN"
8418
+ );
8419
+ const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
8420
+ (shape) => shape.type === "PAD"
8421
+ );
8422
+ const sourcePorts = circuitJson.filter(
8423
+ (element) => element.type === "source_port"
8424
+ );
8425
+ const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
8426
+ pads.forEach((pad, padIndex) => {
8427
+ const sourcePort = sourcePorts.find(
8428
+ (port) => port.source_port_id === `source_port_${padIndex + 1}`
8429
+ );
8430
+ if (!sourcePort) return;
8431
+ const padNumber = String(pad.number);
8432
+ sourcePortNamesByPadNumber.set(padNumber, [
8433
+ ...sourcePortNamesByPadNumber.get(padNumber) ?? [],
8434
+ sourcePort.name
8435
+ ]);
8436
+ });
8437
+ const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
8438
+ const usedPortNames = /* @__PURE__ */ new Set();
8439
+ const metadataByShapeId = /* @__PURE__ */ new Map();
8440
+ pins.forEach((pin, pinIndex) => {
8441
+ const pinNumberKey = String(pin.pinNumber);
8442
+ const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
8443
+ const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
8444
+ let portName = matchingPortNames[matchingPortIndex];
8445
+ usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
8446
+ if (!portName && pin.label) {
8447
+ const normalizedLabel = normalizeSymbolName(pin.label);
8448
+ portName = sourcePorts.find(
8449
+ (port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
8450
+ )?.name;
8451
+ }
8452
+ const numericPinNumber = Number(pin.pinNumber);
8453
+ if (!portName && Number.isInteger(numericPinNumber)) {
8454
+ const numericPortName = `pin${numericPinNumber}`;
8455
+ if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
8456
+ portName = numericPortName;
8457
+ }
8458
+ }
8459
+ portName ??= sourcePorts.find((port) => !usedPortNames.has(port.name))?.name;
8460
+ portName ??= `pin${pinIndex + 1}`;
8461
+ usedPortNames.add(portName);
8462
+ const sourcePort = sourcePorts.find((port) => port.name === portName);
8463
+ metadataByShapeId.set(pin.id, {
8464
+ name: portName,
8465
+ pinNumber: sourcePort?.pin_number,
8466
+ aliases: [
8467
+ ...sourcePort?.port_hints ?? [],
8468
+ ...pin.label ? [normalizeSymbolName(pin.label)] : []
8469
+ ].filter(
8470
+ (alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
8471
+ )
8472
+ });
8473
+ });
8474
+ return metadataByShapeId;
8475
+ };
8476
+ var generateShapeTsx = ({
8477
+ shape,
8478
+ origin,
8479
+ portMetadata,
8480
+ drawingEndpoints = []
8481
+ }) => {
8482
+ const transformPoint = getPointTransformer(origin);
8483
+ if (shape.type === "RECTANGLE") {
8484
+ const center = transformPoint({
8485
+ x: shape.position.x + shape.width / 2,
8486
+ y: shape.position.y + shape.height / 2
8487
+ });
8488
+ 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)}` : ""} />`;
8489
+ }
8490
+ if (shape.type === "ELLIPSE") {
8491
+ const center = transformPoint(shape.center);
8492
+ 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)}` : ""} />`;
8493
+ }
8494
+ if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
8495
+ const isPolygon = shape.type === "POLYGON";
8496
+ const points = shape.points.map(transformPoint);
8497
+ if (isPolygon && points.length > 0) points.push(points[0]);
8498
+ return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
8499
+ }
8500
+ if (shape.type === "PATH") {
8501
+ const transformedPath = transformSvgPath(shape.pathData, origin);
8502
+ if (!transformedPath) return void 0;
8503
+ return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
8504
+ }
8505
+ if (shape.type === "ARC") {
8506
+ const transformedPath = transformSvgPath(shape.pathData, origin);
8507
+ if (!transformedPath) return void 0;
8508
+ return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
8509
+ }
8510
+ if (shape.type === "TEXT") {
8511
+ if (shape.visibility !== "1") return void 0;
8512
+ const position2 = transformPoint({ x: shape.x, y: shape.y });
8513
+ 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)}} />`;
8514
+ }
8515
+ if (shape.type === "PIN" && portMetadata) {
8516
+ if (shape.visibility !== "show") return void 0;
8517
+ const direction = getPinDirection(shape.rotation);
8518
+ const stemLength = getPinStemLength(shape.path);
8519
+ const position2 = alignPortToDrawing({
8520
+ position: transformPoint({ x: shape.x, y: shape.y }),
8521
+ direction,
8522
+ stemLength,
8523
+ drawingEndpoints
8524
+ });
8525
+ const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
8526
+ const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
8527
+ const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
8528
+ return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
8529
+ }
8530
+ if (shape.type === "IGNORED") return void 0;
8531
+ return void 0;
8532
+ };
8533
+ var generateSymbolTsx = (easyEdaJson, circuitJson, {
8534
+ includePorts = true,
8535
+ alignPortsToDrawing = false
8536
+ } = {}) => {
8537
+ const shapes = easyEdaJson.dataStr.shape;
8538
+ if (shapes.length === 0) return void 0;
8539
+ const headOrigin = {
8540
+ x: easyEdaJson.dataStr.head.x,
8541
+ y: easyEdaJson.dataStr.head.y
8542
+ };
8543
+ const bounds = easyEdaJson.dataStr.BBox;
8544
+ const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
8545
+ const origin = isHeadOriginInsideBounds ? headOrigin : {
8546
+ x: bounds.x + bounds.width / 2,
8547
+ y: bounds.y + bounds.height / 2
8548
+ };
8549
+ const portMetadataByShapeId = getPortMetadataByShapeId(
8550
+ easyEdaJson,
8551
+ circuitJson
8552
+ );
8553
+ const transformPoint = getPointTransformer(origin);
8554
+ const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
8555
+ const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
8556
+ (shape) => generateShapeTsx({
8557
+ shape,
8558
+ origin,
8559
+ portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
8560
+ drawingEndpoints
8561
+ })
8562
+ ).filter((tsx) => Boolean(tsx));
8563
+ if (shapeTsx.length === 0) return void 0;
8564
+ return `<symbol>
8565
+ ${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
8566
+ </symbol>`;
8567
+ };
8568
+ var hasNonBoxSchematicSymbol = (easyEdaJson) => {
8569
+ const drawableShapes = easyEdaJson.dataStr.shape.filter(
8570
+ (shape) => shape.type !== "PIN" && shape.type !== "TEXT" && shape.type !== "IGNORED"
8571
+ );
8572
+ if (drawableShapes.length === 0) return false;
8573
+ const rectangles = drawableShapes.filter(
8574
+ (shape) => shape.type === "RECTANGLE"
8575
+ );
8576
+ const onlyBoxPrimitives = drawableShapes.every(
8577
+ (shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
8578
+ );
8579
+ return rectangles.length !== 1 || !onlyBoxPrimitives;
8580
+ };
8581
+
8237
8582
  // lib/websafe/generate-footprint-tsx.ts
8238
8583
  var mapPortHints = (portHints, portHintsMap) => {
8239
8584
  if (!portHintsMap || !portHints) return portHints;
@@ -8455,7 +8800,8 @@ var generateTypescriptComponent = ({
8455
8800
  inductance: inductance2,
8456
8801
  crystalFrequency,
8457
8802
  crystalPinVariant,
8458
- symbolTsx
8803
+ symbolTsx,
8804
+ schPinArrangement
8459
8805
  }) => {
8460
8806
  const safePinLabels = pinLabels ?? {};
8461
8807
  const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
@@ -8500,6 +8846,8 @@ ${polarizedPinLabelsString}
8500
8846
  const symbolProp = symbolTsx ? ` symbol={
8501
8847
  ${symbolTsx.split("\n").map((line) => ` ${line}`).join("\n")}
8502
8848
  }
8849
+ ` : "";
8850
+ const schPinArrangementProp = schPinArrangement ? ` schPinArrangement={${JSON.stringify(schPinArrangement)}}
8503
8851
  ` : "";
8504
8852
  const cadModelLines = [
8505
8853
  objUrl ? `objUrl: "${objUrl}",` : "",
@@ -8744,7 +9092,7 @@ ${pinAttributesBlock}export const ${componentName} = (props: ChipProps<typeof pi
8744
9092
  return (
8745
9093
  <chip
8746
9094
  pinLabels={pinLabels}
8747
- ${pinAttributesProp}${symbolProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
9095
+ ${pinAttributesProp}${symbolProp}${schPinArrangementProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
8748
9096
  manufacturerPartNumber="${manufacturerPartNumber}"
8749
9097
  footprint={${footprintTsx}}
8750
9098
  ${objUrl || stepUrl ? `cadModel={{
@@ -8752,495 +9100,151 @@ ${cadModelLines}
8752
9100
  }}` : ""}
8753
9101
  {...props}
8754
9102
  />
8755
- )
8756
- }
8757
- `.trim();
8758
- };
8759
-
8760
- // lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
8761
- var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
8762
- var normalizeCapacitanceValue = (value) => {
8763
- if (typeof value !== "string") return void 0;
8764
- const trimmedValue = value.trim();
8765
- if (!capacitancePattern.test(trimmedValue)) return void 0;
8766
- return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
8767
- };
8768
- var isCapacitorComponent = (betterEasy) => {
8769
- const componentParameters = betterEasy.dataStr.head.c_para;
8770
- const prefix = componentParameters.pre;
8771
- const value = componentParameters.Value;
8772
- return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
8773
- };
8774
-
8775
- // lib/websafe/convert-to-typescript-component/is-crystal-component.ts
8776
- var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
8777
- var isCrystalComponent = (betterEasy) => {
8778
- const componentParameters = betterEasy.dataStr.head.c_para;
8779
- const packageName = componentParameters.package;
8780
- const value = componentParameters.Value;
8781
- return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
8782
- };
8783
-
8784
- // lib/websafe/convert-to-typescript-component/is-inductor-component.ts
8785
- var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
8786
- var isInductorComponent = (betterEasy) => {
8787
- const componentParameters = betterEasy.dataStr.head.c_para;
8788
- const packageName = componentParameters.package;
8789
- const value = componentParameters.Value;
8790
- return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
8791
- };
8792
-
8793
- // lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
8794
- var isMicroUsbConnectorComponent = (betterEasy) => {
8795
- const componentParameters = betterEasy.dataStr.head.c_para;
8796
- return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
8797
- };
8798
-
8799
- // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
8800
- var categoryValueContainsPushbutton = (value) => {
8801
- if (typeof value === "string") {
8802
- const normalized = value.toLowerCase();
8803
- if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
8804
- return false;
8805
- }
8806
- 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);
8807
- }
8808
- if (Array.isArray(value)) {
8809
- return value.some(categoryValueContainsPushbutton);
8810
- }
8811
- if (value && typeof value === "object") {
8812
- return Object.values(value).some(categoryValueContainsPushbutton);
8813
- }
8814
- return false;
8815
- };
8816
-
8817
- // lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
8818
- var isPushbuttonCategoryComponent = (betterEasy) => {
8819
- const cPara = betterEasy.dataStr.head.c_para;
8820
- return [
8821
- betterEasy.tags,
8822
- betterEasy.title,
8823
- betterEasy.description,
8824
- cPara.category,
8825
- cPara.Category,
8826
- cPara["LCSC Category"],
8827
- cPara["JLCPCB Category"],
8828
- cPara.package,
8829
- cPara.pre,
8830
- betterEasy.category
8831
- ].some(categoryValueContainsPushbutton);
8832
- };
8833
-
8834
- // lib/websafe/convert-to-typescript-component/is-resistor-component.ts
8835
- var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
8836
- var normalizeExplicitScale = (scale2) => {
8837
- if (scale2 === "k" || scale2 === "K") return "k";
8838
- if (scale2 === "m") return "m";
8839
- if (scale2 === "M") return "M";
8840
- if (scale2 === "g" || scale2 === "G") return "G";
8841
- return "";
9103
+ )
9104
+ }
9105
+ `.trim();
8842
9106
  };
8843
- var normalizeResistorValue = (value) => {
9107
+
9108
+ // lib/websafe/convert-to-typescript-component/is-capacitor-component.ts
9109
+ var capacitancePattern = /^\d+(?:\.\d+)?\s*(?:pF|nF|[uµμ]F|mF|F)$/i;
9110
+ var normalizeCapacitanceValue = (value) => {
8844
9111
  if (typeof value !== "string") return void 0;
8845
- const compactValue = value.trim().replace(/\s+/g, "");
8846
- const explicitUnitMatch = compactValue.match(
8847
- /^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
8848
- );
8849
- if (explicitUnitMatch) {
8850
- const [, magnitude, scale2] = explicitUnitMatch;
8851
- if (Number(magnitude) === 0) return "0ohm";
8852
- return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
8853
- }
8854
- const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
8855
- if (resistorCodeMatch) {
8856
- const [, whole, multiplier, fraction] = resistorCodeMatch;
8857
- const magnitude = fraction ? `${whole}.${fraction}` : whole;
8858
- if (Number(magnitude) === 0) return "0ohm";
8859
- const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
8860
- return `${magnitude}${scale2}ohm`;
8861
- }
8862
- if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
8863
- return void 0;
9112
+ const trimmedValue = value.trim();
9113
+ if (!capacitancePattern.test(trimmedValue)) return void 0;
9114
+ return trimmedValue.replace(/\s+/g, "").replace(/[µμ]/g, "u");
8864
9115
  };
8865
- var isResistorComponent = (betterEasy) => {
9116
+ var isCapacitorComponent = (betterEasy) => {
8866
9117
  const componentParameters = betterEasy.dataStr.head.c_para;
8867
- const packageName = componentParameters.package;
8868
- return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
9118
+ const prefix = componentParameters.pre;
9119
+ const value = componentParameters.Value;
9120
+ return prefix?.toUpperCase() === "C?" && normalizeCapacitanceValue(value) !== void 0;
8869
9121
  };
8870
9122
 
8871
- // lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
8872
- var categoryValueContainsSwitch = (value) => {
8873
- if (typeof value === "string") {
8874
- const normalized = value.toLowerCase();
8875
- if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
8876
- return false;
8877
- }
8878
- return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
8879
- }
8880
- if (Array.isArray(value)) {
8881
- return value.some(categoryValueContainsSwitch);
8882
- }
8883
- if (value && typeof value === "object") {
8884
- return Object.values(value).some(categoryValueContainsSwitch);
8885
- }
8886
- return false;
9123
+ // lib/websafe/convert-to-typescript-component/is-crystal-component.ts
9124
+ var frequencyPattern = /^\d+(?:\.\d+)?\s*(?:Hz|kHz|MHz|GHz)$/i;
9125
+ var isCrystalComponent = (betterEasy) => {
9126
+ const componentParameters = betterEasy.dataStr.head.c_para;
9127
+ const packageName = componentParameters.package;
9128
+ const value = componentParameters.Value;
9129
+ return componentParameters.pre === "X?" && packageName?.toUpperCase().startsWith("CRYSTAL-") === true && typeof value === "string" && frequencyPattern.test(value.trim());
8887
9130
  };
8888
9131
 
8889
- // lib/websafe/convert-to-typescript-component/is-switch-category-component.ts
8890
- var isSwitchCategoryComponent = (betterEasy) => {
8891
- const cPara = betterEasy.dataStr.head.c_para;
8892
- return [
8893
- betterEasy.tags,
8894
- cPara.category,
8895
- cPara.Category,
8896
- cPara["LCSC Category"],
8897
- cPara["JLCPCB Category"],
8898
- betterEasy.category
8899
- ].some(categoryValueContainsSwitch);
9132
+ // lib/websafe/convert-to-typescript-component/is-inductor-component.ts
9133
+ var inductancePattern = /^\d+(?:\.\d+)?\s*(?:pH|nH|uH|µH|mH|H)$/i;
9134
+ var isInductorComponent = (betterEasy) => {
9135
+ const componentParameters = betterEasy.dataStr.head.c_para;
9136
+ const packageName = componentParameters.package;
9137
+ const value = componentParameters.Value;
9138
+ return packageName?.toUpperCase().startsWith("IND-") === true && typeof value === "string" && inductancePattern.test(value.trim());
8900
9139
  };
8901
9140
 
8902
- // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
8903
- var round = (value) => Number(value.toFixed(6));
8904
- var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
8905
- var toSchematicUnits = (value) => round(value * EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT);
8906
- var getPointTransformer = (origin) => (point2) => ({
8907
- x: toSchematicUnits(point2.x - origin.x),
8908
- y: toSchematicUnits(origin.y - point2.y)
8909
- });
8910
- var formatNumber = (value) => String(round(value));
8911
- var SVG_PATH_COMMAND_PARAMETER_COUNTS = {
8912
- A: 7,
8913
- C: 6,
8914
- H: 1,
8915
- L: 2,
8916
- M: 2,
8917
- Q: 4,
8918
- S: 4,
8919
- T: 2,
8920
- V: 1,
8921
- Z: 0
8922
- };
8923
- var transformSvgPath = (pathData, origin) => {
8924
- const tokens = pathData.match(
8925
- /[AaCcHhLlMmQqSsTtVvZz]|[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g
8926
- ) ?? [];
8927
- const output = [];
8928
- let command = "";
8929
- let tokenIndex = 0;
8930
- let currentX = 0;
8931
- let currentY = 0;
8932
- let subpathStartX = 0;
8933
- let subpathStartY = 0;
8934
- const transformPoint = getPointTransformer(origin);
8935
- const getOriginalPoint = (x, y, isRelative) => ({
8936
- x: isRelative ? currentX + x : x,
8937
- y: isRelative ? currentY + y : y
8938
- });
8939
- while (tokenIndex < tokens.length) {
8940
- if (/^[A-Za-z]$/.test(tokens[tokenIndex])) {
8941
- command = tokens[tokenIndex];
8942
- tokenIndex += 1;
8943
- }
8944
- if (!command) break;
8945
- const upperCommand = command.toUpperCase();
8946
- const parameterCount = SVG_PATH_COMMAND_PARAMETER_COUNTS[upperCommand];
8947
- if (parameterCount === void 0) break;
8948
- if (upperCommand === "Z") {
8949
- output.push("Z");
8950
- currentX = subpathStartX;
8951
- currentY = subpathStartY;
8952
- command = "";
8953
- continue;
8954
- }
8955
- if (tokenIndex + parameterCount > tokens.length) break;
8956
- if (/^[A-Za-z]$/.test(tokens[tokenIndex])) continue;
8957
- const values = tokens.slice(tokenIndex, tokenIndex + parameterCount).map(Number);
8958
- tokenIndex += parameterCount;
8959
- const isRelative = command === command.toLowerCase();
8960
- if (upperCommand === "H" || upperCommand === "V") {
8961
- const point2 = getOriginalPoint(
8962
- upperCommand === "H" ? values[0] : isRelative ? 0 : currentX,
8963
- upperCommand === "V" ? values[0] : isRelative ? 0 : currentY,
8964
- isRelative
8965
- );
8966
- const transformed = transformPoint(point2);
8967
- output.push(
8968
- `L ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
8969
- );
8970
- currentX = point2.x;
8971
- currentY = point2.y;
8972
- continue;
8973
- }
8974
- if (["M", "L", "T"].includes(upperCommand)) {
8975
- const point2 = getOriginalPoint(values[0], values[1], isRelative);
8976
- const transformed = transformPoint(point2);
8977
- output.push(
8978
- `${upperCommand} ${formatNumber(transformed.x)} ${formatNumber(transformed.y)}`
8979
- );
8980
- currentX = point2.x;
8981
- currentY = point2.y;
8982
- if (upperCommand === "M") {
8983
- subpathStartX = point2.x;
8984
- subpathStartY = point2.y;
8985
- command = isRelative ? "l" : "L";
8986
- }
8987
- continue;
8988
- }
8989
- if (["C", "S", "Q"].includes(upperCommand)) {
8990
- const transformedValues = [];
8991
- for (let valueIndex = 0; valueIndex < values.length; valueIndex += 2) {
8992
- const point2 = getOriginalPoint(
8993
- values[valueIndex],
8994
- values[valueIndex + 1],
8995
- isRelative
8996
- );
8997
- const transformed = transformPoint(point2);
8998
- transformedValues.push(transformed.x, transformed.y);
8999
- }
9000
- output.push(
9001
- `${upperCommand} ${transformedValues.map(formatNumber).join(" ")}`
9002
- );
9003
- currentX = isRelative ? currentX + values[values.length - 2] : values[values.length - 2];
9004
- currentY = isRelative ? currentY + values[values.length - 1] : values[values.length - 1];
9005
- continue;
9006
- }
9007
- if (upperCommand === "A") {
9008
- const endpoint = getOriginalPoint(values[5], values[6], isRelative);
9009
- const transformedEndpoint = transformPoint(endpoint);
9010
- output.push(
9011
- [
9012
- "A",
9013
- formatNumber(toSchematicUnits(Math.abs(values[0]))),
9014
- formatNumber(toSchematicUnits(Math.abs(values[1]))),
9015
- formatNumber(-values[2]),
9016
- String(values[3]),
9017
- String(values[4] === 0 ? 1 : 0),
9018
- formatNumber(transformedEndpoint.x),
9019
- formatNumber(transformedEndpoint.y)
9020
- ].join(" ")
9021
- );
9022
- currentX = endpoint.x;
9023
- currentY = endpoint.y;
9024
- }
9025
- }
9026
- return output.join(" ");
9027
- };
9028
- var getPinDirection = (rotation2) => {
9029
- const normalizedRotation = (rotation2 % 360 + 360) % 360;
9030
- if (normalizedRotation === 90) return "up";
9031
- if (normalizedRotation === 180) return "left";
9032
- if (normalizedRotation === 270) return "down";
9033
- return "right";
9034
- };
9035
- var getPinStemLength = (path) => {
9036
- const segment = path.match(/[hHvV]\s*(-?(?:\d*\.\d+|\d+\.?))/);
9037
- if (!segment) return void 0;
9038
- return toSchematicUnits(Math.abs(Number(segment[1])));
9039
- };
9040
- var getOpenPolylineEndpoints = (shapes, transformPoint) => shapes.flatMap((shape) => {
9041
- if (shape.type !== "POLYLINE" || shape.points.length < 2) return [];
9042
- const first = shape.points[0];
9043
- const last = shape.points[shape.points.length - 1];
9044
- if (first.x === last.x && first.y === last.y) return [];
9045
- return [transformPoint(first), transformPoint(last)];
9046
- });
9047
- var alignPortToDrawing = ({
9048
- position: position2,
9049
- direction,
9050
- stemLength,
9051
- drawingEndpoints
9052
- }) => {
9053
- if (stemLength === void 0) return position2;
9054
- const outwardDirection = getUnitVectorFromDirection(direction);
9055
- const expectedBodyConnection = {
9056
- x: position2.x - outwardDirection.x * stemLength,
9057
- y: position2.y - outwardDirection.y * stemLength
9058
- };
9059
- const alignmentTolerance = Math.max(0.02, stemLength * 0.25);
9060
- const nearestEndpoint = drawingEndpoints.map((endpoint) => ({
9061
- endpoint,
9062
- distance: distance2(endpoint, expectedBodyConnection)
9063
- })).filter((candidate) => candidate.distance <= alignmentTolerance).sort((a, b) => a.distance - b.distance)[0]?.endpoint;
9064
- if (!nearestEndpoint) return position2;
9065
- return {
9066
- x: round(nearestEndpoint.x + outwardDirection.x * stemLength),
9067
- y: round(nearestEndpoint.y + outwardDirection.y * stemLength)
9068
- };
9069
- };
9070
- var getTextFontSize = (fontSize) => {
9071
- const numericFontSize = Number.parseFloat(fontSize);
9072
- if (!Number.isFinite(numericFontSize)) return 0.2;
9073
- return toSchematicUnits(numericFontSize);
9074
- };
9075
- var getTextAnchor = (alignment) => {
9076
- if (alignment === "L") return "left";
9077
- if (alignment === "R") return "right";
9078
- return "center";
9141
+ // lib/websafe/convert-to-typescript-component/is-micro-usb-connector-component.ts
9142
+ var isMicroUsbConnectorComponent = (betterEasy) => {
9143
+ const componentParameters = betterEasy.dataStr.head.c_para;
9144
+ return componentParameters.pre === "USB?" && componentParameters.package?.toUpperCase().startsWith("MICRO-USB-") === true;
9079
9145
  };
9080
- var getPortMetadataByShapeId = (easyEdaJson, circuitJson) => {
9081
- const pins = easyEdaJson.dataStr.shape.filter(
9082
- (shape) => shape.type === "PIN"
9083
- );
9084
- const pads = easyEdaJson.packageDetail.dataStr.shape.filter(
9085
- (shape) => shape.type === "PAD"
9086
- );
9087
- const sourcePorts = circuitJson.filter(
9088
- (element) => element.type === "source_port"
9089
- );
9090
- const sourcePortNamesByPadNumber = /* @__PURE__ */ new Map();
9091
- pads.forEach((pad, padIndex) => {
9092
- const sourcePort = sourcePorts.find(
9093
- (port) => port.source_port_id === `source_port_${padIndex + 1}`
9094
- );
9095
- if (!sourcePort) return;
9096
- const padNumber = String(pad.number);
9097
- sourcePortNamesByPadNumber.set(padNumber, [
9098
- ...sourcePortNamesByPadNumber.get(padNumber) ?? [],
9099
- sourcePort.name
9100
- ]);
9101
- });
9102
- const usedPortNamesByPadNumber = /* @__PURE__ */ new Map();
9103
- const usedPortNames = /* @__PURE__ */ new Set();
9104
- const metadataByShapeId = /* @__PURE__ */ new Map();
9105
- pins.forEach((pin, pinIndex) => {
9106
- const pinNumberKey = String(pin.pinNumber);
9107
- const matchingPortNames = sourcePortNamesByPadNumber.get(pinNumberKey) ?? [];
9108
- const matchingPortIndex = usedPortNamesByPadNumber.get(pinNumberKey) ?? 0;
9109
- let portName = matchingPortNames[matchingPortIndex];
9110
- usedPortNamesByPadNumber.set(pinNumberKey, matchingPortIndex + 1);
9111
- if (!portName && pin.label) {
9112
- const normalizedLabel = normalizeSymbolName(pin.label);
9113
- portName = sourcePorts.find(
9114
- (port) => !usedPortNames.has(port.name) && port.port_hints?.includes(normalizedLabel)
9115
- )?.name;
9116
- }
9117
- const numericPinNumber = Number(pin.pinNumber);
9118
- if (!portName && Number.isInteger(numericPinNumber)) {
9119
- const numericPortName = `pin${numericPinNumber}`;
9120
- if (!usedPortNames.has(numericPortName) && sourcePorts.some((port) => port.name === numericPortName)) {
9121
- portName = numericPortName;
9122
- }
9146
+
9147
+ // lib/websafe/convert-to-typescript-component/category-value-contains-pushbutton.ts
9148
+ var categoryValueContainsPushbutton = (value) => {
9149
+ if (typeof value === "string") {
9150
+ const normalized = value.toLowerCase();
9151
+ if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
9152
+ return false;
9123
9153
  }
9124
- portName ??= sourcePorts.find((port) => !usedPortNames.has(port.name))?.name;
9125
- portName ??= `pin${pinIndex + 1}`;
9126
- usedPortNames.add(portName);
9127
- const sourcePort = sourcePorts.find((port) => port.name === portName);
9128
- metadataByShapeId.set(pin.id, {
9129
- name: portName,
9130
- pinNumber: sourcePort?.pin_number,
9131
- aliases: [
9132
- ...sourcePort?.port_hints ?? [],
9133
- ...pin.label ? [normalizeSymbolName(pin.label)] : []
9134
- ].filter(
9135
- (alias, index, aliases) => alias !== portName && aliases.indexOf(alias) === index
9136
- )
9137
- });
9138
- });
9139
- return metadataByShapeId;
9140
- };
9141
- var generateShapeTsx = ({
9142
- shape,
9143
- origin,
9144
- portMetadata,
9145
- drawingEndpoints = []
9146
- }) => {
9147
- const transformPoint = getPointTransformer(origin);
9148
- if (shape.type === "RECTANGLE") {
9149
- const center = transformPoint({
9150
- x: shape.position.x + shape.width / 2,
9151
- y: shape.position.y + shape.height / 2
9152
- });
9153
- 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)}` : ""} />`;
9154
- }
9155
- if (shape.type === "ELLIPSE") {
9156
- const center = transformPoint(shape.center);
9157
- 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)}` : ""} />`;
9158
- }
9159
- if (shape.type === "POLYLINE" || shape.type === "POLYGON") {
9160
- const isPolygon = shape.type === "POLYGON";
9161
- const points = shape.points.map(transformPoint);
9162
- if (isPolygon && points.length > 0) points.push(points[0]);
9163
- return `<schematicpath points={${JSON.stringify(points)}} strokeColor=${JSON.stringify(isPolygon ? shape.lineColor : shape.color)}${isPolygon && shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
9154
+ 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);
9164
9155
  }
9165
- if (shape.type === "PATH") {
9166
- const transformedPath = transformSvgPath(shape.pathData, origin);
9167
- if (!transformedPath) return void 0;
9168
- return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.strokeColor)}${shape.fillColor !== "none" ? ` isFilled fillColor=${JSON.stringify(shape.fillColor)}` : ""} />`;
9156
+ if (Array.isArray(value)) {
9157
+ return value.some(categoryValueContainsPushbutton);
9169
9158
  }
9170
- if (shape.type === "ARC") {
9171
- const transformedPath = transformSvgPath(shape.pathData, origin);
9172
- if (!transformedPath) return void 0;
9173
- return `<schematicpath svgPath=${JSON.stringify(transformedPath)} strokeColor=${JSON.stringify(shape.color)} />`;
9159
+ if (value && typeof value === "object") {
9160
+ return Object.values(value).some(categoryValueContainsPushbutton);
9174
9161
  }
9175
- if (shape.type === "TEXT") {
9176
- if (shape.visibility !== "1") return void 0;
9177
- const position2 = transformPoint({ x: shape.x, y: shape.y });
9178
- 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)}} />`;
9162
+ return false;
9163
+ };
9164
+
9165
+ // lib/websafe/convert-to-typescript-component/is-pushbutton-category-component.ts
9166
+ var isPushbuttonCategoryComponent = (betterEasy) => {
9167
+ const cPara = betterEasy.dataStr.head.c_para;
9168
+ return [
9169
+ betterEasy.tags,
9170
+ betterEasy.title,
9171
+ betterEasy.description,
9172
+ cPara.category,
9173
+ cPara.Category,
9174
+ cPara["LCSC Category"],
9175
+ cPara["JLCPCB Category"],
9176
+ cPara.package,
9177
+ cPara.pre,
9178
+ betterEasy.category
9179
+ ].some(categoryValueContainsPushbutton);
9180
+ };
9181
+
9182
+ // lib/websafe/convert-to-typescript-component/is-resistor-component.ts
9183
+ var standardSmdResistorPackagePattern = /^R(?:01005|0201|0402|0504|0603|0805|1206|1210|1812|2010|2512)(?:$|[_-])/i;
9184
+ var normalizeExplicitScale = (scale2) => {
9185
+ if (scale2 === "k" || scale2 === "K") return "k";
9186
+ if (scale2 === "m") return "m";
9187
+ if (scale2 === "M") return "M";
9188
+ if (scale2 === "g" || scale2 === "G") return "G";
9189
+ return "";
9190
+ };
9191
+ var normalizeResistorValue = (value) => {
9192
+ if (typeof value !== "string") return void 0;
9193
+ const compactValue = value.trim().replace(/\s+/g, "");
9194
+ const explicitUnitMatch = compactValue.match(
9195
+ /^(\d+(?:\.\d+)?)([mMkKgG]?)(?:Ω|ohms?)$/i
9196
+ );
9197
+ if (explicitUnitMatch) {
9198
+ const [, magnitude, scale2] = explicitUnitMatch;
9199
+ if (Number(magnitude) === 0) return "0ohm";
9200
+ return `${magnitude}${normalizeExplicitScale(scale2)}ohm`;
9179
9201
  }
9180
- if (shape.type === "PIN" && portMetadata) {
9181
- const direction = getPinDirection(shape.rotation);
9182
- const stemLength = getPinStemLength(shape.path);
9183
- const position2 = alignPortToDrawing({
9184
- position: transformPoint({ x: shape.x, y: shape.y }),
9185
- direction,
9186
- stemLength,
9187
- drawingEndpoints
9188
- });
9189
- const pinNumberProp = portMetadata.pinNumber === void 0 ? "" : ` pinNumber={${portMetadata.pinNumber}}`;
9190
- const aliasesProp = portMetadata.aliases.length === 0 ? "" : ` aliases={${JSON.stringify(portMetadata.aliases)}}`;
9191
- const stemLengthProp = stemLength === void 0 ? "" : ` schStemLength={${stemLength}}`;
9192
- return `<port name=${JSON.stringify(portMetadata.name)}${pinNumberProp}${aliasesProp} direction=${JSON.stringify(direction)} schX={${position2.x}} schY={${position2.y}}${stemLengthProp} />`;
9202
+ const resistorCodeMatch = compactValue.match(/^(\d+)([RrKkMm])(\d*)$/);
9203
+ if (resistorCodeMatch) {
9204
+ const [, whole, multiplier, fraction] = resistorCodeMatch;
9205
+ const magnitude = fraction ? `${whole}.${fraction}` : whole;
9206
+ if (Number(magnitude) === 0) return "0ohm";
9207
+ const scale2 = multiplier === "R" || multiplier === "r" ? "" : multiplier === "K" || multiplier === "k" ? "k" : "M";
9208
+ return `${magnitude}${scale2}ohm`;
9193
9209
  }
9194
- if (shape.type === "IGNORED") return void 0;
9210
+ if (/^0+(?:\.0+)?$/.test(compactValue)) return "0ohm";
9195
9211
  return void 0;
9196
9212
  };
9197
- var generateSymbolTsx = (easyEdaJson, circuitJson, {
9198
- includePorts = true,
9199
- alignPortsToDrawing = false
9200
- } = {}) => {
9201
- const shapes = easyEdaJson.dataStr.shape;
9202
- if (shapes.length === 0) return void 0;
9203
- const headOrigin = {
9204
- x: easyEdaJson.dataStr.head.x,
9205
- y: easyEdaJson.dataStr.head.y
9206
- };
9207
- const bounds = easyEdaJson.dataStr.BBox;
9208
- const isHeadOriginInsideBounds = headOrigin.x >= bounds.x && headOrigin.x <= bounds.x + bounds.width && headOrigin.y >= bounds.y && headOrigin.y <= bounds.y + bounds.height;
9209
- const origin = isHeadOriginInsideBounds ? headOrigin : {
9210
- x: bounds.x + bounds.width / 2,
9211
- y: bounds.y + bounds.height / 2
9212
- };
9213
- const portMetadataByShapeId = getPortMetadataByShapeId(
9214
- easyEdaJson,
9215
- circuitJson
9216
- );
9217
- const transformPoint = getPointTransformer(origin);
9218
- const drawingEndpoints = alignPortsToDrawing ? getOpenPolylineEndpoints(shapes, transformPoint) : [];
9219
- const shapeTsx = shapes.filter((shape) => includePorts || shape.type !== "PIN").map(
9220
- (shape) => generateShapeTsx({
9221
- shape,
9222
- origin,
9223
- portMetadata: shape.type === "PIN" ? portMetadataByShapeId.get(shape.id) : void 0,
9224
- drawingEndpoints
9225
- })
9226
- ).filter((tsx) => Boolean(tsx));
9227
- if (shapeTsx.length === 0) return void 0;
9228
- return `<symbol>
9229
- ${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
9230
- </symbol>`;
9213
+ var isResistorComponent = (betterEasy) => {
9214
+ const componentParameters = betterEasy.dataStr.head.c_para;
9215
+ const packageName = componentParameters.package;
9216
+ return componentParameters.pre?.toUpperCase() === "R?" && typeof packageName === "string" && standardSmdResistorPackagePattern.test(packageName.trim()) && normalizeResistorValue(componentParameters.Value) !== void 0;
9231
9217
  };
9232
- var hasNonBoxSchematicSymbol = (easyEdaJson) => {
9233
- const drawableShapes = easyEdaJson.dataStr.shape.filter(
9234
- (shape) => shape.type !== "PIN" && shape.type !== "TEXT" && shape.type !== "IGNORED"
9235
- );
9236
- if (drawableShapes.length === 0) return false;
9237
- const rectangles = drawableShapes.filter(
9238
- (shape) => shape.type === "RECTANGLE"
9239
- );
9240
- const onlyBoxPrimitives = drawableShapes.every(
9241
- (shape) => shape.type === "RECTANGLE" || shape.type === "ELLIPSE" && shape.radiusX <= 2 && shape.radiusY <= 2
9242
- );
9243
- return rectangles.length !== 1 || !onlyBoxPrimitives;
9218
+
9219
+ // lib/websafe/convert-to-typescript-component/category-value-contains-switch.ts
9220
+ var categoryValueContainsSwitch = (value) => {
9221
+ if (typeof value === "string") {
9222
+ const normalized = value.toLowerCase();
9223
+ if (/analog\s+switch/.test(normalized) || /multiplex/.test(normalized) || /switching\s+diodes?/.test(normalized) || /\bics?\b/.test(normalized)) {
9224
+ return false;
9225
+ }
9226
+ return /(?:slide|toggle|dip|key|micro|limit)\s+switch(?:es)?/.test(normalized) || /(^|[^a-z])switch(?:es)?([^a-z]|$)/.test(normalized);
9227
+ }
9228
+ if (Array.isArray(value)) {
9229
+ return value.some(categoryValueContainsSwitch);
9230
+ }
9231
+ if (value && typeof value === "object") {
9232
+ return Object.values(value).some(categoryValueContainsSwitch);
9233
+ }
9234
+ return false;
9235
+ };
9236
+
9237
+ // lib/websafe/convert-to-typescript-component/is-switch-category-component.ts
9238
+ var isSwitchCategoryComponent = (betterEasy) => {
9239
+ const cPara = betterEasy.dataStr.head.c_para;
9240
+ return [
9241
+ betterEasy.tags,
9242
+ cPara.category,
9243
+ cPara.Category,
9244
+ cPara["LCSC Category"],
9245
+ cPara["JLCPCB Category"],
9246
+ betterEasy.category
9247
+ ].some(categoryValueContainsSwitch);
9244
9248
  };
9245
9249
 
9246
9250
  // lib/websafe/convert-to-typescript-component/index.tsx
@@ -9256,6 +9260,24 @@ var getGeneratedComponentType = (betterEasy, pinCount) => {
9256
9260
  if (isMicroUsbConnectorComponent(betterEasy)) return "connector";
9257
9261
  return "chip";
9258
9262
  };
9263
+ var getVisibleSchematicPinArrangement = (betterEasy) => {
9264
+ const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN");
9265
+ if (!pins.some((pin) => pin.visibility !== "show")) return void 0;
9266
+ const arrangement = {
9267
+ leftSide: [],
9268
+ rightSide: [],
9269
+ topSide: [],
9270
+ bottomSide: []
9271
+ };
9272
+ for (const pin of pins.filter((pin2) => pin2.visibility === "show")) {
9273
+ const rotation2 = (pin.rotation % 360 + 360) % 360;
9274
+ const side = rotation2 === 90 ? "topSide" : rotation2 === 180 ? "leftSide" : rotation2 === 270 ? "bottomSide" : "rightSide";
9275
+ arrangement[side].push(pin.pinNumber);
9276
+ }
9277
+ return Object.fromEntries(
9278
+ Object.entries(arrangement).filter(([, pins2]) => pins2.length > 0)
9279
+ );
9280
+ };
9259
9281
  var convertRawEasyToTsx = async ({ rawEasy }) => {
9260
9282
  const betterEasy = EasyEdaJsonSchema.parse(rawEasy);
9261
9283
  const result = await convertBetterEasyToTsx({
@@ -9289,6 +9311,11 @@ var convertBetterEasyToTsx = async ({
9289
9311
  }
9290
9312
  const componentName = normalizeManufacturerPartNumber(manufacturerPartNumber);
9291
9313
  const sourcePorts = su(circuitJson).source_port.list();
9314
+ const hiddenSchematicPinNumbers = new Set(
9315
+ betterEasy.dataStr.shape.flatMap(
9316
+ (shape) => shape.type === "PIN" && shape.visibility !== "show" ? [String(shape.pinNumber)] : []
9317
+ )
9318
+ );
9292
9319
  const pinLabels = {};
9293
9320
  const sortedPorts = sourcePorts.sort((a, b) => {
9294
9321
  const aNum = Number.parseInt(a.name.replace("pin", ""));
@@ -9296,6 +9323,7 @@ var convertBetterEasyToTsx = async ({
9296
9323
  return aNum - bNum;
9297
9324
  });
9298
9325
  for (const sourcePort of sortedPorts) {
9326
+ if (hiddenSchematicPinNumbers.has(String(sourcePort.pin_number))) continue;
9299
9327
  pinLabels[sourcePort.name] = [
9300
9328
  sourcePort.name,
9301
9329
  ...sourcePort.port_hints ?? []
@@ -9333,6 +9361,7 @@ var convertBetterEasyToTsx = async ({
9333
9361
  const symbolTsx = isPassiveWithCustomSymbol || componentType === "chip" && !isMultiPinDiode && !isMultiPinInductor && hasNonBoxSchematicSymbol(betterEasy) ? generateSymbolTsx(betterEasy, circuitJson, {
9334
9362
  alignPortsToDrawing: isPassiveWithCustomSymbol
9335
9363
  }) : void 0;
9364
+ const schPinArrangement = symbolTsx ? void 0 : getVisibleSchematicPinArrangement(betterEasy);
9336
9365
  return generateTypescriptComponent({
9337
9366
  componentName,
9338
9367
  manufacturerPartNumber,
@@ -9347,7 +9376,8 @@ var convertBetterEasyToTsx = async ({
9347
9376
  inductance: inductance2,
9348
9377
  crystalFrequency,
9349
9378
  crystalPinVariant,
9350
- symbolTsx
9379
+ symbolTsx,
9380
+ schPinArrangement
9351
9381
  });
9352
9382
  };
9353
9383
  var checkModelObjUrlValidity = async (url) => {