@rulecad/keyboard-layout

One layout file that the plate, keycaps, case and board all read; and an importer for keyboard-layout-editor.com.

npm 0.1.5sourceMITNode >=20runs in this page
npm install @rulecad/keyboard-layout

Try it

Bring in a keyboard-layout-editor.com layout

Reference

A keyboard layout as plain JSON that everything else can read: the plate, the keycaps, the case and the circuit board all take their positions from one file. No dependencies; browsers and Node 20+.

{
  "defaults": { "legend": "@label" },
  "rows": [
    { "row": "R1", "keys": ["Esc", "Q", "W", "E"] },
    { "row": "R2", "keys": [["Tab", 1.5], "A", { "label": "F", "homing": true }] }
  ]
}
import { keys, width, depth } from '@rulecad/keyboard-layout';

keys(layout)   // [{ label: 'Esc', u: 1, row: 'R1', legend: 'Esc', x: -1.5, y: 0.5, … }, …]
width(layout)  // 4: the widest row, in key units
depth(layout)  // 2 rows

From keyboard-layout-editor.com

import { fromKLE } from '@rulecad/keyboard-layout';

const { layout, notes } = fromKLE(rawData);   // its JSON download, or the text from its "Raw data" tab

Rows, widths, gaps and legends come across, and a shifted legend ("!" over "1") becomes legend2. What this format has no place for (rotated keys, rows nudged up or down, tall or stepped keys such as ISO Enter) is listed in notes, and those keys keep their place in the row. With the cad command: npx cad import-kle layout.json keyboard/mine.