easyeda 0.0.369 → 0.0.371

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.d.ts CHANGED
@@ -297,6 +297,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
297
297
  textType: string;
298
298
  mirror: string;
299
299
  backgroundColor?: string | undefined;
300
+ isReferenceDesignator?: boolean | undefined;
300
301
  }, string>, z.ZodUnion<[z.ZodObject<{
301
302
  type: z.ZodLiteral<"RECTANGLE">;
302
303
  position: z.ZodObject<{
@@ -521,6 +522,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
521
522
  fontDecoration: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, string, unknown>;
522
523
  content: z.ZodString;
523
524
  textType: z.ZodString;
525
+ isReferenceDesignator: z.ZodOptional<z.ZodBoolean>;
524
526
  visibility: z.ZodEnum<["0", "1"]>;
525
527
  mirror: z.ZodString;
526
528
  id: z.ZodString;
@@ -541,6 +543,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
541
543
  textType: string;
542
544
  mirror: string;
543
545
  backgroundColor?: string | undefined;
546
+ isReferenceDesignator?: boolean | undefined;
544
547
  }, {
545
548
  type: "TEXT";
546
549
  x: number;
@@ -558,6 +561,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
558
561
  fontWeight?: unknown;
559
562
  fontStyle?: unknown;
560
563
  fontDecoration?: unknown;
564
+ isReferenceDesignator?: boolean | undefined;
561
565
  }>, z.ZodObject<{
562
566
  type: z.ZodLiteral<"IGNORED">;
563
567
  sourceType: z.ZodEnum<["AR", "I"]>;
@@ -744,6 +748,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
744
748
  textType: string;
745
749
  mirror: string;
746
750
  backgroundColor?: string | undefined;
751
+ isReferenceDesignator?: boolean | undefined;
747
752
  })[];
748
753
  head: {
749
754
  x: number;
@@ -894,6 +899,7 @@ declare const DataStrSchema: z.ZodEffects<z.ZodObject<{
894
899
  textType: string;
895
900
  mirror: string;
896
901
  backgroundColor?: string | undefined;
902
+ isReferenceDesignator?: boolean | undefined;
897
903
  })[];
898
904
  head: {
899
905
  x: number;
@@ -3077,6 +3083,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3077
3083
  textType: string;
3078
3084
  mirror: string;
3079
3085
  backgroundColor?: string | undefined;
3086
+ isReferenceDesignator?: boolean | undefined;
3080
3087
  }, string>, z.ZodUnion<[z.ZodObject<{
3081
3088
  type: z.ZodLiteral<"RECTANGLE">;
3082
3089
  position: z.ZodObject<{
@@ -3301,6 +3308,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3301
3308
  fontDecoration: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, string, unknown>;
3302
3309
  content: z.ZodString;
3303
3310
  textType: z.ZodString;
3311
+ isReferenceDesignator: z.ZodOptional<z.ZodBoolean>;
3304
3312
  visibility: z.ZodEnum<["0", "1"]>;
3305
3313
  mirror: z.ZodString;
3306
3314
  id: z.ZodString;
@@ -3321,6 +3329,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3321
3329
  textType: string;
3322
3330
  mirror: string;
3323
3331
  backgroundColor?: string | undefined;
3332
+ isReferenceDesignator?: boolean | undefined;
3324
3333
  }, {
3325
3334
  type: "TEXT";
3326
3335
  x: number;
@@ -3338,6 +3347,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3338
3347
  fontWeight?: unknown;
3339
3348
  fontStyle?: unknown;
3340
3349
  fontDecoration?: unknown;
3350
+ isReferenceDesignator?: boolean | undefined;
3341
3351
  }>, z.ZodObject<{
3342
3352
  type: z.ZodLiteral<"IGNORED">;
3343
3353
  sourceType: z.ZodEnum<["AR", "I"]>;
@@ -3524,6 +3534,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3524
3534
  textType: string;
3525
3535
  mirror: string;
3526
3536
  backgroundColor?: string | undefined;
3537
+ isReferenceDesignator?: boolean | undefined;
3527
3538
  })[];
3528
3539
  head: {
3529
3540
  x: number;
@@ -3674,6 +3685,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
3674
3685
  textType: string;
3675
3686
  mirror: string;
3676
3687
  backgroundColor?: string | undefined;
3688
+ isReferenceDesignator?: boolean | undefined;
3677
3689
  })[];
3678
3690
  head: {
3679
3691
  x: number;
@@ -4975,6 +4987,7 @@ declare const EasyEdaJsonSchema: z.ZodObject<{
4975
4987
  textType: string;
4976
4988
  mirror: string;
4977
4989
  backgroundColor?: string | undefined;
4990
+ isReferenceDesignator?: boolean | undefined;
4978
4991
  })[];
4979
4992
  head: {
4980
4993
  x: number;
package/dist/index.js CHANGED
@@ -14273,6 +14273,43 @@ function generateArcFromSweep(startX, startY, endX, endY, radius, largeArcFlag,
14273
14273
  // lib/utils/easyeda-unit-to-mm.ts
14274
14274
  var mil10ToMm = (value) => value * 10 * 0.0254;
14275
14275
 
14276
+ // lib/utils/expand-easyeda-path-data.ts
14277
+ var expandEasyEdaPathData = (pathData) => {
14278
+ const rawRoute = [];
14279
+ let currentPoint;
14280
+ for (const commandMatch of pathData.matchAll(/([MLAZ])([^MLAZ]*)/gi)) {
14281
+ const command = commandMatch[1]?.toUpperCase();
14282
+ const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
14283
+ if ((command === "M" || command === "L") && values.length >= 2) {
14284
+ currentPoint = { x: values[0], y: values[1] };
14285
+ rawRoute.push(currentPoint);
14286
+ } else if (command === "A" && currentPoint && values.length >= 7) {
14287
+ const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values;
14288
+ const generatedArcRoute = generateArcFromSweep(
14289
+ currentPoint.x,
14290
+ currentPoint.y,
14291
+ endX,
14292
+ endY,
14293
+ radiusX,
14294
+ largeArcFlag === 1,
14295
+ sweepFlag === 1
14296
+ );
14297
+ const maxArcSegments = 16;
14298
+ const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
14299
+ { length: maxArcSegments + 1 },
14300
+ (_, pointIndex) => generatedArcRoute.at(
14301
+ Math.round(
14302
+ pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
14303
+ )
14304
+ )
14305
+ ).filter((point4) => !!point4);
14306
+ rawRoute.push(...arcRoute.slice(1));
14307
+ currentPoint = { x: endX, y: endY };
14308
+ }
14309
+ }
14310
+ return rawRoute;
14311
+ };
14312
+
14276
14313
  // node_modules/@tscircuit/math-utils/dist/chunk-EFLPMB4J.js
14277
14314
  function orientation(p, q, r) {
14278
14315
  const val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
@@ -14388,6 +14425,22 @@ var getBoardOutlinePolygons = (tracks) => {
14388
14425
  return polygons;
14389
14426
  };
14390
14427
 
14428
+ // lib/utils/get-easyeda-npth-slot-geometry.ts
14429
+ var getEasyEdaNpthSlotGeometry = (solidRegion) => {
14430
+ const rawRoute = expandEasyEdaPathData(solidRegion.pathData);
14431
+ if (rawRoute.length < 2) return null;
14432
+ const points = rawRoute.map((point4) => ({
14433
+ x: mil2mm(point4.x) * 10,
14434
+ y: mil2mm(point4.y) * 10
14435
+ }));
14436
+ const firstPoint = points[0];
14437
+ const lastPoint = points.at(-1);
14438
+ if (firstPoint.x !== lastPoint.x || firstPoint.y !== lastPoint.y) {
14439
+ points.push({ ...firstPoint });
14440
+ }
14441
+ return { points };
14442
+ };
14443
+
14391
14444
  // lib/utils/normalize-pin-labels.ts
14392
14445
  var normalizeActiveLowPinLabel = (label) => {
14393
14446
  const hasActiveLowMarker = label.startsWith("#") || label.endsWith("#");
@@ -14976,40 +15029,7 @@ var handleFabricationNotePath = (track, index) => pcb_fabrication_note_path.pars
14976
15029
  stroke_width: mil10ToMm(track.width)
14977
15030
  });
14978
15031
  var handleFabricationNoteSolidRegion = (solidRegion, index) => {
14979
- const rawRoute = [];
14980
- let currentPoint;
14981
- for (const commandMatch of solidRegion.pathData.matchAll(
14982
- /([MLAZ])([^MLAZ]*)/gi
14983
- )) {
14984
- const command = commandMatch[1]?.toUpperCase();
14985
- const values = commandMatch[2]?.match(/[-+]?(?:\d*\.\d+|\d+\.?)(?:[eE][-+]?\d+)?/g)?.map(Number) ?? [];
14986
- if ((command === "M" || command === "L") && values.length >= 2) {
14987
- currentPoint = { x: values[0], y: values[1] };
14988
- rawRoute.push(currentPoint);
14989
- } else if (command === "A" && currentPoint && values.length >= 7) {
14990
- const [radiusX, , , largeArcFlag, sweepFlag, endX, endY] = values;
14991
- const generatedArcRoute = generateArcFromSweep(
14992
- currentPoint.x,
14993
- currentPoint.y,
14994
- endX,
14995
- endY,
14996
- radiusX,
14997
- largeArcFlag === 1,
14998
- sweepFlag === 1
14999
- );
15000
- const maxArcSegments = 16;
15001
- const arcRoute = generatedArcRoute.length <= maxArcSegments + 1 ? generatedArcRoute : Array.from(
15002
- { length: maxArcSegments + 1 },
15003
- (_, pointIndex) => generatedArcRoute.at(
15004
- Math.round(
15005
- pointIndex * (generatedArcRoute.length - 1) / maxArcSegments
15006
- )
15007
- )
15008
- ).filter((point4) => !!point4);
15009
- rawRoute.push(...arcRoute.slice(1));
15010
- currentPoint = { x: endX, y: endY };
15011
- }
15012
- }
15032
+ const rawRoute = expandEasyEdaPathData(solidRegion.pathData);
15013
15033
  const route = rawRoute.map((point4) => ({
15014
15034
  x: mil10ToMm(point4.x),
15015
15035
  y: mil10ToMm(point4.y)
@@ -15140,9 +15160,11 @@ var handleCutout = (solidRegion, index) => {
15140
15160
  });
15141
15161
  };
15142
15162
  var LEAD_SHAPE_LAYER = 100;
15163
+ var NPTH_FILL_STYLE = "npth";
15143
15164
  var isPcbSolidRegionCutout = (shape) => {
15144
15165
  return shape.fillStyle === "cutout" && shape.layermask !== LEAD_SHAPE_LAYER;
15145
15166
  };
15167
+ var isPcbSolidRegionNpth = (shape) => shape.fillStyle === NPTH_FILL_STYLE && shape.layermask !== LEAD_SHAPE_LAYER;
15146
15168
  var getCadPositionZMmFromMetadata = (easyEdaJson) => {
15147
15169
  const svgNode = easyEdaJson.packageDetail.dataStr.shape.find(
15148
15170
  (shape) => shape.type === "SVGNODE" && shape.svgData.attrs?.uuid
@@ -15338,6 +15360,20 @@ var convertEasyEdaJsonToCircuitJsonWithPinAttributes = (easyEdaJson, {
15338
15360
  ).forEach((sr, index) => {
15339
15361
  circuitElements.push(handleCutout(sr, index));
15340
15362
  });
15363
+ easyEdaJson.packageDetail.dataStr.shape.filter(
15364
+ (shape) => shape.type === "SOLIDREGION" && isPcbSolidRegionNpth(shape)
15365
+ ).forEach((sr, index) => {
15366
+ const geometry = getEasyEdaNpthSlotGeometry(sr);
15367
+ if (!geometry) return;
15368
+ circuitElements.push(
15369
+ pcb_cutout.parse({
15370
+ type: "pcb_cutout",
15371
+ pcb_cutout_id: `pcb_cutout_npth_${index + 1}`,
15372
+ shape: "polygon",
15373
+ points: geometry.points
15374
+ })
15375
+ );
15376
+ });
15341
15377
  const boardOutlineTracks = easyEdaJson.packageDetail.dataStr.shape.filter(
15342
15378
  (shape) => shape.type === "TRACK" && shape.layer === 10
15343
15379
  );
@@ -16425,6 +16461,7 @@ var TextShapeOutputSchema = z217.object({
16425
16461
  fontDecoration: optionalEasyEdaTextField(z217.string().optional().default("")),
16426
16462
  content: z217.string(),
16427
16463
  textType: z217.string(),
16464
+ isReferenceDesignator: z217.boolean().optional(),
16428
16465
  visibility: z217.enum(["0", "1"]),
16429
16466
  mirror: z217.string(),
16430
16467
  id: z217.string()
@@ -16432,7 +16469,7 @@ var TextShapeOutputSchema = z217.object({
16432
16469
  var parseText = (str) => {
16433
16470
  const [
16434
16471
  ,
16435
- alignment,
16472
+ textMark,
16436
16473
  x,
16437
16474
  y,
16438
16475
  rotation2,
@@ -16450,8 +16487,11 @@ var parseText = (str) => {
16450
16487
  ] = str.split("~");
16451
16488
  return {
16452
16489
  type: "TEXT",
16453
- // Some EasyEDA component payloads use "P" for start-aligned text.
16454
- alignment: alignment === "P" ? "L" : alignment,
16490
+ // EasyEDA's second text field is a mark: L=label, N=name, P=reference prefix.
16491
+ // Text anchoring is a separate field (start/middle/end).
16492
+ // https://docs.easyeda.com/en/DocumentFormat/2-EasyEDA-Schematic-File-Format/#annotations
16493
+ // Preserve the existing normalized alignment representation for consumers.
16494
+ alignment: textMark === "P" ? "L" : textMark,
16455
16495
  x: Number(x),
16456
16496
  y: Number(y),
16457
16497
  rotation: Number(rotation2),
@@ -16463,6 +16503,7 @@ var parseText = (str) => {
16463
16503
  fontDecoration,
16464
16504
  content,
16465
16505
  textType,
16506
+ ...textMark === "P" ? { isReferenceDesignator: true } : {},
16466
16507
  visibility,
16467
16508
  mirror,
16468
16509
  id
@@ -16783,6 +16824,27 @@ var normalizeSymbolName = (name) => {
16783
16824
  return trimmedName.replace(/(?<=[A-Za-z0-9])-(?=[A-Za-z0-9])/g, "_");
16784
16825
  };
16785
16826
 
16827
+ // lib/websafe/convert-to-typescript-component/generate-symbol-reference-text.ts
16828
+ var REFERENCE_TEXT_MARGIN_SCHEMATIC_UNITS = 0.2;
16829
+ var generateSymbolReferenceText = ({
16830
+ shapes,
16831
+ bounds,
16832
+ transformPoint
16833
+ }) => {
16834
+ const hasVisibleReferenceText = shapes.some(
16835
+ (shape) => shape.type === "TEXT" && shape.visibility === "1" && (shape.isReferenceDesignator || /\{(?:NAME|REF|REFERENCE)\}/.test(shape.content))
16836
+ );
16837
+ if (hasVisibleReferenceText) return void 0;
16838
+ const position2 = transformPoint({
16839
+ x: bounds.x + bounds.width / 2,
16840
+ y: bounds.y
16841
+ });
16842
+ const schY = Number(
16843
+ (position2.y + REFERENCE_TEXT_MARGIN_SCHEMATIC_UNITS).toFixed(6)
16844
+ );
16845
+ return `<schematictext schX={${position2.x}} schY={${schY}} text="{NAME}" fontSize={0.2} anchor="bottom_center" />`;
16846
+ };
16847
+
16786
16848
  // lib/websafe/convert-to-typescript-component/generate-symbol-tsx.ts
16787
16849
  var round = (value) => Number(value.toFixed(6));
16788
16850
  var EASYEDA_SCHEMATIC_UNIT_TO_TSCIRCUIT_UNIT = 0.02;
@@ -17071,7 +17133,8 @@ var generateShapeTsx = ({
17071
17133
  if (shape.type === "TEXT") {
17072
17134
  if (shape.visibility !== "1") return void 0;
17073
17135
  const position2 = transformPoint({ x: shape.x, y: shape.y });
17074
- 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)}} />`;
17136
+ const text = shape.isReferenceDesignator ? "{NAME}" : shape.content;
17137
+ return `<schematictext schX={${position2.x}} schY={${position2.y}} text=${JSON.stringify(text)} fontSize={${getTextFontSize(shape.fontSize)}} anchor=${JSON.stringify(getTextAnchor(shape.alignment))} color=${JSON.stringify(shape.fontColor)} schRotation={${round(-shape.rotation)}} />`;
17075
17138
  }
17076
17139
  if (shape.type === "PIN" && portMetadata) {
17077
17140
  if (shape.visibility !== "show") return void 0;
@@ -17122,6 +17185,12 @@ var generateSymbolTsx = (easyEdaJson, circuitJson, {
17122
17185
  })
17123
17186
  ).filter((tsx) => Boolean(tsx));
17124
17187
  if (shapeTsx.length === 0) return void 0;
17188
+ const referenceTextTsx = generateSymbolReferenceText({
17189
+ shapes,
17190
+ bounds,
17191
+ transformPoint
17192
+ });
17193
+ if (referenceTextTsx) shapeTsx.push(referenceTextTsx);
17125
17194
  return `<symbol>
17126
17195
  ${shapeTsx.map((tsx) => ` ${tsx}`).join("\n")}
17127
17196
  </symbol>`;