easyeda 0.0.272 → 0.0.274
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.js +35 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/index.js +35 -11
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +36 -12
- package/dist/main.cjs.map +1 -1
- package/package.json +1 -1
package/dist/browser/index.js
CHANGED
|
@@ -11285,11 +11285,11 @@ var generateFootprintTsx = (circuitJson, options = {}) => {
|
|
|
11285
11285
|
const cornerRadius = smtPad.corner_radius ?? smtPad.rect_border_radius ?? void 0;
|
|
11286
11286
|
const cornerRadiusAttr = cornerRadius !== void 0 ? ` cornerRadius="${mmStr(cornerRadius)}"` : "";
|
|
11287
11287
|
elementStrings.push(
|
|
11288
|
-
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}"${cornerRadiusAttr} shape="rect" />`
|
|
11288
|
+
`<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}"${cornerRadiusAttr} shape="rect" />`
|
|
11289
11289
|
);
|
|
11290
11290
|
} else if (smtPad.shape === "pill") {
|
|
11291
11291
|
elementStrings.push(
|
|
11292
|
-
`<smtpad portHints={${JSON.stringify(smtPad.port_hints)}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" radius="${mmStr(smtPad.radius)}" shape="pill" />`
|
|
11292
|
+
`<smtpad portHints={${JSON.stringify(mapPortHints(smtPad.port_hints, options.portHintsMap))}} pcbX="${mmStr(smtPad.x)}" pcbY="${mmStr(smtPad.y)}" width="${mmStr(smtPad.width)}" height="${mmStr(smtPad.height)}" radius="${mmStr(smtPad.radius)}" shape="pill" />`
|
|
11293
11293
|
);
|
|
11294
11294
|
} else if (smtPad.shape === "polygon") {
|
|
11295
11295
|
const pointsStr = smtPad.points.map((p) => `{x: "${mmStr(p.x)}", y: "${mmStr(p.y)}"}`).join(", ");
|
|
@@ -11332,10 +11332,15 @@ var getPinLabelValues = (labels) => {
|
|
|
11332
11332
|
if (typeof labels === "string") return [labels];
|
|
11333
11333
|
return [...labels];
|
|
11334
11334
|
};
|
|
11335
|
-
var
|
|
11335
|
+
var stripEasyEdaPolarityHintDecoration = (label) => label.toLowerCase().replace(/[^a-z0-9+-]/g, "");
|
|
11336
|
+
var getPinKeySortValue = (pinKey) => {
|
|
11337
|
+
const match = /^pin(\d+)$/i.exec(pinKey);
|
|
11338
|
+
return match ? Number(match[1]) : Number.MAX_SAFE_INTEGER;
|
|
11339
|
+
};
|
|
11340
|
+
var getPolarizedPinMetadata = (pinLabels) => {
|
|
11336
11341
|
const labelsByPin = Object.entries(pinLabels ?? {}).map(([pin, labels]) => ({
|
|
11337
11342
|
pin,
|
|
11338
|
-
labels: getPinLabelValues(labels).map(
|
|
11343
|
+
labels: getPinLabelValues(labels).map(stripEasyEdaPolarityHintDecoration)
|
|
11339
11344
|
}));
|
|
11340
11345
|
const anodePin = labelsByPin.find(
|
|
11341
11346
|
({ labels }) => labels.some((label) => ["a", "anode", "pos", "+"].includes(label))
|
|
@@ -11344,9 +11349,17 @@ var getPolarizedPortHintsMap = (pinLabels) => {
|
|
|
11344
11349
|
({ labels }) => labels.some((label) => ["c", "k", "cathode", "neg", "-"].includes(label))
|
|
11345
11350
|
)?.pin;
|
|
11346
11351
|
if (!anodePin || !cathodePin) return void 0;
|
|
11352
|
+
const polarizedPinEntries = [
|
|
11353
|
+
[anodePin, ["anode", "pos"]],
|
|
11354
|
+
[cathodePin, ["cathode", "neg"]]
|
|
11355
|
+
].sort(
|
|
11356
|
+
([pinA], [pinB]) => getPinKeySortValue(pinA) - getPinKeySortValue(pinB)
|
|
11357
|
+
);
|
|
11347
11358
|
return {
|
|
11348
|
-
|
|
11349
|
-
|
|
11359
|
+
portHintsMap: Object.fromEntries(
|
|
11360
|
+
polarizedPinEntries.map(([pin, labels]) => [pin, [pin, ...labels]])
|
|
11361
|
+
),
|
|
11362
|
+
pinLabels: Object.fromEntries(polarizedPinEntries)
|
|
11350
11363
|
};
|
|
11351
11364
|
};
|
|
11352
11365
|
var generateTypescriptComponent = ({
|
|
@@ -11360,10 +11373,13 @@ var generateTypescriptComponent = ({
|
|
|
11360
11373
|
componentType = "chip"
|
|
11361
11374
|
}) => {
|
|
11362
11375
|
const safePinLabels = pinLabels ?? {};
|
|
11376
|
+
const polarizedPinMetadata = getPolarizedPinMetadata(safePinLabels);
|
|
11377
|
+
const polarizedPortHintsMap = polarizedPinMetadata?.portHintsMap;
|
|
11378
|
+
const polarizedPinLabels = polarizedPinMetadata?.pinLabels;
|
|
11363
11379
|
const cadComponent = circuitJson.find((item) => item.type === "cad_component");
|
|
11364
11380
|
const footprintTsx = generateFootprintTsx(
|
|
11365
11381
|
circuitJson,
|
|
11366
|
-
componentType === "diode" || componentType === "led" ? { portHintsMap:
|
|
11382
|
+
componentType === "diode" || componentType === "led" ? { portHintsMap: polarizedPortHintsMap } : void 0
|
|
11367
11383
|
);
|
|
11368
11384
|
const simplifiedPinLabels = Object.fromEntries(
|
|
11369
11385
|
Object.entries(safePinLabels).map(([pin, labels]) => {
|
|
@@ -11374,6 +11390,14 @@ var generateTypescriptComponent = ({
|
|
|
11374
11390
|
})
|
|
11375
11391
|
);
|
|
11376
11392
|
const pinLabelsString = Object.entries(simplifiedPinLabels).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
|
|
11393
|
+
const polarizedPinLabelsString = Object.entries(polarizedPinLabels ?? {}).map(([pin, labels]) => ` ${pin}: ${JSON.stringify(labels)}`).join(",\n");
|
|
11394
|
+
const polarizedPinLabelsBlock = polarizedPinLabels ? `const pinLabels = {
|
|
11395
|
+
${polarizedPinLabelsString}
|
|
11396
|
+
} as const
|
|
11397
|
+
|
|
11398
|
+
` : "";
|
|
11399
|
+
const polarizedPinLabelsProp = polarizedPinLabels ? ` pinLabels={pinLabels}
|
|
11400
|
+
` : "";
|
|
11377
11401
|
const cadModelLines = [
|
|
11378
11402
|
objUrl ? `objUrl: "${objUrl}",` : "",
|
|
11379
11403
|
stepUrl ? `stepUrl: "${stepUrl}",` : "",
|
|
@@ -11384,13 +11408,13 @@ var generateTypescriptComponent = ({
|
|
|
11384
11408
|
return `
|
|
11385
11409
|
import type { DiodeProps } from "@tscircuit/props"
|
|
11386
11410
|
|
|
11387
|
-
export const ${componentName} = (props: DiodeProps) => {
|
|
11411
|
+
${polarizedPinLabelsBlock}export const ${componentName} = (props: DiodeProps) => {
|
|
11388
11412
|
const { name = "D1", ...restProps } = props
|
|
11389
11413
|
|
|
11390
11414
|
return (
|
|
11391
11415
|
<diode
|
|
11392
11416
|
name={name}
|
|
11393
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11417
|
+
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11394
11418
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11395
11419
|
footprint={${footprintTsx}}
|
|
11396
11420
|
${objUrl || stepUrl ? `cadModel={{
|
|
@@ -11406,13 +11430,13 @@ ${cadModelLines}
|
|
|
11406
11430
|
return `
|
|
11407
11431
|
import type { LedProps } from "@tscircuit/props"
|
|
11408
11432
|
|
|
11409
|
-
export const ${componentName} = (props: LedProps) => {
|
|
11433
|
+
${polarizedPinLabelsBlock}export const ${componentName} = (props: LedProps) => {
|
|
11410
11434
|
const { name = "LED1", ...restProps } = props
|
|
11411
11435
|
|
|
11412
11436
|
return (
|
|
11413
11437
|
<led
|
|
11414
11438
|
name={name}
|
|
11415
|
-
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11439
|
+
${polarizedPinLabelsProp} supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
|
|
11416
11440
|
manufacturerPartNumber="${manufacturerPartNumber}"
|
|
11417
11441
|
footprint={${footprintTsx}}
|
|
11418
11442
|
${objUrl || stepUrl ? `cadModel={{
|