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,78 +0,0 @@
1
- import {
2
- FootprintPad,
3
- PadLayers,
4
- PadNet,
5
- PadSize,
6
- PadDrill,
7
- SxClass,
8
- } from "lib/sexpr"
9
- import { expect, test } from "bun:test"
10
-
11
- test("FootprintPad", () => {
12
- const [pad] = SxClass.parse(`
13
- (pad "1" smd roundrect
14
- (at 1.5 -2.5 180)
15
- (size 1.2 0.6)
16
- (drill 0.3)
17
- (layers F.Cu F.Paste F.Mask)
18
- (roundrect_rratio 0.25)
19
- (chamfer top_left bottom_right)
20
- (solder_mask_margin 0.05)
21
- (solder_paste_margin_ratio -0.1)
22
- (clearance 0.15)
23
- (zone_connect 1)
24
- (thermal_gap 0.2)
25
- (thermal_width 0.12)
26
- (net 3 "SIG")
27
- (pinfunction "SIG")
28
- (pintype "input")
29
- (uuid 55555555-6666-7777-8888-999999999999)
30
- locked
31
- )
32
- `)
33
-
34
- expect(pad).toBeInstanceOf(FootprintPad)
35
- const fpPad = pad as FootprintPad
36
- expect(fpPad.number).toBe("1")
37
- expect(fpPad.padType).toBe("smd")
38
- expect(fpPad.shape).toBe("roundrect")
39
- expect(fpPad.at).toBeDefined()
40
- expect(fpPad.size).toBeInstanceOf(PadSize)
41
- expect(fpPad.size?.width).toBe(1.2)
42
- expect(fpPad.size?.height).toBe(0.6)
43
- expect(fpPad.drill).toBeInstanceOf(PadDrill)
44
- expect(fpPad.drill?.oval).toBe(false)
45
- expect(fpPad.drill?.diameter).toBe(0.3)
46
- expect(fpPad.layers).toBeInstanceOf(PadLayers)
47
- expect(fpPad.layers?.layers).toEqual(["F.Cu", "F.Paste", "F.Mask"])
48
- expect(fpPad.roundrectRatio).toBe(0.25)
49
- expect(fpPad.chamferCorners).toEqual(["top_left", "bottom_right"])
50
- expect(fpPad.net).toBeInstanceOf(PadNet)
51
- expect(fpPad.net?.id).toBe(3)
52
- expect(fpPad.net?.name).toBe("SIG")
53
- expect(fpPad.pinfunction).toBe("SIG")
54
- expect(fpPad.pintype).toBe("input")
55
- expect(fpPad.locked).toBe(true)
56
-
57
- expect(fpPad.getString()).toMatchInlineSnapshot(`
58
- "(pad \"1\" smd roundrect
59
- (at 1.5 -2.5 180)
60
- (size 1.2 0.6)
61
- (drill 0.3)
62
- (layers F.Cu F.Paste F.Mask)
63
- (roundrect_rratio 0.25)
64
- (chamfer top_left bottom_right)
65
- (net 3 \"SIG\")
66
- (pinfunction SIG)
67
- (pintype input)
68
- (solder_mask_margin 0.05)
69
- (solder_paste_margin_ratio -0.1)
70
- (clearance 0.15)
71
- (zone_connect 1)
72
- (thermal_width 0.12)
73
- (thermal_gap 0.2)
74
- (uuid 55555555-6666-7777-8888-999999999999)
75
- locked
76
- )"
77
- `)
78
- })
@@ -1,45 +0,0 @@
1
- import { FpArc, Layer, Stroke, SxClass } from "lib/sexpr"
2
- import { expect, test } from "bun:test"
3
-
4
- test("FpArc", () => {
5
- const [arc] = SxClass.parse(`
6
- (fp_arc
7
- (start 0 0)
8
- (mid 1 1)
9
- (end 2 0)
10
- (layer F.SilkS)
11
- (stroke (width 0.12) (type solid) (color 0 0 1 1))
12
- (uuid 12340000-0000-0000-0000-000000000000)
13
- )
14
- `)
15
-
16
- expect(arc).toBeInstanceOf(FpArc)
17
- const fpArc = arc as FpArc
18
- expect(fpArc.start?.x).toBe(0)
19
- expect(fpArc.mid?.y).toBe(1)
20
- expect(fpArc.end?.x).toBe(2)
21
- expect(fpArc.layer).toBeInstanceOf(Layer)
22
- expect(fpArc.stroke).toBeInstanceOf(Stroke)
23
- expect(fpArc.uuid).toBe("12340000-0000-0000-0000-000000000000")
24
-
25
- fpArc.width = 0.25
26
- expect(fpArc.width).toBe(0.25)
27
- fpArc.locked = true
28
-
29
- expect(fpArc.getString()).toMatchInlineSnapshot(`
30
- "(fp_arc
31
- (start 0 0)
32
- (mid 1 1)
33
- (end 2 0)
34
- (layer F.SilkS)
35
- (width 0.25)
36
- (stroke
37
- (width 0.12)
38
- (type solid)
39
- (color 0 0 1 1)
40
- )
41
- (uuid 12340000-0000-0000-0000-000000000000)
42
- locked
43
- )"
44
- `)
45
- })
@@ -1,39 +0,0 @@
1
- import { FpCircle, Layer, Stroke, SxClass } from "lib/sexpr"
2
- import { expect, test } from "bun:test"
3
-
4
- test("FpCircle", () => {
5
- const [circle] = SxClass.parse(`
6
- (fp_circle
7
- (center 1 1)
8
- (end 2 1)
9
- (layer F.SilkS)
10
- (stroke (width 0.1) (type dash) (color 0.2 0.2 0.2 1))
11
- (uuid 55555555-6666-7777-8888-999999999999)
12
- )
13
- `)
14
-
15
- expect(circle).toBeInstanceOf(FpCircle)
16
- const fpCircle = circle as FpCircle
17
- expect(fpCircle.center?.x).toBe(1)
18
- expect(fpCircle.end?.x).toBe(2)
19
- expect(fpCircle.layer).toBeInstanceOf(Layer)
20
- expect(fpCircle.stroke).toBeInstanceOf(Stroke)
21
- expect(fpCircle.uuid).toBe("55555555-6666-7777-8888-999999999999")
22
-
23
- fpCircle.locked = true
24
-
25
- expect(fpCircle.getString()).toMatchInlineSnapshot(`
26
- "(fp_circle
27
- (center 1 1)
28
- (end 2 1)
29
- (layer F.SilkS)
30
- (stroke
31
- (width 0.1)
32
- (type dash)
33
- (color 0.2 0.2 0.2 1)
34
- )
35
- (uuid 55555555-6666-7777-8888-999999999999)
36
- locked
37
- )"
38
- `)
39
- })
@@ -1,43 +0,0 @@
1
- import { FpPoly, Layer, Pts, Stroke, SxClass } from "lib/sexpr"
2
- import { expect, test } from "bun:test"
3
-
4
- test("FpPoly", () => {
5
- const [poly] = SxClass.parse(`
6
- (fp_poly
7
- (pts (xy 0 0) (xy 1 0) (xy 1 1) (xy 0 1))
8
- (layer F.SilkS)
9
- (stroke (width 0.1) (type solid) (color 0 0 0 1))
10
- (fill yes)
11
- (uuid 10101010-2020-3030-4040-505050505050)
12
- )
13
- `)
14
-
15
- expect(poly).toBeInstanceOf(FpPoly)
16
- const fpPoly = poly as FpPoly
17
- expect(fpPoly.points).toBeInstanceOf(Pts)
18
- expect(fpPoly.layer).toBeInstanceOf(Layer)
19
- expect(fpPoly.stroke).toBeInstanceOf(Stroke)
20
- expect(fpPoly.fill?.filled).toBe(true)
21
-
22
- fpPoly.locked = true
23
-
24
- expect(fpPoly.getString()).toMatchInlineSnapshot(`
25
- "(fp_poly
26
- (pts
27
- (xy 0 0)
28
- (xy 1 0)
29
- (xy 1 1)
30
- (xy 0 1)
31
- )
32
- (layer F.SilkS)
33
- (stroke
34
- (width 0.1)
35
- (type solid)
36
- (color 0 0 0 1)
37
- )
38
- (fill yes)
39
- (locked yes)
40
- (uuid 10101010-2020-3030-4040-505050505050)
41
- )"
42
- `)
43
- })
@@ -1,40 +0,0 @@
1
- import { FpRect, Layer, Stroke, SxClass } from "lib/sexpr"
2
- import { expect, test } from "bun:test"
3
-
4
- test("FpRect", () => {
5
- const [rect] = SxClass.parse(`
6
- (fp_rect
7
- (start 0 0)
8
- (end 5 5)
9
- (layer F.Cu)
10
- (stroke (width 0.2) (type solid) (color 1 0 0 1))
11
- (uuid 00000000-1111-2222-3333-444444444444)
12
- )
13
- `)
14
-
15
- expect(rect).toBeInstanceOf(FpRect)
16
- const fpRect = rect as FpRect
17
- expect(fpRect.start?.x).toBe(0)
18
- expect(fpRect.end?.y).toBe(5)
19
- expect(fpRect.layer).toBeInstanceOf(Layer)
20
- expect(fpRect.stroke).toBeInstanceOf(Stroke)
21
- expect(fpRect.uuid).toBe("00000000-1111-2222-3333-444444444444")
22
-
23
- fpRect.width = 0.3
24
- expect(fpRect.width).toBe(0.3)
25
-
26
- expect(fpRect.getString()).toMatchInlineSnapshot(`
27
- "(fp_rect
28
- (start 0 0)
29
- (end 5 5)
30
- (layer F.Cu)
31
- (width 0.3)
32
- (stroke
33
- (width 0.2)
34
- (type solid)
35
- (color 1 0 0 1)
36
- )
37
- (uuid 00000000-1111-2222-3333-444444444444)
38
- )"
39
- `)
40
- })
@@ -1,84 +0,0 @@
1
- import {
2
- FpTextBox,
3
- FpTextBoxAngle,
4
- FpTextBoxEnd,
5
- FpTextBoxStart,
6
- Layer,
7
- Pts,
8
- RenderCache,
9
- Stroke,
10
- TextEffects,
11
- Uuid,
12
- SxClass,
13
- } from "lib/sexpr"
14
- import { expect, test } from "bun:test"
15
-
16
- test("FpTextBox", () => {
17
- const [textBox] = SxClass.parse(`
18
- (fp_text_box locked "Notes"
19
- (start 0 0)
20
- (end 10 5)
21
- (pts (xy 0 0) (xy 10 0) (xy 10 5) (xy 0 5))
22
- (angle 45)
23
- (layer F.SilkS)
24
- (effects (font (size 1 1) (thickness 0.15)))
25
- (stroke (width 0.1) (type solid) (color 0 0 0 1))
26
- (uuid 11111111-2222-3333-4444-555555555555)
27
- (render_cache "Notes text" 0 0)
28
- )
29
- `)
30
-
31
- expect(textBox).toBeInstanceOf(FpTextBox)
32
- const fpTextBox = textBox as FpTextBox
33
-
34
- expect(fpTextBox.locked).toBe(true)
35
- expect(fpTextBox.text).toBe("Notes")
36
- expect(fpTextBox.start).toBeInstanceOf(FpTextBoxStart)
37
- expect(fpTextBox.start?.x).toBe(0)
38
- expect(fpTextBox.end).toBeInstanceOf(FpTextBoxEnd)
39
- expect(fpTextBox.end?.y).toBe(5)
40
- expect(fpTextBox.pts).toBeInstanceOf(Pts)
41
- expect(fpTextBox.pts?.points.length).toBe(4)
42
- expect(fpTextBox.angle).toBeInstanceOf(FpTextBoxAngle)
43
- expect(fpTextBox.angle?.value).toBe(45)
44
- expect(fpTextBox.layer).toBeInstanceOf(Layer)
45
- expect(fpTextBox.effects).toBeInstanceOf(TextEffects)
46
- expect(fpTextBox.stroke).toBeInstanceOf(Stroke)
47
- expect(fpTextBox.uuid).toBeInstanceOf(Uuid)
48
- expect(fpTextBox.renderCache).toBeInstanceOf(RenderCache)
49
- expect(fpTextBox.renderCache?.text).toBe("Notes text")
50
- expect(fpTextBox.renderCache?.angle).toBe(0)
51
- expect(fpTextBox.renderCache?.offsetX).toBe(0)
52
- expect(fpTextBox.renderCache?.offsetY).toBeUndefined()
53
-
54
- fpTextBox.locked = false
55
-
56
- expect(fpTextBox.getString()).toMatchInlineSnapshot(`
57
- "(fp_text_box
58
- \"Notes\"
59
- (start 0 0)
60
- (end 10 5)
61
- (pts
62
- (xy 0 0)
63
- (xy 10 0)
64
- (xy 10 5)
65
- (xy 0 5)
66
- )
67
- (angle 45)
68
- (layer F.SilkS)
69
- (effects
70
- (font
71
- (size 1 1)
72
- (thickness 0.15)
73
- )
74
- )
75
- (stroke
76
- (width 0.1)
77
- (type solid)
78
- (color 0 0 0 1)
79
- )
80
- (uuid 11111111-2222-3333-4444-555555555555)
81
- (render_cache \"Notes text\" 0 0)
82
- )"
83
- `)
84
- })
@@ -1,58 +0,0 @@
1
- import {
2
- At,
3
- Image,
4
- ImageData,
5
- ImageScale,
6
- Layer,
7
- SxClass,
8
- Uuid,
9
- } from "lib/sexpr"
10
- import { expect, test } from "bun:test"
11
-
12
- test("Image", () => {
13
- const [image] = SxClass.parse(`
14
- (image
15
- (at 12.7 25.4 90)
16
- (scale 0.75)
17
- (layer F.SilkS B.SilkS)
18
- (uuid 12345678-1234-1234-1234-123456789abc)
19
- (data iVBORw0KGgoAAAANSUhEUgAAAAUA)
20
- )
21
- `)
22
-
23
- expect(image).toBeInstanceOf(Image)
24
- const img = image as Image
25
-
26
- const at = img.position as At
27
- expect(at.x).toBe(12.7)
28
- expect(at.y).toBe(25.4)
29
- expect(at.angle).toBe(90)
30
-
31
- const scale = img.scale as ImageScale
32
- expect(scale.value).toBe(0.75)
33
-
34
- const layer = img.layer as Layer
35
- expect(layer.names).toEqual(["F.SilkS", "B.SilkS"])
36
-
37
- const uuid = img.uuid as Uuid
38
- expect(uuid.value).toBe("12345678-1234-1234-1234-123456789abc")
39
-
40
- const data = img.data as ImageData
41
- expect(data.value).toBe("iVBORw0KGgoAAAANSUhEUgAAAAUA")
42
-
43
- img.scale = 1.2
44
- img.layer = "F.Cu"
45
- img.uuid = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
46
- img.data = "ZGF0YQ=="
47
- img.position = new At([0, 0])
48
-
49
- expect(img.getString()).toMatchInlineSnapshot(`
50
- "(image
51
- (at 0 0)
52
- (scale 1.2)
53
- (layer F.Cu)
54
- (uuid aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee)
55
- (data \"ZGF0YQ==\")
56
- )"
57
- `)
58
- })
@@ -1,95 +0,0 @@
1
- import {
2
- KicadSch,
3
- Paper,
4
- Property,
5
- SchematicSymbol,
6
- Sheet,
7
- SxClass,
8
- TitleBlock,
9
- Wire,
10
- } from "lib/sexpr"
11
- import { expect, test } from "bun:test"
12
-
13
- test("KicadSch parse", () => {
14
- const [parsed] = SxClass.parse(`
15
- (kicad_sch
16
- (version 20240101)
17
- (generator kicad-cli)
18
- (uuid 01234567-89ab-cdef-0123-456789abcdef)
19
- (paper A4)
20
- (title_block
21
- (title "Demo")
22
- (company "Example Co")
23
- )
24
- (property "Sheetfile" "demo.kicad_sch")
25
- (sheet
26
- (at 0 0 0)
27
- (size 100 80)
28
- (uuid abcdefab-1234-5678-90ab-abcdefabcdef)
29
- )
30
- (symbol "Device:R"
31
- (at 25.4 12.7)
32
- (uuid fedcba98-7654-3210-fedc-ba9876543210)
33
- )
34
- (wire (pts (xy 0 0) (xy 10 10)))
35
- )
36
- `)
37
-
38
- expect(parsed).toBeInstanceOf(KicadSch)
39
- const schematic = parsed as KicadSch
40
-
41
- expect(schematic.version).toBe(20240101)
42
- expect(schematic.generator).toBe("kicad-cli")
43
- expect(schematic.uuid?.value).toBe("01234567-89ab-cdef-0123-456789abcdef")
44
-
45
- expect(schematic.paper).toBeInstanceOf(Paper)
46
- expect(schematic.titleBlock).toBeInstanceOf(TitleBlock)
47
- expect(schematic.titleBlock?.title).toBe("Demo")
48
- expect(schematic.titleBlock?.company).toBe("Example Co")
49
-
50
- expect(schematic.properties).toHaveLength(1)
51
- expect(schematic.properties[0]).toBeInstanceOf(Property)
52
- expect(schematic.properties[0]?.key).toBe("Sheetfile")
53
- expect(schematic.properties[0]?.value).toBe("demo.kicad_sch")
54
-
55
- expect(schematic.sheets).toHaveLength(1)
56
- expect(schematic.sheets[0]).toBeInstanceOf(Sheet)
57
-
58
- expect(schematic.symbols).toHaveLength(1)
59
- expect(schematic.symbols[0]).toBeInstanceOf(SchematicSymbol)
60
-
61
- expect(schematic.wires).toHaveLength(1)
62
- expect(schematic.wires[0]).toBeInstanceOf(Wire)
63
-
64
- expect(schematic.getString()).toMatchInlineSnapshot(`
65
- "(kicad_sch
66
- (version 20240101)
67
- (generator kicad-cli)
68
- (uuid 01234567-89ab-cdef-0123-456789abcdef)
69
- (paper
70
- A4
71
- )
72
- (title_block
73
- (title "Demo")
74
- (company "Example Co")
75
- )
76
- (property "Sheetfile" "demo.kicad_sch"
77
- )
78
- (sheet
79
- (at 0 0 0)
80
- (size 100 80)
81
- (uuid abcdefab-1234-5678-90ab-abcdefabcdef)
82
- )
83
- (symbol "Device:R"
84
- (at 25.4 12.7)
85
- (uuid fedcba98-7654-3210-fedc-ba9876543210)
86
- )
87
- (wire
88
- (pts
89
- (xy 0 0)
90
- (xy 10 10)
91
- )
92
- )
93
- )"
94
- `)
95
- })
@@ -1,30 +0,0 @@
1
- import { Paper, SxClass } from "lib/sexpr"
2
- import { expect, test } from "bun:test"
3
-
4
- test("Paper standard size", () => {
5
- const [paper] = SxClass.parse(`
6
- (paper
7
- A4
8
- portrait
9
- )
10
- `)
11
-
12
- expect(paper).toBeInstanceOf(Paper)
13
-
14
- const page = paper as Paper
15
- expect(page.size).toBe("A4")
16
- expect(page.customSize).toBeUndefined()
17
- expect(page.isPortrait).toBe(true)
18
-
19
- page.isPortrait = false
20
- page.customSize = { width: 210, height: 297 }
21
-
22
- expect(page.size).toBeUndefined()
23
- expect(page.customSize).toEqual({ width: 210, height: 297 })
24
-
25
- expect(page.getString()).toMatchInlineSnapshot(`
26
- "(paper
27
- 210 297
28
- )"
29
- `)
30
- })
@@ -1,48 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { At, Property, SxClass } from "lib/sexpr"
3
- import { parseToPrimitiveSExpr } from "lib/sexpr/parseToPrimitiveSExpr"
4
- import { expectEqualPrimitiveSExpr } from "../../fixtures/expectEqualPrimitiveSExpr"
5
-
6
- test("Property preserves extended attributes", () => {
7
- const input = `
8
- (property "Reference" "R1"
9
- (at 1 2 90)
10
- (unlocked yes)
11
- (layer "F.SilkS")
12
- (hide yes)
13
- (uuid 12345678-1234-1234-1234-123456789abc)
14
- (effects
15
- (font
16
- (size 1 1)
17
- (thickness 0.15)
18
- )
19
- )
20
- )
21
- `
22
-
23
- const [parsed] = SxClass.parse(input)
24
- expect(parsed).toBeInstanceOf(Property)
25
-
26
- const property = parsed as Property
27
- expect(property.key).toBe("Reference")
28
- expect(property.value).toBe("R1")
29
- const position = property.position
30
- expect(position).toBeInstanceOf(At)
31
- if (position instanceof At) {
32
- expect(position.x).toBe(1)
33
- expect(position.y).toBe(2)
34
- expect(position.angle).toBe(90)
35
- }
36
- expect(property.unlocked).toBe(true)
37
- expect(property.layer?.names).toEqual(["F.SilkS"])
38
- expect(property.hidden).toBe(true)
39
- expect(property.uuid?.value).toBe("12345678-1234-1234-1234-123456789abc")
40
- expect(property.effects).toBeDefined()
41
-
42
- const roundTrip = property.getString()
43
-
44
- const originalPrimitive = parseToPrimitiveSExpr(input)
45
- const roundTripPrimitive = parseToPrimitiveSExpr(roundTrip)
46
-
47
- expectEqualPrimitiveSExpr(roundTripPrimitive, originalPrimitive)
48
- })