@keymanapp/kmc-ldml 17.0.104-alpha
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.
- package/build/src/compiler/compiler-options.d.ts +11 -0
- package/build/src/compiler/compiler-options.d.ts.map +1 -0
- package/build/src/compiler/compiler-options.js +3 -0
- package/build/src/compiler/compiler-options.js.map +1 -0
- package/build/src/compiler/compiler.d.ts +38 -0
- package/build/src/compiler/compiler.d.ts.map +1 -0
- package/build/src/compiler/compiler.js +144 -0
- package/build/src/compiler/compiler.js.map +1 -0
- package/build/src/compiler/disp.d.ts +10 -0
- package/build/src/compiler/disp.d.ts.map +1 -0
- package/build/src/compiler/disp.js +37 -0
- package/build/src/compiler/disp.js.map +1 -0
- package/build/src/compiler/keymanweb-compiler.d.ts +16 -0
- package/build/src/compiler/keymanweb-compiler.d.ts.map +1 -0
- package/build/src/compiler/keymanweb-compiler.js +96 -0
- package/build/src/compiler/keymanweb-compiler.js.map +1 -0
- package/build/src/compiler/keys.d.ts +26 -0
- package/build/src/compiler/keys.d.ts.map +1 -0
- package/build/src/compiler/keys.js +207 -0
- package/build/src/compiler/keys.js.map +1 -0
- package/build/src/compiler/layr.d.ts +10 -0
- package/build/src/compiler/layr.d.ts.map +1 -0
- package/build/src/compiler/layr.js +79 -0
- package/build/src/compiler/layr.js.map +1 -0
- package/build/src/compiler/loca.d.ts +16 -0
- package/build/src/compiler/loca.d.ts.map +1 -0
- package/build/src/compiler/loca.js +58 -0
- package/build/src/compiler/loca.js.map +1 -0
- package/build/src/compiler/messages.d.ts +93 -0
- package/build/src/compiler/messages.d.ts.map +1 -0
- package/build/src/compiler/messages.js +54 -0
- package/build/src/compiler/messages.js.map +1 -0
- package/build/src/compiler/meta.d.ts +12 -0
- package/build/src/compiler/meta.d.ts.map +1 -0
- package/build/src/compiler/meta.js +58 -0
- package/build/src/compiler/meta.js.map +1 -0
- package/build/src/compiler/metadata-compiler.d.ts +13 -0
- package/build/src/compiler/metadata-compiler.d.ts.map +1 -0
- package/build/src/compiler/metadata-compiler.js +47 -0
- package/build/src/compiler/metadata-compiler.js.map +1 -0
- package/build/src/compiler/name.d.ts +10 -0
- package/build/src/compiler/name.d.ts.map +1 -0
- package/build/src/compiler/name.js +20 -0
- package/build/src/compiler/name.js.map +1 -0
- package/build/src/compiler/ordr.d.ts +12 -0
- package/build/src/compiler/ordr.d.ts.map +1 -0
- package/build/src/compiler/ordr.js +35 -0
- package/build/src/compiler/ordr.js.map +1 -0
- package/build/src/compiler/section-compiler.d.ts +12 -0
- package/build/src/compiler/section-compiler.d.ts.map +1 -0
- package/build/src/compiler/section-compiler.js +22 -0
- package/build/src/compiler/section-compiler.js.map +1 -0
- package/build/src/compiler/touch-layout-compiler.d.ts +8 -0
- package/build/src/compiler/touch-layout-compiler.d.ts.map +1 -0
- package/build/src/compiler/touch-layout-compiler.js +87 -0
- package/build/src/compiler/touch-layout-compiler.js.map +1 -0
- package/build/src/compiler/tran.d.ts +41 -0
- package/build/src/compiler/tran.d.ts.map +1 -0
- package/build/src/compiler/tran.js +102 -0
- package/build/src/compiler/tran.js.map +1 -0
- package/build/src/compiler/visual-keyboard-compiler.d.ts +7 -0
- package/build/src/compiler/visual-keyboard-compiler.d.ts.map +1 -0
- package/build/src/compiler/visual-keyboard-compiler.js +51 -0
- package/build/src/compiler/visual-keyboard-compiler.js.map +1 -0
- package/build/src/compiler/vkey.d.ts +10 -0
- package/build/src/compiler/vkey.d.ts.map +1 -0
- package/build/src/compiler/vkey.js +59 -0
- package/build/src/compiler/vkey.js.map +1 -0
- package/build/src/kpj.schema.json +127 -0
- package/build/src/kvks.schema.json +182 -0
- package/build/src/ldml-keyboard.schema.json +702 -0
- package/build/src/ldml-keyboardtest.schema.json +221 -0
- package/build/src/main.d.ts +9 -0
- package/build/src/main.d.ts.map +1 -0
- package/build/src/main.js +8 -0
- package/build/src/main.js.map +1 -0
- package/build/src/util/util.d.ts +32 -0
- package/build/src/util/util.d.ts.map +1 -0
- package/build/src/util/util.js +85 -0
- package/build/src/util/util.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default interface CompilerOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Add debug information to the .kmx file when compiling
|
|
4
|
+
*/
|
|
5
|
+
debug?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Add metadata about the compiler version to .kmx file when compiling
|
|
8
|
+
*/
|
|
9
|
+
addCompilerVersion?: boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=compiler-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-options.d.ts","sourceRoot":"","sources":["../../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,WAAW,eAAe;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler-options.js","sourceRoot":"","sources":["../../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAYC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { LDMLKeyboard, KMXPlus, CompilerCallbacks, LDMLKeyboardTestDataXMLSourceFile } from '@keymanapp/common-types';
|
|
2
|
+
import CompilerOptions from './compiler-options.js';
|
|
3
|
+
import LDMLKeyboardXMLSourceFile = LDMLKeyboard.LDMLKeyboardXMLSourceFile;
|
|
4
|
+
import KMXPlusFile = KMXPlus.KMXPlusFile;
|
|
5
|
+
export default class Compiler {
|
|
6
|
+
private readonly callbacks;
|
|
7
|
+
constructor(callbacks: CompilerCallbacks, _options?: CompilerOptions);
|
|
8
|
+
private buildSections;
|
|
9
|
+
/**
|
|
10
|
+
* Loads a LDML Keyboard xml file and compiles into in-memory xml
|
|
11
|
+
* structures.
|
|
12
|
+
* @param filename input filename, will use callback to load from disk
|
|
13
|
+
* @returns the source file, or null if invalid
|
|
14
|
+
*/
|
|
15
|
+
load(filename: string): LDMLKeyboardXMLSourceFile | null;
|
|
16
|
+
/**
|
|
17
|
+
* Loads a LDML Keyboard test data xml file and compiles into in-memory xml
|
|
18
|
+
* structures.
|
|
19
|
+
* @param filename input filename, will use callback to load from disk
|
|
20
|
+
* @returns the source file, or null if invalid
|
|
21
|
+
*/
|
|
22
|
+
loadTestData(filename: string): LDMLKeyboardTestDataXMLSourceFile | null;
|
|
23
|
+
/**
|
|
24
|
+
* Validates that the LDML keyboard source file and lints. Actually just
|
|
25
|
+
* compiles the keyboard and returns `true` if everything is good...
|
|
26
|
+
* @param source
|
|
27
|
+
* @returns true if the file validates
|
|
28
|
+
*/
|
|
29
|
+
validate(source: LDMLKeyboardXMLSourceFile): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Transforms in-memory LDML keyboard xml file to an intermediate
|
|
32
|
+
* representation of a .kmx file.
|
|
33
|
+
* @param source in-memory representation of LDML keyboard xml file
|
|
34
|
+
* @returns KMXPlusFile intermediate file
|
|
35
|
+
*/
|
|
36
|
+
compile(source: LDMLKeyboardXMLSourceFile): KMXPlusFile;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,iCAAiC,EAAE,MAAM,yBAAyB,CAAC;AACvJ,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAYpD,OAAO,yBAAyB,GAAG,YAAY,CAAC,yBAAyB,CAAC;AAC1E,OAAO,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;AAgBzC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;gBAGjC,SAAS,EAAE,iBAAiB,EAAE,QAAQ,CAAC,EAAE,eAAe;IAWrE,OAAO,CAAC,aAAa;IAIrB;;;;;OAKG;IACI,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,yBAAyB,GAAG,IAAI;IAwB/D;;;;;OAKG;IACM,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,iCAAiC,GAAG,IAAI;IA2BjF;;;;;OAKG;IACI,QAAQ,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO;IAI3D;;;;;OAKG;IACI,OAAO,CAAC,MAAM,EAAE,yBAAyB,GAAG,WAAW;CAiC/D"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { LDMLKeyboardXMLSourceFileReader, KMXPlus } from '@keymanapp/common-types';
|
|
2
|
+
import { CompilerMessages } from './messages.js';
|
|
3
|
+
import { BkspCompiler, FinlCompiler, TranCompiler } from './tran.js';
|
|
4
|
+
import { DispCompiler } from './disp.js';
|
|
5
|
+
import { KeysCompiler } from './keys.js';
|
|
6
|
+
import { LayrCompiler } from './layr.js';
|
|
7
|
+
import { LocaCompiler } from './loca.js';
|
|
8
|
+
import { MetaCompiler } from './meta.js';
|
|
9
|
+
import { NameCompiler } from './name.js';
|
|
10
|
+
import { OrdrCompiler } from './ordr.js';
|
|
11
|
+
import { VkeyCompiler } from './vkey.js';
|
|
12
|
+
var KMXPlusFile = KMXPlus.KMXPlusFile;
|
|
13
|
+
const SECTION_COMPILERS = [
|
|
14
|
+
BkspCompiler,
|
|
15
|
+
DispCompiler,
|
|
16
|
+
FinlCompiler,
|
|
17
|
+
KeysCompiler,
|
|
18
|
+
LayrCompiler,
|
|
19
|
+
LocaCompiler,
|
|
20
|
+
MetaCompiler,
|
|
21
|
+
NameCompiler,
|
|
22
|
+
OrdrCompiler,
|
|
23
|
+
TranCompiler,
|
|
24
|
+
VkeyCompiler,
|
|
25
|
+
];
|
|
26
|
+
export default class Compiler {
|
|
27
|
+
callbacks;
|
|
28
|
+
// private readonly options: CompilerOptions; // not currently used
|
|
29
|
+
constructor(callbacks, _options) {
|
|
30
|
+
/*
|
|
31
|
+
this.options = {
|
|
32
|
+
debug: false,
|
|
33
|
+
addCompilerVersion: true,
|
|
34
|
+
...options
|
|
35
|
+
};
|
|
36
|
+
*/
|
|
37
|
+
this.callbacks = callbacks;
|
|
38
|
+
}
|
|
39
|
+
buildSections(source) {
|
|
40
|
+
return SECTION_COMPILERS.map(c => new c(source, this.callbacks));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Loads a LDML Keyboard xml file and compiles into in-memory xml
|
|
44
|
+
* structures.
|
|
45
|
+
* @param filename input filename, will use callback to load from disk
|
|
46
|
+
* @returns the source file, or null if invalid
|
|
47
|
+
*/
|
|
48
|
+
load(filename) {
|
|
49
|
+
const reader = new LDMLKeyboardXMLSourceFileReader(this.callbacks);
|
|
50
|
+
const data = this.callbacks.loadFile(filename);
|
|
51
|
+
if (!data) {
|
|
52
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({ errorText: 'Unable to read XML file' }));
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const source = reader.load(data);
|
|
56
|
+
if (!source) {
|
|
57
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({ errorText: 'Unable to load XML file' }));
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
if (!reader.validate(source, this.callbacks.loadSchema('ldml-keyboard'))) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({ errorText: e.toString() }));
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return source;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Loads a LDML Keyboard test data xml file and compiles into in-memory xml
|
|
73
|
+
* structures.
|
|
74
|
+
* @param filename input filename, will use callback to load from disk
|
|
75
|
+
* @returns the source file, or null if invalid
|
|
76
|
+
*/
|
|
77
|
+
loadTestData(filename) {
|
|
78
|
+
const reader = new LDMLKeyboardXMLSourceFileReader(this.callbacks);
|
|
79
|
+
const data = this.callbacks.loadFile(filename);
|
|
80
|
+
if (!data) {
|
|
81
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({ errorText: 'Unable to read XML file' }));
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const source = reader.loadTestData(data);
|
|
85
|
+
if (!source) {
|
|
86
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({ errorText: 'Unable to load XML file' }));
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
// TODO-LDML: The unboxed data doesn't match the schema anymore. Skipping validation, for now.
|
|
90
|
+
// try {
|
|
91
|
+
// if (!reader.validate(source, this.callbacks.loadSchema('ldml-keyboard-test'))) {
|
|
92
|
+
// return null;
|
|
93
|
+
// }
|
|
94
|
+
// } catch(e) {
|
|
95
|
+
// this.callbacks.reportMessage(CompilerMessages.Error_InvalidFile({errorText: e.toString()}));
|
|
96
|
+
// return null;
|
|
97
|
+
// }
|
|
98
|
+
return source;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Validates that the LDML keyboard source file and lints. Actually just
|
|
102
|
+
* compiles the keyboard and returns `true` if everything is good...
|
|
103
|
+
* @param source
|
|
104
|
+
* @returns true if the file validates
|
|
105
|
+
*/
|
|
106
|
+
validate(source) {
|
|
107
|
+
return !!this.compile(source);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Transforms in-memory LDML keyboard xml file to an intermediate
|
|
111
|
+
* representation of a .kmx file.
|
|
112
|
+
* @param source in-memory representation of LDML keyboard xml file
|
|
113
|
+
* @returns KMXPlusFile intermediate file
|
|
114
|
+
*/
|
|
115
|
+
compile(source) {
|
|
116
|
+
const sections = this.buildSections(source);
|
|
117
|
+
let passed = true;
|
|
118
|
+
const kmx = new KMXPlusFile();
|
|
119
|
+
// These two sections are required by other sections
|
|
120
|
+
kmx.kmxplus.strs = new KMXPlus.Strs();
|
|
121
|
+
kmx.kmxplus.elem = new KMXPlus.Elem(kmx.kmxplus.strs);
|
|
122
|
+
kmx.kmxplus.list = new KMXPlus.List(kmx.kmxplus.strs);
|
|
123
|
+
for (let section of sections) {
|
|
124
|
+
if (!section.validate()) {
|
|
125
|
+
passed = false;
|
|
126
|
+
// We'll keep validating other sections anyway, so we get a full set of
|
|
127
|
+
// errors for the keyboard developer.
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const sect = section.compile({ strs: kmx.kmxplus.strs, elem: kmx.kmxplus.elem, list: kmx.kmxplus.list });
|
|
131
|
+
/* istanbul ignore if */
|
|
132
|
+
if (!sect) {
|
|
133
|
+
// This should not happen -- validate() should have told us
|
|
134
|
+
// if something is going to fail to compile
|
|
135
|
+
this.callbacks.reportMessage(CompilerMessages.Fatal_SectionCompilerFailed({ sect: section.id }));
|
|
136
|
+
passed = false;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
kmx.kmxplus[section.id] = sect;
|
|
140
|
+
}
|
|
141
|
+
return passed ? kmx : null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAgB,OAAO,EAAwD,MAAM,yBAAyB,CAAC;AAEvJ,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM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gBAC3C,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,gBAAgB,CAAC,2BAA2B,CAAC,EAAC,IAAI,EAAC,OAAO,CAAC,EAAE,EAAC,CAAC,CAAC,CAAC;gBAC9F,MAAM,GAAG,KAAK,CAAC;gBACf,SAAS;aACV;YACD,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,IAAW,CAAC;SACvC;QAED,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { KMXPlus } from '@keymanapp/common-types';
|
|
2
|
+
import { SectionCompiler } from "./section-compiler.js";
|
|
3
|
+
import GlobalSections = KMXPlus.GlobalSections;
|
|
4
|
+
import Disp = KMXPlus.Disp;
|
|
5
|
+
export declare class DispCompiler extends SectionCompiler {
|
|
6
|
+
get id(): import("@keymanapp/ldml-keyboard-constants").SectionIdent;
|
|
7
|
+
validate(): boolean;
|
|
8
|
+
compile(sections: GlobalSections): Disp;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=disp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disp.d.ts","sourceRoot":"","sources":["../../../src/compiler/disp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;AAC/C,OAAO,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAG3B,qBAAa,YAAa,SAAQ,eAAe;IAE/C,IAAW,EAAE,8DAEZ;IAEM,QAAQ,IAAI,OAAO;IAkBnB,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;CAgB/C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { constants } from "@keymanapp/ldml-keyboard-constants";
|
|
2
|
+
import { KMXPlus } from '@keymanapp/common-types';
|
|
3
|
+
import { CompilerMessages } from "./messages.js";
|
|
4
|
+
import { SectionCompiler } from "./section-compiler.js";
|
|
5
|
+
var Disp = KMXPlus.Disp;
|
|
6
|
+
export class DispCompiler extends SectionCompiler {
|
|
7
|
+
get id() {
|
|
8
|
+
return constants.section.disp;
|
|
9
|
+
}
|
|
10
|
+
validate() {
|
|
11
|
+
let valid = true;
|
|
12
|
+
const tos = new Set();
|
|
13
|
+
if (this.keyboard.displays?.display) {
|
|
14
|
+
for (const { to } of this.keyboard.displays?.display) {
|
|
15
|
+
if (tos.has(to)) {
|
|
16
|
+
this.callbacks.reportMessage(CompilerMessages.Error_DisplayIsRepeated({ to }));
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
tos.add(to);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return valid;
|
|
23
|
+
}
|
|
24
|
+
compile(sections) {
|
|
25
|
+
let result = new Disp();
|
|
26
|
+
// displayOptions
|
|
27
|
+
result.baseCharacter = sections.strs.allocAndUnescapeString(this.keyboard.displays?.displayOptions?.baseCharacter);
|
|
28
|
+
// displays
|
|
29
|
+
result.disps = this.keyboard.displays?.display.map(display => ({
|
|
30
|
+
to: sections.strs.allocAndUnescapeString(display.to),
|
|
31
|
+
display: sections.strs.allocAndUnescapeString(display.display),
|
|
32
|
+
})) || [];
|
|
33
|
+
result.disps.sort((a, b) => a.to.compareTo(b.to));
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=disp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disp.js","sourceRoot":"","sources":["../../../src/compiler/disp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,OAAO,EAA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AC;YACpD,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC;SAC/D,CAAC,CAAC,IAAI,EAAE,CAAC;QAEV,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAW,EAAE,CAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEtE,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CompilerCallbacks, LDMLKeyboard } from "@keymanapp/common-types";
|
|
2
|
+
import CompilerOptions from "./compiler-options.js";
|
|
3
|
+
export interface KeymanWebCompilerOptions extends CompilerOptions {
|
|
4
|
+
}
|
|
5
|
+
export declare class KeymanWebCompiler {
|
|
6
|
+
private callbacks;
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly nl;
|
|
9
|
+
private readonly tab;
|
|
10
|
+
constructor(callbacks: CompilerCallbacks, options?: KeymanWebCompilerOptions);
|
|
11
|
+
compileVisualKeyboard(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): string;
|
|
12
|
+
compileTouchLayout(source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): string;
|
|
13
|
+
private cleanName;
|
|
14
|
+
compile(name: string, source: LDMLKeyboard.LDMLKeyboardXMLSourceFile): string;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=keymanweb-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keymanweb-compiler.d.ts","sourceRoot":"","sources":["../../../src/compiler/keymanweb-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,YAAY,EAAyB,MAAM,yBAAyB,CAAC;AACjH,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAMpD,MAAM,WAAW,wBAAyB,SAAQ,eAAe;CAChE;AAED,qBAAa,iBAAiB;IAKhB,OAAO,CAAC,SAAS;IAJ7B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;gBAET,SAAS,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,wBAAwB;IAM7E,qBAAqB,CAAC,MAAM,EAAE,YAAY,CAAC,yBAAyB;IAgBpE,kBAAkB,CAAC,MAAM,EAAE,YAAY,CAAC,yBAAyB;IAOxE,OAAO,CAAC,SAAS;IAcV,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,yBAAyB,GAAG,MAAM;CA0DrF"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { VisualKeyboard, TouchLayoutFileWriter } from "@keymanapp/common-types";
|
|
2
|
+
import { TouchLayoutCompiler } from "./touch-layout-compiler.js";
|
|
3
|
+
import VisualKeyboardCompiler from "./visual-keyboard-compiler.js";
|
|
4
|
+
const MINIMUM_KMW_VERSION = '16.0';
|
|
5
|
+
;
|
|
6
|
+
export class KeymanWebCompiler {
|
|
7
|
+
callbacks;
|
|
8
|
+
options;
|
|
9
|
+
nl;
|
|
10
|
+
tab;
|
|
11
|
+
constructor(callbacks, options) {
|
|
12
|
+
this.callbacks = callbacks;
|
|
13
|
+
this.options = { ...options };
|
|
14
|
+
this.nl = this.options.debug ? "\n" : '';
|
|
15
|
+
this.tab = this.options.debug ? " " : '';
|
|
16
|
+
}
|
|
17
|
+
compileVisualKeyboard(source) {
|
|
18
|
+
const nl = this.nl, tab = this.tab;
|
|
19
|
+
const vkc = new VisualKeyboardCompiler();
|
|
20
|
+
const vk = vkc.compile(source);
|
|
21
|
+
let result = `{F: '${vk.header.unicodeFont.size}pt ${JSON.stringify(vk.header.unicodeFont.name)}', ` +
|
|
22
|
+
`K102: ${vk.header.flags & 1 /* VisualKeyboard.VisualKeyboardHeaderFlags.kvkh102 */ ? 1 : 0}};${nl}` + // TODO-LDML: escape ' and " in font name correctly
|
|
23
|
+
`${tab}this.KV.KLS={${nl}` +
|
|
24
|
+
`${tab}${tab}TODO_LDML: ${vk.keys.length}${nl}` +
|
|
25
|
+
// TODO-LDML: fill in KLS
|
|
26
|
+
`${tab}}`;
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
compileTouchLayout(source) {
|
|
30
|
+
const tlcompiler = new TouchLayoutCompiler();
|
|
31
|
+
const layout = tlcompiler.compileToJavascript(source);
|
|
32
|
+
const writer = new TouchLayoutFileWriter({ formatted: this.options.debug });
|
|
33
|
+
return writer.compile(layout);
|
|
34
|
+
}
|
|
35
|
+
cleanName(name) {
|
|
36
|
+
let result = this.callbacks.path.basename(name, '.xml');
|
|
37
|
+
if (!result) {
|
|
38
|
+
throw new Error(`Invalid file name ${name}`);
|
|
39
|
+
}
|
|
40
|
+
result = result.replaceAll(/[^a-z0-9]/g, '_');
|
|
41
|
+
if (result.match(/^[0-9]/)) {
|
|
42
|
+
// Can't have a digit as initial
|
|
43
|
+
result = '_' + result;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
compile(name, source) {
|
|
48
|
+
const nl = this.nl, tab = this.tab;
|
|
49
|
+
const sName = 'Keyboard_' + this.cleanName(name);
|
|
50
|
+
const displayUnderlying = true; // TODO-LDML
|
|
51
|
+
const modifierBitmask = 0; // TODO-LDML: define the modifiers used by this keyboard
|
|
52
|
+
const vkDictionary = ''; // TODO-LDML: vk dictionary for touch keys
|
|
53
|
+
const hasSupplementaryPlaneChars = false; // TODO-LDML
|
|
54
|
+
const isRTL = false; // TODO-LDML
|
|
55
|
+
let result = `if(typeof keyman === 'undefined') {${nl}` +
|
|
56
|
+
`${tab}console.error('Keyboard requires KeymanWeb ${MINIMUM_KMW_VERSION} or later');${nl}` +
|
|
57
|
+
`} else {${nl}` +
|
|
58
|
+
`${tab}KeymanWeb.KR(new ${sName}());${nl}` +
|
|
59
|
+
`}${nl}` +
|
|
60
|
+
`function ${sName}() {${nl}` +
|
|
61
|
+
// `${tab}${this.setupDebug()}${nl}` + ? we may use this for modifierBitmask in future
|
|
62
|
+
// `${tab}this._v=(typeof keyman!="undefined"&&typeof keyman.version=="string")?parseInt(keyman.version,10):9;${nl}` + ? we probably don't need this, it's for back-compat
|
|
63
|
+
`${tab}this.KI="${sName}";${nl}` +
|
|
64
|
+
`${tab}this.KN=${JSON.stringify(source.keyboard.names.name[0])};${nl}` +
|
|
65
|
+
`${tab}this.KMINVER=${JSON.stringify(MINIMUM_KMW_VERSION)};${nl}` +
|
|
66
|
+
`${tab}this.KV=${this.compileVisualKeyboard(source)};${nl}` +
|
|
67
|
+
`${tab}this.KDU=${displayUnderlying ? '1' : '0'};${nl}` +
|
|
68
|
+
`${tab}this.KH="";${nl}` + // TODO-LDML: help text not supported
|
|
69
|
+
`${tab}this.KM=0;${nl}` + // TODO-LDML: mnemonic layout not supported for LDML keyboards
|
|
70
|
+
`${tab}this.KBVER=${JSON.stringify(source.keyboard.version?.number || '0.0')};${nl}` +
|
|
71
|
+
`${tab}this.KMBM=${modifierBitmask};${nl}`;
|
|
72
|
+
if (isRTL) {
|
|
73
|
+
result += `${tab}this.KRTL=1;${nl}`;
|
|
74
|
+
}
|
|
75
|
+
if (hasSupplementaryPlaneChars) {
|
|
76
|
+
result += `${tab}this.KS=1;${nl}`;
|
|
77
|
+
}
|
|
78
|
+
if (vkDictionary != '') {
|
|
79
|
+
result += `${tab}this.KVKD=${JSON.stringify(vkDictionary)};${nl}`;
|
|
80
|
+
}
|
|
81
|
+
let layoutFile = this.compileTouchLayout(source);
|
|
82
|
+
if (layoutFile != '') {
|
|
83
|
+
result += `${tab}this.KVKL=${layoutFile};${nl}`;
|
|
84
|
+
}
|
|
85
|
+
// TODO-LDML: KCSS not supported
|
|
86
|
+
// TODO-LDML: embed binary keyboard for loading into Core
|
|
87
|
+
// A LDML keyboard has a no-op for its gs() (begin Unicode) function,
|
|
88
|
+
// because the functionality is embedded in Keyman Core
|
|
89
|
+
result += `${tab}this.gs=function(t,e){${nl}` +
|
|
90
|
+
`${tab}${tab}return 0;${nl}` + // TODO-LDML: we will start by embedding call into Keyman Core here
|
|
91
|
+
`${tab}};${nl}`;
|
|
92
|
+
result += `}${nl}`;
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=keymanweb-compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keymanweb-compiler.js","sourceRoot":"","sources":["../../../src/compiler/keymanweb-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,cAAc,EAAgB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,sBAAsB,MAAM,+BAA+B,CAAC;AAEnE,MAAM,mBAAmB,GAAG,MAAM,CAAC;AAGlC,CAAC;AAEF,MAAM,OAAO,iBAAiB;IAKR;IAJH,OAAO,CAA2B;IAClC,EAAE,CAAS;IACX,GAAG,CAAS;IAE7B,YAAoB,SAA4B,EAAE,OAAkC;QAAhE,cAAS,GAAT,SAAS,CAAmB;QAC9C,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,CAAC;IAEM,qBAAqB,CAAC,MAA8C;QACzE,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACnC,MAAM,GAAG,GAAG,IAAI,sBAAsB,EAAE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
|
|
3
|
+
import GlobalSections = KMXPlus.GlobalSections;
|
|
4
|
+
import Keys = KMXPlus.Keys;
|
|
5
|
+
export declare class KeysCompiler extends SectionCompiler {
|
|
6
|
+
get id(): import("@keymanapp/ldml-keyboard-constants").SectionIdent;
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @returns just the non-touch layers.
|
|
10
|
+
*/
|
|
11
|
+
hardwareLayers(): LDMLKeyboard.LKLayers[];
|
|
12
|
+
validate(): boolean;
|
|
13
|
+
compile(sections: GlobalSections): Keys;
|
|
14
|
+
loadFlicks(sections: GlobalSections, sect: Keys): void;
|
|
15
|
+
loadKeys(sections: GlobalSections, sect: Keys): void;
|
|
16
|
+
/**
|
|
17
|
+
* TODO-LDML: from old 'keys'
|
|
18
|
+
* Validate for purpose of kmap
|
|
19
|
+
* @param hardware the 'form' parameter
|
|
20
|
+
* @param layer
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
private validateHardwareLayerForKmap;
|
|
24
|
+
private compileHardwareLayerToKmap;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../src/compiler/keys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,OAAO,EAAa,MAAM,yBAAyB,CAAC;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;AAC/C,OAAO,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAK3B,qBAAa,YAAa,SAAQ,eAAe;IAE/C,IAAW,EAAE,8DAEZ;IAED;;;OAGG;IACI,cAAc;IAId,QAAQ;IAyCR,OAAO,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IA+BvC,UAAU,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI;IAqB/C,QAAQ,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI;IAuCpD;;;;;;OAMG;IACH,OAAO,CAAC,4BAA4B;IAkDpC,OAAO,CAAC,0BAA0B;CA+BnC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { constants } from '@keymanapp/ldml-keyboard-constants';
|
|
2
|
+
import { KMXPlus, Constants } from '@keymanapp/common-types';
|
|
3
|
+
import { CompilerMessages } from './messages.js';
|
|
4
|
+
import { SectionCompiler } from "./section-compiler.js";
|
|
5
|
+
var Keys = KMXPlus.Keys;
|
|
6
|
+
var KeysFlicks = KMXPlus.KeysFlicks;
|
|
7
|
+
import { allUsedKeyIdsInLayers, calculateUniqueKeys, translateLayerAttrToModifier, validModifier } from '../util/util.js';
|
|
8
|
+
export class KeysCompiler extends SectionCompiler {
|
|
9
|
+
get id() {
|
|
10
|
+
return constants.section.keys;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @returns just the non-touch layers.
|
|
15
|
+
*/
|
|
16
|
+
hardwareLayers() {
|
|
17
|
+
return this.keyboard.layers?.filter(({ form }) => form !== 'touch');
|
|
18
|
+
}
|
|
19
|
+
validate() {
|
|
20
|
+
let valid = true;
|
|
21
|
+
// general key-level validation here, only of used keys
|
|
22
|
+
const usedKeys = allUsedKeyIdsInLayers(this.keyboard?.layers);
|
|
23
|
+
const uniqueKeys = calculateUniqueKeys([...this.keyboard.keys?.key]);
|
|
24
|
+
for (let key of uniqueKeys) {
|
|
25
|
+
const { id, flicks } = key;
|
|
26
|
+
if (!usedKeys.has(id)) {
|
|
27
|
+
continue; // unused key, ignore
|
|
28
|
+
}
|
|
29
|
+
// TODO-LDML: further key-level validation here
|
|
30
|
+
if (!flicks) {
|
|
31
|
+
continue; // no flicks
|
|
32
|
+
}
|
|
33
|
+
const flickEntry = this.keyboard.keys?.flicks?.find(x => x.id === flicks);
|
|
34
|
+
if (!flickEntry) {
|
|
35
|
+
valid = false;
|
|
36
|
+
this.callbacks.reportMessage(CompilerMessages.Error_MissingFlicks({ flicks, id }));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// the layr compiler does more extensive validation of the layer attributes.
|
|
40
|
+
// Kmap validation
|
|
41
|
+
const hardwareLayers = this.hardwareLayers();
|
|
42
|
+
if (hardwareLayers.length >= 1) {
|
|
43
|
+
// validate all errors
|
|
44
|
+
for (let layers of hardwareLayers) {
|
|
45
|
+
for (let layer of layers.layer) {
|
|
46
|
+
valid = this.validateHardwareLayerForKmap(layers.form, layer) && valid; // note: always validate even if previously invalid results found
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// TODO-LDML: Touch?
|
|
52
|
+
}
|
|
53
|
+
return valid;
|
|
54
|
+
}
|
|
55
|
+
compile(sections) {
|
|
56
|
+
if (!this.keyboard?.keys?.key && !this.keyboard?.keys?.flicks) {
|
|
57
|
+
// short-circuit if no keys or flicks
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
let sect = new Keys(sections.strs);
|
|
61
|
+
// Load the flicks first
|
|
62
|
+
this.loadFlicks(sections, sect);
|
|
63
|
+
// Now, load the keys
|
|
64
|
+
this.loadKeys(sections, sect);
|
|
65
|
+
// Finally, kmap
|
|
66
|
+
// Use LayerMap + keys to generate compiled keys for hardware
|
|
67
|
+
const hardwareLayers = this.hardwareLayers();
|
|
68
|
+
if (hardwareLayers.length > 1) {
|
|
69
|
+
// validation should have already caught this
|
|
70
|
+
throw Error(`Internal error: Expected 0 or 1 hardware layer, not ${hardwareLayers.length}`);
|
|
71
|
+
}
|
|
72
|
+
else if (hardwareLayers.length === 1) {
|
|
73
|
+
const theLayers = hardwareLayers[0];
|
|
74
|
+
const { form } = theLayers;
|
|
75
|
+
for (let layer of theLayers.layer) {
|
|
76
|
+
this.compileHardwareLayerToKmap(sections, layer, sect, form);
|
|
77
|
+
}
|
|
78
|
+
} // else: TODO-LDML do nothing if only touch layers
|
|
79
|
+
return sect;
|
|
80
|
+
}
|
|
81
|
+
loadFlicks(sections, sect) {
|
|
82
|
+
for (let lkflicks of this.keyboard.keys.flicks) {
|
|
83
|
+
let flicks = new KeysFlicks(sections.strs.allocString(lkflicks.id));
|
|
84
|
+
for (let lkflick of lkflicks.flick) {
|
|
85
|
+
let flags = 0;
|
|
86
|
+
// TODO-LDML: single char
|
|
87
|
+
const to = sections.strs.allocAndUnescapeString(lkflick.to);
|
|
88
|
+
flags |= constants.keys_flick_flags_extend;
|
|
89
|
+
let directions = sections.list.allocListFromSpaces(sections.strs, lkflick.directions);
|
|
90
|
+
flicks.flicks.push({
|
|
91
|
+
directions,
|
|
92
|
+
flags,
|
|
93
|
+
to,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
sect.flicks.push(flicks);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
loadKeys(sections, sect) {
|
|
100
|
+
const usedKeys = allUsedKeyIdsInLayers(this.keyboard?.layers);
|
|
101
|
+
const uniqueKeys = calculateUniqueKeys([...this.keyboard.keys?.key]);
|
|
102
|
+
for (let key of uniqueKeys) {
|
|
103
|
+
if (!usedKeys.has(key.id)) {
|
|
104
|
+
// TODO-LDML: linting for unused, non-implied and non-imported keys,
|
|
105
|
+
continue; // unused key, skip
|
|
106
|
+
}
|
|
107
|
+
let flags = 0;
|
|
108
|
+
const flicks = key.flicks;
|
|
109
|
+
if (!!key.gap) {
|
|
110
|
+
flags |= constants.keys_key_flags_gap;
|
|
111
|
+
}
|
|
112
|
+
if (key.transform === 'no') {
|
|
113
|
+
flags |= constants.keys_key_flags_notransform;
|
|
114
|
+
}
|
|
115
|
+
const id = sections.strs.allocString(key.id);
|
|
116
|
+
const longPress = sections.list.allocListFromEscapedSpaces(sections.strs, key.longPress);
|
|
117
|
+
const longPressDefault = sections.strs.allocAndUnescapeString(key.longPressDefault);
|
|
118
|
+
const multiTap = sections.list.allocListFromEscapedSpaces(sections.strs, key.multiTap);
|
|
119
|
+
const keySwitch = sections.strs.allocString(key.switch); // 'switch' is a reserved word
|
|
120
|
+
flags |= constants.keys_key_flags_extend;
|
|
121
|
+
const to = sections.strs.allocAndUnescapeString(key.to); // TODO-LDML: single char
|
|
122
|
+
const width = Math.ceil((key.width || 1) * 10.0); // default, width=1
|
|
123
|
+
sect.keys.push({
|
|
124
|
+
flags,
|
|
125
|
+
flicks,
|
|
126
|
+
id,
|
|
127
|
+
longPress,
|
|
128
|
+
longPressDefault,
|
|
129
|
+
multiTap,
|
|
130
|
+
switch: keySwitch,
|
|
131
|
+
to,
|
|
132
|
+
width,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* TODO-LDML: from old 'keys'
|
|
138
|
+
* Validate for purpose of kmap
|
|
139
|
+
* @param hardware the 'form' parameter
|
|
140
|
+
* @param layer
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
143
|
+
validateHardwareLayerForKmap(hardware, layer) {
|
|
144
|
+
let valid = true;
|
|
145
|
+
const { modifier } = layer;
|
|
146
|
+
if (!validModifier(modifier)) {
|
|
147
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidModifier({ modifier, layer: layer.id }));
|
|
148
|
+
valid = false;
|
|
149
|
+
}
|
|
150
|
+
const keymap = Constants.HardwareToKeymap.get(hardware);
|
|
151
|
+
if (!keymap) {
|
|
152
|
+
this.callbacks.reportMessage(CompilerMessages.Error_InvalidHardware({ form: hardware }));
|
|
153
|
+
valid = false;
|
|
154
|
+
}
|
|
155
|
+
const uniqueKeys = calculateUniqueKeys([...this.keyboard.keys?.key]);
|
|
156
|
+
if (layer.row.length > keymap.length) {
|
|
157
|
+
this.callbacks.reportMessage(CompilerMessages.Error_HardwareLayerHasTooManyRows());
|
|
158
|
+
valid = false;
|
|
159
|
+
}
|
|
160
|
+
for (let y = 0; y < layer.row.length && y < keymap.length; y++) {
|
|
161
|
+
const keys = layer.row[y].keys.split(' ');
|
|
162
|
+
if (keys.length > keymap[y].length) {
|
|
163
|
+
this.callbacks.reportMessage(CompilerMessages.Error_RowOnHardwareLayerHasTooManyKeys({ row: y + 1, hardware, modifier }));
|
|
164
|
+
valid = false;
|
|
165
|
+
}
|
|
166
|
+
let x = -1;
|
|
167
|
+
for (let key of keys) {
|
|
168
|
+
x++;
|
|
169
|
+
let keydef = uniqueKeys.find(x => x.id == key);
|
|
170
|
+
if (!keydef) {
|
|
171
|
+
this.callbacks.reportMessage(CompilerMessages.Error_KeyNotFoundInKeyBag({ keyId: key, col: x + 1, row: y + 1, layer: layer.id, form: 'hardware' }));
|
|
172
|
+
valid = false;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (!keydef.to && !keydef.gap && !keydef.switch) {
|
|
176
|
+
this.callbacks.reportMessage(CompilerMessages.Error_KeyMissingToGapOrSwitch({ keyId: key }));
|
|
177
|
+
valid = false;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return valid;
|
|
183
|
+
}
|
|
184
|
+
compileHardwareLayerToKmap(sections, layer, sect, hardware) {
|
|
185
|
+
const mod = translateLayerAttrToModifier(layer);
|
|
186
|
+
const keymap = Constants.HardwareToKeymap.get(hardware);
|
|
187
|
+
let y = -1;
|
|
188
|
+
for (let row of layer.row) {
|
|
189
|
+
y++;
|
|
190
|
+
const keys = row.keys.split(' ');
|
|
191
|
+
let x = -1;
|
|
192
|
+
for (let key of keys) {
|
|
193
|
+
x++;
|
|
194
|
+
// TODO-LDML: we already validated that the key exists, above.
|
|
195
|
+
// So here we only need the ID?
|
|
196
|
+
// let keydef = this.keyboard.keys?.key?.find(x => x.id == key);
|
|
197
|
+
sect.kmap.push({
|
|
198
|
+
vkey: keymap[y][x],
|
|
199
|
+
mod: mod,
|
|
200
|
+
key, // key id, to be changed into key index at finalization
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return sect;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=keys.js.map
|