@rulecad/keyboard-layout
One layout file that the plate, keycaps, case and board all read; and an importer for keyboard-layout-editor.com.
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
- A key is a label (
"Q", 1u wide),[label, units], or an object withlabel,uand any other properties. - A row is a list of keys, or an object whose other properties apply to every key in it.
defaultsapply to every key, and a key's own properties win."@label"means the key's own label. - Rows run back to front and start at the same left edge.
xandyare each key's centre in key units, with the layout centred on 0 (x to the right, y to the back). Multiply by your pitch (19.05 mm for Cherry MX). project(layout, fields)keeps only the fields something reads, so you can tell whether an edit matters to it.{ "gap": 0.5 }in a row is space between keys, such as the groups of a function row.
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.