Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions lib/schemas/easy-eda-json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const OwnerSchema = z.object({

export const HeadSchema = z.object({
docType: z.preprocess((val) => (val == null ? val : String(val)), z.string()),
editorVersion: z.string(),
editorVersion: z.string().default(""),
c_para: z.record(z.string(), z.string().nullable()),
x: z.number(),
y: z.number(),
Expand All @@ -53,7 +53,7 @@ export const HeadSchema = z.object({
}, z.number()),
importFlag: z.number().optional(),
c_spiceCmd: z.any().optional(),
hasIdFlag: z.boolean(),
hasIdFlag: z.boolean().default(false),
})

export const BBoxSchema = z.object({
Expand All @@ -78,13 +78,23 @@ export const ObjectItemSchema = z.object({
locked: z.boolean(),
})

export const DataStrSchema = z.object({
head: HeadSchema,
canvas: z.string(),
shape: z.array(SingleLetterShapeSchema),
BBox: BBoxSchema,
colors: z.union([z.array(z.string()), z.record(z.string())]),
})
export const DataStrSchema = z
.object({
head: HeadSchema,
canvas: z.string(),
shape: z.array(SingleLetterShapeSchema),
BBox: BBoxSchema.optional(),
colors: z.union([z.array(z.string()), z.record(z.string())]).default([]),
})
.transform((data) => ({
...data,
BBox: data.BBox ?? {
x: data.head.x,
y: data.head.y,
width: 0,
height: 0,
},
}))

export const PackageDetailDataStrSchema = z.object({
head: HeadSchema,
Expand Down
10 changes: 7 additions & 3 deletions lib/schemas/package-detail-shape-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const safeNumber = (defaultValue = 0) =>
.union([z.number(), z.string()])
.transform((val) => {
const num = Number(val)
return isNaN(num) ? defaultValue : num
return Number.isNaN(num) ? defaultValue : num
})
.default(defaultValue)

Expand Down Expand Up @@ -191,17 +191,21 @@ export const ShapeItemSchema = z
}
case "PAD": {
const [padShape, ...params] = shape.data.split("~")
const rawPadNumber = params[6]
const [
centerX,
centerY,
width,
height,
layermask,
net,
number,
numericPadNumber,
holeRadius,
...rest
] = params.map((p) => (Number.isNaN(Number(p)) ? p : Number(p)))
const padNumber = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(rawPadNumber)
? numericPadNumber
: rawPadNumber
const center = { x: centerX, y: centerY }
let points: number[][] | undefined

Expand All @@ -221,7 +225,7 @@ export const ShapeItemSchema = z
height,
layermask,
net,
number,
number: padNumber,
holeRadius,
points,
rotation,
Expand Down
2,275 changes: 2,275 additions & 0 deletions tests/assets/C2943786.raweasy.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/convert-to-ts/__snapshots__/c2943786-pcb.snap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/convert-to-ts/__snapshots__/c2943786-schematic.snap.svg

@imrishabh18 imrishabh18 Jul 30, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seveibar This looks crazy. Maybe a chip this large should automatically be split into multiple <schematicbox /> ?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading