{"id":21590936,"url":"https://github.com/spaceteam/kicad_svg_parser","last_synced_at":"2025-03-18T10:15:24.216Z","repository":{"id":244851549,"uuid":"512450840","full_name":"SpaceTeam/kicad_svg_parser","owner":"SpaceTeam","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-14T22:31:44.000Z","size":59,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-24T16:28:16.531Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpaceTeam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-10T14:06:11.000Z","updated_at":"2024-06-17T19:01:38.000Z","dependencies_parsed_at":"2024-06-17T22:15:21.729Z","dependency_job_id":"0f95d733-a8fd-4614-8b1a-f213fc4268d5","html_url":"https://github.com/SpaceTeam/kicad_svg_parser","commit_stats":null,"previous_names":["spaceteam/kicad_svg_parser"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceTeam%2Fkicad_svg_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceTeam%2Fkicad_svg_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceTeam%2Fkicad_svg_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpaceTeam%2Fkicad_svg_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpaceTeam","download_url":"https://codeload.github.com/SpaceTeam/kicad_svg_parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244198406,"owners_count":20414443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T16:21:03.913Z","updated_at":"2025-03-18T10:15:24.198Z","avatar_url":"https://github.com/SpaceTeam.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kicad to SVG converter (kicad_svg_parser)\n\nThis module parses a `*.kicad_sch` file and translates it to a stylable SVG file. It works with the new [S-Expression](https://dev-docs.kicad.org/en/file-formats/sexpr-schematic/) file format used in KiCad version 6.0 and higher.\n\n# Installation\n\nInstall using npm (package is not in npm package registry, will be cloned from this repo by npm)\n\n```\nnpm install SpaceTeam/kicad_svg_parser\n```\n\n# Usage\n\n## Basic (Commandline)\n\nThe tool can be run from the command line using `npx`:\n\n```\nnpx kicad_svg_parser \u003cpath to schematic\u003e [output_file]\n```\n\nIf output file is omitted the parser will output a file in the same folder as the schematic with `.html` appended.\n\nIn this configuration the parser generates the svg content with default settings, and embeds it in html with inline styles, producing a standalone viewable file of the KiCad schematic.\n\n## Advanced\n\nFor more configuration options, the parser can be used as a module:\n\n```typescript\nimport * as kicad_parser from \"kicad_parser\"\n\n//Parse schematic\nconst schematicTxt = \"...\"\nconst schematic = kicad_parser.readSchematic(schematicTxt)\n//Create svg generator\nconst config: SVGConfiguration = {}\nconst generator = kicad_parser.SVGGenerator(config)\n//Generate svg\nconst out = generator.generateSVG(schematic)\n```\n\nSee [SVGConfiguration](src/svg/svg_api.ts) for all available generator options, [svg_generator.ts](src/svg/svg_generator.ts) for default settings and [Schematic](src/kicad/kicad_types.ts) for all available schematic properties and data types of KiCad elements.\n\nExample usage as module:\n\n```typescript\nimport * as fs from \"fs\" \nimport * as kicad_parser from \"kicad_parser\"\n\nexport function convertPNID(schematic_file_name: string, output_file_name?: string) {\n    output_file_name = output_file_name ?? schematic_file_name+\".svg\"\n\n    // Read schematic file\n    // Schematic file path needs to be passed as the first argument of the script\n    const schematic_txt = fs.readFileSync(schematic_file_name, 'utf-8');\n    // parse the schematic file contents\n    const schematic = kicad_parser.readSchematic(schematic_txt)\n    // log schematic version\n    console.info(`Loaded schematic '${schematic_file_name}'`)\n    console.info(`- version: ${schematic.version}`)\n    console.info(`- symbols: ${schematic.$symbol?.length ?? 0}`)\n    console.info(`- wires: ${schematic.$wire?.length ?? 0}`)\n\n\n    // create a generator with customized settings\n    const generator = new kicad_parser.SVGGenerator({\n        debug: kicad_parser.DEFAULT_SVG_DEBUG_SETTINGS,\n        classes: kicad_parser.DEFAULT_SVG_CLASSES,\n        styleVars: kicad_parser.DEFAULT_SVG_STYLEVARS,\n        createHiddenTexts: true,\n        callbacks: {\n            NET_ATTRIBUTES: net =\u003e {\n                return `data-pnid-net=\"${net.name}\"`\n            },\n            SYMBOL_ATTRIBUTES: symbol =\u003e {\n                const unit = symbol.$property?.find(p =\u003e p.key === \"Unit\")?.value\n                const sensorTag = \":sensor\"\n                const sensor = symbol.$property?.find(p =\u003e p.key === \"Value\" \u0026\u0026 p.value.endsWith(sensorTag))?.value?.slice(0, -sensorTag.length)\n                const content = symbol.$property?.find(p =\u003e p.key === \"Data_Content\")?.value\n                const type = symbol.lib_id.substring(symbol.lib_id.indexOf(\":\")+1)\n\n                const typeAttr = `data-pnid-type=\"${type}\"`\n                const unitAttr = `data-pnid-unit=\"${unit ?? \"\"}\"`\n                const sensorAttr = sensor ? `data-pnid-sensor=\"${sensor}\"` : \"\"\n                const contentAttr = `data-pnid-content=\"${content ?? \"\"}\"`\n\n                return `pointer-events=\"bounding-box\" ${typeAttr} ${unitAttr} ${sensorAttr} ${contentAttr}`\n            },\n            PROPERTY_ATTRIBUTES: property =\u003e {\n                return `data-pnid-property=\"${property.key}\"`\n            }\n        }\n    })\n    // generate svg file contents\n    console.info(`Generating html for schematic...`)\n    const svg = generator.generateSVG(schematic)\n    console.info(`Saving file '${output_file_name}'...`)\n    // save svg file\n    fs.writeFileSync(output_file_name, svg)\n    console.info(`Done.`)\n}\n```\n\n# Internals\n\n# Build and Test\n\nThe package can be built by running `npm build`, which builds the parser from the `.pegjs` grammar and compiles typescript to javascript.\n\nRunning `npm test` (after build, because otherwise the parser will not have been generated) compiles typescript and runs the parser on the test schematic file, producing `out.html` in the root folder.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceteam%2Fkicad_svg_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspaceteam%2Fkicad_svg_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaceteam%2Fkicad_svg_parser/lists"}