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,16 +0,0 @@
1
- import { SxPrimitiveString } from "../base-classes/SxPrimitiveString"
2
- import { SxClass } from "../base-classes/SxClass"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
-
5
- const isSymbol = (value: string) => /^[A-Za-z0-9._-]+$/.test(value)
6
-
7
- export class PcbGeneratorVersion extends SxPrimitiveString {
8
- static override token = "generator_version"
9
- static override parentToken = "kicad_pcb"
10
- token = "generator_version"
11
-
12
- override getString(): string {
13
- return `(generator_version ${isSymbol(this.value) ? this.value : quoteSExprString(this.value)})`
14
- }
15
- }
16
- SxClass.register(PcbGeneratorVersion)
@@ -1,106 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
- import { toNumberValue } from "../utils/toNumberValue"
5
- import { toStringValue } from "../utils/toStringValue"
6
-
7
- export class PcbLayerDefinition extends SxClass {
8
- static override token = "__pcb_layer_definition__"
9
- static override parentToken = "layers"
10
- token = "__pcb_layer_definition__"
11
-
12
- private _index?: number
13
- private _name?: string
14
- private _type?: string
15
- private _userName?: string
16
-
17
- constructor(options: {
18
- index?: number
19
- name?: string
20
- type?: string
21
- userName?: string
22
- }) {
23
- super()
24
- this._index = options.index
25
- this._name = options.name
26
- this._type = options.type
27
- this._userName = options.userName
28
- }
29
-
30
- static fromPrimitive(primitive: PrimitiveSExpr): PcbLayerDefinition {
31
- if (!Array.isArray(primitive) || primitive.length < 3) {
32
- throw new Error(
33
- `layers entry must be an array with at least index, name, and type: ${JSON.stringify(primitive)}`,
34
- )
35
- }
36
- const [rawIndex, rawName, rawType, rawUser] = primitive
37
- const index = toNumberValue(rawIndex)
38
- const name = toStringValue(rawName)
39
- const type = toStringValue(rawType)
40
- const userName = rawUser === undefined ? undefined : toStringValue(rawUser)
41
-
42
- if (index === undefined || name === undefined || type === undefined) {
43
- throw new Error(
44
- `layers entry is missing required values: ${JSON.stringify(primitive)}`,
45
- )
46
- }
47
-
48
- return new PcbLayerDefinition({ index, name, type, userName })
49
- }
50
-
51
- get index(): number | undefined {
52
- return this._index
53
- }
54
-
55
- set index(value: number | undefined) {
56
- this._index = value
57
- }
58
-
59
- get name(): string | undefined {
60
- return this._name
61
- }
62
-
63
- set name(value: string | undefined) {
64
- this._name = value
65
- }
66
-
67
- get type(): string | undefined {
68
- return this._type
69
- }
70
-
71
- set type(value: string | undefined) {
72
- this._type = value
73
- }
74
-
75
- get userName(): string | undefined {
76
- return this._userName
77
- }
78
-
79
- set userName(value: string | undefined) {
80
- this._userName = value
81
- }
82
-
83
- override getChildren(): SxClass[] {
84
- return []
85
- }
86
-
87
- override getString(): string {
88
- if (
89
- this._index === undefined ||
90
- this._name === undefined ||
91
- this._type === undefined
92
- ) {
93
- return "()"
94
- }
95
- const tokens = [
96
- String(this._index),
97
- quoteSExprString(this._name),
98
- this._type,
99
- ]
100
- if (this._userName !== undefined) {
101
- tokens.push(quoteSExprString(this._userName))
102
- }
103
- return `(${tokens.join(" ")})`
104
- }
105
- }
106
- SxClass.register(PcbLayerDefinition)
@@ -1,34 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { PcbLayerDefinition } from "./PcbLayerDefinition"
4
-
5
- export class PcbLayers extends SxClass {
6
- static override token = "layers"
7
- static override parentToken = "kicad_pcb"
8
- token = "layers"
9
-
10
- private _definitions: PcbLayerDefinition[] = []
11
-
12
- static override fromSexprPrimitives(
13
- primitiveSexprs: PrimitiveSExpr[],
14
- ): PcbLayers {
15
- const layers = new PcbLayers()
16
- layers._definitions = primitiveSexprs.map((primitive) =>
17
- PcbLayerDefinition.fromPrimitive(primitive),
18
- )
19
- return layers
20
- }
21
-
22
- get definitions(): PcbLayerDefinition[] {
23
- return [...this._definitions]
24
- }
25
-
26
- set definitions(value: PcbLayerDefinition[]) {
27
- this._definitions = [...value]
28
- }
29
-
30
- override getChildren(): SxClass[] {
31
- return [...this._definitions]
32
- }
33
- }
34
- SxClass.register(PcbLayers)
@@ -1,56 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { quoteSExprString } from "../utils/quoteSExprString"
4
- import { toNumberValue } from "../utils/toNumberValue"
5
- import { toStringValue } from "../utils/toStringValue"
6
-
7
- export class PcbNet extends SxClass {
8
- static override token = "net"
9
- static override parentToken = "kicad_pcb"
10
- token = "net"
11
-
12
- private _id: number
13
- private _name: string
14
-
15
- constructor(id: number, name: string) {
16
- super()
17
- this._id = id
18
- this._name = name
19
- }
20
-
21
- static override fromSexprPrimitives(
22
- primitiveSexprs: PrimitiveSExpr[],
23
- ): PcbNet {
24
- const id = toNumberValue(primitiveSexprs[0])
25
- const name = toStringValue(primitiveSexprs[1])
26
- if (id === undefined || name === undefined) {
27
- throw new Error("net requires numeric id and string name")
28
- }
29
- return new PcbNet(id, name)
30
- }
31
-
32
- get id(): number {
33
- return this._id
34
- }
35
-
36
- set id(value: number) {
37
- this._id = value
38
- }
39
-
40
- get name(): string {
41
- return this._name
42
- }
43
-
44
- set name(value: string) {
45
- this._name = value
46
- }
47
-
48
- override getChildren(): SxClass[] {
49
- return []
50
- }
51
-
52
- override getString(): string {
53
- return `(net ${this._id} ${quoteSExprString(this._name)})`
54
- }
55
- }
56
- SxClass.register(PcbNet)
@@ -1,9 +0,0 @@
1
- import { SxPrimitiveNumber } from "../base-classes/SxPrimitiveNumber"
2
- import { SxClass } from "../base-classes/SxClass"
3
-
4
- export class PcbVersion extends SxPrimitiveNumber {
5
- static override token = "version"
6
- static override parentToken = "kicad_pcb"
7
- token = "version"
8
- }
9
- SxClass.register(PcbVersion)
@@ -1,301 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { printSExpr } from "../parseToPrimitiveSExpr"
4
- import { quoteSExprString } from "../utils/quoteSExprString"
5
- import { toStringValue } from "../utils/toStringValue"
6
- import { At, type AtInput } from "./At"
7
- import { Layer } from "./Layer"
8
- import { PropertyHide } from "./PropertyHide"
9
- import { PropertyUnlocked } from "./PropertyUnlocked"
10
- import { TextEffects } from "./TextEffects"
11
- import { Uuid } from "./Uuid"
12
- import { Xy } from "./Xy"
13
-
14
- const SUPPORTED_SINGLE_CHILDREN = new Set([
15
- "at",
16
- "xy",
17
- "layer",
18
- "uuid",
19
- "effects",
20
- "unlocked",
21
- "hide",
22
- ])
23
-
24
- const ensureSingleChild = (
25
- arrayPropertyMap: Record<string, SxClass[]>,
26
- token: string,
27
- ) => {
28
- const entries = arrayPropertyMap[token]
29
- if (entries && entries.length > 1) {
30
- throw new Error(`property does not support repeated "${token}" children`)
31
- }
32
- }
33
-
34
- const primitiveToString = (
35
- value: PrimitiveSExpr | undefined,
36
- ): string | undefined => {
37
- if (value === undefined) {
38
- return undefined
39
- }
40
- const asString = toStringValue(value)
41
- if (asString !== undefined) {
42
- return asString
43
- }
44
- return printSExpr(value)
45
- }
46
-
47
- export interface PropertyConstructorParams {
48
- key?: string
49
- value?: string
50
- position?: AtInput | Xy
51
- layer?: Layer | Array<string | number> | string
52
- uuid?: string | Uuid
53
- effects?: TextEffects
54
- unlocked?: boolean | PropertyUnlocked
55
- hidden?: boolean | PropertyHide
56
- }
57
-
58
- export class Property extends SxClass {
59
- static override token = "property"
60
- token = "property"
61
-
62
- private _key = ""
63
- private _value = ""
64
- private _sxAt?: At
65
- private _sxXy?: Xy
66
- private _sxLayer?: Layer
67
- private _sxUuid?: Uuid
68
- private _sxEffects?: TextEffects
69
- private _sxUnlocked?: PropertyUnlocked
70
- private _sxHide?: PropertyHide
71
-
72
- constructor(
73
- keyOrParams: string | PropertyConstructorParams = {},
74
- value = "",
75
- ) {
76
- super()
77
-
78
- // Support both old constructor signature and new params interface
79
- if (typeof keyOrParams === "string") {
80
- this._key = keyOrParams
81
- this._value = value
82
- } else {
83
- const params = keyOrParams
84
- if (params.key !== undefined) {
85
- this._key = params.key
86
- }
87
- if (params.value !== undefined) {
88
- this._value = params.value
89
- }
90
- if (params.position !== undefined) {
91
- this.position = params.position
92
- }
93
- if (params.layer !== undefined) {
94
- this.layer = params.layer
95
- }
96
- if (params.uuid !== undefined) {
97
- this.uuid = params.uuid
98
- }
99
- if (params.effects !== undefined) {
100
- this.effects = params.effects
101
- }
102
- if (params.unlocked !== undefined) {
103
- if (params.unlocked instanceof PropertyUnlocked) {
104
- this._sxUnlocked = params.unlocked
105
- } else {
106
- this.unlocked = params.unlocked
107
- }
108
- }
109
- if (params.hidden !== undefined) {
110
- if (params.hidden instanceof PropertyHide) {
111
- this._sxHide = params.hidden
112
- } else {
113
- this.hidden = params.hidden
114
- }
115
- }
116
- }
117
- }
118
-
119
- static override fromSexprPrimitives(
120
- primitiveSexprs: PrimitiveSExpr[],
121
- ): Property {
122
- if (primitiveSexprs.length < 2) {
123
- throw new Error("property requires key and value arguments")
124
- }
125
-
126
- const [rawKey, rawValue, ...rest] = primitiveSexprs
127
-
128
- const key = primitiveToString(rawKey)
129
- const value = primitiveToString(rawValue)
130
- if (key === undefined) {
131
- throw new Error("property key must be a printable value")
132
- }
133
- if (value === undefined) {
134
- throw new Error("property value must be a printable value")
135
- }
136
-
137
- for (const primitive of rest) {
138
- if (!Array.isArray(primitive)) {
139
- throw new Error(
140
- `property encountered unexpected primitive child: ${JSON.stringify(primitive)}`,
141
- )
142
- }
143
- if (primitive.length === 0 || typeof primitive[0] !== "string") {
144
- throw new Error(
145
- `property encountered invalid child expression: ${JSON.stringify(primitive)}`,
146
- )
147
- }
148
- }
149
-
150
- const property = new Property(key, value)
151
-
152
- const { propertyMap, arrayPropertyMap } =
153
- SxClass.parsePrimitivesToClassProperties(rest, this.token)
154
-
155
- for (const token of Object.keys(propertyMap)) {
156
- if (!SUPPORTED_SINGLE_CHILDREN.has(token)) {
157
- throw new Error(
158
- `property encountered unsupported child token "${token}"`,
159
- )
160
- }
161
- }
162
-
163
- for (const token of Object.keys(arrayPropertyMap)) {
164
- if (!SUPPORTED_SINGLE_CHILDREN.has(token)) {
165
- throw new Error(
166
- `property encountered unsupported child token "${token}"`,
167
- )
168
- }
169
- ensureSingleChild(arrayPropertyMap, token)
170
- }
171
-
172
- const at = propertyMap.at as At | undefined
173
- const xy = propertyMap.xy as Xy | undefined
174
- if (at && xy) {
175
- throw new Error("property can't include both at and xy children")
176
- }
177
-
178
- property._sxAt = at
179
- property._sxXy = xy
180
- property._sxLayer = propertyMap.layer as Layer | undefined
181
- property._sxUuid = propertyMap.uuid as Uuid | undefined
182
- property._sxEffects = propertyMap.effects as TextEffects | undefined
183
- property._sxUnlocked = propertyMap.unlocked as PropertyUnlocked | undefined
184
- property._sxHide = propertyMap.hide as PropertyHide | undefined
185
-
186
- return property
187
- }
188
-
189
- get key(): string {
190
- return this._key
191
- }
192
-
193
- set key(value: string) {
194
- this._key = value
195
- }
196
-
197
- get value(): string {
198
- return this._value
199
- }
200
-
201
- set value(value: string) {
202
- this._value = value
203
- }
204
-
205
- get position(): At | Xy | undefined {
206
- return this._sxAt ?? this._sxXy
207
- }
208
-
209
- set position(value: AtInput | Xy | undefined) {
210
- if (value === undefined) {
211
- this._sxAt = undefined
212
- this._sxXy = undefined
213
- return
214
- }
215
- if (value instanceof Xy) {
216
- this._sxXy = value
217
- this._sxAt = undefined
218
- return
219
- }
220
- // Handle AtInput (At, array, or object)
221
- this._sxAt = At.from(value as AtInput)
222
- this._sxXy = undefined
223
- }
224
-
225
- get layer(): Layer | undefined {
226
- return this._sxLayer
227
- }
228
-
229
- set layer(value: Layer | Array<string | number> | string | undefined) {
230
- if (value === undefined) {
231
- this._sxLayer = undefined
232
- return
233
- }
234
- if (value instanceof Layer) {
235
- this._sxLayer = value
236
- return
237
- }
238
- const names = Array.isArray(value) ? value : [value]
239
- this._sxLayer = new Layer(names)
240
- }
241
-
242
- get uuid(): Uuid | undefined {
243
- return this._sxUuid
244
- }
245
-
246
- set uuid(value: Uuid | string | undefined) {
247
- if (value === undefined) {
248
- this._sxUuid = undefined
249
- return
250
- }
251
- this._sxUuid = value instanceof Uuid ? value : new Uuid(value)
252
- }
253
-
254
- get effects(): TextEffects | undefined {
255
- return this._sxEffects
256
- }
257
-
258
- set effects(value: TextEffects | undefined) {
259
- this._sxEffects = value
260
- }
261
-
262
- get unlocked(): boolean {
263
- return this._sxUnlocked?.value ?? false
264
- }
265
-
266
- set unlocked(value: boolean) {
267
- this._sxUnlocked = new PropertyUnlocked(value)
268
- }
269
-
270
- get hidden(): boolean {
271
- return this._sxHide?.value ?? false
272
- }
273
-
274
- set hidden(value: boolean) {
275
- this._sxHide = new PropertyHide(value)
276
- }
277
-
278
- override getChildren(): SxClass[] {
279
- const children: SxClass[] = []
280
- if (this._sxAt) children.push(this._sxAt)
281
- if (this._sxXy) children.push(this._sxXy)
282
- if (this._sxUnlocked) children.push(this._sxUnlocked)
283
- if (this._sxLayer) children.push(this._sxLayer)
284
- if (this._sxHide) children.push(this._sxHide)
285
- if (this._sxUuid) children.push(this._sxUuid)
286
- if (this._sxEffects) children.push(this._sxEffects)
287
- return children
288
- }
289
-
290
- override getString(): string {
291
- const lines = [
292
- `(property ${quoteSExprString(this._key)} ${quoteSExprString(this._value)}`,
293
- ]
294
- for (const child of this.getChildren()) {
295
- lines.push(child.getStringIndented())
296
- }
297
- lines.push(")")
298
- return lines.join("\n")
299
- }
300
- }
301
- SxClass.register(Property)
@@ -1,9 +0,0 @@
1
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
2
- import { SxClass } from "../base-classes/SxClass"
3
-
4
- export class PropertyHide extends SxPrimitiveBoolean {
5
- static override token = "hide"
6
- static override parentToken = "property"
7
- token = "hide"
8
- }
9
- SxClass.register(PropertyHide)
@@ -1,9 +0,0 @@
1
- import { SxPrimitiveBoolean } from "../base-classes/SxPrimitiveBoolean"
2
- import { SxClass } from "../base-classes/SxClass"
3
-
4
- export class PropertyUnlocked extends SxPrimitiveBoolean {
5
- static override token = "unlocked"
6
- static override parentToken = "property"
7
- token = "unlocked"
8
- }
9
- SxClass.register(PropertyUnlocked)
@@ -1,67 +0,0 @@
1
- import { SxClass } from "../base-classes/SxClass"
2
- import type { PrimitiveSExpr } from "../parseToPrimitiveSExpr"
3
- import { printSExpr } from "../parseToPrimitiveSExpr"
4
- import { Xy } from "./Xy"
5
-
6
- export class Pts extends SxClass {
7
- static override token = "pts"
8
- token = "pts"
9
-
10
- points: Array<Xy>
11
-
12
- constructor(points: Array<Xy> = []) {
13
- super()
14
- this.points = points
15
- }
16
-
17
- static override fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): Pts {
18
- const points: Xy[] = []
19
-
20
- for (const primitive of primitiveSexprs) {
21
- if (!Array.isArray(primitive) || primitive.length === 0) {
22
- throw new Error(
23
- `Unexpected primitive inside pts: ${printSExpr(primitive)}`,
24
- )
25
- }
26
-
27
- const parsed = SxClass.parsePrimitiveSexpr(primitive, {
28
- parentToken: this.token,
29
- })
30
-
31
- if (parsed instanceof Xy) {
32
- points.push(parsed)
33
- continue
34
- }
35
-
36
- if (parsed instanceof SxClass) {
37
- throw new Error(
38
- `Unsupported child "${parsed.token}" inside pts expression`,
39
- )
40
- }
41
-
42
- throw new Error(
43
- `Unable to parse child inside pts: ${printSExpr(primitive)}`,
44
- )
45
- }
46
-
47
- return new Pts(points)
48
- }
49
-
50
- override getChildren(): SxClass[] {
51
- return [...this.points]
52
- }
53
-
54
- override getString(): string {
55
- const lines = ["(pts"]
56
- for (const point of this.points) {
57
- const pointString = point.getString()
58
- const segments = pointString.split("\n")
59
- for (const segment of segments) {
60
- lines.push(` ${segment}`)
61
- }
62
- }
63
- lines.push(")")
64
- return lines.join("\n")
65
- }
66
- }
67
- SxClass.register(Pts)