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,450 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { printSExpr, type PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
- import { toNumberValue } from "../utils/toNumberValue"
5
- import { toStringValue } from "../utils/toStringValue"
6
- import { Layer } from "./Layer"
7
- import { TextEffects } from "./TextEffects"
8
- import { Uuid } from "./Uuid"
9
- import { Stroke } from "./Stroke"
10
- import { Pts } from "./Pts"
11
- import { RenderCache } from "./RenderCache"
12
-
13
- function primitiveToString(value: PrimitiveSExpr | undefined): string {
14
- if (value === undefined) return ""
15
- const str = toStringValue(value)
16
- if (str !== undefined) return str
17
- return printSExpr(value)
18
- }
19
-
20
- const SUPPORTED_SINGLE_TOKENS = new Set([
21
- "start",
22
- "end",
23
- "pts",
24
- "angle",
25
- "layer",
26
- "uuid",
27
- "effects",
28
- "stroke",
29
- "render_cache",
30
- ])
31
-
32
- const SUPPORTED_MULTI_TOKENS = new Set<string>()
33
-
34
- export interface FpTextBoxConstructorParams {
35
- locked?: boolean
36
- text?: string
37
- start?: FpTextBoxStart | { x: number; y: number }
38
- end?: FpTextBoxEnd | { x: number; y: number }
39
- pts?: Pts
40
- angle?: FpTextBoxAngle | number
41
- layer?: Layer | string | string[]
42
- uuid?: Uuid | string
43
- effects?: TextEffects
44
- stroke?: Stroke
45
- renderCache?: RenderCache
46
- }
47
-
48
- export class FpTextBox extends SxClass {
49
- static override token = "fp_text_box"
50
- token = "fp_text_box"
51
-
52
- private _sxLocked?: FpTextBoxLocked
53
- private _text = ""
54
- private _sxStart?: FpTextBoxStart
55
- private _sxEnd?: FpTextBoxEnd
56
- private _sxPts?: Pts
57
- private _sxAngle?: FpTextBoxAngle
58
- private _sxLayer?: Layer
59
- private _sxUuid?: Uuid
60
- private _sxEffects?: TextEffects
61
- private _sxStroke?: Stroke
62
- private _sxRenderCache?: RenderCache
63
-
64
- constructor(params: FpTextBoxConstructorParams = {}) {
65
- super()
66
- if (params.locked !== undefined) this.locked = params.locked
67
- if (params.text !== undefined) this.text = params.text
68
- if (params.start !== undefined) this.start = params.start
69
- if (params.end !== undefined) this.end = params.end
70
- if (params.pts !== undefined) this.pts = params.pts
71
- if (params.angle !== undefined) this.angle = params.angle
72
- if (params.layer !== undefined) this.layer = params.layer
73
- if (params.uuid !== undefined) this.uuid = params.uuid
74
- if (params.effects !== undefined) this.effects = params.effects
75
- if (params.stroke !== undefined) this.stroke = params.stroke
76
- if (params.renderCache !== undefined) this.renderCache = params.renderCache
77
- }
78
-
79
- static override fromSexprPrimitives(
80
- primitiveSexprs: PrimitiveSExpr[],
81
- ): FpTextBox {
82
- const fpTextBox = new FpTextBox()
83
-
84
- if (primitiveSexprs.length === 0) {
85
- throw new Error("fp_text_box requires a text value")
86
- }
87
-
88
- let capturedText = false
89
- let locked = false
90
- const structuredPrimitives: PrimitiveSExpr[] = []
91
-
92
- for (const primitive of primitiveSexprs) {
93
- if (typeof primitive === "string") {
94
- if (primitive === "locked") {
95
- if (locked) {
96
- throw new Error("fp_text_box encountered duplicate locked flags")
97
- }
98
- locked = true
99
- continue
100
- }
101
- if (!capturedText) {
102
- fpTextBox._text = primitive
103
- capturedText = true
104
- continue
105
- }
106
- throw new Error(
107
- `fp_text_box encountered unsupported flag "${primitive}"`,
108
- )
109
- }
110
-
111
- if (!capturedText) {
112
- fpTextBox._text = primitiveToString(primitive)
113
- capturedText = true
114
- continue
115
- }
116
-
117
- if (!Array.isArray(primitive) || primitive.length === 0) {
118
- throw new Error(
119
- `fp_text_box encountered invalid child expression: ${JSON.stringify(primitive)}`,
120
- )
121
- }
122
-
123
- structuredPrimitives.push(primitive)
124
- }
125
-
126
- if (!capturedText) {
127
- throw new Error("fp_text_box did not include a text value")
128
- }
129
-
130
- if (locked) {
131
- fpTextBox._sxLocked = new FpTextBoxLocked()
132
- }
133
-
134
- const { propertyMap, arrayPropertyMap } =
135
- SxClass.parsePrimitivesToClassProperties(structuredPrimitives, this.token)
136
-
137
- for (const token of Object.keys(propertyMap)) {
138
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
139
- throw new Error(
140
- `fp_text_box encountered unsupported child token "${token}"`,
141
- )
142
- }
143
- }
144
-
145
- for (const [token, entries] of Object.entries(arrayPropertyMap)) {
146
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
147
- throw new Error(
148
- `fp_text_box encountered unsupported child token "${token}"`,
149
- )
150
- }
151
- if (!SUPPORTED_MULTI_TOKENS.has(token) && entries.length > 1) {
152
- throw new Error(
153
- `fp_text_box does not support repeated child token "${token}"`,
154
- )
155
- }
156
- }
157
-
158
- fpTextBox._sxStart = propertyMap.start as FpTextBoxStart | undefined
159
- fpTextBox._sxEnd = propertyMap.end as FpTextBoxEnd | undefined
160
- fpTextBox._sxPts = propertyMap.pts as Pts | undefined
161
- fpTextBox._sxAngle = propertyMap.angle as FpTextBoxAngle | undefined
162
- fpTextBox._sxLayer = propertyMap.layer as Layer | undefined
163
- fpTextBox._sxUuid = propertyMap.uuid as Uuid | undefined
164
- fpTextBox._sxEffects = propertyMap.effects as TextEffects | undefined
165
- fpTextBox._sxStroke = propertyMap.stroke as Stroke | undefined
166
- fpTextBox._sxRenderCache = propertyMap.render_cache as
167
- | RenderCache
168
- | undefined
169
-
170
- return fpTextBox
171
- }
172
-
173
- get locked(): boolean {
174
- return this._sxLocked !== undefined
175
- }
176
-
177
- set locked(value: boolean) {
178
- this._sxLocked = value ? new FpTextBoxLocked() : undefined
179
- }
180
-
181
- get text(): string {
182
- return this._text
183
- }
184
-
185
- set text(value: string) {
186
- this._text = value
187
- }
188
-
189
- get start(): FpTextBoxStart | undefined {
190
- return this._sxStart
191
- }
192
-
193
- set start(value: FpTextBoxStart | { x: number; y: number } | undefined) {
194
- if (value === undefined) {
195
- this._sxStart = undefined
196
- return
197
- }
198
- this._sxStart =
199
- value instanceof FpTextBoxStart
200
- ? value
201
- : new FpTextBoxStart([value.x, value.y])
202
- }
203
-
204
- get end(): FpTextBoxEnd | undefined {
205
- return this._sxEnd
206
- }
207
-
208
- set end(value: FpTextBoxEnd | { x: number; y: number } | undefined) {
209
- if (value === undefined) {
210
- this._sxEnd = undefined
211
- return
212
- }
213
- this._sxEnd =
214
- value instanceof FpTextBoxEnd
215
- ? value
216
- : new FpTextBoxEnd([value.x, value.y])
217
- }
218
-
219
- get pts(): Pts | undefined {
220
- return this._sxPts
221
- }
222
-
223
- set pts(value: Pts | undefined) {
224
- this._sxPts = value
225
- }
226
-
227
- get angle(): FpTextBoxAngle | undefined {
228
- return this._sxAngle
229
- }
230
-
231
- set angle(value: FpTextBoxAngle | number | undefined) {
232
- if (value === undefined) {
233
- this._sxAngle = undefined
234
- return
235
- }
236
- this._sxAngle =
237
- value instanceof FpTextBoxAngle ? value : new FpTextBoxAngle([value])
238
- }
239
-
240
- get layer(): Layer | undefined {
241
- return this._sxLayer
242
- }
243
-
244
- set layer(value: Layer | string | string[] | undefined) {
245
- if (value === undefined) {
246
- this._sxLayer = undefined
247
- return
248
- }
249
- if (value instanceof Layer) {
250
- this._sxLayer = value
251
- } else {
252
- const names = Array.isArray(value) ? value : [value]
253
- this._sxLayer = new Layer(names)
254
- }
255
- }
256
-
257
- get effects(): TextEffects | undefined {
258
- return this._sxEffects
259
- }
260
-
261
- set effects(value: TextEffects | undefined) {
262
- this._sxEffects = value
263
- }
264
-
265
- get stroke(): Stroke | undefined {
266
- return this._sxStroke
267
- }
268
-
269
- set stroke(value: Stroke | undefined) {
270
- this._sxStroke = value
271
- }
272
-
273
- get uuid(): Uuid | undefined {
274
- return this._sxUuid
275
- }
276
-
277
- set uuid(value: Uuid | string | undefined) {
278
- if (value === undefined) {
279
- this._sxUuid = undefined
280
- return
281
- }
282
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
283
- }
284
-
285
- get renderCache(): RenderCache | undefined {
286
- return this._sxRenderCache
287
- }
288
-
289
- set renderCache(value: RenderCache | undefined) {
290
- this._sxRenderCache = value
291
- }
292
-
293
- override getChildren(): SxClass[] {
294
- const children: SxClass[] = []
295
- if (this._sxLocked) children.push(this._sxLocked)
296
- if (this._sxStart) children.push(this._sxStart)
297
- if (this._sxEnd) children.push(this._sxEnd)
298
- if (this._sxPts) children.push(this._sxPts)
299
- if (this._sxAngle) children.push(this._sxAngle)
300
- if (this._sxLayer) children.push(this._sxLayer)
301
- if (this._sxEffects) children.push(this._sxEffects)
302
- if (this._sxStroke) children.push(this._sxStroke)
303
- if (this._sxUuid) children.push(this._sxUuid)
304
- if (this._sxRenderCache) children.push(this._sxRenderCache)
305
- return children
306
- }
307
-
308
- override getString(): string {
309
- const lines = ["(fp_text_box"]
310
-
311
- if (this._sxLocked) {
312
- lines.push(this._sxLocked.getStringIndented())
313
- }
314
-
315
- lines.push(` ${quoteSExprString(this._text)}`)
316
-
317
- for (const child of this.getChildren()) {
318
- if (child === this._sxLocked) continue
319
- lines.push(child.getStringIndented())
320
- }
321
-
322
- lines.push(")")
323
- return lines.join("\n")
324
- }
325
- }
326
- SxClass.register(FpTextBox)
327
-
328
- export class FpTextBoxStart extends SxClass {
329
- static override token = "start"
330
- static override parentToken = "fp_text_box"
331
- token = "start"
332
-
333
- x: number
334
- y: number
335
-
336
- constructor(args: [number, number]) {
337
- super()
338
- this.x = args[0]
339
- this.y = args[1]
340
- }
341
-
342
- static override fromSexprPrimitives(
343
- primitiveSexprs: PrimitiveSExpr[],
344
- ): FpTextBoxStart {
345
- const [rawX, rawY] = primitiveSexprs
346
- const x = Number(rawX)
347
- const y = Number(rawY)
348
- return new FpTextBoxStart([
349
- Number.isFinite(x) ? x : 0,
350
- Number.isFinite(y) ? y : 0,
351
- ])
352
- }
353
-
354
- override getChildren(): SxClass[] {
355
- return []
356
- }
357
-
358
- override getString(): string {
359
- return `(start ${this.x} ${this.y})`
360
- }
361
- }
362
- SxClass.register(FpTextBoxStart)
363
-
364
- export class FpTextBoxEnd extends SxClass {
365
- static override token = "end"
366
- static override parentToken = "fp_text_box"
367
- token = "end"
368
-
369
- x: number
370
- y: number
371
-
372
- constructor(args: [number, number]) {
373
- super()
374
- this.x = args[0]
375
- this.y = args[1]
376
- }
377
-
378
- static override fromSexprPrimitives(
379
- primitiveSexprs: PrimitiveSExpr[],
380
- ): FpTextBoxEnd {
381
- const [rawX, rawY] = primitiveSexprs
382
- const x = Number(rawX)
383
- const y = Number(rawY)
384
- return new FpTextBoxEnd([
385
- Number.isFinite(x) ? x : 0,
386
- Number.isFinite(y) ? y : 0,
387
- ])
388
- }
389
-
390
- override getChildren(): SxClass[] {
391
- return []
392
- }
393
-
394
- override getString(): string {
395
- return `(end ${this.x} ${this.y})`
396
- }
397
- }
398
- SxClass.register(FpTextBoxEnd)
399
-
400
- export class FpTextBoxAngle extends SxClass {
401
- static override token = "angle"
402
- static override parentToken = "fp_text_box"
403
- token = "angle"
404
-
405
- value: number
406
-
407
- constructor(args: [number]) {
408
- super()
409
- this.value = args[0]
410
- }
411
-
412
- static override fromSexprPrimitives(
413
- primitiveSexprs: PrimitiveSExpr[],
414
- ): FpTextBoxAngle {
415
- const [raw] = primitiveSexprs
416
- const numeric =
417
- typeof raw === "number"
418
- ? raw
419
- : (toNumberValue(raw as PrimitiveSExpr) ?? 0)
420
- return new FpTextBoxAngle([numeric])
421
- }
422
-
423
- override getChildren(): SxClass[] {
424
- return []
425
- }
426
-
427
- override getString(): string {
428
- return `(angle ${this.value})`
429
- }
430
- }
431
- SxClass.register(FpTextBoxAngle)
432
-
433
- class FpTextBoxLocked extends SxClass {
434
- static override token = "locked"
435
- static override parentToken = "fp_text_box"
436
- token = "locked"
437
-
438
- static override fromSexprPrimitives(): FpTextBoxLocked {
439
- return new FpTextBoxLocked()
440
- }
441
-
442
- override getChildren(): SxClass[] {
443
- return []
444
- }
445
-
446
- override getString(): string {
447
- return "locked"
448
- }
449
- }
450
- SxClass.register(FpTextBoxLocked)
@@ -1,264 +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 { GrLineStart } from "./GrLineStart"
8
- import { GrLineEnd } from "./GrLineEnd"
9
- import { GrLineAngle } from "./GrLineAngle"
10
- import { GrLineLocked } from "./GrLineLocked"
11
-
12
- export interface GrLinePoint {
13
- x: number
14
- y: number
15
- }
16
-
17
- const SUPPORTED_SINGLE_TOKENS = new Set([
18
- "start",
19
- "end",
20
- "angle",
21
- "layer",
22
- "width",
23
- "stroke",
24
- "uuid",
25
- "locked",
26
- ])
27
-
28
- export interface GrLineConstructorParams {
29
- start?: GrLineStart | GrLinePoint
30
- end?: GrLineEnd | GrLinePoint
31
- angle?: number
32
- layer?: Layer | string | Array<string | number>
33
- width?: Width | number
34
- stroke?: Stroke
35
- uuid?: Uuid | string
36
- locked?: boolean
37
- }
38
-
39
- export class GrLine extends SxClass {
40
- static override token = "gr_line"
41
- override token = "gr_line"
42
-
43
- private _sxStart?: GrLineStart
44
- private _sxEnd?: GrLineEnd
45
- private _sxAngle?: GrLineAngle
46
- private _sxLayer?: Layer
47
- private _sxWidth?: Width
48
- private _sxStroke?: Stroke
49
- private _sxUuid?: Uuid
50
- private _sxLocked?: GrLineLocked
51
-
52
- constructor(params: GrLineConstructorParams = {}) {
53
- super()
54
- if (params.start !== undefined) this.start = params.start
55
- if (params.end !== undefined) this.end = params.end
56
- if (params.angle !== undefined) this.angle = params.angle
57
- if (params.layer !== undefined) this.layer = params.layer
58
- if (params.width !== undefined) this.width = params.width
59
- if (params.stroke !== undefined) this.stroke = params.stroke
60
- if (params.uuid !== undefined) this.uuid = params.uuid
61
- if (params.locked !== undefined) this.locked = params.locked
62
- }
63
-
64
- static override fromSexprPrimitives(
65
- primitiveSexprs: PrimitiveSExpr[],
66
- ): GrLine {
67
- const grLine = new GrLine()
68
-
69
- const { propertyMap, arrayPropertyMap } =
70
- SxClass.parsePrimitivesToClassProperties(primitiveSexprs, this.token)
71
-
72
- const unexpectedTokens = new Set<string>()
73
- for (const token of Object.keys(propertyMap)) {
74
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
75
- unexpectedTokens.add(token)
76
- }
77
- }
78
- for (const token of Object.keys(arrayPropertyMap)) {
79
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
80
- unexpectedTokens.add(token)
81
- continue
82
- }
83
- if (arrayPropertyMap[token]!.length > 1) {
84
- throw new Error(
85
- `gr_line does not support repeated child tokens: ${token}`,
86
- )
87
- }
88
- }
89
-
90
- if (unexpectedTokens.size > 0) {
91
- throw new Error(
92
- `Unsupported child tokens inside gr_line expression: ${[...unexpectedTokens].join(", ")}`,
93
- )
94
- }
95
-
96
- for (const primitive of primitiveSexprs) {
97
- if (Array.isArray(primitive)) continue
98
- throw new Error(
99
- `gr_line encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
100
- )
101
- }
102
-
103
- grLine._sxStart = propertyMap.start as GrLineStart | undefined
104
- grLine._sxEnd = propertyMap.end as GrLineEnd | undefined
105
- grLine._sxAngle = propertyMap.angle as GrLineAngle | undefined
106
- grLine._sxLayer = propertyMap.layer as Layer | undefined
107
- grLine._sxWidth = propertyMap.width as Width | undefined
108
- grLine._sxStroke = propertyMap.stroke as Stroke | undefined
109
- const locked = propertyMap.locked as GrLineLocked | undefined
110
- grLine._sxLocked = locked && locked.value ? locked : undefined
111
- grLine._sxUuid = propertyMap.uuid as Uuid | undefined
112
-
113
- if (!grLine._sxStart) {
114
- throw new Error("gr_line requires a start child token")
115
- }
116
- if (!grLine._sxEnd) {
117
- throw new Error("gr_line requires an end child token")
118
- }
119
- if (!grLine._sxLayer) {
120
- throw new Error("gr_line requires a layer child token")
121
- }
122
-
123
- return grLine
124
- }
125
-
126
- get start(): GrLineStart | undefined {
127
- return this._sxStart
128
- }
129
-
130
- set start(value: GrLineStart | GrLinePoint | undefined) {
131
- this._sxStart = this.normalizeStart(value)
132
- }
133
-
134
- get end(): GrLineEnd | undefined {
135
- return this._sxEnd
136
- }
137
-
138
- set end(value: GrLineEnd | GrLinePoint | undefined) {
139
- this._sxEnd = this.normalizeEnd(value)
140
- }
141
-
142
- get startPoint(): GrLinePoint | undefined {
143
- return this._sxStart?.toObject()
144
- }
145
-
146
- get endPoint(): GrLinePoint | undefined {
147
- return this._sxEnd?.toObject()
148
- }
149
-
150
- get angle(): number | undefined {
151
- return this._sxAngle?.value
152
- }
153
-
154
- set angle(value: number | undefined) {
155
- if (value === undefined) {
156
- this._sxAngle = undefined
157
- return
158
- }
159
- this._sxAngle = new GrLineAngle(value)
160
- }
161
-
162
- get layer(): Layer | undefined {
163
- return this._sxLayer
164
- }
165
-
166
- set layer(value: Layer | string | Array<string | number> | undefined) {
167
- if (value === undefined) {
168
- this._sxLayer = undefined
169
- return
170
- }
171
- if (value instanceof Layer) {
172
- this._sxLayer = value
173
- return
174
- }
175
- const names = Array.isArray(value) ? value : [value]
176
- this._sxLayer = new Layer(names)
177
- }
178
-
179
- get width(): number | undefined {
180
- return this._sxWidth?.value
181
- }
182
-
183
- set width(value: Width | number | undefined) {
184
- if (value === undefined) {
185
- this._sxWidth = undefined
186
- return
187
- }
188
- this._sxWidth = value instanceof Width ? value : new Width(value)
189
- }
190
-
191
- get widthClass(): Width | undefined {
192
- return this._sxWidth
193
- }
194
-
195
- set widthClass(value: Width | undefined) {
196
- this._sxWidth = value
197
- }
198
-
199
- get stroke(): Stroke | undefined {
200
- return this._sxStroke
201
- }
202
-
203
- set stroke(value: Stroke | undefined) {
204
- this._sxStroke = value
205
- }
206
-
207
- get uuid(): Uuid | undefined {
208
- return this._sxUuid
209
- }
210
-
211
- set uuid(value: Uuid | string | undefined) {
212
- if (value === undefined) {
213
- this._sxUuid = undefined
214
- return
215
- }
216
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
217
- }
218
-
219
- get locked(): boolean {
220
- return this._sxLocked?.value ?? false
221
- }
222
-
223
- set locked(value: boolean) {
224
- this._sxLocked = value ? new GrLineLocked(true) : undefined
225
- }
226
-
227
- override getChildren(): SxClass[] {
228
- const children: SxClass[] = []
229
- if (this._sxStart) children.push(this._sxStart)
230
- if (this._sxEnd) children.push(this._sxEnd)
231
- if (this._sxAngle) children.push(this._sxAngle)
232
- if (this._sxStroke) children.push(this._sxStroke)
233
- if (this._sxWidth) children.push(this._sxWidth)
234
- if (this._sxLocked) children.push(this._sxLocked)
235
- if (this._sxLayer) children.push(this._sxLayer)
236
- if (this._sxUuid) children.push(this._sxUuid)
237
- return children
238
- }
239
-
240
- private normalizeStart(
241
- value: GrLineStart | GrLinePoint | undefined,
242
- ): GrLineStart | undefined {
243
- if (value === undefined) {
244
- return undefined
245
- }
246
- if (value instanceof GrLineStart) {
247
- return value
248
- }
249
- return new GrLineStart(value.x, value.y)
250
- }
251
-
252
- private normalizeEnd(
253
- value: GrLineEnd | GrLinePoint | undefined,
254
- ): GrLineEnd | undefined {
255
- if (value === undefined) {
256
- return undefined
257
- }
258
- if (value instanceof GrLineEnd) {
259
- return value
260
- }
261
- return new GrLineEnd(value.x, value.y)
262
- }
263
- }
264
- SxClass.register(GrLine)