@rulecad/pcb 0.2.0 → 0.2.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/pcb.mjs +15 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/pcb",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Circuit boards from rules: parts from rule sets or any standard footprint, quarter-turn rotation, nets and autorouting; keyboards with every matrix track drawn by rule. Gerbers, KiCad files and a JLCPCB BOM. Circuit JSON written directly: no React.",
5
5
  "type": "module",
6
6
  "exports": "./pcb.mjs",
package/pcb.mjs CHANGED
@@ -415,11 +415,22 @@ export async function kicadFiles(json, name) {
415
415
  export async function views(json) {
416
416
  const { convertCircuitJsonToPcbSvg, convertCircuitJsonToSchematicSvg } = await import('circuit-to-svg');
417
417
  return [
418
- ['Board: both sides', convertCircuitJsonToPcbSvg(json)],
419
- ['Board: front', convertCircuitJsonToPcbSvg(json, { layer: 'top' })],
420
- ['Board: back', convertCircuitJsonToPcbSvg(json, { layer: 'bottom' })],
418
+ ['Board: both sides', convertCircuitJsonToPcbSvg(json)], // the model page makes front and back from its layers
421
419
  ['Schematic', convertCircuitJsonToSchematicSvg(json)],
422
- ];
420
+ ].map(([name, svg]) => [name, light(svg)]);
421
+ }
422
+
423
+ /**
424
+ * A drawing made lighter for a link, looking the same: numbers in attributes rounded to 0.01 (the drawings are
425
+ * 800 px wide, so that's invisible; text keeps every digit), tscircuit's data-* attributes gone but each element's
426
+ * copper layer (data-pcb-layer, which the model page uses to show one side), and empty style tags gone.
427
+ * A board's link was mostly its drawings' 15-digit coordinates, which don't compress.
428
+ * @param {string} svg @returns {string}
429
+ */
430
+ export function light(svg) {
431
+ const round = (v) => v.replace(/-?\d+\.\d{3,}/g, (n) => String(Math.round(Number(n) * 100) / 100));
432
+ return svg.replace(/ data-(?!pcb-layer=)[\w-]+="[^"]*"/g, '').replace(/<style><\/style>/g, '')
433
+ .replace(/(<[^>]+>)/g, (tag) => tag.replace(/="([^"]*)"/g, (_, v) => `="${round(v)}"`));
423
434
  }
424
435
 
425
436
  // The schematic as a PNG