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
package/package.json CHANGED
@@ -1,16 +1,19 @@
1
1
  {
2
2
  "name": "kicadts",
3
3
  "module": "dist/index.js",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/tscircuit/kicadts"
9
9
  },
10
+ "files": [
11
+ "dist"
12
+ ],
10
13
  "scripts": {
11
14
  "build": "tsup-node lib/index.ts --format esm --dts",
12
15
  "download-references": "bun run scripts/download-references.ts",
13
- "download-demos": "git clone --depth 1 --filter=blob:none --sparse git@gitlab.com:kicad/code/kicad.git kicad-demos && cd kicad-demos && git sparse-checkout set demos",
16
+ "download-demos": "git clone --depth 1 --filter=blob:none --sparse https://gitlab.com/kicad/code/kicad.git kicad-demos && cd kicad-demos && git sparse-checkout set demos",
14
17
  "typecheck": "bunx tsc --noEmit",
15
18
  "format": "biome format --write .",
16
19
  "format:check": "biome format ."
@@ -1,111 +0,0 @@
1
- ---
2
- description: Use Bun instead of Node.js, npm, pnpm, or vite.
3
- globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
4
- alwaysApply: false
5
- ---
6
-
7
- Default to using Bun instead of Node.js.
8
-
9
- - Use `bun <file>` instead of `node <file>` or `ts-node <file>`
10
- - Use `bun test` instead of `jest` or `vitest`
11
- - Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
12
- - Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
13
- - Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
14
- - Bun automatically loads .env, so don't use dotenv.
15
-
16
- ## APIs
17
-
18
- - `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
19
- - `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
20
- - `Bun.redis` for Redis. Don't use `ioredis`.
21
- - `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
22
- - `WebSocket` is built-in. Don't use `ws`.
23
- - Prefer `Bun.file` over `node:fs`'s readFile/writeFile
24
- - Bun.$`ls` instead of execa.
25
-
26
- ## Testing
27
-
28
- Use `bun test` to run tests.
29
-
30
- ```ts#index.test.ts
31
- import { test, expect } from "bun:test";
32
-
33
- test("hello world", () => {
34
- expect(1).toBe(1);
35
- });
36
- ```
37
-
38
- ## Frontend
39
-
40
- Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
41
-
42
- Server:
43
-
44
- ```ts#index.ts
45
- import index from "./index.html"
46
-
47
- Bun.serve({
48
- routes: {
49
- "/": index,
50
- "/api/users/:id": {
51
- GET: (req) => {
52
- return new Response(JSON.stringify({ id: req.params.id }));
53
- },
54
- },
55
- },
56
- // optional websocket support
57
- websocket: {
58
- open: (ws) => {
59
- ws.send("Hello, world!");
60
- },
61
- message: (ws, message) => {
62
- ws.send(message);
63
- },
64
- close: (ws) => {
65
- // handle close
66
- }
67
- },
68
- development: {
69
- hmr: true,
70
- console: true,
71
- }
72
- })
73
- ```
74
-
75
- HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
76
-
77
- ```html#index.html
78
- <html>
79
- <body>
80
- <h1>Hello, world!</h1>
81
- <script type="module" src="./frontend.tsx"></script>
82
- </body>
83
- </html>
84
- ```
85
-
86
- With the following `frontend.tsx`:
87
-
88
- ```tsx#frontend.tsx
89
- import React from "react";
90
-
91
- // import .css files directly and it works
92
- import './index.css';
93
-
94
- import { createRoot } from "react-dom/client";
95
-
96
- const root = createRoot(document.body);
97
-
98
- export default function Frontend() {
99
- return <h1>Hello, world!</h1>;
100
- }
101
-
102
- root.render(<Frontend />);
103
- ```
104
-
105
- Then, run index.ts
106
-
107
- ```sh
108
- bun --hot ./index.ts
109
- ```
110
-
111
- For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.
@@ -1,26 +0,0 @@
1
- # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
- name: Format Check
3
-
4
- on:
5
- push:
6
- branches: [main]
7
- pull_request:
8
- branches: [main]
9
-
10
- jobs:
11
- format-check:
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v4
16
-
17
- - name: Setup bun
18
- uses: oven-sh/setup-bun@v2
19
- with:
20
- bun-version: latest
21
-
22
- - name: Install dependencies
23
- run: bun install
24
-
25
- - name: Run format check
26
- run: bun run format:check
@@ -1,70 +0,0 @@
1
- # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
- name: Publish to npm
3
- on:
4
- push:
5
- branches:
6
- - main
7
- workflow_dispatch:
8
-
9
- env:
10
- UPSTREAM_REPOS: "" # comma-separated list, e.g. "eval,tscircuit,docs"
11
- UPSTREAM_PACKAGES_TO_UPDATE: "" # comma-separated list, e.g. "@tscircuit/core,@tscircuit/protos"
12
-
13
- jobs:
14
- publish:
15
- runs-on: ubuntu-latest
16
- steps:
17
- - uses: actions/checkout@v4
18
- with:
19
- token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
20
- - name: Setup bun
21
- uses: oven-sh/setup-bun@v2
22
- with:
23
- bun-version: latest
24
- - uses: actions/setup-node@v3
25
- with:
26
- node-version: 20
27
- registry-url: https://registry.npmjs.org/
28
- - run: npm install -g pver
29
- - run: bun install --frozen-lockfile
30
- - run: bun run build
31
- - run: pver release
32
- env:
33
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34
- GITHUB_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
35
-
36
- # - name: Create Pull Request
37
- # id: create-pr
38
- # uses: peter-evans/create-pull-request@v5
39
- # with:
40
- # commit-message: "chore: bump version"
41
- # title: "chore: bump version"
42
- # body: "Automated package update"
43
- # branch: bump-version-${{ github.run_number }}
44
- # base: main
45
- # token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
46
- # committer: tscircuitbot <githubbot@tscircuit.com>
47
- # author: tscircuitbot <githubbot@tscircuit.com>
48
-
49
- # - name: Enable auto-merge
50
- # if: steps.create-pr.outputs.pull-request-number != ''
51
- # run: |
52
- # gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} --rebase --delete-branch
53
- # env:
54
- # GH_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
55
-
56
- # - name: Trigger upstream repo updates
57
- # if: env.UPSTREAM_REPOS && env.UPSTREAM_PACKAGES_TO_UPDATE
58
- # run: |
59
- # IFS=',' read -ra REPOS <<< "${{ env.UPSTREAM_REPOS }}"
60
- # for repo in "${REPOS[@]}"; do
61
- # if [[ -n "$repo" ]]; then
62
- # echo "Triggering update for repo: $repo"
63
- # curl -X POST \
64
- # -H "Accept: application/vnd.github.v3+json" \
65
- # -H "Authorization: token ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}" \
66
- # -H "Content-Type: application/json" \
67
- # "https://api.github.com/repos/tscircuit/$repo/actions/workflows/update-package.yml/dispatches" \
68
- # -d "{\"ref\":\"main\",\"inputs\":{\"package_names\":\"${{ env.UPSTREAM_PACKAGES_TO_UPDATE }}\"}}"
69
- # fi
70
- # done
@@ -1,32 +0,0 @@
1
- # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
- name: Bun Test
3
-
4
- on:
5
- pull_request:
6
- push:
7
- branches:
8
- - main
9
-
10
- jobs:
11
- test:
12
- runs-on: ubuntu-latest
13
- timeout-minutes: 5
14
-
15
- # Skip test for PRs that not chore: bump version
16
- if: "${{ github.event_name != 'pull_request' || github.event.pull_request.title != 'chore: bump version' }}"
17
-
18
- steps:
19
- - name: Checkout code
20
- uses: actions/checkout@v4
21
-
22
- - name: Setup bun
23
- uses: oven-sh/setup-bun@v2
24
- with:
25
- bun-version: latest
26
-
27
- - name: Install dependencies
28
- run: bun install
29
- - run: bun run download-demos
30
-
31
- - name: Run tests
32
- run: bun test
@@ -1,26 +0,0 @@
1
- # Created using @tscircuit/plop (npm install -g @tscircuit/plop)
2
- name: Type Check
3
-
4
- on:
5
- push:
6
- branches: [main]
7
- pull_request:
8
- branches: [main]
9
-
10
- jobs:
11
- type-check:
12
- runs-on: ubuntu-latest
13
-
14
- steps:
15
- - uses: actions/checkout@v4
16
-
17
- - name: Setup bun
18
- uses: oven-sh/setup-bun@v2
19
- with:
20
- bun-version: latest
21
-
22
- - name: Install dependencies
23
- run: bun i
24
-
25
- - name: Run type check
26
- run: bunx tsc --noEmit
@@ -1,16 +0,0 @@
1
- {
2
- "workbench.colorCustomizations": {
3
- "commandCenter.border": "#15202b99",
4
- "sash.hoverBorder": "#18f7e8",
5
- "statusBar.background": "#07d5c7",
6
- "statusBar.foreground": "#15202b",
7
- "statusBarItem.hoverBackground": "#05a499",
8
- "statusBarItem.remoteBackground": "#07d5c7",
9
- "statusBarItem.remoteForeground": "#15202b",
10
- "titleBar.activeBackground": "#07d5c7",
11
- "titleBar.activeForeground": "#15202b",
12
- "titleBar.inactiveBackground": "#07d5c799",
13
- "titleBar.inactiveForeground": "#15202b99"
14
- },
15
- "peacock.color": "#07d5c7"
16
- }
package/AGENTS.md DELETED
@@ -1,31 +0,0 @@
1
- This is the `kicadts` typescript library. It's still in early developement and
2
- we're trying to make sure we parse the entire KiCad S-expression specification.
3
-
4
- You can find the difference specifications in the `references` directory, the
5
- most extensive one is `references/SEXPR_MAIN.adoc` (use `bun run scripts/download-references.ts` to download if it's not already there)
6
-
7
- - `references/SCHEMATIC_SEXPR.adoc`
8
- - `references/PCB_SEXPR.adoc`
9
- - `references/FOOTPRINT_SEXPR.adoc`
10
- - `references/SCH_SYM_SEXPR.adoc`
11
- - `references/SEXPR_MAIN.adoc`
12
-
13
- ### Tips
14
-
15
- - Every S-expression token must have a corresponding `SxClass` subclass and be registered via `SxClass.register`; missing registrations cause parse failures.
16
- - Tokens reused under different parents (for example `type` under `stroke`) require `static parentToken` overrides so the correct class resolves during parsing.
17
- - When a class accepts unordered child tokens, set `_propertyMap` using `loadProperties` to make getters convenient and keep `getString()` deterministic.
18
- - Snapshot tests with `bun test` provide quick verification that `getString()` matches the KiCad formatting expectations.
19
-
20
- ### Major Refactor Notice
21
-
22
- - The code in this repo is only partially migrated to the new pattern
23
- - NEW PATTERN: Constructors never take `PrimitiveSExpr` arguments
24
- - NEW PATTERN: All classes have a `fromSexprPrimitives` static method that takes a `PrimitiveSExpr` array and returns an instance of the class
25
- - NEW PATTERN: Classes have ergonomic getters and setters for properties
26
- - NEW PATTERN: Never has "extras" property, everything becomes an `SxClass`
27
- - NEW PATTERN: Never have "switch cases" that switch on the token. Always use the `SxClass.parsePrimitiveSexpr` or `SxClass.parsePrimitivesToClassProperties` methods to parse arrays of `PrimitiveSExpr` into instances of the correct class
28
- - NEW PATTERN: Never track the order of children unless absolutely necessary, use the `_sx*` properties and `getChildren` to return the children in a predefined order
29
- - NEW PATTERN: Never track unknown children, throw an error/allow an error to be thrown if you encounter a child PrimitiveSExpr that can't be parsed. You can introduce new `_sx*` properties and a new class to prevent the error
30
- - NEW PATTERN: One class per file
31
- - NEW PATTERN: Ergonomic constructors for classes
package/TODO.md DELETED
@@ -1,46 +0,0 @@
1
- # TODO: Ergonomic Constructors
2
-
3
- The following classes need ergonomic constructors created (similar to the pattern in `KicadSch.ts`):
4
-
5
- ## Main Container Classes
6
-
7
- - [x] **KicadSch** - `lib/sexpr/classes/KicadSch.ts`
8
- - [ ] **Bus** - `lib/sexpr/classes/Bus.ts`
9
- - [ ] **BusEntry** - `lib/sexpr/classes/BusEntry.ts`
10
- - [ ] **Footprint** - `lib/sexpr/classes/Footprint.ts`
11
- - [ ] **FootprintPad** - `lib/sexpr/classes/FootprintPad.ts`
12
- - [ ] **FpArc** - `lib/sexpr/classes/FpArc.ts`
13
- - [ ] **FpCircle** - `lib/sexpr/classes/FpCircle.ts`
14
- - [ ] **FpLine** - `lib/sexpr/classes/FpLine.ts`
15
- - [ ] **FpPoly** - `lib/sexpr/classes/FpPoly.ts`
16
- - [ ] **FpRect** - `lib/sexpr/classes/FpRect.ts`
17
- - [ ] **FpText** - `lib/sexpr/classes/FpText.ts`
18
- - [ ] **FpTextBox** - `lib/sexpr/classes/FpTextBox.ts`
19
- - [ ] **GrLine** - `lib/sexpr/classes/GrLine.ts`
20
- - [ ] **GrText** - `lib/sexpr/classes/GrText.ts`
21
- - [ ] **Image** - `lib/sexpr/classes/Image.ts`
22
- - [ ] **Junction** - `lib/sexpr/classes/Junction.ts`
23
- - [ ] **KicadPcb** - `lib/sexpr/classes/KicadPcb.ts`
24
- - [ ] **Label** - `lib/sexpr/classes/Label.ts`
25
- - [ ] **NoConnect** - `lib/sexpr/classes/NoConnect.ts`
26
- - [ ] **PadPrimitiveGrArc** - `lib/sexpr/classes/PadPrimitiveGrArc.ts`
27
- - [ ] **PadPrimitiveGrCircle** - `lib/sexpr/classes/PadPrimitiveGrCircle.ts`
28
- - [ ] **Property** - `lib/sexpr/classes/Property.ts`
29
- - [ ] **SchematicText** - `lib/sexpr/classes/SchematicText.ts`
30
- - [ ] **Segment** - `lib/sexpr/classes/Segment.ts`
31
- - [ ] **Sheet** - `lib/sexpr/classes/Sheet.ts`
32
- - [ ] **Symbol** (SchematicSymbol) - `lib/sexpr/classes/Symbol.ts`
33
- - [ ] **TextEffects** - `lib/sexpr/classes/TextEffects.ts`
34
- - [ ] **TitleBlock** - `lib/sexpr/classes/TitleBlock.ts`
35
- - [ ] **Via** - `lib/sexpr/classes/Via.ts`
36
- - [ ] **Wire** - `lib/sexpr/classes/Wire.ts`
37
-
38
- ## Pattern Requirements
39
-
40
- Each class needs:
41
- 1. A TypeScript interface `{ClassName}ConstructorParams` with optional properties
42
- 2. Properties should accept either primitive values (strings, numbers) OR SxClass wrapper objects
43
- 3. Constructor that accepts the params interface and handles both cases
44
- 4. Getter/setter pairs working with primitive values while storing SxClass objects internally
45
-
46
- See `lib/sexpr/classes/KicadSch.ts` for reference implementation.
package/biome.json DELETED
@@ -1,93 +0,0 @@
1
- {
2
- "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
3
- "assist": { "actions": { "source": { "organizeImports": "on" } } },
4
- "formatter": {
5
- "enabled": true,
6
- "indentStyle": "space"
7
- },
8
- "files": {
9
- "includes": ["**", "!**/cosmos-export", "!**/dist", "!**/package.json"]
10
- },
11
- "javascript": {
12
- "formatter": {
13
- "jsxQuoteStyle": "double",
14
- "quoteProperties": "asNeeded",
15
- "trailingCommas": "all",
16
- "semicolons": "asNeeded",
17
- "arrowParentheses": "always",
18
- "bracketSpacing": true,
19
- "bracketSameLine": false
20
- }
21
- },
22
- "linter": {
23
- "enabled": true,
24
- "rules": {
25
- "recommended": true,
26
- "suspicious": {
27
- "noExplicitAny": "off"
28
- },
29
- "complexity": {
30
- "noForEach": "error",
31
- "useLiteralKeys": "off"
32
- },
33
- "a11y": {
34
- "noAccessKey": "off",
35
- "noAriaHiddenOnFocusable": "off",
36
- "noAriaUnsupportedElements": "off",
37
- "noAutofocus": "off",
38
- "noDistractingElements": "off",
39
- "noHeaderScope": "off",
40
- "noInteractiveElementToNoninteractiveRole": "off",
41
- "noLabelWithoutControl": "off",
42
- "noNoninteractiveElementToInteractiveRole": "off",
43
- "noNoninteractiveTabindex": "off",
44
- "noPositiveTabindex": "off",
45
- "noRedundantAlt": "off",
46
- "noRedundantRoles": "off",
47
- "noStaticElementInteractions": "off",
48
- "noSvgWithoutTitle": "off",
49
- "useAltText": "off",
50
- "useAnchorContent": "off",
51
- "useAriaActivedescendantWithTabindex": "off",
52
- "useAriaPropsForRole": "off",
53
- "useAriaPropsSupportedByRole": "off",
54
- "useButtonType": "off",
55
- "useFocusableInteractive": "off",
56
- "useHeadingContent": "off",
57
- "useHtmlLang": "off",
58
- "useIframeTitle": "off",
59
- "useKeyWithClickEvents": "off",
60
- "useKeyWithMouseEvents": "off",
61
- "useMediaCaption": "off",
62
- "useSemanticElements": "off",
63
- "useValidAnchor": "off",
64
- "useValidAriaProps": "off",
65
- "useValidAriaRole": "off",
66
- "useValidAriaValues": "off",
67
- "useValidAutocomplete": "off",
68
- "useValidLang": "off"
69
- },
70
- "style": {
71
- "useSingleVarDeclarator": "error",
72
- "noParameterAssign": "off",
73
- "noUselessElse": "off",
74
- "noNonNullAssertion": "off",
75
- "useNumberNamespace": "off",
76
- "noUnusedTemplateLiteral": "off",
77
- "useFilenamingConvention": {
78
- "level": "error",
79
- "options": {
80
- "strictCase": true,
81
- "requireAscii": true,
82
- "filenameCases": ["kebab-case", "export"]
83
- }
84
- },
85
- "useAsConstAssertion": "error",
86
- "useDefaultParameterLast": "error",
87
- "useEnumInitializers": "error",
88
- "useSelfClosingElements": "error",
89
- "noInferrableTypes": "error"
90
- }
91
- }
92
- }
93
- }
package/bunfig.toml DELETED
@@ -1,5 +0,0 @@
1
- [test]
2
- preload = ["./tests/fixtures/preload.ts"]
3
-
4
- [install.lockfile]
5
- save = false
package/lib/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./sexpr"
@@ -1,164 +0,0 @@
1
- import {
2
- parseToPrimitiveSExpr,
3
- type PrimitiveSExpr,
4
- } from "../parseToPrimitiveSExpr"
5
-
6
- const DEFAULT_PARENT_TOKEN = "__default__"
7
-
8
- export abstract class SxClass {
9
- abstract token: string
10
- static token: string
11
-
12
- /**
13
- * Token strings are sometimes re-used (e.g. a "type" token) but the class
14
- * varies based on the parent token
15
- */
16
- static parentToken?: string
17
-
18
- isSxClass = true
19
-
20
- getChildren(): SxClass[] {
21
- // By default, return any properties found in this instance that have the _sx* prefix
22
- return Object.keys(this)
23
- .filter((k) => k.startsWith("_sx"))
24
- .map((k) => (this as any)[k])
25
- .filter((v) => v && typeof v === "object" && v.isSxClass)
26
- }
27
-
28
- getStringIndented(): string {
29
- return this.getString()
30
- .split("\n")
31
- .map((line) => ` ${line}`)
32
- .join("\n")
33
- }
34
-
35
- getString(): string {
36
- const children = this.getChildren()
37
- if (children.length === 0) {
38
- return `(${this.token})`
39
- }
40
-
41
- const lines = [`(${this.token}`]
42
- for (const p of children) {
43
- lines.push(p.getStringIndented())
44
- }
45
- lines.push(")")
46
- return lines.join("\n")
47
- }
48
- get [Symbol.toStringTag](): string {
49
- return this.getString()
50
- }
51
- [Symbol.for("nodejs.util.inspect.custom")]() {
52
- return this.getString()
53
- }
54
-
55
- // =========================== STATIC METHODS ===========================
56
-
57
- static classes: Record<string, Record<string, any>> = {}
58
-
59
- /**
60
- * Should be called after class definition to register the class for parsing
61
- */
62
- static register(newClass: any) {
63
- if (!newClass.token) {
64
- throw new Error("Class must have a static override token")
65
- }
66
- const parentKey = newClass.parentToken ?? DEFAULT_PARENT_TOKEN
67
- const existing = SxClass.classes[newClass.token] ?? {}
68
- existing[parentKey] = newClass
69
- SxClass.classes[newClass.token] = existing
70
- }
71
-
72
- /**
73
- * Parse an S-expression string into registered SxClass instances
74
- */
75
- static parse(sexpr: string): SxClass[] {
76
- const primitiveSexpr = parseToPrimitiveSExpr(sexpr)
77
-
78
- return SxClass.parsePrimitiveSexpr(primitiveSexpr) as any
79
- }
80
-
81
- static fromSexprPrimitives(primitiveSexprs: PrimitiveSExpr[]): SxClass {
82
- throw new Error(
83
- `"${this.name}" class has not implemented fromSexprPrimitives`,
84
- )
85
- }
86
-
87
- static parsePrimitiveSexpr(
88
- primitiveSexpr: PrimitiveSExpr,
89
- options: { parentToken?: string } = {},
90
- ): SxClass | SxClass[] | number | string | boolean | null {
91
- const parentToken = options.parentToken
92
-
93
- if (
94
- Array.isArray(primitiveSexpr) &&
95
- primitiveSexpr.length >= 1 &&
96
- typeof primitiveSexpr[0] === "string"
97
- ) {
98
- const classToken = primitiveSexpr[0] as string
99
- const classGroup = SxClass.classes[classToken]
100
- if (!classGroup) {
101
- throw new Error(
102
- `Class "${classToken}" not registered via SxClass.register`,
103
- )
104
- }
105
- const parentKey = parentToken ?? DEFAULT_PARENT_TOKEN
106
- const ClassDef: any =
107
- classGroup[parentKey] ?? classGroup[DEFAULT_PARENT_TOKEN]
108
- if (!ClassDef) {
109
- throw new Error(
110
- `Class "${classToken}" not registered for parent "${parentToken ?? "<root>"}"`,
111
- )
112
- }
113
- const args = primitiveSexpr.slice(1) as PrimitiveSExpr[]
114
- if (!("fromSexprPrimitives" in ClassDef)) {
115
- throw new Error(
116
- `Class "${classToken}" does not have a fromSexprPrimitives method`,
117
- )
118
- }
119
- const classInstance = ClassDef.fromSexprPrimitives(args)
120
- return classInstance
121
- }
122
-
123
- if (Array.isArray(primitiveSexpr)) {
124
- return primitiveSexpr.map((item) =>
125
- SxClass.parsePrimitiveSexpr(item, options),
126
- ) as any[]
127
- }
128
-
129
- if (
130
- typeof primitiveSexpr === "number" ||
131
- typeof primitiveSexpr === "string" ||
132
- typeof primitiveSexpr === "boolean" ||
133
- primitiveSexpr === null
134
- ) {
135
- return primitiveSexpr as number | string | boolean | null
136
- }
137
-
138
- throw new Error(
139
- `Couldn't parse primitive S-expression: ${JSON.stringify(primitiveSexpr)}`,
140
- )
141
- }
142
-
143
- // =========================== STATIC UTILITIES ===========================
144
- static parsePrimitivesToClassProperties(
145
- primitiveSexprs: PrimitiveSExpr[],
146
- parentToken?: string,
147
- ): {
148
- propertyMap: Record<string, SxClass>
149
- arrayPropertyMap: Record<string, SxClass[]>
150
- } {
151
- const propertyMap = {} as Record<string, SxClass>
152
- const arrayPropertyMap = {} as Record<string, SxClass[]>
153
- for (const primitiveSexpr of primitiveSexprs) {
154
- const sxClass = SxClass.parsePrimitiveSexpr(primitiveSexpr, {
155
- parentToken,
156
- }) as SxClass
157
- if (!sxClass.isSxClass) continue
158
- propertyMap[sxClass.token] = sxClass
159
- arrayPropertyMap[sxClass.token] ??= []
160
- arrayPropertyMap[sxClass.token]!.push(sxClass)
161
- }
162
- return { propertyMap, arrayPropertyMap }
163
- }
164
- }