kicadts 0.0.2 → 0.0.4
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 +4466 -0
- package/dist/index.js +14253 -0
- package/package.json +5 -2
- package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
- package/.github/workflows/bun-formatcheck.yml +0 -26
- package/.github/workflows/bun-pver-release.yml +0 -70
- package/.github/workflows/bun-test.yml +0 -32
- package/.github/workflows/bun-typecheck.yml +0 -26
- package/.vscode/settings.json +0 -16
- package/AGENTS.md +0 -31
- package/TODO.md +0 -46
- package/biome.json +0 -93
- package/bunfig.toml +0 -5
- package/lib/index.ts +0 -1
- package/lib/sexpr/base-classes/SxClass.ts +0 -164
- package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +0 -35
- package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +0 -26
- package/lib/sexpr/base-classes/SxPrimitiveString.ts +0 -26
- package/lib/sexpr/classes/At.ts +0 -53
- package/lib/sexpr/classes/Bus.ts +0 -103
- package/lib/sexpr/classes/BusEntry.ts +0 -169
- package/lib/sexpr/classes/Color.ts +0 -29
- package/lib/sexpr/classes/Dnp.ts +0 -8
- package/lib/sexpr/classes/EmbeddedFonts.ts +0 -68
- package/lib/sexpr/classes/ExcludeFromSim.ts +0 -8
- package/lib/sexpr/classes/FieldsAutoplaced.ts +0 -8
- package/lib/sexpr/classes/Footprint.ts +0 -849
- package/lib/sexpr/classes/FootprintAttr.ts +0 -104
- package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +0 -9
- package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +0 -9
- package/lib/sexpr/classes/FootprintClearance.ts +0 -9
- package/lib/sexpr/classes/FootprintDescr.ts +0 -44
- package/lib/sexpr/classes/FootprintLocked.ts +0 -32
- package/lib/sexpr/classes/FootprintModel.ts +0 -142
- package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +0 -52
- package/lib/sexpr/classes/FootprintPad.ts +0 -857
- package/lib/sexpr/classes/FootprintPath.ts +0 -44
- package/lib/sexpr/classes/FootprintPlaced.ts +0 -32
- package/lib/sexpr/classes/FootprintPrivateLayers.ts +0 -56
- package/lib/sexpr/classes/FootprintSheetfile.ts +0 -44
- package/lib/sexpr/classes/FootprintSheetname.ts +0 -44
- package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +0 -9
- package/lib/sexpr/classes/FootprintTags.ts +0 -44
- package/lib/sexpr/classes/FootprintTedit.ts +0 -21
- package/lib/sexpr/classes/FootprintThermalGap.ts +0 -9
- package/lib/sexpr/classes/FootprintThermalWidth.ts +0 -9
- package/lib/sexpr/classes/FootprintZoneConnect.ts +0 -9
- package/lib/sexpr/classes/FpArc.ts +0 -312
- package/lib/sexpr/classes/FpCircle.ts +0 -314
- package/lib/sexpr/classes/FpLine.ts +0 -316
- package/lib/sexpr/classes/FpPoly.ts +0 -286
- package/lib/sexpr/classes/FpPolyFill.ts +0 -48
- package/lib/sexpr/classes/FpPolyLocked.ts +0 -40
- package/lib/sexpr/classes/FpRect.ts +0 -314
- package/lib/sexpr/classes/FpText.ts +0 -375
- package/lib/sexpr/classes/FpTextBox.ts +0 -450
- package/lib/sexpr/classes/GrLine.ts +0 -264
- package/lib/sexpr/classes/GrLineAngle.ts +0 -32
- package/lib/sexpr/classes/GrLineEnd.ts +0 -61
- package/lib/sexpr/classes/GrLineLocked.ts +0 -40
- package/lib/sexpr/classes/GrLineStart.ts +0 -61
- package/lib/sexpr/classes/GrText.ts +0 -228
- package/lib/sexpr/classes/Image.ts +0 -283
- package/lib/sexpr/classes/InBom.ts +0 -8
- package/lib/sexpr/classes/Junction.ts +0 -166
- package/lib/sexpr/classes/KicadPcb.ts +0 -361
- package/lib/sexpr/classes/KicadSch.ts +0 -397
- package/lib/sexpr/classes/KicadSchGenerator.ts +0 -32
- package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +0 -30
- package/lib/sexpr/classes/KicadSchVersion.ts +0 -22
- package/lib/sexpr/classes/Label.ts +0 -176
- package/lib/sexpr/classes/Layer.ts +0 -51
- package/lib/sexpr/classes/Layers.ts +0 -47
- package/lib/sexpr/classes/LibSymbols.ts +0 -61
- package/lib/sexpr/classes/NoConnect.ts +0 -90
- package/lib/sexpr/classes/OnBoard.ts +0 -8
- package/lib/sexpr/classes/PadChamfer.ts +0 -50
- package/lib/sexpr/classes/PadChamferRatio.ts +0 -9
- package/lib/sexpr/classes/PadClearance.ts +0 -9
- package/lib/sexpr/classes/PadDieLength.ts +0 -9
- package/lib/sexpr/classes/PadDrill.ts +0 -145
- package/lib/sexpr/classes/PadDrillOffset.ts +0 -54
- package/lib/sexpr/classes/PadLayers.ts +0 -71
- package/lib/sexpr/classes/PadNet.ts +0 -56
- package/lib/sexpr/classes/PadOptions.ts +0 -181
- package/lib/sexpr/classes/PadPinFunction.ts +0 -9
- package/lib/sexpr/classes/PadPinType.ts +0 -9
- package/lib/sexpr/classes/PadPrimitiveGrArc.ts +0 -272
- package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +0 -298
- package/lib/sexpr/classes/PadPrimitiveGrLine.ts +0 -126
- package/lib/sexpr/classes/PadPrimitives.ts +0 -291
- package/lib/sexpr/classes/PadRectDelta.ts +0 -57
- package/lib/sexpr/classes/PadRoundrectRratio.ts +0 -9
- package/lib/sexpr/classes/PadSize.ts +0 -69
- package/lib/sexpr/classes/PadSolderMaskMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMargin.ts +0 -9
- package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +0 -9
- package/lib/sexpr/classes/PadTeardrops.ts +0 -210
- package/lib/sexpr/classes/PadThermalBridgeAngle.ts +0 -9
- package/lib/sexpr/classes/PadThermalGap.ts +0 -9
- package/lib/sexpr/classes/PadThermalWidth.ts +0 -9
- package/lib/sexpr/classes/PadZoneConnect.ts +0 -9
- package/lib/sexpr/classes/Paper.ts +0 -119
- package/lib/sexpr/classes/PcbGeneral.ts +0 -82
- package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +0 -44
- package/lib/sexpr/classes/PcbGeneralThickness.ts +0 -9
- package/lib/sexpr/classes/PcbGenerator.ts +0 -16
- package/lib/sexpr/classes/PcbGeneratorVersion.ts +0 -16
- package/lib/sexpr/classes/PcbLayerDefinition.ts +0 -106
- package/lib/sexpr/classes/PcbLayers.ts +0 -34
- package/lib/sexpr/classes/PcbNet.ts +0 -56
- package/lib/sexpr/classes/PcbVersion.ts +0 -9
- package/lib/sexpr/classes/Property.ts +0 -301
- package/lib/sexpr/classes/PropertyHide.ts +0 -9
- package/lib/sexpr/classes/PropertyUnlocked.ts +0 -9
- package/lib/sexpr/classes/Pts.ts +0 -67
- package/lib/sexpr/classes/RenderCache.ts +0 -221
- package/lib/sexpr/classes/SchematicText.ts +0 -171
- package/lib/sexpr/classes/Segment.ts +0 -243
- package/lib/sexpr/classes/SegmentEnd.ts +0 -59
- package/lib/sexpr/classes/SegmentLocked.ts +0 -33
- package/lib/sexpr/classes/SegmentNet.ts +0 -64
- package/lib/sexpr/classes/SegmentStart.ts +0 -59
- package/lib/sexpr/classes/Setup/PcbPlotParams.ts +0 -689
- package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +0 -9
- package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +0 -105
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +0 -104
- package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +0 -105
- package/lib/sexpr/classes/Setup/Setup.ts +0 -574
- package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +0 -119
- package/lib/sexpr/classes/Setup/Stackup.ts +0 -135
- package/lib/sexpr/classes/Setup/StackupLayer.ts +0 -233
- package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +0 -80
- package/lib/sexpr/classes/Setup/StackupProperties.ts +0 -40
- package/lib/sexpr/classes/Setup/base.ts +0 -165
- package/lib/sexpr/classes/Setup/index.ts +0 -14
- package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +0 -53
- package/lib/sexpr/classes/Setup/setupNumericProperties.ts +0 -151
- package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +0 -90
- package/lib/sexpr/classes/Setup/setupStringProperties.ts +0 -75
- package/lib/sexpr/classes/Sheet.ts +0 -287
- package/lib/sexpr/classes/SheetFill.ts +0 -44
- package/lib/sexpr/classes/SheetInstances.ts +0 -168
- package/lib/sexpr/classes/SheetInstancesRoot.ts +0 -165
- package/lib/sexpr/classes/SheetPin.ts +0 -125
- package/lib/sexpr/classes/SheetProperty.ts +0 -115
- package/lib/sexpr/classes/SheetSize.ts +0 -44
- package/lib/sexpr/classes/Stroke.ts +0 -58
- package/lib/sexpr/classes/StrokeType.ts +0 -34
- package/lib/sexpr/classes/Symbol.ts +0 -1666
- package/lib/sexpr/classes/TextEffects.ts +0 -461
- package/lib/sexpr/classes/TitleBlock.ts +0 -369
- package/lib/sexpr/classes/Unit.ts +0 -28
- package/lib/sexpr/classes/Uuid.ts +0 -8
- package/lib/sexpr/classes/Via.ts +0 -363
- package/lib/sexpr/classes/ViaNet.ts +0 -60
- package/lib/sexpr/classes/Width.ts +0 -8
- package/lib/sexpr/classes/Wire.ts +0 -111
- package/lib/sexpr/classes/Xy.ts +0 -33
- package/lib/sexpr/classes/Zone.ts +0 -39
- package/lib/sexpr/index.ts +0 -130
- package/lib/sexpr/parseKicadSexpr.ts +0 -5
- package/lib/sexpr/parseToPrimitiveSExpr.ts +0 -245
- package/lib/sexpr/utils/indentLines.ts +0 -3
- package/lib/sexpr/utils/parseYesNo.ts +0 -12
- package/lib/sexpr/utils/quoteSExprString.ts +0 -8
- package/lib/sexpr/utils/strokeFromArgs.ts +0 -18
- package/lib/sexpr/utils/toNumberValue.ts +0 -13
- package/lib/sexpr/utils/toStringValue.ts +0 -11
- package/scripts/download-references.ts +0 -68
- package/tests/fixtures/expectEqualPrimitiveSExpr.ts +0 -199
- package/tests/fixtures/png-matcher.ts +0 -109
- package/tests/fixtures/preload.ts +0 -1
- package/tests/sexpr/KicadPcbDemos.test.ts +0 -48
- package/tests/sexpr/KicadSchDemos.test.ts +0 -49
- package/tests/sexpr/classes/Footprint.test.ts +0 -277
- package/tests/sexpr/classes/FootprintPad.test.ts +0 -78
- package/tests/sexpr/classes/FpArc.test.ts +0 -45
- package/tests/sexpr/classes/FpCircle.test.ts +0 -39
- package/tests/sexpr/classes/FpPoly.test.ts +0 -43
- package/tests/sexpr/classes/FpRect.test.ts +0 -40
- package/tests/sexpr/classes/FpTextBox.test.ts +0 -84
- package/tests/sexpr/classes/Image.test.ts +0 -58
- package/tests/sexpr/classes/KicadSch.test.ts +0 -95
- package/tests/sexpr/classes/Paper.test.ts +0 -30
- package/tests/sexpr/classes/Property.test.ts +0 -48
- package/tests/sexpr/classes/Setup.test.ts +0 -188
- package/tests/sexpr/classes/Sheet.test.ts +0 -107
- package/tests/sexpr/classes/Stroke.test.ts +0 -15
- package/tests/sexpr/classes/Symbol.test.ts +0 -96
- package/tests/sexpr/classes/TextEffects.test.ts +0 -56
- package/tests/sexpr/classes/TitleBlock.test.ts +0 -40
- package/tsconfig.json +0 -35
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
4
|
-
|
|
5
|
-
const isSymbol = (value: string) => /^[A-Za-z0-9._-]+$/.test(value)
|
|
6
|
-
|
|
7
|
-
export class PcbGeneratorVersion extends SxPrimitiveString {
|
|
8
|
-
static override token = "generator_version"
|
|
9
|
-
static override parentToken = "kicad_pcb"
|
|
10
|
-
token = "generator_version"
|
|
11
|
-
|
|
12
|
-
override getString(): string {
|
|
13
|
-
return `(generator_version ${isSymbol(this.value) ? this.value : quoteSExprString(this.value)})`
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
SxClass.register(PcbGeneratorVersion)
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
4
|
-
import { toNumberValue } from "../utils/toNumberValue"
|
|
5
|
-
import { toStringValue } from "../utils/toStringValue"
|
|
6
|
-
|
|
7
|
-
export class PcbLayerDefinition extends SxClass {
|
|
8
|
-
static override token = "__pcb_layer_definition__"
|
|
9
|
-
static override parentToken = "layers"
|
|
10
|
-
token = "__pcb_layer_definition__"
|
|
11
|
-
|
|
12
|
-
private _index?: number
|
|
13
|
-
private _name?: string
|
|
14
|
-
private _type?: string
|
|
15
|
-
private _userName?: string
|
|
16
|
-
|
|
17
|
-
constructor(options: {
|
|
18
|
-
index?: number
|
|
19
|
-
name?: string
|
|
20
|
-
type?: string
|
|
21
|
-
userName?: string
|
|
22
|
-
}) {
|
|
23
|
-
super()
|
|
24
|
-
this._index = options.index
|
|
25
|
-
this._name = options.name
|
|
26
|
-
this._type = options.type
|
|
27
|
-
this._userName = options.userName
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static fromPrimitive(primitive: PrimitiveSExpr): PcbLayerDefinition {
|
|
31
|
-
if (!Array.isArray(primitive) || primitive.length < 3) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
`layers entry must be an array with at least index, name, and type: ${JSON.stringify(primitive)}`,
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
const [rawIndex, rawName, rawType, rawUser] = primitive
|
|
37
|
-
const index = toNumberValue(rawIndex)
|
|
38
|
-
const name = toStringValue(rawName)
|
|
39
|
-
const type = toStringValue(rawType)
|
|
40
|
-
const userName = rawUser === undefined ? undefined : toStringValue(rawUser)
|
|
41
|
-
|
|
42
|
-
if (index === undefined || name === undefined || type === undefined) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`layers entry is missing required values: ${JSON.stringify(primitive)}`,
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return new PcbLayerDefinition({ index, name, type, userName })
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get index(): number | undefined {
|
|
52
|
-
return this._index
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
set index(value: number | undefined) {
|
|
56
|
-
this._index = value
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get name(): string | undefined {
|
|
60
|
-
return this._name
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
set name(value: string | undefined) {
|
|
64
|
-
this._name = value
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get type(): string | undefined {
|
|
68
|
-
return this._type
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
set type(value: string | undefined) {
|
|
72
|
-
this._type = value
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get userName(): string | undefined {
|
|
76
|
-
return this._userName
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
set userName(value: string | undefined) {
|
|
80
|
-
this._userName = value
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
override getChildren(): SxClass[] {
|
|
84
|
-
return []
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
override getString(): string {
|
|
88
|
-
if (
|
|
89
|
-
this._index === undefined ||
|
|
90
|
-
this._name === undefined ||
|
|
91
|
-
this._type === undefined
|
|
92
|
-
) {
|
|
93
|
-
return "()"
|
|
94
|
-
}
|
|
95
|
-
const tokens = [
|
|
96
|
-
String(this._index),
|
|
97
|
-
quoteSExprString(this._name),
|
|
98
|
-
this._type,
|
|
99
|
-
]
|
|
100
|
-
if (this._userName !== undefined) {
|
|
101
|
-
tokens.push(quoteSExprString(this._userName))
|
|
102
|
-
}
|
|
103
|
-
return `(${tokens.join(" ")})`
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
SxClass.register(PcbLayerDefinition)
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { PcbLayerDefinition } from "./PcbLayerDefinition"
|
|
4
|
-
|
|
5
|
-
export class PcbLayers extends SxClass {
|
|
6
|
-
static override token = "layers"
|
|
7
|
-
static override parentToken = "kicad_pcb"
|
|
8
|
-
token = "layers"
|
|
9
|
-
|
|
10
|
-
private _definitions: PcbLayerDefinition[] = []
|
|
11
|
-
|
|
12
|
-
static override fromSexprPrimitives(
|
|
13
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
14
|
-
): PcbLayers {
|
|
15
|
-
const layers = new PcbLayers()
|
|
16
|
-
layers._definitions = primitiveSexprs.map((primitive) =>
|
|
17
|
-
PcbLayerDefinition.fromPrimitive(primitive),
|
|
18
|
-
)
|
|
19
|
-
return layers
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get definitions(): PcbLayerDefinition[] {
|
|
23
|
-
return [...this._definitions]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
set definitions(value: PcbLayerDefinition[]) {
|
|
27
|
-
this._definitions = [...value]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
override getChildren(): SxClass[] {
|
|
31
|
-
return [...this._definitions]
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
SxClass.register(PcbLayers)
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
4
|
-
import { toNumberValue } from "../utils/toNumberValue"
|
|
5
|
-
import { toStringValue } from "../utils/toStringValue"
|
|
6
|
-
|
|
7
|
-
export class PcbNet extends SxClass {
|
|
8
|
-
static override token = "net"
|
|
9
|
-
static override parentToken = "kicad_pcb"
|
|
10
|
-
token = "net"
|
|
11
|
-
|
|
12
|
-
private _id: number
|
|
13
|
-
private _name: string
|
|
14
|
-
|
|
15
|
-
constructor(id: number, name: string) {
|
|
16
|
-
super()
|
|
17
|
-
this._id = id
|
|
18
|
-
this._name = name
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static override fromSexprPrimitives(
|
|
22
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
23
|
-
): PcbNet {
|
|
24
|
-
const id = toNumberValue(primitiveSexprs[0])
|
|
25
|
-
const name = toStringValue(primitiveSexprs[1])
|
|
26
|
-
if (id === undefined || name === undefined) {
|
|
27
|
-
throw new Error("net requires numeric id and string name")
|
|
28
|
-
}
|
|
29
|
-
return new PcbNet(id, name)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get id(): number {
|
|
33
|
-
return this._id
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set id(value: number) {
|
|
37
|
-
this._id = value
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get name(): string {
|
|
41
|
-
return this._name
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
set name(value: string) {
|
|
45
|
-
this._name = value
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
override getChildren(): SxClass[] {
|
|
49
|
-
return []
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
override getString(): string {
|
|
53
|
-
return `(net ${this._id} ${quoteSExprString(this._name)})`
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
SxClass.register(PcbNet)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
|
|
4
|
-
export class PcbVersion extends SxPrimitiveNumber {
|
|
5
|
-
static override token = "version"
|
|
6
|
-
static override parentToken = "kicad_pcb"
|
|
7
|
-
token = "version"
|
|
8
|
-
}
|
|
9
|
-
SxClass.register(PcbVersion)
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { printSExpr } from "../parseToPrimitiveSExpr"
|
|
4
|
-
import { quoteSExprString } from "../utils/quoteSExprString"
|
|
5
|
-
import { toStringValue } from "../utils/toStringValue"
|
|
6
|
-
import { At, type AtInput } from "./At"
|
|
7
|
-
import { Layer } from "./Layer"
|
|
8
|
-
import { PropertyHide } from "./PropertyHide"
|
|
9
|
-
import { PropertyUnlocked } from "./PropertyUnlocked"
|
|
10
|
-
import { TextEffects } from "./TextEffects"
|
|
11
|
-
import { Uuid } from "./Uuid"
|
|
12
|
-
import { Xy } from "./Xy"
|
|
13
|
-
|
|
14
|
-
const SUPPORTED_SINGLE_CHILDREN = new Set([
|
|
15
|
-
"at",
|
|
16
|
-
"xy",
|
|
17
|
-
"layer",
|
|
18
|
-
"uuid",
|
|
19
|
-
"effects",
|
|
20
|
-
"unlocked",
|
|
21
|
-
"hide",
|
|
22
|
-
])
|
|
23
|
-
|
|
24
|
-
const ensureSingleChild = (
|
|
25
|
-
arrayPropertyMap: Record<string, SxClass[]>,
|
|
26
|
-
token: string,
|
|
27
|
-
) => {
|
|
28
|
-
const entries = arrayPropertyMap[token]
|
|
29
|
-
if (entries && entries.length > 1) {
|
|
30
|
-
throw new Error(`property does not support repeated "${token}" children`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const primitiveToString = (
|
|
35
|
-
value: PrimitiveSExpr | undefined,
|
|
36
|
-
): string | undefined => {
|
|
37
|
-
if (value === undefined) {
|
|
38
|
-
return undefined
|
|
39
|
-
}
|
|
40
|
-
const asString = toStringValue(value)
|
|
41
|
-
if (asString !== undefined) {
|
|
42
|
-
return asString
|
|
43
|
-
}
|
|
44
|
-
return printSExpr(value)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface PropertyConstructorParams {
|
|
48
|
-
key?: string
|
|
49
|
-
value?: string
|
|
50
|
-
position?: AtInput | Xy
|
|
51
|
-
layer?: Layer | Array<string | number> | string
|
|
52
|
-
uuid?: string | Uuid
|
|
53
|
-
effects?: TextEffects
|
|
54
|
-
unlocked?: boolean | PropertyUnlocked
|
|
55
|
-
hidden?: boolean | PropertyHide
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export class Property extends SxClass {
|
|
59
|
-
static override token = "property"
|
|
60
|
-
token = "property"
|
|
61
|
-
|
|
62
|
-
private _key = ""
|
|
63
|
-
private _value = ""
|
|
64
|
-
private _sxAt?: At
|
|
65
|
-
private _sxXy?: Xy
|
|
66
|
-
private _sxLayer?: Layer
|
|
67
|
-
private _sxUuid?: Uuid
|
|
68
|
-
private _sxEffects?: TextEffects
|
|
69
|
-
private _sxUnlocked?: PropertyUnlocked
|
|
70
|
-
private _sxHide?: PropertyHide
|
|
71
|
-
|
|
72
|
-
constructor(
|
|
73
|
-
keyOrParams: string | PropertyConstructorParams = {},
|
|
74
|
-
value = "",
|
|
75
|
-
) {
|
|
76
|
-
super()
|
|
77
|
-
|
|
78
|
-
// Support both old constructor signature and new params interface
|
|
79
|
-
if (typeof keyOrParams === "string") {
|
|
80
|
-
this._key = keyOrParams
|
|
81
|
-
this._value = value
|
|
82
|
-
} else {
|
|
83
|
-
const params = keyOrParams
|
|
84
|
-
if (params.key !== undefined) {
|
|
85
|
-
this._key = params.key
|
|
86
|
-
}
|
|
87
|
-
if (params.value !== undefined) {
|
|
88
|
-
this._value = params.value
|
|
89
|
-
}
|
|
90
|
-
if (params.position !== undefined) {
|
|
91
|
-
this.position = params.position
|
|
92
|
-
}
|
|
93
|
-
if (params.layer !== undefined) {
|
|
94
|
-
this.layer = params.layer
|
|
95
|
-
}
|
|
96
|
-
if (params.uuid !== undefined) {
|
|
97
|
-
this.uuid = params.uuid
|
|
98
|
-
}
|
|
99
|
-
if (params.effects !== undefined) {
|
|
100
|
-
this.effects = params.effects
|
|
101
|
-
}
|
|
102
|
-
if (params.unlocked !== undefined) {
|
|
103
|
-
if (params.unlocked instanceof PropertyUnlocked) {
|
|
104
|
-
this._sxUnlocked = params.unlocked
|
|
105
|
-
} else {
|
|
106
|
-
this.unlocked = params.unlocked
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (params.hidden !== undefined) {
|
|
110
|
-
if (params.hidden instanceof PropertyHide) {
|
|
111
|
-
this._sxHide = params.hidden
|
|
112
|
-
} else {
|
|
113
|
-
this.hidden = params.hidden
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
static override fromSexprPrimitives(
|
|
120
|
-
primitiveSexprs: PrimitiveSExpr[],
|
|
121
|
-
): Property {
|
|
122
|
-
if (primitiveSexprs.length < 2) {
|
|
123
|
-
throw new Error("property requires key and value arguments")
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const [rawKey, rawValue, ...rest] = primitiveSexprs
|
|
127
|
-
|
|
128
|
-
const key = primitiveToString(rawKey)
|
|
129
|
-
const value = primitiveToString(rawValue)
|
|
130
|
-
if (key === undefined) {
|
|
131
|
-
throw new Error("property key must be a printable value")
|
|
132
|
-
}
|
|
133
|
-
if (value === undefined) {
|
|
134
|
-
throw new Error("property value must be a printable value")
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (const primitive of rest) {
|
|
138
|
-
if (!Array.isArray(primitive)) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
`property encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
if (primitive.length === 0 || typeof primitive[0] !== "string") {
|
|
144
|
-
throw new Error(
|
|
145
|
-
`property encountered invalid child expression: ${JSON.stringify(primitive)}`,
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const property = new Property(key, value)
|
|
151
|
-
|
|
152
|
-
const { propertyMap, arrayPropertyMap } =
|
|
153
|
-
SxClass.parsePrimitivesToClassProperties(rest, this.token)
|
|
154
|
-
|
|
155
|
-
for (const token of Object.keys(propertyMap)) {
|
|
156
|
-
if (!SUPPORTED_SINGLE_CHILDREN.has(token)) {
|
|
157
|
-
throw new Error(
|
|
158
|
-
`property encountered unsupported child token "${token}"`,
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
for (const token of Object.keys(arrayPropertyMap)) {
|
|
164
|
-
if (!SUPPORTED_SINGLE_CHILDREN.has(token)) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`property encountered unsupported child token "${token}"`,
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
ensureSingleChild(arrayPropertyMap, token)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const at = propertyMap.at as At | undefined
|
|
173
|
-
const xy = propertyMap.xy as Xy | undefined
|
|
174
|
-
if (at && xy) {
|
|
175
|
-
throw new Error("property can't include both at and xy children")
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
property._sxAt = at
|
|
179
|
-
property._sxXy = xy
|
|
180
|
-
property._sxLayer = propertyMap.layer as Layer | undefined
|
|
181
|
-
property._sxUuid = propertyMap.uuid as Uuid | undefined
|
|
182
|
-
property._sxEffects = propertyMap.effects as TextEffects | undefined
|
|
183
|
-
property._sxUnlocked = propertyMap.unlocked as PropertyUnlocked | undefined
|
|
184
|
-
property._sxHide = propertyMap.hide as PropertyHide | undefined
|
|
185
|
-
|
|
186
|
-
return property
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
get key(): string {
|
|
190
|
-
return this._key
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
set key(value: string) {
|
|
194
|
-
this._key = value
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
get value(): string {
|
|
198
|
-
return this._value
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
set value(value: string) {
|
|
202
|
-
this._value = value
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
get position(): At | Xy | undefined {
|
|
206
|
-
return this._sxAt ?? this._sxXy
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
set position(value: AtInput | Xy | undefined) {
|
|
210
|
-
if (value === undefined) {
|
|
211
|
-
this._sxAt = undefined
|
|
212
|
-
this._sxXy = undefined
|
|
213
|
-
return
|
|
214
|
-
}
|
|
215
|
-
if (value instanceof Xy) {
|
|
216
|
-
this._sxXy = value
|
|
217
|
-
this._sxAt = undefined
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
// Handle AtInput (At, array, or object)
|
|
221
|
-
this._sxAt = At.from(value as AtInput)
|
|
222
|
-
this._sxXy = undefined
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
get layer(): Layer | undefined {
|
|
226
|
-
return this._sxLayer
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
set layer(value: Layer | Array<string | number> | string | undefined) {
|
|
230
|
-
if (value === undefined) {
|
|
231
|
-
this._sxLayer = undefined
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
if (value instanceof Layer) {
|
|
235
|
-
this._sxLayer = value
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
const names = Array.isArray(value) ? value : [value]
|
|
239
|
-
this._sxLayer = new Layer(names)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
get uuid(): Uuid | undefined {
|
|
243
|
-
return this._sxUuid
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
set uuid(value: Uuid | string | undefined) {
|
|
247
|
-
if (value === undefined) {
|
|
248
|
-
this._sxUuid = undefined
|
|
249
|
-
return
|
|
250
|
-
}
|
|
251
|
-
this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
get effects(): TextEffects | undefined {
|
|
255
|
-
return this._sxEffects
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
set effects(value: TextEffects | undefined) {
|
|
259
|
-
this._sxEffects = value
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
get unlocked(): boolean {
|
|
263
|
-
return this._sxUnlocked?.value ?? false
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
set unlocked(value: boolean) {
|
|
267
|
-
this._sxUnlocked = new PropertyUnlocked(value)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
get hidden(): boolean {
|
|
271
|
-
return this._sxHide?.value ?? false
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
set hidden(value: boolean) {
|
|
275
|
-
this._sxHide = new PropertyHide(value)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
override getChildren(): SxClass[] {
|
|
279
|
-
const children: SxClass[] = []
|
|
280
|
-
if (this._sxAt) children.push(this._sxAt)
|
|
281
|
-
if (this._sxXy) children.push(this._sxXy)
|
|
282
|
-
if (this._sxUnlocked) children.push(this._sxUnlocked)
|
|
283
|
-
if (this._sxLayer) children.push(this._sxLayer)
|
|
284
|
-
if (this._sxHide) children.push(this._sxHide)
|
|
285
|
-
if (this._sxUuid) children.push(this._sxUuid)
|
|
286
|
-
if (this._sxEffects) children.push(this._sxEffects)
|
|
287
|
-
return children
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
override getString(): string {
|
|
291
|
-
const lines = [
|
|
292
|
-
`(property ${quoteSExprString(this._key)} ${quoteSExprString(this._value)}`,
|
|
293
|
-
]
|
|
294
|
-
for (const child of this.getChildren()) {
|
|
295
|
-
lines.push(child.getStringIndented())
|
|
296
|
-
}
|
|
297
|
-
lines.push(")")
|
|
298
|
-
return lines.join("\n")
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
SxClass.register(Property)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
|
|
4
|
-
export class PropertyHide extends SxPrimitiveBoolean {
|
|
5
|
-
static override token = "hide"
|
|
6
|
-
static override parentToken = "property"
|
|
7
|
-
token = "hide"
|
|
8
|
-
}
|
|
9
|
-
SxClass.register(PropertyHide)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
|
|
2
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
3
|
-
|
|
4
|
-
export class PropertyUnlocked extends SxPrimitiveBoolean {
|
|
5
|
-
static override token = "unlocked"
|
|
6
|
-
static override parentToken = "property"
|
|
7
|
-
token = "unlocked"
|
|
8
|
-
}
|
|
9
|
-
SxClass.register(PropertyUnlocked)
|
package/lib/sexpr/classes/Pts.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { SxClass } from "../base-classes/SxClass"
|
|
2
|
-
import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
|
|
3
|
-
import { printSExpr } from "../parseToPrimitiveSExpr"
|
|
4
|
-
import { Xy } from "./Xy"
|
|
5
|
-
|
|
6
|
-
export class Pts extends SxClass {
|
|
7
|
-
static override token = "pts"
|
|
8
|
-
token = "pts"
|
|
9
|
-
|
|
10
|
-
points: Array<Xy>
|
|
11
|
-
|
|
12
|
-
constructor(points: Array<Xy> = []) {
|
|
13
|
-
super()
|
|
14
|
-
this.points = points
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static override fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): Pts {
|
|
18
|
-
const points: Xy[] = []
|
|
19
|
-
|
|
20
|
-
for (const primitive of primitiveSexprs) {
|
|
21
|
-
if (!Array.isArray(primitive) || primitive.length === 0) {
|
|
22
|
-
throw new Error(
|
|
23
|
-
`Unexpected primitive inside pts: ${printSExpr(primitive)}`,
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const parsed = SxClass.parsePrimitiveSexpr(primitive, {
|
|
28
|
-
parentToken: this.token,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
if (parsed instanceof Xy) {
|
|
32
|
-
points.push(parsed)
|
|
33
|
-
continue
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (parsed instanceof SxClass) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Unsupported child "${parsed.token}" inside pts expression`,
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
throw new Error(
|
|
43
|
-
`Unable to parse child inside pts: ${printSExpr(primitive)}`,
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return new Pts(points)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override getChildren(): SxClass[] {
|
|
51
|
-
return [...this.points]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
override getString(): string {
|
|
55
|
-
const lines = ["(pts"]
|
|
56
|
-
for (const point of this.points) {
|
|
57
|
-
const pointString = point.getString()
|
|
58
|
-
const segments = pointString.split("\n")
|
|
59
|
-
for (const segment of segments) {
|
|
60
|
-
lines.push(` ${segment}`)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
lines.push(")")
|
|
64
|
-
return lines.join("\n")
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
SxClass.register(Pts)
|