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.
Files changed (195) hide show
  1. package/dist/index.d.ts +4466 -0
  2. package/dist/index.js +14253 -0
  3. package/package.json +5 -2
  4. package/.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc +0 -111
  5. package/.github/workflows/bun-formatcheck.yml +0 -26
  6. package/.github/workflows/bun-pver-release.yml +0 -70
  7. package/.github/workflows/bun-test.yml +0 -32
  8. package/.github/workflows/bun-typecheck.yml +0 -26
  9. package/.vscode/settings.json +0 -16
  10. package/AGENTS.md +0 -31
  11. package/TODO.md +0 -46
  12. package/biome.json +0 -93
  13. package/bunfig.toml +0 -5
  14. package/lib/index.ts +0 -1
  15. package/lib/sexpr/base-classes/SxClass.ts +0 -164
  16. package/lib/sexpr/base-classes/SxPrimitiveBoolean.ts +0 -35
  17. package/lib/sexpr/base-classes/SxPrimitiveNumber.ts +0 -26
  18. package/lib/sexpr/base-classes/SxPrimitiveString.ts +0 -26
  19. package/lib/sexpr/classes/At.ts +0 -53
  20. package/lib/sexpr/classes/Bus.ts +0 -103
  21. package/lib/sexpr/classes/BusEntry.ts +0 -169
  22. package/lib/sexpr/classes/Color.ts +0 -29
  23. package/lib/sexpr/classes/Dnp.ts +0 -8
  24. package/lib/sexpr/classes/EmbeddedFonts.ts +0 -68
  25. package/lib/sexpr/classes/ExcludeFromSim.ts +0 -8
  26. package/lib/sexpr/classes/FieldsAutoplaced.ts +0 -8
  27. package/lib/sexpr/classes/Footprint.ts +0 -849
  28. package/lib/sexpr/classes/FootprintAttr.ts +0 -104
  29. package/lib/sexpr/classes/FootprintAutoplaceCost180.ts +0 -9
  30. package/lib/sexpr/classes/FootprintAutoplaceCost90.ts +0 -9
  31. package/lib/sexpr/classes/FootprintClearance.ts +0 -9
  32. package/lib/sexpr/classes/FootprintDescr.ts +0 -44
  33. package/lib/sexpr/classes/FootprintLocked.ts +0 -32
  34. package/lib/sexpr/classes/FootprintModel.ts +0 -142
  35. package/lib/sexpr/classes/FootprintNetTiePadGroups.ts +0 -52
  36. package/lib/sexpr/classes/FootprintPad.ts +0 -857
  37. package/lib/sexpr/classes/FootprintPath.ts +0 -44
  38. package/lib/sexpr/classes/FootprintPlaced.ts +0 -32
  39. package/lib/sexpr/classes/FootprintPrivateLayers.ts +0 -56
  40. package/lib/sexpr/classes/FootprintSheetfile.ts +0 -44
  41. package/lib/sexpr/classes/FootprintSheetname.ts +0 -44
  42. package/lib/sexpr/classes/FootprintSolderMaskMargin.ts +0 -9
  43. package/lib/sexpr/classes/FootprintSolderPasteMargin.ts +0 -9
  44. package/lib/sexpr/classes/FootprintSolderPasteRatio.ts +0 -9
  45. package/lib/sexpr/classes/FootprintTags.ts +0 -44
  46. package/lib/sexpr/classes/FootprintTedit.ts +0 -21
  47. package/lib/sexpr/classes/FootprintThermalGap.ts +0 -9
  48. package/lib/sexpr/classes/FootprintThermalWidth.ts +0 -9
  49. package/lib/sexpr/classes/FootprintZoneConnect.ts +0 -9
  50. package/lib/sexpr/classes/FpArc.ts +0 -312
  51. package/lib/sexpr/classes/FpCircle.ts +0 -314
  52. package/lib/sexpr/classes/FpLine.ts +0 -316
  53. package/lib/sexpr/classes/FpPoly.ts +0 -286
  54. package/lib/sexpr/classes/FpPolyFill.ts +0 -48
  55. package/lib/sexpr/classes/FpPolyLocked.ts +0 -40
  56. package/lib/sexpr/classes/FpRect.ts +0 -314
  57. package/lib/sexpr/classes/FpText.ts +0 -375
  58. package/lib/sexpr/classes/FpTextBox.ts +0 -450
  59. package/lib/sexpr/classes/GrLine.ts +0 -264
  60. package/lib/sexpr/classes/GrLineAngle.ts +0 -32
  61. package/lib/sexpr/classes/GrLineEnd.ts +0 -61
  62. package/lib/sexpr/classes/GrLineLocked.ts +0 -40
  63. package/lib/sexpr/classes/GrLineStart.ts +0 -61
  64. package/lib/sexpr/classes/GrText.ts +0 -228
  65. package/lib/sexpr/classes/Image.ts +0 -283
  66. package/lib/sexpr/classes/InBom.ts +0 -8
  67. package/lib/sexpr/classes/Junction.ts +0 -166
  68. package/lib/sexpr/classes/KicadPcb.ts +0 -361
  69. package/lib/sexpr/classes/KicadSch.ts +0 -397
  70. package/lib/sexpr/classes/KicadSchGenerator.ts +0 -32
  71. package/lib/sexpr/classes/KicadSchGeneratorVersion.ts +0 -30
  72. package/lib/sexpr/classes/KicadSchVersion.ts +0 -22
  73. package/lib/sexpr/classes/Label.ts +0 -176
  74. package/lib/sexpr/classes/Layer.ts +0 -51
  75. package/lib/sexpr/classes/Layers.ts +0 -47
  76. package/lib/sexpr/classes/LibSymbols.ts +0 -61
  77. package/lib/sexpr/classes/NoConnect.ts +0 -90
  78. package/lib/sexpr/classes/OnBoard.ts +0 -8
  79. package/lib/sexpr/classes/PadChamfer.ts +0 -50
  80. package/lib/sexpr/classes/PadChamferRatio.ts +0 -9
  81. package/lib/sexpr/classes/PadClearance.ts +0 -9
  82. package/lib/sexpr/classes/PadDieLength.ts +0 -9
  83. package/lib/sexpr/classes/PadDrill.ts +0 -145
  84. package/lib/sexpr/classes/PadDrillOffset.ts +0 -54
  85. package/lib/sexpr/classes/PadLayers.ts +0 -71
  86. package/lib/sexpr/classes/PadNet.ts +0 -56
  87. package/lib/sexpr/classes/PadOptions.ts +0 -181
  88. package/lib/sexpr/classes/PadPinFunction.ts +0 -9
  89. package/lib/sexpr/classes/PadPinType.ts +0 -9
  90. package/lib/sexpr/classes/PadPrimitiveGrArc.ts +0 -272
  91. package/lib/sexpr/classes/PadPrimitiveGrCircle.ts +0 -298
  92. package/lib/sexpr/classes/PadPrimitiveGrLine.ts +0 -126
  93. package/lib/sexpr/classes/PadPrimitives.ts +0 -291
  94. package/lib/sexpr/classes/PadRectDelta.ts +0 -57
  95. package/lib/sexpr/classes/PadRoundrectRratio.ts +0 -9
  96. package/lib/sexpr/classes/PadSize.ts +0 -69
  97. package/lib/sexpr/classes/PadSolderMaskMargin.ts +0 -9
  98. package/lib/sexpr/classes/PadSolderPasteMargin.ts +0 -9
  99. package/lib/sexpr/classes/PadSolderPasteMarginRatio.ts +0 -9
  100. package/lib/sexpr/classes/PadTeardrops.ts +0 -210
  101. package/lib/sexpr/classes/PadThermalBridgeAngle.ts +0 -9
  102. package/lib/sexpr/classes/PadThermalGap.ts +0 -9
  103. package/lib/sexpr/classes/PadThermalWidth.ts +0 -9
  104. package/lib/sexpr/classes/PadZoneConnect.ts +0 -9
  105. package/lib/sexpr/classes/Paper.ts +0 -119
  106. package/lib/sexpr/classes/PcbGeneral.ts +0 -82
  107. package/lib/sexpr/classes/PcbGeneralLegacyTeardrops.ts +0 -44
  108. package/lib/sexpr/classes/PcbGeneralThickness.ts +0 -9
  109. package/lib/sexpr/classes/PcbGenerator.ts +0 -16
  110. package/lib/sexpr/classes/PcbGeneratorVersion.ts +0 -16
  111. package/lib/sexpr/classes/PcbLayerDefinition.ts +0 -106
  112. package/lib/sexpr/classes/PcbLayers.ts +0 -34
  113. package/lib/sexpr/classes/PcbNet.ts +0 -56
  114. package/lib/sexpr/classes/PcbVersion.ts +0 -9
  115. package/lib/sexpr/classes/Property.ts +0 -301
  116. package/lib/sexpr/classes/PropertyHide.ts +0 -9
  117. package/lib/sexpr/classes/PropertyUnlocked.ts +0 -9
  118. package/lib/sexpr/classes/Pts.ts +0 -67
  119. package/lib/sexpr/classes/RenderCache.ts +0 -221
  120. package/lib/sexpr/classes/SchematicText.ts +0 -171
  121. package/lib/sexpr/classes/Segment.ts +0 -243
  122. package/lib/sexpr/classes/SegmentEnd.ts +0 -59
  123. package/lib/sexpr/classes/SegmentLocked.ts +0 -33
  124. package/lib/sexpr/classes/SegmentNet.ts +0 -64
  125. package/lib/sexpr/classes/SegmentStart.ts +0 -59
  126. package/lib/sexpr/classes/Setup/PcbPlotParams.ts +0 -689
  127. package/lib/sexpr/classes/Setup/PcbPlotParamsBase.ts +0 -9
  128. package/lib/sexpr/classes/Setup/PcbPlotParamsNumericProperties.ts +0 -105
  129. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesA.ts +0 -104
  130. package/lib/sexpr/classes/Setup/PcbPlotParamsStringPropertiesB.ts +0 -105
  131. package/lib/sexpr/classes/Setup/Setup.ts +0 -574
  132. package/lib/sexpr/classes/Setup/SetupPropertyTypes.ts +0 -119
  133. package/lib/sexpr/classes/Setup/Stackup.ts +0 -135
  134. package/lib/sexpr/classes/Setup/StackupLayer.ts +0 -233
  135. package/lib/sexpr/classes/Setup/StackupLayerProperties.ts +0 -80
  136. package/lib/sexpr/classes/Setup/StackupProperties.ts +0 -40
  137. package/lib/sexpr/classes/Setup/base.ts +0 -165
  138. package/lib/sexpr/classes/Setup/index.ts +0 -14
  139. package/lib/sexpr/classes/Setup/setupMultiValueProperties.ts +0 -53
  140. package/lib/sexpr/classes/Setup/setupNumericProperties.ts +0 -151
  141. package/lib/sexpr/classes/Setup/setupPropertyHandlers.ts +0 -90
  142. package/lib/sexpr/classes/Setup/setupStringProperties.ts +0 -75
  143. package/lib/sexpr/classes/Sheet.ts +0 -287
  144. package/lib/sexpr/classes/SheetFill.ts +0 -44
  145. package/lib/sexpr/classes/SheetInstances.ts +0 -168
  146. package/lib/sexpr/classes/SheetInstancesRoot.ts +0 -165
  147. package/lib/sexpr/classes/SheetPin.ts +0 -125
  148. package/lib/sexpr/classes/SheetProperty.ts +0 -115
  149. package/lib/sexpr/classes/SheetSize.ts +0 -44
  150. package/lib/sexpr/classes/Stroke.ts +0 -58
  151. package/lib/sexpr/classes/StrokeType.ts +0 -34
  152. package/lib/sexpr/classes/Symbol.ts +0 -1666
  153. package/lib/sexpr/classes/TextEffects.ts +0 -461
  154. package/lib/sexpr/classes/TitleBlock.ts +0 -369
  155. package/lib/sexpr/classes/Unit.ts +0 -28
  156. package/lib/sexpr/classes/Uuid.ts +0 -8
  157. package/lib/sexpr/classes/Via.ts +0 -363
  158. package/lib/sexpr/classes/ViaNet.ts +0 -60
  159. package/lib/sexpr/classes/Width.ts +0 -8
  160. package/lib/sexpr/classes/Wire.ts +0 -111
  161. package/lib/sexpr/classes/Xy.ts +0 -33
  162. package/lib/sexpr/classes/Zone.ts +0 -39
  163. package/lib/sexpr/index.ts +0 -130
  164. package/lib/sexpr/parseKicadSexpr.ts +0 -5
  165. package/lib/sexpr/parseToPrimitiveSExpr.ts +0 -245
  166. package/lib/sexpr/utils/indentLines.ts +0 -3
  167. package/lib/sexpr/utils/parseYesNo.ts +0 -12
  168. package/lib/sexpr/utils/quoteSExprString.ts +0 -8
  169. package/lib/sexpr/utils/strokeFromArgs.ts +0 -18
  170. package/lib/sexpr/utils/toNumberValue.ts +0 -13
  171. package/lib/sexpr/utils/toStringValue.ts +0 -11
  172. package/scripts/download-references.ts +0 -68
  173. package/tests/fixtures/expectEqualPrimitiveSExpr.ts +0 -199
  174. package/tests/fixtures/png-matcher.ts +0 -109
  175. package/tests/fixtures/preload.ts +0 -1
  176. package/tests/sexpr/KicadPcbDemos.test.ts +0 -48
  177. package/tests/sexpr/KicadSchDemos.test.ts +0 -49
  178. package/tests/sexpr/classes/Footprint.test.ts +0 -277
  179. package/tests/sexpr/classes/FootprintPad.test.ts +0 -78
  180. package/tests/sexpr/classes/FpArc.test.ts +0 -45
  181. package/tests/sexpr/classes/FpCircle.test.ts +0 -39
  182. package/tests/sexpr/classes/FpPoly.test.ts +0 -43
  183. package/tests/sexpr/classes/FpRect.test.ts +0 -40
  184. package/tests/sexpr/classes/FpTextBox.test.ts +0 -84
  185. package/tests/sexpr/classes/Image.test.ts +0 -58
  186. package/tests/sexpr/classes/KicadSch.test.ts +0 -95
  187. package/tests/sexpr/classes/Paper.test.ts +0 -30
  188. package/tests/sexpr/classes/Property.test.ts +0 -48
  189. package/tests/sexpr/classes/Setup.test.ts +0 -188
  190. package/tests/sexpr/classes/Sheet.test.ts +0 -107
  191. package/tests/sexpr/classes/Stroke.test.ts +0 -15
  192. package/tests/sexpr/classes/Symbol.test.ts +0 -96
  193. package/tests/sexpr/classes/TextEffects.test.ts +0 -56
  194. package/tests/sexpr/classes/TitleBlock.test.ts +0 -40
  195. package/tsconfig.json +0 -35
