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,397 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { Image } from "./Image"
4
- import { KicadSchGenerator } from "./KicadSchGenerator"
5
- import { KicadSchGeneratorVersion } from "./KicadSchGeneratorVersion"
6
- import { KicadSchVersion } from "./KicadSchVersion"
7
- import { LibSymbols } from "./LibSymbols"
8
- import { Paper } from "./Paper"
9
- import { Property } from "./Property"
10
- import { Label } from "./Label"
11
- import { SchematicSymbol } from "./Symbol"
12
- import { SchematicText } from "./SchematicText"
13
- import { Sheet } from "./Sheet"
14
- import { EmbeddedFonts } from "./EmbeddedFonts"
15
- import { SheetInstances } from "./SheetInstances"
16
- import { TitleBlock } from "./TitleBlock"
17
- import { Uuid } from "./Uuid"
18
- import { Wire } from "./Wire"
19
- import { Junction } from "./Junction"
20
-
21
- const SINGLE_CHILD_TOKENS = new Set([
22
- "version",
23
- "generator",
24
- "generator_version",
25
- "uuid",
26
- "paper",
27
- "title_block",
28
- "lib_symbols",
29
- "sheet_instances",
30
- "embedded_fonts",
31
- ])
32
-
33
- const MULTI_CHILD_TOKENS = new Set([
34
- "property",
35
- "image",
36
- "sheet",
37
- "symbol",
38
- "text",
39
- "label",
40
- "junction",
41
- "wire",
42
- ])
43
-
44
- const SUPPORTED_CHILD_TOKENS = new Set([
45
- ...SINGLE_CHILD_TOKENS,
46
- ...MULTI_CHILD_TOKENS,
47
- ])
48
-
49
- export interface KicadSchConstructorParams {
50
- version?: number | KicadSchVersion
51
- generator?: string | KicadSchGenerator
52
- generatorVersion?: string | KicadSchGeneratorVersion
53
- uuid?: string | Uuid
54
- paper?: Paper
55
- titleBlock?: TitleBlock
56
- libSymbols?: LibSymbols
57
- sheetInstances?: SheetInstances
58
- embeddedFonts?: EmbeddedFonts
59
- properties?: Property[]
60
- images?: Image[]
61
- sheets?: Sheet[]
62
- symbols?: SchematicSymbol[]
63
- texts?: SchematicText[]
64
- labels?: Label[]
65
- wires?: Wire[]
66
- junctions?: Junction[]
67
- }
68
-
69
- export class KicadSch extends SxClass {
70
- static override token = "kicad_sch"
71
- token = "kicad_sch"
72
-
73
- private _sxVersion?: KicadSchVersion
74
- private _sxGenerator?: KicadSchGenerator
75
- private _sxGeneratorVersion?: KicadSchGeneratorVersion
76
- private _sxUuid?: Uuid
77
- private _sxPaper?: Paper
78
- private _sxTitleBlock?: TitleBlock
79
- private _sxLibSymbols?: LibSymbols
80
- private _sxSheetInstances?: SheetInstances
81
- private _sxEmbeddedFonts?: EmbeddedFonts
82
- private _properties: Property[] = []
83
- private _images: Image[] = []
84
- private _sheets: Sheet[] = []
85
- private _symbols: SchematicSymbol[] = []
86
- private _texts: SchematicText[] = []
87
- private _labels: Label[] = []
88
- private _wires: Wire[] = []
89
- private _junctions: Junction[] = []
90
-
91
- constructor(params: KicadSchConstructorParams = {}) {
92
- super()
93
-
94
- if (params.version instanceof KicadSchVersion) {
95
- this._sxVersion = params.version
96
- } else if (params.version !== undefined) {
97
- this.version = params.version
98
- }
99
-
100
- if (params.generator instanceof KicadSchGenerator) {
101
- this._sxGenerator = params.generator
102
- } else if (params.generator !== undefined) {
103
- this.generator = params.generator
104
- }
105
-
106
- if (params.generatorVersion instanceof KicadSchGeneratorVersion) {
107
- this._sxGeneratorVersion = params.generatorVersion
108
- } else if (params.generatorVersion !== undefined) {
109
- this.generatorVersion = params.generatorVersion
110
- }
111
-
112
- if (params.uuid !== undefined) {
113
- this.uuid = params.uuid
114
- }
115
-
116
- if (params.paper !== undefined) {
117
- this.paper = params.paper
118
- }
119
-
120
- if (params.titleBlock !== undefined) {
121
- this.titleBlock = params.titleBlock
122
- }
123
-
124
- if (params.libSymbols !== undefined) {
125
- this.libSymbols = params.libSymbols
126
- }
127
-
128
- if (params.sheetInstances !== undefined) {
129
- this.sheetInstances = params.sheetInstances
130
- }
131
-
132
- if (params.embeddedFonts !== undefined) {
133
- this.embeddedFonts = params.embeddedFonts
134
- }
135
-
136
- if (params.properties !== undefined) {
137
- this.properties = params.properties
138
- }
139
-
140
- if (params.images !== undefined) {
141
- this.images = params.images
142
- }
143
-
144
- if (params.sheets !== undefined) {
145
- this.sheets = params.sheets
146
- }
147
-
148
- if (params.symbols !== undefined) {
149
- this.symbols = params.symbols
150
- }
151
-
152
- if (params.texts !== undefined) {
153
- this.texts = params.texts
154
- }
155
-
156
- if (params.labels !== undefined) {
157
- this.labels = params.labels
158
- }
159
-
160
- if (params.wires !== undefined) {
161
- this.wires = params.wires
162
- }
163
-
164
- if (params.junctions !== undefined) {
165
- this.junctions = params.junctions
166
- }
167
- }
168
-
169
- static override fromSexprPrimitives(
170
- primitiveSexprs: PrimitiveSExpr[],
171
- ): KicadSch {
172
- for (const primitive of primitiveSexprs) {
173
- if (!Array.isArray(primitive)) {
174
- throw new Error(
175
- `kicad_sch encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
176
- )
177
- }
178
- if (primitive.length === 0 || typeof primitive[0] !== "string") {
179
- throw new Error(
180
- `kicad_sch encountered invalid child expression: ${JSON.stringify(primitive)}`,
181
- )
182
- }
183
- }
184
-
185
- const { propertyMap, arrayPropertyMap } =
186
- SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
187
-
188
- for (const token of Object.keys(propertyMap)) {
189
- if (!SUPPORTED_CHILD_TOKENS.has(token)) {
190
- throw new Error(
191
- `kicad_sch encountered unsupported child token "${token}"`,
192
- )
193
- }
194
- }
195
-
196
- for (const [token, entries] of Object.entries(arrayPropertyMap)) {
197
- if (!SUPPORTED_CHILD_TOKENS.has(token)) {
198
- throw new Error(
199
- `kicad_sch encountered unsupported child token "${token}"`,
200
- )
201
- }
202
- if (!MULTI_CHILD_TOKENS.has(token) && entries.length > 1) {
203
- throw new Error(
204
- `kicad_sch does not support repeated child token "${token}"`,
205
- )
206
- }
207
- }
208
-
209
- return new KicadSch({
210
- version: propertyMap.version as KicadSchVersion | undefined,
211
- generator: propertyMap.generator as KicadSchGenerator | undefined,
212
- generatorVersion: propertyMap.generator_version as
213
- | KicadSchGeneratorVersion
214
- | undefined,
215
- uuid: propertyMap.uuid as Uuid | undefined,
216
- paper: propertyMap.paper as Paper | undefined,
217
- titleBlock: propertyMap.title_block as TitleBlock | undefined,
218
- libSymbols: propertyMap.lib_symbols as LibSymbols | undefined,
219
- sheetInstances: propertyMap.sheet_instances as SheetInstances | undefined,
220
- embeddedFonts: propertyMap.embedded_fonts as EmbeddedFonts | undefined,
221
- properties: (arrayPropertyMap.property as Property[]) ?? [],
222
- images: (arrayPropertyMap.image as Image[]) ?? [],
223
- sheets: (arrayPropertyMap.sheet as Sheet[]) ?? [],
224
- symbols: (arrayPropertyMap.symbol as SchematicSymbol[]) ?? [],
225
- texts: (arrayPropertyMap.text as SchematicText[]) ?? [],
226
- labels: (arrayPropertyMap.label as Label[]) ?? [],
227
- junctions: (arrayPropertyMap.junction as Junction[]) ?? [],
228
- wires: (arrayPropertyMap.wire as Wire[]) ?? [],
229
- })
230
- }
231
-
232
- get version(): number | undefined {
233
- return this._sxVersion?.value
234
- }
235
-
236
- set version(value: number | undefined) {
237
- this._sxVersion =
238
- value === undefined ? undefined : new KicadSchVersion(value)
239
- }
240
-
241
- get generator(): string | undefined {
242
- return this._sxGenerator?.value
243
- }
244
-
245
- set generator(value: string | undefined) {
246
- this._sxGenerator =
247
- value === undefined ? undefined : new KicadSchGenerator(value)
248
- }
249
-
250
- get generatorVersion(): string | undefined {
251
- return this._sxGeneratorVersion?.value
252
- }
253
-
254
- set generatorVersion(value: string | undefined) {
255
- this._sxGeneratorVersion =
256
- value === undefined ? undefined : new KicadSchGeneratorVersion(value)
257
- }
258
-
259
- get uuid(): Uuid | undefined {
260
- return this._sxUuid
261
- }
262
-
263
- set uuid(value: Uuid | string | undefined) {
264
- if (value === undefined) {
265
- this._sxUuid = undefined
266
- return
267
- }
268
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
269
- }
270
-
271
- get paper(): Paper | undefined {
272
- return this._sxPaper
273
- }
274
-
275
- set paper(value: Paper | undefined) {
276
- this._sxPaper = value
277
- }
278
-
279
- get titleBlock(): TitleBlock | undefined {
280
- return this._sxTitleBlock
281
- }
282
-
283
- set titleBlock(value: TitleBlock | undefined) {
284
- this._sxTitleBlock = value
285
- }
286
-
287
- get libSymbols(): LibSymbols | undefined {
288
- return this._sxLibSymbols
289
- }
290
-
291
- set libSymbols(value: LibSymbols | undefined) {
292
- this._sxLibSymbols = value
293
- }
294
-
295
- get sheetInstances(): SheetInstances | undefined {
296
- return this._sxSheetInstances
297
- }
298
-
299
- set sheetInstances(value: SheetInstances | undefined) {
300
- this._sxSheetInstances = value
301
- }
302
-
303
- get embeddedFonts(): EmbeddedFonts | undefined {
304
- return this._sxEmbeddedFonts
305
- }
306
-
307
- set embeddedFonts(value: EmbeddedFonts | undefined) {
308
- this._sxEmbeddedFonts = value
309
- }
310
-
311
- get properties(): Property[] {
312
- return [...this._properties]
313
- }
314
-
315
- set properties(value: Property[]) {
316
- this._properties = [...value]
317
- }
318
-
319
- get images(): Image[] {
320
- return [...this._images]
321
- }
322
-
323
- set images(value: Image[]) {
324
- this._images = [...value]
325
- }
326
-
327
- get sheets(): Sheet[] {
328
- return [...this._sheets]
329
- }
330
-
331
- set sheets(value: Sheet[]) {
332
- this._sheets = [...value]
333
- }
334
-
335
- get symbols(): SchematicSymbol[] {
336
- return [...this._symbols]
337
- }
338
-
339
- set symbols(value: SchematicSymbol[]) {
340
- this._symbols = [...value]
341
- }
342
-
343
- get texts(): SchematicText[] {
344
- return [...this._texts]
345
- }
346
-
347
- set texts(value: SchematicText[]) {
348
- this._texts = [...value]
349
- }
350
-
351
- get labels(): Label[] {
352
- return [...this._labels]
353
- }
354
-
355
- set labels(value: Label[]) {
356
- this._labels = [...value]
357
- }
358
-
359
- get junctions(): Junction[] {
360
- return [...this._junctions]
361
- }
362
-
363
- set junctions(value: Junction[]) {
364
- this._junctions = [...value]
365
- }
366
-
367
- get wires(): Wire[] {
368
- return [...this._wires]
369
- }
370
-
371
- set wires(value: Wire[]) {
372
- this._wires = [...value]
373
- }
374
-
375
- override getChildren(): SxClass[] {
376
- const children: SxClass[] = []
377
- if (this._sxVersion) children.push(this._sxVersion)
378
- if (this._sxGenerator) children.push(this._sxGenerator)
379
- if (this._sxGeneratorVersion) children.push(this._sxGeneratorVersion)
380
- if (this._sxUuid) children.push(this._sxUuid)
381
- if (this._sxPaper) children.push(this._sxPaper)
382
- if (this._sxTitleBlock) children.push(this._sxTitleBlock)
383
- if (this._sxLibSymbols) children.push(this._sxLibSymbols)
384
- if (this._sxSheetInstances) children.push(this._sxSheetInstances)
385
- if (this._sxEmbeddedFonts) children.push(this._sxEmbeddedFonts)
386
- children.push(...this._properties)
387
- children.push(...this._images)
388
- children.push(...this._sheets)
389
- children.push(...this._symbols)
390
- children.push(...this._texts)
391
- children.push(...this._labels)
392
- children.push(...this._junctions)
393
- children.push(...this._wires)
394
- return children
395
- }
396
- }
397
- SxClass.register(KicadSch)
@@ -1,32 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
3
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
4
- import { quoteSExprString } from "../utils/quoteSExprString"
5
- import { toStringValue } from "../utils/toStringValue"
6
-
7
- const isSymbolToken = (value: string) => /^[A-Za-z0-9._-]+$/.test(value)
8
-
9
- export class KicadSchGenerator extends SxPrimitiveString {
10
- static override token = "generator"
11
- static override parentToken = "kicad_sch"
12
- override token = "generator"
13
-
14
- static override fromSexprPrimitives(
15
- primitiveSexprs: PrimitiveSExpr[],
16
- ): KicadSchGenerator {
17
- const [rawValue] = primitiveSexprs
18
- const parsedValue = toStringValue(rawValue)
19
- if (parsedValue === undefined) {
20
- throw new Error("generator expects a string argument")
21
- }
22
- return new KicadSchGenerator(parsedValue)
23
- }
24
-
25
- override getString(): string {
26
- const serialized = isSymbolToken(this.value)
27
- ? this.value
28
- : quoteSExprString(this.value)
29
- return `(generator ${serialized})`
30
- }
31
- }
32
- SxClass.register(KicadSchGenerator)
@@ -1,30 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
3
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
4
- import { quoteSExprString } from "../utils/quoteSExprString"
5
- import { toStringValue } from "../utils/toStringValue"
6
-
7
- export class KicadSchGeneratorVersion extends SxPrimitiveString {
8
- static override token = "generator_version"
9
- static override parentToken = "kicad_sch"
10
- override token = "generator_version"
11
-
12
- static override fromSexprPrimitives(
13
- primitiveSexprs: PrimitiveSExpr[],
14
- ): KicadSchGeneratorVersion {
15
- const [rawValue] = primitiveSexprs
16
- const parsedValue = toStringValue(rawValue)
17
- if (parsedValue === undefined) {
18
- throw new Error("generator_version expects a string argument")
19
- }
20
- return new KicadSchGeneratorVersion(parsedValue)
21
- }
22
-
23
- override getString(): string {
24
- const serialized = /^[^\s()\"]+$/.test(this.value)
25
- ? this.value
26
- : quoteSExprString(this.value)
27
- return `(generator_version ${serialized})`
28
- }
29
- }
30
- SxClass.register(KicadSchGeneratorVersion)
@@ -1,22 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
3
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
4
- import { toNumberValue } from "../utils/toNumberValue"
5
-
6
- export class KicadSchVersion extends SxPrimitiveNumber {
7
- static override token = "version"
8
- static override parentToken = "kicad_sch"
9
- override token = "version"
10
-
11
- static override fromSexprPrimitives(
12
- primitiveSexprs: PrimitiveSExpr[],
13
- ): KicadSchVersion {
14
- const [rawValue] = primitiveSexprs
15
- const parsedValue = toNumberValue(rawValue)
16
- if (parsedValue === undefined) {
17
- throw new Error("version expects a numeric argument")
18
- }
19
- return new KicadSchVersion(parsedValue)
20
- }
21
- }
22
- SxClass.register(KicadSchVersion)
@@ -1,176 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
- import { toStringValue } from "../utils/toStringValue"
5
- import { At, type AtInput } from "./At"
6
- import { TextEffects } from "./TextEffects"
7
- import { Uuid } from "./Uuid"
8
- import { FieldsAutoplaced } from "./FieldsAutoplaced"
9
-
10
- const SUPPORTED_TOKENS = new Set(["at", "effects", "uuid", "fields_autoplaced"])
11
-
12
- export interface LabelConstructorParams {
13
- value?: string
14
- at?: AtInput
15
- effects?: TextEffects
16
- uuid?: string | Uuid
17
- fieldsAutoplaced?: boolean | FieldsAutoplaced
18
- }
19
-
20
- export class Label extends SxClass {
21
- static override token = "label"
22
- static override parentToken = "kicad_sch"
23
- override token = "label"
24
-
25
- private _value = ""
26
- private _sxAt?: At
27
- private _sxEffects?: TextEffects
28
- private _sxUuid?: Uuid
29
- private _sxFieldsAutoplaced?: FieldsAutoplaced
30
-
31
- constructor(params: LabelConstructorParams = {}) {
32
- super()
33
-
34
- if (params.value !== undefined) {
35
- this.value = params.value
36
- }
37
-
38
- if (params.at !== undefined) {
39
- this.at = params.at
40
- }
41
-
42
- if (params.effects !== undefined) {
43
- this.effects = params.effects
44
- }
45
-
46
- if (params.uuid !== undefined) {
47
- this.uuid = params.uuid
48
- }
49
-
50
- if (params.fieldsAutoplaced !== undefined) {
51
- if (params.fieldsAutoplaced instanceof FieldsAutoplaced) {
52
- this._sxFieldsAutoplaced = params.fieldsAutoplaced
53
- } else {
54
- this.fieldsAutoplaced = params.fieldsAutoplaced
55
- }
56
- }
57
- }
58
-
59
- static override fromSexprPrimitives(
60
- primitiveSexprs: PrimitiveSExpr[],
61
- ): Label {
62
- const [textPrimitive, ...rest] = primitiveSexprs
63
- const value = toStringValue(textPrimitive)
64
- if (value === undefined) {
65
- throw new Error("label expects a string value")
66
- }
67
-
68
- const label = new Label()
69
- label._value = value
70
-
71
- const { propertyMap, arrayPropertyMap } =
72
- SxClass.parsePrimitivesToClassProperties(rest, this.token)
73
-
74
- const unsupportedTokens = Object.keys(propertyMap).filter(
75
- (token) => !SUPPORTED_TOKENS.has(token),
76
- )
77
- if (unsupportedTokens.length > 0) {
78
- throw new Error(
79
- `Unsupported child tokens inside label expression: ${unsupportedTokens.join(", ")}`,
80
- )
81
- }
82
-
83
- for (const [token, entries] of Object.entries(arrayPropertyMap)) {
84
- if (!SUPPORTED_TOKENS.has(token)) {
85
- throw new Error(
86
- `Unsupported child tokens inside label expression: ${token}`,
87
- )
88
- }
89
- if (entries.length > 1) {
90
- throw new Error(
91
- `label does not support repeated child tokens: ${token}`,
92
- )
93
- }
94
- }
95
-
96
- label._sxAt =
97
- (arrayPropertyMap.at?.[0] as At | undefined) ??
98
- (propertyMap.at as At | undefined)
99
- label._sxEffects =
100
- (arrayPropertyMap.effects?.[0] as TextEffects | undefined) ??
101
- (propertyMap.effects as TextEffects | undefined)
102
- label._sxUuid =
103
- (arrayPropertyMap.uuid?.[0] as Uuid | undefined) ??
104
- (propertyMap.uuid as Uuid | undefined)
105
- label._sxFieldsAutoplaced =
106
- (arrayPropertyMap.fields_autoplaced?.[0] as
107
- | FieldsAutoplaced
108
- | undefined) ??
109
- (propertyMap.fields_autoplaced as FieldsAutoplaced | undefined)
110
-
111
- return label
112
- }
113
-
114
- get value(): string {
115
- return this._value
116
- }
117
-
118
- set value(newValue: string) {
119
- this._value = newValue
120
- }
121
-
122
- get at(): At | undefined {
123
- return this._sxAt
124
- }
125
-
126
- set at(value: AtInput | undefined) {
127
- this._sxAt = value !== undefined ? At.from(value) : undefined
128
- }
129
-
130
- get effects(): TextEffects | undefined {
131
- return this._sxEffects
132
- }
133
-
134
- set effects(value: TextEffects | undefined) {
135
- this._sxEffects = value
136
- }
137
-
138
- get uuid(): Uuid | undefined {
139
- return this._sxUuid
140
- }
141
-
142
- set uuid(value: Uuid | string | undefined) {
143
- if (value === undefined) {
144
- this._sxUuid = undefined
145
- return
146
- }
147
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
148
- }
149
-
150
- get fieldsAutoplaced(): boolean {
151
- return this._sxFieldsAutoplaced?.value ?? false
152
- }
153
-
154
- set fieldsAutoplaced(value: boolean) {
155
- this._sxFieldsAutoplaced = new FieldsAutoplaced(value)
156
- }
157
-
158
- override getChildren(): SxClass[] {
159
- const children: SxClass[] = []
160
- if (this._sxAt) children.push(this._sxAt)
161
- if (this._sxEffects) children.push(this._sxEffects)
162
- if (this._sxUuid) children.push(this._sxUuid)
163
- if (this._sxFieldsAutoplaced) children.push(this._sxFieldsAutoplaced)
164
- return children
165
- }
166
-
167
- override getString(): string {
168
- const lines = [`(label ${quoteSExprString(this._value)}`]
169
- for (const child of this.getChildren()) {
170
- lines.push(child.getStringIndented())
171
- }
172
- lines.push(")")
173
- return lines.join("\n")
174
- }
175
- }
176
- SxClass.register(Label)
@@ -1,51 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { printSExpr, type PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
-
5
- export class Layer extends SxClass {
6
- static override token = "layer"
7
- token = "layer"
8
-
9
- private _names: string[] = []
10
-
11
- constructor(names: Array<string | number> = []) {
12
- super()
13
- this.names = names.map((name) => String(name))
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): Layer {
19
- const names = primitiveSexprs.map((primitive) =>
20
- typeof primitive === "string" || typeof primitive === "number"
21
- ? String(primitive)
22
- : printSExpr(primitive),
23
- )
24
- return new Layer(names)
25
- }
26
-
27
- get names(): string[] {
28
- return [...this._names]
29
- }
30
-
31
- set names(values: Array<string | number>) {
32
- this._names = values.map((value) => String(value))
33
- }
34
-
35
- addName(name: string | number) {
36
- this._names.push(String(name))
37
- }
38
-
39
- override getString(): string {
40
- const rendered = this._names
41
- .map((name) => {
42
- if (/^[^\s()"]+$/u.test(name) && !["nil", "#t", "#f"].includes(name)) {
43
- return name
44
- }
45
- return quoteSExprString(name)
46
- })
47
- .join(" ")
48
- return `(layer ${rendered})`
49
- }
50
- }
51
- SxClass.register(Layer)