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,286 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { Layer } from "./Layer"
4
- import { Stroke } from "./Stroke"
5
- import { Uuid } from "./Uuid"
6
- import { Width } from "./Width"
7
- import { Pts } from "./Pts"
8
- import { Xy } from "./Xy"
9
- import { FpPolyFill } from "./FpPolyFill"
10
- import { FpPolyLocked } from "./FpPolyLocked"
11
-
12
- const SUPPORTED_TOKENS = new Set([
13
- "pts",
14
- "xy",
15
- "layer",
16
- "width",
17
- "stroke",
18
- "fill",
19
- "locked",
20
- "uuid",
21
- ])
22
-
23
- export interface FpPolyConstructorParams {
24
- points?: Pts | Xy[] | Array<{ x: number; y: number }>
25
- layer?: Layer | string | Array<string | number>
26
- width?: Width | number
27
- stroke?: Stroke
28
- fill?: FpPolyFill | boolean
29
- locked?: boolean
30
- uuid?: Uuid | string
31
- }
32
-
33
- export class FpPoly extends SxClass {
34
- static override token = "fp_poly"
35
- override token = "fp_poly"
36
-
37
- private _sxPts?: Pts
38
- private _sxLayer?: Layer
39
- private _sxWidth?: Width
40
- private _sxStroke?: Stroke
41
- private _sxFill?: FpPolyFill
42
- private _sxLocked?: FpPolyLocked
43
- private _sxUuid?: Uuid
44
-
45
- constructor(params: FpPolyConstructorParams = {}) {
46
- super()
47
- if (params.points !== undefined) this.points = params.points
48
- if (params.layer !== undefined) this.layer = params.layer
49
- if (params.width !== undefined) this.width = params.width
50
- if (params.stroke !== undefined) this.stroke = params.stroke
51
- if (params.fill !== undefined) this.fill = params.fill
52
- if (params.locked !== undefined) this.locked = params.locked
53
- if (params.uuid !== undefined) this.uuid = params.uuid
54
- }
55
-
56
- static override fromSexprPrimitives(
57
- primitiveSexprs: PrimitiveSExpr[],
58
- ): FpPoly {
59
- const fpPoly = new FpPoly()
60
-
61
- const { propertyMap, arrayPropertyMap } =
62
- SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
63
-
64
- const unexpectedTokens = new Set<string>()
65
- for (const token of Object.keys(propertyMap)) {
66
- if (!SUPPORTED_TOKENS.has(token)) {
67
- unexpectedTokens.add(token)
68
- }
69
- }
70
- for (const token of Object.keys(arrayPropertyMap)) {
71
- if (!SUPPORTED_TOKENS.has(token)) {
72
- unexpectedTokens.add(token)
73
- }
74
- if (token !== "xy" && arrayPropertyMap[token]!.length > 1) {
75
- unexpectedTokens.add(token)
76
- }
77
- }
78
-
79
- if (unexpectedTokens.size > 0) {
80
- throw new Error(
81
- `Unsupported child tokens inside fp_poly expression: ${[...unexpectedTokens].join(", ")}`,
82
- )
83
- }
84
-
85
- const ptsEntries = arrayPropertyMap.pts as Pts[] | undefined
86
- if (ptsEntries && ptsEntries.length > 1) {
87
- throw new Error("fp_poly does not support repeated pts tokens")
88
- }
89
-
90
- const xyEntries = arrayPropertyMap.xy as Xy[] | undefined
91
- let pts = propertyMap.pts as Pts | undefined
92
-
93
- if (pts && xyEntries && xyEntries.length > 0) {
94
- throw new Error("fp_poly cannot mix pts and xy child tokens")
95
- }
96
-
97
- if (!pts && ptsEntries?.length) {
98
- pts = ptsEntries[0]
99
- }
100
-
101
- if (!pts && xyEntries && xyEntries.length > 0) {
102
- pts = new Pts(xyEntries)
103
- }
104
-
105
- fpPoly._sxPts = pts
106
- fpPoly._sxLayer = propertyMap.layer as Layer | undefined
107
- fpPoly._sxWidth = propertyMap.width as Width | undefined
108
- fpPoly._sxStroke = propertyMap.stroke as Stroke | undefined
109
- fpPoly._sxFill = propertyMap.fill as FpPolyFill | undefined
110
- const lockedClass = propertyMap.locked as FpPolyLocked | undefined
111
- fpPoly._sxLocked =
112
- lockedClass && lockedClass.value ? lockedClass : undefined
113
- fpPoly._sxUuid = propertyMap.uuid as Uuid | undefined
114
-
115
- for (const primitive of primitiveSexprs) {
116
- if (primitive === "locked") {
117
- if (!fpPoly._sxLocked) {
118
- fpPoly._sxLocked = new FpPolyLocked(true)
119
- }
120
- continue
121
- }
122
-
123
- if (!Array.isArray(primitive) || primitive.length === 0) {
124
- throw new Error(
125
- `fp_poly encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
126
- )
127
- }
128
-
129
- const [token, ...rest] = primitive
130
- if (typeof token !== "string") {
131
- throw new Error(
132
- `fp_poly child token must be a string, received: ${JSON.stringify(token)}`,
133
- )
134
- }
135
-
136
- if (!SUPPORTED_TOKENS.has(token)) {
137
- throw new Error(
138
- `Unsupported child token inside fp_poly expression: ${token}`,
139
- )
140
- }
141
-
142
- if (token === "locked" && !fpPoly._sxLocked) {
143
- fpPoly._sxLocked = FpPolyLocked.fromSexprPrimitives(
144
- rest as PrimitiveSExpr[],
145
- )
146
- if (!fpPoly._sxLocked.value) {
147
- fpPoly._sxLocked = undefined
148
- }
149
- }
150
- }
151
-
152
- if (!fpPoly._sxPts) {
153
- throw new Error("fp_poly requires pts or xy child tokens")
154
- }
155
- if (!fpPoly._sxLayer) {
156
- throw new Error("fp_poly requires a layer child token")
157
- }
158
- if (!fpPoly._sxUuid) {
159
- throw new Error("fp_poly requires a uuid child token")
160
- }
161
-
162
- return fpPoly
163
- }
164
-
165
- get points(): Pts | undefined {
166
- return this._sxPts
167
- }
168
-
169
- set points(value: Pts | Xy[] | Array<{ x: number; y: number }> | undefined) {
170
- if (value === undefined) {
171
- this._sxPts = undefined
172
- return
173
- }
174
-
175
- if (value instanceof Pts) {
176
- this._sxPts = value
177
- return
178
- }
179
-
180
- if (Array.isArray(value) && value.every((point) => point instanceof Xy)) {
181
- this._sxPts = new Pts(value as Xy[])
182
- return
183
- }
184
-
185
- if (Array.isArray(value)) {
186
- this._sxPts = new Pts(value.map(({ x, y }) => new Xy(x, y)))
187
- return
188
- }
189
-
190
- throw new Error("Unsupported points value provided to fp_poly")
191
- }
192
-
193
- get layer(): Layer | undefined {
194
- return this._sxLayer
195
- }
196
-
197
- set layer(value: Layer | string | Array<string | number> | undefined) {
198
- if (value === undefined) {
199
- this._sxLayer = undefined
200
- return
201
- }
202
- if (value instanceof Layer) {
203
- this._sxLayer = value
204
- return
205
- }
206
- const names = Array.isArray(value) ? value : [value]
207
- this._sxLayer = new Layer(names)
208
- }
209
-
210
- get width(): number | undefined {
211
- return this._sxWidth?.value
212
- }
213
-
214
- set width(value: Width | number | undefined) {
215
- if (value === undefined) {
216
- this._sxWidth = undefined
217
- return
218
- }
219
- this._sxWidth = value instanceof Width ? value : new Width(value)
220
- }
221
-
222
- get widthClass(): Width | undefined {
223
- return this._sxWidth
224
- }
225
-
226
- set widthClass(value: Width | undefined) {
227
- this._sxWidth = value
228
- }
229
-
230
- get stroke(): Stroke | undefined {
231
- return this._sxStroke
232
- }
233
-
234
- set stroke(value: Stroke | undefined) {
235
- this._sxStroke = value
236
- }
237
-
238
- get fill(): FpPolyFill | undefined {
239
- return this._sxFill
240
- }
241
-
242
- set fill(value: FpPolyFill | boolean | undefined) {
243
- if (value === undefined) {
244
- this._sxFill = undefined
245
- return
246
- }
247
- if (value instanceof FpPolyFill) {
248
- this._sxFill = value
249
- return
250
- }
251
- this._sxFill = new FpPolyFill(value)
252
- }
253
-
254
- get locked(): boolean {
255
- return this._sxLocked?.value ?? false
256
- }
257
-
258
- set locked(value: boolean) {
259
- this._sxLocked = value ? new FpPolyLocked(true) : undefined
260
- }
261
-
262
- get uuid(): Uuid | undefined {
263
- return this._sxUuid
264
- }
265
-
266
- set uuid(value: Uuid | string | undefined) {
267
- if (value === undefined) {
268
- this._sxUuid = undefined
269
- return
270
- }
271
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
272
- }
273
-
274
- override getChildren(): SxClass[] {
275
- const children: SxClass[] = []
276
- if (this._sxPts) children.push(this._sxPts)
277
- if (this._sxLayer) children.push(this._sxLayer)
278
- if (this._sxWidth) children.push(this._sxWidth)
279
- if (this._sxStroke) children.push(this._sxStroke)
280
- if (this._sxFill) children.push(this._sxFill)
281
- if (this._sxLocked) children.push(this._sxLocked)
282
- if (this._sxUuid) children.push(this._sxUuid)
283
- return children
284
- }
285
- }
286
- SxClass.register(FpPoly)
@@ -1,48 +0,0 @@
1
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { SxClass } from "../base-classes/SxClass"
4
-
5
- const truthyStrings = new Set(["yes", "true", "1"])
6
-
7
- export class FpPolyFill extends SxPrimitiveBoolean {
8
- static override token = "fill"
9
- static override parentToken = "fp_poly"
10
- override token = "fill"
11
-
12
- constructor(filled: boolean) {
13
- super(filled)
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): FpPolyFill {
19
- const [rawValue] = primitiveSexprs
20
-
21
- if (rawValue === undefined) {
22
- return new FpPolyFill(false)
23
- }
24
-
25
- if (typeof rawValue === "boolean") {
26
- return new FpPolyFill(rawValue)
27
- }
28
-
29
- if (typeof rawValue === "string") {
30
- return new FpPolyFill(truthyStrings.has(rawValue.toLowerCase()))
31
- }
32
-
33
- return new FpPolyFill(false)
34
- }
35
-
36
- get filled(): boolean {
37
- return this.value
38
- }
39
-
40
- set filled(filled: boolean) {
41
- this.value = filled
42
- }
43
-
44
- override getString(): string {
45
- return `(fill ${this.value ? "yes" : "no"})`
46
- }
47
- }
48
- SxClass.register(FpPolyFill)
@@ -1,40 +0,0 @@
1
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { SxClass } from "../base-classes/SxClass"
4
-
5
- const truthyStrings = new Set(["yes", "true", "1"])
6
-
7
- export class FpPolyLocked extends SxPrimitiveBoolean {
8
- static override token = "locked"
9
- static override parentToken = "fp_poly"
10
- override token = "locked"
11
-
12
- constructor(value: boolean) {
13
- super(value)
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): FpPolyLocked {
19
- const [rawValue] = primitiveSexprs
20
-
21
- if (rawValue === undefined) {
22
- return new FpPolyLocked(true)
23
- }
24
-
25
- if (typeof rawValue === "boolean") {
26
- return new FpPolyLocked(rawValue)
27
- }
28
-
29
- if (typeof rawValue === "string") {
30
- return new FpPolyLocked(truthyStrings.has(rawValue.toLowerCase()))
31
- }
32
-
33
- return new FpPolyLocked(false)
34
- }
35
-
36
- override getString(): string {
37
- return `(locked ${this.value ? "yes" : "no"})`
38
- }
39
- }
40
- SxClass.register(FpPolyLocked)
@@ -1,314 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { Layer } from "./Layer"
4
- import { Stroke } from "./Stroke"
5
- import { Uuid } from "./Uuid"
6
- import { Width } from "./Width"
7
- import { toNumberValue } from "../utils/toNumberValue"
8
- import { toStringValue } from "../utils/toStringValue"
9
-
10
- export interface FpRectConstructorParams {
11
- start?: FpRectStart | { x: number; y: number }
12
- end?: FpRectEnd | { x: number; y: number }
13
- layer?: Layer | string | string[]
14
- width?: number | Width
15
- stroke?: Stroke
16
- fill?: boolean | FpRectFill
17
- uuid?: string | Uuid
18
- locked?: boolean
19
- }
20
-
21
- export class FpRect extends SxClass {
22
- static override token = "fp_rect"
23
- token = "fp_rect"
24
-
25
- private _sxStart?: FpRectStart
26
- private _sxEnd?: FpRectEnd
27
- private _sxLayer?: Layer
28
- private _sxWidth?: Width
29
- private _sxStroke?: Stroke
30
- private _sxFill?: FpRectFill
31
- private _sxUuid?: Uuid
32
- private _locked = false
33
-
34
- constructor(params: FpRectConstructorParams = {}) {
35
- super()
36
- if (params.start !== undefined) this.start = params.start
37
- if (params.end !== undefined) this.end = params.end
38
- if (params.layer !== undefined) this.layer = params.layer
39
- if (params.width !== undefined) this.width = params.width
40
- if (params.stroke !== undefined) this.stroke = params.stroke
41
- if (params.fill !== undefined) this.fill = params.fill
42
- if (params.uuid !== undefined) this.uuid = params.uuid
43
- if (params.locked !== undefined) this.locked = params.locked
44
- }
45
-
46
- static override fromSexprPrimitives(
47
- primitiveSexprs: PrimitiveSExpr[],
48
- ): FpRect {
49
- const rect = new FpRect()
50
-
51
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
52
- primitiveSexprs,
53
- this.token,
54
- )
55
-
56
- rect._sxStart = propertyMap.start as FpRectStart | undefined
57
- rect._sxEnd = propertyMap.end as FpRectEnd | undefined
58
- rect._sxLayer = propertyMap.layer as Layer | undefined
59
- rect._sxWidth = propertyMap.width as Width | undefined
60
- rect._sxStroke = propertyMap.stroke as Stroke | undefined
61
- rect._sxFill = propertyMap.fill as FpRectFill | undefined
62
- rect._sxUuid = propertyMap.uuid as Uuid | undefined
63
-
64
- for (const primitive of primitiveSexprs) {
65
- if (primitive === "locked") {
66
- rect._locked = true
67
- }
68
- }
69
-
70
- return rect
71
- }
72
-
73
- get start(): FpRectStart | undefined {
74
- return this._sxStart
75
- }
76
-
77
- set start(value: FpRectStart | { x: number; y: number } | undefined,) {
78
- if (value === undefined) {
79
- this._sxStart = undefined
80
- return
81
- }
82
- if (value instanceof FpRectStart) {
83
- this._sxStart = value
84
- return
85
- }
86
- this._sxStart = new FpRectStart(value.x, value.y)
87
- }
88
-
89
- get end(): FpRectEnd | undefined {
90
- return this._sxEnd
91
- }
92
-
93
- set end(value: FpRectEnd | { x: number; y: number } | undefined) {
94
- if (value === undefined) {
95
- this._sxEnd = undefined
96
- return
97
- }
98
- if (value instanceof FpRectEnd) {
99
- this._sxEnd = value
100
- return
101
- }
102
- this._sxEnd = new FpRectEnd(value.x, value.y)
103
- }
104
-
105
- get layer(): Layer | undefined {
106
- return this._sxLayer
107
- }
108
-
109
- set layer(value: Layer | string | string[] | undefined) {
110
- if (value === undefined) {
111
- this._sxLayer = undefined
112
- return
113
- }
114
- if (value instanceof Layer) {
115
- this._sxLayer = value
116
- return
117
- }
118
- const names = Array.isArray(value) ? value : [value]
119
- this._sxLayer = new Layer(names)
120
- }
121
-
122
- get stroke(): Stroke | undefined {
123
- return this._sxStroke
124
- }
125
-
126
- set stroke(value: Stroke | undefined) {
127
- this._sxStroke = value
128
- }
129
-
130
- get width(): number | undefined {
131
- return this._sxWidth?.value
132
- }
133
-
134
- set width(value: number | Width | undefined) {
135
- if (value === undefined) {
136
- this._sxWidth = undefined
137
- return
138
- }
139
- if (value instanceof Width) {
140
- this._sxWidth = value
141
- return
142
- }
143
- this._sxWidth = new Width(value)
144
- }
145
-
146
- get widthClass(): Width | undefined {
147
- return this._sxWidth
148
- }
149
-
150
- get fill(): boolean | undefined {
151
- return this._sxFill?.filled
152
- }
153
-
154
- set fill(value: boolean | FpRectFill | undefined) {
155
- if (value === undefined) {
156
- this._sxFill = undefined
157
- return
158
- }
159
- if (value instanceof FpRectFill) {
160
- this._sxFill = value
161
- return
162
- }
163
- this._sxFill = new FpRectFill(value)
164
- }
165
-
166
- get fillClass(): FpRectFill | undefined {
167
- return this._sxFill
168
- }
169
-
170
- get uuid(): string | undefined {
171
- return this._sxUuid?.value
172
- }
173
-
174
- set uuid(value: string | Uuid | undefined) {
175
- if (value === undefined) {
176
- this._sxUuid = undefined
177
- return
178
- }
179
- if (value instanceof Uuid) {
180
- this._sxUuid = value
181
- return
182
- }
183
- this._sxUuid = new Uuid(value)
184
- }
185
-
186
- get uuidClass(): Uuid | undefined {
187
- return this._sxUuid
188
- }
189
-
190
- get locked(): boolean {
191
- return this._locked
192
- }
193
-
194
- set locked(value: boolean) {
195
- this._locked = value
196
- }
197
-
198
- override getChildren(): SxClass[] {
199
- const children: SxClass[] = []
200
- if (this._sxStart) children.push(this._sxStart)
201
- if (this._sxEnd) children.push(this._sxEnd)
202
- if (this._sxLayer) children.push(this._sxLayer)
203
- if (this._sxWidth) children.push(this._sxWidth)
204
- if (this._sxStroke) children.push(this._sxStroke)
205
- if (this._sxFill) children.push(this._sxFill)
206
- if (this._sxUuid) children.push(this._sxUuid)
207
- return children
208
- }
209
-
210
- override getString(): string {
211
- const lines = ["(fp_rect"]
212
- const push = (value?: SxClass) => {
213
- if (!value) return
214
- lines.push(value.getStringIndented())
215
- }
216
-
217
- push(this._sxStart)
218
- push(this._sxEnd)
219
- push(this._sxLayer)
220
- push(this._sxWidth)
221
- push(this._sxStroke)
222
- push(this._sxFill)
223
- push(this._sxUuid)
224
-
225
- if (this._locked) {
226
- lines.push(" locked")
227
- }
228
-
229
- lines.push(")")
230
- return lines.join("\n")
231
- }
232
- }
233
- SxClass.register(FpRect)
234
-
235
- export class FpRectStart extends SxClass {
236
- static override token = "start"
237
- static override parentToken = "fp_rect"
238
- token = "start"
239
-
240
- x: number
241
- y: number
242
-
243
- constructor(x: number, y: number) {
244
- super()
245
- this.x = x
246
- this.y = y
247
- }
248
-
249
- static override fromSexprPrimitives(
250
- primitiveSexprs: PrimitiveSExpr[],
251
- ): FpRectStart {
252
- const x = toNumberValue(primitiveSexprs[0]) ?? 0
253
- const y = toNumberValue(primitiveSexprs[1]) ?? 0
254
- return new FpRectStart(x, y)
255
- }
256
-
257
- override getString(): string {
258
- return `(start ${this.x} ${this.y})`
259
- }
260
- }
261
- SxClass.register(FpRectStart)
262
-
263
- export class FpRectEnd extends SxClass {
264
- static override token = "end"
265
- static override parentToken = "fp_rect"
266
- token = "end"
267
-
268
- x: number
269
- y: number
270
-
271
- constructor(x: number, y: number) {
272
- super()
273
- this.x = x
274
- this.y = y
275
- }
276
-
277
- static override fromSexprPrimitives(
278
- primitiveSexprs: PrimitiveSExpr[],
279
- ): FpRectEnd {
280
- const x = toNumberValue(primitiveSexprs[0]) ?? 0
281
- const y = toNumberValue(primitiveSexprs[1]) ?? 0
282
- return new FpRectEnd(x, y)
283
- }
284
-
285
- override getString(): string {
286
- return `(end ${this.x} ${this.y})`
287
- }
288
- }
289
- SxClass.register(FpRectEnd)
290
-
291
- export class FpRectFill extends SxClass {
292
- static override token = "fill"
293
- static override parentToken = "fp_rect"
294
- token = "fill"
295
-
296
- filled: boolean
297
-
298
- constructor(filled: boolean) {
299
- super()
300
- this.filled = filled
301
- }
302
-
303
- static override fromSexprPrimitives(
304
- primitiveSexprs: PrimitiveSExpr[],
305
- ): FpRectFill {
306
- const state = toStringValue(primitiveSexprs[0])
307
- return new FpRectFill(state === "yes")
308
- }
309
-
310
- override getString(): string {
311
- return `(fill ${this.filled ? "yes" : "no"})`
312
- }
313
- }
314
- SxClass.register(FpRectFill)