@@ -1,35 +0,0 @@
1
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
2
- import { SxClass } from "./SxClass"
3
-
4
- export abstract class SxPrimitiveBoolean extends SxClass {
5
- value: boolean
6
-
7
- constructor(v: boolean) {
8
- super()
9
- this.value = v
10
- }
11
-
12
- set(value: boolean) {
13
- this.value = value
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): SxPrimitiveBoolean {
19
- const [rawVal] = primitiveSexprs
20
- let booleanVal: boolean
21
- if (typeof rawVal === "boolean") {
22
- booleanVal = rawVal
23
- } else if (typeof rawVal === "string") {
24
- booleanVal = rawVal === "true" || rawVal === "yes"
25
- } else {
26
- booleanVal = false
27
- }
28
- // @ts-ignore
29
- return new this(booleanVal)
30
- }
31
-
32
- override getString() {
33
- return `(${this.token} ${this.value ? "yes" : "no"})`
34
- }
35
- }
@@ -1,26 +0,0 @@
1
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
2
- import { SxClass } from "./SxClass"
3
-
4
- export abstract class SxPrimitiveNumber extends SxClass {
5
- value: number
6
-
7
- constructor(v: number) {
8
- super()
9
- this.value = v
10
- }
11
-
12
- set(value: number) {
13
- this.value = value
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): SxPrimitiveNumber {
19
- // @ts-ignore
20
- return new this(primitiveSexprs[0] as number)
21
- }
22
-
23
- override getString() {
24
- return `(${this.token} ${this.value})`
25
- }
26
- }
@@ -1,26 +0,0 @@
1
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
2
- import { SxClass } from "./SxClass"
3
-
4
- export abstract class SxPrimitiveString extends SxClass {
5
- value: string
6
-
7
- constructor(v: string) {
8
- super()
9
- this.value = v
10
- }
11
-
12
- set(value: string) {
13
- this.value = value
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): SxPrimitiveString {
19
- // @ts-ignore
20
- return new this(primitiveSexprs[0] as string)
21
- }
22
-
23
- override getString() {
24
- return `(${this.token} ${this.value})`
25
- }
26
- }
@@ -1,53 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
-
4
- export type AtInput =
5
- | At
6
- | [x: number, y: number, angle?: number]
7
- | { x: number; y: number; angle?: number }
8
-
9
- export class At extends SxClass {
10
- static override token = "at"
11
- token = "at"
12
-
13
- constructor(
14
- args: [x: number, y: number, angle?: number],
15
- opts: { isTextSymbol?: boolean } = {},
16
- ) {
17
- super()
18
- this.x = args[0]
19
- this.y = args[1]
20
- this.angle = args[2]
21
- if (this.angle && opts.isTextSymbol) {
22
- this.angle *= 10
23
- }
24
- }
25
-
26
- x: number
27
- y: number
28
- angle?: number
29
-
30
- static from(input: AtInput, opts: { isTextSymbol?: boolean } = {}): At {
31
- if (input instanceof At) {
32
- return input
33
- }
34
- if (Array.isArray(input)) {
35
- return new At(input, opts)
36
- }
37
- return new At([input.x, input.y, input.angle], opts)
38
- }
39
-
40
- static override fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): At {
41
- const [x, y, angle] = primitiveSexprs
42
- return new At([x as number, y as number, angle as number])
43
- }
44
-
45
- override getString(): string {
46
- const parts: Array<string | number> = [this.x, this.y]
47
- if (this.angle !== undefined) {
48
- parts.push(this.angle)
49
- }
50
- return `(at ${parts.join(" ")})`
51
- }
52
- }
53
- SxClass.register(At)
@@ -1,103 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { Pts } from "./Pts"
4
- import { Stroke } from "./Stroke"
5
- import { Uuid } from "./Uuid"
6
-
7
- const SUPPORTED_TOKENS = new Set(["pts", "stroke", "uuid"])
8
-
9
- export interface BusConstructorParams {
10
- points?: Pts
11
- stroke?: Stroke
12
- uuid?: string | Uuid
13
- }
14
-
15
- export class Bus extends SxClass {
16
- static override token = "bus"
17
- static override parentToken = "kicad_sch"
18
- override token = "bus"
19
-
20
- private _sxPts?: Pts
21
- private _sxStroke?: Stroke
22
- private _sxUuid?: Uuid
23
-
24
- constructor(params: BusConstructorParams = {}) {
25
- super()
26
-
27
- if (params.points !== undefined) {
28
- this.points = params.points
29
- }
30
-
31
- if (params.stroke !== undefined) {
32
- this.stroke = params.stroke
33
- }
34
-
35
- if (params.uuid !== undefined) {
36
- this.uuid = params.uuid
37
- }
38
- }
39
-
40
- static override fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): Bus {
41
- const bus = new Bus()
42
-
43
- const { propertyMap, arrayPropertyMap } =
44
- SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
45
-
46
- if (Object.keys(arrayPropertyMap).length > 0) {
47
- const tokens = Object.keys(arrayPropertyMap).join(", ")
48
- throw new Error(`bus does not support repeated child tokens: ${tokens}`)
49
- }
50
-
51
- const unsupportedTokens = Object.keys(propertyMap).filter(
52
- (token) => !SUPPORTED_TOKENS.has(token),
53
- )
54
- if (unsupportedTokens.length > 0) {
55
- throw new Error(
56
- `Unsupported child tokens inside bus expression: ${unsupportedTokens.join(", ")}`,
57
- )
58
- }
59
-
60
- bus._sxPts = propertyMap.pts as Pts | undefined
61
- bus._sxStroke = propertyMap.stroke as Stroke | undefined
62
- bus._sxUuid = propertyMap.uuid as Uuid | undefined
63
-
64
- return bus
65
- }
66
-
67
- get points(): Pts | undefined {
68
- return this._sxPts
69
- }
70
-
71
- set points(value: Pts | undefined) {
72
- this._sxPts = value
73
- }
74
-
75
- get stroke(): Stroke | undefined {
76
- return this._sxStroke
77
- }
78
-
79
- set stroke(value: Stroke | undefined) {
80
- this._sxStroke = value
81
- }
82
-
83
- get uuid(): Uuid | undefined {
84
- return this._sxUuid
85
- }
86
-
87
- set uuid(value: Uuid | string | undefined) {
88
- if (value === undefined) {
89
- this._sxUuid = undefined
90
- return
91
- }
92
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
93
- }
94
-
95
- override getChildren(): SxClass[] {
96
- const children: SxClass[] = []
97
- if (this._sxPts) children.push(this._sxPts)
98
- if (this._sxStroke) children.push(this._sxStroke)
99
- if (this._sxUuid) children.push(this._sxUuid)
100
- return children
101
- }
102
- }
103
- SxClass.register(Bus)
@@ -1,169 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { At, type AtInput } from "./At"
4
- import { Stroke } from "./Stroke"
5
- import { Uuid } from "./Uuid"
6
-
7
- const SUPPORTED_TOKENS = new Set(["at", "size", "stroke", "uuid"])
8
-
9
- export interface BusEntryConstructorParams {
10
- at?: AtInput
11
- size?: BusEntrySize | { x: number; y: number }
12
- stroke?: Stroke
13
- uuid?: string | Uuid
14
- }
15
-
16
- export class BusEntry extends SxClass {
17
- static override token = "bus_entry"
18
- static override parentToken = "kicad_sch"
19
- override token = "bus_entry"
20
-
21
- private _sxAt?: At
22
- private _sxSize?: BusEntrySize
23
- private _sxStroke?: Stroke
24
- private _sxUuid?: Uuid
25
-
26
- constructor(params: BusEntryConstructorParams = {}) {
27
- super()
28
-
29
- if (params.at !== undefined) {
30
- this.at = params.at
31
- }
32
-
33
- if (params.size !== undefined) {
34
- this.size = params.size
35
- }
36
-
37
- if (params.stroke !== undefined) {
38
- this.stroke = params.stroke
39
- }
40
-
41
- if (params.uuid !== undefined) {
42
- this.uuid = params.uuid
43
- }
44
- }
45
-
46
- static override fromSexprPrimitives(
47
- primitiveSexprs: PrimitiveSExpr[],
48
- ): BusEntry {
49
- const entry = new BusEntry()
50
-
51
- const { propertyMap, arrayPropertyMap } =
52
- SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
53
-
54
- if (Object.keys(arrayPropertyMap).length > 0) {
55
- const tokens = Object.keys(arrayPropertyMap).join(", ")
56
- throw new Error(
57
- `bus_entry does not support repeated child tokens: ${tokens}`,
58
- )
59
- }
60
-
61
- const unsupportedTokens = Object.keys(propertyMap).filter(
62
- (token) => !SUPPORTED_TOKENS.has(token),
63
- )
64
- if (unsupportedTokens.length > 0) {
65
- throw new Error(
66
- `Unsupported child tokens inside bus_entry expression: ${unsupportedTokens.join(", ")}`,
67
- )
68
- }
69
-
70
- entry._sxAt = propertyMap.at as At | undefined
71
- entry._sxSize = propertyMap.size as BusEntrySize | undefined
72
- entry._sxStroke = propertyMap.stroke as Stroke | undefined
73
- entry._sxUuid = propertyMap.uuid as Uuid | undefined
74
-
75
- return entry
76
- }
77
-
78
- get at(): At | undefined {
79
- return this._sxAt
80
- }
81
-
82
- set at(value: AtInput | undefined) {
83
- this._sxAt = value !== undefined ? At.from(value) : undefined
84
- }
85
-
86
- get size(): { x: number; y: number } | undefined {
87
- return this._sxSize?.toObject()
88
- }
89
-
90
- set size(value: BusEntrySize | { x: number; y: number } | undefined) {
91
- if (value === undefined) {
92
- this._sxSize = undefined
93
- return
94
- }
95
- if (value instanceof BusEntrySize) {
96
- this._sxSize = value
97
- return
98
- }
99
- this._sxSize = new BusEntrySize(value.x, value.y)
100
- }
101
-
102
- get stroke(): Stroke | undefined {
103
- return this._sxStroke
104
- }
105
-
106
- set stroke(value: Stroke | undefined) {
107
- this._sxStroke = value
108
- }
109
-
110
- get uuid(): Uuid | undefined {
111
- return this._sxUuid
112
- }
113
-
114
- set uuid(value: Uuid | string | undefined) {
115
- if (value === undefined) {
116
- this._sxUuid = undefined
117
- return
118
- }
119
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
120
- }
121
-
122
- override getChildren(): SxClass[] {
123
- const children: SxClass[] = []
124
- if (this._sxAt) children.push(this._sxAt)
125
- if (this._sxSize) children.push(this._sxSize)
126
- if (this._sxStroke) children.push(this._sxStroke)
127
- if (this._sxUuid) children.push(this._sxUuid)
128
- return children
129
- }
130
- }
131
- SxClass.register(BusEntry)
132
-
133
- export class BusEntrySize extends SxClass {
134
- static override token = "size"
135
- static override parentToken = "bus_entry"
136
- override token = "size"
137
-
138
- private _x: number
139
- private _y: number
140
-
141
- constructor(x: number, y: number) {
142
- super()
143
- this._x = x
144
- this._y = y
145
- }
146
-
147
- static override fromSexprPrimitives(
148
- primitiveSexprs: PrimitiveSExpr[],
149
- ): BusEntrySize {
150
- const [rawX, rawY] = primitiveSexprs
151
- if (typeof rawX !== "number" || typeof rawY !== "number") {
152
- throw new Error("bus_entry size expects two numeric arguments")
153
- }
154
- return new BusEntrySize(rawX, rawY)
155
- }
156
-
157
- toObject(): { x: number; y: number } {
158
- return { x: this._x, y: this._y }
159
- }
160
-
161
- override getChildren(): SxClass[] {
162
- return []
163
- }
164
-
165
- override getString(): string {
166
- return `(size ${this._x} ${this._y})`
167
- }
168
- }
169
- SxClass.register(BusEntrySize)
@@ -1,29 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
-
4
- export type RGBAColor = { r: number; g: number; b: number; a: number }
5
-
6
- export class Color extends SxClass {
7
- static override token = "color"
8
- token = "color"
9
-
10
- color: RGBAColor
11
-
12
- constructor(args: [r: number, g: number, b: number, a: number]) {
13
- super()
14
- this.color = { r: args[0], g: args[1], b: args[2], a: args[3] }
15
- }
16
-
17
- static override fromSexprPrimitives(
18
- primitiveSexprs: PrimitiveSExpr[],
19
- ): Color {
20
- return new Color(
21
- primitiveSexprs as [r: number, g: number, b: number, a: number],
22
- )
23
- }
24
-
25
- override getString() {
26
- return `(color ${this.color.r} ${this.color.g} ${this.color.b} ${this.color.a})`
27
- }
28
- }
29
- SxClass.register(Color)
@@ -1,8 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
-
4
- export class Dnp extends SxPrimitiveBoolean {
5
- static override token = "dnp"
6
- token = "dnp"
7
- }
8
- SxClass.register(Dnp)
@@ -1,68 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
-
4
- export class EmbeddedFonts extends SxClass {
5
- static override token = "embedded_fonts"
6
- override token = "embedded_fonts"
7
-
8
- private _enabled = false
9
-
10
- constructor(enabled = false) {
11
- super()
12
- this._enabled = enabled
13
- }
14
-
15
- static override fromSexprPrimitives(
16
- primitiveSexprs: PrimitiveSExpr[],
17
- ): EmbeddedFonts {
18
- if (primitiveSexprs.length === 0) {
19
- return new EmbeddedFonts(false)
20
- }
21
-
22
- if (primitiveSexprs.length > 1) {
23
- throw new Error("embedded_fonts accepts at most a single value")
24
- }
25
-
26
- const [raw] = primitiveSexprs
27
-
28
- if (raw === undefined) {
29
- return new EmbeddedFonts(false)
30
- }
31
-
32
- if (typeof raw === "boolean") {
33
- return new EmbeddedFonts(raw)
34
- }
35
-
36
- if (typeof raw === "string") {
37
- const normalized = raw.toLowerCase()
38
- if (normalized === "yes") {
39
- return new EmbeddedFonts(true)
40
- }
41
- if (normalized === "no") {
42
- return new EmbeddedFonts(false)
43
- }
44
- throw new Error(`embedded_fonts expects "yes" or "no", received "${raw}"`)
45
- }
46
-
47
- throw new Error(
48
- `embedded_fonts encountered unsupported value ${JSON.stringify(raw)}`,
49
- )
50
- }
51
-
52
- get enabled(): boolean {
53
- return this._enabled
54
- }
55
-
56
- set enabled(value: boolean) {
57
- this._enabled = value
58
- }
59
-
60
- override getChildren(): SxClass[] {
61
- return []
62
- }
63
-
64
- override getString(): string {
65
- return `(embedded_fonts ${this._enabled ? "yes" : "no"})`
66
- }
67
- }
68
- SxClass.register(EmbeddedFonts)
@@ -1,8 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
-
4
- export class ExcludeFromSim extends SxPrimitiveBoolean {
5
- static override token = "exclude_from_sim"
6
- token = "exclude_from_sim"
7
- }
8
- SxClass.register(ExcludeFromSim)
@@ -1,8 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
-
4
- export class FieldsAutoplaced extends SxPrimitiveBoolean {
5
- static override token = "fields_autoplaced"
6
- token = "fields_autoplaced"
7
- }
8
- SxClass.register(FieldsAutoplaced)