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,32 +0,0 @@
1
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
2
- import { toNumberValue } from "../utils/toNumberValue"
3
- import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
4
- import { SxClass } from "../base-classes/SxClass"
5
-
6
- export class GrLineAngle extends SxPrimitiveNumber {
7
- static override token = "angle"
8
- static override parentToken = "gr_line"
9
- override token = "angle"
10
-
11
- constructor(value: number) {
12
- super(value)
13
- }
14
-
15
- static override fromSexprPrimitives(
16
- primitiveSexprs: PrimitiveSExpr[],
17
- ): GrLineAngle {
18
- const [rawAngle] = primitiveSexprs
19
- const angle = toNumberValue(rawAngle)
20
-
21
- if (angle === undefined) {
22
- throw new Error("gr_line angle expects a numeric value")
23
- }
24
-
25
- return new GrLineAngle(angle)
26
- }
27
-
28
- override getString(): string {
29
- return `(angle ${this.value})`
30
- }
31
- }
32
- SxClass.register(GrLineAngle)
@@ -1,61 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { toNumberValue } from "../utils/toNumberValue"
4
-
5
- export class GrLineEnd extends SxClass {
6
- static override token = "end"
7
- static override parentToken = "gr_line"
8
- override token = "end"
9
-
10
- private _x: number
11
- private _y: number
12
-
13
- constructor(x: number, y: number) {
14
- super()
15
- this._x = x
16
- this._y = y
17
- }
18
-
19
- static override fromSexprPrimitives(
20
- primitiveSexprs: PrimitiveSExpr[],
21
- ): GrLineEnd {
22
- const [rawX, rawY] = primitiveSexprs
23
- const x = toNumberValue(rawX)
24
- const y = toNumberValue(rawY)
25
-
26
- if (x === undefined || y === undefined) {
27
- throw new Error("gr_line end expects two numeric arguments")
28
- }
29
-
30
- return new GrLineEnd(x, y)
31
- }
32
-
33
- get x(): number {
34
- return this._x
35
- }
36
-
37
- set x(value: number) {
38
- this._x = value
39
- }
40
-
41
- get y(): number {
42
- return this._y
43
- }
44
-
45
- set y(value: number) {
46
- this._y = value
47
- }
48
-
49
- toObject(): { x: number; y: number } {
50
- return { x: this._x, y: this._y }
51
- }
52
-
53
- override getChildren(): SxClass[] {
54
- return []
55
- }
56
-
57
- override getString(): string {
58
- return `(end ${this._x} ${this._y})`
59
- }
60
- }
61
- SxClass.register(GrLineEnd)
@@ -1,40 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
4
-
5
- const truthyStrings = new Set(["true", "yes", "1"])
6
-
7
- export class GrLineLocked extends SxPrimitiveBoolean {
8
- static override token = "locked"
9
- static override parentToken = "gr_line"
10
- override token = "locked"
11
-
12
- constructor(value: boolean) {
13
- super(value)
14
- }
15
-
16
- static override fromSexprPrimitives(
17
- primitiveSexprs: PrimitiveSExpr[],
18
- ): GrLineLocked {
19
- const [rawValue] = primitiveSexprs
20
-
21
- if (rawValue === undefined) {
22
- return new GrLineLocked(true)
23
- }
24
-
25
- if (typeof rawValue === "boolean") {
26
- return new GrLineLocked(rawValue)
27
- }
28
-
29
- if (typeof rawValue === "string") {
30
- return new GrLineLocked(truthyStrings.has(rawValue.toLowerCase()))
31
- }
32
-
33
- return new GrLineLocked(false)
34
- }
35
-
36
- override getString(): string {
37
- return `(locked ${this.value ? "yes" : "no"})`
38
- }
39
- }
40
- SxClass.register(GrLineLocked)
@@ -1,61 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { toNumberValue } from "../utils/toNumberValue"
4
-
5
- export class GrLineStart extends SxClass {
6
- static override token = "start"
7
- static override parentToken = "gr_line"
8
- override token = "start"
9
-
10
- private _x: number
11
- private _y: number
12
-
13
- constructor(x: number, y: number) {
14
- super()
15
- this._x = x
16
- this._y = y
17
- }
18
-
19
- static override fromSexprPrimitives(
20
- primitiveSexprs: PrimitiveSExpr[],
21
- ): GrLineStart {
22
- const [rawX, rawY] = primitiveSexprs
23
- const x = toNumberValue(rawX)
24
- const y = toNumberValue(rawY)
25
-
26
- if (x === undefined || y === undefined) {
27
- throw new Error("gr_line start expects two numeric arguments")
28
- }
29
-
30
- return new GrLineStart(x, y)
31
- }
32
-
33
- get x(): number {
34
- return this._x
35
- }
36
-
37
- set x(value: number) {
38
- this._x = value
39
- }
40
-
41
- get y(): number {
42
- return this._y
43
- }
44
-
45
- set y(value: number) {
46
- this._y = value
47
- }
48
-
49
- toObject(): { x: number; y: number } {
50
- return { x: this._x, y: this._y }
51
- }
52
-
53
- override getChildren(): SxClass[] {
54
- return []
55
- }
56
-
57
- override getString(): string {
58
- return `(start ${this._x} ${this._y})`
59
- }
60
- }
61
- SxClass.register(GrLineStart)
@@ -1,228 +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 { Xy } from "./Xy"
7
- import { Layer } from "./Layer"
8
- import { TextEffects } from "./TextEffects"
9
- import { Uuid } from "./Uuid"
10
-
11
- export interface GrTextPosition {
12
- x: number
13
- y: number
14
- angle?: number
15
- }
16
-
17
- const SUPPORTED_SINGLE_TOKENS = new Set([
18
- "at",
19
- "xy",
20
- "layer",
21
- "uuid",
22
- "effects",
23
- ])
24
-
25
- export interface GrTextConstructorParams {
26
- text?: string
27
- position?: AtInput | Xy | GrTextPosition
28
- layer?: Layer | string | Array<string | number>
29
- uuid?: Uuid | string
30
- effects?: TextEffects
31
- }
32
-
33
- export class GrText extends SxClass {
34
- static override token = "gr_text"
35
- override token = "gr_text"
36
-
37
- private _text = ""
38
- private _sxPosition?: At | Xy
39
- private _sxLayer?: Layer
40
- private _sxUuid?: Uuid
41
- private _sxEffects?: TextEffects
42
-
43
- constructor(params: GrTextConstructorParams | string = {}) {
44
- super()
45
- if (typeof params === "string") {
46
- this.text = params
47
- } else {
48
- if (params.text !== undefined) this.text = params.text
49
- if (params.position !== undefined) this.position = params.position
50
- if (params.layer !== undefined) this.layer = params.layer
51
- if (params.uuid !== undefined) this.uuid = params.uuid
52
- if (params.effects !== undefined) this.effects = params.effects
53
- }
54
- }
55
-
56
- static override fromSexprPrimitives(
57
- primitiveSexprs: PrimitiveSExpr[],
58
- ): GrText {
59
- if (primitiveSexprs.length === 0) {
60
- throw new Error("gr_text requires a text argument")
61
- }
62
-
63
- const [rawText, ...rest] = primitiveSexprs
64
- const text = toStringValue(rawText)
65
- if (text === undefined) {
66
- throw new Error("gr_text text must be a string value")
67
- }
68
-
69
- const grText = new GrText(text)
70
-
71
- const { propertyMap, arrayPropertyMap } =
72
- SxClass.parsePrimitivesToClassProperties(rest, this.token)
73
-
74
- const unexpectedTokens = new Set<string>()
75
- for (const token of Object.keys(propertyMap)) {
76
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
77
- unexpectedTokens.add(token)
78
- }
79
- }
80
- for (const token of Object.keys(arrayPropertyMap)) {
81
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
82
- unexpectedTokens.add(token)
83
- continue
84
- }
85
- if (arrayPropertyMap[token]!.length > 1) {
86
- throw new Error(
87
- `gr_text does not support repeated child tokens: ${token}`,
88
- )
89
- }
90
- }
91
-
92
- if (unexpectedTokens.size > 0) {
93
- throw new Error(
94
- `Unsupported child tokens inside gr_text expression: ${[...unexpectedTokens].join(", ")}`,
95
- )
96
- }
97
-
98
- for (const primitive of rest) {
99
- if (Array.isArray(primitive)) continue
100
- throw new Error(
101
- `gr_text encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
102
- )
103
- }
104
-
105
- const atInstance = propertyMap.at as At | undefined
106
- const xyInstance = propertyMap.xy as Xy | undefined
107
- if (atInstance && xyInstance) {
108
- throw new Error("gr_text cannot include both at and xy tokens")
109
- }
110
-
111
- grText._sxPosition = atInstance ?? xyInstance
112
- grText._sxLayer = propertyMap.layer as Layer | undefined
113
- grText._sxUuid = propertyMap.uuid as Uuid | undefined
114
- grText._sxEffects = propertyMap.effects as TextEffects | undefined
115
-
116
- if (!grText._sxPosition) {
117
- throw new Error("gr_text requires a position child token")
118
- }
119
- if (!grText._sxLayer) {
120
- throw new Error("gr_text requires a layer child token")
121
- }
122
- if (!grText._sxUuid) {
123
- throw new Error("gr_text requires a uuid child token")
124
- }
125
- if (!grText._sxEffects) {
126
- throw new Error("gr_text requires an effects child token")
127
- }
128
-
129
- return grText
130
- }
131
-
132
- get text(): string {
133
- return this._text
134
- }
135
-
136
- set text(value: string) {
137
- this._text = value
138
- }
139
-
140
- get position(): At | Xy | undefined {
141
- return this._sxPosition
142
- }
143
-
144
- set position(value: AtInput | Xy | GrTextPosition | undefined,) {
145
- if (value === undefined) {
146
- this._sxPosition = undefined
147
- return
148
- }
149
- if (value instanceof Xy) {
150
- this._sxPosition = value
151
- return
152
- }
153
- // Check if it's GrTextPosition (plain object with x, y)
154
- if (
155
- typeof value === "object" &&
156
- "x" in value &&
157
- "y" in value &&
158
- !Array.isArray(value) &&
159
- !(value instanceof At)
160
- ) {
161
- const { x, y, angle } = value as GrTextPosition
162
- if (angle !== undefined) {
163
- this._sxPosition = new At([x, y, angle])
164
- } else {
165
- this._sxPosition = new Xy(x, y)
166
- }
167
- return
168
- }
169
- // Handle AtInput (At, array, or object with angle)
170
- this._sxPosition = At.from(value as AtInput)
171
- }
172
-
173
- get layer(): Layer | undefined {
174
- return this._sxLayer
175
- }
176
-
177
- set layer(value: Layer | string | Array<string | number> | undefined) {
178
- if (value === undefined) {
179
- this._sxLayer = undefined
180
- return
181
- }
182
- if (value instanceof Layer) {
183
- this._sxLayer = value
184
- return
185
- }
186
- const names = Array.isArray(value) ? value : [value]
187
- this._sxLayer = new Layer(names)
188
- }
189
-
190
- get uuid(): Uuid | undefined {
191
- return this._sxUuid
192
- }
193
-
194
- set uuid(value: Uuid | string | undefined) {
195
- if (value === undefined) {
196
- this._sxUuid = undefined
197
- return
198
- }
199
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
200
- }
201
-
202
- get effects(): TextEffects | undefined {
203
- return this._sxEffects
204
- }
205
-
206
- set effects(value: TextEffects | undefined) {
207
- this._sxEffects = value
208
- }
209
-
210
- override getChildren(): SxClass[] {
211
- const children: SxClass[] = []
212
- if (this._sxPosition) children.push(this._sxPosition)
213
- if (this._sxLayer) children.push(this._sxLayer)
214
- if (this._sxUuid) children.push(this._sxUuid)
215
- if (this._sxEffects) children.push(this._sxEffects)
216
- return children
217
- }
218
-
219
- override getString(): string {
220
- const lines = ["(gr_text", ` ${quoteSExprString(this._text)}`]
221
- for (const child of this.getChildren()) {
222
- lines.push(child.getStringIndented())
223
- }
224
- lines.push(")")
225
- return lines.join("\n")
226
- }
227
- }
228
- SxClass.register(GrText)
@@ -1,283 +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 { Uuid } from "./Uuid"
8
- import { At, type AtInput } from "./At"
9
- import { Xy } from "./Xy"
10
-
11
- const SUPPORTED_SINGLE_TOKENS = new Set([
12
- "at",
13
- "xy",
14
- "scale",
15
- "layer",
16
- "uuid",
17
- "data",
18
- ])
19
-
20
- const SUPPORTED_MULTI_TOKENS = new Set<string>()
21
-
22
- export interface ImageConstructorParams {
23
- position?: AtInput | Xy
24
- scale?: ImageScale | number
25
- layer?: Layer | string | string[]
26
- uuid?: Uuid | string
27
- data?: ImageData | string | string[]
28
- }
29
-
30
- export class Image extends SxClass {
31
- static override token = "image"
32
- token = "image"
33
-
34
- private _sxPosition?: At | Xy
35
- private _sxScale?: ImageScale
36
- private _sxLayer?: Layer
37
- private _sxUuid?: Uuid
38
- private _sxData?: ImageData
39
-
40
- constructor(params: ImageConstructorParams = {}) {
41
- super()
42
-
43
- if (params.position !== undefined) this.position = params.position
44
- if (params.scale !== undefined) this.scale = params.scale
45
- if (params.layer !== undefined) this.layer = params.layer
46
- if (params.uuid !== undefined) this.uuid = params.uuid
47
- if (params.data !== undefined) this.data = params.data
48
- }
49
-
50
- static override fromSexprPrimitives(
51
- primitiveSexprs: PrimitiveSExpr[],
52
- ): Image {
53
- const image = new Image()
54
-
55
- const structuredPrimitives: PrimitiveSExpr[] = []
56
-
57
- for (const primitive of primitiveSexprs) {
58
- if (!Array.isArray(primitive) || primitive.length === 0) {
59
- throw new Error(
60
- `image encountered invalid child expression: ${JSON.stringify(primitive)}`,
61
- )
62
- }
63
-
64
- structuredPrimitives.push(primitive)
65
- }
66
-
67
- const { propertyMap, arrayPropertyMap } =
68
- SxClass.parsePrimitivesToClassProperties(structuredPrimitives, this.token)
69
-
70
- for (const token of Object.keys(propertyMap)) {
71
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
72
- throw new Error(`image encountered unsupported child token "${token}"`)
73
- }
74
- }
75
-
76
- for (const [token, entries] of Object.entries(arrayPropertyMap)) {
77
- if (!SUPPORTED_SINGLE_TOKENS.has(token)) {
78
- throw new Error(`image encountered unsupported child token "${token}"`)
79
- }
80
- if (!SUPPORTED_MULTI_TOKENS.has(token) && entries.length > 1) {
81
- throw new Error(
82
- `image does not support repeated child token "${token}"`,
83
- )
84
- }
85
- }
86
-
87
- const atInstance = propertyMap.at as At | undefined
88
- const xyInstance = propertyMap.xy as Xy | undefined
89
- if (atInstance && xyInstance) {
90
- throw new Error("image cannot include both at and xy child tokens")
91
- }
92
-
93
- image._sxPosition = atInstance ?? xyInstance
94
- image._sxScale = propertyMap.scale as ImageScale | undefined
95
- image._sxLayer = propertyMap.layer as Layer | undefined
96
- image._sxUuid = propertyMap.uuid as Uuid | undefined
97
- image._sxData = propertyMap.data as ImageData | undefined
98
-
99
- return image
100
- }
101
-
102
- get position(): At | Xy | undefined {
103
- return this._sxPosition
104
- }
105
-
106
- set position(value: AtInput | Xy | undefined) {
107
- if (value === undefined) {
108
- this._sxPosition = undefined
109
- return
110
- }
111
- if (value instanceof Xy) {
112
- this._sxPosition = value
113
- return
114
- }
115
- // Handle AtInput (At, array, or object)
116
- this._sxPosition = At.from(value as AtInput)
117
- }
118
-
119
- get scale(): ImageScale | undefined {
120
- return this._sxScale
121
- }
122
-
123
- set scale(value: ImageScale | number | undefined) {
124
- if (value === undefined) {
125
- this._sxScale = undefined
126
- return
127
- }
128
- this._sxScale = value instanceof ImageScale ? value : new ImageScale(value)
129
- }
130
-
131
- get layer(): Layer | undefined {
132
- return this._sxLayer
133
- }
134
-
135
- set layer(value: Layer | string | string[] | undefined) {
136
- if (value === undefined) {
137
- this._sxLayer = undefined
138
- return
139
- }
140
- if (value instanceof Layer) {
141
- this._sxLayer = value
142
- } else {
143
- const names = Array.isArray(value) ? value : [value]
144
- this._sxLayer = new Layer(names)
145
- }
146
- }
147
-
148
- get uuid(): Uuid | undefined {
149
- return this._sxUuid
150
- }
151
-
152
- set uuid(value: Uuid | string | undefined) {
153
- if (value === undefined) {
154
- this._sxUuid = undefined
155
- return
156
- }
157
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
158
- }
159
-
160
- get data(): ImageData | undefined {
161
- return this._sxData
162
- }
163
-
164
- set data(value: ImageData | string | string[] | undefined) {
165
- if (value === undefined) {
166
- this._sxData = undefined
167
- return
168
- }
169
- if (value instanceof ImageData) {
170
- this._sxData = value
171
- } else if (Array.isArray(value)) {
172
- this._sxData = ImageData.fromStrings(value)
173
- } else {
174
- this._sxData = ImageData.fromStrings([value])
175
- }
176
- }
177
-
178
- override getChildren(): SxClass[] {
179
- const children: SxClass[] = []
180
- if (this._sxPosition) children.push(this._sxPosition)
181
- if (this._sxScale) children.push(this._sxScale)
182
- if (this._sxLayer) children.push(this._sxLayer)
183
- if (this._sxUuid) children.push(this._sxUuid)
184
- if (this._sxData) children.push(this._sxData)
185
- return children
186
- }
187
- }
188
- SxClass.register(Image)
189
-
190
- export class ImageScale extends SxClass {
191
- static override token = "scale"
192
- static override parentToken = "image"
193
- token = "scale"
194
-
195
- value: number
196
-
197
- constructor(value: number) {
198
- super()
199
- this.value = value
200
- }
201
-
202
- static override fromSexprPrimitives(
203
- primitiveSexprs: PrimitiveSExpr[],
204
- ): ImageScale {
205
- const [raw] = primitiveSexprs
206
- const numeric = toNumberValue(raw)
207
- return new ImageScale(numeric ?? 1)
208
- }
209
-
210
- override getChildren(): SxClass[] {
211
- return []
212
- }
213
-
214
- override getString(): string {
215
- return `(scale ${this.value})`
216
- }
217
- }
218
- SxClass.register(ImageScale)
219
-
220
- export class ImageData extends SxClass {
221
- static override token = "data"
222
- static override parentToken = "image"
223
- token = "data"
224
-
225
- private _chunks: string[]
226
-
227
- constructor(chunks: string[] = []) {
228
- super()
229
- this._chunks = chunks
230
- }
231
-
232
- static override fromSexprPrimitives(
233
- primitiveSexprs: PrimitiveSExpr[],
234
- ): ImageData {
235
- const chunks = primitiveSexprs.map((primitive) =>
236
- primitiveToChunk(primitive),
237
- )
238
- return new ImageData(chunks)
239
- }
240
-
241
- static fromStrings(values: string[]): ImageData {
242
- return new ImageData(values)
243
- }
244
-
245
- get chunks(): string[] {
246
- return [...this._chunks]
247
- }
248
-
249
- set chunks(values: string[]) {
250
- this._chunks = [...values]
251
- }
252
-
253
- get value(): string {
254
- return this._chunks.join("")
255
- }
256
-
257
- set value(data: string) {
258
- this._chunks = [data]
259
- }
260
-
261
- override getChildren(): SxClass[] {
262
- return []
263
- }
264
-
265
- override getString(): string {
266
- if (this._chunks.length === 0) {
267
- return "(data)"
268
- }
269
- const rendered = this._chunks
270
- .map((chunk) => quoteSExprString(chunk))
271
- .join(" ")
272
- return `(data ${rendered})`
273
- }
274
- }
275
- SxClass.register(ImageData)
276
-
277
- function primitiveToChunk(value: PrimitiveSExpr): string {
278
- const stringValue = toStringValue(value)
279
- if (stringValue !== undefined) {
280
- return stringValue
281
- }
282
- return printSExpr(value)
283
- }
@@ -1,8 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
3
-
4
- export class InBom extends SxPrimitiveBoolean {
5
- static override token = "in_bom"
6
- token = "in_bom"
7
- }
8
- SxClass.register(InBom)