@rulecad/keyboard-layout 0.1.3 → 0.1.5

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.
@@ -51,7 +51,7 @@ export const depth = (layout) => (layout.rows || []).length;
51
51
  // project(layout, fields): only the fields something reads, key by key, so a change to anything else (a legend, when
52
52
  // only positions matter) isn't a change to it. Positions always count.
53
53
  /** Only the fields something reads, key by key (positions always). @param {Layout} layout @param {string[]} [fields] @returns {object[]} */
54
- export const project = (layout, fields = []) => keys(layout).map((k) => Object.fromEntries(['index', 'col', 'u', ...fields].map((f) => [f, k[f] ?? null])));
54
+ export const project = (layout, fields = []) => keys(layout).map((k) => Object.fromEntries(['row', 'index', 'col', 'u', 'x', 'y', ...fields].map((f) => [f, k[f] ?? null]))); // (x and y too: a gap moves the keys after it)
55
55
 
56
56
  /**
57
57
  * A layout from keyboard-layout-editor.com: its JSON download, or the "Raw data" text. Rows, widths and the gaps
@@ -90,9 +90,11 @@ export function fromKLE(kle) {
90
90
 
91
91
  // "Raw data" from keyboard-layout-editor.com is JSON with its object keys unquoted and the outer brackets left off
92
92
  function parseRaw(text) {
93
- try { return JSON.parse(text); } catch {}
93
+ // (one row on its own is a list with no lists in it: a three-key macropad's raw data. It is a layout of one row)
94
+ const rows = (data) => (Array.isArray(data) && data.length && !data.some(Array.isArray) ? [data] : data);
95
+ try { return rows(JSON.parse(text)); } catch {}
94
96
  const quoted = `[${text}]`.replace(/([{,]\s*)([A-Za-z_][\w]*)\s*:/g, '$1"$2":');
95
- try { return JSON.parse(quoted); } catch { throw new Error("this isn't keyboard-layout-editor data: paste its Raw data, or use its JSON download"); }
97
+ try { return rows(JSON.parse(quoted)); } catch { throw new Error("this isn't keyboard-layout-editor data: paste its Raw data, or use its JSON download"); }
96
98
  }
97
99
 
98
100
  // A key's legends: "Q", or "!\n1" (top-left shifted, bottom-left main), up to twelve positions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/keyboard-layout",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "A plain JSON keyboard layout format: rows of keys with widths and any per-key properties.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,6 +28,10 @@
28
28
  "url": "git+https://github.com/JoniBach/rulecad.git",
29
29
  "directory": "packages/keyboard-layout"
30
30
  },
31
+ "homepage": "https://github.com/JoniBach/rulecad/tree/main/packages/keyboard-layout#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/JoniBach/rulecad/issues"
34
+ },
31
35
  "scripts": {
32
36
  "test": "node --test"
33
37
  },