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,461 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
- import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
4
- import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
5
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
6
- import { quoteSExprString } from "../utils/quoteSExprString"
7
- import { toNumberValue } from "../utils/toNumberValue"
8
- import { toStringValue } from "../utils/toStringValue"
9
-
10
- export type TextEffectsProperty = TextEffectsFont | TextEffectsJustify
11
-
12
- export interface TextEffectsConstructorParams {
13
- font?: TextEffectsFont
14
- justify?: TextEffectsJustify
15
- hiddenText?: boolean
16
- }
17
-
18
- export class TextEffects extends SxClass {
19
- static override token = "effects"
20
- token = "effects"
21
-
22
- _sxFont?: TextEffectsFont
23
- _sxJustify?: TextEffectsJustify
24
- private _hiddenText = false
25
-
26
- constructor(params: TextEffectsConstructorParams = {}) {
27
- super()
28
-
29
- if (params.font !== undefined) this.font = params.font
30
- if (params.justify !== undefined) this.justify = params.justify
31
- if (params.hiddenText !== undefined) this.hiddenText = params.hiddenText
32
- }
33
-
34
- get font(): TextEffectsFont {
35
- if (!this._sxFont) {
36
- this._sxFont = new TextEffectsFont()
37
- }
38
- return this._sxFont
39
- }
40
-
41
- set font(value: TextEffectsFont | undefined) {
42
- this._sxFont = value
43
- }
44
-
45
- get justify(): TextEffectsJustify | undefined {
46
- return this._sxJustify
47
- }
48
-
49
- set justify(value: TextEffectsJustify | undefined) {
50
- this._sxJustify = value
51
- }
52
-
53
- get hiddenText(): boolean {
54
- return this._hiddenText
55
- }
56
-
57
- set hiddenText(value: boolean) {
58
- this._hiddenText = value
59
- }
60
-
61
- static override fromSexprPrimitives(
62
- primitiveSexprs: PrimitiveSExpr[],
63
- ): TextEffects {
64
- const effects = new TextEffects()
65
-
66
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
67
- primitiveSexprs,
68
- this.token,
69
- )
70
-
71
- effects._sxFont = propertyMap.font as TextEffectsFont | undefined
72
- effects._sxJustify = propertyMap.justify as TextEffectsJustify | undefined
73
- const hideNode = propertyMap.hide as TextEffectsHide | undefined
74
- if (hideNode) {
75
- effects._hiddenText = hideNode.value
76
- }
77
-
78
- for (const primitive of primitiveSexprs) {
79
- if (typeof primitive === "string") {
80
- if (primitive === "hide") {
81
- effects._hiddenText = true
82
- continue
83
- }
84
- throw new Error(`Unknown text effects token: ${primitive}`)
85
- }
86
-
87
- if (Array.isArray(primitive)) {
88
- // Arrays are parsed via parsePrimitivesToClassProperties already.
89
- continue
90
- }
91
-
92
- throw new Error(
93
- `Unsupported text effects primitive: ${JSON.stringify(primitive)}`,
94
- )
95
- }
96
-
97
- return effects
98
- }
99
-
100
- override getChildren(): SxClass[] {
101
- const children: SxClass[] = []
102
- if (this._sxFont) children.push(this._sxFont)
103
- if (this._sxJustify) children.push(this._sxJustify)
104
- if (this._hiddenText) children.push(new TextEffectsHide(true))
105
- return children
106
- }
107
-
108
- override getString(): string {
109
- const lines = ["(effects"]
110
- if (this._sxFont) {
111
- lines.push(this._sxFont.getStringIndented())
112
- }
113
- if (this._sxJustify) {
114
- lines.push(this._sxJustify.getStringIndented())
115
- }
116
- if (this._hiddenText) {
117
- lines.push(new TextEffectsHide(true).getStringIndented())
118
- }
119
- lines.push(")")
120
- return lines.join("\n")
121
- }
122
- }
123
- SxClass.register(TextEffects)
124
-
125
- export type TextEffectsFontProperty =
126
- | TextEffectsFontFace
127
- | TextEffectsFontSize
128
- | TextEffectsFontThickness
129
- | TextEffectsFontLineSpacing
130
-
131
- export class TextEffectsFont extends SxClass {
132
- static override token = "font"
133
- static override parentToken = "effects"
134
- token = "font"
135
-
136
- _sxFace?: TextEffectsFontFace
137
- _sxSize?: TextEffectsFontSize
138
- _sxThickness?: TextEffectsFontThickness
139
- _sxLineSpacing?: TextEffectsFontLineSpacing
140
- private _bold = false
141
- private _italic = false
142
-
143
- get face(): string | undefined {
144
- return this._sxFace?.value
145
- }
146
-
147
- set face(value: string | undefined) {
148
- this._sxFace =
149
- value === undefined ? undefined : new TextEffectsFontFace(value)
150
- }
151
-
152
- get size(): { height: number; width: number } | undefined {
153
- if (!this._sxSize) return undefined
154
- return { height: this._sxSize.height, width: this._sxSize.width }
155
- }
156
-
157
- set size(value:
158
- | TextEffectsFontSize
159
- | { height: number; width: number }
160
- | undefined,) {
161
- if (value === undefined) {
162
- this._sxSize = undefined
163
- return
164
- }
165
-
166
- if (value instanceof TextEffectsFontSize) {
167
- this._sxSize = value
168
- return
169
- }
170
-
171
- this._sxSize = new TextEffectsFontSize(value.height, value.width)
172
- }
173
-
174
- get thickness(): number | undefined {
175
- return this._sxThickness?.value
176
- }
177
-
178
- set thickness(value: number | undefined) {
179
- this._sxThickness =
180
- value === undefined ? undefined : new TextEffectsFontThickness(value)
181
- }
182
-
183
- get lineSpacing(): number | undefined {
184
- return this._sxLineSpacing?.value
185
- }
186
-
187
- set lineSpacing(value: number | undefined) {
188
- this._sxLineSpacing =
189
- value === undefined ? undefined : new TextEffectsFontLineSpacing(value)
190
- }
191
-
192
- get bold(): boolean {
193
- return this._bold
194
- }
195
-
196
- set bold(value: boolean) {
197
- this._bold = value
198
- }
199
-
200
- get italic(): boolean {
201
- return this._italic
202
- }
203
-
204
- set italic(value: boolean) {
205
- this._italic = value
206
- }
207
-
208
- static override fromSexprPrimitives(
209
- primitiveSexprs: PrimitiveSExpr[],
210
- ): TextEffectsFont {
211
- const font = new TextEffectsFont()
212
- const { propertyMap } = SxClass.parsePrimitivesToClassProperties(
213
- primitiveSexprs,
214
- this.token,
215
- )
216
-
217
- font._sxFace = propertyMap.face as TextEffectsFontFace
218
- font._sxSize = propertyMap.size as TextEffectsFontSize
219
- font._sxThickness = propertyMap.thickness as TextEffectsFontThickness
220
- font._sxLineSpacing = propertyMap.line_spacing as TextEffectsFontLineSpacing
221
-
222
- for (const primitive of primitiveSexprs) {
223
- if (typeof primitive === "string") {
224
- if (primitive === "bold") {
225
- font._bold = true
226
- continue
227
- }
228
- if (primitive === "italic") {
229
- font._italic = true
230
- continue
231
- }
232
- throw new Error(`Unknown font token: ${primitive}`)
233
- }
234
-
235
- if (Array.isArray(primitive)) {
236
- continue
237
- }
238
-
239
- throw new Error(
240
- `Unsupported font primitive: ${JSON.stringify(primitive)}`,
241
- )
242
- }
243
-
244
- return font
245
- }
246
-
247
- override getChildren(): SxClass[] {
248
- const children: SxClass[] = []
249
- if (this._sxFace) children.push(this._sxFace)
250
- if (this._sxSize) children.push(this._sxSize)
251
- if (this._sxThickness) children.push(this._sxThickness)
252
- if (this._sxLineSpacing) children.push(this._sxLineSpacing)
253
- return children
254
- }
255
-
256
- override getString(): string {
257
- const lines = ["(font"]
258
- if (this._sxFace) {
259
- lines.push(this._sxFace.getStringIndented())
260
- }
261
- if (this._sxSize) {
262
- lines.push(this._sxSize.getStringIndented())
263
- }
264
- if (this._sxThickness) {
265
- lines.push(this._sxThickness.getStringIndented())
266
- }
267
- if (this._bold) {
268
- lines.push(" bold")
269
- }
270
- if (this._italic) {
271
- lines.push(" italic")
272
- }
273
- if (this._sxLineSpacing) {
274
- lines.push(this._sxLineSpacing.getStringIndented())
275
- }
276
- lines.push(")")
277
- return lines.join("\n")
278
- }
279
- }
280
- SxClass.register(TextEffectsFont)
281
-
282
- export class TextEffectsFontFace extends SxPrimitiveString {
283
- static override token = "face"
284
- static override parentToken = "font"
285
- token = "face"
286
-
287
- override getString(): string {
288
- return `(face ${quoteSExprString(this.value)})`
289
- }
290
- }
291
- SxClass.register(TextEffectsFontFace)
292
-
293
- export class TextEffectsFontSize extends SxClass {
294
- static override token = "size"
295
- static override parentToken = "font"
296
- token = "size"
297
-
298
- private _height = 0
299
- private _width = 0
300
-
301
- constructor(height = 0, width = 0) {
302
- super()
303
- this._height = height
304
- this._width = width
305
- }
306
-
307
- static override fromSexprPrimitives(
308
- primitiveSexprs: PrimitiveSExpr[],
309
- ): TextEffectsFontSize {
310
- const height = toNumberValue(primitiveSexprs[0]) ?? 0
311
- const width = toNumberValue(primitiveSexprs[1]) ?? 0
312
- return new TextEffectsFontSize(height, width)
313
- }
314
-
315
- get height(): number {
316
- return this._height
317
- }
318
-
319
- set height(value: number) {
320
- this._height = value
321
- }
322
-
323
- get width(): number {
324
- return this._width
325
- }
326
-
327
- set width(value: number) {
328
- this._width = value
329
- }
330
-
331
- override getString(): string {
332
- return `(size ${this._height} ${this._width})`
333
- }
334
- }
335
- SxClass.register(TextEffectsFontSize)
336
-
337
- export class TextEffectsFontThickness extends SxPrimitiveNumber {
338
- static override token = "thickness"
339
- static override parentToken = "font"
340
- token = "thickness"
341
- }
342
- SxClass.register(TextEffectsFontThickness)
343
-
344
- class TextEffectsHide extends SxPrimitiveBoolean {
345
- static override token = "hide"
346
- static override parentToken = "effects"
347
- token = "hide"
348
-
349
- constructor(value?: boolean) {
350
- super(value ?? true)
351
- }
352
-
353
- override getString(): string {
354
- return this.value ? "(hide yes)" : "(hide no)"
355
- }
356
- }
357
- SxClass.register(TextEffectsHide)
358
-
359
- export class TextEffectsFontLineSpacing extends SxPrimitiveNumber {
360
- static override token = "line_spacing"
361
- static override parentToken = "font"
362
- token = "line_spacing"
363
- }
364
- SxClass.register(TextEffectsFontLineSpacing)
365
-
366
- export class TextEffectsJustify extends SxClass {
367
- static override token = "justify"
368
- static override parentToken = "effects"
369
- token = "justify"
370
-
371
- private _horizontal?: "left" | "right"
372
- private _vertical?: "top" | "bottom"
373
- private _mirror = false
374
-
375
- constructor(
376
- options: {
377
- horizontal?: "left" | "right"
378
- vertical?: "top" | "bottom"
379
- mirror?: boolean
380
- } = {},
381
- ) {
382
- super()
383
- this._horizontal = options.horizontal
384
- this._vertical = options.vertical
385
- this._mirror = options.mirror ?? false
386
- }
387
-
388
- static override fromSexprPrimitives(
389
- primitiveSexprs: PrimitiveSExpr[],
390
- ): TextEffectsJustify {
391
- const justify = new TextEffectsJustify()
392
-
393
- for (const primitive of primitiveSexprs) {
394
- const value = toStringValue(primitive)
395
- if (value === undefined) {
396
- throw new Error(
397
- `Unsupported justify primitive: ${JSON.stringify(primitive)}`,
398
- )
399
- }
400
-
401
- if (value === "left" || value === "right") {
402
- justify._horizontal = value
403
- continue
404
- }
405
-
406
- if (value === "top" || value === "bottom") {
407
- justify._vertical = value
408
- continue
409
- }
410
-
411
- if (value === "mirror") {
412
- justify._mirror = true
413
- continue
414
- }
415
-
416
- throw new Error(`Unknown justify token: ${value}`)
417
- }
418
-
419
- return justify
420
- }
421
-
422
- get horizontal(): "left" | "right" | undefined {
423
- return this._horizontal
424
- }
425
-
426
- set horizontal(value: "left" | "right" | undefined) {
427
- this._horizontal = value
428
- }
429
-
430
- get vertical(): "top" | "bottom" | undefined {
431
- return this._vertical
432
- }
433
-
434
- set vertical(value: "top" | "bottom" | undefined) {
435
- this._vertical = value
436
- }
437
-
438
- get mirror(): boolean {
439
- return this._mirror
440
- }
441
-
442
- set mirror(value: boolean) {
443
- this._mirror = value
444
- }
445
-
446
- override getString(): string {
447
- const parts = ["(justify"]
448
- if (this._horizontal) {
449
- parts.push(` ${this._horizontal}`)
450
- }
451
- if (this._vertical) {
452
- parts.push(` ${this._vertical}`)
453
- }
454
- if (this._mirror) {
455
- parts.push(" mirror")
456
- }
457
- parts.push(")")
458
- return parts.join("")
459
- }
460
- }
461
- SxClass.register(TextEffectsJustify)